
var error="";
e_regex = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,})+$/;

function Checkit(theform) {
	
	if(theform.yourname.value=="") {
		error+="You did not enter your name\n";
	}
	
	if(theform.youremail.value=="") {
		error+="You did not enter your email\n";
	} else if(!e_regex.test(theform.youremail.value)) {
		error+="Invalid email address\n";
	}
	
	if(theform.yoursubject.value=="") {
		error+="You did not enter your subject\n";
	}
		
	if(theform.yourmessage.value=="") {
		error+="You did not enter your message\n";
	}
	
	if(error) {
		alert('**The form returned the following errors:**\n\n' + error);
		error="";
		return false;
	} else {
		return true;
	}
}

function AppCheckit(theform) {

	if(theform.loanamount.value=="") {
		error+="You did not enter your loan amount required\n";
	}
	
	if(theform.yourname.value=="") {
		error+="You did not enter your full name\n";
	}
	
	if(theform.yourdob.value=="") {
		error+="You did not enter your date of birth\n";
	}
	
	if(theform.yourstatus.value=="") {
		error+="You did not enter your marital status\n";
	}
	
	if(theform.yourcontact.value=="") {
		error+="You did not enter your contact preference\n";
	}
	
	if(theform.youremail.value=="") {
		error+="You did not enter your email\n";
	} else if(!e_regex.test(theform.youremail.value)) {
		error+="Invalid email address\n";
	}

	if(theform.yourphone.value=="") {
		error+="You did not enter your phone number\n";
	}
	
	if(theform.youraddress1.value=="") {
		error+="You did not enter your address\n";
	}
	
	if(theform.yourpostcode1.value=="") {
		error+="You did not enter your postcode\n";
	}
	
	if(theform.occupancy1.value=="" && theform.occupancy1y.value=="") {
		error+="You did not enter your length of occupancy, in months / years\n";
	}
	
	if(theform.homeowner[0].checked == false && theform.homeowner[1].checked == false ) {
		error+="You did not enter if you are a homeowner or tenant\n";
	}
	
	if(theform.personalcredit[0].checked == false && theform.personalcredit[1].checked == false ) {
		error+="You did not enter if you have any other personal credit\n";
	}
	
	if (theform.creditrepay1.value && theform.creditcomp1rep[0].checked == false && theform.creditcomp1rep[1].checked == false ) {
		error+="You did not enter a credit repayment pw or pm\n";
	} else if (theform.creditrepay2.value && theform.creditcomp2rep[0].checked == false && theform.creditcomp2rep[1].checked == false ) {
		error+="You did not enter a credit repayment pw or pm\n";
	} else if (theform.creditrepay3.value && theform.creditcomp3rep[0].checked == false && theform.creditcomp3rep[1].checked == false ) {
		error+="You did not enter a credit repayment pw or pm\n";
	}
	
	//if(theform.authorisation.value!="Yes") {
	//	error+="You must give your authorisation for a representative to call at your home address\n";
	//}
	
	if(theform.terms.value!="Yes") {
		error+="You must confirm that you have read and understood the terms of the application form\n";
	}
	
	if(error) {
		alert('**The form returned the following errors:**\n\n' + error);
		error="";
		return false;
	} else {
		return true;
	}
}


function toggleBox(szDivID, iState) // 1 visible, 0 hidden
{
   var obj = document.layers ? document.layers[szDivID] :
   document.getElementById ?  document.getElementById(szDivID).style :
   document.all[szDivID].style;
   obj.display = document.layers ? (iState ? "show" : "hide") :
   (iState ? "block" : "none");
}
