


function isAlphabet(str) {
	var result= "false"; 
	for (var x = 0; x < str.length ; x++) {
		if((str.charAt(x) >= "a" &&  str.charAt(x) <= "z") || (str.charAt(x) >= "A" &&  str.charAt(x) <= "Z")) {
			result= "true";
		}
		else {
			result= "false";
		}
        if(result=="false") {
			break;
		}
	}
	return result;
}

function checkFirstName(str) {
	var error = "";
	if (str == "") {
		error = "Please enter your first name.\n";
	}
	else {
		if(isAlphabet(str) == "false") {
	        error ="Your first name must contain only letters.\n";
		}
	}
	return error;
}

function checkLastName(str) {
	var error = "";
	if (str == "") {
		error = "Please enter your last name.\n";
	}
	else {
		if(isAlphabet(str) == "false") {
	        error ="Your first name must contain only letters.\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 {
    	if (isNaN(str)) {
			error = "Your phone number must contain only numbers.\n";
		}
		else {
			if (!(str.length == 10)) {
				error = "Please enter your complete phone number, including area code.\n";
			}
		}
	} 
	return error;
}


function checkEmployees(str) {
	var error = "";
	if (str == "") {
		error = "Please enter the number of employees.\n";
	}
    if (isNaN(str)) {
		error = "Number of employees must contain only numbers.\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.\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|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 = "Your zip code must contain only numbers.\n";
		}
		else {
			if (!(str.length == 5)) {
				error = "Please enter a 5-digit zip code.\n";
			}
		}
	} 
	return error;
}



