// JavaScript Document
// +----------------------------------------------------------------------+
// | Blank Motion Studios Website       			                      |
// +----------------------------------------------------------------------+
// | Copyright (c) 2005 Blank Motion Studios Pty Ltd                      |
// |                                                                      |   
// | http://www.blankmotion.com.au                                        |   
// | 								                                      |
// | Please do not remove this information                                |   
// | Do not replicate or alther this code without the                     | 
// | permission of Blank Motion Studios                                   |
// | Email: info@blankmotion.com.au	                                      | 
// | 								                                      |
// | Portions otherwise noted are copyright of their respective owners    |
// +----------------------------------------------------------------------+

function submitform(form) { 

		document.getElementById(form).submit(); 

}

function validate(myobject, reqField) {
	var action = '<?php echo $action; ?>'
	if(action == 'submit'){
		alert("Your enquiry was already submitted");
		return true
	}
	else
		{
		var error = false;
		var errorMsg = '';
		var errorNum = 0;
		if(!document.getElementById('required')){
			submitform(myobject);
		}
		else
		{
			var reqfields=document.getElementById(reqField).value.split(',');
			for(var i=0;i<reqfields.length;i++)
		   {
		   		var f=document.getElementById(reqfields[i])
				if(f.value.length > 0 && f.value != ''){
					if(f.id == 'email'){
						if(!isValidEmail(f))
						{
							errorMsg += "Your email address is not valid\n";
							error = true;
						}
					}
				}
				else
				{	
					if(errorNum < 1){
						errorMsg += "You left a required field blank\n";
						errorNum++;
					}
					error = true;
				}
			}
			if(error)
			{
				errorMsg += "The form was incorrectly completed. Please try again";
				alert(errorMsg);
				return false;
			}
			else
			{
				submitform(myobject)
			}
		}
	}
}			
	
	
function isValidEmail(emailfield) {	
	if(emailfield.value.indexOf(".") > 0 && emailfield.value.indexOf("@") > 0)
		{
			 return true
		}
	else
		 {
			 return false
	}
}	
