/**********************************************************************************************
* Author:   Andrew Connick
* Date:     23/09/09
***********************************************************************************************/

function prsContactForm(frm) {
	if (isBlank(frm.contactusemail)) {
		alert("Please enter your email address.");
		frm.contactusemail.focus();
		return false;
	}
	if (!vldEmail(frm.contactusemail)) return false;
	if (!vldText(frm.contactusname, "Your name")) return false;
	if (!vldTextTag(frm.contactusmessage)) return false;
}

function showElm(id) { try { document.getElementById(id).style.display = "block"; } catch(e) { } }
function hideElm(id) { try { document.getElementById(id).style.display = "hide"; } catch(e) { } }

/* Validation functions ************************************************************************/

function isBlank(fld) {
	if (fld==null) return false;
	else if (fld.value == "") return true;
	else if (fld.value == " ") return true;
	else if (fld.value == "0") return true;
	else return false;
}

function vldEmail(e) {
	// define a regular expression to validate the email address
	r = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/;
	if (r.test(e.value)) return true;                        // quit if the email is valid.
	// otherwise set an error.
	e.select();
	alert("Please enter a valid email address.");
	e.focus();
	return false;                                            // return false to halt processing.
}

// Validate text for special characters
function vldText(txt, dsc) {
	if (txt.value.indexOf('>')>=0 || 
			txt.value.indexOf('<')>=0 ||
			txt.value.indexOf('"')>=0 ||
			txt.value.indexOf('\'')>=0 ||
			txt.value.indexOf('\n')>=0 ||
			txt.value.indexOf('\r')>=0 ||
			txt.value.indexOf('\r\n')>=0 ||
			txt.value.indexOf('&')>=0) {
		txt.select();
		alert(dsc + " contains an invalid character \n < > & quotes newline \n are not allowed.");
		txt.focus();
		return false;
	}
	return true;
}

// Validate text for < > characters
function vldTextTag(txt) {
	if (txt.value.indexOf('>')>=0 || 
			txt.value.indexOf('<')>=0) {
		txt.select();
		alert("Text contains an invalid character < & > are not allowed.");
		txt.focus();
		return false;
	}
	return true;
}

