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) {}
    }
  }
    return xmlHttp;
}


function model_tyres()
{
	document.getElementById("model_tyre").innerHTML='<img src="/img/ajax-loader-2.gif" width="128" height="15">';
var	param1=document.getElementById('marka_tyre').value;
var	param2=document.getElementById('model_tyre_value').value;
  if (xmlHttp)
  {
      xmlHttp.open("GET", "/search/search/xml/model.php?ma="+param1+"&mo="+param2, true);
      xmlHttp.onreadystatechange = handleRequestStateChange;
      xmlHttp.send(null);
  }


function handleRequestStateChange() 
{
	if (xmlHttp.readyState == 4 && xmlHttp.status == 200) 
	  {
        handleServerResponse();
	  }
}

 
function handleServerResponse()
{
  var xmlResponse = xmlHttp.responseXML;
  xmlRoot = xmlResponse.documentElement;  
  titleArray = xmlRoot.getElementsByTagName("title");
  title2Array = xmlRoot.getElementsByTagName("title2");
  selArray = xmlRoot.getElementsByTagName("sel");
  var html = '<select name="mo" class="sel" id="model_tyre2"><option value="">[все]</option>';  
  for (var i=0; i<titleArray.length; i++)
  html = html + '<option value="'+title2Array.item(i).firstChild.data+'" '+selArray.item(i).firstChild.data+'>'+titleArray.item(i).firstChild.data+'</option>';
  myDiv = document.getElementById("model_tyre");
  myDiv.innerHTML = html+'</select>';
}
}

//автомобили
//модели
function model_auto()
{
	document.getElementById("model_auto").innerHTML='<img src="/img/ajax-loader-2.gif" width="128" height="15">';
var	param3=document.getElementById('marka_auto').value;
var	param4=document.getElementById('model_auto_value').value;
  if (xmlHttp)
  {
      xmlHttp.open("GET", "/search/auto/xml/model.php?ma="+param3+"&mo="+param4, true);
      xmlHttp.onreadystatechange = handleRequestStateChange;
      xmlHttp.send(null);
  }


function handleRequestStateChange() 
{
  if (xmlHttp.readyState == 4) 
  {
	  if (xmlHttp.status == 200)
	  {
        handleServerResponse();
	  }
  }
}

 
function handleServerResponse()
{
  var xmlResponse = xmlHttp.responseXML;
  xmlRoot = xmlResponse.documentElement;  
  titleArray = xmlRoot.getElementsByTagName("title");
  selArray = xmlRoot.getElementsByTagName("sel");
  var html = '<select name="mo" class="sel" id="model_auto2" onChange="god_auto();"><option value="">выберите</option>';  
  for (var i=0; i<titleArray.length; i++)
  html = html + '<option value="'+titleArray.item(i).firstChild.data+'" '+selArray.item(i).firstChild.data+'>'+titleArray.item(i).firstChild.data+'</option>';
  myDiv = document.getElementById("model_auto");
  myDiv.innerHTML = html+'</select>';
}
}
//года
function god_auto()
{
	document.getElementById("year1auto").innerHTML='<img src="/img/ajax-loader-2.gif" width="128" height="15">';
var	param5=document.getElementById("marka_auto").value;
var	param6=document.getElementById("model_auto2").value;
var	param7=document.getElementById("model_auto_value").value;
  if (xmlHttp)
  {
      xmlHttp.open("GET", "/search/auto/xml/year.php?ma="+param5+"&mo="+param6+"&year="+param7, true);
      xmlHttp.onreadystatechange = handleRequestStateChange;
      xmlHttp.send(null);
  }


function handleRequestStateChange() 
{
  if (xmlHttp.readyState == 4) 
  {
	  if (xmlHttp.status == 200)
	  {
        handleServerResponse();
	  }
  }
}

 
function handleServerResponse()
{
  var xmlResponse = xmlHttp.responseXML;
  xmlRoot = xmlResponse.documentElement;  
  titleArray = xmlRoot.getElementsByTagName("title");
  selArray = xmlRoot.getElementsByTagName("sel");
  var html = '<select name="year" class="sel" id="year1auto2" onChange="val2_auto();"><option value="">выберите</option>';  
  for (var i=0; i<titleArray.length; i++)
  html = html + '<option value="'+titleArray.item(i).firstChild.data+'" '+selArray.item(i).firstChild.data+'>'+titleArray.item(i).firstChild.data+'</option>';
  myDiv = document.getElementById("year1auto");
  myDiv.innerHTML = html+'</select>';
}
}
//валуе
function val2_auto()
{
	document.getElementById("val2auto").innerHTML='<img src="/img/ajax-loader-2.gif" width="128" height="15" style="padding:0px">';
var	param8=document.getElementById("marka_auto").value;
var	param9=document.getElementById("model_auto2").value;
var	param10=document.getElementById("year1auto2").value;
var	param11=document.getElementById("val2_auto_value").value;
  if (xmlHttp)
  {
      xmlHttp.open("GET", "/search/auto/xml/val.php?ma="+param8+"&mo="+param9+"&year="+param10, true);
      xmlHttp.onreadystatechange = handleRequestStateChange;
      xmlHttp.send(null);
  }


function handleRequestStateChange() 
{
  if (xmlHttp.readyState == 4) 
  {
	  if (xmlHttp.status == 200)
	  {
        handleServerResponse();
	  }
  }
}

 
function handleServerResponse()
{
  var xmlResponse = xmlHttp.responseXML;
  xmlRoot = xmlResponse.documentElement;  
  titleArray = xmlRoot.getElementsByTagName("title");
  selArray = xmlRoot.getElementsByTagName("sel");
  var html = '<select name="value" class="sel" id="val_auto2"><option value="">выберите</option>';  
  for (var i=0; i<titleArray.length; i++)
  html = html + '<option value="'+titleArray.item(i).firstChild.data+'" '+selArray.item(i).firstChild.data+'>'+titleArray.item(i).firstChild.data+'</option>';
  myDiv = document.getElementById("val2auto");
  myDiv.innerHTML = html+'</select>';
}
}