var bNotUK = false

function B2BNavigate(theForm,destination,ID){
		theForm.action=destination+"?id=" + ID;
		disableButtons(theForm)
		theForm.submit();
}

function B2BClientUnlockFormNavigate(theForm,ID){
	B2BNavigate(theForm,"clientunlock.asp",ID)
}

function B2BFormNavigate(theForm,ID){
	B2BNavigate(theForm,"default.asp",ID)
}

function B2BAccountNavigate(theForm,ID){
	B2BNavigate(theForm,"account.asp",ID)
}

function B2BDetailsNavigate(theForm,ID){
//	B2BNavigate(theForm,"details.asp",ID)
	//set default destination
	theForm.action="details.asp?id=" + ID;
	//determine if need to go to set up futurepay
	var pm = document.getElementById("txt_PayMethod")
	var pbfp = document.getElementById("PayByFuturePay")
	var fpid = document.getElementById("FuturePayID")
	if(pbfp.options[pm.selectedIndex].value==1){
		if(fpid.value=='' || fpid.value=='0'){
			theForm.action="FuturePay.asp?ID=2" //"BrokerApply.asp?id=" + fpp;
		}
	}
	disableButtons(theForm)
	theForm.submit();
}

function B2BCertFormNavigate(theForm){
	B2BNavigate(theForm,"certificate.asp","1&CID="+ theForm.CertNo.value)
}

function B2BCertificateNavigate(QID){
		var strDestination
		strDestination = "/shippers/quote/certificatedisplay.asp?KEY=" + jsEncryptString(QID)
		window.open(strDestination, '_blank', 'toolbar=no,status=no,address=no,scrollbars=yes,menubar=no,resizable=yes,directories=no,fullscreen=no')
}

function B2BAgentFormNavigate(theForm,ID){
	B2BNavigate(theForm,"agent.asp",ID)
}

function B2BAgentShipFFNavigate(theForm){
		disableButtons(theForm)
		document.location = "../shippers/forwarders/default.asp"
}

function B2BAgentShipmentNavigate(theForm){
		theForm.action="../shippers/quote/recall.asp";
		setCookie("ClientName", theForm.txt_AgentName.value, 8)
		setCookie("ClientID", theForm.txt_AgentID.value, 8)
		//theForm.ClientName.value = theForm.txt_AgentName.value
		//theForm.ClientID.value = theForm.txt_AgentID.value
		disableButtons(theForm)
		theForm.submit();
}

function B2BQuoteCertificateNavigate(theForm){
		var strDestination
		strDestination = "/shippers/quote/certificatedisplay.asp?KEY=" + jsEncryptString(theForm.txt_QuoteID.value)
		window.open(strDestination, '_blank', 'toolbar=no,status=no,address=no,scrollbars=yes,menubar=no,resizable=yes,directories=no,fullscreen=no')
		
}

/*function B2BNewQuoteNavigate(theForm){
		theForm.action="../shippers/quote/default.asp";
		setCookie("ClientName", theForm.txt_AgentName.value, 8)
		setCookie("ClientID", theForm.txt_AgentID.value, 8)
		disableButtons(theForm)
		theForm.submit();
}*/
function B2BNewQuoteNavigate(theForm, agentName, agentID){
		theForm.action="../shippers/quote/default.asp";
		setCookie("ClientName", agentName, 8)
		setCookie("ClientID", agentID, 8)
		disableButtons(theForm)
		theForm.submit();
}

function readCookie(name){
	return WM_readCookie(WM_readCookie(document.cookie, "GoCargo", ";"), name, "&")
}

function WM_readCookie(strCookie, name, delim) {
    if(strCookie == '') { // there's no cookie, so go no further
	return false; 
    } else { // there is a cookie
	var firstChar, lastChar;
	var theBigCookie = strCookie;
	firstChar = theBigCookie.indexOf(name + "=");	// find the start of 'name'
	var NN2Hack = firstChar + name.length;
	if((firstChar != -1) && (theBigCookie.charAt(NN2Hack) == '=')) { // if you found the cookie
	    firstChar += name.length + 1; // skip 'name' and '='
	    lastChar = theBigCookie.indexOf(delim, firstChar); // Find the end of the value string (i.e. the next ';').
		if(lastChar == -1) lastChar = theBigCookie.length; //neither delimiter found - use end of string
	    return theBigCookie.substring(firstChar, lastChar);
	} else { // If there was no cookie of that name, return false.
	    return '';
	}
    }	
} // WM_readCookie

function setCookie (name, value, hours) {
	var not_NN2 = (navigator && navigator.appName 
		       && (navigator.appName == 'Netscape') 
		       && navigator.appVersion 
		       && (parseInt(navigator.appVersion) == 2))?false:true;

	if(hours && not_NN2) { // NN2 cannot handle Dates, so skip this part
	    if ( (typeof(hours) == 'string') && Date.parse(hours) ) { // already a Date string
		var numHours = hours;
	    } else if (typeof(hours) == 'number') { // calculate Date from number of hours
		var numHours = (new Date((new Date()).getTime() + hours*3600000)).toGMTString();
	    }
	}
	var newCookie = name + '=' + value //+ ((numHours)?(';expires=' + numHours):'')
	newCookie = newCookie.replace(' ', '+')
	var strCookie = unescape(WM_readCookie(document.cookie, "GoCargo", ";"))
	var strNewCookie
	var firstChar, lastChar
	firstChar = strCookie.indexOf(name + "=");
	if(firstChar ==-1){
		strNewCookie = strCookie + "&" + newCookie
	} else {
		lastChar = strCookie.indexOf("&", firstChar);
		if(lastChar == -1) lastChar = strCookie.length;
		strNewCookie = strCookie.substring(0, firstChar) + newCookie + strCookie.substring(lastChar , strCookie.length )
	}
	killCookie()
	document.cookie = "GoCargo=" + strNewCookie + '; path=/' //replace cookie
}	//setCookie

function killCookie(){
	var kill_time = new Date("January 1, 1970");
	var kill_string = "GoCargo=stub;expires=" + kill_time.toGMTString();
	document.cookie = kill_string;
}	//killCookie

function B2BQuoteFormNavigate(theForm,ID){
		theForm.action="quote.asp?id=" + ID;
		disableButtons(theForm)
		theForm.submit();
}

function B2BValidateAgent(theForm){
	
	var bWarning = false;
	
	if (theForm.txt_AgentName.value.length==0){
		alert("Please enter your client's company name in the space provided..")
		theForm.txt_AgentName.focus();
		return false;
	}

	if (theForm.txt_FirstName.value.length==0){
		alert("Please enter your client's first name in the space provided..")
		theForm.txt_FirstName.focus();
		return false;
	}

	if (theForm.txt_Surname.value.length==0){
		alert("Please enter your client's surname in the space provided..")
		theForm.txt_Surname.focus();
		return false;
	}
	
	if (theForm.txt_PositionHeld.value.length==0){
		alert("Please enter your client's position in the space provided..")
		theForm.txt_PositionHeld.focus();
		return false;
	}

	if (theForm.txt_Address1.value.length == 0) {
		alert("Please enter the first line of your client's address in the space provided..")
		theForm.txt_Address1.focus();
		return false;
	}

	if (theForm.txt_Town.value.length == 0) {
		alert("Please enter the town of your client's address in the space provided..")
		theForm.txt_Town.focus();
		return false;
	}

	if ((theForm.txt_County.value.length == 0) && (theForm.txt_County.className == "comp")) {
		alert("Please enter the county of your client's address in the space provided..")
		theForm.txt_County.focus();
		return false;
	}
	
	if (theForm.txt_PostCode.value.length == 0) {
		alert("Please enter your client's postcode in the space provided..")
		theForm.txt_PostCode.focus();
		return false;
	}

	if (theForm.txt_CountryID.options[theForm.txt_CountryID.selectedIndex].text != "United Kingdom"){
		bNotUK = true
		switch (theForm.txt_AgentTypeID.value){
			case "2":
				alert("Sorry. We can only provide insurance cover to companies based in the UK.")
				return false;
				break
			case "1":
				alert("Warning: A non-UK address has been selected")
				break
		}
	}

	if (theForm.txt_Telephone.value.length>0){
		if (!isPhone(theForm.txt_Telephone.value)){
			alert("Invalid telephone number")
			theForm.txt_Telephone.focus();
			return false;
		}
	} else {
		alert("Please enter your client's telephone number in the space provided..")
		theForm.txt_Telephone.focus();
		return false;
	}

	if (theForm.txt_Fax.value.length > 0){
		if (!isPhone(theForm.txt_Fax.value)){
			alert("Invalid fax number")
			theForm.txt_Fax.focus();
			return false;
		}
	}
	
	if (!theForm.txt_BusinessImport.checked && !theForm.txt_BusinessExport.checked && !theForm.txt_BusinessSellBuy.checked){
		alert("One or more business types must be selected");
		return false;
	}	
	
	if (theForm.txt_GoodsType.value.length == 0){
		alert("A type of goods must be entered")
		theForm.txt_GoodsType.focus()
		return false;
	}
		
	if (!theForm.txt_CargoByAir.checked && !theForm.txt_CargoByOceanFCL.checked && !theForm.txt_CargoByOceanLCL.checked && !theForm.txt_CargoByRoadRail.checked){
		alert("One or more transport methods must be selected")
		return false;
	}
	
	if (theForm.txt_AnnualInsured.value.length == 0){
		alert("An annual value of insured cargo must be entered")
		theForm.txt_AnnualInsured.focus()
		return false;
	} else {
		if (!isNumeric(theForm.txt_AnnualInsured.value)){
			alert("Annual value of insured cargo must be numeric")
			theForm.txt_AnnualInsured.focus()
			return false;
		} else {
			if (theForm.txt_AnnualInsured.value == 0 || theForm.txt_AnnualInsured.value > 999999999999999999){
				alert("Annual value of insured cargo must be greater than 0 and less than 999999999999999999")
				theForm.txt_AnnualInsured.focus()
				return false;
			}
		}
	}

	//JPipe 14/09/06
/*  JPipe 15/09/06	if (theForm.txt_MarineCargo.value == 1){
		alert("Sorry. We cannot offer your client cover through this website. \n\nThey should use their current Marine Cargo Policy.");
		theForm.txt_MarineCargoUnderwriter.focus()
		return false;
	}*/
	
	if ((theForm.txt_MarineCargo.value == 1) && theForm.txt_MarineCargoUnderwriter.value.length == 0){
		alert("The marine cargo underwriter must be entered")
		theForm.txt_MarineCargoUnderwriter.focus()
		return false;
	}

	if (theForm.txt_MarineCargoWithdrawn.value == 1){
		alert("Sorry. We cannot offer cover for you through this website. \n\nPlease contact GoCargoInsurance using the details on the Contact page");
		return false;
	}
	
	if (theForm.txt_RegistrationEmail.value.length == 0) {
		alert("An email address must be provided")
		theForm.txt_RegistrationEmail.focus();
		return false;
	}else{
		if(!isEmail(theForm.txt_RegistrationEmail.value)){
			alert("A valid email address must be entered")
			theForm.txt_RegistrationEmail.focus();
			return false;
		}
	}

	if (theForm.txt_ClientLossesCount.value.length == 0){
		alert("The number of insurance losses must be entered")
		theForm.txt_ClientLossesCount.focus()
		return false;
	}else{
		if (!isNumeric(theForm.txt_ClientLossesCount.value)){
			alert("The number of insurance losses must be entered")
			theForm.txt_ClientLossesCount.focus()
			return false;
		}
	}
	
	if (theForm.txt_ClientClaimsValue.value.length == 0){
		alert("The total value of insurance claims must be entered")
		theForm.txt_ClientLossesCount.focus()
		return false;
	}else{
		if (!isCurrency(theForm.txt_ClientClaimsValue.value)){
			alert("The total value of insurance claims must be entered")
			theForm.txt_ClientClaimsValue.focus()
			return false;
		}
	}
	
	if (bWarning){
		alert("WARNING: Not all fields to activate this agent have been entered, however, Agent details will be updated.")
	}
	
	return true;
}

function B2BValidateQuote(theForm){

	if (!theForm.txt_PackedProtected.checked){
		alert("Goods that are not fully packed and protected cannot be insured");
		theForm.txt_PackedProtected.focus();
		return false;
	}


	if (theForm.txt_ConveyanceSea.checked && !theForm.txt_EnclosedContainer.checked){
		alert("All goods shipped by sea must be in a fully enclosed ISO container");
		return false;
	}

	if (!theForm.txt_ConveyanceRoadRail.checked && !theForm.txt_ConveyanceAir.checked && !theForm.txt_ConveyanceSea.checked){
		alert("One or more conveyance method must be selected");
		return false;
	}	
	
	if (theForm.txt_CommodityCategoryID.value == 0){
		alert("A 'Commodity Category' must be selected");
		theForm.txt_CommodityCategoryID.focus();
		return false;
	}

	if (theForm.txt_ConditionID.value == 0){
		alert("A 'Goods Condition' must be selected");
		theForm.txt_ConditionID.focus();
		return false;
	}
	if (theForm.txt_FromLocation.value.length == 0){
		alert("A 'From Location' must be entered");
		theForm.txt_FromLocation.focus();
		return false;
	}

	if (theForm.txt_FromCountryID.value == 0){
		alert("A 'From Country' must be selected");
		theForm.txt_FromCountryID.focus();
		return false;
	}

	if (theForm.txt_ToLocation.value.length == 0){
		alert("A 'To Location' must be entered");
		theForm.txt_ToLocation.focus();
		return false;
	}
	
	if (theForm.txt_ToCountryID.value == 0){
		alert("A 'To Country' must be selected");
		theForm.txt_ToCountryID.focus();
		return false;
	}

	if ((theForm.txt_SumInsured.value - 0) == 0){
		alert("Sum Insured value must be more than zero"); 
		theForm.txt_SumInsured.focus();
		return false;
	}

	if (!isDate(theForm.txt_EstDepartureDate.value, "dd/MM/yyyy")){
		alert("Estimated departure date must be a valid date (dd/mm/yyyy)");
		theForm.txt_EstDepartureDate.focus();
		return false;
	}
	
	return true;	
}

function B2BValidateQuoteDraft(theForm) {
	if (theForm.txt_GoodsDescription.value.length == 0){
		alert("WARNING: Description of goods and packing must be entered");
		theForm.txt_GoodsDescription.focus();
//		return false;
	}
	return true;
}

function ConveyanceSea(theForm) {
	theForm.txt_EnclosedContainer.disabled = (theForm.txt_ConveyanceSea.checked==false);
	return true
}

function ConvertToSelectedCurrency(theValue, theCurrencyControl){
	var ExchRateFactor = theCurrencyControl.options[theCurrencyControl.selectedIndex].attributes.getNamedItem("Extra").value
	return theValue * ExchRateFactor
}

function GetSelectedCurrencyCode(theCurrencyControl){
	var SelectedCurrencyCode = theCurrencyControl.options[theCurrencyControl.selectedIndex].attributes.getNamedItem("Extra1").value
	return SelectedCurrencyCode
}

function GetDiv(sDiv){
    var div;
    if (document.getElementByName)
        div = document.getElementByName(sDiv).nodeValue;
    else if (document.all)
        div = eval("window." + sDiv);
    else if (document.layers)
        div = document.layers[sDiv].nodeValue;
    else
        div = null;
    return div;
}	

function B2BPrepareReport(theForm, act){
	var Year
	var Month
	var ReportID
	var Posted
	var strID
	var strReport
	var strMonth
	switch (theForm.BordereauxMonth.value){
		case "0":	Month = 'mm'; strMonth = 'All'; break
		default: Month = theForm.BordereauxMonth.value;strMonth = theForm.BordereauxMonth.options[theForm.BordereauxMonth.selectedIndex].text;break
	}
	theForm.ReportMonth.value = strMonth
	switch (theForm.BordereauxYear.value){
		case "0":	Year = 'yyyy'; strYear = 'All'; break
		default: Year = theForm.BordereauxYear.value; strYear = Year; break
	}
	theForm.ReportYear.value = strYear;
	
	Posted = theForm.PostState.options[theForm.PostState.selectedIndex].value
	theForm.ReportType.value = theForm.OutputFormat.options[theForm.OutputFormat.selectedIndex].value
	switch (theForm.ReportType.value){
		case 'detail': strID = '8';	break
		case 'summary':	strID = '9'; break
		default: break
	}
	strReport = strID + Month + Year + Posted + theForm.BrokerID.value
	theForm.Report.value = strReport
	if (strID != ''){
		switch (act){
			case "DOWNLOAD": DownloadB2BFile(strReport); break
			case "VIEW": B2BAccountNavigate(theForm, "2"); break
		}
	}
}

function DownloadB2BFile(strReport) {
	open("/admin/GoCargo.asp?ID=" + strReport,"Download","resizable=yes,status=yes,location=no,toolbar=yes,scrollbars=yes,left=100,top=30,screenX=0,screenY=0");
}

function B2BValidateBroker(theForm){
	
	var bWarning = false;
	
	if (theForm.txt_BrokerName.value.length==0){
		alert("Please enter your company name in the space provided.")
		theForm.txt_BrokerName.focus();
		return false;
	}

	if (theForm.txt_ContactName.value.length==0){
		alert("Please enter your full name in the space provided.")
		theForm.txt_ContactName.focus();
		return false;
	}

	if (theForm.txt_Address1.value.length==0){
		alert("Please enter the first line of your address in the space provided.")
		theForm.txt_Address1.focus();
		return false;
	}
	
	if (theForm.txt_Town.value.length==0){
		alert("Please enter your town/city in the space provided.")
		theForm.txt_Town.focus();
		return false;
	}

	if (theForm.txt_County.value.length == 0) {
		alert("Please enter the county of your address in the space provided.")
		theForm.txt_County.focus();
		return false;
	}

	if (theForm.txt_Postcode.value.length == 0) {
		alert("Please enter the postcode of your address in the space provided.")
		theForm.txt_Postcode.focus();
		return false;
	}

	if (theForm.txt_Telephone.value.length>0){
		if (!isPhone(theForm.txt_Telephone.value)){
			alert("Please enter a valid telephone number in the space provided.")
			theForm.txt_Telephone.focus();
			return false;
		}
	} else {
		alert("Please enter a telephone number in the space provided..")
		theForm.txt_Telephone.focus();
		return false;
	}
	
	if (theForm.txt_EmailAddress.value.length == 0) {
		alert("Please enter your email address in the space provided.")
		theForm.txt_EmailAddress.focus();
		return false;
	}else{
		if(!isEmail(theForm.txt_EmailAddress.value)){
			alert("Please enter a valid email address in the space provided.")
			theForm.txt_EmailAddress.focus();
			return false;
		}
	}

	if (theForm.txt_IBAAccMgr.value.length == 0) {
		alert("Please enter the email address of the IBA Account Manager in the space provided.")
		theForm.txt_IBAAccMgr.focus();
		return false;
	}else{
		if(!isEmail(theForm.txt_IBAAccMgr.value)){
			alert("Please enter a valid email address in the space provided.")
			theForm.txt_IBAAccMgr.focus();
			return false;
		}
	}
	
	if (theForm.chkFSARegistered.checked == false){
		alert("Only companies that are FSA regulated can become Brokers")
		theForm.chkFSARegistered.focus();
		return false;
	}
	
	if (theForm.txt_FSAFirmRef.value.length == 0){
		alert("Please enter a FSA Reference in the space provided.")
		theForm.txt_FSAFirmRef.focus();
		return false;
	}else{
		if (!isFSARef(theForm.txt_FSAFirmRef.value)){
			alert("Please enter a valid FSA Reference in the space provided.")
			theForm.txt_FSAFirmRef.focus();
			return false;
		}
	}
	
	if (theForm.txt_EstimatedAnnualPolicies.value.length == 0){
		alert("Please enter an estimated annual policy count in the space provided.")
		theForm.txt_EstimatedAnnualPolicies.focus()
		return false;
	}else{
		if (!isNumeric(theForm.txt_EstimatedAnnualPolicies.value)){
			alert("Please enter an estimated annual policy count in the space provided.")
			theForm.txt_EstimatedAnnualPolicies.focus()
			return false;
		}
	}
	if (theForm.chkTerms.checked == false){
		alert("The Terms of Business must be read and accepted")
		return false;
	}
	
	return true;
}
function B2BValidateBrokerEdit(theForm){
	
	var bWarning = false;
	var yourCommission = '\n\nYour commission will be paid using these details.'
	
	if (theForm.txt_BrokerName.value.length==0){
		alert("Please enter your company name in the space provided.")
		theForm.txt_BrokerName.focus();
		return false;
	}

	if (theForm.txt_ContactName.value.length==0){
		alert("Please enter your full name in the space provided.")
		theForm.txt_ContactName.focus();
		return false;
	}

	if (theForm.txt_Address1.value.length==0){
		alert("Please enter the first line of your address in the space provided.")
		theForm.txt_Address1.focus();
		return false;
	}
	
	if (theForm.txt_Town.value.length==0){
		alert("Please enter your town/city in the space provided.")
		theForm.txt_Town.focus();
		return false;
	}

	if (theForm.txt_County.value.length == 0) {
		alert("Please enter the county of your address in the space provided.")
		theForm.txt_County.focus();
		return false;
	}

	if (theForm.txt_Postcode.value.length == 0) {
		alert("Please enter the postcode of your address in the space provided.")
		theForm.txt_Postcode.focus();
		return false;
	}

	if (theForm.txt_Telephone.value.length>0){
		if (!isPhone(theForm.txt_Telephone.value)){
			alert("Please enter a valid telephone number in the space provided.")
			theForm.txt_Telephone.focus();
			return false;
		}
	} else {
		alert("Please enter a telephone number in the space provided..")
		theForm.txt_Telephone.focus();
		return false;
	}
	
	if (theForm.txt_EmailAddress.value.length == 0) {
		alert("Please enter your email address in the space provided.")
		theForm.txt_EmailAddress.focus();
		return false;
	}else{
		if(!isEmail(theForm.txt_EmailAddress.value)){
			alert("Please enter a valid email address in the space provided.")
			theForm.txt_EmailAddress.focus();
			return false;
		}
	}

	if (theForm.txt_IBAAccMgr.value.length == 0) {
		alert("Please enter the email address of the IBA Account Manager in the space provided.")
		theForm.txt_IBAAccMgr.focus();
		return false;
	}else{
		if(!isEmail(theForm.txt_IBAAccMgr.value)){
			alert("Please enter a valid email address in the space provided.")
			theForm.txt_IBAAccMgr.focus();
			return false;
		}
	}
	
	if (theForm.chkFSARegistered.checked == false){
		alert("Only companies that are FSA regulated can become Brokers")
		theForm.chkFSARegistered.focus();
		return false;
	}
	
	if (theForm.txt_FSAFirmRef.value.length == 0){
		alert("Please enter a FSA Reference in the space provided.")
		theForm.txt_FSAFirmRef.focus();
		return false;
	}else{
		if (!isFSARef(theForm.txt_FSAFirmRef.value)){
			alert("Please enter a valid FSA Reference in the space provided.")
			theForm.txt_FSAFirmRef.focus();
			return false;
		}
	}
	
	if (theForm.txt_EstimatedAnnualPolicies.value.length == 0){
		alert("Please enter an estimated annual policy count in the space provided.")
		theForm.txt_EstimatedAnnualPolicies.focus()
		return false;
	}else{
		if (!isNumeric(theForm.txt_EstimatedAnnualPolicies.value)){
			alert("Please enter an estimated annual policy count in the space provided.")
			theForm.txt_EstimatedAnnualPolicies.focus()
			return false;
		}
	}
	if(theForm.txt_BankName.type!="hidden"){
		if (theForm.txt_BankName.value.length == 0){
			alert("Please enter the name of your bank."+yourCommission)
			theForm.txt_BankName.focus()
			return false;
		}
		if (theForm.txt_BankAddress1.value.length == 0){
			alert("Please enter the address of your bank."+yourCommission)
			theForm.txt_BankAddress1.focus()
			return false;
		}
		if (theForm.txt_BankTown.value.length == 0){
			alert("Please enter the town of your bank."+yourCommission)
			theForm.txt_BankTown.focus()
			return false;
		}
		if (theForm.txt_BankCounty.value.length == 0){
			alert("Please enter the county of your bank."+yourCommission)
			theForm.txt_BankCounty.focus()
			return false;
		}
		if (theForm.txt_BankPostcode.value.length == 0){
			alert("Please enter the postcode of your bank."+yourCommission)
			theForm.txt_BankPostcode.focus()
			return false;
		}
		if (theForm.txt_BankAccountNo.value.length == 0){
			alert("Please enter your account number."+yourCommission)
			theForm.txt_BankAccountNo.focus()
			return false;
		}
		if (theForm.txt_BankBranchCode.value.length == 0){
			alert("Please enter the sort code of your bank."+yourCommission)
			theForm.txt_BankBranchCode.focus()
			return false;
		}else{
			if (!isBranch(theForm.txt_BankBranchCode.value))	{
				alert("Please enter the sort code of your bank in the form nn-nn-nn."+yourCommission)
				theForm.txt_BankBranchCode.focus();
				return false;
			}
		}
	}
	return true;
}
function B2BFuturePayNavigate(theForm,ID,userLevel){
	if(userLevel==null){
		theForm.action="FuturePay.asp?ID="+ID
	}else{
		if(userLevel.parseInt!=0){ 
			//logged on - go to broker update screen
			theForm.action="details.asp?ID="+ID
		}else{
			//not logged on - go to apply screen
			theForm.action="BrokerApply.asp?id=" + ID;
			//B2BApplyNavigate(theForm, ID, null)
		}
	}
	disableButtons(theForm)
	theForm.submit();
}

function B2BApplyNavigate(theForm, ID, fpp){
	//set default destination
	theForm.action="BrokerApply.asp?id=" + ID;
	//determine if futurepay set up required
	if(fpp!=null){
		var pm = document.getElementById("txt_PayMethod")
		var pbfp = document.getElementById("PayByFuturePay")
		var fpid = document.getElementById("FuturePayID")
		if(pbfp.options[pm.selectedIndex].value==1){
			if(fpid.value=='' || fpid.value=='0')	theForm.action="BrokerApply.asp?id=" + fpp;//theForm.action="FuturePay.asp" 
		}
	}
	disableButtons(theForm)
	theForm.submit();
}

function isFSARef(ref){
	if (window.RegExp) {
			var re = new RegExp('^[0-9]{6}$', '');
            return re.test( ref );
	}
	else {
			if (ref.length != 6) { return false } else { return true }
	}
}

function B2BCheckClaimsLimits(){
	if(document.getElementsByName("ClientStatusAllowShipment")[0].value == "0"){
		document.getElementById("divNewShipment").style.display = 'none'
		document.getElementById("divRequestUnlock").style.display = 'inline'
	}else{
		document.getElementById("divNewShipment").style.display = 'inline'
		document.getElementById("divRequestUnlock").style.display = 'none'
	}
	if(document.getElementsByName("ClientStatusID")[0].value == "1"){
		if(document.getElementById("UnlockEmailSent")){
			alert("This client will not be able to buy insurance due to their claim history \n\n An unlock request for this client has been sent to the underwriters")
		}else{
			alert("This client will not be able to buy insurance due to their claim history \n\n Click 'Request Unlock' to send an email to the underwriters requesting the restriction to be lifted")
		}
	}
}
function B2BValidatefuturePay(theForm){
	if (theForm.txt_CardType.selectedIndex==0){
		alert("Please select the card type from the list provided.")
		theForm.txt_CardType.focus();
		return false;	
	}
	if (theForm.txt_CardName.value==""){
		alert("Please enter the name on the card in the space provided.")
		theForm.txt_CardName.focus();
		return false;	
	}
	
	if (theForm.txt_CardNumber.value==""){
		alert("Please enter the card number in the space provided.")
		theForm.txt_CardNumber.focus();
		return false; 
	} 
	else if (!isNumeric(theForm.txt_CardNumber.value)) {
		alert("Card Number must be numeric with no spaces")
		theForm.txt_CardNumber.focus();
		return false; 
	} 
 	if (theForm.txt_CardMonthExp.selectedIndex==0){
		alert("Please enter the expiry month of the card in the space provided.")
		theForm.txt_CardMonthExp.focus();
		return false;	
	}
	if (theForm.txt_CardYearExp.selectedIndex==0){
		alert("Please enter the expiry year of the card in the space provided.")
		theForm.txt_CardYearExp.focus();
		return false;	
	}
	if (theForm.txt_CardCVV.value.length==0){
		alert("Please enter the card security code in the space provided.")
		theForm.txt_CardCVV.focus();
		return false;
	}
	else {if (theForm.txt_CardCVV.value.length < 3)
		{
		alert("Security code must be 3 or 4 characters")
		theForm.txt_CardCVV.focus();
		return false;
		}
		else if (!isNumeric(theForm.txt_CardCVV.value)) 
			{
			alert("Card Security Code must be numeric")
			theForm.txt_CardCVV.focus();
			return false;
		} 	
	}
	if (theForm.txt_Email.value.length == 0) {
		alert("An email address must be provided")
		theForm.txt_Email.focus();
		return false;
	}else{
		if(!isEmail(theForm.txt_Email.value)){
			alert("A valid email address must be entered")
			theForm.txt_Email.focus();
			return false;
		}
	}
	
	return true
}