// JavaScript Document

function isValidEmail(str) {
   return (str.indexOf(".") > 0) && (str.indexOf("@") > 0);
}

function validate_contactform()
{
  var message = '';

  if (!document.contactform.fname.value) { message += "First Name\n"; }
  if (!document.contactform.lname.value) { message += "Last Name\n"; }
  if (!document.contactform.email.value) { message += "Email\n"; }
  if (!document.contactform.confirm_email.value) { message += "Confirm Email\n"; }
  if (!document.contactform.zip.value) { message += "Zip\n"; }
  if (!document.contactform.phone.value) { message += "Phone\n"; }

  if (document.contactform.email.value != document.contactform.confirm_email.value) {
      message += "Email and Confirm Email do not match";
  }
  if (document.contactform.email.value) {
    if (!isValidEmail(document.contactform.email.value)) {
      message += "Invalid Email Format\n";
    }
  }

  if (message.length) {
    alert("Please complete the following required fields:\n\n"+message);
    return false;
  }
  document.contactform.submit();
}

function validate_quoteform()
{
  var message = '';

  if (!document.quoteform.fname.value) { message += "First Name\n"; }
  if (!document.quoteform.lname.value) { message += "Last Name\n"; }
  if (!document.quoteform.email.value) { message += "Email\n"; }

  if (document.quoteform.email.value) {
    if (!isValidEmail(document.quoteform.email.value)) {
      message += "Invalid Email Format\n";
    }
  }

  if (message.length) {
    alert("Please complete the following required fields:\n\n"+message);
    return false;
  }
  document.quoteform.submit();
}
