// JavaScript Document
function CheckData() {
	var msg = "";
	pass=true;
	var f = document.contactform;

	if  ((pass) && (! ValidateTextBox(f.FunctionDate))) {
		msg = "Please enter the Function Date";
		pass = errorMsg(msg, f.FunctionDate);
	}

	//Validate Name
	if  ((pass) && (! ValidateTextBox(f.Name))) {
		msg = "Please enter a contact name";
		pass = errorMsg(msg, f.Name);
	}
	
	if  ((pass) && (! ValidateTextBox(f.Address1))) {
		msg = "Please enter your address";
		pass = errorMsg(msg, f.Address1);
	}
	
	if  ((pass) && (! ValidateTextBox(f.Tel))) {
		msg = "Please enter your telephone number";
		pass = errorMsg(msg, f.Tel);
	}

	//Email
	/*if ((pass) && (!ValidateEMail(f.Email.value))) {
		msg = "Please enter a valid Email Address";
		pass = errorMsg(msg, f.Email);
	}*/

	if  ((pass) && (! ValidateTextBox(f.BinNumber))) {
		msg = "Please enter the bin number";
		pass = errorMsg(msg, f.BinNumber);
	}
	
	if  ((pass) && (! ValidateTextBox(f.Quantity))) {
		msg = "Please enter the quantity";
		pass = errorMsg(msg, f.Quantity);
	}
	
	if  ((pass) && (! ValidateTextBox(f.Price))) {
		msg = "Please enter the Price";
		pass = errorMsg(msg, f.Price);
	}
	
	if  ((pass) && (! ValidateTextBox(f.TotalPrice))) {
		msg = "Please enter the Total Price";
		pass = errorMsg(msg, f.TotalPrice);
	}

	if  ((pass) && (! ValidateTextBox(f.Comments))) {
		msg = "Please enter your Comments";
		pass = errorMsg(msg, f.Comments);
	}
	


	if(!pass){
		return false;
	}
	else {
		f.submit();
		return true;
	}
}

function ValidateTextBox(form_object) {
	if (form_object.value == "") {
		return(false);
	}
	else {
		return(true);
	}
}

function errorMsg(msg, form_object) {
	alert(msg);
	form_object.focus();
	if(form_object.type == "text") {
		form_object.select();
	}
}

function ValidateEMail(i_strEMailAddress) {
	var supported = 0;
	if (window.RegExp) {
		var tempStr = "a";
		var tempReg = new RegExp(tempStr);
		if (tempReg.test(tempStr)) {
			supported = 1;
		}
	}

	if (!supported) {
    		return (i_strEMailAddress.indexOf(".") > 2) && (i_strEMailAddress.indexOf("@") > 0);
    	}

	var r1 = new RegExp("(@.*@)|(\\.\\.)|(@\\.)|(^\\.)");
	var r2 = new RegExp("^.+\\@(\\[?)[a-zA-Z0-9\\-\\.]+\\.([a-zA-Z]{2,3}|[0-9]{1,3})(\\]?)$");
	return (!r1.test(i_strEMailAddress) && r2.test(i_strEMailAddress));
}
