function chkgen() {
	df=document.form;
	
	if (df.Forename.value.length<1) {alert("Please enter a name");return false;}
	if (df.Surname.value.length<3) {alert("Please enter a name");return false;}
	if (df.Email.value!=document.form.Email2.value) {alert("Email address and confirmation aren't the same");return false;}
	em=df.Email.value;
	atpos=em.indexOf('@');
	dotpos=em.lastIndexOf('.');
	
	ph=df.Phone.value;
	while (ph.indexOf(' ')>-1){
		ix=ph.indexOf(' ')
		ph=ph.substring(0,ix)+ph.substr(ix+1);
	}
	if (ph.length<1){alert("Please enter a phone number.");return false;}
	if (ph.length<10){alert("Phone number is incorrect.");return false;}
	for (i=0;i<ph.length;i++){
		pc=ph.charCodeAt(i);
		if (pc<48 || pc>59){alert("Phone number is incorrect");return false;}
	}
	
	if (em.length<1){retsts=alert("Please enter an email address");return false;}
	else if (em.length<5||atpos<1||dotpos<atpos+2) {
		retsts=confirm("Email address doesn't look right - press CANCEL to correct\n or OK if you're sure about '"+em+"'");
		if (!retsts)return false;
	}
	
	if (df.address1.value.length<1){alert("Please enter your address");return false;}
	if (df.Postcode.value.length<5){alert("Please enter your postcode");return false;}
	if (!chkpcd())return false;
	return true;
}

var pcd;
pcs=" AB AL B BA BB BD BH BL BN BR BS BT CA CB CF CH CM CO CR CT CV CW DA DD DE DG DH DL DN DT ";
pcs+=" DY E EC EH EN EX FK FY G GL GU HA HD HG HP HR HS HU HX IG IP IV KA KT KW KY L LA LD LE LL ";
pcs+=" LN LS LU M ME MK ML N NE NG NN NP NR NW OL OX PA PE PH PL PO PR RG RH RM S SA SE SG SK SL ";
pcs+=" SM SN SO SP SR SS ST SW SY TA TD TF TN TQ TR TS TW UB W WA WC WD WF WN WR WS WV YO ZE ";

function isalpha(nm){
	c=pcd.charCodeAt(nm);
	if (c>64 && c<91) return true; else return false;
}

function isnum(nm){
	c=pcd.charCodeAt(nm);
	if (c>47 && c<58) return true; else return false;
}

function chkpcd(){
	df=document.form;
	pcd=df.Postcode.value.toUpperCase();
	while (pcd.indexOf(' ')>-1){
		ix=pcd.indexOf(' ')
		pcd=pcd.substring(0,ix)+pcd.substr(ix+1);
	}
	pat="";
	for(i=0;i<pcd.length;i++){
		if(isnum(i))pat+="9";
		else if(isalpha(i))pat+="A";
		else pat+="!"
	}
	if(pat.charAt(1)=="9")tn=pcd.charAt(0);
	else tn=pcd.substr(0,2);
	tn=" "+tn+" ";
	if (pcs.indexOf(tn)<0) pok=false;
	else {
		pok=false;
		if(pat=="A99AA"||pat=="A999AA")pok=(" B E G L M N S W ".indexOf(tn)>-1);
		else if(pat=="AA99AA"||pat=="AA999AA")pok=true;
		else if(pat=="A9A9AA")pok=(" W E N ".indexOf(tn)>-1);
		else if(pat=="AA9A9AA")pok=(" EC WC NW SE SW ".indexOf(tn)>-1);
	}
	
	if (!pok) {alert("Postcode is incorrect");return false;}
	df.Postcode.value=pcd.substr(0,pcd.length-3)+" "+pcd.substr(pcd.length-3);
	return true;
}
