function validatePage()
{
	//alert("page has been validated");
	document.TForm.submit();
}
///------------------------------------------------------------------------------------------------

function checkcompanyfield()
{
var sMsg = '';

	sMsg = sMsg + '\n';
	if(isNaN(document.TForm._CommissionRate.value)==true)
		{
			sMsg = 'The Commission Rate must be a valid price format ie 9.99 \n';
		}
	if(isNaN(document.TForm._TTFee.value)==true)
		{
			sMsg = sMsg + 'The TT Fee must be a valid format ie 9.99 \n';
		}
	if(isNaN(document.TForm._StdFeeIncrement.value)==true)
		{
			sMsg = sMsg + 'The Standard Fee Increment must be a valid price format ie 9.99 \n';
		}
		
	if ((isNaN(document.TForm._LandTaxFeeFH.value)==true)||(isNaN(document.TForm._LandTaxFeeLH.value)==true))
		{
			sMsg = sMsg + 'Please check the format of the Stamp Duty Land Tax Fee \n';
		}

	if ((document.TForm._TrackUpdByEmail.value=='Y')&&(document.TForm._TrackUpdEmailDest.value==''))
	{
			sMsg = sMsg + 'Please enter the destination of the Tracking Email Update.  \n';
	}

	if ((document.TForm._TrackUpdByEmail.value=='Y')&&(document.TForm._EmailAddress.value==''))
	{
		if ((document.TForm._TrackUpdEmailDest.value=='CO')||(document.TForm._TrackUpdEmailDest.value=='BO'))
		{
			sMsg = sMsg + 'Ensure that a valid email address is present \n';
		}
	}
	if ((document.TForm._TrackUpdByEmail.value=='F')&&(document.TForm._TrackUpdEmailDest.value==''))
	{
			sMsg = sMsg + 'Please enter the destination of the Tracking Fax Update.  \n';
	}

	if ((document.TForm._TrackUpdByEmail.value=='F')&&(document.TForm._FaxNo.value==''))
	{
		if ((document.TForm._TrackUpdEmailDest.value=='CO')||(document.TForm._TrackUpdEmailDest.value=='BO'))
		{
			sMsg = sMsg + 'Ensure that a valid Fax number is present \n';
		}
	}
	if (document.TForm._UserCode.value=='SU')
	{
		if ((document.TForm._SignedAgreement[1].checked==true) && (document.TForm._SignedDate.value!=''))
		{
			sMsg = sMsg + 'Ensure that the Agreement is signed before you assign a date \n';
		}
		
		if ((document.TForm._MHMSignedAgreement[1].checked==true) && (document.TForm._MHMSignedDate.value!=''))
		{
			sMsg = sMsg + 'Ensure that the MHM Agreement is signed before you assign a date \n';
		}
		
		if ((document.TForm._PPLSignedAgreement[1].checked==true) && (document.TForm._PPLSignedDate.value!=''))
		{
			sMsg = sMsg + 'Ensure that the PPL Agreement is signed before you assign a date \n';
		}
		
		if (document.TForm._CompanyType.value!='GP')
		{
			if ((document.TForm._SignedAgreement[1].checked==true) && (document.TForm._MHMSignedAgreement[1].checked==true) && (document.TForm._PPLSignedAgreement[1].checked==true) && (document.TForm._UpFrontComm[0].checked==true))
				{
					sMsg = sMsg + 'An Agreement must be signed for Up Front Commission to apply. \n';
				}
		}
	}
	
		
	if(isNaN(document.TForm._MoverCases.value)==true)
		{
			sMsg = sMsg + 'The Number of Mover Cases must be a valid number \n';
		}
		
	if(isNaN(document.TForm._RMCases.value)==true)
		{
			sMsg = sMsg + 'The Number of Re-mortgage Cases must be a valid number \n';
		}
		
	if ((document.TForm._HIPBranches.value=='A' || document.TForm._HIPBranches.value=='S') && (document.TForm._HIPSAgreement[0].checked==false))
		{
			sMsg = sMsg + 'Ensure that there is a HIP Agreement in place before you use Signed HIP Agreement for Branches \n';
		}	
		
		
	if ((document.TForm._LegalFeeInclCommission[1].checked==true ) && ((document.TForm._LHInclCommission[0].checked==true) || (document.TForm._MortgageInclCommission[0].checked==true)))
		{
			sMsg = sMsg + 'Ensure that the \n\n Include Legal Fee in Introducer Commission \n\n\ button is set if you want to include LH and/or Mortgage Fee in Introducer Commission \n';
		}	

	if ((document.TForm._IncludeHIPFee[0].checked==true ) && (document.TForm._LegalFeeInclCommission[0].checked==true ))
		{
			sMsg = sMsg + 'You cannot have Include HIP Fee and Include Legal Fee in Introducer commission \n';
		}
		
	if((sMsg != '') && (sMsg != '\n') && (sMsg != '\n\n'))
	{
		alert(sMsg);
		return false;
	} 
	else 
	{
		if ((document.TForm._CompanyType.value=='GP') && (document.TForm._VariableComm[0].checked==true))
		{
			sMsg = 'This group has been set up with variable commission.\n Please check that the variable commission has been set up. \n';
			alert(sMsg);
		}
		return true;
	}
}
///------------------------------------------------------------------------------------------------

function upfrontcommission()
{
var sMsg;
		
	if (document.TForm._SignedAgreement[1].checked==true)
	{	
		
		if (document.TForm._UpFrontComm[0].checked==true)
		{
			sMsg = 'A Signed Agreement no longer exists - the Up Front Commission will be set to NO. \n';
			alert(sMsg);
		}
		document.TForm._UpFrontComm[1].checked=true;
		return true;
	}
}
///////////////////////////////////////////////////////////////////////////////////////////

///------------------------------------------------------------------------------------------------
function showFeeEarnerList()
{
	if (document.TForm._CaseFirm.value=='PPL')
	{ 
		eval("document.all.MHM.style.display='none';");
		eval("document.all.PPL.style.display='inline';");
	}	
	else
	{ 
		eval("document.all.PPL.style.display='none';");
		eval("document.all.MHM.style.display='inline';");
	}
}

///------------------------------------------------------------------------------------------------

function resubmitcompform()
{
	document.TForm.action="AddSysCompany.asp";
	document.TForm.submit();
}
///------------------------------------------------------------------------------------------------

function resubmitbranchform()
{
	document.TForm.action="AddSysBranch.asp";
	document.TForm.submit();
}

///------------------------------------------------------------------------------------------------

function checkbranchfields(){
var sMsg = '';
	
	sMsg = sMsg + '\n';
	if((isNaN(document.TForm._SaleMortgageFee.value)==true)||(isNaN(document.TForm._PurchaseMortgageFee.value)==true))
		{
			sMsg = 'Please check the format of the Sale and Purchase Charge \n';
		}
		
	if ((isNaN(document.TForm._LandTaxFeeFH.value)==true)||(isNaN(document.TForm._LandTaxFeeLH.value)==true))
		{
			sMsg = sMsg + 'Please check the format of the Stamp Duty Land Tax Fee \n';
		}
		
	if (isNaN(document.TForm._TTFee.value)==true)
		{
			sMsg = sMsg + 'Please check the format of the TT Fee \n';
		}
		
	if (isNaN(document.TForm._BuySellCommission.value)==true)
		{
			sMsg = sMsg + 'Please check the format of the Sale/Purchase Commission \n';
		}
		
	if (isNaN(document.TForm._RemortgageCommission.value)==true)
		{
			sMsg = sMsg + 'Please check the format of the Re-mortgage Commission \n';
		}
		
	if ((document.TForm._TrackUpd[0].checked==true)&&(document.TForm._TrackUpdMethod.value==''))
	{
			sMsg = sMsg + 'Please enter the method of the Tracking Update distribution.  \n';
	}
	
	if ((document.TForm._TrackUpd[0].checked==true)&&(document.TForm._TrackUpdMethod.value=='E')&&(document.TForm._EmailAddress.value==''))
	{
		sMsg = sMsg + 'Ensure that a valid email address is present \n';
	}
	
	if ((document.TForm._TrackUpd[0].checked==true)&&(document.TForm._TrackUpdMethod.value=='F')&&(document.TForm._FaxNo.value==''))
	{
			sMsg = sMsg + 'Ensure that a valid Fax number is present.  \n';
	}
	
	if (document.TForm._UserCode.value=='SU')
	{
		if (document.TForm._AgreementActive[1].checked==true)
		{
			if ((document.TForm._SignedAgreement[0].checked==true) || (document.TForm._SignedDate.value!=''))
			{
				sMsg = sMsg + 'Ensure that the Agreement is active for the branch if agreement details have been entered \n';
			}
		}
		else
		{
			if ((document.TForm._SignedAgreement[1].checked==true) && (document.TForm._SignedDate.value!=''))
			{
				sMsg = sMsg + 'Ensure that the Agreement is signed before you assign a date \n';
			}
		}
		
		if (document.TForm._MHMAgreementActive[1].checked==true)
		{
			if ((document.TForm._MHMSignedAgreement[0].checked==true) || (document.TForm._MHMSignedDate.value!=''))
			{
				sMsg = sMsg + 'Ensure that the MHM Agreement is active for the branch if agreement details have been entered \n';
			}
		}
		
		else
		{
			if ((document.TForm._MHMSignedAgreement[1].checked==true) && (document.TForm._MHMSignedDate.value!=''))
			{
				sMsg = sMsg + 'Ensure that the MHM Agreement is signed before you assign a date \n';
			}
		}
		
		if (document.TForm._PPLAgreementActive[1].checked==true)
		{
			if ((document.TForm._PPLSignedAgreement[0].checked==true) || (document.TForm._PPLSignedDate.value!=''))
			{
				sMsg = sMsg + 'Ensure that the PPL Agreement is active for the branch if agreement details have been entered \n';
			}
		}
		else
		{
			if ((document.TForm._PPLSignedAgreement[1].checked==true) && (document.TForm._PPLSignedDate.value!=''))
			{
				sMsg = sMsg + 'Ensure that the PPL Agreement is signed before you assign a date \n';
			}
		}
		
		if ((document.TForm._SignedAgreement[1].checked==true) && (document.TForm._MHMSignedAgreement[1].checked==true) && (document.TForm._PPLSignedAgreement[1].checked==true) && (document.TForm._UpFrontComm[0].checked==true))
			{
				sMsg = sMsg + 'An Agreement must be signed for Up Front Commission to apply. \n';
			}
		
	}
	
	if (document.TForm._CaseCreateActive[1].checked==true)
	{
		if ((document.TForm._CaseFirm.value!='') || (document.TForm._CaseHandler.value!='') || (document.TForm._CallCentreTeam.value!=''))
		{
			sMsg = sMsg + 'Ensure that the Case Creation is Active for the branch before assigning Case Details  \n';
		}
	}
	
	if ((document.TForm._CaseFirm.value=='') && ((document.TForm._CaseHandler.value!='') || (document.TForm._CallCentreTeam.value!='')))
		{
			sMsg = sMsg + 'Please select the Firm in the Case Creation Details \n';
		}
		
	if (document.TForm._CaseCreateActive[0].checked==true)
	{
		if ((document.TForm._CaseFirm.value=='') && (document.TForm._CaseHandler.value=='') && (document.TForm._CallCentreTeam.value==''))
		{
			sMsg = sMsg + 'Case Create is Active for this branch - Please complete the Case Details  \n';
		}
	}
	
	if (document.TForm._MHMIDAgreement[0].checked==true)
		{
			if (document.TForm._MHMIDActive[1].checked==true)
			{
				sMsg = sMsg + 'Ensure that the MHM Agency ID Agreement is active for the branch \n';
			}
		}
		
	if (document.TForm._PPLIDAgreement[0].checked==true)
		{
			if (document.TForm._PPLIDActive[1].checked==true)
			{
				sMsg = sMsg + 'Ensure that the PPL Agency ID Agreement is active for the branch \n';
			}
		}
		
	if(isNaN(document.TForm._MoverCases.value)==true)
		{
			sMsg = sMsg + 'The Number of Mover Cases must be a valid number \n';
		}
		
	if(isNaN(document.TForm._RMCases.value)==true)
		{
			sMsg = sMsg + 'The Number of Re-mortgage Cases must be a valid number \n';
		}

			
	if (document.TForm._HIPSActive[1].checked==true  && (document.TForm._HIPEnabled[0].checked==true || document.TForm._HIPSAgreement[0].checked==true || document.TForm._HIPSSignedDate.value!=''))
		{
			sMsg = sMsg + 'Please ensure the HIPS Agreement Active for Branch is set \n';
		}
		
	if (document.TForm._HIPEnabled[0].checked==true)
		{
			if (document.TForm._CoHIPAgreement.value!='Y' || document.TForm._CoHIPBranches.value!='S')
			{
				sMsg = sMsg + 'To Select Branch for Company HIPs please ensure there is a \n HIP agreement and Signed HIP Agreement for Some Branches set at Company level\n';
			}
		}
	
	if (document.TForm._PriceBundleActive[1].checked==true  && document.TForm._PriceBundle[0].checked==true)
		{
			sMsg = sMsg + 'Please ensure the Price Bundle Active for Branch is set \n';
		}
	
	if ((document.TForm._LegalFeeInclCommission[1].checked==true ) && ((document.TForm._LHInclCommission[0].checked==true) || (document.TForm._MortgageInclCommission[0].checked==true)))
		{
			sMsg = sMsg + 'Ensure that the \n\n Include Legal Fee in Introducer Commission \n\n\ button is set if you want to include LH and/or Mortgage Fee in Introducer Commission \n';
		}
	
	if((sMsg != '') && (sMsg != '\n') && (sMsg != '\n\n'))
	{
		alert(sMsg);
		return false;
	} 
	else 
	{
		return true;
	}
}

///------------------------------------------------------------------------------------------------

function opencompanydetails(companyid)
{
	var sURL;

	sURL='../../asp/Usermanagement/ViewCompanyContact.asp';
	
	window.open(sURL + '?CompanyID=' + escape(companyid) + '&TaskWindow=Y','CompanyTASK','');
}	
///------------------------------------------------------------------------------------------------

function openbranchdetails(branchid,companyid)
{
	var sURL;

	sURL='../../asp/Usermanagement/ViewBranchContact.asp';
	
	window.open(sURL + '?BranchID=' + escape(branchid) + '&CompanyID=' + escape(companyid) + '&TaskWindow=Y','BranchTASK','');
}	

//------------------------------------------------------------------------------------------------
function ClearLookupFields()
{
	if ((document.TForm._LoginCompanyType.value=='SO')||(document.TForm._UserType.value=='5'))
	{
		document.TForm._cCompanyName.value='';
		document.TForm._cBranchName.value='';
	}
	else
	{
		document.TForm._cBranchName.value='';
	}
}
//------------------------------------------------------------------------------------------------
function ClearInfoLookupFields()
{
	document.TForm._cCompanyName.value='';
}
///////////////////////////////////////////////////////////////////////////////////////////
function Mandatoryfields()
{
	var sMsg = '';
	var sIntroCode;
	
		if ((document.TForm._cCompanyName.value=='')||(document.TForm._cBranchName.value==''))
		{
			sMsg = sMsg + '\n';
			sMsg = sMsg + 'Please ensure you select both a company and a branch. \n';
			sMsg = sMsg + '\n';
			alert(sMsg);
			return false;
		}
		else
		{
			document.TForm._cIntroducerCode.value = document.TForm._cIntroducerCode.value + '-' + document.TForm._cBranchCode.value;
			
			if (document.TForm._cBuyingSelling.value=='4')
			{
				document.TForm.action="../../asp/QuoteUser/makeRemortgageQuote.asp?QuotationRequestID=" + escape(document.TForm._cQuotationRequestID.value) + "&IntroducerCode=" + escape(document.TForm._cIntroducerCode.value) + "&QuotationRefCode=" + escape(document.TForm._cQuotationRefCode.value);				
			}
			else
			{
				document.TForm.action="../../asp/QuoteUser/MakeMasterQuote.asp?QuotationRequestID=" + escape(document.TForm._cQuotationRequestID.value) + "&IntroducerCode=" + escape(document.TForm._cIntroducerCode.value) + "&QuotationRefCode=" + escape(document.TForm._cQuotationRefCode.value) + "&BuyingSelling=" + escape(document.TForm._cBuyingSelling.value);				
			}
			document.TForm.submit();	
			return true;
		}
}

///------------------------------------------------------------------------------------------------
function settobranchsearch()
{
	document.TForm._TypeOfSearch[1].checked = true;
}
//------------------------------------------------------------------------------------------------
function companynameorder()
{
	document.TForm._SearchOrder.value='0';
	document.TForm.submit();	
}
//------------------------------------------------------------------------------------------------
function introducercodeorder()
{
	document.TForm._SearchOrder.value='1';
	document.TForm.submit();	
}
//------------------------------------------------------------------------------------------------

//------------------------------------------------------------------------------------------------
function branchnameorder()
{
	document.TForm._SearchOrder.value='0';
	document.TForm.submit();	
}
//------------------------------------------------------------------------------------------------
function branchcodeorder()
{
	document.TForm._SearchOrder.value='1';
	document.TForm.submit();	
}
//------------------------------------------------------------------------------------------------



