function getModels(makeid,element_name,select_name,mode){
 plik = "http://"+location.host+"/scripts/osa/pobierz_modele.php?q="+makeid;
 e = document.getElementById(element_name);
 bsel = 'buda_select'+mode;
 bid = 'bid'+mode;
 xml = null;
 e.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){
    e.innerHTML = "<select class=\"w170 lblue_brd\" name=\""+select_name+"\" onchange=\"getVersions(this[this.selectedIndex].value,'"+bsel+"','"+bid+"',"+mode+")\"><option value=\"0\">wybierz model</option>"+xml.responseText+"</select>";
   }
  }
  xml.open("GET", plik, true);
  xml.send(null);

 }
 if(mode==1){
  document.xform.bid1.selectedIndex = 0;
  document.xform.engineid1.selectedIndex = 0;
  document.xform.yearfrom1.selectedIndex = 0;
  document.xform.yearto1.selectedIndex = 0;
 }else if(mode==2){
  document.xform.bid2.selectedIndex = 0;
  document.xform.engineid2.selectedIndex = 0;
  document.xform.yearfrom2.selectedIndex = 0;
  document.xform.yearto2.selectedIndex = 0;
 }
 return false;
}

function getVersions(modelid,element_name,select_name,mode){
 plik = "http://"+location.host+"/scripts/osa/pobierz_wersje.php?q="+modelid;
 element = document.getElementById(element_name);
 esel = 'engine_select'+mode;
 eid = 'engineid'+mode;
 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 class=\"w170 lblue_brd\" name=\""+select_name+"\" onchange=\"getEngines(this[this.selectedIndex].value,'"+esel+"','"+eid+"',"+mode+")\"><option value=\"0\">wybierz wersję nadwozia</option>"+xml.responseText+"</select>";
   }
  }
  xml.open("GET", plik, true);
  xml.send(null);
 }
 if(mode==1){
  document.xform.engineid1.selectedIndex = 0;
  document.xform.yearfrom1.selectedIndex = 0;
  document.xform.yearto1.selectedIndex = 0;
 }else if(mode==2){
  document.xform.engineid2.selectedIndex = 0;
  document.xform.yearfrom2.selectedIndex = 0;
  document.xform.yearto2.selectedIndex = 0;
 }
 return false;
}

function getEngines(budaid,element_name,select_name,mode){
 plik = "http://"+location.host+"/scripts/osa/pobierz_silniki.php?q="+budaid;
 element = document.getElementById(element_name);
 ysel = "years_select"+mode;
 yid1 = "yearfrom"+mode;
 yid2 = "yearto"+mode;
 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 class=\"w170 lblue_brd\" name=\""+select_name+"\" onchange=\"getYears(document.xform.modelid"+mode+"[document.xform.modelid"+mode+".selectedIndex].value,document.xform.bid"+mode+"[document.xform.bid"+mode+".selectedIndex].value,this[this.selectedIndex].value,'"+ysel+"','"+yid1+"','"+yid2+"',"+mode+")\"><option value=\"0\">wybierz silnik</option>"+xml.responseText+"</select>";
   }
  }
  xml.open("GET", plik, true);
  xml.send(null);

 }
 return false;
}

function getYears(modelid,bid,engineid,element_name,select1_name,select2_name,mode){
 plik = "http://"+location.host+"/scripts/osa/pobierz_roczniki_od_do.php?q="+bid+"&q3="+modelid+"&q2="+engineid+"&q4="+mode;
 element = document.getElementById(element_name);
 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 = xml.responseText;
   }
  }
  xml.open("GET", plik, true);
  xml.send(null);

 }
 return false;
}

function IsValid(){
 if(!document.xform.modelid1.selectedIndex||!document.xform.modelid2.selectedIndex){
  alert("Proszę wybrać modele porównywanych samochodów");
  if(!document.xform.modelid1.selectedIndex) document.xform.modelid1.focus();
  if(!document.xform.modelid2.selectedIndex) document.xform.modelid2.focus();
  return false;
 }
 return true;
}

