function Valid() {

    var reg = /^[0-9]*$/;
    if (document.xform.length > 0) {
    if (!document.xform.run_km.value.match(reg))
    {
    	alert("Niepoprawny format w ilosci km przejechanych na gazie");
    	document.xform.run_km.focus();
    	return false;
    }
    }
    alert("wysylam");
    return false;

}


function pobierz_modele(){

 plik = "http://"+location.host+"/scripts/lpg/lpg_pobierz_modele.php?q="+document.xform.makeid.value;
 element = document.getElementById("modelid");

 xml = null;
 element.innerHTML="";
 try{
  xml = new ActiveXObject("Microsoft.XMLHTTP"); // IE
 }catch(e){
  try {
   xml = new XMLHttpRequest(); // Mozilla/FireFox/Opera
  }catch(e){
   xml = null;
  }
 }
 if(xml != null){
  xml.onreadystatechange = function(){
   if(xml.readyState==4){
    element.innerHTML = "<select id=\"model\" name=\"modelid\" tabindex=\"2\" class=\"w170 lblue_brd\" disabled=\"disabled\" onchange=\"pobierz_nadwozia();\"><option value=\"0\" selected=\"selected\">wybierz</option>"+xml.responseText+"</select>";
    document.xform.modelid.disabled = false;
		document.xform.budaid.selectedIndex = 0;
		document.xform.budaid.disabled = true;
		document.xform.enginebindid.selectedIndex = 0;
		document.xform.enginebindid.disabled = true;
		document.xform.year.selectedIndex = 0;
		document.xform.year.disabled = true;
   }
  }
  xml.open("GET", plik, true);
  xml.send(null);
 }

 return false;
}

function pobierz_modele_search(){

 plik = "http://"+location.host+"/scripts/lpg/lpg_pobierz_modele.php?q="+document.xform.makeid.value;
 element = document.getElementById("modelid");

 xml = null;
 element.innerHTML="";
 try{
  xml = new ActiveXObject("Microsoft.XMLHTTP"); // IE
 }catch(e){
  try {
   xml = new XMLHttpRequest(); // Mozilla/FireFox/Opera
  }catch(e){
   xml = null;
  }
 }
 if(xml != null){
  xml.onreadystatechange = function(){
   if(xml.readyState==4){
    element.innerHTML = "<select id=\"model\" name=\"modelid\" class=\"w160 lblue_brd\" onchange=\"javascript:pobierz_generacje_search();\"><option value=\"0\" selected=\"selected\">dowolny</option>"+xml.responseText+"</select>";
		document.xform.genid.selectedIndex = 0;
		document.xform.genid.disabled = true;
		document.xform.enginebindid.selectedIndex = 0;
		document.xform.enginebindid.disabled = true;	 
	 }
  }
  xml.open("GET", plik, true);
  xml.send(null);
 }

 return false;
}


function pobierz_generacje_search(){

 plik = "http://"+location.host+"/scripts/lpg/lpg_pobierz_generacje.php?q="+document.xform.modelid.value;

 element = document.getElementById("genid");

 xml = null;
 element.innerHTML="";
 try{
  xml = new ActiveXObject("Microsoft.XMLHTTP"); // IE
 }catch(e){
  try {
   xml = new XMLHttpRequest(); // Mozilla/FireFox/Opera
  }catch(e){
   xml = null;
  }
 }
 if(xml != null){
  xml.onreadystatechange = function(){
   if(xml.readyState==4){
    if(xml.responseText == false) {
    }else {
		
		if(xml.responseText.match(/BRAK;/)) {
		
		xml_input = xml.responseText.substr(5,(xml.responseText.length-5))
		element.innerHTML = "<select id=\"generacja\" name=\"genid\" class=\"w170 lblue_brd\" onchange=\"\">"+xml_input+"</option></select>";
		document.xform.genid.disabled = true;
		document.xform.genid.selectedIndex = 1;
		pobierz_silniki_search();
		}
    else {element.innerHTML = "<select id=\"generacja\" name=\"genid\" class=\"w170 lblue_brd\" onchange=\"javascript:pobierz_silniki_search();\"><option value=\"0\">dowolna</option>"+xml.responseText+"</select>";
		
		document.xform.genid.disabled = false;
		document.xform.genid.selectedIndex = 0;
		document.xform.enginebind.disabled = true;;
		document.xform.enginebind.selectedIndex = 0;
		}
		}
   }
  }
  xml.open("GET", plik, true);
  xml.send(null);
 }
 return false;
}

function pobierz_silniki_search(){

 if(document.xform.genid.value) plik2 = "http://"+location.host+"/scripts/lpg/lpg_pobierz_silniki_bind.php?genid="+document.xform.genid.value;
 else plik2 = "http://"+location.host+"/scripts/lpg/lpg_pobierz_silniki_bind.php?modelid="+document.xform.modelid.value;
 
 element2 = document.getElementById("enginebindid");

 xml2 = null;
 element2.innerHTML="";
 try{
  xml2 = new ActiveXObject("Microsoft.XMLHTTP"); // IE
 }catch(e){
  try {
   xml2 = new XMLHttpRequest(); // Mozilla/FireFox/Opera
  }catch(e){
   xml2 = null;
  }
 }
 if(xml2 != null){
  xml2.onreadystatechange = function(){
   if(xml2.readyState==4){
    if(xml2.responseText == false) {
    }else {
    element2.innerHTML = "<select id=\"enginebind\" name=\"enginebindid\" class=\"w170 lblue_brd\"><option value=\"0\">dowolny</option>"+xml2.responseText+"</select>";
		}
   }
  }
  xml2.open("GET", plik2, true);
  xml2.send(null);
 }
 return false;
}


function pobierz_nadwozia(){

 plik = "http://"+location.host+"/scripts/lpg/lpg_pobierz_nadwozia.php?q="+document.xform.modelid.value;

 element = document.getElementById("budaid");

 xml = null;
 element.innerHTML="";
 try{
  xml = new ActiveXObject("Microsoft.XMLHTTP"); // IE
 }catch(e){
  try {
   xml = new XMLHttpRequest(); // Mozilla/FireFox/Opera
  }catch(e){
   xml = null;
  }
 }
 if(xml != null){
  xml.onreadystatechange = function(){
   if(xml.readyState==4){
    if(xml.responseText == false) {
    }else {
    element.innerHTML = "<select id=\"buda\" name=\"budaid\" tabindex=\"3\" class=\"w170 lblue_brd\" disabled=\"disabled\" onchange=\"pobierz_silniki();\"><option value=\"0\">wybierz</option>"+xml.responseText+"</select>";
    document.xform.budaid.disabled = false;
		document.xform.enginebindid.selectedIndex = 0;
		document.xform.enginebindid.disabled = true;
		document.xform.year.selectedIndex = 0;
		document.xform.year.disabled = true;
		}
   }
  }
  xml.open("GET", plik, true);
  xml.send(null);
 }
 return false;
}

function pobierz_silniki(){

 plik = "http://"+location.host+"/scripts/lpg/lpg_pobierz_silniki.php?modelid="+document.xform.modelid.value;
 if(document.xform.budaid.value)
 {
 plik+= "&budaid="+document.xform.budaid.value;
 }

 element = document.getElementById("enginebind");

 xml = null;
 element.innerHTML="";
 try{
  xml = new ActiveXObject("Microsoft.XMLHTTP"); // IE
 }catch(e){
  try {
   xml = new XMLHttpRequest(); // Mozilla/FireFox/Opera
  }catch(e){
   xml = null;
  }
 }
 if(xml != null){
  xml.onreadystatechange = function(){
   if(xml.readyState==4){
    if(xml.responseText == false) {
    }else {
    element.innerHTML = "<select id=\"enginebind_id\" class=\"w170 lblue_brd\" tabindex=\"4\" name=\"enginebindid\" onchange=\"pobierz_roczniki();\" ><option value=\"0\">wybierz</option>"+xml.responseText+"</select>";
    document.xform.year.selectedIndex = 0;
		document.xform.year.disabled = true;
		}
   }
  }
  xml.open("GET", plik, true);
  xml.send(null);
 
 }
 return false;
}

function pobierz_roczniki(){
 plik = "http://"+location.host+"/scripts/lpg/lpg_pobierz_roczniki.php?q="+document.xform.enginebindid.value;
 //"&q2="+document.xform.version.value;
 //rocznik_select = document.xform.year;
 element = document.getElementById("years");

 xml = null;
 element.innerHTML="";
 try{
  xml = new ActiveXObject("Microsoft.XMLHTTP"); // IE
 }catch(e){
  try {
   xml = new XMLHttpRequest(); // Mozilla/FireFox/Opera
  }catch(e){
   xml = null;
  }
 }
 if(xml != null){
  xml.onreadystatechange = function(){
   if(xml.readyState==4){
    element.innerHTML = "<select name=\"year\" tabindex=\"5\" class=\"w170 lblue_brd\"><option value=\"0\">wybierz</option>"+xml.responseText+"</select>";
   }
  }
  xml.open("GET", plik, true);
  xml.send(null);

 }
 return false;
}

function silnik_info()
{

plik = "http://"+location.host+"/scripts/lpg/lpg_silnik_info.php?modelid="+document.xform.modelid.value+"&budaid="+document.xform.budaid.value+"&enginebindid="+document.xform.enginebindid.value;

 element2 = document.getElementById("full_engine");

 xml2 = null;
 element2.innerHTML="";
 try{
  xml2 = new ActiveXObject("Microsoft.XMLHTTP"); // IE
 }catch(e){
  try {
   xml2 = new XMLHttpRequest(); // Mozilla/FireFox/Opera
  }catch(e){
   xml2 = null;
  }
 }
 if(xml2 != null){
  xml2.onreadystatechange = function(){
   if(xml2.readyState==4){
    if(xml2.responseText == false) {
    }else {
    element2.innerHTML = xml2.responseText;
		}
   }
  }
  xml2.open("GET", plik, true);
  xml2.send(null);
 }
 return false;


}

function IsValid(){
 var xf = document.xform;
 var error;
 
 if(!xf.makeid.selectedIndex){
  alert("Proszę podać markę auta");
  xf.makeid.focus();
  return false;
 }
 if(!xf.modelid.selectedIndex){
  alert("Proszę podać model auta");
  xf.modelid.focus();
  return false;
 }
 if(!xf.budaid.selectedIndex){
  alert("Proszę wybrać wersję nadwoziową auta");
  xf.budaid.focus();
  return false;
 }
 
 if(!xf.enginebindid.selectedIndex){
  alert("Proszę wybrać wersję silnika");
  xf.enginebindid.focus();
  return false;
 }
 
	if(!xf.year.selectedIndex){
  alert("Proszę podać rocznik auta");
  xf.year.focus();
  return false;
 } 
 
	if(!xf.producentid.selectedIndex){
  alert("Proszę wybrać producenta instalcji LPG lub wybierz opcję nie wiem");
  xf.producentid.focus();
  return false;
 }

 if(!xf.sterid.selectedIndex){
  alert("Proszę wybrać nazwę instalcji LPG");
  xf.sterid.focus();
  return false;
 }
 
 for(i=0;i < xf.spalanie.length;i++)
	{
	if(xf.spalanie[i].checked==true){
	error = false;
	break;
	}else error = true;
 }
 
 if(error)
 {
	alert("Proszę wybrać różnicę spalania");
  xf.spalanie[0].focus();
  return false;
 }
	
 
  for(i=0;i < xf.serwisy.length;i++)
	{
	if(xf.serwisy[i].checked==true){
	error = false;
	break;
	}else error = true;
 }
 
 if(error)
 {
	alert("Proszę wybrać jak częste są twoje wizyty w serwisie");
  xf.serwisy[0].focus();
  return false;
 }
 
 
  for(i=0;i < xf.moc.length;i++)
	{
	if(xf.moc[i].checked==true){
	error = false;
	break;
	}else error = true;
 }
 
 if(error)
 {
	alert("Wybierz czy nastąpił spadek mocy na gazie");
  xf.moc[0].focus();
  return false;
 }
 
  for(i=0;i < xf.ocena.length;i++)
	{
	if(xf.ocena[i].checked==true){
	error = false;
	break;
	}else error = true;
  }
	
 if(error)
 {
	alert("Proszę ocenić czy silnik pracuje poprawnie na gazie");
  xf.ocena[0].focus();
  return false;
 }	
 
 if(!xf.podpis.value)
 {
	alert("Proszę podać swój podpis");
  xf.podpis.focus();
  return false;
 }
 
 return true;
}

function IsValid2(){
 var xf = document.xform;
 var error;
 
 if(!xf.geoid.selectedIndex && xf.geoid){
  if(!xf.geoid.value){
	alert("Proszę wybrać warsztat");
  xf.makeid.focus();
  return false;
	}
 }
 
 	for(i=0;i < xf.answ1.length;i++)
	{
	if(xf.answ1[i].checked==true){
	error = false;
	break;
	}else error = true;
 }
 
 if(error)
 {
	alert("Proszę ocenić jakość wykonanego montażu instalacji");
  xf.answ1[0].focus();
  return false;
 }
 
	for(i=0;i < xf.answ2.length;i++)
	{
	if(xf.answ2[i].checked==true){
	error = false;
	break;
	}else error = true;
 }
 
 if(error)
 {
	alert("Proszę ocenić kulturę obsługi");
  xf.answ2[0].focus();
  return false;
 }
 
 	for(i=0;i < xf.answ3.length;i++)
	{
	if(xf.answ3[i].checked==true){
	error = false;
	break;
	}else error = true;
 }
 
 if(error)
 {
	alert("Proszę ocenić poziom cenowy");
  xf.answ3[0].focus();
  return false;
 }
 
 
 	for(i=0;i < xf.answ4.length;i++)
	{
	if(xf.answ4[i].checked==true){
	error = false;
	break;
	}else error = true;
 }
 
 if(error)
 {
	alert("Proszę wybrać czy poleciłbyś ten warsztat innym");
  xf.answ4[0].focus();
  return false;
 }
 
 if(!xf.podpis.value)
 {
	alert("Proszę podać swój podpis");
  xf.podpis.focus();
  return false;
 }
 
 return true;;
}


function rotate_wizyty(action)
{
	var i;
	var radio = document.xform.wizyty;
	var span = document.getElementById("wizyty");
	
	for(i=0;i < radio.length;i++)
	{
	
		if(action) {
		radio[i].disabled = false;
		span.style.color = "#7DA445";
		//span.setAttribute('style', 'color: rgb(125, 164, 69);'); 
		}
		else
		{
		span.style.color = "#AAAAAA";
		//span.setAttribute('style', 'color: rgb(170, 170, 170);'); 
		radio[i].checked  = false;
		radio[i].disabled = true;
		}
	}
	
}

function miasta()
{
 plik = "http://"+location.host+"/scripts/lpg/lpg_miasta.php?regionid="+document.xform.regionid.value; 
 element = document.getElementById("miasta");


 document.xform.geoid.selectedIndex = 0;
 document.xform.geoid.disabled = true; 
 
 if(document.xform.regionid.value == "")
 {
		document.xform.cityid.disabled = true;
		document.xform.cityid.selectedIndex = -1;
		return false;
 }
 
 xml = null;
 element.innerHTML="";
 try{
  xml = new ActiveXObject("Microsoft.XMLHTTP"); // IE
 }catch(e){
  try {
   xml = new XMLHttpRequest(); // Mozilla/FireFox/Opera
  }catch(e){
   xml = null;
  }
 }
 if(xml != null){
  xml.onreadystatechange = function(){
   if(xml.readyState==4){
    element.innerHTML = "<select name=\"cityid\" class=\"wid2\" onchange=\"javascript:warsztaty();\" class=\"w160 lblue_brd\"><option value=\"0\">wybierz</option>"+xml.responseText+"</select>";
   }
  }
  xml.open("GET", plik, true);
  xml.send(null);

 }
 return false;

}

function warsztaty()
{
 plik2 = "http://"+location.host+"/scripts/lpg/lpg_warsztaty.php?regionid="+document.xform.regionid.value;
 if(document.xform.cityid) plik2+="&cityid="+document.xform.cityid.value;
 
 element2 = document.getElementById("warsztaty");
 
 if(document.xform.cityid.value == '0')
 {
		document.xform.geoid.disabled = true;
		document.xform.geoid.selectedIndex = -1;
		return false;
 }

 xml2 = null;
 element2.innerHTML="";
 try{
  xml2 = new ActiveXObject("Microsoft.XMLHTTP"); // IE
 }catch(e){
  try {
   xml2 = new XMLHttpRequest(); // Mozilla/FireFox/Opera
  }catch(e){
   xml2 = null;
  }
 }
 if(xml2 != null){
  xml2.onreadystatechange = function(){
   if(xml2.readyState==4){
	 
	 if(xml2.responseText == "BRAK") element2.innerHTML = "<select name=\"geoid\" class=\"lblue_brd\" style=\"width: 454px;\" disabled=\"disabled\"><option value=\"0\">brak warsztatów</option></select>";
    else element2.innerHTML = "<select name=\"geoid\" class=\"lblue_brd\" style=\"width: 454px;\"><option value=\"0\">wybierz</option>"+xml2.responseText+"</select>";
   }
  }
  xml2.open("GET", plik2, true);
  xml2.send(null);

 }
 return false;

}

function Isgen() {
 elem = document.getElementById("genid_lista");
 wartosc = elem.options[elem.selectedIndex].value;
 if(wartosc == -1) {
 elem.disabled = true;
 return false;
 }else {
 elem.disabled = false;
 return true;
 }
}


function google_search()
{
	var f = document.sform;
	
	if(f.wname) var nazwa = f.wname.value;
	if(f.adres) var adres = f.adres.value;
	if(f.city && f.city.selectedIndex != -1 && f.city.selectedIndex != "") var city = f.city.options[f.city.selectedIndex].innerHTML;
	
	if(nazwa)	var url = nazwa
	if(adres)	url+= ' '+adres;
	if(city)	url+= ' '+city;
	url+=' telefon';
	
	
	if(url) window.open('http://www.google.pl/search?hl=pl&q='+url+'&btnG=Szukaj+w+Google&lr=', 'test', 'toolbar=yes,location=yes,directories=yes,status=yes,menubar=yes,scrollbars=yes,resizable=yes,fullscreen=no,channelmode=yes,width=,height=,top=,left=');
	else alert('Wpisz nazwę firmy oraz miejscowość.');




}

