// JavaScript Document
//Form Validator and checker by Reneiro N. Matarranz
//(c) 2004 -- Reneiro N. Matarranz

function validate() {
  firstName=document.contactFrm.firstName.value;
  lastName=document.contactFrm.lastName.value;
  messageSubject=document.contactFrm.messageSubject.value;
  messageContents=document.contactFrm.messageContents.value;
  phoneNumber=document.contactFrm.phoneNumber.value;
  emailAddress=document.contactFrm.emailAddress.value;
  process_app=document.contactFrm.process_app.value;

  if (firstName=='') {
    alert('Please enter your First Name on the \"First Name\" field.');
    document.contactFrm.firstName.focus();
    document.contactFrm.firstName.select();
    document.contactFrm.firstName.style.backgroundColor='yellow';
    return false;
  }
  else if (lastName=='') {
    alert('Please enter your Last Name on the \"Last Name\" field.');
    document.contactFrm.lastName.focus();
    document.contactFrm.lastName.select();
    document.contactFrm.lastName.style.backgroundColor='yellow';
    return false;
  }
  else if (!/^[1-9]\d{2}\s?\d{3}\d{4}$/.test(phoneNumber)) {
    alert("You have entered an invalid US phone number in the \"Phone Number\" field.");
    document.contactFrm.phoneNumber.focus();
    document.contactFrm.phoneNumber.select();
    document.contactFrm.phoneNumber.style.backgroundColor='yellow';
    return false;
  }
  else if (!/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(emailAddress)){
    alert("You have entered an invalid value in the \"E-mail\" field.");
    document.contactFrm.emailAddress.focus();
    document.contactFrm.emailAddress.select();
    document.contactFrm.emailAddress.style.backgroundColor='yellow';
    return false;
  }
  else if (messageSubject=='') {
    alert('You need to enter a message subject.');
    document.contactFrm.messageSubject.focus();
    document.contactFrm.messageSubject.select();
    document.contactFrm.messageSubject.style.backgroundColor='yellow';
    return false;
  }
  else if (messageContents=='') {
    alert('Please enter a message to be delivered.');
    document.contactFrm.messageContents.focus();
    document.contactFrm.messageContents.select();
    document.contactFrm.messageContents.style.backgroundColor='yellow';
    return false;
  }
  else if (process_app=="0") {
    document.contactFrm.process_app.value="1";
  }
  else {
    event.returnValue=true;
  }
}

function numbersonly(qty, e, dec)
{
  var key;
  var keychar;

  if (window.event)
    key = window.event.keyCode;
  else if (e)
    key = e.which;
  else
    return true;

  keychar = String.fromCharCode(key);
  // control keys
  if ((key==null) || (key==0) || (key==8) || 
    (key==9) || (key==13) || (key==27) )
    return true;

  // numbers
  else if ((("0123456789").indexOf(keychar) > -1))
    return true;

  // decimal point jump
  else if (dec && (keychar == ".")) {
    myfield.form.elements[dec].focus();
    return false;
  }
  else
   return false;
}

function contact() {
  if(document.contactFrm.storeContact.value=="other")
  {
    document.contactFrm.storeOther.disabled=false;
    document.contactFrm.storeOther.value = '';
    document.contactFrm.storeOther.focus();
  }

  if(document.contactFrm.storeContact.value !="other")
  {
    document.contactFrm.storeOther.disabled=true;
    document.contactFrm.storeOther.value = 'Other...';
  }
}

function department_check() {
  if(document.contactFrm.department.value=="other")
  {
    document.contactFrm.departmentOther.disabled=false;
    document.contactFrm.departmentOther.value = '';
    document.contactFrm.departmentOther.focus();
  }

  if(document.contactFrm.department.value !="other")
  {
    document.contactFrm.departmentOther.disabled=true;
    document.contactFrm.departmentOther.value = 'Other...';
  }
}
