var xmlHttp = createXmlHttpRequestObject();
var chyba = 'Nastala chyba.';
function createXmlHttpRequestObject(){	
	var xmlHttp;
	if ( window.ActiveXObject ){
	    xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
	}
	else {
		xmlHttp = new XMLHttpRequest();
  }
  if ( !xmlHttp )
	  alert("Chyba při vytváření objektu.");
	else 
    return xmlHttp;
}
function preloader() {
 //heavyImage = new Image(); 
 //heavyImage.src = "images/submit_big_over.png";
}

function typeOfNavigation(id) {
    if (xmlHttp.readyState == 4 || xmlHttp.readyState == 0) {
      if (id == "1") {
        document.getElementById('typeOfNavigation0').className = "nav_nosel";
        document.getElementById('typeOfNavigation2').className = "nav_nosel";
        document.getElementById('typeOfNavigation1').className = "nav_sel";
      }
      else if (id == "2") {
        document.getElementById('typeOfNavigation1').className = "nav_nosel";
        document.getElementById('typeOfNavigation0').className = "nav_nosel";
        document.getElementById('typeOfNavigation2').className = "nav_sel";
      }
      else {
        document.getElementById('typeOfNavigation0').className = "nav_sel";
        document.getElementById('typeOfNavigation1').className = "nav_nosel";
        document.getElementById('typeOfNavigation2').className = "nav_nosel";
      }
    	xmlHttp.open("GET", "http://"+location.hostname+"/ajax/navigation.php?id="+id, true);  
    	xmlHttp.onreadystatechange = function () {stateNavigation(id); } ;  	
    	xmlHttp.send(null);
	}
	else{ 
		setTimeout(function(){typeOfNavigation(id)},1000);
	}
}

function stateNavigation(id) {
	if (xmlHttp.readyState == 4){
	    if (xmlHttp.status == 200){
        document.getElementById("navigation").innerHTML=xmlHttp.responseText;
    	}
    	else{
   			alert(chyba);
		}
	}
}



function phraseSearch() {
  if (document.getElementById('phrase').value != "") {
    if (document.getElementById('phrase').value == "Hledané zboží") {
      document.getElementById('phrase').value = "";
    }
  }
  else {
    document.getElementById('phrase').value = "";
  }
}
function NewsEmail() {
  if (document.getElementById('email_news').value != "") {
    if (document.getElementById('email_news').value == "E-mailová adresa") {
      document.getElementById('email_news').value = "";
    }
  }
  else {
    document.getElementById('email_news').value = "";
  }
}

function showBlock(id) {
  if (document.getElementById(id).className == "hidden") {
    document.getElementById(id).className="";
    document.getElementById("firma").checked=true;
    return false
  }
  if (document.getElementById(id).className != "hidden") {
    document.getElementById("firma").checked=false;
    document.getElementById(id).className="hidden";
    return false
  }
}
function showBlockDiv(id) {
  if (document.getElementById(id).className == "hidden") {
    document.getElementById(id).className="";
    return false
  }
  if (document.getElementById(id).className != "hidden") {
    document.getElementById(id).className="hidden";
    return false
  }
}

function checkInput(id) {
  if (document.getElementById(id).checked === true) {
    document.getElementById(id).checked=false;
  }
  else if (document.getElementById(id).checked === false) {
    document.getElementById(id).checked=true;
  }
}
/*
 * Zkontroluje platny format emailove adresy
 */
function validEmail(email)
{
  invalidChars = " /:,;"

  if(email == "")
  {
    return false
  }
  for(i=0; i < invalidChars.length; i++)
  {
    badChar = invalidChars.charAt(i)
    if (email.indexOf(badChar,0) > -1)
    {
      return false
    }
  }
  atPos = email.indexOf("@",1)
  if(atPos == -1)
  {
    return false
  }
  if(email.indexOf("@",atPos+1) > -1)
  {
    return false
  }
  periodPos = email.indexOf(".",atPos)
  if(periodPos == -1)
  {
    return false
  }
  if(periodPos+3 > email.length)
  {
    return false
  }
  return true
}
function validPhone(phonenumber) {
  vyraz = /^[+]?[()/0-9. -]{9,}$/
  if (vyraz.test(phonenumber)==true)
    return true;
  else 
    return false;
}

