/* Form validation functions */

function validate_form(form_id) {
   with (form_id) {
      if (form_id.name=="newsletter") {
         if (validate_email(form_id,"email")==false)
         {email.focus();return false;}
      }
      if (form_id.name=="information") {
         if (validate_email(form_id,"email")==false)
         {email.focus();return false;}
         if (validate_required(question,"Please enter your question.")==false)
         {question.focus();return false;}
      }
   }
}

function validate_required(field,alerttxt) {
   with (field) {
      if (value==null||value=="")
         {alert(alerttxt);return false;}
      else
         {return true;}
   }
}

function validate_email(form_id,email_field) {
   var reg_exp = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
   var addr_field = form_id.elements[email_field];
   var addr_value = addr_field.value;
   if(reg_exp.test(addr_value) == false) {
      alert('Invalid e-mail address.  Please enter a complete address like "john@example.com".');
      return false;
   }
}























/*
============================================================
Script:     Email Address Checker-Validator

Functions:

   Checks name field to see if empty
   Checks e-mail address, which must have:
      - "@" symbol and no spaces
      - one or more good characters before
            and after "@"
      - .xx country code or .com, .net,
            .edu, .mil, .gov, .org at end
   First (em) and second (emx) email addresses
      must be equal and name field must have more
      than one character to pass the script tests

Browsers:   All 4.0 and later browsers

Author:     etLux
============================================================

Put the following form and script in the body of your page:

<font size="2" face="Arial" color="#FF0000">
<form name="TheForm">
<input type="text" name="nm"  size="33"> Your Name
<br><br>
<input type="text" name="em"  size="33"> E-mail address
<br>
<input type="text" name="emx" size="33"> Re-enter to confirm
<br><br>
<input type="button" value="Submit" name="SB" onClick="sendOff();">

<script language="JavaScript1.2">

// (C) 2000 www.CodeLifter.com
// http://www.codelifter.com
// Free for all users, but leave in this  header

var good;
function checkEmailAddress(field) {

// Note: The next expression must be all on one line...
//       allow no spaces, linefeeds, or carriage returns!
var goodEmail = field.value.match(/\b(^(\S+@).+((\.com)|(\.net)|(\.edu)|(\.mil)|(\.gov)|(\.org)|(\..{2,2}))$)\b/gi);

if (goodEmail){
   good = true
} else {
   alert('Please enter a valid e-mail address.')
   field.focus()
   field.select()
   good = false
   }
}

function sendOff(){
   nmcheck = document.TheForm.nm.value
   if (nmcheck.length <1) {
      alert('Please enter your name.')
      return
   }
   good = false
   checkEmailAddress(document.TheForm.em)
   if ((document.TheForm.em.value ==
        document.TheForm.emx.value)&&(good)){
      // This is where you put your action
      // if name and email addresses are good.
      // We show an alert box, here; but you can
      // use a window.location= 'http://address'
      // to call a subsequent html page,
      // or a Perl script, etc.
      alert("Name and email address fields verified good.")
   }
   if ((document.TheForm.em.value !=
          document.TheForm.emx.value)&&(good)){
          alert('Both e-mail address entries must match.')
   }
}
</script>
</form>
</font>

============================================================
*/

