
var tochange = '';
var defaultValue = '';
var tireSelector_language = 'English';
var uri='$AJAX_URL';
	
var year, make, model, options, tireSize;
var size, width, aspectratio, diameter;
var name, category;	
var flag=null;
var count=0;

$(document).ready(function() {$('#'+'sizeajaxloadersize').hide();
 $('#'+'sizeajaxloadername').hide();  
  $('#'+'sizeajaxloadervehicle').hide();  
   $('#'+'sizeajaxloadercategory').hide();  
 
 
	$('#btn_explore').show();

	$(".icon_help, .helplinks").addClass('clickable').click(function(e) {
	var sizeofTooltip = (($(this).attr('alt').length < 200 ) ? ($(this).attr('alt').indexOf("img") > 0 ? '300px' : '180px') : ('300px'));
	var hardCodeSizeAspectRatio = $(this).attr('alt').indexOf("R2-aspect.png");
	var hardCodeTireSize = $(this).attr('alt').indexOf("R2-Size.png");
	
		$("div.tooltip_widget").show().css({
				position:'absolute',
				top: (e.pageY-190)+'px',
				left:(e.pageX-220)+'px',
				width: sizeofTooltip
			}).children('span').eq(0).html($(this).attr('alt').split('\n').join('<br />'));
			if(sizeofTooltip!="180px")
				{
					
					$("div.tooltip_widget span").find("div").css({
					width:"308px",
					'text-align':'center'
					});
				}
			if(hardCodeSizeAspectRatio>0)
			{
				$("div.tooltip_widget").css("top","258px")
			}
			if(hardCodeTireSize>0)
			{
				$("div.tooltip_widget").css("top","258px")
			}
			return false;
	});
$("div.tooltip_widget img").addClass('clickable').click(function(event) {
		$("div.tooltip_widget").hide();
		event.stopPropagation();
	});
	$("#find_vehicle_submit").hide();
	$("#find_size_submit").hide();
	$("#find_name_submit").hide();
	$("#find_category_submit").hide();
	
/*	searchType = $("#searchType").val();
	$('#printLink').attr("onClick","fnOpenPrintWindow($('#printPageName').val());");
 
  
	if(searchType != null || searchType != '')
	{
		if(searchType =='vehicle')
		{
			/*$('ul.tabs li#search_by_vihicle a').addClass("active");
			$('ul.tabs li#search_by_size a').removeClass("active");
			$('ul.tabs li#search_by_name a').removeClass("active");
			$('ul.tabs li#search_by_category a').removeClass("active");
			
			$("#tab_vehicle").show();
			$("#tab_size").hide();
			$("#tab_name").hide();
			$("#tab_category").hide();
			year = $("#yearVal").val();
			make = $("#makeVal").val();
			model = $("#modelVal").val();
			options = $("#optionVal").val();
			toChange = 'year';
			fnSetDDL(toChange,year);
		}
		else if(searchType =='size')
		{
			$('ul.tabs li#search_by_vihicle a').removeClass("active");
			$('ul.tabs li#search_by_size a').addClass("active");
			$('ul.tabs li#search_by_name a').removeClass("active");
			$('ul.tabs li#search_by_category a').removeClass("active");
			
			//$("#vehicle_tab").hide();
			//$("#tire_size_tab").show();
			//$("#tire_name_tab").hide();
			//$("#tire_category_tab").hide();
			
			size = $("#typeVal").val();
			width = $("#widthVal").val();
			aspectratio = $("#aspectVal").val();
			diameter = $("#rimVal").val();
			toChange = 'size';
			fnSetDDL(toChange,size);
			
		}
		else if(searchType =='name')
		{
			$('ul.tabs li#search_by_vihicle a').removeClass("active");
			$('ul.tabs li#search_by_size a').removeClass("active");
			$('ul.tabs li#search_by_name a').addClass("active");
			$('ul.tabs li#search_by_category a').removeClass("active");
			
			//$("#vehicle_tab").hide();
			//$("#tire_size_tab").hide();
			//$("#tire_name_tab").show();
			//$("#tire_category_tab").hide();
			
			name = $("#nameVal").val();
			toChange = 'name';
			fnSetDDL(toChange,name);
			
		}
		else if(searchType =='category')
		{
			$('ul.tabs li#search_by_vihicle a').removeClass("active");
			$('ul.tabs li#search_by_size a').removeClass("active");
			$('ul.tabs li#search_by_name a').removeClass("active");
			$('ul.tabs li#search_by_category a').addClass("active");
			
			//$("#vehicle_tab").hide();
			//$("#tire_size_tab").hide();
			//$("#tire_name_tab").hide();
			//$("#tire_category_tab").show();
			category = $("#categoryVal").val();
			toChange = 'category';
			fnSetDDL(toChange,category);
		}
		
		
	}*/
	if($.cookie('type') != null || $.cookie('type') != '')
	{

		if($.cookie('type') =='vehicle')
		{
        $('.tire_module').hide(); $('.tire-tab').removeClass("selected"); $('#tire_vehicle').fadeIn(); $('#tab_vehicle').addClass("selected");
			year = $.cookie('year');
			make = $.cookie('make');
			model = $.cookie('model');
			options = $.cookie('options');
			tireSize = $.cookie('tireSize');
			toChange = 'year';
			fnSetDDL(toChange,year);
			
			document.getElementById('find_vehicle_button_id').style.display='block';
			document.getElementById('find_category_button_id').style.display='none';
			document.getElementById('find_name_button_id').style.display='none';
			document.getElementById('find_size_button_id').style.display='none';
		}
		else if($.cookie('type') =='size')
		{
//removeFifthDropdown();
$('.tire_module').hide(); $('.tire-tab').removeClass("selected"); $('#tire_size').fadeIn(); $('#tab_size').addClass("selected");
		
			size = $.cookie('size');
			width = $.cookie('width');
			aspectratio = $.cookie('aspectratio');
			diameter = $.cookie('diameter');
			toChange = 'size';
			fnSetDDL(toChange,size);
			
			document.getElementById('find_vehicle_button_id').style.display='none';
			document.getElementById('find_category_button_id').style.display='none';
			document.getElementById('find_name_button_id').style.display='none';
			document.getElementById('find_size_button_id').style.display='block';
			
		}
		else if($.cookie('type') =='name')
		{

		//removeFifthDropdown();
		$('.tire_module').hide(); $('.tire-tab').removeClass("selected"); $('#tire_name').fadeIn(); $('#tab_name').addClass("selected");
		
			name = $.cookie('name');
			toChange = 'name';
			fnSetDDL(toChange,name);
			
			document.getElementById('find_vehicle_button_id').style.display='none';
			document.getElementById('find_category_button_id').style.display='none';
			document.getElementById('find_name_button_id').style.display=' block' ;
			document.getElementById('find_size_button_id').style.display='none';
			
		}
		else if($.cookie('type') =='category')
		{
          //removeFifthDropdown();
		  $('.tire_module').hide(); 
		  $('.tire-tab').removeClass("selected");
		  $('#tire_category').fadeIn(); 
		  $('#tab_category').addClass("selected");
		
			category = $.cookie('category');
			toChange = 'category';
			fnSetDDL(toChange,category);
			
			document.getElementById('find_vehicle_button_id').style.display='none';
			document.getElementById('find_category_button_id').style.display='block';
			document.getElementById('find_name_button_id').style.display='none';
			document.getElementById('find_size_button_id').style.display='none';
		}
		
		
	}
	
		if($.fixIESelectWidth) $("select").fixIESelectWidth();	  
	 });
	 
function fnSetDDL(toChange, value)
{

var onChange = toChange;
	for(var i=0;i<document.getElementById(onChange).length;i=i+1)
	{
		var ddlText=document.getElementById(onChange).options[i].value;
		txtText=value;
		if(ddlText==txtText)
		{
		document.getElementById(onChange).selectedIndex=i;
		break;
		}
	}
	$("#"+onChange).change();

}


function populateDropDowns(temp) {
	if (temp == "year")
	{
		var yearValue = document.getElementById('year').value;
	    var year = $.cookie('year');
		if(yearValue != year){
			make = "";
			//if(year != null){
			removeFifthDropdown();
			$.cookie('tireSizeFlag', null,{path: '/' });
			flag=null;//}
		}
		
		$("#find_vehicle_submit").hide();
		$("#go_wrap").show();
			
		if(yearValue != '-1')
		{	
			$("#make, #model, #options,#tireSize").html('');
			$("#width, #aspectratio, #diameter").html('');
			fnSetDDL("size","-1");
			fnSetDDL("category","-1");
			fnSetDDL("name","-1");
			tochange = 'make';
			defaultValue = 'choose_a_make';
			temp=temp+"&yearValue="+yearValue;
                ajaxCall(temp);
		}
		else {
			document.getElementById('wrapmake').innerHTML="";	
			document.getElementById('wrapmodel').innerHTML="";	
			document.getElementById('wrapoptions').innerHTML="";
			document.getElementById('wrapwidth').innerHTML="";	
			document.getElementById('wrapaspectratio').innerHTML="";	
			document.getElementById('wrapdiameter').innerHTML="";
		}
		
	//	}
	}
	if(temp == "make")
	{
		var yearValue = document.getElementById('year').value;
		var makeValue = document.getElementById('make').value;	
		
			if(makeValue != make){
				model = "";
				removeFifthDropdown();
					$.cookie('tireSizeFlag', null,{path: '/' });
					flag=null;//}
			}
		
		$("#model,#options").html('');
		$("#find_vehicle_submit").hide();
		$("#go_wrap").show();
		
		if(makeValue != '-1'){	
			tochange = 'model';
			defaultValue = 'choose_a_model';
			makeValue = escape(makeValue);
			temp=temp+"&yearValue="+yearValue+"&makeValue="+makeValue;
			ajaxCall(temp);
		}
		else {
			document.getElementById('wrapmodel').innerHTML="";	
			document.getElementById('wrapoptions').innerHTML="";			
			
			}

	}
	if(temp == "model")
	{
		var yearValue = document.getElementById('year').value;
		var makeValue = document.getElementById('make').value;
		var modelValue = document.getElementById('model').value;
		
		
			if(modelValue != model){
	
			options = "";
			removeFifthDropdown();
					$.cookie('tireSizeFlag', null,{path: '/' });
					flag=null;
		         }

	
	
		$("#options").html('');
		

			$("#find_vehicle_submit").hide();
			$("#go_wrap").show();
		if(modelValue != '-1'){	
			tochange = 'options';
			defaultValue = 'choose_an_option';
			makeValue = escape(makeValue);
		modelValue = escape(modelValue);
		
			
			temp=temp+"&yearValue="+yearValue+"&makeValue="+makeValue+"&modelValue="+modelValue;
			ajaxCall(temp);
		}
		else{
		document.getElementById('wrapoptions').innerHTML="";	
		}
		
	
	}
	if(temp == "options")
	{
		var yearValue = document.getElementById('year').value;
		var makeValue = document.getElementById('make').value;
		var modelValue = document.getElementById('model').value;
		var optionValue = document.getElementById('options').value;
		
		
			if(optionValue != options){
	
				tireSize = "";
				removeFifthDropdown();
					$.cookie('tireSizeFlag', null,{path: '/' });
					flag=null;//}
			      }

		
		
		if(optionValue != '-1'){
				tochange = 'tireSize';
				defaultValue = 'choose_a_tire_size';
				//makeValue = customReplace(makeValue," ","+");
			    //modelValue = customReplace(modelValue," ","+");
				//optionValue = customReplace(optionValue," ","+");
				//makeValue = customReplace(makeValue,"&","%26");
			   // modelValue = customReplace(modelValue,"&","%26");
			    makeValue = escape(makeValue);
			    modelValue = escape(modelValue);
				optionValue = escape(optionValue);
				temp=temp+"&yearValue="+yearValue+"&makeValue="+makeValue+"&modelValue="+modelValue+"&optionValue="+optionValue;
				
				ajaxCall(temp);
		}
		else{
		
		document.getElementById('wraptireSize').innerHTML="";	
		}
		

	}
	if(temp == "size")
	{
		var sizeTypeValue= document.getElementById('size').value;	
		if(sizeTypeValue != '-1'){
			if(sizeTypeValue != size){
			width = "";
		           }

		
			$("#width, #aspectratio, #diameter").html('');
			$("#make, #model, #options,#tireSize").html('');
			document.getElementById('wrapmake').innerHTML="";	
			document.getElementById('wrapmodel').innerHTML="";	
			document.getElementById('wrapoptions').innerHTML="";
			fnSetDDL("year","-1");
			fnSetDDL("category","-1");
			fnSetDDL("name","-1");
			$("#find_size_submit_disable").show();
			$("#find_size_submit").hide();
		    tochange = 'width';
			defaultValue = 'choose_a_width';
			temp=temp+"&sizeTypeValue="+sizeTypeValue;
			ajaxCall(temp);
		}else{
		document.getElementById('wrapwidth').innerHTML="";	
		document.getElementById('wrapaspectratio').innerHTML="";	
		document.getElementById('wrapdiameter').innerHTML="";		
		}
		
	
	}
	if(temp == "width")
	{
		var sizeTypeValue= document.getElementById('size').value;
		var widthValue= document.getElementById('width').value;	
		if(widthValue != '-1'){
			if(widthValue != width){
			aspectratio = "";
		            }
        
	
	
			$("#aspectratio, #diameter").html('');
			$("#find_size_submit_disable").show();
			$("#find_size_submit").hide();
			tochange = 'aspectratio';
			defaultValue = 'choose_an_aspect_ratio';
			temp=temp+"&sizeTypeValue="+sizeTypeValue+"&widthValue="+widthValue;
			
			ajaxCall(temp);
		}else{
		document.getElementById('wrapaspectratio').innerHTML="";	
		document.getElementById('wrapdiameter').innerHTML="";		
		}
		
	
	}
	if(temp == "aspectratio")
	{
		var sizeTypeValue= document.getElementById('size').value;
		var widthValue= document.getElementById('width').value;
		var aspectValue = document.getElementById('aspectratio').value;		
		if(aspectValue != '-1'){
			if(aspectValue != aspectratio){
			diameter = "";
		   }

	
	
			$("#diameter").html('');
			$("#find_size_submit_disable").show();
			$("#find_size_submit").hide();
			tochange = 'diameter';
			defaultValue = 'choose_a_size';
			temp=temp+"&sizeTypeValue="+sizeTypeValue+"&widthValue="+widthValue+"&aspectValue="+aspectValue;
			
			ajaxCall(temp);
		}else{
		document.getElementById('wrapdiameter').innerHTML="";		
		}
		
		
	}
}

function customReplace(temp,delimiter,replaceWith){
var var1 = temp.split(delimiter);
var finalString;
var token;
	if(var1.length > 1){
    for (var i=0; i < var1.length; i++) 
   {
   if(i==0){
   finalString = var1[i];
   }
   else{
    token = var1[i];   
    token = token.replace(delimiter,replaceWith);
	finalString = finalString+replaceWith+token;
	}
	}
	temp = finalString;
}	
return temp;
}


function ajaxCall(temp)
{ 
		
		
		$.ajax({
		 type: "GET",
                 url: uri+"?type="+temp+'&ajaxCall=true',
		 dataType: "xml",
		 success: function(xml){     
                 parsexml(xml);    
		}                 	  
		});
	}

 
 function parsexml(result){
	
		if(tochange == "winterNonWinterCountVehicle")
		{
		
			var differentWinterTires = result.getElementsByTagName("winterCount");
			if(differentWinterTires.length > 0){
				var winterCount = differentWinterTires[0].getAttribute("winter_count");                                  
				var nonWinterCount = differentWinterTires[0].getAttribute("Non_winter_count");
				if(nonWinterCount < 1){
					submitPage('vehicle','no');
				} else {
					$("#winterCount").text("["+winterCount+"]");
					$("#nonWinterCount").text("["+nonWinterCount+"]");
					$("#winter_yes").click(function () {
						submitPage('vehicle','yes');
					});

					$("#winter_no").click(function () {
						submitPage('vehicle','no');
					});
					$("#tire_search_widget_overlay").show();
					$("#tire_form").hide();
					$("#tire-form").hide();
					$("#explore_form").hide();
					//$("#btn_find_tires").hide();
					$("#btn_explore").hide();
				}
				
			}
			else
			{
				submitPage('vehicle','no');
			}
		}
		if(tochange == "winterNonWinterCountSize")
		{
		
			var differentWinterTires = result.getElementsByTagName("winterCount");
			if(differentWinterTires.length > 0){
				var winterCount = differentWinterTires[0].getAttribute("winter_count");                                  
				var nonWinterCount = differentWinterTires[0].getAttribute("Non_winter_count");
				if(nonWinterCount == 0){
					submitPage('size','no');
				} else {
					$("#winterCount").text("["+winterCount+"]");
					$("#nonWinterCount").text("["+nonWinterCount+"]");
					$("#winter_yes").click(function () {
						submitPage('size','yes');
					});
					$("#winter_no").click(function () {
						submitPage('size','no');
					});
					$("#tire_search_widget_overlay").show();
					
					$("#tire_form").hide();
					$("#tire-form").hide();
					$("#explore_form").hide();
					//$("#btn_find_tires").hide();
					$("#btn_explore").hide();
				}
				
			}
			else
			{
				submitPage('size','no');
			}
		}
		if(tochange == "tireSize")
		{
	
			var toShowOrNotLst = result.getElementsByTagName("tstireSize");
		
			if(toShowOrNotLst.length > 0){
				addFifthDropdown();
		
				$("#find_vehicle_submit").hide();
				$("#go_wrap").show();
			
			} else{
			  
				$("#go_wrap").hide();
				$("#find_vehicle_submit").show();
		
			}
		}
		if(tochange != 'winterNonWinterCountVehicle' && tochange != 'winterNonWinterCountSize')
		{
			document.getElementById(tochange).options.length = 0;	
		}
												   
		var oSelField = document.getElementById(tochange);
		
				  
		var dnl = result.getElementsByTagName(tochange);
		/*if(dnl.length == 1){
		    var val = dnl[0].getAttribute(tochange+"_value");                                  
			var name= dnl[0].getAttribute(tochange+"_name");                         
			var oOption = document.createElement("OPTION");
			
			oOption.text = name ;
			oOption.value = val ;
			//oOption.selectedIndex = "0";
			
			oOption.selected = true;
			$(oSelField).removeClass("inactive");
			oOption.selected = true;
         //   oOption.selectedIndex = "1";
			oSelField.options.add(oOption);
		
		
		
			
		//	oSelField.selectedIndex = 0;
		
						
			if(tochange == "diameter")
				{
					$("#find_size_submit_disable").hide();
					$("#find_size_submit").show();
				
				}
			if(tochange == "options")
				{
					$("#find_vehicle_submit").show();
					$("#go_wrap").hide();
					
				}
		
		
			
					populateDropDowns(tochange);
			
			
		} else {*/
		if(dnl.length > 1){
			
			}
			for (var i=0; i < dnl.length; i++) 
			{                              
				var val = dnl[i].getAttribute(tochange+"_value");                                  
				var name= dnl[i].getAttribute(tochange+"_name");                         
				var oOption = document.createElement("OPTION");
				
				oSelField.options.add(oOption);
				oOption.text = name;
				oOption.title = name;
				oOption.value = val ;
			}
			if(tochange=="make"){
				fnSetDDL(tochange,make);
			}
			else if(tochange=="model"){
				fnSetDDL(tochange,model);
			}
			else if(tochange=="options"){
				fnSetDDL(tochange,options);
			}
			else if(tochange=="tireSize"){
				fnSetDDL(tochange,tireSize);
			}
			if(tochange=="width"){
				fnSetDDL(tochange,width);
			}
			else if(tochange=="aspectratio"){
				fnSetDDL(tochange,aspectratio);
			}
			else if(tochange=="diameter"){
				fnSetDDL(tochange,diameter);
			}
			
		//}
}
var xmlhttp=GetXmlHttpObject();
function GetXmlHttpObject()
{
		var xmlHttp=null;
		try
		 {
			 // Firefox, Opera 8.0+, Safari
			 xmlHttp=new XMLHttpRequest();
		 }
		catch (e)
		 {
			 //Internet Explorer
			 try
			  {
			  xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
			  }
			 catch (e)
			  {
			  xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
			  }
		 }
		return xmlHttp;
}

function checkForWinter(methodName){ 
		$("#mx_tire_search_widget_overlay").show();
		$("#tire_form").hide();
		$("#tire-form").hide();
		$("#btn_explore").hide();
		
		$("#mx_accept").click(function (e){
			$('#mx_cancel').next('img').remove();
			var imag='<img src="/es_MX/assets/bfg/system/images/ajax-loader.gif" style="float:left; display:block; height:24px; width:24px;" />';
			$(imag).insertAfter($("#mx_cancel"));
			submitPage('vehicle','no');
			//stop further click			
			$(this).unbind('click');				
				
		});
		$("#mx_cancel").click(function (e) {
			$("#mx_tire_search_widget_overlay").hide();
			$("#tire_form").show();
			$("#tire-form").show();				
			$("#btn_explore").show();
				
		});			
}

function checkForWinterSize(methodName){


		var sizeValue = document.getElementById('size').value;
		var widthValue = document.getElementById('width').value;
		var aspectratioValue = document.getElementById('aspectratio').value;
		var diameterValue = document.getElementById('diameter').value;
		
		sizeValue = escape(sizeValue);
		widthValue = escape(widthValue);
		aspectratioValue = escape(aspectratioValue);
		diameterValue = escape(diameterValue);
		tochange = 'winterNonWinterCountSize';
		var winterCount="winterCountSize&sizeTypeValue="+sizeValue+"&widthValue="+widthValue+"&aspectValue="+aspectratioValue+"&rimValue="+diameterValue;
		
		ajaxCall(winterCount);
	
}
function submitPage(methodName,winterOrNot){

	var searchType=document.createElement("input");
	searchType.setAttribute("type", "hidden");
	searchType.setAttribute("id", "searchType");
    searchType.setAttribute("name", "searchType");
	searchType.setAttribute("value", methodName);
	


// creating cookies which expires in 180 days.
if(methodName == 'vehicle')
{
var winterTires=document.createElement("input");
	winterTires.setAttribute("type", "hidden");
	winterTires.setAttribute("id", "winterNonWinter");
    winterTires.setAttribute("name", "winterNonWinter");
	
	var winterDiv = document.getElementById('winterNonWinter');
	if(winterDiv != null)
	document.forms["vehicle"].removeChild(winterDiv);	

	var ajaxLoderimgName = 'sizeajaxloader'+methodName;
	$('#'+ajaxLoderimgName).show();
	document.forms["vehicle"].appendChild(searchType);
	
	if(winterOrNot == 'yes'){
		document.forms["vehicle"].appendChild(winterTires);
		document.getElementById('winterNonWinter').value = "true";
	}
	
	year	= $("#year option:selected").val();
	make	= $("#make option:selected").val();
	model	= $("#model option:selected").val();
	options	= $("#options option:selected").val();
	tireSize = $("#tireSize option:selected").val();
	
	$.cookie('type', 'vehicle', { expires: 180 , path: '/' });
	$.cookie('year', year ,{ expires: 180, path: '/' });
	$.cookie('make', make ,{ expires: 180 , path: '/'});
	$.cookie('model', model ,{ expires: 180 , path: '/'});
	$.cookie('options', options ,{ expires: 180 , path: '/'});
	if(tireSize != "" && tireSize != undefined && tireSize != null){
	   $.cookie('tireSize', tireSize ,{ expires: 180 , path: '/'});
	   $.cookie('tireSizeFlag', 'showFifthDropDown' ,{ expires: 180 , path: '/'});
	   flag="showFifthDropDown";
	   }
	   else{
	   $.cookie('tireSizeFlag', null,{path: '/' });
	   flag=null;
	   }
	$.cookie('size', null,{path: '/' });
	$.cookie('width', null,{path: '/' });
	$.cookie('aspectratio', null),{path: '/' };
	$.cookie('diameter', null,{path: '/' });
	$.cookie('name', null,{path: '/' });
	$.cookie('category', null,{path: '/' });
	
	var makeValue = document.getElementById('make').value;
	var modelValue = document.getElementById('model').value;
	var optionValue = document.getElementById('options').value;
       
	
	var makeCombo = document.getElementById('make');
	var modelCombo = document.getElementById('model');
	var optionCombo=document.getElementById('options');
    

       makeCombo.options[makeCombo.selectedIndex].value=escape(makeValue);
	modelCombo.options[modelCombo.selectedIndex].value=escape(modelValue);
	optionCombo.options[optionCombo.selectedIndex].value=escape(optionValue);

	document.forms["vehicle"].submit();
	
}
if(methodName == 'size')
{
	var winterTiresSize=document.createElement("input");
	winterTiresSize.setAttribute("type", "hidden");
	winterTiresSize.setAttribute("id", "winterNonWinterSize");
    winterTiresSize.setAttribute("name", "winterNonWinterSize");
	winterTiresSize.setAttribute("value", "false");
	var ajaxLoderimgName = 'sizeajaxloader'+methodName;

	var winterDiv = document.getElementById('winterNonWinterSize');
if(winterDiv != null)
document.forms["tiresize"].removeChild(winterDiv);

	document.forms["tiresize"].appendChild(winterTiresSize);
	document.forms["tiresize"].appendChild(searchType);
	if(winterOrNot == 'yes'){
		document.getElementById('winterNonWinterSize').value = "true";
	}

$('#'+ajaxLoderimgName).show();

	

	size = $("#size option:selected").val();
	width	= $("#width option:selected").val();
	aspectratio		= $("#aspectratio option:selected").val();
	diameter		= $("#diameter option:selected").val();
    
	
	$.cookie('type', 'size', { expires: 180, path: '/' });
 $.cookie('tireSizeFlag', null,{path: '/' });
 flag=null;
	$.cookie('size', size ,{ expires: 180 , path: '/'});
	$.cookie('width', width ,{ expires: 180, path: '/' });
	$.cookie('aspectratio', aspectratio ,{ expires: 180 , path: '/'});
	$.cookie('diameter', diameter ,{ expires: 180 , path: '/'});
	
	$.cookie('year', null,{path: '/' });
	$.cookie('make', null,{path: '/' });
	$.cookie('model', null,{path: '/' });
	$.cookie('options', null,{path: '/' });
	$.cookie('tireSize', null ,{path: '/'});
	$.cookie('name', null,{path: '/' });
	$.cookie('category', null,{path: '/' });
	
	
	
	
	
	document.forms["tiresize"].submit();
	
}
if(methodName == 'name')
{
var ajaxLoderimgName = 'sizeajaxloader'+methodName;


$('#'+ajaxLoderimgName).show();

	name = $('#name option:selected').val();
	 document.forms["tirename"].appendChild(searchType);	
	 $.cookie('tireSizeFlag', null,{path: '/' });
	 flag=null;
	$.cookie('type', 'name', { expires: 180 , path: '/'});
	$.cookie('name', name ,{ expires: 180, path: '/' });

	$.cookie('year', null,{path: '/' });
	$.cookie('make', null,{path: '/' });
	$.cookie('model', null,{path: '/' });
	$.cookie('options', null,{path: '/' });
	$.cookie('tireSize', null ,{path: '/'});
	$.cookie('size', null,{path: '/' });
	$.cookie('width', null,{path: '/' });
	$.cookie('aspectratio', null,{path: '/' });
	$.cookie('diameter', null,{path: '/' });
	$.cookie('category', null,{path: '/' });
	
	
  
	
	document.forms["tirename"].submit();

	
}
if(methodName == 'category')
{
var ajaxLoderimgName = 'sizeajaxloader'+methodName;


$('#'+ajaxLoderimgName).show();

	category = $('#category option:selected').val();
    document.forms["tirecategory"].appendChild(searchType);
flag=null;	
	 $.cookie('tireSizeFlag', null,{path: '/' });
	$.cookie('type', 'category', { expires: 180, path: '/' });
	$.cookie('category', category ,{ expires: 180 , path: '/'});
	
	$.cookie('year', null,{path: '/' });
	$.cookie('make', null,{path: '/' });
	$.cookie('model', null,{path: '/' });
	$.cookie('options', null,{path: '/' });
	$.cookie('tireSize', null ,{path: '/'});
	$.cookie('size', null,{path: '/' });
	$.cookie('width', null,{path: '/' });
	$.cookie('aspectratio', null,{path: '/' });
	$.cookie('diameter', null,{path: '/' });
	$.cookie('name', null,{path: '/' });
	

  

	
	document.forms["tirecategory"].submit();
	
	
}
}


function activateSearch(selectType){

	if(selectType == "options"){
		if(document.getElementById('options').value == "-1")
		{
			$("#go_wrap").show();
			$("#find_vehicle_submit").hide();
		
		}
	}
	if(selectType == "tireSize"){
		if(document.getElementById('tireSize').value != "-1")
		{
			$("#go_wrap").hide();
			$("#find_vehicle_submit").show();
			
		}else if(document.getElementById('tireSize').value == "-1")
		{
			$("#go_wrap").show();
			$("#find_vehicle_submit").hide();
		
		}
	}
	if(selectType == "diameter"){
		if(document.getElementById('diameter').value != "-1")
		{
			$("#find_size_submit_disable").hide();
			$("#find_size_submit").show();
		
		} else if(document.getElementById('diameter').value == "-1")
		{
			$("#find_size_submit_disable").show();
		$("#find_size_submit").hide();
		
		}
	}
	if(selectType == "name"){
		if(document.getElementById('name').value != "-1")
		{
			document.getElementById('wrapwidth').innerHTML="";	
			document.getElementById('wrapaspectratio').innerHTML="";	
			document.getElementById('wrapdiameter').innerHTML="";
			document.getElementById('wrapmake').innerHTML="";	
			document.getElementById('wrapmodel').innerHTML="";	
			document.getElementById('wrapoptions').innerHTML="";
			fnSetDDL("year","-1");
			fnSetDDL("category","-1");
			fnSetDDL("size","-1");
			$("#find_name_submit_disable").hide();
			$("#find_name_submit").show();
		
		}else if(document.getElementById('name').value == "-1")
		{
			$("#find_name_submit_disable").show();
			$("#find_name_submit").hide();
		
		}
	}
	if(selectType == "category"){
		if(document.getElementById('category').value != "-1")
		{
			document.getElementById('wrapwidth').innerHTML="";	
			document.getElementById('wrapaspectratio').innerHTML="";	
			document.getElementById('wrapdiameter').innerHTML="";
			document.getElementById('wrapmake').innerHTML="";	
			document.getElementById('wrapmodel').innerHTML="";	
			document.getElementById('wrapoptions').innerHTML="";
			fnSetDDL("size","-1");
		   fnSetDDL("year","-1");
		   fnSetDDL("name","-1");
			$("#find_category_submit_disable").hide();
			$("#find_category_submit").show();
		
		}else if(document.getElementById('category').value == "-1")
		{

			$("#find_category_submit_disable").show();
			$("#find_category_submit").hide();
		
		}
	}
}

function addFifthDropdown() {
	var yearValue = document.getElementById('year').value;
	flag="showFifthDropDown";
	if($.cookie('tireSizeFlag') == null){ // value from msl
		if(btn_find_tires_clicked==true){
			//$('#btn_explore').hide();
			$('#btn_find_tires').css({'top': '88px'});
		}
	} else{//value from cookie
		$('#btn_find_tires').css({'top': '132px'});
	}
	$('#dropdown5').show();
	$('#tire_form').css({'top': '132px', 'height': '150px'});
	/*$('#go_wrap img').addClass("go_btn");
	$('#go_wrap1 img').addClass("go_btn1");*/
	
	$('#find_vehicle_submit_disable').css({'color': '#53535'}).animate({'top': "-13px"});
	$('#find_vehicle_submit').css({'color': '#53535'}).animate({'top': '-13px'});
	if($.browser.msie && $.browser.version == "8.0"){
	$('#sizeajaxloadervehicle').css({'top': "-58px",'left':"-90px"});
	}
	else
	{
	$('#sizeajaxloadervehicle').css({'top': "-58px",'left':"40px"});
	}
}

function removeFifthDropdown() {
	$('#btn_explore').show();
	$('#dropdown5').hide();
	$('#tire_form').css({'top': '153px', 'height': '160px'});
	$('#tire-form').css({'top': '153px', 'height': '160px'});
	if(btn_find_tires_clicked) {
		$('#btn_find_tires').css({'top': '103px'});
	}
	$('#go_wrap img').removeClass("go_btn");
	$('#go_wrap1 img').removeClass("go_btn1");
	
	$('#find_vehicle_submit_disable').css({'top': "15px"});
	$('#find_vehicle_submit').css({'top': "15px"});	
	if($.browser.msie && $.browser.version == "7.0"){
	$('#sizeajaxloadervehicle').css({'top': "-32px",'left':"-90px"});
	}
	else
	{
	$('#sizeajaxloadervehicle').css({'top': "-31px",'left':"40px"});
	}
}

function findTires() {
	tsdlReset();
	$('#tire_search_widget_overlay').hide();
	$('#tire_search_widget_overlay').hide();
	
	
	if($.cookie('tireSizeFlag') != null) {
		//$('#btn_explore').hide();
		if(btn_find_tires_clicked == true){
			$('#btn_find_tires').animate({
			top: "88px"
			}, 300 , "easeInQuad", function() {
				$('#tire_form').show();
				$('#btn_find_tires').removeClass("restoreHome");
				$('#btn_find_tires').css({"background": "none", height: "auto"}).addClass("maxi");
			}).addClass("maxi");
		}
	} else if(flag=="showFifthDropDown") {
			//$('#btn_explore').hide();
			$('#btn_find_tires').animate({
			top: "88px"
		}, 300 , "easeInQuad", function() {
			$('#tire_form').show();
			$('#btn_find_tires').removeClass("restoreHome");
			$('#btn_find_tires').css({"background": "none", height: "auto"}).addClass("maxi");
		}).addClass("maxi");
	} else {
		if(btn_find_tires_clicked == true) {
			$('#btn_find_tires').animate({
					top: "103px"
			}, 300 , "easeInQuad", function() {
				$('#tire_form').show();
				$('#btn_find_tires').removeClass("restoreHome");
				$('#btn_find_tires').css({"background": "none", height: "auto"}).addClass("maxi");
			}).addClass("maxi");
		}
	}
	$('#btn_explore').css({'color': '#535353'}).animate({
		top: "260px",
		fontSize: "16px"
	}, 300, "easeInQuad", function() {
	}).addClass("mini");
	
	$('#find_name_submit').css({'color': '#53535'}).animate({
		top: "93px",
		fontSize: "16px"
	}, 300, "easeInQuad", function() {
	}).addClass("mini");
	
	$('#find_size_submit').css({'color': '#53535'}).animate({
		top: "15px",
		fontSize: "16px"
	}, 300, "easeInQuad", function() {
	}).addClass("mini");
	
	$('#find_category_submit').css({'color': '#53535'}).animate({
		position:"relative",
		top: "93px",
		fontSize: "16px"
	}, 300, "easeInQuad", function() {
	}).addClass("mini");
	
	$('#find_vehicle_submit').css({'color': '#53535'}).animate({
	
		top: "15px",
		fontSize: "16px"
	}, 300, "easeInQuad", function() {
	}).addClass("mini");
	
	
	
	$('#find_name_submit_disable').css({'color': '#535353'}).animate({
		top: "93px",
		fontSize: "16px"
	}, 300, "easeInQuad", function() {
	}).addClass("mini");
	
	$('#find_size_submit_disable').css({'color': '#535353'}).animate({
		top: "15px",
		fontSize: "16px"
	}, 300, "easeInQuad", function() {
	}).addClass("mini");
	
	$('#find_category_submit_disable').css({'color': '#535353'}).animate({
		top: "93px",
		fontSize: "16px"
	}, 300, "easeInQuad", function() {
	}).addClass("mini");
	
	$('#find_vehicle_submit_disable').css({'color': '#535353'}).animate({
		
		top: "15px",
		fontSize: "16px"
	}, 300, "easeInQuad", function() {
	}).addClass("mini");
}


function explore() {
	tsdlReset();
	$('#btn_find_tires').css({'color': '#535353'}).animate({
			top : "310px",
			fontSize : "16px"
		}, 300 , "easeInQuad", function() {
		$('#explore_form').show();
		$('#btn_find_tires').removeClass("restoreHome");
		$('#btn_find_tires').css({"background": "none", height: "auto"}).addClass("mini");
	});	
	$('#btn_explore').animate({
			top: "47px"
		}, 300 , "easeInQuad", function() {
	}).addClass("maxi");	
}

function tsdlReset() {
	$('#tire_form').hide();
	$('#explore_form').hide();
			$('#mx_tire_search_widget_overlay').hide();
	$('#btn_find_tires').css({'color': '#fff'}).animate({
			top: "132px",
			fontSize: "25px"
		}, 200 , "easeInQuad", function() {
		$('#btn_find_tires').addClass("restoreHome");
	})
	.removeClass("mini").removeClass("maxi");
$('#btn_explore').show();
	$('#btn_explore').css({'color': '#fff'}).animate({
			top: "150px",
			fontSize: "25px"
		}, 200 , "easeInQuad", function() {
	}).removeClass("mini").removeClass("maxi");

}




