var numb = '0123456789';
var lwr = 'abcdefghijklmnopqrstuvwxyz';
var upr = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
var exep = '$ £';
var exep1 = '+ -';
var exepnormal = "! @',.()$£*?/\+-:;";
function isValid(parm,val) {
if (parm == "") return true;
for (i=0; i<parm.length; i++) {
if (val.indexOf(parm.charAt(i),0) == -1) return false;
}
return true;
}

function isNumber(parm) {return isValid(parm,numb);}
function isNumberplus(parm) {return isValid(parm,numb+exep1);}
function isLower(parm) {return isValid(parm,lwr);}
function isUpper(parm) {return isValid(parm,upr);}
function isAlpha(parm) {return isValid(parm,lwr+upr);}
function isAlphanum(parm) {return isValid(parm,lwr+upr+numb);} 
function isAlphanume(parm) {return isValid(parm,lwr+upr+numb+exep);}
function isAlphanumnormal(parm) {return isValid(parm,lwr+upr+numb+exepnormal);} 
function notready() {
alert('This link is not yet available'); }

function CheckForm6() { 

	//Initialise variables
	var errorMsg = "";
	var txtfield = document.S6.custnotesx.value;
	var txtfield1 = txtfield.replace(/[\r\l\n]+/g, ' ');
	var ncount=0
	// Check extra message for unacceptable charcters
	if (!isAlphanumnormal(txtfield1)) 
	{
		errorMsg += "\n\tExtra Message \t- Contains invalid characters!";	
	}
	//If there is aproblem with the form then display an error
	if (errorMsg != ""){
		msg = "______________________________________________________________\n\n";
		msg += "Sorry we cannot continue - some input needs correcting.\n";
		msg += "Please correct the problem(s).\n";
		msg += "______________________________________________________________\n\n";
		msg += "The following field(s) need to be corrected: -\n";
		
		errorMsg += alert(msg + errorMsg + "\n\n");
		return false;
	}
	
	return true;
}



function CheckForm1 () { 

	//Initialise variables
	var errorMsg = "";
    var fullstring = "";
	var ncount=0
	fullsring=document.s1.fnamex.value+document.s1.snamex.value+document.s1.companyx.value+document.s1.ad1x.value+document.s1.ad2x.value+document.s1.townx.value+document.s1.countyx.value+document.s1.pcex.value ;
	//Check for a first name
	if (document.s1.fnamex.value == ""){
		errorMsg += "\n\tName \t- Enter your First Name";	
	}
	// Check first name for unacceptable charcters
	if (!isAlphanumnormal(document.s1.fnamex.value)) 
	{
		errorMsg += "\n\tFirst Name \t- Contains invalid characters!";	
	}
	
	//Check for a surname
	if (document.s1.snamex.value == ""){
		errorMsg += "\n\tName \t- Enter your Surname";	
	}
	// Check surname for unacceptable charcters
	if (!isAlphanumnormal(document.s1.snamex.value)) 
	{
		errorMsg += "\n\tSurname \t- Contains invalid characters!";	
	}
    // Check company for unacceptable charcters
	if (!isAlphanumnormal(document.s1.companyx.value)) 
	{
		errorMsg += "\n\tCompany Name \t- Contains invalid characters!";	
	}	
	//Check for a the first line of the address
	if (document.s1.ad1x.value == ""){
		errorMsg += "\n\tAddress \t- Enter your the first line of your address";	
	}
    // Check 1st line of address for unacceptable charcters
	if (!isAlphanumnormal(document.s1.ad1x.value)) 
	{
		errorMsg += "\n\tAddress line 1 \t- Contains invalid characters!";	
	}		
    // Check 2nd line of address for unacceptable charcters
	if (!isAlphanumnormal(document.s1.ad2x.value)) 
	{
		errorMsg += "\n\tAddress line 2 \t- Contains invalid characters!";	
	}	
	//Check for a the town/city
	if (document.s1.townx.value == ""){
		errorMsg += "\n\tAddress \t- Enter your Town or City";	
	}
	    // Check town/city for unacceptable charcters
	if (!isAlphanumnormal(document.s1.townx.value)) 
	{
		errorMsg += "\n\tTown/City \t- Contains invalid characters!";	
	}	
    // Check county for unacceptable charcters
	if (!isAlphanumnormal(document.s1.countyx.value)) 
	{
		errorMsg += "\n\tCounty \t- Contains invalid characters!";	
	}		
	
	//Check for a the postcode
	if (document.s1.pcex.value == ""){
		errorMsg += "\n\tAddress \t- Complete your postcode";	
	}
    // Check end of postcode for unacceptable charcters
	if (!isAlphanumnormal(document.s1.pcex.value)) 
	{
		errorMsg += "\n\tPostcode 1 \t- Contains invalid characters!";	
	}	
	
	//If there is aproblem with the form then display an error
	if (errorMsg != ""){
		msg = "______________________________________________________________\n\n";
		msg += "Sorry we cannot continue - some input needs correcting.\n";
		msg += "Please correct the problem(s).\n";
		msg += "______________________________________________________________\n\n";
		msg += "The following field(s) need to be corrected: -\n";
		
		errorMsg += alert(msg + errorMsg + "\n\n");
		return false;
	}
	
	return true;
}
function CheckForm2 () { 

	//Initialise variables
	var errorMsg = "";
    var fullstring = "";
	var ncount=0
	
	// Check for only alpha numeric content (does not allow spaces or puctuation)
	
	if (!isNumberplus(document.s2.telx.value)) 
	{
		errorMsg += "\n\tTelephone \t- Can only be numbers!";	
	}
	if (!isNumberplus(document.s2.mobx.value)) 
	{
		errorMsg += "\n\tMobile \t- Can only be numbers!";	
	}
	if (document.s2.telx.value.length<1 && document.s2.mobx.value.length<1)
	{
		errorMsg += "\n\tPassword \t- You must enter at least one contact number";	
	}	
	
	if (!isAlphanum(document.s2.pw1x.value)) 
	{
		errorMsg += "\n\tPassword \t- Cannot contain invalid characters";	
	}
	
	if (document.s2.pw1x.value.length<5)
	{
		errorMsg += "\n\tPassword \t- This must be at least 5 characters long";	
	}
	if (document.s2.pw1x.value.length>10)
	{
		errorMsg += "\n\tPassword \t- This must not be more than 10 characters long";	
	}	
	var pw1=document.s2.pw1x.value;
	var pw2=document.s2.pw2x.value;
	if (pw1==pw2)
	{  }
	else
	{
		errorMsg += "\n\tPasswords \t- The password and confirm password are not the same!";	
	}	
	
	//If there is a problem with the form then display an error
	if (errorMsg != ""){
		msg = "______________________________________________________________\n\n";
		msg += "Sorry we cannot continue - some input needs correcting.\n";
		msg += "Please correct the problem(s).\n";
		msg += "______________________________________________________________\n\n";
		msg += "The following field(s) need to be corrected: -\n";
		
		errorMsg += alert(msg + errorMsg + "\n\n");
		return false;
	}
	
	return true;
}
function CheckForm0 () { 

	//Initialise variables
	var errorMsg = "";

	

	 	
	//Check for an e-mail address and that it is valid
	if(!ValidateEmail(document.s0.emailx.value)) { 
		errorMsg += "\n\tE-mail \t- you entered an invalid address!";
	}
			
	
		
	//If there is aproblem with the form then display an error
	if (errorMsg != ""){
		msg = "______________________________________________________________\n\n";
		msg += "Sorry we cannot continue.\n";
		msg += "There is a problem with your entry\n";
		msg += "______________________________________________________________\n\n";
		msg += "The following field need to be corrected: -\n";
		
		errorMsg += alert(msg + errorMsg + "\n\n");
		return false;
	}
	
	return true;
}

function ValidateEmail(sEmail)
{ 
var reEmail=/^(.+)@(.+)$/; 
var reQuotedString="(\"[^\"]*\")";
var reIPDomain=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/;
var reValidCharString="\[^\\s\\(\\)><@,;:\\\\\\\"\\.\\[\\]\]+";
var reGetString="(" + reValidCharString + "|" + reQuotedString + ")";
var reUserName=new RegExp("^" + reGetString + "(\\." + reGetString + ")*$");
var reDomain=new RegExp("^" + reValidCharString + "(\\." + reValidCharString +")*$");
var reWholeCharString=new RegExp("^" + reValidCharString + "$");

var matchArray=sEmail.match(reEmail);
if (matchArray==null) return false; 
var sUsername=matchArray[1];
var sDomain=matchArray[2];

for (i=0; i<sUsername.length; i++) {
    if (sUsername.charCodeAt(i)>127) return false; 
} 
if (sUsername.match(reUserName)==null) return false;

for (i=0; i<sDomain.length; i++) {
    if (sDomain.charCodeAt(i)>127) return false;
} 

var arrIPNums=sDomain.match(reIPDomain);
if (arrIPNums!=null)
{
    for (var i=1;i<=4;i++) { 
        if (arrIPNums>255) return false; 
    }    
} 
else
{
    var arrDomains=sDomain.split(".");
    var iDomainLen=arrDomains.length;
    if (iDomainLen<2) return false; 
    for (i=0;i<iDomainLen;i++) { 
        if (arrDomains[i].search(reWholeCharString)==-1) return false; 
    } 
}
return true;
} 

function CheckFormC1 () { 

	//Initialise variables
	var errorMsg = "";
    var fullstring = "";
	var ncount=0
	//Check for an e-mail address and that it is valid
	if(!ValidateEmail(document.c1.emailx.value)) { 
		errorMsg += "\n\tE-mail \t- you entered an invalid address!";
	}
	
	
		//Check for a first name
	if (document.c1.fnamex.value == ""){
		errorMsg += "\n\tName \t- Enter your First Name";	
	}
	// Check first name for unacceptable charcters
	if (!isAlphanumnormal(document.c1.fnamex.value)) 
	{
		errorMsg += "\n\tFirst Name \t- Contains invalid characters!";	
	}
	
	//Check for a surname
	if (document.c1.snamex.value == ""){
		errorMsg += "\n\tName \t- Enter your Surname";	
	}
	// Check surname for unacceptable charcters
	if (!isAlphanumnormal(document.c1.snamex.value)) 
	{
		errorMsg += "\n\tSurname \t- Contains invalid characters!";	
	}
    // Check company for unacceptable charcters
	if (!isAlphanumnormal(document.c1.companyx.value)) 
	{
		errorMsg += "\n\tCompany Name \t- Contains invalid characters!";	
	}	
	
	
	//If there is aproblem with the form then display an error
	if (errorMsg != ""){
		msg = "______________________________________________________________\n\n";
		msg += "Sorry we cannot continue - some input needs correcting.\n";
		msg += "Please correct the problem(s).\n";
		msg += "______________________________________________________________\n\n";
		msg += "The following field(s) need to be corrected: -\n";
		
		errorMsg += alert(msg + errorMsg + "\n\n");
		return false;
	}
	
	return true;
}
function CheckFormC2 () { 

	//Initialise variables
	var errorMsg = "";
    var fullstring = "";
	var ncount=0
//Check for a the first line of the address
	if (document.c2.ad1x.value == ""){
		errorMsg += "\n\tAddress \t- Enter your the first line of your address";	
	}
    // Check 1st line of address for unacceptable charcters
	if (!isAlphanumnormal(document.c2.ad1x.value)) 
	{
		errorMsg += "\n\tAddress line 1 \t- Contains invalid characters!";	
	}		
    // Check 2nd line of address for unacceptable charcters
	if (!isAlphanumnormal(document.c2.ad2x.value)) 
	{
		errorMsg += "\n\tAddress line 2 \t- Contains invalid characters!";	
	}	
	//Check for a the town/city
	if (document.c2.townx.value == ""){
		errorMsg += "\n\tAddress \t- Enter your Town or City";	
	}
	    // Check town/city for unacceptable charcters
	if (!isAlphanumnormal(document.c2.townx.value)) 
	{
		errorMsg += "\n\tTown/City \t- Contains invalid characters!";	
	}	
    // Check county for unacceptable charcters
	if (!isAlphanumnormal(document.c2.countyx.value)) 
	{
		errorMsg += "\n\tCounty \t- Contains invalid characters!";	
	}		
	
	//Check for a the postcode
	if (document.c2.pcex.value == ""){
		errorMsg += "\n\tAddress \t- Complete your postcode";	
	}
    // Check end of postcode for unacceptable charcters
	if (!isAlphanumnormal(document.c2.pcex.value)) 
	{
		errorMsg += "\n\tPostcode 1 \t- Contains invalid characters!";	
	}	
	
	//If there is aproblem with the form then display an error
	if (errorMsg != ""){
		msg = "______________________________________________________________\n\n";
		msg += "Sorry we cannot continue - some input needs correcting.\n";
		msg += "Please correct the problem(s).\n";
		msg += "______________________________________________________________\n\n";
		msg += "The following field(s) need to be corrected: -\n";
		
		errorMsg += alert(msg + errorMsg + "\n\n");
		return false;
	}
	
	return true;
}

function CheckFormC3 () { 

	//Initialise variables
	var errorMsg = "";
    var fullstring = "";
	var ncount=0
// Check for only numeric content (plus a few extras)
	
	if (!isNumberplus(document.c3.telx.value)) 
	{
		errorMsg += "\n\tTelephone \t- Can only be numbers!";	
	}
	if (!isNumberplus(document.c3.mobx.value)) 
	{
		errorMsg += "\n\tMobile \t- Can only be numbers!";	
	}
	
	//If there is aproblem with the form then display an error
	if (errorMsg != ""){
		msg = "______________________________________________________________\n\n";
		msg += "Sorry we cannot continue - some input needs correcting.\n";
		msg += "Please correct the problem(s).\n";
		msg += "______________________________________________________________\n\n";
		msg += "The following field(s) need to be corrected: -\n";
		
		errorMsg += alert(msg + errorMsg + "\n\n");
		return false;
	}
	
	return true;
}
function CheckFormC4 () { 

	//Initialise variables
	var errorMsg = "";
    var fullstring = "";
	var ncount=0
if (!isAlphanum(document.c4.pwORIGx.value)) 
	{
		errorMsg += "\n\tOriginal Password \t- Cannot contain invalid characters";	
	}
if (!isAlphanum(document.c4.pwNEWx.value)) 
	{
		errorMsg += "\n\tNew Password \t- Cannot contain invalid characters";	
	}	
    var pw1=document.c4.pwNEWx.value;
	var pw2=document.c4.pwCONFIRMx.value;
	if (pw1==pw2)
	{  }
	else
	{
		errorMsg += "\n\tPasswords \t- The new password and confirm password are not the same!";	
	}		
	if (document.c4.pwORIGx.value.length<5)
	{
		errorMsg += "\n\tOriginal Password \t- This must be at least 5 characters long";	
	}	
	if (document.c4.pwORIGx.value.length>10)
	{
		errorMsg += "\n\tOriginal Password \t- This must not be more than 10 characters long";	
	}	
		
	if (document.c4.pwNEWx.value.length<5)
	{
		errorMsg += "\n\tNew Password \t- This must be at least 5 characters long";	
	}
	if (document.c4.pwNEWx.value.length>10)
	{
		errorMsg += "\n\tNew Password \t- This must not be more than 10 characters long";	
	}	
	
	
	//If there is aproblem with the form then display an error
	if (errorMsg != ""){
		msg = "______________________________________________________________\n\n";
		msg += "Sorry we cannot continue - some input needs correcting.\n";
		msg += "Please correct the problem(s).\n";
		msg += "______________________________________________________________\n\n";
		msg += "The following field(s) need to be corrected: -\n";
		
		errorMsg += alert(msg + errorMsg + "\n\n");
		return false;
	}
	
	return true;
}



