 // JavaScript Document
		
function validateFormOnSubmit(theForm, page) {
   var reason = "";

if (page == "inform") {
  reason += validateEmpty(theForm.Title, "Title");
  reason += validateEmpty(theForm.FirstName, "First Name");
  reason += validateEmpty(theForm.LastName, "Last Name");
  reason += validateEmpty(theForm.Address1, "Address 1");
  reason += validateEmpty(theForm.DOB, "DOB");
  reason += validateEmpty(theForm.Age, "Age");
  reason += validateEmpty(theForm.Where1, "Where1");  
  //reason += validateEmpty(theForm.PostCode, "Post Code");
  //reason += validateEmail(theForm.Email);
  //reason += validateChecked(theForm.inform_sent);
  //reason += validateEmpty(theForm.Information_Request, "Information Request");
  //reason += validateEmpty(theForm.wsp_code, "Image code");
}
else if (page == "press") {
  reason += validateEmpty(theForm.Title, "Title");
  reason += validateEmpty(theForm.FirstName, "First Name");
  reason += validateEmpty(theForm.LastName, "Last Name");
  reason += validateEmpty(theForm.Address1, "Address 1");
  //reason += validateEmpty(theForm.Telephone, "Telephone");
  //reason += validateEmpty(theForm.PostCode, "Post Code");
  //reason += validateEmailC(theForm.Email, theForm.Email2);
  //reason += validateEmpty(theForm.wsp_code, "Image code");
}
else if (page == "rateform") {
	
reason += validateEmptyn(theForm.name, "Name");
reason += validateEmail(theForm.email);
reason += validateEmptyn(theForm.title, "Title");
reason += validateEmptyn(theForm.comment, "Comment");
reason += validateEmpty(theForm.wsp_code, "Image code");

}   
  if (reason != "") {
    alert("Some fields need correction:\n" + reason);
    return false;
  }
  return true;
}
function validateEmpty(fld, field) {
    var error = "";
 
    if (fld.value.length == 0) {
        fld.style.background = '#FEB8BD'; 
		error = field + " has not been filled in.\n"
    } else {
        fld.style.background = 'White';
    }
    return error;  
}

function validateEmptyn(fld, field) {
    var error = "";
 
    if (fld.value.length == 0) {
        fld.style.background = '#FEB8BD'; 
		error = field + " has not been filled in.\n"
    } else {
        fld.style.background = 'White';
    }
	
	   
    return error;  
}

function trim(s)
{
  return s.replace(/^\s+|\s+$/, '');
}
function validateEmail(fld) {
    var error="";
    var tfld = trim(fld.value);                        // value of field with whitespace trimmed off
    var emailFilter = /^[^@]+@[^@.]+\.[^@]*\w\w$/ ;
    var illegalChars= /[\(\)\<\>\,\;\:\\\"\[\]]/ ;
	
	if (fld.value == "") { 
		fld.style.background = '#FEB8BD';
		error = "You didn't enter confrim email.\n";
	} else {
        fld.style.background = 'White';
    }
   
    if (fld.value == "") {
        fld.style.background = '#FEB8BD';
        error = "You didn't enter an email address.\n";
	}  else if (!emailFilter.test(tfld)) {              //test email for illegal characters
        fld.style.background = '#FEB8BD';
        error = "Please enter a valid email address.\n";
    } else if (fld.value.match(illegalChars)) {
        fld.style.background = '#FEB8BD';
        error = "The email address contains illegal characters.\n";
    } else {
        fld.style.background = 'White';
    }
    return error;
}

function validateEmailC(fld, fld2) {
    var error="";
    var tfld = trim(fld.value);                        // value of field with whitespace trimmed off
	var tfld2 = trim(fld2.value); 
    var emailFilter = /^[^@]+@[^@.]+\.[^@]*\w\w$/ ;
    var illegalChars= /[\(\)\<\>\,\;\:\\\"\[\]]/ ;
	
	if (fld2.value == "") { 
		fld2.style.background = 'FEB8BD';
		error = "You didn't enter confrim email.\n";
	} else {
        fld.style.background = 'White';
    }
   
    if (fld.value == "") {
        fld.style.background = 'FEB8BD';
        error = "You didn't enter an email address.\n";
	}  else if (!emailFilter.test(tfld)) {              //test email for illegal characters
        fld.style.background = 'FEB8BD';
        error = "Please enter a valid email address.\n";
    } else if (fld.value.match(illegalChars)) {
        fld.style.background = 'FEB8BD';
        error = "The email address contains illegal characters.\n";
	} else if (fld2.value != fld.value) { 
		fld2.style.background = 'FEB8BD';
		error = "Email address not match.\n";
    } else {
        fld.style.background = 'White';
		fld2.style.background = 'White';
    }
    return error;
}

//function validatePhone(fld) {
    //var error = "";
    //var stripped = fld.value.replace(/[\(\)\.\-\ ]/g, '');    

   //if (fld.value == "") {
        //error = "You didn't enter a phone number.\n";
        //fld.style.background = '#FEB8BD';
    //} else if (isNaN(parseInt(stripped))) {
        //error = "The phone number contains illegal characters.\n";
        //fld.style.background = '#FEB8BD';
    //} else if (!(stripped.length == 10)) {
        //error = "The phone number is the wrong length. Make sure you included an area code.\n";
        //fld.style.background = '#FEB8BD';
    //}
   // return error;
//}


//function validateChecked(fldObj){
	 //var error = "";
     //valCheck = 0;
     //selChoices = -1;
     //for (counter = 0; counter < fldObj.length; counter++){
        //if (fldObj[counter].checked) {
           //selChoices = selChoices + 1;
        //}
     //}
     //if (selChoices < 0){
        //error = "Please check How you would like the information to be sent.\n";
    // } else {
       // valCheck = 1;
    // }
    // return error;
 //}

