﻿function validateText ( theField, theValidationText) {

   if ( theField)   {
	  if(theField.value == '')  {
	     validated = false;
                     alert(theValidationText);
	      theField.focus();
	       return (false);
                  }
    }
    return(true);
} 



function validateDropDownText ( theField, theValidationText) {
   if ( theField)  {
           if (  (theField[theField.selectedIndex].text == '' ) ||  (theField[theField.selectedIndex].text == '[Select]' )  || (theField[theField.selectedIndex].text.substring(0,1) == '[' )   ) {
             validated = false;
              alert(theValidationText);
              theField.focus();
              return (false);
           }
    }
     return (true);
} 

//customised for contact us forms, e.g. annual report request, feedback, media, etc.
function validateDropDownSelect ( theField, theValidationText) {
   if ( theField)  {
           if (  (theField[theField.selectedIndex].text == '' ) || (theField[theField.selectedIndex].text.substring(0,6) == 'select' )   ) {
             validated = false;
              alert(theValidationText);
              theField.focus();
              return (false);
           }
    }
     return (true);
} 


function validateNumber ( theField, theValidationText, mandatory) {

     if ( theField ) {
       if (theField.value != '')  {
          // alert ( parseInt (theField.value, 10) + "\n" + theField.value  );
          if (parseInt (theField.value, 10) != theField.value )  {
                    validated = false;
                    alert(theValidationText);
                    theField.focus();
                    return (false);
           }
        }
        else {
            if (mandatory) {
                    validated = false;
                    alert(theValidationText);
                    theField.focus();
                    return (false) ;
            }
        }

     }
     return(true);
} 


function validateMultiValuedCheckBox ( theField, theValidationText) {
   if ( theField)  {
        atLeastOneChecked = false;
        if (theField.length) {
            for (i=0 ; i<theField.length  ; i++  ) {
                 if (theField[i].checked) { atLeastOneChecked=true;}
            }
         }
        else {
               if (theField.checked) { atLeastOneChecked=true;}  
        }
        if (!(atLeastOneChecked)) {
              validated = false;
              if (theValidationText!="") {
                 alert(theValidationText);
                 if (theField.length)
                        theField[0].focus();               
                 else 
                        theField.focus();               
              }
              return (false);
        }
     }
     return (true);
} 

function emailCheck(txt) {
if (txt.indexOf("@")<2){
alert("The email address you have entered is not valid. Please"
+" check the prefix and '@' sign.");
return (false);
  }
if ((txt.indexOf(".com")<5)&&(txt.indexOf(".org")<5)
&&(txt.indexOf(".gov")<5)&&(txt.indexOf(".net")<5)
&&(txt.indexOf(".mil")<5)&&(txt.indexOf(".edu")<5)){
alert("The email address you have entered is not valid. Please"
+" check the suffix for accuracy. (It should include a "
+".com, .edu, .net, .org, .gov or .mil)");
return (false);
  }
return(true);
}


function validateFields()
{
   var theField;
   var theValidationText;
   validated = true;

df = document.forms[0];

if ( (validateMultiValuedCheckBox   (     df.alertServices   , ""  ) )  &&  (validateMultiValuedCheckBox   (     df.alertServices_UNSUBSCRIBE   , ""  ) )  ) {
           alert ("You must select EITHER the service you wish to subscribe to, OR the unsubscribe option.");
           return (false);
}
else if ( (!(validateMultiValuedCheckBox   (     df.alertServices   , ""  ) ))  &&  (!(validateMultiValuedCheckBox   (     df.alertServices_UNSUBSCRIBE   , ""  ) ) )  ) {
           alert ("You must select the Alert Service");
           return (false);
}


if (!(validateText (     df.email     ,     "Email address is a mandatory field."   ) ))
     return (false);

if  (   (df.email.value).indexOf ("@") < 0 ) {
           // document.forms[0].email.focus();
           // alert ("Your email address must include the @ symbol.");
           // return (false);
           document.forms[0].email.value = document.forms[0].email.value + "@";
}


  return(true);

}

function submitForm()
{

   if (validateFields())
       document.forms[0].submit();
}




