// JavaScript Document


function validation()
{
	var expTelephone = /[^\d|\s]+/;
	var expname=/[^A-Za-z\s\.\'-]+/;
	if(document.frmQuotation.forename.value.replace(/\s/g,'')=="")
	{
		alert("Please provide your first name. \nFor example: John"); 
		document.frmQuotation.forename.value="";
		document.frmQuotation.forename.focus();
		return false;
	}
	if(expname.test(document.frmQuotation.forename.value)==true)
	{
		alert("Please provide your first name.");
		document.frmQuotation.forename.value="";
		document.frmQuotation.forename.focus();
		return false;
	}
	if(document.frmQuotation.surname.value.replace(/\s/g,'')=="")
	{
		alert("Please provide your surname.\nFor example Smith"); 
		document.frmQuotation.surname.value="";
		document.frmQuotation.surname.focus();
		return false;
	}
	if(expname.test(document.frmQuotation.surname.value)==true)
	{
		alert("Please provide your surname.");
		document.frmQuotation.surname.value="";
		document.frmQuotation.surname.focus();
		return false;
	}
	if(document.frmQuotation.email.value.replace(/\s/g,'')=="")
	{
		alert("Please provide your email address.\nFor example, john.smith@safestyle.co.uk");
		document.frmQuotation.email.value="";
		document.frmQuotation.email.focus();
		return false;
	}
   else if(!/^\w+([\.\']?-*\w+)*@\w+([\.-]?\w+)*(\.\w{2,4})+$/.test(document.frmQuotation.email.value))
	{
		alert("Please provide a valid email address.\nFor example, john.smith@safestyle.co.uk");
		document.frmQuotation.email.focus();
		return false;
	} 
	if (document.frmQuotation.postcode.value=='') {
		alert("Please provide your postcode.\nFor example, M1 6HT");
		document.frmQuotation.postcode.focus();
		return false;
	}
	if (document.frmQuotation.dphone.value=='') {
		alert("Please provide your telephone number.\nFor example, 08456 044414");
		document.frmQuotation.dphone.focus();
		return false;
	}
	if (validatephone(document.frmQuotation.dphone.value)==false)
	{
		alert("Phone number must be numeric.");
	    document.frmQuotation.dphone.focus();
		return false;
	}
	if (validatephonelength(document.frmQuotation.dphone.value)==false)
	{
		alert("Please provide a valid UK telephone number.\nFor example, 08456 044414");
	    document.frmQuotation.dphone.focus();
		return false;
	}
	if (document.frmQuotation.ephone.value=='') {
		alert("Please provide your telephone number.\nFor example, 08456 044414");
		document.frmQuotation.ephone.focus();
		return false;
	}
	if (validatephone(document.frmQuotation.ephone.value)==false)
	{
		alert("Phone number must be numeric.");
	    document.frmQuotation.ephone.focus();
		return false;
	}
	if (validatephonelength(document.frmQuotation.ephone.value)==false)
	{
		alert("Please provide a valid UK telephone number.\nFor example, 08456 044414");
	    document.frmQuotation.ephone.focus();
		return false;
	}
	
return true;
}

function validatephone(addr)
	{
		var Chars = "0123456789- ";
		for (var i = 0; i < addr.length; i++)
		{
			if (Chars.indexOf(addr.charAt(i)) == -1)
			return false;
		}
		return true;
	}

function validatephonelength(addr)
{
		var telephone=addr;
		var teltemp = "";
		telephone = '' + telephone;
		splittel = telephone.split(" ");
		for(i = 0; i < splittel.length; i++)
        teltemp += splittel[i];
        lentel=teltemp.length;
		if((lentel < 10) || (lentel > 11))
           return false;
		else
		 return true;
	}
	
/*function changeBorder(){
	document.getElementById("forename").style.borderColor="#829022";
	document.getElementById("forename").style.backgroundColor="#fdfaec";
	}
function changeBorderBack(){
	document.getElementById("forename").style.borderColor="#ded5b4";
	document.getElementById("forename").style.backgroundColor="#f7f1d7";
	}
function changeBorder1(){
	document.getElementById("surname").style.borderColor="#829022";
	document.getElementById("surname").style.backgroundColor="#fdfaec";
	}
function changeBorderBack1(){
	document.getElementById("surname").style.borderColor="#ded5b4";
	document.getElementById("surname").style.backgroundColor="#f7f1d7";
	}
function changeBorder2(){
	document.getElementById("email").style.borderColor="#829022";
	document.getElementById("email").style.backgroundColor="#fdfaec";
	}
function changeBorderBack2(){
	document.getElementById("email").style.borderColor="#ded5b4";
	document.getElementById("email").style.backgroundColor="#f7f1d7";
	}
function changeBorder3(){
	document.getElementById("postcode").style.borderColor="#829022";
	document.getElementById("postcode").style.backgroundColor="#fdfaec";
	}
function changeBorderBack3(){
	document.getElementById("postcode").style.borderColor="#ded5b4";
	document.getElementById("postcode").style.backgroundColor="#f7f1d7";
	}
function changeBorder4(){
	document.getElementById("dphone").style.borderColor="#829022";
	document.getElementById("dphone").style.backgroundColor="#fdfaec";
	}
function changeBorderBack4(){
	document.getElementById("dphone").style.borderColor="#ded5b4";
	document.getElementById("dphone").style.backgroundColor="#f7f1d7";
	}
function changeBorder5(){
	document.getElementById("ephone").style.borderColor="#829022";
	document.getElementById("ephone").style.backgroundColor="#fdfaec";
	}
function changeBorderBack5(){
	document.getElementById("ephone").style.borderColor="#ded5b4";
	document.getElementById("ephone").style.backgroundColor="#f7f1d7";
	}*/
	
	
function changeBorder(n){
	switch(n){
		case 1:
			document.getElementById("forename").style.borderColor="#829022";
			document.getElementById("forename").style.backgroundColor="#fdfaec";
		break;
		
		case 2:
			document.getElementById("surname").style.borderColor="#829022";
			document.getElementById("surname").style.backgroundColor="#fdfaec";
		break;
		
		case 3:
			document.getElementById("email").style.borderColor="#829022";
			document.getElementById("email").style.backgroundColor="#fdfaec";
		break;
		
		case 4:
			document.getElementById("postcode").style.borderColor="#829022";
			document.getElementById("postcode").style.backgroundColor="#fdfaec";
		break;
		
		case 5:
			document.getElementById("dphone").style.borderColor="#829022";
			document.getElementById("dphone").style.backgroundColor="#fdfaec";
		break;
		
		case 6:
			document.getElementById("ephone").style.borderColor="#829022";
			document.getElementById("ephone").style.backgroundColor="#fdfaec";
		break;
		
		case 7:
			document.getElementById("addinfo").style.borderColor="#829022";
			document.getElementById("addinfo").style.backgroundColor="#fdfaec";
		break;
				
	}
}

function changeBorderBack(n){
	switch(n){
		case 1:
			document.getElementById("forename").style.borderColor="#d2c28a";
			document.getElementById("forename").style.backgroundColor="#f7f1d7";
		break;
		
		case 2:
			document.getElementById("surname").style.borderColor="#d2c28a";
			document.getElementById("surname").style.backgroundColor="#f7f1d7";
		break;
		
		case 3:
			document.getElementById("email").style.borderColor="#d2c28a";
			document.getElementById("email").style.backgroundColor="#f7f1d7";
		break;
		
		case 4:
			document.getElementById("postcode").style.borderColor="#d2c28a";
			document.getElementById("postcode").style.backgroundColor="#f7f1d7";
		break;
		
		case 5:
			document.getElementById("dphone").style.borderColor="#d2c28a";
			document.getElementById("dphone").style.backgroundColor="#f7f1d7";
		break;
		
		case 6:
			document.getElementById("ephone").style.borderColor="#d2c28a";
			document.getElementById("ephone").style.backgroundColor="#f7f1d7";
		break;
		
		case 7:
			document.getElementById("addinfo").style.borderColor="#d2c28a";
			document.getElementById("addinfo").style.backgroundColor="#f7f1d7";
		break;
		
	}
}


