// Javascript Program to Check the "realname" and "email" of a form
// CheckForm test form variable for entry and the "email" variable for format.

function checkform(f) { // f is the form (passed using the this keyword)

//	f.realname.value = f.first_name.value + " " + f.last_name.value;

//	if(f.realname.value.length < 2){
//		alert("Please Enter Your Real Name.");
//		f.realname.style.background = "yellow"; // change the color of text field
//		f.realname.focus(); // put the prompt in the name field 
//		return false; // make sure the form is not submitted
//	}
	
	if(f.first_name.value.length < 2){
		alert("Please Enter Your First Name.");
		f.first_name.style.background = "yellow"; // change the color of text field
		f.first_name.focus(); // put the prompt in the name field 
		return false; // make sure the form is not submitted
	}
	
	if(f.last_name.value.length < 2){
		alert("Please Enter Your Last Name.");
		f.last_name.style.background = "yellow"; // change the color of text field
		f.first_name.focus(); // put the prompt in the name field 
		return false; // make sure the form is not submitted
	}
	
	if(f.address.value.length < 2){
		alert("Please Enter Your Address.");
		f.address.style.background = "yellow"; // change the color of text field
		f.address.focus(); // put the prompt in the name field 
		return false; // make sure the form is not submitted
	}
	
	if(f.city.value.length < 2){
		alert("Please Enter Your City.");
		f.city.style.background = "yellow"; // change the color of text field
		f.city.focus(); // put the prompt in the name field 
		return false; // make sure the form is not submitted
	}
	
	if(f.zip.value.length < 5){
		alert("Please Enter Your Zip.");
		f.zip.style.background = "yellow"; // change the color of text field
		f.zip.focus(); // put the prompt in the name field 
		return false; // make sure the form is not submitted
	}
	
	if(f.phone.value.length < 7){
		alert("Please Enter Your Phone.");
		f.phone.style.background = "yellow"; // change the color of text field
		f.phone.focus(); // put the prompt in the name field 
		return false; // make sure the form is not submitted
	}
	
	// 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.style.background = "yellow"; // change the color of text field
		f.email.focus(); // put the prompt in the name field
		return false; // make sure the form is not submitted
	}
	
	if(f.state.value.length != 2){
		alert("Please Enter Your State.");
		f.state.style.background = "yellow"; // change the color of text field
		f.state.focus(); // put the prompt in the name field 
		return false; // make sure the form is not submitted
	}
	
}

// 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);		
		} 
	}
}
