/**
 * DHTML email validation script. Courtesy of SmartWebby.com (http://www.smartwebby.com/dhtml/)
 */

function echeck(str) {
	var at="@";
	var dot=".";
	var lat=str.indexOf(at);
	var lstr=str.length;
	var ldot=str.indexOf(dot);
	if (str.indexOf(at)==-1)
	   return false;

	if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr)
	   return false;

	if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr)
		return false;

	 if (str.indexOf(at,(lat+1))!=-1)
		return false;

	 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot)
		return false;

	 if (str.indexOf(dot,(lat+2))==-1)
		return false;
	
	 if (str.indexOf(" ")!=-1)
		return false;

	 return true;
}

function validateJoinForm ()
{
	var validation = '';
	if (document.getElementById('frw_name').value == '')
		validation+= '* You must specify Business name\n';
	if (document.getElementById('frw_customer_supply_partner').value == '')
		validation+= '* You must specify Customer of (Supply Partner)\n';
	if (document.getElementById('frw_contact_name').value == '')
		validation+= '* You must specify Contact name\n';
	if (document.getElementById('frw_phone').value == '')
		validation+= '* You must specify Phone number\n';
	if (document.getElementById('frw_gst_no').value == '')
		validation+= '* You must specify GST number\n';
	if (document.getElementById('frw_postal_address').value == '')
		validation+= '* You must specify Postal address\n';
	if (document.getElementById('frw_physical_address').value == '')
		validation+= '* You must specify Physical address\n';
	if (document.getElementById('frw_agree').checked == 0)
		validation+= '* You must agree to the Terms & Conditions\n';	
	if (document.getElementById('frw_email').value == '')
		validation+= '* You must specify an email address\n';
	else if (!echeck(document.getElementById('frw_email').value))
		validation+= '* You must specify a valid email address\n';
	
	if (validation == '')
	{
		return true;
	}
	else
	{
		alert (validation)
		return false;
	}
}

function validateFPForm ()
{
	var validation = '';
	if (document.getElementById('frw_name').value == '')
		validation+= '* You must specify Business name\n';
	if (document.getElementById('frw_memberid').value == '')
		validation+= '* You must specify Member ID\n';
	if (document.getElementById('frw_password').value == '')
		validation+= '* You must specify a Password\n';
	if (document.getElementById('frw_supply_partner').value == '')
		validation+= '* You must specify Supply Partner\n';
	if (document.getElementById('frw_no_fastpoints').value == '')
		validation+= '* You must specify No. fastPOINTS\n';
	if (document.getElementById('frw_agree').checked == 0)
		validation+= '* You must agree to the Terms & Conditions\n';	
	
	if (validation == '')
	{
		return true;
	}
	else
	{
		alert (validation)
		return false;
	}
}