<!--
// JavaScript Document

function addToCart(frm)
{
	var midScreenWidth = (screen.availWidth)/2; // find the mid width
	var midScreenHeight = (screen.availHeight)/2; // find the mid height
	var l = midScreenWidth - 208; // position left
	var t = midScreenHeight - 150; // position top
	var quantity = frm.prodQuantity.value;
	var typeid = frm.typeID.value;
	var subcatid = frm.subcatID.value;
	var product = frm.prodID.value;
	var charlen = quantity.length + product.length;
	var winFeatures = ("width=416,height=350,left="+l+",top="+t+",scrollbars=1,resizeable=1");
	var winURL = "/addcart.asp?cartaction=add&prodID="+product+"&typeID="+typeid+"&subcatID="+subcatid+"&quantity="+quantity+"&charlen="+charlen;
	
	//if(!popWin || popWin.closed)
	//{
  		//popWin = window.open(winURL, 'popWin', winFeatures);
		window.location = winURL;
 	/*}
 	else
	
  		popWin.location = winURL;
  		popWin.focus();
 	}
	//window.opener.location.reload();
	*/
}

//----------------------------
// utility function to test for invalid input
//---------------------
function checkCartQuantities(frm)
{
	var elQuant, i, minQuant;
	var upperLimit = (frm.productLines.value) - 1;
	for(i=1; i <= upperLimit; i++)
	{
		//alert(i);
		//alert(eval('frm.uQuantity'+i+'.value'));
		elQuant = eval('frm.uQuantity'+i);
		minQuant = eval('frm.minquantity'+i);
		if (isNaN(elQuant.value) || elQuant.value < 1 || elQuant.value == "")
		{
			alert("Please enter a numeric value.");
			elQuant.select();
			return false;
		}
		if (elQuant.value-0 < minQuant.value-0)
		{
			alert("Cannot update quantity as the minimum order quantity is " + minQuant.value + ".");
			elQuant.select();
			return false;
		}
	}
	return true;
}

function updateCartOnSubmit(frm)
{
	return checkCartQuantities(frm);
}

//end of shopping cart methods
function resizeBoxes2(){
if (document.cart.cartaction)
{
	if (document.cart.cartaction.value == "viewcart"){}
	if (document.cart.cartaction.value == "emptycart"){}
	if (document.cart.cartaction.value == "del"){}
	if (document.cart.cartaction.value == "checkout"){}
	if (document.cart.cartaction.value == "checkout2")
		{	
		if(nameCode==1 ){
			document.cart.bname.size=25;
			document.cart.baddress.cols=24;
			document.cart.btown.size=25;
			document.cart.bcounty.size=25;
			document.cart.bpostcode.size=10;
			document.cart.bemail.size=25;
			document.cart.btel.size=25;
			document.cart.bfax.size=25;}
		else if(versionCode>=5){
			document.cart.bname.size=25;
			document.cart.baddress.cols=24;
			document.cart.btown.size=25;
			document.cart.bcounty.size=25;
			document.cart.bpostcode.size=10;
			document.cart.bemail.size=25;
			document.cart.btel.size=25;
			document.cart.bfax.size=25;}
	}
	if (document.cart.cartaction.value == "checkout3")
	{	
		if(nameCode==1 ){
			document.cart.dname.size=25;
			document.cart.daddress.cols=24;
			document.cart.dtown.size=25;
			document.cart.dcounty.size=25;
			document.cart.dpostcode.size=10;
			document.cart.dtel.size=25;}
		else if(versionCode>=5){
			document.cart.dname.size=25;
			document.cart.daddress.cols=24;
			document.cart.dtown.size=25;
			document.cart.dcounty.size=25;
			document.cart.dpostcode.size=10;
			document.cart.dtel.size=25;}
	}
	if (document.cart.cartaction.value == "checkout4")
	{	
		if(nameCode==1 ){
			document.cart.comments.cols=20;}
		else if(versionCode>=5){
			document.cart.comments.cols=20;}
	}
	if (document.cart.cartaction.value == "processemail")
	{	
		if (document.cart.bemail){
			if(nameCode==1 ){
				document.cart.bemail.size=25;}
			else if(versionCode>=5){
				document.cart.bemail.size=25;}
		}
	}
	if (document.cart.cartaction.value == "thankyou"){}
	if (document.cart.cartaction.value == "printShopCart"){}
	if (document.cart.cartaction.value == "processemail"){}
}
}

var popWin = null;
function popUp(popUrl, popWinName, popWidth, popHeight)
{
 if(!popWin || popWin.closed) {
  popWin = window.open(popUrl, popWinName,
config="width="+popWidth+",height="+popHeight+",scrollbars=yes,resizable=yes");
 }
 else {
  popWin.location = popUrl;
  popWin.resizeTo(popWidth, popHeight);
  popWin.focus();
 }
}

function bvalid(){
var submit_me=0;
var my_form=document.cart;
if(my_form.bname.value=="" || my_form.bname.value==" "){
	alert("Please enter your name.");
	my_form.bname.focus();
	submit_me=1;}
if(notValidEmail(my_form.bemail.value) && submit_me==0){
		alert("Please enter a valid e-mail address.")
		my_form.bemail.select();
		submit_me=1;}
if(my_form.cartaction.value == "registerNewUser")
{
	if((trim(my_form.password.value)=="") && submit_me==0){
		alert("Please enter your password.");
		my_form.baddress.focus();
		submit_me=1;}
	if(my_form.password.value.indexOf("'") != -1 && submit_me==0){
		alert("Your password cannot contain apostrophes.");
		my_form.baddress.focus();
		submit_me=1;}
}
if((my_form.baddress.value=="" || my_form.baddress.value==" ") && submit_me==0){
	alert("Please enter your billing address.");
	my_form.baddress.focus();
	submit_me=1;}
if((my_form.btown.value=="" || my_form.btown.value==" ") && submit_me==0){
	alert("Please enter your billing town name.");
	my_form.btown.focus();
	submit_me=1;}
if((my_form.bpostcode.value=="" || my_form.bpostcode.value==" ") && submit_me==0){
	alert("Please enter your billing postcode.");
	my_form.bpostcode.focus();
	submit_me=1;}	
if((my_form.btel.value=="" || my_form.btel.value==" ") && submit_me==0){
	alert("Please enter your telephone number.");
	my_form.btel.focus();
	submit_me=1;}		

if ((my_form.sameAddress.checked) && submit_me==0)
{
	//same address do nothing
}
else if (my_form.chkCollection && (my_form.chkCollection.checked) && submit_me==0)
{
	// collection do nothing
}
else if(submit_me==0)
{
	if((my_form.daddress.value=="" || my_form.daddress.value==" ") && submit_me==0){
	alert("Please enter your delivery address.");
	my_form.daddress.focus();
	submit_me=1;}
if((my_form.dtown.value=="" || my_form.dtown.value==" ") && submit_me==0){
	alert("Please enter your delivery town name.");
	my_form.dtown.focus();
	submit_me=1;}
if((my_form.dpostcode.value=="" || my_form.dpostcode.value==" ") && submit_me==0){
	alert("Please enter your delivery postcode.");
	my_form.dpostcode.focus();
	submit_me=1;}
if((my_form.dtel.value=="" || my_form.dtel.value==" ") && submit_me==0){
	alert("Please enter your delivery telephone number.");
	my_form.dtel.focus();
	submit_me=1;}
}
if(submit_me==0){my_form.submit();}
}

function dvalid(){
var submit_me=0;
var my_form=document.cart;
if((my_form.daddress.value=="" || my_form.daddress.value==" ") && submit_me==0){
	alert("Please enter your delivery address.");
	my_form.daddress.focus();
	submit_me=1;}
if((my_form.dtown.value=="" || my_form.dtown.value==" ") && submit_me==0){
	alert("Please enter your delivery town name.");
	my_form.dtown.focus();
	submit_me=1;}
if((my_form.dcounty.value=="" || my_form.dcounty.value==" ") && submit_me==0){
	alert("Please enter your delivery county name.");
	my_form.dcounty.focus();
	submit_me=1;}
if((my_form.dpostcode.value=="" || my_form.dpostcode.value==" ") && submit_me==0){
	alert("Please enter your delivery postcode.");
	my_form.dpostcode.focus();
	submit_me=1;}	
if(submit_me==0){my_form.submit();}
}

function notValidEmail(pString){
var dotpos=pString.indexOf('.');
var atpos=pString.indexOf('@');
	if(atpos == -1 || (pString=="") || (pString==" ") || (pString.length < 6)){
		return true;
	}
	else if(dotpos + 1 == atpos){
		return true;
	}
	else{
		var emailterm=pString.substring(atpos, (pString.length));
		if(emailterm.indexOf('.')==-1 || emailterm.length < 2){
			return true;}
		else return false;
	}

}

/*
This script is written by Eric (Webcrawl@usa.net)
For full source code, installation instructions,
100's more DHTML scripts, and Terms Of
Use, visit dynamicdrive.com
*/

function printit(){  
if (window.print) {
		window.print() ;  
	} else {
		var WebBrowser = '<OBJECT ID="WebBrowser1" WIDTH=0 HEIGHT=0 CLASSID="CLSID:8856F961-340A-11D0-A96B-00C04FD705A2"></OBJECT>';
		document.body.insertAdjacentHTML('beforeEnd', WebBrowser);
		WebBrowser1.ExecWB(6, 2);//Use a 1 vs. a 2 for a prompting dialog box    WebBrowser1.outerHTML = "";  
	}
}

function trim(inputString) {
   // Removes leading and trailing spaces from the passed string. Also removes
   // consecutive spaces and replaces it with one space. If something besides
   // a string is passed in (null, custom object, etc.) then return the input.
   if (typeof inputString != "string") { return inputString; }
   var retValue = inputString;
   var ch = retValue.substring(0, 1);
   while (ch == " ") { // Check for spaces at the beginning of the string
      retValue = retValue.substring(1, retValue.length);
      ch = retValue.substring(0, 1);
   }
   ch = retValue.substring(retValue.length-1, retValue.length);
   while (ch == " ") { // Check for spaces at the end of the string
      retValue = retValue.substring(0, retValue.length-1);
      ch = retValue.substring(retValue.length-1, retValue.length);
   }
   while (retValue.indexOf("  ") != -1) { // Note that there are two spaces in the string - look for multiple spaces within the string
      retValue = retValue.substring(0, retValue.indexOf("  ")) + retValue.substring(retValue.indexOf("  ")+1, retValue.length); // Again, there are two spaces in each of the strings
   }
   return retValue; // Return the trimmed string back to the user
}
//-->