var xmlHttp = createXmlHttpRequestObject();



function createXmlHttpRequestObject() 
{
  var xmlHttp;
  try
  {
    xmlHttp = new XMLHttpRequest();
  }
  catch(e)
  {
    var XmlHttpVersions = new Array("MSXML2.XMLHTTP.6.0",
                                    "MSXML2.XMLHTTP.5.0",
                                    "MSXML2.XMLHTTP.4.0",
                                    "MSXML2.XMLHTTP.3.0",
                                    "MSXML2.XMLHTTP",
                                    "Microsoft.XMLHTTP");
    for (var i=0; i<XmlHttpVersions.length && !xmlHttp; i++) 
    {
      try 
      { 
        xmlHttp = new ActiveXObject(XmlHttpVersions[i]);
      } 
      catch (e) {} // ignore potential error
    }
  }
  // return the created object or display an error message
  if (!xmlHttp)
    alert("Error creating the XMLHttpRequest object.");
  else 
    return xmlHttp;
}


function SpoctiCenu(cen) {
	cena=0;
	if(document.getElementById('luzko2').checked==true) {
		cena=cena+3590;
	}
	if(document.getElementById('luzko1').checked==true) {
		cena=cena+3890;
	}
	if(document.getElementById('olo').checked==true) {
		cena=cena+550;
	}
	if(document.getElementById('pha').checked==true) {
		cena=cena+720;
	}
	if(document.getElementById('vla').checked==true) {
		cena=cena+0;
	}
//	cena=cena-document.getElementById("formsleva").value;
		
//	cena=cena+cen;
	var cenacelk= document.getElementById("cenacelk");
cenacelk.innerHTML = cena;
document.getElementById("celkcena").value=cena;
}


function GivePovinn(dataSource,typ, POV)
{
	document.getElementById("overlay").style.display='';
	document.getElementById("overlay").style.position='absolute';
	document.getElementById("overlay").style.top='0';
	document.getElementById("overlay").style.left='0';
	document.getElementById("overlay").style.height='100%';
	document.getElementById("overlay").style.width='100%'; 
	winHeight = document.documentElement.clientHeight;
	vyska=winHeight/2;
	var obr= document.getElementById("overlay");
	obr.innerHTML = '<div style="padding-top:'+vyska+'px; text-align:center; color:white; font-weight:bold">Ověřuji<img 			src="images/loading.gif" /></div>';
xmlHttp = createXmlHttpRequestObject();
	xmlHttp.open("GET", dataSource);
	xmlHttp.onreadystatechange = function()
	{
		if (xmlHttp.readyState == 4 && xmlHttp.status == 200)
		{
			if(xmlHttp.responseText == "neni")
			{
				alert('Nesprávna hodnota');
				document.getElementById("form"+typ).value="";
				document.getElementById("form"+typ).focus();
					document.getElementById("form"+typ).style.backgroundColor="#F00";
					var obr= document.getElementById("over"+typ);
					obr.innerHTML = '';
				document.getElementById("overlay").style.display='none';
				if(pov=='P')
				{
					document.getElementById("form"+typ).style.backgroundColor="#F00";
					var obr= document.getElementById("over"+typ);
					obr.innerHTML = '';
				document.getElementById("overlay").style.display='none';
				}
			}
			else
			{
				document.getElementById("form"+typ).style.backgroundColor="white";
				var obr= document.getElementById("over"+typ);
			obr.innerHTML = '<img src="images/ok.png" alt="" />';
				document.getElementById("overlay").style.display='none';
			}
		}
	
	}
	xmlHttp.send(null);
}


function FormPovinn(udalost,typ,kolik,pov)
{
	udalost = (udalost) ? udalost: window.event;
	txt = (udalost.target) ? udalost.target : udalost.srcElement;
	
	if (udalost.type == "blur")
	{
				if (txt.value) {GivePovinn("validpovinn.php?co=" + txt.value +"&kolik=" + kolik,typ,pov);}
	}
}

function GivePsc(dataSource)
{
	document.getElementById("overlay").style.display='';
	document.getElementById("overlay").style.position='absolute';
	document.getElementById("overlay").style.top='0';
	document.getElementById("overlay").style.left='0';
	document.getElementById("overlay").style.height='100%';
	document.getElementById("overlay").style.width='100%'; 
	winHeight = document.documentElement.clientHeight;
	vyska=winHeight/2;
	var obr= document.getElementById("overlay");
	obr.innerHTML = '<div style="padding-top:'+vyska+'px; text-align:center; color:white; font-weight:bold">Ověřuji<img 			src="images/loading.gif" /></div>';
xmlHttp = createXmlHttpRequestObject();
	xmlHttp.open("GET", dataSource);
	xmlHttp.onreadystatechange = function()
	{
		if (xmlHttp.readyState == 4 && xmlHttp.status == 200)
		{
			if(xmlHttp.responseText == "neni")
			{
				alert('Nesprávna hodnota');
				document.getElementById("formpsc").value="";
				document.getElementById("formpsc").focus();	
				document.getElementById("formpsc").style.backgroundColor="#F00";
					var obr= document.getElementById("over"+typ);
					obr.innerHTML = '';
				document.getElementById("overlay").style.display='none';
			}
			else
			{
				document.getElementById("formpsc").style.backgroundColor="white";
				var obr= document.getElementById("over"+typ);
			obr.innerHTML = '<img src="images/ok.png" alt="" />';
				document.getElementById("overlay").style.display='none';
			}
		}
	
	}
	xmlHttp.send(null);
}


function ControlPostcode(udalost)
{
	udalost = (udalost) ? udalost: window.event;
	txt = (udalost.target) ? udalost.target : udalost.srcElement;
	
	if (udalost.type == "blur")
	{
				if (txt.value) {GivePsc("validpsc.php?co=" + txt.value);}
	}
}

function GivePhone(dataSource,typ,pov)
{
xmlHttp = createXmlHttpRequestObject();
	xmlHttp.open("GET", dataSource);
	xmlHttp.onreadystatechange = function()
	{
		if (xmlHttp.readyState == 4 && xmlHttp.status == 200)
		{
			if(xmlHttp.responseText == "neni")
			{
				alert('Nesprávna hodnota');
				document.getElementById("form"+typ).value="";
				document.getElementById("form"+typ).focus();
				if(pov=='P')
				{
					document.getElementById("form"+typ).style.backgroundColor="#F00";
				}
			}
			else
			{
				document.getElementById("form"+typ).style.backgroundColor="white";
			}

		}
	
	}
	xmlHttp.send(null);
}


function ControlPhone(udalost,typ, pov)
{
udalost = (udalost) ? udalost: window.event;
	txt = (udalost.target) ? udalost.target : udalost.srcElement;
	if (udalost.type == "blur")
	{
				if (txt.value) {GivePhone("validphone.php?co=" + txt.value,typ, pov);}
	}
}

function GivePovinnC(dataSource,typ, POV)
{
	document.getElementById("overlay").style.display='';
	document.getElementById("overlay").style.position='absolute';
	document.getElementById("overlay").style.top='0';
	document.getElementById("overlay").style.left='0';
	document.getElementById("overlay").style.height='100%';
	document.getElementById("overlay").style.width='100%'; 
	winHeight = document.documentElement.clientHeight;
	vyska=winHeight/2;
	var obr= document.getElementById("overlay");
	obr.innerHTML = '<div style="padding-top:'+vyska+'px; text-align:center; color:white; font-weight:bold">Ověřuji<img 			src="images/loading.gif" /></div>';
xmlHttp = createXmlHttpRequestObject();
	xmlHttp.open("GET", dataSource);
	xmlHttp.onreadystatechange = function()
	{
		if (xmlHttp.readyState == 4 && xmlHttp.status == 200)
		{
			if(xmlHttp.responseText == "neni")
			{
				alert('Nesprávna hodnota');
				document.getElementById("form"+typ).value="";
				document.getElementById("form"+typ).focus();
					var obr= document.getElementById("over"+typ);
					obr.innerHTML = '';
				document.getElementById("overlay").style.display='none';
				if(pov=='P')
				{
					document.getElementById("form"+typ).style.backgroundColor="#F00";
					var obr= document.getElementById("over"+typ);
					obr.innerHTML = '';
				document.getElementById("overlay").style.display='none';
				}
			}
			else
			{
				document.getElementById("form"+typ).style.backgroundColor="white";
				var obr= document.getElementById("over"+typ);
			obr.innerHTML = '<img src="images/ok.png" alt="" />';
				document.getElementById("overlay").style.display='none';
			}
		}
	
	}
	xmlHttp.send(null);
}


function FormPovinnC(udalost,typ,kolik,pov)
{
	udalost = (udalost) ? udalost: window.event;
	txt = (udalost.target) ? udalost.target : udalost.srcElement;
	
	if (udalost.type == "blur")
	{
				if (txt.value) {GivePovinnC("validpovinnc.php?co=" + txt.value +"&kolik=" + kolik,typ,pov);}
	}
}

function GiveEmail(dataSource,typ,pov)
{
	document.getElementById("overlay").style.display='';
	document.getElementById("overlay").style.position='absolute';
	document.getElementById("overlay").style.top='0';
	document.getElementById("overlay").style.left='0';
	document.getElementById("overlay").style.height='100%';
	document.getElementById("overlay").style.width='100%'; 
	winHeight = document.documentElement.clientHeight;
	vyska=winHeight/2;
	var obr= document.getElementById("overlay");
	obr.innerHTML = '<div style="padding-top:'+vyska+'px; text-align:center; color:white; font-weight:bold">Ověřuji<img src="images/loading.gif" /></div>';
xmlHttp = createXmlHttpRequestObject();
	xmlHttp.open("GET", dataSource);
	xmlHttp.onreadystatechange = function()
	{
		if (xmlHttp.readyState == 4 && xmlHttp.status == 200)
		{
			if(xmlHttp.responseText == "full")
			{
				alert('Emailová adresa je již zaregistrována');
				document.getElementById("form"+typ).value="";
				document.getElementById("form"+typ).focus();
				document.getElementById("form"+typ).style.backgroundColor="#F00";
				document.getElementById("overlay").style.display='none';
					var obr= document.getElementById("over"+typ);
					obr.innerHTML = '';
			}
			else
			{
				if(xmlHttp.responseText == "false")
				{
					alert('Nesprávna hodnota');
					document.getElementById("form"+typ).value="";
					document.getElementById("form"+typ).focus();	
					document.getElementById("form"+typ).style.backgroundColor="#F00";
					document.getElementById("overlay").style.display='none';
					var obr= document.getElementById("over"+typ);
					obr.innerHTML = '';
				}
				else
				{
					document.getElementById("form"+typ).style.backgroundColor="white";
					document.getElementById("overlay").style.display='none';
				var obr= document.getElementById("over"+typ);
			obr.innerHTML = '<img src="images/ok.png" alt="" />';
				}
			}
		}
	
	}
	xmlHttp.send(null);
}


function ControlEmail(udalost,typ, pov, cont)
{
	udalost = (udalost) ? udalost: window.event;
	txt = (udalost.target) ? udalost.target : udalost.srcElement;
	if (udalost.type == "blur")
	{
				if (txt.value) {GiveEmail("validemail.php?co=" + txt.value + "&cont=" + cont,typ, pov);}
	}
}


function GiveEmail1(dataSource,typ,pov)
{
	document.getElementById("overlay").style.display='';
	document.getElementById("overlay").style.position='absolute';
	document.getElementById("overlay").style.top='0';
	document.getElementById("overlay").style.left='0';
	document.getElementById("overlay").style.height='100%';
	document.getElementById("overlay").style.width='100%'; 
	winHeight = document.documentElement.clientHeight;
	vyska=winHeight/2;
	var obr= document.getElementById("overlay");
	obr.innerHTML = '<div style="padding-top:'+vyska+'px; text-align:center; color:white; font-weight:bold">Ověřuji<img src="images/loading.gif" /></div>';
xmlHttp = createXmlHttpRequestObject();
	xmlHttp.open("GET", dataSource);
	xmlHttp.onreadystatechange = function()
	{
		if (xmlHttp.readyState == 4 && xmlHttp.status == 200)
		{
			if(xmlHttp.responseText.substr(0,4) == "full")
			{
//				alert('Emailová adresa je již zaregistrována');
//				document.getElementById("form"+typ).value="";
				var myString = new String(xmlHttp.responseText);
				var myArray = myString.split(';'); 
				document.getElementById("formjmeno").value=myArray[1];
				document.getElementById("formulice").value=myArray[2];
				document.getElementById("formpsc").value=myArray[3];
				document.getElementById("formmesto").value=myArray[4];
				document.getElementById("formtelefon").value=myArray[5];
				document.getElementById("formsleva").value=myArray[6];
				document.getElementById("captcha_code").focus();
				document.getElementById("formjmeno").style.backgroundColor="white";
				document.getElementById("formulice").style.backgroundColor="white";
				document.getElementById("formpsc").style.backgroundColor="white";
				document.getElementById("formmesto").style.backgroundColor="white";
				document.getElementById("formtelefon").style.backgroundColor="white";
				document.getElementById("form"+typ).style.backgroundColor="white";
				document.getElementById("overlay").style.display='none';
				document.getElementById("over"+typ).innerHTML = '<img src="images/ok.png" alt="" />';
				document.getElementById("overjmeno").innerHTML = '<img src="images/ok.png" alt="" />';
				document.getElementById("overulice").innerHTML = '<img src="images/ok.png" alt="" />';
				document.getElementById("overpsc").innerHTML = '<img src="images/ok.png" alt="" />';
				document.getElementById("overmesto").innerHTML = '<img src="images/ok.png" alt="" />';
				document.getElementById("overtelefon").innerHTML = '<img src="images/ok.png" alt="" />';
				document.getElementById("sleva").innerHTML = 'Sleva: '+myArray[6]+' Kč';
			}
			else
			{
				if(xmlHttp.responseText == "false")
				{
					alert('Nesprávna hodnota');
					document.getElementById("form"+typ).value="";
					document.getElementById("form"+typ).focus();	
					document.getElementById("form"+typ).style.backgroundColor="#F00";
					document.getElementById("overlay").style.display='none';
					var obr= document.getElementById("over"+typ);
					obr.innerHTML = '';
				}
				else
				{
					document.getElementById("form"+typ).style.backgroundColor="white";
					document.getElementById("overlay").style.display='none';
				var obr= document.getElementById("over"+typ);
			obr.innerHTML = '<img src="images/ok.png" alt="" />';
				}
			}
		}
	
	}
	xmlHttp.send(null);
}


function ControlEmail1(udalost,typ, pov, cont)
{
	udalost = (udalost) ? udalost: window.event;
	txt = (udalost.target) ? udalost.target : udalost.srcElement;
	if (udalost.type == "blur")
	{
				if (txt.value) {GiveEmail1("validemail1.php?co=" + txt.value + "&cont=" + cont,typ, pov);}
	}
}

function ObjDarek() {
	if(document.getElementById('formdarek').checked==true) {
		document.getElementById('darektable').style.display='';
	}
	else 
{
		document.getElementById('darektable').style.display='none';
}
}
