

function checkFirstName(str) {
	var error = "";
	if (str == "") {
		error = "Please enter your first name.\n";
	}
	return error;
}

function checkLastName(str) {
	var error = "";
	if (str == "") {
		error = "Please enter your last name.\n";
	}
	return error;
}

function checkCostcoNum(str) {
	var error = "";
	if (str == "") {
    	error = "Please enter your Costco member number.\n";
	}
	else {
    	if (isNaN(str)) {
			error = "Your Costco member number must contain only numbers.\n";
		}
		else {
			if (!(str.length == 12)) {
				error = "Your Costco member number should be 12 digits long.\n";
			}
		}
	} 
	return error;
}

function checkCompany(str) {
	var error = "";
	if (str == "") {
    	error = "Please enter your company name.\n";
	}
	return error;
}

function checkTitle(choice) {
	var error = "";
    if (choice == 0) {
    	error = "Please select your title.\n";
    }    
	return error;
}        

function checkEmail(str) {
	var error="";
	if (str == "") {
		error = "Please enter your email address.\n";
	}
	else {
    	var emailFilter = /^.+@.+\..{2,3}$/;
    	if (!(emailFilter.test(str))) { 
			error = "Please enter a valid email address.\n";
		}
		else {
			var illegalChars = /[\(\)\<\>\,\;\:\\\"\[\]]/
			if (str.match(illegalChars)) {
				error = "Please enter a valid email address.\n";
			}
		}
	}
	return error;    
}

function checkPhone(str) {
	var error = "";
	if (str == "") {
		error = "Please enter your phone number.\n";
	}
	else {
		var stripped = str.replace(/[\(\)\.\-\ ]/g, ''); //strip out acceptable non-numeric characters
    	if (isNaN(stripped)) {
			error = "The phone number contains illegal characters.\n";
		}
		else {
			if (!(stripped.length == 10)) {
				error = "The phone number is the wrong length. Make sure you included an area code.\n";
			}
		}
	} 
	return error;
}

function checkEmployees(str) {
	var error = "";
	if (str == "") {
		error = "Please enter the number of employees.\n";
	}
    if (isNaN(str)) {
		error = "Please use numeric digits only for number of employees.\n";
	}
	return error;
}


function checkAddress(str) {
	var error = "";
	if (str == "") {
    	error = "Please enter your mailing address.\n";
	}
	return error;
}

function checkCity(str) {
	var error = "";
	if (str == "") {
    	error = "Please enter your city.\n";
	}
	return error;
}

function checkState(str) {
	var error = "";
	if (str == "") {
    	error = "Please enter your state abbreviation.\n";
	}
	else {
		var stateAbbr =  /AK|AL|AR|AZ|CA|CO|CT|DC|DE|FL|GA|HI|IA|ID|IL|IN|KS|KY|LA|MA|MD|ME|MI|MN|MO|MS|MT|NC|ND|NE|NH|NJ|NM|NV|NY|OH|OK|OR|PA|RI|SC|SD|TN|TX|UT|VA|VT|WA|WI|WV|WY/;
    	if (!(str.match(stateAbbr))) {
			error = "Please enter a valid two-letter state abbreviation.\n";
		}
		else {
			if (!(str.length == 2)) {
				error = "Please enter a two-letter state abbreviation.\n";
			}
		}
	} 
	return error;
}

function checkZip(str) {
	var error = "";
	if (str == "") {
    	error = "Please enter your zip code.\n";
	}
	else {
    	if (isNaN(str)) {
			error = "Please use numeric digits only for the zip code.\n";
		}
		else {
			if (!(str.length == 5)) {
				error = "The zip code is the wrong length. Please enter 5 digits.\n";
			}
		}
	} 
	return error;
}

