    function twsProductPagePreCallBack(){
		document.getElementById("TWSProductPageLoading").style.display = "block";
		document.getElementById("TechnicalAdviceLinks").style.display = "none";
		var lpsBox = document.getElementById("LoadPressureSpeed");
		if(lpsBox){
			lpsBox.style.display = "none";
		}		
    }
    
    function twsProductPagePostCallBack(){
		alternateRows();
		document.getElementById("TWSProductPageLoading").style.display = "none";
		document.getElementById("TechnicalAdviceLinks").style.display = "block";
		var lpsBox = document.getElementById("LoadPressureSpeed");
		if(lpsBox){
			lpsBox.style.display = "block";
		}
		var convertTo = get_cookie("TWSUnit");
		set_cookie("TWSUnit","Metric");	// db values are saved in metrics
		convertAllUnits(convertTo, "");
    }
    
  
    function selectTire(value){
		Anthem_InvokePageMethod(
			'selectTire', 
			[value]
		);
		tb_init('a.thickbox');
		var obj 
		//obj = thisMovie("twstireselector");
		//obj = window.twstireselector;
		//obj = document.forms[0].twstireselector;
		obj = document.getElementById("twstireselector");
		obj.EndBuffer();
    }
    
    function convertAllUnits(unitsystem,defaultSystem){
		if(get_cookie("TWSUnit") == "undefined" || get_cookie("TWSUnit") == ""){
			set_cookie("TWSUnit",defaultSystem);
		}
		
		var usbutton = document.getElementById("USButton");
		var metricsbutton = document.getElementById("MetricButton");
		
		if(!usbutton ||!metricsbutton){
			return;
		}
		
		if(unitsystem == "US"){
			usbutton.className = "linkArrow bold";
			metricsbutton.className = "linkArrow";
		} else {
			usbutton.className = "linkArrow";
			metricsbutton.className = "linkArrow bold";
		}
    
		var values = document.getElementsByTagName("SPAN");
		for(var i=0;i<values.length;i++){
			if(values[i].className == "size" || values[i].className == "weight" || values[i].className == "liquid"){
				values[i].innerHTML = convertUnit(unitsystem, values[i].className,values[i].innerHTML);
			}
			
			if(values[i].className == "sizeUnit" || values[i].className == "weightUnit" || values[i].className == "liquidUnit" || values[i].className == "speedUnit"){
				values[i].innerHTML = convertUnitText(unitsystem, values[i].className,values[i].innerHTML);
			}
		}
		
		values = document.getElementsByTagName("SELECT");
		for(var i=0;i<values.length;i++){
			if(values[i].className == "size" || values[i].className == "weight" || values[i].className == "liquid" || values[i].className == "speed"){		
				for(var j=0;j<values[i].options.length;j++){
					values[i].options[j].value = convertUnit(unitsystem, values[i].className,values[i].options[j].value);
					values[i].options[j].text = convertUnit(unitsystem, values[i].className,values[i].options[j].text);
				}
			}
		}		
		set_cookie("TWSUnit",unitsystem);
    }
    
    function convertUnitText(unitsystem, unit, text){
		var currentSystem = get_cookie("TWSUnit");
		
		if(unitsystem == currentSystem){
			return text;
		}

		if(unitsystem == "US"){
			if(unit == "sizeUnit" && text.indexOf("(mm)") != -1) // mm => in
			{
				return text.substring(0,text.indexOf("(mm)")) + "(in)";
			} 
			else if(unit == "weightUnit" && text.indexOf("(kg)") != -1) 	// kg => lbs
			{
				return text.substring(0,text.indexOf("(kg)")) + "(lbs)";
			} 
			else if(unit == "liquidUnit" && text.indexOf("(L)") != -1)	// l => gal
			{
				return text.substring(0,text.indexOf("(L)")) + "(gal)";
			}
			else if(unit == "speedUnit" && text.indexOf("(km/h)") != -1)	// km/h => mph
			{
				return text.substring(0,text.indexOf("(km/h)")) + "(mph)";
			}						
		} else if(unitsystem == "Metric") {
			if(unit == "sizeUnit" && text.indexOf("(in)") != -1) // in => mm
			{
				return text.substring(0,text.indexOf("(in)")) + "(mm)";
			} 
			else if(unit == "weightUnit" && text.indexOf("(lbs)") != -1) 	// lbs => kg
			{
				return text.substring(0,text.indexOf("(lbs)")) + "(kg)";
			}		
			else if(unit == "liquidUnit" && text.indexOf("(gal)") != -1)	// l => gal
			{
				return text.substring(0,text.indexOf("(gal)")) + "(L)";
			}
			else if(unit == "speedUnit" && text.indexOf("(mph)") != -1)	// mph => km/h
			{
				return text.substring(0,text.indexOf("(mph)")) + "(km/h)";
			}			
		}
		
		return text;
	}
    
    function convertUnit(unitsystem, unit, amount){
		var currentSystem = get_cookie("TWSUnit");
		
		if(unitsystem == currentSystem){
			return amount;
		}
		
		if(unitsystem == "US"){
			if(unit == "size") // mm => inch
			{
				return round(amount * 0.0393700787,2);
			} 
			else if(unit == "weight") // kg => lbs
			{
				return round(amount * 2.20462262,2);
			} 
			else if(unit == "liquid") // l => gal
			{
				return round(amount * 0.264172051,2);
			}
			else if(unit == "speed") // km/h => mph
			{
				return round(amount * 0.621371192,2);
			}			
		} else if(unitsystem == "Metric") {
			if(unit == "size") // inch => mm
			{
				return round(amount * 25.4,0);
			} 
			else if(unit == "weight") // lbs => kg
			{
				return round(amount * 0.45359237,0);
			}		
			else if(unit == "liquid") // gal => l
			{
				return round(amount * 3.7854118,0);
			}			
			else if(unit == "speed") // mph =>km/h
			{
				return round(amount * 1.609344,0);
			}						
		}
		
		return amount;
    }

	function calculateLB(ddlTireDimensionId){
		var ddlFilling = document.getElementById("ddlFilling");
		var ddlTireDimension = document.getElementById(ddlTireDimensionId);
		var ddlTemperature = document.getElementById("ddlTemperature");
		var ddlAntiFreeze = document.getElementById("ddlAntiFreeze");
		
		var fFilling = parseFloat(ddlFilling.options[ddlFilling.selectedIndex].value);
		var iVolume = parseInt(ddlTireDimension.options[ddlTireDimension.selectedIndex].value);
		var iTemperature = parseInt(ddlTemperature.options[ddlTemperature.selectedIndex].value);
		var iAntiFreeze = parseInt(ddlAntiFreeze.options[ddlAntiFreeze.selectedIndex].value);
		
		var txtAntiFreezeAmount = document.getElementById("txtAntiFreezeAmount");
		var txtWaterAmount = document.getElementById("txtWaterAmount");
		var txtWeight = document.getElementById("txtWeight");
		
		var fAntiFreezeAmount;
		
		var cacl2_glycol_kg;
		var glycol_litre;
		var water_litre;
					
		switch(iAntiFreeze){
			case 0:	// CaCl2
				switch(iTemperature){
					case -10:
						cacl2_glycol_kg = 0.14;
						water_litre = 0.95;
						break;
					case -20:
						cacl2_glycol_kg = 0.24;
						water_litre = 0.90;
						break;
					case -30:
						cacl2_glycol_kg = 0.36;
						water_litre = 0.83;
						break;
					case -40:
						cacl2_glycol_kg = 0.49;
						water_litre = 0.76;
						break;
				}
				
				fAntiFreezeAmount = fFilling * iVolume * cacl2_glycol_kg;
				break;
			case 1:	// ethylene glycol
				switch(iTemperature){
					case -10:
						cacl2_glycol_kg = 0.26;
						glycol_litre = 0.23;
						water_litre = 0.77;
						break;
					case -20:
						cacl2_glycol_kg = 0.37;
						glycol_litre = 0.33;
						water_litre = 0.67;
						break;
					case -30:
						cacl2_glycol_kg = 0.48;
						glycol_litre = 0.43;
						water_litre = 0.57;
						break;
					case -40:
						cacl2_glycol_kg = 0.59;
						glycol_litre = 0.53;
						water_litre = 0.77;
						break;
				}
				
				fAntiFreezeAmount = fFilling * iVolume * glycol_litre;					
				break;
		}

		txtAntiFreezeAmount.innerHTML = parseInt(fAntiFreezeAmount);
		txtWaterAmount.innerHTML = parseInt(fFilling * iVolume * water_litre);
		txtWeight.innerHTML = parseInt(fFilling * iVolume * (cacl2_glycol_kg + water_litre));

		var convertTo = get_cookie("TWSUnit");
		set_cookie("TWSUnit","Metric");	// db values are saved in metrics
		convertAllUnits(convertTo, "");
	}
	
	function setDropdowns(ddl1, ddl2Id){
		var ddl2 = document.getElementById(ddl2Id);
		ddl2.selectedIndex = ddl1.selectedIndex;
	}
	
	function initCodeTable(){
		var convertTo = get_cookie("TWSUnit");
		set_cookie("TWSUnit","Metric");	// db values are saved in metrics
		convertAllUnits(convertTo, "");	
	}
	
	function unitconverter(metricToUs){
		var metricUnits  = Array(	"txtKilograms",
									"txtHectares",
									"txtBar",
									"txtKilometers",
									"txtMillimeters",
									"txtMeters",
									"txtCelsius",
									"txtLitres");

		var convertToUs = Array (	"x*2.20462262",
									"x*2.47105381",
									"x*14.5037738",
									"x*0.621371192",
									"x*0.0393700787",
									"x*1.0936133",
									"(9/5)*x+32",
									"x*0.264172051");
									
		var usUnits = Array(	"txtPounds",
								"txtAcres",
								"txtPsi",
								"txtMiles",
								"txtInches",
								"txtYards",
								"txtFahrenheit",
								"txtUSGallons");
		
		var convertToMetric = Array (	"x*0.45359237",
										"x*0.404685642",
										"x*0.0689475729",
										"x*1.609344",
										"x*25.4",
										"x*0.9144",
										"(5/9)(x-32)",
										"x*3.7854118");
		
		var targetUnit, sourceUnit, formula, value;
		for(var i=0;i<metricUnits.length;i++){
			if(metricToUs){
				targetUnit = document.getElementById(usUnits[i]);
				sourceUnit = document.getElementById(metricUnits[i]);
				formula = convertToUs[i];
			} else {
				sourceUnit = document.getElementById(usUnits[i]);
				targetUnit = document.getElementById(metricUnits[i]);
				formula = convertToMetric[i];
			}
			
			value = sourceUnit.value.replace(',','.');
			
			if(targetUnit != null && sourceUnit != null && value != "" && !isNaN(value)){
				targetUnit.value = round(eval(formula.replace('x',value)),2);
			} else {
				targetUnit.value = "";
			}	
		}		
	}
	
	function clearUnits(id1,id2){
		document.getElementById(id1).value = "";
		document.getElementById(id2).value = "";
	}

	function clearAllUnits(){
		var units  = Array(	"txtKilograms",
							"txtHectares",
							"txtBar",
							"txtKilometers",
							"txtMillimeters",
							"txtMeters",
							"txtCelsius",
							"txtLitres",
							"txtPounds",
							"txtAcres",
							"txtPsi",
							"txtMiles",
							"txtInches",
							"txtYards",
							"txtFahrenheit",
							"txtUSGallons");	
							
		for(var i=0;i<units.length;i++){
			document.getElementById(units[i]).value = "";
		}
	}
