var modeC;
var xmlHttpC;
function getCars(mode)
{
modeC = mode;
xmlHttpC = GetXmlHttpObjectC();
var urlC="proc.php";
xmlHttpC.onreadystatechange=stateCars;

add = "&car=" + document.forms['SearchForm'].elements['autobrand'].value + "&model=" + document.forms['SearchForm'].elements['model'].value + "&engine=" +document.forms['SearchForm'].elements['engine'].value + "&year=" + document.forms['SearchForm'].elements['year'].value  ;

xmlHttpC.open("GET", urlC + "?mode=" + mode + add,true);
xmlHttpC.send(null);
}



function stateCars()
{
if (xmlHttpC.readyState==4 || xmlHttpC.readyState=="complete")
{
if(modeC == "car"){
window.document.forms['SearchForm'].elements['model'].value = "";
window.document.forms['SearchForm'].elements['engine'].value = "";
window.document.forms['SearchForm'].elements['year'].value = "";
window.document.forms['SearchForm'].elements['model'].disabled = false;
window.document.forms['SearchForm'].elements['engine'].disabled = true;
window.document.forms['SearchForm'].elements['year'].disabled = true;
inSET = '<select class="search-selecta" name="model" id="model" onchange="getCars(&#39;model&#39;);">' + xmlHttpC.responseText +'</select>';
document.getElementById('model-container').innerHTML = inSET;
getCars('sizes');
}
if(modeC == "model"){
window.document.forms['SearchForm'].elements['engine'].value = "";
window.document.forms['SearchForm'].elements['year'].value = "";
window.document.forms['SearchForm'].elements['engine'].disabled = false;
window.document.forms['SearchForm'].elements['year'].disabled = true;
inSET = '<select class="search-selecta" name="engine" id="engine" onchange="getCars(&#39;engine&#39;);">' + xmlHttpC.responseText +'</select>';
document.getElementById('engine-container').innerHTML = inSET;
getCars('sizes');
}
if(modeC == "engine"){
window.document.forms['SearchForm'].elements['year'].disabled = false;
inSET = '<select class="search-selecta" name="year" id="year" onchange="getCars(&#39;year&#39;);">' + xmlHttpC.responseText +'</select>';
document.getElementById('year-container').innerHTML = inSET;
getCars('sizes');
}

if(modeC == "sizes"){
inSET = '<select class="search-selecta" name="sizes" id="sizes" onchange="sendRequest();" style="background:#74D374;width:100%;">' + xmlHttpC.responseText +'</select>';
document.getElementById('sizecontainer').innerHTML = inSET;
}

///sendRequest();

} else {
setTimeout('stateCars();',10);
}

}



function disableC(){
window.document.forms['SearchForm'].elements['model'].setAttribute('disabled','disabled');
window.document.forms['SearchForm'].elements['engine'].setAttribute('disabled','disabled');
window.document.forms['SearchForm'].elements['year'].setAttribute('disabled','disabled');
}

function GetXmlHttpObjectC()
{
var objXMLHttp=null;
if (window.XMLHttpRequest)
 {
objXMLHttp=new XMLHttpRequest();
 }
else if (window.ActiveXObject)
 {
objXMLHttp=new ActiveXObject("Microsoft.XMLHTTP");
 }
return objXMLHttp;
}