var xmlHttp
function GetXmlHttpObject(){ 
	var objXMLHttp=null
	if (window.XMLHttpRequest){
		objXMLHttp=new XMLHttpRequest()
	}
	else if (window.ActiveXObject){
		try{
			objXMLHttp=new ActiveXObject("Microsoft.XMLHTTP")
		}
		catch(e){
		}
	}
	return objXMLHttp
}

function showLev1(str){ 


	xmlHttp=GetXmlHttpObject()
	if (xmlHttp==null)	{
		alert ("Browser does not support HTTP Request")
		return
	} 
	var url="includes/com/sell/getautodata.php"
	url=url+"?lev1="+str
	url=url+"&sid="+Math.random()
	xmlHttp.onreadystatechange=stateChanged 
	xmlHttp.open("GET",url,true)
	xmlHttp.send(null)
}


function showLev2(str){ 
	xmlHttp=GetXmlHttpObject()
	if (xmlHttp==null)	{
		alert ("Browser does not support HTTP Request")
		return
	} 
	var url="includes/com/sell/getautodata.php"
	url=url+"?lev2="+str
	url=url+"&sid="+Math.random()	
	xmlHttp.onreadystatechange=stateChanged2 
	xmlHttp.open("GET",url,true)
	xmlHttp.send(null)
}


function stateChanged(){ 
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete"){ 
		document.getElementById("divLev1").style.display = "block" ;
		document.getElementById("divLev2").style.display = "none";
		document.getElementById("selected").style.display = "none";
		document.getElementById("divLev1").innerHTML=xmlHttp.responseText 
		if(xmlHttp.responseText == ""){
			showBuyContinue();
		}
	} 
} 

function stateChanged2(){ 
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete"){ 	
		document.getElementById("divLev2").style.display = "block";	
		document.getElementById("selected").style.display = "none";	
		document.getElementById("divLev2").innerHTML=xmlHttp.responseText 
		if(xmlHttp.responseText == ""){
			showBuyContinue();
		}
	} 
} 

function showBuyContinue(){
	document.getElementById("selected").style.display = "block";
}



function getModel(x, mainUrl){
	xmlHttp=GetXmlHttpObject()
	if (xmlHttp==null)	{
		alert ("Browser does not support HTTP Request")
		return
	} 
	var url=mainUrl + "includes/com/sell/getvehicle.php"
	url=url+"?make="+x
	url=url+"&sid="+Math.random()

	xmlHttp.onreadystatechange=stateChanged3
	xmlHttp.open("GET",url,true)
	xmlHttp.send(null)
}

function stateChanged3(){ 
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete"){ 		
		document.getElementById("model").innerHTML=xmlHttp.responseText 
	} 
} 

function showOther(){
	if( document.buystep2.other_mm.checked == true ){
		document.getElementById("model").style.display = "none";	
		document.getElementById("modelOther").style.display = "block";	
		
		document.getElementById("make").style.display = "none";	
		document.getElementById("makeOther").style.display = "block";
	}
	else{
		document.getElementById("model").style.display = "block";	
		document.getElementById("modelOther").style.display = "none";	
		
		document.getElementById("make").style.display = "block";	
		document.getElementById("makeOther").style.display = "none";	
	}	
}

function doLoad(value) {
    // Create new JsHttpRequest object.
    var req = new JsHttpRequest();
    // Code automatically called on load finishing.
    req.onreadystatechange = function() {
        if (req.readyState == 4) {    
            document.getElementById('debug').innerHTML = req.responseText;
        }
    }
    
    req.open(null, 'includes/com/sell/upl_backend.php', true);    
    req.send( { q: value } );
}

function uploadImage(){
	document.buystep3.buymode.value = "buystep4file";
	document.buystep3.submit();
}
function contImage(){
	document.buystep3.buymode.value = "buystep4";
	document.buystep3.submit();
}
function imageAction(imgId, action){
	
	document.buystep3.buymode.value    = "buystep4file";
	document.buystep3.imagemode.value  = action;
	document.buystep3.imagevalue.value = imgId;	
	document.buystep3.submit();
}

function sellBack(formName, buymodeValue){
	var formRef = formName.form; 
	formRef.buymode.value = buymodeValue;
	formRef.submit();
}