function getxmlhttp()
{	
	var xmlhttp = false;	
	try{
		xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
	} catch(e) {
		try{
			xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
		}catch(E) {
			xmlhttp = false;
		}
	}
	if(!xmlhttp && typeof XMLHttpRequest != 'undefined'){
		xmlhttp = new XMLHttpRequest();
	}
	return xmlhttp;
}
function processajax (obj, serverPage)
{
	var theimg;
	xmlhttp = getxmlhttp();
    xmlhttp.open("GET",serverPage);
	xmlhttp.onreadystatechange = function()
	{
		if(xmlhttp.readyState == 4 && xmlhttp.status == 200)
		{
			document.getElementById(obj).innerHTML = xmlhttp.responseText;
		}
	}
	xmlhttp.send(null);
	
}

function runAjax(objID, serverPage)
{
	var xmlhttp = false;	
	try{
		xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
	} catch(e) {
		try{
			xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
		}catch(E) {
			xmlhttp = false;
		}
	}
	if(!xmlhttp && typeof XMLHttpRequest != 'undefined'){
		xmlhttp = new XMLHttpRequest();
	}

	xmlhttp.open("GET", serverPage);
	xmlhttp.onreadystatechange = function()
	{
		if(xmlhttp.readyState == 4 && xmlhttp.status == 200)
		{
			document.getElementById(objID).innerHTML = xmlhttp.responseText;
		}
	}
	xmlhttp.send(null);
}

function updateStatus(divID)
{
	document.getElementById(divID).innerHTML = "<b>Processing....</b>";
}

var refreshrate = 1000;
function refreshView(divID,serverPage)
{
	var command = 'runAjax ("' + divID + '","' + serverPage + '")';
	updateStatus(divID);
	setTimeout (command, refreshrate);
}

function submitForm(theform,divID,serverPage)
{
	updateStatus(divID);
	theform.submit;	
	refreshView(divID,serverPage);
}
function updateDiv(divID,serverPage)
{
	updateStatus(divID);
	refreshView(divID,serverPage);
}
function jsGet(type)
{
	if(location.href.match(type))
	{
		return location.href.split(type+'=')[1].split('&')[0];
	}
	else
	{
		return 'FALSE';
	}
}
function processSelect(frm,serverPage)
{
	var selectElements = ['vehicle_year','make','model'];	
	var frmName = document.getElementById(frm);	
	var frmElements = frmName.elements;
	for(i=0;i<selectElements.length;i++)
	{
		var frmTargetSelect = frmElements[selectElements[i]];
		frmTargetSelect.options.length = 0;
		frmTargetSelect.options[0] = new Option('Loading...','All');
	}
	var command = 'updateSelect ("' + frm + '","' + serverPage + '")';

	setTimeout (command, refreshrate);
}

function updateSelect(frm,serverPage)
{
	var xmlhttp = false;
	
	try
	{
		xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
	} 
	catch(e) 
	{
		try
		{
			xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
		}
		catch(E) 
		{
			xmlhttp = false;
		}
	}
	if(!xmlhttp && typeof XMLHttpRequest != 'undefined')
	{
		xmlhttp = new XMLHttpRequest();
	}
	//alert(serverPage);
	xmlhttp.open("GET", serverPage);
	xmlhttp.onreadystatechange = function()
	{
		if(xmlhttp.readyState == 4 && xmlhttp.status == 200)
		{			
			var response_content = xmlhttp.responseText;			
			var exploded_arrays = response_content.split("||");
			
			//alert(exploded_arrays);
			
			//var selectElements = ['_condition','vehicle_year','make','model'];
			var selectElements = ['vehicle_year','make','model'];	
			var frmName = document.getElementById(frm);
			var frmElements = frmName.elements;			
			//var frmTargetSelect = frmElements[selectElements[x]]; 				
			//frmTargetSelect.options.length = 0;
			//frmTargetSelect.options.length = exploded_content.length;
			//alert(exploded_arrays.length);
			for (x=0; x < exploded_arrays.length; x++)
			{
				//alert(exploded_arrays[x]);
				var exploded_content = exploded_arrays[x].split(",");
				
				frmTargetSelect = frmElements[selectElements[x]]; 				
				//frmTargetSelect.options.length = 0;
				frmTargetSelect.options.length = exploded_content.length-1;
								
				var selectedValue = exploded_content[0];
				for (y=1; y < exploded_content.length; y++)
				{
					//if(jsGet(selectElements[x])==exploded_content[y])
					if(selectedValue==exploded_content[y])
					{
						var selectTrue = true;
					}
					else
					{
						var selectTrue = false;	
					}
					frmTargetSelect.options[y-1] = new Option(exploded_content[y],exploded_content[y],false,selectTrue);
				}
				if(selectElements[x]=='make' && selectedValue == 'All')
				{
					frmName.model.disabled = true;
				}
				else
				{
					frmName.model.disabled = false;
				}
			}
		}
	}
	xmlhttp.send(null);
}