//--Form Validation

function doFocusSubmit() {
     document.forms["newsSubmit"].first.focus();
}

function doFocusSubscr() {
     document.forms["newsSubscr"].FName.focus();
}

function validFirst(first) {
     if (first=="") {
         return false;
     }
     return true;
}

function validLast(last) {
     if (last=="") {
         return false;
     }
     return true;
}

function validEmail(email) {
     invalidChars=" /:,;";
     if (email=="") {
         alert("An invalid email address...");
         return false;
     }
     for (i=0; i<invalidChars.length; i++) {
           badChar=invalidChars.charAt(i);
           if (email.indexOf(badChar, 0) !=-1) {
           alert("An invalid email address...");
               return false;
           }
      }
      atPos=email.indexOf("@", 1);
      if (atPos==-1) {
          alert("An invalid email address...");
          return false;
      }
      if (email.indexOf("@", atPos+1) !=-1) {
          alert("An invalid email address...");
          return false;
      }
      periodPos=email.indexOf(".", atPos);
      if (periodPos==-1) {
          alert("An invalid email address...");
          return false;
      }
      if (periodPos+3>email.length) {
          alert("An invalid email address...");
          return false;
      }
     return true;
}

function validPhone(phone) {
     if (phone=="") {
         return false;
     }
     return true;
}

function validCenter(center) {
     if (center=="") {
         return false;
     }
     return true;
}

function validText(text) {
     if (text=="") {
         return false;
     }
     return true;
}

function newsFormSubmit(form) {
     if (!validFirst(form.first.value)) {
         alert("Please enter your first name...");
         form.first.focus();
         form.first.select();
         return false;
     }
     if (!validLast(form.last.value)) {
         alert("Please enter your last name...");
         form.last.focus();
         form.last.select();
         return false;
     }
     if (!validEmail(form.email.value)) {
         alert("Please enter a valid email address...");
         form.email.focus();
         form.email.select();
         return false;
     }
     if (!validPhone(form.phone.value)) {
         alert("Please enter your phone number...");
         form.phone.focus();
         form.phone.select();
         return false;
     }
     if (!validCenter(form.center.value)) {
         alert("Please enter your center affiliation...");
         form.center.focus();
         form.center.select();
         return false;
     }
     if (!validText(form.text.value)) {
         alert("Please type in the news...");
         form.text.focus();
         form.text.select();
         return false;
     }
    return true;
}

/////Newsletter DB functions////////////////////////////////

function validFName(FName) {
     if (FName=="") {
         return false;
     }
     return true;
}
function validLName(LName) {
     if (LName=="") {
         return false;
     }
     return true;
}
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;
      }
      if (Email.indexOf("@", atPos+1) !=-1) {
          return false;
      }
      periodPos=Email.indexOf(".", atPos);
      if (periodPos==-1) {
          return false;
      }
      if (periodPos+3>Email.length) {
          return false;
      }
     return true;
}
function validHow(How) {
     if (How=="") {
         return false;
     }
     return true;
}
function validRName(RefName) {
     if (RefName=="") {
         return false;
     }
     return true;
}
function validRCenter(RefAffiliation) {
     if (RefAffiliation=="") {
         return false;
     }
     return true;
}
function validREmail(RefEmail) {
     invalidChars=" /:,;";
     if (RefEmail=="") {
         return false;
     }
     for (i=0; i<invalidChars.length; i++) {
           badChar=invalidChars.charAt(i);
           if (RefEmail.indexOf(badChar, 0) !=-1) {
               return false;
           }
      }
      atPos=RefEmail.indexOf("@", 1);
      if (atPos==-1) {
          return false;
      }
      if (RefEmail.indexOf("@", atPos+1) !=-1) {
          return false;
      }
      periodPos=RefEmail.indexOf(".", atPos);
      if (periodPos==-1) {
          return false;
      }
      if (periodPos+3>RefEmail.length) {
          return false;
      }
     return true;
}
function validRPhone(RefPhone) {
     if (RefPhone=="") {
         return false;
     }
     return true;
}

function newsFormSubscr(form) {
     if (!validFName(form.FName.value)) {
         alert("Please enter your first name...");
         form.FName.focus();
         form.FName.select();
         return false;
     }
     if (!validLName(form.LName.value)) {
         alert("Please enter your last name...");
         form.LName.focus();
         form.LName.select();
         return false;
     }
     if (!validEmail(form.Email.value)) {
         alert("Please enter a valid email address...");
         form.Email.focus();
         form.Email.select();
         return false;
     }
     if (!validHow(form.How.value)) {
         alert("How did you hear about this newsletter?..");
         form.How.focus();
         form.How.select();
         return false;
     }
     if (!validRName(form.RefName.value)) {
         alert("Please enter the referrer\'s name...");
         form.RefName.focus();
         form.RefName.select();
         return false;
     }
     if (!validRCenter(form.RefAffiliation.value)) {
         alert("Please enter the referrer\'s center...");
         form.RefAffiliation.focus();
         form.RefAffiliation.select();
         return false;
     }
     if (!validREmail(form.RefEmail.value)) {
         alert("Please enter a valid referrer\'s email address...");
         form.RefEmail.focus();
         form.RefEmail.select();
         return false;
     }
     if (!validRPhone(form.RefPhone.value)) {
         alert("Please enter the referrer\'s phone number...");
         form.RefPhone.focus();
         form.RefPhone.select();
         return false;
     }
    return true;
}
//End

// -->
