function check_form(theForm){

if (theForm.firstname.value==""){
alert("Please enter your first name");
theForm.firstname.focus();
return false;
}

if (theForm.surname.value==""){
alert("Please enter your surname");
theForm.surname.focus();
return false;
}

var x = theForm.email.value;
var filter  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
if (filter.test(x) !=true){
alert("Please enter a valid email address");
theForm.email.focus();
return false;
}

if (theForm.telnumber.value==""){
alert("Please enter your telephone number");
theForm.telnumber.focus();
return false;
}

var url = theForm.action;

var propref = theForm.propertyref.value;
var comment = theForm.comment.value;

var message="Website Enquiry\n";
message+="Lead generated: The Serious Business Group (http://seriousgroup.co.uk) \n\n";
message+="Name: "+theForm.firstname.value+"\n";
message+="Email: "+theForm.email.value+"\n";
message+="Telephone: "+theForm.telnumber.value+"\n";
message+="Comments: "+comment+"\n\n\n";

 $.ajax({
   type: "POST",
   url: url,
   data:  { propertyref:propref, message: message },
   dataType: "script"
   });
//reset values
theForm.firstname.value="";
theForm.surname.value="";
theForm.email.value="";
theForm.telnumber.value="";
theForm.comment.value="";

	return false;
}

////////////////////////////////////////////////////////////////////////////////////////////////////////////////

function checkBillingForm(theForm) {

//check card details

if (theForm.cardname.value==""){
	alert("Please enter the cardholder's name");
	theForm.cardname.focus();
	return false;
}
if (theForm.cardnumber.value==""){
	alert("Please enter a card number.");
	theForm.cardnumber.focus();
	return false;
}
if((theForm.cardtype.value=="AMEX") && (theForm.cardnumber.value.length!=15)){
	alert('American Express card numbers are 15 digits long.');
	theForm.cardnumber.focus();
	return false;
}
if((theForm.cardtype.value=="VISA") && (theForm.cardnumber.value.length!=16)){
	alert('Visa card numbers are 16 digits long.');
	theForm.cardnumber.focus();
	return false;
}
if((theForm.cardtype.value=="Mastercard") && (theForm.cardnumber.value.length!=16)){
	alert('Mastercard numbers are 16 digits long.');
	theForm.cardnumber.focus();
	return false;
}
if((theForm.cardtype.value=="Solo") && (theForm.cardnumber.value.length!=16)){
	alert('Solo card numbers are 16 digits long.');
	theForm.cardnumber.focus();
	return false;
}
if((theForm.cardtype.value=="Maestro") && (theForm.cardnumber.value.length!=18)){
	alert('Maestro card numbers are 18 digits long.');
	theForm.cardnumber.focus();
	return false;
}

// expiry and start date checks.

var expyear = theForm.expyear.value;
var expmonth = theForm.expmon.value;
var startyear = theForm.startyear.value;
var startmonth = theForm.startmon.value;
var d = new Date();
var curryear = d.getFullYear(); // 2009
var currmonth = d.getMonth(); // Will return 5 (i.e. June)

// "expiry date" checking.

if(expyear<curryear){
	alert("Expiry date cannot be in the past.");
	return false;
}
if((expmonth<currmonth) && (expyear==curryear)){
	alert("Expiry date cannot be in the past.");
	return false;
}

// "start date" checking.

// check for a partially filled in start date

if( (startyear=='') && (startmonth!='') ){
	alert('You have not chosen a start date year.');
	return false;
}
if ( (startmonth=='') && (startyear!='') ) {
	alert('You have not chosen a start date month.');
	return false;
}

if((startmonth!='') && (startyear!='')){

	if(startyear>curryear){ // if the start date year is after this year
		alert("Start date cannot be in the future.");
		return false;
	}
	if(startyear==curryear){ // if the start date year is this year
		if(startmonth>currmonth){ // if the start date month is after this month
			alert("Start date cannot be in the future.");
			return false;
		}
	}
}

if(theForm.cvv.value==""){
	alert('CVV number is required.');
	theForm.cvv.focus();
	return false;
}
if((theForm.cardtype.value!="AMEX") && (theForm.cvv.value.length!=3)){
	alert('CVV numbers for this type of card are 3 digits long.');
	theForm.cvv.focus();
	return false;
}
if((theForm.cardtype.value=="AMEX") && (theForm.cvv.value.length!=4)){
	alert('CVV numbers for this type of card are 4 digits long.');
	theForm.cvv.focus();
	return false;
}

if((theForm.cardtype.value=="Maestro") && (theForm.issue.value=="")){
	alert('Issue numbers are required for Maestro cards.');
	theForm.issue.focus();
	return false;
}
	
//check personal details

if(theForm.namenum.value==""){
	alert('Please enter a house name or number.');
	theForm.namenum.focus();
	return false;
}
if(theForm.street.value==""){
	alert("Please enter your street name.");
	theForm.street.focus();
	return false;
}
if(theForm.city.value==""){
	alert('Please enter your city.');
	theForm.city.focus();
	return false;
}
if(theForm.zip.value==""){
	alert('Please enter your zip/postal code.');
	theForm.zip.focus();
	return false;
}
if(theForm.phone.value==""){
	alert("Please enter your primary telephone number");
	theForm.phone.focus();
	return false;
}
var x = theForm.email.value;
var filter  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
if (filter.test(x) !=true){
	alert("Please enter a valid email address");
	theForm.email.focus();
	return false;
}
if(theForm.emailconfirm.value==""){
	alert('Please confirm your e-mail address.');
	theForm.emailconfirm.focus();
	return false;
}
if(theForm.emailconfirm.value!=theForm.email.value){
	alert('The e-mail addresses do not match.')
	theForm.emailconfirm.focus();
	return false;	
}

/*
if(theForm.password.value==""){
	alert("Please enter a password.");
	theForm.password.focus();
	return false;
}
if(theForm.password.value.length<6){
	alert("Your password must be at least 6 digits long.");
	theForm.password.focus();
	return false;
}
*/
	var fullname = theForm.cardname.value;
	var email = theForm.email.value;
	var formattedexpiry =( parseInt(theForm.expmon.value) + 1);
	var formattedstart =( parseInt(theForm.startmon.value) + 1 );
	var orderedproducts = theForm.cartcontents.value;

	var message="Personal Details\n\n";
	//message+="Ordered products: "+orderedproducts+"\n\n";
	message+="Name: "+theForm.cardname.value+"\n\n";
	message+="Email: "+theForm.email.value+"\n";
	message+="Telephone: "+theForm.phone.value+"\n";
	
		if(theForm.mobile.value!=""){
			message+="Mobile number: "+theForm.mobile.value+"\n";
		}
	
	message+="Address: "+theForm.namenum.value+", "+theForm.street.value+"\n";
	message+="City: "+theForm.city.value+"\n";
		if(theForm.county.value!=""){
			message+="County: "+theForm.county.value+"\n";
		}
		
	message+="Postal/Zip code: "+theForm.zip.value+"\n";
	message+="Country: "+theForm.country.value+"\n\n\n";
	message+="Credit card information\n\n";
	message+="Card type: "+theForm.cardtype.value+"\n";
	message+="Card number: "+theForm.cardnumber.value+"\n";
	message+="Expiry: "+formattedexpiry+"/"+theForm.expyear.value+"\n";
		if(theForm.startmon.value!=""){
			message+="Start date: "+formattedstart+"/"+theForm.startyear.value+"\n";
		}
	message+="CVV Code: "+theForm.cvv.value+"\n\n";


	return true;

}

////////////////////////////////////////////////////////////////////////////////////////////////////////////////

function check_paymentform(theForm) {

if (theForm.firstname.value==""){
alert("Please enter your first name");
theForm.firstname.focus();
return false;
}

if (theForm.surname.value==""){
alert("Please enter your surname");
theForm.surname.focus();
return false;
}

var x = theForm.email.value;
var filter  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
if (filter.test(x) !=true){
alert("Please enter a valid email address");
theForm.email.focus();
return false;
}


if (theForm.telnumber.value==""){
alert("Please enter your telephone number");
theForm.telnumber.focus();
return false;
}

}

////////////////////////////////////////////////////////////////////////////////////////////////////////////////

function check_contactform(theForm) {

if(theForm.firstname.value==""){
	alert("Please fill in your first name.");
	theForm.firstname.focus();
	return false;
}
if(theForm.surname.value==""){
	alert("Please fill in your surname.");
	theForm.surname.focus();
	return false;
}

var x = theForm.email.value;
var filter  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;

if (filter.test(x) !=true){
	alert("Please enter a valid email address");
	theForm.email.focus();
	return false;
}
if(theForm.phone.value==""){
	alert("Please enter a phone number.");
	theForm.phone.focus();
	return false;
}
if(theForm.message.value==""){
	alert("You have not entered a message.");
	theForm.message.focus();
	return false;
}
var fullname = theForm.firstname.value+" "+theForm.surname.value;
var email = theForm.email.value;
var phone = theForm.phone.value;
var subject = "Domain God contact form";

var message="Name: "+fullname+"\n";
message+="E-mail address: "+email+"\n";
message+="Phone number: "+phone+"\n";
message+="Message: "+theForm.message.value+"\n";

$.ajax({
  type: "POST",
  url: "http://domaingoddev.seriousgroup.co.uk/app/core/php/factory/ajax.php",
  data:  { trigger: "contact", subject: subject, message: message,name: fullname, email: email },
  cache: false,
  success: function(html){
  	alert(html);  
  }
});
		theForm.firstname.value="";
		theForm.surname.value="";
		theForm.email.value="";
		theForm.phone.value="";
		theForm.message.value="";

	return false;

}

////////////////////////////////////////////////////////////////////////////////////////////////////////////////
