function uloz_cookie()
	{ 
		var str; 
		var vyprs=new Date(); 
		vyprs.setDate(vyprs.getDate() - 365); 
		document.cookie="nastaveni=1; expires="+vyprs.toGMTString()+";"; 
		vyprs.setDate(365 + 365 + vyprs.getDate()); 
		document.cookie="nastaveni=1; expires="+vyprs.toGMTString()+";"; 
	} 

function openLink(URI){
win = window.open(URI,"secWin","");
win.focus;
}

/*function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}*/ //pouzivano drive v cms, pokud bude stranka hlasit chybu javascriptu, muze to byt tim

function preload_images()
{
	var promenna=new Array();
	for (var i=0; i<preload_images.arguments.length; i++)
	{
		promenna[i] = new Image();
		promenna[i].src = preload_images.arguments[i];
	}
}


function JustSoPicWindow(imageName,imageWidth,imageHeight,typ) 
{
	bgcolor="#FFFFFF";
	
	if (typ==1)
		imageName=imageName.substring(0,imageName.lastIndexOf("/"))+"-big"+imageName.substring(imageName.lastIndexOf("/"),imageName.length);
	else if (typ==2)
		imageName=imageName.substring(0,(imageName.length-5))+"v.jpg";
	else if (typ==3)
		;
	else
		imageName=imageName.substring(0,(imageName.length-8))+"big.jpg";
		
	if ((typ==1) || (typ=='') || (typ==2))
		typ="Klikněte pro zavření okna";
		
		
	//nove promenne
	var pimageWidth=imageWidth;
	var pimageHeight=imageHeight;
	var posuvnik='no';
	//********************
	
	var adj=10;
	var w = screen.width;
	var h = screen.height;
	
	var scrWidth;
	var scrHeight;
	var plus=0;
	
	//alert(w+","+h);
	//var byFactor=1;
	
	if (w<imageWidth) //obrazek je sirsi nez obrazovka
	{
		posuvnik='yes';
		srcWidth=w;
		plus=20;
	}
	else srcWidth=parseInt(imageWidth)+plus;
	
	if ((h-50-plus)<imageHeight) //obrazek je vyssi nez obrazovka
	{
		posuvnik='yes';
		srcHeight=h;
		plus=20;
	}
	else srcHeight=parseInt(imageHeight)+plus;
	
	srcWidth=srcWidth+plus;

	var posLeft=Math.round((w-srcWidth)/2);
	var posTop=Math.round((h-srcHeight)/2);

	/*posTop = parseInt(posTop);
	posLeft = parseInt(posLeft);		
	scrWidth = parseInt(scrWidth); 
	scrHeight = parseInt(scrHeight);*/
	
	
	
	var agt=navigator.userAgent.toLowerCase();
	if (agt.indexOf("opera") != -1){
	  var args= new Array();
	  args[0]='parent';
	  args[1]=imageName;
	  var i ; document.MM_returnValue = false;
	  for (i=0; i<(args.length-1); i+=2) eval(args[i]+".location='"+args[i+1]+"'");
	} else {
	newWindow = window.open("",null,"width="+srcWidth+",height="+srcHeight+",left="+posLeft+",top="+posTop+", scrollbars="+posuvnik);
	newWindow.document.open();
	newWindow.document.write('<html><title>'+typ+'</title><body leftmargin="0" topmargin="0" marginheight="0" marginwidth="0" bgcolor='+bgcolor+' onBlur="self.close()" onClick="self.close()">');  
	newWindow.document.write('<table width='+imageWidth+' border="0" cellspacing="0" cellpadding="0" align="center" height='+scrHeight+' ><tr><td>');
	newWindow.document.write('<img src="'+imageName+'" width='+imageWidth+' height='+imageHeight+' alt="'+typ+'" >'); 
	newWindow.document.write('</td></tr></table></body></html>');
	newWindow.document.close();
	newWindow.focus();
	}
}

function kontrola_poptavka()
{
	var vysl=''
	if (document.form_odeslat.mail.value.search(/^([^(@#$*()!\?)]+)@([^(@#$*()!\?)]+)[.][a-zA-Z]{2,3}$/))
	{
		alert('Poptávka nemohla být odeslána, protože se vyskytla tato chyba:\n - byla zadána neplatná e-mailová adresa');
		return false;
	}
	return true;
}	

function send_xmlhttprequest(obsluha, method, url, content, headers) {
  
    var xmlhttp = (window.XMLHttpRequest ? new XMLHttpRequest : (window.ActiveXObject ? new ActiveXObject("Microsoft.XMLHTTP") : false));
    if (!xmlhttp) {
        return false;
    }
    xmlhttp.open(method, url);
    xmlhttp.onreadystatechange = function() {
        obsluha(xmlhttp);
    };
    if (headers) {
        for (var key in headers) {
            xmlhttp.setRequestHeader(key, headers[key]);
        }
    }
    xmlhttp.send(content);
    return true;
}

function ZapocitejKlik(kampan,umisteni) {
    // odeslani pozadavku na aktualizaci dat
    if (!send_xmlhttprequest(ZapocitejObsluha, 'GET', 'odkazy-kliknuti.php?kampan=' + kampan + '&umisteni=' + umisteni)) {
        return false;
    }
    return true;
}

function ZapocitejObsluha(xmlhttp) {
    return true;
}

var barva_vyrazna = '#fabc00';
  var barva_normalni = '#0581c7';
  
function zkontroluj_input(elem) {

  if (document.getElementById(elem).value=='') {
    document.getElementById(elem).style.borderColor = barva_vyrazna;
    return 1;
  } else {
    document.getElementById(elem).style.borderColor = barva_normalni;
    return 0;
  }
  
}



function kontrola_dotaznik() {
 
  var vysledek = 0;
  vysledek += zkontroluj_input('dotaznik_skola');
  vysledek += zkontroluj_input('dotaznik_trida');
  vysledek += zkontroluj_input('dotaznik_jmeno');
  vysledek += zkontroluj_input('dotaznik_prijmeni');
  vysledek += zkontroluj_input('dotaznik_adresa');
  vysledek += zkontroluj_input('dotaznik_datum');
  vysledek += zkontroluj_input('dotaznik_telefon');
  vysledek += zkontroluj_input('dotaznik_email');
  vysledek += zkontroluj_input('dotaznik_zdravotni_omezeni');
  vysledek += zkontroluj_input('dotaznik_stravovaci_omezeni');
   //vysledek += zkontroluj_input('dotaznik_poznamka');
  
  // pokud chybi nejaky udaj
  if (vysledek>0) {
    document.getElementById('oznameni-1').style.display = 'block';
  } else {
    document.getElementById('oznameni-1').style.display = 'none';
  }
  
  
  //pokud email neni ve tvaru emailu
  if ((document.getElementById('dotaznik_email').value.search(/^([^(@#$*()!\?)]+)@([^(@#$*()!\?)]+)[.][a-zA-Z]{2,4}$/) != 0) && (document.getElementById('dotaznik_email').value!='')) {
    document.getElementById('oznameni-2').style.display = 'block';
    document.getElementById('dotaznik_email').style.borderColor = barva_vyrazna;
    vysledek += 1;
  } else {
    document.getElementById('oznameni-2').style.display = 'none';
    }
  
  
  // kontrola, zda je telefon v odpovidajicim tvaru
  if ((document.getElementById('dotaznik_telefon').value.search(/\x2B{0,1}\d{9,14}$/) != 0) && (document.getElementById('dotaznik_telefon').value!='')) {
    document.getElementById('oznameni-4').style.display = 'block';
    document.getElementById('dotaznik_telefon').style.borderColor = barva_vyrazna;
    vysledek += 1;
  } else {
    document.getElementById('oznameni-4').style.display = 'none';
    }
      
  // kontrola, zda je datum ve spravnem tvaru
  if ((document.getElementById('dotaznik_datum').value.search(/\d{4}.\d{1,2}.\d{1,2}$/) != 0) && (document.getElementById('dotaznik_datum').value!='')) {
    document.getElementById('oznameni-3').style.display = 'block';
    document.getElementById('dotaznik_datum').style.borderColor = barva_vyrazna;
    vysledek += 1;
  } else {
    document.getElementById('oznameni-3').style.display = 'none';
    }
      
  
  if (vysledek>0) {
    return false;
  } else {
    //document.getElementById('reg_heslo').value = str_md5(document.getElementById('reg_heslo2').value);
    return true;
  }
    
}

function zkontroluj_radio(elem,error_elem,voleb,otazka) {
  var vysledek = 0;
  
  if (otazka==1) {
    for (var i = 0;i<voleb;i++) {
      if (document.soutez.soutez_otazka_1[i].checked==true) {
        vysledek = vysledek + 1;
      }
    }
  } else if (otazka==2) {
    for (var i = 0;i<voleb;i++) {
      if (document.soutez.soutez_otazka_2[i].checked==true) {
        vysledek = vysledek + 1;
      }
    }
  } else if (otazka==3) {
    for (var i = 0;i<voleb;i++) {
      if (document.soutez.soutez_otazka_3[i].checked==true) {
        vysledek = vysledek + 1;
      }
    }
  }
  
  if (vysledek==0) {
    document.getElementById(error_elem).style.color = barva_vyrazna;
    return 1;
  } else {
    document.getElementById(error_elem).style.color = barva_normalni;
    return 0;
  }

  
}

function kontrola_soutez() {
  var vysledek = 0;
  vysledek += zkontroluj_input('soutez_jmeno');
  vysledek += zkontroluj_input('soutez_prijmeni');
  vysledek += zkontroluj_input('soutez_adresa');
  vysledek += zkontroluj_input('soutez_skola');
  vysledek += zkontroluj_input('soutez_email');
  vysledek += zkontroluj_input('soutez_nazev');
  //vysledek += zkontroluj_input('soutez_fotografie');
  vysledek += zkontroluj_radio(document.soutez.soutez_otazka_1,'otazka_volby_1',2,1);
  vysledek += zkontroluj_radio(document.soutez.soutez_otazka_2,'otazka_volby_2',3,2);
  vysledek += zkontroluj_radio(document.soutez.soutez_otazka_3,'otazka_volby_3',3,3);
  
  // pokud chybi nejaky udaj
  if (vysledek>0) {
    document.getElementById('oznameni-1').style.display = 'block';
  } else {
    document.getElementById('oznameni-1').style.display = 'none';
  }
  
  
  
  //pokud email neni ve tvaru emailu
  if ((document.getElementById('soutez_email').value.search(/^([^(@#$*()!\?)]+)@([^(@#$*()!\?)]+)[.][a-zA-Z]{2,4}$/) != 0) && (document.getElementById('soutez_email').value!='')) {
    document.getElementById('oznameni-2').style.display = 'block';
    document.getElementById('soutez_email').style.borderColor = barva_vyrazna;
    vysledek += 1;
  } else {
    document.getElementById('oznameni-2').style.display = 'none';
    }
      //alert(document.getElementById('soutez_fotografie').value);
  //pokud obrazek neni JPG
  if (
    (
      (document.getElementById('soutez_fotografie').value.indexOf('.jpg') != -1) ||
      (document.getElementById('soutez_fotografie').value.indexOf('.JPG') != -1) || 
      (document.getElementById('soutez_fotografie').value.indexOf('.jpeg') != -1) ||
      (document.getElementById('soutez_fotografie').value.indexOf('.JPEG') != -1)
    )
     && (document.getElementById('soutez_fotografie').value!='')) {
    document.getElementById('oznameni-4').style.display = 'none';
  } else {
    
    document.getElementById('oznameni-4').style.display = 'block';
    document.getElementById('soutez_fotografie').style.borderColor = barva_vyrazna;
    vysledek += 1;
    }      
  
  if (vysledek>0) {
    return false;
  } else {
    //document.getElementById('reg_heslo').value = str_md5(document.getElementById('reg_heslo2').value);
    return true;
  }
    
}
