function rePopulate(objForm, strCurrent, strNextSelected)
{
	var arrNextDropDown = new Array("Model")
	strValue= eval('objForm.cmb' + strCurrent +' .value');

	strParams = "type="+strCurrent+"&value="+strValue;

	$.ajax(
	{
		url: HTTP_JS_SERVER + 'used-cars/search_data',
		type: 'POST',
		data: strParams,
		timeout: 6000,
		error: function(strReponseResult){},
		success: function(strReponseResult)
		{

			var arrResponse = new Array();
			var arrOptions = new Array();
			arrResponse = strReponseResult.split("~^~");
			arrOptions = arrResponse[0].split(',');
			var strType = arrResponse[1];

			refDropDown = eval('objForm.cmb' + strType);
			var newDropDown = document.createElement('select');
				newDropDown.name = 'cmb'+strType;
				newDropDown.id = 'cmb'+strType;
				newDropDown.style.width="100px";
				
				if( strType != "Year" ) 
				{
					newDropDown.onchange = function() { rePopulate(objForm, strType, ''); }
				}			
				
				newDropDown.options[0] = new Option('All ' + strType+'s', '');
				for(cntOpt=0; cntOpt < arrOptions.length; cntOpt++ )
				{
					if( arrOptions[cntOpt] != "" )
					{
						newDropDown.options[parseInt(cntOpt)+1] = new Option(arrOptions[cntOpt], arrOptions[cntOpt]);
						newDropDown.options[parseInt(cntOpt)+1].selected = ( arrOptions[cntOpt] == strNextSelected ? true : false );
					}
				}

		refDropDown.parentNode.replaceChild(newDropDown, refDropDown);
		
		}
	}
	);
}

function submitSearch(objForm)
{
	var strZipCode = objForm.txtZipCode.value
	strZipCode = strZipCode.toLowerCase();

	var objRegExp  = /(^-?\d\d*$)/;

	if(strZipCode == '' || strZipCode == 'zip code'){
		alert("Please enter proper zip code.");
		objForm.txtZipCode.focus();
	}
	else if(!objRegExp.test(strZipCode)){
		alert("Only numerics allowed in zipcode.");
		objForm.txtZipCode.value = '';
		objForm.txtZipCode.focus();
	}else
	{
		objForm.submit();
	}
}

function rePopulateNew(objForm, strCurrent, strNextSelected)
{
	var arrNextDropDown = new Array("Model")
	strValue= eval('objForm.cmb' + strCurrent +' .value');

	strParams = "type="+strCurrent+"&value="+strValue;

	$.ajax(
	{
		url: HTTP_JS_SERVER + 'used-cars/search_data',
		type: 'POST',
		data: strParams,
		timeout: 6000,
		error: function(strReponseResult){},
		success: function(strReponseResult)
		{

			var arrResponse = new Array();
			var arrOptions = new Array();
			arrResponse = strReponseResult.split("~^~");
			arrOptions = arrResponse[0].split(',');
			var strType = arrResponse[1];

			refDropDown = eval('objForm.cmb' + strType);
			var newDropDown = document.createElement('select');
				newDropDown.name = 'cmb'+strType;
				newDropDown.id = 'cmb'+strType;
				newDropDown.style.width="100px";
				
				if( strType != "Year" ) 
				{
					//newDropDown.onchange = function() { rePopulate(objForm, strType, ''); }
				}			
				
				newDropDown.options[0] = new Option('All', '');
				for(cntOpt=0; cntOpt < arrOptions.length; cntOpt++ )
				{
					if( arrOptions[cntOpt] != "" )
					{
						newDropDown.options[parseInt(cntOpt)+1] = new Option(arrOptions[cntOpt], arrOptions[cntOpt]);
						newDropDown.options[parseInt(cntOpt)+1].selected = ( arrOptions[cntOpt] == strNextSelected ? true : false );
					}
				}

		refDropDown.parentNode.replaceChild(newDropDown, refDropDown);
		
		}
	}
	);
}