// JavaScript Document
/* BSL Basic variables for Help */
var Months = ['zero','January','February','March','April','May','June','July','August','September','October','November','December'];

var BrowserSelRows = [null, null, null, null, null, null, null, null];
var FormKeyOK = false;
var MenuOnBy = null;
var MenuOn = null;
var SubMenuOn = null;  //This LHS menu is the current one
var MClearID = null;

var ValueTop = 0;//Offset into the value list
var ValueSeek = null;
var ValuePlac = null;
var ValueNewTop = 0;//Offset into the value list to set it to if the user asks for more
var ValueShowall = false;//Last time this was asked for
var ValueOb = null;
var ValueHoldFlag = false;
var ValueLaunch = null;
var ValueDivOb = null;
var ValueFld = null;
var ValueVisible = false;
var ValueTime =null;
//var ValueMenu = null;
var ValueTO = null;
var unloadBackSpace = false;

var XHelpOnBy = null;
var XHelpOn = null;
var UseVis = false;
var HClearID = null;
var PermitUnload = false;
var gotDefFocus = false;
if(!window.gl_esc)gl_esc = 'Cancel';
if(!window.gl_ret)gl_ret = null;
var gl_sel = null;//For managing the login screen options right
var last_ai_cdt = null;
var disv = new Array();
var acl = new Array();

var global_waitdbl = false;
var dblClickLatch = null;
var formLoaded = false;

//StdUnload is set in the body of the html document, and is called whenever the user navigates,
//PermitUnload is set to true by any function which detects programmed navigation
function StdUnload(e){
	if(!PermitUnload){
		if(unloadBackSpace){//Simply eat up backspace initiated unloads
			unloadBackSpace = false;
			return "Please don't navigate away from this page - instead use the buttons provided.";
		}
		if (e && e.clientY < 0) {
			if (confirm('Logout?'))
			{
				//They want to go...INTERNAL
				var objForm = document.INTERNAL;
				if(!objForm){objForm = document.ROINTERNAL;}
				if(objForm){
					objForm.BSLAction.value = 'BSLAppTerm';
					objForm.submit();
					return 'You will be logged out if you click OK.';
				}else{
					//objform not found, default action
					return 'Please log out correctly!  Click Cancel to return...';
				}
			}else{
				return 'Click Cancel to continue...';
			}
		}else{
			return 'You may log out by closing the window, but risk losing a little data.\n\nIt is better to log out correctly.  Click Cancel to do this...';
		}
	}
}

//Performance timer functions
function OnLoadX(){
//	var objForm = eval("document.INTERNAL");
	var objForm = document.INTERNAL;
	if(!objForm){objForm = document.ROINTERNAL;}
//	if(!objForm){objForm = eval("document.ROINTERNAL");}
//	if(!objForm){objForm = eval("document.BROWSER");}
	if(objForm){
//		objForm.BSLLoadTime.value = new Date().getTime();
	}
	if(window.OnLoad)OnLoad();//Call the per page on load function
	defaultFocus();//Maybe this needs to be after the given OnLoad()?
	formLoaded = true;
}

function mnOut() {
	MClearTimerSet();
}

function MClearTimerReset(){
if(MClearID){
	window.clearTimeout(MClearID);
	MClearID = null;
	}
}

function MClearTimerSet(){
if(MClearID){
	window.clearTimeout(MClearID);
	MClearID = null;
	}
MClearID = window.setTimeout('MClearTimer()',1800);
}

function MClearTimer(){
//alert('timer');
HideOld();
}

function ValueHold(){
	//cannot disappear it here
	ValueHoldFlag = true;
}

function ValueUnhold(){
	//can disappear it here
	ValueHoldFlag = false;
}

function HideValStop(){
if(ValueTime){
	window.clearTimeout(ValueTime );
	ValueTime  = null;
	}
}

function HideVal(){
ValueTime = window.setTimeout('HideValAux()',200);
}

function HideValAux(){
if(ValueHoldFlag){
	ValueTime = window.setTimeout('HideValAux()',200);
	return;
}
ValueTime = null;
if(ValueDivOb && !ValueHoldFlag){
  if(UseVis){ValueDivOb.visibility = "hide";}else{ValueDivOb.className="hidden";}
  ValueVisible = false;
  }
}

function HideOld(){
	if(MenuOn){
		if(UseVis){MenuOn.visibility = "hide";}else{MenuOn.className="hidden";}
		if(MenuOn.onHide){
			MenuOn.onHide();
		}
		MenuOn = null;
		if(SubMenuOn)smoff(SubMenuOn);
		last_ai_cdt = null;
	}
	HideOld2();
}

function HideOld2(){
	if(MenuOn2){
		if(UseVis){MenuOn2.visibility = "hide";}else{MenuOn2.className="hidden";}
		MenuOn2 = null;
		if(SubMenuOn2)smoff2(SubMenuOn2);
		last_ai_cdt = null;
	}
}

//Version 2
function mnOvr(src,mn,A) {
	if(!MTimerT2){
		if(MClearID){MClearTimerReset()};
		HideOld(); 
		MenuOnBy=src;
		var a = null;
		if(mn && mn.length>0)a = MM_findObj(mn);
		var ai = null;
		if (a) {
		  UseVis = true;
		  MenuOn = a;
		  SetPosBelowC(MenuOnBy,MenuOn,A);
		  a.visibility = "show";
		}else{
			ai = MM_findObj(mn+"I");
			if (ai) {
			  MenuOn = ai;
			  SetPosBelowC(MenuOnBy,MenuOn,A);
			  ai.className="visible";
			}
		}
	}
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}


// BROWSER SNIFFER (Sniff out the good and bad browsers)
function stringToNumber(s)
{
        return parseInt(('0' + s), 10);
}
function Is() {
   // convert all characters to lowercase to simplify testing
    var agt=navigator.userAgent.toLowerCase();

    // --- BROWSER VERSION ---
    this.major = stringToNumber(navigator.appVersion);
    this.minor = parseFloat(navigator.appVersion);

    this.nav  = ((agt.indexOf('mozilla')!=-1) && ((agt.indexOf('spoofer')==-1)
                && (agt.indexOf('compatible') == -1)));
    this.nav2 = (this.nav && (this.major == 2));
    this.nav3 = (this.nav && (this.major == 3));
    this.nav4 = (this.nav && (this.major == 4));
        
        //Netscape 6
        this.nav5 =     (this.nav && (this.major == 5));
        this.nav6 = (this.nav && (this.major == 5));
        this.gecko = (this.nav && (this.major >= 5));

    this.ie   = (agt.indexOf("msie") != -1);
    this.ie3  = (this.ie && (this.major == 2));
    this.ie4  = (this.ie && (this.major == 3));
    this.ie5  = (this.ie && (this.major == 4));


    this.opera = (agt.indexOf("opera") != -1);
     
    this.nav4up = this.nav && (this.major >= 4);
    this.ie4up  = this.ie  && (this.major >= 4);
}

var is = new Is();

function onerror() {
    document.location.href = "javascript:";
}

// DOCUMENT OBJECT SWITCH (Used for building cross_browser functions)
var doc = "";
var sty = "";
var htm = "";

if(is.ns4) {
    doc = "document";
    sty = "";
    htm = ".document"
} else if(is.ie4) {
    doc = "document.all";
    sty = ".style";
    htm = ""
}

// MY get parent - might be buggy
function getEltParNode (elt) {
	if(is.ie4up){
		return elt.parentNode;
	}else{
		return elt.parentElement;
	}
}

/////////***********************************
// New position stuff
function setEltLeft (elt, x) {
  if (is.nav4)     elt.left=x;
  else if (is.ie4up) elt.style.pixelLeft=x;
  else if (is.gecko) elt.style.left = (x + "px");
}


/* Returns left edge of elt in pixels. */
function getEltLeft (elt) {
  if (is.nav4)     return (elt.left);
  else if (is.ie4up) return (elt.style.pixelLeft);
  else if (is.gecko) return stringToNumber(elt.style.left);
}

/* Sets top edge of elt in pixels. */
function setEltTop (elt, y) 
{ if (is.nav4)     elt.top=y;
  else if (is.ie4up) elt.style.pixelTop=y;
  else if (is.gecko) elt.style.top= (y + "px");
}

/* Returns top edge of elt in pixels. */
function getEltTop (elt) 
{ if (is.nav4)     return (elt.top);
  else if (is.ie4up) return (elt.style.pixelTop);
  else if (is.gecko) return stringToNumber(elt.style.top);
}

/* Returns width of elt in pixels. */
function getEltWidth(elt) {

  if (is.nav4) {
    if (elt.document.width)
      return elt.document.width;
    else
      return elt.clip.right - elt.clip.left;
  }
  if (is.ie4up) {
    if (elt.style.pixelWidth)
      return elt.style.pixelWidth;

    else
      return elt.offsetWidth;
  }
  if (is.gecko) {
    if (elt.style.width)
      return stringToNumber(elt.style.width);
    else
      return stringToNumber(elt.offsetWidth);
  }
  return -1;
}

/* set width of elt in pixels */
function setEltWidth(elt,wdth)
{
        if(is.nav4)
    { 
             elt.document.width = wdth;
    }
    else if(elt.style)
    { 
        elt.style.width = wdth;
    }
}

/* Returns height of elt in pixels. */
function getEltHeight(elt) {
  if (is.nav4) {
    if (elt.document.height)
      return elt.document.height;
    else
      return elt.clip.bottom - elt.clip.top;
  }
  if (is.ie4up) {
    if (elt.style.pixelHeight)
      return elt.style.pixelHeight;
    else
      return elt.clientHeight;
  }
  if (is.gecko) {
    if (elt.style.height)
      return stringToNumber(elt.style.height);
    else
      return stringToNumber(elt.offsetHeight);
  }
  return -1;
}

/* set width of elt in pixels */

function setEltHeight(elt,hght)
{
        if(is.nav4)
    { 
                elt.document.height = hght;
    }
    else if(elt.style)
    { 
        elt.style.height = hght;
    }
}

//************************************************* MAIN MENU STUFF STARTS
/*position finding. used for the menu*/
function whereami(ob){
	alert('findPosX: '+findPosX(ob)+'\nfindPosY: '+findPosY(ob)+'\nHeight: '+getEltHeight(ob)+'\nWidth: '+getEltWidth(ob));
}

function findPosX(obj) {
	var curleft = 0;
	if (obj.offsetParent) {
		while (obj.offsetParent) {
			//alert("object = " + obj.id);
			if (obj.name!="X") {
				curleft += obj.offsetLeft;
			}
			//else{
//				curleft += obj.offsetLeft;
//			}
			obj = obj.offsetParent;
		}
	} 
	else if (obj.x)
		curleft += obj.x;
	return curleft;
}

function findPosY(obj) {
	var curtop = 0;
	if (obj.offsetParent) {
		while (obj.offsetParent) {
			curtop += obj.offsetTop
			obj = obj.offsetParent;
		}
	}
	else if (obj.y)
		curtop += obj.y;
	return curtop;
}

/* Menu and Tab Control */
var shownMenu = -1;
var shownTab = 1;

var ignoreGlobalClick = false;
var mnuMax = 10;
var MenusDisabled = false;

function ovrShowTab(mnuID,tdHead) {
	//highlights the tabHead if the menus enabled
	if (!MenusDisabled) {
		if(shownTab==mnuID){
			tdHead.className='TabHeadOn';
		}else{
			tdHead.className='TabHeadOn';
		}
	}
}

function clkShowTab(mnuID,tdHead) {
	if (!MenusDisabled) {
		ShowTab(mnuID,tdHead);
	}
}

function ovrShowMenu(mnuID,tdHead) {
	//highlights the menuHead if the menus enabled
	if (!MenusDisabled) {
		tdHead.className='MenuHeadOn';
		//shows menu(menuID) only if there is a menu being shown
		if (shownMenu!=-1 && shownMenu!=mnuID) {
			ShowMenu(mnuID,tdHead);
		}
	}
}

function clkShowMenu(mnuID,tdHead) {
	if (!MenusDisabled) {
		if (shownMenu==-1) {
			ShowMenu(mnuID,tdHead);
			ignoreGlobalClick=true;
		}
		else {
			hideMenu(shownMenu);
			shownMenu=-1;
		}
	}
}

function globalClose() {
	if (!ignoreGlobalClick){
		CloseMenu(shownMenu);
	}else{
		ignoreGlobalClick=false;
	}
}

function mnuUnselect(mnuID) {
	//this turns the highlight off, only if this menu is not being shown
	//alert(mnuID);
	if (shownMenu!=mnuID && !MenusDisabled) {
		HM = eval("HM" + mnuID);
		if (HM) {HM.className='MenuHeadOff';}
	}
}

function tabUnselect(mnuID,tdHead) {
	if (!MenusDisabled) {
		if(shownTab==mnuID){
			tdHead.className='TabHeadSelected';
		}else{
			tdHead.className='TabHeadOff';
		}
	}
}

function ShowTab(mnuID,tdHead) { //this
	var menu;
	var HM;
	CloseTab();
	if (mnuID <= mnuMax) { 
		if (document.all["Tab"+mnuID]) {
			menu = eval("Tab"+mnuID);
			menu.className = 'show';
			HM = eval("TB"+mnuID);
			HM.className='TabHeadSelected';
			shownTab=mnuID;
		}
	}
	else
		alert("failed to open menu " + mnuID);
}

function CloseTab() {
	if (shownTab!=-1) {
		hideTab(shownTab);
		unSelectTab(shownTab);
		shownTab=-1;
	}
}

function ShowMenu(mnuID,tdHead) { //this
	var menu;
	var HM;
	CloseMenu();
	if (mnuID <= mnuMax) { 
		if (menu = MM_findObj("Menu"+mnuID)) {
			//alert('sm');
		//if (document.all["Menu"+mnuID]) {
			//menu = eval("Menu"+mnuID);
			menu.className = 'show';
			setEltLeft (menu, findPosX(tdHead));
			setEltTop (menu,findPosY(tdHead) + getEltHeight(tdHead));
			//HM = eval("HM"+mnuID);
			HM = MM_findObj("HM"+mnuID);
			HM.className='MenuHeadOn';
			shownMenu=mnuID;
		}
	}
	else
		alert("failed to open menu " + mnuID);
}

function CloseMenu() {
	if (shownMenu!=-1) {
		hideMenu(shownMenu);
		unSelectHM(shownMenu);
		shownMenu=-1;
	}
}

function hideMenu(mnuID){
	var menu;
	//menu = eval("Menu" + mnuID);
	menu = MM_findObj("Menu" + mnuID);
	if (menu) {menu.className= 'hid';}
}

function hideTab(mnuID){
	var menu;
	//menu = eval("Tab" + mnuID);
	menu = MM_findObj("Tab" + mnuID);
	if (menu) {menu.className= 'hid';}
}

function unSelectHM(mnuID) {
	var HM;
//	HM = eval("HM" + shownMenu);
	HM = MM_findObj("HM" + shownMenu);
	if (HM) {HM.className= 'MenuHeadOff';}
}

function unSelectTab(mnuID) {
	var HM;
	//HM = eval("TB" + shownTab);
	HM = MM_findObj("TB" + shownTab);
	if (HM) {HM.className= 'TabHeadOff';}
}

function DisableHeaders() {	//this
	MenusDisabled = true;
		if(document.body.all){
			for (i=1; i<=mnuMax; i++) {
				if (document.all["HM" + i]) {
					mnuHead = eval("HM" + i);
					mnuHead.className = "MenuHeadDisabled";
				}
			}
			for (i=1; i<=mnuMax; i++) {
				if (document.all["TB" + i]) {
					mnuHead = eval("TB" + i);
					mnuHead.className = "TabHeadDisabled";
				}
			}
		}else if (document.getElementsByTagName) {
			for (i=1; i<=mnuMax; i++) {
				if (document.getElementById("HM" + i)) {
					mnuHead = document.getElementById("HM" + i);
					mnuHead.className = "MenuHeadDisabled";
				}
			}
			for (i=1; i<=mnuMax; i++) {
				if (document.getElementById("TB" + i)) {
					mnuHead = document.getElementById("TB" + i);
					mnuHead.className = "TabHeadDisabled";
				}
			}
		}
}

//************************MAIN MENU STUFF ENDS 
	
//add the following code to every cubmit button rq.
//onclick="disableInputs();submit()"
	var flgNoValidate = false; 
	var flgSubmitted = false;
	var CID = "a";
	
	function menuClick(mval, form) {
		CID=mval;
		CloseMenu();
		var objForm = eval("document." + form);
		if (onceOnly(objForm)) objForm.submit();
	}

	function brClick(bval){
		CID=bval;
		if (onceOnly(document.BSLBrow))	document.BSLBrow.submit();
	}
	
	//genSave is to permit us to click somewhere and end up as if we clicked the SAVE standard button
	//This reults in a REFRESH which lets us simply do nothing except reset the session 30 minute timeout 
	function genSave(){
		menuClick('Save','INTERNAL');
	}
	
	function mout_aux(aEvent,cname){
		var ob;
		if(aEvent){
			ob = aEvent.target;
			if(ob.tagName.toUpperCase()=='INPUT'){
				ob = ob.parentNode;
			}
			ob = ob.parentNode;
		}else{
			ob = window.event.srcElement;
			//Old version in ESF: if(ob.isContentEditable)ob = ob.parentElement;
			if(ob.isContentEditable){
				ob = ob.parentElement;
			}else{
				if(ob.type=="checkbox"){
					ob = ob.parentElement;
				}
			}
			ob = ob.parentElement;
		}
		ob.className =cname;
	}
	
	function smout(aEvent){
		mout_aux(aEvent, 'BRwOffSel');
	}
	
	function mout(aEvent){
		mout_aux(aEvent, 'BRwOff0');
	}
	
/*	function smout(){
		var ob = window.event.srcElement;
		if(ob.isContentEditable){
			ob = ob.parentElement;
		}else{
			if(ob.type=="checkbox"){
				ob = ob.parentElement;
			}
		}
		ob = ob.parentElement;
		ob.className ='BRwOffSel';
	}
	
	function mout(){
		var ob = window.event.srcElement;
		if(ob.isContentEditable){
			ob = ob.parentElement;
		}else{
			if(ob.type=="checkbox"){
				ob = ob.parentElement;
			}
		}
		ob = ob.parentElement;
		ob.className ='BRwOff0';
	}*/

	function srClick(bval,ob){
		//Onscreen markup of new selected record
		var objForm ;
		var tvar = true;
		var BOff = 0;
		//var ob = window.event.srcElement;
		if(bval.substring(0,1)!='S'){BOff = bval.substring(0,1);}
		if(BrowserSelRows[BOff]!=null){
			BrowserSelRows[BOff].className = "BRwOff0";
			BrowserSelRows[BOff].onmouseout = mout;
			tvar = false;
		}
		BrowserSelRows[BOff] = ob;
		ob.className = "BRwOnSel";
		ob.onmouseout = smout;
		if(bval.substring(0,1)!='S'){
			objForm = eval("document.INTERNAL.BSLBrowserPos"+bval.substring(0,1));
		}else{
			objForm = document.BROWSER.BSLBrowserPos;
		}
		objForm.value = bval;
		//alert('Hi! '+objForm.value);
	}
	
	function StatusToggle(){
		StatusMessage.className=(StatusMessage.className=="hid" ? "show" : "hid");
	}
		
	function HelpToggle(){
		HelpRegion.className=(HelpRegion.className=="hid" ? "show" : "hid");
	}
		
	function submitOnce() {
		if(document.body.all){
			var objInput = document.body.all.tags("input"); //get the first table
			for (i=0;i<objInput.length;i++) {
				if (objInput[i].type=="submit") objInput[i].disabled = true;
			}
			DisableHeaders();
		}else if (document.getElementsByTagName) {
			var objInput = document.body.getElementsByTagName('INPUT');
			for (i=0;i<objInput.length;i++) {
				if (objInput[i].type=="submit") objInput[i].disabled = true;
			}
			DisableHeaders();
		}
	}	
/*	function submitOnce() {
			var objInput = document.body.all.tags("input"); //get the first table
			for (i=0;i<objInput.length;i++) {
				if (objInput[i].type=="submit") objInput[i].disabled = true;
			}
		DisableHeaders();
	}	*/

	function aboutToSubmit(){
		//Finally check to see if there is a routine bslOnSubmit()
		//Java version
		if(window.bslOnSubmitInternal){
			bslOnSubmitInternal();
		}
		//User version
		if(window.bslOnSubmit){
			bslOnSubmit();
		}
	}

	function onceOnly(frm){
		PermitUnload = true;
		frm.BSLButton.value = CID;
		if (flgSubmitted != true) {
			//We are going to submit
			xkvEnab();
			//Mark submission time
			var objForm = document.INTERNAL;
			if(!objForm){objForm = document.ROINTERNAL;}
			if(!objForm){objForm = document.BROWSER;}
			if(objForm){
//				objForm.BSLSubmitTime.value = new Date().getTime();
			}
			if (flgNoValidate != true) {
					//Validate here...
					if(!bslVForm(frm))return false;
					aboutToSubmit();
					flgSubmitted = true;
					submitOnce();
					return true;
			} else {
				aboutToSubmit();
				flgSubmitted = true;
				return true;
			}
		} else {
			/*sErr = "Duplicate Submission Detected\r\r"
			sErr = sErr+"Forms should only be submitted once, pressing the\r"
			sErr = sErr+"<enter> key or <return> key multiple times can often\r"
			sErr = sErr+"result in creating multiples of the item requested.\r\r"
			sErr = sErr+"The extra submission has been cancelled. Please wait \r"
			sErr = sErr+"for the servers response to your initial submission.\r"
			alert(sErr);*/
			return false;
		}
	}
	
	function listSelect(srchText) {
		//example tag in textbox: onkeyup="listSelect(this.value, 'selectlist')"
		// (where selectlist is the ID of the SELECT object 
		// you want the autoselection to occur in.)
		var list;
		var i;
		var txtLen;
		txtLen = srchText.length;
		list = document.getElementById('selList');
		if(list){
			for (i=0;i<list.length;i++) {
				if (new String(srchText).toLowerCase()== new String(list.options[i].text).substr(0, txtLen).toLowerCase()) {
					list.selectedIndex = i;
					i=list.length; //exit nastily
				}
			}
		}
	}
	

//The next function allows us to open a nearly featureless window.
function HelpWOpen(xloc){
w=window.open(xloc,"Help_Window","location=no,Width=400,Height=260,scrollbars,resizable");
w.focus();
}

function WOpen(loc,props){
window.open(loc,'_blank',props);
}

//Help functions: We emulate the mouse hover over input approach, but without the timer, so clearing is immediate
function SetPosBelow(U,D){
SetPosBelowAcross(U,D,0);
}

function SetPosBelowAcross(U,D,A){
var x = findPosX(U);
var y = findPosY(U);
var delta = getEltHeight(U);
setEltLeft(D,x+A);
setEltTop(D,y+delta);
}

function SetPosBelowC(U,D,A){
//A is a string determining placement stuff.
if(!A) {A = '--';}else{A = A + '--';}
var x = findPosX(U);
var y = findPosY(U);
var A1 = A.charAt(0);
var A2 = A.charAt(1);
var deltay = getEltHeight(U);
var deltax = getEltWidth(U);
//if (!deltay){deltay = U.height}
//if (!deltax){deltax = U.width}
//if (!deltay || deltay<4){deltay = 32;}
//if(!deltax)deltax = 0;

if(A1=='T')deltay=0; //The only non default setting
if(A1=='U'){
	if(UseVis){
		deltay= - D.height;
	}else{
		deltay += -D.clientHeight;
	}
}
if('ABCDEFGHIJKLMNOPQRS'.indexOf(A1)>=0){
	deltay = 'ABCDEFGHIJKLMNOPQRS'.indexOf(A1)*3;
}
if('abcdefghijklmnopqrstuvwxyz'.indexOf(A1)>=0){
	deltay = 'abcdefghijklmnopqrstuvwxyz'.indexOf(A1)*-10;
}
if('ABCDEFGHIJKLMNOPQRST'.indexOf(A2)>=0){
        deltax = 'ABCDEFGHIJKLMNOPQRST'.indexOf(A2)*20;
}
if('01234567890'.indexOf(A2)>=0){
	deltax = ('01234567890'.indexOf(A2)*15+10)*deltax;
}
if(y+deltay<0)deltay = -y;

//if(UseVis){D.left = x+deltax; D.top = y+deltay;}else{D.style.pixelLeft = x+deltax;D.style.pixelTop = y+deltay;}
setEltLeft(D,x+deltax);
setEltTop(D,y+deltay);
}

function SetPosBelowH(U,D){
var x = findPosX(U);
var y = findPosY(U);
var delta = getEltHeight(U)+2;
var w = getEltWidth(U);
if(x+w>780){x = 780 - w;}
setEltLeft(D,x);
setEltTop(D,y+delta);
/*var delta = U.style.pixelHeight+2;
if (!delta || delta<4){delta = 28;}
//IE does not support window.innerWidth
if(x+D.style.pixelWidth>780){x = 780 - D.style.pixelWidth;}
if(UseVis){D.left = x; D.top = y+delta;}else{D.style.pixelLeft = x;D.style.pixelTop = y+delta;}*/
}

function HideOldHlp(){
if(XHelpOn){
  if(UseVis){XHelpOn.visibility = "hide";}else{XHelpOn.className="hidden";}
  XHelpOn = null;
  }
}

function HlpOut(src,mn) {
//alert('Help out!');
HideOldHlp(); 
}

function HlpOvr(src,mn) {
	HideOldHlp(); 
	XHelpOnBy=src; 
	var a = MM_findObj(mn);
	var ai = null;
	if (a) {
	  UseVis = true;
	  XHelpOn = a;
	  SetPosBelowH(XHelpOnBy,XHelpOn);
	  a.visibility = "show";
	}else{
	    ai = MM_findObj(mn+"I");
		if (ai) {
		  XHelpOn = ai;
		  SetPosBelowH(XHelpOnBy,XHelpOn);
		  ai.className="visible";
		}
	}
}

function mdays(m,y){
if(m==2){
  if(((y % 400)==0)||((y % 100) !=0)&&((y % 4)==0))return 29;
  return 28;
}else{
	if((m==4)||(m==6)||(m==9)||(m==11))return 30;
	return 31;
	}
}

function strValid(ob,s){
//version 1.0
var errstr,poskey,thestr,tdata,d,er,td,n,r;
//alert('Checking');
thestr = ob.value;
if(thestr=="")return true;
if(s=="D" || s=="d"){
	td = new Date();
	r = /\-/g;
	thestr = thestr.replace(r,'/');
	r = /\./g;
	thestr = thestr.replace(r,'/');
	d = thestr.split('/');
	if(d.length==1){
		//Has the user provided a meaningful string:
		n = thestr.length;
		if(n==3){
			d[0]=thestr.substr(0,2);
			d[1]=thestr.substr(2,1);
		}else if(n==4){
			d[0]=thestr.substr(0,2);
			d[1]=thestr.substr(2,2);
		}else if(n>4){
			d[0]=thestr.substr(0,2);
			d[1]=thestr.substr(2,2);
			d[2]=thestr.substr(4,n-4);
		}
	}
	if(d.length==1){
		//Use today for month and year
		d[1] = 1+td.getMonth();
		d[1] = d[1].toString();
	}
	if(d.length==2){
		//Use today for month and year
		d[2] = td.getFullYear();
		d[2] = d[2].toString();
	}
	if(d.length!=3){
		if(s=="D"){
			if(thestr=="")return true;
			alert('Invalid date: Please complete or remove what you have already typed!');
			return false;
			}
		alert('Invalid date: not enough slashes!');
		return false;
		}
	d[2]=parseInt(d[2],10);
	if(d[2]<100)d[2]=2000+d[2];	
	d[1]=parseInt(d[1],10);
	d[0]=parseInt(d[0],10);
	er = '';
	if(d[0]<1)er = '\nDay cannot be negative.';
	if(d[1]<1)er = er+ '\nMonth cannot be negative.';
	if(d[1]>12)er = er+ '\nMonth must not exceed 12.';
	if(d[0]>mdays(d[1],d[2])){
		if((d[1]>0)&&(d[1]<13))er = er+ '\n'+Months[d[1]]+' has only got '+mdays(d[1],d[2])+' days.';
		}
	if(er!=""){
		//alert('The date entered is not valid.d m y = '+d[0]+','+d[1]+','+d[2]);
		alert('The date entered is not valid.\n'+er);
		return false;
		}
	if(d[0]<10){d[0]='0'+parseInt(d[0],10);}
	if(d[1]<10){d[1]='0'+parseInt(d[1],10);}
	ob.value = d[0]+'/'+d[1]+'/'+d[2];
	}
if(s=="C"){
	r = /\,/g;
	thestr = thestr.replace(r,'');
  	if((thestr!="")&&isNaN(parseFloat(thestr))){
		alert('The entered value is not a number.');
		return false;
		}
	d = parseFloat(thestr).toString().split('.');
	if(d.length==1){
		ob.value = d[0].toString()+'.00';
	}else{
//	alert(d[0]+'-'+d[1]);
		d[1]=Math.round(parseFloat('0.'+d[1])*100);
		if(d[1]>=99.5){
			d[0] = parseInt(d[0],10)+1;
			ob.value = d[0].toString()+'.00';
		}else{
			d[1]=d[1].toString();
			if(d[1].length>2){d[1]=d[1].substring(1,2);}
			if(d[1].length==1){d[1]='0'+d[1];}
			ob.value = d[0]+'.'+d[1];
			}
		}
	ob.value = AddCommas(ob.value);
	return true;
	}
return true;
}

function AddCommas(s){
var n,t;
t = "";
n=s.length-6;
while(n>0){
	s=s.substring(0,n)+','+s.substring(n,30);
	n=n-3;
	}
return s;
}

/*ESF Version:
function FormKey(e){
	//Trap return
	var kp = window.event ? e.keyCode : e.which;
	if(kp==13 && !FormKeyOK){
		alert('Please do not use Enter!');
		return false;
	}else{
		return true;
	}
}
*/
function FormKey(e,frm,ret,esc){
	//VERSION 1.0.0 May 2007
	//Trap return
	//old:var kp = event.keyCode;
	var kp = window.event ? e.keyCode : e.which;
	//alert(kp);
	//We want to know if Alt is down...
	//if(event.altKey){
	//}
	if(kp==13){
		if(FormKeyOK)return true;
		if(!FormKeySubmit(frm,ret,gl_ret,true)){
			alert('Enter does not work on this screen.');
		}
		return false;
	}else{
		//alert(kp);
		if(kp==27){
		//  alert('esc');
		FormKeySubmit(frm,esc,gl_esc,true);
//		event.returnValue = true;
		}
	}
	e.returnValue = true;
	return true;
}

function keyLength(ob,s){
	if(s>0 && ob.value.length>s-1){
		ob.value = ob.value.substring(0,s-1);
		return false;
	}
	return true;
}

function keyValid(ob,s,e){
//version 1.0
//IE Only
var errstr,poskey,thekeystr;
poskey="*";
errstr = "Invalid key.";
if(s=="D"){
	errstr = 'This is a date field!\nDates must be entered dd/mm/yyyy.\n\nSeparators can be /, . or -.\n'
	poskey='1234567890/.-\n\r';
}
if((s=="N")||(s=="C"))poskey='1234567890,.-\n\r';
if(!e)e=window.event;
thekeystr = String.fromCharCode(window.event ? e.keyCode : e.which);
if((poskey!="*")&&(poskey.indexOf(thekeystr)==-1)&& thekeystr>=' '){
	alert(errstr+'\nPlease use only the following keys:\n\n'+poskey);
	e.returnValue = false;
	if(is.ie){
		e.cancelBubble = true;
	}else{
		e.stopPropagation();
	}
	return false;
	}
return true;
}

function selchg(f,mains,subs){
//f= form name, mains = the select ob, subs = name of other select
//This rountine is passed the name of the form, the master list and the sublists to alter
//It has to cope with there being . in names of select objects
//The . are not allowed in array names.
	var frm,elm,sublist,subsel,narr,narrv,r,s;
	sublist=subs.split(";");
	r = /\./g;
	frm = eval('document.'+f);
	for(var k=0;k<sublist.length;++k){
		elm = frm.elements[sublist[k]];
		s = sublist[k].replace(r,'_');
		if(subsel=elm){
			narr = eval(f+'_'+s+'_'+mains.value);
			narrv = eval(f+'_'+s+'_'+mains.value+'V');
			for (var i=(subsel.options.length-1); i>=0; i--) {
				subsel.options[i] = null;
			}
			for (var i=0;i<narr.length; i++) {
				subsel.options.add(new Option(narr[i],narrv[i]));
			}
		}
	}
}

function bslVFormValidate(m,v,t){
//m is the mask and v the value at present, t is the name of the field.
//The return value is a string indicating the error
//which is empty if there is no error
var Res;
Res = '';
if((m.substr(0,1)=='Y')&&(v==null || v=='')){
//alert(m+'\n'+v+'\n'+t);
	Res = '"'+t+'" must have a value';
	}
if((m.substr(0,1)=='Z')&&((v==null || v=='')||(parseFloat(v)==0))){
//alert(m+'\n'+v+'\n'+t);
	Res = '"'+t+'" must have a non-zero value';
	}
//alert(Res);
return Res;
}

function bslVForm(f){
//version 1.0
//f is the form to validate
//we see if there is a variable of the same name as the form objects we are looking for
var n,k,i,narr,s,r,Res,t;
r = /\./g;
Res='';
k=-1;
for(i=0;i<f.elements.length;++i){
	if(f.elements[i].type=='text'){
		s = f.elements[i].name; 
		//s = s.replace(r,'_');
		for(n=0;n<bslv.length;n+=3){
			if(s==bslv[n]){
				//We validate according to bslv[n+1]
				//This is a string which asserts some stuff about the field
				//It is of form <must_have _value=YN><type_spec=D:Date,I:Int,N:Number>
				//Perhaps more later...
				//All errors are stored in the string Res
				//The first field to go wrong is saved in k
				//alert('Got: '+s+' = '+bslv[n+1]+'('+f.elements[i].value+')');
				t = bslVFormValidate(bslv[n+1],f.elements[i].value,bslv[n+2]);
				if(t!=''){
					//alert('Error:'+t)
					if(k==-1)k = i;
					Res = Res + '\n' + t;
				}
				//f.elements[i].style = 'background-color:#FF8080';
				//f.elements[i].style = 'bslError';
				}
			}
		}
	}
if(Res=='')return true;
alert('Your data requires attention:\n'+Res);
f.elements[k].focus();
return false;
}

function ValueTOClear(){
	if(ValueTO){
		window.clearTimeout(ValueTO);
		ValueTO = null;
	}
}

function ValueList(f,ob){
	ValueOb = MM_findObj(f);
	ValueFld = f;
	ValueTOClear();
	ValueTop = 0;
	//Try setting ValueSeek here?
	ValueSeek
	ValueTO = window.setTimeout('ValueListTimer()',0);
	//We need the timeout to allow the event to fire
}

function ValueListTimer(){
	//Field name passed, and object 'this'
	//We read the value into string v
	var v = ValueOb.value;
	ValueSeek = v;
	//alert(v);
	r = /\./g;
	s = 'VALUES_'+ValueFld.replace(r,'_');
	//Does this give us a match?
	var testArray = eval(s);
	if(testArray){
		for(n=0;n<testArray.length;n+=1){
			if(v == testArray[n].substring(0,v.length)){
				//Capture the new text in v1
				v1 = testArray[n].substring(v.length);
				//Assign the value
				ValueOb.value = v+v1;
				var tr = ValueOb.createTextRange();
				if(tr!=null){
					try{
						if(tr.findText(v1,-1000,1))tr.select();
					}catch(err){}
//BAD BAD BAD finds the text in the FIRST HALF if it is there					if(tr.findText(v1))tr.select();
				}
				//alert('OK');
				return;
			}
//		ValueOb.value = v;
		}
	}
}

function ValueTest(f,ob) {
	//f is the ob name and ob is the calling ob, sometimes IDENTICAL...
	//f is ALSO the field identifier - e.g. REP.TITLE
	//we must replace .s and find the test array
	ValueOb = MM_findObj(f);
	r = /\./g;
	s = 'VALUES_'+f.replace(r,'_');
	t = eval(s);
	alert(t[0]);

/*	var tr = ValueOb.createTextRange();
	if(tr!=null){
		tr.findText('other client');
		tr.select();*/
}

function ValueShow(f,ob,plac) {
	ValueLaunch = ob;
	ValueShowAux(f,ob,false,plac);
}
function ValueShowAll(f) {
	//Do not alter the value launcher on All
	ValueTop = 0;
	ValueShowAux(f,ValueLaunch,true,ValuePlac);
	ValueLaunch.focus();
}

function ValueShowAux(f,ob,showall,plac) {
	//This shows VALUESDIV or VALUESDIVI
	//First build the div...
	HideValStop();
/*	if(ValueVisible){
		HideVal();
		if(!showall)return;
	}*/
	ValueShowall = showall;
	ValuePlac = plac;
	var mn = 'VALUESDIV';
	var a = MM_findObj(mn);
	if(a==null){
		ai = MM_findObj(mn+"I");
		ValueDivOb = ai;
	}else{
		ValueDivOb = a;
	}
	var A = null;
	ValueFld = f;
	ValueOb = MM_findObj(f);
	var listed = 0;
	if(ValueDivOb){
		listed=ValuesDivBuild(showall);
		if(listed>=0){
			if(listed>12){listed = 12;}
			var Car = 'abcdefghijklm'.charAt(listed);
			if(plac!=null && plac!='X'){
				Car = plac;
			}
			if (a) {
			  UseVis = true;
			  //SetPosBelowH(ob,a,A);
			  SetPosBelowC(ob,a,Car+'B');
			  a.visibility = "show";
			}else{
				if (ai) {
				  //SetPosBelowH(ob,ai,A);
				  SetPosBelowC(ob,ai,Car+'B');
				  ai.className="visible";
				}
			}
		}
	}
}

function ValuePgDn(){
	ValueTop = ValueNewTop;
	ValueShowAux(ValueFld,ValueLaunch,ValueShowall,ValuePlac);
}

function ValuePgUp(){
	ValueTop -= 20;
	if(ValueTop<0)ValueTop = 0;
	ValueShowAux(ValueFld,ValueLaunch,ValueShowall,ValuePlac);
}

function ValuesDivBuild(showall){
	//Build the div if possible
	r = /\./g;
	rs = /\'/g;
	s = 'VALUES_'+ValueFld.replace(r,'_');
	//Does this give us a match?
	var testArray = new Array();
	var CallForAll = false;
	if(showall){
		testArray = eval(s);
	}else{
		var parray = eval(s);
		if(parray){
			m=0;
			var v;
			var vo;
			vo= ValueOb.value;
			if(ValueSeek){
				v = ValueSeek;
				if(vo.length<v.length)v = vo;
				ValueSeek = v;
			}else{
				v= vo;
			}
			v = v.toUpperCase();
			var lastEntry = -1;
			var firstEntry = -1;
			var skippedArray = new Array();
			var skipCount = 0;
			for(n=0;n<parray.length;n++){
				if(v == parray[n].substring(0,v.length).toUpperCase()){
					testArray[m++] = parray[n];
					lastEntry = n;
					if(firstEntry==-1)firstEntry = n;
				}else{
					if(firstEntry>-1 && skipCount<12){
						skippedArray[skipCount++] = parray[n];
					}
				}
			}
			//if NOTHING selected then show all...
			if(firstEntry==-1){
				testArray = parray;
			}else{
				//If the resulting array is small we can supply more info if it is there...
				if(m<10){
					var sextra = 0;
					CallForAll = true;
					if(firstEntry>5){
						sextra = (10 - Math.ceil(m/2));
					}else{
						sextra = firstEntry;
					}
					m=0;
					testArray2 = new Array();
					for(n=firstEntry-sextra;n<firstEntry;n++){
						testArray2[m++] = parray[n];
					}
					for(n=0;n<testArray.length;n++){
						testArray2[m++] = testArray[n];
					}
					for(n=0;n<skippedArray.length;n++){
						testArray2[m++] = skippedArray[n];
						if(m>18)break;
					}
					testArray = testArray2;
				}
			}
		}
	}
	//Parse
	if(testArray){
		//This is the set of values to put into the popup
		var s = '<table bgcolor="#c43737" width="100" border="0" cellspacing="1" cellpadding="0" class="PopMenuTabSm">';
		
		if(ValueTop>0){
			s += '<tr><td class="PopMenuDefaultSm" onClick="ValuePgUp()">Up to more...</td></tr>';
		}else{
			s += '<tr><td class="PopMenuDefaultSm">Options...</td></tr>';
		}

		if(testArray.length<2 || CallForAll){
			s += '<tr><td nowrap class="PopMenuOffSm" onMouseOver="className=\'PopMenuOnSm\'" onMouseOut="className=\'PopMenuOffSm\'" onClick="ValueShowAll(\''+ValueFld+'\');">Click for all...</td></tr>';
		}
		listed = 0;
		if(ValueTop>=testArray.length)ValueTop = 0;
		for(n=ValueTop;n<testArray.length;n++){
//			s += '<tr><td nowrap class="PopMenuOffSm" onMouseOver="className=\'PopMenuOnSm\'" onMouseOut="className=\'PopMenuOffSm\'" onClick="ValueOb.value=\''+testArray[n]+'\';HideVal();">'+testArray[n]+'</td></tr>';
			s += '<tr><td nowrap class="PopMenuOffSm" onMouseOver="className=\'PopMenuOnSm\'" onMouseOut="className=\'PopMenuOffSm\'" onClick="ValueOb.value=\''+testArray[n].replace(rs,'\\\'')+'\';ValueSeek=ValueOb.value;ValueUnhold();HideVal();">'+testArray[n]+'</td></tr>';
//			s += '<tr><td nowrap class="PopMenuOffSm" onMouseOver="className=\'PopMenuOnSm\'" onMouseOut="className=\'PopMenuOffSm\'" onClick="ValueOb.value=\''+testArray[n]+'\';HideVal();">'+testArray[n]+'</td></tr>';
//			s += '<tr><td nowrap class="PopMenuOffSm" onMouseOver="className=\'PopMenuOnSm\'" onMouseOut="className=\'PopMenuOffSm\'" onClick="ValueOb.value=this.innerText;HideVal();">'+testArray[n]+'</td></tr>';
			listed += 1;
			if(listed>=18){
				s += '<tr><td class="PopMenuDefaultSm" onClick="ValuePgDn()">Down to more...</td></tr>';
				ValueNewTop = ValueTop + listed;
				break;
			}
		}
		s += '</table>';
		ValueDivOb.innerHTML = s;
		return listed;		
	}else{
		return 0;
	}
}

//************************** new to extend browser functionality

//acheck uses functionality imported by screens in javascript
//anything importing such stuff must provide the function getUseCi which must return a boolean

function acheck(acc,c,dcn){//dcn means dont change nar
	//Are the control features here?
	var dnf=null;
	if(window.accrefobfld && window.narobfld && (window.use_amount || (window.credobfld && window.debobfld))){
		//Establish rnum
		n = acc.name.lastIndexOf('.');
		rnum = parseInt(acc.name.substring(n+1,acc.name.length));
		ai = MM_findObj(accrefobfld+rnum);
		//Only proceed if acc matches ai
		var useCi = true;
		var useCiTitle = '';
		if(acc==ai){
		  var lacc = mypf(ai.value)*100;
		  if(acl[lacc] && acl[lacc].length>0){
			  useCi = (acl[lacc].charAt(0)=='C');
			  useCiTitle = acl[lacc].substring(1,acl[lacc].length);
		  }else{
			  useCi = true;
			  useCiTitle = '';
		  }
		  ai = MM_findObj(narobfld+rnum);
		  if(ai==null){
			alert('No nar ob.');
		  }else{
			if(!dcn && (ai.value==null || ai.value=='')){
			   //If defnarfld exists and can be found we use it as the precursor to the narrative
			   var narpc='';
			   if(window.defnarfld){
				   if(!(dnf = MM_findObj(defnarfld))){
					   alert('Missing defnarfld field: ' + defnarfld);
				   }else{
					   narpc = ((dnf.value==null || dnf.value == '')? '' : dnf.value + ' ');
				   }
			   }
			   ai.value = narpc + useCiTitle;
			} 
		  }

		   //If shtnarfld exists and the field associated with it exists too
		   //and defshtnarfld exists and has a value we assign
		   //the value of the n'th shtnarfld to the value in defshtnarfld
		   //but only if it is BLANK
		   if(!dcn && window.shtnarfld && window.defshtnarfld){
			   var si = null;
			   si = MM_findObj(shtnarfld+rnum);
			   if(si){
					if(!(dnf = MM_findObj(defshtnarfld))){
						alert('Missing defshtnarfld field: ' + defshtnarfld);
					}else{
						if(si.value==null || si.value=='')si.value = (dnf.value==null ? '' : dnf.value);
					}
			   }
		   }

		  if(!window.use_amount){
			  //credob is the ID of the ob
			  ci = MM_findObj(credobfld+rnum);
			  if(ci==null)alert('No ci ob.');
			  //debob is the ID of the ob
			  di = MM_findObj(debobfld+rnum);
			  if(di==null)alert('No di ob.'+debobfld+rnum);
			  //Do nothing if EITHER not found
			  if(ci!=null && di!=null){
				 if(!useCi){
				   ai = ci;
				   ci = di;
				   di = ai;
				 }
				 //We have to check that both values are null before interfering
				 //UNLESS dcn is true in which case we WANT to disable the ZERO one unless BOTH are zero
				 //var didit = false;
				 if(dcn){
					 //if either is null or empty AND THE OTHER NOT thend disable the null one
					 if((ci.value==null || ci.value=='' || parseFloat(ci.value)==0)&&(di.value!=null || di.value!='' || parseFloat(di.value)!=0)){
						 //We can act - ci is always the one to use
						 di.disabled = false;
						 ci.disabled = true;
						 ci.value="";
						 //didit=true;
						 //if(UseVis){di.visibility = "hide";}else{di.className="hidden";}
					 }
					 if((ci.value!=null || ci.value!='' || parseFloat(ci.value)!=0)&&(di.value==null || di.value=='' || parseFloat(di.value)==0)){
						 //We can act - ci is always the one to use
						 ci.disabled = false;
						 di.disabled = true;
						 di.value="";
						 //didit=true;
						 //if(UseVis){di.visibility = "hide";}else{di.className="hidden";}
					 }
					 //if(!didit)alert('Did not do '+n);
				 }else{
					 if((ci.value==null || ci.value=='' || parseFloat(ci.value)==0)&&(di.value==null || di.value=='' || parseFloat(di.value)==0)){
						 //We can act - ci is always the one to use
						 ci.disabled = false;
						 di.disabled = true;
						 //if(UseVis){di.visibility = "hide";}else{di.className="hidden";}
					 }
				 }
			  }
		  }
		}
		//Is there an update field defined?
		if(window.formLoaded && window.pybalfld){
			//There is a prev year balance field defined.  We execute an asynchronous update...
			n = acc.name.lastIndexOf('.');
			rnum = parseInt(acc.name.substring(n+1,acc.name.length));
			ai = MM_findObj(accrefobfld+rnum);
			//Only proceed if acc matches ai
			if(acc==ai){
				var pbacc = mypf(ai.value);
				//ai = MM_findObj(pybalfld+rnum);
				ajax1(pybalfld+rnum+'_flddiv','SOLA_GET_PY_BAL','GXTP_THEACCREF',pbacc);
			}
		}
		//Is there an update field defined for jnl?
		if(window.formLoaded && window.pyjnlfld){
			//There is a prev year balance field defined.  We execute an asynchronous update...
			n = acc.name.lastIndexOf('.');
			rnum = parseInt(acc.name.substring(n+1,acc.name.length));
			ai = MM_findObj(accrefobfld+rnum);
			//Only proceed if acc matches ai
			if(acc==ai){
				var pbacc = mypf(ai.value);
				//ai = MM_findObj(pybalfld+rnum);
				ajax1(pyjnlfld+rnum+'_flddiv','SOLA_GET_JNL','GXTP_THEACCREF',pbacc);
			}
		}
	}
	return strValid(acc,c);
}

function brNav(isCheck){
  ek = event.keyCode;
  //alert(ek);
  if(event.srcElement){
		elid = event.srcElement.name;
		n = elid.lastIndexOf('.');
		rnum = parseInt(elid.substring(n+1,elid.length));
		elid = elid.substring(0,n+1);
		ai = null;
		if(ek==38){
			//alert(elid+' up');
			//alert(elid+rnum);
		    rnum = rnum-1;
			ai = MM_findObj(elid+rnum);
		}
		if(ek==40){
		    rnum = rnum+1;
			//alert(elid+rnum);
			ai = MM_findObj(elid+rnum);
		}
		if(ai){
			//alert(ai.name);
			holdval = false;
			if(isCheck)holdval = ai.checked;
			ai.click();
			if(isCheck)ai.checked = holdval;
			ai.focus();
			//sfOb = ai;
			event.returnValue = false;
		}
  }
}

function xkvDisab(a){
	gotit = false;
	for(var n=0;n<disv.length;n++){
		if(a==disv[n])return;
	}
	disv[n]=a;
}

function xkvEnab(){
	for(var n=0;n<disv.length;n++){
		disv[n].disabled = false;
	}
}

function xkeyValid(t,c){
	if(window.credobfld && window.debobfld){
		thekeystr = String.fromCharCode(event.keyCode);
		n = t.name.lastIndexOf('.');
		rnum = parseInt(t.name.substring(n+1,t.name.length));
		aa = MM_findObj(debobfld+rnum);
		bb = MM_findObj(credobfld+rnum);
		if(aa!=null && bb!=null &&(aa==t || bb==t)){
			if(thekeystr=='-'){
			  //First see if we can swap items and values
				if(is.ie){
					event.cancelBubble = true;
				}else{
					event.stopPropagation();
				}
			  //event.returnValue = false;
			  //	  alert('both found');
			  ai = aa;
			  if(t==aa)ai = bb;
			  //		alert('this was aa');
			  //	  if(t==bb)alert('this was bb');
			  ai.value = t.value;
			  t.value = '';
			  if(t.onchange)t.onchange();
			  t.disabled = true;
			  xkvDisab(t);
			  ai.disabled = false;
			  ai.focus();
			  //tremendous bug? since ai is used in the caleld function it is altered!
			  if(ai.onchange)ai.onchange();
			  return false;
			}
	   }
   }
  return keyValid(t,c);
}

//************************** new for inclusion elsewhere
function include_dom(script_filename) {
    var html_doc = document.getElementsByTagName('head').item(0);
    var js = document.createElement('script');
    js.setAttribute('language', 'javascript');
    js.setAttribute('type', 'text/javascript');
    js.setAttribute('src', script_filename);
    html_doc.appendChild(js);
    return false;
}

//**************************** new menu functions
function smon(ob){
	if(SubMenuOn)smoff(SubMenuOn);
	ob.className='PopMenuOn';
	SubMenuOn = ob;
}

function smoff(ob){
	ob.className='PopMenuOff';
	if(SubMenuOn == ob)SubMenuOn = null;
}

function getElidRaw(elid){
	//The return value can be used to find sub menu items
	if(elid)return elid.substring(0,elid.length-1)+'_';
	return null;
}

//Allows us to scroll through popup menus using the cursor keys, and to select using space
function btnKey(e){
	if(!e)e=window.event;
	var ek = window.event ? e.keyCode : e.which;
	elid = null;
	//Eat the backspace key- THIS DOES NOT WORK YET
	if(ek==8){
		unloadBackSpace = true;
	}
	
	if(MenuOn){
		//alert(ek);
		if(SubMenuOn && ek==32){
			SubMenuOn.click();
			e.returnValue = false;
			return;
		}
		//We can do something
		//Is there a selected submenu?
		rnum = -1;
		elid = getElidRaw(MenuOn.id);
		ai=null;
		if(SubMenuOn){
			elid = SubMenuOn.id;
			n = elid.lastIndexOf('_');
			rnum = parseInt(elid.substring(n+1,elid.length));
			elid = elid.substring(0,n+1);
		}
		//alert(ek);
		if(ek==37 && SubMenuOn){
			//Only makes sense in the circumstance where we are on a SubMenu
			smoff(SubMenuOn);
			//MenuOn.focus();
			//elid = elid.substring(0,elid.length-1);
			//ai = MM_findObj(elid);

			//alert(elid);
		}
		if(ek==38){
			//alert(elid+' up');
			//alert(elid+rnum);
			rnum = rnum-1;
			//if rnum<0 we have no target
			if(rnum<0){
				if(MenuOn.maxoffset){
					rnum = MenuOn.maxoffset;
				}else{
					rnum = 0;
					while(MM_findObj(elid+rnum))rnum++;
					--rnum;
					MenuOn.maxoffset = rnum;
				}
			}
			ai = MM_findObj(elid+rnum);
		}
		if(ek==40 || ek==39){
			//Treat right arrow as a down
			//alert(elid+' up');
			//alert(elid+rnum);
			rnum = rnum+1;
			ai = MM_findObj(elid+rnum);
			if(ai==null){
				//register the maxoffset and goto 0
				MenuOn.maxoffset = rnum-1;
				ai = MM_findObj(elid+'0');
			}
		}
		if(ek>64 && ek<91){
			if(e.altKey && findBtn(ek)){
				e.returnValue = false;
				if(is.ie){
					e.cancelBubble = true;
				}else{
					e.stopPropagation();
				}
			}
			//We have a keypress within a menu
			//alert(elid+' up');
			//alert(elid+rnum);
			rnum = 0;
			sv1 = String.fromCharCode(ek);
			sv = '<U>'+sv1+'</U>';
			ai_cdt = null;
			cdt_click = true;
			first_ai_cdt = null;
			prev_was_last = false;
			using_prev = false;
			while(ai=MM_findObj(elid+rnum)){
				//We have an ob in ai
				if(ai.innerHTML.toUpperCase().indexOf(sv)>=0){
					e.returnValue = false;
					ai.click();
					return;
				}
				//Not got that one, have we got a first letter?
				//We may find many - we react by choosing the one AFTER the last_ai_cdt, or the FIRST one
				if(ai.innerHTML.toUpperCase().charAt(0)==sv1){
					//register the first
					if(first_ai_cdt==null)first_ai_cdt=ai;
					//If this is not the first then we must alt the click
					if(ai_cdt!=null)cdt_click = false;
					//if there isn't one use this one
					if(ai_cdt == null)ai_cdt = ai;
					//register the one after last
					if(prev_was_last)ai_cdt = ai;
					prev_was_last = (ai == last_ai_cdt);
				}
				rnum++;
			}
			//If there wasn't a last one use the first one
			//if(last_ai_cdt==null){
			//	ai_cdt=first_ai_cdt;
			//}
			if(ai_cdt){
				if(cdt_click){
					e.returnValue = false;
					ai_cdt.click();
				}
				ai = ai_cdt;
				last_ai_cdt = ai_cdt;
				//return;
			}
		}
		if(ai){
			//ai.mouseover();
			smon(ai);
			//SubMenuOn = ai;
			e.returnValue = false;
		}
	}else{
		if(e.altKey && ek!=18 && ek>64){
			//alert('Alt-'+ek);
			if(findBtn(ek)){
				e.returnValue = false;
				if(is.ie){
					e.cancelBubble = true;
				}else{
					e.stopPropagation();
				}
			}
		}

	}
}


function findBtn(ek){
	//ek is the raw keycode
	if(ek>64){
		ek = ek-64;
		if(accKey[ek]){
			ai = MM_findObj(accKey[ek]);
			if(ai){
				ai.focus();
				return true;
			}
		}
	}
}

function defaultFocus(){
	//Attempt to find an object within the screen to set focus to...
	//Policy: try defFocOb
	if(gotDefFocus)return;
	ai = null;
	if(window.defFocOb && (ai = MM_findObj(defFocOb))){
		ai.focus();
		gotDefFocus = true;
		return;
	}
	if(ai==null){
		ai = MM_findObj('INTERNAL');
		if(ai==null)ai = MM_findObj('ROINTERNAL');
		//DELIBERATELY DO NOT SEARCH FOR MODAL
		//if(ai==null)ai = MM_findObj('MODAL').elements[0].focus();
	}
	if(ai!=null && ai.elements.length>0){
		try{
			ai.elements[0].focus();
		}catch(e){}
		gotDefFocus = true;
	}
}

function opSel(ob){
	if(gl_sel)opUnSel(gl_sel);
	if(document.activeElement &&(document.activeElement.type=="submit")&& (ob != document.activeElement)){
		document.activeElement.className="buttonOff";
	}
	ob.className="buttonOn";
	gl_sel=ob;
}

function opUnSel(ob){
	//refuse to unsel? NO asa it will limit future stuff
	if(document.activeElement &&(document.activeElement.type=="submit")&& (ob != document.activeElement)){
		document.activeElement.className="buttonOn";
		gl_sel=document.activeElement;
	}
	ob.className="buttonOff";
	gl_sel=null;
}


function bfoc(s){
var a = MM_findObj(s);
//We have to trap the possibility that the form has been closed...
if(a && a.disabled==false)a.focus();
}

function bfoc(s){
var a = MM_findObj(s);
//We have to trap the possibility that the form has been closed...
if(a && a.disabled==false)a.focus();
}

function tcn(ob,cn){
	if (flgSubmitted != true)ob.className = cn;
}

function tbi(ob,cn){
	if (flgSubmitted != true)ob.style.backgroundImage='url('+cn+')';
}

function kvNum(e){
	if(!e)e=window.event;
	return keyValid(null,'N',e);
}

function kvDate(e){
	if(!e){
		e=window.event;
	}
	return keyValid(null,'D',e);
}

function kvNul(e){
	return true;
}

/************** LOCALIZABLE GLOBAL VARIABLES ****************/

var gArgCountErr =	'The "%%" function requires an even number of arguments.'
				+	'\nArguments should be in the form "atttributeName", "attributeValue", ...';

/******************** END LOCALIZABLE **********************/

var gTagAttrs				= null;
var gQTGeneratorVersion		= 1.0;

function AC_QuickTimeVersion()	{ return gQTGeneratorVersion; }

function _QTComplain(callingFcnName, errMsg)
{
    errMsg = errMsg.replace("%%", callingFcnName);
	alert(errMsg);
}

function _QTAddAttribute(prefix, slotName, tagName)
{
	var		value;

	value = gTagAttrs[prefix + slotName];
	if ( null == value )
		value = gTagAttrs[slotName];

	if ( null != value )
	{
		if ( 0 == slotName.indexOf(prefix) && (null == tagName) )
			tagName = slotName.substring(prefix.length); 
		if ( null == tagName ) 
			tagName = slotName;
		return tagName + '="' + value + '" ';
	}
	else
		return "";
}

function _QTAddObjectAttr(slotName, tagName)
{
	// don't bother if it is only for the embed tag
	if ( 0 == slotName.indexOf("emb#") )
		return "";

	if ( 0 == slotName.indexOf("obj#") && (null == tagName) )
		tagName = slotName.substring(4); 

	return _QTAddAttribute("obj#", slotName, tagName);
}

function _QTAddEmbedAttr(slotName, tagName)
{
	// don't bother if it is only for the object tag
	if ( 0 == slotName.indexOf("obj#") )
		return "";

	if ( 0 == slotName.indexOf("emb#") && (null == tagName) )
		tagName = slotName.substring(4); 

	return _QTAddAttribute("emb#", slotName, tagName);
}


function _QTAddObjectParam(slotName, generateXHTML)
{
	var		paramValue;
	var		paramStr = "";
	var		endTagChar = (generateXHTML) ? ' />' : '>';

	if ( -1 == slotName.indexOf("emb#") )
	{
		// look for the OBJECT-only param first. if there is none, look for a generic one
		paramValue = gTagAttrs["obj#" + slotName];
		if ( null == paramValue )
			paramValue = gTagAttrs[slotName];

		if ( 0 == slotName.indexOf("obj#") )
			slotName = slotName.substring(4); 
	
		if ( null != paramValue )
			paramStr = '  <param name="' + slotName + '" value="' + paramValue + '"' + endTagChar + '\n';
	}

	return paramStr;
}

function _QTDeleteTagAttrs()
{
	for ( var ndx = 0; ndx < arguments.length; ndx++ )
	{
		var attrName = arguments[ndx];
		delete gTagAttrs[attrName];
		delete gTagAttrs["emb#" + attrName];
		delete gTagAttrs["obj#" + attrName];
	}
}

		

// generate an embed and object tag, return as a string
function _QTGenerate(callingFcnName, generateXHTML, args)
{
	// is the number of optional arguments even?
	if ( args.length < 4 || (0 != (args.length % 2)) )
	{
		_QTComplain(callingFcnName, gArgCountErr);
		return "";
	}
	
	// allocate an array, fill in the required attributes with fixed place params and defaults
	gTagAttrs = new Array();
	gTagAttrs["src"] = args[0];
	gTagAttrs["width"] = args[1];
	gTagAttrs["height"] = args[2];
	gTagAttrs["classid"] = "clsid:02BF25D5-8C17-4B23-BC80-D3488ABDDC6B";
		//Impportant note: It is recommended that you use this exact classid in order to ensure a seamless experience for all viewers
	gTagAttrs["pluginspage"] = "http://www.apple.com/quicktime/download/";

	// set up codebase attribute with specified or default version before parsing args so
	//  anything passed in will override
	var activexVers = args[3]
	if ( (null == activexVers) || ("" == activexVers) )
		activexVers = "6,0,2,0";
	gTagAttrs["codebase"] = "http://www.apple.com/qtactivex/qtplugin.cab#version=" + activexVers;

	var	attrName,
		attrValue;

	// add all of the optional attributes to the array
	for ( var ndx = 4; ndx < args.length; ndx += 2)
	{
		attrName = args[ndx].toLowerCase();
		attrValue = args[ndx + 1];

		// "name" and "id" should have the same value, the former goes in the embed and the later goes in
		//  the object. use one array slot 
		if ( "name" == attrName || "id" == attrName )
			gTagAttrs["name"] = attrValue;

		else 
			gTagAttrs[attrName] = attrValue;
	}

	// init both tags with the required and "special" attributes
	var objTag =  '<object '
					+ _QTAddObjectAttr("classid")
					+ _QTAddObjectAttr("width")
					+ _QTAddObjectAttr("height")
					+ _QTAddObjectAttr("codebase")
					+ _QTAddObjectAttr("name", "id")
					+ _QTAddObjectAttr("tabindex")
					+ _QTAddObjectAttr("hspace")
					+ _QTAddObjectAttr("vspace")
					+ _QTAddObjectAttr("border")
					+ _QTAddObjectAttr("align")
					+ _QTAddObjectAttr("class")
					+ _QTAddObjectAttr("title")
					+ _QTAddObjectAttr("accesskey")
					+ _QTAddObjectAttr("noexternaldata")
					+ '>\n'
					+ _QTAddObjectParam("src", generateXHTML);
	var embedTag = '  <embed '
					+ _QTAddEmbedAttr("src")
					+ _QTAddEmbedAttr("width")
					+ _QTAddEmbedAttr("height")
					+ _QTAddEmbedAttr("pluginspage")
					+ _QTAddEmbedAttr("name")
					+ _QTAddEmbedAttr("align")
					+ _QTAddEmbedAttr("tabindex");

	// delete the attributes/params we have already added
	_QTDeleteTagAttrs("src","width","height","pluginspage","classid","codebase","name","tabindex",
					"hspace","vspace","border","align","noexternaldata","class","title","accesskey");

	// and finally, add all of the remaining attributes to the embed and object
	for ( var attrName in gTagAttrs )
	{
		attrValue = gTagAttrs[attrName];
		if ( null != attrValue )
		{
			embedTag += _QTAddEmbedAttr(attrName);
			objTag += _QTAddObjectParam(attrName, generateXHTML);
		}
	} 

	// end both tags, we're done
	return objTag + embedTag + '> </em' + 'bed>\n</ob' + 'ject' + '>';
}

// return the object/embed as a string
function QT_GenerateOBJECTText()
{
	return _QTGenerate("QT_GenerateOBJECTText", false, arguments);
}

function QT_GenerateOBJECTText_XHTML()
{
	return _QTGenerate("QT_GenerateOBJECTText_XHTML", true, arguments);
}

function QT_WriteOBJECT()
{
	document.writeln(_QTGenerate("QT_WriteOBJECT", false, arguments));
}

function QT_WriteOBJECT_XHTML()
{
	document.writeln(_QTGenerate("QT_WriteOBJECT_XHTML", true, arguments));
}
/*************************** BSL SCRIPT STANDARDISATION EFFORT ***************/
/**      ------- THIS COMMENT APPLIES TO FILE stdscr.js IN COMMON -------   **/
/**            SCRIPTS THAT FOLLOW ARE GUARANTEED LATEST AND STDARDISED     **/
/**                                                                         **/
/**                  These can be included in any file at the bottom        **/
/**                                                                         **/
/**        The functions of same name elsewhere need to be removed first    **/
/**                                                                         **/
/*************************** BSL SCRIPT STANDARDISATION EFFORT ***************/
var MenuOnBy2 = null;
var MenuOn2 = null;
var SubMenuOnT2 = null;//This LHS popup menu started ST2
var SubMenuOn2 = null;//This is a RHS menu
var MTimerT2 = null;

var global_jsf = false;
var global_gcob = false;

//******************************* new 

function mnOvr2(src,mn,A) {
	//if(MClearID2){MClearTimer2Reset()};
    HideOld2(); 
	MenuOnBy2=src;
	var x = findPosX(src);
	var y = findPosY(src);
	var ph = getEltHeight(MenuOn);//Parent menu item
	var py = findPosY(MenuOn);//Parent menu item top
	var nmh = 0;
	var deltax = getEltWidth(src);
	//We want to - for now - ensure that the bottom of the new menu is no lower than the bottom of the parent

	var a = null;
	if(mn && mn.length>0)a = MM_findObj(mn);
	var ai = null;
	if (a) {
		UseVis = true;
		MenuOn2 = a;
		nmh = getEltHeight(MenuOn2);
		y = y-nmh/2;
		if(y<py)y=py;
		if(y>py+ph-nmh){
			y=py+ph-nmh;
		}
		setEltLeft (MenuOn2, x+deltax);
		setEltTop (MenuOn2, y);
		a.visibility = "show";
	}else{
	    ai = MM_findObj(mn+"I");
		if (ai) {
			MenuOn2 = ai;
			nmh = getEltHeight(MenuOn2);
			y = y-nmh/2;
			if(y<py)y=py;
			if(y>py+ph-nmh){
				y=py+ph-nmh;
			}
			setEltLeft (MenuOn2, x+deltax);
			setEltTop (MenuOn2, y);
			ai.className="visible";
		}
	}
}

function smonT(ob,sub,plac){	//Called when we go over a LHS menu in a LHS RHS combination
	//NEW method: Do nothing if MTimerT2 is running
	if(!MTimerT2){
		parob = MenuOnBy;
		smonTGo(ob,parob,sub,plac);
	}
}

function smonTGo(ob,parob,sub,plac){
	//Called to do the actual work of going to a sub menu
	if(SubMenuOn)smoff(SubMenuOn);
	ob.className='PopMenuOn';
	SubMenuOn = ob;
	mnOvr2(ob,sub,plac);
}

var smoffTLatch = false;
var smoffMenuHoldLatch = false;
function smoffT(){
	if(smoffTLatch){
		MTimerT2 = window.setTimeout('MTimerT2Do()',1000);
		smoffTLatch = false;
	}
}

function smClick(ob){
	MClearTimerReset();
	if(MTimerT2){
		window.clearTimeout(MTimerT2);
		MTimerT2 = null;
		ob.onmouseover();
	}
	smoffTLatch = true;
	smoffMenuHoldLatch = true;
}

function smon2(ob){//Called when we go over an RHS menu
	if(MTimerT2){
		window.clearTimeout(MTimerT2);
		MTimerT2 = null;
	}
	if(SubMenuOn2)smoff(SubMenuOn2);
	ob.className='PopMenuOn';
	SubMenuOn2 = ob;
}

function smoff2(ob){
	ob.className='PopMenuOff';
	if(SubMenuOn2 == ob)SubMenuOn2 = null;
}

function MTimerT2Do(){
	MTimerT2=null;
}

function mypf(s){
if(!s || s.length==0)return 0;
return parseFloat(s);
}

/************************** NEW SOLA ROUTINES ********************************/
/* These need to be set by the user of these routines 
 *	var mastID='PAYDET2.ACCREF_MST_DUM';
 *	var subID='PAYDET2.ACCREF';
 *	var subStub='INTERNAL_PAYDET2_ACCREF';
*/
function makePD(ob){
	if(document.getElementById('BMXI')==MenuOn && MenuOn){
		MClearTimerReset();
	}
	var mast = document.getElementById(mastID);
	if(!mastMenuBuilt){
		mastMenuBuilt = true;
		var p = '';
		var s = '<div onMouseOver="MClearTimerReset()" onMouseOut="if(!smoffMenuHoldLatch)MClearTimerSet()" id="BMXI" class="hidden" style="position:absolute">';
		s = s + '<table bgcolor="#c43737" width="100" border="0" cellspacing="1" cellpadding="0" class="PopMenuTab">';
		s = s + '<tr><td class="PopMenuDefault">Main accounts (Click to hold)</td></tr>';
		//Make the main DIV - but as we go we make the subsidiary divs also.
		//The subsidiary DIVS need an ID which we can get from the VALUE of each element in the main
		var x=mast;
		var i=0;
		var xlen = x.length;
		for (i=0;i<x.length;i++){
			//s=s+(x.options[i].value)+'<br>';
			s = s + '<tr><td nowrap class="PopMenuOff" onMouseOver="smonT(this,\'BMX'+x.options[i].value+'\',\'TG\')" ';
			s = s + ' onMouseOut="smoffT()" onclick="smClick(this)" id="submenu'+x.options[i].value+'" >'+x.options[i].text+'</td></tr>';
			p = p + makeSD(x.options[i].value, xlen);
		}
		s = s + '</table></div>';
		document.getElementById('playDIV2').innerHTML = s+p;
		document.getElementById('BMXI').onHide = onPDHide;
		//alert(s);
	}
	mnOvr(ob,'BMX','GA');
	if(document.getElementById('BMXI').className == "visible"){
		mast.className = "hidden";
		document.getElementById(subID).className = "hidden";
	}else{
		alert('failed '+document.getElementById('BMXI').className);
	}
}
function makeSD(sdId,pLen){
	//We are creating a sub div and sdid tells us how to get the required data
	var s='';
	var x=eval("window."+subStub+"_"+sdId);
	var xlen = x.length;
	if (pLen<5)
	{
		pLen=20;
	}
	if (pLen>33)
	{
		pLen = 33;
	}
	var cols = Math.floor(xlen/pLen);
	var percol = Math.floor(xlen/(1+cols))+1;

	s = '<div onMouseOver="MClearTimerReset()" onMouseOut="if(!smoffMenuHoldLatch)MClearTimerSet()" id="BMX'+sdId+'I" class="hidden" style="position:absolute">';
	s = s + '<table bgcolor="#c43737" width="100" border="0" cellspacing="1" cellpadding="0" class="PopMenuTab">';
	s = s + '<tr><td '+((cols>0) ? 'colspan="'+(cols+1)+'" ':'')+'class="PopMenuDefault">Sub accounts</td></tr>';
	var i=0;
	var n=0;
	var m=0;
	var crows = Math.min(xlen,pLen);
	for (n=0;n<crows;n++){
		s = s + '<tr>';
		for (m=0;m<=cols;m++){
			//Convert n to i
			i = n + m * crows;
			if(i<xlen){
				s = s + '<td nowrap class="PopMenuOff" onMouseOver="smon2(this)" ';
				s = s + 'onMouseOut="smoff2(this)" id="submenu'+sdId+'_'+i+'" onclick="SDOnSel('+sdId+','+i+')">'+x[i]+'</td>'
			}else{
				s = s + '<td nowrap class="PopMenuOff">&nbsp;</td>';
			}
		}
		s = s + '</tr>';
	}
	s = s + '</table></div>';
	return s;
}

function SDOnSel(mastInd,childInd){
var mast = document.getElementById(mastID);
mast.selectedIndex = mastInd-1;
mast.onchange();
document.getElementById(subID).selectedIndex = childInd;
HideOld();
}

function onPDHide(){
	document.getElementById(mastID).className = "XLSPink";
	document.getElementById(subID).className = "XLSPink";
}

/**************************** script clicks ***********************/
function scrClick(scrname,varname,varval){
	var objForm = eval("document.INTERNAL");
	objForm.BSLAction.value = 'EXTERNAL';
	var myLoc = objForm.action;
	//myLoc is the stub of the location
	window.location=scrClickLoc(myLoc,scrname,varname,varval);
}

function scrClickLoc(loc,scrname,varname,varval){
	var myLoc=loc+'&BSLAction=EXTERNAL&BSLButton=scr&XTSCRIPT=';
	//var myLoc=loc+'&BSLAction=INTERNAL&BSLButton=scr&XTSCRIPT=';
	//+scrname;
	//scrname is the script name followed by one or more parameter names
	var re = /;/;
	var myParams = scrname.split(re);
	for(n=0;n<myParams.length;++n){
		if(n==0){
			myLoc=myLoc+myParams[0];
		}else{
			var objForm = document.INTERNAL;
			if(!objForm){objForm = document.ROINTERNAL;}
			var varObj = eval("objForm."+myParams[n]);
			var locvarval="";
			if(varObj)locvarval = escape(varObj.value);
			myLoc=myLoc+'&GXTP_'+escape(myParams[n])+'='+locvarval;
		}
	}
	if(varname){
		//VARNAME is the name of the variable to return SO NO EVAL NECESSARY var varObj = eval("objForm."+varname);
		//if(varObj)varObj.value = varval;
		myLoc=myLoc+'&'+escape(varname)+'='+escape(varval);
	}
	return myLoc;
	//alert(myLoc);
	//We MUST prevent submit - not doing this kills Tomcat somehow...
	//Current solution is in BoxRes.java - but the implementation is flawed - it can be broken with badly constructed INPUTMC records
}


/**************************** AJAX ********************************/
function HttpClient() { }
HttpClient.prototype = {
	// type GET,POST passed to open
	requestType:'GET',
	// when set to true, async calls are made
	isAsync:false,
	// where an XMLHttpRequest instance is stored
	clientDiv:false,
	// where an XMLHttpRequest instance is stored
	xmlhttp:false,
	// what is called when a successful async call is made
	callback:false,

	// what is called when send is called on XMLHttpRequest
	// set your own function to onSend to have a custom loading
	// effect
	onSend:function() {
		document.getElementById('HttpClientStatus').style.display =
			      'block';
	},

	// what is called when readyState 4 is reached, this is
	// called before your callback
	onload:function() {
	  document.getElementById('HttpClientStatus').style.display =
			      'none';
	},

	// what is called when an http error happens
	onError:function(error) {
	 alert(error);
	},

	// method to initialize an xmlhttpclient
	init:function() {
	try {
	   // Mozilla / Safari
	    this.xmlhttp = new XMLHttpRequest();
	} catch (e) {
	   // IE
	   var XMLHTTP_IDS = new Array('MSXML2.XMLHTTP.5.0',
				     'MSXML2.XMLHTTP.4.0',
				     'MSXML2.XMLHTTP.3.0',
				     'MSXML2.XMLHTTP',
				     'Microsoft.XMLHTTP');
	   var success = false;
	   for (var i=0;i < XMLHTTP_IDS.length && !success; i++) {
	       try {
		   this.xmlhttp = new ActiveXObject(XMLHTTP_IDS[i]);
		   success = true;
	       } catch (e) {}
	   }
	   if (!success) {
	       this.onError('Unable to create XMLHttpRequest.');
	   }
	}
	},
	// method to make a page request
	// @param string url  The page to make the request to
	// @param string payload  What you're sending if this is a POST
	//                        request
	makeRequest: function(url,payload,contype) {
	 if (!this.xmlhttp) {
	     this.init();
	 }

	 this.xmlhttp.open(this.requestType,url,this.isAsync);

	 //RAVI: set headers for post
	 if(this.requestType=='POST'){
		 var ctype =  contype ? contype : 'application/x-www-form-urlencoded';
		 this.xmlhttp.setRequestHeader("Content-type", ctype);
		 var plen = payload ? payload.length : 0;
		 this.xmlhttp.setRequestHeader("Content-length", plen);
	 }

	 // set onreadystatechange here since it will be reset after a
	//completed call in Mozilla
	 var self = this;
	 this.xmlhttp.onreadystatechange = function() {self._readyStateChangeCallback(); }

	 this.xmlhttp.send(payload);

	 if (!this.isAsync) {
	     return this.xmlhttp.responseText;
	 }
	},

	// internal method used to handle ready state changes
	_readyStateChangeCallback:function() {
	 switch(this.xmlhttp.readyState) {
	      case 2:
	       //this.onSend();
	       break;
	    case 4:
	       //this.onload();
	       if (this.xmlhttp.status == 200) {
		   this.callback(this.xmlhttp.responseText,this.clientDiv);
	       } else {
		   this.onError('HTTP Error Making Request: '+
				       '['+this.xmlhttp.
				       status+']'+this.xmlhttp.statusText);
	       }
	       break;
	 }
	}
 }

function ajax1(thediv,thescript,varname,varval){
ajax1AUX(false,thediv,thescript,varname,varval);
}

function ajax1test(thediv,thescript,varname,varval){
ajax1AUX(true,thediv,thescript,varname,varval);
}

function ajax2(thediv,thescript,varname,varval){
ajax2AUX(false,thediv,thescript,varname,varval);
}

function ajax2test(thediv,thescript,varname,varval){
ajax2AUX(true,thediv,thescript,varname,varval);
}

function ajax3(thediv,thescript,varname,varval){
ajax3AUX(false,thediv,thescript,varname,varval);
}

function ajax3test(thediv,thescript,varname,varval){
ajax3AUX(true,thediv,thescript,varname,varval);
}

function ajax4(thediv){
ajax4AUX(false,thediv);
}

function ajax4test(thediv){
ajax4AUX(true,thediv);
}

function ajax5(thediv){
ajax5AUX(false,thediv);
}

function ajax5test(thediv){
ajax5AUX(true,thediv);
}

function ajax6(thediv,typecar){
ajax6AUX(false,thediv,typecar);
}

function ajax6test(thediv,typecar){
ajax6AUX(true,thediv,typecar);
}

function ajax1AUX(ifAlert,thediv,thescript,varname,varval){
	var mydiv = document.getElementById(thediv);
	if(mydiv){
		var req = new HttpClient();
		req.isAsync = true;
		req.clientDiv = mydiv;
		req.callback = function(result,ldiv) {
			try{
				ldiv.innerHTML = result;
			}catch(e){
				ldiv.innerHTML = 'Error: '+e.message;
			}
		}
		var thisLoc = ajaxReq(thescript,varname,varval);
		if(ifAlert){alert(thisLoc);}
		req.makeRequest(thisLoc,null);
	}else{
		window.status = 'The div '+thediv+' could not be found on '+thescript;
	}
}

function ajax2AUX(ifAlert,thediv,thescript,varname,varval){
	var mydiv = document.getElementById(thediv);
	if(mydiv){
		var req = new HttpClient();
		req.isAsync = true;
		req.clientDiv = mydiv;
		req.callback = function(result,ldiv) {
			try{
				ldiv.innerHTML = result;
			}catch(e){
				ldiv.innerHTML = 'Error: '+e.message;
			}
		}
		var thisLoc = ajaxRebuild(thescript,varname,varval);
		if(ifAlert){alert(thisLoc);}
		req.makeRequest(thisLoc,null);
	}else{
		window.status = 'The div '+thediv+' could not be found on '+thescript;
	}
}

function ajax3AUX(ifAlert,thediv,thescript,varname,varval){
	var mydiv = document.getElementById(thediv);
	if(mydiv){
		var req = new HttpClient();
		req.isAsync = true;
		req.clientDiv = mydiv;
		req.callback = function(result,ldiv) {
			try{
				ldiv.innerHTML = result;
			}catch(e){
				ldiv.innerHTML = 'Error: '+e.message;
			}
		}
		var thisLoc = ajaxFS(thescript,varname,varval);
		if(ifAlert){alert(thisLoc);}
		req.makeRequest(thisLoc,null);
	}else{
		window.status = 'The div '+thediv+' could not be found on '+thescript;
	}
}

function ajax4AUX(ifAlert,thediv){
	var mydiv = document.getElementById(thediv);
	if(mydiv){
		var req = new HttpClient();
		req.isAsync = true;
		req.clientDiv = mydiv;
		req.callback = function(result,ldiv) {
			try{
				ldiv.innerHTML = result;
			}catch(e){
				ldiv.innerHTML = 'Error: '+e.message;
			}
		}
		var thisLoc = ajaxStd('ajaxDS.jsp');
		if(ifAlert){alert(thisLoc);}
		req.makeRequest(thisLoc,null);
	}else{
		window.status = 'The div '+thediv+' could not be found.';
	}
}

function ajax5AUX(ifAlert,thediv){
	var mydiv = document.getElementById(thediv);
	if(mydiv){
		var req = new HttpClient();
		req.isAsync = true;
		req.clientDiv = mydiv;
		req.callback = function(result,ldiv) {
			try{
				ldiv.innerHTML = result;
			}catch(e){
				ldiv.innerHTML = 'Error: '+e.message;
			}
		}
		var thisLoc = ajaxStd('ajaxDIV.jsp');
		if(ifAlert){alert(thisLoc);}
		req.makeRequest(thisLoc,null);
	}else{
		window.status = 'The div '+thediv+' could not be found.';
	}
}

function ajax6AUX(ifAlert,thediv,typecar){
	var objForm = eval("document.INTERNAL");
	objForm.BSLButton.value = CID;//Set by other processes
	var mydiv = document.getElementById(thediv);
	if(mydiv){
		var req = new HttpClient();
		req.isAsync = true;
		req.requestType = 'POST';//For POST
		req.clientDiv = mydiv;
		req.callback = function(result,ldiv) {
			try{
				ldiv.innerHTML = result;
			}catch(e){
				ldiv.innerHTML = 'Error: '+e.message;
			}
		}
		var thisLoc = '';
		var plSep = '----------------'+Math.random()*1000000000000;
		//var payLoad = ajaxAllPost(plSep);
		var payLoad = ajaxAllPostURLEncode();
		if(typecar=='R'){
			thisLoc = 'ajaxDIV.jsp';
		}else{
			thisLoc = 'ajaxDS.jsp';
		}
		if(ifAlert){alert(payLoad);}
		//req.makeRequest(thisLoc,payLoad,'multipart/form-data; boundary='+plSep);
		req.makeRequest(thisLoc,payLoad);
	}else{
		window.status = 'The div '+thediv+' could not be found.';
	}
}

function getCookie(c_name)
{
if (document.cookie.length>0)
  {
  c_start=document.cookie.indexOf(c_name + "=")
  if (c_start!=-1)
    { 
    c_start=c_start + c_name.length+1 
    c_end=document.cookie.indexOf(";",c_start)
    if (c_end==-1) c_end=document.cookie.length
    return unescape(document.cookie.substring(c_start,c_end))
    } 
  }
return ""
}

/***  this returns the PAYLOAD not the URL ***/
function ajaxAllPost(plSep){
	//Build the ajax request string using ALL the elements
	//BSLSessionStr, BSLButton, BSLAction
	var objForm = eval("document.INTERNAL");
	//var myPayload = 'Cookie: '+document.cookie+'\nContent-Type: multipart/form-data; boundary='+plSep+'\n';
	//var myPayload = 'Content-Type: multipart/form-data; boundary='+plSep+'\n';
	var myPayload = plSep+'\n';
	for (var i=0;i<objForm.length;i++){
		if((objForm.elements[i].type!='checkbox' || objForm.elements[i].checked)&& (objForm.elements[i].name!='B')){
			myPayload = myPayload+'\n--'+plSep+'\nContent-Disposition: form-data; name="'+objForm.elements[i].name+'"\n';
			myPayload = myPayload+objForm.elements[i].value;
		}
	}
	myPayload = myPayload+'\n--'+plSep+'--\n';
	return myPayload;//scrClickLoc(myLoc,scrname,varname,varval);
}

function ajaxAll(jsp){
	//Build the ajax request string using ALL the elements
	//BSLSessionStr, BSLButton, BSLAction
	var objForm = eval("document.INTERNAL");
	var myLoc = jsp;
	var plcar = '?';
	for (var i=0;i<objForm.length;i++){
		if((objForm.elements[i].type!='checkbox' || objForm.elements[i].checked)&& (objForm.elements[i].name!='B')){
			myLoc = myLoc + plcar + escape(objForm.elements[i].name)+'='+escape(objForm.elements[i].value);
			plcar = '&';
		}
	}
	return myLoc;//scrClickLoc(myLoc,scrname,varname,varval);
}

function ajaxAllPostURLEncode(){
	//Build the ajax request string using ALL the elements
	//BSLSessionStr, BSLButton, BSLAction
	var objForm = eval("document.INTERNAL");
	var myLoc = '';
	var plcar = '';
	for (var i=0;i<objForm.length;i++){
		if((objForm.elements[i].type!='checkbox' || objForm.elements[i].checked)&& (objForm.elements[i].name!='B')){
			myLoc = myLoc + plcar + escape(objForm.elements[i].name)+'='+escape(objForm.elements[i].value);
			plcar = '&';
		}
	}
	return myLoc;//scrClickLoc(myLoc,scrname,varname,varval);
}

function ajaxStd(jsp){
	//Build the ajax request string using the standard settings
	//BSLSessionStr, BSLButton, BSLAction
	var objForm = eval("document.INTERNAL");
	var myLoc = jsp+'?BSLSessionStr='+objForm.BSLSessionStr.value;
	myLoc = myLoc+"&BSLAction="+objForm.BSLAction.value;
	myLoc = myLoc+"&BSLButton="+CID;
	myLoc = myLoc+"&BSLContext="+objForm.BSLContext.value;
	//myLoc is the stub of the location
	return myLoc;//scrClickLoc(myLoc,scrname,varname,varval);
}

function ajaxReq(scrname,varname,varval){
	var objForm = eval("document.INTERNAL");
	var myLoc = 'ajaxDS.jsp?BSLSessionStr='+objForm.BSLSessionStr.value;
	//myLoc is the stub of the location
	return scrClickLoc(myLoc,scrname,varname,varval);
}

function ajaxRebuild(scrname,varname,varval){
	var objForm = eval("document.INTERNAL");
	var myLoc = 'ajaxDIV.jsp?BSLSessionStr='+objForm.BSLSessionStr.value;
	//myLoc is the stub of the location
	return scrClickLoc(myLoc,scrname,varname,varval);
}

function ajaxFS(scrname,varname,varval){
	var objForm = eval("document.INTERNAL");
	var myLoc = 'ajaxFS.jsp?BSLSessionStr='+objForm.BSLSessionStr.value;
	//myLoc is the stub of the location
	return scrClickLoc(myLoc,scrname,varname,varval);
}

/************************** GENCLICK Support *****************************************/
	// First mode of registered browser submit
	function gen2Click(bval,jsf,gcob){
		global_waitdbl = false;
		if(window.dblClickLatch){
			window.clearTimeout(dblClickLatch);
			dblClickLatch = null;
		}
		CID=bval;
		if(CID=='TEST1'){
			alert('double');
			return;
		}
		var objForm = document.INTERNAL;
		if(jsf){
			//First do the on screen selection display modification
			if(gcob){
				srClick(bval,gcob);
			}
			//Interpret the nature of the AJAX requirement (
			var old_action = objForm.BSLAction.value;
			objForm.BSLAction.value = 'SELECT2';
			try{
				//New encoding:  look for R: (redrew) or S: (String replacement) - default is S
				if(jsf.length>2 && jsf.charAt(1)==':'){
					if(jsf.charAt(0)=='R'){
						ajax5(jsf.substr(2));
					}else{
						ajax4(jsf.substr(2));
					}
				}else{
					ajax4(jsf);
				}
			}finally{
				objForm.BSLAction.value = old_action;
			}

		}else{
			objForm.BSLAction.value = 'SELECT2';
			if (onceOnly(objForm)) objForm.submit();
		}
	}
	

	// Second mode of registered browser submit
	function genClickAux(){
		if(CID=='TEST1'){
			alert('single');
			return;
		}
		var objForm = document.INTERNAL;
		//if global_jsf is not null we eval it
		//if the result we want is ajax we need to construct the response string using the browser position and id
		//This is automatic if CID is used as set...
		if(global_jsf){
			if(global_gcob){
				srClick(CID,global_gcob);
			}
			var old_action = objForm.BSLAction.value;
			objForm.BSLAction.value = 'SELECT';
			try{
				//New encoding:  look for R: (redrew) or S: (String replacement) - default is S
				if(global_jsf.length>2 && global_jsf.charAt(1)==':'){
					if(global_jsf.charAt(0)=='R'){
						ajax5(global_jsf.substr(2));
					}else{
						ajax4(global_jsf.substr(2));
					}
				}else{
					ajax4(global_jsf);
				}
			}finally{
				objForm.BSLAction.value = old_action;
			}
		}else{
			objForm.BSLAction.value = 'SELECT';
			if (onceOnly(objForm)) objForm.submit();
		}
	}
	
	function genClick(bval,jsf,gcob){
		CID=bval;
		//if(window.dblClickLatch==null){
			global_waitdbl = true;
			global_jsf = jsf;
			global_gcob = gcob;
			dblClickLatch = window.setTimeout(genClickAux,333);
		//}
	}
	
	
//**************** older functions IN A NEW GUISE
	// Internal browser buttons - we cannot allow the usual name approach as this gets displayed
	//New: to invoke an AJAX next page we have a third element in the call - the DIV name of the browser control
	//The EXE needs to be able to handle this
	//The EXE will process it all in the stanrard way EXCEPT that if it knows the broser ID it will react
	//in the first place by extending teh mbrClick call to include this and secondly on response it will set SYS_AJAX_DIV
var global_jsf = false;
var global_gcob = false;

	function mbrClick(sval,bval,brdiv){
		CID=bval;
		var objForm = document.INTERNAL;
		if(brdiv){
			//Attempt AJAX
			var old_action = objForm.BSLAction.value;
			objForm.BSLAction.value = sval;
			try{
				ajax6(brdiv,'R');
				//ajax5(brdiv);
			}finally{
				objForm.BSLAction.value = old_action;
			}
		}else{
			objForm.BSLAction.value = sval;
			if (onceOnly(objForm)) objForm.submit();
		}
	}
	// Assume for now that an internal browser can only return if we are in an INTERNAL form.

function FormKeySubmit(frm,c,g,eat){
	//c is the current object passed to FormKey, and g is the global
	// returns true if the form was submitted 
	ai=null;
	if(frm){
		if(c)ai = MM_findObj(c);
		if(ai==null && g){
			c = g;
			ai = MM_findObj(c);
		}
		if(ai){
			CID = c;
			if(eat){
				if(ai.onclick && ai.type!="submit"){
					ai.onclick();
				}else{
					if(frm.onsubmit())frm.submit();
				}
			}

			return true;
		}
	}
	return false;
}


