
function gotoLocation() {
	var frm_width =document.getElementById("tireWidthId");
	var frm_diameter =document.getElementById("tireDiameterId");
	var frm_ratio =document.getElementById("tireRatioId");
	if(frm_width.value == "Select width" || frm_diameter.value == "Select diameter") {
		alert("Please choose the size before submit. Only the tire width and the diameter are required. The ratio is not required.");
	} else {
		document.getElementById("hidModeId").value="forwardSize";
		var width=frm_width.value;
		var raio= frm_ratio.value;
		var ratio_select= frm_ratio.value;
		var diameter= frm_diameter.value;
		var tireSizes;

		if(ratio_select.indexOf("/") != -1) {
			var ratioLen =ratio_select.length;
			ratio_select= ratio_select.substring(1,ratioLen);
			tireSizes=width+"-"+ratio_select+"-"+diameter;
		} else if(ratio_select=="Select ratio") {
			tireSizes=width+"-"+diameter;
		} else {
			tireSizes=width+"-"+ratio_select+"-"+diameter;
		}

		document.fitmentForm.tireFitment.value='true';
		document.fitmentForm.vehicleFitment.value='false';
		document.fitmentForm.submit();
	}
}



function initFitment()
{
  var frm_cName =document.getElementById("cName");	
 $('body').append('<div id="loadImg" style="display:none;"></div>');	
  renderYearList();
  if(frm_cName.value == 'Tires'){
  	renderTireList();
  	resetTireValues();
  }
  resetValues();
  if(onloadPreFitment) onloadPreFitment();
}  
/* if already set*/
onloadPreFitment = window.onload; 
onload = initFitment;

function loadVehicleOptions(requestType)
{
	var frm =document.fitmentForm;
	var frm_year =document.getElementById("yearId");
	var frm_make =document.getElementById("makeId");
	var frm_model =document.getElementById("modelId");
	var frm_cName =document.getElementById("cName");
	var requestType=document.getElementById("requestType");
		var url_Auto="";	
	if (requestType.value=='https')
	{
	    url_Auto='GetEnginesCmdHTTPS';
	}
	 else   
	 {
		url_Auto='GetEnginesCmdHTTP';					
	  }	
	url_Auto +="?storeId=10153&catalogId=12605&mode=engine&caller=ajax";
	url_Auto +="&year="+frm_year.value;
	url_Auto +="&model="+encodeURIComponent(frm_model.value);
	url_Auto +="&make="+encodeURIComponent(frm_make.value);
	url_Auto +="&category="+encodeURIComponent(frm_cName.value);
	
		bodyPreloaderAuto("#engineOption1");
	
	document.getElementById('engineOption').innerHTML="";
	var optionHtml=""; // Assigning default value to engineoption1
	optionHtml=optionHtml + " <select id='engineId' name='engine'>";
	optionHtml=optionHtml + "<option value='Select Engine'>Choose...</option>";
    optionHtml=optionHtml + " </select>"
    document.getElementById('engineOption1').innerHTML=optionHtml;	 
	// Code to disable the engine drop down	
	document.getElementById("engineId").disabled = true;
	
	// Make the Ajax call using JSON
	$.ajaxSetup( {
				error : errorFunction,
				type: "POST"
			});
		 request =$.getJSON(url_Auto,getAllJsonEngines);
		
				function errorFunction(jsonData) {
				// Call function to show error popup
					removeCurtainAuto();
		}

	/* Retreive the engines array from the json response */	
		function getAllJsonEngines(jsonData){
			
			var optionHTML="";
			var inoptionHTML="";
			optionHTML+="<select name='engine' property='engine' styleId='engineId'>";
			optionHTML+= "<option value='Select Engine'>Choose...</option>";
			var engineOptionRec1=document.getElementById('engineOption1');
			var engineOptionRec=document.getElementById('engineOption');
				var optionTypesLen  =jsonData.engines.length;
			if(optionTypesLen >0) 
			{
				var optionName;
				var optionValue;
				for(var i=0; i<optionTypesLen; i++) {
					    
						optionName  = jsonData.engines[i].eng;
						optionValue = jsonData.engines[i].eng;
						
					inoptionHTML= inoptionHTML+"<option value='" +optionValue+"'>"+optionName+"</option>";
				}
				optionHTML=optionHTML+inoptionHTML+"</select>";
				engineOptionRec1.innerHTML=optionHTML;   
			}

			removeCurtainAuto();
		}
		
}
	
	  function compare(modelArray,modelValue){
	var currModel;
	modelValue=modelValue.replace(/ /gi,"");
		var matchedModel=null;
	for (var i=0;i<modelArray.length;i++)
	{
			
		currModel=modelArray[i];
		result=currModel.replace(/ /gi,"");
		if(result == modelValue)
			{
				matchedModel=currModel;
				break;
 			}
 	}
 	
	return matchedModel;
}
function bodyPreloaderAuto(option){   
	offsetPos = $(option).offset();
	$("div#loadImg").css({ left:offsetPos.left+162 , top:offsetPos.top-3, position:'absolute'}).show();
}
function removeCurtainAuto() {
	$("div#loadImg").hide(0);   
}
	
