/* Code for confirmation box on the basket page */
var url = decodeURIComponent(window.location.href);
var arr=url.split('/');

window.onkeydown = function (e) {
	var keyCode = (window.Event) ? e.which : e.keyCode;
	if(keyCode==116){
		window.onbeforeunload = UnPopIt;
	}
}
function PopIt(e) {
	return "您真的要退出么?\n如果您有什么问题, 请与我们电话联系.";
}
function UnPopIt(e)  {
	window.onbeforeunload = null;
}
/* Code for confirmation box on the basket page */

if(window.opener){
	$(document).ready(function(){
		//$('#liveChatLink').hide();
	});
//getElementById('liveChatLink').style.display='none';
}

var carParts = "car-parts";
var hRotator = 0;
var qSearchKey = "/search/";
var _strCurrentAd = "ad1-1";
var strXor = "6";
var arrWords = new Array();
var arrMessages = new Array();

arrWords[0] = "`sem";
arrWords[1] = "eshr";
arrWords[2] = "qghm";
arrWords[3] = "etgv";
arrWords[4] = "dgurgtb";
arrWords[5] = "unor";
arrWords[6] = "esk";
arrWords[7] = "rqgr";
arrWords[8] = "doren";
arrWords[9] = "gtuc";
arrWords[10] = "guu";

arrMessages[0] = "Uqcgtoha!u&dgb*&k!mg'";
arrMessages[1] = "_is&mouu&ist&kirnct&qorn&rniuc&jovu";
arrMessages[2] = "Egtc`sj&hiq'";
arrMessages[3] = "G&tiuc&d&gh&irnct&hgkc&qisjb&ukcjj&gu&uqccr'";
arrMessages[4] = "O&mhiq&is&gtc*&dsr&qngr&gk&O9";
arrMessages[5] = "Vti`ghor&ou&rnc&eikkih&etsren&i`&rnc&eihpctugroihgj&etovvjc";
arrMessages[6] = "Uqcgtoha&ou&`it&rniuc&qni&gtch!r&ejcpct&chisan&ri&dc&qorr";

var arrReservedKeywords = new Array("select","update","delete","drop","table","describe","desc","asc","group","having","where","order","limit","rename","revoke","union","unique","while","return","schema","sql","trigger","upgrade","inout","create");

function InArray(arr, val)
{
	var exists = -1;
	for(var i = 0; i < arr.length; i++)
	{
		if(arr[i][1] == val)
		{
			exists = i;
			break;
		}
	}
	return exists;
}

function xorString(strValue)
{
    var strReturn = "";
    
	for(var i = 0; i < strValue.length; ++i)
	{
		strReturn+=String.fromCharCode(strXor^strValue.charCodeAt(i));
	}
	
	return strReturn;
}

function currencyFormatted(dAmount)
{
  var dMoney = parseFloat(dAmount);
  var cMinus = '';

  if (isNaN(dMoney))
  {
    dMoney = 0.00;
  }

  if (dMoney < 0)
  {
    cMinus = '-';
  }

  dMoney = Math.abs(dMoney);
  dMoney = parseInt((dMoney + .005) * 100);
  dMoney = dMoney / 100;

  var sMoney = new String(dMoney);

  if (sMoney.indexOf('.') < 0)
  {
    sMoney += '.00';
  }

  if (sMoney.indexOf('.') == (sMoney.length - 2))
  {
    sMoney += '0';
  }

  sMoney = cMinus + sMoney;

  return sMoney;  
}

function postGetOffForm(ob)
{
	if(ob.value == "" || ob.value == "在此输入您的邮件")
	{
		alert("请输入您的邮件.");
	}
	else
	{
		if(checkEmail(ob.value) == false)
		{
			alert("请输入有效的的电子邮件地址.");
		}
		else
		{
			alert("感谢您的注册.");
			ob.value = "在此输入您的邮件";
		}
	}
}

function clearDefaultValue(objInput)
{
  if (objInput.getAttribute("clearedDefault") != "true")
  {
    objInput.value = "";
    objInput.setAttribute("clearedDefault", "true");
  }
}

String.prototype.isValidCardNumber = function(){	
	// replace any white space in the card number	
	var number = this.replace(/\s+/g, '') ;	
	
    if (number.match("1111222233334444"))
    {
        return false;
    }
	
	//replace if contains non-numbers	
	if(number.match(/\D/))
	{		
		return false ;	
	}	
	// convert to array and reverse the number	
	number = number.split('').reverse().join('') ;	
	
	// loop through the number one digit at a time	
	// double the value of every second digit starting	
	// from the right, and concatenate the new values 	
	// with the unaffected digits	
	var digits = '';	
	for(var i = 0; i < number.length; i++)
	{		
		digits += '' + ((i%2) ?			number.charAt(i) * 2 :			number.charAt(i)) ;	
	}	
	
	// add all of the single digits together	
	var sum = 0 ;	
	for (var i = 0; i < digits.length; i++)
	{		
		sum += (digits.charAt(i) * 1) ;	
	}	//alert(sum) ;	
	
	// valid card numbers will be transformed into	// a multiple of 10	
	
	return (sum % 10) ? false : true ;
}


function checkQuantity(objInput)
{
	if (objInput.value == "0" || objInput.value == "")
	{
		objInput.value = 1;
	}
}

function numericOnly(objEvent)
{
	var objReg = new RegExp("^\d*\.?\d*$");   
	var objEvent = objEvent || window.event;  
	var strKeyCode = objEvent.keyCode || objEvent.which;

	var strKey = String.fromCharCode( strKeyCode );
	var strRegEx = /[0-9]|\./;
	
	if (!strRegEx.test(strKey) && strKeyCode != "9" &&strKeyCode != "8") 
	{ 
		objEvent.returnValue = false;
		
		// Not valid for IE
		try
		{
			objEvent.preventDefault();
		}
		catch (e){}
	}
}

function quickSearchCheck(e, bCarSearch)
{
  var objEvent = objEvent || window.event;
  var strKeyCode = objEvent.keyCode || objEvent.which;

  if (strKeyCode == "13")
  {
    quickSearch(bCarSearch);
  }
}

function selectCategory(strCode)
{
	startLoading("_selectCategory('" + strCode + "')");
}

function _selectCategory(strCode)
{
	var objAjax = new CAjax();
	var objDiv;
	
	if (objAjax.open("dynamic/selectCategory.php?catCode=" + strCode, true))
	{
		objDiv = document.getElementById("bodyC");
		objDiv.innerHTML = objAjax.getResponse();		
	}	
	
	endLoading();
}

function showNotes(strProductCode)
{
	var strDivId = "notes_" + strProductCode;
	var objDiv = document.getElementById(strDivId);
	
	if (objDiv.getAttribute("displayed") == "true")
	{
		
		CollapseDiv(strDivId);
		objDiv.setAttribute("displayed", "false");
	}
	else
	{
		ExpandDiv(strDivId);
		objDiv.setAttribute("displayed", "true");
	}
}

function HExpandDiv(strDivId)
{
	var objDiv = document.getElementById(strDivId);
	var iWidth = parseInt(objDiv.getAttribute("origWidth"));

	if (objDiv.getAttribute("expanded") != "true")
	{
		objDiv.setAttribute("expanded", "true");
		objDiv.setAttribute("collapsed", "false");
		
		//objDiv.style.height = 0;
		objDiv.style.overflow = "hidden";
		
		objDiv.style.display = "block";

		if (!iWidth)
		{
			objDiv.setAttribute("origWidth", objDiv.offsetWidth);
			iWidth = objDiv.offsetWidth;
		}

		objDiv.style.display = "none";
		
		objDiv.style.width = 0;

		setTimeout("_HExpandDiv('" + strDivId + "', 0, " + iWidth + ")", 30);
	}
}

function _HExpandDiv(strDivId, iWidth, iMaxWidth)
{
	var objDiv = document.getElementById(strDivId);

	if (iWidth == 0)
	{
		objDiv.style.display = "block";
	}

	iWidth += 5;
	
	if (iWidth < iMaxWidth)
	{
		
		objDiv.style.width = iWidth;
		setTimeout("_HExpandDiv('" + strDivId + "', " + iWidth + ", " + iMaxWidth + ")", 20);
	}
	else
	{
		objDiv.style.width = iMaxWidth;
	}
}

function ExpandDiv(strDivId)
{
	var objDiv = document.getElementById(strDivId);
	if(objDiv)
	{
		var iHeight = parseInt(objDiv.getAttribute("origHeight"));
	
		if (objDiv.getAttribute("expanded") != "true")
		{
			objDiv.setAttribute("expanded", "true");
			objDiv.setAttribute("collapsed", "false");
			
			//objDiv.style.height = 0;
			objDiv.style.overflow = "hidden";
			objDiv.style.whiteSpace = "nowrap";
			objDiv.style.display = "block";

			if (!iHeight)
			{
				objDiv.setAttribute("origHeight", objDiv.offsetHeight);
				iHeight = objDiv.offsetHeight;
			}

			objDiv.style.display = "none";
			
			objDiv.style.height = 0;

			setTimeout("_ExpandDiv('" + strDivId + "', 0, " + iHeight + ")", 30);
		}
	}
}

function _ExpandDiv(strDivId, iHeight, iMaxHeight)
{
	var objDiv = document.getElementById(strDivId);

	if (iHeight == 0)
	{
		objDiv.style.display = "block";
		
	}

	iHeight += 5;
	
	if (iHeight < iMaxHeight)
	{
		
		objDiv.style.height = iHeight;
		setTimeout("_ExpandDiv('" + strDivId + "', " + iHeight + ", " + iMaxHeight + ")", 20);
	}
	else
	{
		objDiv.style.height = iMaxHeight;
		objDiv.style.height = "auto";
	}
}

function HCollapseDiv(strDivId, strDivToExpand)
{
	var objDiv = document.getElementById(strDivId);
	var iWidth = parseInt(objDiv.getAttribute("origWidth"));

	if (objDiv.getAttribute("collapsed") != "true")
	{
		objDiv.setAttribute("collapsed", "true");
		objDiv.setAttribute("expanded", "false");
		
		if (!iWidth)
		{
			objDiv.setAttribute("origWidth", GetObjWidth(objDiv));
			iWidth = parseInt(objDiv.getAttribute("origWidth"));
		}
		
		objDiv.style.overflow = "scroll";
		objDiv.style.whiteSpace = "nowrap";
		
		setTimeout("_HCollapseDiv('" + strDivId + "', " + iWidth + ", '" + strDivToExpand + "')", 20);
	}
}

function _HCollapseDiv(strDivId, iWidth, strDivToExpand)
{
	var objDiv = document.getElementById(strDivId);
	
	iWidth -= 5;
		
	if (iWidth > 0)
	{
		objDiv.style.width = iWidth;
		setTimeout("_HCollapseDiv('" + strDivId + "', " + iWidth + ", '" + strDivToExpand + "')", 10);
	}
	else
	{
		objDiv.style.display = "none";

		if (strDivToExpand != undefined)
		{
			HExpandDiv(strDivToExpand);
		}
	}
}

function CollapseDiv(strDivId, strDivToExpand)
{
	var objDiv = document.getElementById(strDivId);
	if(objDiv)
	{
		var iHeight = parseInt(objDiv.getAttribute("origHeight"));
	}
	if (objDiv.getAttribute("collapsed") != "true")
	{
		objDiv.setAttribute("collapsed", "true");
		objDiv.setAttribute("expanded", "false");
		
		if (!iHeight)
		{
			objDiv.setAttribute("origHeight", GetObjHeight(objDiv));
			iHeight = parseInt(objDiv.getAttribute("origHeight"));
		}
		
		objDiv.style.overflow = "hidden";

		setTimeout("_CollapseDiv('" + strDivId + "', " + iHeight + ", '" + strDivToExpand + "')", 20);
	}
}

function _CollapseDiv(strDivId, iHeight, strDivToExpand)
{
	var objDiv = document.getElementById(strDivId);
	
	iHeight -= 5;
		
	if (iHeight > 0)
	{
		objDiv.style.height = iHeight;
		setTimeout("_CollapseDiv('" + strDivId + "', " + iHeight + ", '" + strDivToExpand + "')", 10);
	}
	else
	{
		objDiv.style.display = "none";

		if (strDivToExpand != "undefined")
		{
			ExpandDiv(strDivToExpand);
		}
	}
}

function GetObjHeight(objItem)
{
	return findBottom(objItem) - findTop(objItem);
}

function GetObjWidth(objItem)
{
	return findRight(objItem) - findLeft(objItem);
}

function filterProductResults()
{
	var objLoading = document.getElementById("resultsLoading");
	var objResults = document.getElementById("results");
	var objNoResults = document.getElementById("noResults");
	var objNoProducts = document.getElementById("noProducts");
	
	//objLoading.style.display = "block";
	objResults.style.display = "none";
	objNoResults.style.display = "none";
	objNoProducts.style.display = "none";

	//setTimeout("_filterProductResults()", 1000);
	_filterProductResults();
}

function resetModelFilter()
{
  var objElement = document.getElementById("models");
  objElement.value = "";
  
  clearFilters("modelListFilter");
  
  filterProductResults();
}


function changeModelTypeFilter(objLink, strModel)
{
  var objElement = document.getElementById("models");
  objElement.value = strModel;
  
  clearFilters("modelListFilter");
  
  objLink.className = "selected";
  filterProductResults();
}

function resetBodyTypeFilter()
{
  var objElement = document.getElementById("bodyTypes");
  objElement.value = "";
  
  clearFilters("bodyListFilter");
  
  filterProductResults();
}

function changeBodyTypeFilter(objLink, strBodyType)
{
  var objElement = document.getElementById("bodyTypes");
  objElement.value = strBodyType;
  
  clearFilters("bodyListFilter");
  
  objLink.className = "selected";
  filterProductResults();
}

function resetBrandFilter()
{
  var objElement = document.getElementById("brands");
  objElement.value = "";

  clearFilters("brandListFilter");
  if(document.getElementById("ball"))
  {
	//document.getElementById("ball").style.visibility = "hidden";
  }
  filterProductResults();
}

function resetBrandFilterPitlane()
{
  var objElement = document.getElementById("brands");
  objElement.value = "";
  jQuery('div.fe_products').show();
  clearFilters("brandListFilter");
  if(document.getElementById("ball"))
  {
	//document.getElementById("ball").style.visibility = "hidden";
  }
  filterProductResults();
}
function changeBrandFilter(objLink, strBrand)
{
  var objElement = document.getElementById("brands");
  objElement.value = strBrand;
  
  clearFilters("brandListFilter");
  if(document.getElementById("ball"))
  {
	//document.getElementById("ball").style.visibility = "visible";
  }
  objLink.className = "selected";
  filterProductResults();
}

function changeBrandFilterPitlane(objLink, strBrand)
{
  var objElement = document.getElementById("brands");
  objElement.value = strBrand;
  var brandName = strBrand.replace("&", "and");
  //alert(brandName);
  jQuery('div.fe_products').hide();
  jQuery('#b_'+brandName).show();
  
  clearFilters("brandListFilter");
  if(document.getElementById("ball"))
  {
	document.getElementById("ball").style.visibility = "visible";
  }
  objLink.className = "selected";
  filterProductResults();
}

function changePositionFilter(objLink, strPosition)
{
  //var objElement = document.getElementById("positions");
  //objElement.value = strPosition;
  var pval = "";
  //clearFilters("positionListFilter");
	$('#positionListFilter :checkbox:checked').each(function() {
			if(pval == "") pval = $(this).val();
			else pval += "," + $(this).val();
				});
	alert(pval);
  //objLink.className = "selected";
  filterProductResults();
}

function changeFuelTypeFilter(objLink, strFuelType)
{
  var objElement = document.getElementById("fuelTypes");
  objElement.value = strFuelType;
  
  clearFilters("fuelTypeListFilter");
  
  objLink.className = "selected";
  filterProductResults();
}

function resetPositonFilter()
{
  var objElement = document.getElementById("positions");
  objElement.value = "";
  
  clearFilters("positionListFilter");
  
  filterProductResults();
}

function resetFuelTypeFilter()
{
  var objElement = document.getElementById("fuelTypes");
  objElement.value = "";
  
  clearFilters("fuelTypeListFilter");
  
  filterProductResults();
}

function clearFilters(strId)
{
  var objDiv = document.getElementById(strId);
  
  var arrLinks = objDiv.getElementsByTagName("a");
  
  for (var i = 0; i < arrLinks.length; i++)
  {
    if (arrLinks[i].getAttribute("filterLink") == "true")
    {
      arrLinks[i].className = "";
    }
  }
}

function sendNewPageOrder(arrPages)
{
	var objPagesNode, objAjax;
	var objPagesXml = xml_createXmlDom();

	var objFilterNode = document.getElementById("filtering");
	
	if (objFilterNode)
	{
	  var strCacheName = objFilterNode.getAttribute("cachename");
  	
	  objPagesXml.loadXML("<pages/>");
	  objPagesNode = objPagesXml.selectSingleNode("/pages");
  	
	  objPagesNode.setAttribute("cacheName", strCacheName);
  	
	  for (var i = 0; i < arrPages.length; i++)
	  {
		  xml_createNode(objPagesNode, "page", arrPages[i]);
	  }
  	
	  objAjax = new CAjax();
  	
	  if (objAjax.open("/dynamic/updatePages.php", false))
	  {
		  objAjax.send(objPagesNode.xml);
	  }
	}

}

function showAllProductResults()
{
	var objModels = document.getElementById("models");
	var objBodyTypes = document.getElementById("bodyTypes");
	var objBrands = document.getElementById("brands");
	var objFuelTypes = document.getElementById("fuelTypes");
	var objPositions = document.getElementById("positions");
	
	objModels[0].selected = true;
	objBodyTypes[0].selected = true;
	objBrands[0].selected = true;
	objFuelTypes[0].selected = true;
	objPositions[0].selected = true;
	
	filterProductResults();
}

function filterListPagination(pageNo, ftype)
{
	window.scrollTo(200, 200);
	if(pageNo == 0) document.getElementById("hidCurrentPage").value = 1;
	else document.getElementById("hidCurrentPage").value = pageNo;
	/*
	if(ftype == 10)
	{
		_sortNonCarParts('sortBy');
	}
	else _filterProductResults(ftype);
	*/
	_filterProductResults(ftype);
}

function paginateRecords(iResults)
{
	var counter = 0, offset = 0, strType = "";
	var totalR = document.getElementById("cboPage").value;
	var thisPage = document.getElementById("hidCurrentPage").value;
	var objDivs = document.getElementsByTagName("div");
	
	var limitRecords = (totalR * thisPage);
	if(thisPage > 1) offset = (totalR * (parseInt(thisPage) - 1));
	document.getElementById("listOffset").innerHTML = (parseInt(offset) + 1);
	if(limitRecords > iResults) document.getElementById("listLimit").innerHTML = iResults;
	else document.getElementById("listLimit").innerHTML = limitRecords;

	for (var i = 0; i < objDivs.length; i++)
	{
		objDiv = objDivs[i];
		strType = objDiv.getAttribute("type");
		if (strType == "productResult")
		{
			strId = objDiv.getAttribute("id");
			if(document.getElementById(strId).style.display == "block")
			{
				if(counter >= limitRecords || counter < offset) { hideDiv(strId); }
				counter++;
			}
		}
	}
	createPagination();
}

function _filterProductResults(ftype)
{
	objLoading = document.getElementById("resultsLoadingProductsListing");
	objLoading.style.display = "block";
	var objDiv, strType, strId, objNoResults, objLoading, objResults, objFilteredNumber, iResults;
	var objDivs;
	var strModel, strBodyType, strYear, strBrand, strFuelType, strSelectedModel, strSelectedBodyType, strSelectedBrand, strSelectedFuelType, strSelectedPosition, strPosition, strPrice;
	var bResults = false;
	var arrPages = new Array();
	var arrPrices = new Array();
	var arrBrands = new Array();
	var arrType = new Array();
	var arrLowRange = new Array();
	var arrHighRange = new Array();
	var objDisplayPageLabel = document.getElementById("DisplayPageLabel");
	var objSortBy = document.getElementById("sortBy");
	var objSortBy2 = document.getElementById("sortBy2");
	var totalR = document.getElementById("cboPage").value;
	var thisPage = document.getElementById("hidCurrentPage").value;
	
	iResults = 0;
	objDivs = document.getElementsByTagName("div");
	objResults = document.getElementById("results");
	//objNoResults = document.getElementById("noResults");
	objNoProducts = document.getElementById("noProducts");
	objFilteredNumber = document.getElementById("filteredNumber");
	
	strSelectedModel = getFormValue("models");
	strSelectedBodyType = getFormValue("bodyTypes");
	strSelectedBrand = getFormValue("brands");
	strSelectedFuelType = getFormValue("fuelTypes");
	strSelectedPosition = getFormValue("positions");
	
	var chosenPRange = 0;
	var ps = 0;
	var chosenFilters = "";
	var chosenBrands = "";
	var lowRange = 0, highRange = 0, showIt = 0, cnt = 0, cntPrices = 0, cntB = 0;
	
	$('#positionListFilter :checkbox:checked').each(function() {
			chosenFilters += $(this).val() + ",";
				});
	$('#brandListFilter :checkbox:checked').each(function() {
			chosenBrands += $(this).val() + ",";
				});
	$('#priceListFilter :checkbox:checked').each(function() {
			priceValues = $(this).val().split("-");
			arrLowRange[chosenPRange] = priceValues[0];
			arrHighRange[chosenPRange] = priceValues[1];
			chosenPRange++;
				});
	if(ftype == 5)
	{
		chosenFilters = "";
		chosenBrands = "";
		chosenPRange = 0;
	}
	for (var i = 0; i < objDivs.length; i++)
	{
		objDiv = objDivs[i];
		strType = objDiv.getAttribute("type");
	
		if (strType == "productResult")
		{
			showIt = 0;
			strModel = objDiv.getAttribute("lModel");
			strBodyType = objDiv.getAttribute("lBodyType");
			strBrand = objDiv.getAttribute("lBrand");
			strFuelType = objDiv.getAttribute("lFuelType");
			strPosition = objDiv.getAttribute("lPosition");
			strPrice = objDiv.getAttribute("price");
			strId = objDiv.getAttribute("id");
			
			if(chosenPRange == 0) showIt = 1;
			else
			{
				for(var p = 0; p < chosenPRange; p++)
				{
					if((parseFloat(strPrice) >= parseFloat(arrLowRange[p]) && parseFloat(strPrice) <= parseFloat(arrHighRange[p])))
					{ showIt = 1; }
				}
			}
			
			if ((strModel.indexOf(strSelectedModel) >= 0 || strSelectedModel == "") &&
					(strBodyType.indexOf(strSelectedBodyType) >= 0 || strSelectedBodyType == "") &&
					((chosenBrands.indexOf(strBrand + ",") >= 0 && strBrand.replace(" ", "") != "") || chosenBrands == "") &&
					(strFuelType.indexOf(strSelectedFuelType) >= 0 || strSelectedFuelType == "") &&
					(showIt == 1) &&
					((chosenFilters.indexOf(strPosition + ",") >= 0 && strPosition != "") || chosenFilters == ""))
			{
				if (objDiv.getAttribute("stockHidden") != "true")
				{
					showDiv(strId);
					bResults = true;
					iResults ++;
					if(strPosition != "")
					{
						ps = InArray(arrType, strPosition);
						if(ps == -1)
						{
							arrType[cnt] = new Array();
							arrType[cnt][1] = strPosition;
							arrType[cnt][2] = 1;
							cnt++;
						}
						else if(arrType[ps][1] == strPosition)
						{
							arrType[ps][2] = (parseInt(arrType[ps][2]) + 1);
						}
					}
					
					if(strBrand != "")
					{
						ps = InArray(arrBrands, strBrand);
						if(ps == -1)
						{
							arrBrands[cntB] = new Array();
							arrBrands[cntB][1] = strBrand;
							arrBrands[cntB][2] = 1;
							cntB++;
						}
						else if(arrBrands[ps][1] == strBrand)
						{
							arrBrands[ps][2] = (parseInt(arrBrands[ps][2]) + 1);
						}
					}
					if(strPrice != "")
					{
						arrPrices[cntPrices] = strPrice;
						cntPrices++;
					}
				}
				objDiv.setAttribute("filterHidden", "false");
			}
			else
			{
				objDiv.setAttribute("filterHidden", "true");
				hideDiv(strId);
			}
		}
	}

	
	if (!bResults)
	{
		objDisplayPageLabel.style.display = "none";
		objNoProducts.style.display = "block";
		objSortBy.disabled = "true";
		objSortBy2.disabled = "true";
	}
	else
	{
		if (objSortBy.getAttribute("allow") == "true")
		{
			objSortBy.disabled = "";
			objSortBy2.disabled = "";
		}
		objSortBy.disabled = "";
		objSortBy2.disabled = "";
		objNoProducts.style.display = "none";
		objDisplayPageLabel.style.display = "block";
	}
	
	objFilteredNumber.innerHTML = iResults;
	document.getElementById("hidTotalRecords").value = iResults;

	if(ftype == 1 || ftype == 5)
	{
		filterTypeList(arrType);
		filterPricesList(arrPrices);
	}
	if(ftype == 2)
	{
		filterPricesList(arrPrices);
	}
	
	paginateRecords(iResults);
	
	objLoading.style.display = "none";
	objResults.style.display = "block";
}

function filterBrandsList(arrBrands)
{
	var typeHTML = '';
	if(arrBrands.length > 0) typeHTML = '<p class="RFHeadP">BY BRAND</p>';
	arrBrands.sort();
	for(var t = 0; t < arrBrands.length; t++)
	{
		typeHTML += '<div class="ChkBoxDiv"><p><input type="checkbox" name="" id="" value="' + arrBrands[t][1] + '" onclick="javascript:filterListPagination(0, 1); return true;" /> <span>' + arrBrands[t][1] + ' (' + arrBrands[t][2] + ')</span></p></div>';
	}
	if(document.getElementById("brandListFilter")) document.getElementById("brandListFilter").innerHTML = typeHTML;
}

function filterTypeList(arrType)
{
	var typeHTML = '';
	if(arrType.length > 0) typeHTML = '<p class="RFHeadP">BY TYPE</p>';
	arrType.sort();
	for(var t = 0; t < arrType.length; t++)
	{
		typeHTML += '<div class="ChkBoxDiv"><p><input type="checkbox" name="" id="" value="' + arrType[t][1] + '" onclick="javascript:filterListPagination(0, 2); return true;" /> <span>' + arrType[t][1] + ' (' + arrType[t][2] + ')</span></p></div>';
	}
	if(document.getElementById("positionListFilter")) document.getElementById("positionListFilter").innerHTML = typeHTML;
}

function compare(a,b)
{
	return a-b;
}

function filterPricesList(arrPrices)
{
	arrPrices.sort(compare);
	var min =0, max = 0;
	var minValue = arrPrices[0];
	var maxValue = arrPrices[(arrPrices.length - 1)];
	var priceRangeHTML = '';
	if(arrPrices.length > 0) priceRangeHTML = '<p class="RFHeadP">BY PRICE</p>';
	var variations = Math.ceil(parseFloat(maxValue) / 10);
	var incrementBy = (Math.ceil(parseInt(variations) / 4) * 10);
	var lowerRange = 0, totalVal = 0;
	var higherRange = ((parseInt(lowerRange) + parseInt(incrementBy)) - 0.01);
	if(parseInt(variations) > 4) variations = 4;
	
	for(var cnt = 0; cnt < variations; cnt++)
	{
		totalVal = 0;
		if(parseFloat(lowerRange) < parseFloat(maxValue))
		{
			if(parseFloat(minValue) > parseFloat(lowerRange)) min = minValue;
			else min = lowerRange;
			
			if(parseFloat(higherRange) < parseFloat(maxValue)) max = higherRange;
			else max = maxValue;
			
			if(parseFloat(minValue) < parseFloat(higherRange))
			{
				totalVal = InRange(roundNumber(min, 2), roundNumber(max, 2), arrPrices);
				//alert(totalVal);
				priceRangeHTML += '<div class="ChkBoxDiv"><p><input type="checkbox" onclick="javascript:filterListPagination(0, 3); return true;" name="" id="" value="' + roundNumber(min, 2) + '-' + roundNumber(max, 2) + '" /> <span>' + roundNumber(min, 2) + ' - ' + roundNumber(max, 2) + ' (' + totalVal + ')</span></p></div>';
			}
			lowerRange = parseFloat(lowerRange) + parseFloat(incrementBy);
			higherRange = parseFloat(higherRange) + parseFloat(incrementBy);
		}
	}
	if(document.getElementById("priceListFilter")) document.getElementById("priceListFilter").innerHTML = priceRangeHTML;
	
}

function InRange(min, max, arr)
{
	arr.sort(compare);
	var occurences = 0;
	for(var r = 0; r < arr.length; r++)
	{
		//alert(arr[r]);
		if(r > max)
		{
			break;
		}
		else if(parseFloat(arr[r]) >= parseFloat(min) && parseFloat(arr[r]) <= parseFloat(max)) 
		{
			occurences++;
		}
	}
	return occurences;
}

function roundNumber(num, dec) 
{
	var ans = Math.round(num * Math.pow(10, dec)) / Math.pow(10, dec);
	if(ans.toString().indexOf(".") < 0) ans = ans + ".00";
	return ans;
}

function changeTotalProductsDisplay(val)
{
	document.getElementById("hidCurrentPage").value = 1;
	document.getElementById("cboPage").value = val;
	document.getElementById("cboPage2").value = val;
	_filterProductResults();
}

function createPagination()
{
	var pager = new Pager();
	pager.init(); 
	pager.showPageNav('pager', 'pagingLinks'); 
	pager.showPageNav('pager', 'pagingLinks2');
}

function filterTheFilters(strFilterDivId, strType)
{
	//alert(strFilterDivId);
	//alert(strType);
	var bOk = false;
	strSelectedModel = getFormValue("models");
	strSelectedBodyType = getFormValue("bodyTypes");
	strSelectedBrand = getFormValue("brands");
	strSelectedFuelType = getFormValue("fuelTypes");
	strSelectedPosition = getFormValue("positions");
  
  var bContinue = true;

  
  if (bContinue)
  {
    objDivs = document.getElementsByTagName("div");
    var objFilterDiv = document.getElementById(strFilterDivId);

    if (!objFilterDiv) return;
    
		var objLinks = objFilterDiv.getElementsByTagName("a");

    for (var j = 0; j < objLinks.length; j++)
		{
			var objLink = objLinks[j];
      bOk = false;
      
			 if (objLink.getAttribute("filterLink") == "true")
			 {
			   
          switch(strType)
          {
          case "brand":
            strSelectedBrand = objLink.getAttribute("val");
            break;
          case "model":
            strSelectedModel = objLink.getAttribute("val");
            break;
          case "bodyType":
            strSelectedBodyType = objLink.getAttribute("val");
            break;
          case "fuelType":
            strSelectedFuelType = objLink.getAttribute("val");
            break;
          case "position":
            strSelectedPosition = objLink.getAttribute("val");
            break; 
          }

          for (var i = 0; i < objDivs.length; i++)
	        {
		        objDiv = objDivs[i];
      		  strRowType = objDiv.getAttribute("type");
      		  
		        if (strRowType == "productResult")
		        {
			        strModel = objDiv.getAttribute("lModel");
			        strBodyType = objDiv.getAttribute("lBodyType");
			        strBrand = objDiv.getAttribute("lBrand");
			        strFuelType = objDiv.getAttribute("lFuelType");
			        strPosition = objDiv.getAttribute("lPosition");
 
	            if ((strModel.indexOf(strSelectedModel) >= 0 || strSelectedModel == "") &&
			          (strBodyType.indexOf(strSelectedBodyType) >= 0 || strSelectedBodyType == "") &&
			          (strBrand.indexOf(strSelectedBrand) >= 0 || strSelectedBrand == "") &&
			          (strFuelType.indexOf(strSelectedFuelType) >= 0 || strSelectedFuelType == "") &&
			          (strPosition.indexOf(strSelectedPosition) >= 0 || strSelectedPosition == ""))
	            {
		            if (objDiv.getAttribute("stockHidden") != "true")
		            {
		              bOk = true;
		              break;
		            }
		          }
			      }
	        }
	        
	          if (bOk)
            {
              objLink.parentNode.style.display = "list-item";
            }
            else
            {
              objLink.parentNode.style.display = "none";
            }
	      }
	      
	     
	  }
	}
}


function hideDiv(strDivId)
{
	var objDiv = document.getElementById(strDivId);
	
	objDiv.style.display = "none";
}

function showDiv(strDivId)
{
	var objDiv = document.getElementById(strDivId);
	objDiv.style.display = "block";
}

function validateFormElement(strElement)
{
	var bOk = true;
	var objInput = document.getElementById(strElement);
	var objDiv = document.getElementById("d_" + strElement);
	
	if (trim(objInput.value) == "")
	{
		objDiv.className = "error";
		bOk = false;
	}
	else
	{
		objDiv.className = "field";
	}
	
	return bOk;
	
}
function validateFormContactUs(objForm, strFormAnchor)
{
	var objElements, bComplete, bEmailOk, objParent, strName;
	
	bComplete = true;
	
	if(document.layers)
	{  
		objElements = objForm.all;
	}
	else if(document.all)
	{
		objElements = objForm.all;
	}
	else
	{
		objElements = objForm.getElementsByTagName("*");
	}

	for (var i=0; i < objElements.length;i++)
	{
		var strType = objElements[i].getAttribute("type");
		
		bEmailOk = true;
		
		if (objElements[i].getAttribute("email") == "true")
		{
			bEmailOk = checkEmail(objElements[i].value);
		}
		
		if (objElements[i].getAttribute("required") == "true")
		{
			if (objElements[i].value.length <= 0 || !bEmailOk)
			{
				strName = objElements[i].getAttribute("holder");
				
				if (strName == null)
				{
					strName = "d_" + objElements[i].id;
				}

				objParent = document.getElementById(strName);
				
				if (objParent)
				{
					objParent.className = "error";
				}
				
				bComplete = false;
			}
			else
			{
			
				objParent = document.getElementById("d_" + objElements[i].id);
				
				if (objParent)
				{
					objParent.className = "field";
				}
			}
		}
	}
	
	if (!bComplete)
	{
		objAnchor = document.getElementById(strFormAnchor);
		
		if (!objAnchor)
		{
			alert("Please complete the required fields");
		}
		else
		{
			return true;
		}
	}
	
	return bComplete;
}


function validateForm(objForm, strFormAnchor)
{
	var objElements, bComplete, bEmailOk, objParent, strName;
	
	bComplete = true;
	
	if(document.layers)
	{  
		objElements = objForm.all;
	}
	else if(document.all)
	{
		objElements = objForm.all;
	}
	else
	{
		objElements = objForm.getElementsByTagName("*");
	}
	
	for (var i=0; i < objElements.length;i++)
	{
		var strType = objElements[i].getAttribute("type");
		var bEmailOk = true;

		/* ****** condition will check all text type input fields for mysql reserved keywords entry  */
		if(strType=="text"){
			var bReservedkeywords = true;
			bReservedkeywords = checkReservedWords(objElements[i]);		
			if(!bReservedkeywords){
				return false;
				break;
			}
		}
		/* ****** */

		if (objElements[i].getAttribute("email") == "true")
		{
			bEmailOk = checkEmail(objElements[i].value);
		}
		
		if (objElements[i].getAttribute("required") == "true")
		{
			if (objElements[i].value.length <= 0 || !bEmailOk)
			{
				strName = objElements[i].getAttribute("holder");
				
				if (strName == null)
				{
					strName = "d_" + objElements[i].id;
				}

				objParent = document.getElementById(strName);
				
				if (objParent)
				{
					objParent.className = "error";
				}
				
				bComplete = false;
			}
			else
			{
			
				objParent = document.getElementById("d_" + objElements[i].id);
				
				if (objParent)
				{
					objParent.className = "field";
				}
			}
		}
	}

	if (!bComplete)
	{
		objAnchor = document.getElementById(strFormAnchor);
		
		if (!objAnchor)
		{
			alert("Please complete the required fields");
		}
		else
		{
			smoothScroll(strFormAnchor);
		}
	}	
	return bComplete; 
}


/* Function will check all text type input fields for mysql reserved keywords entry  */
/* arrReservedKeywords = array of some mysql keywords */

function checkReservedWords(objElement){	
	objElementName = objElement.value;
	var arrInput = objElementName.split(" ");
	var bBad = false;
	
	if(objElement.className.match(/RKws/)){
		if(objElementName == 'YOUR REG'){
			bBad = true;
		}
	}
	for (var i = 0; i < arrInput.length; i++)
	{
		if (/MSIE (\d+\.\d+);/.test(navigator.userAgent)){ //  IE does not support indexOf function of js
			for(var k=0;k<arrReservedKeywords.length;k++){
				if (arrInput[i].toLowerCase() == arrReservedKeywords[k]) {
					bBad = true;
					break;
				}
			}
		}else{
			if (arrReservedKeywords.indexOf(arrInput[i].toLowerCase()) >= 0)
			{
				bBad = true;
				break;
			}
		}
	}
   
	if (bBad)
	{
		alert("Please enter valid value");
		objElement.focus();
		return false;
	}else{
	   return true;
	}
}


function selectToolTier(objSelect, iId) 
{
    var objDiv = document.getElementById("d_toolTier" + iId);
    var objAjax = new CAjax();

    if (objAjax.open("/dynamic/toolTier.php?level=" + iId + "&catCode=" + getToolCode("toolTier" + (iId - 1)), true)) {
       
        objDiv.innerHTML = objAjax.getResponse();
    }
}

function getFriendlyTool(strId) {

    var strValue = getFormValue(strId);

    var objOption = document.getElementById(strValue);

    return objOption.getAttribute("friendly");
}

function getToolCode(strId) {

    var strValue = getFormValue(strId);
  
    var objOption = document.getElementById(strValue);

    return objOption.getAttribute("catCode");
}

function gotoTools() 
{
  var objForm = document.getElementById("toolForm");
  var strCarLink, strTier2, strTier3, strTier4;

  if (validateForm(objForm)) {
      strCarLink = getFormValue("carLink");
      strTier2 = getFriendlyTool("toolTier2");
      strTier3 = getFriendlyTool("toolTier3");
      strTier4 = getFriendlyTool("toolTier4");

      var strLink = "/ecp/" + strCarLink + "p/Tools/" + strTier2 + "/" + strTier4;

      document.location.href = strLink;
  }
}

function getElementsByClassName(oElm, strTagName, strClassName)
{
	var arrElements = (strTagName == "*" && oElm.all)? oElm.all : oElm.getElementsByTagName(strTagName);
	var arrReturnElements = new Array();
	strClassName = strClassName.replace(/\-/g, "\\-");
	var oRegExp = new RegExp("(^|\\s)" + strClassName + "(\\s|$)");
	var oElement;
	for(var i=0; i<arrElements.length; i++){
		oElement = arrElements[i];
		if(oRegExp.test(oElement.className)){
			arrReturnElements.push(oElement);
		}
	}
	return (arrReturnElements);
}

function sortNonCarParts(objSelect)
{
	var objLoading = document.getElementById("resultsLoadingProductsListing");
	var objResults = document.getElementById("results");
	var objDisplayPageLabel = document.getElementById("DisplayPageLabel");
	var objNoProducts = document.getElementById("noProducts");
	if(objLoading) objLoading.style.display = "block";
	if(objResults) objResults.style.display = "none";
	if(objDisplayPageLabel) objDisplayPageLabel.style.display = "block";
	if(objNoProducts) objNoProducts.style.display = "none";
	
	var sortVal = objSelect.value;
	if(document.getElementById("sortBy")) document.getElementById("sortBy").value = sortVal;
	if(document.getElementById("sortBy2")) document.getElementById("sortBy2").value = sortVal;
	
	setTimeout("_sortNonCarParts('" + objSelect.id + "')", 200);
}

function refineResult(strBrand, strPosition, strPrice)
{
	var chosenFilters = "", chosenBrands = "", showIt = 0;
	
	$('#positionListFilter :checkbox:checked').each(function() {
		chosenFilters += $(this).val() + ",";
	});
	$('#brandListFilter :checkbox:checked').each(function() {
		chosenBrands += $(this).val() + ",";
	});

	if($('#priceListFilter :checkbox:checked').length == 0) showIt = 1;
	else
	{
		$('#priceListFilter :checkbox:checked').each(function() {
			priceValues = $(this).val().split("-");
			if((parseFloat(strPrice) >= parseFloat(priceValues[0]) && parseFloat(strPrice) <= parseFloat(priceValues[1])))
			{ showIt = 1; }
		});
	}

	if (((chosenBrands.indexOf(strBrand + ",") >= 0 && strBrand.replace(" ", "") != "") || chosenBrands == "") &&
		(showIt == 1) &&
		((chosenFilters.indexOf(strPosition + ",") >= 0) || chosenFilters == ""))
	{ return true; }
	else return false;
}

function _sortNonCarParts(strId)
{
	var objLoading = document.getElementById("resultsLoadingProductsListing");
	var objResults = document.getElementById("results");
	var objSelect = document.getElementById(strId);
	var objResults = document.getElementById("results");
	//var objHolders = objResults.getElementsByTagName("div");
	var objHolders = getElementsByClassName(objResults, 'div', 'ProdListInnerBoxDiv');
	var objOption = document.getElementById(objSelect.value);
	var strSort = objOption.getAttribute("sort");
	var strAsc = objOption.getAttribute("asc");
	var strNumeric = objOption.getAttribute("numeric");
	var iResults = $('div.ProdListInnerBoxDiv').length;
	var refine = 0, allowed = 1, allowed2 = 1;

	if($('#positionListFilter :checkbox:checked').length > 0 || $('#brandListFilter :checkbox:checked').length > 0 || $('#priceListFilter :checkbox:checked').length > 0)
	{
		refine = 1;
	}
	
	for (var i=0; i<(objHolders.length-1); i++)
	{
		strId = objHolders[i].getAttribute("id");
		if(allowed == 0){
			hideDiv(strId);
		}
		else{
			showDiv(strId);
			var strI = objHolders[i].getAttribute(strSort);
			for (var j=(i+1); j<objHolders.length; j++)
			{
				var strJ = objHolders[j].getAttribute(strSort);
				if(allowed2 == 1){
					if (strNumeric == "true" && strSort != "stock"){
						strJ = parseFloat(strJ);
						strI = parseFloat(strI);
					}
					if(typeof strJ === "string" && (strSort != "atoz" || strSort != "ztoa")){
						strJ = strJ.substring(0, 1);
						strI = strI.substring(0, 1);
					}
					if (strAsc == "true"){
						if (strJ < strI){
							swapRows(objHolders[i], objHolders[j]);
						}
					}
					else{
						if (strJ > strI){
							swapRows(objHolders[i], objHolders[j]);
						}
					}
				}
			}
		}
	}
	if(refine > 0){
		_filterProductResults();
	}
	else{
		paginateRecords(iResults);
	}
	//createPagination();
	objLoading.style.display = "none";
	objResults.style.display = "block";
}

function swapRows(objA, objB)
{
	if(objA.nextSibling != null){
		objA.parentNode.insertBefore(objA, objB.nextSibling);
	}
	
	/*
	var objBParent = objB.parentNode;
	var objBSibling = objB.nextSibling;
	if(objBParent != null && objBSibling != null)
	{
		if(objA.nextSibling != null){
			objA.parentNode.insertBefore(objB, objA.nextSibling);
		}
		objBParent.insertBefore(objA, objBSibling);
	}
	*/
}

function inStockOnly(objCheck)
{
	var objLoading = document.getElementById("resultsLoading");
	var objResults = document.getElementById("results");
	var objNoResults = document.getElementById("noResults");
	
	//objLoading.style.display = "block";
	objResults.style.display = "none";
	objNoResults.style.display = "none";
	
	setTimeout("_inStockOnly(" + objCheck.checked + ")", 200);
}

function _inStockOnly(bChecked)
{
	var objResults = document.getElementById("results");
	var objLoading = document.getElementById("resultsLoading");
	var objHolders = objResults.getElementsByTagName("div");
	var bHide = false;
	var objNoResults = document.getElementById("noResults");
	var bResults = false;
	var objSortBy = document.getElementById("sortBy");
	var objFilteredNumber = document.getElementById("filteredNumber");
	var iResults = 0;
	var arrPages = new Array();
	
	for (var i = 0; i < objHolders.length; i++)
	{
		bHide = false;
		
		if (objHolders[i].getAttribute("type") == "productResult")
		{
				if (bChecked)
				{
					if (parseInt(objHolders[i].getAttribute("stock")) <= 0)
					{
						bHide = true;
					}
				}
		
				if (bHide)
				{
					objHolders[i].style.display = "none";
					objHolders[i].setAttribute("stockHidden", "true");
				}
				else
				{
					if (objHolders[i].getAttribute("filterHidden") != "true")
					{
						bResults = true;
						iResults ++;
						objHolders[i].style.display = "block";
						
						arrPages[arrPages.length] = escape(objHolders[i].getAttribute("productCode")) + "&1&" + objHolders[i].getAttribute("hash");
	
					}
					
					objHolders[i].setAttribute("stockHidden", "false");
				}
		}
	}

	objFilteredNumber.innerHTML = iResults;
	
	if (bResults)
	{
		objNoResults.style.display = "none";
		
		if (objSortBy.getAttribute("allow") == "true")
		{
			objSortBy.disabled = "";
		}
		
		ExpandDiv("filteredNotice");
	}
	else
	{
		objNoResults.style.display = "block";
		objSortBy.disabled = "true";
		CollapseDiv("filteredNotice");
	}
	
	//objLoading.style.display = "none";
	objResults.style.display = "block";
	
	sendNewPageOrder(arrPages);
}

function changeCurrentJump(objA, strCatCode)
{
	var objATemp, arrAs, objDiv;
	
	objA.className = "current";
	objDiv = document.getElementById("tier3_" + strCatCode);
	objDiv.style.display = "block";
			
	objDiv = document.getElementById("toggleLevel");
	arrAs = objDiv.getElementsByTagName("a");
	
	for (var i = 0; i < arrAs.length; i++)
	{
		objATemp = arrAs[i];
		
		if (objATemp.id.substr(0,7) == "jumper_")
		{
			strCurrentCatCode = objATemp.getAttribute("catCode");
		
			if (strCurrentCatCode != strCatCode)
			{
				objATemp.className = "";
				
				objDiv = document.getElementById("tier3_" + strCurrentCatCode);
				objDiv.style.display = "none";
			}
		}
	}
}

function toggleJumpMenu(e)
{
	e = e || null;
	var objDiv = document.getElementById("catMenu");
	objDiv.setAttribute("class", "dropbox");
	
	if (objDiv.getAttribute("shown") != "true")
	{
		if(e != null){
			e.className = "active";
		}
		objDiv.style.display = "block";
		objDiv.setAttribute("shown", "true");
	}
	else
	{
		if(e != null){
			e.className = "";
		}
		objDiv.style.display = "none";
		objDiv.setAttribute("shown", "false");
	}
}

function searchPartNo()
{
  var objForm = document.getElementById("partSearchForm");
  var objDiv = document.getElementById("productNotFound");

  objDiv.style.display = "none";
  
	if (validateForm(objForm))
	{
	  if (isValidProduct(escape(getFormValue("partNoSearch"))))
	  {
	    document.location.href = "/ecp/n/" + encodeURIComponent(getFormValue("partNoSearch")) + "/p/" + getFormValue("friendly1") + ".html";
	  }
	  else
	  {
	    objDiv.style.display = "block";
	  }
	}	
	return false;
}

function quickSearch(bCar)
{
	var bSearch = bCar;
	var objForm = document.getElementById("quickSearchForm");
	if (validateForm(objForm))
	{
		if (!bCar)
		{
			bSearch = ajaxSelectCar(getFormValue("quickVrm"));
		}

		if (bSearch)
		{
			searchForKeyword("quickSearchForm", "quickKeyword", "quickFriendly1");
		}
	}
	return false;
}
function IsNumeric(sText)
{
	var ValidChars = "0123456789";
	var IsNumber=true;
	var Char = 0;
	var cntInvalidChars = 0;

	for (i = 0; i < sText.length && IsNumber == true; i++) 
	{ 
		Char = sText.charAt(i);
		if (ValidChars.indexOf(Char) == -1) 
		{
			cntInvalidChars = 1;
			break;
		}
	}
	if(parseInt(cntInvalidChars) == 0)
	{ 
		return true;
	}
    else
	{
		return false;
	}
}

function ajaxSelectCar(strVrm)
{
	var objAjax = new CAjax();
	var bOk = false;
	
	if (objAjax.open("/dynamic/selectCar.php?vrm=" + strVrm, true))
    {
		var strResponse = trim(objAjax.getResponse());
		
		if (strResponse != "")
		{
			alert(strResponse);
			bOk = false;
		}
		else
		{
			bOk = true;
		}
    }
	return bOk;
}

Array.prototype.has = function(v){
	for (i=0; i<this.length; i++){
		if (this[i] == v){
			return i;
		}
	}
	return -1;
};

function searchForKeyword(strForm, strInput, strFriendly)
{
    var objForm = document.getElementById(strForm);
    var objInput = document.getElementById(strInput);
    var arrInput = objInput.value.split(" ");
	
	if(objInput.value.replace(" ", "") != '"' && objInput.value.replace(" ", "") != "/" && objInput.value.replace(" ", "") != "\\" && objInput.value.replace(" ", "") != "'" && objInput.value.replace(" ", "") != "" && objInput.value != "关键词，配件编号等")
	{
		var bBad = false;

		for (var i = 0; i < arrInput.length; i++)
		{
			if (arrWords.has(xorString(arrInput[i])) >= 0)
			{
				bBad = true;
				break;
			}
		}
	   //if(strFriendly.value == "") strFriendly.value = carParts;
	   if (bBad)
	   {
			return false;
	   }

		if (validateForm(objForm))
		{
			objCarDiv = document.getElementById("carDetails");
			
			if (objCarDiv)
			{
				objLoadingDiv = document.getElementById("resultsLoadingKeyword");
			}
			
			setTimeout("_searchForKeyword('" + strInput + "', '" + strFriendly + "')", 100);
		}
		
		return false;
	}
	else
	{
		alert("请输入一个有效的关键词.");
	}
}

function _searchForKeyword(strInput, strFriendly)
{
	if(getFormValue(strFriendly) == "")
	{
		//document.location.href = qSearchKey + encodeURIComponent(getFormValue(strInput)) + "/p/"+carParts;
		document.location.href = qSearchKey + encodeURIComponent(getFormValue(strInput)) + "/p/home" + ".html";
	}
	else
	{
		document.location.href = qSearchKey + encodeURIComponent(getFormValue(strInput)) + "/p/" + escape(getFormValue(strFriendly)) + ".html";
	}	
}

function searchForTools()
{
	var objForm = document.getElementById("toolForm");

	if (validateForm(objForm))
	{
	  document.location.href = "/ecp/f/" + encodeURIComponent(escape(getFormValue("toolsSearch"))) + "/p/" + getFormValue("friendly1") + ".html";
	}
	
	return false;
}

function searchForToolsQuick()
{
	var objForm = document.getElementById("quickSearchForm");
	if(document.getElementById("quickKeyword").value.replace(" ", "") != "'" && document.getElementById("quickKeyword").value.replace(" ", "") != "/" && document.getElementById("quickKeyword").value.replace(" ", "") != "\\" && document.getElementById("quickKeyword").value.replace(" ", "") != '"' && document.getElementById("quickKeyword").value.replace(" ", "") != "" && document.getElementById("quickKeyword").value != "关键词、分类、品牌、配件号等")
	{
		var sectionN = getFormValue("quickFriendly1");
		//var sectionN = getFormValue("quickSearchSelect");
		if(sectionN == "") sectionN = "home";

		if (validateForm(objForm))
		{
			//document.location.href = "/ecp/f/" + encodeURIComponent(getFormValue("quickKeyword")) + "/p/" + sectionN;
			document.location.href = qSearchKey + encodeURIComponent(getFormValue("quickKeyword")) + "/p/" + sectionN + ".html";
		}
	}
	else
	{
		alert("请输入一个有效的关键词、分类、品牌或者配件号进行查询.");
	}
	return false;
}

function searchForToolsLeftBox()
{
    var objForm = document.getElementById("quickSearchFormLeftBox");
	if(document.getElementById("txtLeftBox").value.replace(" ", "") != "" && document.getElementById("txtLeftBox").value.replace(" ", "") != "/" && document.getElementById("txtLeftBox").value.replace(" ", "") != "\\" && document.getElementById("txtLeftBox").value.replace(" ", "") != "'")
	{
		var sectionN = getFormValue("quickFriendly1LeftBox");
		if(sectionN == "") sectionN = carParts;

		if (validateForm(objForm))
		{
			//document.location.href = "/ecp/f/" + encodeURIComponent(getFormValue("txtLeftBox")) + "/p/" + sectionN;
			document.location.href = qSearchKey + encodeURIComponent(getFormValue("txtLeftBox").replace("'", "").replace('"', '')) + "/p/" + sectionN + ".html";
		}
	}
	else
	{
		alert("请输入一个有效的关键词进行查询.");
	}
  return false;
}

function postcodeLookup(objForm)
{
	//var objForm = document.getElementById("postcodeForm");
	if(objForm.postcode.value=="Enter UK Postal Code"){
		objForm.postcode.value = "";
	}
	if(objForm.postcodeagain){
		 if(objForm.postcodeagain.value == "Search again, with a different postcode?" || objForm.postcodeagain.value == ""){
			objForm.postcodeagain.value = "Search again, with a different postcode?";
			alert("Please complete the required fields.");
			return false;
		 }
	}
	if (validateForm(objForm)){
	  var strPostCode = objForm.postcode.value;
	  strPostCode = strPostCode.replace(/\s+/g,'');
	  //document.location.href = "/ecp/store-locator/f/" + encodeURI(strPostCode);
	  document.location.href = "/store-locator/f/" + encodeURI(strPostCode);
	}
	else{
		objForm.postcode.value = "Enter UK Postal Code";
	}
	return false;
}

function initializeGMap(iLat, iLong) 
{ 
	if (GBrowserIsCompatible()) 
	{ 
		var map = new GMap2(document.getElementById("map")); 
	
		map.setCenter(new GLatLng(iLat, iLong), 13); 
		map.addOverlay(new GMarker(new GLatLng(iLat, iLong)));
		
		map.addControl(new GSmallMapControl());
		map.addControl(new GMapTypeControl());
		    
	} 
		
		
} 

/*function changeImage(objImg)
{
	var strImage = objImg.getAttribute("ref");
	var objMainImage = document.getElementById("mainImage");

	objMainImage.style.backgroundImage = "url(" + strImage + ")";
}*/

function changeImage(objImg , ImgId)
{
	var imgIdd = ImgId;
	var strImage = objImg.getAttribute("ref");
	var objMainImage = document.getElementById("mainImage");
	objMainImage.style.backgroundImage = "url(" + strImage + ")";
		
	for(var i=1; i<=3; i++){
		if(document.getElementById("image"+i)){
			document.getElementById("image"+i).style.display = "none";
		}
	}
	document.getElementById("image"+ImgId).style.display = "block";
}

function promptForCar()
{
		var noPopupObjDiv = document.getElementById("NoPromptPopup");
		if (noPopupObjDiv){
			alert('Oops! No vehicle selected. We need you to select your vehicle before continuing');
		}else{	
			var objDiv = document.getElementById("promptForCar");
			var objLocator = document.getElementById("carPromptLocator");
			
			hideMenu();
			if (!objDiv)
			{
				objDiv = document.createElement("div");
				objDiv.id = "promptForCar";
				document.body.appendChild(objDiv);
			}
			
			setOpacity("promptForCar", 100);
			objDiv.style.display = "block";
			
			iDivWidth = findRight(objDiv) - findLeft(objDiv);
			iDivHeight = findBottom(objDiv) - findTop(objDiv);
			
			objDiv.style.top = findTop(objLocator) - iDivHeight/2;
			objDiv.style.left = findRight(objLocator);
			
			objDiv.setAttribute("opacity", 300);
			setTimeout("fadeFrom('promptForCar')", 4000);
			
			changeVehicle();
			smoothScroll();			
		}
}

function smoothScroll(strId)
{
	var iScroll = 0, iOffsetScroll = 0;
	iScroll = document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop;
	
	if (strId != "undefined" && strId != undefined)
	{
		var objDiv = document.getElementById(strId);
		iOffsetScroll = findTop(objDiv);
	}

	if (iScroll >= 0)
	{
		setTimeout("_smoothScroll(" + iScroll + ", " + iOffsetScroll + ")", 10);
	}
}

function _smoothScroll(iScrollLeft, iOffsetScroll)
{
	iScrollLeft -= 30;
	
	if (iScrollLeft < 0)
	{
		iScrollLeft = 0;
	}
	
	scrollTo(0, iScrollLeft);
	
	if (iScrollLeft != 0 && iScrollLeft >= iOffsetScroll && iScrollLeft - iOffsetScroll != 0)
	{
		setTimeout("_smoothScroll(" + iScrollLeft + ", " + iOffsetScroll + ")", 10);
	}
	else
	{
		scrollTo(0, iOffsetScroll);
	}
}
function checkEmailAddressFormat(objInput, bIgnoreCurrent)
{
	var strResponse, objDiv, objPs;
	objDiv = objInput.parentNode;
	objPs = document.getElementById("pEmail");
	//alert(objPs[0].innerHTML);
	//alert(objDiv);
	var strEmail = objInput.value;
	//alert(strEmail);
	if(checkEmail(strEmail) == false) 
	{
		objDiv.className = "error";
		//objPs[0].innerHTML = "Please enter a valid E-Mail.";
		objInput.setAttribute("valid", "false");
	}
	else
	{
		objDiv.className = "field";
		//objPs[0].innerHTML = "";
		objInput.setAttribute("valid", "true");
	}
}

function checkEmailAddress(objInput, bIgnoreCurrent)
{
	var strResponse, objDiv, objPs;
	var strEmail = objInput.value;
	var objAjax = new CAjax();
	var strIgnoreCurrent = "false";
	
	if (bIgnoreCurrent)
	{
		strIgnoreCurrent = "true";
	}
	
    if (objAjax.open("/dynamic/checkUserEmail.php?ignoreCurrent=" + strIgnoreCurrent + "&email=" + strEmail, true))
    {
        strResponse = objAjax.getResponse();
        objDiv = objInput.parentNode;
        objPs = objDiv.getElementsByTagName("strong");
    		
        if (strResponse.length >1)
        {
			objDiv.className = "error";
			objPs[0].innerHTML = strResponse;
			objInput.setAttribute("valid", "false");
        }
        else
        {
			objDiv.className = "field";
			objPs[0].innerHTML = "";
			objInput.setAttribute("valid", "true");
        }
  }
	
}

function loginCheck(objEvent) 
{ 
  var objEvent = (objEvent) ? objEvent : event;
  
  var iCharCode = (objEvent.which) ? objEvent.which : objEvent.keyCode;
  
  if (iCharCode == 13) 
  { 
    loginDynamic();
  }

} 

function loginDynamic()
{
	var objButton = document.getElementById("login");
	var objPleaseWait = document.getElementById("pleaseWaitLogin");

	if (objButton)
	{
		objButton.style.display = "none";
  }
  
  if (objPleaseWait)
  {
		objPleaseWait.style.display = "block";	
	}
	
	setTimeout("_loginDynamic()", 100);
}

function _loginDynamic()
{
	var strResponse, objAjax;
	var objForm = document.getElementById("loginForm");
	var objButton = document.getElementById("login");
	var objPleaseWait = document.getElementById("pleaseWaitLogin");
	var bOk = false;
	
	if (validateForm(objForm, "loginPanel"))
	{
		var objAjax = new CAjax();

		if (objAjax.open("/dynamic/login.php?email=" + getFormValue("loginEmail") + "&password=" + getFormValue("loginPassword"), true))
		{
			strResponse = trim(objAjax.getResponse());
			
			objPs = document.getElementById("d_loginEmail").getElementsByTagName("strong");
			if(strResponse!='')
				document.getElementById("d_loginEmail").className = 'error';
			objPs[0].innerHTML = strResponse;
			
			if (strResponse == "") 
			{	
				bOk = true;
				objForm.submit();
			}
		}
	}
	
	if (!bOk)
	{
		if (objButton)
		{
			objButton.style.display = "block";
		}
	  
		if (objPleaseWait)
		{
			objPleaseWait.style.display = "none";	
		}
	}
	
	return false;
}

function loginDynamic1()
{
	var objButton = document.getElementById("loginHeader");
	var objPleaseWait = document.getElementById("pleaseWaitLoginHeader");

	if (objButton)
	{
		//objButton.style.display = "none";
    }
	if (objPleaseWait)
	{
		//objPleaseWait.style.display = "block";	
	}

	setTimeout("_loginDynamic1()", 100);
 	
}

function _loginDynamic1()
{
	var strResponse, objAjax;
	var objForm = document.getElementById("loginFormHeader");
	var objButton = document.getElementById("loginHeader");
	var objError = document.getElementById("SignInErrorMessage");
	var objPleaseWait = document.getElementById("pleaseWaitLoginHeader");

	var bOk = false;
	
	if (validateForm(objForm, "loginPanel"))
	{
		var objAjax = new CAjax();

		if (objAjax.open("/dynamic/login.php?email=" + getFormValue("loginEmailHeader") + "&password=" + getFormValue("loginPasswordHeader"), true))
		{
			strResponse = trim(objAjax.getResponse());

			if (strResponse == "") 
			{	
				bOk = true;
				objForm.submit();
			}
		}
	}
	
	if (!bOk)
	{
		if (objButton)
		{
			//objButton.style.display = "block";
			objError.style.display = "block";
			objError.innerHTML = strResponse;
		}
		if (objPleaseWait)
		{
			//objPleaseWait.style.display = "none";	
		}
	}
	
	return false;
}

function deleteMyBillingAddress(strPrefix, bIncDefault)
{
	var objDiv;
	var iInternalId = getFormValue(strPrefix + "internalId");
	var strIncDefault = "true";
	var objAjax = new CAjax();
	var objButton = document.getElementById("updateButton");
	var objDeleteButton = document.getElementById("deleteButton");
	
	if (!bIncDefault)
	{
		strIncDefault = "false";
	}
	
	if (iInternalId != "0")
	{
		if (objAjax.open("/dynamic/deleteBillingAddress.php?prefix=" + strPrefix + "&incDefault=" + strIncDefault + "&id=" + iInternalId, true)) {
			objDiv = document.getElementById("addressResponse");
			objDiv.innerHTML = "Updated";
	    
			objDiv = document.getElementById("billingSelect");
			objDiv.innerHTML = objAjax.getResponse();
			
			document.getElementById(strPrefix + "address1").value = "";
			document.getElementById(strPrefix + "address2").value = "";
			document.getElementById(strPrefix + "town").value = "";
			document.getElementById(strPrefix + "county").value = "";
			document.getElementById(strPrefix + "postcode").value = "";
			document.getElementById(strPrefix + "contactName").value = "";
			
			document.getElementById(strPrefix + "internalId").value = "0";
		
			objButton.style.display = "none";
			objDeleteButton.style.display = "none";
	
		}
  }
}

function deleteMyDeliveryAddress(strPrefix, bIncDefault)
{
	var objDiv;
	var iInternalId = getFormValue(strPrefix + "internalId");
	var strIncDefault = "true";
	var objAjax = new CAjax();
	var objButton = document.getElementById("updateButton");
	var objDeleteButton = document.getElementById("deleteButton");
	
	if (!bIncDefault)
	{
		strIncDefault = "false";
	}
	
	if (iInternalId != "0")
	{
		if (objAjax.open("/dynamic/deleteDeliveryAddress.php?prefix=" + strPrefix + "&incDefault=" + strIncDefault + "&id=" + iInternalId, true)) {
			objDiv = document.getElementById("addressResponse");
			objDiv.innerHTML = "Updated";
	    
			objDiv = document.getElementById("deliverySelect");
			objDiv.innerHTML = objAjax.getResponse();
			
			document.getElementById(strPrefix + "address1").value = "";
			document.getElementById(strPrefix + "address2").value = "";
			document.getElementById(strPrefix + "town").value = "";
			document.getElementById(strPrefix + "county").value = "";
			document.getElementById(strPrefix + "postcode").value = "";
			document.getElementById(strPrefix + "contactName").value = "";
			
			document.getElementById(strPrefix + "internalId").value = "0";
			
			objButton.style.display = "none";
			objDeleteButton.style.display = "none";
		
		}
  }
}

function updateMyDeliveryAddress(strPrefix, bCreate, bIncDefault) 
{
  var objForm = document.getElementById("deliveryAddress");
	
  var iInternalId = getFormValue(strPrefix + "internalId");
  var strAddress1 = getFormValue(strPrefix + "address1");
  var strAddress2 = getFormValue(strPrefix + "address2");
  var strTown = getFormValue(strPrefix + "town");
  var strCounty = getFormValue(strPrefix + "county");
  var strPostCode = getFormValue(strPrefix + "postcode");
  var strContactName = getFormValue(strPrefix + "contactName");
  var objAjax = new CAjax();
	var strIncDefault = "true";
	var objButton = document.getElementById("updateButton");
	var objDeleteButton = document.getElementById("deleteButton");
	
	if (!bIncDefault)
	{
		strIncDefault = "false";
	}

  if (bCreate) 
  {
     iInternalId = -1;
  }
  
  if (validateForm(objForm)) 
  {
    if (objAjax.open("/dynamic/updateDeliveryAddress.php?prefix=" + strPrefix + "&incDefault=" + strIncDefault + "&id=" + iInternalId + "&address1=" + strAddress1 + "&address2=" + strAddress2 + "&town=" + strTown + "&county=" + strCounty + "&postcode=" + strPostCode + "&contactName=" + strContactName, true)) {
      objDiv = document.getElementById("addressResponse");
      objDiv.innerHTML = "Updated";
      
      objDiv = document.getElementById("deliverySelect");
      objDiv.innerHTML = objAjax.getResponse();
      
       if (objButton)
			{
				objButton.style.display = "block";
				objDeleteButton.style.display = "block";
			}
    }
  }
   
}


function updateMyBillingAddress(strPrefix, bCreate, bIncDefault) 
{	
  var objForm = document.getElementById(strPrefix + "cardDetails");
  var iInternalId = getFormValue(strPrefix + "internalId");
  var strAddress1 = getFormValue(strPrefix + "address1");
  var strAddress2 = getFormValue(strPrefix + "address2");
  var strTown = getFormValue(strPrefix + "town");
  var strCounty = getFormValue(strPrefix + "county");
  var strPostCode = getFormValue(strPrefix + "postcode");
  var strContactName = getFormValue(strPrefix + "contactName");
  var objAjax = new CAjax();
	var strIncDefault = "true";
	var objButton = document.getElementById("updateButton");
	var objDeleteButton = document.getElementById("deleteButton");
	
	if (!bIncDefault)
	{
		strIncDefault = "false";
	}
	
  if (bCreate) 
  {
     iInternalId = -1;
  }
  if (validateForm(objForm)) 
  {
    if (objAjax.open("/dynamic/updateBillingAddress.php?prefix=" + strPrefix + "&incDefault=" + strIncDefault + "&id=" + iInternalId + "&address1=" + strAddress1 + "&address2=" + strAddress2 + "&town=" + strTown + "&county=" + strCounty + "&postcode=" + strPostCode + "&contactName=" + strContactName, true)) {
        objDiv = document.getElementById("addressResponse");
        objDiv.innerHTML = "Updated";

        objDiv = document.getElementById("billingSelect");
        objDiv.innerHTML = objAjax.getResponse();
        
        if (objButton)
        {
					objButton.style.display = "block";
					objDeleteButton.style.display = "block";
				}
    }
  }
}

function retreivePassword()
{
	var objForm = document.getElementById("forgottenForm");
	var strEmail;

	if (validateForm(objForm))
	{
		strEmail = getFormValue("forgottenEmail");
		objForm.submit();
	}
	
	return false;
}

function trim(str, chars)
{
  return ltrim(rtrim(str, chars), chars);
}

function ltrim(str, chars)
{
  chars = chars || "\\s";
  return str.replace(new RegExp("^[" + chars + "]+", "g"), "");
}

function rtrim(str, chars)
{
  chars = chars || "\\s";
  return str.replace(new RegExp("[" + chars + "]+$", "g"), "");
}
function changePassword()
{
	var objForm = document.getElementById("changePassword");

	strEmail = getFormValue("email");
	strPassword1 = getFormValue("password1");
	strPassword2 = getFormValue("password2");
	
	objPassword1 = document.getElementById("d_password1");
	objPassword2 = document.getElementById("d_password2");

	objPassword1.className = "field";
	objPassword2.className = "field";
	
	bError = false;
	
	if (strPassword1.length < 8)
	{
		objPassword1.className = "error";
		bError = true;
	}
	
	if(strPassword1 != strPassword2)
	{
		objPassword1.className = "error";
		objPassword2.className = "error";
		bError = true;
	}
	
	if (!bError)
	{
		objForm.submit();
	}
	
}


function QL()
{
// Quick Parts lookup
	var objButton = document.getElementById("check");
	var objPleaseWait = document.getElementById("pleaseWait");

	if (objButton)
	{
		objButton.style.display = "none";
  }
  
  if (objPleaseWait)
  {
		objPleaseWait.style.display = "block";	
	}
	
	setTimeout("_QL()", 100);
	return false;
}

function _QL()
{
	var strResponse, objAjax;
	var objForm = document.getElementById("QLForm");
	var objButton = document.getElementById("check");
	var objPleaseWait = document.getElementById("pleaseWait");
	var bOk = false;
	
	var objAjax = new CAjax();

	if (objAjax.open("ql.php?part=" + getFormValue("partNumber"), true))
	{
		strResponse = objAjax.getResponse();
		
		objPs = document.getElementById("d_part").getElementsByTagName("p");
		objPs[0].innerHTML = strResponse;

		if (strResponse == "") 
		{	
			bOk = true;
			objForm.submit();
		}
	}
	
	if (!bOk)
	{
		if (objButton)
		{
			objButton.style.display = "block";
		}
	  
		if (objPleaseWait)
		{
			objPleaseWait.style.display = "none";	
		}
	}
	
	return false;
}

function requestFeedback()
{
	var objForm = document.getElementById("feedbackForm");
	var strContactName, strTelephone, strEmail, strPartRequired, strVehicleReg, strMake, strModel, strSubModel, strEngine, strYear, strNotes;
	var strMethod;
	
	if (validateForm(objForm))
	{
		strContactName = getFormValue("contactName");
		strTelephone = getFormValue("telephone");
		strEmail = getFormValue("email");
		strPartRequired = getFormValue("partRequired");
		strVehicleReg = getFormValue("reg");
		strMake = getFormValue("make");
		strModel = getFormValue("model");
		strSubModel = getFormValue("subModel");
		strEngine = getFormValue("engine");
		strYear = getFormValue("year");
		strNotes = getFormValue("notes");
		
		var objCallBack = document.getElementById("callBack");
		
		strMethod = "E";
		
		if (objCallBack.checked)
		{
			strMethod = "C";
		}
		
		var objAjax = new CAjax();

		if (objAjax.open("/dynamic/sendFeedback.php?contactName=" + escape(strContactName) +
										 "&telephone=" + escape(strTelephone) +
									   "&email=" + escape(strEmail) +
									   "&partRequired=" + escape(strPartRequired) +
									   "&reg=" + escape(strVehicleReg) +
									   "&make=" + escape(strMake) +
									   "&model=" + escape(strModel) +
									   "&subModel=" + escape(strSubModel) +
									   "&engine=" + escape(strEngine) +
									   "&year=" + escape(strYear) +
									   "&notes=" + escape(strNotes) +
									   "&method=" + strMethod, true))
		{
			var strResponse = objAjax.getResponse();
			
			if (trim(strResponse) == "")
			{
				var objThanks = document.getElementById("feedbackThanks");
				
				objThanks.style.display = "block";
				objForm.style.display = "none";
			}
		}
	}
}

function submitCompetition()
{
	var objForm = document.getElementById("competitionForm");
	var strForeName, strNumber, strEmail, strSurname, strTitle, strAdd1, strAdd2, strTown, strCounty, strPostcode, strMOT, strChoice, strMake, strModel;

	if (validateForm(objForm))
	{	

		strTitle = getFormValue("title");
		strForeName = getFormValue("forename");
		strSurname = getFormValue("surname");
		strEmail = getFormValue("email");
		strNumber = getFormValue("number");
		strAdd1 = getFormValue("add1");
		strAdd2 = getFormValue("add2");
		strTown = getFormValue("town");
		strCounty = getFormValue("county");
		strPostcode = getFormValue("pstcode");
		strMOT = getFormValue("mot");
		strChoice= getFormValue("choice");
		strMake = getFormValue("make");
		strModel= getFormValue("model");		
			
		var objAjax = new CAjax();
				
		if (objAjax.open("/dynamic/submitComp.php?forename=" + escape(strForeName) +
										 "&title=" + escape(strTitle) +
									   "&surname=" + escape(strSurname) +
									   "&email=" + escape(strEmail) +
									   "&number=" + escape(strNumber) +
									   "&add1=" + escape(strAdd1) +
									   "&add2=" + escape(strAdd2) +
									   "&town=" + escape(strTown) +
									   "&county=" + escape(strCounty) +
									   "&postcode=" + escape(strPostcode) +
									   "&mot=" + escape(strMOT) +
									   "&make=" + escape(strMake) +
									   "&model=" + escape(strModel) +
									   "&choice=" + escape(strChoice), true))
		{
		
		var strResponse = objAjax.getResponse();
			
		if (trim(strResponse) == "")
			{
				var objThanks = document.getElementById("feedbackThanks");				
				objThanks.style.display = "block";
				objForm.style.display = "none";
			}
		}
	}
}

/* PITLANE JS FUNCTION */

function toggle_bullet_options(varientCount){
	var val1 = jQuery('#toggle_'+varientCount).html();
	if(val1=='More Info'){
		jQuery('#toggle_'+varientCount).html('Less Info');
		jQuery('#toggle_'+varientCount).removeClass('moreInfo').addClass('lessInfo');
		jQuery('#div_'+varientCount).slideDown();
	}else{
		jQuery('#toggle_'+varientCount).html('More Info');
		jQuery('#toggle_'+varientCount).removeClass('lessInfo').addClass('moreInfo');
		jQuery('#div_'+varientCount).slideUp();
	}
}


function changePSPrice(optionDetail,varientCount){
	var objVarientHiddenPrice = document.getElementById('varientHiddenPrice_'+varientCount);
	var ecpCurrentPrice = objVarientHiddenPrice.value;

	if(trim(optionDetail.value)=="Select")
	{
		document.getElementById('varientPrice_'+varientCount).innerHTML = "<u>&pound;"+ecpCurrentPrice+"</u><span> (inc VAT)</span>";
	}
	else
	{
		var opDetail	= optionDetail.value.split('::');
		var opName		= opDetail[0];
		var opPrice		= opDetail[1];
		
		var newPrice = parseFloat(ecpCurrentPrice)+parseFloat(opPrice);
		document.getElementById('varientPrice_'+varientCount).innerHTML = "<u> &pound;"+newPrice.toFixed(2)+"</u><span> (inc VAT)</span>";
	}
}

function gotFocus(ctl,val)
{
    if(ctl.value==val)
    {
        ctl.value='';
    }
}
function lostFocus(ctl,val)
{
    if(ctl.value=='')
    {
        ctl.value=val;
    }
}

function showValidProductPopup(prdCode, carPartStatus){
	if(carPartStatus == '0'){
		jQuery('#'+prdCode+'_'+carPartStatus).show('slow');
		setTimeout("hideValidProductPopup(" + prdCode + ',' + carPartStatus +")", 4000);
	}	
}

function hideValidProductPopup(prdCode, carPartStatus){
	if(carPartStatus == '0'){
		jQuery('#'+prdCode+'_'+carPartStatus).hide('slow');
	}
}


/**************    PRODUCTS LISTING FUNCTIONS   *******************/

function refreshProductsList(pg)
{
	var strResponse = "";
	var iCurrentPage = pg;
	if(iCurrentPage == 0) iCurrentPage = document.getElementById("hidCurrentPage").value;
	
	var iRecords = document.getElementById("cboRecords").value;
	var iSortBy = document.getElementById("cboSortBy").value;
	var sKeyword = document.getElementById("hidSearchKey").value;
	var iTotal = document.getElementById("hidTotalRecords").value;
	var sTier1F = document.getElementById("hidTier1F").value;

	var bval = "";
	$('#brandListFilter :checkbox:checked').each(function() {
			if(bval == "") bval = $(this).val();
			else bval += "," + $(this).val();
				});
	var pval = "";
	$('#priceListFilter :checkbox:checked').each(function() {
			if(pval == "") pval = $(this).val();
			else pval += "," + $(this).val();
				});

	var objAjax = new CAjax();
	if (objAjax.open("/dynamic/listing.php?records=" + iRecords + "&cpage=" + iCurrentPage + "&by=" + iSortBy + "&sKeyword=" + sKeyword + "&iTotal=" + iTotal + "&bval=" + bval + "&pval=" + pval + "&sTier1F=" + sTier1F, true))
	{
		strResponse = objAjax.getResponse();
		document.getElementById("productsList").innerHTML = strResponse;
	}
}

function printPopUp(type)
{
	ntype = type || 'pitlane';
	window.open(self.location + "&ptype=print&ntype="+ntype, 'Print','left=100, top=20,width=780, height=500,toolbar=0, resizable=1, scrollbars=1');
}

function hideMenu(){
	jQuery('div.MenuTab').find('div.Tier3CatLiDiv').hide();
	return false;
}

function clearAllFilter2()
{
	$('#brandListFilter input[type=checkbox]').attr('checked', false);
	$('#positionListFilter input[type=checkbox]').attr('checked', false);
	$('#priceListFilter input[type=checkbox]').attr('checked', false);
	filterListPagination(0, 5);
}

function clearAllFilter()
{
	$('#brandListFilter input[type=checkbox]').attr('checked', false);
	$('#positionListFilter input[type=checkbox]').attr('checked', false);
	$('#priceListFilter input[type=checkbox]').attr('checked', false);
	filterListPagination(0, 5);
}

function findAddressByPostCode()
{
	var strPostcode;
	var objResultHolder;
	var objAjax = new CAjax();
	
	strPostcode = getFormValue("findPostcode");
	objResultHolder = document.getElementById("finderResults");
	document.getElementById("PC1").style.display = "none";
	
	if(strPostcode == ""){
		document.getElementById("PC1").style.display = "block";
		document.getElementById("findPostcode").focus();
		return false;
	}
	
	if (objAjax.open("/dynamic/findAddress.php?postcode=" + strPostcode + "&delivery=false", true)){
		objResultHolder.innerHTML = objAjax.getResponse();
		ExpandDiv("finderResults");
	}
}

$(document).ready(function(){

	var isEntered = false;
	var isEntered2 = false;
	
	if($("a[rel^=prettyPhoto]") != null){
		if($("a[rel^=prettyPhoto]").length > 0){ 
			$("a[rel^='prettyPhoto']").prettyPhoto();
		}		
	}
	
	if($('#ProductsOuterIdHome').length > 0){
		iClAuto = (($('ul.jCarouselLiteUl0').find('li').length > 5)?1000:0);
		iCircular = (($('ul.jCarouselLiteUl0').find('li').length > 5)?true:false);
		iVisible = 5 ;
		
		
		/* Recommended products */
		$("div.jCarouselLite0").jCarouselLite({
			btnNext: ".next0",
			btnPrev: ".prev0",
			auto:0,
			speed:2000,
			btnSpeed:500,
			autoSpeed: 2000,
			easing:'easeinout',
			visible:iVisible,
			circular:(($('ul.jCarouselLiteUl0').find('li').length > 5)?true:false),
			scroll:1,
			listCount:$('ul.jCarouselLiteUl0').find('li').length,
			countClass:'.prodCounts'					
		});
		
		/* Deals of the week */
		$("div.jCarouselLite1").jCarouselLite({
			btnNext: ".next1",
			btnPrev: ".prev1",
			btnPause: ".pause",
			btnPlay: ".play",
			auto:(($('ul.jCarouselLiteUl').find('li').length > 5)?1000:0),
			speed:2000,
			btnSpeed:500,
			autoSpeed: 2000,
			easing:'easeinout',
			visible:iVisible,
			circular:(($('ul.jCarouselLiteUl').find('li').length > 5)?true:false),
			scroll:1,
			pauseOnHover:false
		});
		
		var imghost = $('#imghost').val();
		var hideImg = imghost+'imgs/home/expand.gif';
		var showImg = imghost+'imgs/home/collapse_icon.gif';
		var choverImg = imghost+'imgs/home/collapsHover.gif';				
		
		$("a#toggleRemProducts").click(function(event) {
			event.preventDefault();					
			if ( $('div#remProducts').is(':visible')){
				$('div#remProducts').slideUp('slow');
				$("#remProdtsShow").attr("src", hideImg);
				setTimeout(function(){ $('div#remProducts2').show();}, 100);
			}else{
				$('div#remProducts2').hide();
				$('div#remProducts').slideDown('slow');
				$("#remProdtsShow").attr("src", showImg);
			}
		});
				
	}else{
	
		if($('#crosssellhidden').length > 0 && !isEntered){
			iCPCount = parseInt($('#crosssellhidden').val());
			iClAuto = (($('ul.jCarouselLiteUl').find('li').length > 8)?1000:0);
			iCircular = (($('ul.jCarouselLiteUl').find('li').length > 8)?true:false);
			iVisible = 8 ;
			isEntered = true;
		}else{
			iClAuto = (($('ul.jCarouselLiteUl').find('li').length > 4)?1000:0);
			iCircular = (($('ul.jCarouselLiteUl').find('li').length > 4)?true:false);
			iVisible = 4 ;
		}
	
		if($(".jCarouselLite1").length > 0){
			$(".jCarouselLite1").jCarouselLite({
				btnNext: ".next1",
				btnPrev: ".prev1",
				btnPause: ".pause",
				btnPlay: ".play",
				auto:iClAuto,
				speed:2000,
				btnSpeed:500,
				autoSpeed: 2000,
				easing:'easeinout',
				visible:iVisible,
				circular:iCircular,
				scroll:1,
				pauseOnHover:false
			});
		}
	}
	
	if($('.CheckFitmentBut').length > 0){	
		$('.CheckFitmentBut').bind('click', function(){
			if($(this).parents('.ProdLtBottomDiv').find('.CheckFitmentDiv').is(':visible')){
				$(this).parents('.ProdLtBottomDiv').find('.CheckFitmentDiv').slideUp('slow');
				$(this).removeClass('CFButB').addClass('CFButA');
			}
			else{
				$(this).parents('.ProdLtBottomDiv').find('.CheckFitmentDiv').slideDown('slow');
				$(this).removeClass('CFButA').addClass('CFButB');
			}
		});
	}	
});


function showfitmentDetails(objs){
	
	if($('.CheckFitmentBut').length > 0){	
		if($('#CheckFitmentDiv'+objs).is(':visible')){
			
			$('#CheckFitmentDiv'+objs).slideUp('slow');
			$('#CheckFitmentBut'+objs).removeClass('CFButB').addClass('CFButA');
		}
		else{
			
			$('#CheckFitmentDiv'+objs).slideDown('slow');
			$('#CheckFitmentBut'+objs).removeClass('CFButA').addClass('CFButB');
		}
	
	}
}

function globalSearch(){
	var strSearchSection;
	strSearchSection = document.getElementById('quickSearchSelect').value;
	if(strSearchSection == ''){
		allSectionSearch(true);
	}else if(strSearchSection == 'car-parts'){
		quickSearch(true);
	}else{
		searchForToolsQuick(true);
	}	
}

function openLiveChat(){
	//window.open('','wochat','width=440,height=330');
}

function minimizeChat(){
document.getElementById('liveChatLink').style.display='none';
document.getElementById('chatMin').style.display='block';
}

function maxChat(){
document.getElementById('chatMin').style.display='none';
document.getElementById('liveChatLink').style.display='block';
}
