// JavaScript Document


function setStartHP(){
   
   setMainMenu();
   setVyhledavaniHP();
   //picChange();
}

function setStart(){
   
   setMainMenu();
}

function openppClaim(elem){
  var wClaim = window.open(elem.href, 'tClaim', 'width=682,height=590');
  wClaim.focus();
  return false;
}

function changeCSSclass (el,cssclass){
	el.className = cssclass;
}

function setMainMenu(){
  if (!document.getElementsByTagName){ return; }
	
	var imgs = document.getElementsByTagName("img");
  
	for (var i=0; i<imgs.length; i++){
		var imgEl = imgs[i];
		
		if (imgEl.getAttribute("src").indexOf('menu-out')!=-1){
			 cislo = imgEl.src.slice(-6,-4);
			 //imgEl.setAttribute('onmouseover',"this.src='images/web/hp/"+imgsrc+"/menu-on-"+cislo+".jpg'");
		   //imgEl.setAttribute('onmouseout',"this.src='images/web/hp/"+imgsrc+"/menu-out-"+cislo+".jpg'");
		   //alert('images/web/hp/"+imgsrc+"/menu-on-"+cislo+".jpg')
			 imgEl.onmouseover =  new Function('this.src="images/web/'+imgsrc+'/menu-on-'+cislo+'.jpg";');
		   imgEl.onmouseout =  new Function('this.src="images/web/'+imgsrc+'/menu-out-'+cislo+'.jpg";');
		}
	}
	
}


var arrFlagy = new Array();

function setVyhledavaniHP(){
  if (!document.getElementsByTagName){ return; }
	
	var divs = document.getElementsByTagName("div");
  
  j=0;
	for (var i=0; i<divs.length; i++){
		var divEl = divs[i];
		
		
		if (divEl.getAttribute("className") =="flag" || divEl.getAttribute("className") =="flag_on" || divEl.getAttribute("class") =="flag" || divEl.getAttribute("class") =="flag_on"){
			 
			 divEl.onclick =  new Function("changeFastSearchForm('" + divEl.getAttribute("id") + "');");
		   if(j>0) {
			   document.getElementById(divEl.getAttribute("id")+"-box").style.display = "none";
			   
			 }else{
			   divEl.className = "flag_on";
			 }
			 arrFlagy[j] = divEl.getAttribute("id");  
		   j++
		}
	}
	
}


function changeFastSearchForm(box){
     for (var i=0; i<arrFlagy .length; i++){
		   document.getElementById(arrFlagy[i]+"-box").style.display = "none";
		   document.getElementById(arrFlagy[i]).className = "flag";
		 }
		 
		 document.getElementById(box).className = "flag_on";
		 document.getElementById(box+"-box").style.display = "block";
		 
		 document.getElementById("hledejPodle").value = box;
		  
}

function rate(id) {
    okno_fotka = window.open(base+"hodnoceni.php?id="+id,"hodnoceni","top=100,left=200,width=300,height=460,menubar=no,directories=no,toolbar=no,location=no,status=no,scrollbars=no,resizable=no");
    okno_fotka.focus();
}

function addPhotoComment(id) {
    okno_fotka = window.open(base+"userphotocomment.php?id="+id,"FotoKomentar","top=100,left=200,width=480,height=550,menubar=no,directories=no,toolbar=no,location=no,status=no,scrollbars=no,resizable=no");
    okno_fotka.focus();
}

function checkFormLogin(f){

   if(f.log_name.value.length==0){
       alert((lang=='en')?'You have to fill your username.':'Musíte vyplnit Vaše uživatelské jméno.');
       f.log_name.focus();
       return false;       
   }
   if(f.log_psw.value.length==0){
       alert((lang=='en')?'You have to fill your password':'Musíte vyplnit Vaše heslo.');
       f.log_psw.focus();
       return false;       
   }
   
   return true;
}

function checkFormReg(f){
   var mail      = "^[_a-zA-Z0-9\.\-]+@[_a-zA-Z0-9\.\-]+[\.]{1}[a-zA-Z]{2,4}$";
   var reg_mobil1 = "^[0-9]{9}$";
   var reg_mobil2 = "^[0-9]{13}$";
   
   
   if(f.jmeno.value.length==0){
       alert((lang=='en')?'You have to fill your name':'Vaše jméno je povinná položka.');
       f.jmeno.focus();
       return false;       
   }
   if(f.prijmeni.value.length==0){
       alert((lang=='en')?'You have to fill your surname':'Vaše přijmení je povinná položka.');
       f.prijmeni.focus();
       return false;       
   }
   if(f.misto.value.length==0){
       alert((lang=='en')?'You have to fill city':'Město je povinná položka.');
       f.misto.focus();
       return false;       
   } 
   if(f.email.value.length==0){
       alert((lang=='en')?'You have to fill your e-mail':'E-mail je povinná položka.');
       f.email.focus();
       return false;       
   }
   if (!f.email.value.match(mail)) {
		   alert ((lang=='en')?'Bad format of e-mail':'Špatný formát e-mailové adresy.');
		   f.email.focus();
		   return false;
	 }
	 
	 if ((f.mobil.value.length>0) && (!f.mobil.value.match(reg_mobil1)) && (!f.mobil.value.match(reg_mobil2))) {
		   alert ((lang=='en')?'Bad format of mobil phone number (use number format without + ).':'Špatný formát čísla mobilního telefonu (použijte 00 místo + , pokud uvádíte číslo v mezinár. tvaru).');
		   f.mobil.focus();
		   return false;
	 }
	 
	 if(f.login.value.length==0){
       alert((lang=='en')?'You have to fill your username':'Uživatelské jméno je povinná položka.');
       f.login.focus();
       return false;       
   }
   
   if(f.heslo.value.length<4){
       alert((lang=='en')?'Password must have 4 chars at least':'Heslo musí mít alespoň 4 znaky.');
       f.heslo.focus();
       return false;       
   }
   
   if(f.heslo2.value.length<4){
       alert((lang=='en')?'You have to fill password check':'Musíte vyplnit heslo pro kontrolu.');
       f.heslo2.focus();
       return false;       
   }
   
   if(f.heslo2.value!=f.heslo.value){
       alert((lang=='en')?'You filled different passwords':'Napsal(a) jste rozdílná hesla.');
       f.heslo.focus();
       return false;       
   }
   
   
   return true;
}


function checkFormOrder(f){
   var mail = "^[_a-zA-Z0-9\.\-]+@[_a-zA-Z0-9\.\-]+[\.]{1}[a-zA-Z]{2,4}$";
   var reg_pocet = "^[123456789]{1}[0-9]{1,}$";
   if(f.pocet.value.length==0){
       alert((lang=='en')?'Please fill number of pieces':'Vyplňte prosím pořet kusů.');
       f.pocet.focus();
       return false;       
   }
  
   if(!f.pocet.value.match(reg_pocet)){
       alert((lang=='en')?'Payment is cash on delivery: minimum 10 copies':'dobírkou zasíláme minimálně 10ks.');
       f.pocet.focus();
       return false;       
   }
   
   if(f.jmeno.value.length==0){
       alert((lang=='en')?'You have to fill your name and surname':'Vaše jméno a přijmení je povinná položka.');
       f.jmeno.focus();
       return false;       
   }
   if(f.adresa.value.length==0){
       alert((lang=='en')?'You have to fill address':'Vyplňte prosím adresu.');
       f.adresa.focus();
       return false;       
   } 
   if(f.adresa2.value.length==0){
       alert((lang=='en')?'You have to fill Zip/Postal code and city':'Vyplňte prosím PSČ a místo.');
       f.adresa2.focus();
       return false;       
   }
   if (!f.email.value.match(mail)) {
		   alert ((lang=='en')?'Bad format of e-mail address':'Špatný formát e-mailové adresy.');
		   f.email.focus();
		   return false;
	 }
   
   if(f.heslo.value.length<4){
       alert((lang=='en')?'Password must have 4 chars at least':'Heslo musí mít alespoň 4 znaky.');
       f.heslo.focus();
       return false;       
   }
   
   if(f.heslo2.value.length<4){
       alert((lang=='en')?'You have to fill password check':'Musíte vyplnit heslo pro kontrolu.');
       f.heslo2.focus();
       return false;       
   }
   
   if(f.heslo2.value!=f.heslo.value){
       alert((lang=='en')?'You filled different passwords':'Napsal(a) jste rozdílná hesla.');
       f.heslo.focus();
       return false;       
   }
   
   
   return true;
}

function checkFormSendPsw(f){
    
   var mail = "^[_a-zA-Z0-9\.\-]+@[_a-zA-Z0-9\.\-]+[\.]{1}[a-zA-Z]{2,4}$";
   if (f.reg_mail.value!='' && !f.reg_mail.value.match(mail)) {
		   alert ((lang=='en')?'You have to fill password check':'Špatný formát e-mailové adresy.');
		   f.reg_mail.focus();
		   return false;
	 }
	 
	 if (f.reg_mail.value=='' && f.reg_name.value=='') {
		   alert ((lang=='en')?'You have to fill password check':'Alespoň jednu položku musíte vyplňit.');
		   f.reg_mail.focus();
		   return false;
	 }
   
   
   return true;
}

function changeLoc($loc){
  if($loc=="tocountry"){
    document.getElementById('LocPrag').style.display='none';
    document.getElementById('LocCountry').style.display='block';
  }
  if($loc=="toprag"){
    document.getElementById('LocPrag').style.display='block';
    document.getElementById('LocCountry').style.display='none';
  }
}

function zobraz_foto(query_string,sirka,vyska) {
    okno_fotka = window.open(base+"fotogalery_d.php?" + query_string + "&part=foto","okno_fotografie","width=" + sirka + ",height=" + vyska + ",menubar=no,directories=no,toolbar=no,location=no,status=no,scrollbars=no,resizable=no");
    okno_fotka.focus();
}

function checkFormSearchRec(f){
   if(f.searchRec.value.length<3){
       alert((lang=='en')?'Minimum length of string are 3 chars':'Hledaný text musí mít alespoň 3 znaky.');
       f.searchRec.focus();
       return false;       
   }
   return true;
}


function checkFormUserComment(f){
   if((f.komentar.value.length<4) || (f.komentar.value.length>1000)){ 
     alert((lang=='en')?'Comment is out of range (from 4 to 1000 chars)':'Komentář mimo povolený rozsah (4 až 1000 znaků)');
     return false;
   }
   return true;
}

var temp = '';
function checkComment(el){
  if(el.value.length>1000){
    el.value = temp;
    alert((lang=='en')?'Max length of comment is 1000 chars':'Maximalní délka komentáře je 1000 znaků');
  }else{
    temp = el.value;
  } 
}

function checkFormAddSMSvote(f){
   var reg_mobil = "^[0-9]{9}$";
	 if(!f.mobil.value.match(reg_mobil)){
	   alert('Telefon musí být ve formátu "777123456"');
     return false;
   }
   return true;
}


/*Prevzato z Eklasa.cz*/
function open_klip(src){
 
  var sirkaOkna;
  var vyskaOkna;
                
    with(screen) {
     sirkaOkna=availWidth;    
     vyskaOkna=availHeight;     
   }
                              
         sirkaOkna -= 400;
         sirkaOkna -= 25; //scrollbar
         sirkaOkna /= 2;
         
         vyskaOkna -= 400;
         vyskaOkna /= 2;
 
 window.open(base+"video.php?klip="+src,'',"width=400,height=400,left="+sirkaOkna+",top="+vyskaOkna+",menubar=no,directories=no,toolbar=no,location=no,status=no,scrollbars=no,resizable=no");
 
}

/**
 * Oznaceni a odznaceni checkboxu v podrobnem vyhledanvi
 */
 var stav_kuchyne           = false;
 var stav_lokalita_praha    = false;
 var stav_lokalita_kraje    = false;
 var stav_benefity = false;
  
 function selectAll(skupina, pocet_ve_skupine){
   
   if(skupina == 'kuchyne'){
	    if (stav_kuchyne) 
			   stav_kuchyne = false;
	    else
	       stav_kuchyne = true;
	       
	    stav = stav_kuchyne; 
	 }
	 
	 if(skupina == 'lokalita_praha'){
	    if (stav_lokalita_praha) 
			   stav_lokalita_praha = false;
	    else
			   stav_lokalita_praha = true;
			   
			stav = stav_lokalita_praha; 
	 }
	 
	 if(skupina == 'lokalita_kraje'){
	    if (stav_lokalita_kraje) 
			   stav_lokalita_kraje = false;
	    else
	       stav_lokalita_kraje = true;
	    
			stav = stav_lokalita_kraje; 
	 }
	 
	 if(skupina == 'benefity'){
	    if (stav_benefity) 
			   stav_benefity = false;
	    else
	       stav_benefity = true;
	    
			stav = stav_benefity; 
	 }


	 for(i=1;i<=pocet_ve_skupine;i++){
	   document.getElementById(skupina+'_'+i).checked = (stav) ? 'checked' : '';
	 }  
	 
   
 
 } 



function rateProceed(){
	  
	  
	 	var prealoadBox = document.getElementById('PreloadBox');
		   
		if(xmlHttp.readyState == 1)
		{
			
			pageSize  = getPageSize();
			pageScroll = getPageScroll();
			prealoadBox.style.width = pageSize[0]+'px';
		  prealoadBox.style.height = pageSize[1]+'px';
		  prealoadBox.style.paddingTop = pageScroll[1] + (pageSize[3] / 10)+'px';
			prealoadBox.style.display='block';
			
  	}
		else if (xmlHttp.readyState == 4)
		{
		  
		  if(xmlHttp.status == 200){
			  try {
				  
				  //objBody.removeChild(prealoadBox);
					//prealoadBox = null;
				  
					var xmlResponse  = xmlHttp.responseXML;
					xmlRoot          = xmlResponse.documentElement;
					
					hodnoceni        = xmlRoot.getElementsByTagName("hodnoceni");
					hodnoceni				 = hodnoceni.item(0);
					 
					id_restaurace    = hodnoceni.getAttribute("id_restaurace");
					typ              = hodnoceni.getAttribute("typ");
					znamka           = hodnoceni.getAttribute("znamka");
					kompletni        = hodnoceni.getAttribute("kompletni");
					
					if(znamka == '2.5' || znamka == ''){
					    document.getElementById('polozka_'+id_restaurace+'_'+typ).style.border = '';
				  }else{
					    document.getElementById('polozka_'+id_restaurace+'_'+typ).style.border = '2px solid rgb(151,159,17)';
					}
					
					if(kompletni == 'ano'){
					   document.getElementById('polozka_'+id_restaurace).style.backgroundColor = '#f8efe8';
					}else{
					   document.getElementById('polozka_'+id_restaurace).style.backgroundColor = '';
					}
					
					prealoadBox.style.display='none';
				
				}
				catch (e) 
				{
				   alert('Nedorazila data:' + e.toString());
				}
			
			}else{
		     alert('Nedorazila data:' + xmlHttp.statusText);
		  }
	
	  }
 }
 
 function setVoteItem(id_restaurace, typ, znamka) {
    
 
    params = new Array();
    params[0] = 'id_restaurace='+id_restaurace;
    params[1] = 'typ='+typ;
    params[2] = 'znamka='+znamka;
    
		process( 'GET', 'ajax/set_hodnoceni.php', params, 'rateProceed');
 }
 
 
 //
// getPageSize()
// Returns array with page width, height and window width, height
// Core code from - quirksmode.com
// Edit for Firefox by pHaez
//
function getPageSize(){
	
	var xScroll, yScroll;
	
	if (window.innerHeight && window.scrollMaxY) {	
		xScroll = window.innerWidth + window.scrollMaxX;
		yScroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}
	
	var windowWidth, windowHeight;
	
//	console.log(self.innerWidth);
//	console.log(document.documentElement.clientWidth);

	if (self.innerHeight) {	// all except Explorer
		if(document.documentElement.clientWidth){
			windowWidth = document.documentElement.clientWidth; 
		} else {
			windowWidth = self.innerWidth;
		}
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) { // other Explorers
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}	
	
	// for small pages with total height less then height of the viewport
	if(yScroll < windowHeight){
		pageHeight = windowHeight;
	} else { 
		pageHeight = yScroll;
	}

//	console.log("xScroll " + xScroll)
//	console.log("windowWidth " + windowWidth)

	// for small pages with total width less then width of the viewport
	if(xScroll < windowWidth){	
		pageWidth = xScroll;		
	} else {
		pageWidth = windowWidth;
	}
//	console.log("pageWidth " + pageWidth)

	arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight) 
	return arrayPageSize;
}

//
// getPageScroll()
// Returns array with x,y page scroll values.
// Core code from - quirksmode.com
//
function getPageScroll(){

	var xScroll, yScroll;

	if (self.pageYOffset) {
		yScroll = self.pageYOffset;
		xScroll = self.pageXOffset;
	} else if (document.documentElement && document.documentElement.scrollTop){	 // Explorer 6 Strict
		yScroll = document.documentElement.scrollTop;
		xScroll = document.documentElement.scrollLeft;
	} else if (document.body) {// all other Explorers
		yScroll = document.body.scrollTop;
		xScroll = document.body.scrollLeft;	
	}

	arrayPageScroll = new Array(xScroll,yScroll) 
	return arrayPageScroll;
}	 	 

