<!--
// JavaScript Document

function advancedSearch()
{
	var keyword = document.forms['adSearch'].searchstring.value;
	if (keyword == "")
	{
		alert("Please enter a searchterm before submitting this form");
		return false;
	}
}

function search_account()
{
    var surname = document.forms['accountSearch'].strSearchStringSurname.value;
    var postcode = document.forms['accountSearch'].strSearchStringPostCode.value;
    if ( (surname == "") && (postcode == "") )
    {
        alert("Please fill in the required information before submitting this form");
        return false;
    }
    else
    {
        if (surname == "")
        {
            alert("Please enter a surname before submitting this form");
            return false;
        }
        if  (postcode == "")
        {
            alert("Please enter a postcode before submitting this form");
            return false;
        }
    }
}

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
{
var 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
{
var txt=document.forms[1].searchstring.value;
document.forms[1].searchtitle.value=txt;
}

function put3()

{
var id=document.forms['f2'].searchstring.options[document.forms['f2'].searchstring.selectedIndex].text;
document.forms['f2'].searchtitle.value=id;
}

function contactValidator()
//Validates the e-mail form
{

var person=document.forms['frm'].name.value;
var address=document.forms['frm'].email.value;
var address_2=document.forms['frm'].email_2.value;
var mailto=document.forms['frm'].recipient.value;

var box=document.forms['frm'].recipient.options[document.forms['frm'].recipient.selectedIndex].text;
document.forms['frm'].subject.value=box;

var message = document.forms['frm'].enquiry.value;
var zRegExp = "^[A-Za-z0-9_-]+[A-Za-z0-9_.-]*@[A-Za-z0-9]+[A-Za-z0-9_-]+[.][A-Za-z0-9_-]+[A-Za-z0-9_.-]*[A-Za-z0-9]+$";

	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 (address.search(zRegExp) == -1)
	{
		alert("Please enter a valid E-Mail Address in the E-mail field");
		return false;
	}
	else if (address_2.search(zRegExp) == -1)
	{
		alert("Please enter a valid E-Mail Address in the Confirmation E-mail field");
		return false;
	}
	else if (address != address_2)
	{
		alert("You have not confirmed the e-mail address correctly.  Please double-check and resubmit.");
		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 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 = 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 = basket.href
		//basket.href = basketLink + "&refer=1"
		var basketLink_2 = basket2.href;
		basket2.href = basketLink_2 + "&refer=1";
	}
	else if (c.test(a))
	{
		// ***** COMMENTED OUT AFTER REMOVAL OF BASKET LINK FROM SIDE MENUS *****
		//var basketLink = basket.href
		//basket.href = basketLink + "&refer=2"
		var basketLink_2 = basket2.href;
		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, 29/12, 30/12, 31/12 & 02/01/09, 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, 29/12, 30/12, 31/12 & 02/01/09, 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';
	}
	//Recursive call, keeps the clock ticking
	setTimeout('countdown(' + year + ',' + month + ',' + day + ',' + hour + ',' + minute + ',' + format + ');', 1000);
}

//-->