// JavaScript Document
	var	daysInMonth=new Array(31,29,31,30,31,30,31,31,30,31,30,31);
	var	monthInYear=new Array("January","February","March","April","May","June","July","August","September","October","November","December");

	function initFields(){
		var startYear=1930;
		document.prForm.dbday.length=32;
		document.prForm.dbmonth.length=13;
		document.prForm.dbyear.length=10;
		setDaysList(31);

		for (i=0;i<12;i++){
			document.prForm.dbmonth.options[i+1].text=monthInYear[i];
			document.prForm.dbmonth.options[i+1].value=i+1;
		}
		for (i=0;i<document.prForm.dbyear.length-1;i++){
			document.prForm.dbyear.options[i+1].text=2009-54-i;			
		}
	}
	
	function changeDaysInMonth(){
		var list=document.prForm.dbmonth;
		var selectedMonth=list.options[list.selectedIndex-1].value;
		setDaysList(daysInMonth[selectedMonth]);
	}
	
	function setDaysList(maxDays){
		document.prForm.dbday.length=maxDays+1;
		
		for (i=0;i<maxDays;i++){
			document.prForm.dbday.options[i+1].text=i+1;
		}
	}
	
	function isEmail(emailAddress) {
		var re = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/
		return re.test(emailAddress);
	}

	function checkForm(){
		var list=document.prForm.dbyear;
		var selectedYear=list.options[list.selectedIndex].text;
		list=document.prForm.dbmonth;
		var selectedMonth=list.options[list.selectedIndex].text;
		list=document.prForm.dbday;
		var selectedDay=list.options[list.selectedIndex].text;
		
		var warningDiv=document.getElementById("warning");
		var fChild=warningDiv.firstChild;
		warningDiv.style.display="block";
		warningDiv.removeChild(fChild);
		
		if (document.prForm.firstname.value == ""){
			document.prForm.firstname.style.backgroundColor="pink";
			var warningText=document.createTextNode("Please enter your first name");
			warningDiv.appendChild(warningText);
			document.prForm.firstname.focus();
			return false;
		}else{
			document.prForm.firstname.style.backgroundColor="";
		}

		if (document.prForm.surname.value == ""){
			document.prForm.surname.style.backgroundColor="pink";
			var warningText=document.createTextNode("Please enter your surname");
			warningDiv.appendChild(warningText);
			document.prForm.surname.focus();
			return false;
		}else{
			document.prForm.surname.style.backgroundColor="";
		}

		if (document.prForm.email.value == '') {
			/*document.prForm.email.style.backgroundColor="pink";
			var warningText=document.createTextNode("Please enter your email");
			warningDiv.appendChild(warningText);
			document.prForm.email.focus();
			return false;*/
			document.prForm.email.style.backgroundColor="";
		} else {
			if (!(/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(document.prForm.email.value))) {
				document.prForm.email.style.backgroundColor="pink";
				var warningText=document.createTextNode("Please enter a valid email");
				warningDiv.appendChild(warningText);
				document.prForm.email.focus();
				return false;
			}else{
				document.prForm.email.style.backgroundColor="";
			}
		}
		
		if (document.prForm.telephone.value == ""){
			document.prForm.telephone.style.backgroundColor="pink";
			var warningText=document.createTextNode("Please enter your telephone");
			warningDiv.appendChild(warningText);
			document.prForm.telephone.focus();
			return false;
		}else{
			document.prForm.telephone.style.backgroundColor="";
		}

		if (selectedDay =="dd"){
			var warningText=document.createTextNode("Please enter your correct day of birth");
			warningDiv.appendChild(warningText);
			document.prForm.dbday.focus();
			return false;
		}

		if (selectedMonth =="mm"){
			var warningText=document.createTextNode("Please enter your correct month of birth");
			warningDiv.appendChild(warningText);
			document.prForm.dbmonth.focus();
			return false;
		}

		if (selectedYear =="yyyy"){
			var warningText=document.createTextNode("Please enter your correct year of birth");
			warningDiv.appendChild(warningText);
			document.prForm.dbyear.focus();
			return false;
		}

		if (document.prForm.postcode.value == ""){
			document.prForm.postcode.style.backgroundColor="pink";
			var warningText=document.createTextNode("Please enter your postcode");
			warningDiv.appendChild(warningText);
			document.prForm.postcode.focus();
			return false;
		}else{
			document.prForm.postcode.style.backgroundColor="";
		}

		if (document.prForm.address1.value == ""){
			document.prForm.address1.style.backgroundColor="pink";
			var warningText=document.createTextNode("Please enter your address");
			warningDiv.appendChild(warningText);
			document.prForm.address1.focus();
			return false;
		}else{
			document.prForm.address1.style.backgroundColor="";
		}

		if (document.prForm.town.value == ""){
			document.prForm.town.style.backgroundColor="pink";
			var warningText=document.createTextNode("Please enter your town");
			warningDiv.appendChild(warningText);
			document.prForm.town.focus();
			return false;
		}else{
			document.prForm.town.style.backgroundColor="";
		}
	
		if (document.prForm.county.value == ""){
			document.prForm.county.style.backgroundColor="pink";
			var warningText=document.createTextNode("Please enter your county");
			warningDiv.appendChild(warningText);
			document.prForm.county.focus();
			return false;
		}else{
			document.prForm.county.style.backgroundColor="";
		}

		warningDiv.style.display="none";
		return true;
	}
