﻿function checkWholeForm(contact) {
    var why = "";
    why += checkEmail(contact.email.value);
    why += isEmpty1(contact.name.value);
    why += isEmpty2(contact.telephone.value);
    why += isEmpty3(contact.company.value);
    why += isEmpty4(contact.address.value);
    why += isEmpty5(contact.city.value);
    why += isEmpty6(contact.state.value);
    why += isEmpty7(contact.zip.value);
    why += isEmpty8(contact.country.value);
    why += voltageDropdown(contact.volt.selectedIndex);
    if (why != "") {
       alert(why);
       return false;
    }
return true;
}

// Name Check

function isEmpty1(strng) {
var error = "";
  if (strng.length == 0) {
     error = "You did not enter your Name.\n"
  }
return error;     
}


// Telephone Check

function isEmpty2(strng) {
var error = "";
  if (strng.length == 0) {
     error = "Please enter your Telephone number.\n"
  }
return error;     
}

// Company Check

function isEmpty3(strng) {
var error = "";
  if (strng.length == 0) {
     error = "Please provide your Company name.\n"
  }
return error;     
}

// Address Check

function isEmpty4(strng) {
var error = "";
  if (strng.length == 0) {
     error = "Please enter your Address.\n"
  }
return error;     
}

// City Check

function isEmpty5(strng) {
var error = "";
  if (strng.length == 0) {
     error = "Please enter your City.\n"
  }
return error;     
}

// State Check

function isEmpty6(strng) {
var error = "";
  if (strng.length == 0) {
     error = "Please enter your State.\n"
  }
return error;     
}

// Zip Code Check

function isEmpty7(strng) {
var error = "";
  if (strng.length == 0) {
     error = "Please provide a Zip Code.\n"
  }
return error;     
}

// Country Check

function isEmpty8(strng) {
var error = "";
  if (strng.length == 0) {
     error = "Please enter a Country.\n"
  }
return error;     
}

// Voltage Check

function voltageDropdown(choice) {
    var error = "";
    if (choice == 0) {
       error = "Please select a Voltage.\n";
    }    
return error;
}  

// Email Check

function checkEmail (strng) {
var error="";
if (strng == "") {
   error = "Please enter a Email Address.\n";
}

    var emailFilter=/^.+@.+\..{2,3}$/;
    if (!(emailFilter.test(strng))) { 
       error = "Please enter a valid Email Address.\n";
    }
    else {
//test email for illegal characters
       var illegalChars= /[\(\)\<\>\,\;\:\\\"\[\]]/
         if (strng.match(illegalChars)) {
          error = "This is not a true Email Address.\n";
       }
    }
return error;    
}

