function getSelectedValue(select){ return (select.value == undefined) ? select.options[select.selectedIndex].value : select.value; }
function getSelectedText(select){ return (select.text == undefined) ? select.options[select.selectedIndex].text : select.text; }
function addOption(selectbox,text,value){
	var optn = document.createElement("OPTION");
	optn.text = text;
	optn.value = value;
	selectbox.options.add(optn);
}
function bindDictionaryToSelectBox(selectbox, dictionary){ for(var index = 0; index < dictionary.length; index++) addOption(selectbox, dictionary[index].Name, dictionary[index].Value); }
function bindListToSelectBox(selectbox, list){ for(var index = 0; index < list.length; index++) addOption(selectbox, list[index], list[index]); }
function getAspForm(){ return (!document.forms['aspnetForm']) ? document.aspnetForm : document.forms['aspnetForm']; }
function setToLoadingSelectBox(selectbox, loading){
	selectbox.options.length = 0;
	if(loading) addOption(selectbox, "Loading...", "0");
	selectbox.disabled = true;
}
// Custom event-binder that allows for concurrent event implementations.
function BindEvent(bindingObject, bindingEvent, boundDelegate){
	try {
		var bindingEventValue = new String(bindingEvent);
		if(bindingObject.attachEvent){
			bindingObject.attachEvent(bindingEvent, boundDelegate);
		} else if(bindingObject.addEventListener){
			bindingEventValue = bindingEventValue.toLowerCase().replace("on", "");
			bindingObject.addEventListener(bindingEventValue, boundDelegate, false);
		}
	} catch (e){}
}
// Create a DHTML layer
function createLayer(name, left, top, width, height, visible, content, bg){
	var layer;
	if(document.layers){
		document.writeln('<layer name="' + name + '" left=' + left + ' top=' + top + ' width=' + width + ' height=' + height +  ' visibility=' + (visible ? '"show"' : '"hide"') + ' bgcolor=' + bg + '>');
		document.writeln(content);
		document.writeln('</layer>');
		layer = getLayer(name);
		layer.width = width;
		layer.height = height;
	}
	if(document.all){
		document.writeln('<div id="' + name + '" style="background-color: '+ bg +'; position:absolute; overflow:none; left:' + left + 'px; top:' + top + 'px; width:' + width + 'px; height:' + height + 'px;' + ' visibility:' + (visible ? 'visible;' : 'hidden;') +  '">');
		document.writeln(content);
		document.writeln('</div>');
	}
	clipLayer(name, 0, 0, width, height);
}
// get the layer object called "name"
function getLayer(name){
	if(document.layers) return(document.layers[name]);
	else if(document.all){
		if(eval('document.all.' + name) != null){
			layer = eval('document.all.' + name + '.style');
			return(layer);
		} else return(null);
	} else return(null);
}
// move layer to x,y
function moveLayer(name, x, y){
  	var layer = getLayer(name);
	if(layer != null){
	  	if(document.layers) layer.moveTo(x, y);
	  	if(document.all){ layer.left = x; layer.top  = y; }
	}
}
// toggle layer to invisible
function hideLayer(name){
  	var layer = getLayer(name);
	if(layer != null){
	  	if(document.layers) layer.visibility = "hide";
	  	if(document.all) layer.visibility = "hidden";
	}
}
// toggle layer to visible
function showLayer(name){
  	var layer = getLayer(name);
	if(layer != null){
	  	if(document.layers) layer.visibility = "show";
	  	if(document.all) layer.visibility = "visible";
	}
}
// clip layer display to clipleft, cliptip, clipright, clipbottom
function clipLayer(name, clipleft, cliptop, clipright, clipbottom){
	var layer = getLayer(name);
	if(layer != null){
		if(document.layers){
			layer.clip.left = clipleft;
			layer.clip.top = cliptop;
			layer.clip.right = clipright;
			layer.clip.bottom = clipbottom;
		}
		if(document.all) layer.clip = 'rect(' + cliptop + ' ' +  clipright + ' ' + clipbottom + ' ' + clipleft +')';
	}
}
function na_preload_img(){
	var img_list = na_preload_img.arguments;
	if(document.preloadlist == null) document.preloadlist = new Array();
	var top = document.preloadlist.length;
	for(var i=0; i < img_list.length-1; i++){
		document.preloadlist[top+i] = new Image;
		document.preloadlist[top+i].src = img_list[i+1];
	}
}
function gotoOrder(name){
	window.location = "/contactus.htm?catName=" + name;
}
function selectCatalog(){ if($('#compCatSelectBox').val()) window.location='catalogAsset.htm?catalogId=' + $('#compCatSelectBox').val(); }
function popUp(URL){
	day = new Date();
	id = day.getTime();
	eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0,width=502,height=425,left = 257,top = 179');");
}
var currentTabIndex ='1';
function selectContainer(containerId, tabObject){
	if(containerId !== currentTabIndex){
		var currentContainer = document.getElementById("container_"+currentTabIndex);
		var newContainer = document.getElementById("container_"+containerId);
		var newTab = tabObject;
		var currentTab = document.getElementById("selector_"+currentTabIndex);
		currentContainer.className = extractSelected(currentContainer.className);
		newContainer.className = insertSelected(newContainer.className);
		currentTab.className = extractSelected(currentTab.className);
		newTab.className = insertSelected(newTab.className);
		currentTabIndex = containerId;
	}
}
function extractSelected(className){ return className.substr(0, className.length -9); }
function insertSelected(className){ return className + "_selected"; }
function setRating(rating){ $('#rating').val(rating); }
function setHtml(targetId, html){ if($("#" + targetId).length) $("#" + targetId).html(html); }
function createRequestObject(){
	try{
		return (navigator.appName == "Microsoft Internet Explorer") ? new ActiveXObject("Microsoft.XMLHTTP") : new XMLHttpRequest();
	}catch(e){
		return new Object();
	}
}
var http = createRequestObject();
//------------------------------------ Tire Fitment Guide Ajax -------------------------------------------------//
var vehicleHttp = createRequestObject();
var IDMap = new Object();
var TFG = new Object();
function getServerControl(clientName){
	var id = IDMap[clientName];
	var control = document.getElementById(id);
	return control;
}
function enableSBVSubmit(){
	var submit = getServerControl('btnSearchByVehicle');
	if(submit) submit.disabled = false;
}
function pauseSizes(loading){
	// Pause sizes list box
	setToLoadingSelectBox(getServerControl('lstSizes'), loading);
	// Disable "Go" button
	var submit = getServerControl('btnSearchByVehicle');
	if(submit) submit.disabled = true;
}
function pauseStyles(loading){
	// Pause styles drop-down
	setToLoadingSelectBox(getServerControl('cmbStyles'), loading);
	// Disable dependents
	pauseSizes(false);
}
function pauseModels(loading){
	// Pause models drop-down
	setToLoadingSelectBox(getServerControl('cmbModels'), loading);
	// Disable dependents
	pauseStyles(false);
}
function pauseMakes(loading){
	// Pause makes drop-down
	setToLoadingSelectBox(getServerControl('cmbMakes'), loading);
	// Disable dependents
	pauseModels(false);
}
function pauseYears(){
	// Pause years drop-down
	setToLoadingSelectBox(getServerControl('cmbYears'), true);
	// Disable dependents
	pauseMakes(false);
}
//------------ Initial Years Loading ------------------//
function requestVehicleYears(){
	pauseYears();
	$.ajax({
		url: 'services/TireFitmentGuide.asmx/GetYearsJSON',
		dataType: "xml",
		dataFilter: function(data, type) { return data; }, 
		success: function(responseXML) {
			eval("var yearData = " + responseXML.documentElement.firstChild.nodeValue + ";");
			var years = getServerControl('cmbYears');
			years.options.length = 0;
			addOption(years, "Pick a Year", "0");
			bindListToSelectBox(years, yearData.list);
			years.disabled = false;
		}
	});
}
//------------ On Years Selection ---------------------//
function requestVehicleMakes(selectbox){
	pauseMakes(true);
	$.ajax({
		type: "POST",
		url: "services/TireFitmentGuide.asmx/GetMakesJSON",
		data: "year=" + getSelectedValue(selectbox),
		dataType: "xml",
		dataFilter: function(data, type) { return data; }, 
		success: function(responseXML) {
			eval("var tfgData = " + responseXML.documentElement.firstChild.nodeValue + ";");
			var makes = getServerControl('cmbMakes');
			makes.options.length = 0;
			addOption(makes,'Pick a Make','0');
			bindDictionaryToSelectBox(makes, tfgData.list);
			makes.disabled = false;
		}
	});
}
//------------ On Makes Selection ---------------------//
function requestVehicleModels(selectbox){
	pauseModels(true);
	$.ajax({
		type: "POST",
		url: "services/TireFitmentGuide.asmx/GetModelsJSON",
		data: "makeId=" + getSelectedValue(selectbox) + "&makeValue=" + getSelectedText(selectbox),
		dataType: "xml",
		dataFilter: function(data, type) { return data; }, 
		success: function(responseXML) {
			eval("var tfgData = " + responseXML.documentElement.firstChild.nodeValue + ";");
			var models = getServerControl('cmbModels');
			models.options.length = 0;
			addOption(models,'Pick a Model','0');
			bindDictionaryToSelectBox(models, tfgData.list);
			models.disabled = false;
		}
	});
}
//------------ On Models Selection ---------------------//
function requestVehicleStyles(selectbox){
	pauseStyles(true);
	$.ajax({
		type: "POST",
		url: "services/TireFitmentGuide.asmx/GetStylesJSON",
		data: "modelId=" + getSelectedValue(selectbox) + "&modelValue=" + getSelectedText(selectbox),
		dataType: "xml",
		dataFilter: function(data, type) { return data; }, 
		success: function(responseXML) {
			eval("var tfgData = " + responseXML.documentElement.firstChild.nodeValue + ";");
			var styles = getServerControl('cmbStyles');
			styles.options.length = 0;
			addOption(styles,'Pick a Style','0');
			bindDictionaryToSelectBox(styles, tfgData.list);
			styles.disabled = false;
		}
	});
}
//------------ On Styles Selection ---------------------//
var tireFitmentGuideTireSizeInfo = null;
var tireFitmentGuideTireSizeInfoIndex = 0;
function getTFGTireSizeAtIndex(index){
	var width = getServerControl('cmbWidth');
	if(width!=null && tireFitmentGuideTireSizeInfo!=null && tireFitmentGuideTireSizeInfo.length>index){
		tireFitmentGuideTireSizeInfoIndex = index;
		selectOptionValue(width, tireFitmentGuideTireSizeInfo[index].Width);
		requestHeights(width);
	}
}
function selectOptionValue(selectCtrl, value){
	if(value!=null && value!=""){
		for(var index=0; index < selectCtrl.options.length; index++){
			if(selectCtrl.options[index].value==value) selectCtrl.selectedIndex = index;
		}
	} else {
		selectCtrl.selectedIndex = 0;
	}
}
function requestSearchResults(selectbox){
	pauseSizes(true);
	$.ajax({
		type: "POST",
		url: "services/TireFitmentGuide.asmx/GetTireSizesJSON",
		data: "styleId=" + getSelectedValue(selectbox) + "&styleValue=" + getSelectedText(selectbox),
		dataType: "xml",
		dataFilter: function(data, type) { return data; }, 
		success: function(responseXML) {
			eval("var tfgData = " + responseXML.documentElement.firstChild.nodeValue + ";");
			tireFitmentGuideTireSizeInfo = tfgData.list;
			var sizes = getServerControl('lstSizes');
			sizes.options.length = 0;
			bindDictionaryToSelectBox(sizes, tfgData.list);
			if(sizes.length>0){
				sizes.selectedIndex = 0;
				getTFGTireSizeAtIndex(0);
				requestSubmitUrl(sizes);
			}
			sizes.disabled = false;
		}
	});	
}
//--------------- On Size Selection ----------------//
function requestSubmitUrl(selectbox){
	var submit = getServerControl('btnSearchByVehicle');
	if(submit){
		submit.disabled = false;
	} else {
		submit = getServerControl('btnRequestAQuote');
		if(submit){
			var yearBox = getServerControl('cmbYears');
			var year = (yearBox) ? getSelectedText(yearBox) : '';
			var makeBox = getServerControl('cmbMakes');
			var make = (makeBox) ? getSelectedText(makeBox) : '';
			var modelBox = getServerControl('cmbModels');
			var model = (modelBox) ? getSelectedText(modelBox) : '';
			var styleBox = getServerControl('cmbStyles');
			var style = (styleBox) ? getSelectedText(styleBox) : '';
			var styleId = (styleBox) ? getSelectedValue(styleBox) : '';
			var size = getSelectedValue(selectbox);
			// Send Request
			var raqsBody = document.getElementById("raqs_body");
			if(raqsBody!=null){
				submit.disabled = false;
				var txtSize = document.getElementById("rq_txtTireSize");
				if(txtSize!=null) txtSize.value = size;
				var txtYear = document.getElementById("rq_txtVehicleYear");
				if(txtYear!=null) txtYear.value = year;
				var txtMake = document.getElementById("rq_txtVehicleMake");
				if(txtMake!=null) txtMake.value = make;
				var txtModel = document.getElementById("rq_txtVehicleModel");
				if(txtModel!=null) txtModel.value = model;
				var txtStyle = document.getElementById("rq_txtVehicleStyle");
				if(txtStyle!=null) txtStyle.value = style;
			} else {
				submit.disabled = true;
				$.ajax({
					type: "POST",
					url: "services/TireFitmentGuide.asmx/GetSubmitUrl",
					data: "productListPage=TireFitmentProductList.htm&styleId=" + styleId + "&size=" + size + "&year=" + year + "&make=" + escape(make) + "&model=" + escape(model) + "&style=" + escape(style),
					dataType: "xml",
					dataFilter: function(data, type) { return data; }, 
					success: function(responseXML) {
						var submit = getServerControl('btnRequestAQuote');
						if(response && submit){
							submit.disabled = false;
							TFG.OnRequestAQuoteClick = function(){ eval(responseXML.documentElement.firstChild.nodeValue); }
						}
					}
				});	
			}
		}
	}
}
var knownSizeHttp = createRequestObject();
function test_searchByKnownSize(){
	var width = getServerControl('cmbWidth');
	var height = getServerControl('cmbHeight');
	var diameter = getServerControl('cmbDiameter');
	if((width!=null && height!=null && diameter!=null) && (width.value=="0" || diameter.value=="0")){
		alert("Please select a tire size before searching");
		return false;
	}
	return true;
}
function test_searchByVehicle(){
	var sizes = getServerControl('lstSizes');
	if(sizes!=null && sizes.selectedValue==""){
		alert("Please select a tire size before searching");
		return false;
	}
	return true;
}
function pauseDiameters(loading){
	setToLoadingSelectBox(getServerControl('cmbDiameter'), loading);
	var btnSubmit = getServerControl('btnSearchByKnownSize');
}
function pauseHeights(loading){
	setToLoadingSelectBox(getServerControl('cmbHeight'), loading);
	pauseDiameters(false);
}
//------------ On Width Selection ---------------------//
function handleTFGWidthSelectResponse(){
	if(knownSizeHttp.readyState == 4){
		var response = knownSizeHttp.responseXML;
		var root = (response!=null) ? response.documentElement : null;
		var content = (response!=null && root!=null) ? root.firstChild.nodeValue : '{ "list":[ "" ] }';
		eval("var tfgData = " + content + ";");
		var heights = getServerControl('cmbHeight');
		heights.options.length = 0;
		bindListToSelectBox(heights, tfgData.list);
		heights.disabled = false;
		if(heights!=null && tireFitmentGuideTireSizeInfo!=null && tireFitmentGuideTireSizeInfo.length>tireFitmentGuideTireSizeInfoIndex){
			selectOptionValue(heights, tireFitmentGuideTireSizeInfo[tireFitmentGuideTireSizeInfoIndex].Height);
		}
		requestDiameters(heights);
		var submit = getServerControl('btnSearchByKnownSize');
		submit.disabled = (response!=null && root!=null) ? false : true;
	}
}
function requestHeights(selectbox){
	pauseHeights(true);
	// Send Request
	if(selectbox.Value!=""){
		knownSizeHttp.open('GET', 'services/TireFitmentGuide.asmx/GetTireHeightsJSON?width=' + getSelectedValue(selectbox));
		knownSizeHttp.onreadystatechange = handleTFGWidthSelectResponse;
		knownSizeHttp.send(null);
	} else {
		handleTFGWidthSelectResponse();
	}
}
//------------ On Height Selection ---------------------//
function handleTFGHeightSelectResponse(){
	if(knownSizeHttp.readyState == 4){
		var response = knownSizeHttp.responseXML;
		var root = (response!=null) ? response.documentElement : null;
		var content = (response!=null && root!=null) ? root.firstChild.nodeValue : '{ "list":[ "" ] }';
		eval("var tfgData = " + content + ";");
		var diameters = getServerControl('cmbDiameter');
		diameters.options.length = 0;
		bindListToSelectBox(diameters, tfgData.list);
		diameters.disabled = false;
		if(diameters!=null && tireFitmentGuideTireSizeInfo!=null && tireFitmentGuideTireSizeInfo.length>tireFitmentGuideTireSizeInfoIndex){
			selectOptionValue(diameters, tireFitmentGuideTireSizeInfo[tireFitmentGuideTireSizeInfoIndex].Diameter);
		}
	}
}
function requestDiameters(selectbox){
	pauseDiameters(true);
	// Send Request
	if(selectbox.Value!=""){
		knownSizeHttp.open('GET', 'services/TireFitmentGuide.asmx/GetTireDiametersJSON?width=' + getSelectedValue(getServerControl('cmbWidth')) + '&height=' + getSelectedValue(selectbox));
		knownSizeHttp.onreadystatechange = handleTFGHeightSelectResponse;
		knownSizeHttp.send(null);
	} else {
		handleTFGHeightSelectResponse();
	}
}
//------------------- TFG Unload ---------------------------//
function resetTFG(){
	var yearBox = getServerControl('cmbYears');
	if(yearBox){
		yearBox.selectedIndex = 0;
		var sizes = getServerControl('lstSizes');
		if(sizes){ sizes.options.length = 0; }
		var makeBox = getServerControl('cmbMakes');
		if(makeBox) makeBox.options.length = 0;
		var modelBox = getServerControl('cmbModels');
		if(modelBox) modelBox.options.length = 0;
		var styleBox = getServerControl('cmbStyles');
		if(styleBox) styleBox.options.length = 0;
		var submit = getServerControl('btnSearchByVehicle');
		if(submit) submit.disabled = true;
	}
	var width = getServerControl('cmbWidth');
	if(width){
		width.selectedIndex = 0;
		var heights = getServerControl('cmbHeight');
		if(heights) heights.selectedIndex = 0;
		var diameters = getServerControl('cmbDiameter');
		if(diameters) diameters.selectedIndex = 0;
	}
}
function onWindowLoad(){ sortables_init(); resetTFG(); }
//------------------------------------ Showcase New Equipment Ajax ---------------------------------------------//
function sndReq(targetId, service, productId, action){
	$.ajax({
		type: "GET",
		url: service,
		data: "targetId="+targetId+"&productId="+productId+"&actionId="+action,
		dataType: "xml",
		dataFilter: function(data, type) { return data; }, 
		success: function(responseXML) {
			var rootNode = responseXML.documentElement;
			var targetId = rootNode.getAttribute("targetId");
			var fragments = rootNode.childNodes;
			var content = '';
			if(fragments.length > 1){
				for(var i=0; i < fragments.length; i++){
					if(fragments[i].nodeName == 'fragment') content += fragments[i].firstChild.nodeValue;
				}
			}else{
				content = rootNode.firstChild.nodeValue;
			}
			if(targetId && content){
				if($("#" + targetId).length) $("#" + targetId).html(content);
			}
		}
	});
}
function sndReviewReq(targetId, service, productId){
	$.ajax({
		type: "GET",
		url: service,
		data: "targetId="+targetId+"&productId="+productId,
		dataType: "xml",
		dataFilter: function(data, type) { return data; }, 
		success: function(responseXML) {
			var rootNode = responseXML.documentElement;
			var targetId = rootNode.getAttribute("targetId");
			var fragments = rootNode.childNodes;
			var content = '';
			if(fragments.length > 1){
				for(var i=0; i < fragments.length; i++){
					if(fragments[i].nodeName == 'fragment') content += fragments[i].firstChild.nodeValue;
				}
			}else{
				content = rootNode.firstChild.nodeValue;
			}
			if(targetId && content){
				if($("#" + targetId).length) $("#" + targetId).html(content);
			}
		}
	});	
}
function sendRequestForUsedEquipmentList(service){
	$.ajax({
		type: "GET",
		url: service,
		dataType: "xml",
		dataFilter: function(data, type) { return data; }, 
		success: function(responseXML) {
			var rootNode = responseXML.documentElement;
			var targetId = rootNode.getAttribute("targetId");
			var content = rootNode.firstChild.nodeValue;
			if(targetId && content){
				$("#" + targetId).html(content);
				sortables_init();
			}
		}
	});	
}
addEvent(window, "load", onWindowLoad);
var SORT_COLUMN_INDEX;
function sortables_init(){
	if($('#ecms_sortableTblCtl').length) ts_makeSortable($('#ecms_sortableTblCtl')[0]);
}
function ts_makeSortable(table){
	if(table.rows && table.rows.length > 0) var firstRow = table.rows[0];
	if(!firstRow) return;
	// We have a first row: assume it's the header, and make its contents clickable links
	for(var i=0;i<firstRow.cells.length;i++){
		var cell = firstRow.cells[i];
		var txt = cell.innerHTML;
		if(txt !='&nbsp;') cell.innerHTML = '<a href="#" class="ecms_sortableTblCtlSelector" onclick="ts_resortTable(this);return false;">'+txt+'<span class="ecms_sortableTblCtlDirection"><img src="media/arrowNull.gif" /></span></a>';
	}
}
function ts_getInnerText(el){
	if(typeof el == "string") return el;
	if(typeof el == "undefined"){ return el };
	if(el.innerText) return el.innerText;	//Not needed but it is faster
	var str = "";
	var cs = el.childNodes;
	for(var i = 0; i < cs.length; i++){
		switch (cs[i].nodeType){
			case 1: //ELEMENT_NODE
				str += ts_getInnerText(cs[i]);
				break;
			case 3:	//TEXT_NODE
				str += cs[i].nodeValue;
				break;
		}
	}
	return str;
}
function ts_resortTable(lnk){
	// get the span
	var span;
	for(var ci=0;ci<lnk.childNodes.length;ci++){
		if(lnk.childNodes[ci].tagName && lnk.childNodes[ci].tagName.toLowerCase() == 'span') span = lnk.childNodes[ci];
	}
	var spantext = ts_getInnerText(span);
	var td = lnk.parentNode;
	var column = td.cellIndex;
	var table = getParent(td,'TABLE');
	// Work out a type for the column
	if(table.rows.length <= 1) return;
	var itm = ts_getInnerText(table.rows[1].cells[column]);
	sortfn = ts_sort_caseinsensitive;
	if(itm.match(/^\d\d[\/-]\d\d[\/-]\d\d\d\d$/)) sortfn = ts_sort_date;
	if(itm.match(/^\d\d[\/-]\d\d[\/-]\d\d$/)) sortfn = ts_sort_date;
	if(itm.match(/[$]/)) sortfn = ts_sort_currency;
	if(itm.match(/^[\d\.]+$/)) sortfn = ts_sort_numeric;
	SORT_COLUMN_INDEX = column;
	var firstRow = new Array();
	var newRows = new Array();
	for(i=0;i<table.rows[0].length;i++){ firstRow[i] = table.rows[0][i]; }
	for(j=1;j<table.rows.length;j++){ newRows[j-1] = table.rows[j]; }
	newRows.sort(sortfn);
	if(span.getAttribute("sortdir") == 'down'){
		ARROW = '<img src="media/downArrowBlack.gif" />';
		newRows.reverse();
		span.setAttribute('sortdir','up');
	} else {
		ARROW = '<img src="media/upArrowBlack.gif" />';
		span.setAttribute('sortdir','down');
	}
	// We appendChild rows that already exist to the tbody, so it moves them rather than creating new ones
	// don't do sortbottom rows
	for(i=0;i<newRows.length;i++){ if(!newRows[i].className || (newRows[i].className && (newRows[i].className.indexOf('sortbottom') == -1))) table.tBodies[0].appendChild(newRows[i]);}
	// do sortbottom rows only
	for(i=0;i<newRows.length;i++){ if(newRows[i].className && (newRows[i].className.indexOf('sortbottom') != -1)) table.tBodies[0].appendChild(newRows[i]);}
	// Delete any other arrows there may be showing
	var allspans = document.getElementsByTagName("span");
	for(var ci=0;ci<allspans.length;ci++){
		if(allspans[ci].className == 'ecms_sortableTblCtlDirection' && getParent(allspans[ci],"table") == getParent(lnk,"table")){
			allspans[ci].innerHTML = '<img src="media/arrowNull.gif" />';
		}
	}
	for(var rowIndex=0; rowIndex < table.rows.length; rowIndex++){
		var row = table.rows[rowIndex];
 		row.className = (row.className.substr(0,(row.className.length -8))+(rowIndex % 2 == 0) ? "_tblRow0" : "_tblRow1");

	}
	span.innerHTML = ARROW;
}
function getParent(el, pTagName){
	if(el == null)
		return null;
	else if(el.nodeType == 1 && el.tagName.toLowerCase() == pTagName.toLowerCase())	// Gecko bug, supposed to be uppercase
		return el;
	else
		return getParent(el.parentNode, pTagName);
}
function ts_sort_date(a,b){
	// y2k notes: two digit years less than 50 are treated as 20XX, greater than 50 are treated as 19XX
	aa = ts_getInnerText(a.cells[SORT_COLUMN_INDEX]);
	bb = ts_getInnerText(b.cells[SORT_COLUMN_INDEX]);
	if(aa.length == 10){
		dt1 = aa.substr(6,4)+aa.substr(3,2)+aa.substr(0,2);
	} else {
		yr = aa.substr(6,2);
		if(parseInt(yr) < 50){ yr = '20'+yr; } else { yr = '19'+yr; }
		dt1 = yr+aa.substr(3,2)+aa.substr(0,2);
	}
	if(bb.length == 10){
		dt2 = bb.substr(6,4)+bb.substr(3,2)+bb.substr(0,2);
	} else {
		yr = bb.substr(6,2);
		if(parseInt(yr) < 50){ yr = '20'+yr; } else { yr = '19'+yr; }
		dt2 = yr+bb.substr(3,2)+bb.substr(0,2);
	}
	if(dt1==dt2) return 0;
	if(dt1<dt2) return -1;
	return 1;
}
function ts_sort_currency(a,b){
	aa = ts_getInnerText(a.cells[SORT_COLUMN_INDEX]).replace(/[^0-9.]/g,'');
	bb = ts_getInnerText(b.cells[SORT_COLUMN_INDEX]).replace(/[^0-9.]/g,'');
	return parseFloat(aa) - parseFloat(bb);
}
function ts_sort_numeric(a,b){
	aa = parseFloat(ts_getInnerText(a.cells[SORT_COLUMN_INDEX]));
	if(isNaN(aa)) aa = 0;
	bb = parseFloat(ts_getInnerText(b.cells[SORT_COLUMN_INDEX]));
	if(isNaN(bb)) bb = 0;
	return aa-bb;
}
function ts_sort_caseinsensitive(a,b){
	aa = ts_getInnerText(a.cells[SORT_COLUMN_INDEX]).toLowerCase();
	bb = ts_getInnerText(b.cells[SORT_COLUMN_INDEX]).toLowerCase();
	if(aa==bb) return 0;
	if(aa<bb) return -1;
	return 1;
}
function ts_sort_default(a,b){
	aa = ts_getInnerText(a.cells[SORT_COLUMN_INDEX]);
	bb = ts_getInnerText(b.cells[SORT_COLUMN_INDEX]);
	if(aa==bb) return 0;
	if(aa<bb) return -1;
	return 1;
}
function addEvent(elm, evType, fn, useCapture){
	if(elm.addEventListener){
		elm.addEventListener(evType, fn, useCapture);
		return true;
	} else if(elm.attachEvent){
		return elm.attachEvent("on"+evType, fn);
	} else {
		alert("Handler could not be removed");
	} return false;
}
//Industry Form Access
function getSpecificationsPage(basePath, optionId){
	var url = basePath + "popupPages/Specifications.aspx?optionId=" + optionId;
	//Set the window size (window automatically centered by this function)
	var height = 250;
	var width = 450;
	var top = parseInt((window.screen.height - height) / 2);
	var left = parseInt((window.screen.width - width) / 2);
	window.open(url, "_blank", "location=no,menubar=no,directories=no,toolbar=no,status=yes,resizable=yes,scrollbars=yes,top=" + top + "px,left=" + left + "px,width=" + width + "px,height=" + height + "px");
}
//Industry Form Access
function getRequestAQuoteForm(basePath, manufacturer, model, year, image, productType, industryId, aspect, partNumber, notAvailable){
	var url = basePath + "popupForms/dynamic/Request.aspx?manufacturer=" + manufacturer + "&model=" + model + "&year=" + year + "&image=" + image + "&productType=" + productType + "&industryId=" + industryId + "&aspect=" + aspect + "&partNumber=" + partNumber;
	if(notAvailable) url += "&productNotAvailable=true";
	//Set the window size (window automatically centered by this function)
	var height = 480;
	var width = 400;
	var top = parseInt((window.screen.height - height) / 2);
	var left = parseInt((window.screen.width - width) / 2);
	window.open(url, "_blank", "location=no,menubar=no,directories=no,toolbar=no,status=yes,resizable=yes,scrollbars=yes,top=" + top + "px,left=" + left + "px,width=" + width + "px,height=" + height + "px");
}
function getRequestAQuoteFormFromTFG(basePath, manufacturer, model, year, image, productType, industryId, aspect, notAvailable, vehicleYear, vehicleMake, vehicleModel, vehicleStyle, tireSize){
	var url = basePath + "popupForms/dynamic/Request.aspx?manufacturer=" + '' + "&model=" + '' + "&year=" + '' + "&image=" + '' + "&productType=" + productType + "&industryId=" + industryId + "&aspect=" + aspect + "&vehicleYear=" + vehicleYear + "&vehicleMake=" + escape(vehicleMake) + "&vehicleModel=" + escape(vehicleModel) + "&vehicleStyle=" + escape(vehicleStyle) + "&tireSize=" + tireSize
	if(notAvailable) url += "&productNotAvailable=true";
	//Set the window size (window automatically centered by this function)
	var height = 480;
	var width = 400;
	var top = parseInt((window.screen.height - height) / 2);
	var left = parseInt((window.screen.width - width) / 2);
	window.open(url, "_blank", "location=no,menubar=no,directories=no,toolbar=no,status=yes,resizable=yes,scrollbars=yes,top=" + top + "px,left=" + left + "px,width=" + width + "px,height=" + height + "px");
}
function getRequestABrochureForm(basePath, manufacturer, model, year, image){
	var url = basePath + "popupForms/brochureRequest/BrochureRequest.aspx?manufacturer=" + manufacturer + "&model=" + model + "&year=" + year + "&image=" + image;
	//Set the window size (window automatically centered by this function)
	var height = 480;
	var width = 400;
	var top = parseInt((window.screen.height - height) / 2);
	var left = parseInt((window.screen.width - width) / 2);
	window.open(url, "_blank", "location=no,menubar=no,directories=no,toolbar=no,status=yes,resizable=yes,scrollbars=yes,top=" + top + "px,left=" + left + "px,width=" + width + "px,height=" + height + "px");
}
function getFinancingApplication(basePath, manufacturer, model, year, amount, image){
	var url = basePath + "financing/Financing.aspx?manufacturer=" + manufacturer + "&model=" + model + "&year=" + year + "&amount=" + amount + "&image=" + image;
	//Set the window size (window automatically centered by this function)
	var height = 480;
	var width = 640;
	var top = parseInt((window.screen.height - height) / 2);
	var left = parseInt((window.screen.width - width) / 2);
	window.open(url, "_blank", "location=no,menubar=no,directories=no,toolbar=no,status=yes,resizable=yes,scrollbars=yes,top=" + top + "px,left=" + left + "px,width=" + width + "px,height=" + height + "px");
}
function getShowcasePrintProductComparison(basePath, products, areOptions){
	var url = basePath + "showcaseprintprodcompare.htm?products=" + products;
	if(areOptions) url += "&areOptions=true";
	//Set the window size (window automatically centered by this function)
	var height = 480;
	var width = 760;
	var top = parseInt((window.screen.height - height) / 2);
	var left = parseInt((window.screen.width - width) / 2);
	window.open(url, "_blank", "location=no,menubar=yes,directories=no,toolbar=no,status=yes,resizable=yes,scrollbars=yes,top=" + top + "px,left=" + left + "px,width=" + width + "px,height=" + height + "px");
}
function getCorporatePromotionsPrintPage(url){
	//Set the window size (window automatically centered by this function)
	var height = 480;
	var width = 760;
	var top = parseInt((window.screen.height - height) / 2);
	var left = parseInt((window.screen.width - width) / 2);
	window.open(url, "_blank", "location=no,menubar=yes,directories=no,toolbar=no,status=yes,resizable=yes,scrollbars=yes,top=" + top + "px,left=" + left + "px,width=" + width + "px,height=" + height + "px");
}
//----------------------------- Flash Object Triggering ----------------------------//
var flashObjectCollection = new Object();
function WriteFlashObjects(){ if(flashObjectCollection) for(var tag in flashObjectCollection) flashObjectCollection[tag].write(tag); }
BindEvent(window, "onload", WriteFlashObjects);

function ImageLib(){
	//_imageLib = this;
	this.buttons = new Buttons();
	this.preLoader = new PreLoader();
}
function PreLoader(){ this.count = 0; }
PreLoader.prototype.add = function(image, path){
	if(!image.src) return;
	var oImage = new Image;
	oImage.onload = PreLoader.prototype.onload;
	oImage.preLoader = this[this.count];
	oImage.reference = image;
	this[this.count] = oImage;
	this.count++;
	image.onload = null
	oImage.src = path;
}
PreLoader.prototype.onload = function(){ this.reference.src = this.src; }
function Buttons(){ this.count = 0; }
Buttons.prototype.add = function(image){
	var sId;
	var sState;
	if(!image.src) return;
	try { sId = image.id; } catch(e){ return e; }
	//was a state parameter passed in?
	if(arguments.length > 1){
		sState = arguments[1].toString();
		switch (sState){
			case "0" : sState = "inactive"; break;
			case "1" : sState = "active"; break;
			default: sState = "inactive"; break;
		}
	} else {
		sState = "inactive"
	}
	//Add button to the buttons collection
	Buttons.prototype[sId] = new Button(image, sState);
	//increment button count
	this.count++;
	//bind events to image if inactive
	if(sState == "inactive"){
		image.button = this[sId];
		image.onmouseover = Button.prototype.over;
		image.onmouseout = Button.prototype.out;
	}
	image.onload = null;
	//return reference to button
	return this[sId];
}
function Button(image, state){
	this.id = image.id;
	this.boundImage = image;  //reference to image
	this.isLoaded = false; //is the hover image loaded
	this.inert = new Image; //the inert state
	this.hover = new Image; //the hover state
	//load inert state
	this.inert.src = image.src;
	//load hover by naming convention
	this.hover.onload = Button.prototype.loaded;
	this.hover.button = this;
	this.hover.src = image.src.substr(0, image.src.length - ((state == "inactive") ? 4 : 6)) + "_h." + image.src.substr(image.src.length - 3, image.src.length);
}
Button.prototype.over = function(){
	var oElement = (this.button) ? this.button : this;
	if(oElement.isLoaded == false) return;
	if(oElement.boundImage.src == oElement.hover.src) return;
	oElement.boundImage.src = oElement.hover.src;
	return;
}
Button.prototype.out = function(){
	var oElement = (this.button) ? this.button : this;
	if(oElement.isLoaded == false) return;
	if(oElement.boundImage.src == oElement.inert.src) return;
	oElement.boundImage.src = oElement.inert.src;
	return;
}
Button.prototype.loaded = function(){ this.button.isLoaded = true; return; }
Button.prototype.setHover = function(path){ try { this.hover.src = path; } catch (e){ return e; } return; }
Button.prototype.toString = function(){ return this.id; }
var imageLib = new ImageLib();
function doSubmitGoogle(address, city, state, zipcode){
	document.GoogleLocalMap.q.value = address + "," + city + "," + state + "," + zipcode;
	window.open('','processor_window','menubar=no,toolbar=yes,resizable=yes,status=no,scrollbars=auto,left=25,top=25');
	document.GoogleLocalMap.target = "processor_window";
	document.GoogleLocalMap.submit();
}
function getCouponPrint(couponId){
	var cssFiles = document.getElementsByTagName('link');
	var width=400;
	var height=200;
	var viewer=window.open('','viewer','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,width='+width+',height='+height+',left=200,top=50');
	viewer.document.open();
	viewer.document.write('<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">\n');
	viewer.document.write('<html id=\"couponPopUp\">\n');
	viewer.document.write('<head>\n');
	viewer.document.write('<title>Coupon</title>\n');
	for(var x = 0; x < cssFiles.length; x++){
		viewer.document.write('<link rel=\"stylesheet\" type=\"text/css\" href=\"'+cssFiles[x].href+'\"/>\n');
	}
	viewer.document.write('</head>\n');
	viewer.document.write('<body leftmargin=\"0\" topmargin=\"0\" marginwidth=\"0\" marginheight=\"0\" class=\"couponDisplayPopup\">\n');
	viewer.document.write('<div class=\"couponPrint\">\n');
	viewer.document.write($("#" + couponId).html()+'\n');
	viewer.document.write('</div>\n');
	viewer.document.write('<div class=\"couponControls\"><input class=\"ecomm_button\" type=\"button\" name=\"print\" value=\"Print\" onClick=\"window.print()\"><input class=\"ecomm_button\" type=\"button\" name=\"close\" value=\"Close\" onClick=\"window.close()\"></div>\n');
	viewer.document.write('</body>\n');
	viewer.document.write('</html>\n');
	viewer.document.close();
}
function getGalleryDisplayImg(IMAGE){
	var pic = new Image();
	pic.onload = initGalleryPopUp;
	pic.src = IMAGE;
}
function initGalleryPopUp(){
	var pic = this;
	var cssFiles = document.getElementsByTagName('link');
	var width=(pic.width+40);
	var height=(pic.height+60);
	var viewer=window.open('','viewer','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,width='+width+',height='+height+',left=200,top=50');
	viewer.document.open();
	viewer.document.write('<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">\n');
	viewer.document.write('<html>\n');
	viewer.document.write('<head>\n');
	viewer.document.write('<title>Gallery</title>\n');
	for(var x = 0; x < cssFiles.length; x++){
		viewer.document.write('<link rel=\"stylesheet\" type=\"text/css\" href=\"'+cssFiles[x].href+'\"/>\n');
	}
	viewer.document.write('</head>\n');
	viewer.document.write('<body leftmargin=\"0\" topmargin=\"0\" marginwidth=\"0\" marginheight=\"0\" class=\"galleryDisplayPopup\">\n');
	viewer.document.write('<table class=\"galleryDisplay_tbl\" align=\"center\" width=\"'+pic.width+'\" border=\"0\" cellspacing=\"10\" cellpadding=\"0\">\n');
	viewer.document.write('<tr class=\"galleryDisplay_tblRow\" >\n');
	viewer.document.write('<td class=\"galleryDisplay_tblCell\"  align=\"center\" valign=\"top\"><image src=\"'+pic.src+'\"</td>\n');
	viewer.document.write('</tr>\n');
	viewer.document.write('<tr class=\"galleryDisplay_tblRow\" >\n');
	viewer.document.write('<td class=\"galleryDisplayControls_tblCell\" align=\"right\" valign=\"middle\"><input class=\"ecomm_button\" type=\"button\" name=\"close\" value=\"Close\" onClick=\"window.close()\"></td>\n');
	viewer.document.write('</tr>\n');
	viewer.document.write('</table>\n');
	viewer.document.write('</body>\n');
	viewer.document.write('</html>\n');
	viewer.document.close();
}
function primaryNavInit(){
	if(jQuery.browser.msie && jQuery.browser.version < 7){
		$("#primeNavList li").hover(function(){ $(this).children("ul").show(); }, function(){ $(this).children("ul").hide(); });
	}
}
function clearForm(formIdent){
	$("#" + formIdent + " input").each(function() {
		if(this.type == "text") this.value = '';
	});
}
function toggleTradeDiv(value){
	if($("#requestQuoteTrade").length) $("#requestQuoteTrade")[0].style.display = ((value || value==null) ? "" : "none");
}
function getToggleForTrade(){
	var el = $(".requestQuoteCheckWithTrade");
	if(el.length) {
		el = el[0];
		if(el!=null) {
			el = el.childNodes[0];
			if(el!=null) toggleTradeDiv(el.checked);
		}
	}
}
function AlertMe(ctrl){
	ctrl.selectedIndex = 0;
	alert(ctrl);
}
function showMore(show){
	var docElement = document.getElementById(show.id+'More');
	if(docElement != null){
		if(docElement.style.display == 'none'){
			docElement.style.display = 'block';
			show.innerHTML = "<div class='navItemLink'><a class=\"leftNavItemViewMore\">Hide Extra...</a></div>";
		} else{
			docElement.style.display = 'none';
			show.innerHTML = "<div class='navItemLink'><a class=\"leftNavItemViewMore\">View More...</a></div>";
		}
	}
	return;
}
function doHourglass(){
	var f = this.document.getElementById('endeavor_searchbox');
	if(f && f.searchProducts){
		var q = f.searchProducts;
		if((q.value == 'Search for Brand, Product or Part Number') || (q.value == '')){
			return false;
		} else {
			this.document.body.style.cursor = 'wait';
		}
		f.searchKeywordLookupId.value='';
		f.searchKeywordLookupName.value='';
	} else {
		this.document.body.style.cursor = 'wait';
	}
	return true;
}
function MM_preloadImages(){
	var d=document;
	if(d.images){
		if(!d.MM_p) d.MM_p=new Array();
		var i,j=d.MM_p.length,a=MM_preloadImages.arguments;
		for(i=0; i<a.length; i++){
			if(a[i].indexOf("#")!=0){
				d.MM_p[j]=new Image;
				d.MM_p[j++].src=a[i];
			}
		}
	}
}
function MM_swapImgRestore(){ var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc; }
function MM_findObj(n, d){
	var p,i,x;
	if(!d) d=document;
	if((p=n.indexOf("?"))>0&&parent.frames.length){
		d=parent.frames[n.substring(p+1)].document;
		n=n.substring(0,p);
	}
	if(!(x=d[n])&&d.all) x=d.all[n];
	for(i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
	for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
	if(!x && d.getElementById) x=d.getElementById(n);
	return x;
}
function MM_swapImage(){
	var i,j=0,x,a=MM_swapImage.arguments;
	document.MM_sr=new Array;
	for(i=0;i<(a.length-2);i+=3){
		if((x=MM_findObj(a[i]))!=null){
			document.MM_sr[j++]=x;
			if(!x.oSrc) x.oSrc=x.src;
			x.src=a[i+2];
		}
	}
}
function updateCheckoutStatus(orderguid){ $.post("/Services/OrderServices.asmx/UpdateOrderStatus", { orderGuid: orderguid }); }
BindEvent(window,"onload", primaryNavInit);