function user_account_validate()
{

var title = document.getElementById('title').value;
var email1 = document.getElementById('email1').value;
var email2 = document.getElementById('email2').value;
var title = document.getElementById('title').value;
var firstname = document.getElementById('firstname').value;
var lastname = document.getElementById('lastname').value;
var phone_invoice = document.getElementById('phone_invoice').value;
var address1 = document.getElementById('address1').value;
var town = document.getElementById('town').value;
var county = document.getElementById('county').value;
var postcode = document.getElementById('postcode').value;


var emailRegExp = /^([\w]+)(.[\w]+)*@([\w]+)(.[\w]{2,3}){1,2}$/;
var firstnameRegExp = /^([a-zA-Z]+)$/;
var lastnameRegExp = /^([a-zA-Z]+)$/;
var phoneRegExp = /^([0-9]{11})$/;
var pcodeRegExp = /^([A-Za-z]{1,2})([0-9]{1,2})([\s]{0,1})([0-9]{1})([A-Za-z]{2})$/;

var message = 'You have not filled in the form correctly:';
var valid = 'true';
var Focus = '';



	if(title == 'ignore')
	{

		message=message+'\n please enter a title'
		valid = false;
		Focus = 'title';
	}

/**********

	NAME CHECKING

	checks that the firstname and surname fields have been filled in
	checks that both fields only contain characters

***********/

	if(firstname != '')
	{
		if(firstnameRegExp.test(firstname) != true)
		{
			message=message+'\n firstname must contain characters only'
			valid = false;
			Focus = 'firstname';
		}
	}
	else
	{
		message=message+'\n please enter your firstname'
		valid = false;
		Focus = 'firstname';
	}
	
	if(lastname != '')
	{
		if(lastnameRegExp.test(lastname) != true)
		{
			message=message+'\n lastname must contain characters only'
			valid = false;
			Focus = 'lastname';
		}
	}
	else
	{
		message=message+'\n please enter your lastname'
		valid = false;
		Focus = 'lastname';
	}



/**********

	Phone number checking

	performs the following checks
	1. firstly that the user has entered a phone number
	2. that the phone number is of the correct format (i.e 11 digits long)

***********/

	if(phone_invoice != '')
	{
		if(phoneRegExp.test(phone_invoice) != true)
		{
			message = message+'\n invalid phone number'
			valid = false;
			Focus = 'phone_evening';
		}
	}
	else
	{
		message = message+'\n please enter a phone number'
		valid = false;
		Focus = 'phone_evening';
	}


/********

	EMAIL CHECKING

*********/

	//if null
	if(email1 == '' || email2 =='')
	{
		message = message+'\n please complete both email fields'
		valid = false;
		Focus = 'email1';
	}	

	else if (emailRegExp.test(email1) != true || emailRegExp.test(email2) != true)
	{
		message = message+'\n Please enter a valid email address';
		valid = false;
		Focus = 'email';
	}
	
	if(email1 != email2)
	{
		message = message+'\n Email addresses do not match'
		valid = false;
		Focus = 'email1';
	}


/********

	ADDRESS CHECKING

*********/

	//if null
	if(address1 == '')
	{
		message = message+'\n please complete the address field(s)'
		valid = false;
		Focus = 'address1';
	}	

	if(town == '')
	{
		message = message+'\n please enter a town'
		valid = false;
		Focus = 'town';
	}
	
	if(county == '')
	{
		message = message+'\n please enter a county'
		valid = false;
		Focus = 'county';
	}

	if(postcode != '')
	{
	
		if(pcodeRegExp.test(postcode) != true)
		{
			message = message+'\n invalid UK postcode'
			valid = false;
			Focus = 'postcode';
		}
	}
	else
	{
		message = message+'\n please enter a valid UK postcode'
		valid = false;
		Focus = 'postcode';
		
		
	}	

//if an error with the input has been identified print error

	if(valid == false)
	{
		alert(message);
		//signupform.Focus.select();
		
		return false;
		
	}
	else
	{
		return true;
	}

}

function submitform(myform)
{
  myform.submit();
}

function card_validator(form)
{ 

	var letter = /^[a-zA-Z\s]+$/;
	var today = new Date();
	var start_date = new Date(form.CCVYear.options[form.CCVYear.selectedIndex].value, form.CCVMonth.options[form.CCVMonth.selectedIndex].value-1);
	var expiry_date = new Date(form.CCEYear.options[form.CCEYear.selectedIndex].value, form.CCEMonth.options[form.CCEMonth.selectedIndex].value);
	var CCNum = form.CCNum.value;
	
	//Card number 
	var CCNum = CCNum.replace(/ /g, "");
	var msg = 'The credit card number you entered could not be\n validated. Please check the number and try again.';
	
	//########## Get the card type ########## 
	for (var i=0; i<form.CCType.length; i++)
	{ 
		if (form.CCType.options[i].selected)
		{ 
			var CCType=form.CCType.options[i].value; 
		} 
	} 
	
	//########## Check Dates & Name ##########
	if(start_date > today)
	{ 
		alert('Your credit card is not yet valid!');
		form.CCVYear.focus();
		return false; 
	} 
	
	if(expiry_date < today)
	{ 
		alert('Your credit card has expired!'); 
		form.CCEYear.focus(); 
		return false; 
	} 
	
	if (!letter.test(form.CCName.value))
	{ 
		window.alert("The name as it appears on the credit card is required.");
		form.CCName.focus();
		return false;
	} 
	
	//########## Check Visa ########## 
	if(CCType.indexOf('Visa') !=-1)
	{ 
		if ((CCNum.length == 13 || CCNum.length == 16) && (CCNum.substring(0,1) == 4))
		{ 
			return true 
		} 
		else
		{ 
			alert(msg); 
			form.CCNum.focus(); 
			return false; 
		} 
	} 
	
	//########## Check Delta ########## 
	if(CCType.indexOf('Delta') !=-1)
	{ 
		if ((CCNum.length==16) && (CCNum.match(/^(413733|413734|413735|413736|413737|4462|453978|453979|454313|454313|454432|454433|454434|454435|454742|456725|456726|456727|456728|456729|45673|456740|456741|456742|456743|456744|456745|46583|46584|46585|46586|46587|484409|484410|49096|49097|492181|492182|498824)/)))
		{ 
			return true 
		}
		else
		{ 
			alert(msg); 
			form.CCNum.focus(); 
			return false; 
		} 
	} 
	
	//########## Check Solo ########## 
	if(CCType.indexOf('Solo') !=-1)
	{ 
		if ((CCNum.length==16 || CCNum.length==18 || CCNum.length==19) && (CCNum.match(/63345|63346|63347|63348|63349|6767/)))
		{ 
			return true 
		} 
		else
		{ 
			alert(msg); 
			form.CCNum.focus(); 
			return false; 
		}
	} 
	
	//########## Check Mastercard ########## 
	if(CCType.indexOf('Mastercard') !=-1)
	{ 
		var firstdig=CCNum.substring(0,1);
		var seconddig=CCNum.substring(1,2);
		
		if ((CCNum.length == 16 || CCNum.length == 19) && (firstdig == 5) && ((seconddig >= 1) && (seconddig <= 5)))
		{ 	
			return true 
		} 
		else
		{ 
			alert(msg);
			form.CCNum.focus();
			return false;
		} 
	} 
	
	//########## Check Diners ########## 
	if(CCType.indexOf('Diners') !=-1)
	{ 
		firstdig = CCNum.substring(0,1);
		seconddig = CCNum.substring(1,2); 
		
		if ((CCNum.length == 14 || CCNum.length == 17) && (firstdig == 3) && ((seconddig == 0) || (seconddig == 6) || (seconddig == 8)))
		{ 
			return true 
		} 
		else
		{ 
			alert(msg); 
			form.CCNum.focus(); 
			return false; 
		}
	} 
	
	//########## Check Amex ########## 
	if(CCType.indexOf('Amex') !=-1)
	{ 
		firstdig = CCNum.substring(0,1); 
		seconddig = CCNum.substring(1,2); 
		
		if (((CCNum.length == 15) || (CCNum.length == 18)) && (firstdig == 3) && ((seconddig == 4) || (seconddig == 7)))
		{ 	
			return true 
		} 
		else
		{ 
			alert(msg); 
			form.CCNum.focus(); 
			return false; 
		} 
	} 
	
	//########## Check Switch ########## 
	if(CCType.indexOf('Switch') !=-1)
	{ 
		if ((CCNum.length==16) && (CCNum.match(/^(491101|491102|564182|633300|633302|633303|633304|633305|633306|633307|633308|633309|633310|633311|633312|633313|633314|633315|633316|633317|633318|633319|633320|633321|633322|633323|633324|633325|633326|633327|633328|633329|633330|633331|633332|633333|633334|633335|633336|633337|633338|633339|633340|633341|633342|633343|633344|633345|633346|633347|633348|633349|675900|675902|675903|675904|675906|675907|675908|675909|675910|675911|675912|675913|675914|675915|675916|675917|675919|675920|675921|675922|675923|675924|675925|675926|675927|675928|675929|675930|675931|675932|675933|675934|675935|675936|675937|675941|675942|675943|675944|675945|675946|675947|675948|675949|675963|675964|675965|675966|675967|675968|675969|675970|675971|675972|675973|675974|675975|675976|675977|675978|675979|675980|675981|675982|675983|675984|675985|675986|675987|675988|675989|675990|675991|675992|675993|675994|675995|675996|675997|675999)/))|| (CCNum.length==18) && (CCNum.match(/^(675938|675939|675940|490302|490303|490304|490305|490306|490307|490308|490309|490335|490336|490337|490338|490339|491174|491175|491176|491177|491178|491179|491180|491181|491182)/))|| (CCNum.length==19) && (CCNum.match(/^(4936|633301|675901|675905|675918|675950|675951|675952|675953|675954|675955|675956|675957|675958|675959|675960|675961|675962|675998)/)))
		{ 
			return true 
		} 
		else
		{ 
			alert(msg); 
			form.CCNum.focus(); 
			return false; 
		} 
	} 
	
	//########## Check JCB ########## 
	if(CCType.indexOf('jcb') !=-1)
	{ 
		if ((CCNum.length==16) && (CCNum.match(/^(3088|3096|3112|3158|3337|3528)/)))
		{ 
			return true 
		} 
		else
		{ 
			alert(msg); 
			form.CCNum.focus(); 
			return false; 
		}
	} 
	
	//########## Check Discover ########## 
	if(CCType.indexOf('Discover') !=-1)
	{ 
		var firstfour = CCNum.substring(0, 4); 
		if ((CCNum.length == 16) && (firstfour == 6011))
		{ 
			return true; 
		} 
		else
		{ 
			alert(msg); 
			form.CCNum.focus(); 
			return false; 
		} 
		
	} 
}
