function goDealer(objCmb){
	if(objCmb.value != ''){
		document.location =  objCmb.value;
	}
}


function getHomeModels(objComboManu){
	
	var objManuCombo = objComboManu;
	var objModelCombo = document.getElementById("model_select");
	var objModelDiv = document.getElementById("divModel");
	var objModelPlace = document.getElementById("model_place_holder");
	
	if(objManuCombo.value != ''){
			
			$.ajax({
				type: "POST",
				url: "get_data.php",
				data: "action=get_models&manu_id=" + objManuCombo.value,
				error: function(errorResponse){alert(errorResponse.statusText);},
				success: function(xmlReponseResult) {
					
					var objNewCmbModel = document.createElement('SELECT');
						objNewCmbModel.name = "model_select";
						objNewCmbModel.id = "model_select";
						//objNewCmbModel.onchange = function() { add_trim(this); }
						
						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++)
						{
							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 strDisText = modelYear + " " + modelName;
								/* To display values in drop down */
								objNewCmbModel.options[cnt+1] = new Option(strDisText, modelID);
								/* To check the db value with the dropdown value to display the option selected */
								//objOrgType.options[parseInt(cntOrgType)+1].selected = ( PosOrgType == arrOrgType[cntOrgType] ? true : false );
										/* For loop ends here */										
						}
					}
					
					objModelPlace.style.display = "none";
					objModelDiv.style.display = "";
					objModelCombo.parentNode.replaceChild(objNewCmbModel, objModelCombo);
					
				}
			});
	}
}


function getHomeTrims(objComboModel){

	var objModelCombo = objComboModel;
	var objTrimCombo = document.getElementById("style_select");
	var objTrimDiv = document.getElementById("spnTrim");
	var objTrimPlace = document.getElementById("trim_place_holder");

	if(objModelCombo.value != ''){
			$.ajax({
				type: "POST",
				url: "get_data.php",
				data: "action=get_trims&model_id=" + objModelCombo.value,
				error: function(errorResponse){alert(errorResponse.statusText);},
				success: function(xmlReponseResult) {
					var objNewCmbModel = document.createElement('SELECT');
						objNewCmbModel.name = "style_select";
						objNewCmbModel.id = "style_select";
						objNewCmbModel.onchange = function() { add_trim(this); }

						objNewCmbModel.options[0] = new Option('Select Style', '');

					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);
						}
					}
					
					//objTrimPlace.style.display = "none";
					objTrimDiv.style.display = "";
					objTrimCombo.parentNode.replaceChild(objNewCmbModel, objTrimCombo);
				}
			});
	}
}

function compare_model(){
	var objModels = document.getElementById("model_select");
	if(objModels.value == '') return;
	model_id = objModels.value;
	if(model_id != ''){
			$.ajax({
				type: "POST",
				url: NEW_STR_URL,
				data: "action=get_home_compare_url&model_id=" + model_id,
				error: function(errorResponse){alert(errorResponse.statusText);},
				success: function(xmlReponseResult) {
					window.location = xmlReponseResult;
				}
			});
	}
}

function add_trim(objTrimCombo){
	if (objTrimCombo.selectedIndex < 1) return;
	model_id = objTrimCombo.options[objTrimCombo.selectedIndex].value;
	if(model_id != ''){
			$.ajax({
				type: "POST",
				url: NEW_STR_URL,
				data: "action=get_home_compare_url&model_id=" + model_id,
				error: function(errorResponse){alert(errorResponse.statusText);},
				success: function(xmlReponseResult) {
					window.location = xmlReponseResult;
				}
			});
	}
	//document.location = '?action=add&trimID=' + style_id;
	//document.location = 'compare-cars/add/' + style_id;
}

function getQuoteModels(objComboManu){
	
	var objManuCombo = objComboManu;
	var objModelCombo = document.getElementById("quote_model_select");
	var objManuValue = objManuCombo.value;

	var arrManu = new Array();
	arrManu = objManuValue.split("#");

	var objManuId = arrManu[0];
	var objManuName = arrManu[1];
	
	if(objManuCombo.value != ''){
			
			$.ajax({
				type: "POST",
				url: "get_data.php",
				data: "action=get_quote_models&manu_id=" + objManuId,
				error: function(errorResponse){alert(errorResponse.statusText);},
				success: function(xmlReponseResult) {

					var objNewCmbModel = document.createElement('SELECT');
						objNewCmbModel.name = "quote_model_select";
						objNewCmbModel.id = "quote_model_select";
						objNewCmbModel.options[0] = new Option(' All Models ', 'new-cars/'+objManuName);

					if(xmlReponseResult.getElementsByTagName('modelID').item(0).firstChild.nodeValue != 'NO_RECORDS')
					{
						for(var cnt=0; cnt < xmlReponseResult.getElementsByTagName('modelID').length; cnt++)
						{
							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 opText = modelYear + " " + modelName;
							objNewCmbModel.options[cnt+1] = new Option(opText, strUrl);
						}
					}
					
					objModelCombo.parentNode.replaceChild(objNewCmbModel, objModelCombo);
				}
			});
	}
}

function goQuote(strCmb){
	objCmb = document.getElementById(strCmb);
	if(objCmb.value != ''){
		document.location = objCmb.value;
	}
}

function searchUsedCars(objForm){
	var strZipCode = objForm.txtZipCode.value
	strZipCode = strZipCode.toLowerCase();

	var objRegExp  = /(^-?\d\d*$)/;

	/*if(objForm.cmbUsedCarMake.value == ''){
		alert("Please select the manufacturer.");
		objForm.cmbUsedCarMake.focus();
	}else if(objForm.cmbModel.value == ''){
		alert("Please select the model.");
		objForm.cmbModel.focus();
	}*/
	if(objForm.txtZipCode.value == '' || objForm.txtZipCode.value == '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 getUsedCarsModels(objComboManu){
	var objManuCombo = objComboManu;
	var objModelCombo = document.getElementById("cmbModel");
	
	if(objManuCombo.value != ''){
			
			$.ajax({
				type: "POST",
				url: "get_data.php",
				data: "action=get_old_models&manu_name=" + objManuCombo.value,
				error: function(errorResponse){alert(errorResponse.statusText);},
				success: function(xmlReponseResult) {
					
					var objNewCmbModel = document.createElement('SELECT');
						objNewCmbModel.name = "cmbModel";
						objNewCmbModel.id = "cmbModel";
						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;
							objNewCmbModel.options[cnt+1] = new Option(modelName, modelName);
						}
					}
					objModelCombo.parentNode.replaceChild(objNewCmbModel, objModelCombo);
				}
			});
	}
}

function popularCarDetail(manuID, modelID, Year, divId, total, curSelection)
{
	var objSelectedId = document.getElementById(divId);

	for(var i=1; i<=total; i++)
	{
		var objDiv = document.getElementById('popular_'+i);
		objDiv.className = 'normalText';
		document.getElementById("shortName_"+i).innerHTML = document.getElementById("hidshortName_"+i).value;
	}

	objSelectedId.className = 'selectedTab';

	$.ajax({
				type: "POST",
				url: "get_data_new.php",
				data: "action=get_popular_car_details&manuID=" + manuID + "&modelID=" + modelID + "&year=" + Year,
				error: function(errorResponse){alert(errorResponse.statusText);},
				success: function(strReponseResult) {
					$("#popularDetail").html(strReponseResult);
					//document.getElementById("fullCarName").innerHTML = document.getElementById("hidFullName_"+curSelection).value;
				}
		});
		
		document.getElementById("shortName_"+curSelection).innerHTML = document.getElementById("hidFullName_"+curSelection).value;
}