/*-------------------------------------------------------------
	 Javascript functions for goodedesign.com.au form validation
	 Created by: tudor@goodedesign.com.au	
	 Created on: 19-10-2004
	 Modified by: tudor@goodedesign.com.au	
	 Modified on: 19-10-2004
	
	 (c) Copyright Goode Design Pty Limited 2004
 -------------------------------------------------------------*/



//----------------------------------------------
//	Validate email address syntax

//----------------------------------------------
// check for correct email format 

	function isValidEmail(email)
	{	
		var emailFormat=/^\w(\.?[\w-])*@\w(\.?[\w-])*\.[a-z]{2,6}(\.[a-z]{2})?$/i;
		if(emailFormat.test(email))  return true; else return false;
		  
	}
//----------------------------------------------
	
//----------------------------------------------
//	Check manditory fields have been completed
function validateForm(form)
{
	var email = form.from.value;
	
	if(form.name == "inquiry")
	{
		//alert("I am in inquiry" + form.name);
		if(email)
		{
			if(!isValidEmail(email))
			{
				alert("Invalid email! \n\rPlease re-enter your email in the format myname@mydomain.com.au.");
				form.from.focus();
			}
			else
			{
				form.submit();
			
			}
		}
	 	else
	 	{
	 		alert("Please enter your email address.\n\rWithout your email address we cannot respond to your inquiry");
			form.from.focus();
	 	}
		
	}
	 
	if(form.name == "feedback")
	{
		//alert("I am in feedback" + form.name);
		var type = getRadioValue(form.type);
		if(email && type)
		{
			form.submit();
		}
		 	
		if(!email)
		{
			var supplyemail = confirm("You have not entered enter your email address.\n\rWithout your email address we cannot respond to your feedback.\n\rDo you what to provide anonymous feedback");
			if(supplyemail)
			{
				if(type)
				{
					form.from.value = "ANON_FEEDBACK@goodedesign.com.au";
					//form.submit();
				}
				else
				{
					form.from.value = "ANON_FEEDBACK@goodedesign.com.au";
					alert("Please select the type of feedback you are providing.\n\rThis helps us more effectively respond to your comments.");
					form.type[0].focus();
				}
			}
			else
			{
				form.from.focus();
			}
		}
	
		else 
		{
			if(!type)
		 	{
		 		alert("Please select the type of feedback you are providing.\n\rThis helps us more effectively respond to your comments.");
				form.type[0].focus();
		 	}
		
			else
			{
				//alert("at the end submit!");
				form.submit();
			}
		}
	}
}
  
//----------------------------------------------
//	Get the value of the selected radio button in a group
function getRadioValue(group)
{
 var selectedRadioValue = "";
 var count;

 for (count = 0; count < group.length; count++)
 {
   if (group[count].checked)
   {
     selectedRadioValue = group[count].value;
     break;
   }
 }
 return selectedRadioValue;
}