function validate(theForm){

	var OK = 1;
	var sMsg = 'The following errors occurred:\n';

	if (theForm.enquiry.value == ''){
		sMsg = sMsg + ' - no enquiry message supplied\n';
		theForm.enquiry.focus(); 
		theForm.valid.value = 0;
		OK = 0;
	}
	if (theForm.phone.value == ''){
		sMsg = sMsg + ' - no phone number supplied\n';
		theForm.phone.focus(); 
		theForm.valid.value = 0;
		OK = 0;
	}
	if (theForm.email.value==''){ 
		sMsg = sMsg + ' - no email address supplied\n'; 
		theForm.email.focus(); 
		theForm.valid.value = 0;
		OK = 0;
	}
	if (theForm.email.value != ''){
		if(checkEmail(theForm.email.value) != "") {
			sMsg = sMsg + checkEmail(theForm.email.value);
			theForm.email.focus();
			theForm.valid.value = 0;
			OK = 0;
		}
	}
	if(theForm.lastname.value==''){
		OK = 0;
		sMsg = sMsg + ' - no lastname supplied\n';
		theForm.lastname.focus();
		theForm.valid.value = 0;
	}
	if(theForm.firstname.value==''){
		OK = 0;
		sMsg = sMsg + ' - no firstname supplied\n';
		theForm.firstname.focus();
		theForm.valid.value = 0;
	}

	if (OK==1) {
		theForm.valid.value = 1;
		theForm.submit();
//		return true;
	} else {
		alert(sMsg);
		return false;
	}
}

function validateEmail(theForm){

	var OK = 1;
	var sMsg = 'The following error occurred:\n\n';

	if (theForm.email.value==''){ 
		sMsg = sMsg + ' - no email address supplied\n'; 
		theForm.email.focus(); 
		theForm.valid.value = 0;
		OK = 0;
	}
	if (theForm.email.value != ''){
		if(checkEmail(theForm.email.value) != "") {
			sMsg = sMsg + checkEmail(theForm.email.value);
			theForm.email.focus();
			theForm.valid.value = 0;
			OK = 0;
		}
	}
	if (OK==1) {
		theForm.valid.value = 1;
		return true;
	} else {
		alert(sMsg);
		return false;
	}
}

function checkEmail(strng) {
	var error="";
	if (strng == "") {
	   error = " - no email address supplied\n";
	}

    var emailFilter=/^.+@.+\..{2,3}$/;
    if (!(emailFilter.test(strng))) { 
       error = " - email address supplied is not valid\n";
    }
    else {
		//test email for illegal characters
		var illegalChars= /[\(\)\<\>\,\;\:\\\"\[\]]/
        //"
		if (strng.match(illegalChars)) {
    		error = " - the email address contains illegal characters\n";
		}
    }
	return error;    
}

function validateLogin(oForm){
	var OK = 0;
	var oLoginForm = document.forms[oForm.name];
	var strMessage;
	
	if(OK == 0){
		if(oLoginForm.txtUsername.value == ''){
			OK = 1;
			alert('Please enter your username.');
			oLoginForm.txtUsername.focus();
		}
	}
	
	if(OK == 0){
		if(oLoginForm.txtPassword.value == ''){
			OK = 1;
			alert('Please enter your password.');
			oLoginForm.txtPassword.focus();
		}
	}
	
	if(OK == 0){
		oLoginForm.blnSubmit.value = 1;
		oLoginForm.submit();
	}
}

function checkCookies(obj){
	var cookieEnabled=(navigator.cookieEnabled)? true : false;
	//if not IE4+ nor NS6+
	if (typeof navigator.cookieEnabled=="undefined" && !cookieEnabled){ 
		document.cookie="test";
		cookieEnabled=(document.cookie=="test")? true : false;
		document.cookie=""; 
	}	
	if (!cookieEnabled) {
		alert('This feature requires a cookie to be placed on your computer.\nPlease unblock or enable cookies before using this feature.');		
		obj.checked = false;
	}
}

function requestPass() {
	var forgottenForm = document.forms["forgotten"];
	var forgottenEmail	= forgottenForm.ForgottenPassEmail;
	if (forgottenEmail.value.length == 0) { 
		alert("Please supply email address."); 
		forgottenEmail.focus(); 
	} else {
		if(checkEmail(forgottenEmail.value) != "") {
			alert ("The email address supplied is not valid.");
			forgottenEmail.focus();
		} else {
			forgottenForm.submit();
		}
	}
}

function alertMessage(strType){
	if (strType == 'sentpass'){
		alert('Your password has been successfully\nsent to your registered email address.');
	} else if (strType == 'noemail'){
		alert('The specified email address does not\nexist in the wheretowork.com database.');
	} else if (strType == 'emailexists'){
		alert('The specified email address already exists in the database.\nIf you have forgotten your password you can request\nyour password to be resent to this email address.');
	}
}

function validateRegister(theForm){

	var OK = 1;
	var sMsg = 'Registration failure:\n';
	
	if (theForm.howheard.value == ''){
		sMsg = sMsg + ' - please tell us how you heard about wheretowork.com\n'; 
		theForm.howheard.focus(); 
		theForm.btnSubmit.value = 0;
		OK = 0;
	}

	if (theForm.EducationID.selectedIndex == 0){
		sMsg = sMsg + ' - please select your education level\n';
		theForm.EducationID.focus(); 
		theForm.btnSubmit.value = 0;
		OK = 0;
	}	
	if (theForm.CareerLevelID.selectedIndex == 0){
		sMsg = sMsg + ' - please select your career level\n';
		theForm.CareerLevelID.focus(); 
		theForm.btnSubmit.value = 0;
		OK = 0;
	}	
	if (theForm.ExperienceID.selectedIndex == 0){
		sMsg = sMsg + ' - please select your experience level\n';
		theForm.ExperienceID.focus(); 
		theForm.btnSubmit.value = 0;
		OK = 0;
	}	
	
	if (theForm.WorkStatusID.selectedIndex == 0){
		sMsg = sMsg + ' - please select your employment status\n';
		theForm.WorkStatusID.focus(); 
		theForm.btnSubmit.value = 0;
		OK = 0;
	}	

	if (theForm.CountryID.selectedIndex == 0){ 
	sMsg = sMsg + ' - please select your country of residence\n';
	theForm.CountryID.focus(); 
	theForm.btnSubmit.value = 0;
	OK = 0;
}
	if(theForm.Surname.value==''){
		OK = 0;
		sMsg = sMsg + ' - please confirm your last name\n'; 
		theForm.Surname.focus(); 
		theForm.btnSubmit.value = 0;
	}
	if(theForm.FirstName.value==''){
		OK = 0;
		sMsg = sMsg + ' - please confirm your first name\n';
		theForm.FirstName.focus();
		theForm.btnSubmit.value = 0;
	}
	if (theForm.Email.value==''){ 
		sMsg = sMsg + ' - please confirm your email address\n'; 
		theForm.Email.focus(); 
		theForm.btnSubmit.value = 0;
		OK = 0;
	}
	if (theForm.Email.value != ''){
		if(checkEmail(theForm.Email.value) != "") {
			sMsg = sMsg + checkEmail(theForm.Email.value) + '\n';
			theForm.Email.focus();
			theForm.btnSubmit.value = 0;
			OK = 0;
		}
	}
	if (OK==1) {
		if (!theForm.ReadTerms.checked) {
			sMsg = 'Please check the box stating that you\nhave read our terms and conditions.';
			//This focus method doesnt work here 
			//theForm.sectorFocus.focus();
			theForm.btnSubmit.value = 0;
			OK = 0;
		} 
	}
	
	if (OK==1) {
		theForm.btnSubmit.value = 1;
		theForm.submit();
//		return true;
	} else {
		alert(sMsg);
		return false;
	}
}

function validateRMEventRegister(theForm){

	var OK = 1;
	var sMsg = 'Registration failure:\n';
	
	if(theForm.FirstName.value==''){
		OK = 0;
		sMsg = sMsg + ' - please confirm your first name\n';
		theForm.FirstName.focus();
		theForm.btnSubmit.value = 0;
	}
	if(theForm.Surname.value==''){
		OK = 0;
		sMsg = sMsg + ' - please confirm your last name\n'; 
		theForm.Surname.focus(); 
		theForm.btnSubmit.value = 0;
	}

	if (theForm.Email.value==''){ 
		sMsg = sMsg + ' - please confirm your email address\n'; 
		theForm.Email.focus(); 
		theForm.btnSubmit.value = 0;
		OK = 0;
	}
	if (theForm.Email.value != ''){
		if(checkEmail(theForm.Email.value) != "") {
			sMsg = sMsg + checkEmail(theForm.Email.value) + '\n';
			theForm.Email.focus();
			theForm.btnSubmit.value = 0;
			OK = 0;
		}
	}
	
	if (OK==1) {
		theForm.btnSubmit.value = 1;
		theForm.submit();
	} else {
	  	theForm.Register.disabled=false;
		alert(sMsg);
		return false;
	}
}