// JavaScript Document
// ================= VALIDATION FUNCTIONS CALLED ON SUBMIT =====================

function validate_email(field,alerttxt) {
	with (field) {
		// THERE IS A VALUE NOW CHECK IF IT IS VALID
		apos=value.indexOf("@");
		dotpos=value.lastIndexOf(".");
			
		if (apos<1||dotpos-apos<2) {
			alert(alerttxt);
			return false;
		} else {
			return true;
		}
	}
}

function validate_field(field,alerttxt) {
	with (field) {
  		if (value==null||value=="") {
  			alert(alerttxt);
			return false;
  		} else {
  			return true;
  		}
	}
}

// ============= CALL ALL VALIDATION FUNCTIONS ===================


function validate_form(thisform) {

	with (thisform) {
		if (validate_field(name,"Please Enter Your Name!")==false) {
			name.focus();
			return false;
		}
		
		if (validate_email(email,"Please Enter a Valid Email Address!")==false) {
			email.focus();
			return false;
		}
		
		if (validate_field(message,"Please Enter a Message!")==false) {
			message.focus();
			return false;
		}
	}
}
