function isEmailWellFormed(email) {

	
	invalidChars=" <>[]{}/:,';!";
	
	
	for (i=0; i<invalidChars.length; i++) {
		if (email.indexOf((invalidChars.charAt(i)),0)>-1) {
			return("The following characters are not allowed in an e-mail address:'" + invalidChars + "'");
		}
	}

	
	atPos=email.indexOf("@",0);
	if ((atPos<=0) || (email.indexOf("@",atPos+1)>-1)) {
		return("A valid e-mail address has the form: username@domain");
	}

	
	
	domainParts = (email.substring(atPos+1,email.length)).split(".");
	domainPartsCount = domainParts.length;
	
	
	if (domainPartsCount<2) {
		return("The domain must contain at least one period");
	}

	
	for (i=0;i<domainPartsCount;i++) {
		if (domainParts[i].length==0) {
			return("Periods in the domain are not placed properly.");
		}
	}

	
	if (domainParts[domainPartsCount-1].length<2) {
		return("The final portion of the domain must be at least two characters long");
	}

	
	return ("");
}

function FilterName(name) {
	str = name.replace(/!/gi, "");
	str = Trim(str);
	return str;
}

function LTrim(str)  {
      for (var i=0; str.charAt(i)==" "; i++);
      return str.substring(i,str.length);
}

function RTrim(str) {
      for (var i=str.length-1; str.charAt(i)==" "; i--);
      return str.substring(0,i+1);
}

function Trim(str) {
	  return LTrim(RTrim(str));
}

function validateForm() {
	form = document.getElementById("contactform");
	emailValid = isEmailWellFormed(form.email.value);
	if (form.name.value == "") {
		alert("Please enter your name.");
		form.name.focus();
		return false;
	} else if (form.phone.value == "") {
		alert("Please enter your phone number.");
		form.phone.focus();
		return false;
	} else if (form.email.value == "" || emailValid != "") {
		if (emailValid != "") {
			alert(emailValid);
		} else {
			alert("Please enter a valid email address.");
		}
		form.email.focus();
		return false;
	} else if (form.position.value == "") {
		alert("Please enter the position you are applying for.");
		form.position.focus();
		return false;
	} else if (form.mainmessage.value == "") {
		alert("Please enter a message.");
		form.mainmessage.focus();
		return false;
	}
}

function resetForm() {
	form = document.getElementById("contactform");
	form.browser.options[0].selected = true;
	form.os.options[0].selected = true;
	form.Subject.options[0].selected = true;
	form.name.value = "";
	form.empId.value = "";
	form.phone.value = "";
	form.email.value = "";
	form.position.value = "";
	form.mainmessage.value = "";
	form.browser.focus();
}