// Validate basic company information such as email address, name, company, address, city, state, zip
// For a basic job seeker form, comment out company test.
// -sam 06/29/2009
// HTML code example below.
//<FORM action="http://minnesotajobs.com/someaction.php" method="post" name="frm" onSubmit="return check_form();">
//<INPUT type="text" class="itext" name="comp_contact" size="30" value=""> <b><font color="red" size="2">REQUIRED</font></b>
//<INPUT type="text" class="itext" name="company" size="30" value=""> <b><font color="red" size="2">REQUIRED</font></b>
//<textarea name="address" rows="3" cols="30"></textarea> <b><font color="red" size="2">REQUIRED</font></b>
//<INPUT type="text" class="itext" name="city" size="30" value=""><b><font color="red" size="2">REQUIRED</font></b>
//<INPUT type="text" class="itext" name="province" size="30" value="">  <b><font color="red" size="2">REQUIRED</font></b>
//<INPUT type="text" class="itext" name="postalcode" size="10" value="">  <b><font color="red" size="2">REQUIRED</font></b>
//<INPUT type="text" class="itext" name="phone" size="20" value=""></FONT> <b><font color="red" size="2">REQUIRED</font></b>
//<INPUT type="text" class="itext" name="email" size="30" value=""></FONT> <b><font color="red" size="2">REQUIRED</font></b>
//</form>

function isSTR(val){
        var str = val;
        // Return false if characters are not a-z, A-Z, or a space.
        for (var i = 0; i < str.length; i++){
                var ch = str.substring(i, i + 1);
                if (((ch < "a" || "z" < ch) && (ch < "A" || "Z" < ch)) && ch != ' '){
                       return 1;
                }
        }
        return 0;
}
function isEmail(val)
   {
   // Return false if e-mail field does not contain a '@' and '.' .
   if (val.indexOf ('@',0) == -1 ||
       val.indexOf ('.',0) == -1)
      {
      return 1;
      }
   else
      {
      return 0;
      }
   }

function isNum(str)
   {
   // Return false if characters are not '0-9' or '.' .
   for (var i = 0; i < str.length; i++)
      {
      var ch = str.substring(i, i + 1);
      if ((ch < "0" || "9" < ch) && ch != '.' && ch != '-')
         {
         return 1;
         }
      }
   return 0;
  }

function isPhone(str) {
   // Return false if characters are not '0-9' or '.' .
   for (var i = 0; i < str.length; i++)
      {
      var ch = str.substring(i, i + 1);
      if ((ch < "0" || "9" < ch) && ch != ' ' && ch != '+' && ch != '-' && ch !=')' && ch !='(' && ch !='.')
         {
         return 1;
         }
      }
   return 0;
}
function check_form() {
  var error = 0;
  var error_message = "An error has occurred while processing your information\nPlease make the following corrections:\n\n";
  var company = document.frm.company.value;
  var comp_contact = document.frm.comp_contact.value;
  var address = document.frm.address.value;
  var phone = document.frm.phone.value;
  var email = document.frm.email.value;
  var postalcode = document.frm.postalcode.value;
  var province = document.frm.province.value;
  var city = document.frm.city.value;

      //Validation for COMPANY
   if (company == "" || company.length < 3) {
    error_message = error_message + "*The Company field must contain only characters and must have at least 3 characters.\n";
    error = 1;
   }
      //Validation for Contact Name
   if (comp_contact == "") {
    error_message = error_message + "*Please Provide Contact Name for Company.\n";
    error = 1;
   }
   //Validation for EMAIL
   if (email == "" || email.length < 4 || isEmail(document.frm.email.value)==1) {
    error_message = error_message + "*The E-mail field must have at least 4 characters and must be a valid email address.\n";
    error = 1;
   }
   //Validation for ADDRESS
   if (address == "" || address.length < 3) {
    error_message = error_message + "*The Address field must have at least 3 characters.\n";
    error = 1;
   }
   //Validation for   TELEPHONE
   if (phone == "" || phone.length < 3 || isPhone(document.frm.phone.value)==1) {
    error_message = error_message + "*The Phone field must have at least 3 characters and must have only numbers.\n";
    error = 1;
   }
   var j_sel = 0;
      //Validation for POSTALCODE
   if (postalcode == "" || postalcode.length < 4) {
    error_message = error_message + "*The Zip field must have at least 4 characters.\n";
    error = 1;
   }
     //Validation for CITY
   if (city == "" || city.length < 3) {
    error_message = error_message + "*The City field must have at least 3 characters.\n";
    error = 1;
   }

     //Validation for PROVINCE
   if (province == "" || province.length < 2) {
     error_message = error_message + "*The State field must have at least 2 characters.\n";
     error = 1;
   }

  if (error == 1) {
    alert(error_message);
    return false;
  } else {
    return true;
  }
}


