
// Forms routines

	// is browser sufficiently advanced for true W3C DOM scripting ?
	if (document.getElementById && document.createElement && document.childNodes)
		W3CDOM = true;
	else
		W3CDOM = false;


	function ResetFocus()
	{
		if (W3CDOM)
		{
			// focus on Text Box using the W3C DOM
			document.getElementById("txtName").focus();
		}
	}


	function CheckForm()
	{
		if (W3CDOM)
		{
			txtName = document.getElementById("txtName").value;
			txtEmail = document.getElementById("txtEmail").value;
			txtFriendsName = document.getElementById("txtFriendsName").value;
			txtFriendsEmail = document.getElementById("txtFriendsEmail").value;

			if ((txtName != "") && (txtEmail != "") && (txtFriendsName != "") && (txtFriendsEmail != ""))
			{
				return true;
			}
			else
			{
				if (txtName == "") document.getElementById("txtName").focus();
				if (txtEmail == "") document.getElementById("txtEmail").focus();
				if (txtFriendsName == "") document.getElementById("txtFriendsName").focus();
				if (txtFriendsEmail == "") document.getElementById("txtFriendsEmail").focus();
				alert('Please complete all the required form fields ...');
				return false;
			}
		}
	}


	function CheckContactForm()
	{
		if (W3CDOM)
		{
			txtName = document.getElementById("txtName").value;
			txtEmail = document.getElementById("txtEmail").value;
			txtPhone = document.getElementById("txtPhone").value;
			txtEnquiry = document.getElementById("txtEnquiry").value;

			if ((txtName != "") && (txtEmail != "") && (txtPhone != "") && (txtEnquiry != ""))
			{
				return true;
			}
			else
			{
				if (txtName == "") document.getElementById("txtName").focus();
				if (txtEmail == "") document.getElementById("txtEmail").focus();
				if (txtPhone == "") document.getElementById("txtPhone").focus();
				if (txtEnquiry == "") document.getElementById("txtEnquiry").focus();
				alert('Please complete all the required form fields ...');
				return false;
			}
		}
	}


	function CheckRegisterForm()
	{
		if (W3CDOM)
		{
			txtName = document.getElementById("txtName").value;
			txtEmail = document.getElementById("txtEmail").value;

			if ((txtName != "") && (txtEmail != ""))
			{
				return true;
			}
			else
			{
				if (txtName == "") document.getElementById("txtName").focus();
				if (txtEmail == "") document.getElementById("txtEmail").focus();
				alert('Please complete all the required form fields ...');
				return false;
			}
		}
	}


	function GoBack()
	{
		window.history.back();
	}


//****************************************************
// Sentence Case Checker and Setter routine for use in Text Form Fields
// C. Sewell 2003
//****************************************************

function CheckCase(field)	// check for Sentence case and enforce
{
	var excludes=" the and or a ";	// list of words to Exclude from Sentence Case

	var strFieldValue = document.getElementById(field.name).value;

	if (strFieldValue == "") return false;
	var textField = field;
	var textValue = new String(textField.value);

	txt=textValue+" ";
	txt=txt.toLowerCase();
	txtl="";
	punc=",.?!:;)'";
	punc+='"';
	while ((txt.length>0)&&(txt.indexOf(" ")>-1)){
	pos=txt.indexOf(" ");
	wrd=txt.substring(0,pos);
	wrdpre="";
	if (punc.indexOf(wrd.substring(0,1))>-1){
	wrdpre=wrd.substring(0,1);
	wrd=wrd.substring(1,wrd.length);
	}
	cmp=" "+wrd+" ";
	for (var i=0;i<9;i++){
	p=wrd.indexOf(punc.substring(i,i+1));
	if (p==wrd.length-1){
	 cmp=" "+wrd.substring(0,wrd.length-1)+" ";
	 i=9;
	 }
	}
	if (excludes.indexOf(cmp)<0){
	ltr=wrd.substring(0,1);
	ltr=ltr.toUpperCase();
	wrd=ltr+wrd.substring(1,wrd.length);
	}
	txtl+=wrdpre+wrd+" "; 
	txt=txt.substring((pos+1),txt.length);
	}
	ltr=txtl.substring(0,1);
	ltr=ltr.toUpperCase();
	txtl=ltr+txtl.substring(1,txtl.length-1);

	document.getElementById(field.name).value = txtl;
}


//****************************************************
// Valid Email Checker routine for use in Text Form Fields
// C. Sewell 2003
//****************************************************


function CheckEmail(field)
{
	var strFieldValue = document.getElementById(field.name).value;

	if (strFieldValue == "") return false;
	var textField = field;
	var strEmail = new String(textField.value);

	var exclude=/[^@\-\.\w]|^[_@\.\-]|[\._\-] {2}|[@\.]{2}|(@)[^@]*\1/;
	var check=/@[\w\-]+\./;
	var checkend=/\.[a-zA-Z]{2,3}$/;

	if (((strEmail.search(exclude) != -1) || 
	(strEmail.search(check)) == -1) || 
	(strEmail.search(checkend) == -1))
	{
		alert("invalid email address");
		document.getElementById(field.name).focus();
		return false;
	}
	else
	{
	    return true;
	}
}
