/*

	Web Site Feedback validator
	Matt Bell 2009
	Medicare Australia
	
*/

function validate()
{
	var SubmitOK = true; //Boolean which gets set to false if theres a problem
	var SpitError = true; //Only spit an error once
	var Survey = document._HICSurvey;
	
	var DefaultStyle = "1px solid #7f9db9";
	var HighlightStyle = "2px solid #cb0000";
	
	Survey.Replyname.style.border = DefaultStyle;
	Survey.txtName.style.border = DefaultStyle;
	Survey.txtNameConfirmed.style.border = DefaultStyle;
	Survey.feedback.style.border = DefaultStyle;

	// EMAIL
	if (Survey.txtName.value.length > 1)
	{
		if (Survey.txtName.value.indexOf("@") < 1 || Survey.txtName.value.indexOf(".") < 1)
		{
			Survey.txtName.style.border = HighlightStyle;
			SubmitOK = false;
			
			if (SpitError)
			{
				alert("Please use a valid email address");
				SpitError = false;
			}
		}
	}
	
	// EMAIL CONFIRM
	if (Survey.txtName.value != Survey.txtNameConfirmed.value)
	{
		Survey.txtNameConfirmed.style.border = HighlightStyle;
		Survey.txtName.style.border = HighlightStyle;
		SubmitOK = false;
		
		if (SpitError)
		{
			alert("Please make sure your email address is correct in both fields");
			SpitError = false;
		}
	}
	
	
	// FEEDBACK FEILD
	if (Survey.feedback.value.length < 2)
	{
		Survey.feedback.style.border = HighlightStyle;
		SubmitOK = false;
		
		if (SpitError)
		{
			alert("Please provide some feedback in the area highlighted in red");
			SpitError = false;
		}
	}
	
	//SUBMIT FORM
	if (SubmitOK)
	{
		var FeedbackDiv = document.getElementById("feedbackform");
		var SubmitFormDiv = document.getElementById("submitform");
		
		FeedbackDiv.style.display = "none";
		SubmitFormDiv.style.display = "block";
		
		var LoadingImageDiv = document.getElementById("loadimage");
		
		LoadingImageDiv.innerHTML = "<img src='/common/images/loading.gif' alt='Please wait...'/>";

		Survey.Submit.disabled = true;
		Survey.Cancel.disabled = true;
		
		Survey.submit();
	}
}