// Javascript Program to Check the "realname" and "email" of a form
// CheckForm test the "realname" variable for entry and the "email" variable for format
function checkform(f) { // f is the form (passed using the this keyword)
	if(f.realname.value.length < 2){
		alert("Please Enter Your Name.");
		f.realname.focus(); // put the prompt in the name field 
		// if the browser is Netscape 6 or IE
		if(document.all || document.getElementByID){
			// change the color of text field
			f.realname.style.background = "yellow";
			f.realname.focus();
		}
		// make sure the form is not submitted
		return false;
	}
	
	// check the first email address ( the exclamation means "not" )
	if(!check_email(f.email.value)){
		alert("Invalid E-mail Address. Please Enter Your E-mail Address");
		f.email.focus(); 
		// if the browser is Netscape 6 or IE
		if(document.all || document.getElementByID){
			// change the color of text field
			f.email.style.background = "yellow";
			f.email.focus();
		}
		// make sure the form is not submitted
		return false;
	}
}

// Email Validation. Written by PerlScriptsJavaScripts.com
function check_email(e) {
	ok = " 1234567890qwertyuiop[]asdfghjklzxcvbnm.@-_QWERTYUIOPASDFGHJKLZXCVBNM";

	for(i=0; i < e.length ;i++){
		if(ok.indexOf(e.charAt(i))<0){ 
			return (false);
		}	
	} 
	
	if (document.images) {
		re = /(@.*@)|(\.\.)|(^\.)|(^@)|(@$)|(\.$)|(@\.)/;
		re_two = /^.+\@(\[?)[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$/;
		if (!e.match(re) && e.match(re_two)) {
			return (-1);		
		} 
	}
}

