/*
<Prologue>
		<Name>			jscript/AddEditUser.js			</Name>
		<Version>		2.0								</Version>
		<VersionDate>	2006-06-28						</VersionDate>
		<Application>	First Report					</Application>
		<Language>		JavaScript						</Language>
		<Owner>			First Report Ltd				</Owner>
		<CreatedDate>									</CreatedDate>
		<Copyright>		yMonda Ltd 2006					</Copyright>
		<Author>		W Charlton						</Author>
		<Output>		HTML							</Output>
		<DependsOn> </DependsOn>
		<Dependent></Dependent>
		<Notes>
				Validation functions For Admin Interface
		</Notes>
		<RevisionList>
			2005-06-23 VS replaced code to validate fields with regex
			2005-08-05 WHC replaced uk with GB and allowed blank postcode for non GB addresses
			2005-09-22 VS added JS code to validate Useer First Name to see if no Mr,Mrs,Dr,Ms were entered
			2005-09-26 VS added JS to validate AffiliateURL if Exists
			2005-11-17 VS added JS to validate OrgName
			2006-06-28 WHC Added Prologue, removed validation for PostTown
			2006-07-14 WHC Removed validation for Honorofic and position
			2007-07-11 JO Commented out CheckCreditsIfSelected
			2008-04-24 JO Added #637 Capture SectorID
		</RevisionList>
	</Prologue>
*/

var p_bSubmit = 0;
var counter = 0;
var Emails = "";

function ValidateForm(objForm){
	with (objForm)
	{
/*
		if (Honorific.value == "")
		{
				alert("Please select your Title.");
				Honorific.focus();
				return (false);
		}
*/

		if (!goodGivenName(GivenName, "Please enter a valid First Name"))
		{
			return (false);
		}

		if ((GivenName.value.toUpperCase() == "DR") ||(GivenName.value.toUpperCase() == "MR")||(GivenName.value.toUpperCase() == "MS")||(GivenName.value.toUpperCase() == "MRS"))
		{
			alert("Please enter a valid First Name");
			GivenName.focus();
			return (false);
		}

		if (!goodFamilyName(FamilyName, "Please enter a valid Surname"))
		{
			return (false);
		}

/*
		if (txtPosition.value == "")
		{
			alert("Please select value for 'Position:' field");
			txtPosition.focus();
			return (false);
		}

*/
		if ((OrgName.value.indexOf(' ') != -1) && (OrgName.value.length <= 3))
		{
			alert("Full company name is required");
			OrgName.focus();
			return (false);
		}

		if (!goodOrgName(OrgName, "Full company name is required"))
		{
			return (false);
		}

		if ("undefined" != typeof(AffiliateURL))
		{
				if (AffiliateURL.value == "")
				{
					alert("Please enter a value  for Affiliate URL field");
					AffiliateURL.focus();
					return (false);
				}
		}

		if (!goodAddress(Street, "Please enter a valid Address line1"))
		{
			return (false);
		}

/*
		if (!goodTownCounty(PostTown, "Please enter a valid Town/City/Area"))
		{
			return (false);
		}
*/

		if (Country.value =="GB")
		{
			if (!goodUKPostCode(PostCode, "Please enter a valid PostCode"))
			{
				return (false);
			}
		}

		if ((PostCode.value == "") && (Country.value =="GB"))
		{
			alert("Postcode value is Empty");
			PostCode.focus();
			return (false);
		}

		if (!goodEmailAddress(Email, "Please enter a Valid E-mail address"))
		{
			return (false);
		}

		if (Country.value =="GB")
		{
			if (!goodTel(Telephone, "Please enter a valid Telephone number"))
			{
				return (false);
			}
		}

		if (Mobile.value != "")
		{
			if (!goodMobile(Mobile, "Please enter a value for the \"Mobile Telephone\" field."))
			{
				return (false);
			}
		}

		if (Fax.value != "")
		{
			if (!goodTel(Fax, "Please enter a valid Fax number"))
			{
				return (false);
			}
		}

		if ("undefined" != typeof(AffiliateURL))
		{
		}
		else
		{
/*
			if (CheckCreditsIfSelected(objForm) == false)
			{
				return false;
			}
*/
		}
		
		if (SectorID.value == "0"){
			alert("Please select your sector.");
			SectorID.focus();
			return (false);
		}

		if (agree.checked == false)
		{
			alert("You must have read and agreed to the Terms and Conditions.");
			agree.focus();
			return (false);
		}



	}


	counter++;
	if(counter > 1)
	{
		if(counter > 2) { return false; }
		alert('Page is processing, please wait...\n\n' +
		'One click is sufficient.\n\n' +
		'Thank you for your patience.');
		return false;
	}

}

function CheckCreditsIfSelected(thisform) {
	myOption = -1;
	for (i=0; i< thisform.length; i++)
	{
		var e = thisform.elements[i] ;
		if ((e.checked) && (e.type == "radio"))
			{
				myOption = i;
			}
	}

	if (myOption == -1)
	{
		alert("You need to select some Credits for your account");
		return false;
	}
	else
	{
		return true;
	}
}
