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 validateContactForm(theForm) {
previousInnerHTML='';
	if(theForm.your_name.value == "") {
		AddErrorMsg("Please enter your Name");
		theForm.your_name.focus();		
	}


	if(theForm.your_email.value == "") {
		AddErrorMsg("Please enter your Email");
		theForm.your_email.focus();

	}


	if(theForm.your_friends_name.value == "") {
		AddErrorMsg("Please enter your Friend's Name");
		theForm.your_friends_name.focus();
	}


	if(theForm.your_friends_email.value == "") {
		AddErrorMsg("Please enter your Friends Email");
		theForm.your_friends_email.focus();

	}


	if((!validateEmail(theForm.your_email.value)) && (theForm.your_email.value != "")) {
		AddErrorMsg("Please enter a valid Email address");
		theForm.your_email.focus();

	}	

	if((!validateEmail(theForm.your_friends_email.value)) && (theForm.your_friends_email.value != "")) {
		AddErrorMsg("Please enter a valid Email address for your Friend");
		theForm.your_friends_email.focus();

	}	



		if (previousInnerHTML!='')
		{
			document.getElementById('divErrors').innerHTML = '<p>Please correct the following errors&#8230;</p> <ul>' + previousInnerHTML + '</ul>' ;
			document.getElementById('divErrors').style.display='block';
			//alert(previousInnerHTML + 'false');
			return false;
		}
		else
		{
			//alert(previousInnerHTML + 'true');
			return true;
		}




}
