
function ValidateForm(obj){

	var strAlert = "";
	strAlert = "______________________________________\n\nPlease\n\n";
	var isAlert = false;

	// trim the values of white space

	var strCompany = strTrim(obj.Company.value);
	var strContact = strTrim(obj.Contact.value);	
	var strTelephone = strTrim(obj.Telephone.value);
	var strAddress = strTrim(obj.Address.value);		
	var strPostcode = strTrim(obj.Postcode.value);	
	var strEmail = strTrim(obj.Email.value);


	if (strCompany==""){
		strAlert += "- Enter your Company\n";
		isAlert = true;
	}
	if (strContact==""){
		strAlert += "- Enter your Contact\n";
		isAlert = true;
	}	
	if (strTelephone==""){
		strAlert += "- Enter your Telephone number\n";
		isAlert = true;
	}
	if (strAddress==""){
		strAlert += "- Enter your Address\n";
		isAlert = true;
	}		

	if (strPostcode==""){
		strAlert += "- Enter your Postcode\n";
		isAlert = true;
	}else if(isNaN(strPostcode) || (strPostcode.length!=4) ){
		strAlert += "- Enter a valid Postcode\n";
		isAlert = true;	
	} 			
	if (!ValidEmail(strEmail)){
		strAlert += "- Enter a valid email address\n";
		isAlert = true;
	}
	if (isAlert == true){
		strAlert += "\n\n______________________________________";
		alert (strAlert);
		return false;
	}else{
		return true;
	}	
}

function strTrim(strText) {
		for (i=0; i<strText.length; ++i) {
			if (strText.charAt(i) != ' ') break;
		}
		if (i >= strText.length) return ('');
		if (i > 0) strText = strText.substring(i, strText.length);
		for (j=strText.length-1; j > i; --j) {
			if (strText.charAt(j) != ' ') break;
		}
		if (j < strText.length -1)
			strText = strText.substring(0, j+1);
		return strText;

}
function ValidEmail(s){
    var i = 1;
    var sLength = s.length;
    while ((i < sLength) && (s.charAt(i) != "@"))
    { i++
    }
    if ((i >= sLength) || (s.charAt(i) != "@")) return false;
    else i += 2;
    while ((i < sLength) && (s.charAt(i) != "."))
    { i++
    }
    if ((i >= sLength - 1) || (s.charAt(i) != ".")) return false;
    else return true;
} 