function validEmail(email){
  invalidChars = " /:,;";

  if (email ==" "){
    return false;
  }

  for (i=0; i<invalidChars.length; i++){
    badChar = invalidChars.charAt(i);
    if(email.indexOf(badChar,0) > -1){
      return false;
    }
  }

  atPos =email.indexOf("@",1);
  if(atPos ==  -1) {
    return false;
  }

  periodPos = email.indexOf(".", atPos);
  if (periodPos == -1){
    return false;
  }

  if(periodPos+3 > email.length) {
   return false;
  }
  return true;
}

function isANum(str){
  for(i=0;i<str.length;i++){
    ch = str.substring(i,i+1);
    if (ch < "0" || ch > "9"){
      return false;
    }
  }
  return true;
}

function chkForm(formName){

 if (formName.raceName1.value ==""){
   alert("Please enter the field of \"Race Name\"");
   formName.raceName1.focus();
   return false;
 }

 if (formName.horseName.value ==""){
    alert("Please enter the field of \"Name of Horse\"");
    formName.horseName.focus();
    formName.horseName.select();
    return false;
  }
 if (formName.horseCountryFoaled.value ==""){
    alert("Please enter the field of \"Country Foaled\"");
    formName.horseCountryFoaled.focus();
    formName.horseCountryFoaled.select();
    return false;
  }

if (formName.horseAge.value ==""){
    alert("Please enter the field of \"Age\"");
    formName.horseAge.focus();
    formName.horseAge.select();
    return false;
  }

if (formName.horseSex.value ==""){
    alert("Please enter the field of \"Sex\"");
    formName.horseSex.focus();
    formName.horseSex.select();
    return false;
  }

 if (formName.trainerName.value ==""){
    alert("Please enter the name of trainer..");
    formName.trainerName.focus();
    formName.trainerName.select();
    return false;
  }

if (formName.trainerTel.value ==""){
    alert("Please enter the field of \"Telephone\"");
    formName.trainerTel.focus();
    formName.trainerTel.select();
    return false;
  }

if (formName.trainerFax.value =="" && formName.trainerEmailAddress.value ==""){
    alert("Please enter either the field of \"Fax\" or \"Email Address\" of the Trainer." );
    formName.trainerFax.focus();
    formName.trainerFax.select();
    return false;
  }
 
if (!(formName.trainerEmailAddress.value =="")){
  if (!validEmail(formName.trainerEmailAddress.value)){
    alert("Please input a valid Trainer email address..");
    formName.trainerEmailAddress.focus();
    formName.trainerEmailAddress.select();
    return false;
  }    
  }

if (formName.ownerName1.value ==""){
    alert("Please enter the field of \"Name of Owner\"");
    formName.ownerName1.focus();
    formName.ownerName1.select();
    return false;
  }

if (formName.nominee.value ==""){
    alert("Please enter the field of \"Nomination made by\"");
    formName.nominee.focus();
    formName.nominee.select();
    return false;
  }  

  if (!validEmail(formName.emailAddress.value)){
    alert("Please input a valid email address..");
    formName.emailAddress.focus();
    formName.emailAddress.select();
    return false;
  }
 
  return true;
 
}


