// 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 findAddress()	{
		id = new Date().getTime();
		eval("page" + id + " = window.open('address_finder.php?postcode=' + document.getElementById('postcode').value, '" + id + "', 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0,width=520,height=400');");
	}
	
	function initFields(){
		var startYear=1930;
		document.erForm.dbday.length=32;
		document.erForm.dbmonth.length=13;
		document.erForm.dbyear.length=36;
		setDaysList(31);

		for (i=0;i<12;i++){
			document.erForm.dbmonth.options[i+1].text=monthInYear[i];
			document.erForm.dbmonth.options[i+1].value=i+1;
		}
		for (i=0;i<document.erForm.dbyear.length-1;i++){
			document.erForm.dbyear.options[i+1].text=2008-55-i;			
		}
	}
	
	function changeDaysInMonth(){
		var list=document.erForm.dbmonth;
		var selectedMonth=list.options[list.selectedIndex-1].value;
		setDaysList(daysInMonth[selectedMonth]);
	}
	
	function setDaysList(maxDays){
		document.erForm.dbday.length=maxDays+1;
		
		for (i=0;i<maxDays;i++){
			document.erForm.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.erForm.dbyear;
		var selectedYear=list.options[list.selectedIndex].text;
		list=document.erForm.dbmonth;
		var selectedMonth=list.options[list.selectedIndex].text;
		list=document.erForm.dbday;
		var selectedDay=list.options[list.selectedIndex].text;

		if (document.erForm.firstname.value == ""){
			document.erForm.firstname.style.backgroundColor="pink";
			var warningText="Please enter your first name";
			alert(warningText);
			document.erForm.firstname.focus();
			return false;
		}else{
			document.erForm.firstname.style.backgroundColor="";
		}

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

		if ((document.erForm.telephone.value == "") && (document.erForm.email.value == '')){
			document.erForm.telephone.style.backgroundColor="pink";
			var warningText="Please enter either your telephone number or email address";
			alert(warningText);
			document.erForm.telephone.focus();
			return false;		
		}else{
			document.erForm.telephone.style.backgroundColor="";			
		}

		if (document.erForm.email.value == '') {
		} else {
			if (!(/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(document.erForm.email.value))) {
				document.erForm.email.style.backgroundColor="pink";
				var warningText="Please enter a valid email";
				alert(warningText);
				document.erForm.email.focus();
				return false;
			}else{
				document.erForm.email.style.backgroundColor="";
			}
		}
		
		if (selectedDay =="dd"){
			var warningText="Please enter your correct day of birth";
			alert(warningText);
			document.erForm.dbday.focus();
			return false;
		}

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

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

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

		if (document.erForm.town.value == ""){
			document.erForm.town.style.backgroundColor="pink";
			var warningText="Please enter your town";
			alert(warningText);
			document.erForm.town.focus();
			return false;
		}else{
			document.erForm.town.style.backgroundColor="";
		}

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

		if (document.erForm.agreeTerms.checked != true) {
			var warningText="Have you read the points to consider page? If you already have and would like to proceed, please tick the box.";
			alert(warningText);
			document.erForm.agreeTerms.focus();
			return false;
		}

		return true;
	}

