document.getElementById('divErrors').style.display='none';
document.getElementById('divSuccess').style.display='block';

var previousInnerHTML = new String();

	function validateEmail(email) {
		invalidChars = " /:,;"

		for (i=0; i<invalidChars.length; i++) {// does it contain any invalid characters?
			badChar = invalidChars.charAt(i)
			if (email.indexOf(badChar,0) > -1) {
				return false
			}
		}
		atPos = email.indexOf("@",1)  // there must be one "@" symbol
		if (atPos == -1) {
			return false
		}
		if (email.indexOf("@",atPos+1) != -1) {  // and only one "@" symbol
			return false
		}
		periodPos = email.indexOf(".",atPos)
		if (periodPos == -1) {  // and at least one "." after the "@"
			return false
		}
		if (periodPos+3 > email.length) {  // must be at least 2 characters after the "."
			return false
		}
		return true;
	}



function AddErrorMsg(msg)
{
	previousInnerHTML = previousInnerHTML.concat("<li>" + msg + "</li>");    
} 



 // ----------------------------------------------------------------------

/*
function SubmitForm(theForm) {
alert('here');
validateContactForm(this);
theForm.Submit();
}
*/


function validateContactForm(theForm) {
	previousInnerHTML='';
	if(theForm.name.value == "") {
		AddErrorMsg("Please complete the Name field");
		theForm.name.focus();
	}


	if(theForm.address.value == "") {
		AddErrorMsg("Please complete the Address field");
		theForm.address.focus();

	}

	if(theForm.suburb.value == "") {
		AddErrorMsg("Please complete the Suburb field");
		theForm.suburb.focus();

	}


	if(theForm.phone.value == "") {
		AddErrorMsg("Please enter Phone Number");
		theForm.phone.focus();

	}


	if(theForm.email.value == "") {
		AddErrorMsg("Please complete the Email Address field");
		theForm.email.focus();

	}


	if((!validateEmail(theForm.email.value)) && (theForm.email.value != "")) {
		AddErrorMsg("Please enter a valid Email Address");
		theForm.email.focus();

	}	


	if(theForm.comments.value == "") {
		AddErrorMsg("Please complete the Comments field");
		theForm.comments.focus();

	}


		if (previousInnerHTML!='')
		{
			document.getElementById('divErrors').innerHTML = '<p>Please correct the following errors&#8230;</p> <ul>' + previousInnerHTML + '</ul>' ;
			document.getElementById('divErrors').style.display='block';

			return false;
		}
		else
		{
			return true;
		}

}


