function MM_swapImgRestore() {
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() {
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) {
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() {
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}


function doVerify() {
	//alert(document.booking.name.value);
	if (document.booking.name.value.length == 0) {
		alert("Please enter your name.");
		document.booking.name.focus(); 
		return false;
	}

	if (document.booking.phone.value == "") {
		 var myTelNo = document.booking.phone.value;
		  // If invalid number, report back error
		  if (!checkUKTelephone (myTelNo)) {
		     alert (telNumberErrors[telNumberErrorNo]);
		     document.booking.phone.focus(); 
		     return false;
		  }
		  // Otherwise redisplay telephone number on form in corrected format
		  else {
		     document.booking.phone.value =  checkUKTelephone (myTelNo);
		  }


//		alert("Please enter your contact number.");
//		document.booking.phone.focus(); 
//		return false;
	}

	if (document.booking.email.value == "") {
		if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(document.booking.email.value)){
		}
		alert("Invalid E-mail Address! Please re-enter.")
		document.booking.email.focus(); 
		return false;
//		alert("Please enter your email address.");
//		document.booking.email.focus(); 
//		return false;
	}

	if ((document.booking.ehrs.value < document.booking.shrs.value == true) && (document.booking.ehrs.value > 0 || document.booking.shrs.value > 0)) {
		alert("Ending time cannot finish before start time!");
		return false;
	}

	if ((document.booking.ehrs.value == document.booking.shrs.value) && (document.booking.ehrs.value > 0 || document.booking.shrs.value > 0)) {
		if ((document.booking.emins.value <= document.booking.smins.value == true) && (document.booking.emins.value >= 0 || document.booking.smins.value >= 0)) {
			alert("Ending time cannot finish before start time!");
			return false;
		}
	}

	if (document.booking.month.value == 4 || document.booking.month.value == 6 || document.booking.month.value == 9 || document.booking.month.value == 11) {
		if (document.booking.day.value > 30) {
			alert("Month selected only has 30 days in the month.");
			return false;
		}
	}
	
	if (document.booking.month.value == 2) {
		if (document.booking.day.value > 29) {
			alert("February does not have 30 days or more!");
			return false;
		}
		else if (document.booking.year.value % 4 != 0) {
			if (document.booking.day.value > 28) {
				alert("There are only 28 days in February for the year " +document.booking.year.value);
				return false;
			}
		}
	}
}


function checkUKTelephone (telephoneNumber) {

  var telnum;
  // Convert into a string and check that we were provided with a number
  telnum = telephoneNumber + " ";
  if (telnum.length == 1)  {
     telNumberErrorNo = 1;
     return false;
  }
  telnum.length = telnum.length - 1;
  
  // Don't allow country codes to be included (assumes a leading "+")
  exp = /^(\+)[\s]*(.*)$/;
  if (exp.test(telnum) == true) {
     telNumberErrorNo = 2;
     return false;
  }
  
  // Remove spaces from the telephone number to help validation
  while (telnum.indexOf(" ")!= -1)  {
    telnum = telnum.slice (0,telnum.indexOf(" ")) + telnum.slice (telnum.indexOf(" ")+1)
  }
  
  // Remove hyphens from the telephone number to help validation
  while (telnum.indexOf("-")!= -1)  {
    telnum = telnum.slice (0,telnum.indexOf("-")) + telnum.slice (telnum.indexOf("-")+1)
  }  
  
  // Now check that all the characters are digits
  exp = /^[0-9]{10,11}$/
  if (exp.test(telnum) != true) {
     telNumberErrorNo = 3;
     return false;
  }
  
  // Now check that the first digit is 0
  exp = /^0[0-9]{9,10}$/
  if (exp.test(telnum) != true) {
     telNumberErrorNo = 4;
     return false;
  }
  
  // Now check that the telephone number is appropriate.
  exp = /^(01|02|05|070|077|078|079)[0-9]+$/;
  if (exp.test(telnum) != true) {
     telNumberErrorNo = 5;
     return false;
  }
  
  // Seems to be valid - return the stripped telehone number
  
  return telnum;
}
var telNumberErrorNo = 0;
telNumberErrors = new Array (0);
telNumberErrors[0] = "Valid UK telephone number";
telNumberErrors[1] = "Telephone number not provided";
telNumberErrors[2] = "UK telephone number without the country code, please";
telNumberErrors[3] = "UK telephone numbers should contain 10 or 11 digits";
telNumberErrors[4] = "The telephone number should start with a 0";
telNumberErrors[5] = "The telephone number is either invalid or inappropriate";