var agt=navigator.userAgent.toLowerCase();
var is_major = parseInt(navigator.appVersion);
var is_minor = parseFloat(navigator.appVersion);
var is_nav  = ((agt.indexOf('mozilla')!=-1) && (agt.indexOf('spoofer')==-1) && (agt.indexOf('compatible') == -1) && (agt.indexOf('opera')==-1) && (agt.indexOf('webtv')==-1));

var is_nav4 = (is_nav && (is_major == 4));
var is_nav4up = (is_nav && (is_major >= 4));
var is_nav6 = (is_nav && (is_major == 5));
var is_nav6up = (is_nav && (is_major >= 5));
var is_ie   = (agt.indexOf("msie") != -1);
var is_ie3  = (is_ie && (is_major < 4));
var is_ie4  = (is_ie && (is_major == 4) && (agt.indexOf("msie 5.0")==-1));
var is_ie4up  = (is_ie  && (is_major >= 4));
var is_ie5  = (is_ie && (is_major == 4) && (agt.indexOf("msie 5.0")!=-1));
var is_ie5up  = (is_ie && !is_ie3 && !is_ie4);
var is_opera = (agt.indexOf("opera") != -1);
var is_opera4 = (is_opera && (is_major == 4));
var is_opera5 = (is_opera && (is_major == 5));
var is_opera5up = (is_opera && (is_major >= 5));

var is_domcom = ((is_nav6up)||(is_ie5up)||(is_opera5up))
var is_mac    = (agt.indexOf("mac")!=-1);
var is_mac68k = (is_mac && ((agt.indexOf("68k")!=-1) || (agt.indexOf("68000")!=-1)));
var is_macppc = (is_mac && ((agt.indexOf("ppc")!=-1) || (agt.indexOf("powerpc")!=-1)));



var _timeout	= 500;

function getElementByIds(_id) {

	var _el;

	if(is_domcom) {
		_el	= document.getElementById(_id);
	} else if(is_ie4) {
		_el	= document.all[_id];
	}

	return _el;
}

function _showMenu(_objID) {
	var _obj	= getElementByIds(_objID);
	if(_obj) {
		_obj.style.display	= 'block';
	}
}

function _hideMenu(_objID) {
	var _obj	= getElementByIds(_objID);
	if(_obj) {
		_obj.style.display	= 'none';
	}
}

//hide other submenus begin
function hideOther(_id){
	var myMenu = getElementByIds(_id);
	var sm1 = getElementByIds("subMenu1Div");
	var sm2 = getElementByIds("subMenu2Div");
	var sm3 = getElementByIds("subMenu3Div");
	var sm4 = getElementByIds("subMenu4Div");

	if(sm1 && sm1 != myMenu) {
		sm1.style.display	= 'none';
	}
	if(sm2 && sm2 != myMenu) {
		sm2.style.display	= 'none';
	}
	if(sm3 && sm3 != myMenu) {
		sm3.style.display	= 'none';
	}
	if(sm4 && sm4 != myMenu) {
		sm4.style.display	= 'none';
	}
}
//hide other submenus end

//highliht selected menu item parent begin
function highlightMenuItem(item){
	var item = getElementByIds(item);
	
	if(item){
		item.style.backgroundColor = '#94DEFB';
	}
}

function unhighlightMenuItem(item){
	var item = getElementByIds(item);
	
	if(item){
		item.style.backgroundColor = 'transparent';
	}
}

//highliht selected menu item parent end

/*************************************************
 *	shows element with id passed as parameter
 *************************************************/
function doOver(_id) {
	var _el	= getElementByIds(_id);
	hideOther(_id);
	if(_el) {
		if(_el.timer) {
			clearTimeout(_el.timer);
		}
		 _showMenu(_id);
	}
}

/*************************************************
 *	hides element with id passed as parameter
 *************************************************/

var time

function doOut(_id) {

	var _el	= getElementByIds(_id);

	if(_el) {
		var _timer	= setTimeout("_hideMenu('" + _id + "')", _timeout);
		_el.timer	= _timer;
	}
}




/*************************************************
 *	fixes the IE png alpha channel bug
 *  WARNING: This prolongate loading the page
 *************************************************/
function correctPNG() {
if (!is_opera) {
   for(var i=0; i<document.images.length; i++)
      {
	  var img = document.images[i]
	  var imgName = img.src.toUpperCase()
	  if (imgName.substring(imgName.length-3, imgName.length) == "PNG")
	     {
		 var imgID = (img.id) ? "id='" + img.id + "' " : ""
		 var imgClass = (img.className) ? "class='" + img.className + "' " : ""
		 var imgTitle = (img.title) ? "title='" + img.title + "' " : "title='" + img.alt + "' "
		 var imgStyle = "display:inline-block;" + img.style.cssText 
		 if (img.align == "left") imgStyle = "float:left;" + imgStyle
		 if (img.align == "right") imgStyle = "float:right;" + imgStyle
		 if (img.parentElement.href) imgStyle = "cursor:hand;" + imgStyle		
		 var strNewHTML = "<span " + imgID + imgClass + imgTitle
		 + " style=\"" + "width:" + img.width + "px; height:" + img.height + "px;" + imgStyle + ";"
	     + "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader"
		 + "(src=\'" + img.src + "\', sizingMethod='scale');\"></span>" 
		 img.outerHTML = strNewHTML
		 i = i-1
	     }
      }
}
}

//**************************
//NOFLASH PAGE VERSION BEGIN
//**************************

var MM_contentVersion = 6;
var plugin = (navigator.mimeTypes &&
navigator.mimeTypes["application/x-shockwave-flash"]) ? navigator.mimeTypes["application/x-shockwave-flash"].enabledPlugin : 0; if ( plugin ) {
		var words = navigator.plugins["Shockwave Flash"].description.split(" ");
	    for (var i = 0; i < words.length; ++i)
	    {
		if (isNaN(parseInt(words[i])))
		continue;
		var MM_PluginVersion = words[i];
	    }
	var MM_FlashCanPlay = MM_PluginVersion >= MM_contentVersion;
}
else if (navigator.userAgent && navigator.userAgent.indexOf("MSIE")>=0 &&
(navigator.appVersion.indexOf("Win") != -1)) {
	document.write('<SCR' + 'IPT LANGUAGE=VBScript\> \n'); //FS hide this from IE4.5 Mac by splitting the tag
	document.write('on error resume next \n');
	document.write('MM_FlashCanPlay = ( IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash." & MM_contentVersion)))\n');
	document.write('</SCR' + 'IPT\> \n');
}

//************************
//NOFLASH PAGE VERSION END
//************************

//contestFileUploadValidate() begin
function contestFileUploadValidate(){
	var i = 0, temp = 0;
	var errorArray = new Array(4);
	var mailValue = document.formFileUpload.file_mail.value;
	var photoPath = document.formFileUpload.file_myfile.value;

	//email 
	for (i = 0; i < mailValue.length; i++){
		if(mailValue.substring(i, i + 1) =='@'){
			temp++;
		}
	}
	if(temp != 1 | mailValue.substring(0,1) == '@' | mailValue.substring(mailValue.length - 1 , mailValue.length) == '@')
		errorArray[0] = true;
		
	//description
	if(document.formFileUpload.file_description.value == '')
		errorArray[1] = true;
		
	//photo path
	if(photoPath.length < 5)
		errorArray[2] = true;
	else
		if ((photoPath.substring(photoPath.length-3, photoPath.length-4) != '.' | photoPath.substring(photoPath.length-2, photoPath.length-3) != 'j' | photoPath.substring(photoPath.length-1, photoPath.length-2) != 'p' | photoPath.substring(photoPath.length, photoPath.length-1) != 'g') & (photoPath.substring(photoPath.length-4, photoPath.length-5) != '.' | photoPath.substring(photoPath.length-3, photoPath.length-4) != 'j' | photoPath.substring(photoPath.length-2, photoPath.length-3) != 'p' | photoPath.substring(photoPath.length-1, photoPath.length-2) != 'e' | photoPath.substring(photoPath.length, photoPath.length-1) != 'g'))
			
		errorArray[3] = true;
		
	if(errorArray[0] | errorArray[1] | errorArray[2] | errorArray[3]){
		var errorAlert = 'Prosím, vyplňte nasledovné údaje:\n';
		if(errorArray[0])
			errorAlert += '\nE-mail'
		if(errorArray[1])
			errorAlert += '\nPopis fotky'
		if(errorArray[2])
			errorAlert += '\nCestu k fotke'
		if(errorArray[3])
			errorAlert += '\nProsím, vyberte obrázok typu JPG'
		
		alert(errorAlert);
	}
	else
		document.formFileUpload.submit();
}

//contestFileUploadValidate() end

//submitDetelePhoto() begin
function submitDeletePhoto(_id){
	document.formPhotosList.delete_photo.value = -1;
	document.formPhotosList.delete_photo.value = _id;
	
	continueDelete = confirm("Chcete odstrániť túto fotku?");
	if(continueDelete)
		document.formPhotosList.submit();
}
//submitDetelePhoto() end

//submitSelectPhoto() begin
function submitSelectPhoto(id){

	document.contestSelectForm.selected_photo.value = -1;
	document.contestSelectForm.selected_photo.value = id;
	
	document.contestSelectForm.submit();
}
//submitSelectPhoto() end

//submitPhotoVoting() begin
function submitPhotoVoting(id){
	var i = 0, temp = 0;
	var errorArray = new Array(1);
	var mailValue = document.formVoterMail.voterMail.value;
	
	//email 
	for (i = 0; i < mailValue.length; i++){
		if(mailValue.substring(i, i + 1) =='@'){
			temp++;
		}
	}
	if(temp != 1 | mailValue.substring(0,1) == '@' | mailValue.substring(mailValue.length - 1 , mailValue.length) == '@')
		errorArray[0] = true;

		
	if(errorArray[0]){
		alert('Prosím, zadajte svoj e-mail');
	}
	else{
		id.voter_mail.value = document.formVoterMail.voterMail.value;
		id.submit();
	}
}
//submitPhotoVoting() end

//showContactMap begin
function showContactMap(){
	window.open("/env/images/contactMapBig.jpg", "_blank", "width = 716, height = 553");
}
//showContactMap end


function popUp(URL) {
day = new Date();
id = day.getTime();
eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=1,width=600,height=430,left = 340,top = 302');");
}
