function checkEmail(strEmail) 
{
	var filter = /^[^@\s]+@([-a-z0-9]+\.)+[a-z]{2,}$/i;
	if (!filter.test(strEmail)) 
	{
		return false;
	}
	else
	{
		return true;
	}
}

function checkformenquiry()
{

	var mandatory = new Array("iconame", "iname", "iaddress", "iemail", "itel", "icountry", "imessage");
	return checkform(mandatory, "iemail", "iformmessage", "enquiryform");
}

function checkformreseller()
{

	var mandatory = new Array("jconame", "jcontactname", "jjobtitle", "jaddress", "jemail", "jtel", "jcountry", "jdescription");
	return checkform(mandatory, "jemail", "jformmessage", "resellerform");
}

function checkformsupport()
{

	var mandatory = new Array("iproduct", "iconame", "icontactname", "iemail", "isubject", "idescription");
	return checkform(mandatory, "iemail", "iformmessage", "supportform");
}


function isradio(oField)
{
	if (typeof(oField[0]) !=  "undefined")
	{
		if (oField[0].type=="radio")
			return true;
	}
	return false;
}

function checkform(arrFields, strEmail, strFormMessage, frmName)
{
	var bGoingon = true;

	for (x=0; x < arrFields.length; x++)
	{
		strCField = arrFields[x];
		oField = document.forms[frmName].elements[strCField];
		strVal = "";
		if (typeof(oField) == "undefined")
			continue;
		
		// if it's a radio button look through the array, otherwise get the value
		if (isradio(oField))
		{
			for (var i=0; i< oField.length; i++) 
			{
				if (oField[i].checked)
				{
					strVal = oField[i].value;
				}
			}
		}	
		else
			strVal = document.forms[frmName].elements[strCField].value;
		oLabel = document.getElementById("l" + strCField);
		if (strCField == strEmail)
		{
			if (!checkEmail(strVal))
			{
				bGoingon = false;
				oLabel.style.color="red";
			}
			else
			{
				oLabel.style.color="#595959";
			}
		}
		else
		{
			if (strVal.length < 1)
			{
				bGoingon = false;
				oLabel.style.color="red";
			}
			else
			{
				oLabel.style.color="#595959";
			}
		}
	}
	if (bGoingon)
	{
		document.getElementById(strFormMessage).style.color = "#595959";
		document.getElementById(strFormMessage).innerHTML = "Submitting details";
		return true;
	}
	else
	{
		document.getElementById(strFormMessage).style.color = "red";
		document.getElementById(strFormMessage).innerHTML = " *Please complete required fields";
		return false;
	}

}
