
/**
*
*
*/
function checkWholeForm(form) {
    var why = "";
		why += checkName(form.name.value);
		why += checkCompany(form.company.value);
		why += checkAddress(form.address.value);
		why += checkCity(form.city.value);
		why += checkState(form.state.value);	
		why += checkZip(form.zip.value);	
    why += checkPhone(form.phone.value);
		why += checkEmail(form.email.value);
    if (why != "") {
       alert(why);
       return false;
    }
return true;
}

function checkName(strng) {
	var error = "";
	if (strng == "") {
		error = "You didn't enter your name.\n";
		return error;
	}
	return error;
}

function checkCompany(strng) {
	var error = "";
	if (strng == "") {
		error = "You didn't enter your company.\n";
		return error;
	}
	return error;
}

function checkAddress(strng) {
	var error = "";
	if (strng == "") {
		error = "You didn't enter your address.\n";
		return error;
	}
	return error;
}

function checkCity(strng) {
	var error = "";
	if (strng == "") {
		error = "You didn't enter your city.\n";
		return error;
	}
	return error;
}

function checkState(strng) {
	var error = "";
	if (strng == "default") {
		error = "You didn't select your state.\n";
		return error;
	}
	return error;
}

function checkZip(strng) {
	var valid = "0123456789-";
	var hyphencount = 0;
	var error = "";
	
	if (strng.length == "") {
		error = "You didn't enter your zip.\n";
		return error;
	}
	
	if (strng.length!=5 && strng.length!=10) {
		error = "You entered your zip incorrectly. Use either a 5 digit or 5-4 digit format.\n";
		return error;
	}
	
	for (var i = 0; i < strng.length; i++) {
		temp = "" + strng.substring(i, i+1);
		if (temp == "-") {
			hyphencount++;
		}
		
		if (valid.indexOf(temp) == "-1") {
			error = "Invalid characters in your zip code.  Please try again.\n";
			return error;
		}
		
		if ((hyphencount > 1) || ((strng.length==10) && ""+strng.charAt(5)!="-")) {
			error = "The hyphen should be used with a properly formatted 5-4 digit zip code, ex: '12345-6789'.\n";
			return error;
   	}
	}
	return error;
}

function checkPhone(strng) {
	var error = "";
	if (strng == "") {
		error = "You didn't enter a phone number.\n";
		return error;
	}
	var stripped = strng.replace(/[\(\)\.\-\ ]/g, ''); //strip out acceptable non-numeric characters
	if (isNaN(parseInt(stripped))) {
  	error = "The phone number contains illegal characters.";
		return error;
	}
	if (!(stripped.length == 10)) {
		error = "The phone number is the wrong length. Make sure you included an area code.\n";
		return error;
	}
	return error;
}

function checkEmail(strng) {
	var error = "";
	if (strng == "") {
		error = "You didn't enter an email address.\n"
		return error;
	}
	var emailFilter=/^.+@.+\..{2,3}$/;
	if (!(emailFilter.test(strng))) { 
		error = "Please enter a valid email address.\n";
		return error;
	}
	else {
		var illegalChars= /[\(\)\<\>\,\;\:\\\/\"\[\]]/
		if (strng.match(illegalChars)) {
			error = "The email address contains illegal characters.\n";
			return error;
		}
	}
	return error;
}