// JavaScript Document
/* BSL Basic variables for Help */

var Months = ['zero','January','February','March','April','May','June','July','August','September','October','November','December'];

var gl_oshbx_disabled = false;
var gl_delayed_click_ob=false;
var gl_delayed_click_to=false;
var gl_delayed_dclick_ob=false;
var gl_delayed_dclick_to=false;

var glPictureViewerClicked=false;
var glOldVidDivHtml=false;
var gl_FormAltered = false;
var gl_displayHolder = new Object;
var BrowserSelRows = [null, null, null, null, null, null, null, null];
var waitLock = false;
// 2 new vars - brFocusOb and brFocusDo
var brFocusOb = false;
var brFocusDo = false;
/*var lastBlurOb = false;
var lastBlurFocusDo = false; NOT IMPLEMENTED YET */
var FormKeyOK = false;
var FormRetKill = false;
var FormAcheckKill = false;
var MenuOnBy = null;
var HelpOnBy = null;
var HelpOn = null;
var MenuOn = null;
var SubMenuOn = null;  //This LHS menu is the current one
var MClearID = null;
var glFormAcheckAccOnBlur=false;
var glFormAcheckProtectNar = false;

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 gl_link_init = 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 dblClickLatchOb = null;
var formLoaded = false;

//Testing globals
var global_app_path = "";//Default global app path for AJAX stuff - sites using rewrite need to set this...
var global_testdiv = false;
var global_last_ajax_return = 'None yet.';
var global_on_click = false;
var global_on_click_defeat = false;
var global_varctr = 1;
var global_on_click_flag = false;
var global_vlAlert = false;
var global_vlAlert_timer = null;
var global_vlAlert_opacity = 100;
var global_vlAlert_width = 180;
var def_global_vlAlert_width = 180;
var ajx_ob = false;	//This is to be set by the event initiated by the user
var ajx_procob = false;	//This is set by the callback handler to the ajx_ob it was created with
var ajx_position = 'ZA';
var scrollTimer = false;
var scrollStep = false;
var killDdTimer = false;

var glFadeInOpacity = 100;
var glFadeInDiv = null;
var glOnFadeIn = null;
var glFadeInStep;
var glFadeOutStep;
var glOnFadeInVar = null;
var glFadeOutOpacity = 100;
var glFadeOutDiv = null;
var glOnFadeOut = null;
var glOnFadeOutVar = null;

var theCRows = false;
var theCRowsCt = 0;
var theCurrRow = 0;
var theLastChoices = false;

var gl_thediv = false;
var gl_typecar = false;
var gl_parOb = false;
var gl_offsPos = false;
var gl_multipart = false;
var ajax6TO = false;
var bslDragMode = false;

var glHidden = new Array();
var glAjaxRequests = new Array();
var gl_vlAlertClassOverride = false;
var gl_vlAlertClass = 'vlAlert';
var gl_vlAlertStyle = '';
var gl_vlAlertStyleOverride = '';
var glMouseX=null;
var glMouseY=null;

var gl_calendar = false;
var gl_calendarTo = false;
var gl_oldso = false;

var gl_help_init = false;
var gl_help_show = false;
var gl_help_flag = false;

function helpInit(){
	gl_help_init = true;
	if(!gl_help_flag){
		var objForm = (document.forms['INTERNAL'] || document.forms['ROINTERNAL']);
		if(objForm){gl_help_flag = objForm.BSLHelpFlag.value;}else{gl_help_flag='T';}
	}
	gl_help_show=(gl_help_flag=='T');
}

function addEvent( obj, type, fn ) {/* Thanks to John Resig */
  if ( obj.attachEvent ) {
    obj['e'+type+fn] = fn;
    obj[type+fn] = function(){obj['e'+type+fn]( window.event );};
    obj.attachEvent('on'+type, obj [type+fn] );
  } else { obj.addEventListener( type, fn, false ); }
}

function killCal(){
	if(gl_calendar){
		gl_calendar.makeFree();
		gl_calendarTo=window.setTimeout('gl_calendar.doneFree();',100);
	}
}

function cloakemail(user,domain,extra,DisplayText){
    var asciiMAILTO = "&#109;&#97;&#105;&#108;&#116;&#111;&#58;"; //-- Ascii for 'mailto:'
    if (DisplayText == null || DisplayText== "" ){ DisplayText = user +'&#64;' + domain;}
    return '<a href="' + asciiMAILTO + user + '&#64;' + domain + extra + '">' + DisplayText + '</a>';
}

//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 subGen(){
var mainfrm=(document.forms['INTERNAL'] || document.forms['ROINTERNAL']);
if(mainfrm && mainfrm.onsubmit && mainfrm.onsubmit()){mainfrm.submit()};
}

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.forms['INTERNAL'] || document.forms['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 remain here...';
			}
		}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...';
		}
	}
}

function getStyle(x,styleProp)
{
	if (x.currentStyle)
		var y = x.currentStyle[styleProp];
	else if (window.getComputedStyle)
		var y = document.defaultView.getComputedStyle(x,null).getPropertyValue(styleProp);
	return y;
}

function getTarget(e){
//as an example from quirksmode
var targ;
if(e==null)var e=window.event;
if (e.target) targ = e.target;
else if (e.srcElement) targ = e.srcElement;
if (targ.nodeType == 3) targ = targ.parentNode;
return targ;
}

function setFormAltered(){gl_FormAltered = true;}

function myOnFocus(e,targ){
	if(targ==null)targ = getTarget(e);
	var oc = targ.getAttribute('origColor');
	if(oc)targ.style.color=oc;
	if(targ.value == targ.getAttribute('inPlace'))targ.value='';
}

function myOnBlur(e,targ){
	if(targ==null)targ = getTarget(e);
	targ.setAttribute('origColor',getStyle(targ,'color'));
	var ip = targ.getAttribute('inPlace');
	if(ip && targ.value == ''){
		targ.style.color=(targ.getAttribute('validKey')=='Y')?'pink':'grey';
		targ.value=ip;
	}
}
//Performance timer functions
function OnLoadX(){
	var objForm = (document.forms['INTERNAL'] || document.forms['ROINTERNAL']);
	if(objForm){
//		objForm.BSLLoadTime.value = new Date().getTime();
		var objEl = objForm.elements;
		for (var i=0;i<objEl.length;i++){
			addEvent(objEl[i] , 'change', setFormAltered);
			var ip = objEl[i].getAttribute('inPlace');
			if(ip){
				addEvent(objEl[i] , 'focus', myOnFocus);
				addEvent(objEl[i] , 'blur', myOnBlur);
				if(objEl[i].value == '')myOnBlur(null,objEl[i]);
			}
		}
	}
	if(window.OnLoad)OnLoad();//Call the per page on load function
	defaultFocus();//Maybe this needs to be after the given OnLoad()?
	formLoaded = true;
	try{
		objForm.BSLScreenWidth.value=window.screen.width;
		objForm.BSLScreenHeight.value=window.screen.height;
	}catch(err){var t=1;}
}

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 getMousePos(e){
/*writes glMouseX and glMouseY*/
if (e.pageX || e.pageY) 	{
		glMouseX = e.pageX;
		glMouseY = e.pageY;
	}
	else if (e.clientX || e.clientY) 	{
		glMouseX = e.clientX + document.body.scrollLeft
			+ document.documentElement.scrollLeft;
		glMouseY = e.clientY + document.body.scrollTop
			+ document.documentElement.scrollTop;
	}
}

function hideHelp(){
	if(HelpOn){
		HelpOn.style.visibility = "hidden";
	}
	HelpOn = null;
}

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;
	}
	hideHelp();
	HideOld2();
}

function HideOld2(){
	if(MenuOn2){
		if(UseVis){MenuOn2.visibility = "hide";}else{MenuOn2.className="hidden";}
		MenuOn2 = null;
		if(SubMenuOn2)smoff2(SubMenuOn2);
		last_ai_cdt = null;
	}
}

function ovrHelp(byob,ob){
	if(!gl_help_init)helpInit();
	if(gl_help_show){
		var ht = ob.getAttribute('helpId');
		if(ht){
			var htdiv=MM_findObj(ht);
			if(htdiv){
				HelpOn = htdiv;
				SetPosBelowC(byob,HelpOn,"--,",true);
				HelpOn.style.visibility='visible';
			}
		}
	}
}

function helpDivOver(ob){
MClearTimerReset();
}

function helpDivOut(ob){
MClearTimerSet();
}

//Version 2
function mnOvrKill(){
	if(MClearID){MClearTimerReset()};
	HideOld(); 
}

function mnOvr(src,mn,A) {
	if(!MTimerT2){
		if(MClearID){MClearTimerReset()};
		HideOld(); 
		MenuOnBy=src;
		ovrHelp(src,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";
			  divFadeInOb(ai,null,10);
			}else{
				//alert('Menu Ovr Ob not found: '+mn );
			}
		}
	}
}

function shPopClk(a){
	//A shared popup is clicked - we are passed the value to set to BSLSubAction - after which we must call the onclick for the MenuOnBy
	var objForm = (document.forms['INTERNAL'] || document.forms['ROINTERNAL']);
	objForm.BSLSubAction.value=a;
	MenuOnBy.onclick();
}

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.ie6  = (window.external && typeof window.XMLHttpRequest == "undefined");

    this.opera = (agt.indexOf("opera") != -1);
     
    this.nav4up = this.nav && (this.major >= 4);
    this.ie4up  = this.ie  && (this.major >= 4);
	this.is_css = (document.body  && document.body.style);
    this.is_w3c = (this.is_css && document.getElementById);
}

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 = ""
}

function isParentOf(ob,posPar){
	// return true if posPar is actually a parent of ob or return false
	while (ob = getEltParNode(ob))
	{
		if(ob==posPar)return true;
	}
	return false;
}

// MY get parent - might be buggy
function getEltParNode (elt) {
		return elt.parentNode;
}

/////////***********************************
// New position stuff
function setEltPos (elt, x, y, w, h) {
	//We set them all - but the caller is responsible for hiding and showing
	if (is.nav4){
		elt.left=x;elt.top=y;
		elt.document.width = w;
		elt.document.height = h;
	} else if (is.ie4up) {
		elt.style.pixelLeft=x;
		elt.style.pixelTop=y;
		elt.style.width = w;
		elt.style.height = h;
	} else if (is.gecko) {
		elt.style.left = (x + "px");
		elt.style.top= (y + "px");
		elt.style.width = w;
		elt.style.height = h;
	}
}

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,killabs) {
	var curleft = 0;
	if (obj.offsetParent) {
		while (obj.offsetParent) {
			if(killabs && obj.style.position=="absolute")return curleft;
			curleft += obj.offsetLeft;
			obj = obj.offsetParent;

		}
	} 
	else if (obj.x)
		curleft += obj.x;
	return curleft;
}

function findPosY(obj,killabs) {
	var curtop = 0;
	if (obj.offsetParent) {
		while (obj.offsetParent) {
			//alert(obj.offsetTop);
			if(killabs && obj.style.position=="absolute")return curtop;
			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 ( global_on_click)
	{
		if(global_on_click_defeat){
			return;
		}
		eval(global_on_click);
		return;
	}
	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 flgConfirmCancel = false; 
	var flgSubmitted = false;
	var CID = "a";
	
	function menuClick(mval, form) {
		CID=mval;
		CloseMenu();
		var objForm = document.forms[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;
		}
		var ocl = classStub(ob);
		if(ocl)ob.className =ocl+cname;
	}
	
	function smout(aEvent){
		mout_aux(aEvent, 'OffSel');
	}
	
	function mout(aEvent){
		mout_aux(aEvent, 'Off0');
	}
	
/*	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 classStub(ob){
		var ocl = ob.className;
		//ocl must end in On or OnSel
		var oclp = ocl.lastIndexOf("On");
		if(oclp>0){
			ocl = ocl.substr(0,oclp);
		}else{
			oclp = ocl.lastIndexOf("Off");
			if(oclp>0){
				ocl = ocl.substr(0,oclp);
			}else{
				ocl=null;
			}
		}
		return ocl;
	}

	function srClick(bval,ob){
		//Onscreen markup of new selected record
		var objForm ;
		var tvar = true;
		var BOff = 0;
		var ocl = classStub(ob);
		//var ob = window.event.srcElement;
		if(bval.substring(0,1)!='S'){BOff = bval.substring(0,1);}
		if(BrowserSelRows[BOff]!=null){
			if(ocl)BrowserSelRows[BOff].className = ocl+"Off0";
			BrowserSelRows[BOff].onmouseout = mout;
			tvar = false;
		}
		BrowserSelRows[BOff] = ob;
		if(ocl)ob.className = ocl+"OnSel";
		ob.onmouseout = smout;
		if(bval.substring(0,1)!='S'){
			objForm = document.getElementById("BSLBrowserPos"+bval.substring(0,1));
			if(!objForm)objForm = eval("document.forms['INTERNAL'].BSLBrowserPos"+bval.substring(0,1));
		}else{
			objForm = document.getElementById("BSLBrowserPos"+bval.substring(0,1));
			if(!objForm)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++) {
				var ip = objInput[i].getAttribute('inPlace');
				if(ip && objInput[i].value==ip)objInput[i].value='';
				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++) {
				var ip = objInput[i].getAttribute('inPlace');
				if(ip && objInput[i].value==ip)objInput[i].value='';
				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 pausecomp(millis) 
	{
	var date = new Date();
	var curDate = null;

	do { curDate = new Date(); } 
	while(curDate-date < millis);
	} 

	function onceOnly(frm){
		PermitUnload = true;
		frm.BSLButton.value = CID;
		if (flgSubmitted != true) {
			if (flgConfirmCancel && gl_FormAltered) {
				flgConfirmCancel=false;
				if(!confirm('Are you sure you want to close without saving?\n\nClick Ok to close, click Cancel to stay.'))return false;
			}
			//We are going to submit
			xkvEnab();
			//Mark submission time
			var objForm = document.forms['INTERNAL'];
			if(!objForm){objForm = document.forms['ROINTERNAL'];}
			if(!objForm){objForm = document.forms['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,dx,dy){
//Set position of object D relative to object U
SetPosBelowAcross(U,D,dx,dy);
}

function SetPosBelowAcross(U,D,A,B){
//Set position of object D relative to object U
var x = findPosX(U);
var y = findPosY(U);
var delta = getEltHeight(U);
if(!A)A=0;
if(!B)B=0;
setEltLeft(D,x+A);
setEltTop(D,y+delta+B);
}

function SetPosBelowC(U,D,A,killAbs){
//A is a string determining placement stuff.
//SPECIALS:
// A = #A = Top Left #C = Top Right #S ==> SCREEN CENTER, #T,L,B,R screen top, left bottom or right
var notKillAbs = killAbs?false:true;
if(!A) {A = '--';}else{A = A + '--';}
//A=A.substr(0,2);
var processed = false;
	var th;
	var tw;
	var px;
	var py;
	if(window.innerWidth){th=window.innerHeight;tw=window.innerWidth;px=window.pageXOffset;py=window.pageYOffset;}
	else{var dc = document.documentElement;tw=dc.clientWidth;th=dc.clientHeight;px=dc.scrollLeft;py=dc.scrollTop;}
	var sh = getEltHeight(D);
	var sw = getEltWidth(D);
if(A.indexOf("#A")==0){
	//Screen center
	sh = py+(th-sh)/2;
	sw = px+(tw-sw)/2;
	if(sh<0){sh=0;}
	if(sw<0){sw=0;}
	setEltLeft(D,sw);
	setEltTop(D,sh);
	processed = true;
}
if(A.indexOf("#S")==0){
	//Screen center
	sh = py+(th-sh)/2;
	sw = px+(tw-sw)/2;
	if(sh<0){sh=0;}
	if(sw<0){sw=0;}
	setEltLeft(D,sw);
	setEltTop(D,sh);
	processed = true;
}
if(A.indexOf("#T")==0){
	//Center Top
	sh = py+4;
	sw = px+(tw-sw)/2;
	if(sh<0){sh=0;}
	if(sw<0){sw=0;}
	setEltLeft(D,sw);
	setEltTop(D,sh);
	processed = true;
}
if(A.indexOf("#L")==0){
	//Center Left
	sh = py+(th-sh)/2;
	sw = px+4;
	if(sh<0){sh=0;}
	if(sw<0){sw=0;}
	setEltLeft(D,sw);
	setEltTop(D,sh);
	processed = true;
}
if(A.indexOf("#R")==0){
	//Center Right
	sh = py+(th-sh)/2;
	sw = px+tw-sw-4;
	if(sh<0){sh=0;}
	if(sw<0){sw=0;}
	setEltLeft(D,sw);
	setEltTop(D,sh);
	processed = true;
}
if(A.indexOf("#B")==0){
	//Center Bottom
	sh = py+th-sh-4;
	sw = px+(tw-sw)/2;
	if(sh<0){sh=0;}
	if(sw<0){sw=0;}
	setEltLeft(D,sw);
	setEltTop(D,sh);
	processed = true;
}
if(A.indexOf("#X")==0){
	//Above passed object align with left
	var x = findPosX(U,notKillAbs);
	var y = findPosY(U,notKillAbs);
	var deltay = getEltHeight(D);
	setEltLeft(D,x);
	setEltTop(D,y-deltay);
	processed = true;
}
if(!processed){
	if(U.tagName=='A'){
		//	deltay=0;
		// We want the size of any embedded ob ...
		var nc=U.childNodes;
		if(nc && nc[0].tagName=='IMG'){
			U = nc[0];
		}
	}
	var x = findPosX(U,notKillAbs);
	var y = findPosY(U,notKillAbs);
	var A1 = A.charAt(0);
	var A2 = A.charAt(1);
	var A3 = '.';
	if(A.length>2){A3=A.charAt(2);}
	var deltay = getEltHeight(U);
	var deltax = getEltWidth(U);
	if(A1=='T')deltay=0; //The only non default setting
	//U is also a default which ensures UNDER the ob... DO NOTHING about it.
	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('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(A3==','){
		setEltLeft(D,x+deltax+1);
		setEltTop(D,y+deltay-getEltHeight(D)-12);
	}else{
		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"){
	killCal();
	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){
		if(d[2]<30){
			d[2]=2000+d[2];	
		}else{
			d[2]=1900+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(FormRetKill)return false;
		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 liFormKey(e){
	//VERSION 1.0.0 Nov 2010
	var kp = window.event ? e.keyCode : e.which;
	if(kp==27){
	    var ob = document.getElementById(gl_esc);
		if(ob){CID=ob.id;subGen(ob);}
		return false;
	}
	var myKey = false;
	if(kp==38 && bslBRow>0){--bslBRow;myKey=true;}
	if(kp==40 && bslBRow<bslButtonRows){++bslBRow;myKey=true;}
	if(kp==37){
		if(bslBCol>0){
			--bslBCol;myKey=true;
		}else{
			if(bslBRow>0){bslBCol=bslButtonCols-1;--bslBRow;myKey=true;}
		}
	}
	if(kp==39){
		if(bslBCol<bslButtonCols-1){++bslBCol;myKey=true;}else{if(bslBRow<bslButtonRows){bslBCol=0;++bslBRow;myKey=true;}}
	}
	if(myKey){
		buttonFocusUpdate();
		e.returnValue = false;
		return false;
	}
	if((kp>64 && kp<91)||(kp>96 && kp<123)){
		lookUp(String.fromCharCode(kp));
		e.returnValue = false;
		return false;
	}

	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...<br>";
if(s=="D"){
	errstr = 'This is a date field!<br>Dates must be entered dd/mm/yyyy.<br><br>Separators can be /, . or -.<br>'
	poskey='1234567890/.-<br>';
}
if((s=="N")||(s=="C"))poskey='1234567890,.-<br>';
if(!e)e=window.event;
thekeystr = String.fromCharCode(window.event ? e.keyCode : e.which);
if((poskey!="*")&&(poskey.indexOf(thekeystr)==-1)&& thekeystr>=' '){
	vlAlertT(errstr+'Please use only the <br>following keys:<br><br>'+poskey,2000,ob);
	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 = document.forms[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 cancBub(e){
	if (!e) var e = window.event;
	e.cancelBubble = true;
	if (e.stopPropagation) e.stopPropagation();
}

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'){
		if(f.elements[i].value == f.elements[i].getAttribute('inPlace'))f.elements[i].value='';
		s = f.elements[i].name; 
		//s = s.replace(r,'_');
		if(window.bslv){
			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;
for(i=0;i<f.elements.length;++i){
	if(f.elements[i].type=='text'){
		var ip = f.elements[i].getAttribute('inPlace');
		if(ip && f.elements[i].value == '')myOnBlur(null,f.elements[i]);
	}
}
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();ValueOb.focus();">'+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(e,acc,c,dcn){
	//e is a dummy
	//dcn means dont change nar
	//Option to kill this function on a page by page or processed basis...
	if(FormAcheckKill)return true;

	//Option to PROTECT NAR GLOBALLY on a page by page basis...
	if(glFormAcheckProtectNar)dcn = true;

	//Are the control features here?
	var dnf=null;
	var rnum;
	try	{ lastBlurOb = acc.name;}catch (e){}
	var n = acc.name.lastIndexOf('.');
	if(window.accrefobfld && window.narobfld && (window.use_amount || (window.credobfld && window.debobfld))){
		//Establish rnum
		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 = ''+Math.round(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 = '';
		  }
		  //Allow for acc onblur processing programmed:
		  if(glFormAcheckAccOnBlur){
			try{
				FormAcheckAccOnBlurDo(acc,rnum,lacc);
			}catch(exc){}
		  }
		  //New for TITLE ob...
		  if(window.titleobfld && (ai = MM_findObj(titleobfld+rnum+'_flddiv'))){
			  var ihtm = ai.innerHTML;
			  if(((ihtm==null) || ihtm.length==0 || ihtm!=useCiTitle) && useCiTitle!='') ai.innerHTML = 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 - but first disable the default
					 ci.disabled = false;
					 di.disabled = true;
					 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 a percent input and balance pair?
		if(window.formLoaded && window.pcEntryFld && window.pcBalFld){
			//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(pcEntryFld+rnum);
			//Only proceed if acc matches ai
			if(acc==ai){
				var pbacc = mypf(ai.value);
				if(pbacc>100 || pbacc<0){
					alert('Pecentage fields cannot exceed 100, or be negative...');
					return false;
				}
				//ai = MM_findObj(pybalfld+rnum);
				MM_findObj(pcBalFld+rnum+'_flddiv').innerHTML = 100 - pbacc;
			}
		}
		//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);
			}
		}
	}else{
		//Generic on blus processing has a DIFFERENT ARG STRUCTURE == event, calling ob and for convenience rownum
	  if(glFormAcheckAccOnBlur){
		try{
			rnum = -1;
			try{rnum = parseInt(acc.name.substring(n+1,acc.name.length));}catch(err){}
			FormAcheckAccOnBlurDo(e,acc,rnum);
		}catch(exc){}
	  }
	}
	return strValid(acc,c);
}

function brFocus(){
	//If brFocusDo is true and brFocusOb identifies a browser row WITH and EDITABLE INPUT then we set the focus to the first input
	if(brFocusDo && brFocusOb){
		var ai = MM_findObj(brFocusOb);
		//var nod = ai;
		if(ai){
			try{
				ai = brFirstEd(ai);
				if(ai){
					ai.focus();
					return true;
				}
			}catch(e){}
		}
	}
	return false;
}

function brFirstEd(ob,k){
	//Passed the row object and we try to return the first editable field or the kth column
	//return false if none found
	if(k)return ob.cells[k].firstChild;
	var n=0;
	for(n=0;n<ob.cells.length;++n){
		thisTd = ob.cells[n].firstChild;
		if(thisTd.name){
			return thisTd;
		}
	}
	return null;
}

function brNav(e,isCheck){
	var ek = false;
	var se = false;
	se = window.event ? window.event.srcElement : e.target;
	ek = (window.event ? e.keyCode : e.which);
  if(se){
		//One consequence of using the row ID is that the object firing the event no longer has a relevant identifier
		var nodt = getEltParNode(se);
		var nodx = getEltParNode(nodt);
		var j = nodx.rowIndex;
		var k = nodt.cellIndex;
		var tb = getEltParNode(nodx);
		var ai = null;

		if(ek==38){
			try{
				ai = tb.rows[j-1];
			}catch(err){alert(err);}
		}
		if(ek==40){
			try{
				ai = tb.rows[j+1];
			}catch(err){alert(err);}
		}
		if(ai){
			var pai = ai;
			ai = brFirstEd(ai,k);
			if(ai){
				holdval = false;
				if(isCheck)holdval = ai.checked;
				ai.click();
				if(isCheck)ai.checked = holdval;
				try{
					ai.focus();
				}catch(err){
					if(k>0){k=k-1}else{k=k+1};
					ai=brFirstEd(pai,k);
					try{
						ai.focus();
					}catch(ferr){}
				}
				//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(e,t,c){
	var ek = window.event ? e.keyCode : e.which;
	if(window.credobfld && window.debobfld){
		thekeystr = String.fromCharCode(ek);
		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){
					e.cancelBubble = true;
				}else{
					e.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,e);
}

//************************** 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){
	hideHelp();
	ovrHelp(ob,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;

	if(bslDragMode){
		return doDragMode(e);
	}

	//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 brFocus defFocOb
	if(brFocus())return;
	if(gotDefFocus)return;
	var ai = null;
	if(window.defFocOb && (ai = MM_findObj(defFocOb))){
		ai.focus();
		gotDefFocus = true;
		return;
	}
	if(ai==null){
		ai = (document.forms['INTERNAL'] || document.forms['ROINTERNAL']);
		//DELIBERATELY DO NOT SEARCH FOR MODAL
	}
	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.pClassName = ob.className;
		ob.className = cn;
		//ob.style.zIndex=9;
		if(ob.tagName=='DIV'){
			if(cn.indexOf('Off')>0)ob.style.zIndex=0; else ob.style.zIndex=100;
			vlAlertAux(ob.innerHTML,null,ob,'EC',false,false,true);
			var mDiv = MM_findObj('VTDIVI');
			setEltWidth(mDiv,300);
		}
	}
}

function tcnp(ob){
	if (flgSubmitted != true){
		if(ob.pClassName){
			ob.className = ob.pClassName;
		}
		//ob.style.zIndex=9;
		if(ob.tagName=='DIV'){
			if(ob.className.indexOf('Off')>0)ob.style.zIndex=0; else ob.style.zIndex=100;
			vlAlertAux(ob.innerHTML,null,ob,'EC',false,false,true);
			var mDiv = MM_findObj('VTDIVI');
			setEltWidth(mDiv,300);
		}
	}
}

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){
	killCal();
	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_WriteOBJECTVal()
{
	return _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;
var global_scrname = false;
var global_varname = false;
var global_varval = 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.replace(',',''));
}

/************************** 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');
	//Seems to be wrong where we aer not using visible
	var f = document.getElementById(subID);
	if(!f){
		f = document.getElementsByName(subID)[0];
	}
	if(!f)alert('no found '+subID);
	if(UseVis){
		if(document.getElementById('BMXI').visibility == "show"){
			mast.visibility = "hide";
			f.visibility = "hide";
		}
	}else{
		if(document.getElementById('BMXI').className == "visible"){
			mast.className = "hidden";
			f.className = "hidden";
		}
	}
//	{ValueDivOb.visibility = "hide";}else{ValueDivOb.className="hidden";}

}
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<25)
	{
		pLen=25;
	}
	if (pLen>38)
	{
		pLen = 38;
	}
	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();
var f = document.getElementById(subID);
if(!f)f = document.getElementsByName(subID)[0];
f.selectedIndex = childInd;
HideOld();
}

function onPDHide(){
	document.getElementById(mastID).className = "XLSPink";
	var f = document.getElementById(subID);
	if(!f)f = document.getElementsByName(subID)[0];
	f.className = "XLSPink";
}

/**************************** script clicks ***********************/
function scrClick(scrname,varname,varval,gcob){
	if(gcob==null){
		scrClickAux(scrname,varname,varval,false,false);
		var objForm = (document.forms['INTERNAL'] || document.forms['ROINTERNAL']);
		objForm.BSLSubAction.value='';
	}else{
		if(window.dblClickLatchOb!=gcob && (window.dblClickLatchOb==null || !isParentOf(window.dblClickLatchOb,gcob))){
			global_waitdbl = true; 
			global_scrname = scrname;
			global_varname = varname;
			global_varval = varval;
	/*			global_gcob = gcob;*/
			dblClickLatchOb = gcob;
			dblClickLatch = window.setTimeout(scrClickDoAux,333);
		}
	}
}

function scrDblClick(scrname,varname,varval){
	global_waitdbl = false;
	if(window.dblClickLatch){
		window.clearTimeout(dblClickLatch);
		dblClickLatch = null;
		dblClickLatchOb = null;
	}
	scrClickDo(scrname,varname,varval);
}

/*function scrDblClick(scrname,varname,varval,gcob){
	scrClickAux(scrname,varname,varval,false,false);
	var objForm = document.forms['INTERNAL'];
	objForm.BSLSubAction.value='';
}*/

/* new for double click is the scrClickDo call, which is the old scrClick, and scrClickDoAux which is the timer version*/
function scrClickDoAux(){
	scrClickDo(global_scrname,global_varname,global_varval);
}

/* new for double click is the scrClickDo call, which is the old scrClick*/
function scrClickDo(scrname,varname,varval){
	scrClickAux(scrname,varname,varval,false,false);
	var objForm = (document.forms['INTERNAL'] || document.forms['ROINTERNAL']);
	objForm.BSLSubAction.value='';
}

function scrPlnClick(scrname,varname,varval){
	//DEBUG TOOL HIDDEN HERE - IF SHIFT AND CTRL ARE PRESSED WE DO AN ALERT SHOWING THE LAST AJAX RETURN
	//Only for IE
	if(window.event && window.event.ctrlKey && window.event.altKey){
		//vlAlertT(global_last_ajax_return,2000,MM_findObj("divIName_00001369"),'AA');
		vlAlertX(global_last_ajax_return);
		return false;
	}
	//FORCES return to http:// rather than https://
	scrClickAux(scrname,varname,varval,false,true);
	var objForm = (document.forms['INTERNAL'] || document.forms['ROINTERNAL']);
	objForm.BSLSubAction.value='';
}

function scrSecClick(scrname,varname,varval){
	scrClickAux(scrname,varname,varval,true,false);
	var objForm = (document.forms['INTERNAL'] || document.forms['ROINTERNAL']);
	objForm.BSLSubAction.value='';
	//return false;
}

function scrClickAux(scrname,varname,varval,secure,force){
	var objForm = (document.forms['INTERNAL'] || document.forms['ROINTERNAL']);
	objForm.BSLAction.value = 'EXTERNAL';
	var myLoc = false;
	//myLoc is the stub of the location

	//force is true if the protocol swap to plain http is definitely required
	//the default for EXECSCRIPT etc. is to STAY WITH THE PROTOCOL we are in

	/* New Jan 2008: We need to do some thinking - for AJAX to work here - and it would be useful - we need to decide
	   at some point that it is an ajax style call.
	   One reasonable approach which works elsewhere is to use the form of the BSLSubAction assignment
	   This currently dictates AJAX in other situations.
	   IFF BSLSubAction starts R: S: F: we have an AJAX situation.

	   FEB 2008:
	   ========
	   EXTSCRIPT BUTTONS currently cannot deal with AJAX - what happens is that the script name comes in
	   with $S:xxxDIV appended.
	   If this happens we can be sure that BSLSubAction is not set, and really we should 
	   be able to simply SET bslSubAction to everything after the script name and proceed as usual
	   We could WARN if BSLSubaction was already set...
	*/

	/* Secure scripts 
		These are EXECSEC - external scripts which demand that the user be redirected to the current
		website using https if not already there.
		This call IS NOT IMPLEMENTED in ajax cases although it could be...

	*/
	var notIfNoSubAc = false;
	if(scrname && scrname.length>0 && scrname.charAt(0)=='*'){
		//Cancel if no subaction...
		scrname = scrname.substr(1);
		notIfNoSubAc = true;
	}

	var sa = objForm.BSLSubAction.value;

	if(!sa || sa.length==0){
		//No sub action...  Have we got a script name which asks for AJAX ?
		//Yes if there is a $...
		var re = /\$/;  //NOTE special char $ requires escape
		var locSplit = scrname.split(re);
		if(locSplit.length>1){
			scrname = locSplit[0];
			sa = locSplit[1];
		}

	}


	if(sa && sa.length>2 && 'FSR'.indexOf(sa.charAt(0))>=0 && sa.charAt(1)==':'){
			var cDecode = ajxDecode(sa);
			objForm.BSLSubAction.value = cDecode[0];
			myLoc = '?BSLSessionStr='+objForm.BSLSessionStr.value;
			//myLoc = '?a=a';
			var buildId = Math.floor(Math.random()*1000000000000);
			myLoc = scrClickLoc(myLoc,scrname,varname,varval)+'&BSLBuildId='+buildId;
			ajax7(cDecode[1],cDecode[2],null,myLoc);
	}else{
		//Is there a sub action?
		if(!sa || sa.length==0){
			//There is NO BslSubAction defined...
			if(notIfNoSubAc){
				return;
			}
		}
		//if ordinary then we just use it
		if(secure){
			//myLoc is currently everything AFTER /esf/
			//We want the whole website
			myLoc = 'https://'+window.location.host+window.location.pathname+'?BSLSessionStr='+objForm.BSLSessionStr.value;
			//alert(myLoc);
		}else{
			if(force){//force http even if protocol is https
				myLoc = 'http://'+window.location.host+window.location.pathname+'?BSLSessionStr='+objForm.BSLSessionStr.value;
				//alert(myLoc);
			}else{
				myLoc = objForm.action;
			}
		}
		myLoc = scrClickLoc(myLoc,scrname,varname,varval);
		window.location= myLoc;
	}
}

function scrClickLoc(loc,scrname,varname,varval){
	var myLoc=loc+'&BSLAction=EXTERNAL&BSLButton=scr&BSLSubAction='+encodeURIComponent(document.forms['INTERNAL'].BSLSubAction.value)+'&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.forms['INTERNAL'] || document.forms['ROINTERNAL']);
			var varObj = eval("objForm."+myParams[n]);
			var locvarval="";
			if(varObj)locvarval = encodeURIComponent(varObj.value);
			myLoc=myLoc+'&GXTP_'+encodeURIComponent(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+'&'+encodeURIComponent(varname)+'='+encodeURIComponent(varval);
	}

	return myLoc+'&r='+Math.floor(Math.random()*10000);
	//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 ajaxWaiter() { }
ajaxWaiter.prototype = {
	//Store the div ID
	theOb:false,
	theDiv:false,
	//The count of requests sent - DIV disappears if this gets to 0
	callCount:0,
	theMsg:"done",
	incCC:function(){
		this.callCount = this.callCount + 1;
		if(this.callCount == 1){
			this.theDiv = waitDiv(this.theOb);
		}
	},
	decCC:function(){
		this.callCount = this.callCount - 1;
		if(this.callCount == 0){
			//redoDiv(this.theDiv,this.theMsg);
			window.setTimeout('dropDiv("'+this.theDiv+'")',100);
			//dropDiv('"'+this.theDiv+'"');
		}
	}
}

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,
	// hold url for error reporting
	theUrl:false,
	// hold payload for error reporting
	thePayload:false,
	// Ravi's ajaxWaiter object
	waiterOb:false,
	callerOb:false,
	callerPos:'ZA',
	typeCar:'',
	divName:false,

	// what is called when send is called on XMLHttpRequest
	// set your own function to onSend to have a custom loading
	// effect
	onSend:function() {
		//unused
	},

	// what is called when readyState 4 is reached, this is
	// called before your callback
	onload:function() {
		//unused
	},

	// what is called when an http error happens
	onError:function(error,ob) {
	 alert(error+'\n'+ob.theUrl+'\n'+ob.thePayload+':'+ob.Document);
	 if(this.waiterOb){
		 this.waiterOb.decCC();
	 }
	 window.location=ob.theUrl;
	},

	// method to initialize an xmlhttpclient
	init:function() {
    if(this.waiterOb)this.waiterOb.incCC();
	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;
			//if(this.waiterOb)this.waiterOb.incCC();
		} catch (e) {}
	   }
	   if (!success) {
	       this.onError('Unable to create XMLHttpRequest.',this);
	   }
	}
	},
	// 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) {
	glAjaxRequests.push(this);
//if(window.debugob)debugob.value = debugob.value + 'Added';
	 if (!this.xmlhttp) {
	     this.init();
	 }
	 this.theUrl = url;
	 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(); }

	 thePayload = payload;
	 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(gotAjaxRequest(this,true)){
			   if (this.xmlhttp.status == 200) {
				   global_last_ajax_return = this.xmlhttp.responseText;
				   if(this.waiterOb)this.waiterOb.decCC();
				   ajx_procob = this.callerOb;
				   ajx_position = this.callerPos;
				   this.callback(this.xmlhttp.responseText,this.clientDiv,this.divName,this.typeCar);
			   } else {
				   //Quieten the error
				   //this.onError('HTTP Error Making Request: '+
				//		   '['+this.xmlhttp.
				//		   status+']'+this.xmlhttp.statusText,this);
			   }
			}else{
//if(window.debugob)debugob.value = debugob.value + 'Aborted';
			}
	       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,typecar){
	//Attempt to do ajax6 style functionality if typecar is specified
ajax4AUX(false,thediv);
}

function ajax4test(thediv){
ajax4AUX(true,thediv);
}

function ajax5(thediv){
ajax5AUX(false,thediv);
}

function ajax5test(thediv){
ajax5AUX(true,thediv);
}

function ajax6Help(parOb,sval){
	CID='SYS_HELPW';
	var objForm = (document.forms['INTERNAL'] || document.forms['ROINTERNAL']);
	objForm.BSLSubAction.value=sval;
	ajax6Do('divSHOLD','S',parOb,'',true);
}

function ajax6f(thediv,typecar,parOb,offsPos){
	ajax6(thediv,typecar,parOb,offsPos,true);
}
function ajax6e(e,thediv,typecar,parOb,offsPos){
	//If e is defined then there are some classes of event which will be ignored
	var kill = false;
	if(e && e.type=="keyup"){
		var kc = (window.event ? e.keyCode : e.which);
		kill = (kc>8 && kc<46);
	}
	if(!kill)ajax6(thediv,typecar,parOb,offsPos);
}

function ajax6(thediv,typecar,parOb,offsPos,asMultipart){
	if(parOb && (parOb.tagName.toUpperCase()=='INPUT' || parOb.tagName.toUpperCase()=='TEXTAREA')){
		//Allow event to bubble...
		gl_thediv = thediv;
		gl_typecar = typecar;
		gl_parOb = parOb;
		gl_offsPos = offsPos;
		gl_multipart = asMultipart;
		//vlAlertClose();//requierd for immediate response...
		//killDdList(parOb);
		ajax6TO = window.setTimeout('ajax6Timer()',300);
	}else{
		ajax6Do(thediv,typecar,parOb,offsPos,!asMultipart);
	}
}

function ajax6Timer(){
	ajax6TO = null;
	ajax6Do(gl_thediv,gl_typecar,gl_parOb,gl_offsPos,!gl_multipart);
}

function ajax6Do(thediv,typecar,parOb,offsPos,urlEncoded,ajaxURL){
	//offsPos is used for positioning standard divs - defualt = 'ZA'
	//e is the event but might be null even...
	//e is used ONLY to complete the value of a string in an input box...
	//Multidiv functionality comes in here - thediv might be a list of divs
	//Main Issue is that we cannot dictate the order the calls get made in
	//Here we do not care - but the first call has got to process everything
	//The real problem is that what we call the second call can get made first depending on how busy the local processor is
	//The problem is solved by making all calls peers and allowing the server to decide which one is first
	//There is higher posting cost - marginally
	//The problem of multiple String posts is harder
	//With DIVS we simply ask for the div we want
	//For strings we need to ask for the string we want (on singles this is always the same)
	//BUT since we know the name of the DIV we are writing to we can use the div for assignments
	//i.e. for DIV=divIRAVI we assign string value to AJAX_STR_divIRAVI
	//PLUS for more flexible processing we change the exe to react flexibly to multiple specifications:
	//R:div1;div2;div3 means R is the type car for all of them
	//R:div1;S:div2;F:div3 means different type cars
	//HERE we expect either a single type char or exactly the same number as the divs
	if(ajaxURL==null)ajaxURL=false;
	killAjax(parOb);
	var evRet = true;
	var theDivs = thediv.split(";");
	var theType = typecar.split(";");
	var n=0;
	var buildId = Math.floor(Math.random()*1000000000000);
	var sTime = false;
	var myWaiter = false;
	if(offsPos){
		ajx_position = offsPos;
	}
	if(parOb){
		ajx_ob = parOb;
		myWaiter = new ajaxWaiter();
		myWaiter.theOb = parOb;
	}else{
		ajx_ob = MM_findObj(CID);
	}

	if(theType.length == theDivs.length){
		for(n=0;n<theDivs.length;++n){
			//alert(theDivs[n]+'='+theType[n]);
			ajax6AUX(false,theDivs[n],theType[n],sTime,buildId,myWaiter,ajaxURL,urlEncoded);
			sTime = true;
		}
	}else{
		for(n=0;n<theDivs.length;++n){
			ajax6AUX(false,theDivs[n],typecar,sTime,buildId,myWaiter,ajaxURL,urlEncoded);
			sTime = true;
		}
	}
	return evRet;
}

function ajax7(thediv,typecar,parOb,theLoc){
	//Specifically for BRENDER2 Ajax calls detected on the basis of the BSLSubAction string
	//What makes this different is that we have to add the build ID to each call - onto the end of the Loc
	//which after call could have already been done...

	//EXCEPT that the BSLAjaxDiv and/or BSLAjaxString needs to be set here or in ajax7Aux
	var theDivs = thediv.split(";");
	var theType = typecar.split(";");
	var n=0;
	var myWaiter = false;
	if(parOb){
		myWaiter = new ajaxWaiter();
		myWaiter.theOb = parOb;
	}

	if(theType.length == theDivs.length){
		for(n=0;n<theDivs.length;++n){
			//alert(theDivs[n]+'='+theType[n]);
			ajax7AUX(false,theLoc,theDivs[n],theType[n],myWaiter);
		}
	}else{
		for(n=0;n<theDivs.length;++n){
			ajax7AUX(false,theLoc,theDivs[n],typecar,myWaiter);
		}
	}
}

function ajax6test(thediv,typecar){
ajax6AUX(true,thediv,typecar);
}

function ajax1AUX(ifAlert,thediv,thescript,varname,varval){
	var mydiv = getAjaxDiv(thediv);
	if(mydiv){
		var req = new HttpClient();
		req.isAsync = true;
		req.clientDiv = mydiv;
		req.callback = function(result,ldiv,dName,typeCar) {
			handleAjaxDiv(ldiv,result,dName,typeCar);
		}
		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 = getAjaxDiv(thediv);
	if(mydiv){
		var req = new HttpClient();
		req.isAsync = true;
		req.clientDiv = mydiv;
		req.callback = function(result,ldiv,dName,typeCar) {
			handleAjaxDiv(ldiv,result,dName,typeCar);
		}
		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 = getAjaxDiv(thediv);
	if(mydiv){
		var req = new HttpClient();
		req.isAsync = true;
		req.clientDiv = mydiv;
		req.callback = function(result,ldiv,dName,typeCar) {
			handleAjaxDiv(ldiv,result,dName,typeCar);
		}
		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 = getAjaxDiv(thediv);
	if(mydiv){
		var req = new HttpClient();
		req.isAsync = true;
		req.clientDiv = mydiv;
		req.callback = function(result,ldiv,dName,typeCar) {
			handleAjaxDiv(ldiv,result,dName,typeCar);
		}
		var thisLoc = ajaxStd('ajaxDS.jsp');
		if(ifAlert){alert(thisLoc);}
		req.makeRequest(thisLoc,null);
	}else{
		window.status = 'The div '+thediv+' could not be found.';
	}
}

function ajaxRefresh(){
	//Called to invoke a full screen refresh using ajax but a minimal post - no data posted
	ajax5pAUX(false,'divDMainScreen');
}

function ajax5AUX(ifAlert,thediv){
	var mydiv = getAjaxDiv(thediv);
	if(mydiv){
		var req = new HttpClient();
		req.isAsync = true;
		req.clientDiv = mydiv;
		req.callback = function(result,ldiv,dName,typeCar) {
			handleAjaxDiv(ldiv,result,dName,typeCar);
		}
		var thisLoc = ajaxStd('ajaxDIV.jsp');
		if(ifAlert){alert(thisLoc);}
		req.makeRequest(thisLoc,null);
	}else{
		window.status = 'The div '+thediv+' could not be found.';
	}
}

function ajax5pAUX(ifAlert,thediv){ //used by ajax refresh
	var mydiv = getAjaxDiv(thediv);
	var objForm = (document.forms['INTERNAL'] || document.forms['ROINTERNAL']);
	if(mydiv){
		var req = new HttpClient();
		req.isAsync = true;
		req.clientDiv = mydiv;
		req.callback = function(result,ldiv,dName) {
			handleAjaxDiv(ldiv,result,dName);
		}
		objForm.BSLAjaxDiv.value = thediv;
		var thisLoc = ajaxStdBuildId('ajaxDIV.jsp');
		if(ifAlert){alert(thisLoc);}
		req.makeRequest(thisLoc,null);
	}else{
		window.status = 'The div '+thediv+' could not be found.';
	}
}
function checkReload(){
	//A function to see if the user back-stepped to a data post page which will need reloading 
	//We set up a data gram request varname = getSysVar varvalue = BSLSYS_CONTEXT
	var cb = function(result,ldiv,dName){
		var objForm = (document.forms['INTERNAL'] || document.forms['ROINTERNAL']);
		var myv = objForm.BSLContext.value;
		result = result.replace(/\n/g,'');
		result = result.replace(/\r/g,'');
		if(result!=myv){location.reload(location.href);}else{vlAlertCloseT();}
	};
	ajaxDG(cb,'getSysVar','BSLSYS_CONTEXT');
}

function ajaxDG(callBack,varName,varValue,cDiv,dName){
	//An AJAX handler which will NOT post anything except what is passed here
	//and the response is JUST SOME DATA handed back to the callback function passed here
	//BSLBuildId is made here...
	if (flgSubmitted)return;
	var req = new HttpClient();
	req.isAsync = true;
	//req.requestType = (isRepeat ? 'GET' : 'POST');
	req.requestType = 'GET';
	ajx_ob = false;
	req.clientDiv = cDiv;
	req.divName = dName;
	//This is what the req does on load: = this.callback(this.xmlhttp.responseText,this.clientDiv,this.divName);
	//We can use clientDiv and divName as communication strings == but only locally
	req.callback = callBack;
	//We need to construct thisLoc and the payLoad
	var payLoad = '';//ajaxAllPostURLEncode();
	var objForm = (document.forms['INTERNAL'] || document.forms['ROINTERNAL']);
	var myLoc = global_app_path+'ajaxDG.jsp?BSLSessionStr='+objForm.BSLSessionStr.value;
/*	myLoc = myLoc+"&BSLAction="+objForm.BSLAction.value;
	myLoc = myLoc+"&BSLButton="+CID;*/
	myLoc = myLoc+"&BSLContext="+objForm.BSLContext.value;
	myLoc = myLoc+"&BSLAjaxDiv="+encodeURIComponent(varName);
	myLoc = myLoc+"&BSLAjaxString="+encodeURIComponent(varValue);
	var buildId = Math.floor(Math.random()*1000000000000);
	objForm.BSLBuildId.value=buildId;
	myLoc = myLoc+"&BSLBuildId="+buildId;
	req.makeRequest(myLoc,payLoad);
/*	callback is defined like this: callback = function(result,ldiv,dName) {
		doSomething in javascript;
	}*/

}

function ajax6AUX(ifAlert,thediv,typecar,isRepeat,buildId,waiterOb,locOverride,urlEncoded){
	ajax6AUXp(ifAlert,thediv,typecar,isRepeat,buildId,waiterOb,locOverride,urlEncoded);
}

function ajax6AUXp(ifAlert,thediv,typecar,isRepeat,buildId,waiterOb,locOverride,urlEncoded){
	//if isRepeat is true we WERE DOING use GET and do not submit a payload
	//now isRepeat signals that were are in NEW STYLE PROCESSING which tells the server the div ID
	//locOverride is set if we MUST NOT CALCULATE loc - but is currently IGNORED
	//If submit already done then ignore...
	if (flgSubmitted)return;
	var objForm = (document.forms['INTERNAL'] || document.forms['ROINTERNAL']);
	objForm.BSLButton.value = CID;//Set by other processes
	objForm.BSLBuildId.value = (buildId==null ? '' :buildId);
	objForm.BSLAjaxDiv.value = thediv;
/*	if(isRepeat){
		objForm.BSLAjaxString.value = thediv;//Allows old style items to get hold of SYS_AJAX_STRING
	}else{
		objForm.BSLAjaxString.value = '';
	}*/
	//New always copies the div name...
	objForm.BSLAjaxString.value = thediv;

	//typecar is R for a full screen redraw
	//it is S of F for a string based redraw
	//if it is F then we need to process CID to get the correct div
	if(typecar=='F'){
		//Field div.  The passed div identifier is taken to be the field name
		//of a column in the current browser
		//of form <ALIAS>.<FIELDNAME>
		//we have to add .<rec>_flddiv
		//CURRENTLY NOTHING CALLS FOR THIS but if we want the browsers to then genclick will need modifying to use ajax6
		var bRec=1;
		if(CID.substring(0,1)!='S'){
			bRec = CID.substring(4);
		}
		thediv = (thediv+'.'+bRec+'_flddiv');
	}
	var mydiv = getAjaxDiv(thediv);
	if(mydiv){
		var req = new HttpClient();
		req.isAsync = true;
		//req.requestType = (isRepeat ? 'GET' : 'POST');
		req.requestType = 'POST';
		req.clientDiv = mydiv;
		req.waiterOb = waiterOb;
		req.callerOb = ajx_ob;
		req.callerPos = ajx_position;
		req.divName = thediv;
		ajx_ob = false;
		req.callback = function(result,ldiv,dName,typeCar) {
			handleAjaxDiv(ldiv,result,dName,typeCar,typeCar);
		}
		var thisLoc = '';
		req.typeCar = typecar;
		if(locOverride==false){
			if(typecar=='R'){
				thisLoc = global_app_path+'ajaxDIV.jsp';
			}else{
				thisLoc = global_app_path+'ajaxDS.jsp';
			}
		}else{
			thisLoc=locOverride;
		}
		var plSep = '----------------'+Math.floor(Math.random()*1000000000000);
		var payLoad = false;
		
		//Check for location search string
		var possStr = null;
		try{new RegExp("BSLSessionStr=[0-9]*","g").exec(window.location.search)[0].substr(14);
			if(possStr!=null)MM_findObj('BSLSessionStr').value=possStr;}catch(e){}

		if(urlEncoded){
			payLoad = ajaxAllPostURLEncode();
			req.makeRequest(thisLoc,payLoad);
		}else{
			payLoad = ajaxAllPost(plSep);
			req.makeRequest(thisLoc,payLoad,'multipart/form-data; boundary='+plSep);
		}
	}else{
		window.status = 'The div '+thediv+' could not be found.';
	}
}

function handleAjaxDiv(ldiv,result,dName,typeCar){
	try{
		if(result.length>7 && result.indexOf('jsexec:')>=0){
			var t = result.indexOf('jsexec:');
			var j = eval(result.substr(t+7));
			if(ldiv==true || j==null){
				//do nothing
			}else{
				ldiv.innerHTML = j;
			}
		}else{
			//P processing override done HERE
			if(typeCar=='P'){
				//result is of form string|string|string, but the third stig is discarded
				//FOR NOW first we hide the vlAlert
				vlAlertClose();
				var tmp = result.split('|');
				if(tmp.length<2){throw new String("Ajax P response did not have enough parts.");}
				typeCar=tmp[0].substring(tmp[0].length-1);
				dName=tmp[1];
				//dName must be a standard, or exist on the page
				ldiv = getAjaxDiv(dName);
				if(ldiv==null){throw new String("Ajax P response div not found: "+dName);}
				result = result.substring(2+tmp[0].length+tmp[1].length);
			}

			if(ldiv!=true){//For Standard divs ldiv == true, all others are actual div obljects == cannot get here with ldiv == false
				if(typeCar=='T'){//Currently T only works with given divs
					ldiv.innerHTML = ldiv.innerHTML + result;
				}else{
					if(typeCar=='U'){//Currently U only works with given divs
						ldiv.innerHTML = result + ldiv.innerHTML;
					}else{
						ldiv.innerHTML = result;
					}
				}
			}else{
				global_on_click_defeat = false;
				if(dName=='divSHOLD'){
			//Ravi / Louis : Jan 4th 2012 ; altered to vlAlert2 without regard to other consequences
					vlAlert2(result,ajx_procob,ajx_position);
					ajx_position = 'ZA';
				}else if(dName=='divSHOLDFIX'){
			//Ravi / Louis : Jan 4th 2012 ; altered to vlAlert2 without regard to other consequences
					vlAlert2(result,ajx_procob,ajx_position);
					global_on_click_defeat = true;
					gl_oshbx_disabled=true;
					ajx_position = 'ZA';
				}else if(dName=='divSHOLDP'){
					vlAlert(result,ajx_procob,ajx_position);
					global_on_click_defeat = true;
					ajx_position = 'ZA';
				}else if(dName=='divSCENTER'){
					vlAlert(result,ajx_procob,'#S');
					global_on_click_defeat = true;
				}else if(dName=='divSTOPLEFT'){
					vlAlert(result,ajx_procob,'#A');
/*				}else if(dName=='divSTOPRIGHT'){
					vlAlert(result,ajx_procob,ajx_position);
					ajx_position = '#A';
				}else if(dName=='divSBOTLEFT'){
					vlAlert(result,ajx_procob,ajx_position);
					ajx_position = '#A';
				}else if(dName=='divSBOTRIGHT'){
					vlAlert(result,ajx_procob,ajx_position);
					ajx_position = '#A';*/
				}else if(dName=='divSCHOOSE'){
					//Here we want to react to up and down by cycling through the choices
					vlAlert(result,ajx_procob,ajx_position,true,true);//Last param sets noFade true
					var mDiv = MM_findObj('VTDIVI');
					var thisChoices = document.getElementById('divICHOICES');
					if(thisChoices)mDiv.innerHTML = '<div id="divICHOICES">'+thisChoices.innerHTML+'</div>';
					ajx_position = 'ZA';
				}else if(dName=='divSSELF'){
					//Can only be used once VTDIV has been set up correctly...
					vlAlertReplace(result);
				}else if(dName=='divSREPLACE'){
					//New attempt to rEplace current contents...
					//Complete stab in the dark...
					//function vlAlert(s,p,a,supClose){
					vlAlertAux(result,null,null,null,false,false,null,true);
					/*var mDiv = MM_findObj('VTDIVI');
					mDiv.innerHTML = result;*/
				}else if(dName=='divSREPLACEFIX'){
					vlAlertAux(result,null,null,null,false,false,null,true);
					global_on_click_defeat = true;
					gl_oshbx_disabled=true;
				}else{
					alert('Unrecognised special div:'+dName);
				}
			}
		}
		onAjaxReload(ldiv);
	}catch(e){
		if(ldiv==true){
			alert('Error: '+e.message);
		}else{
			ldiv.innerHTML = 'Error: '+e.message;
		}
	}
}

function errmsg(e){
if(e instanceof String){return e;}else{return e.message;}
}

function ajax7AUX(ifAlert,thisLoc,thediv,typecar,waiterOb){
	//Specifically to handle BRENDER2 single parameter ajax calls
	//The URL has already been prepared
	//IT IS ALWAYS A GET
//NOTE this has to be dealt with by the caller:  here it is just to remind us...
	//typecar is R for a full screen redraw
	//it is S of F for a string based redraw
	//if it is F then we need to process CID to get the correct div
//	alert(thisLoc);//
//	return;
	if(typecar=='F'){
		var bRec=1;
		if(CID.substring(0,1)!='S'){
			bRec = CID.substring(4);
		}
		thediv = (thediv+'.'+bRec+'_flddiv');
	}
	var mydiv = getAjaxDiv(thediv);
	if(mydiv){
		var req = new HttpClient();
		req.isAsync = true;
		//req.requestType = (isRepeat ? 'GET' : 'POST');
		req.requestType = 'GET';
		req.clientDiv = mydiv;
		//req.waiterOb = waiterOb;
		req.callerOb = ajx_ob;
		req.callerPos = ajx_position;
		req.divName = thediv;
		ajx_ob = false;
		req.callback = function(result,ldiv,dName,typeCar) {
			handleAjaxDiv(ldiv,result,dName,typeCar);
		}
		if(typecar=='R'){
			thisLoc = global_app_path+'ajaxDIV.jsp'+thisLoc+'&BSLAjaxDiv='+encodeURIComponent(thediv);
		}else{
			thisLoc = global_app_path+'ajaxDS.jsp'+thisLoc+'&BSLAjaxString='+encodeURIComponent(thediv);
		}
//		alert(thisLoc);
		req.makeRequest(thisLoc,null);
	}else{
		window.status = 'The div '+thediv+' could not be found.';
	}
}

/*
MULTIPLE divs on the same screen using the same post call would be a useful feature

One method would be to encapsulate several responses into one - and that would be very useful.
XML could be used, for example, to report back - giving us scope for Javascript execution and so on.

For now, we transparently allow the named div to contain ; to separate out the various other divs we want to fill.

The entire process is:

1. Discover that there are many divs to fill...
2. Use Ajax6 with POST for the first one - this sends the data and we only want to do this once
3. we use Ajax6 with GET for the remaining ones

Limitations of the first implementation:

1. All divs in a set must have the same character? No - we could semicolon sep R:x;S:y;F:z BUT NOT THE FIRST TIME
   The reason for this is that the exe interprets an ajax $R:divName spec into the char and the div explicitly
   AT COMPILE TIME so sharing the characters is a good plan for now

*/

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 decodeURIComponent(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 = (document.forms['INTERNAL'] || document.forms['ROINTERNAL']);
	//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 = (document.forms['INTERNAL'] || document.forms['ROINTERNAL']);
	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 + encodeURIComponent(objForm.elements[i].name)+'='+encodeURIComponent(objForm.elements[i].value);
			plcar = '&';
		}
	}
	return myLoc;//scrClickLoc(myLoc,scrname,varname,varval);
}

function enSafe(s){
	if(!s)return s;
return s.replace(/\u20AC/g,"Euro ").replace(/\u201A/g,",").replace(/\u0192/g,"f").replace(/\u201E/g,",,").replace(/\u2026/g,"...").replace(/\u2020/g,"§").replace(/\u2021/g,"¶").replace(/\u2030/g,"%o").replace(/\u0160/g,"S").replace(/\u0152/g,"OE").replace(/\u2018/g,"'").replace(/\u2019/g,"'").replace(/\u201C/g,"'").replace(/\u201D/g,'"').replace(/\u2022/g,'"').replace(/\u2013/g,"-").replace(/\u2014/g,"-").replace(/\u2122/g,"(TM)").replace(/\u0161/g,"s").replace(/\u0153/g,"oe").replace(/\u0178/g,"Y").replace(/\u02C6/g,"^").replace(/\u2039/g,"[").replace(/\u017D/g,"Z").replace(/\u203A/g,"]").replace(/\u017E/g,"z").replace(/\u02dc/g,"~");
}

function ajaxAllPostURLEncode(){
	//Build the ajax request string using ALL the elements
	//BSLSessionStr, BSLButton, BSLAction
	var objForm = (document.forms['INTERNAL'] || document.forms['ROINTERNAL']);
	var myLoc = '';
	var plcar = '';
	for (var i=0;i<objForm.length;i++){
		if((!(objForm.elements[i].type=='checkbox' || objForm.elements[i].type=='radio') || objForm.elements[i].checked)&& (objForm.elements[i].name!='B')){
			//myLoc = myLoc + plcar + encodeURIComponent(objForm.elements[i].name)+'='+encodeURIComponent(objForm.elements[i].value);
			//above code is correct but does not honour charset
			//a hack appears below:
			myLoc =  myLoc + plcar + escape(objForm.elements[i].name).replace(/\+/g,"%2B").replace(/\//g,"%2F")+'='+escape(enSafe(objForm.elements[i].value)).replace(/\+/g,"%2B").replace(/\//g,"%2F");
			plcar = '&';
		}
	}
	return myLoc+plcar+'randomiser='+Math.random();//scrClickLoc(myLoc,scrname,varname,varval);
}

function ajaxStd(jsp){
	//Build the ajax request string using the standard settings
	//BSLSessionStr, BSLButton, BSLAction, BSLContext and BSLSubAction
	var objForm = (document.forms['INTERNAL'] || document.forms['ROINTERNAL']);
	var myLoc = global_app_path+jsp+'?BSLSessionStr='+objForm.BSLSessionStr.value;
	myLoc = myLoc+"&BSLAction="+objForm.BSLAction.value;
	myLoc = myLoc+"&BSLButton="+CID;
	myLoc = myLoc+"&BSLContext="+objForm.BSLContext.value;
	myLoc = myLoc+"&BSLSubAction="+encodeURIComponent(objForm.BSLSubAction.value);
	return myLoc;
}

function ajaxStdBuildId(jsp){
	//Build the ajax request string using the standard settings
	//BSLSessionStr, BSLButton, BSLAction, BSLContext and BSLSubAction
	var objForm = (document.forms['INTERNAL'] || document.forms['ROINTERNAL']);
	var myLoc = global_app_path+jsp+'?BSLSessionStr='+objForm.BSLSessionStr.value;
/*	myLoc = myLoc+"&BSLAction="+objForm.BSLAction.value;
	myLoc = myLoc+"&BSLButton="+CID;*/
	myLoc = myLoc+"&BSLContext="+objForm.BSLContext.value;
	myLoc = myLoc+"&BSLAjaxDiv="+encodeURIComponent(objForm.BSLAjaxDiv.value);
	myLoc = myLoc+"&BSLAjaxString="+encodeURIComponent(objForm.BSLAjaxString.value);
	myLoc = myLoc+"&BSLBuildId="+encodeURIComponent(objForm.BSLBuildId.value);
	return myLoc;
}

function ajaxReq(scrname,varname,varval){
	var objForm = (document.forms['INTERNAL'] || document.forms['ROINTERNAL']);
	var myLoc = global_app_path+'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 = (document.forms['INTERNAL'] || document.forms['ROINTERNAL']);
	var myLoc = global_app_path+'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 = (document.forms['INTERNAL'] || document.forms['ROINTERNAL']);
	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;
			dblClickLatchOb = null;
		}
		CID=bval;
		genClickAuxExec(jsf,gcob,'SELECT2');
	}
	

	// Second mode of registered browser submit
	function genClickAux(){
		dblClickLatch = null;
		dblClickLatchOb = null;
		genClickAuxExec(global_jsf,global_gcob,'SELECT');
	}

	//Common parts of both functions
	/*
	To allow BSLSubAction to partake in the process will allow us to have Brender2 items which call AJAX style stuff by
	setting the values appropriately.  The appproach will be to see if there is a BSLSubAction
	and if there is, whether it can be used to generate AJAX behaviour.

	g_jsf is of the appropriate form by itself in ordinary circumstances
	if we have BSLSubActiob defined then:
	   If it is of the form R:xxxx S:xxxx or F:xxxx we ALLOW it to override g_jsf
	*/
	function genClickAuxExec(g_jsf,g_gcob,selectType){
		var objForm = (document.forms['INTERNAL'] || document.forms['ROINTERNAL']);
		//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...
		//SubAction defines a COMPLETE ajax processing string - i.e. with R:divID1;S:divID2;divID3 form
		//BUT if it ENDS ::xxxx then this is taken to be the BslSubAction value OTHERWISE the first Div is used
		//If it exists it completely replaces g_jsf and g_gctype

		// ACTUALLY:
		// There are more possibilities than currently designed in...
		// BSLSubAction should be able to OVERRULE AJAX processing involved in the genClick parameter
		// BSLSubAction will - if not of AJAX form - henceforth kill the AJAX call in the surrounding object, if there was one
		// unless it starts ::

		//Very Newest thing: oct 2008 : if g_jsf starts with an asterisk it is trimmed and evaled immediately...
		//check it is a string and starts with a *
		try{
			if(g_jsf.charAt(0)=='*'){
				try{
					eval(g_jsf.substr(1));
					return;
				}catch(er1){
					alert(er1);
				}
			}
		}catch(er){}

		var sa = objForm.BSLSubAction.value;
		if(sa){
			if(sa.length>2 && sa.charAt(1)==':' && sa.charAt(0)==':'){
				objForm.BSLSubAction.value = sa.substr(2);
				sa=false;
			}else{
				if( sa.length>2 && 'FSR'.indexOf(sa.charAt(0))>=0 && sa.charAt(1)==':'){
					//Replacement for g_jst f and g_gctype established here...
					var cDecode = ajxDecode(sa);
					//g_jsf = sa;
					//objForm.BSLSubAction.value = sa.substr(2);
					objForm.BSLSubAction.value = cDecode[0];
					g_jsf = cDecode[1];
					g_gctype = cDecode[2];
				}else{
					g_jsf = null;
				}
			}
		}
		if(g_jsf){
			if(g_gcob){
				srClick(CID,g_gcob);
			}
			//Now we see if we need ajax...
			//g_jsf determines this
			//We do the standard decode and depending on the result we act.
			//testThis(g_jsf);
			var jDecode = null;
			if(sa){
				//do nothing
			}else{
				jDecode = ajxDecode(g_jsf);
				//we IGNORE SubAction spec here...
				//However all forms of the old stuff will comply with the new approach
				g_jsf = jDecode[1];
				g_gctype = jDecode[2];
			}


			var old_action = objForm.BSLAction.value;
			objForm.BSLAction.value = selectType;
			try{
				//Required for old un-recompiled screens - REMOVE FEB 2008
				//encoding:  look for R: (redrew) or S: (String replacement) - default is S
				if(g_jsf.length>2 && g_jsf.charAt(1)==':'){
					if(g_jsf.charAt(0)=='R'){
						//Redraw
						ajax5(g_jsf.substr(2));
					}else{
						//String or field div
						var bRec=1;
						if(CID.substring(0,1)!='S'){
							bRec = CID.substring(4);
						}
						if(g_jsf.charAt(0)=='F'){
							//Field div.  The passed div identifier is taken to be the field name
							//of a column in the current browser
							//of form <ALIAS>.<FIELDNAME>
							//we have to add .<rec>_flddiv
							ajax4(g_jsf.substr(2)+'.'+bRec+'_flddiv');
						}else{
							ajax4(g_jsf.substr(2));
						}
					}
				}else{
					//we detect MULTIPLE DIVS because the g_gctype is NOT NULL
					if(g_gctype!=null){
						//New AJAX6 style handling
						//alert(g_jsf+'='+g_gctype+'='+g_gcob);
						ajax6(g_jsf,g_gctype,g_gcob);
					}else{
						//Old standard handling...
						ajax4(g_jsf);
					}
				}
			}finally{
				objForm.BSLAction.value = old_action;
				objForm.BSLSubAction.value = '';
			}
		}else{
			objForm.BSLAction.value = selectType;
			if (onceOnly(objForm)) objForm.submit();
		}
	}
	
	function genClick(bval,jsf,gcob){
		//Managing too fast click calls
		//ALSO kill parental onclick
		//if(window.dblClickLatchOb!=null && isParentOf(window.dblClickLatchOb,gcob))alert('parent');
		try{
			if(jsf.charAt(0)=='*'){
				try{
					global_gcob = gcob;
					eval(jsf.substr(1));
					return;
				}catch(er1){
					alert(er1);
				}
			}
		}catch(er){}
		if(window.dblClickLatchOb!=gcob && (window.dblClickLatchOb==null || !isParentOf(window.dblClickLatchOb,gcob))){
			CID=bval;
			global_waitdbl = true; 
			global_jsf = jsf;
			global_gcob = gcob;
			dblClickLatchOb = gcob;
			dblClickLatch = window.setTimeout(genClickAux,333);
		}
	}

	function onAjaxReload(ldiv){
		//Always called
/*		if(lastBlurFocusDo && lastBlurOb){
			lastBlurFocusDo = false;
			try{
				var myLbo = lastBlurOb;
				lastBlurOb = false;
				MM_findObj(myLbo).focus();
				return true;
			}catch(e){}
		}*/
	}

	
	
//**************** 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,ob){
		CID=bval;
		var objForm = (document.forms['INTERNAL'] || document.forms['ROINTERNAL']);
		var theOb = ob;
		//bval = bval.id;
		if(brdiv){
			//Attempt AJAX
			var old_action = objForm.BSLAction.value;
			objForm.BSLAction.value = sval;
			try{
				ajax6Do(brdiv,'R',theOb,false,true);
				//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;
}

function ajaxAlert(alertMsg, retVal){
	alert(alertMsg);
	return retVal;
}

function testThis(a){
	var v = ajxDecode(a);
	alert(v[0]+'\n'+v[1]+'\n'+v[2]);
}

function testDiv(ob){
	//Write a new div to document
/*	var dn = 'divI'+Math.floor(Math.random()*1000000000000);
	var divText = '<div id="'+dn+'" class="hidden" style="position:absolute"><img src="Assets/Images/waiting24.gif"></div>';
	//Position the div near ob
	var theAnc = MM_findObj("genAnchor");
	theAnc.innerHTML = theAnc.innerHTML + divText;
	var theDiv = MM_findObj(dn);
	if(!theDiv)alert("Div not found...");
	SetPosBelow(ob,theDiv);
	theDiv.className="visible";
	//Set up a timer to change to OK text
	window.setTimeout('redoDiv("'+dn+'","Thanks....")',800);
	//This should be called AFTER we display the message - for testing it has to be now... 
	window.setTimeout('killDiv("'+dn+'")',1800);*/
	var myDiv = new ajaxWaiter();
	myDiv.theOb = ob;
	myDiv.incCC();
	global_testdiv = myDiv
	window.setTimeout('global_testdiv.decCC()',1800);
}

function killDiv(ob){
	//ob must be a div whose contents we can write...
	var theDiv = MM_findObj(ob);
	if(theDiv){
		theDiv.className="hidden";
	}
}

function dropDiv(ob){
	//ob must be a div whose contents we can write...
	var theDiv = MM_findObj(ob);
	if(theDiv){
		document.body.removeChild(theDiv);
	}
}

function redoDiv(ob,str){
	//ob must be a div whose contents we can write...
	var theDiv = MM_findObj(ob);
	if(!theDiv){
		alert("Div "+ob+" not found...");
	}else{
		theDiv.innerHTML='<span style="color:80a080;font-size:11px">'+str+'</font>';
	}
}

function waitDiv(ob){
	//Write a new div to document
	var dn = 'divI'+Math.floor(Math.random()*1000000000000);
	var myDiv = document.createElement('div');
	myDiv.id = dn;
	myDiv.style.position='absolute';
	myDiv.className="visible";
	//myDiv.innerHTML = '<div style="background-color:white;border:#bcd6f7 1px solid;color:#3284ec;font-size:10px;font-family:Verdana;"><img src="Assets/Images/ajax-loader.gif" style="padding:2px 4px 2px 4px">Loading...</div>';
	myDiv.innerHTML = '<div style="background-color:white;border:#bcd6f7 1px solid;color:#3284ec;font-size:10px;font-family:Verdanaopacity:0.4;filter:alpha(opacity=40);"><img src="'+global_app_path+'Assets/Images/ajax-loader.gif" style="padding:4px 4px 2px 8px"><span style="padding:5px 8px 0 5px;vertical-align:4px">Loading...</span></div>';
	document.body.appendChild(myDiv);
	myDiv.style.zIndex="101";
	SetPosBelow(ob,myDiv,140);
	return dn;
}

function ajxDecode(doThis){
	//Passed full ajax string R:xxx;yyy;S:www;F:ddd::SubActionValue
	//Returns rv[0]=SubActionValue or first div
	//rv[1]='xxx;yyy;www;ddd'
	//rv[2]='R;R;S;F'
	var rv = new Array();
	var rvFull = doThis.split('::');
	var rvAjx = rvFull[0].split(';');
	var rvAjx2 = rvFull[0].split(';');
	rv[0]=rvFull[0];
	rv[1]=null;
	var ajxC = ''+rvAjx[0].charAt(0);
	for(n=0;n<rvAjx.length;++n){
		if(rvAjx[n].length>1 && rvAjx[n].charAt(1)==':'){
			//Plain format
			rvAjx2[n]=''+rvAjx[n].charAt(0);
			ajxC=''+rvAjx[n].charAt(0);
			rvAjx[n]=rvAjx[n].substring(2);
		}else{
			rvAjx2[n]=ajxC;
		}
	}
	//Results
	if(rvFull[1]!=null){
		rv[0]=rvFull[1];
	}else{
		rv[0]=rvAjx[0];
	}
	//alert(rv[0]);
	rv[1]=rvAjx.join(';');
	rv[2]=rvAjx2.join(';');
	return rv;
}

function extScript(s){
	//Name of script is s
	var objForm = (document.forms['INTERNAL'] || document.forms['ROINTERNAL']);
	window.location = 'dsES1.jsp?BSLAction=EXTERNAL&BSLButton=scr&XTSCRIPT='+s+'&BSLSessionStr='+objForm.BSLSessionStr.value+'&r='+Math.floor(Math.random()*10000);
}

function extPlnScript(s){
	//DEBUG TOOL HIDDEN HERE - IF SHIFT AND CTRL ARE PRESSED WE DO AN ALERT SHOWING THE LAST AJAX RETURN
	//Only for IE
	if(window.event && window.event.ctrlKey && window.event.altKey){
		//vlAlertT(global_last_ajax_return,2000,MM_findObj("divIName_00001369"),'AA');
		vlAlertX(global_last_ajax_return);
		return false;
	}
	//Name of script is s
	var objForm = (document.forms['INTERNAL'] || document.forms['ROINTERNAL']);
	myLoc = 'dsES1.jsp?BSLAction=EXTERNAL&BSLButton=scr&XTSCRIPT='+s+'&BSLSessionStr='+objForm.BSLSessionStr.value+'&r='+Math.floor(Math.random()*10000);
	if(window.location.protocol=='http:'){
		window.location = myLoc;
	}else{
		window.location = 'http://'+window.location.host+window.location.pathname+'?BSLAction=EXTERNAL&BSLButton=scr&XTSCRIPT='+s+'&BSLSessionStr='+objForm.BSLSessionStr.value+'&r='+Math.floor(Math.random()*10000);
	}
	//WAS window.location = 'dsES1.jsp?BSLAction=EXTERNAL&BSLButton=scr&XTSCRIPT='+s+'&BSLSessionStr='+objForm.BSLSessionStr.value;
}

function extSecScript(s){
	//Name of script is s
	var objForm = (document.forms['INTERNAL'] || document.forms['ROINTERNAL']);
	myLoc = 'dsES1.jsp?BSLAction=EXTERNAL&BSLButton=scr&XTSCRIPT='+s+'&BSLSessionStr='+objForm.BSLSessionStr.value+'&r='+Math.floor(Math.random()*10000);
	if(window.location.protocol=='https:'){
		window.location = myLoc;
	}else{
		window.location = 'https://'+window.location.host+window.location.pathname+'?BSLAction=EXTERNAL&BSLButton=scr&XTSCRIPT='+s+'&BSLSessionStr='+objForm.BSLSessionStr.value+'&r='+Math.floor(Math.random()*10000);
	}
}

/*

vlAlert is a method of showing a div whose contents are passed to the call vlAlert

The div is shown and has the property that any clicks OUTSIDE the div will HIDE it.

It is useful for showing transient information.

vlAlertT is similar but takes 2 parameters - the second is millisecs until autoclose

*/

function hideIfRequired(ob){
	//Hide any relevant elements - these are SELECT obs that intersect ob
	try{
		if(is.ie6){
			var t = findPosY(ob);
			var b = t + getEltHeight(ob);
			var objForm = (document.forms['INTERNAL'] || document.forms['ROINTERNAL']);
			glHidden = new Array();
			if(objForm){
				for(var n=0;n<objForm.elements.length;++n){
					var lob = objForm.elements[n];
					if(lob.tagName=='SELECT'){
						var et = findPosY(lob);
						var eb = et + getEltHeight(lob);
						if(et<b && eb>t){
							glHidden.push(lob);
							if(UseVis){
								lob.visibility = "hide";
							}else{
								lob.oldClassName=objForm.elements[n].className;
								lob.className="hidden";
							}
						}
					}
				}
			}
		}
	}catch(erx){alert(erx);}
}

function showIfRequired(){
	//Show any hidden elements
	//alert('showing...');
	if(glHidden.length>0){
		for(var n=0;n<glHidden.length;++n){
			if(UseVis){
				glHidden[n].visibility = "show";
			}else{
			  glHidden[n].className=glHidden[n].oldClassName;
			}
		}
	}
	glHidden = new Array();
}


function vlAlertCloseCheck(){
	//Was it on some other part of the screen?
	if(global_on_click_flag){
		global_on_click_flag  = false;
		return;
	}
	vlAlertClose();
}

function vlAlertCloseT(){
	global_vlAlert_opacity = 100;
	global_vlAlert_timer = window.setTimeout("vlAlertCloseFade()",50);
}

function vlAlertCloseT2(){
	global_vlAlert_opacity = 100;
	global_vlAlert_timer = window.setTimeout("vlAlertCloseFade('VTDIVI2')",50);
}

function vlAlertCloseFade(mDivID){
//if(mDivID=='VTDIVI2')alert('vt2');
	global_vlAlert_opacity -= 10;
	if(!mDivID){mDivID='VTDIVI';}
	var mDiv = MM_findObj(mDivID);
	if(global_vlAlert_opacity>0){
		if(mDiv){
			mDiv.style.filter='alpha(opacity='+global_vlAlert_opacity+')';
			mDiv.style.opacity='0.'+global_vlAlert_opacity;
			global_vlAlert_timer = window.setTimeout("vlAlertCloseFade('"+mDivID+"')",50);
		}
	}else{
		mDiv.style.filter='alpha(opacity=0)';
		mDiv.style.opacity='0';
		global_vlAlert_timer = null;
		vlAlertClose(mDivID);
	}
}

function vlAlertCloseKillTimer(){
	if(global_vlAlert_timer){
		window.clearTimeout(global_vlAlert_timer);
		global_vlAlert_timer = null;
	}
}

function vlAlertClose(mDivID){
	//Clear up timer if required
gl_oshbx_disabled = false;
	if(!mDivID){mDivID='VTDIVI';}
	vlAlertCloseKillTimer();
	if(global_on_click){
		//Only execute once per invocation, unless on vtDivI2
		if(mDivID!='VTDIVI2'){
			global_on_click = false;
			//also hide VTDIV2 if visible
			var mDiv2 = MM_findObj('VTDIVI2');
			//Ravi / Louis : Jan 4th 2012 ; uncommented the innerHTML to '' line without regard to other consequences
			if(mDiv2)mDiv2.innerHTML='';
		}
		var mDiv = MM_findObj(mDivID);
		// mDiv.className="hidden"; == Unnecessary - and needs to be undone by later calls - source of a bug
		mDiv.innerHTML='';
	}
	showIfRequired();
}

function vlAlertReplace(s){
	//Standard Ajx message REPLACES the AJAX form 
	vlAlertAux(s,2000,null,null,false,true);
}

function vlAlertAjx(s){
	//Standard Ajx message - uses the ajx_procob and AZ
	//Oct 2007 was ajx_position(i.e. true) in param 3 (0,1,2,)
	vlAlertAux(s,2000,ajx_procob,false,false);
	ajx_position = 'ZA';
}

function vlAlertT1(s,t,p,a){
	if(p && p.alerted==undefined){
		if(t==null)t=2000;
		p.alerted=true;
		vlAlertT(s,t,p,a);
	}
}

function vlTipMouse(e,s,t,dx,dy,w,h,c){
	//as below, but e is the event, and p is not present
	if(!dx)dx=0;
	if(!dy)dy=0;
	getMousePos(e);
	vlTipMax(s,null,t,glMouseX+dx,glMouseY+dy,w,h,c);
}

function vlTipMaxId(s,p,t,dx,dy,w,h,c){
	//as below, but p is an ID
	p=MM_findObj(p);vlTipMax(s,p,t,dx,dy,w,h,c);
}

function vlTipMax(s,p,t,dx,dy,w,h,c){
	/*S is a string which may contain HTML, p is the positioning object , t is the timer value in millisec after which fade starts - if t is absent
	then it defaults to 2500, if t=0 then it is taken to be permanent display, if t<500 it is made 500
	dx and dy are relative placement offsets to the pos ob Top Left Corner default 0,0
	w,h are the alert width and height request which defualt to 800x300
	c is the class assigned to the dive we create */
	if(!dx)dx=0;
	if(!dy)dy=0;
	if(p){
		dx = dx + findPosX(p);
		dy = dy + findPosY(p);
	}
	if(!w)w=800;
	if(!h)h=300;
	if(!t){t=2500;}else{if(t==0){t=false;}else{if(t<500)t=500;}}
	var mDiv = MM_findObj('VTDIVI');
	mDiv.style.filter='alpha(opacity=0)';
	mDiv.style.opacity='0';
	setEltPos (mDiv, dx, dy, w, h);
	if(c){c='<div class="'+c+'">'}else{c='<div style="padding:0px">';}
	vlAlertAux(c+s+'</div>',t,null,null,null,null,true,true,true);

}

function vlTip(s,p){
	var dw = 100;
	try{
		dw = s.length * 8;
	}catch(e){}
	if(dw>200)dw=200;
	global_vlAlert_width = dw;
	vlAlertAux(s,2000,p,'GC',false);
	global_vlAlert_width = def_global_vlAlert_width;
}

function vlAlertT(s,t,p,a){
	//s=string, p=parent ob, a=placement string, supClose=true hides the close icon
	if(t==null)t=2000;
	if(isInDiv(p,MM_findObj('VTDIVI'))){
		vlAlertAux2(s,t,p,a,false);
	}else{
		vlAlertAux(s,t,p,a,false);
	}
}

function vlAlert(s,p,a,supClose,noFade){
	vlAlertAux(s,null,p,a,false,false,supClose,false,null,noFade);
}

function vlAlert2(s,p,a,supClose,noFade){
	//Provides a second level if required
	if(isInDiv(p,MM_findObj('VTDIVI'))){
		vlAlertAux2(s,null,p,a,false,false,supClose,false,null,noFade);
		return 'VTDIVI2';f
	}else{
		vlAlertAux(s,null,p,a,false,false,supClose,false,null,noFade);
		return 'VTDIVI';
	}
}

function vlAlertProg(p){
	var objForm = (document.forms['INTERNAL'] || document.forms['ROINTERNAL'] || document.forms['MODAL']);
	if(objForm==null){objForm = document.forms['MODAL'];}
	myLoc = '?BSLSessionStr='+objForm.BSLSessionStr.value;
	vlAlert('<div style="padding:20px;"><a href="QProg.jsp?BSLSessionStr='+objForm.BSLSessionStr.value+'" class="onScreenInfo" target="_self">Click here to see the progress of your request...</a></div>',p,'HA',true);
}

function vlAlertX(s,p,a){
	//Places the result in a TEXTBOX
	vlAlertAux(s,null,p,a,true);
}

function vlAlertSetWidth(w,mDivID){
	if(!mDivID){mDivID='VTDIVI';}
	var mDiv = MM_findObj(mDivID);
	if(mDiv){mDiv.style.width=w+'px';}
}

function vlAlertAuxRaw(s,mDivID){
	if(!mDivID){mDivID='VTDIVI';}
	var mDiv = MM_findObj(mDivID);
	if(mDiv){
		mDiv.innerHTML='<table border="0" cellspacing="0" cellpadding="0" class="siBDD" onclick="global_on_click_flag=true;"><tr><td><table border="0" cellspacing="0" cellpadding="0" bgcolor="#ffffff">'+
						'<tr><td>'+s+'</td></tr></table></td></tr></table>';
	}else{
		//Fail by alerting anyway
		alert('** NO VTDIV on Page **\n'+s);
	}
}

/* vlAlert perhaps needs to allow two alert levels so we can have alerts on ajax deliveries 
We rely on there being only one VTDIV to hide extraneous objects when a new one comes along.
If we have two, we then need a mechanism to say where we are, what the priority levels are and so on.
This is tricky.
In the instance of a calendar object, if we always use VTDIVI2 the situation is SIMPLER ==
We currently rely on the calendar closing the existing alerts, which is cool if the calendar is OUTSIDE the VTDIV
If it is INSIDE then closing the div kills the div (and the calendar is not shown either)
If we could work out whether we are in the div then that might be useful.

The first thing to tackle is the on entry message on date fields...

*/

function HTMLNodeIterator()
{
	//task:function,node:HTML Node
	this.iterate = function iterate(task,node)
	{
		//if(task(node))return true;
		var x=0;
		for(x=0;x<node.childNodes.length;x++)
		{
			var childNode = node.childNodes[x];
 
			if(task(childNode))return true;
 
			if( childNode.childNodes.length > 0 )
				if(this.iterate(task,childNode))return true;

		}
		return false;
	}
}

function setFocusToGrab(ob){
//	alert(ob.innerHTML);return;
var htmlNodeIterator = new HTMLNodeIterator();
htmlNodeIterator.iterate(setFocusToGrabDo,ob);
}

function setFocusToGrabDo(ob){
//	alert(ob.innerHTML);
	try{
		var gfo=ob.getAttribute('grabfocus');
		if(gfo){
			try{ob.focus();}catch(e){alert(e);}
			return true;
		}
	}catch(e1){}
	return false;
}

function setGlRet(ob){
//	alert(ob.innerHTML);return;
var htmlNodeIterator = new HTMLNodeIterator();
htmlNodeIterator.iterate(setGlRetDo,ob);
}

function setGlRetDo(ob){
//	alert(ob.innerHTML);
	try{
		var gfo=ob.getAttribute('gl_ret');
		if(gfo){
			gl_ret=ob.id;
			return true;
		}
	}catch(e1){}
	return false;
}

function isInDiv(ob,div){
	if(ob==null)return false;
	while(ob=ob.parentNode){
		if(div==ob)return true;
	}
	return false;
}

function vlAlertAux(s,t,p,a,textbox,replace,supClose,noShift,supTimerStyle,noFade){
	vlAlertClose();
	var mDiv = MM_findObj('VTDIVI');
	vlAlertAuxDo(mDiv,s,t,p,a,textbox,replace,supClose,noShift,supTimerStyle,noFade);
	mnOvrKill();
	setFocusToGrab(mDiv);
	setGlRet(mDiv);
}

function vlAlertAux2(s,t,p,a,textbox,replace,supClose,noShift,supTimerStyle,noFade){
	var mDiv = MM_findObj('VTDIVI2');
	if(mDiv==null){
		//div id="VTDIVI" class="hidden" style="position:absolute;">&nbsp;</div><
		mDiv = document.createElement('div');
		mDiv.id = 'VTDIVI2';
		mDiv.style.position='absolute';
		//mDiv.className="hidden";
		document.body.appendChild(mDiv);
		mDiv.style.zIndex="102";
	}
	mDiv = MM_findObj('VTDIVI2');
	vlAlertAuxDo(mDiv,s,t,p,a,textbox,replace,supClose,noShift,supTimerStyle,noFade);
	mnOvrKill();
	setFocusToGrab(mDiv);
	setGlRet(mDiv);
}

function vlAlertAuxDo(mDiv,s,t,p,a,textbox,replace,supClose,noShift,supTimerStyle,noFade){
	/* 
	mDiv is the Div to use
	s = string content of div to display
	   t = time in milliseconds to display for - null means no auto close
	   p = parent object for placement purposes - null means at tlc
	   a = placement string - can be null - defaults to --
	   textbox is a boolean which signals putting all the text into a textbox - HTML is displayed as it reads...
	   replace is a boolean signifying that the text REPLACES the current contents of the div -- saves the error on when the ajax ob is in the div!
	*/
	//If already in alert close...
	if(textbox && s){
		r = /textarea/gi;
		s = s.replace(r,'text area');
	}
	if(mDiv){
		//if not s or s is zero length we must null the div...
		mDiv.style.filter='alpha(opacity=100)';
		mDiv.style.opacity='1';
		mDiv.className='visible';
		if(s==null || s=='\r\n\r\n'){
			mDiv.innerHTML='';
		}else{
			//FOR NOW if t is not then we display the textbox with button
			//otherwise we use the popup title div settings
			if(t){
				if(supTimerStyle){
					mDiv.innerHTML='<table width="'+global_vlAlert_width+'px" border="0" cellspacing="1" cellpadding="0">'+
								'<tr><td>'+s+'</td></tr></table>';
				}
				else{
					mDiv.innerHTML='<table class="vlAlertTimed" width="'+global_vlAlert_width+'px" border="0" cellspacing="1" cellpadding="0" class="PopMenuTab">'+
								'<tr><td class="PopMenuDefault">'+s+'</td></tr></table>';
				}
			}else{
				if(textbox){
					mDiv.innerHTML='<table class="vlAlertText" onclick="global_on_click_flag=true;"><tr><td><textarea  class="XLocatorSmallB"  style="width:380px;height:280px;"  type="text">'+s+
						'</textarea><br><input class="SubMenuOff" style="width:100px;height:19px;" type="button" name="B" value= "Close" onclick="vlAlertClose();"/></td></tr></table>';
				}else{
					var local_class = gl_vlAlertClass;
					if(gl_vlAlertClassOverride){local_class = gl_vlAlertClassOverride;gl_vlAlertClassOverride=false;}
					var local_style = gl_vlAlertStyle;
					if(gl_vlAlertStyleOverride){local_style = gl_vlAlertStyleOverride;gl_vlAlertStyleOverride=false;}
//					mDiv.innerHTML='<div class="'+local_class+
//						'" style="padding-bottom:8px;display:inline-block;zoom:1;'+local_style+
//						'" onclick="global_on_click_flag=true;">'+
//						(supClose ? '' : '<div style="float:right;width:14px"><img src="'
//						+global_app_path+'Assets/Images/close.gif" alt = "Close" onclick="vlAlertClose();"></div>')+s+'</div>';
					mDiv.innerHTML='<table><tr><td class="'+local_class+
						'" style="padding-bottom:8px;text-align:left;'+local_style+
						'" onclick="global_on_click_flag=true;">'+
						(supClose ? '' : '<div style="float:right;width:14px;padding:2px"><img src="'
						+global_app_path+'Assets/Images/close.gif" style="padding:1px" alt = "Close" onclick="vlAlertClose();"></div>')+s+'</td></tr></table>';
//					mDiv.innerHTML='<table  border="0" cellspacing="0" cellpadding="0" class="'+local_class+'" style="padding-bottom:8px;'+local_style+'" onclick="global_on_click_flag=true;"><tr><td><table border="0" cellspacing="0" cellpadding="0" width="100%">'+
//						(supClose ? '' : '<tr><td align="right"><img src="'+global_app_path+'Assets/Images/close.gif" alt = "Close" onclick="vlAlertClose();"></td></tr>')+
//						'<tr><td>'+s+'</td></tr></table></td></tr></table>';
				}
			}
		}
		if(!noShift){
			if(!replace){
				if(p){
					SetPosBelowC(p,mDiv,a,true);
				}else{
					setEltPos (mDiv, 0, 0, 800, 500);
				}
			}
		}
		mDiv.style.zIndex="101";
		mDiv.className="visible";
		if(!noFade)divFadeInOb(mDiv,null,10);
		hideIfRequired(mDiv);
		window.setTimeout("global_on_click = 'vlAlertCloseCheck()'",600);
		if(t){
			//var lmDiv = MM_findObj('VTDIVI');
			if(mDiv.id=='VTDIVI'){
				global_vlAlert_timer = window.setTimeout("vlAlertCloseT()",t);
			}else{
				global_vlAlert_timer = window.setTimeout("vlAlertCloseT2()",t);
			}
		}
	}else{
		//Fail by alerting anyway
		alert('** NO VTDIV on Page **\n'+s);
	}
}

function getAjaxDiv(thediv){
	//This is called by all routines checking for ajax purposes whether the div exists
	//The idea is that standard named divs with their standard behaviours can be responded to here positively even if they do not exist
	if(thediv=='divSNULL')return true;
	if(thediv=='divSHOLD')return true;
	if(thediv=='divSHOLDFIX')return true;
	if(thediv=='divSHOLDP')return true;
	if(thediv=='divSCHOOSE')return true;
	if(thediv=='divSSELF')return true;
	if(thediv=='divSREPLACE')return true;
	if(thediv=='divSTOPLEFT')return true;
/*	if(thediv=='divSTOPRIGHT')return true;
	if(thediv=='divSBOTLEFT')return true;
	if(thediv=='divSBOTRIGHT')return true;*/
	if(thediv=='divSCENTRE')return true;
	if(thediv=='divSCENTER')return true;
	return document.getElementById(thediv);//The default response
}

/******************************************** ESF SPECIFIC FUNTIONS ********************************************/
function doNothing (){}

function sbRemAux(ob){
	var cob = ob;
	var rob = ob;
	var prob = ob;
	var pprob = ob;
	var foundrow = false;
	while (cob = getEltParNode (cob)){
		if(cob.id && cob.id == "BRENDER"){
			//We are at the relevant table object
			//rob is the row
			//alert('found BRENDER');
			var n=0;
			//alert(cob.rows.length);
			for(n=0;n<cob.rows.length;++n){
				if(cob.rows[n]==rob || cob.rows[n]==prob || cob.rows[n]==pprob){
					foundrow = true;
					cob.deleteRow(n);
					break;
				}
			}
			if(foundrow)break;
		}
		pprob = prob;
		prob = rob;
		rob = cob;
	} 
}

function sbRem(ob,subAc){
	//Remove from list in BRENDER
	//FIRST FIND THE Surrounding din called divIName_00000361
	document.forms['INTERNAL'].BSLSubAction.value=subAc;
	var myvar = 'globvar_'+(global_varctr++);
	eval(myvar+'=ob;');
	window.setTimeout('sbRemAux('+myvar+')',133);
}

function piAddRemAux(ob){
	var cob = getEltParNode (ob); 
	var ih = cob.innerHTML;

	r = /add_bask_on/gi;
	ih = ih.replace(r,'abonInt');
	r = /rem_bask_ong/gi;
	ih = ih.replace(r,'rbonInt');
	r = /add_bask_off/gi;
	ih = ih.replace(r,'abofInt');
	r = /rem_bask_offg/gi;
	ih = ih.replace(r,'rbofInt');

	r = /abonInt/gi;
	ih = ih.replace(r,'rem_bask_ong');
	r = /rbonInt/gi;
	ih = ih.replace(r,'add_bask_on');
	r = /abofInt/gi;
	ih = ih.replace(r,'rem_bask_offg');
	r = /rbofInt/gi;
	ih = ih.replace(r,'add_bask_off');

	r = /Add to Basket/gi;
	ih = ih.replace(r,'xxxxInt');
	r = /Remove from basket/gi;
	ih = ih.replace(r,'Add to Basket');
	r = /xxxxInt/gi;
	ih = ih.replace(r,'Remove from basket');

	cob.innerHTML = ih;
}

function piAddRem(ob,subAc){
	document.forms['INTERNAL'].BSLSubAction.value=subAc;
	var myvar = 'globvar_'+(global_varctr++);
	eval(myvar+'=ob;');
	//The timer is so that the onclick for the parent can happen in the gap...
	window.setTimeout('piAddRemAux('+myvar+')',133);
}

function gc2s(a,b,c){
	alert(a+'\n'+b+'\n'+c);
}

var glob_po = null;

function gc2(a,b,c){
	if(glob_po!=null && isParentOf(glob_po,c))alert('parent');
	glob_po=c;
	alert(a+'\n'+b+'\n'+c);
}


function testme(){
	var d = eval('window.location="asdf"');
	alert(d);
}

function slowScrollDnAux(){
	if(scrollStep<13){
		scrollStep = scrollStep-1;
		window.scrollBy(0,1);
	}else{
		var ts = scrollStep/2;
		if(ts>40)ts=40;
		scrollStep = scrollStep - ts;
		window.scrollBy(0,ts);
	}
	if(scrollStep<0){
		window.clearInterval(scrollTimer);
	}
}

function slowScrollUpAux(){
	if(scrollStep>-13){
		scrollStep = scrollStep + 1;
		window.scrollBy(0,-1);
	}else{
		var ts = scrollStep/2;
		if(ts<-40)ts=-40;
		scrollStep = scrollStep - ts;
		window.scrollBy(0,ts);
	}
	if(scrollStep>0){
		window.clearInterval(scrollTimer);
	}
}

function slowScroll(d){
	if(scrollTimer){
		window.clearInterval(scrollTimer);
		scrollTimer = null;
	}
	if(d==0)return;
	scrollStep = d;
	//Scroll to abs pos d from here in steps of 20
	if(scrollStep<0){
		scrollTimer = window.setInterval('slowScrollUpAux()',6);
	}else{
		scrollTimer = window.setInterval('slowScrollDnAux()',6);
	}
}

function tillBr(s,hideList){
	//s is an object whose innerHTML is obtained and parsed to return everything this side of the <br> which if not found
	//if <br> not found return the entire html
	//if there is a trappable error we alert the user in an alert
	try{
		// go for it
		mys = s.innerHTML;
		myc = mys.toUpperCase().indexOf('<BR>');
		if(hideList){
			vlAlertCloseT();
		}
		if(myc<0)return mys;
		return remHtmlMkUp(mys.substr(0,myc));
	}catch(er){alert(er);return '';}
}

function remHtmlMkUp(S){
	S = S.replace(/&amp;/g,'&');
	S = S.replace(/&lt;/g,'<');
	S = S.replace(/&gt;/g,'>');
	return S;
}

function exCol(s,n,hideList){
	//s is an object whose innerHTML is obtained and parsed 
	//it is expected to be a SINGLE TABLE ROW
	//the n'th column value is returned
	//if there is no nth column an error alert is sent
	try{
		// go for it
		mys = s.cells[n].innerHTML;
		if(hideList){
			vlAlertCloseT();
		}
		return remHtmlMkUp(mys);
	}catch(er){alert(er);return '';}
}

function getFirstTab(anode){
	var x=anode.childNodes;
	for (i=0;i<x.length;i++){
		if(x[i].nodeName == 'TABLE'){
			return x[i];
		}
	}
	return null;
}

function analyseChoices(){
	var f = document.getElementById('divICHOICES');
	var s = '';
	theCurrRow = 0;
	var theRows=false;
	if(f){
		f=getFirstTab(f);
		if(f){
			f=getFirstTab(f.rows[0].cells[0]);
			if(f){
				theCRows = f.rows;
				theCRowsCt = theCRows.length;
			}
		}
	}else{
		alert('not found');
	}
}

function choicesKD(e){

	var ek = window.event;
	if(e==null)e=window.event;
	if(ek){
		ek = e.keyCode;
	}else{
		ek = e.which;
	}

	var lastRow = theCurrRow;
	var thisChoices = document.getElementById('divICHOICES');
	if(thisChoices){
		if((ek==13)||(ek==38)||(ek==40)){
			if(thisChoices==theLastChoices){}else{
				analyseChoices();
				theLastChoices = thisChoices;
			}
			if(theCRows){
				if(ek==13){
					ajx_procob.value=exCol(theCRows[theCurrRow],0,1);
					try{if(ajx_procob.onchange)ajx_procob.onchange();}catch(erx){alert(erx);}
					e.returnValue = false;
					e.cancelBubble = true;
					if(e.stopPropagation)e.stopPropagation();
					return false;
				}

				if(ek==38){
					theCurrRow = theCurrRow-1;
				}
				if(ek==40){
					theCurrRow = theCurrRow+1;
				}
				if(theCurrRow>=theCRowsCt){
					theCurrRow=0;
				}
				if(theCurrRow<0){
					theCurrRow=theCRowsCt-1;
				}
				try{theCRows[lastRow].onmouseout();}catch(er){}
				try{theCRows[theCurrRow].onmouseover();}catch(er){}
			}
		}
	}
}

function chooserClick(){
ajx_procob.value=exCol(global_gcob,0,1);
try{if(ajx_procob.onchange)ajx_procob.onchange();}catch(erx){alert(erx);}
}

function gotAjaxRequest(ob,del){
	//we are passed an ajax request which we return true if we find it
	//if del is true then we remove the request if we do find it
	for(var n=0;n<glAjaxRequests.length;++n){
		if(glAjaxRequests[n]==ob){
			if(del)glAjaxRequests.splice(n,1);
			return true;
		}
	}
	return false;
}

function killDdList(ob){
	//Kill drop down lists for various reasons
	//Kil any pending requests from this ob
	killAjax(ob);
//if(window.debugob)debugob.value = debugob.value + 'killed';
	//If showing kill it
	if(ajax6TO){
		window.clearTimeout(ajax6TO);
		ajax6TO = null;
	}
	//immediately hide any existing...
	killDdTimer = window.setTimeout('vlAlertClose()',1000);
}

function killAjax(caller){
	//ob is the owner object of the ajax request we want to kill
	for(var n=0;n<glAjaxRequests.length;++n){
		if(glAjaxRequests[n].callerOb==caller){
			glAjaxRequests[n].waiterOb.decCC();
			glAjaxRequests.splice(n,1);
			--n;
		}
	}
}

/**
 * http://www.openjs.com/scripts/events/keyboard_shortcuts/
 * Version : 2.01.B
 * By Binny V A
 * License : BSD 
 */
shortcut = {
	'all_shortcuts':{},//All the shortcuts are stored in this array
	'add': function(shortcut_combination,callback,opt,helpText) {
		//Provide a set of default options
		var default_options = {
			'type':'keydown',
			'propagate':false,
			'disable_in_input':false,
			'target':document,
			'keycode':false
		}
		if(!opt) opt = default_options;
		else {
			for(var dfo in default_options) {
				if(typeof opt[dfo] == 'undefined') opt[dfo] = default_options[dfo];
			}
		}

		var ele = opt.target;
		if(typeof opt.target == 'string') ele = document.getElementById(opt.target);
		var ths = this;
		shortcut_combination = shortcut_combination.toLowerCase();

		//The function to be called at keypress
		var func = function(e) {
			e = e || window.event;
			
			if(opt['disable_in_input']) { 
				var element;
				if(e.target) element=e.target;
				else if(e.srcElement) element=e.srcElement;
				if(element.nodeType==3) element=element.parentNode;

				if (element.tagName == 'SELECT' || element.tagName == 'TEXTAREA' || (element.tagName == 'INPUT' && element.type == 'text')) return;			}
	
			//Find Which key is pressed
			if (e.keyCode) code = e.keyCode;
			else if (e.which) code = e.which;
			var character = String.fromCharCode(code).toLowerCase();
			
			if(code == 188) character=","; //If the user presses , when the type is onkeydown
			if(code == 190) character="."; //If the user presses , when the type is onkeydown

			var keys = shortcut_combination.split("+");
			//Key Pressed - counts the number of valid keypresses - if it is same as the number of keys, the shortcut function is invoked
			var kp = 0;
			
			//Work around for stupid Shift key bug created by using lowercase - as a result the shift+num combination was broken
			var shift_nums = {
				"`":"~",
				"1":"!",
				"2":"@",
				"3":"#",
				"4":"$",
				"5":"%",
				"6":"^",
				"7":"&",
				"8":"*",
				"9":"(",
				"0":")",
				"-":"_",
				"=":"+",
				";":":",
				"'":"\"",
				",":"<",
				".":">",
				"/":"?",
				"\\":"|"
			}
			//Special Keys - and their codes
			var special_keys = {
				'esc':27,
				'escape':27,
				'tab':9,
				'space':32,
				'return':13,
				'enter':13,
				'backspace':8,
	
				'scrolllock':145,
				'scroll_lock':145,
				'scroll':145,
				'capslock':20,
				'caps_lock':20,
				'caps':20,
				'numlock':144,
				'num_lock':144,
				'num':144,
				
				'pause':19,
				'break':19,
				
				'insert':45,
				'home':36,
				'delete':46,
				'end':35,
				
				'pageup':33,
				'page_up':33,
				'pu':33,
	
				'pagedown':34,
				'page_down':34,
				'pd':34,
	
				'left':37,
				'up':38,
				'right':39,
				'down':40,
	
				'f1':112,
				'f2':113,
				'f3':114,
				'f4':115,
				'f5':116,
				'f6':117,
				'f7':118,
				'f8':119,
				'f9':120,
				'f10':121,
				'f11':122,
				'f12':123
			}
	
			var modifiers = { 
				shift: { wanted:false, pressed:false},
				ctrl : { wanted:false, pressed:false},
				alt  : { wanted:false, pressed:false},
				meta : { wanted:false, pressed:false}	//Meta is Mac specific
			};
                        
			if(e.ctrlKey)	modifiers.ctrl.pressed = true;
			if(e.shiftKey)	modifiers.shift.pressed = true;
			if(e.altKey)	modifiers.alt.pressed = true;
			if(e.metaKey && navigator.userAgent.toLowerCase().indexOf("chrome") == -1) modifiers.meta.pressed = true;
                        
			for(var i=0; k=keys[i],i<keys.length; i++) {
				//Modifiers
				if(k == 'ctrl' || k == 'control') {
					kp++;
					modifiers.ctrl.wanted = true;

				} else if(k == 'shift') {
					kp++;
					modifiers.shift.wanted = true;

				} else if(k == 'alt') {
					kp++;
					modifiers.alt.wanted = true;
				} else if(k == 'meta') {
					kp++;
					modifiers.meta.wanted = true;
				} else if(k.length > 1) { //If it is a special key
					if(special_keys[k] == code) kp++;
					
				} else if(opt['keycode']) {
					if(opt['keycode'] == code) kp++;

				} else { //The special keys did not match
					if(character == k) kp++;
					else {
						if(shift_nums[character] && e.shiftKey) { //Stupid Shift key bug created by using lowercase
							character = shift_nums[character]; 
							if(character == k) kp++;
						}
					}
				}
			}
			
			if(kp == keys.length && 
						modifiers.ctrl.pressed == modifiers.ctrl.wanted &&
						modifiers.shift.pressed == modifiers.shift.wanted &&
						modifiers.alt.pressed == modifiers.alt.wanted &&
						modifiers.meta.pressed == modifiers.meta.wanted) {
				callback(e);
	
				if(!opt['propagate']) { //Stop the event
					//e.cancelBubble is supported by IE - this will kill the bubbling process.
					e.cancelBubble = true;
					e.returnValue = false;
	
					//e.stopPropagation works in Firefox.
					if (e.stopPropagation) {
						e.stopPropagation();
						e.preventDefault();
					}
					return false;
				}
			}
		}
		if(this.all_shortcuts[shortcut_combination]==undefined || this.all_shortcuts[shortcut_combination]['target']!=ele){
			this.all_shortcuts[shortcut_combination] = {
				'callback':func, 
				'target':ele, 
				'event': opt['type'],
				'helpText':helpText
			};
			//Attach the function with the event
			if(ele.addEventListener) ele.addEventListener(opt['type'], func, false);
			else if(ele.attachEvent) ele.attachEvent('on'+opt['type'], func);
			else ele['on'+opt['type']] = func;
		}else{
			//Alert
			alert(shortcut_combination+' on this element already assigned.');
		}
		//This code will silently overwrite:
/*		if(this.all_shortcuts[shortcut_combination]!=undefined && this.all_shortcuts[shortcut_combination]['target']==ele){
			this.remove(shortcut_combination);
		}
		this.all_shortcuts[shortcut_combination] = {
			'callback':func, 
			'target':ele, 
			'event': opt['type'],
			'helpText':helpText
		};
		//Attach the function with the event
		if(ele.addEventListener) ele.addEventListener(opt['type'], func, false);
		else if(ele.attachEvent) ele.attachEvent('on'+opt['type'], func);
		else ele['on'+opt['type']] = func;*/
	},

	//helpText display
	'help':function(){
		var s='Shortcut key help:\n';
		var non = true;
		for(var i in this.all_shortcuts){
			non=false;
			s += '\n'+(this.all_shortcuts[i].helpText==undefined?i+' does something!':'Press '+ i +' to ' + this.all_shortcuts[i].helpText);
		}
		if(non){s+='\nThere are no shortcuts defined on this page.'};
		alert(s);
	},

	//Remove the shortcut - just specify the shortcut and I will remove the binding
	'remove':function(shortcut_combination) {
		shortcut_combination = shortcut_combination.toLowerCase();
		var binding = this.all_shortcuts[shortcut_combination];
		delete(this.all_shortcuts[shortcut_combination])
		if(!binding) return;
		var type = binding['event'];
		var ele = binding['target'];
		var callback = binding['callback'];

		if(ele.detachEvent) ele.detachEvent('on'+type, callback);
		else if(ele.removeEventListener) ele.removeEventListener(type, callback, false);
		else ele['on'+type] = false;
	}
}

/**
  bslCal calendar
 */
var sDays = new Array("Mon","Tue","Wed","Thu","Fri","Sat","Sun");
var sMons = new Array("Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec");

function bslCal(){ }
bslCal.prototype = {
	theDate:false,
	currDate:false,
	today:false,
	bslId:false,
	divob:false,
	calDivID:false,
	srcOb:false,
	isFree:false,
	init:function(aDate,fdivob){
		this.bslId = 'bslId'+Math.floor(Math.random()*10000);
		this.srcOb = aDate;
		this.theDate = new Date();
		this.currDate = new Date();
		this.today = new Date();
		this.trimDate(this.today);
		this.trimDate(this.theDate);
		this.trimDate(this.currDate);
		if(aDate){
			//aDate is an input object whose value is a string of form dd/mm/yyyy
			strValid(aDate,"D");
			var aDateStr = aDate.value;
			if(aDateStr.length>0){
				this.theDate.setDate(1);
				this.theDate.setFullYear(parseInt(aDateStr.substr(6,4),10));
				this.theDate.setMonth(parseInt(aDateStr.substr(3,2),10)-1);
				this.currDate.setDate(parseInt(aDateStr.substr(0,2),10));
				this.currDate.setFullYear(parseInt(aDateStr.substr(6,4),10));
				this.currDate.setMonth(parseInt(aDateStr.substr(3,2),10)-1);
			}
		}
		//fdivob.innerHTML=this.render();
		//vlAlertAux(this.render(),null,aDate,'ZA',false,false,true,false);
		vlAlertCloseKillTimer();
		vlAlertSetWidth(212,this.calDivID=vlAlert2(this.render(),aDate,'HA',true));
	if(fdivob){
			this.divob = fdivob;
		}else{
			this.divob = false;//MM_findObj('VTDIVI');
		}
	gl_calendar = this;
 	},
	trimDate:function(d){
		d.setMilliseconds(0);
		d.setSeconds(0);
		d.setMinutes(0);
		d.setHours(0);
	},
	goToday:function(){
		this.theDate = new Date();
		this.put();
	},
	downYr:function(){
		this.theDate.setFullYear(this.theDate.getFullYear()-1);
		this.put();
	},
	put:function(){
			gl_calendar=this;
			window.setTimeout('gl_calendar.makeUnFree();',50);
		if(this.divob){
			this.divob.innerHTML=this.render();
		}else{
			vlAlertAuxRaw(this.render(),this.calDivID);
		}
		this.putFocus();
	},
	downMonth:function(){
		var tm = this.theDate.getMonth();
		if(tm==0){
			this.theDate.setFullYear(this.theDate.getFullYear()-1);
			this.theDate.setMonth(11);
		}else{
			this.theDate.setMonth(tm-1);
		}
		this.put();
	},
	upYr:function(){
		this.theDate.setFullYear(this.theDate.getFullYear()+1);
		this.put();
	},
	upMonth:function(){
		var tm = this.theDate.getMonth();
		if(tm==11){
			this.theDate.setFullYear(this.theDate.getFullYear()+1);
			this.theDate.setMonth(0);
		}else{
			this.theDate.setMonth(tm+1);
		}
		this.put();
	},
	done:function(){
		if(this.divob){
			this.divob.innerHTML='';
		}else{
			vlAlertClose(this.calDivID);
		}
	},
	doneFree:function(){
		if(this.isFree){this.done();return false;}else{return this;}
	},
	makeFree:function(){
		this.isFree=true;
	},
	makeUnFree:function(){
		this.isFree=false;
	},
	equalDates:function(da,db){
		return(da.getDate()==db.getDate() && da.getMonth()==db.getMonth() && da.getYear()==db.getYear());
	},
	putValue:function(a){
		if(this.srcOb && a){
			this.srcOb.focus();
			this.srcOb.value = (a<10?'0':'')+a+'/'+(this.theDate.getMonth()<9?'0':'')+(1+this.theDate.getMonth()+'/'+this.theDate.getFullYear());
		}
		var oldso = this.srcOb;
		this.done();
		if(oldso.onchange)oldso.onchange();
	},
	putFocus:function(){
		gl_oldso = this.srcOb;
		if(gl_oldso)window.setTimeout('gl_oldso.focus();',300);
	},
	render:function (){
		var d = this.theDate;
		var d2 = new Date(d);
		var d1 = new Date(d);
		this.trimDate(d1);
		this.trimDate(d2);

		d2.setDate(1);
		d1.setDate(1);
		var fDay = d2.getDay();
		if(fDay==0)fDay=7;
		if(d2.getMonth==11){
			d1.setMonth(0);
			d1.setFullYear(d2.getYear()+1);
		}else{
			d1.setMonth(d2.getMonth()+1);
		}
		var daysInMon = Math.round((d1.getTime() - d2.getTime())/(1000*60*60*24));
		var weeksInMon = Math.ceil((fDay+daysInMon-1)/7);
		//var weeksInMon = 6;
		var nRowCell = '<td style="height:1px;width:30px"></td>';
		var dCellE = '</td>';
		var dRowS = '<tr>';
		var dRowE = '</tr>';
		var n = 0;
		var m = 0;
		var cd;
		var cDay = 0;
		var theDay = 1;
		eval(this.bslId+'=this;');
		var lbutns = '<img src="'+global_app_path+'Assets/Images/darl.gif" alt="Down a year" onmousedown="'+this.bslId+'.downYr()"><img src="'+global_app_path+'Assets/Images/sarl.gif" alt="Down a month" onmousedown="'+this.bslId+'.downMonth()">';
		var rbutns = '<img src="'+global_app_path+'Assets/Images/harr.gif" alt="Today" onmousedown="'+this.bslId+'.goToday()"><img src="'+global_app_path+'Assets/Images/sarr.gif" alt="Up a month" onmousedown="'+this.bslId+'.upMonth()"><img src="'+global_app_path+'Assets/Images/darr.gif" alt="Up a year" onmousedown="'+this.bslId+'.upYr()">';
		//alert(eval(this.bslId));
		//document.getElementById(\''+this.bslId+'\').downMonth()
		var s = '<table cellpadding="1" cellspacing="0" border="0" width="210px" bgcolor="black" style="text-align:center;table-layout:auto" class="listTable" >';
				s = s + '<tr class="listTitles">';
				s = s + nRowCell + nRowCell + nRowCell + nRowCell + nRowCell + nRowCell + nRowCell;
				s = s + '</tr>';
				s = s + '<tr class="listTitles"><td colspan="2" style="text-align:left">'+lbutns+'</td><td style="width:150px" colspan="3">'+sMons[d.getMonth()]+' '+this.theDate.getFullYear()+'</td><td colspan="2" style="text-align:right">'+rbutns+'</td></tr>';
				s = s + '<tr class="listTitles"><td>Mo</td><td>Tu</td><td>We</td><td>Th</td><td>Fr</td><td>Sa</td><td>Su</td></tr>';
				for(m=0;m<weeksInMon;++m){
					s = s + dRowS;
					for(n=1;n<8;++n){
						cd = (n<fDay?'':(theDay<=daysInMon?theDay++:''));
						var cStyle="listOff1";
						if(this.equalDates(d2,this.currDate)){
							cStyle="listOff4";
						}else if(this.equalDates(d2,this.today) ){
							cStyle="listOff3";
						}else{
							if(n>5){
								cStyle="listOff2";
								//s = s + '<td class="listOff2" '+(n<fDay?'':'onMouseOver="tcn(this,\'listOn\')" onMouseOut="tcnp(this)" onmousedown="'+this.bslId+'.putValue('+cd+')"')+'>' + cd + dCellE;
							}else{
								cStyle="listOff1";
								//s = s + '<td class="listOff1" '+(n<fDay?'':'onMouseOver="tcn(this,\'listOn\')" onMouseOut="tcnp(this)" onmousedown="'+this.bslId+'.putValue('+cd+')"')+'>' + cd + dCellE;
							}
						}
						s = s + (cd==''?'<td></t>':'<td class="'+cStyle+'" '+(n<fDay?'':'onMouseOver="tcn(this,\'listOn\')" onMouseOut="tcnp(this)" onmousedown="'+this.bslId+'.putValue('+cd+')"')+'>' + cd + dCellE);
						if(cd!=''){
							d2.setTime(d2.getTime()+(1000*60*60*24));
						}
					}
					cDay = cDay+7;
					fDay=-1;
					s = s + dRowE;
				}
				s = s + '</tr></table>';
				return s;
	}
}

function doDoc(a){
	PermitUnload = true;
	var parentDiv = document.createElement("div");
	parentDiv.innerHTML = '<iframe style="display:none" src="'+a+'"></iframe>';
	document.body.appendChild(parentDiv); 
}

function doDocOLD(a){
    PermitUnload = true;
    var iframe = document.createElement("iframe");
    iframe.src = a;
    iframe.style.display = "none";
    document.body.appendChild(iframe); 
}

function doDocPop(a){
w=window.open(a,a,"location=no,scrollbars,resizable");
w.focus();
}


function divFadeIn(s,x){
	divFadeInOb(glFadeInDiv = MM_findObj(s),x);
}

function divFadeInOb(s,x,d){
	glFadeInDiv = s;
	glFadeInDiv.style.filter='alpha(opacity=0)';
	glFadeInDiv.style.opacity='0';
	glOnFadeIn = x;
	glFadeInStep=d?d:5;
	if(glFadeInDiv){
		glFadeInOpacity = -5;
		divFadeInDo();
	}else{
		alert('Div '+s+' not found...');
	}
}

function divFadeInDo(){
	glFadeInOpacity += glFadeInStep;
	if(glFadeInOpacity<100){
		glFadeInDiv.style.filter='alpha(opacity='+glFadeInOpacity+')';
		glFadeInDiv.style.opacity=String(glFadeInOpacity/100);
		window.setTimeout("divFadeInDo()",30);
	}else{
		glFadeInDiv.style.filter='alpha(opacity=100)';
		glFadeInDiv.style.opacity='1';
		if(glOnFadeIn)eval(glOnFadeIn);
	}

}

function divFadeOut(s,x){
	divFadeOutOb(MM_findObj(s),x);
}

function divFadeOutOb(s,x,d){
	glFadeOutDiv = s;
	glOnFadeOut = x;
	glFadeOutStep=d?d:5;
	if(glFadeOutDiv){
		glFadeOutOpacity = 100;
		divFadeOutDo();
	}else{
		alert('Div '+s+' not found...');
	}
}

function divFadeOutDo(){
	glFadeOutOpacity -= glFadeOutStep;
	if(glFadeOutOpacity>0){
		glFadeOutDiv.style.filter='alpha(opacity='+glFadeOutOpacity+')';
		glFadeOutDiv.style.opacity=String(glFadeOutOpacity/100);
		window.setTimeout("divFadeOutDo()",30);
	}else{
		glFadeOutDiv.style.filter='alpha(opacity=0)';
		glFadeOutDiv.style.opacity='0';
		if(glOnFadeOut)eval(glOnFadeOut);
	}
}

function showHide(s,t,v){
//s is the div, t is the calling object, v is a boolean indicating use + and - instead of hide and show
var myDiv = MM_findObj(s);
if(myDiv){
	if(myDiv.style.display=='none'){
		if(!gl_displayHolder[s]){gl_displayHolder[s]='block';}
		myDiv.style.display=gl_displayHolder[s];
		if(t)t.value=v?'-':"Hide";
	}else{
		var oldDisplay = myDiv.style.display;
		if(oldDisplay){oldDisplay=oldDisplay;}else{oldDisply='block';}
		gl_displayHolder[s]=oldDisplay;
		myDiv.style.display='none';
		if(t)t.value=v?'+':"Show";
	}
}else{alert('showHide failed to find div: '+s);}
}

function jpgOver(img){
	//this function checks to see if we are magnifying and does it if required -- reuires the paeg to have included the magnifier code
	TJPzoomif(img);
}

function myPrint(s){
var myWin = window.open('','mywindow');
myPrintAux(myWin,s);
myWin.setTimeout('this.print();this.close()',400);
}

function myShow(s){
var myWin = window.open('','mywindow'+Math.floor(Math.random()*1000+1));
myPrintAux(myWin,s);
}

function myPrintAux(myWin,s){
if(!s)s='Printing and Viewing window';
myWin.document.write('<html><head><link href="Assets/print.css" rel="stylesheet" type="text/css" media="print"><title>'+s+'</title></head><body>');
myWin.document.write(MM_findObj('html_print_cont_div').innerHTML);
myWin.document.write('</body>');
myWin.document.close();
myWin.focus();
}

function subFile(s){
CID=s;
document.forms['INTERNAL'].method='post';
document.forms['INTERNAL'].enctype='multipart/form-data';
document.forms['INTERNAL'].encoding='multipart/form-data';
subGen();
}

function unwatch(){
var vd=document.getElementById('vidDiv');
if(vd){vd.innerHTML=glOldVidDivHtml?glOldVidDivHtml:'';}
}

function vidWatch(s){
var vd=document.getElementById('vidDiv');
var n=s.lastIndexOf('/');
if(n>=0){s=s.substring(n+1);}
if(vd){
	glOldVidDivHtml=vd.innerHTML;
	vd.innerHTML='<div><a href="javascript:unwatch();" style="display:block;margin:3px 3px 3px 0;width:86px;padding:3px;border:1px solid #B53614">hide video</a></div><iframe width="480" height="300" src="http://www.youtube.com/embed/'+s+'" frameborder="0" allowfullscreen></iframe>';}
}

function linkOver(ob){if(gl_link_init)ob.className = ob.getAttribute('classStub')+'H';}

function linkOut(ob){if(gl_link_init)ob.className = ob.getAttribute('oldClassName');}

function linkFixup(){
	var i=0;
	var ll = document.links.length;
	/*The javascript function will be passed a boolean to say if the class is replaced, and MUST check to see if H terminates the old class name and drop it if it does*/
	for (i=0;i<ll;i++){
		var parnod = document.links[i].parentNode;
		var ocn = parnod.getAttribute('classStub');
		var cReplace = true;
		if(ocn==null){
			ocn=parnod.className;
			cReplace=false;
		}
		if(!cReplace){parnod.setAttribute('classStub',ocn);}
		if(document.links[i].host.indexOf(window.location.host)==0){
			var pn = document.links[i].pathname;
			if(pn.charAt(0)=='/'){var a=0;}else{pn='/'+pn;}
			if(window.location.pathname.indexOf(pn+'/')==0 || 
				window.location.pathname == pn){
				var nc = cReplace?ocn+'This':ocn + ' '+ocn+'This';
				parnod.className=nc;
				parnod.setAttribute('oldClassName',nc);
			}else{
				parnod.setAttribute('oldClassName',ocn);
			}
		}else{
			parnod.setAttribute('oldClassName',ocn);
		}
	}
	gl_link_init = true;
}

function replaceImage(ob,s,c){
var ol="solid silver thick";
if(!glPictureViewerClicked){
	glPictureViewerClicked=MM_findObj('glPictureViewerFirst');
}
if(glPictureViewerClicked){
	ol=glPictureViewerClicked.style.outline;
	glPictureViewerClicked.style.outline="";
}
glPictureViewerClicked=ob;
ob.style.outline=ol;
var d = MM_findObj('divIPFIMG');
divFadeOut('divIPFIMG');
if(c){c='class="'+c+'"';}else{c='';}
glOnFadeOutVar = '<img '+c+' src="'+s+'"/>';
glOnFadeOut = 'replaceImageIn()';
var im = new Image;
im.src=s;
}

function replaceImageIn(){
var d = MM_findObj('divIPFIMG');
d.innerHTML = glOnFadeOutVar;
divFadeIn('divIPFIMG');
}

function setHVar(s,v){ var d = MM_findObj(s); if(d){d.value=v;}else{alert(s+' not found...');} }

function oshbSetP(pname,val){
	var p = MM_findObj(pname);
	if(p)p.value=val;
}

function oshbx(ob,div,p1,p2,p3,p4){
	if(gl_oshbx_disabled)return;
	oshbSetP('BSLHP1',p1);
	oshbSetP('BSLHP2',p2);
	oshbSetP('BSLHP3',p3);
	oshbSetP('BSLHP4',p4);
	CID='oshb';ajax6e(null,div,'S',ob);
}

function oshbxP(ob,div,pos,p1,p2,p3,p4){//Placed using pos
	if(gl_oshbx_disabled)return;
	oshbSetP('BSLHP1',p1);
	oshbSetP('BSLHP2',p2);
	oshbSetP('BSLHP3',p3);
	oshbSetP('BSLHP4',p4);
	CID='oshb';ajax6e(null,div,'S',ob,pos);
}

function showOb(s){
var d = MM_findObj(s);
if(d){d.className='visible';}
}
function hideOb(s){
var d = MM_findObj(s);
if(d){d.className='hidden';}
}
//Single click delayed handlers
function setDC(ob){
gl_delayed_click_ob = ob;
gl_delayed_click_to=window.setTimeout('dco()',400);
}
function clearDC(){
if(gl_delayed_click_to)window.clearTimeout(gl_delayed_click_to);
gl_delayed_click_to=false;
}
function dco(){
if(gl_delayed_click_ob)gl_delayed_click_ob.onclick();
}
//Double click delayed handlers
function setDDC(ob){
gl_delayed_dclick_ob = ob;
gl_delayed_dclick_to=window.setTimeout('ddco()',400);
}
function clearDDC(){
if(gl_delayed_dclick_to)window.clearTimeout(gl_delayed_dclick_to);
gl_delayed_dclick_to=false;
}
function ddco(){
if(gl_delayed_dclick_ob)gl_delayed_dclick_ob.ondblclick();
}

var theCurrRow=false;
function myAnalyseChoices(){
	var f = document.getElementById('divICHOICESD');
	var s = '';
	theCurrRow = 0;
	var theRows=false;
	if(f){
		f=getFirstTab(f);
		if(f){
			theCRows = f.rows;
			theCRowsCt = theCRows.length;
		}else{alert('Tab not found...');}
	}else{
		alert('not found');
	}
}

function myChoicesKD(e){

	var ek = window.event;
var ob;
	if(e==null)e=window.event;
	if(ek){
		ek = e.keyCode;
ob=e.srcElement;
	}else{
		ek = e.which;
ob=e.target;
	}
if((ek==46 || ek==8) && ob.value==''){return delLast();}
	var lastRow = theCurrRow;
	var thisChoices = document.getElementById('divICHOICESD');
	if(thisChoices){
		if((ek==13)||(ek==38)||(ek==40)){
			if(thisChoices==theLastChoices){}else{
				myAnalyseChoices();
theCurrRow = -1;
				theLastChoices = thisChoices;
			}
if(ek==8){delLast();e.returnValue = false;
e.cancelBubble = true;
if(e.stopPropagation)e.stopPropagation();
return false;
}
			if(theCRows){
				if(ek==13){
					try{theCRows[lastRow].cells[0].onclick();}catch(er){return;}
					try{if(ajx_procob.onchange)ajx_procob.onchange();}catch(erx){return;/* possible error in coding here */}
					e.returnValue = false;
					e.cancelBubble = true;
					if(e.stopPropagation)e.stopPropagation();
					return false;
				}

				if(ek==38){
					theCurrRow = theCurrRow-1;
				}
				if(ek==40){
					theCurrRow = theCurrRow+1;
				}
				if(theCurrRow>=theCRowsCt){
					theCurrRow=0;
				}
				if(theCurrRow<0){
					theCurrRow=theCRowsCt-1;
				}
				try{theCRows[lastRow].cells[0].onmouseout();}catch(er){}
				try{theCRows[theCurrRow].cells[0].onmouseover();}catch(er){}
			}
		}
	}
}

var dispDiv=null;
var dispInp=null;
function delLast(){var mt=dispInp.previousSibling;if(mt){encBtnCl(dispInp.previousSibling);}}

function myColF(s,n,hideList,remove,xob,oncl){
try{
var pnval = s.getElementsByTagName('abbr')[0].id;
var clname = s.getElementsByTagName('abbr')[1].id;
if(oncl){
	oncl(pnval,clname,false);
}else{
	myColF2(pnval,clname,false);
}
if(hideList){
	vlAlertCloseT();
}
return '';
}catch(er){alert(er);return '';}
}
function myColF2(pnval,clname,remove,s){
try{
if(dispDiv==null){dispDiv=document.getElementById("divIlistDiv");
var fc = dispDiv.firstChild;dispInp=fc;
dispDiv.setAttribute('onclick','dispInp.focus();');
dispDiv.style.minHeight='2px';
dispDiv.style.border='1px solid #ccc';
dispDiv.style.backgroundColor='#fff';dispDiv.style.border='1px solid #ccc';
fc.style.width='80px';
fc.style.height='20px';
fc.style.border='0';
fc.style.verticalAlign='1px';
var newdiv = document.createElement('div');
newdiv.setAttribute('id','listDiv');newdiv.setAttribute('style','display:inline-block;');dispDiv.insertBefore(newdiv,dispInp);}
var cob = document.getElementById("UTL_DEMO_UNL");
var cval = cob.value;
var nval = "'"+pnval+"'";
var cind = cval.indexOf(nval);
if(cind<0){
var lob = document.getElementById("divIlistDiv");
cob.value=cval+(cval.length==0?'':',')+nval;
encBtn(lob,pnval,clname,s);
}else{
if(remove){remove.parentNode.removeChild(remove);
cob.value=cval.substr(0,cind-(cind==0?0:1))+cval.substring(cind+nval.length+(cind==0?1:0));
}
dispInp.focus();
}
}catch(er){alert(er);return '';}
}
function encBtnCl(ob){myColF2(ob.id.substring(11),'',ob);document.getElementById("UTL_DEMO_CTL").focus();}

function encBtn(lob,id,nam,s){
var newdiv = document.createElement('div');
theLastToken=newdiv;
if(s){
newdiv.setAttribute('style','border:1px solid #ccc;display:inline-block;padding:0 2px 2px 2px;margin:0px 1px 1px 1px;height:37px;background-color:#f8f8f8;width:188px');
newdiv.setAttribute('id','listDivElem'+id);
newdiv.innerHTML = '<div style="float:right;width:16px"><img style="padding:2px 2px 0 0;margin-right:1px" src="'+global_app_path+'Assets/Images/close.gif" onclick="encBtnCl(this.parentNode.parentNode)" alt="Delete '+nam+'"></div><div>'+s.innerHTML + '</div>';
}else{
newdiv.setAttribute('style','border:1px solid #ccc;display:inline-block;padding:0 2px 0 0;margin:2px 1px 2px 1px;height:17px;background-color:#f8f8f8');
newdiv.setAttribute('id','listDivElem'+id);
newdiv.innerHTML = '<img style="padding:2px 2px 0 1px;margin-right:1px" src="'+global_app_path+'Assets/Images/close.gif" onclick="encBtnCl(this.parentNode)" alt="Delete '+nam+'"><span style="vertical-align: 2px;padding 0 2px 0 2px;font-size:11px;font-family:\'lucida grande\', tahoma, verdana, arial, sans-serif;">'+nam+'</span>';
}
lob.insertBefore(newdiv,dispInp);
}

function chooserClickF(ob,xob,oncl){
myColF(ob,0,1,false,xob,oncl);
ajx_procob.value='';
ajx_procob.focus();
}

function linkFunc(pnval,clname){
	window.location="/profilek/"+pnval.toLowerCase()+window.location.search;
}


