/*****************************************inicializace proměnných**************************************************/

var agree = 1;
var view = 1;
var changed = 0;

var xmlHttp = false;

/******************************************deklarace ajax funkcí***************************************************/

function createXmlHttpRequest() {              
	if(navigator.appName == "Microsoft Internet Explorer") {
		xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
	}
	else {
		xmlHttp = new XMLHttpRequest();
	}
}

function domain_check(domain) {
	var td_domain = document.getElementById('domain_ok');
	createXmlHttpRequest()
	xmlHttp.abort();
	xmlHttp.open("GET", "ajax_func.php?domain=" + domain, true);
	xmlHttp.onreadystatechange = function() {
		if(xmlHttp.readyState == 4) {
			if(xmlHttp.status == 200) {
				td_domain.innerHTML = xmlHttp.responseText;
				
			}
		}
	}
	xmlHttp.send(null);
}

function domain1_check(domain) {
	var td_domain = document.getElementById('domain1_ok');
	createXmlHttpRequest()
	xmlHttp.abort();
	xmlHttp.open("GET", "ajax_func.php?domain2=" + domain, true);
	xmlHttp.onreadystatechange = function() {
		if(xmlHttp.readyState == 4) {
			if(xmlHttp.status == 200) {
				td_domain.innerHTML = xmlHttp.responseText;
			}
		}
	}
	xmlHttp.send(null);
}

function domain2_check(domain) {
	var td_domain = document.getElementById('domain2_ok');
	createXmlHttpRequest()
	xmlHttp.abort();
	xmlHttp.open("GET", "ajax_func.php?domain2=" + domain, true);
	xmlHttp.onreadystatechange = function() {
		if(xmlHttp.readyState == 4) {
			if(xmlHttp.status == 200) {
				td_domain.innerHTML = xmlHttp.responseText;
			}
		}
	}
	xmlHttp.send(null);
}

function domain3_check(domain) {
	var td_domain = document.getElementById('domain3_ok');
	createXmlHttpRequest()
	xmlHttp.abort();
	xmlHttp.open("GET", "ajax_func.php?domain2=" + domain, true);
	xmlHttp.onreadystatechange = function() {
		if(xmlHttp.readyState == 4) {
			if(xmlHttp.status == 200) {
				td_domain.innerHTML = xmlHttp.responseText;
			}
		}
	}
	xmlHttp.send(null);
}

function domain4_check(domain) {
	var td_domain = document.getElementById('domain4_ok');
	createXmlHttpRequest()
	xmlHttp.abort();
	xmlHttp.open("GET", "ajax_func.php?domain2=" + domain, true);
	xmlHttp.onreadystatechange = function() {
		if(xmlHttp.readyState == 4) {
			if(xmlHttp.status == 200) {
				td_domain.innerHTML = xmlHttp.responseText;
			}
		}
	}
	xmlHttp.send(null);
}

function domain_konc_check(domain) {
	var td_domain = document.getElementById('domain_konc_ok');
	createXmlHttpRequest()
	xmlHttp.abort();
	xmlHttp.open("GET", "ajax_func.php?domain2=" + domain, true);
	xmlHttp.onreadystatechange = function() {
		if(xmlHttp.readyState == 4) {
			if(xmlHttp.status == 200) {
				td_domain.innerHTML = xmlHttp.responseText;
			}
		}
	}
	xmlHttp.send(null);
}

function comp_check(comp) {
	var td_comp = document.getElementById('comp_ok');
	createXmlHttpRequest()
	xmlHttp.abort();
	xmlHttp.open("GET", "ajax_func.php?comp=" + comp, true);
	xmlHttp.onreadystatechange = function() {
		if(xmlHttp.readyState == 4) {
			if(xmlHttp.status == 200) {
				td_comp.innerHTML = xmlHttp.responseText;
			}
		}
	}
	xmlHttp.send(null);
}

function email_check(email) {
	var td_email = document.getElementById('email_ok');
	createXmlHttpRequest()
	xmlHttp.abort();
	xmlHttp.open("GET", "ajax_func.php?email=" + email, true);
	xmlHttp.onreadystatechange = function() {
		if(xmlHttp.readyState == 4) {
			if(xmlHttp.status == 200) {
				td_email.innerHTML = xmlHttp.responseText;
			}
		}
	}
	xmlHttp.send(null);
}

function email2_check(email) {
	var td_email = document.getElementById('email2_ok');
	createXmlHttpRequest()
	xmlHttp.abort();
	xmlHttp.open("GET", "ajax_func.php?email=" + email, true);
	xmlHttp.onreadystatechange = function() {
		if(xmlHttp.readyState == 4) {
			if(xmlHttp.status == 200) {
				td_email.innerHTML = xmlHttp.responseText;
			}
		}
	}
	xmlHttp.send(null);
}

function phone_check(phone) {
	var td_phone = document.getElementById('phone_ok');
	createXmlHttpRequest()
	xmlHttp.abort();
	xmlHttp.open("GET", "ajax_func.php?phone=" + phone, true);
	xmlHttp.onreadystatechange = function() {
		if(xmlHttp.readyState == 4) {
			if(xmlHttp.status == 200) {
				td_phone.innerHTML = xmlHttp.responseText;
			}
		}
	}
	xmlHttp.send(null);
}

function psc_check(psc) {
	var td_psc = document.getElementById('psc_ok');
	createXmlHttpRequest()
	xmlHttp.abort();
	xmlHttp.open("GET", "ajax_func.php?psc=" + psc, true);
	xmlHttp.onreadystatechange = function() {
		if(xmlHttp.readyState == 4) {
			if(xmlHttp.status == 200) {
				td_psc.innerHTML = xmlHttp.responseText;
			}
		}
	}
	xmlHttp.send(null);
}

function psc2_check(psc) {
	var td_psc = document.getElementById('psc2_ok');
	createXmlHttpRequest()
	xmlHttp.abort();
	xmlHttp.open("GET", "ajax_func.php?psc=" + psc, true);
	xmlHttp.onreadystatechange = function() {
		if(xmlHttp.readyState == 4) {
			if(xmlHttp.status == 200) {
				td_psc.innerHTML = xmlHttp.responseText;
			}
		}
	}
	xmlHttp.send(null);
}

function name_check(name) {
	var td_name = document.getElementById('name_ok');
	createXmlHttpRequest()
	xmlHttp.abort();
	xmlHttp.open("GET", "ajax_func.php?name=" + name, true);
	xmlHttp.onreadystatechange = function() {
		if(xmlHttp.readyState == 4) {
			if(xmlHttp.status == 200) {
				td_name.innerHTML = xmlHttp.responseText;
			}
		}
	}
	xmlHttp.send(null);
}

function name2_check(name) {
	var td_name = document.getElementById('name2_ok');
	createXmlHttpRequest()
	xmlHttp.abort();
	xmlHttp.open("GET", "ajax_func.php?name=" + name, true);
	xmlHttp.onreadystatechange = function() {
		if(xmlHttp.readyState == 4) {
			if(xmlHttp.status == 200) {
				td_name.innerHTML = xmlHttp.responseText;
			}
		}
	}
	xmlHttp.send(null);
}

function street_check(street) {
	var td_street = document.getElementById('street_ok');
	createXmlHttpRequest()
	xmlHttp.abort();
	xmlHttp.open("GET", "ajax_func.php?street=" + street, true);
	xmlHttp.onreadystatechange = function() {
		if(xmlHttp.readyState == 4) {
			if(xmlHttp.status == 200) {
				td_street.innerHTML = xmlHttp.responseText;
			}
		}
	}
	xmlHttp.send(null);
}

function street2_check(street) {
	var td_street = document.getElementById('street2_ok');
	createXmlHttpRequest()
	xmlHttp.abort();
	xmlHttp.open("GET", "ajax_func.php?street=" + street, true);
	xmlHttp.onreadystatechange = function() {
		if(xmlHttp.readyState == 4) {
			if(xmlHttp.status == 200) {
				td_street.innerHTML = xmlHttp.responseText;
			}
		}
	}
	xmlHttp.send(null);
}

function city_check(city) {
	var td_city = document.getElementById('city_ok');
	createXmlHttpRequest()
	xmlHttp.abort();
	xmlHttp.open("GET", "ajax_func.php?city=" + city, true);
	xmlHttp.onreadystatechange = function() {
		if(xmlHttp.readyState == 4) {
			if(xmlHttp.status == 200) {
				td_city.innerHTML = xmlHttp.responseText;
			}
		}
	}
	xmlHttp.send(null);
}

function city2_check(city) {
	var td_city = document.getElementById('city2_ok');
	createXmlHttpRequest()
	xmlHttp.abort();
	xmlHttp.open("GET", "ajax_func.php?city=" + city, true);
	xmlHttp.onreadystatechange = function() {
		if(xmlHttp.readyState == 4) {
			if(xmlHttp.status == 200) {
				td_city.innerHTML = xmlHttp.responseText;
			}
		}
	}
	xmlHttp.send(null);
}

function ip1_check(ip) {
	var td_ip = document.getElementById('ip1_ok');
	createXmlHttpRequest()
	xmlHttp.abort();
	xmlHttp.open("GET", "ajax_func.php?ip=" + ip, true);
	xmlHttp.onreadystatechange = function() {
		if(xmlHttp.readyState == 4) {
			if(xmlHttp.status == 200) {
				td_ip.innerHTML = xmlHttp.responseText;
			}
		}
	}
	xmlHttp.send(null);
}

function ip2_check(ip) {
	var td_ip = document.getElementById('ip2_ok');
	createXmlHttpRequest()
	xmlHttp.abort();
	xmlHttp.open("GET", "ajax_func.php?ip=" + ip, true);
	xmlHttp.onreadystatechange = function() {
		if(xmlHttp.readyState == 4) {
			if(xmlHttp.status == 200) {
				td_ip.innerHTML = xmlHttp.responseText;
			}
		}
	}
	xmlHttp.send(null);
}

function ico2_check(ico) {
	if(ico == '') {
		document.getElementById("klient_cislo").disabled=false;
		document.getElementById("klient_cislo").style.backgroundColor = "#ffffff";
		enable_forms();
		forma();
	}
	else {
		document.getElementById("klient_cislo").disabled=true;
		document.getElementById("klient_cislo").style.backgroundColor = "#cccccc";
		disable_forms();
	}
	var td_ico = document.getElementById('ico2_ok');
	createXmlHttpRequest()
	xmlHttp.abort();
	xmlHttp.open("GET", "ajax_func.php?ico_found=" + ico, true);
	xmlHttp.onreadystatechange = function() {
		if(xmlHttp.readyState == 4) {
			if(xmlHttp.status == 200) {
				td_ico.innerHTML = xmlHttp.responseText;
			}
		}
	}
	xmlHttp.send(null);
}

function id_check(id) {
	if(id == '') {
		document.getElementById("klient_ico").disabled=false;
		document.getElementById("klient_ico").style.backgroundColor = "#ffffff";
		enable_forms();
		forma();
	}
	else {
		document.getElementById("klient_ico").disabled=true;
		document.getElementById("klient_ico").style.backgroundColor = "#cccccc";
		disable_forms();
	}
	var td_id = document.getElementById('id_ok');
	createXmlHttpRequest()
	xmlHttp.abort();
	xmlHttp.open("GET", "ajax_func.php?id=" + id, true);
	xmlHttp.onreadystatechange = function() {
		if(xmlHttp.readyState == 4) {
			if(xmlHttp.status == 200) {
				td_id.innerHTML = xmlHttp.responseText;
			}
		}
	}
	xmlHttp.send(null);
}

/**********************************************funkce pro nápovědu********************************************/

help_shown = false;

function help_enable (text,x,y) {
	help_shown = true;
	var help;
	help = document.getElementById("help");
	if(!help) {
		help = document.createElement("div");
		help.id = "help";
		document.getElementsByTagName("body")[0].appendChild(help);
		
		if(!document.all) help.style.display = "fixed";
	}
	help.style.visibility = "visible";
	help.style.top = y+15+"px";
	help.style.left = x+30+"px";
	help.innerHTML = text;
}

function help_disable () {
	if(help_shown) {
		help_shown=false;
		document.getElementById("help").style.visibility="hidden";
	}
}

/***************************************funkce pro práci s formuláři************************************************/

function disable_forms()
{
	document.registrace.own_organization.disabled=true;
	document.registrace.own_organization.style.backgroundColor = "#cccccc";
	document.registrace.own_name.disabled=true;
	document.registrace.own_name.style.backgroundColor = "#cccccc";
	document.registrace.own_address.disabled=true;
	document.registrace.own_address.style.backgroundColor = "#cccccc";
	document.registrace.own_city.disabled=true;
	document.registrace.own_city.style.backgroundColor = "#cccccc";
	document.registrace.own_psc.style.backgroundColor = "#cccccc";
	document.registrace.own_psc.disabled=true;
	document.registrace.own_email.style.backgroundColor = "#cccccc";
	document.registrace.own_email.disabled=true;
	document.registrace.own_ico.style.backgroundColor = "#cccccc";
	document.registrace.own_ico.disabled=true;
	document.registrace.own_dic.style.backgroundColor = "#cccccc";
	document.registrace.own_dic.disabled=true;
	document.registrace.own_dateofbirth.style.backgroundColor = "#cccccc";
	document.registrace.own_dateofbirth.disabled=true;
	document.registrace.adm_name.style.backgroundColor = "#cccccc";
	document.registrace.adm_name.disabled=true;
	document.registrace.adm_address.style.backgroundColor = "#cccccc";
	document.registrace.adm_address.disabled=true;
	document.registrace.adm_city.style.backgroundColor = "#cccccc";
	document.registrace.adm_city.disabled=true;
	document.registrace.adm_psc.style.backgroundColor = "#cccccc";
	document.registrace.adm_psc.disabled=true;
	document.registrace.adm_phone.style.backgroundColor = "#cccccc";
	document.registrace.adm_phone.disabled=true;
	document.registrace.adm_fax.style.backgroundColor = "#cccccc";
	document.registrace.adm_fax.disabled=true;
	document.registrace.adm_email.style.backgroundColor = "#cccccc";
	document.registrace.adm_email.disabled=true;
	document.registrace.adm_dateofbirth.style.backgroundColor = "#cccccc";
	document.registrace.adm_dateofbirth.disabled=true;
	document.registrace.zalfakt_email.style.backgroundColor = "#cccccc";
	document.registrace.zalfakt_email.disabled=true;
	document.registrace.dns_primary.style.backgroundColor = "#cccccc";
	document.registrace.dns_primary.disabled=true;
	document.registrace.dns_primary_ip.style.backgroundColor = "#cccccc";
	document.registrace.dns_primary_ip.disabled=true;
	document.registrace.dns_secondary.style.backgroundColor = "#cccccc";
	document.registrace.dns_secondary.disabled=true;
	document.registrace.dns_secondary_ip.style.backgroundColor = "#cccccc";
	document.registrace.dns_secondary_ip.disabled=true;
}

function enable_forms()
{
	document.registrace.own_organization.disabled=false;
	document.registrace.own_organization.style.backgroundColor = "#ffffff";
	document.registrace.own_name.disabled=false;
	document.registrace.own_name.style.backgroundColor = "#ffffff";
	document.registrace.own_address.disabled=false;
	document.registrace.own_address.style.backgroundColor = "#ffffff";
	document.registrace.own_city.disabled=false;
	document.registrace.own_city.style.backgroundColor = "#ffffff";
	document.registrace.own_psc.style.backgroundColor = "#ffffff";
	document.registrace.own_psc.disabled=false;
	document.registrace.own_email.style.backgroundColor = "#ffffff";
	document.registrace.own_email.disabled=false;
	document.registrace.own_ico.style.backgroundColor = "#ffffff";
	document.registrace.own_ico.disabled=false;
	document.registrace.own_dic.style.backgroundColor = "#ffffff";
	document.registrace.own_dic.disabled=false;
	document.registrace.own_dateofbirth.style.backgroundColor = "#ffffff";
	document.registrace.own_dateofbirth.disabled=false;
	document.registrace.adm_name.style.backgroundColor = "#ffffff";
	document.registrace.adm_name.disabled=false;
	document.registrace.adm_address.style.backgroundColor = "#ffffff";
	document.registrace.adm_address.disabled=false;
	document.registrace.adm_city.style.backgroundColor = "#ffffff";
	document.registrace.adm_city.disabled=false;
	document.registrace.adm_psc.style.backgroundColor = "#ffffff";
	document.registrace.adm_psc.disabled=false;
	document.registrace.adm_phone.style.backgroundColor = "#ffffff";
	document.registrace.adm_phone.disabled=false;
	document.registrace.adm_fax.style.backgroundColor = "#ffffff";
	document.registrace.adm_fax.disabled=false;
	document.registrace.adm_email.style.backgroundColor = "#ffffff";
	document.registrace.adm_email.disabled=false;
	document.registrace.adm_dateofbirth.style.backgroundColor = "#ffffff";
	document.registrace.adm_dateofbirth.disabled=false;
	document.registrace.zalfakt_email.style.backgroundColor = "#ffffff";
	document.registrace.zalfakt_email.disabled=false;
	document.registrace.dns_primary.style.backgroundColor = "#ffffff";
	document.registrace.dns_primary.disabled=false;
	document.registrace.dns_primary_ip.style.backgroundColor = "#ffffff";
	document.registrace.dns_primary_ip.disabled=false;
	document.registrace.dns_secondary.style.backgroundColor = "#ffffff";
	document.registrace.dns_secondary.disabled=false;
	document.registrace.dns_secondary_ip.style.backgroundColor = "#ffffff";
	document.registrace.dns_secondary_ip.disabled=false;
}

function copy()
{
  if (document.registrace.stejne_udaje.checked) {
	document.registrace.adm_name.value 			= document.registrace.own_name.value;
	document.registrace.adm_address.value 		= document.registrace.own_address.value;
	document.registrace.adm_city.value 			= document.registrace.own_city.value;
	document.registrace.adm_psc.value 			= document.registrace.own_psc.value;
	document.registrace.adm_email.value 		= document.registrace.own_email.value;
	document.registrace.adm_dateofbirth.value 	= document.registrace.own_dateofbirth.value;
  }

  if (changed==0) {
  	document.registrace.zalfakt_email.value = document.registrace.own_email.value;
	}
}

function forma()
{
	if (document.registrace.own_subjtyp[0].checked)
	{
		agree=1;
		document.registrace.own_organization.style.backgroundColor = '#ffffff'; 
		/*document.registrace.own_ico.disabled=false;
		document.registrace.own_ico.style.backgroundColor = '#ffffff'; 
		document.registrace.own_dic.disabled=false;
		document.registrace.own_dic.style.backgroundColor = '#ffffff';*/ 
		document.registrace.own_dateofbirth.disabled=true;
		document.registrace.own_dateofbirth.style.backgroundColor = '#cccccc';
		document.getElementById("birth_ok").innerHTML = '';
	}

	if (document.registrace.own_subjtyp[1].checked)
	{
		agree=0;
		document.registrace.own_organization.value='';
		document.registrace.own_organization.style.backgroundColor = '#cccccc';
		/*document.registrace.own_ico.disabled=true;
		document.registrace.own_ico.style.backgroundColor = '#cccccc';
		document.registrace.own_dic.disabled=true;
		document.registrace.own_dic.style.backgroundColor = '#cccccc';*/
		document.registrace.own_dateofbirth.disabled=false;
		document.registrace.own_dateofbirth.style.backgroundColor = '#ffffff';
		document.getElementById("comp_ok").innerHTML = '';
		document.getElementById("ico_ok").innerHTML = '';
		document.getElementById("dic_ok").innerHTML = '';
	}
}

function zalfakt()
{
	if (document.registrace.zalfakt_typ.selectedIndex == 0)
	{
		view=1;
		document.registrace.zalfakt_email.style.backgroundColor = '#ffffff'; 
	}

	if (document.registrace.zalfakt_typ.selectedIndex == 1)
	{
		view=0;
		document.registrace.zalfakt_email.value='';
		document.registrace.zalfakt_email.style.backgroundColor = '#cccccc';
	}
}

/************************************************Generovani dalsich formularu*****************************************/

function make_form(number, dom1, dom2, dom3, dom4)
{
	var i = 0;
	var x= new Array();
	x[1]=dom1;
	x[2]=dom2;
	x[3]=dom3;
	x[4]=dom4;
	for(i=1;i<number;i++)
	{
		another_form(i,x[i]);
	}
}

function another_form(text,hodnota)
{
	var form_id='form'+text;
	var form_id_name='form'+text+'_name';
	var next_form=text+1;
	var previous=text-1;
	var butt='button'+previous;
	if(hodnota==0) hodnota='';
	var x=0;
	
	var mouse_move="\"if(navigator.appName == 'Microsoft Internet Explorer') {	help_enable('Povolené jsou znaky a-z, A-Z,. ,-. Doménu zadávejte bez www na začátku a přípony na konci.<br/> Příponu zvolte zaškrtnutím některé z nabízených níže. <br/> Příklad správného formátu domény je savvy.',event.clientX + document.documentElement.scrollLeft,(event.clientY + document.documentElement.scrollTop)-20); } if (navigator.appName != 'Microsoft Internet Explorer') { help_enable('Povolené jsou znaky a-z, A-Z,. ,-. Doménu zadávejte bez www na začátku a přípony na konci.<br/> Příponu zvolte zaškrtnutím některé z nabízených níže. <br/> Příklad správného formátu domény je savvy.',event.pageX,event.pageY-20); }\"";
	document.getElementById(form_id_name).innerHTML="<b>Doména "+next_form+":&nbsp;&nbsp;</b>";
	document.getElementById(form_id).innerHTML="<input type='text' value='"+hodnota+"' name='domena"+next_form+"' onkeyup='domain"+text+"_check(this.value);'/>&nbsp;"
	document.getElementById(form_id).innerHTML+="&nbsp;<span id='domain"+text+"_ok' onmousemove="+mouse_move+" onmouseout = 'help_disable()'></span>";
	document.getElementById(form_id).innerHTML+="&nbsp;<input  id='button"+text+"' type='image' src='pictures/add.gif' width='13' title='Další doména' onclick='return another_form("+next_form+","+x+");'/>";
	document.getElementById(butt).style.visibility='hidden';
	if (text==4) 
	{
		butt='button'+text;
		document.getElementById(butt).style.visibility='hidden';
	}
	return false;	
}

function loading()
{
	document.getElementById('was_sent1').innerHTML="<font color='green'><b>Prosím vyčkejte než server ověří dostupnost Vámi požadovaných domén.</b></font>";
	document.getElementById('was_sent2').innerHTML="<font color='green'><b>Tato operace může trvat i několik minut, mějte strpení, prosím.</b></font>";
}

function loading2()
{
	document.getElementById('was_sent3').innerHTML="<font color='green'><b>Prosím vyčkejte než server ověří dostupnost Vámi požadovaných domén.</b></font>";
	document.getElementById('was_sent4').innerHTML="<font color='green'><b>Tato operace může trvat i několik minut, mějte strpení, prosím.</b></font>";
}
