// Intrelate 4.3 Client-side library
// 220607 somerg
gLibVer="070622";
//window.onerror=merr;
// page inits
//
// 040301 somerg added to library from helpscript
// taking account of different doms
if (navigator.appName == "Netscape") {
	layerRef="document.layers";
	styleSwitch="";
  } else {
	layerRef="document.all";
	styleSwitch=".style";
  }

// 060605 keep references to children
var giWinIdx=0; 
var giWinRef=new Array();

// client side timeout globals
var giSessionTimeout; // Session Timeout
var giSessionWarn;
var giSessionTimeoutCounter;
var giInactivityTimeout; // client side timeout 
var giLockTimeout; // update lock timeout
var giIFState; // Interface state 0-initial 1-active 2-inactive 3-warning 4-timedout
var giIFInactiveTime; // how long interface inactive
var giIFIdleCounter; // how long interface has been loaded
var giIFTime; // how long interface has been loaded
var giDaemonInterval; // daemon timer interval
var gDaemonId; // handle for timer
var gbInDaemon=0; // flag to prevent re-entry
var giActivePeriod; // seconds before idle timer starts ticking
// end client side timeout globals

var giar0=0;// main len autorefresh timeout period
var giar=new Array([0,0],[0,0]);

var giwc=0; // flag set by cancel stream
var gidvm=0; // dev mode 256=DEVDEV

var gmx=0,gmy=0; // mouse
var gRCLa; // Right Click Menu Title
var gRCLidx;// Right Click Menu Target Id
var gRCLidx0; 
var gRCLidx1;
var gRCLsid=''; // visible one

var activeEl; // used for toolbar dragdrop
var bBailOut; // timeout for LUOD
var gTimerId;
var gBailOutId;

var gWinCmd; // for report after post (lids too long)
var gWinCmdU;
var gWinCmdN;
var gWinCmdF;

var gLUODsrcName; // globals for LUOD
var gLUODtrgName;
var gLUODcurVal;
var gLUODcurIdx;
var gLUODiT;
var gLUODcurDescr;

var lkeys; // key list in list view
var lids=new String(''); // id list in list view

// 130502 Check events for tools
var gTlChk=new Array(18)

var gikp=0; // flag for user key press - disables move focus

var goBrowser=new Browser();

var giflash=0; // 190307 used by progress bar timer
var giqm=0;
var giql=0;
var gipost=0; // 200307 flag when about to post
var giomm=0;

var lbX=0; // stores body height and width for onmousemove handler
var lbY=0;

var giblurtime=15; // blur warning time in secs
var giblurmode=0;
var grProgXY;

var gLUDynSourceNames;
var gLUDynTargNames;
var gLUDynTargLengths;
var gLUDynTargCurrVals;
var gLUDynTargCurrIdxs; // currently selected values
var gLUDynTargCurrDescs;
var gLUDynTypes;
var giLUDynRequestId=0;

var gibol=new Number(0);//050707 flag page loaded

var gsWaitEval=new String('');
var giWaitEvalTick=new Number(0);






window.onscroll = barUpdate;  // Activate the scroll handler.  Toolbar scrolls with window.
window.onunload=wou; //181104 close window handler ;



function wou(){ // window is closing
if(window.screenTop>10000){
var i=v('mWtp');
if(i&2){
 if(giwc==0){
  var o=window.opener;
  if(o!=null){
   o.sbc('f5','')
   }
 } 
}else{
 var o=window.opener; // test to see if top level 
 if(o==null){
  wnclC();// close any children !!
  window.open('home.asp?mOp=1998','','left=10000');
 }
}
}} // end if window closed / end function

function wnclC(){//close children
if(giWinIdx>0){
 for(i=0;i<giWinIdx;i++){
  try{giWinRef[i].close();}catch(e){};
}}}


function wncl2(i) {
	giwc=1; // suppress event handler;
	if (i&2) {
		var opnr = window.opener;
		if (opnr!=null) {
			opnr.sbc('f5','');
		}
	}
//var winme=document.parentWindow;
//winme.close();
window.close();
// return false; 
// 110506 cancel needs true !!
return true;
}




function gdocm(){
 // alert('window context menu handler');
 window.event.returnValue=false;
 }

//document.oncontextmenu=gdocm;

// 221003 globals for submit handler
var gSBCb;
var gSBCc;
var gSBCk;
var gSBCs;

// 020304 globals for autorefresh
var gtIDar;




// 
// END Page Inits


//060704 calendar functions
function clndrdcl(i){ // day click in month
var a='cl_d'+i;
var ody=o(a);
//alert(a);
if (ody!=null) {
 ss=ody.className;
 var aa=new String(ss);
 arr=aa.split('_');
 if(arr.length>1){ // already selected
  ody.className=arr[0];
 } else {
  ody.className=ss+'_s';
 }
} else {
alert(a + ' not an object');
} // end if an object
} //end function

// end calendar functions

//140604 popup window closer for questionnaire
function wncl(i,b){
// close window if b then refresh opener
var winme=document.parentWindow;
// 270208 why ? b=false;
if(b){
 try{
 var opnr=window.opener;
 if(opnr!=null){
  opnr.sbc('f5','');
  }
  }catch(e){};
 }
// 240804 window.close
winme.close();
return false; 
}

// 030604 tow support
function towcl(a) { // click on cell
//alert('clicked on cell ' + a);
var aa=new String(a);
arr=aa.split('_');
if(arr.length>1){
 r=arr[1];
 c=arr[2];
 nm=arr[0];
 var idx=towk(nm);
 // alert('row '+r+' col'+c);
 if((r==0)&&(c==0)) {
  towsa(nm,idx);
 } else {
  if(r==0){
   towsc(c,nm,idx);
  } else {
   if(c==0){
    towsr(r,nm,idx);
   } else {
    tows1(r,c,nm,a,idx);
   }   
  }
 } 
}}
function towsa(nm,idx){ // set all
for(j=1;j<8;j++) {
 towsr(j,nm,idx);
}}
function towsc(c,nm,idx){ // set col
for(i=1;i<8;i++) {
 a=nm+'_'+i+'_'+c;
 tows1(i,c,nm,a,idx);
}}
function towsr(r,nm,idx){ // set row
for(i=1;i<25;i++) {
 a=nm+'_'+r+'_'+i;
 tows1(r,i,nm,a,idx);
}}
function tows1(r,c,nm,a,idx){ // set cell
var ocl=o(a);
if (ocl!=null) {
 var abg=nm+'_radkybg_'+idx;
 var obg=o(abg);
 if(obg!=null){
  ocl.className=obg.className;
  idp=((r-1)*24)+(c*1);
  var vl=new String ;
  vl=v(nm);
  if(vl!=null){
   if(idp>1){nv1=vl.substring(0,idp-1)}else{nv1=''};
   nv2=''+idx;
   if(idp<168){nv3=vl.substring(idp,168)}else{nv3=''};
   vl='';
   vl=vl.concat(nv1,nv2,nv3);
   oUpd=o(nm);
   if(oUpd!=null){oUpd.value=vl}else{alert(nm+' not an object')}
  }  else {alert('vl not an object')} // vl not null
 }  else {alert(abg+' not an object')} // obg is an object
} else {alert('ocl not an object')} // ocl is an object
} // end function
function towk(nm){ // get current key
var b=0;
var i=0;
var imx=16;
var ard=nm+'_rad';
var oColl=document.all(ard);
while((b==0)&&(i<imx)){
 var ord=oColl[i];
 if(ord!=null){
  if(ord.checked){b=1}else{i++}
 }else{i++}
}
return i
}
// end tow support

function loch(i) { // 150903 list edit change detected
// alert('data changed');
var a="L"+i+"C";
oedt=o(a);
if(oedt!=null){oedt.value=1} else {alert('no object ' + a)};
var a="LAC";
oedt=o(a);
if(oedt!=null){oedt.value=1};
SetTl(0,'Y');
SetTl(1,'Y');
SetTl(2,'Y'); //120505
return true;
} // end function


function soch(o,iCtl,iCount){ // 100106 search field hide/show appropriate div
	if (o!=null) {
		var s=o.value;
		var vis;
		var sL='d'+iCtl+'s'+s;
		// iCount has count of divs 
		// hide all except s
		for (i=0;i<=iCount;i++) {
			sL='d'+iCtl+'s'+i;
			var o2=document.getElementById(sL);
			if (o2!=null) {
				if (i==s) {vis='inline';} else {vis='none';}
				o2.style.display = vis;
			}
		}
	}
}


function chkLength(sN,lmax){//130707 enforce MaxLength on TextAreas
try{
 if(document.forms[0].elements[sN].value.length>lmax){
  document.forms[0].elements[sN].value=document.forms[0].elements[sN].value.substring(0,lmax)
 } 
}catch(e){};
}

function doWin3dl(sUin,sN,sF,chk,msg,x,iFurl,e){ // 100204 version for downloading !!
// kernel function no longer uses window.open directly
// 100505 need to check for very long URL
//alert(sUin);
if(eval(chk)){
 var sU;
 var sUChk = new String;
 sUChk=sUin;
 // alert(sUChk);
 var lenSU=sUChk.length;
 if (lenSU>=2048){ // 2048
  // alert('overflow');
  DoWin3Post(sUin,sN,sF,chk,msg,x,iFurl);
 }else{
  sU=sUin;
 if (x=='x'){
  alert('openwindow :'+sU);
  window.open(sU,sN,sF)
 } else {
  window.location = sU;
 }; // end if x
}
} else {
 alert(msg);
} //end if 
} //end function

function doWin3frm(sUin,sN,sF,chk,msg,x,iFurl,sCtl1){ // 090507 pass input
var a=v(sCtl1);
var sU='';
if(a!=null){sU=sUin+'&'+sCtl1+'='+encodeURI(a);}else{sU=sUin};
doWin3(sU,sN,sF,chk,msg,x,iFurl)
}

function doWin3(sUin,sN,sF,chk,msg,x,iFurl,e){ // 180703 main window opener
	// kernel function no longer uses window.open directly

	//sF='height=300,left=100,location=0,menubar=0,resizable=1,status=1,toolbar=0,top=100,width=300'
	// dont need to turn things off !
	//alert(sU);
	// 020507 need scrollbar on fk finder if (x=='z'){sF='height=100,left='+gmx+',resizable=1,status=0,top='+gmy+',width=100'};
	// 020507 frig for fk demo
	//if (x=='z'){sF='height=100,left='+gmx+',resizable=1,status=0,top='+gmy+',width=100,scrollbars=1'};

	var evt = window.event ? window.event : e;
	
	doWinX = evt.clientX;
	doWinY = evt.clientY;
	
	if (x=='z'){sF='height=100,left='+doWinX+',resizable=1,status=0,top='+(doWinY-100)+',width=100,scrollbars=1'};

	if (eval(chk)) {
		if (gidvm==256) { document.title=sUin; }
		var sU;
		var sUChk = new String;
		sUChk = sUin;
		var lenSU = sUChk.length;
		if (lenSU>=2048) { // 2048
			DoWin3Post(sUin,sN,sF,chk,msg,'x',iFurl);
		} else { 
			// 060605 window.open(sUin,sN,sF)
			giWinRef[giWinIdx] = window.open(sUin,sN,sF);
			giWinIdx = giWinIdx+1;
		}
	} else {
		alert(msg);
	} //end if 
	if (window.event) { evt.cancelBubble = true; } else { evt.stopPropagation(); }
} //end function

// 110505 post ids if URL too large !
function DoWin3Post(sUChk,sN,sF,chk,msg,x,iFurl){ 

// Setup gWinCmd
var idstart=sUChk.indexOf('ID=');
// var idlist=new String;
sU=sUChk.substr(0,idstart);
// in lids ! idlist=sUChk.substr(idstart+3);
sU=sU+'ID=@LIDLIST';
if (x=='x'){gWinCmd='o'} else {gWinCmd='n'};
gWinCmdU=sU;
gWinCmdN=sN;
gWinCmdF=sF;
//load the form into the iframe
var iFrameWin;
iFrameWin = window.frames.hidden;
//alert(iFurl);
iFrameWin.location.replace(iFurl);
// setup the failure timer
bBailOut=0;
var tOutms=9000; // 9 secs 
gBailOutId=setTimeout('bailOut()',tOutms);
// setup the form fill in an interval timer
gTimerId=setInterval('FillForm()',400); // try every half second
}

function FillForm() { // if the form has arrived fill it out and submit
if (bBailOut==1) { // timed out
 clearInterval(gTimerId);
 // alert('timed out');
 window.status='Problem retrieving system form';
} else {
//alert('looking at ' + gLUODsrcName);
var srcEl = window.frames.hidden.document.body; // all(gLUODsrcName); 
 // window.status=window.status+'.';
 if (srcEl!=null) {
  var s=srcEl.readyState;
  //  alert (s);
  if (s=='complete') {
   clearTimeout(gBailOutId);
   clearInterval(gTimerId);
   //alert('now fill out form');
   window.frames.hidden.document.all.mSetEnvName.value='LIDLIST';
   window.frames.hidden.document.all.mSetEnvVal.value=lids;
   //alert('goodtogo');
   window.frames.hidden.document.forms(0).submit();
   // setup the failure timer
   bBailOut=0;
   var tOutms=9000; // 9 secs 
   gBailOutId=setTimeout('bailOut()',tOutms);
   // setup the window call in an interval timer
   gTimerId=setInterval('DoWin3AfterPost()',400); // try every half second
  }; // End if (complete)
 }; // End If (object)
}; // End If (bailout)
} // End Function


function DoWin3AfterPost() { // if the post is successfult then do the report
if (bBailOut==1) { // timed out
 clearInterval(gTimerId);
 // alert('timed out');
 window.status='Problem posting system form';
} else {
var srcEl = window.frames.hidden.document.body;
 if (srcEl!=null) {
  var s=srcEl.readyState;
  if (s=='complete') {
   clearTimeout(gBailOutId);
   clearInterval(gTimerId);
   if(gWinCmd=='o'){
    window.open(gWinCmdU,gWinCmdN,gWinCmdF);
   }else{
    window.location = gWinCmdU;
   }
  }; // End if (complete)
 }; // End If (object)
}; // End If (bailout)
} // End Function


function isb(a){if(a==''){return true} else {return false}};
function nisb(a){if(a==''){return false} else {return true}};

function nisb2(a){if(a==''){alert('Nothing Selected');return false} else {return true}};

function nisb2df(a){
if(a==''){
 alert('Nothing Selected');
 return false;
} else {
 var ss=new String(a);
 var s=ss.split(',');
 var j=s.length;
 if(j==1){
  var sMsg='Click OK to Delete file or Cancel to Cancel Deletion';
 }else{
  var sMsg='Click OK to Delete ' + j + ' files or Cancel to Cancel Deletion';
 }
 var confirm=window.confirm(sMsg);
 if (confirm){
  return true ;
 }else{
  return false;
 }
}
}

function chklidi(){ //major change 181206
lisethead(0);
liresize(0,0);
} //end function

function lisethead(l){ //131206 set column heading widths
// li0cc0->li0hc0 li0cc1->li0hc1
// li0c0..n -> li0h0..n
var i=0;
var a='li0c0';
var o=document.getElementById(a);
while(o!=null){
 var ha='li0h'+i;
 var ho=document.getElementById(ha);
 if(ho!=null){
  var w=o.clientWidth;
  var hw=ho.clientWidth;
  //alert('w='+w+' hw='+hw);
  if(w>hw){ho.style.width=w-10}else{o.style.width=hw-10}; // cellpadding
//  if(w>hw){ho.style.width=w}else{o.style.width=hw}; // cellpadding
  //alert('w='+o.clientWidth+' hw='+ho.clientWidth);
  } 
 i=i+1;
 a='li0c'+i;
 var o=document.getElementById(a);
}
var i=0;
var a='li0cc0';
var o=document.getElementById(a);
while((o!=null) && (i<2)){// might be cc1 but no cc0 !
 var ha='li0hc'+i;
 var ho=document.getElementById(ha);
 if(ho!=null){
  var w=o.clientWidth;
  var hw=ho.clientWidth;
  //alert('w='+w+' hw='+hw);
  if(w>hw){ho.style.width=w-10}else{o.style.width=hw-10}; // cellpadding
  //alert('w='+o.clientWidth+' hw='+ho.clientWidth);
  } ;
 i=i+1;
 a='li0cc'+i;
 var o=document.getElementById(a);
}

}

function liresize(l,ic){//181206 fit to window
// ic=0 from chklidi ic=1 when lh2
// 
if(ic==1){
 var od=document.getElementById('lidi');
 // PROBLEM - DIV does not report its height !! alert(od.clientHeight);
 //  unless its been set !
 //alert(od.clientHeight+' '+od.scrollHeight);
 if(od!=null){
  if(od.scrollHeight>od.clientHeight){
   //alert(' document.documentElement.clientHeight='+document.documentElement.clientHeight+' document.documentElement.scrollHeight='+document.documentElement.scrollHeight)
   od.style.height=od.scrollHeight;
   //alert(' document.documentElement.clientHeight='+document.documentElement.clientHeight+' document.documentElement.scrollHeight='+document.documentElement.scrollHeight)
  }
 }
}
var a='lid0';
var o=document.getElementById(a);
if(o!=null){
var h=o.clientHeight;
//var o=document.getElementById('w');
//alert(o.clientHeight);
//o.style.height=800;
// BackCompat for no doctype CSS1Compat for doctype loose
var s =new String(document.compatMode);
var j=s.indexOf('CSS');
if(j>=0){ // dtd 
 var lclh=document.documentElement.clientHeight; // window height
 var ldch=document.documentElement.scrollHeight; // doc height
}else{ // no dtd
 var lclh=document.body.clientHeight; // window height
 var ldch=document.body.scrollHeight; // doc height
}
//alert(h+' '+document.compatMode+' screenTop='+window.screenTop+'screenHeight='+window.screen.availHeight+'scrollHeight='+document.body.scrollHeight+' clientHeight='+document.body.clientHeight+' offsetHeight='+document.body.offsetHeight+' offsetTop='+document.body.offsetTop)
if(ldch>lclh){bv=true}else{bv=false};
//alert(s+' '+lclh+' '+ldch+' '+bv);
var lresize=0;
if(bv){
 lresize=ldch-lclh;
 var lh=h-lresize+2; // +2 because DIV is container 
 var od=document.getElementById('lidi');
 // PROBLEM - DIV does not report its height !! alert(od.clientHeight);
 //alert('resize by '+lresize+' new height is '+lh);
 if(lh<100){lh=100};
 if(od!=null){od.style.height=lh}// not there when <8 items else{alert('no object')};
// if(od!=null){od.style.height=lh}else{alert('no object')};
}
}
}// end function


//060203 update state for display rules
function ust(i,st){
//alert('ust on '+i+' to '+st);
Lb='l'+i+'s';
Dt='d'+i+'s';
sL=Lb+'1';
var sVisOff='none';
var sVisOn='inline';
// test if sL exists
var o=document.getElementById(sL);
if (o!=null) {
//alert('found '+sL+' st='+st);
if (st==1) {vis=sVisOn} else {vis=sVisOff};
//eval(layerRef+'["'+sL+'"]'+styleSwitch+'.display="' + vis + '"');
try{document.getElementById(sL).style.display=vis}catch(ierr){};
sL=Lb+'2';
if (st==2) {vis=sVisOn} else {vis=sVisOff};
//eval(layerRef+'["'+sL+'"]'+styleSwitch+'.display="' + vis + '"');
try{document.getElementById(sL).style.display=vis}catch(ierr){};
sL=Lb+'4';
if (st==4) {vis=sVisOn} else {vis=sVisOff};
//eval(layerRef+'["'+sL+'"]'+styleSwitch+'.display="' + vis + '"');
try{document.getElementById(sL).style.display=vis}catch(ierr){};
}//else{alert('didnt find '+sL)} // o test
sL=Dt+'1';
var o=document.getElementById(sL);
if (o!=null) {
var o=document.getElementById(sL);
if (st==1) {vis=sVisOn} else {vis=sVisOff};
//eval(layerRef+'["'+sL+'"]'+styleSwitch+'.display="' + vis + '"');
try{document.getElementById(sL).style.display=vis}catch(ierr){};
sL=Dt+'2';
if (st==2) {vis=sVisOn} else {vis=sVisOff};
//eval(layerRef+'["'+sL+'"]'+styleSwitch+'.display="' + vis + '"');
try{document.getElementById(sL).style.display=vis}catch(ierr){};
sL=Dt+'4';
if (st==4) {vis=sVisOn} else {vis=sVisOff};
//eval(layerRef+'["'+sL+'"]'+styleSwitch+'.display="' + vis + '"');
try{document.getElementById(sL).style.display=vis}catch(ierr){};

// 080604 update form control string
// i is index position (0-based)
 try{
  var sa=v('mA');
  var nm='mFC'+sa;
  var vl=new String ;
  vl=v(nm);
  ln=vl.length;
  if(vl!=null){
   j=i+1;
   if(j>1){nv1=vl.substring(0,j-1)}else{nv1=''};
   nv2=''+st;
   if(j<ln){nv3=vl.substring(j,ln)}else{nv3=''};
   vl='';
   vl=vl.concat(nv1,nv2,nv3);
   // alert(vl);
   //oUpd=document.all(nm);
   //var oUpd=document.getElementById(nm);
   // alert('got oUpd');
   //if(oUpd!=null){oUpd.value=vl}else{alert(nm+' not an object')}
   setFormElementValue(nm,vl);//100707 html4
  } //else {alert(nm+' not a control');};
 }catch(e){}; //alert(e.message)
}//else {alert(sL+ 'not found');} // o test
} // end function

function uFC(iRef,iVal,iLayer){//180707
// update Form control String
// iRef : field reference eg 5 for E5
// iVal : 4=will be 
 try{
  var sa=v('mA');
  var nm='mFC'+iLayer;
  var vl=new String ;
  vl=v(nm);
  ln=vl.length;
  if(vl!=null){
   j=iRef+1;
   if(j>1){nv1=vl.substring(0,j-1)}else{nv1=''};
   nv2=''+iVal;
   if(j<ln){nv3=vl.substring(j,ln)}else{nv3=''};
   vl='';
   vl=vl.concat(nv1,nv2,nv3);
   setFormElementValue(nm,vl);//100707 html4
  } //else {alert(nm+' not a control');};
 }catch(e){}; //alert(e.message)
}

function vo(n) { // value from name
// html4 try{ret=document.forms[0].elements[s].value;}catch(ierr){};
// 100707 only used by display rules - TD required ?
//o=document.all[n];
//if (o!=null){
// if(o.tagName=='TD'){
//  r=o.innerText;
//  } else {
//   if(o.type=='checkbox'){
//    if(o.checked){r=0}else{r=1}; // wrong way round - using mouseup !!!!!
//   } else { 
//    r = o.value ;
//   } 
//  } 
//} else {
// r=null;
//} // end if found
//return r ;
//try{var ret=document.forms[0].elements[n].value;}catch(ierr){var ret=null};
try{var o=document.forms[0].elements[n];}catch(e){var o=null};
if (o!=null){
 if(o.tagName=='TD'){
  r=o.innerText;
  } else {
   if(o.type=='checkbox'){
    if(o.checked){r=0}else{r=1}; // wrong way round - using mouseup !!!!!
   } else { 
    r = o.value ;
   } 
  } 
} else {
 r=null;
} // end if found
return r ;
}

//250406 multipick support - Set/Clear All options
function mp0All(i,gsPre){
//alert(i);
// edit field id gpa+i 
// id value id gp+i+-j-i
// chk id gp+i-j  first is gp3
// coll name is gpnm+i
// if edit field is blank then set all otherwise clear all
var sFld=gsPre+'gpa'+i;
var sFldData=v(sFld);
//alert(sFldData);
if((sFldData=='')||(sFldData==null)){
// alert('set all');
 bSetAll=true;
}else{
// alert('Clear all'); 
 bSetAll=false;
}
var coll=gsPre+'cnt-'+i
var ocoll=oAll(coll);
if (ocoll!=null){
// alert('found collection '+ocoll.length);
 var newvals='';
 for (i2=0;i2<ocoll.length;i2++) {
  if (ocoll[i2].type=='checkbox'){
   ocoll[i2].checked=bSetAll;
   if(bSetAll){
    ky=ocoll[i2].id+'i';
    //alert(ky);
    oky=o(ky);
    if (oky!=null){
     if(newvals!=''){newvals=newvals+','};  
     newvals=newvals+oky.value;
 //     } else { alert('oky null with key='+ky);
    }
   } // bSetAll
  } //end if
 }//next 
//  alert('new value = '+newvals);
  edt=gsPre+'gpa'+i;
  oedt=o(edt);
  if(oedt!=null){
   oedt.value=newvals;
  }else{
 //  alert('edit field not found '+edt);
  }
}//ocoll ok 
}


//270603 multipick support
function mp0(i,j,gsPre,iPT){
//150507 iPT Picker Type to support Single Pick
//alert(i+','+j);
// edit field id gpa+i
// id value id gp+i+-j-i
// chk id gp+i-j
// coll name is gpnm+i
var ky=gsPre+'gp'+i+'-'+j+'i';
var sChkName=gsPre+'gp'+i+'-'+j;
//alert(ky);
var oky=o(ky);
if (oky!=null){
// alert('found key');
// alert(oky.value);
if(iPT==1){//singlepick
 var newvals=oky.value;
}else{
 var newvals='';
}
 var coll=gsPre+'cnt-'+i
 var ocoll=oAll(coll);
 if (ocoll!=null){
 //  alert('found collection '+ocoll.length);
  for (i2=0;i2<ocoll.length;i2++) {
   if (ocoll[i2].type=='checkbox'){
    if (ocoll[i2].checked){
     if(iPT==1){//singlepick so clear all the others    
      //alert(sChkName+' '+ocoll[i2].id);
      if (ocoll[i2].id!=sChkName){ocoll[i2].checked = false};
     }else{
      ky=ocoll[i2].id+'i';
      //alert(ky);
      oky=o(ky);
      if (oky!=null){
       if(newvals!=''){newvals=newvals+','};  
       newvals=newvals+oky.value;
      // } else { alert('oky null with key='+ky);
      }
     }//iPT==1
    } //checked
   } //end if checkbox
  }//next 
 // } else {alert('ocoll is null');
 }//ocoll ok 

  //alert('new value = '+newvals);
  edt=gsPre+'gpa'+i;
  oedt=o(edt);
  if(oedt!=null){
   oedt.value=newvals;
  }else{
   //alert('edit field not found '+edt);
  }
//} else {alert('oky is null'); 
}//oky ok 
}

// 201206 id=container now lid0
//   and lcall in lit0
// 171204 pass ia as level
//061202 list checkbox handler
function lc(id,ix,ia) {
if (id=='lcall') { // its the title
 var ochk=o('lcall');
 var tf=ochk.checked; 
 var oColl=oAll('lid0');
 for (i=0;i<oColl.length;i++) {
  if (oColl[i].type=='checkbox'){
   var a=new String(oColl[i].name);
   aa=a.substring(0,2);
   if (aa=='lc') {oColl[i].checked=tf}
  } //end if
 } //next
 if (tf) {
  //oColl.lck.value='All'; // lck no longer in the table !!
  setFormElementValue('lck','All');
  lkeys='All';newidx='All';
  } else {
  // oColl.lck.value='None';
  setFormElementValue('lck','None');
  lkeys='None';newidx='None';
 };
} else { // its one of the list items
 var ochk=o(id);
 var tf=ochk.checked;
 if (tf) { // add this to the list
  var a=new String(id);
  var al=a.length;
  aa=a.substring(2,al);
  //var idx=v('lck');
  var idx=getFormElementValue('lck');
   if (idx=='' || idx=='None' || idx=='All' || idx=='Empty') {
    newidx=aa ;
   } else {
    newidx=idx + ',' + aa ;
   } // end if 
 } else { // rebuild list to remove
  var newidx='';
  var oColl=oAll('lid0');
  for (i=0;i<oColl.length;i++) {
   if (oColl[i].type=='checkbox'){
    var a=new String(oColl[i].name);
    aa=a.substring(0,2);
    if (aa=='lc') {
     if (oColl[i].checked) {
      var al=a.length;
      ky=a.substring(2,al);
      if (newidx!='') {newidx=newidx+","};
      newidx=newidx+ky;
     } // checked
    } // lc
   } //end if checkbox
  } //next
  //oColl.lck.value=newidx;
  setFormElementValue('lck',newidx);
  lkeys=newidx;
 } // end if checked
 if (newidx==''){newidx='None'};  
 // var oColl=oAll('lid0');
 //oColl.lck.value=newidx;
 setFormElementValue('lck',newidx);
 lkeys=newidx;
} //end if title
var i=ia; // 171204
if (i==null){i=0};
//alert(newidx);
if (ix==1){ // just use index (file folder)
 lids=newidx
} else { 
lids=lckeys(i,newidx);
}
}

function lckeys(iL,idxs) {
var idxexpr=new String(idxs);
var sout=new String('');
if (idxexpr=='' || idxexpr=='None' || idxexpr=='Empty') {
 //alert('no keys');
 sout='';
} else { 
 if (idxexpr=='All') {
  var a='mK'+iL;
  var aa=v(a);
  var a=new String(aa);
  keyarr=a.split(';');
  keycount=keyarr.length;
  //alert('keycount='+keycount);
  for (i=0;i<keycount;++i) {
   if (sout!='') {sout=sout+','};
   //alert(keyarr[i]);
   sout=sout+keyarr[i];
  } // next
 } else { 
  var idxarr=idxexpr.split(',');
  idxcount=idxarr.length;
  //alert('idxcount='+idxcount);
 
  var a='mK'+iL;
  var aa=v(a);
  var a=new String(aa);
  keyarr=a.split(';');
  keycount=keyarr.length;
  //alert('keycount='+keycount);
  for (i=0;i<idxcount;++i) {
   j=idxarr[i]; // position in key array
   if (j<=keycount) {
    if (sout!='') {sout=sout+','};
    //alert(keyarr[j]);
    sout=sout+keyarr[j];
   } else {
    //alert('problem');
   } // end if keycount
  } // next

 } // end if idxexpr All
} // end if Empty or None
// alert (sout);
return sout ;
} // end function

// 130502 global submit handler
function sbc(cmd,chk,smt,smcq,chkMsg) { // submit command
	var confirm=true;
	var im=v('mM');
	var iop=v('mOp');
	var ich=v('LAC'); // 120505 change detection in edit in list
	// if (ich=='1'){alert('mode '+im);};
	if ((im==2) || ((im==1) && (iop<7000)) ||(im==17 && ich=='1') && (iop!=2002)) { // editing/adding (not q)
		if ((cmd!='ok') && (cmd!='Save') && (cmd!='Cancel') && (cmd!='EditX') && (cmd!='ok_Add') && (cmd!='ok_Edit')) {
			confirm=window.confirm("Save Changes ?");
			if (confirm) {
				cmd='ok';smt='';
				var a=new String(chk);
				if(a.substring(0,4)=='seta'){chk=''};
			}
		} // end if cmd 
	} // end if im

	if (cmd=='EditX') {
		var ich=v('LAC');
		if (ich=='1') {
			confirm=window.confirm("Save Changes ?");
			if (confirm) { cmd='ok'; smt=''; } else { confirm=true; cmd='Cancel'; smt=''; }
		}
	}
	
	if (confirm) {
		// 120505  if (true) { 
		var bChk=true;
		if (chk!=null) {
			if (chk!='') {
				bChk=eval(chk);
			} // end if (chk!='')
		} // end if (chk!=null)


		if (bChk) {
			if (cmd=='t') { // task post
				setFormElementValue('mT',smt);
				try { setFormElementValue('mCQ',lids); } catch(e){};// 310308 pass lids for Edit Wizard
			} else { // command post
				setFormElementValue('mC',cmd);
				if (smt!='') { setFormElementValue('mCP',smt); }
				if (smcq!='') {setFormElementValue('mCQ',smcq); }
			} // end if (cmd=='t')
			
			if (gSBCb) {
				if ((gSBCc==cmd) && (gSBCk==chk) && (gSBCs==smt)) {
					// alert('the request is already in progress');
				} else {
					confirm=window.confirm('Cancel the current request?');
					if (confirm) {
						gSBCb=true;
						gSBCc=cmd;
						gSBCk=chk;
						gSBCs=smt;
						ifprops();
						giPost=1;
						try { document.forms[0].fireEvent('onsubmit'); } catch(ierr){};
						document.forms[0].submit();
					}
				}
			} else {
				document.body.style.cursor='wait';
				gSBCb=true;
				gSBCc=cmd;
				gSBCk=chk;
				gSBCs=smt;
				ifprops();
				gipost=1;
				try { document.forms[0].fireEvent('onsubmit'); } catch(ierr){};
				document.forms[0].submit();
			}
		} else { // 050406 support validation message
			if (chkMsg!='') { if (chkMsg!=null) { alert(chkMsg); } } 
		} // end if (bChk)
	} // end if confirm
	return false;
} // end function

// 080904
function ifprops(){
var ifcW=cBodyValCW();//document.body.clientWidth;
setFormElementValue('m2',ifcW);//document.all.m2.value=ifcW;
return true;
}
function bInEdit(){// 260606 edit check (from sbc())
var im=v('mM');
var iop=v('mOp');
var ich=v('LAC'); // 120505 change detection in edit in list
if ((im==2) || ((im==1) && (iop<7000)) ||(im==17 && ich=='1')) { // editing/adding (not q)
 return true
}else{
 return false 
}}

function gobk(i,x){ //260606 breadcrumbs go back with edit check
// i is how many, x is 1 for devdev
if(bInEdit()){
 b=window.confirm("Save Changes ?");
 if (b){sbc('ok','')};
}else{
 if(x==1){
  alert('Go back '+i);
 }else{
  history.go(i);
 }
}
return false;
}

// 200502 set layer and return true
function seta(i) {
setFormElementValue('mA',i);
return true;
}

// 210304 bitmask support
function upDbm(el, fieldno) {
var hidden='E'+fieldno;
if (eval( 'document.all.'+hidden )) {
  targ = eval( 'document.all.'+hidden );  
  vl=Math.pow(2,(el.value));
  if(el.checked){
  targ.value=targ.value | (vl);
//   alert(targ.value);   
  }else{
   targ.value=targ.value & ~ (vl);
  }
}else { 
  return false; /*failed to find target hidden field*/ 
} // endif
} // end function


// 270402 option group support
function upD(el, fieldno) {
var hidden='E'+fieldno;
//if (eval( 'document.all.'+hidden )) {
//  targ = eval( 'document.all.'+hidden );  
//  targ.value = el.value;  
//}else { 
//  return false; /*failed to find target hidden field*/ 
//} // endif
try{sFE(hidden,(el.value))}catch(e){return false}
} // end function

function cbRad(box) {
var boxGroup = box.form[box.name];
for (var i = 0; i < boxGroup.length; i++)
 if (boxGroup[i] != box)   boxGroup[i].checked = false;
 return box.checked;
} // end function

// 110102 somerg. Gp key handler
function bkp(e) {
setIFActive(); //030605 for timeout
gikp=1;
var i=e.keyCode;
var iM=v('mM');
if (iM=='2') iM='1';
if (iM=='3') iM='1';
var iOp=v('mOp');
if (iOp=='5011') iM='1';
var sCmd='Save';
if (iOp=='7011') sCmd='f5';
if (iOp=='2002') sCmd='Login';//310108
var b=true;
//alert('mode is ' + iM);
//alert('you pressed '+ i);
switch (i) {
 case 13 :
  switch (iM) {
   case '1': 
    var sT = e.srcElement ? e.srcElement.tagName : e.target.tagName;
    if (sT=='INPUT') {
     // if editinlist move focus away from control to allow on change detection 
     if (iOp='5011'){
      var osrc = e.srcElement ? e.srcElement : e.target;
      var a=new String(osrc.name);
      // alert(osrc.name);
      if(a.charAt(0)=='L'){
       var j=a.indexOf('F');
       var i=a.substring(1,j);
       var aa='L'+i+'C';
       // alert(aa);
       oedt=o(aa);
       if(oedt!=null){oedt.value=1} ; //else {alert('no object ' + a)};
      } // charat
     };
     setFormElementValue('mC',sCmd);//200106'Save';
     //document.all.f0.fireEvent('onsubmit');
     document.forms["f0"].submit();
     e.keyCode=null;
    }
    break;
   default:
  //  alert('default return');
//    e.keyCode=null;
    break;
  } // switch iM
  break;
 case 27 :
  switch (iM) {
   case '1': 
    e.keyCode=null;
    var sT=e.srcElement.tagName;
    if (sT=='INPUT') {
     history.go(-1);
    }
    break;
   default:
    e.keyCode=null;
    break;
  } // switch iM

} // switch i
}// End Function




// somerg 040505 iType 5 - key entry
// somerg 101201 Support FKFinder
function pickFK(sCode,sDescr,sControl,iType,lRow,iMode) {
// 060707 iMode=1 if blank dont set
//var ctl=window.opener.document.getElementById(sControl);
var oopener=window.opener;
if (oopener!=null){
 var ctl=oopener.document.getElementById(sControl);
 if (ctl!=null) {
  if ((iType==5)||(iType=='5')) { // key entry box
   ctl.value=sCode;
   //alert(sCode);
   // 030507 check for format string
   var s=getFormElementValue('mPkMP');
   var iParentIdx=new Number(getFormElementValue('mPkE'));// En on parent
   var ss=new String(s);
   //alert('ss='+ss);
   if(ss!=''){//170907 j is 1 when s is empty !
   var sTerms=ss.split(';');
   j=sTerms.length;
   if(j>0){
    var sOutMap=new String(sTerms[0]);
    var OutMaps=sOutMap.split(',');
    for(j=0;j<OutMaps.length;++j){
     var sMap=new String(OutMaps[j]);
     var sMapItems=sMap.split(':');
     if (sMapItems.length>0){    
      var iToField=new Number(sMapItems[0]);// Offset relative to picker form pos
      var iFromCol=new Number(sMapItems[1]-1);// Column number
      var sFromId='li'+lRow+'c'+iFromCol;
      //alert(sFromId);
      var sItemValue=getElementInnerText(sFromId);
      if((iMode==0)||((iMode==1)&&(sItemValue!=''))){ 
 //120707 patch for Close Window issue     if((iMode==0)||((iMode==1)&&(1==0))){ 
       var iToIdx=new Number(iParentIdx+iToField);
       var sToName="E"+iToIdx;
       //alert(sFromId+' '+sItemValue+' -> ' + sToName);
       try{oopener.document.forms[0].elements[sToName].value=sItemValue;}catch(ierr){};
       try{
        if(oopener.document.forms[0].elements[sToName].onchange!=null){
         oopener.document.forms[0].elements[sToName].fireEvent('onchange');
        }
       }catch(ierr){};
      } // end if mode or value
     } // end if items
    } //next
   } // end if j>0
   } else {
    try{ if(ctl.onchange!=null){ ctl.fireEvent('onchange'); } 
    }catch(ierr){};
   } // end if s not blank
  } else {
   addOption(ctl,sCode,sDescr,1); // } else {alert('control-'+sControl+'-not found');
  } // end if iType==5
 } // End if //ctl !=null
} else { // oopener!=null
//  alert('no opener: code='+sCode+' descr='+sDescr+' for '+sControl);
} // end if
} // End Function

function addOption(o,sC,sD,bSel) {
// add an option to a dropdown and optionally make it current
// valid object ref assumed
// alert('add option -'+sC+'-'+sD);
var opt=window.opener.document.createElement("<OPTION value='"+sC+"'>");
o.options.add(opt);
if(sD==null){sD=sC};
if(sD==''){sD=sC};
opt.innerText = sD;
if (bSel) {o.selectedIndex = (o.options.length-1)};
// 281103 fire the onchange event
o.fireEvent("onchange");
} // end function

function doWin2 (xx,strURL, strWin,evt, width, height, x, y) {
		var getx = document.layers ? window.screenX + evt.x : window.screenLeft + evt.clientX;  // This block for xy positioning onscreen //
		var gety = document.layers ? window.screenY + evt.y + (window.menubar.visible ? 25 : 0)+ (window.toolbar.visible ? 45 : 0) + (window.locationbar.visible ? 25 : 0): window.screenTop + evt.clientY;
		if (!isNaN(x)) { var xpos = x }
		else { var xpos = isNaN(getx) ? 320 : getx; }    // Fallback xpos=320      // Near midscreen 
		if (!isNaN(y)) { var ypos = y }
		else { var ypos = isNaN(gety) ? 240 : gety; }   // Fallback ypos=240      // for most people
//somerg 210302 keep popup within opener window space
var docW=document.body.clientWidth;
var docH=document.body.clientHeight;
var popX2=getx+width;
var popY2=gety+height;
if (popX2>docW) {xpos=docW-width} ;
if (popY2>docH) {ypos=docH-height} ;	
		var args = '';
		args +='dependent,hotkeys=no,location=no, alwaysRaised,';
		args +='directories=no,menubar=no, resizable=yes,';
		args +='status=no,toolbar=no, scrollbars=yes,';
        args +='width=' + width + ',height='+ height + ',';
        args +='screenX=' + xpos + ',screenY=' + ypos + ',';
        args +='left=' + xpos + ',top=' + ypos;
//		var gW = window.open(strURL,strWin,args);
if(xx=='x'){
window.open('about:blank',strWin,args);
} else {
window.open(strURL,strWin,args);
} //end if
//		gW.minervaChild = true;   // set child (popup) flag on window
} // end Function

function getObject(obj) {
  var theObj = document.all[obj];  // eval("document." + range + obj + styleObj); 
  return theObj;
}

// end of FKFinder Support



function focusOnFirstEl(formRef) {
//260707 if form control mFocMe then set focus to that control
var iFocReq = new Number(0);
iFocReq=gFE('mFocMe');
if(iFocReq!=null){
 if(isNaN(parseInt(iFocReq))){
  try{document.forms[0].elements[iFocReq].focus()}catch(e){};
 }else{
  var iFound=new Number(0);
  var iLoop=new Number(0);
  while(iFound==0){
   try{
    iFound=1;
    var s='E'+iFocReq;
    document.forms[0].elements[s].focus()
   }catch(e){iFound=0};
   iFocReq++;
   iLoop=iLoop+1;
   if(iLoop>100){iFound=9};//loop protection
  }//end while
 }//end if NaN
}else{
  var myForm = document.forms[formRef];
  for (var i=0; i < myForm.length; i++) {
    var el = myForm.elements[i];
    //alert(el.id);
    if(el.id!='rtc'){ // dont focus on rtc control
    switch (el.type) {
      case 'hidden': break;
      case 'image' : break;
      case 'reset' : break;
      default:
        try {el.focus();} catch(e) {};
   //     if (e!=''){alert(e)};
   //     alert(el.name+el.type+el.id);
        i = myForm.length+1;
    }
    }
  }
}//end if FocReq
}





	// FinlaT 06.09.01  Functions allow toolbar to follow window scrolling and remain onscreen.
	function moveTo(el, x, y) {
		el.style.left = x;
		el.style.top  = y;
	}

	function getYScroll() {
		return document.body.scrollTop;
	}

	function getXScroll() {
		return document.body.scrollLeft;
	}

function barUpdate() { // 120107 RMCK
var o=document.getElementById('toolDRAGbar');
var x, y;
var left, top;
left = -14;
top = -2;
if (o!=null) {
 //120107 moveTo(document.all.toolDRAGbar, getXScroll()-14, getYScroll()-2);
   	if (goBrowser.isIE) {
    	x = left + document.documentElement.scrollLeft;
    	y = top + document.documentElement.scrollTop;}
  	if (goBrowser.isFF) {
    	x = left + window.scrollX;
    	y = top + window.scrollY;}
  	o.style.left = x + "px";
  	o.style.top  = y + "px";
} // end if
if((giqm&&4)==4){//timed exam mode keep progbar in position
 var o=document.getElementById('progBar');
 if(o!=null){
  var x, y;
  var left, top;
  left = grProgXY[0];
  top = grProgXY[1];
//  alert('left='+left+' top='+top);
   	if (goBrowser.isIE) {
    	x = left + document.documentElement.scrollLeft;
    	y = top + document.documentElement.scrollTop;}
  	if (goBrowser.isFF) {
    	x = left + window.scrollX;
    	y = top + window.scrollY;}
y=top + cBodyScrollY();
//  alert('x='+x+' y='+y);

  	o.style.left = x + "px";
  	o.style.top  = y + "px";

}//else{alert('no object');};
}//else{alert('giqm='+giqm);};
}
function XY(sId){//240907 get X,Y co-ord of object
var x=y=0;
var o=document.getElementById(sId);
if(o!=null){
 if(o.offsetParent){
  while(1){
   x+=o.offsetLeft;y+=o.offsetTop;
   if(!o.offsetParent) break;  
   o=o.offsetParent;
}}}
return [x,y];
}


// 010604 Validate password when original is keyed
function valpwd2(sN) { // Base Field Name
// hidden control not present
// just check that both fields are the same
sRek=sN+'_R';	// rekey field name
//var o=document.all(sN);
//var oREK=document.all(sRek);
//if ((o!=null) && (oREK!=null)) {
// if (oREK.value!=o.value) {
if (getFormElementValue(sRek)!=getFormElementValue(sN)) {
  alert('Password entries do not match. Please re-key them.');
  setFormElementValue(sN,'');
  setFormElementValue(sRek,'');
  return false;
 } // end if
//} // end if
} // end function

// 130701 Validate Password Entry
function valpwd(sN) { // Base Field Name
sRek=sN+'_REK';	// rekey field name
sCtl=sN+'_CTL'; // hidden control field name
var o=document.all(sN);
var oREK=document.all(sRek);
var oCTL=document.all(sCtl);
if ((o!=null) && (oREK!=null) && (oCTL!=null)) {
 if (oREK.value!=o.value) {
  alert('Password entries do not match. Please re-key them.');
  o.value=oCTL.value;
  oREK.value=oCTL.value;
  return false;
 } // end if
} // end if
} // end function

// 100701 Toolbar Control
function Tl(iA) { // paint toolbar for a level
// Form control mTl holds YNH array
var s=v('mTl');
if (s!=null) {
 ss=new String(s);
// alert (ss);
 s=ss.split(':');
 j=s.length;
 if (j >=iA) {
  ss=new String(s[iA]);
//  for (j=0;j<3;++j) {
  for (j=0;j<ss.length;++j) {
   SetTl(j,ss.charAt(j));
  } // next
 } else {
//  alert ('j='+j+' iA='+iA);
 } // end if (j>=iA)
// for(i=0;i<s.length;++i) {
//  alert ( s[i] );
// } // next
} // End if (s!=null)
} // End Function


function SetTl(i,ynh) { // set a tool
var s='mTl' + i;
var o=document.getElementById(s);
if (o!=null) {
 var nm=o.name
// alert('got ' + s+ ' set to '+ynh);
 switch (ynh) {
  case 'Y' :
   //alert('turn '+i+' on');
   o.src='images/toolbar/'+nm+'.gif';
smo="document.all."+s+".src='images/toolbar/"+nm+"_roll.gif';"; // 060505
smt="document.all."+s+".src='images/toolbar/"+nm+".gif';"; // 060505 errro edit in list smo undefined

//   o.onclick="document.all.mC.value='"+nm+"';document.all.f0.submit();return false;";
//   soc="document.all.mC.value='"+nm+"';document.all.f0.submit();return false;";
   switch (i) {
    case 1  : // reset tool
     soc="document.all.frmreset.click(); return false;"
     o.onclick=new Function(soc);
     o.onmouseover=new Function(smo);
     o.onmouseout=new Function(smt);
     smo="document.all."+s+".src='images/toolbar/"+nm+"_roll.gif';";
     smt="document.all."+s+".src='images/toolbar/"+nm+".gif';";
     break;
    case 18 : // common tasks
     // alert('leave common tasks alone');
     break;
    default : // case else 
    schk=gTlChk[i];
    if (schk==null) {schk=''};
    soc="sbc('"+nm+"','"+schk+"');"
    // alert('soc set to : '+soc);
    o.onclick=new Function(soc);
    o.onmouseover=new Function(smo);
    o.onmouseout=new Function(smt);
    //smo="document.all."+s+".src='images/toolbar/"+nm+"_roll.gif';";
    //smt="document.all."+s+".src='images/toolbar/"+nm+".gif';";
   } // end switch
//   o.onclick=new Function('tloc()');
   break;
  case 'N' :
//   alert('turn it off');
   o.src='images/toolbar/'+o.name+'_off.gif'; // set source image
   o.onclick=new Function();
   o.onmouseover=new Function();
   o.onmouseout=new Function();
   break;
  case 'H' :
//   alert('hide it');
   o.src='images/misc/spacer.gif';
   o.onclick=new Function();
   o.onmouseover=new Function();
   o.onmouseout=new Function();
   break;  
 } // end switch
} else {
// alert(s + ' not an element');
} // End If
} // End Function

// 060701 Toolbar initialisation
function setInit() {
var o=document.getElementById('toolDRAGbar');
if (o!=null) {
 o.style.pixelLeft = -14;
 o.style.pixelTop = -2;
 } // End If
}	

// 060701 Toolbar dragdrop support

    currentX = currentY = 0;
    whichEl = null;

    function grabEl(e) {
		setIFActive(); // 030605
		var evt = window.event ? window.event : e;
        whichEl = window.event ? evt.srcElement : e.target;
        
		// not on input elements !!!! 
		var stg = whichEl.tagName;
		if (stg=='INPUT') { whichEl=null;return true} ;

        while (whichEl.id.indexOf("HRAG") == -1) {
         whichEl = whichEl.parentElement;
         if (whichEl == null){return true}
        }

        while (whichEl.id.indexOf("DRAG") == -1) {
         whichEl = whichEl.parentElement;
         if (whichEl == null){return true}
        }

        if (whichEl != activeEl) {
          // some elements not styled !  whichEl.style.zIndex = activeEl.style.zIndex + 1;
            activeEl = whichEl;
        }

        whichEl.style.pixelLeft = whichEl.offsetLeft;
        whichEl.style.pixelTop = whichEl.offsetTop;

        currentX = (evt.clientX + document.body.scrollLeft);
        currentY = (evt.clientY + document.body.scrollTop); 
    }

function moveEl(e) { //191104 maintain vars with mouse pos

		gmx = window.event ? window.event.screenX : e.screenX;
		gmy = window.event ? window.event.screenY : e.screenY;
	
        if (whichEl == null) { 
        return true
        } else {

        newX = (event.clientX + document.body.scrollLeft);
        newY = (event.clientY + document.body.scrollTop);
        distanceX = (newX - currentX);
        distanceY = (newY - currentY);
        currentX = newX;
        currentY = newY;

        whichEl.style.pixelLeft += distanceX;
        whichEl.style.pixelTop += distanceY;
        if (window.event) {event.returnValue = false;}
    }
}

    function checkEl() {
        if (whichEl!=null) { return false }
    }

    function dropEl() {
        whichEl = null;
    }

    function cursEl() {
        //if (event.srcElement.id.indexOf("HRAG") != -1) {
        // 		 event.srcElement.style.cursor = "move"
        //} else {
        // event.returnValue=true;
        //}
    }

//230408 uncommented to support system dialogs
   document.onmousedown = grabEl;
   document.onmousemove = moveEl;
   document.onmouseup = dropEl;
   //document.onmouseover = cursEl;
   document.onselectstart = checkEl;
    
// ?     activeEl = document.all.toolDRAGbar;

// end toolbar dragdrop support

function cTabstubL(id1,id2,ncell) { 
var skip=0;
bgcol = 'transparent' //document.getElementById(id1).currentStyle.backgroundColor;
if(bIE()){
 try{bgblank = document.getElementById(id2).currentStyle.backgroundColor}catch(ierr){skip=1};
}else{
 try{
 var o=document.getElementById(id2);
 var oStyle=document.defaultView.getComputedStyle(o,"");
 bgblank=oStyle.backgroundColor;
 }catch(ierr){skip=1};
}
cellwh = 1;
if(skip==0){
 // Open table
 tablew = cellwh * ncell;
 tableh = cellwh * ncell;		
 var html = "";
 //html += "<table border='0' cellpadding='0' cellspacing='0' width='" + tablew + "' height='" + tableh + "'>"
 html += "<table border='0' cellpadding='0' cellspacing='0' style='width:" + tablew + ";height:" + tableh + "'>"
 // Create rows and cells
 colour = new Array(ncell);	
 for (h=1;h<=ncell;h++) {
  colour[h] = bgcol;
 }
 for (i=1;i<=ncell;i++) {
  html += "<tr>";
  for (j=1;j<=ncell;j++) {
//   html += "<td width='" + cellwh +"' height='" + cellwh + "' bgcolor='" + colour[j] + "'></td>";
   html += "<td style='width:" + cellwh +"px;height:" + cellwh + "px;background-color:" + colour[j] + "'></td>";
  }
  html += "</tr>";
  blank = colour.length - i;
  colour[blank] = bgblank;
 }
 html += "</tr></table>"; // Write the html to screen
 document.write(html);
}else{
// alert('skip');
} // endif skip		
}
	function cTabstubR(id1,id2,ncell) {
//241006 duplicate ids removed
var skip=0;
// other way round from cTabstubL
bgblank = 'transparent' ;
if(bIE()){
 try{bgcol = document.getElementById(id1).currentStyle.backgroundColor}catch(ierr){skip=1};
}else{
 try{
 var o=document.getElementById(id1);
 var oStyle=document.defaultView.getComputedStyle(o,"");
 bgcol=oStyle.backgroundColor;
 }catch(ierr){skip=1};
}
//try{bgcol = document.getElementById(id1).currentStyle.backgroundColor}catch(ierr){skip=1};
cellwh = 1;		
if(skip==0){
	// Open table
		tablew = cellwh * ncell;
		tableh = cellwh * ncell;		
		var html = '';
//		html += '<table border="0" cellpadding="0" cellspacing="0" width="' + tablew +'" height="' + tableh +'">'
		html += '<table border="0" cellpadding="0" cellspacing="0" style="width:' + tablew +';height:' + tableh +'">'
	// Create rows and cells
		colour = new Array(ncell);	
		for (h=1;h<=ncell;h++) {
			colour[h] = bgblank;
			}
		for (i=1;i<=ncell;i++) {
			html += '<tr>';
			for (j=1;j<=ncell;j++) {
//			html += '<td width="' + cellwh +'" height="' + cellwh + '" bgcolor="' + colour[ncell+1-j] + '"></td>';
			html += '<td style="width:' + cellwh +'px;height:' + cellwh + 'px;background-color:' + colour[ncell+1-j] + '"></td>';
			}
			html += '</tr>';
			blank = colour.length - i;
			colour[blank] = bgcol;
		}
		html += '</tr></table>';	// Write the html to screen
		document.write(html);
} // end if skip
}
	


// 280601 somerg popup data window
function Pop(sU) {
var sSize='height=240,width=500,left=500,top=50'
var sS='location=0,menubar=0,resizable=1,scrollbars=1,toolbar=0';
var sW='_blank';
window.open(sU,sW,sS+','+sSize);
} // End Function


// 210601 somerg. Quick Search Key Press
// 060701 finlat. Fix infernal beeping on Enter keypress
// trap return and submit the form
function QS_okp(e) {
	var lKid=e.keyCode;
	if (lKid==13) {
		if (document.all) { e.keyCode = null; }	// nullify Enter keypress, stops form submit & beep
		var srcEl = e.srcElement ? e.srcElement : e.target;
		if (srcEl.value=='')  {
			alert ('Enter Something to Search on !')
	  } 
		else {
			var fireObj = document.getElementsByName(srcEl.name + '_GO')[0];
			
			if (document.all) { 
				fireObj.click(); 
			} else {
				var evObj = document.createEvent('MouseEvents');
				evObj.initMouseEvent( 'click', true, true, window, 1, 12, 345, 7, 220, false, false, true, false, 0, null );
				fireObj.dispatchEvent(evObj);
			}
			//eval('document.all.'+e.srcElement.name+'_GO.click()');
		}							// end if e.srcElement.value=='' (no text)
	}								// end if key13
	return false;
}									// End Function


/*	Scripts for User Permission	*/

function doUserPerm (source, targetId, evt, width, height) {
  var getx = document.layers ? window.screenX + evt.x : window.screenLeft + evt.clientX;
  var gety = document.layers ? window.screenY + evt.y + (window.menubar.visible ? 25 : 0)+ (window.toolbar.visible ? 45 : 0) + (window.locationbar.visible ? 25 : 0): window.screenTop + evt.clientY;
  var xpos = isNaN(getx) ? 320 : getx;		// Fallback xpos=320  |-| Near midscreen 
  var ypos = isNaN(gety) ? 240 : gety;		// Fallback ypos=240  |-| for most people
	
	target = getObj(targetId);
	if (target.length != undefined)
		{
	 	for(j=0;j<target.length;j++) {
			if(target[j].type=='hidden') {
				var el = target[j];
			}
		}
	}
	else {
		var el = target;
	}
  var sTemp = el.value;

  var strURL = source + '?udat=' + escape(sTemp); 
  strURL += '&tar=';
  strURL += targetId;
	
  var args =  'dependent,alwaysRaised,hotkeys=no,location=no,';
      args += 'directories=no,menubar=no,resizable=yes,';
      args += 'scrollbars=yes,status=no,toolbar=no';
			if (width) { args += ',width=' + width; }
				else {args += ',width=' + 200;}
			if (height){ args += ',height='+ height;}
				else {args += ',height='+ 200;}
      args += ',screenX=' + xpos + ',screenY=' + ypos + ',';
      args += 'left=' + xpos + ',top=' + ypos;
			
	//		alert(strURL);
      var dialog = window.open(strURL,"Dialog",args);
	}


function viewUserPerm	(source, targetId, evt, width, height) {
  var getx = document.layers ? window.screenX + evt.x : window.screenLeft + evt.clientX;
  var gety = document.layers ? window.screenY + evt.y + (window.menubar.visible ? 25 : 0)+ (window.toolbar.visible ? 45 : 0) + (window.locationbar.visible ? 25 : 0): window.screenTop + evt.clientY;
  var xpos = isNaN(getx) ? 320 : getx;		// Fallback xpos=320  |-| Near midscreen 
  var ypos = isNaN(gety) ? 240 : gety;		// Fallback ypos=240  |-| for most people
	
	target = getObj(targetId);
	if (target.length != undefined)
		{
	 	for(j=0;j<target.length;j++) {
			if(target[j].type=='hidden') {
				var el = target[j];
			}
		}
	}
	else {
		var el = target;
	}
  var sTemp = el.value;
  var strURL = source + '?udat=' + escape(sTemp); 
  strURL += '&tar=';
  strURL += targetId;
  strURL += '&mode=view';
	
  var args =  'dependent,alwaysRaised,hotkeys=no,location=no,';
      args += 'directories=no,menubar=no,resizable=yes,';
      args += 'scrollbars=yes,status=no,toolbar=no';
			if (width) { args += ',width=' + width; }
				else {args += ',width=' + 200;}
			if (height){ args += ',height='+ height;}
				else {args += ',height='+ 200;}
      args += ',screenX=' + xpos + ',screenY=' + ypos + ',';
      args += 'left=' + xpos + ',top=' + ypos;
			
		//	alert(strURL);
      var dialog = window.open(strURL,"Dialog",args);
	}

	function updateUserPerm (targName, value) {
		//alert('updateUserPerm (targName, value)' + '\n' + targName + '\n' + value);
    var target = document.all ? document.all[targName] : document.getElementById(targName);
	if (target.length != undefined)
		{
	 	for(j=0;j<target.length;j++) {
			if(target[j].type=='hidden') {
				var el = target[j];
			}
		}
	}
	else {
		var el = target;
	}
    el.value = value;
  } 

function viewSinglePerm(source, target, evt, width, height) {
		var getx = document.layers ? window.screenX + evt.x : window.screenLeft + evt.clientX;
		var gety = document.layers ? window.screenY + evt.y + (window.menubar.visible ? 25 : 0)+ (window.toolbar.visible ? 45 : 0) + (window.locationbar.visible ? 25 : 0): window.screenTop + evt.clientY;
		var xpos = isNaN(getx) ? 320 : getx;
		var ypos = isNaN(gety) ? 240 : gety;
		if (target.length != undefined)
			{
	 		for(j=0;j<target.length;j++) {
				if(target[j].type=='hidden') {
					var el = target[j];
				}
			}
		}
		else {
			var el = target;
		}
  		var sTemp = el.value;
		var strURL = source + '?Udat=' + escape(sTemp); 
				strURL += '&mode=view';
		var args = '';
				args = args + 'width=' + width + ',height='+ height + ',';
				args = args + 'screenX=' + xpos + ',screenY=' + ypos + ',';
				args = args + 'left=' + xpos + ',top=' + ypos;
		singPermWin = window.open(strURL,"Dialog",args);
	}


  function getObj(refId) { 
	   var obj = (document.all) ? document.all[refId] : document.getElementById[refId]; 
    return obj;
  }
/*	End scripts for User Permission	*/

// 190601 somerg
function fos() { // form on submit
 return true;
} // End Function

// 040601 somerg
function merr() { // cs error handler
return true ;
 } // End Function

// 040901 somerg
// content picker function
function cnoc(iL) { // content on click
cna8(iL);
} // End Function

// 040901 somerg
// activate content area
function cna8(iL) {
var iM=v('mM'); 
var iA=v('mA'); 
if (iL!=iA) { // not if its the active layer anyway
if (iM==0) { // warn when moving off edit
 var oColl=oAll('wncn'+iL);
 var i=0;
 cncl(oColl,'cnf','cnn','lf','ln','df','dn');
 var iLC=v('mL');
 if (iLC==null) {iLC=0};
 if (iLC<0) {iLC=0};
 if (iL>=0) { // valid iL
  for (i=0;i<=iLC;i++) {
   if (i!=iL) { // not the current layer
    var oColl=oAll('wncn'+i);
    cncl(oColl,'cnn','cnf','ln','lf','df','dn');
   } // End If not the current layer
  } // next i
 } // End If valid iL
 Tl(iL); 
 if (v('mA')!=null) {document.forms[0].elements['mA'].value=iL};
} else {
 alert('Save or Cancel first'); 
} // end if (iM==0)
} // end if (iL!=iA)
} // End Function

// flip class of items in collection
function cncl(oColl,sF,sT,sF1,sT1,sF2,sT2) {
	if (oColl!=null) {
		for (i=0;i<=oColl.length-1;i++) {
			var s=oColl[i].className;
			if (s!=null) {
				if (s==sF) {oColl[i].className=sT;} 
				else if (s==sF1) {oColl[i].className=sT1;}
				else if (s==sF2) {oColl[i].className=sT2;} 
			}
		} 
	} 
} 

// 120601 somerg
function a8(iL,cho,cbo,chno,cto,coto,chf,cbf,chnf,ctf,cotf) { // activate a layer area
DivSw('wdh',iL,cho);
DivSw('wdb',iL,cbo);
HnSw('wdhn',iL,chno);
TabSw('wdt',iL,cto,'workspace_tab_table_off');
TabSw('wdt',iL,coto,'workspace_tab_table_on');
FocOff(iL,chf,cbf,chnf,ctf,cotf);
if (v('mA')!=null) {document.all.mA.value=iL};
} // End Function

// 070601 somerg
function DivSw(s,iL,col) { // turn a div off (or on)
var ncol=0x808080;
if (col!=null){ncol=col} ;
var idname=s + iL;
var o=document.getElementById(idname);
if (o!=null){ // got an object
 var oc=o.all; // children
 for (j=0;j<oc.length;j++) {
  oc(j).style.color=ncol;
   } ; // Next
 } ; // End If got object 
} // End Function

// 280205
function llltgl(iL){ // list len list toggle
var idname='lll'+iL;
var oc=document.all(idname);
if(oc!=null){
var icnt=oc.length;
if (icnt==undefined){ // only one
 var a=oc.style.display;
 if(a=='none'){a='inline'}else{a='none'};
 oc.style.display=a;
} else { 
var a=oc(0).style.display;
if(a=='none'){a='inline'}else{a='none'};
for(i=0;i<oc.length;i++){
 oc(i).style.display=a;
}}}
idname='lllctl'+iL;
var o=document.getElementById(idname);
if(o!=null){
if(a=='none'){a='+'}else{a='-'};
o.innerText=a;
}}
// 120601 somerg
function TabSw(s,iL,col,id) { // turn a TabArea off (or on)
var ncol=0xC0C0C0;
if (col!=null){ncol=col} ;
var idname=s + iL;
var o=document.getElementById(idname);
if (o!=null){ // got an object
 var oc=o.all; // children
 for (j=0;j<oc.length;j++) {
  var bgc=oc(j).style.backgroundColor;
  if ((bgc!=null) && (bgc!='0')) {
   if (oc(j).id==id) {
    oc(j).style.backgroundColor=ncol; 
   } // end if a tab
  } // end if
   } ; // Next
 } ; // End If got object 
} // End Function

// 120601 somerg
function HnSw(s,iL,col) { // turn a handle off (or on)
var ncol=0xC0C0C0;
if (col!=null){ncol=col} ;
var idname=s + iL;
var o=document.getElementById(idname);
if (o!=null){ // got an object
 var oc=o.all; // children
 for (j=0;j<oc.length;j++) {
  var bgc=oc(j).style.backgroundColor;
  if ((bgc!=null) && (bgc!='0')) {
  oc(j).style.backgroundColor=ncol; 
  } // end if
   } ; // Next
  var bgc=o.style.backgroundColor;
  if ((bgc!=null) && (bgc!='0')) {
  o.style.backgroundColor=ncol;
  } // end if
 } ; // End If got object 
} // End Function


// 090701 somerg
function HnSw2(iA,bon) { // turn a handle on or off by class
if (bon==1) {sC='cnn'} else {sC='cnf'}
//ClSw2('hnd'+iA,sC); // handle
//ClSw2('hndl'+iA,sC); // left corner
//ClSw2('hndr'+iA,sC); // right corner
//ClSw2('hndt'+iA,sC); // top border
//ClSw2('hndll'+iA,sC); // left border
//ClSw2('cn'+iA,sC);
} // End Function

// 090701 somerg
function HdSw2(iA,bon) { // turn a handle on or off by class
if (bon==1) {sC='texton'} else {sC='textoff'}
var sid='hd' + iA;
ClSw2(sid,sC);
} // End Function

// 090701 somerg
function ClSw2(sid,sCl) { // set object with id sId to Class sCl
var o=document.getElementById(sid);
if (o!=null) {o.className=sCl};
} // End Function



// 040901 somerg
// get an objects all colletion or 
// return null
function oAll(sid) {
	var oC=o(sid);
	if (oC!=null) {
		return oC.all ? oC.all : oC.getElementsByTagName('*');
	} else {
		return null;
	}
} // End Function

// 240507 somerg html4
// get a form control's value or null
function v(s) {
var ret;
try{ret=document.forms[0].elements[s].value;}catch(ierr){};
return ret;
} // End Function

function cFE_ifvalue_select_text2index(sFrom,sTo,iDoChangeEvent){//130707 copy form value if data
//destination is a select and value is one of the options
try{
 var sval=new String('');
 var osrc=document.forms[0].elements[sFrom];
 sval=osrc.options[osrc.selectedIndex].text;
// alert(sval);
 if(sval!=''){
  var otrg=document.forms[0].elements[sTo];
  for(j=0;j<otrg.options.length;j++){
//   alert(otrg.options[j].index+' '+otrg.options[j].text);
   if(otrg.options[j].value==sval){
    otrg.options[j].selected=true
    if(iDoChangeEvent==1){
     //alert('fire event');
     otrg.onchange()};
   };
  }//next
 }//is value
}catch(e){alert(e.message)};
}

function cFE_ifvalue(sFrom,sTo){//130707 copy form value if data
try{
 var val=new String(getFormElementValue(sFrom));
 //alert(val);
 if(val!=''){setFormElementValue(sTo,val)}
}catch(e){alert(e.message)};
}

function cFE(sFrom,sTo){//090707 copy form value
try{setFormElementValue(sTo,getFormElementValue(sFrom))}catch(ierr){};
}
function gFE(s){return getFormElementValue(s)}
function getFormElementValue(s){ //021106 html4
var ret;
try{ret=document.forms[0].elements[s].value;}catch(ierr){ret=null};
return ret;
}
function sFE(s,Val){setFormElementValue(s,Val)}
function setFormElementValue(s,Val){ //021106 html4
try{document.forms[0].elements[s].value=Val;}catch(ierr){};
}

function setElementInnerText(sId,Val){//190307
try{document.getElementById(sId).innerText=Val;}catch(ierr){};
}
function getElementInnerText(sId){//030507
try{return document.getElementById(sId).innerText}catch(ierr){return ''};
}


// 040901 somerg
// get an object from id or return null
function o(sId) {
return document.getElementById(sId);
} // End Function

// 120601 somerg
function FocOff(iL,chf,cbf,chnf,ctf,cotf) { // set focus off all except iL
//var iLC=document.all('mL').value;
var iLC=v('mL');
if (iLC==null) {iLC=0};
if (iLC<0) {iLC=0};
if (iL>=0) { // valid iL
 for (i=0;i<=iLC;i++) {
  if (i!=iL) { // not the current layer
   DivSw('wdh',i,chf); DivSw('wdb',i,cbf); HnSw('wdhn',i,chnf); TabSw('wdt',i,ctf);  TabSw('wdt',i,cotf);
  } // End If not the current layer
 } // next i
} // End If valid iL
} // End Function

 
// 140207 revised to use Coerce functions
// 191104 resize popup - ensure on screen
function bolrsz(){
var lok=10;
var lh=cBodyValCH();//cBodyHeight();//document.body.clientHeight;
var th=cBodyValSH();//cBodyScrollHeight();//document.body.scrollHeight;
var lw=cBodyValCW();//cBodyWidth();//document.body.clientWidth;
var tw=cBodyValSW();//cBodyScrollWidth();//document.body.scrollWidth;

if((th>lh)||(tw>lw)){
if (document.all) {
	window.resizeBy(tw-lw,th-lh);
} else {
	window.resizeBy(tw-lw+160,th-lh);
}
 lh=cBodyValCH();
 th=cBodyValSH();
 lw=cBodyValCW();
 tw=cBodyValSW();
 };

// is the rhs on the screen ?
var maxX=window.screen.availWidth; // returns 1024 on multi monitor !!
var ow=window.opener;
if(ow!=null){
 var maxWX=ow.screenLeft;
 if(maxWX<0){bNeg=true}else{bNeg=false}; // if in a neg place then put child over parent
// alert('parent left='+maxWX);
 var maxWW=cBodyValCW2(ow);//ow.document.body.clientWidth;
// alert('parent width='+maxWW);
 var extWP=maxWX+maxWW;


// screenLeft screenTop
var extX=window.screenLeft+lw;//cBodyWidth();//document.body.clientWidth;
//alert('extX='+extX+' maxX='+maxX+' maxWX='+extWP);

if(extWP>maxX){maxX=extWP};

var iTopChromeHeight=100; // probably varies with browser and DTD
var iScreenChromeHeight=25; // start bar 

var oY=window.screenTop; // position of top of window excluding chrome

var screenY=window.screen.availHeight;
var maxY=screenY-iScreenChromeHeight-iTopChromeHeight; // height available

szX=lw;// current width 
szY=lh;// current height

if(szY>maxY){// 030507 body is bigger than window so resize it
 var zY=-(szY-maxY); //change height by amount greater than window size
 //alert('resize by '+zY);
 window.resizeBy(0,zY);
 lh=cBodyValCH();
 th=cBodyValSH();
}//(szY>maxY)

oY=window.screenTop; // position of top of window excluding chrome
var extY=oY+lh;  //position of bottom of window

var dY=0;
if(extY>(screenY-iScreenChromeHeight)){// bottom is off the screen
 var dY=-(extY-(screenY-iScreenChromeHeight));
 //alert('extY='+extY+' screenY='+screenY+' dY='+dY);
}else{
 if(oY<0){//top is off the screen  
  dY=oY;
 }//oY<0
}//(extY>maxY)

var dX=0;

if(bNeg){//just put the child over the parent
 maxX=extWP;
 dX=maxX-extX;
}else{
 if(extX>maxX){dX=maxX-extX}else{dX=0};
}
if((dX!=0)||(dY!=0)){
 window.moveBy(dX,dY)
};


//} else {
// alert('no opener');
} // endif 

}

//190607 somerg
// html4 expand w to ensure window is filled
function bolrsz0(){
var lDocH=cBodyValSH();
var lWinH=cBodyValWH();
var lScreenH=cBodyValWSAH();
//window.status='lDocH='+lDocH+' lWinH='+lWinH;
if(lDocH<lWinH){// expand workspace
 var lWhiteSpace=lWinH-lDocH;
 var od=document.getElementById('w');
 if(od!=null){
  try{var lTableClientHeight=od.clientHeight}catch(ierr){lTableClientHeight=0};
  if(lTableClientHeight<1){
   lNewHeight=600;
  }else{
   lNewHeight=lTableClientHeight+lWhiteSpace;
  }  
  //window.status='lDocH='+lDocH+' lWinH='+lWinH+' lTableClientHeight='+lTableClientHeight+ ' lNewHeight='+lNewHeight;
  var sNewHeight =new String('px');
  sNewHeight=(lNewHeight)+sNewHeight;
  try{od.style.height=sNewHeight}catch(ierr){};
  var oS=od.style;
  if(oS!=null){
   var lWrkH=oS.height;
  }else{lWrkH='No Style Object'}
 }else{lWrkH='No Object'}
}
//window.status='lDocH='+lDocH+' lWinH='+lWinH+' lScreenH='+lScreenH+' lWrkH='+lWrkH+' lTableClientHeight='+lTableClientHeight;
//window.status='lWrkH='+lWrkH+' lTableClientHeight='+lTableClientHeight+' lTableHeight='+lTableHeight;
}

function testWinProps(){
a='';
crlf=String.fromCharCode(13,10);
a=a+window.name+crlf;
if(window.opener!=null){a=a+'opener is an object'+crlf};
if(window.parent!=null){
 a=a+'parent is an object'+crlf;
 a=a+'parent name '+window.parent.name+crlf;
 
};
a=a+'mCQ='+gFE('mCQ')+crlf;
a=a+'gibol='+gibol+crlf;
a=a+'end';
alert(a);
window.name='bol done';
sFE('mCQ','99');
}

function chkCookies(){ //040208
var s=document.cookie;
var ss=s.split(';');
for(i=0;i<ss.length;i++){
 var ck=ss[i].split('=');
 var cknm=ck[0];
 var ckval=ck[1];
// alert('-'+cknm.substr(0,8)+'-');
 if(cknm.substr(0,8)==' ASPSESS'){
  alert(cknm + '='+ckval);
  document.cookie=cknm+'=0';
 }
}//next
}//end function


// 010601 somerg 
function bol(iar,wntp,wnid,imsg,idvm,iTO,iTOsecs,iqm) { // body onload handler
//if(gFE('mCQ')=='99'){
// chkCookies();
// window.navigate(document.URL);//sbc('t','','2002') // 040208 trap new window request
//}else{
//testWinProps();
if(wntp&1){bolrsz()}else {bolrsz0()};

// set active area
//var iA;
//var o=document.all('mA');
//if (o!=null) {iA=o.value};
var iA=v('mA');
if (iA==null) {iA=0};
if (iA<0) {iA=0};
//alert('active layer is '+iA);
// a8(iA,0x000000,0x000000,0xFF9933,0xFFB861,0xFF9933,0xC0C0C0,0xC0C0C0,0xFFC78F,0xFFC78F,0xFFC78F);
// a8(iA,0x000000,0x000000,0xe6e6e6,0xcccccc,0xe6e6e6,0xC0C0C0,0xC0C0C0,0xcccccc,0xcccccc,0xcccccc);
var iOp=v('mOp');
if (iOp=='8900') {
 //alert('size to '+th);
 window.resizeTo(document.body.clientWidth,document.body.clientHeight+80);
 } // End If

setInit(); // toolbar initialisation
// 290108 7011 added for profiler view data
// 180208 9000 folder list at level 0
if ((iOp<7000)||(iOp==7011)||(iOp==9000)){chklidi()}; 
window.focus();
var iM=v('mM');
if (iM>0){if (gikp==0){focusOnFirstEl(0)}}; // not in view mode 040505 not if key pressed

// autorefresh timeout
if(iar>0){ artm(iar);}

if(imsg==1){bolmsg()};
gidvm=idvm;

if (iTO>0){setSessTO(iTO,iTOsecs)}; // session timeout

if(iqm>0){ // 190307 setup progressbar
var o=document.getElementById('progBar');
if(o!=null){
 // store position for scroll handler
 grProgXY=XY('progBar');
 setBar(iqm);
 if(iqm>1){
  giqm=iqm;
  window.setTimeout("onSecond()", 1000)
  if(iqm>4){
   sessBlur();
   giql=1;
  }};
}}
gibol=1;//050707 done
//sFE('mCQ','99'); // 040208
//} // end if new window trap
} // End Function


function WaitEval(imS,sEval){
gsWaitEval=unescape(sEval);
//alert(gsWaitEval);
window.setTimeout("WaitEvalDo()",imS);
}
function WaitEval_DynLU(imS,sEval){//wait for DynLU to complete
gsWaitEval=unescape(sEval);
giWaitEvalTick=imS;
window.setTimeout("WaitEvalWaitDynLU()",giWaitEvalTick);
}
function WaitEvalWaitDynLU(){
if(gilL2state==0){
 WaitEvalDo();
}else{
 window.setTimeout("WaitEvalWaitDynLU()",giWaitEvalTick)
}}

function WaitEvalDo(){
eval(gsWaitEval);
}

function setSessTO(iTO,iTOsecs){ // setup session timeout
giDaemonInterval=1; // set daemon interval 
giSessionTimeout=iTOsecs; // initialise Session Timeout Value (20secs less than server Timeout)
giSessionWarn=30; // needs to be more than Daemon Interval !!!!
giSessionTimeoutCounter=0+giSessionTimeout;
giActivePeriod=5;
giIFState=0; // set interface state to initial
setParentState(0);
giIFTime=0;
giIFIdleCounter=0;
giIFInactiveTime=0;
//setFLbl('rtc',sCurrentTime());
setLbl2('rtc',sCurrentTime());
gDaemonID = window.setInterval("daemon()", giDaemonInterval*1000);// activate the daemon timer 
}

function setParentState(i){
var own=window.opener;
if(own!=null){
 //alert('hasparent'+own.frames.length);//.giIFState);
 try{own.setIFActive(1)}catch(ierr){} // user may have closed parent
}}


function setIFActive(b){
if(giIFState!=3||b==1){
giIFIdleCounter=0;
giIFState=1;
giIFInactiveTime=0;
}
if(b==1){hideLayer2('syssessto0_DRAG')}; // hide warning (child activity)

arrst(); // reset autorefresh
}

function daemon(){ // daemon timer
// use a var to update counters - tick may be changed from 1 second !
giIFTime=giIFTime+giDaemonInterval;// increment IFtime
giIFIdleCounter=giIFIdleCounter+giDaemonInterval;// increment IFtime
if (giIFIdleCounter>giActivePeriod){giIFState=2};// if IFtime > 30 and state=0 then set state to 2 (inactive)
if(giIFState==2){giIFInactiveTime=giIFInactiveTime+giDaemonInterval}; // count how long i/f inactive
giSessionTimeoutCounter=giSessionTimeoutCounter-giDaemonInterval;//match server side countdown !
if(giSessionTimeoutCounter<1){// if timed out then post !
 //alert('Server Session has Timed Out');
 window.clearInterval(gDaemonID);// kill the timer
 // if not the parent then close !
 var ow=window.opener;
 if(ow!=null){window.close()}else{sbc('t','','1980')};
}// end if
if(giSessionTimeoutCounter<giSessionWarn){// if close to session timeout then warn
 if(giIFState==1){
  //   if active then post keepalive in iframe
  sessKA(0);
  window.status='Keep Alive posted';
 }else{
  window.status='Session Timeout imminent'; // sysform ok button will have to reset
  giIFState=3;
  showLayer('syssessto0_DRAG');
 } // end if giIFState=1
}// end if giSessionWarn

// auto-refresh timers 
if(giar[0][0]>0){
 //window.status=giar[0][0]+':'+giar[1][0];
 giar[1][0]=giar[1][0]-giDaemonInterval;
 setFLbl('giar0',giar[1][0]);
}

//// defer for 3 secs
//if (giIFTime>3){
if (giIFState>1){
if(gbInDaemon==0){
gbInDaemon=1;
//setLbl('giIFState',sIFState(giIFState));
setFLbl('gisto',giSessionTimeoutCounter);

gbInDaemon=0;
} // inDaemon
//} // > 3 secs
} // iFstate > 1
setLbl2('rtc',sCurrentTime()); //300407
} // end function

function sessKA(b){// keep session alive if b=1 then close warning div 
if(giSessionTimeoutCounter<giSessionWarn){// moving to button may already have fired the event !!
var oframe = window.frames.iiframe0;
if (oframe!=null){
 if(gidvm==256){
  setLbl('giIFState','KEEPALIVE')
 }else{
  oframe.location.replace('home.asp?sS=KEEPALIVE')};
//}else{
// alert('expected iframe iiframe0');
giSessionTimeoutCounter=giSessionTimeout;
}}
if(b==1){hideLayer('syssessto0_DRAG')}; // hide warning
}

function setFLbl(sId,sVal){// set a form controls value 090605 innertext on span too slow !
var o=document.getElementById(sId);
if(o!=null){o.value=sVal}}

function setLbl2(sId,sVal){
try{document.getElementById(sId).innerText=sVal}catch(e){};
}

function setLbl(sId,sVal,b){// set a spans text (div or td too?)
// if b==1 then assume its unique on the page
// VERY SLOW IN LARGE LISTS !!!
if(b==1){
 var o=document.getElementById(sId);
 if(o!=null){
 //alert('o.innerText=sVal')
 o.innerText=sVal;
 }
}else{
 var oSet=document.all(sId);
 if(oSet!=null){
  if(isNaN(oSet.length)){
   oSet.innerText=sVal;
  }else{
   for(i=0;i<oSet.length;i++){
    oSet[i].innerText=sVal;
    } // next
  }//end if
 } // end if
}//end if
} // end function




function bolmsg(){
showLayer('sysmsg_DRAG');
}

function artm(iar){
ims=iar*1000;
gtIDar=window.setTimeout("arto()",ims);
giar[0][0]=iar;
giar[1][0]=iar;
setFLbl('giar0',giar[0][0]);

}
function arto(){
arclr();
sbc('f5','');
}
function arclr(){
window.clearTimeout(gtIDar);
}
function arrst(){
var iar=giar[0][0];
if(iar>0){
window.status=iar;
window.clearTimeout(gtIDar);
artm(iar);
}}



  function resetform(name) { 
      /* feed this the form name */ 
      var el = getObj(name); 
      el.reset(); 
  } 

  function getObj(refId) { 
      var obj = (document.all) ? document.all[refId] : document.getElementById[refId]; 
      return obj; 
  } 

/**************************************/
/*  Start of scripts for Date picker  */
/*      functions:  doWin()           */
/*                  updateTarg()      */
/**************************************/
  function doWin (source, target, evt, width, height) {
    var getx = document.layers ? window.screenX + evt.x : window.screenLeft + evt.clientX;  // This block for xy positioning onscreen //
    var gety = document.layers ? window.screenY + evt.y + (window.menubar.visible ? 25 : 0)+ (window.toolbar.visible ? 45 : 0) + (window.locationbar.visible ? 25 : 0): window.screenTop + evt.clientY;
    var xpos = isNaN(getx) ? 320 : getx;    // Fallback xpos=320      // Near midscreen 
    var ypos = isNaN(gety) ? 240 : gety;    // Fallback ypos=240      // for most people

    var els = document.getElementsByName(target);
	var el;
    if (els.length > 0) {
	 	for (j=0; j<els.length; j++) {
			if (els[j].type=='text') {
				el = els[j];
			}
		}
	} else {
		el = els[0];
	}
    
    var sSrc=new String(source);
    if (sSrc.indexOf('?') > 1) {
     var strURL = source + '&current=' + el.value + '&target=' + el.name;
    } else {
     var strURL = source + '?current=' + el.value + '&target=' + el.name;
    }
    var args = 'dependent,alwaysRaised,hotkeys=no,location=no,';
        args = args + 'directories=no,menubar=no,resizeable=no,';
        args = args + 'scrollbars=no,status=no,toolbar=no,';
        args = args + 'width=' + width + ',height='+ height + ',';
        args = args + 'screenX=' + xpos + ',screenY=' + ypos + ',';
        args = args + 'left=' + xpos + ',top=' + ypos;
    dateWin = window.open(strURL,"Dialog",args);
  }
  
function updateTarg (targName, value) {
	//    var el = document.all ? document.all[targName] : document.getElementByName(targName);
	elcoll = document.getElementsByName(targName);
	var i=elcoll.length;
	if (i==1) {
		elcoll[0].value=value;
		if (document.all) { 
			elcoll[0].fireEvent('onchange'); // 060505
		} else {
			var evObj = document.createEvent('HTMLEvents');
			evObj.initEvent('change', true, false);
			elcoll[0].dispatchEvent(evObj);
		}
	} else { //collection
		for (j=0;j<i;j++) {
			if (elcoll[j].type=='text'){
				elcoll[0].value=value;
				if (document.all) { 
					elcoll[j].fireEvent('onchange'); // 060505
				} else {
					var evObj = document.createEvent('HTMLEvents');
					evObj.initEvent('change', true, false);
					elcoll[j].dispatchEvent(evObj);
				}
			}
		} 
	} 
}
/**************************************/
/*  End of scripts for Date picker    */
/*      functions:  doWin()           */
/*                  updateTarg()      */
/**************************************/

// 060301 somerg
function GetAbsoluteTop(elem)
{
	var topPosition = 0;

	while (elem)
	{
		if (elem.tagName == 'BODY')
		{
			break;
		}
		topPosition += elem.offsetTop;
		elem = elem.offsetParent;
	}
	return topPosition;
}

function GetAbsoluteLeft(elem)
{
	var leftPosition = 0;

	while (elem)
	{
		if (elem.tagName == 'BODY')
		{
			break;
		}
		leftPosition += elem.offsetLeft;
		elem = elem.offsetParent;
	}

	return leftPosition;
}
//181104 mouse over
function omo(a, e) { // context setting
//status='Set Context "'+a+'"';
	var aa=new String(a);
	arr=aa.split(';');
	for(i=0;i<arr.length;i++) {
		// replace ~ with '
		var aaa = new String(arr[i]);
		while (aaa.indexOf('~')>-1) { aaa=aaa.replace('~','"'); }
		while (aaa.indexOf('^')>-1) { aaa=aaa.replace('^',';'); }
		eval(aaa);
	}
	if (window.event) { window.event.cancelBubble=true; } else { e.stopPropagation(); }
}

//181104 right click menu
function rcl(el,orig,o,x,y,e) { //
	var evt = window.event ? window.event : e;
	var rcEl = document.getElementById(el + '_t');
	if(evt.button==2) {
		//eval(el+'_t.innerText=gRCLa');
		if (rcEl != null) { rcEl.innerHTML = gRCLa; }
		if (gRCLsid != '') { hideLayer(gRCLsid); }
		Show2(el,evt);
		if (window.event) { window.event.cancelBubble=true; } else { evt.stopPropagation(); }
		//window.event.returnValue=false;
	} else {
		return false;
	}
}


function Show2(layerName, e) { // for right click menu, updated with colins changes
	var evt = window.event ? window.event : e;
	
	if (window.event) {
		x = evt.clientX + document.documentElement.scrollLeft + document.body.scrollLeft;
		y = evt.clientY + document.documentElement.scrollTop + document.body.scrollTop;
	} else {
		x = evt.pageX;
		y = evt.pageY;
	}
	x -= 10; y -= 10;
	
	var el = document.getElementById(layerName) ? document.getElementById(layerName) : document.getElementsByName(layerName)[0];
	
	if (el != null) {
		el.style.left = x + 'px';
		el.style.top = y + 'px';
		el.style.visibility = "visible";
	}
	
	
	//a=layerRef+'["'+layerName+'"]'+styleSwitch ;
	//eval(a+'.left=' + x );
	//eval(a+'.top=' + y );
	//eval(a+'.visibility="visible"');
	gRCLsid=layerName;
}

// 160606 updated to toggle
function ShowRel2(el,orig,o,x,y) {
// o=TL/TR/BL/BR
try{
var ec=document.getElementById(orig);
//RMCK - If user clicks button while the element is shown, hide it
if(document.getElementById(el).style.visibility == "visible"){
 hideLayer(el)
}else{
if (o == "TR") {
 z = 17;
} else { // top left
 //160606 RMCK - Functions replaced with more accurate version
 ox=GetAbsoluteLeft(ec)+ x ;
 oy=GetAbsoluteTop(ec) + y ;
 ShowXY(el,ox,oy); 
}}
}catch(e){};
return 0;
}


// 040301 somerg show element relative to another
function ShowRel(el,orig,o,x,y) {
// may be explorer only !!// o=TL/TR/BL/BR

var ec=document.all ;
if (o == "TR")
 {
       z = 17;
 }else { // top left
  ox=GetAbsoluteLeft(ec[orig])+ x ;
  oy=GetAbsoluteTop(ec[orig]) + y ;
  ShowXY(el,ox,oy) ; 
}// ;return 0 ;
}

// 040301 somerg show layer at a specific place
function ShowXY(layerName,x,y) {
	var el = document.getElementById(layerName) ? document.getElementById(layerName) : document.getElementsByName(layerName)[0];
	
	if (el != null) {
		el.style.left = x + 'px';
		el.style.top = y + 'px';
		el.style.visibility = "visible";
	}
}

//
// 040301 somerg added to library from helpscript
// layer switching
function displayLayer(layerName) {
//	eval(layerRef+'["'+layerName+'"]'+styleSwitch+'.display="inline"');
showElementById(layerName);
}
function nodisplayLayer(layerName) {	
//eval(layerRef+'["'+layerName+'"]'+styleSwitch+'.display="none"');
hideElementById(layerName);
}
function showLayer(layerName) {
//	eval(layerRef+'["'+layerName+'"]'+styleSwitch+'.visibility="visible"');
visElementById(layerName);
}
function hideLayer(layerName) {
//try{eval(layerRef+'["'+layerName+'"]'+styleSwitch+'.visibility="hidden"');}catch(e){};
invisElementById(layerName);
}

function hideLayer2(layerName){ // 060605 !!!!
// html4 update 021106
//var o=document.getElementById(layerName);
//if(o!=null){
// var os=o.style;
// if(os!=null){
//  os.visibility='hidden';
//}}
invisElementById(layerName);
}

function showLayer2(layerName,sChk,sMsg){ // 120705 !!!!
// html4 update 021106
var b=eval(sChk);
if (b){
 visElementById(layerName)
}else{
 if(sMsg!=null){
  alert(sMsg);
}}}


// 021106 updated
// 300501 somerg 
// layer toggle with form control update
// sL is layer name , i is m1 bit pos
function lv(sL,i) {
showElementById(sL);
hideElementById('s'+sL);
var iPref=getFormElementValue('m1');
iPref=iPref & (255- i) ;
setFormElementValue('m1',iPref);
}
function lh(sL,i) {
hideElementById(sL);
showElementById('s'+sL);
var iPref=getFormElementValue('m1');
iPref=iPref | i ;
setFormElementValue('m1',iPref);
}
function lv2(sL,i) { //021106
showElementById(sL);
showElementById('h'+sL);
hideElementById('s'+sL);
liresize(0,1); // 181206 resize list
var iPref=getFormElementValue('m1');
iPref=iPref & (255- i) ;
setFormElementValue('m1',iPref);
}
function lh2(sL,i) { // 021106 layer toggle when hide tool not on layer
hideElementById(sL);
hideElementById('h'+sL);
showElementById('s'+sL);
liresize(0,1); // 181206 resize list
var iPref=getFormElementValue('m1');
iPref=iPref | i ;
setFormElementValue('m1',iPref);
event.cancelBubble=true;
}

function visElementById(sId){//021106 assumes style object
var o=document.getElementById(sId);
if(o!=null){try{o.style.visibility='visible'}catch(ierr){ierr=0}}; 
}
function invisElementById(sId){//021106 assumes style object
var o=document.getElementById(sId);
if(o!=null){try{o.style.visibility='hidden'}catch(ierr){ierr=0}}; 
}
function showElementById(sId){//021106 assumes style object
var o=document.getElementById(sId);
if(o!=null){try{o.style.display='inline'}catch(ierr){ierr=0}}; 
}
function hideElementById(sId){//021106 assumes style object
var o=document.getElementById(sId);
if(o!=null){try{o.style.display='none'}catch(ierr){ierr=0}}; 
}


// 040301 somerg added to library from histnav
function surfto(form) {
var myindex=form.select1.selectedIndex
if (form.select1.options[myindex].value != 0) {
location=form.select1.options[myindex].value;}
}


// display library version
function mLibVer() { 
 alert("Client-side library version " + gLibVer)
}


//Start of scripts for lookup on demand*******************************************************************************

function loadLookup(iT,srcFile,name,xName,sVal,tWait,sFlds) {
// 270406 type 1 in profiler and search field not posting so changed to item at a time
/*		Arguments:
			iT			: type 1 LUOD 3/4 dynamic/filter
			srcFile	: URL/Filename of source to load into hidden frame.
			name		: name of target element to replace
			xName		: name of source element in hidden frame to copy (same as name)
			tWait		: number of seconds before giving up
			sVal		: Current Value
	*/
srcName=xName;
url=srcFile;
elTarget = document.all[name];
if (elTarget!=null) {
 var iOptCount=elTarget.options.length;
 var iOptCurr=elTarget.value;
 var iOptCurrIdx=elTarget.selectedIndex
 var sOptCurrDescr=elTarget.options(iOptCurrIdx).text
 var bLd
 if(iT==1){bLd=elTarget.bl} else {bLd=0};
// bLd=elTarget.bl;

 // alert(iOptCount + ' options. current is ' + iOptCurr + ' descr is ' + sOptCurrDescr);
// if (iOptCount<3) { // assume we havent done it
// alert(bLd);
 if (bLd==0) { //  havent done it
  //this.window.status='One moment...';
  elTarget.options(iOptCurrIdx).text='loading .';
  iframeWin = window.frames.hidden;
  // if dynamic then add the field
  if(iT==1){
   url=srcFile;
  } else {
   sVal=v(sFlds);
   url=srcFile+'&FVE0='+sVal;
   //dummy=window.prompt('url',url);
  } // end if 
  iframeWin.location.replace(url);
  // setup the failure timer
  bBailOut=0;
  var tOutms=tWait * 1000
  gBailOutId=setTimeout('bailOut()',tOutms);
  // setup the fetch in an interval timer
  gLUODsrcName=xName;
  gLUODtrgName=name;  
  gLUODcurVal=iOptCurr;
  gLUODcurIdx=iOptCurrIdx;
  gLUODiT=iT;
  gLUODcurDescr=sOptCurrDescr;
//  myInterval=setInterval('getEl()',400); // try every half second
  gTimerId=setInterval('getEl()',400); // try every half second
 } ; // End If
} ; // End If
} // End Function

var gilL2state=new Number(0);

function loadLookup2(iDynCount,tWait,sURLIn,sValFld,sTypes,sSources,sTargets,iDev){
// 210507 support multiple targets
clearTimeout(gBailOutId); //210607
clearInterval(gTimerId); //210607
gilL2state=1;
var sVal=v(sValFld);
gLUDynSourceNames=new Array(iDynCount);
gLUDynTargNames=new Array(iDynCount);
gLUDynTargLengths=new Array(iDynCount);
gLUDynTargCurrVals=new Array(iDynCount);
gLUDynTargCurrIdxs=new Array(iDynCount);
gLUDynTargCurrDescs=new Array(iDynCount);
gLUDynTypes=new Array(iDynCount);
var ss=new String(sTargets);
var iTargets=ss.split(',');
var ss=new String(sSources);
var iSources=ss.split(',');
var ss=new String(sTypes);
var iTypes=ss.split(',');
for(i=0;i<iDynCount;i++){
 var sSourceName=new String('E'+(iSources[i]));
 gLUDynSourceNames[i]=sSourceName;
 var sTargName=new String('E'+(iTargets[i]));
 gLUDynTargNames[i]=sTargName;
 gLUDynTypes[i]=iTypes[i];
 var o=document.forms[0].elements[sTargName];
 if(o!=null){
  // 050608 
  if(iTypes[i]==36){
   //alert('Dynamic Multipick');
   var sContentDiv='div-cnt-' + iTargets[i];
   document.getElementById(sContentDiv).innerText='Loading...';
   gLUDynTargNames[i]=iTargets[i];//sContentDiv;
   var sFld='E'+iTargets[i];
   sFE(sFld,'');
  }else{
   gLUDynTargLengths[i]=o.options.length;
   gLUDynTargCurrVals[i]=o.value;
   gLUDynTargCurrIdxs[i]=o.selectedIndex;
   gLUDynTargCurrDescs[i]=o.options[gLUDynTargCurrIdxs[i]].text
   o.options[o.selectedIndex].text='loading .';
  }//end if iType[i]
  //}else{ alert('unexpected null value for ' + sTargName); 
 }
}//next
// build the URL
giLUDynRequestId=giLUDynRequestId+1;
var sURL=sURLIn +'&SEQ=' + giLUDynRequestId +'&FVE0='+escape(sVal);
//050608 add mode for Dynamic Multipick
sURL=sURL+'&MM='+gFE('mM');
if(iDev==1){
 window.prompt(sURL,sURL)
}else{ 
 var iframeWin = window.frames.hidden;
 //window.prompt(sURL,sURL)
 iframeWin.location.replace(sURL);
 // setup the failure timer
 bBailOut=0;
 var tOutms=tWait * 1000
 gBailOutId=setTimeout('bailOut()',tOutms);
 gTimerId=setInterval('getFrame()',400); // try every half second
}//end if iDev
} // End Function



function bailOut() {
bBailOut=1 ;
// alert('Bail Out');
//clearInterval(myInterval);
clearInterval(gTimerId);
window.status='Could not retrieve option list'; //210607
gilL2state=0;//160707
} // end function

//var glgetFrameTick=new Number(0);

function getFrame(){//210507
gilL2state=5;
// frame has form element SEQ = giLUDynRequestId
//glgetFrameTick=glgetFrameTick+1;
//window.status=glgetFrameTick;
if (bBailOut==1) { // timed out
 clearInterval(gTimerId);
// alert('timed out');
 window.status='Could not retrieve option list';
} else {
 //alert('looking at ' + gLUODsrcName);
 // looking at SEQ form field var srcEl = window.frames.hidden.document.all(gLUODsrcName); 
 // window.status=window.status+'.';
 var iSeq=0;
 if(gilL2state==5){
  try{iSeq=window.frames.hidden.document.forms[0].SEQ.value}catch(e){iSeq=0};
  if(gilL2state==5){
   if(iSeq==giLUDynRequestId){//we've got it
    clearTimeout(gBailOutId);
    clearInterval(gTimerId);
    gilL2state=6;
    setDYN(); 
    //alert('sorted');
   }// if(gilL2state==5){
  }//gilL2state
 }else{
  // traverse targets
  for(i=0;i<gLUDynTargNames.length;i++){
   var o=document.forms[0].elements[gLUDynTargNames[i]];
   var sMsg=new String(o.options(gLUDynTargCurrIdxs[i]).text);
   o.options(gLUDynTargCurrIdxs[i]).text=sMsg+'.';
  }//next
 }//End If got it
}// End If (bailout)
}// End Function

function getEl() {
// return the element with the name srcName from the hidden frame
// if it is complete
// time out after tOut seconds and return null
if (bBailOut==1) { // timed out
 clearInterval(gTimerId);
// alert('timed out');
 window.status='Could not retrieve option list';
} else {
//alert('looking at ' + gLUODsrcName);
 var srcEl = window.frames.hidden.document.all(gLUODsrcName); 
 // window.status=window.status+'.';
 if (srcEl!=null) {
  var s=srcEl.readyState;
  //  alert (s);
  if (s=='complete') {
   clearTimeout(gBailOutId);
   clearInterval(gTimerId);
   setLUOD(); 
   // alert('sorted');
  } else {
  elTarget = document.all(gLUODtrgName);
  var sMsg=new String(elTarget.options(gLUODcurIdx).text)
  elTarget.options(gLUODcurIdx).text=sMsg+'.'
  }; // End if (complete)
 } else {
  elTarget = document.all(gLUODtrgName);
  var sMsg=new String(elTarget.options(gLUODcurIdx).text)
  elTarget.options(gLUODcurIdx).text=sMsg+'.'
 }; // End If (object)
}; // End If (bailout)
} // End Function

function setDYN(){//210507 support multiple target fields
if(gilL2state>5){
gilL2state=8;
for(i=0;i<gLUDynTargNames.length;i++){
 if(gilL2state==8){ //gilL2state will change if another request
// try{
  if(gLUDynTypes[i]==36){
   //var sContentDiv=gLUDynTargNames[i];
   var sContentDiv='div-cnt-' + gLUDynTargNames[i];
   document.getElementById(sContentDiv).innerHTML=window.frames.hidden.document.getElementById(sContentDiv).innerHTML;
   var sCtl='E'+gLUDynTargNames[i];
   var sVal=window.frames.hidden.document.forms[0].elements[gLUDynSourceNames[i]].value;
   sFE(sCtl,sVal); // set Default Value 
  }else{
  var otrg=document.forms[0].elements[gLUDynTargNames[i]];
  var osrc=window.frames.hidden.document.forms[0].elements[gLUDynSourceNames[i]];
  if ((osrc!=null) && (otrg!=null)) {
   var sCurr=gLUDynTargCurrVals[i];
   var bSel=false;
   //for(j=otrg.options.length;j>=0;j--)otrg.options[j]=null; //clear target
   otrg.options.length=0;
   var el=document.createElement("option");;
   el.value="";
   el.text="";
   if (document.all) { otrg.add(el); } else { otrg.add(el,null); }
   l=osrc.length;
   // alert(l);
   var iOK=new Number(1);
   for(j=0;j<l;j++){
    //  alert(j);
    iOK=1;
    try{var osrcopt=osrc.options[j]}catch(ierr){iOK=0};
    if(iOK==1){
    el=document.createElement("option");
    if(osrcopt.value!=null){
     el.value=osrcopt.value;
     el.text=osrcopt.text;
     if(sCurr!=null){if(el.value==sCurr){el.selected=true;bSel=true;};};
    if (document.all) { otrg.add(el); } else { otrg.add(el,null); }
    }
    } 
    } // next 
 //}else{alert('missing object') 
 }//both objects
   }//Type 
//    }catch(ierr){}
   } //gilL2state

}//next
} // gilL2state>6
gilL2state=0;//160707
} // end function

function syncLU(sMain,sSupp){//1307070 sync supplementary Lookups
// selectedIndex property is r/w
try{
 document.forms[0].elements[sSupp].selectedIndex=document.forms[0].elements[sMain].selectedIndex
}
catch(e){}//alert(e.message)}
}

function setLUOD() {
var osrc=window.frames.hidden.document.all(gLUODsrcName); 
var otrg=document.all(gLUODtrgName);
if ((osrc!=null) && (otrg!=null)) {
 if(gLUODiT==111){ // 270406 try option at a time for type 1 as well
 s=new String(osrc.outerHTML);
 //s=s.toLowerCase();
 sCurr=gLUODcurVal;
 if (sCurr) { // there is a selected value
//  alert (sCurr);
  sFind=new String("value="+sCurr);
  sReplace=sFind+" selected";
//  alert('look for -'+sFind+'-');
  s=s.replace(sFind,sReplace);
 } // end if (sCurr)
 otrg.outerHTML=s;
 // set the loaded flag
 //  may not be needed as is in the html ?
} else { // iT 3 or 4 need to load element at a time
 // alert(gLUODiT); 
 // o[i]=new Option(T,V,d,s) text/value/default select/selected
 // for (var q=controlToPopulate.options.length;q>=0;q--) controlToPopulate.options[q]=null;
 sCurr=gLUODcurVal;bSel=false;
 for(i=otrg.options.length;i>=0;i--)otrg.options[i]=null; //clear target
 var el;
 var osrcopt;
 el=document.createElement("option");
 el.value="";
 el.text="";
 otrg.add(el);
 l=osrc.length;
// alert(l);
 for(i=0;i<l;i++){
//  alert(i);
  osrcopt=osrc.options[i];
  el=document.createElement("option");
  if(osrcopt.value!=null){
   el.value=osrcopt.value;
   el.text=osrcopt.text;
   if(sCurr!=null){if(el.value==sCurr){el.selected=true;bSel=true;};};
   otrg.add(el);
  } 
 } // next 
 if(bSel==false){
 // clear previous value if(sCurr!=null){
 //  otrg.options[0].value=sCurr;
 //  otrg.options[0].text=gLUODcurDescr;
 //  otrg.options[0].selected=true;
 // };
 };
 if(gLUODiT==1){otrg.bl=1} // 270406 try option at a time for type 1 as well - flag loaded
} // end if (iT==1)
} // end if (2 objects)
} // end function

//End of scripts for lookup on demand*******************************************************************************




//DK 050401

/* Dateline script */

function showDate(sd) {
var days=new Array(8)
days[1]="Sunday";
days[2]="Monday";
days[3]="Tuesday";
days[4]="Wednesday";
days[5]="Thursday";
days[6]="Friday";
days[7]="Saturday";
var time=new Date(sd);
var day=days[time.getDay() + 1];

var months=new Array(13);
months[1]="January";
months[2]="February";
months[3]="March";
months[4]="April";
months[5]="May";
months[6]="June";
months[7]="July";
months[8]="August";
months[9]="September";
months[10]="October";
months[11]="November";
months[12]="December";
//var time=d //new Date();
var month=months[time.getMonth() + 1];
var date=time.getDate();
var year=time.getYear();
if (year < 2000)
year = year + 1900;
document.write(day + ", " + date + " " + month + " " + year);

}

/* End of Dateline script */



/* Deletion Confirm Function */

function confdel()
{
var iA=v('mA');
if (iA==null) {iA=0};
if (iA<0) {iA=0};
// alert('active layer is '+iA);
ss=new String(v('mN'+iA));
// alert (ss);
s=ss.split(';');
j=s.length;
if (j >=13) {
 rec=s[13];vw=s[12];
} else {
 rec='Record';vw='View';
} // end if

var confirm=window.confirm("Click OK to Delete '" + rec + "' from '" + vw + "' or Cancel to Cancel Deletion");
if (confirm)
{
 return true ;
}
else
{
	return false;
}
}
/* End Deletion Confirm */



function sCurrentTime(){// return current time hh:mm:ss 
dt = new Date(); 
hours = sFN(dt.getHours());
minutes = sFN(dt.getMinutes());
seconds = sFN(dt.getSeconds());
var a= hours + ":" + minutes + ":" + seconds;
return a;
}

function sFN(n){if(n<10){return '0'+n}else{return n}}

function sIFState(i){
// 0-initial 1-active 2-inactive 3-warning 4-timedout
switch (i) {
 case 1: 
  return 'active'; 
  break;
 case 2: 
  return 'inactive'; 
  break;
 case 3: 
  return 'timing out soon'; 
  break;
 case 4: 
  return 'timed out'; 
  break;
 default:
  return 'initial';
} // end switch 


} // end function


function bIE(){
var agent = navigator.userAgent;
var browser;
browser = "MSIE";
if (agent.indexOf(browser) >= 0) {return true}else{return false}
}
function Browser() {
	//120107 RMCK - BROWSER DETECTION CODE
	/* This method is referenced from the variable browser, which instantiates it.
	 * It has no parameters or returns, but it has two public variables
	 * isIE - true if browser identifies as Internet Explorer
	 * isFF - true if browser identifies as Netscape or Gecko (Firefox)
	 * For Example
	 * 
	 * if(browser.isIE) {
	 *  	//Browser is Internet Explorer! }
	 * if(browser.isFF) {
	 *      //Browser is Netscape/Firefox! }
	 */
	 
	var agent = navigator.userAgent;
	var browser;

	this.isIE = false;
	this.isFF = false;
  
	browser = "MSIE";
	if (agent.indexOf(browser) >= 0) { this.isIE = true; }

	browser = "Netscape6/";
	if (agent.indexOf(browser) >= 0) { this.isFF = true; }

	browser = "Gecko";
	if (agent.indexOf(browser) >= 0) { this.isFF = true; }
}

// 140207 functions to return correct size information regardless of browser version and doctype
function cBodyWidth() {
  var width = 0;
  if( document.documentElement && document.documentElement.clientWidth ) {
    width = document.documentElement.clientWidth;
  }
  else if( document.body && document.body.clientWidth ) {
    width = document.body.clientWidth;
  }
  else if( window.innerWidth ) {
    width = window.innerWidth - 18;
  }
  return width;
};

function cBodyHeight() {
  var height = 0;
  if( document.documentElement && document.documentElement.clientHeight ) {
    height = document.documentElement.clientHeight;
  }
  else if( document.body && document.body.clientHeight ) {
    height = document.body.clientHeight;
  }
  else if( window.innerHeight ) {
    height = window.innerHeight - 18;
  }
  return height;
};

function cBodyScrollX() {//measures position of scrollbar
  var scrollX = 0;
  if( document.documentElement && document.documentElement.scrollLeft ) {
    scrollX = document.documentElement.scrollLeft;
  }
  else if( document.body && document.body.scrollLeft ) {
    scrollX = document.body.scrollLeft;
  }
  else if( window.pageXOffset ) {
    scrollX = window.pageXOffset;
  }
  else if( window.scrollX ) {
    scrollX = window.scrollX;
  }
  return scrollX;
};

function cBodyScrollY() {
  var scrollY = 0;
  if( document.documentElement && document.documentElement.scrollTop ) {
   scrollY = document.documentElement.scrollTop;
  }
  else if( document.body && document.body.scrollTop ) {
    scrollY = document.body.scrollTop;
  }
  else if( window.pageYOffset ) {
    scrollY = window.pageYOffset;
  }
  else if( window.scrollY ) {
    scrollY = window.scrollY;
  }
  return scrollY;
};
function cBodyScrollWidth() {
// somerg 260407 I need scrollWidth rather than scrollLeft
  var scrollX = 0;
  if( document.documentElement && document.documentElement.scrollWidth ) {
    scrollX = document.documentElement.scrollWidth;
  }
  else if( document.body && document.body.scrollWidth ) {
    scrollX = document.body.scrollWidth;
  }
  else if( window.pageXOffset ) {
    scrollX = window.pageXOffset;
  }
  else if( window.scrollX ) {
    scrollX = window.scrollX;
  }
  return scrollX;
};

//190607 somerg
function cBodyValWSAH(){
return window.screen.availHeight
}
function cBodyValWSAW(){
return window.screen.availWidth
}

function cBodyValWH(){
var s =new String(document.compatMode);
var j=s.indexOf('CSS');
if(j>=0){ // dtd 
 if(bIE()){return document.documentElement.clientHeight}else{return window.innerHeight}
}else{ // no dtd
 return document.body.clientHeight; 
}
}


// 260407 somerg
function cBodyValSW(){// scrollWidth
var s =new String(document.compatMode);
var j=s.indexOf('CSS');
if(j>=0){ // dtd 
 return document.documentElement.scrollWidth; 
}else{ // no dtd
 return document.body.scrollWidth; 
}}
function cBodyValCW(){//clientWidth
var s =new String(document.compatMode);
var j=s.indexOf('CSS');
if(j>=0){ // dtd 
 return document.documentElement.clientWidth;
}else{ // no dtd
 return document.body.clientWidth; 
}}
function cBodyValSH(){// scrollHeight
var s =new String(document.compatMode);
var j=s.indexOf('CSS');
if(j>=0){ // dtd 
 if(bIE()){
  return document.documentElement.scrollHeight
 }else{
  return document.body.clientHeight
 } 
}else{ // no dtd
 return document.body.scrollHeight; 
}}
function cBodyValCH(){
var s =new String(document.compatMode);
var j=s.indexOf('CSS');
if(j>=0){ // dtd 
 if(bIE()){return document.documentElement.clientHeight}else{return window.innerHeight;}; // doc height
}else{ // no dtd
 return document.body.clientHeight; // doc height
}}
function cBodyValCW2(oWin){//clientWidth of window object (parent)
var s =new String(document.compatMode);
var j=s.indexOf('CSS');
if(j>=0){ // dtd 
 return oWin.document.documentElement.clientWidth;
}else{ // no dtd
 return oWin.document.body.clientWidth; 
}}


//190307 exam timer

function onShort(){
if (giqm==2){

}else{
var a=time_left.style.color;
if(a=='red'){
 time_left.style.color='white';
}else{
 time_left.style.color='red';
}
giflash=giflash+1;
if(giflash<9){window.setTimeout("onShort()", 100);}
}}

function onSecond()
{
giflash=0;
var iTGone= getFormElementValue('QU_TT');
var iTTot=getFormElementValue('QU_TA');
var iTTG=iTTot-iTGone;
if(giqm>2){//020507

if (iTTG<1){
 progBar_rightBubble.className='pmTO'
 progBar_midBubble.className='pmTOl'
 progBar_leftBubble.className='pmTOl'
 setElementInnerText('time_left_label','Timed Out');
 time_left.style.color='red';
 time_left_label.style.color='red';
 var ow=window.opener;
 if(ow!=null){window.close()}else{sbc('t','','1980')};
}else{ 
 iTGone=Math.abs(iTGone)+1;
 setFormElementValue('QU_TT',iTGone);
 iTTG=iTTot-iTGone;
 if (iTTG < 60){window.setTimeout("onShort()", 100);}
 setBar(giqm);
 window.setTimeout("onSecond()", 1000);
}// iTTG<1
}else{
 if(giqm==2){
  iTGone=Math.abs(iTGone)+1;
  setFormElementValue('QU_TT',iTGone);
  iTTG=iTTot-iTGone;
  if (iTTG < 30){window.setTimeout("onShort()", 100);}
  setBar(giqm);
  window.setTimeout("onSecond()", 1000);
 }//endif giqm=2
}//giqm>2
}

function getBarTime(dt) {
	//	Given a date delta value, return MM:SS if less than an hour or HH:MM:SS if greater than an hour.
	var barTime;
	barTime = '00:00';
	
	if (dt!=null) {
		barTime = sFN(dt.getMinutes()) + ':' + sFN(dt.getSeconds());
		if (dt.getHours() > 0) { barTime = sFN(dt.getHours()) + ':' + barTime; }
	}
	return barTime;
}

//190307 progress bar for exams
function setBar(iqm){
// iqm=2 for call timer
// iqm=3 for timed exam
var iExtentX=300;
if(iqm==2){iExtentX=100}; //150507
var iBX=26;

var iQDone=getFormElementValue('QU_QD');
var iQTot=getFormElementValue('QU_QC');
var iQToGo=iQTot-iQDone;
setElementInnerText('quest_left',iQToGo);

if(iqm>1){
 var iTGone=getFormElementValue('QU_TT');
 var iTTot=getFormElementValue('QU_TA');
 if(iqm==2){//020507
  var dt=new Date(iTGone*1000);
  var a=getBarTime(dt);
  setElementInnerText('time_taken',a);
  var dt=new Date(iTTot*1000);
  var a=getBarTime(dt);
  setElementInnerText('time_target',a);
  // problem ! if(iTGone>iTTot){iTGone=iTTot}//stop progbar overflowing
 }else{
  var iTTG=iTTot-iTGone;
  var dt=new Date(iTTG*1000);
  var a=getBarTime(dt);
  setElementInnerText('time_left',a);
 }
}else{
 setElementInnerText('time_left_label','');
 setElementInnerText('time_left_sep','');
 var iTTot=0;
}

// leftBubble-leftTube-midBubble-rightTube-rightBubble
// if bubble hidden add 26px to tube
var iElapsed=0;

if(iTTot>0){
 iElapsed=Math.round(iTGone/iTTot*(iExtentX+iBX))
 if(iElapsed>(iExtentX+iBX)){//020507
  iElapsed=iExtentX+iBX;
  if(iqm==2){
   time_taken_label.style.color='red';
   time_taken.style.color='red';
  }
 } 
}



if (iQDone<1){// if none answered then hide leftTube and midBubble
 progBar_leftTube.style.width=0;
 pbLElapsed.style.width=0;
 var iRElapsed=iElapsed;
 pbRElapsed.style.width=iRElapsed; 
 var ir=iExtentX+iBX-iRElapsed;
 progBar_rightTube.style.width=ir;
 progBar_midBubble.style.display='none';
}else{
 if (iQToGo<1){// if all answered then hide rightTube and rightBubble
  var iLElapsed=iElapsed;
  pbLElapsed.style.width=iLElapsed;
  progBar_leftTube.style.width=iExtentX+iBX-iLElapsed;
  progBar_rightTube.style.width=0;
  progBar_rightBubble.style.display='none';
 }else{
  if (iQDone==1){   // no left tube
   progBar_leftTube.style.width=0;
   var iRElapsed=iElapsed;
   iRElapsed=iRElapsed-iBX;if(iRElapsed<1){iRElapsed=0};//compensate for width of ball
   pbLElapsed.style.width=0;
   pbRElapsed.style.width=iRElapsed;
   progBar_rightTube.style.width=iExtentX-iRElapsed;
   progBar_midBubble.style.display='inline';
  }else{
   if (iQToGo==1){ // no right tube
    var iLElapsed=iElapsed;
    if (iLElapsed>=iExtentX){iLElapsed=iExtentX};
    pbLElapsed.style.width=iLElapsed;
    progBar_leftTube.style.width=iExtentX-iLElapsed;
    progBar_rightTube.style.width=0;
   }else{
    var il=iQDone/iQTot*iExtentX;
    var iLElapsed=iElapsed;
    if (iLElapsed>il){
     var iRElapsed=iLElapsed-il;
     iLElapsed=il;
     il=0;
    }else{
     il=il-iLElapsed; 
     iRElapsed=0;
    }
    if (iRElapsed<iBX){iRElapsed=0}else{iRElapsed=iRElapsed-iBX};
    var ir=iExtentX-iLElapsed-il-iRElapsed;
    pbLElapsed.style.width=iLElapsed;
    progBar_leftTube.style.width=il;
    pbRElapsed.style.width=iRElapsed;
    progBar_rightTube.style.width=ir;
}}}}
}// end function



function sessBlur(){
// div is syssesslock0
// class is syssesslock
document.body.onmousemove=omm;
//document.body.onmouseout=sessBlur_Warn;
//document.ondeactivate=omm;
glbX=cBodyWidth();
glbY=cBodyHeight();
document.onkeydown=okd;
}
function okd(evt){
evt = (evt) ? evt : ((event) ? event : null);
if (evt) {
 var i = evt.keyCode;
 if(i==18){sessBlur_Warn()};//Alt
 if(i==17){sessBlur_Warn()};//Ctrl
 if(i==16){sessBlur_Warn()};//Shift
}}

function ontabfocus(){// 010507 accesskey for tab clicks link
window.event.srcElement.click();
}

function omm(){
var lbord=50;
var rbord=19;
var ybord=50;
if (giomm==0){
 giomm=1;
 //var o=window.event.srcElement;
 //var a='';
 //if(o!=null){a=o.name};
 //if(o!=null){a=a+o.tagName};
 var lcX=window.event.clientX;
 var lcY=window.event.clientY;
 var b=false;
 if(lcX<lbord){
  b=true
 }else{
  if(lcX>(glbX-rbord)){
   // 240907 allow RHS b=true
  }else{
   if(lcY<ybord){
    b=true
   }else{
    if(lcY>(glbY-ybord)){
     b=true
 }}}}   
 //setElementInnerText('time_left_label',''+lcX+' '+lcY+' '+a+glbX+' '+glbY);

 if(gipost==0){
  if(b){if(giblurmode==0){sessBlur_Warn()}};
 }}
 giomm=0;
}
function sessBlur_Warn(){
if (giblurmode==0){//210907
showLayer('syssesslock0_DRAG');
giblurmode=1;
giblurtime=15;//270907 
setElementInnerText('sessBlur_label',giblurtime);//240907
window.setTimeout("sessBlur_Countdown()", 1000);
}}

function sessBlur_Countdown(){
if(giblurmode==1){
 giblurtime=giblurtime-1;
 if (giblurtime<1){
  setFormElementValue('QU_X','X');
  var ow=window.opener;
  if(ow!=null){window.close()}else{sbc('t','','1980')};
 }else{
  setElementInnerText('sessBlur_label',giblurtime);
  window.setTimeout("sessBlur_Countdown()", 1000);
}}}

function sessBlur_OK(){
// div is syssesslock0
// class is syssesslock
giblurmode=0;
hideLayer('syssesslock0_DRAG');
}

function autoTab(obj,e){
try{
var replaceText = new String("");
if(e.keyCode==9 || e.keyCode==16){
	 // tab/shift should behave normally
}else{
 if (e.keyCode == 107 || e.keyCode == 13) { //the . symbol has 2 different ways of being pressed on standard keyboards.
  replaceText = obj.value;
  obj.value = replaceText.replace("\+","");
  document.forms[0].elements[getFormIdx(obj)+1].focus(); // set focus to next element
 }else{
  if(obj.value.length==obj.size){
   document.forms[0].elements[getFormIdx(obj)+1].focus(); // set focus to next element
  }
 } // end if Enter/+
} // end if tab/shift
}catch (e){
 //alert(e.message)
 } 
} // end function
function getFormIdx(input) { // get index searches your form for a match
	var index = new Number(0);
	for(index = 0; index < document.forms[0].length; index++) { // while we still have form elements
	 if (document.forms[0].elements[index] == input) {
	 return index;
	 } // end if
	} // end for loop
} // end function getIndex
