function check_browser()
	{
	if (document.getElementsByTagName) products()
	else location.href="old_browser.asp"
	}

function chk()
	{
	content=document.getElementById("intro").innerHTML + document.getElementById("intro2").innerHTML
	document.getElementById("intro").innerHTML=""
	document.getElementById("intro2").innerHTML=""	
	document.getElementById("text").innerHTML= '<br><br>' + content
	}

function products()
	{
	a=document.getElementsByTagName("IMG")
	for (var b=0;b<a.length;b++)
		{
		myString = new String(a[b].src)
		rExp = /products\/thumbs/gi;
		result = myString.search(rExp)

		if(a[b].width>100 && result!=-1)
			{a[b].width=100}
		else if(a[b].height>150 && result!=-1)
			{a[b].height=150}
		}
	}
	
function do_search()
	{
	if (document.getElementById("search_box").value.length>2){document.getElementById("search_option").submit()}else{alert('You must enter at least three characters')}
	}
	
function payment_select(p)
	{
	if (p==0){bill='none';ship='none';pay='none';st='none'}
	else if(p==1){bill='block';ship='block';pay='none';st='none'}
	else if(p==2){bill='block';ship='block';pay='block';st='block'}
	else{bill='block';ship='block';pay='block';st='block'}
	document.getElementById("start").style.display=st
	document.getElementById("billing").style.display=bill
	document.getElementById("shipping").style.display=ship
	document.getElementById("payment2").style.display=pay
	}

function checkout()
	{
	empty=false;fm=document.details;
	if(fm.payment[0].checked==true)tick()
	else if(fm.payment[1].checked==true){fbilling();tick()}
	else{fbilling();fpayment();tick()}
	if(empty==false)fm.submit()
	}
	
function express_checkout()
	{
	empty=false;fm=document.details;
	checker(fm.sname,'You must enter your name');
	checker(fm.shippingaddress1,'You must enter the first line of your address');
	checker(fm.shippingaddress2,'You must enter the second line of your address');
	checker(fm.shippcode,'You must enter your post code');
	check_email(fm.email)
	checker(fm.tel,'You must enter a telephone number');
	if(empty==false)fm.submit()
	}

function checker(obj,msg)
	{if(obj.value=="" && empty==false){alert(msg);empty=true;obj.focus()}}

function check_email(obj)
	{
	var emailStr=obj.value;var emailPat=/^(.+)@(.+)$/
	var specialChars="\\(\\)!£$%^&*()+='#~?<>@,;:\\\\\\\"\\.\\[\\]";var validChars="\[^\\s" + specialChars + "\]";var quotedUser="(\"[^\"]*\")";var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/
	var atom=validChars + '+';var word="(" + atom + "|" + quotedUser + ")";var userPat=new RegExp("^" + word + "(\\." + word + ")*$");var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$");var matchArray=emailStr.match(emailPat)
	if ((matchArray==null) && empty==false){alert("Email address seems incorrect (check @ and .'s)");empty=true}
	if (empty==false){var user=matchArray [1];var domain=matchArray [2];if (user.match(userPat)==null){alert("The username doesn't seem to be valid.");empty=true}}
	if (empty==false){var IPArray=domain.match(ipDomainPat);if (IPArray!=null){for (var j=1;j<=4;j++){if (IPArray[j]>255){alert("Destination IP address is invalid!");empty=true}}}}
	if (empty==false){var domainArray=domain.match(domainPat);if (domainArray==null){alert("The domain name doesn't seem to be valid.");empty=true}}
	if (empty==false){var atomPat=new RegExp(atom,"g");var domArr=domain.match(atomPat);var len=domArr.length;if (domArr[domArr.length-1].length<2 || domArr[domArr.length-1].length>3){alert("The address must end in a three-letter domain, or two letter country.");empty=true}}
	if ((len<2) && empty==false){alert("This address is missing a hostname!");empty=true};
	}
	
function fbilling()
	{
	checker(fm.fname,'You must enter your first name');
	checker(fm.surname,'You must enter your Surname');
	checker(fm.billingaddress1,'You must enter the first line of your address');
	checker(fm.billingaddress2,'You must enter the second line of your address');
	check_email(fm.email)
	checker(fm.tel,'You must enter a telephone number');
	}
	
function fpayment()
	{
	failed=false;Str=fm.creditcard.value;newStr='';
	val_month = fm.startmonth.options[fm.startmonth.selectedIndex].text;val_year = fm.startyear.options[fm.startyear.selectedIndex].text;
	exp_month = fm.expirymonth.options[fm.expirymonth.selectedIndex].text;exp_year = fm.expiryyear.options[fm.expiryyear.selectedIndex].text;
	d=new Date();cur_month=d.getMonth()+1;cur_year=d.getFullYear()
	for (var k=0; k<parseInt(Str.length); k++){var a=Str.charAt(k);if ((a != " ") && (a != "-")){newStr += Str.charAt(k);}}for (var k = 0; k < parseInt(newStr.length);k++){var a=newStr.charAt(k);if (((a < 0) || (a > "9")) && empty==false){alert("Numbers only Please");empty=true;fm.creditcard.focus();}}if((fm.creditcard.value =="" || newStr.length < "10") && empty ==false){alert("Incorrect Number of Digits");empty=true;fm.creditcard.focus();}if(newStr.length % 2 == 0 && empty ==false){even();}if(newStr.length % 2 != 0 && empty==false){odd()}
	if ((exp_year < cur_year)||(exp_year == cur_year && exp_month < cur_month) && empty==false){alert("You Card has expired");empty=true;fm.expirymonth.focus()}
	if ((fm.payment.value==2) && ((val_year =cur_year && val_month > cur_month)||(exp_year > cur_year)) && empty==false){alert("You start date is incorrect");empty=true;fm.startmonth.focus()}
	checker(fm.cvc,'You must enter the last three digits or four digits (Amex) on the reverse of the card')
	}

function even()
	{tot=0;z=parseInt(newStr.charAt(0));bigger_than_5();x=1; y=parseInt(newStr.length);while (x<y){z=parseInt(newStr.charAt(x));if (x % 2 != 0){tot=tot + z;}else {bigger_than_5()}x++;}invalid()}

function odd()
	{tot=0;z=parseInt(newStr.charAt(0));tot=tot + z;x=1; y=parseInt(newStr.length);while (x<y){z=parseInt(newStr.charAt(x));if (x % 2 != 0){bigger_than_5()}else {tot=tot + z;}x++;}invalid()}

function bigger_than_5()
	{if (z*2 >=10){num=z*2;n=num.toString();n1=parseInt(n.charAt(0));n2=parseInt(n.charAt(1));tot=tot + n1 + n2;}else{tot=tot + (z*2);}}

function invalid()
	{if (tot % 10 != 0){alert("Invalid Card Number");empty=true;fm.creditcard.focus()}}

function change_image(obj)
	{
	if (obj.options[obj.selectedIndex].text=="Select Card") gif = 'shim'
	else gif=obj.options[obj.selectedIndex].text
	document.getElementById("ccard").src="/images/" + gif + ".gif"
	}

function terms(a)
	{window.open(a,'terms','width=600,height=400,scrollbars=yes');fm.tbox.disabled=false}
	
function tick()
	{if(fm.tbox.checked!=true && empty==false){alert('You must agree to our terms and conditions');empty=true}}	
	
function cursor_sniff(obj)
	{if (document.all)obj.cursor="hand";else obj.cursor="pointer"}
	
window.onload=check_browser