


function checkForm()
{
	//Get ref to form object
	var f = document.ContactForm;
	//window.alert(f);
	
	var isOK = true;
	
	//Loop through all form elements
	for (var i = 0; i < f.elements.length; i++)
	{
		//Get ref to current element
		var fItem = f.elements[i];
		
		if (fItem.name == "Name")
		{
			isOK = checkValidString(fItem.value, "name");
		}
		else if (fItem.name == "Organisation")
		{
			isOK = checkValidString(fItem.value, "organisation");
		}
		else if (fItem.name == "OtherInfo")
		{
			isOK = checkValidString(fItem.value, "other information");
		}
		else if (fItem.name == "Email")
		{
			isOK = checkEmail(fItem.value);
		}
		
		//If item not ok return false
		if (!isOK) return false
	};
	
	
	//window.alert("Submitting form");
	f.submit();
	
};


function checkValidString(str, itemName)
{
	if (str.length > 0 && str != "")
	{
		return true
	}
	else
	{
		window.alert("Please complete the " + itemName + " field");
		return false
	}
};


function checkEmail(strEmail)
{
	//Set email regular expression string
	var filter=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i
	
	if(filter.test(strEmail))
	{
		return true
	}
	else
	{
		window.alert("Please provide a valid email");
		return false
	}
}