function cursor_sniff(obj)
	{if (document.all){obj.cursor="hand"}else{obj.cursor="pointer"}}
	
function room_book()
	{
	mt = false;
	checker('FullName','You must enter your full name')
	email('details','from')
	checker('telephone','You must enter your telephone number')
	card_check('details','card','cardno')
	checker('cvc','You must enter your 3 digit security number')
	if (mt==false){document.details.submit()}
	}
	
function book()
	{
	mt = false;
	checker('FullName','You must enter your full name')
	email('details','from')
	if (mt==false){document.details.submit()}
	}
	
function offer(offer){location.replace('https://onlinesecurepay.co.uk/hotelsinyork/gateway/room_booking.asp?offer='+offer)}
	
function email(fm,fobj)
	{
	obj=eval('document.'+fm+'.'+fobj)
	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) && mt==false){alert("Email address seems incorrect (check @ and .'s)");mt=true;obj.focus()}
	if (mt==false){var user=matchArray [1];var domain=matchArray [2];if (user.match(userPat)==null){alert("The username doesn't seem to be valid.");mt=true;obj.focus()}}
	if (mt==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!");mt=true;obj.focus()}}}}
	if (mt==false){var domainArray=domain.match(domainPat);if (domainArray==null){alert("The domain name doesn't seem to be valid.");mt=true;obj.focus()}}
	if (mt==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>4){alert("The address must end in a two,three or four letter domain");mt=true;obj.focus()}}
	if ((len<2) && mt==false){alert("This address is missing a hostname!");mt=true;obj.focus()};
	}
		
function checker(fobj,msg)
	{obj=eval('document.details.'+ fobj);if(obj.value=="" && mt==false){alert(msg);mt = true;obj.focus();}}

function check1(fm,fobj)
	{obj=eval('document.'+fm+'.'+fobj);if(obj.value=="" && mt==false){alert("The " + fobj + " field must not be blank");mt=true;obj.focus()}}
	
//Card Validator
function card_check(fm,c,cno)
	{
	failed		= false;d=new Date();cur_month=d.getMonth()+1;cur_year=d.getYear();newStr=''
	card_ty		= eval('document.'+fm+'.'+c);
	card_no		= eval('document.'+fm+'.'+cno);
	val_month 	= document.details.startmonth.options[document.details.startmonth.selectedIndex].text;
	val_year 	= document.details.startyear.options[document.details.startyear.selectedIndex].text;
	exp_month 	= document.details.expirymonth.options[document.details.expirymonth.selectedIndex].text;
	exp_year 	= document.details.expiryyear.options[document.details.expiryyear.selectedIndex].text;
	card		= card_ty.options[card_ty.selectedIndex].text;
	if (card=='Select Card' && mt==false){alert("You must select a Card Type");mt=true;card_ty.focus()}
	for (var k = 0; k < parseInt(card_no.value.length); k++){var a = card_no.value.charAt(k);if ((a != " ") && (a != "-")){newStr += card_no.value.charAt(k);}}for (var k = 0; k < parseInt(newStr.length); k++){var a = newStr.charAt(k);if (((a < 0) || (a > "9")) && mt==false){alert("Numbers only Please");mt=true;card_no.focus()}}
	if((card_no.value== ""  || newStr.length < "10") && mt==false){alert("Incorrect Number of Digits");mt=true;card_no.focus()}
	if(newStr.length % 2 == 0 && mt==false){even();}
	if(newStr.length % 2 != 0 && mt==false){odd();}
	if ((exp_year < cur_year)||(exp_year == cur_year && exp_month < cur_month) && mt==false){alert("You Card has expired");mt=true;document.details.expirymonth.focus();}
	}
	
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");mt= true;document.details.cardno.focus();}}
//End	

function change_image(){card= document.details.card;change_image2('Select Card','shim');change_image2('Maestro','maestro');change_image2('MasterCard','mastercard');change_image2('Solo','solo');change_image2('Visa','visa');change_image2('Delta','delta');}
function change_image2(sel,fname){loc="/images/" + fname + ".gif";if(card.options[card.selectedIndex].text == sel){if(document.images){document.ccard.src= loc}}}

function calc_cost()
	{
	d=document.details.delegates.value;r=document.details.rate.value;c2=document.details.course2.value
	c3=document.details.course3.value;c0=document.details.coffee.value;b=document.details.breakfast.value
	if (d<10){alert("You must have 10 delegates or more");document.details.delegates.focus()}
	t=(d*r);if(c2=="Yes" && (c3=="No" || c3=="")){t=t+(d*4)};if(c3=="Yes"){t=t+(d*8)};if(b=="Yes"){t=t+(d*6)};if(c0=="Yes"){t=t+(d*2)}
	document.details.total.value = "£"+t
	}

function changeval(obj){a=obj.name.replace('-a','');nobj=eval('document.details.'+a);nobj.value=obj.value;calc_cost()}
