function validate() {
var defaultEmptyOK = true;
	var title=document.Mem.Title.value;
	var email=document.Mem.Email.value;
	var name=document.Mem.First_Name.value;
	var last_name=document.Mem.Family_Name.value;
	var dob_dd=document.Mem.DOB_dd.value;
	var dob_mm=document.Mem.DOB_mm.value;
	var dob_yyyy=document.Mem.DOB_yyyy.value;
	//var dob=document.Mem.DOB.value;
	var addr1=document.Mem.Address_Line_1.value;
	var addr2=document.Mem.Address_Line_2.value;
	var city=document.Mem.Town.value;
	var post_code=document.Mem.Postcode.value;
	var tel_home=document.Mem.Tel_Home.value;
	var mobile=document.Mem.Mobile.value;
	var tel=document.Mem.Tel.value;
	var sl=document.Mem.Second_Language.value;
	var ipref=document.Mem.Industry_Preference.value;
	var reasons=document.Mem.Reasons.value;
	var salary=document.Mem.Salary.value;
	var notice=document.Mem.Notice.value;
	var nwf=document.Mem.Not_Work_For.value;
	var already=document.Mem.Already_Applied.value;
	var nbr_end=document.Mem.Nbr_Endorsements.value;
	var nbr_hrs=document.Mem.Nbr_Hours.value;
	
	var gotChecked=0;
/*
	
	var tel=document.Mem..value;
	var tel=document.Mem..value;
*/
	var over22_flag	=	document.Mem.Over22;
	var in_work_flag	=	document.Mem.In_Work;
	var eq_op_flag	=	document.Mem.Eq_Op;
	var car_flag	=	document.Mem.Car;
	var dl_flag	=	document.Mem.Driving_Licence;
	var endorsements_flag	= document.Mem.Endorsements;
	var offence_flag	= document.Mem.Offence;
	var pt_flag	=	document.Mem.Part_Time;
	var tmp_flag	=	document.Mem.Temp_Work;
	var cir_flag	=	document.Mem.Circulate;


	//Check if they entered a Title
	if  (isEmpty(title)) {
		alert ("You didn't enter your title.  \nPlease enter Mr/Ms/Mrs/Miss/Other in the box provided.");
		return false;
	}
	//Check if they entered a name
	if  (isEmpty(name)) {
		alert ("You didn't enter your first name.  \nPlease enter your first name in the box provided.");
		return false;
	}
	//Check if they entered a surname
	if  (isEmpty(last_name)) {
		alert ("You didn't enter your family name.  \nPlease enter your  family name in the box provided.");
		return false;
	}
//alert ("O22 is "+over22_flag[0].checked);
	//Radios first, they're all called blah_flag

	// Over22?
	if (over22_flag[0].checked
	|| over22_flag[1].checked) {
		gotChecked=1;
	}
	else {
		alert ("You didn't answer Yes or No to the over 22 question.");
		return false;
	}
	//They said they were under 22 but did they enter anything for DoB?
	if (over22_flag[1].checked) {
		if  (isEmpty(dob_dd)) {
		alert ("You didn't enter your date of birth but you clicked No to the over 22 question.  \nPlease enter your date of birth in the box provided.");
		return false;
		}
		else {
		//They entered something - was it a number?
			if  (!isInteger(dob_dd))
				{alert("Your date of birth is not numeric! \n Please enter your date of a birth as a number, e.g. 21 for 21st. Thanks.");
			return false;
			}
			else {
			//They entered a number, was it in the right range?
				if  (dob_dd>31)
					{alert("Your date of birth is more than 31! \n Please enter your date of a birth as a number, e.g. 21 for 21st. Thanks.");
				return false;
				}
			}
		}
		if  (isEmpty(dob_mm)) {
		alert ("You didn't enter your month of birth but you clicked No to the over 22 question.  \nPlease enter your month of birth in the box provided.");
		return false;
		}
		else {
		//They entered something - was it a number?
			if  (!isInteger(dob_mm))
				{alert("Your month of birth is not numeric! \n Please enter your month of a birth as a number, e.g. 11 for November. Thanks.");
			return false;
			}
			else {
			//They entered a number, was it in the right range?
				if  (dob_mm>12)
					{alert("Your month of birth is more than 12! \n Please enter your month of a birth as a number, e.g. 11 for November. Thanks.");
				return false;
				}
			}
		}
		if  (isEmpty(dob_yyyy)) {
		alert ("You didn't enter your year of birth but you clicked No to the over 22 question.  \nPlease enter your year of birth as 4 digits in the box provided.");
		return false;
		}
		else {
		//They entered something - was it a number?
			if  (!isInteger(dob_yyyy))
				{alert("Your year of birth is not numeric! \n Please enter your year of a birth as a number, e.g. 1990. Thanks.");
			return false;
			}
		}
	}
	
	//Check if they entered an addr
	if  (isEmpty(addr1)) {
		alert ("You didn't enter the first line of your address.  \nPlease enter your address in the box provided.");
		return false;
	}

	//Check if they entered a city
	if  (isEmpty(city)) {
		alert ("You didn't enter a town or city for your address.  \nPlease enter a town or city in the box provided.");
		return false;
	}
	//Check if they entered a company post_code
	if  (isEmpty(post_code)) {
		alert ("You didn't enter your post code.  \nPlease enter your post code in the box provided.");
		return false;
	}
/* Now optional	
	//Check if they entered a phone number
	if  (isEmpty(tel_home)) {
		alert ("You didn't enter a home telephone number.  \nPlease enter a home phone number in the box provided.");
		return false;
	}
	//Check if they entered a phone number
	if  (isEmpty(tel)) {
		alert ("You didn't enter a telephone number (business).  \nPlease enter a phone number in the box provided.");
		return false;
	}

	//Check if they entered an email
	if  (isEmpty(email)) {
		alert ("You didn't enter your email address.  \nPlease enter a valid email in the box provided.");
		return false;
	}
	//Check if they entered a valid email
	if  (!validEmail(email)){
		alert ("You entered an invalid email address.  \nPlease enter a valid email in the box provided.");
		return false;
	}
*/
	//Check if they entered a phone number
	if  (isEmpty(mobile)) {
		alert ("You didn't enter a mobile telephone number.  \nPlease enter a mobile phone number in the box provided.");
		return false;
	}
	//Check if they entered a second language
/* Now optional
	if  (isEmpty(sl)) {
		alert ("You didn't enter anything for second language.  \nPlease enter any second languages or the word None in the box provided.");
		return false;
	}
*/
	//Check if they entered a industry preference
/* Now optional
	if  (isEmpty(ipref)) {
		alert ("You didn't enter anything for industry preference.  \nPlease enter any industry preference or the word None in the box provided.");
		return false;
	}
*/
	// In work>?
	if (in_work_flag[0].checked
	|| in_work_flag[1].checked) {
	}
	else {
		alert ("You didn't answer Yes or No to the in work question.");
		return false;
	}
	if (in_work_flag[0].checked) {
		//Check if they entered a salary.axa20080726 now optional (Beth)
/*
		if  (isEmpty(salary)) {
			alert ("You didn't enter your present salary.  \nPlease enter your salary in the box provided.");
			return false;
		}
*/
		//Check if they entered a Notice
		if  (isEmpty(notice)) {
			alert ("You didn't enter your notice period.  \nPlease enter the length of notice required in the box provided.");
			return false;
		}
	}
	//Check if they entered a not work for
/* Now optional
	if  (isEmpty(nwf)) {
		alert ("You didn't enter any companies you would not work for.  \nPlease enter any companies or the word None in the box provided.");
		return false;
	}
*/
/* Now optional
	//Check if they entered a alreay applied to
	if  (isEmpty(already)) {
		alert ("You didn't enter any companies you have already applied to.  \nPlease enter any comapnies applied to or the word None in the box provided.");
		return false;
	}
*/
	// licence?
	if (dl_flag[0].checked
	|| dl_flag[1].checked) {
		gotChecked=1;
	}
	else {
		alert ("You didn't answer Yes or No to the driving licence question.");
		return false;
	}
	// car?
	if (!(car_flag[0].checked
	|| car_flag[1].checked)) {
		alert ("You didn't answer Yes or No to the car question.");
		return false;
	}
	// Endorsements?
	if (!(endorsements_flag[0].checked
	|| endorsements_flag[1].checked)) {
		alert ("You didn't answer Yes or No to the Endorsements question.");
		return false;
	}
	//They said Yes but did they enter anything for number of endorsements?
	if (endorsements_flag[0].checked) {
		if  (isEmpty(nbr_end)) {
		alert ("You didn't enter a number of endorsements but you clicked Yes to the Endorsements question.  \nPlease enter the number of driving licence endoresements you have in the box provided.");
		return false;
		}
		else {
	//They entered something - was it a number?
			if  (!isInteger(nbr_end))
				{alert("The number of driving licence endoresements is not numeric! \n Please enter the number of driving licence endoresements you have in the box provided. Thanks.");
			return false;
			}
		}
	}
	// part time?
	if (!(pt_flag[0].checked
	|| pt_flag[1].checked)) {
		alert ("You didn't answer Yes or No to the part time question.");
		return false;
	}
	//They said Yes but did they enter anything for number of hours?
	if (pt_flag[0].checked) {
		if  (isEmpty(nbr_hrs)) {
		alert ("You didn't enter a number of hours but you clicked Yes to the Part time question.  \nPlease enter the number of hours part time work in the box provided.");
		return false;
		}
		else {
	//They entered something - was it a number?
			if  (!isInteger(nbr_end))
				{alert("The number of driving licence endoresements is not numeric! \n Please enter the number of driving licence endoresements you have in the box provided. Thanks.");
			return false;
			}
		}
	}
	// temporary?
	if (!(tmp_flag[0].checked
	|| tmp_flag[1].checked)) {
		alert ("You didn't answer Yes or No to the temporary work question.");
		return false;
	}
	// circulate?
	if (!(cir_flag[0].checked
	|| cir_flag[1].checked)) {
		alert ("You didn't answer Yes or No to the circulate your details question.");
		return false;
	}
	// crim?
	if (!(offence_flag[0].checked
	|| offence_flag[1].checked)) {
		alert ("You didn't answer Yes or No to the criminal offence question.");
		return false;
	}
/*
	if (agree_tacs_flag.checked==false) {
	alert("Please indicate you have read and accept the terms and conditions by clicking the box at the end of the form");
	return false;
	}

	if  (!isInteger(tel))
		{alert("Your telephone number is not numeric! \n Please enter your phone number.  Thanks.");
		return false;
	}
	if  (!isInteger(Number))
		{alert("Your scratchcard ticket number is not numeric! \n Please enter the number revealed by the scratchcard above.  Thanks.");
		return false;
	}
*/
	//alert ("here "+card+name+post_code+r);
return;



}

function validEmail(email) {
	var cLength 	= email.length;
//alert ("We are "+cLength+email);
	//Must be at least 3 long
	if (cLength < 4) {
		return false;
	}
	var hasAt=email.indexOf('@');
	var hasFS=email.indexOf('.');
	//alert("tring at"+hasAt+hasFS );
	if (hasAt == -1) {
		//alert ("No at! ");
		return false;
	}
	if (hasFS == -1) {
		//alert ("No at! ");
		return false;
	}
return true;
}


function strToZero(anyval) {
     anyval = ""+anyval
     if (anyval < "0" || anyval > "999999999999999999999")
	return true;
     else
	return false;
}

// Check for a blank field
function isFieldBlank(theField) {
//alert("got "+theField);
        if(theField.value == "")
	  return true;
        else
	alert("ret false "+theField);
            return false;
}

// Check for a valid numeric range
function isInRange(theMin, theMax, theField) {

//	theMax++;
        if( (theField >=theMin)
	&&  (theField <= theMax) ) {

		  return true;
	}
        else {
//		alert ("date is NOT in range  "+theField +theMin+theMax );
            return false;
	}
}

// Check whether string s is empty.

function isEmpty(s)
{   return ((s == null) || (s.length == 0))
}

// isInteger (STRING s [, BOOLEAN emptyOK])
//
// Returns true if all characters in string s are numbers.
//
// Accepts non-signed integers only. Does not accept floating
// point, exponential notation, etc.
//
// We don't use parseInt because that would accept a string
// with trailing non-numeric characters.
//
// By default, returns defaultEmptyOK if s is empty.
// There is an optional second argument called emptyOK.
// emptyOK is used to override for a single function call
//      the default behavior which is specified globally by
//      defaultEmptyOK.
// If emptyOK is false (or any value other than true),
//      the function will return false if s is empty.
// If emptyOK is true, the function will return true if s is empty.
//
// EXAMPLE FUNCTION CALL:     RESULT:
// isInteger ("5")            true
// isInteger ("")             defaultEmptyOK
// isInteger ("-5")           false
// isInteger ("", true)       true
// isInteger ("", false)      false
// isInteger ("5", false)     true

function isInteger (s)

{   var i;

    if (isEmpty(s))
       if (isInteger.arguments.length == 1) return true;
       else return (isInteger.arguments[1] == true);

    // Search through string's characters one by one
    // until we find a non-numeric character.
    // When we do, return false; if we don't, return true.

    for (i = 0; i < s.length; i++)
    {
        // Check that current character is number.
        var c = s.charAt(i);

        if (!isDigit(c)) return false;
    }

    // All characters are numbers.
    return true;
}

// Returns true if character c is a digit
// (0 .. 9).

function isDigit (c)
{   return ((c >= "0") && (c <= "9"))
}


//}
