/* AJAX FUNCTIONS */


function getHTTPObject()
{   
	if (window.ActiveXObject)        
		return new ActiveXObject("Microsoft.XMLHTTP");   
	else if (window.XMLHttpRequest)        
		return new XMLHttpRequest();   
	else 
	{      
		alert("Your browser does not support AJAX.");      
		return null;   
	}
}

////////////////// Function For Condition Change ///////////

function update_condition(condition)
{ 
	httpObject = getHTTPObject();    
	if (httpObject != null) 
	{
		//alert(cat_id);
		httpObject.open("GET", "ajax_files/update_condition.php?condition="+condition, true);        
		httpObject.send(null);         
		httpObject.onreadystatechange = setOutput;    
	}
}


function setOutput()
{    
	if(httpObject.readyState == 4)
	{         
		document.getElementById('div_year').innerHTML=httpObject.responseText;
		document.getElementById('div_brand').innerHTML="<select class='ddbox' name='brand'><OPTION VALUE='' selected='selected'>Search by Brand</option></select>";
		document.getElementById('div_model').innerHTML="<select class='ddbox' name='model'><OPTION VALUE='' selected='selected'>Search by Model</option></select>";
		document.getElementById('div_body_type').innerHTML="<select class='ddbox' name='body_type'><OPTION VALUE='' selected='selected'>Search by Body Type</option></select>";
		document.getElementById('div_price').innerHTML="<select class='ddbox' name='price'><OPTION VALUE='' selected='selected'>Search by Price</option></select>";
	} 
}


////////////////// Function For Year Change ///////////

function update_year(year)
{ 
	httpObject_year = getHTTPObject();    
	if (httpObject_year != null) 
	{
		//alert(cat_id);
		httpObject_year.open("GET", "ajax_files/update_year.php?year="+year, true);        
		httpObject_year.send(null);         
		httpObject_year.onreadystatechange = setOutput_year;    
	}
}


function setOutput_year()
{    
	if(httpObject_year.readyState == 4)
	{         
		document.getElementById('div_brand').innerHTML=httpObject_year.responseText;
		document.getElementById('div_model').innerHTML="<select class='ddbox' name='model'><OPTION VALUE='' selected='selected'>Search by Model</option></select>";
		document.getElementById('div_body_type').innerHTML="<select class='ddbox' name='body_type'><OPTION VALUE='' selected='selected'>Search by Body Type</option></select>";
		document.getElementById('div_price').innerHTML="<select class='ddbox' name='price'><OPTION VALUE='' selected='selected'>Search by Price</option></select>";
	} 
}

////////////////// Function For Brand Change ///////////

function update_brand(brand)
{ 
	httpObject_brand = getHTTPObject();    
	if (httpObject_brand != null) 
	{
		//alert(cat_id);
		httpObject_brand.open("GET", "ajax_files/update_brand.php?brand="+brand, true);        
		httpObject_brand.send(null);         
		httpObject_brand.onreadystatechange = setOutput_brand;    
	}
}


function setOutput_brand()
{    
	if(httpObject_brand.readyState == 4)
	{         
		document.getElementById('div_model').innerHTML=httpObject_brand.responseText;
		document.getElementById('div_body_type').innerHTML="<select class='ddbox' name='body_type'><OPTION VALUE='' selected='selected'>Search by Body Type</option></select>";
		document.getElementById('div_price').innerHTML="<select class='ddbox' name='price'><OPTION VALUE='' selected='selected'>Search by Price</option></select>";
	} 
}

////////////////// Function For Model Change ///////////

function update_model(model)
{ 
	httpObject_model = getHTTPObject();    
	if (httpObject_model != null) 
	{
		//alert(cat_id);
		httpObject_model.open("GET", "ajax_files/update_model.php?model="+model, true);        
		httpObject_model.send(null);         
		httpObject_model.onreadystatechange = setOutput_model;    
	}
}


function setOutput_model()
{    
	if(httpObject_model.readyState == 4)
	{         
		document.getElementById('div_body_type').innerHTML=httpObject_model.responseText;
		document.getElementById('div_price').innerHTML="<select class='ddbox' name='price'><OPTION VALUE='' selected='selected'>Search by Price</option></select>";
	} 
}

////////////////// Function For Body Type Change ///////////

function update_type(type)
{ 
	httpObject_type = getHTTPObject();    
	if (httpObject_type != null) 
	{
		//alert(cat_id);
		httpObject_type.open("GET", "ajax_files/update_body_type.php?body_type="+type, true);        
		httpObject_type.send(null);         
		httpObject_type.onreadystatechange = setOutput_type;    
	}
}


function setOutput_type()
{    
	if(httpObject_type.readyState == 4)
	{         
		document.getElementById('div_price').innerHTML=httpObject_type.responseText;
	} 
}



function load_thumb(pic)
{ 
	httpObject_pic = getHTTPObject();    
	if (httpObject_pic != null) 
	{
		//alert(cat_id);
		httpObject_pic.open("GET", "ajax_files/load_thumb.php?pic="+pic, true);        
		httpObject_pic.send(null);         
		httpObject_pic.onreadystatechange = setOutput_pic;    
	}
}


function setOutput_pic()
{    
	if(httpObject_pic.readyState == 4)
	{         
		document.getElementById('thumb_preview').innerHTML=httpObject_pic.responseText;
	} 
}

function load_lineup(make)
{
		if(make=="mitsubishi")
		{
			document.getElementById("btn_1").innerHTML="<img border=\"0\" src=\"images/hyundark.png\" width=\"125\" height=\"48\" onclick=\"load_lineup('hyundai')\">";
			document.getElementById("btn_2").innerHTML="<img border=\"0\" src=\"images/mitlight.png\" width=\"125\" height=\"48\" onclick=\"load_lineup('mitsubishi')\">";
		}
		else
		{
			document.getElementById("btn_1").innerHTML="<img border=\"0\" src=\"images/hyunlight.png\" width=\"125\" height=\"48\" onclick=\"load_lineup('hyundai')\">";
			document.getElementById("btn_2").innerHTML="<img border=\"0\" src=\"images/mitsdark.png\" width=\"125\" height=\"48\" onclick=\"load_lineup('mitsubishi')\">";
		}

	httpObject_lineup = getHTTPObject();    
	if (httpObject_lineup != null) 
	{
		httpObject_lineup.open("GET", "load_lineup.php?make="+make, true);        
		httpObject_lineup.send(null);         
		httpObject_lineup.onreadystatechange = setOutput_lineup;    
	}
}


function setOutput_lineup()
{    
	if(httpObject_lineup.readyState == 4)
	{         
		document.getElementById('lineup_div').innerHTML=httpObject_lineup.responseText;
	} 
}

