function emailCheck(emailStr) {
var checkTLD=1;
var knownDomsPat=/^(com|net|org|edu|int|mil|gov|arpa|biz|aero|name|coop|info|pro|museum)$/;
var emailPat=/^(.+)@(.+)$/;
var specialChars="\\(\\)><@,;:\\\\\\\"\\.\\[\\]";
var validChars="\[^\\s" + specialChars + "\]";
var quotedUser="(\"[^\"]*\")";
var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/;
var atom=validChars + '+';
var word="(" + atom + "|" + quotedUser + ")";
var userPat=new RegExp("^" + word + "(\\." + word + ")*$");
var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$");
var matchArray=emailStr.match(emailPat);
if(emailStr == "") {
	subscribe.email.value="Input e-mail address here";
}
if(emailStr != "" && emailStr != "Input e-mail address here") {
	if (matchArray==null) {
	alert("Email address seems incorrect (check @ and .'s)");
	return false;
	}
	var user=matchArray[1];
	var domain=matchArray[2];

	for (i=0; i<user.length; i++) {
	if (user.charCodeAt(i)>127) {
	alert("Ths username contains invalid characters.");
	return false;
	   }
	}
	for (i=0; i<domain.length; i++) {
	if (domain.charCodeAt(i)>127) {
	alert("Ths domain name contains invalid characters.");
	return false;
	   }
	}

	if (user.match(userPat)==null) {

	alert("The username doesn't seem to be valid.");
	return false;
	}

	var IPArray=domain.match(ipDomainPat);
	if (IPArray!=null) {

	for (var i=1;i<=4;i++) {
	if (IPArray[i]>255) {
	alert("Destination IP address is invalid!");
	return false;
	   }
	}
	return true;
	}
	 
	var atomPat=new RegExp("^" + atom + "$");
	var domArr=domain.split(".");
	var len=domArr.length;
	for (i=0;i<len;i++) {
	if (domArr[i].search(atomPat)==-1) {
	alert("The domain name does not seem to be valid.");
	return false;
	   }
	}

	if (checkTLD && domArr[domArr.length-1].length!=2 && 
	domArr[domArr.length-1].search(knownDomsPat)==-1) {
	alert("The address must end in a well-known domain or two letter " + "country.");
	return false;
	}

	if (len<2) {
	alert("This address is missing a hostname!");
	return false;
	}
}
return true;
}

function validateForm(emailStr) {
	if(emailStr != "" && emailStr != "Input e-mail address here") {
		return emailCheck(subscribe.email.value);
	} else {
		subscribe.email.value="";
		alert("Please enter your e-mail address.");
		subscribe.email.focus();
		return false;
	}
}

function validateContact(thisForm) {
	if(thisForm.firstName.value=='') {
		alert("Please enter your name.");
		thisForm.firstName.focus();
		return false;
	} else if(thisForm.lastName.value=='') {
		alert("Sorry, Lastname can't be blank");
		thisForm.lastName.focus();
		return false;
	} else if(thisForm.companyName.value=='') {
		alert("Kindly identify your company name.");
		thisForm.companyName.focus();
		return false;
	} else if(thisForm.address.value=='') {
		alert("Please enter your contact address.");
		thisForm.address.focus();
		return false;
	} else if(thisForm.city.value=='') {
		alert("Please specify the city.");
		thisForm.city.focus();
		return false;
	} else if(thisForm.state.value=='') {
		alert("Sorry, State can't be blank");
		thisForm.state.focus();
		return false;
	} else if(thisForm.zip.value=='') {
		alert("Please enter your zip code.");
		thisForm.zip.focus();
		return false;
	} else if(thisForm.numEmployees.value=='') {
		alert("How many employees in your company?");
		thisForm.numEmployees.focus();
		return false;
	} else if(thisForm.textarea.value=='') {
		alert("Please enter your message.");
		thisForm.textarea.focus();
		return false;
	} else {
		return true;
	};
}

function chField(emailStr) {
	if(emailStr == "Input e-mail address here") {
		subscribe.email.value="";
	}
}
