function checkBuyPartNo(buyqty)  {

	if (buyqty <1)  {
		alert("You have to buy at least 1 of those!");	
		return false;
	}
	if (buyqty >999)  {
		alert("You can't buy that many of those!");	
		return false;
	}
}


bName = navigator.appName;
var addrunonce=0;
var chechoutrunonce=0;

function checkChar(word)  {
	validChars = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ@- .";
	charError=0;
	loop = 0;
	total = word.length;
	while (loop != total)  {
		letter = word.substring(loop,loop+1);
		if (validChars.indexOf(letter) == -1)  {
			charError = 1;
		}
	loop ++;
	}
return charError;
}

function checkDigit(word)  {
	validChars = "0123456789";
	charError=0;
	loop = 0;
	total = word.length;
	while (loop != total)  {
		letter = word.substring(loop,loop+1);
		if (validChars.indexOf(letter) == -1)  {
			charError = 1;
		}
	loop ++;
	}
return charError;
}

function newcheckOut(sesid,club)  {
	return false;
	if (checkChar(document.checkout.name.value) == 1)  {
		alert("You have entered an invalid character in the name.");
		charError=1;
		return false;
	}
	if (checkChar(document.checkout.address1.value) == 1)  {
		alert("You have entered an invalid character in the first line of the address.");
		charError=1;
		return false;
	}
	if (checkChar(document.checkout.address2.value) == 1)  {
		alert("You have entered an invalid character in the second line of the address.");
		charError=1;
		return false;
	}
	if (checkChar(document.checkout.address3.value) == 1)  {
		alert("You have entered an invalid character in the third line of the address.");
		charError=1;
		return false;
	}
	if (checkChar(document.checkout.address4.value) == 1)  {
		alert("You have entered an invalid character in the fourth line of the address.");
		charError=1;
		return false;
	}
	if (checkChar(document.checkout.postcode.value) == 1)  {
		alert("You have entered an invalid character in the post code.");
		charError=1;
		return false;
	}
	if (checkChar(document.checkout.telephone.value) == 1)  {
		alert("You have entered an invalid character in your telephone number.");
		charError=1;
		return false;
	}
	if (checkChar(document.checkout.email.value) == 1)  {
		alert("You have entered an invalid character in your email address.");
		charError=1;
		return false;
	}
	if (checkChar(document.checkout.cardname.value) == 1)  {
		alert("You have entered an invalid character in the card holders name.");
		charError=1;
		return false;
	}
	if (checkDigit(document.checkout.card.value) == 1)  {
		alert("You have entered an invalid character in the card number.");
		charError=1;
		return false;
	}
	if (checkChar(document.checkout.issue.value) == 1)  {
		alert("You have entered an invalid character in the card issue number.");
		charError=1;
		return false;
	}
	if (checkChar(document.checkout.csv.value) == 1)  {
		alert("You have entered an invalid character in the card security number.");
		charError=1;
		return false;
	}
	if (checkChar(document.checkout.cardhouse.value) == 1)  {
		alert("You have entered an invalid character in the card holders house number.");
		charError=1;
		return false;
	}
	if (checkChar(document.checkout.cardpostcode.value) == 1)  {
		alert("You have entered an invalid character in he card holders post code.");
		charError=1;
		return false;
	}
	if (checkChar(document.checkout.cardtelephone.value) == 1)  {
		alert("You have entered an invalid character in the card holders telephone number.");
		charError=1;
		return false;
	}

	error=0;
	if (document.checkout.name.value == '' && error == 0)  {
		alert("Please enter a delivery name.");
		error=1
	}
	if ((document.checkout.address1.value == '' || document.checkout.address2.value == '') && error == 0)  {
		alert("Please enter at least two address lines.");
		error=1
	}
	if ((document.checkout.postcode.value == '') && error == 0)  {
		alert("Please enter a postcode.");
		error=1
	}
	if ((document.checkout.telephone.value == '') && error == 0)  {
		alert("Please enter a telephone number.");
		error=1
	}
	if ((document.checkout.email.value == '') && error == 0)  {
		alert("Please enter your email address.");
		error=1
	}
	if ((document.checkout.email.value.indexOf("@") <0 || (document.checkout.email.value.indexOf(".co.uk") <0 && document.checkout.email.value.indexOf(".com") <0))  && error == 0)   {
		alert("Please enter a valid email address.");
		error=1
	}
	if ((document.checkout.cardname.value == '') && error == 0)  {
		alert("Please enter the card holders name.");
		error=1
	}
	if ((document.checkout.card.value == '') && error == 0)  {
		alert("Please enter the card number.");
		error=1
	}
	if ((document.checkout.startdate.value == 'Please Choose' || document.checkout.startdate.value == '') && error == 0)  {
		alert("Please enter the card start date.");
		error=1
	}
	if ((document.checkout.expirydate.value == 'Please Choose' || document.checkout.expirydate.value == '') && error == 0)  {
		alert("Please enter the card expiry date.");
		error=1
	}
	if ((document.checkout.csv.value == '') && error == 0)  {
		alert("Please enter the cards security number.");
		error=1
	}
	
	if (error == 1)  {
		return false;
	}
}

function checkOut(sesid,colour)  {
	if (checkChar(document.checkout.name.value) == 1)  {
		alert("You have entered an invalid character in the name.");
		charError=1;
		return false;
	}
	if (checkChar(document.checkout.address1.value) == 1)  {
		alert("You have entered an invalid character in the first line of the address.");
		charError=1;
		return false;
	}
	if (checkChar(document.checkout.address2.value) == 1)  {
		alert("You have entered an invalid character in the second line of the address.");
		charError=1;
		return false;
	}
	if (checkChar(document.checkout.address3.value) == 1)  {
		alert("You have entered an invalid character in the third line of the address.");
		charError=1;
		return false;
	}
	if (checkChar(document.checkout.address4.value) == 1)  {
		alert("You have entered an invalid character in the fourth line of the address.");
		charError=1;
		return false;
	}
	if (checkChar(document.checkout.postcode.value) == 1)  {
		alert("You have entered an invalid character in the post code.");
		charError=1;
		return false;
	}
	if (checkChar(document.checkout.telephone.value) == 1)  {
		alert("You have entered an invalid character in your telephone number.");
		charError=1;
		return false;
	}
	if (checkChar(document.checkout.email.value) == 1)  {
		alert("You have entered an invalid character in your email address.");
		charError=1;
		return false;
	}
	if (checkChar(document.checkout.cardname.value) == 1)  {
		alert("You have entered an invalid character in the card holders name.");
		charError=1;
		return false;
	}
	if (checkChar(document.checkout.card.value) == 1)  {
		alert("You have entered an invalid character in the card number.");
		charError=1;
		return false;
	}
	if (checkChar(document.checkout.issue.value) == 1)  {
		alert("You have entered an invalid character in the card issue number.");
		charError=1;
		return false;
	}
	if (checkChar(document.checkout.csv.value) == 1)  {
		alert("You have entered an invalid character in the card security number.");
		charError=1;
		return false;
	}
	if (checkChar(document.checkout.cardhouse.value) == 1)  {
		alert("You have entered an invalid character in the card holders house number.");
		charError=1;
		return false;
	}
	if (checkChar(document.checkout.cardpostcode.value) == 1)  {
		alert("You have entered an invalid character in he card holders post code.");
		charError=1;
		return false;
	}
	if (checkChar(document.checkout.cardtelephone.value) == 1)  {
		alert("You have entered an invalid character in the card holders telephone number.");
		charError=1;
		return false;
	}

	error=0;
	if (document.checkout.name.value == '' && error == 0)  {
		alert("Please enter a delivery name.");
		error=1
	}
	if ((document.checkout.address1.value == '' || document.checkout.address2.value == '') && error == 0)  {
		alert("Please enter at least two address lines.");
		error=1
	}
	if ((document.checkout.postcode.value == '') && error == 0)  {
		alert("Please enter a postcode.");
		error=1
	}
	if ((document.checkout.telephone.value == '') && error == 0)  {
		alert("Please enter a telephone number.");
		error=1
	}
	if ((document.checkout.email.value == '') && error == 0)  {
		alert("Please enter your email address.");
		error=1
	}
	if ((document.checkout.email.value.indexOf("@") <0 || document.checkout.email.value.indexOf(".") <0)  && error == 0)   {
		alert("Please enter a valid email address.");
		error=1
	}
	if ((document.checkout.cardname.value == '') && error == 0)  {
		alert("Please enter the card holders name.");
		error=1
	}
	if ((document.checkout.card.value == '') && error == 0)  {
		alert("Please enter the card number.");
		error=1
	}
	if ((document.checkout.startdate.value == 'Please Choose' || document.checkout.startdate.value == '') && error == 0)  {
		alert("Please enter the card start date.");
		error=1
	}
	if ((document.checkout.expirydate.value == 'Please Choose' || document.checkout.expirydate.value == '') && error == 0)  {
		alert("Please enter the card expiry date.");
		error=1
	}
	if ((document.checkout.csv.value == '') && error == 0)  {
		alert("Please enter the cards security number.");
		error=1
	}
	
	if (error == 1)  {
		return false;
	} else  {
		newUrl = "checkout.php?sesid="+sesid+"&Colour="+colour;
		leftpos = (screen.width - 300) / 2;
		toppos = (screen.height - 190) / 2;
		if (addrunonce == 1) {
                if ( ! addlinkwin.closed){addlinkwin.close();};
         	  };
	        addlinkwin = window.open(newUrl,"AddWindow","scrollbars=no,menubar=no,width=300,height=190,toolbar=0,resizable=0,top="+toppos+",left="+leftpos);
        	addrunonce = 1;
        }
		function closelinkwin()
        	{
	        if (addrunonce == 1) {
        	        if ( ! addlinkwin.closed){addlinkwin.close();};
          	 }
	}
}


function stopEnter() {
	return !(window.event && window.event.keyCode == 13);
}

function checkBuy(sesid,client,product,colour,buyItemId,buyQty)  {
	if (buyQty <1)  {
		alert("You have to buy at least 1 of those!");	
		return false;
	}
	if (buyQty >999)  {
		alert("You can't buy that many of those!");	
		return false;
	}
	newUrl = "/basket.php?BuyAction=add&sesid="+sesid+"&BuyQty="+buyQty+"&BuyItemId="+buyItemId+"&Client="+client+"&Product="+product+"&Colour="+colour

	leftpos = (screen.width - 300) / 2;
	toppos = (screen.height - 190) / 2;
	if (addrunonce == 1) {
                if ( ! addlinkwin.closed){addlinkwin.close();};
         	  };
	        addlinkwin = window.open(newUrl,"AddWindow","scrollbars=no,menubar=no,width=300,height=190,toolbar=0,resizable=0,top="+toppos+",left="+leftpos);
        	addrunonce = 1;
			return false;
        }
	function closelinkwin()
        	{
	        if (addrunonce == 1) {
        	        if ( ! addlinkwin.closed){addlinkwin.close();};
          	 }
}

var runinfo = 0;
function disp_info (url,xwd,yht)
{
	if (runinfo == 1)
	{
		if ( ! infowin.closed){infowin.close();};
	};
	var screen_width;
	var screen_height;
	if ( xwd == 0 )
	{
		screen_width = screen.width * 3/4;
	}
	else
	{
		screen_width = xwd;
	}
	if ( yht == 0 )
	{
		screen_height = screen.height * 3/4;
	}
	else
	{
		screen_height = yht;
	}

	leftpos = (screen.width - screen_width) / 2;
	toppos = (screen.height - screen_height) / 2;

	infowin = window.open(url,"Information","scrollbars=yes,scrolling=yes,toolbar=no,menubar=no,width="+screen_width+",height="+screen_height+",noresizable,top="+toppos+",left="+leftpos);
	runinfo = 1;
}

function start()  {
	today = new Date();
	month = today.getMonth() + 1;
	startMonth = month;
	year = today.getYear();
	if (bName == "Netscape") year = today.getYear() + 1900;
	startYear = year - 5;
	while (year != startYear)  {
		textYear=year;
		while (month != 0)  {
			if (month < 10)  {
				textMonth="0" + month  }
			else  {
				textMonth = month  }
			document.write("<OPTION VALUE=\"",textMonth,"/",textYear,"\">",textMonth,"/",textYear,"</option>");
			month --;
		}
		month = 12;
		year --;
	}
}

function expiry()  {
	today = new Date();
	month = today.getMonth() + 1;
	endMonth = month;
	year = today.getYear();
	if (bName == "Netscape") year = today.getYear() + 1900;
	endYear = year + 5;
	while (year != endYear)  {
		textYear=year;
		while (month != 13)  {
			if (month < 10)  {
				textMonth="0" + month;
			}
			else  {
				textMonth = month;
			}
			document.write("<OPTION VALUE=\"",textMonth,"/",textYear,"\">",textMonth,"/",textYear,"</option>");
			month ++;
		}
	month = 1;
	year ++;
	}
}
