var xmlHttp = createXmlHttpRequestObject();


function createXmlHttpRequestObject() 
{
  // will store the reference to the XMLHttpRequest object
  var xmlHttp;
  // this should work for all browsers except IE6 and older
  try
  {
    // try to create XMLHttpRequest object
    xmlHttp = new XMLHttpRequest();
  }
  catch(e)
  {
    // assume IE6 or older
    var XmlHttpVersions = new Array("MSXML2.XMLHTTP.6.0",
                                    "MSXML2.XMLHTTP.5.0",
                                    "MSXML2.XMLHTTP.4.0",
                                    "MSXML2.XMLHTTP.3.0",
                                    "MSXML2.XMLHTTP",
                                    "Microsoft.XMLHTTP");
    // try every prog id until one works
    for (var i=0; i<XmlHttpVersions.length && !xmlHttp; i++) 
    {
      try 
      { 
        // try to create XMLHttpRequest object
        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 Vpred(kolik)	
{
var url="ajax-vpred.php" +"?kolik="+kolik;
xmlHttp.onreadystatechange=vypispStateChange;
xmlHttp.open("GET",url,true);
xmlHttp.send(null);
}
function Zpet(kolik)	
{
var url="ajax-zpet.php" +"?kolik="+kolik;
xmlHttp.onreadystatechange=vypispStateChange;
xmlHttp.open("GET",url,true);
xmlHttp.send(null);
}
function vypispStateChange()
{
	if(xmlHttp.readyState == 4 && xmlHttp.status == 200)
	{
		var nText = document.getElementById("referencemain");
		nText.innerHTML = xmlHttp.responseText;
	}
}


function PrevR(kolik)	
{
var url="ajax-prevr.php" +"?kolik="+kolik;
xmlHttp.onreadystatechange=vypispStateChange1;
xmlHttp.open("GET",url,true);
xmlHttp.send(null);
}
function vypispStateChange1()
{
	if(xmlHttp.readyState == 4 && xmlHttp.status == 200)
	{
		var nText = document.getElementById("reference-id");
		nText.innerHTML = xmlHttp.responseText;
	}
}


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="#96001d";
				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="#96001d";
				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="#96001d";
			}

		}
	
	}
	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();
					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="#96001d";
				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="#96001d";
					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="#96001d";
				document.getElementById("formulice").style.backgroundColor="#96001d";
				document.getElementById("formpsc").style.backgroundColor="#96001d";
				document.getElementById("formmesto").style.backgroundColor="#96001d";
				document.getElementById("formtelefon").style.backgroundColor="#96001d";
				document.getElementById("form"+typ).style.backgroundColor="#96001d";
				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="#96001d";
					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 GiveLink(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="#96001d";
				var obr= document.getElementById("over"+typ);
			obr.innerHTML = '<img src="images/ok.png" alt="" />';
				document.getElementById("overlay").style.display='none';
			}
		}
	
	}
	xmlHttp.send(null);
}


function FormLink(udalost,typ,kolik,pov)
{
	udalost = (udalost) ? udalost: window.event;
	txt = (udalost.target) ? udalost.target : udalost.srcElement;
	
	if (udalost.type == "blur")
	{
				if (txt.value) {GivePovinn("validlink.php?co=" + txt.value +"&kolik=" + kolik,typ,pov);}
	}
}


/*function isURL(urlStr) {
if (urlStr.indexOf(" ") != -1) {
alert("Spaces are not allowed in a URL");
return false;
}

if (urlStr == "" || urlStr == null) {
return true;
}

urlStr=urlStr.toLowerCase();

var specialChars="\\(\\)><@,;:\\\\\\\"\\.\\[\\]";
var validChars="\[^\\s" + specialChars + "\]";
var atom=validChars + '+';
var urlPat=/^http:\/\/(\w*)\.([\-\+a-z0-9]*)\.(\w*)/;
var matchArray=urlStr.match(urlPat);

if (matchArray==null) {
//alert("The URL seems incorrect \ncheck it begins with http://\n and it has 2 .'s");
return false;
}

var user=matchArray[2];
var domain=matchArray[3];

for (i=0; i<user.length; i++) {
if (user.charCodeAt(i)>127) {
//alert("This domain contains invalid characters.");
return false;
}
}

for (i=0; i<domain.length; i++) {
if (domain.charCodeAt(i) > 127) {
//alert("This domain name contains invalid characters.");
return false;
}
}

var atomPat=new RegExp("^" + atom + "$");
var domArr=domain.split(".");
var len=domArr.length;

for (i=0;i<len;i++) {
if (domArr[i].search(atomPat) == -1) {
//alert("The domain name does not seem to be valid.");
return false;
}
}

return true;
} */
