// JavaScript Document

String.prototype.Trim = function() { 
	return this.replace(/(^\s*)|(\s*$)/g, ""); 
} 

function checkMail(email) {
	var x = email;
	var filter  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
	if (filter.test(x)) return true;
	else return false;
}

function validate(myForm) {
	var contactPerson = myForm.contactPerson;
	var companyName = myForm.companyName;
	var contactNo = myForm.contactNo;
	var email = myForm.email;
	var fax = myForm.fax;
	var address1 = myForm.address1;
	var address2 = myForm.address2;
	var sendFlag = true;
	
	if (contactPerson.value == "" && sendFlag){
		alert("Please input the contact person");
		sendFlag = false;
		contactPerson.focus();
	}
	
	if (companyName.value == "" && sendFlag){
		alert("Please input the company name");
		sendFlag = false;
		companyName.focus();
	}
	
	
	if (email.value.Trim() == "" && sendFlag){
		alert("Please enter your email");
		sendFlag = false;
		email.focus();
	} else if (!checkMail(email.value.Trim()) && sendFlag) {
		alert("Invalid email. Please input a correct email");
		sendFlag = false;
		email.focus();
	}
	
	if (contactNo.value == "" && sendFlag){
		alert("Please input the contact no.");
		sendFlag = false;
		contactNo.focus();
	}
	
	if (fax.value == "" && sendFlag){
		alert("Please input the fax no.");
		sendFlag = false;
		fax.focus();
	}
	
	if (address1.value == "" && sendFlag){
		alert("Please input the address");
		sendFlag = false;
		address1.focus();
	}
	
	if (sendFlag) {
		document.getElementById('btnSubmit').disabled = "disabled";
	}
	
	return sendFlag;
}

function checkContactUs(myForm) {
	var contactPerson = myForm.contactPerson;
	var email = myForm.email;
	var message = myForm.message;
	var sendFlag = true;
	
	if (contactPerson.value == "" && sendFlag){
		alert("Please input the contact person");
		sendFlag = false;
		contactPerson.focus();
	}	
	
	if (email.value.Trim() == "" && sendFlag){
		alert("Please enter your email");
		sendFlag = false;
		email.focus();
	} else if (!checkMail(email.value.Trim()) && sendFlag) {
		alert("Invalid email. Please input a correct email");
		sendFlag = false;
		email.focus();
	}
	
	if (message.value == "" && sendFlag){
		alert("Please leave your message");
		sendFlag = false;
		message.focus();
	}
	
	if (sendFlag) {
		document.getElementById('btnSubmit').disabled = "disabled";
	}
	
	return sendFlag;
}