// JavaScript Document
jQuery.fn.hideDiv = function(){	
	$(this).click(function(){		
		$(this).parent('div').hide(function(){
			// --------- Note Infromation Block -  Dealer Locator Results ------------ //
			var noteInfo_Status = $('.note_information').length;
			if(noteInfo_Status == 0) {
				$('.results_block').css('height', '500px');
			} else {
				var noteinfo_height = $('.note_information').height();
				$('.results_block').css('height', (520 - (noteinfo_height + 24)) + 'px');
			}
		});
		return false;
	});
}
/*hover functionality*/
function appendOver(srcPath){
    var index = srcPath.lastIndexOf('.');
    var defaultPath = srcPath.substr(0, index);
	var endPath = srcPath.substr(index, srcPath.length);
	
    //var changedPath = srcPath.substr(index);
    return defaultPath + "_hover" +endPath ;
}
function changingImgsrcOnhover(){
	
	var originalSrc;
	
	$(".call_it_now img, , .view_tire_details img, .call img, .find_a_tire input,#showWinterTiresTop,#showWinterTiresBottom,#showNonWinterTiresBottom, #showNonWinterTiresTop, #compareNonWinterTop img,#compareNonWinterBottom img, .find_a_size input, .front_tire img,.rear_tire img,#submit_contact,#find_vehicle_submit,#createAccount_Submit,#login_submit,#login_submit_button,#frontRearAncor img,#c2c_submit,#login_submit_button,.editinfo,.continue,#search_onLoad,.select_dealer input,#overlay_dealer_locator img,.action_button,#writeLink img,#submit_button,#forgot_password_submit_button,#get_directions,#find_category_submit,#find_name_submit,#find_vehicle_submit_disable,#button_find_a_tire_disabled,#find_vehicle_submit,#find_size_submit,#submit_form_button img,#submit_vehicle_button img,#submit_tires_button img").hover(function()
	{
		originalSrc=$(this).attr("src");
		var newSorce = appendOver(originalSrc)
		$(this).attr("src", newSorce)

	}, 
	function()
	{
	 $(this).attr("src",originalSrc)
	}
	)
};
function changingImgsrcOnhoverLive(){
	
	var originalSrc;
		
	$('.select_dealer input').live('mouseover',function(){
		originalSrc=$(this).attr("src");
		var newSorce = appendOver(originalSrc)
		$(this).attr("src", newSorce)
	});
	$('.select_dealer input').live('mouseout',function(){
		$(this).attr("src",originalSrc)
	});

};
//end of image hover function
$(document).ready(function(){
	if($.browser.msie && $.browser.version == "7.0"){
			if( $('#tire_size_tab div#backToResultsTireSize').size() >0 ) {
					$("#tire_size_tab p").css('margin-bottom','8px');
				}
				else {
				
				$("#tire_size_tab p").css('margin-bottom','0px');
			}
	}

	$(".mileageText a.no_print").first().click(function(){
			if($(".show_hide_warranties a").attr("class")!='hide_panel')
			{
				$(".show_hide_warranties a").click();
			}
	});
	$(".warranty_logo a img").first().click(function(){	
			if($(".show_hide_warranties a").attr("class")!='hide_panel')
			{
				$(".show_hide_warranties a").click();
			}
	});
$("#tire_highlights_panel").parent().css("position","relative");
	
if($("#specialVehNotes").val() == '')
{
	$("#special_veh_div_Result").parent().css("visibility","hidden");
}

if($("#vehicle_tab .back_to_results").text() != " ")
{
	$(".back_to_results").css("margin-bottom","2px");
}
												  
//$(".overlay_dealer_locator").bind(".click(function(){alert(2);$("#search_address_quicklink").focus();});						   
					   
changingImgsrcOnhover();
changingImgsrcOnhoverLive();

$("#overlay_fitment").click(function(){
	$("#tire_search_widget").css("width","255px");
})
						   if($("#showWinterTiresTop,#showWinterTiresBottom").is(":visible")){
$("#compareNonWinterTop img,#compareNonWinterBottom img").attr("src","/assets/mi/system/images/button_compare_tires_pipe.png")
}
else if($("#showNonWinterTiresTop,#showWinterTiresBottom").is(":visible")){
$("#compareNonWinterTop img,#compareNonWinterBottom img").attr("src","/assets/mi/system/images/button_compare_tires_pipe.png")
}
		
	var optionsTableHeight = ($("#options_table_wrapper .right_columns_wrapper table").height() + 20);
	$("#options_table_wrapper .right_columns_wrapper").height(optionsTableHeight);
	
	$("#page_wrapper").addClass($("#pageId").attr("content"));
	
	$("#tire_details .section_title .show_hide_panel_link a").html($.validator.messages.Show);
	$("#tire_search_results .section_title .show_hide_panel_link a").html($.validator.messages.Hide);
	
	// Below code added by Shikha for #artf1215587 diagnostic-tool-solution  
	var liCurrentPage = document.getElementById('liCurrentPageName');
	var currentPageName = document.getElementById('currentPageName');
	var h1CurrentPage = document.getElementById('h1CurrentPageName');
	if(liCurrentPage != null && currentPageName!=null && h1CurrentPage!= null)
		{
			liCurrentPage.innerHTML = currentPageName.value ;
			h1CurrentPage.innerHTML = currentPageName.value ;
		}


	//Tire Detail Page Accordion script 
	var galleryCreated=false;
	$('.showImage').each(function(){
		$(this).click(function() {
			if($("#gallery").length != 0 && $(this).parent().parent().attr("id") == "media_gallery_panel"){
				$("#gallery_items").toggle();
				$("#gallery_preview").toggle();
				$(this).parent().parent().find(".section_title .show_hide_panel_link a").removeClass("show_panel").html($.validator.messages.Hide)
				var thumbCounter = $(this).attr("thumbId")
				if(galleryCreated==false){
					galleries = $("#gallery").mediaGallery({start_at_index: thumbCounter});
					galleryCreated=true;
				}
			}
		});
	});
	
	$(".section_title .show_hide_panel_link a").click(function(){
		$(this).parent().parent().parent().find(".content_panel").toggle();
		if(galleryCreated==false){
			if($("#gallery").length != 0 && $(this).parent().parent().parent().attr("id") == "media_gallery_panel"){
				galleries = $("#gallery").mediaGallery();
				galleryCreated=true;
			}
		}
		
		if ($(this).attr("class") == "hide_panel")
		{
			if($(this).parent().parent().hasClass('techspec_title') == true){
				$(this).addClass("show_panel").html($.validator.messages.Show_Tire_Detail);
			}
			else{
				$(this).addClass("show_panel").html($.validator.messages.Show);
			}
			if($("#gallery_preview").length != 0 && $(this).parent().parent().parent().attr("id") == "media_gallery_panel"){
				$("#gallery_preview").toggle();
			}

		}
		else
		{
			if($(this).parent().parent().hasClass('techspec_title') == true){
				$(this).removeClass("show_panel").html($.validator.messages.Hide_Tire_Detail);
			}
			else{
			$(this).removeClass("show_panel").html($.validator.messages.Hide);
			}
			if($("#gallery_preview").length != 0 && $(this).parent().parent().parent().attr("id") == "media_gallery_panel"){
				$("#gallery_preview").toggle();
			}
		}
		substituteTableRow();
		footerLockReposition();
		return false;
	});
		$(".section_title .show_hide_warranties a").click(function(){
		$(this).parent().parent().parent().find(".content_panel").toggle();
	
		
		if ($(this).attr("class") == "hide_panel")
		{
			$(this).addClass("show_panel").html($.validator.messages.Show);
		}
		else
		{
			$(this).removeClass("show_panel").html($.validator.messages.Hide);
		
		}
		substituteTableRow();
		footerLockReposition();
		return false;
	});
	
	//Click to Call - Thankyou Page
	/*$('.callme_button').click(function() {
		$('#form_panel').hide();
		var nameValue = $('#name').val();
		var namePhone = $('#phone').val();
		var nameEmail = $('#email').val();
		$('.customerName').html(nameValue);
		$('.customerPhone').html(namePhone);
		$('.customerEmail').html(nameEmail);
		$('.c2c_confirmation').show();
		return false;
	});*/
	$('.editinfo').click(function() {
		$('.c2c_confirmation').hide();
		$('.click2call_form_content').show();
		return false;
	});
	$('.continue').click(function() {
		$('.c2c_confirmation').hide();
		$('.click2call_thanks_panel').show();
		return false;
	});
	
	
	/*Login Pop-Up
	$("#forgot_password_link").click(function() {
		document.getElementById("login_header_text").innerHTML="Forgot your Password";
		$("#frmLogin").hide();
		$("#frmForgotPassword").show();
		var inputs = $("#frmLogin").validator({ lang: 'us' });
		var validation=inputs.data("validator").destroy();
		return false;
	});
	$("#view_login_panel").click(function() {
		document.getElementById("login_header_text").innerHTML="Login to BFGoodrichtires.com";	
		$("#frmLogin").show();
		$("#thankyou_panel").hide();
		return false;
	});*/
	$("#forgot_password_submit_button").click(function() {
		//$("#frmForgotPassword").hide();
		//$("#thankyou_panel").show();
		return false;
	});
	/*$("#back_to_login").click(function() {
		$("#frmForgotPassword").hide();
		$("#frmLogin").show();
		return false;
	});*/
	$("#forgot_password_link_sidebar").click(function() {		
		$("#frmLogin_sidebar").hide();
		$("#frmForgotPassword_sidebar").show();
		$("#thankyou_panel_sidebar").hide();
		document.getElementById("emailaddres").value = "";
		//var inputs = $("#frmLogin_sidebar").validator();
		//var validation=inputs.data("validator").destroy();
		return false;
		});
	
	//Tab Panel script
	$('.button_find_tire').click(function() {
		var panel_height = $("#tire_search_widget > .content_panel").height();
		$('#tire_search_widget_overlay').show();
		$("#tire_search_widget_overlay").css('height', panel_height + 20);
		return false;
	});
	//Winter Overlay Layer Hide
	$('.close_button').click(function(){
		$('#tire_search_widget_overlay').hide();
	});
	
	//Alternate Row Colors
	$("#total_dealer_results ul.result_content > li:odd").addClass("odd_row");
	$("#total_dealer_results ul.result_content > li:even").addClass("even_row");
	$("ul.search_result_block > li:even").addClass("alternate_row_color");

	
	//Alternate Row Colors - Options Table
	$('#light_tires_wrapper .recommended_tires table tr:odd').addClass("odd_row");
	$('#light_tires_wrapper .alternative_tires table tr:odd').addClass("odd_row");
	$('#passenger_tires_wrapper .recommended_tires table tr:odd').addClass("odd_row");
	$('#passenger_tires_wrapper .alternative_tires table tr:odd').addClass("odd_row");

	
	//Toggle Performance Rating & TechSpec Button - Tire Comparison
	$('#passenger_tires_wrapper .show_tech_spec').click(function(){
		$(this).toggleClass('show_performance_rating');
		//$('.performance_rating_table, .techspec_table_wrapper').toggleClass('content_panel');
		
		if($(this).attr("title")==$.validator.messages.showTechnicalSpecifications){
			$(this).attr("title",$.validator.messages.showPerformanceRatings);
			$(this).attr("alt",$.validator.messages.showPerformanceRatings);
		} else {
			$(this).attr("title",$.validator.messages.showTechnicalSpecifications);
			$(this).attr("alt",$.validator.messages.showTechnicalSpecifications);
		}
		
		$(this).parents('#passenger_tires_wrapper').find('.recommended_tires, .alternative_tires, #passenger_recommended_techspec_table, #passenger_alternative_techspec_table').toggle();
		substituteTableRow();
		return false;
	});
	
	//Toggle Performance Rating & TechSpec Button - Tire Comparison
	$('#light_tires_wrapper .show_tech_spec').click(function(){
		$(this).toggleClass('show_performance_rating');
		//$('.performance_rating_table').toggleClass('content_panel');
		
		if($(this).attr("title")==$.validator.messages.showTechnicalSpecifications){
			$(this).attr("title",$.validator.messages.showPerformanceRatings);
			$(this).attr("alt",$.validator.messages.showPerformanceRatings);
		} else {
			$(this).attr("title",$.validator.messages.showTechnicalSpecifications);
			$(this).attr("alt",$.validator.messages.showTechnicalSpecifications);
		}
		
		$(this).parents('#light_tires_wrapper').find('.recommended_tires, .alternative_tires, #lightTruck_recommended_techspec_table, #lightTruck_alternative_techspec_table').toggle();
		substituteTableRow();
		return false;
	});
	
	//Tire Selecter Widget Tooltip
	$(".icon_help").addClass('clickable').click(function(e) {
	var hardCodeSizeAspectRatio = $(this).attr('alt').indexOf("R2-aspect.png");
	var sizeofTooltip = (($(this).attr('alt').length < 200 ) ? ($(this).attr('alt').indexOf("img") > 0 ? '300px' : '180px') : ('300px'));
			$("div.tooltip_widget").show().css({
				position:'absolute',
				top: (e.pageY-30)+'px',
				left:(e.pageX+20)+'px',
				width: sizeofTooltip
			}).children('span').eq(0).html($(this).attr('alt').split('\n').join('<br />'));
			if(sizeofTooltip!="180px")
				{
					$("div.tooltip_widget").show().css({
						top: (e.pageY-30)+'px'
					});
					
					$("div.tooltip_widget span").find("div").css({
					width:"308px",
					'text-align':'center'
					});
			
				
				}
			if(hardCodeSizeAspectRatio>0)
			{
				$("div.tooltip_widget").css("top","298px")
			}
			return false;
	});
	
	//My Vehicles Tires YMMO Tooltip
	$(".ymmo_icon_help").addClass('clickable').live("mouseenter",function(e) {
		var txt=$(this).attr('alt'); 
		var myId=$(this).parent('a').attr('id');
		var myClass=$(this).parent('a').attr('class');
		var pos = $(this).offset();		
		var myLeft=pos.left-($("div.tooltip_widget").width()+30);
		var myTop=pos.top-70;
		
		if(myId==="tireRotationAlert-100"){
			$("div.tooltip_widget").show().css({'position':'absolute','top':myTop+'px','left':myLeft+'px'}).children('span').eq(0).html(txt);
		}else if(myClass.indexOf("sample_vehicle_registration_form")){
			 $("div.tooltip_widget").show().css({'position':'absolute','top':myTop+'px','left':myLeft+'px'}).children('span').eq(0).html(txt);
		}else{
			var sizeofTooltip = (($(this).attr('alt').indexOf("img") > 0 ? '300px' : '180px'));
				$("div.tooltip_widget").show().css({
					position:'absolute',
					top: (e.pageY-150)+'px',
					left:(e.pageX-225)+'px',
					width:sizeofTooltip
				}).children('span').eq(0).html($(this).attr('alt').split('\n').join('<br />'));
				return false;
			}
	});
	
	$(".ymmo_icon_help").addClass('clickable').live("mouseleave",function(e) {
	//var sizeofTooltip = (($(this).attr('alt').indexOf("img") > 0 ? '300px' : '180px'));
			$("div.tooltip_widget").show().css({
			   display: 'none'
				//position:'absolute',
				//top: (e.pageY-150)+'px',
				//left:(e.pageX-225)+'px',
				//width:sizeofTooltip
			})
			return false;
	});
	
	//Tire Selecter Widget Tooltip
	$(".hint").addClass('clickable').click(function(e) {
		$("div.tooltip_widget").show().css({
				position:'absolute',
				top: (e.pageY-30)+'px',
				left:(e.pageX+20)+'px'
			}).children('span').eq(0).html($(this).attr('alt').split('\n').join('<br />'));
			return false;
	});
	

	//Click to Call TextArea Charcaters Count Limit Counter 
	var charactersAllowed = 255; // this is picked from widget configuration
	$("#charCount").html(charactersAllowed);
	 $("#rMessage").keyup(function() {
	  $("#charCount").html(charactersAllowed - ($(this).val().length));
	  if($(this).val().length > charactersAllowed) {
	   this.value = this.value.substring(0, charactersAllowed);
	   $("#charCount").html(charactersAllowed - ($(this).val().length));
	  }
	 });
	 
	 //Contact Us Message TextArea Charcaters Count Limit Counter 
	 var charactersAllowedForContactUs = 1024; 
	 $("#message").keyup(function() {
		  if($(this).val().length > charactersAllowedForContactUs) {
		   this.value = this.value.substring(0, charactersAllowedForContactUs);	  
		  }
	 });
	 
	 //Tire Selecter Widget Tooltip - Close Botton 
	$("div.tooltip_widget img").addClass('clickable').click(function() {
		$("div.tooltip_widget").hide();
	});
	 
	 
	 // Read more information Block
	 $('.read_info').click(function(){
		$(this).toggleClass('read_info_open');
		$(this).parents('.tire_details').find('.less_info, .more_info').toggle();							   
		$(this).text($(this).text() == 'Read more information' ? 'Read less information' : 'Read more information');
		return false;
	});
	 
	 
	 //dealer locator - dealer details swap
	$(".more_details").click(function(){
		$("#total_dealer_results").hide();
		$("#selected_dealer_details").show();
		return false;
	});
	$("#back_to_results_link a").click(function(){
		$("#total_dealer_results").show();
		$("#selected_dealer_details").hide();
		return false;
	});
	
	// TechSpec Table on Category Name Page
	$(".techspec_title span a").toggle(function()
		{
			substituteTableRow();
			//$(".techspecTable .main").css('height','221px');
			$(".techspecTable .main #categoryname_techspec_divfrozen").css('height',"140px")
			$(".techspecTable .main #categoryname_techspec_contentscroll").css('height',"158px")
			$(".techspecTable  #categoryname_techspec_headscroll").css('width','785px')
			$(".techspecTable .main div.content").css('width','802px')
			if($("#categoryname_techspec_headscroll").hasClass('noScroll')){
				$(".techspecTable #categoryname_techspec_headscroll").css('width','802px')
			}
			$(".techspecTable .main #categoryname_techspec_contentscroll").css('overflow-y','scroll')
		},
		function()
		{
			substituteTableRow();
			//$(".techspecTable .main").css('height','31px');
			$(".techspecTable .main #categoryname_techspec_divfrozen").css('height',$(".techspecTable .main #categoryname_techspec_divfrozen table.frozen tr:first-child").height())
			$(".techspecTable .main #categoryname_techspec_contentscroll").css('height',$("#categoryname_techspec_innercontent tr:first-child").height()+18)
			$(".techspecTable .main #categoryname_techspec_contentscroll").css('overflow-y','hidden')
			$(".techspecTable  #categoryname_techspec_headscroll").css('width','802px')
			$(".techspecTable #categoryname_techspec_innercontent").css('width','1151px')
		}
	);
	
	// Option Table Equal Row Height - Tire Detail YMMO
	var leftPanel_rowHeight = $('#left_columns_wrapper table td').height();
	var rightPanel_rowHeight = $('#right_columns_wrapper table td').height();
	var max_rowHeight = Math.max($('#right_columns_wrapper table td').height(),$('#left_columns_wrapper table td').height());
	//alert($('#left_columns_wrapper table td').height());
	if(leftPanel_rowHeight > rightPanel_rowHeight)
	{
		$('#left_columns_wrapper table td').height(max_rowHeight);
		$('#right_columns_wrapper table td').height(max_rowHeight + 13);
	} else {
		$('#left_columns_wrapper table td').height(max_rowHeight + 13);
		$('#right_columns_wrapper table td').height(max_rowHeight);
	}
	
	if($.fixIESelectWidth){
	$("#tire_search_widget select").fixIESelectWidth();
	$(".primary_vehicle select").fixIESelectWidth();
	$("#contact_year select").fixIESelectWidth();
	$("#contact_make select").fixIESelectWidth();
	$("#contact_model select").fixIESelectWidth();
	$("#contact_option select").fixIESelectWidth();
   $("#contact_tireSize select").fixIESelectWidth();

	
	}
	// For tire diagnostic tool, to make image yellow bordered on radio button clicked
	/*var tempImg = 'null';
	$("#table_container li input").click(function(){
		
	if(tempImg !=null){
	
		//tempId = $(this).attr("id");
		$(this).parent().parent().addClass("tool_selected");
		$("#"+tempImg).parent().parent().removeClass("tool_selected");
		
		tempId  = null 
	 }
	 else
	 {	
	
		$(this).parent().parent().addClass("tool_selected");
		$("#"+tempImg).parent().parent().removeClass("tool_selected");
		tempImg  = $(this).attr("id");
	 }
	 
	tempImg  = tempImg = $(this).attr("id");

	
	});*/
	
	$("a[rel=lightbox]").fancybox({
		'transitionIn'		: 'none',
		'transitionOut'		: 'none',
		'overlayColor'		: '#fff',
		'overlayOpacity'	: 0.7,
		'titlePosition' 	: 'inside',
		'titleFormat'		: function(title, currentArray, currentIndex, currentOpts) {
			return '<span id="lightbox-image-counter">' + (currentIndex + 1) + ' of ' + currentArray.length + '</span><span id="lightbox-image-caption">' + (title.length ? title : ' &nbsp; ') + '</span>';
		}
	});
	
	
	$(".lightboxVideo").click(function() {
		var myVideo = $(this).attr('href');
		var isiDevice = /iPad|iPhone|iPod/i.test(navigator.userAgent);
		var userAgent = navigator.userAgent.toLowerCase();
		var leftPos = document.body.clientWidth/2 - 320
		var topPos = window.innerHeight/2 - 190
		var params  = 'width=640,height=380,location=no,menubar=no,scrollbars=no,titlebar=no,toolbar=no';
			params += ',left='+leftPos;
			params += ',top='+topPos;
		$("#videoPathForIdevices").val(myVideo);

		//Detect for iDevice - true
		if(isiDevice) {
			window.open("/assets/mi/system/html/idevice_video.html","mywindow",params);
			return false;
		} else if($.browser.flash != true) {
			$.fancybox({
				'href'		: '#ipad'
			});
			$("#ipad").attr("href","javascript:void(0)");
			flowplayer("ipad", "/assets/mi/system/videos/flowplayer-3.2.5.swf");
			return false;
		} else {
			$.fancybox({
				'href'		: '#ipad'
			});
			$("#ipad").attr("href",myVideo);
			flowplayer("ipad", "/assets/mi/system/videos/flowplayer-3.2.5.swf");
			return false;
		}
	});
	
	
});

function deleleVehicle(obj) {	
	vehicleCount--;	
	if(vehicleCount == 0) {
		statusMessage = "&nbsp;&nbsp;&nbsp;"+$.validator.messages.MyVehicles;
		var msg_div=document.getElementById("addMoreVehicle");					
		msg_div.innerHTML=statusMessage ;	
		document.getElementById("noVehicleMessage").style.display='block';
		document.getElementById("addVehicleLink").style.display='none';
		document.getElementById("submit_vehicle_button").style.display='none';
	}
	if($.browser.msie && $.browser.version == "8.0"){
		footerLockReposition();
		$(obj).parent().parent().parent().parent().remove();
	} else {
		$(obj).parent().parent().parent().parent().remove();
		footerLockReposition();
	}
				
		var vehicleIdToBeRemoved = $(obj).parent().parent().parent().parent().attr("id").charAt($(obj).parent().parent().parent().parent().attr("id").length-1);
					
		$(".something").each(function(){		
			if(vehicleIdToBeRemoved < $(this).parent().parent().parent().attr("id").charAt($(obj).parent().parent().parent().parent().attr("id").length-1))
			{
				$(this).parent().parent().parent().attr("id",$(this).parent().parent().attr("id").substr(0,$(this).parent().parent().attr("id").length-1)+vehicleIdToBeRemoved);
				$(this).parent().parent().parent().attr("id",$(obj).parent().parent().parent().parent().attr("id").substr(0,$(obj).parent().parent().parent().parent().attr("id").length-1)+vehicleIdToBeRemoved);
				
				$(this).parent().attr('id',$(this).parent().attr('id').substr(0,$(this).parent().attr('id').length-1) + vehicleIdToBeRemoved)
				
				if(vehicleIdToBeRemoved==1)
				{
					$(this).html($.validator.messages.primaryVehicle);
				}
				else
				{
					//$(this).html("<h3 class='something'>Vehicle&nbsp;"+vehicleIdToBeRemoved+"</h3>");					
					
					/*for (var name in this) {						
					  alert(name +"  "+this[name]);
					}*/					
					$(this).html($.validator.messages.Vehicle+"&nbsp;"+vehicleIdToBeRemoved+" :");
				}
				vehicleIdToBeRemoved++;
			}				
		})	
}

//Tire Details Scrollable Table
function reposHead(e) {
	var u = document.getElementById('categoryname_techspec_headscroll');
	u.scrollLeft = e.scrollLeft;
	var o = document.getElementById('categoryname_techspec_divfrozen');
	o.scrollTop = e.scrollTop;
  }

//Function to map rowspan concept for TechSpec Table
function substituteTableShow() {	
}//end of function
	
	//Tire Comparision TechSpec Table - Rowspan mapping 
	var optionTableFlag;
var tempmaxHeight =0;

function substituteTableRow() {
			var optionnametable = $(".left_columns_wrapper tr", ".techspec_table_wrapper");
			var optiondetailtable = $(".right_columns_wrapper tr", ".techspec_table_wrapper");
			optionnametable.each(function(i){
				var object = $(this);
			     //var maxHeight=60;
				var crntHt=$("td:first", optionnametable[i]).attr("rowspan");
			var maxHeight = Math.max( $(optiondetailtable[i]).height(), $(optionnametable[i]).height())
				
				if (jQuery.browser.msie) {
				
				      if($.browser.msie && $.browser.version == "8.0" )
					   {
				         maxHeight=61;
						  for ( var k = 0; k < crntHt; k++ )
							{
								tempmaxHeight =  maxHeight/crntHt
					
									$("td:first", optiondetailtable[i+k]).css("height" , tempmaxHeight)
							}
								$("td:first", optionnametable[i]).css("height" , (tempmaxHeight*crntHt))
								if(typeof(crntHt)!="undefined" && crntHt==2){
							$("td:first", optionnametable[i]).css("height" , ((tempmaxHeight*crntHt)+15))
							}
							if(typeof(crntHt)!="undefined" && crntHt>=3)
								{
									$("td:first", optionnametable[i]).css("height" , ((tempmaxHeight*crntHt) + (crntHt*5.5))+18)
								}
								i = i + crntHt;

					    
						
					}
					else
					{
						
						if($.browser.msie && $.browser.version == "7.0")
						{
						maxHeight=61;
						for ( var k = 0; k < crntHt; k++ )
							{
								tempmaxHeight =  maxHeight/crntHt
					
									$("td:first", optiondetailtable[i+k]).css("height" , tempmaxHeight)
							}
								$("td:first", optionnametable[i]).css("height" , (tempmaxHeight*crntHt))
								if(typeof(crntHt)!="undefined" && crntHt==2){
							$("td:first", optionnametable[i]).css("height" , ((tempmaxHeight*crntHt)+13))
							}
							if(typeof(crntHt)!="undefined" && crntHt>=3)
								{
									$("td:first", optionnametable[i]).css("height" , ((tempmaxHeight*crntHt) + (crntHt*5.5)+18))
								}
								i = i + crntHt;

						}
						
							
					}
				}
				else if ($.browser.safari) {
				
					maxHeight=61;
					
						for ( var k = 0; k < crntHt; k++ )
							{
								tempmaxHeight =  maxHeight/crntHt;
					
									$("td:first", optiondetailtable[i+k]).css("height" , tempmaxHeight)
							}
								$("td:first", optionnametable[i]).css("height" , (tempmaxHeight*crntHt))
							if(typeof(crntHt)!="undefined" && crntHt==2){
							$("td:first", optionnametable[i]).css("height" , ((tempmaxHeight*crntHt)+15))
							}
							if(typeof(crntHt)!="undefined" && crntHt>=3)
								{
									$("td:first", optionnametable[i]).css("height" , ((tempmaxHeight*crntHt) + (crntHt*3.4)+18))
								}
								i = i + crntHt;

				
                     }
					 else if ($.browser.opera) {
				
					maxHeight=48;
					
						for ( var k = 0; k < crntHt; k++ )
							{
								tempmaxHeight =  maxHeight/crntHt
					
									$("td:first", optiondetailtable[i+k]).css("height" , tempmaxHeight)
							}
								$("td:first", optionnametable[i]).css("height" , (tempmaxHeight*crntHt))
							if(typeof(crntHt)!="undefined" && crntHt>3)
								{
									$("td:first", optionnametable[i]).css("height" , ((tempmaxHeight*crntHt) + (crntHt*3.4)))
								}
								i = i + crntHt;

				
                     }
				
				
				else if (jQuery.browser.mozilla)
				{
				$("td:first", optiondetailtable[i]).css("height" , maxHeight)
					if(typeof(crntHt)!="undefined" && crntHt<6) {
							tdHt=maxHeight * crntHt;
							$("td:first", optionnametable[i]).css("height" , tdHt)
						}
				}
			})
}//end of function
	
	function footerLockReposition(){}
	
	function countDOTForms(count){
		var currentFormsSize = $(".dot_code_form").size();
		for(i=1; i<=count;i++){
			$("#dot_code_form").clone().appendTo("div#clonedForms");
		}
		return false;
	}
	
	function deleleDotCode(obj) {			
		$(obj).parent().parent().remove();
	}

if($("#gallery_preview").size()!='undefined' ){
window.onload=function(){$("#media_gallery_panel .show_hide_panel_link a").click();$("#techspec_table .show_hide_panel_link a").click();}
}
var pathname = window.location.href;
if(pathname.indexOf('#writeLink')!=-1 || pathname.indexOf('#warranty_content_panel')!=-1){
window.onload=function(){
	if(pathname.indexOf('#writeLink')!=-1){
		htmlScroll = $("#writeLink").offset().top;
	}
	else if(pathname.indexOf('#warranty_content_panel')!=-1){
		htmlScroll = $("#warranty_content_panel").offset().top;
	}
	$("html").scrollTop(htmlScroll);
}	
}

function openTechSpechTable(){
	
$(".techspecTable .main #categoryname_techspec_divfrozen").css('height',"140px");
			$(".techspecTable .main #categoryname_techspec_contentscroll").css('height',"158px");
			$(".techspecTable  #categoryname_techspec_headscroll").css('width','785px');
			$(".techspecTable .main div.content").css('width','802px');
			if($("#categoryname_techspec_headscroll").hasClass('noScroll')){
				$(".techspecTable #categoryname_techspec_headscroll").css('width','802px');
			}
			$(".techspecTable .main #categoryname_techspec_contentscroll").css('overflow-y','scroll');

			$(".section_title .show_hide_panel_link a").removeClass("show_panel").html($.validator.messages.Hide_Tire_Detail);
}

//Vehicle Registration and DOT form cloning function
	var vehicleCount;
	var uniqueValue = 0;
	function countForms(count){	
		
		uniqueValue = $(".cloned_vehicle_form").size()+1;
		document.getElementById("mandatoryField").style.display='none';
		currentFormsSize = $(".cloned_vehicle_form").size();
		vehicleCount = (parseInt(currentFormsSize) + parseInt(count));
		
		if((parseInt(currentFormsSize) + parseInt(count)) > 5){
			alert($.validator.messages.noMoreVehicles);
			return false;
		} else {
			for(var i=1; i<=count;i++){
				obj = $("#sample_vehicle_registration_form").clone().addClass("cloned_vehicle_form").attr("id","sample_vehicle_registration_form"+uniqueValue).attr("name","sample_vehicle_registration_form"+uniqueValue);
				obj.appendTo("div#clonedForms");
				obj.find('select').each(function(){
					$(this).attr("id", $(this).attr("id")+uniqueValue)
					$(this).attr("name", $(this).attr("name")+uniqueValue)
				});
				obj.find('#error_msg_id_vehicles_tires').each(function(){
					$(this).attr("id", $(this).attr("id")+uniqueValue)
					$(this).attr("name", $(this).attr("name")+uniqueValue)
				});
				$("#tireSizeBlock").attr("id","tireSizeBlock_"+uniqueValue);
				$("#tireSizeBlock_"+uniqueValue).attr("class","tireSizeBlock_size");
				$("#clonedForms select").fixIESelectWidth();
				if(uniqueValue != 1)
				{					
					$("#adMoreVehicles").attr("href","#sample_vehicle_registration_form"+uniqueValue);
					$("#adMoreVehicles12").attr("href","#sample_vehicle_registration_form"+uniqueValue);					
										
					if($("#vName").parent().parent().attr("id") == "sample_vehicle_registration_form1")
					{
													
					}
					else
					{						
						$("#vName").attr("id","vName"+uniqueValue);
						$("#vName"+uniqueValue).html("<h3 class='something'>Vehicle&nbsp;"+uniqueValue+" :</h3>");
					}					
				}
				else
				{					
					$("#vName").remove();					
					$("#primaryVehicleName").html("<h3 class='something'>"+$.validator.messages.primaryVehicle+" :</h3>");
				}
				uniqueValue++;
			}
			footerLockReposition();
			changeInVehicleSection = true;	
			return false;
		}
}
