// JavaScript Document
	function initFields(){
		var startYear=1925;
		document.calculator.age.length=2009-startYear-55;

		for (i=0;i<document.calculator.age.length;i++){
			document.calculator.age.options[i+1].text=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 checkForm(){
		var list=document.calculator.age;
		var selectedAge=list.options[list.selectedIndex].text*1.0;
		var propertyValue=document.calculator.propertyValue.value*1.0;
		var name=document.calculator.name.value;
		var phone=document.calculator.phone.value;
		var email=document.calculator.email.value;

		if (name==""){
			var warningText="Please enter a valid name";
			alert(warningText);
			document.calculator.name.focus();
			return false;
		}

		if ((email=="") && (phone=="")){
			var warningText="Please enter a valid phone number or email address";
			alert(warningText);
			document.calculator.phone.focus();
			return false;
		}

		if ((selectedAge>=55) && (selectedAge<=85)){
			var minPropertyValue=70000;
			var maxLoanValue=(selectedAge-55)+21.5;
			maxLoanValue=maxLoanValue/100;
		}else{
			var warningText="Please enter a valid age";
			alert(warningText);
			document.calculator.age.focus();
			return false;
		}
		
		if (propertyValue>=70000){
			propertyValue=Math.round(propertyValue);
			document.calculator.mType.value="lifetime";
			var rValue=propertyValue*maxLoanValue;
			rValue=Math.round(rValue);
			document.calculator.rValue.value=rValue;
		}else{
			var warningText="To release equity, you require a minimum property value of £70000";
			alert(warningText);
			document.calculator.propertyValue.focus();
			return false;		
		}
		if (document.calculator.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.calculator.agreeTerms.focus();
			return false;
		}else{
			return true;
		}
		return false;
		
	}
