function validemail(txt) {
	var str = txt.value; // email string
	var reg1 = /(@.*@)|(\.\.)|(@\.)|(\.@)|(^\.)/; // not valid
	var reg2 = /^.+\@(\[?)[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,3}|[0-9]{1,3})(\]?)$/; // valid
	if (!reg1.test(str) && reg2.test(str)) { // if syntax is valid
		return true;
	}
	return false;
}

function txtCheck(txt) {
    var trimmed = txt.value.replace(/^\s+|\s+$/g, '') ;
    if (trimmed == "") {
        alert("Please provide all required fields.");
        txt.focus();
        return false;
    }
    return true;
}

function validatecontact() {
//contact_form: tbName, tbSurname, tbEmail, tbCompany, tbAddress, tbPhone, tbFax, tbComment
	var toReturn = true;
	if (toReturn) toReturn = txtCheck(contact_form.tbName);
	if (toReturn) toReturn = txtCheck(contact_form.tbSurname);
	if (toReturn) {
		toReturn = txtCheck(contact_form.tbEmail);
		//Check valid email
	        if (toReturn) {
            	    if (!validemail(contact_form.tbEmail)) {
                    	alert("Please provide a valid email address.");
	                contact_form.tbEmail.focus();
        	        toReturn = false;
                    }
	        }
	}
	if (toReturn) toReturn = txtCheck(contact_form.tbCompany);
	if (toReturn) toReturn = txtCheck(contact_form.tbAddress);
	if (toReturn) toReturn = txtCheck(contact_form.tbPhone);
	if (toReturn) toReturn = txtCheck(contact_form.tbFax);
	if (toReturn) toReturn = txtCheck(contact_form.tbComment);
	
	return toReturn;	
}