//detekcia prehliadaca
var NS4 = (document.layers);
var IE4 = (document.all);
var IE5 = (document.getElementById && document.all);
var IE55 = (IE4 && navigator.appVersion.indexOf("5.5")!=-1);
var IE6 = (typeof (document.media) == 'string' && document.getElementById && document.all)
var IE = IE4||IE5||IE55||IE6;
var ver4 = (NS4 || IE4);
var isMac = (navigator.appVersion.indexOf("Mac") != -1);
var isMenu = (NS4 || (IE4 && !isMac) || (IE5 && !isMac));

// ---------------
// FLASH DETECTION
// ---------------
var requiredVersion = 3;

var flash2Installed = false;
var flash3Installed = false;
var flash4Installed = false;
var flash5Installed = false;
var flash6Installed = false;
var flash7Installed = false;
var flash8Installed = false;
var flash9Installed = false;
var maxVersion = 9;
var actualVersion = 0;
var hasRightVersion = false;
var jsVersion = 1.0;

var isIE = (navigator.appVersion.indexOf("MSIE") != -1) ? true : false;
var isWin = (navigator.appVersion.indexOf("Windows") != -1) ? true : false;

jsVersion = 1.1;

if(isIE && isWin){
	document.write('<SCR' + 'IPT LANGUAGE=VBScript\> \n');
	document.write('on error resume next \n');
	document.write('flash2Installed = (IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash.2"))) \n');
	document.write('flash3Installed = (IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash.3"))) \n');
	document.write('flash4Installed = (IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash.4"))) \n');
	document.write('flash5Installed = (IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash.5"))) \n');	
	document.write('flash6Installed = (IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash.6"))) \n');	
	document.write('flash7Installed = (IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash.7"))) \n');
	document.write('flash8Installed = (IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash.8"))) \n');
	document.write('flash9Installed = (IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash.9"))) \n');
	document.write('</SCR' + 'IPT\> \n');
}

function detectFlash(){	

	if (navigator.plugins){
		if (navigator.plugins["Shockwave Flash 2.0"]
		|| navigator.plugins["Shockwave Flash"]){

			var isVersion2 = navigator.plugins["Shockwave Flash 2.0"] ? " 2.0" : "";
			var flashDescription = navigator.plugins["Shockwave Flash" + isVersion2].description;
			var flashVersion = parseInt(flashDescription.charAt(flashDescription.indexOf(".") - 1));
			
			flash2Installed = flashVersion == 2;		
			flash3Installed = flashVersion == 3;
			flash4Installed = flashVersion == 4;
			flash5Installed = flashVersion == 5;
			flash6Installed = flashVersion == 6;
			flash7Installed = flashVersion == 7;
			flash8Installed = flashVersion == 8;
			flash9Installed = flashVersion == 9;
		}
	}
	
	for (var i = 2; i <= maxVersion; i++) {	
		if (eval("flash" + i + "Installed") == true) actualVersion = i;
	}

	if(navigator.userAgent.indexOf("WebTV") != -1) actualVersion = 2;	
	

	if (actualVersion >= requiredVersion)
		hasRightVersion = true;
	else
		hasRightVersion = false;
		
	return hasRightVersion;
}


// priradim hodnotu
var isFLASH = detectFlash();

// -------------------------------------------------------------------
//	Univerzalna funkcia na vypis flash 
// -------------------------------------------------------------------
function writeFlashBanner(FlashSRC,Width,Height)
{
	document.write("<object type=\"application/x-shockwave-flash\" data=\"" + FlashSRC + "\" width=\"" + Width + "\" height=\"" + Height + "\" id=ObjectFlash>");
	document.write("<param name=\"movie\" value=\"" + FlashSRC + "\">");
	document.write("<param name=quality value=high>");
	document.write("<PARAM NAME=wmode VALUE=transparent>");
	document.write("</OBJECT>");
}

function ConfirmDelete(){
	var agree=confirm("Are you sure you wish to delete item?");
	if (agree)
		return true ;
	else
		return false ;
}

function CheckForm(){
	var message = "Missing:\r\n";
	var eligible = true;
	
	if (document.getElementById("title").value.length == 0){
		message += "- Title\r\n";
		eligible = false;
	}
	/*if (document.getElementById("description").value.length == 0){
		message += "- Description\r\n";
		eligible = false;
	}*/		
	if (document.getElementById("place").value.length == 0){
		message += "- Place\r\n";
		eligible = false;
	}
	if (document.getElementById("start_date").value.length == 0){
		message += "- Start date\r\n";
		eligible = false;
	}
		
	if (!eligible)
		alert(message);
		
	return eligible;	
}

function FormatDate(DateToFormat,FormatAs){
if(DateToFormat==""){return"";}
if(!FormatAs){FormatAs="dd/mm/yyyy";}

var strReturnDate;
FormatAs = FormatAs.toLowerCase();
DateToFormat = DateToFormat.toLowerCase();
var arrDate
var arrMonths = new Array("January","February","March","April","May","June","July","August","September","October","November","December");
var strMONTH;
var Separator;

while(DateToFormat.indexOf("st")>-1){
DateToFormat = DateToFormat.replace("st","");
}

while(DateToFormat.indexOf("nd")>-1){
DateToFormat = DateToFormat.replace("nd","");
}

while(DateToFormat.indexOf("rd")>-1){
DateToFormat = DateToFormat.replace("rd","");
}

while(DateToFormat.indexOf("th")>-1){
DateToFormat = DateToFormat.replace("th","");
}

if(DateToFormat.indexOf(".")>-1){
Separator = ".";
}

if(DateToFormat.indexOf("-")>-1){
Separator = "-";
}


if(DateToFormat.indexOf("/")>-1){
Separator = "/";
}

if(DateToFormat.indexOf(" ")>-1){
Separator = " ";
}

arrDate = DateToFormat.split(Separator);
DateToFormat = "";
	for(var iSD = 0;iSD < arrDate.length;iSD++){
		if(arrDate[iSD]!=""){
		DateToFormat += arrDate[iSD] + Separator;
		}
	}
DateToFormat = DateToFormat.substring(0,DateToFormat.length-1);
arrDate = DateToFormat.split(Separator);

if(arrDate.length < 3){
return "";
}

var DAY = arrDate[0];
var MONTH = arrDate[1];
var YEAR = arrDate[2];




if(parseFloat(arrDate[1]) > 12){
DAY = arrDate[1];
MONTH = arrDate[0];
}

if(parseFloat(DAY) && DAY.toString().length==4){
YEAR = arrDate[0];
DAY = arrDate[2];
MONTH = arrDate[1];
}


for(var iSD = 0;iSD < arrMonths.length;iSD++){
var ShortMonth = arrMonths[iSD].substring(0,3).toLowerCase();
var MonthPosition = DateToFormat.indexOf(ShortMonth);
	if(MonthPosition > -1){
	MONTH = iSD + 1;
		if(MonthPosition == 0){
		DAY = arrDate[1];
		YEAR = arrDate[2];
		}
	break;
	}
}

var strTemp = YEAR.toString();
if(strTemp.length==2){

	if(parseFloat(YEAR)>40){
	YEAR = "19" + YEAR;
	}
	else{
	YEAR = "20" + YEAR;
	}

}


	if(parseInt(MONTH)< 10 && MONTH.toString().length < 2){
	MONTH = "0" + MONTH;
	}
	if(parseInt(DAY)< 10 && DAY.toString().length < 2){
	DAY = "0" + DAY;
	}
	switch (FormatAs){
	case "dd/mm/yyyy":
	return DAY + "/" + MONTH + "/" + YEAR;
	case "mm/dd/yyyy":
	return MONTH + "/" + DAY + "/" + YEAR;
	case "dd/mmm/yyyy":
	return DAY + " " + arrMonths[MONTH -1].substring(0,3) + " " + YEAR;
	case "mmm/dd/yyyy":
	return arrMonths[MONTH -1].substring(0,3) + " " + DAY + " " + YEAR;
	case "dd/mmmm/yyyy":
	return DAY + " " + arrMonths[MONTH -1] + " " + YEAR;	
	case "mmmm/dd/yyyy":
	return arrMonths[MONTH -1] + " " + DAY + " " + YEAR;
	}

return DAY + "/" + strMONTH + "/" + YEAR;;

}

function isDate(DateToCheck){
	if(DateToCheck==""){return true;}
	var m_strDate = FormatDate(DateToCheck);
	if(m_strDate==""){
		return false;
	}
	var m_arrDate = m_strDate.split("/");
	var m_DAY = m_arrDate[0];
	var m_MONTH = m_arrDate[1];
	var m_YEAR = m_arrDate[2];
	if(m_YEAR.length > 4){return false;}
	
	m_strDate = m_MONTH + "/" + m_DAY + "/" + m_YEAR;	
	var testDate=new Date(m_strDate);
	if(testDate.getMonth()+1==m_MONTH){
		return true;
	} 
	else{
		return false;
	}
}

function ValidateDate(input){
	var value = input.value;	
	if (value.Length == 0) return;
	
	if (!isDate(value)){
		input.style.borderColor = '#ff0000';	
	}
	else{
		input.style.borderColor = '#038ec7';
	}
}


function ShowHide(elementId) {
	var element = document.getElementById(elementId);
	if (element.style.display == 'block')
		element.style.display = 'none';
	else
		element.style.display = 'block';
}

function ShowHideParentSibling(element, level) {
	while (level-->0) {
		element = element.parentNode;
	}
	var sibling = element.nextSibling;
	while ((sibling != null) && (sibling.nodeType != Node.ELEMENT_NODE)) {
		sibling = sibling.nextSibling;
	}

	if (sibling.style.visibility=='visible')
		sibling.style.visibility = 'hidden';
	else
		sibling.style.visibility = 'visible';
}

