
function ShowHide(ElementID)
{
	if (document.getElementById(ElementID).style.display == 'block')
		document.getElementById(ElementID).style.display = 'none'
	else
		document.getElementById(ElementID).style.display = 'block'
}

function TryToSubmitComments()
{
	//1.	Ensure entered comments.
	//2.	If entered email, ensure valid format
	//3.	Send via ajax

	//1.
	if (document.CommentForm.CommentsText.value == "")
	{
		ShowPopup("ERROR", "Please enter your comments.");
		FocusOnField(document.CommentForm.CommentsText);
		return false;
	}
	
	//2.
	if (document.CommentForm.CommentsEmail.value != "" && !IsValidEmail(document.CommentForm.CommentsEmail.value))
	{
		ShowPopup("ERROR", "Please enter a valid email address, or leave this field blank.");
		FocusOnField(document.CommentForm.CommentsEmail);
		return false;
	}
	
	//3.
	var Parameters = "SubmitComments=1" +
			 "&Comments=" + escape(document.CommentForm.CommentsText.value) +
			 "&Email=" + escape(document.CommentForm.CommentsEmail.value);
	
	var MyAjax = new AjaxConnection("http://" + location.host + "/ajax/ajax_submit_comments.php", Parameters, "AfterTryToSubmitComments"); 
}


function AfterTryToSubmitComments(xml, text)
{
	ShowHide('CommentsWrapper');
	document.CommentForm.CommentsText.value = "";
	
	ShowPopup("Comments Submitted", "Thank you, your feedback is appreciated.");
}


function NewsletterSignUp()
{
	if (IsValidEmail(document.SignupForNewsletter.EMAIL.value))
	{
		//document.getElementById('mce-EMAIL').value = document.SignupForNewsletter.EMAIL.value;
		document.SignupForNewsletter.submit();
		ShowPopup("Email Sent", "A confirmation e-mail has been sent to " +document.SignupForNewsletter.EMAIL.value+ ".  You must click on the link in this e-mail to sign up for the newsletter.");
	}
	else
		ShowPopup("ERROR", "Please enter a valid e-mail address.");

}


function SetBackgrounds(elem)
{
	//1.	Remove background-color from all elements
	//2.	Add background-color to this element

	//1.
	//ClearBackgrounds();

	//2.
	elem.style.backgroundColor = "#FFFF99";
}


function ClearBackgrounds(MyForm)
{
	for(i = 0; i < MyForm.elements.length; i++)
		MyForm.elements[i].style.backgroundColor = "";
}

