function CheckPresent(v, i){
if (i=="") 
	{
	if (v.value=="") {return false;} else {return true;}
	};
var x=document.getElementById(i);
if (v.value == "") { 
   x.src='images/smallexcl.gif';
   return false;}
else {
   x.src='images/smallwhite.gif';
   return true}
};

function rightTrim(sString) 
{
while (sString.substring(sString.length-1, sString.length) == ' ')
{
sString = sString.substring(0,sString.length-1);
}
return sString.length;
};

function CheckCheckBox(v, i){
var x=document.getElementById(i);
if (v.checked==false) { 
   x.src='images/smallexcl.gif';
   return false;}
else {
   x.src='images/smallwhite.gif';
   return true}
};

function CheckNum(j) {
for (i=0; i<j.length; i++) 
{if ((j.charCodeAt(i)>57)||(j.charCodeAt(i)<48)) {return false}}
return true
};

function CheckDoB(i) {
var myDayStr = document.applyform.DoBDD.value;
var myMM = document.applyform.DoBMM.value;
var myMonthStr = --myMM;
var myYearStr = document.applyform.DoBYY.value;
var myMonth = new Array('Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec'); 
var myDateStr = myDayStr + ' ' + myMonth[myMonthStr] + ' ' + myYearStr;

/* Using form values, create a new date object using the setFullYear function */
var myDate = new Date();
myDate.setFullYear( myYearStr, myMonthStr, myDayStr );
if ( myYearStr=="Year") {
     document.getElementById(i).src="images/smallexcl.gif";
     return false;}

if ( myDate.getMonth() != myMonthStr ) {
     document.getElementById(i).src="images/smallexcl.gif";
     return false;}
else {
     document.getElementById(i).src="images/smallwhite.gif";
     return true}
}

function echeck (emailStr)
{var emess=emailCheck(emailStr)
if (emess=="")
{document.getElementById('EmImg').src="images/smallwhite.gif";
return true}
else
{document.getElementById('EmImg').src="images/smallexcl.gif";
return false}}

function fecheck (emailStr)
{var emess=femailCheck(emailStr)
if (emess=="")
{document.getElementById('FemImg').src="images/smallwhite.gif";
return true}
else
{document.getElementById('FemImg').src="images/smallexcl.gif";
return false}}


function emailCheck (IemailStr) {

/* The following variable tells the rest of the function whether or not
to verify that the address ends in a two-letter country or well-known
TLD.  1 means check it, 0 means don't. */
var msg=""
var checkTLD=1;
var emailStr=IemailStr.toLowerCase();

if (CheckPresent(document.applyform.HomeEmailAddress,"")==false)
{msg="Email address not entered";
return msg}

/* The following is the list of known TLDs that an e-mail address must end with. */

var knownDomsPat=/^(com|net|org|edu|int|mil|gov|arpa|biz|aero|name|coop|info|pro|museum)$/;

/* The following pattern is used to check if the entered e-mail address
fits the user@domain format.  It also is used to separate the username
from the domain. */

var emailPat=/^(.+)@(.+)$/;

/* The following string represents the pattern for matching all special
characters.  We don't want to allow special characters in the address. 
These characters include ( ) < > @ , ; : \ " . [ ] */

var specialChars="\\(\\)><@,;:\\\\\\\"\\.\\[\\]";

/* The following string represents the range of characters allowed in a 
username or domainname.  It really states which chars aren't allowed.*/

var validChars="\[^\\s" + specialChars + "\]";

/* The following pattern applies if the "user" is a quoted string (in
which case, there are no rules about which characters are allowed
and which aren't; anything goes).  E.g. "jiminy cricket"@disney.com
is a legal e-mail address. */

var quotedUser="(\"[^\"]*\")";

/* The following pattern applies for domains that are IP addresses,
rather than symbolic names.  E.g. joe@[123.124.233.4] is a legal
e-mail address. NOTE: The square brackets are required. */

var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/;

/* The following string represents an atom (basically a series of non-special characters.) */

var atom=validChars + '+';

/* The following string represents one word in the typical username.
For example, in john.doe@somewhere.com, john and doe are words.
Basically, a word is either an atom or quoted string. */

var word="(" + atom + "|" + quotedUser + ")";

// The following pattern describes the structure of the user

var userPat=new RegExp("^" + word + "(\\." + word + ")*$");

/* The following pattern describes the structure of a normal symbolic
domain, as opposed to ipDomainPat, shown above. */

var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$");

/* Finally, let's start trying to figure out if the supplied address is valid. */

/* Begin with the coarse pattern to simply break up user@domain into
different pieces that are easy to analyze. */

var matchArray=emailStr.match(emailPat);

if (matchArray==null) {

/* Too many/few @'s or something; basically, this address doesn't
even fit the general mould of a valid e-mail address. */

msg="Email address seems incorrect (check @ and .'s)";
return msg;
}
var user=matchArray[1];
var domain=matchArray[2];

// Start by checking that only basic ASCII characters are in the strings (0-127).

for (i=0; i<user.length; i++) {
if (user.charCodeAt(i)>127) {
msg="Your email username contains invalid characters.";
return msg;
   }
}
for (i=0; i<domain.length; i++) {
if (domain.charCodeAt(i)>127) {
msg="Your email domain name contains invalid characters.";
return msg;
   }
}

// See if "user" is valid 

if (user.match(userPat)==null) {

// user is not valid

msg="The email username doesn't seem to be valid.";
return msg;
}

/* if the e-mail address is at an IP address (as opposed to a symbolic
host name) make sure the IP address is valid. */

var IPArray=domain.match(ipDomainPat);
if (IPArray!=null) {

// this is an IP address

for (var i=1;i<=4;i++) {
if (IPArray[i]>255) {
msg="Your email destination IP address is invalid";
return msg;
   }
}
return true;
}

// Domain is symbolic name.  Check if it's valid.
 
var atomPat=new RegExp("^" + atom + "$");
var domArr=domain.split(".");
var len=domArr.length;
for (i=0;i<len;i++) {
if (domArr[i].search(atomPat)==-1) {
msg="The email domain name does not seem to be valid.";
return msg;
   }
}

/* domain name seems valid, but now make sure that it ends in a
known top-level domain (like com, edu, gov) or a two-letter word,
representing country (uk, nl), and that there's a hostname preceding 
the domain or country. */

if (checkTLD && domArr[domArr.length-1].length!=2 && 
domArr[domArr.length-1].search(knownDomsPat)==-1) {
msg="The email address must end in a well-known domain or two letter country";
return msg;
}

// Make sure there's a host name preceding the domain.

if (len<2) {
msg="This email address is missing a hostname!";
return msg;
}

// If we've gotten this far, everything's valid!
msg="";
return msg;
}

//  End -->






function femailCheck (IemailStr) {

/* The following variable tells the rest of the function whether or not
to verify that the address ends in a two-letter country or well-known
TLD.  1 means check it, 0 means don't. */
var msg=""
var checkTLD=1;
var emailStr=IemailStr.toLowerCase();

if (CheckPresent(document.applyform.FriendEmailAddress,"")==false)
{msg="Friend's Email address not entered";
return msg}

/* The following is the list of known TLDs that an e-mail address must end with. */

var knownDomsPat=/^(com|net|org|edu|int|mil|gov|arpa|biz|aero|name|coop|info|pro|museum)$/;

/* The following pattern is used to check if the entered e-mail address
fits the user@domain format.  It also is used to separate the username
from the domain. */

var emailPat=/^(.+)@(.+)$/;

/* The following string represents the pattern for matching all special
characters.  We don't want to allow special characters in the address. 
These characters include ( ) < > @ , ; : \ " . [ ] */

var specialChars="\\(\\)><@,;:\\\\\\\"\\.\\[\\]";

/* The following string represents the range of characters allowed in a 
username or domainname.  It really states which chars aren't allowed.*/

var validChars="\[^\\s" + specialChars + "\]";

/* The following pattern applies if the "user" is a quoted string (in
which case, there are no rules about which characters are allowed
and which aren't; anything goes).  E.g. "jiminy cricket"@disney.com
is a legal e-mail address. */

var quotedUser="(\"[^\"]*\")";

/* The following pattern applies for domains that are IP addresses,
rather than symbolic names.  E.g. joe@[123.124.233.4] is a legal
e-mail address. NOTE: The square brackets are required. */

var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/;

/* The following string represents an atom (basically a series of non-special characters.) */

var atom=validChars + '+';

/* The following string represents one word in the typical username.
For example, in john.doe@somewhere.com, john and doe are words.
Basically, a word is either an atom or quoted string. */

var word="(" + atom + "|" + quotedUser + ")";

// The following pattern describes the structure of the user

var userPat=new RegExp("^" + word + "(\\." + word + ")*$");

/* The following pattern describes the structure of a normal symbolic
domain, as opposed to ipDomainPat, shown above. */

var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$");

/* Finally, let's start trying to figure out if the supplied address is valid. */

/* Begin with the coarse pattern to simply break up user@domain into
different pieces that are easy to analyze. */

var matchArray=emailStr.match(emailPat);

if (matchArray==null) {

/* Too many/few @'s or something; basically, this address doesn't
even fit the general mould of a valid e-mail address. */

msg="Your friend's email address seems incorrect (check @ and .'s)";
return msg;
}
var user=matchArray[1];
var domain=matchArray[2];

// Start by checking that only basic ASCII characters are in the strings (0-127).

for (i=0; i<user.length; i++) {
if (user.charCodeAt(i)>127) {
msg="Your friend's email username contains invalid characters.";
return msg;
   }
}
for (i=0; i<domain.length; i++) {
if (domain.charCodeAt(i)>127) {
msg="Your friend's email domain name contains invalid characters.";
return msg;
   }
}

// See if "user" is valid 

if (user.match(userPat)==null) {

// user is not valid

msg="Your friend's email username doesn't seem to be valid.";
return msg;
}

/* if the e-mail address is at an IP address (as opposed to a symbolic
host name) make sure the IP address is valid. */

var IPArray=domain.match(ipDomainPat);
if (IPArray!=null) {

// this is an IP address

for (var i=1;i<=4;i++) {
if (IPArray[i]>255) {
msg="Your friend's email destination IP address is invalid";
return msg;
   }
}
return true;
}

// Domain is symbolic name.  Check if it's valid.
 
var atomPat=new RegExp("^" + atom + "$");
var domArr=domain.split(".");
var len=domArr.length;
for (i=0;i<len;i++) {
if (domArr[i].search(atomPat)==-1) {
msg="Your friend's email domain name does not seem to be valid.";
return msg;
   }
}

/* domain name seems valid, but now make sure that it ends in a
known top-level domain (like com, edu, gov) or a two-letter word,
representing country (uk, nl), and that there's a hostname preceding 
the domain or country. */

if (checkTLD && domArr[domArr.length-1].length!=2 && 
domArr[domArr.length-1].search(knownDomsPat)==-1) {
msg="Your friend's address must end in a well-known domain or two letter country";
return msg;
}

// Make sure there's a host name preceding the domain.

if (len<2) {
msg="Your friend's email address is missing a hostname!";
return msg;
}

// If we've gotten this far, everything's valid!
msg="";
return msg;
}

//  End -->

function cecheck (emailStr)
{var emess=compemailCheck(emailStr);
if ((emess=="")||(document.applyform.EmailAcct[1].checked == false))
{document.getElementById('OldEmailImg').src="images/smallwhite.gif";
if ((emailStr.toLowerCase()==document.applyform.HomeEmailAddress.value.toLowerCase())&&(emailStr!=""))
{alert ('WARNING - If you select the same address for your competitions as your regular email you may \nfind the amount of competition related mail makes it difficult for you to find your other correspondence.\n\nYou should use a different address for your competitions to avoid this');
return true}
else
{return true}}
else
{document.getElementById('OldEmailImg').src="images/smallexcl.gif";
return false}};


function compemailCheck (IemailStr) {

/* The following variable tells the rest of the function whether or not
to verify that the address ends in a two-letter country or well-known
TLD.  1 means check it, 0 means don't. */
var msg=""
var checkTLD=1;
var emailStr=IemailStr.toLowerCase();

if (CheckPresent(document.applyform.ExistingCompEmail,"")==false)
{msg="Competition email address not entered";
return msg}

/* The following is the list of known TLDs that an e-mail address must end with. */

var knownDomsPat=/^(com|net|org|edu|int|mil|gov|arpa|biz|aero|name|coop|info|pro|museum)$/;

/* The following pattern is used to check if the entered e-mail address
fits the user@domain format.  It also is used to separate the username
from the domain. */

var emailPat=/^(.+)@(.+)$/;

/* The following string represents the pattern for matching all special
characters.  We don't want to allow special characters in the address. 
These characters include ( ) < > @ , ; : \ " . [ ] */

var specialChars="\\(\\)><@,;:\\\\\\\"\\.\\[\\]";

/* The following string represents the range of characters allowed in a 
username or domainname.  It really states which chars aren't allowed.*/

var validChars="\[^\\s" + specialChars + "\]";

/* The following pattern applies if the "user" is a quoted string (in
which case, there are no rules about which characters are allowed
and which aren't; anything goes).  E.g. "jiminy cricket"@disney.com
is a legal e-mail address. */

var quotedUser="(\"[^\"]*\")";

/* The following pattern applies for domains that are IP addresses,
rather than symbolic names.  E.g. joe@[123.124.233.4] is a legal
e-mail address. NOTE: The square brackets are required. */

var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/;

/* The following string represents an atom (basically a series of non-special characters.) */

var atom=validChars + '+';

/* The following string represents one word in the typical username.
For example, in john.doe@somewhere.com, john and doe are words.
Basically, a word is either an atom or quoted string. */

var word="(" + atom + "|" + quotedUser + ")";

// The following pattern describes the structure of the user

var userPat=new RegExp("^" + word + "(\\." + word + ")*$");

/* The following pattern describes the structure of a normal symbolic
domain, as opposed to ipDomainPat, shown above. */

var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$");

/* Finally, let's start trying to figure out if the supplied address is valid. */

/* Begin with the coarse pattern to simply break up user@domain into
different pieces that are easy to analyze. */

var matchArray=emailStr.match(emailPat);

if (matchArray==null) {

/* Too many/few @'s or something; basically, this address doesn't
even fit the general mould of a valid e-mail address. */

msg="Competition email competition address seems incorrect (check @ and .'s)";
return msg;
}
var user=matchArray[1];
var domain=matchArray[2];

// Start by checking that only basic ASCII characters are in the strings (0-127).

for (i=0; i<user.length; i++) {
if (user.charCodeAt(i)>127) {
msg="Your competition email username contains invalid characters.";
return msg;
   }
}
for (i=0; i<domain.length; i++) {
if (domain.charCodeAt(i)>127) {
msg="Your competition email domain name contains invalid characters.";
return msg;
   }
}

// See if "user" is valid 

if (user.match(userPat)==null) {

// user is not valid

msg="The competition email username doesn't seem to be valid.";
return msg;
}

/* if the e-mail address is at an IP address (as opposed to a symbolic
host name) make sure the IP address is valid. */

var IPArray=domain.match(ipDomainPat);
if (IPArray!=null) {

// this is an IP address

for (var i=1;i<=4;i++) {
if (IPArray[i]>255) {
msg="Your competition email destination IP address is invalid";
return msg;
   }
}
return true;
}

// Domain is symbolic name.  Check if it's valid.
 
var atomPat=new RegExp("^" + atom + "$");
var domArr=domain.split(".");
var len=domArr.length;
for (i=0;i<len;i++) {
if (domArr[i].search(atomPat)==-1) {
msg="The competition email domain name does not seem to be valid.";
return msg;
   }
}

/* domain name seems valid, but now make sure that it ends in a
known top-level domain (like com, edu, gov) or a two-letter word,
representing country (uk, nl), and that there's a hostname preceding 
the domain or country. */

if (checkTLD && domArr[domArr.length-1].length!=2 && 
domArr[domArr.length-1].search(knownDomsPat)==-1) {
msg="The competition email address must end in a well-known domain or two letter country";
return msg;
}

// Make sure there's a host name preceding the domain.

if (len<2) {
msg="This competition email address is missing a hostname!";
return msg;
}

// If we've gotten this far, everything's valid!
msg="";
return msg;
}

//  End -->

function mailboxcheck(i)
{document.applyform.EmailAcct[0].checked = true;
 document.applyform.ExistingCompEmail.value = '';
if ( document.applyform.MailBoxNme.value.length<7)
    {
       document.getElementById(i).src="images/smallexcl.gif";
       return false;
}
else
{
       document.getElementById(i).src="images/smallwhite.gif";
       return true;

}}


function ValMailBox(i,j)
{if ( document.applyform.EmailAcct[0].checked == true )
    {
       document.applyform.ExistingCompEmail.value = '';
       document.getElementById(i).src="images/smallreqd.gif";
       document.getElementById(j).src="images/smallwhite.gif";
       return true;
}
else
{
       document.getElementById(j).src="images/smallreqd.gif";
       document.getElementById(i).src="images/smallwhite.gif";
       return true;
}}    

function ValEmail(i,j)
{if ( document.applyform.EmailAcct[1].checked == true )
    {  document.applyform.MailBoxNme.value = '';
       document.getElementById(j).src="images/smallreqd.gif";
       document.getElementById(i).src="images/smallwhite.gif";
       return true;
}
else
{if ( document.applyform.ExistingCompEmail.value != "" )
    {  document.applyform.EmailAcct[1].checked = true;
       document.applyform.MailBoxNme.value = ''; 
       document.getElementById(i).src="images/smallwhite.gif";
       return true;
}
else
{document.getElementById('OldEmailImg').src="images/smallwhite.gif";
}}}    
    


function ValSex(i)
{if ( ( document.applyform.Sex[0].checked == false )
    && ( document.applyform.Sex[1].checked == false ) )
    {
       document.getElementById(i).src="images/smallexcl.gif";
       return false;
    }
else
	{
       document.getElementById(i).src="images/smallwhite.gif";
       return true;
	}}    

function ValMS(i)
{if ( ( document.applyform.MaritalStatus[0].checked == false )
    && ( document.applyform.MaritalStatus[1].checked == false ) )
    {
		document.getElementById(i).src="images/smallexcl.gif";
       return false;
    }
else
	{
		document.getElementById(i).src="images/smallwhite.gif";
       return true;
	}}    



function valall(){
var mess="";
var tit=document.applyform.Title.value;
if (CheckPresent(document.applyform.Title,'TtImg')==false){mess+="\nTitle not selected"};

if (CheckPresent(document.applyform.Forename,'FImg')==false){mess+="\nForename not entered"}
else
{if (rightTrim(document.applyform.Forename.value)<2)
{mess+="\nForename must have at least 2 characters"}
};

if (CheckPresent(document.applyform.Surname,'SImg')==false){mess+="\nSurname not entered"}
else
{if (rightTrim(document.applyform.Surname.value)<2)
{mess+="\nSurname must have at least 2 characters"}
};


if ((document.applyform.Sex[0].checked == true)&&((tit!="Mr")&&(tit!="Dr")))
{mess+="\Male gender is not compatible with title chosen"};

if ((document.applyform.Sex[1].checked == true)&&(tit=="Mr"))
{mess+="\Female gender is not compatible with title chosen"};


if (ValSex('SxImg')==false){mess+="\nGender not selected"};
if (ValMS('MSImg')==false){mess+="\nMarital Status not selected"};

if (CheckPresent(document.applyform.HomePhoneCode,'HPhnImg')==false)
{mess+="\nHome Phone Area Code not entered"}
else
{if (CheckNum(document.applyform.HomePhoneCode.value)==false)
{mess+="\nHome Phone Area Code must be numeric characters only"}
else
{if
((rightTrim(document.applyform.HomePhoneCode.value)<3)||(rightTrim(document.applyform.HomePhoneCode.value)>5))
{mess+="\nHome Phone Area code must be 3 to 5 characters"}}}
;

if (CheckPresent(document.applyform.HomePhoneNo,'HPhnImg')==false)
{mess+="\nHome Phone Number not entered"}
else
{if (CheckNum(document.applyform.HomePhoneNo.value)==false)
{mess+="\nHome Phone Number must be numeric characters only"}
else
{if ((rightTrim(document.applyform.HomePhoneNo.value)<5)||(rightTrim(document.applyform.HomePhoneNo.value)>8))
{mess+="\nHome Phone Number must be 5 to 8 characters"}}}
;


if (CheckPresent(document.applyform.WorkPhoneCode,'')==true)
{if (CheckNum(document.applyform.WorkPhoneCode.value)==false)
{mess+="\nWork Phone Area Code must be numeric characters only"}
else
{if ((rightTrim(document.applyform.WorkPhoneCode.value)<3)||(rightTrim(document.applyform.WorkPhoneCode.value)>5))
{mess+="\nWork Phone Area code must be 3 to 5 characters"}}}
;
if (CheckPresent(document.applyform.WorkPhoneNo,'')==true)
{if (CheckNum(document.applyform.WorkPhoneNo.value)==false)
{mess+="\nWork Phone Number must be numeric characters only"}
else
{if ((rightTrim(document.applyform.WorkPhoneNo.value)<5)||(rightTrim(document.applyform.WorkPhoneNo.value)>8))
{mess+="\nWork Phone Number must be 5 to 8 characters"}}}
;



if ((CheckPresent(document.applyform.MobilePhoneCode,'')==true)||(CheckPresent(document.applyform.MobilePhoneNo,'')==true))
{if (CheckNum(document.applyform.MobilePhoneCode.value)==false)
{mess+="\nMobile Phone Area Code must be numeric characters only"}
else
{if ((rightTrim(document.applyform.MobilePhoneCode.value)<5)||(rightTrim(document.applyform.MobilePhoneCode.value)>5))
{mess+="\nMobile Phone Area code must be 5 characters"}}}
;


if (CheckPresent(document.applyform.MobilePhoneNo,'')==true)
{if (CheckNum(document.applyform.MobilePhoneNo.value)==false)
{mess+="\nMobile Phone Number must be numeric characters only"}
else
{if ((rightTrim(document.applyform.MobilePhoneNo.value)<6)||(rightTrim(document.applyform.MobilePhoneNo.value)>7))
{mess+="\nMobile Phone Number must be 6 to 7 characters"}}}
;

if (CheckPresent(document.applyform.PhoneChoice,'HPhnCh')==false){mess+="\nPreferred Phone Number Choice not entered"};

if ((document.applyform.PhoneChoice.value=='Work')&&(document.applyform.WorkPhoneNo.value.length==0))
{mess+="\nWork number selected as preferred number but it was not entered"};
if ((document.applyform.PhoneChoice.value=='Mobile')&&(document.applyform.MobilePhoneNo.value.length==0))
{mess+="\nMobile number selected as preferred number but it was not entered"};

if (document.applyform.PhoneChoice.value=='Select')
{mess+="\nTelephone number choice not specified"};

if (CheckDoB('DoBDDImg')==false){mess+="\nDate of Birth is not a valid date"};

if (CheckPresent(document.applyform.Occupation,'OccImg')==false){mess+="\nOccupation not entered"};

if (echeck(document.applyform.HomeEmailAddress.value)==false)
{mess+=("\n"+emailCheck(document.applyform.HomeEmailAddress.value))}
else
{if (document.applyform.HomeEmailAddress.value != document.applyform.HomeEmailConfirm.value)
{mess+="\nEmail Address and Email Confirmation do not match"}}
;
if (CheckPresent(document.applyform.HomeEmailConfirm,'ConfImg')==false){mess+="\nConfirmation Email Address not entered"};


if ( document.applyform.EmailAcct[0].checked == true)
{
if (rightTrim(document.applyform.MailBoxNme.value)<7)
{mess+="\nMailbox Name must have at least 7 characters"}

var match=new RegExp("^[a-z][a-z0-9_]*$")
if (match.test(document.applyform.MailBoxNme.value)==false)
{mess+="\nMailbox Name may only use characters a to z, 0 to 9 and '_' and must start with a letter"}

var match=new RegExp("wewin","i")
if (match.test(document.applyform.MailBoxNme.value)==true)
{mess+="\nMailbox Name may not contain the word 'wewin'"}

};


if (document.applyform.EmailAcct[1].checked == true)
{
if (compemailCheck(document.applyform.ExistingCompEmail.value)!="")
{
mess+=("\n"+compemailCheck(document.applyform.ExistingCompEmail.value))
}
var match=new RegExp("wewin","i")
if (match.test(document.applyform.ExistingCompEmail.value)==true)
{mess+="\nEmail address may not contain the word 'wewin'"}


};

if ((document.applyform.MailBoxNme.value!="")&&(document.applyform.ExistingCompEmail.value!=""))
{mess+="\nPlease enter either a Mailbox or an Existing Email Address, not both"};

if (CheckPresent(document.applyform.HouseNumber,'HsNoImg')==false){mess+="\nHouse Number not entered"};
if (CheckPresent(document.applyform.StreetName,'StNmImg')==false){mess+="\nStreet Name not entered"};
if (CheckPresent(document.applyform.Town,'TownImg')==false){mess+="\nTown name not entered"};
if (CheckPresent(document.applyform.County,'CntyImg')==false){mess+="\nCounty not entered"};
if (CheckPresent(document.applyform.Country,'CntryImg')==false){mess+="\nCountry not entered"};
if (CheckCheckBox(document.applyform.AddrConf,'AddrConfImg')==false){mess+="\nPlease confirm this address is residential"};
if (CheckCheckBox(document.applyform.AddrConf2,'AddrConf2Img')==false){mess+="\nPlease confirm no other members live at this address"};
if (document.applyform.Country.value=='Select')
{mess+="\nCountry within UK not specified"};

if (CheckPresent(document.applyform.PostCodeIn,'PCdeImg')==false)
{mess+="\nFirst part of Postcode not entered"}
else
{if ((rightTrim(document.applyform.PostCodeIn.value)<2)||(rightTrim(document.applyform.PostCodeIn.value)>4)){
mess+="\nFirst part of Postcode must be 2 to 4 characters"}
};
if (CheckPresent(document.applyform.PostCodeOut,'PCdeImg')==false){mess+="\nLast part of Postcode not entered"}
else 
{if ((rightTrim(document.applyform.PostCodeOut.value)<3)||(rightTrim(document.applyform.PostCodeOut.value)>3))
{mess+="\nLast part of Postcode must be exactly 3 characters"}
};

//var match=new RegExp("^[A-Z]{1,2}[0-9]{1,2}[A-Z]? [0-9]{1,2}[A-Z]{1,3}$","i")
//if (match.test(rightTrim(document.applyform.PostCodeIn.value)+" "+rightTrim(document.applyform.PostCodeOut.value))==false)
//{mess+="\nPostcode format appears to be incorrect"};


if (document.applyform.TandCread.checked==false){mess+="\nYou must agree to the Terms and Conditions"}


if (mess=="")
{return true}
else
{
alert ("We found some errors!\nPlease correct the details below:\n"+mess);
return false;
}};

function valcon()
{
var mess="";
if (CheckPresent(document.applyform.Name,'NmImg')==false)
{mess+="\nName not entered"}
else
{if (document.applyform.Name.value.length<4)
{mess+="\nYour name must have at least 4 characters"}
};

if (echeck(document.applyform.HomeEmailAddress.value)==false)
{mess+=("\n"+emailCheck(document.applyform.HomeEmailAddress.value))};
if (CheckPresent(document.applyform.Message,'MessImg')==false){mess+="\nNo Message entered"};

if (mess=="")
{
return true}
else
{
alert ("We found some errors!\nPlease correct the details below:\n"+mess);
return false}
}

function valref()
{
var mess="";
if (CheckPresent(document.applyform.Name,'NmImg')==false)
{mess+="\nName not entered"}
else
{if (document.applyform.Name.value.length<4)
{mess+="\nYour name must have at least 4 characters"}
};

if (echeck(document.applyform.HomeEmailAddress.value)==false)
{mess+=("\n"+emailCheck(document.applyform.HomeEmailAddress.value))};
if (CheckPresent(document.applyform.MembershipNumber,'MemImg')==false){mess+="\nYour membership number has not been entered"};
if (CheckPresent(document.applyform.Message,'MessImg')==false){mess+="\nYour friend's details have not been entered"};

if (mess=="")
{
return true}
else
{
alert ("We found some errors!\nPlease correct the details below:\n"+mess);
return false}
}

function giftref()
{
var mess="";
if (CheckPresent(document.applyform.Name,'NmImg')==false)
{mess+="\nName not entered"}
else
{if (document.applyform.Name.value.length<6)
{mess+="\nYour name must have at least 6 characters"}
};
if (CheckPresent(document.applyform.FriendName,'FmImg')==false)
{mess+="\nYour friend's name has not been entered"}
else
{if (document.applyform.FriendName.value.length<6)
{mess+="\nYour friend's name must have at least 6 characters"}
};

if (echeck(document.applyform.HomeEmailAddress.value)==false)
{mess+=("\n"+emailCheck(document.applyform.HomeEmailAddress.value))};

if (fecheck(document.applyform.FriendEmailAddress.value)==false)
{mess+=("\n"+femailCheck(document.applyform.FriendEmailAddress.value))};

if ((document.applyform.HomeEmailAddress.value==document.applyform.FriendEmailAddress.value)&&(document.applyform.FriendEmailAddress.value!=""))
{mess+="\nThe email addresses must be different"};


if (mess=="")
{
return true}
else
{
alert ("We found some errors!\nPlease correct the details below:\n"+mess);
return false}
}


function valfr()
{
var mess="";
if (CheckPresent(document.applyform.Name,'NmImg')==false)
{mess+="\nYour name has not been entered"}
else
{if (document.applyform.Name.value.length<4)
{mess+="\nYour name must have at least 4 characters"}
};
if (CheckPresent(document.applyform.FriendName,'FmImg')==false)
{mess+="\nYour friend's name has not been entered"}
else
{if (document.applyform.FriendName.value.length<4)
{mess+="\nYour friend's name must have at least 4 characters"}
};

if (echeck(document.applyform.HomeEmailAddress.value)==false)
{mess+=("\n"+emailCheck(document.applyform.HomeEmailAddress.value))};

if (mess=="")
{
return true}
else
{
alert ("We found some errors!\nPlease correct the details below:\n"+mess);
return false}
}

<!-- This script and many more are available free online at -->

<!-- The JavaScript Source!! http://javascript.internet.com -->

<!-- Original:  Nick Baker -->

<!-- Begin

// Cookie Functions  ////////////////////  (:)



// Set the cookie.

// SetCookie('your_cookie_name', 'your_cookie_value', exp);



// Get the cookie.

// var someVariable = GetCookie('your_cookie_name');



var expDays = 100;

var exp = new Date(); 

exp.setTime(exp.getTime() + (expDays*24*60*60*1000));



function getCookieVal (offset) {  

	var endstr = document.cookie.indexOf (";", offset);  

	if (endstr == -1) { endstr = document.cookie.length; }

	return unescape(document.cookie.substring(offset, endstr));

}



function GetCookie (name) {  

	var arg = name + "=";  

	var alen = arg.length;  

	var clen = document.cookie.length;  

	var i = 0;  

	while (i < clen) {    

		var j = i + alen;    

		if (document.cookie.substring(i, j) == arg) return getCookieVal (j);    

		i = document.cookie.indexOf(" ", i) + 1;    

		if (i == 0) break;   

	}  

	return null;

}



function SetCookie (name, value) {  

	var argv = SetCookie.arguments;  

	var argc = SetCookie.arguments.length;  

	var expires = (argc > 2) ? argv[2] : null;  

	var path = (argc > 3) ? argv[3] : null;  

	var domain = (argc > 4) ? argv[4] : null;  

	var secure = (argc > 5) ? argv[5] : false;  

	document.cookie = name + "=" + escape (value) + 

	((expires == null) ? "" : ("; expires=" + expires.toGMTString())) + 

	((path == null) ? "" : ("; path=" + path)) +  

	((domain == null) ? "" : ("; domain=" + domain)) +    

	((secure == true) ? "; secure" : "");

}



// cookieForms saves form content of a page.



// use the following code to call it:

//  <body onLoad="cookieForms('open', 'form_1', 'form_2', 'form_n')" onUnLoad="cookieForms('save', 'form_1', 'form_2', 'form_n')">



// It works on text fields and dropdowns in IE 5+

// It only works on text fields in Netscape 4.5





function cookieForms() {  

	var mode = cookieForms.arguments[0];

	

	for(f=1; f<cookieForms.arguments.length; f++) {

		formName = cookieForms.arguments[f];

		

		if(mode == 'open') {	

			cookieValue = GetCookie('saved_'+formName);

			if(cookieValue != null) {

				var cookieArray = cookieValue.split('#cf#');

				

				if(cookieArray.length == document[formName].elements.length) {

					for(i=0; i<document[formName].elements.length; i++) {

					

						if(cookieArray[i].substring(0,6) == 'select') { document[formName].elements[i].options.selectedIndex = cookieArray[i].substring(7, cookieArray[i].length-1); }

						else if((cookieArray[i] == 'cbtrue') || (cookieArray[i] == 'rbtrue')) { document[formName].elements[i].checked = true; }

						else if((cookieArray[i] == 'cbfalse') || (cookieArray[i] == 'rbfalse')) { document[formName].elements[i].checked = false; }

						else { document[formName].elements[i].value = (cookieArray[i]) ? cookieArray[i] : ''; }

					}

				}

			}

		}

				

		if(mode == 'save') {	

			cookieValue = '';

			for(i=0; i<document[formName].elements.length; i++) {

				fieldType = document[formName].elements[i].type;

				

				if(fieldType == 'password') { passValue = ''; }

				else if(fieldType == 'checkbox') { passValue = 'cb'+document[formName].elements[i].checked; }

				else if(fieldType == 'radio') { passValue = 'rb'+document[formName].elements[i].checked; }

				else if(fieldType == 'select-one') { passValue = 'select'+document[formName].elements[i].options.selectedIndex; }

				else { passValue = document[formName].elements[i].value; }

			

				cookieValue = cookieValue + passValue + '#cf#';

			}

			cookieValue = cookieValue.substring(0, cookieValue.length-4); // Remove last delimiter

			

			SetCookie('saved_'+formName, cookieValue, exp);		

		}	

	}

}

//  End -->

// -----------------------------------------------------//
// SAVE FORM FIELD SELECTIONS IN COOKIES 		//
// formcookie_saverestore.js				//
// Written by Tony Davis, T. Davis Consulting, Inc.	//
// Date written: September 27, 2005			//
// Email: tony@tdavisconsulting.com			//
// Web site: http://www.tdavisconsulting.com		//
// -----------------------------------------------------//

// instructions:
// ------------
// Change <BODY>
// to <BODY onunload="saveSelections(document.forms[0])"> and
// Change </FORM>
// TO </FORM><SCRIPT language=JavaScript type="">loadSelections(document.forms[0]);</SCRIPT>
// see a working example at: http://www.tdavisconsulting.com/formcookie
//

//
// ------------------------------------------------
// This function will concatentate all the fields in
// in the form into one string, delimited by a PIPE
// symbol, into one cookie. The cookie name is the
// same name as the form name. ALL fields are saved.
// ------------------------------------------------
//


function saveSelections(frm) {
		var setvalue;
		var fieldType;
		var index;
		var formname = frm.name;

		// Expire cookie in 999 days.
		var today = new Date();
		var exp   = new Date(today.getTime()+999*24*60*60*1000);

		var string = "formname=" + formname + "|";
		var cookieName = formname;

		//alert(exp);
		//alert(formname);

		var n = frm.length;
		for (i = 0; i < n; i++)

		{
			e 	    = frm[i].name;
			fieldValue  = frm[i].value;
			fieldType   = frm[i].type;

			//alert(e);
			//alert(fieldType);
			//alert(fieldValue);

			//
			// RADIO BUTTON
			//
			if (fieldType == "radio") {
			//alert(frm.elements[e].length);
				for (x=0; x < frm.elements[e].length; x++) {
					if (frm.elements[e][x].checked)
					{
					index = x
					}
				}
			string = string + index + "\|";
			}

			//
			// TEXT, TEXTAREA, and DROPDOWN
			//
			if ((fieldType == "text") ||
			    (fieldType == "textarea") ||
			    (fieldType == "select-one"))
			{
		    	string = string + frm.elements[e].value + "\|";
		    	//alert("text");
			}

			//
			// CHECKBOX
			//
			if (fieldType == "checkbox")
			{
				if (frm.elements[e].checked==true) {
					var setvalue = "1";
					}
				if (frm.elements[e].checked==false) {
					var setvalue = "0";
					}
			string = string + setvalue + "\|";
			//alert("checkbox");
			}

			//
			// HIDDEN field
			//
			//if (fieldType == "hidden")
			//{
		    	//string = string + frm.elements[e].value + "\|";
		    	//alert("text");
			//}
		}

//alert(string);
setCookie(cookieName, string, exp); }

//
// LOAD FORM FIELD SELECTIONS FROM SAVED COOKIES
//

function loadSelections(frm) {
var e;
var z;
var x;
var cookieName;
var fieldArray;
var fieldValues;
var fieldValue;

var formname = frm.id;

// Retrieve form elements from cookie and split into array.

cookieName  = formname;
fieldValues = getCookie(cookieName);
fieldArray  = fieldValues.split("\|");

//alert(fieldArray);
//alert(fieldArray[0]);
//alert(fieldArray[1]);
//alert(fieldArray[2]);
//alert(fieldArray[3]);

		var n = frm.length;
		for (i = 0; i < n; i++) {
			e = frm[i].name;
			z = i;
			z++;
			var fieldType  = frm[i].type;
			var fieldValue = fieldArray[z];

			//
			// TEXT, TEXTAREA, and DROPDOWN
			//
			if ((fieldType == "text") ||
			    (fieldType == "textarea") ||
			    (fieldType == "select-one"))
			{
		    	frm.elements[e].value = fieldValue;
		    	//alert(e);
		    	//alert(fieldValue);
			}

			// CHECKBOX
			//
			if (fieldType == "checkbox")
			{
				fld_checkbox = fieldValue;
				if (fld_checkbox == "1") {
					frm.elements[e].checked = true;
				}
				else{
					frm.elements[e].checked = false;
				}
			}

			// RADIO BUTTON
			//
			if (fieldType == "radio") {
				x = fieldValue;
				//alert(x);
				frm.elements[e][x].checked = true;
			}

			//
			// HIDDEN field
			//
			//if (fieldType == "hidden")
			//{
		    	//frm.elements[e].value = fieldValue;
		        //}
		}
}

/// COOKIE FUNCTIONS

function setCookie(name, value, expires, path, domain, secure) {
document.cookie= name + "=" + escape(value) +
((expires) ? "; expires=" + expires.toGMTString() : "") +
((path) ? "; path=" + path : "") +
((domain) ? "; domain=" + domain : "") +
((secure) ? "; secure" : "");
}

function getCookie(name) {
var dc = document.cookie;
var prefix = name + "=";
var begin = dc.indexOf("; " + prefix);
if (begin == -1) {
begin = dc.indexOf(prefix);
if (begin != 0) return null;
} else {
begin += 2;
}
var end = document.cookie.indexOf(";", begin);
if (end == -1) {
end = dc.length;
}
return unescape(dc.substring(begin + prefix.length, end));
}






