<!--
// JavaScript Document

function flashType(flashinstalled, flashversion)
{
	var a = document.getElementById('image')
	if (flashinstalled != 2)
	{
		a.innerHTML = "<img src='resource/main_text.gif' width='620' height='90' alt='Gaugemaster.com - the online home of The Engine Shed'>"
	}
	else
	{
		if (flashversion < 6)
		{
			a.innerHTML = "<img src='resource/main_text.gif' width='620' height='90' alt='Gaugemaster.com - the online home of The Engine Shed'>"
		}
			
	}
}

function put()
//For transferring the searchstring enterered by the user into the searchtitle field before submitting a search
{
txt=document.forms[0].searchstring.value
document.forms[0].searchtitle.value=txt
}

function put2()
//For transferring the searchstring enterered by the user into the searchtitle field before submitting a search
{
txt=document.forms[1].searchstring.value
document.forms[1].searchtitle.value=txt
}

function put3()

{
id=document.forms[2].searchstring.options[document.forms[2].searchstring.selectedIndex].innerHTML
document.forms[2].searchtitle.value=id
}

function MM_openBrWindow(theURL,winName,features) { //v2.0 Opens a window for display of large product images.
  window.open(theURL,winName,features);
}

function contactValidator()
//Validates the e-mail form
{
var person = document.forms['frm'].name.value
var address = document.forms['frm'].email.value
var mailto = document.forms['frm'].recipient.value

box = document.forms['frm'].recipient
var subject = box.options[box.selectedIndex].index
document.forms['frm'].subject.value = subject

var message = document.forms['frm'].enquiry.value

if (person.length == 0)
	{
	alert("Please enter your name")
	return false;
	}
else if (address.length == 0)
	{
	alert("Please enter your e-mail address")
	return false;
	}
else if (mailto == "*")
	{
	alert("Please choose a subject for your enquiry")
	return false;
	}
else if (message.length == 0)
	{
	alert("Please enter a message")
	return false;
	}
else 
	{
	return true;
	}
}

function disable()
// This function is used for enabling and disabling the carriage service
// drop down box according to the country selected, and also deletes or adds
// the VAT when the country selection is changed and updates the order total
{
var x=document.checkform.carriage
var checkUK = new RegExp("United Kingdom|IOM|Northern Ireland|Scotland|IOW", "i");
var country = document.checkform.p_country.value;
	if (checkUK.test(country))
	{
		x.disabled=false
		a=new RegExp("nTotal", "i");
		b=document.checkform.elements;
		for (i=0;i<b.length;i++){
			if (a.exec(b[i].name)){
				d=Number(b[i].getAttribute('value'))
				w=document.getElementById('foreign')
				y=document.getElementById('text')
				z=document.getElementById('newTotal')
				document.checkform.new_total.value="£"+CurrencyFormatted(d)
				y.innerHTML="Order Total:"
				z.innerHTML="£"+d
				w.innerHTML="&nbsp;"
			}
		}
		updateTotal()
	}
	else
	{
		x.disabled=true
		var checkEU = new RegExp("Austria|Belgium|Cyprus|Czech Republic|Denmark|Estonia|Finland|France|Germany|Greece|Hungary|Ireland|Italy|Latvia|Lithuania|Luxembourg|Malta|Poland|Portugal|Slovakia|Slovenia|Spain|Sweden|Netherlands|blank", "i");
		if (checkEU.test(country) == false)
		{
			document.checkform.new_total.title=Number(CurrencyFormatted(getValue()))
			result=Number(getValue()+handlingCharge());
			w=document.getElementById('foreign')
			y=document.getElementById('text')
			z=document.getElementById('newTotal')
			document.checkform.new_total.value="£"+CurrencyFormatted(result)
			y.innerHTML="Order Total (Tax Free):"
			z.innerHTML="£"+CurrencyFormatted(result)
			if (handlingCharge()==2.00)
			{
				w.innerHTML="(Please note that this total includes a £2.00 small orders handling charge, but does not include the Carriage charge for shipping the order)"
			}
			else
			{
				w.innerHTML="(Please note that this total does not include the Carriage charge for shipping the order)"
			}
		}
		else
		{
			a=new RegExp("nTotal", "i");
			b=document.checkform.elements;
			for (i=0;i<b.length;i++)
			{
				if (a.exec(b[i].name))
				{
					d=Number(b[i].getAttribute('value'));
					w=document.getElementById('foreign')
					y=document.getElementById('text')
					z=document.getElementById('newTotal')
					result=CurrencyFormatted(d+handlingCharge())
					document.checkform.new_total.value="£"+result
					document.checkform.new_total.title=result
					y.innerHTML="Order Total:"
					z.innerHTML="£"+result
					if (handlingCharge()==2.00)
					{
						w.innerHTML="(Please note that this total includes a £2.00 small orders handling charge, but does not include the Carriage charge for shipping the order)"
					}
					else
					{
						w.innerHTML="(Please note that this total does not include the Carriage charge for shipping the order)"
					}
				}
			}
		}
	}
}

function updateTotal()
// Updates the total to include any selected carriage service for UK orders
{
w=document.forms['checkform'].carriage;
x=w.options[w.selectedIndex].value;
y=Number(document.checkform.new_total.title);
if (x=="nextday")
	{
		carrTot=4.95
	}
else if (x=="1st")
	{
		carrTot=1.50
	}
else
	{
		carrTot=0.00
	}
var newTotal=(y+carrTot);
var result=CurrencyFormatted(newTotal)
z=document.getElementById('newTotal')
z.innerHTML="£"+result
w=document.getElementById('foreign')
w.innerHTML="(Please note that this includes a £2.00 Small Orders Handling Charge)"
document.forms['checkform'].new_total.value="£"+result
}

function CurrencyFormatted(amount)
// Formats an amount into two decimal places for use as currency
{
	var i = parseFloat(amount);
	if(isNaN(i)) { i = 0.00; }
	var minus = '';
	if(i < 0) { minus = '-'; }
	i = Math.abs(i);
	i = parseInt((i + .005) * 100);
	i = i / 100;
	s = new String(i);
	if(s.indexOf('.') < 0) { s += '.00'; }
	if(s.indexOf('.') == (s.length - 2)) { s += '0'; }
	s = minus + s;
	return s;
}

function loadCalc()
{
	var a=handlingCharge()
	if (a==2)
	{
		var y=document.getElementById('newTotal')
		var z=Number(document.checkform.new_total.title)
		var result=Number(z+a)
		w=document.getElementById('foreign')
		x=CurrencyFormatted(result)
		y.innerHTML="£"+x
		document.checkform.new_total.title=x
		document.checkform.new_total.value="£"+x
		w.innerHTML="(includes £2.00 Small Orders Handling Charge)"
	}
}

function handlingCharge()
// Determines whether or not to add a handling charge.
{
	var goods=document.checkform.new_total.title
	if (goods < 10.00)
	{
		a=new RegExp("nPrice", "i")
		l=new RegExp("catalogues", "i")
		b=document.checkform.elements
		var m=0
		var n=0
		for(i=0;i<b.length;i++)
		{
			if (a.exec(b[i].name))
			{
				j=b[i].getAttribute('title')
				if (l.test(j))
				{
					n=n+1
				}
				else
				{
					n=n+1
					m=m+1
				}
			}
		}
		if (m==n)
		{
			return Number(CurrencyFormatted(2))
		}
		else
		{
			return Number(CurrencyFormatted(0))
		}
	}
	else
	{
		return Number(CurrencyFormatted(0))
	}
}

function getValue()
// Calculates VAT Free values on the checkout confirm
// page for Non-EU countries + Channel Islands
{
a=new RegExp("nPrice", "i")
k=new RegExp("¬vat1¬", "i")
b=document.checkform.elements
var h=0.00

for(i=0;i<b.length;i++){
	if (a.exec(b[i].name))
	{
	j=b[i].getAttribute('title')
		if (k.test(j) == false)
		{
		c=Number(b[i].getAttribute('value'))
		d=b[i].getAttribute('alt')
		var e=CurrencyFormatted(c/1.175)
		var f=(e*d)
		var g=(f+h)
		}
		else
		{
		c=Number(b[i].getAttribute('value'))
		d=b[i].getAttribute('alt')
		var f=(c*d)
		var g=(f+h)
		}
	h=g
	}
}
return h;
}


function confirmValidator()
//Validates the form on checkout_confirm.asp
{
	var checkUK = new RegExp("IOM|Northern Ireland|Scotland|IOW", "i");
	var country = document.checkform.p_country.value;
	var foreign = new RegExp("United Kingdom|IOM|Northern Ireland|Scotland|IOW", "i");

	if (document.checkform.gauge.value == "blank")
	//ensures that a gauge has been selected
	{
	alert("Please select the closest gauge/hobby from the list");
	document.checkform.gauge.style.backgroundColor="#FFFF66";
	return false;
	}    
	else
	{
	document.checkform.gauge.style.backgroundColor="white";
	}
	
	if (document.checkform.p_country.value == "blank")
	//ensures that a country has been selected
	{
	alert("Please enter your country.");
	document.checkform.p_country.style.backgroundColor="#FFFF66";
	return false;
	}
	else
	{
	document.checkform.p_country.style.backgroundColor="white";
	}
	if (foreign.test(country) && (document.checkform.carriage.value == "blank"))
	{
	alert("Please select your desired Carriage Service");
	document.checkform.carriage.style.backgroundColor="#FFFF66";
	return false;
	}
	else
	{
	document.checkform.carriage.style.backgroundColor="white";
	}
	
return true;
}

function emptyValidator()
{
	var a=document.empty.target
	if (a.checked)
	{
		return true;
	}
	else
	{
		alert("If you wish to empty your shopping basket, please check the box and then click \"Confirm\"");
		return false;
	}
}

function basket_link()
{
	var a = window.document.URL
	var b = new RegExp("search_results.asp", "i")
	var c = new RegExp("prod.asp", "i")

	if (b.test(a))
	{
		// ***** COMMENTED OUT AFTER REMOVAL OF BASKET LINK FROM SIDE MENUS *****
		//var basketLink = document.getElementById('basket').href
		//document.getElementById('basket').href = basketLink + "&refer=1"
		if (document.getElementByID && document.getElementByID('basket2'))
		{
			var basketLink_2 = document.getElementById('basket2').href
			document.getElementById('basket2').href = basketLink_2 + "&refer=1"
		}
	}
	else if (c.test(a))
	{
		// ***** COMMENTED OUT AFTER REMOVAL OF BASKET LINK FROM SIDE MENUS *****
		//var basketLink = document.getElementById('basket').href
		//document.getElementById('basket').href = basketLink + "&refer=2"
		if (document.getElementByID && document.getElementByID('basket2'))
		{
			var basketLink_2 = document.getElementById('basket2').href
			document.getElementById('basket2').href = basketLink_2 + "&refer=2"
		}
	}
}

function guide()
{
	window.location.href = "siteguide.asp#searchboxes"
}

function lrgImage(pid,strLargeFileAndPath,strFileAndPath,nCount,nLargeImageWidth)
{
	var row = document.getElementById('row_'+nCount)
	var row2 = document.getElementById('row2_'+nCount)
	var button = document.getElementById(pid)
	var cell = document.getElementById(nCount)
	var large = document.getElementById('lrg_'+nCount)
	var action = "smallImage('" + pid + "', '" + strLargeFileAndPath + "', '" + strFileAndPath + "', '" + nCount + "', '" + nLargeImageWidth + "');"
	button.src = strLargeFileAndPath
	row.insertCell(0)
	row2.insertCell(0)
	button.width = nLargeImageWidth
	cell.rowSpan="1"
	cell.colSpan="4"
	cell.width = "100%"
	if (navigator.appName == "Microsoft Internet Explorer")
	{
		button.onclick = action
		large.onclick = action
		large.src = "resource/tran.gif"
		large.width = "1"
		large.height = "1"
	}
	else
	{
		button.setAttribute('onClick', action)
		large.setAttribute('onClick', action)
		large.src = "resource/view_small.gif"
	}
	window.location="#"+nCount
}

function smallImage(pid,strLargeFileAndPath,strFileAndPath,nCount,nLargeImageWidth)
{
	var row = document.getElementById('row_'+nCount)
	var row2 = document.getElementById('row2_'+nCount)
	var button = document.getElementById(pid)
	var cell = document.getElementById(nCount)
	var large = document.getElementById('lrg_'+nCount)
	var action = "lrgImage('" + pid + "', '" + strLargeFileAndPath + "', '" + strFileAndPath + "', '" + nCount + "', '" + nLargeImageWidth + "');"
	row.deleteCell(0)
	row2.deleteCell(0)
	button.src = strFileAndPath
	button.width = "100"
	cell.rowSpan="3"
	cell.colSpan="1"
	cell.width = "100"
	if (navigator.appName == "Microsoft Internet Explorer")
	{
		button.onclick = action
		large.onclick = action
		large.src = "resource/tran.gif"
		large.width="1"
		large.height="1"
	}
	else
	{
		button.setAttribute('onClick', action)
		large.setAttribute('onClick', action)
		large.src = "resource/view_large.gif"
	}
	window.location="#"+nCount
}

function countdown(year, month, day, hour, minute, format)
{
	Today = new Date();
	Todays_Year = Today.getFullYear() - 2000;
	Todays_Month = Today.getMonth() + 1;                  
	
	//Convert both today's date and the target date into miliseconds.                           
	Todays_Date = (new Date(Todays_Year, Todays_Month, Today.getDate(), 
						 Today.getHours(), Today.getMinutes(), Today.getSeconds())).getTime();                                 
	Target_Date = (new Date(year, month, day, hour, minute, 00)).getTime();                  
	
	//Find their difference, and convert that into seconds.                  
	Time_Left = Math.round((Target_Date - Todays_Date) / 1000);
	
	if(Time_Left < 0)
	Time_Left = 0;
	
	switch(format)
	{
		case 0:
			//The simplest way to display the time left.
			if (Time_Left <= 0)
			{
				document.getElementById("ndays").innerHTML = 'The festive Next Business Day delivery dates are: 24/12, 28/12, 29/12, 30/12, 31/12 & 04/01/10, normal service thereafter.';
				break;
			}
			else
			{
				document.getElementById("ndays").innerHTML = Time_Left + ' seconds';
			}
			
			break;
		case 1:
			//More datailed.
			if (Time_Left <= 0)
			{
				document.getElementById("ndays").innerHTML = 'The festive Next Business Day delivery dates are: 24/12, 28/12, 29/12, 30/12, 31/12 & 04/01/10, normal service thereafter.';
				
			}
			else
			{
				days = Math.floor(Time_Left / (60 * 60 * 24));
				Time_Left %= (60 * 60 * 24);
				hours = Math.floor(Time_Left / (60 * 60));
				Time_Left %= (60 * 60);
				minutes = Math.floor(Time_Left / 60);
				Time_Left %= 60;
				seconds = Time_Left;
				
				dps = 's'; hps = 's'; mps = 's'; sps = 's';
				//ps is short for plural suffix.
				if(days == 1) dps ='';
				if(hours == 1) hps ='';
				if(minutes == 1) mps ='';
				if(seconds == 1) sps ='';
				if(minutes < 10) minutes = "0" + minutes;
				if(seconds < 10) seconds = "0" + seconds;
				
				document.getElementById("ndays").innerHTML = days + ' days left';
				document.getElementById("ntime").innerHTML = hours + ':';
				document.getElementById("ntime").innerHTML += minutes + ':';
				document.getElementById("ntime").innerHTML += seconds;
			}
			break;
		default: 
			document.getElementById("ndays").innerHTML = Time_Left + ' seconds';
	}
	if (Time_Left > 0) // Added 22.12.05 by MSC to only make recursive call if Time_Left is greater than 0
	{
	//Recursive call, keeps the clock ticking
	setTimeout('countdown(' + year + ',' + month + ',' + day + ',' + hour + ',' + minute + ',' + format + ');', 1000);
	}
}
//-->