function restore_zip_text(el)
{
	if (el.value == '') el.value = 'Zip Code';
}

function clear_zip_text(el)
{
	if (el.value == 'Zip Code') el.value = '';
}

function sendQuickQuote(objForm){
	if(objForm.quick_quote_division.value != '' && objForm.quick_quote_model.value != ''&& objForm.quick_quote_style.value != '' ){
		//location.href = "/new_cars.php?manu=&"+ objForm.quick_quote_division.value +"model="+ objForm.quick_quote_model.value +"&trim="+ objForm.quick_quote_style.value;
		objForm.submit();
	}
}


function getModels(objComboManu){

	var objManuCombo = objComboManu;
	var objModelCombo = document.getElementById("quick_quote_model");
	
	if(objManuCombo.value != ''){
			
			$.ajax({
				type: "POST",
				url: STR_URL,
				data: "action=get_models&manu_id=" + objManuCombo.value,
				error: function(errorResponse){alert(errorResponse.statusText);},
				success: function(xmlReponseResult) {
						
					var objNewCmbModel = document.createElement('SELECT');
						objNewCmbModel.name = "quick_quote_model";
						objNewCmbModel.id = "quick_quote_model";
						objNewCmbModel.onchange = function() { getTrims(this); }



						/* To display the first option of the drop down */
						objNewCmbModel.options[0] = new Option('Select Model', '');

					if(xmlReponseResult.getElementsByTagName('modelID').item(0).firstChild.nodeValue != 'NO_RECORDS')
					{
						for(var cnt=0; cnt < xmlReponseResult.getElementsByTagName('modelID').length; cnt++)
						{
							/* To assign values to variables from response xml tags */
							var modelID = xmlReponseResult.getElementsByTagName('modelID').item(cnt).firstChild.nodeValue;
							var modelName = xmlReponseResult.getElementsByTagName('modelName').item(cnt).firstChild.nodeValue;
							var modelYear = xmlReponseResult.getElementsByTagName('modelYear').item(cnt).firstChild.nodeValue;
							var strDisplay = modelYear + " " + modelName;

							objNewCmbModel.options[cnt+1] = new Option(strDisplay, modelID);									
						}
					}

					objModelCombo.parentNode.replaceChild(objNewCmbModel, objModelCombo);
				}
			});
	}
}

function getTrims(objComboModel){

	var objModelCombo = objComboModel;
	var objTrimCombo = document.getElementById("quick_quote_style");

	if(objModelCombo.value != ''){
			$.ajax({
				type: "POST",
				url: STR_URL,
				data: "action=get_trims&model_id=" + objModelCombo.value,
				error: function(errorResponse){alert(errorResponse.statusText);},
				success: function(xmlReponseResult) {
					var objNewCmbModel = document.createElement('SELECT');
						objNewCmbModel.name = "quick_quote_style";
						objNewCmbModel.id = "quick_quote_style";

						objNewCmbModel.options[0] = new Option('Select Trim', '');

					if(xmlReponseResult.getElementsByTagName('trimID').item(0).firstChild.nodeValue != 'NO_RECORDS')
					{
						for(var cnt=0; cnt < xmlReponseResult.getElementsByTagName('trimID').length; cnt++)
						{
							var trimID = xmlReponseResult.getElementsByTagName('trimID').item(cnt).firstChild.nodeValue;
							var trimName = xmlReponseResult.getElementsByTagName('trimName').item(cnt).firstChild.nodeValue;

								objNewCmbModel.options[cnt+1] = new Option(trimName, trimID);
						}
					}
					objTrimCombo.parentNode.replaceChild(objNewCmbModel, objTrimCombo);
				}
			});
	}
}


function getHeaderModels(objComboManu){
	var objManuCombo = objComboManu;
	var objModelCombo = document.getElementById("quick_quote_model_header");
	
	if(objManuCombo.value != ''){
			
			$.ajax({
				type: "POST",
				url: STR_URL,
				data: "action=get_quote_models&manu_id=" + objManuCombo.value,
				error: function(errorResponse){alert(errorResponse.statusText);},
				success: function(xmlReponseResult) {
						
					var objNewCmbModel = document.createElement('SELECT');
						objNewCmbModel.name = "quick_quote_model_header";
						objNewCmbModel.id = "quick_quote_model_header";
						objNewCmbModel.style.width = "150px";
						//objNewCmbModel.onchange = function() { sendQuickQuoteHeader(this); }



						/* To display the first option of the drop down */
						objNewCmbModel.options[0] = new Option('Select Model', '');

					if(xmlReponseResult.getElementsByTagName('modelID').item(0).firstChild.nodeValue != 'NO_RECORDS')
					{
						for(var cnt=0; cnt < xmlReponseResult.getElementsByTagName('modelID').length; cnt++)
						{
							/* To assign values to variables from response xml tags */
							var modelID = xmlReponseResult.getElementsByTagName('modelID').item(cnt).firstChild.nodeValue;
							var modelName = xmlReponseResult.getElementsByTagName('modelName').item(cnt).firstChild.nodeValue;
							var modelYear = xmlReponseResult.getElementsByTagName('modelYear').item(cnt).firstChild.nodeValue;
							var strUrl = xmlReponseResult.getElementsByTagName('modurl').item(cnt).firstChild.nodeValue;
							var strDisplay = modelYear + " " + modelName;

							objNewCmbModel.options[cnt+1] = new Option(strDisplay, strUrl);									
						}
					}

					objModelCombo.parentNode.replaceChild(objNewCmbModel, objModelCombo);
				}
			});
	}
}

function getHeaderTrims(objComboModel){

	var objModelCombo = objComboModel;
	var objTrimCombo = document.getElementById("quick_quote_style_header");

	if(objModelCombo.value != ''){
			$.ajax({
				type: "POST",
				url: STR_URL,
				data: "action=get_trims&model_id=" + objModelCombo.value,
				error: function(errorResponse){alert(errorResponse.statusText);},
				success: function(xmlReponseResult) {
					var objNewCmbModel = document.createElement('SELECT');
						objNewCmbModel.name = "quick_quote_style_header";
						objNewCmbModel.id = "quick_quote_style_header";

						objNewCmbModel.options[0] = new Option('Select Trim', '');

					if(xmlReponseResult.getElementsByTagName('trimID').item(0).firstChild.nodeValue != 'NO_RECORDS')
					{
						for(var cnt=0; cnt < xmlReponseResult.getElementsByTagName('trimID').length; cnt++)
						{
							var trimID = xmlReponseResult.getElementsByTagName('trimID').item(cnt).firstChild.nodeValue;
							var trimName = xmlReponseResult.getElementsByTagName('trimName').item(cnt).firstChild.nodeValue;

								objNewCmbModel.options[cnt+1] = new Option(trimName, trimID);
						}
					}
					objTrimCombo.parentNode.replaceChild(objNewCmbModel, objTrimCombo);
				}
			});
	}
}

function sendQuickQuoteHeader(strCombo){
	var objCombo = document.getElementById(strCombo);
	if(objCombo.value != ''){
		location.href = HTTP_JS_SERVER + objCombo.value +'';
	}
}

function getHeaderUsedCarsModels(objComboManu){
	var objManuCombo = objComboManu;
	var objModelCombo = document.getElementById("quick_quote_used_model_header");
	var strParams = "action=get_old_models&manu_name=" + objManuCombo.value;
	if(objManuCombo.value != ''){
			
			$.ajax({
				type: "POST",
				url: HTTP_JS_SERVER + "get_data.php",
				data: strParams,
				error: function(errorResponse){alert(errorResponse.statusText);},
				success: function(xmlReponseResult) {
					
					var objNewCmbModel = document.createElement('SELECT');
						objNewCmbModel.name = "quick_quote_used_model_header";
						objNewCmbModel.id = "quick_quote_used_model_header";
						objNewCmbModel.style.width="100px";

						objNewCmbModel.options[0] = new Option('All Models', '');

					if(xmlReponseResult.getElementsByTagName('modelName').item(0).firstChild.nodeValue != 'NO_RECORDS')
					{
						for(var cnt=0; cnt < xmlReponseResult.getElementsByTagName('modelName').length; cnt++)
						{
							var modelName = xmlReponseResult.getElementsByTagName('modelName').item(cnt).firstChild.nodeValue;
							var strDisText = modelName;
							var strKeyText = modelName;
							objNewCmbModel.options[cnt+1] = new Option(strDisText, strKeyText);
						}
					}
					objModelCombo.parentNode.replaceChild(objNewCmbModel, objModelCombo);
				}
			});
	}
}

function headerSearchUsedCars(objForm){

	var strZipCode = objForm.txtZipCode.value
	strZipCode = strZipCode.toLowerCase();

	var objRegExp  = /(^-?\d\d*$)/;

	/*if(objForm.quick_quote_used_division_header.value == ''){
		alert("Please select the manufacturer.");
		objForm.quick_quote_used_division_header.focus();
	}else if(objForm.quick_quote_used_model_header.value == ''){
		alert("Please select the model.");
		objForm.quick_quote_used_model_header.focus();
	}*/
	if(strZipCode == '' || strZipCode == 'zip code'){
		alert("Please enter proper zip code.");
		objForm.txtZipCode.focus();
	}else if(!objRegExp.test(strZipCode)){
		alert("Only numerics allowed in zip code.");
		objForm.txtZipCode.value = '';
		objForm.txtZipCode.focus();
	}else{
		objForm.submit();
	}
}

function usedCarSelect()
{
	$('#divUsedCar').show();
	$('#divNewCar').hide();
	objNewCarDiv = document.getElementById("headNewCar");
	objNewCarDiv.className = 'pad10 newPlain newBlueBg';
	objNewCarDiv = document.getElementById("headUsedCar");
	objNewCarDiv.className = 'pad10 newPlain';
}

function newCarSelect()
{
	$('#divNewCar').show();
	$('#divUsedCar').hide();
	objNewCarDiv = document.getElementById("headUsedCar");
	objNewCarDiv.className = 'usedBlueBg';
	objNewCarDiv = document.getElementById("headNewCar");
	objNewCarDiv.className = 'pad10 newPlain';
}