var fields=new Array();
var names=new Array();
fields['0']='login';
names['0']='Login Name';
fields['1']='firstname';
names['1']='Forename';
fields['2']='surname';
names['2']='Surname';
fields['3']='email';
names['3']='Email Address';
fields['4']='landline';
names['4']='Phone (Landline)';
fields['5']='addr1';
names['5']='Address line 1';
fields['6']='town';
names['6']='Town/City';
fields['7']='county';
names['7']='County/State';
fields['8']='postcode';
names['8']='Post Code';
fields['9']='nok';
names['9']='Emergency Contact name';
fields['10']='noktel';
names['10']='Emergency Contact Phone';
fields['11']='dob';
names['11']='Date of Birth';
fields['12']='gender';
names['12']='Gender';
fields['13']='password';
names['13']='Choose Password';
fields['14']='passwordc';
names['14']='Confirm Password';
	
	function checkreg(checkpw) {
	
		if(checkpw) {
			pw1=document.getElementById('password');
			pw2=document.getElementById('passwordc');
			if(!pw1 || !pw2) {
				alert("Corrupt form");
				return false;
			}
	
			if(pw1.value!=pw2.value) {
				alert("Your passwords do not match");
				return false;
			}
		}

		var flength=fields.length;
		for(i=0; i<flength; i++) {
		//>
			if(fields[i].indexOf("dob")!=-1) {
				var res=check_dob();
				if(!res) return false;
				continue;
			}
			if(fields[i]=="gender") {	
				check=document.getElementById('regform');
				if(!check) continue;
				ok=0;
				for(j=0; j < check.gender.length; j++) {
					if(check.gender[j].checked) ok++;
				}
				if(!ok) {
					alert("Please fill in the " + names[i] + " field")
					return false;
				}
				else continue;
			}
			check=document.getElementById(fields[i]);
			if(!check.id) continue;
			//alert("checking for " + fields[i] + " found " + check.id + ": "+check.value.length);
			
			
			if(check.value.length<2) {
				alert("Please fill in the " + names[i] + " field")
				return false;
			}
		
		}
		document.forms[1].submit();
		return false;
	}
	
	function check_dob() {
		var cday=document.getElementById('dob_d');
		var cmonth=document.getElementById('dob_m');
		var cyear=document.getElementById('dob_y');
		
		if(cday[cday.selectedIndex].value==0 || cmonth[cmonth.selectedIndex].value==0 || cyear[cyear.selectedIndex].value==0) {
			alert("Please enter your Date of Birth");
			return false;
		}
		return true;
	}
	
	function checkpw() {
		var currentid=document.getElementById('current');
		var newpwid=document.getElementById('new');
		var confirmpwid=document.getElementById('confirm');
		if(!currentid || !newpwid || !confirmpwid) {
			alert("This form is corrupt");
			return false;
		}
		
		current=currentid.value;
		newpw=newpwid.value;
		confirmpw=confirmpwid.value;
		if(!current.length) {
			alert("You must enter your current password");
			return false;
		}
		
		if(!newpw.length) {
			alert("You must enter a new password");
			return false;
		}
		
		if(newpw != confirmpw) {
			alert("Those passwords do not match");
			return false;
		}
	
	}
