//********************************************************************************
//********************************************************************************
// Version 01.00 - 28/04/2006
//
// This file contains some routines specific to this application
//********************************************************************************
//********************************************************************************


//********************************************************************************
//    Author: Steve Betts
//      Date: Apr 2006
//      Desc: Validate the form fields.
//            This master function calls a series of sub-functions, each of which
//            checks a single form field.
//
// Amendment:
//********************************************************************************
function ValidateForm(p_oForm, p_sAction) {

 if (p_sAction == "20SUBMIT") {
    var why = "";
    why += CheckName(p_oForm.eName.value);
    why += CheckEmail(p_oForm.eEmail.value);
    why += CheckSubject(p_oForm.eSubject.value);
    why += CheckMessage(p_oForm.eMessage.value);

    if (why != "") {
       alert(why);
       return false;
    }
 }

 return true;
}


function CheckName (p_sValue) {
 var sError = "";
 var sValue = Trim(p_sValue);

 if (sValue == "") {
    sError = "No name has been entered.\n";
 }
 return sError;
}       

function CheckEmail (p_sValue) {
 var nValid = 0;
 var sError = "";
 var sValue = Trim(p_sValue);
  
 if (sValue == "") {
    sError = "Email address is missing.\n";
 }
 else {
    nValid = VerifyEmailFormat(p_sValue);
    if (nValid != 0) sError = "Email address has an invalid format.\n";
 }
 return sError;
}       

function CheckSubject (p_sValue) {
 var sError = "";
 var sValue = Trim(p_sValue);

 if (sValue == "Please choose a subject...") {
    sError = "Please choose an appropriate subject.\n";
 }
 return sError;
}       

function CheckMessage (p_sValue) {
 var sError = "";
 var sValue = Trim(p_sValue);

 if (sValue == "Please write details here..." || sValue == "" ) {
    sError = "Please enter a message.\n";
 }

 if (sValue.length > 1000) {
    sError = "Maximum message size is 1000 characters yours is " + sValue.length + " characters.\n";
 }

 return sError;
}       


//********************************************************************************
//    Author: Steve Betts
//      Date: Oct 2005
//      Desc: NoEnter
//            Traps the [Enter] key to prevent a form from being submitted
//
// Amendment:
//********************************************************************************
function NoEnter() {
  return !(window.event && window.event.keyCode == 13); 
}


