﻿	function e_check(str) {

		var at="@"
		var dot="."
		var lat=str.indexOf(at)
		var lstr=str.length
		var ldot=str.indexOf(dot)
		var ret = 0;

		if (str.indexOf(at)==-1)ret = 1;

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr)ret = 1;

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr)ret = 1;

		if (str.indexOf(at,(lat+1))!=-1) ret = 1;

		if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot)ret = 1;

		if (str.indexOf(dot,(lat+2))==-1)ret = 1;

		if (str.indexOf(" ")!=-1)ret = 1;
		
		if (ret == 1) {
		    return false;
		}
 		return true;				
	}


	function check_inputs (comment) {

		var ret = true;
		var alpha = /^[a-zA-Z]+$/;
		var code = /[\<\>\{\}]+/;
		var emailCheck = /^[\w\-\.\+]+\@[a-zA-Z0-9\.\-]+\.[a-zA-z0-9]{2,4}$/;
	
		if (document.form.first.value == "") {
			document.getElementById('s1').innerHTML = "* Enter First Name";
			ret = false;
		} else {
			if (document.form.first.value.match(alpha)) {
				document.getElementById('s1').innerHTML = "*";
			} else {
				document.getElementById('s1').innerHTML = "* Use Only Alphanumeric Characters";
				ret = false;
			}
		}
		if (document.form.last.value == "") {
			document.getElementById('s2').innerHTML = "* Enter Last Name";
			ret = false;
		} else {
			if (document.form.last.value.match(alpha)) {
				document.getElementById('s2').innerHTML = "*";
			} else {
				document.getElementById('s2').innerHTML = "* Use Only Alphanumeric Characters";
				ret = false;
			}
		}
		if (document.form.email.value == "") {
			document.getElementById('s3').innerHTML = "* Enter E-mail Address";
			ret = false;
		} else {		
			if (e_check(document.form.email.value)) {
				if (document.form.email.value.match(emailCheck)) {
					document.getElementById('s3').innerHTML = "*";
				} else {
					document.getElementById('s3').innerHTML = "* Not a Valid E-mail!";
					ret = false;
				}
			} else {
				if (document.form.email.value.match(emailCheck)) {
					document.getElementById('s3').innerHTML = "* Not a Valid E-mail!";
					ret = false;
				} else {
					document.getElementById('s3').innerHTML = "* Not a Valid E-mail!";
					ret = false;
				}
			}
		}
		if (comment == 1) {
			if (document.form.comments.value == "") {
				document.getElementById('s4').innerHTML = "* Enter Comment / Question";
				ret = false;
			} else {
				if (document.form.comments.value.match(code)) {
					document.getElementById('s4').innerHTML = "* Message Cannot Contain Brackets";
					ret = false;
				} else {
					document.getElementById('s4').innerHTML = "*";
				}
			}
			if (document.form.math1.value == "") {
				document.getElementById('s5').innerHTML = "* Show me that you are not a robot!";
				ret = false;
			} else
				document.getElementById('s5').innerHTML = "*";		
		}
				
		return ret;
	}

