function emailValidate(element) {
    //Validating the email field
    var re = /^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/
    if (! element.value.match(re)) {
        alert("Invalid email address");
        element.focus();
        element.select();
        return (false);
    }
    return(true);

}

function textValidate(field,alerttxt)
{

	with (field)
	{
		if (value == "") {
			{alert(alerttxt);
			return false}
			}
		else {
			field.action = "submit_order.php";
			return true}
	}
}
function checkForOilType()
{
	if (document.orderForm.field_TCOD.value == 'Meal')
		document.getElementById('fieldQuantDiv').innerHTML = 'kg';
	else
		document.getElementById('fieldQuantDiv').innerHTML = 'litres';
}

function numberValidate(field,alerttxt)
{

	with (field)
	{
		if (value == "") {
			{alert(alerttxt);
			return false}
			}
		else if (value <= 0) {
			{alert(alerttxt);
			return false}
			}
		else {
			field.action = "submit_order.php";
			return true}
	}
}

function formValidate()
{
	if (textValidate(document.orderForm.field_n,"Please enter a name.")==false)
		{document.orderForm.field_n.focus();return false}
	else if (emailValidate(document.orderForm.field_e)==false)
		{document.orderForm.field_e.focus();return false;}
	else if (textValidate(document.orderForm.field_tele,"Please enter a phone number.")==false)
		{document.orderForm.field_tele.focus();return false}
	else if (textValidate(document.orderForm.field_add,"Please enter a street address or P.O. box.")==false)
		{document.orderForm.field_add.focus();return false}
	else if (textValidate(document.orderForm.field_code,"Please enter a postal or zip code.")==false)
		{document.orderForm.field_code.focus();return false}
	else if (textValidate(document.orderForm.field_prov,"Please enter a Province or State.")==false)
		{document.orderForm.field_prov.focus();return false}
	else if (textValidate(document.orderForm.field_town,"Please enter a town or city.")==false)
		{document.orderForm.field_town.focus();return false}
	else if (textValidate(document.orderForm.field_coun,"Please enter a country.")==false)
		{document.orderForm.field_coun.focus();return false}
	else if (textValidate(document.orderForm.field_TCOD,"Please enter a type of Camelina Oil desired.")==false)
		{document.orderForm.field_TCOD.focus();return false}
	else if (numberValidate(document.orderForm.field_quant,"Please enter a valid quantity.")==false)
		{document.orderForm.field_quant.focus();return false}
	else if (numberValidate(document.orderForm.field_pack,"Please enter a type of packaging required.")==false)
		{document.orderForm.field_pack.focus();return false}
	else if (emailValidate(document.orderForm.field_e)==true)
		{document.orderForm.action = "submit_order.php";}
}

