//note - msgbox does not sleep execution
preloadlist('vgfxa/helpicon3.gif;vgfxa/helpicon3b.gif;vgfxa/helpicon3c.gif;vgfxa/waiting.gif');
var sessiontimeoutwarning_percent=.2;
var sessiontimeoutwarning_minimum=30;

var msgbox_width,titlecolor,titleshadowcolor, dobgfade=true;
var msgbox_styles=new Array();//2nd dimension: msgbox_width, titlecolor, titleshadowcolor, fadebg
//msgbox_styles[0]=[500,'#EEEE00','#888844'];//default style
msgbox_styles[0]=[500,'#FFCF91','#886A44',true];//default style
msgbox_styles[1]=[680,'#CDE2FF','#455A77',true];
msgbox_styles[2]=[520,'#CDE2FF','#455A77',true];
msgbox_styles[3]=[500,'#FFCF91','#886A44',false];
msgbox_loadstyle(0);

var msgbox_buttonlist = Array('Ok','Continue','Cancel','Yes','No','Close');
var msgbox_b_ok=0, msgbox_b_continue=1, msgbox_b_cancel=2, msgbox_b_yes=3, msgbox_b_no=4, msgbox_b_close=5;

var showhelppane=false;
var currenthelpid=0;
var lasthelpid=0;
var thisbid=0;

var mbsid=0;//msgbox_stackid - 1 Based, not 0 Based!!! 0 is reserved for the fader div on some arrays
var mbsmaxstack=5;
var msgbox_bid=new Array(-1,-1,-1,-1,-1,-1);
var msgbox_callback=new Array('','','','','','');
var msgbox_typeid=new Array(0,0,0,0,0,0);
var closeonclick=new Array(true,true,true,true,true,true);
var msgbox_lastx=new Array(0,0,0,0,0,0);
var msgbox_lasty=new Array(0,0,0,0,0,0);
var lastmsgboxwindowtitle=new Array('','','','','','');
var msgbox_currentid=new Array(0,0,0,0,0,0);
var referenceobj=new Array();
var currentehelpswitchid=new Array(0,0,0,0,0,0);
var mb_obj=new Array(1,1,1,1,1,1);//left off - change arrays to mbfaderdiv,mbdiv
var mb_interval=new Array();
var mb_fadecount=new Array(0,0,0,0,0,0);
var mb_opacityfctr=new Array(.5,1,1,1,1,1);
var mb_fadestep=new Array(20,20,20,20,20,20);
var msgboxisopen=new Array(false,false,false,false,false,false);

var switchid_1=1;
var switchid_2=2;
var switchid_3=4;
var switchid_4=8;
var switchid_5=16;
var switchid_6=32;
var switchid_7=64;
var updatems=30;
var addx=10,addy=0;
var windowmaxx=0,windowmaxy=0;
var cursorx=0,cursory=0;
var pup=null,pup_content=null;
var doinstantfade=false;

getWindowSize();
getScrollXY();
msgbox_outputdivs();
addloadcommand('msgbox_init()');

var currentstyleid=0;
function msgbox_loadstyle(id){
 msgbox_width=msgbox_styles[id][0];
 titlecolor=msgbox_styles[id][1];
 titleshadowcolor=msgbox_styles[id][2];
 dobgfade=msgbox_styles[id][3];
 currentstyleid=id;
}
function msgbox_outputdivs(){
 var msgboxhtml='';
 for (var i=1;i<=mbsmaxstack;i++){
  msgboxhtml+='<div id="msgboxdiv'+i+'" name="msgboxdiv'+i+'" style="width:'+msgbox_width+';display:none;position:absolute;"></div>';
 } 
 msgboxhtml='<div id="msgboxfaderdiv" name="msgboxfaderdiv" style="display:none;position:absolute;background:#999999;"></div>'+msgboxhtml;
 document.write(msgboxhtml);
 var smallpanehtml='<div id="pupdiv" name="pupdiv" style="width:350;display:none;position:absolute;" onmouseover="mouseoverpop();" onmouseout="domouseout();"></div>';
 document.write(smallpanehtml);
}
function msgbox_init(){
 mb_obj[0]=getobj('msgboxfaderdiv');
 for (var i=1;i<=mbsmaxstack;i++){
  mb_obj[i]=getobj('msgboxdiv'+i);
 }
}
function getlastknownmbsid(){
 var thismbsid=mbsmaxstack;
 for (var i=mbsmaxstack;i>=1;i--){
  if (msgboxisopen[i]){
   thismbsid=i;
   break;
  }
 }
 return thismbsid;
}
function setavailablembsid(){//sets mbsid to the next available spot
 mbsid=1;
 for (var i=1;i<=mbsmaxstack;i++){
  if (!msgboxisopen[i]){
   mbsid=i;
   break;
  }
 }
}
function msgboxesareopen(){
 for (var i=mbsmaxstack;i>=1;i--){
  if (msgboxisopen[i])
   return true;
 }
 return false;
}

function msgbox_destroy(id){
 mb_obj[id].style.display='none';
 setopacity(mb_obj[id],0);
 clearInterval(mb_interval[id]);
 changetext(mb_obj[id],'');
 if (id>=1){
  msgboxisopen[id]=false;
  mbsid=getlastknownmbsid();
  if (!msgboxesareopen())
   mb_fadeboxout(0);//fade out background now that all msgboxes are invisible
 }
 if (!msgboxesareopen())
  togglecontenttohide(1);
}

function mb_fadeboxin(id,thisfadevalue){
 if (!msgboxisopen[(id==0)?1:id]) return;
 if(w3c){
  clearInterval(mb_interval[id]);
  if (thisfadevalue==null)
   mb_fadecount[id]=0;
  else
   mb_fadecount[id]=thisfadevalue/mb_opacityfctr[id];
  if (dobgfade){
   if (dofx((id==0)?1:0)){
    setopacity(mb_obj[id],mb_fadecount[id]*mb_opacityfctr[id]);
    mb_obj[id].style.display='block';
    mb_interval[id]=setInterval('mb_sub_fadein('+id+')',15);
    getspeeddiff();
   } else {
    setopacity(mb_obj[id],100*mb_opacityfctr[id]);
    mb_obj[id].style.display='block';
    if (id>=1)//fade in background now that msgbox is visible
     mb_fadeboxin(0,100);
   }
  } else {
   setopacity(mb_obj[id],100);
   mb_obj[id].style.display='block';
  }
 }
}
function mb_fadeboxout(id){
 var thisfadevalue=getopacity(mb_obj[id]);
 if(w3c){
  clearInterval(mb_interval[id]);
  if (doinstantfade || !dofx((id==0)?1:0)){
   msgbox_destroy(id);
  } else {
   if (thisfadevalue==null)
    mb_fadecount[id]=100;
   else
    mb_fadecount[id]=thisfadevalue/mb_opacityfctr[id];
   setopacity(mb_obj[id],mb_fadecount[id]*mb_opacityfctr[id]);
   mb_obj[id].style.display='block';
   if (dofx((id==0)?1:0)){
    mb_interval[id]=setInterval('mb_sub_fadeout('+id+')',15);
    getspeeddiff();
   } else {
    msgbox_destroy(id);
   }
  }
 }
}
function mb_sub_fadein(id){
 if (!msgboxisopen[(id==0)?1:id]) return;
 mb_fadecount[id]=mb_fadecount[id]>100-mb_fadestep[id]*.7?100:mb_fadecount[id]+mb_fadestep[id]*.7;
 setopacity(mb_obj[id],mb_fadecount[id]*mb_opacityfctr[id])
 if(mb_fadecount[id]>=99){
  mb_obj[id].style.display='block';
  clearInterval(mb_interval[id]);
  handlespeeddiff(2000,(id==0)?1:0);
  if (id>=1){//fade in background now that msgbox is visible
   clearInterval(mb_interval[0]);
   mb_fadeboxin(0,getopacity(mb_obj[0]));
  }
 }
}
function mb_sub_fadeout(id){
 mb_fadecount[id]=mb_fadecount[id]<0-mb_fadestep[id]?0:mb_fadecount[id]-mb_fadestep[id];
 setopacity(mb_obj[id],mb_fadecount[id]*mb_opacityfctr[id]);
 if(mb_fadecount[id]<=0){
  handlespeeddiff(2000,(id==0)?1:0);
  msgbox_destroy(id);
 }
}


function msgbox_clickedbutton(bid,this_mbsid){
 this_mbsid=(this_mbsid==null)?mbsid:this_mbsid;
 thisbid=bid;//defined for callback ease of use
 msgbox_bid[this_mbsid]=thisbid;
 safeeval(msgbox_callback[this_mbsid]);
 if (closeonclick[this_mbsid]){
  if (document.msgboxform){
   if (document.msgboxform.optout.checked && currentehelpswitchid[this_mbsid]>0){
    sethelpswitch(currentehelpswitchid[this_mbsid]);
   }
  }
  msgbox_close(this_mbsid);
//  currentehelpswitchid[this_mbsid]=0;
//  mb_fadeboxout(this_mbsid);
 }
}
function msgbox_close(this_mbsid,thisid){
 if (this_mbsid==null)
  this_mbsid=mbsid;
 if (thisid!=null){
  if (thisid!=msgbox_currentid[this_mbsid])
   return;
 }
 currentehelpswitchid[this_mbsid]=0;
 mb_fadeboxout(this_mbsid);
 if (!msgboxesareopen())
  togglecontenttohide(1);
}
function msgbox_assigntype(typeid){
 msgbox_typeid[mbsid]=typeid;
}
function msgbox_closetype(typeid){
 doinstantfade=true;
 for (var i=0;i<=mbsmaxstack;i++){
  if (msgbox_typeid[i]==typeid){
   msgbox_close(i);
  }
 }
 doinstantfade=false;
}
function msgbox_doresize(){
 getWindowSize();// gets windowWidth and windowHeight
 getScrollXY();
 var minx=scrollOffsetX;
 var maxx=windowWidth+scrollOffsetX;
 var miny=scrollOffsetY;
 var maxy=windowHeight+scrollOffsetY;
 var docwidth=getpagewidth();
 var docheight=getpageheight();
 if (docheight<windowHeight)
  docheight=document.body.height=windowHeight;
 
 moveit(mb_obj[0],0,0);
 mb_obj[0].style.width=docwidth+'px';
 mb_obj[0].style.height=docheight+'px';
 
 
 for (var i=1;i<=mbsid;i++){
  var msgboxdivwidth=getwidth(mb_obj[i]);
  var msgboxdivheight=getheight(mb_obj[i]);
  var x=(maxx-minx)/2+minx-msgboxdivwidth/2;
  var y=(maxy-miny)/2+miny-msgboxdivheight/2;
  if (referenceobj[i]!=null){
   var pos=findpos(referenceobj[i]);
   x=pos[0]+10;
   y=pos[1]+getheight(referenceobj[i]);
  }
  if ((x+msgboxdivwidth)>=maxx)
   x=maxx-msgboxdivwidth-20;
  if ((y+msgboxdivheight)>=maxy)
   y=maxy-msgboxdivheight-20;
  if (x<minx)
   x=minx;
  if (y<miny)
   y=miny;
  if (msgbox_lastx[i]!=x || msgbox_lasty[i]!=y){
   moveit(mb_obj[i],x,y);
   msgbox_lastx[i]=x;
   msgbox_lasty[i]=y;
  }
 } 
 
}
function mbover(what){
 var obj=what.firstChild;
 obj.style.backgroundColor='#EEEEEE';
 obj.style.borderWidth='2 1px 1px 2';
}
function mbout(what){
 var obj=what.firstChild;
 obj.style.backgroundColor='#D4D4DF';
 obj.style.borderWidth='0 3px 3px 0';
}

function msgbox_setcloseonclick(b){
 closeonclick[mbsid]=b;
}








function msgbox_open(callingobj,windowtitle,explanationhtml,buttonset,callback,helpswitch){
 setavailablembsid();//sets mbsid to next available on stack
 mb_obj[mbsid].style.width=msgbox_width+'px';
 currentehelpswitchid[mbsid]=0;
 msgbox_typeid[mbsid]=0;
 if (helpswitch!=null){
  if (!gethelpswitch(helpswitch) && helpswitch!=switchid_7){//quick solution for switchid_7
   mb_fadeboxout(mbsid);
   thisbid=msgbox_b_continue;//defined for callback ease of use
   msgbox_bid[mbsid]=thisbid;
   safeeval(callback);
   return;
  }
  currentehelpswitchid[mbsid]=helpswitch;
 }
 msgbox_currentid[mbsid]++;
 closeonclick[mbsid]=true;
 window.focus(); 
 var oldopacity=getopacity(mb_obj[mbsid])
 msgboxisopen[mbsid]=true;
 window.onresize=msgbox_doresize;
 window.onscroll=msgbox_doresize;
 referenceobj[mbsid]=callingobj;
 msgbox_callback[mbsid]=(callback==null?'':callback);
 msgbox_bid[mbsid]=-1;
 if (!buttonset||buttonset==null) buttonset=1;
 function addbutton(bsrc){
  var bid,btitle;
  if (typeof bsrc=='object'){
   bid=bsrc[0];
   btitle=bsrc[1];
  } else {
   bid=bsrc;
   btitle=msgbox_buttonlist[bid];
  }
  return '<div onclick="msgbox_clickedbutton('+bid+','+mbsid+')" onmouseover="mbover(this)" onmouseout="mbout(this)" style="float:left;border:solid #BBBBBB;border-width:2px 0 0 2px;cursor:pointer;cursor:hand;"><div class=buttondark style="border:solid #777777;border-width:0 3px 3px 0;text-align:center;padding:1px 20px">'+btitle+'</div></div><div style="float:left;width:15px;">&nbsp;</div>'
 }
 stopflash();
 togglecontenttohide(0);
 getWindowSize();// gets windowWidth and windowHeight
 getScrollXY();
 var minx=scrollOffsetX;
 var maxx=windowWidth+scrollOffsetX;
 var miny=scrollOffsetY;
 var maxy=windowHeight+scrollOffsetY;
 var docwidth=getpagewidth();
 var docheight=getpageheight();
 if (docheight<windowHeight)
  docheight=document.body.height=windowHeight;
 var buttons=''; 
 
 var buttons='';
 if (currentehelpswitchid[mbsid]!=0 && g_so==1)
  buttons+='<form method=POST name="msgboxform" id="msgboxform"><input type=checkbox class=checkbox_clean value=1 id="optout" style="margin-top:10px;"> Don\'t show this message again.</form>'
 buttons+='<table cellpadding=0 cellspacing=5 align=center><tr><td nowrap><div style="float:left;width:15px;">&nbsp;</div>';
 if(typeof buttonset=='string'){
  //format: 104:Button Name 1;105:Button Name 2
  if (buttonset.length>0){
   var barray=buttonset.split(';');
   for (var i=0;i<=barray.length-1;i++){
    var bobj=barray[i].split(':');
    buttons+=addbutton(bobj);
   }
  }
 } else {
  if (buttonset==1){
   buttons+=addbutton(msgbox_b_ok);
  }
  if (buttonset==2){
   buttons+=addbutton(msgbox_b_continue);
  }
  if (buttonset==3){
   buttons+=addbutton(msgbox_b_continue);
   buttons+=addbutton(msgbox_b_cancel);
  }
  if (buttonset==4){
   buttons+=addbutton(msgbox_b_yes);
   buttons+=addbutton(msgbox_b_no);
  }
  if (buttonset==5){
   buttons+=addbutton(msgbox_b_close);
  }
  if (buttonset==6){
   buttons+=addbutton(msgbox_b_cancel);
  }
 }
 buttons+='<div style="clear:left;"></div></td></tr></table>';
  
 var bgcolor='#FFFFFF';
 var textclass='textblack';
 var htmlinner='<div width='+msgbox_width+' class=textbigb style="background-color:'+titlecolor+';text-align:center;color:#444444;border:solid '+titleshadowcolor+';border-width:0 0 1px;">'+windowtitle+'</div><div width='+msgbox_width+' id="msgboxdiv_content" name="msgboxdiv_content" class='+textclass+' style="text-align:center;background-color:'+bgcolor+';padding-top:5px;">'+explanationhtml+' '+buttons+'</div>'
 htmlinner=generateborder_start(htmlinner,msgbox_width,titlecolor,bgcolor,'#404040')
 changetext(mb_obj[mbsid],htmlinner);
 lastmsgboxwindowtitle[mbsid]=windowtitle;
 
 moveit(mb_obj[0],0,0);
 mb_obj[0].style.width=docwidth+'px';
 mb_obj[0].style.height=docheight+'px';
// setopacity(mb_obj[0],oldopacity);
// mb_obj[0].style.display='block';
 setopacity(mb_obj[mbsid],oldopacity);
 mb_obj[mbsid].style.display='block';
 var msgboxdivwidth=getwidth(mb_obj[mbsid]);
 var msgboxdivheight=getheight(mb_obj[mbsid]);
 
 var x=(maxx-minx)/2+minx-msgboxdivwidth/2;
 var y=(maxy-miny)/2+miny-msgboxdivheight/2;
 if (referenceobj[mbsid]!=null){
  var pos=findpos(referenceobj[mbsid]);
  x=pos[0]+10;
  y=pos[1]+getheight(referenceobj[mbsid]);
 }
 
 if ((x+msgboxdivwidth)>=maxx)
  x=maxx-msgboxdivwidth-20;
 if ((y+msgboxdivheight)>=maxy)
  y=maxy-msgboxdivheight-20;
 if (x<minx)
  x=minx;
 if (y<miny)
  y=miny;
 moveit(mb_obj[mbsid],x,y);
 msgbox_lastx[mbsid]=x;
 msgbox_lasty[mbsid]=y;
// if(oldopacity==0){
//  mb_obj[mbsid].style.display='none';
// }
 if (getlastknownmbsid()==1)
  bringfront(mb_obj[0]);
 bringfront(mb_obj[mbsid]);
 mb_fadeboxin(mbsid,oldopacity);
}

function msgbox_dialog_close(callingobj,title,content,helpswitch,callback){
 msgbox_open(callingobj,title,encapsulate(content),5,callback,helpswitch);
}
function msgbox_dialog_continue(callingobj,title,content,helpswitch,callback){
 msgbox_open(callingobj,title,encapsulate(content),2,callback,helpswitch);
}
function msgbox_dialog_ok(callingobj,title,content,helpswitch,callback){
 msgbox_open(callingobj,title,encapsulate(content),1,callback,helpswitch);
}
function msgbox_dialog_cancel(callingobj,title,content,helpswitch,callback){
 msgbox_open(callingobj,title,encapsulate(content),6,callback,helpswitch);
}
function msgbox_dialog_none(callingobj,title,content,helpswitch,callback){
 msgbox_open(callingobj,title,encapsulate(content),-1,callback,helpswitch);
}


function myalert(content){
 var title=domnshow;
 msgbox_open(null,title,encapsulate(content),1);
}
function myconfirmurl(content,url,optionaltitle,helpswitch){
 var title=domnshow;
 if (optionaltitle!=null){
  title=optionaltitle;
 }
 msgbox_open(null,title,encapsulate(content),4,'gourlifpositive(\''+url+'\')',helpswitch);
 return false;
}
function gourlifpositive(url){
 if(positiveresponse())
  gourl(url);
}
function myconfirmjs(content,jspos,jsneg,helpswitch,obj){
 var title=domnshow;
 msgbox_open(obj,title,encapsulate(content),4,'msgboxresponsejshandler(\''+jspos+'\',\''+jsneg+'\')',helpswitch);
 return false;
}
function msgboxresponsejshandler(jsifpositive,jsifnegative){
 if(positiveresponse())
  safeeval(jsifpositive);
 else
  safeeval(jsifnegative);
}
function positiveresponse(){
 return (thisbid==msgbox_b_yes || thisbid==msgbox_b_continue || thisbid==msgbox_b_ok);
}
function encapsulate(c){
 return '<table align=center cellpadding=0 cellspacing=0 style="padding:10 8px;"><tr><td class=textblack align=left>'+c+'</td></tr></table>';
}
function msgbox_sectionhelp(callingobj,helpid,callback){
 var section_title='';
 var section_description='';
 
 var helpdata=gethelprecord(helpid);
 section_title=helpdata[0];
 var extras=helpdata[1];
 section_description=helpdata[2];
 var html='';
 if (section_title==null)
  section_title='Help ID #'+helpid;
 if (section_description==null)
  section_description='Help index not found! Please contact support.';
  
 var m_description='<tr><td class=textblack colspan=2>'+section_description+'<br>&nbsp;</td></tr>';
 var m_mover='';
 var m_extra='';
 if (extras.length>0){
  if (extras.indexOf('<faq>')>=0)
   m_extra='<tr><td class=textblack nowrap valign=top align=right><a href="#">Related FAQ</a>: &nbsp;</td><td class=textblack>Frequently asked questions that relate to this section.<br>&nbsp;</td></tr>';
 }
 if (hasquickhelp){//extras.indexOf('<hp>')>=0 || 
  if (showhelppane)
   m_mover='<tr><td class=textblack nowrap valign=top align=right><a href="#" onclick="disablepopups();return false;" style="color:#FF0000">Disable Quick Help</a>: &nbsp;</td><td class=textblack>Turn OFF Mouse-Over help.<br>&nbsp;</td></tr>';
  else
   m_mover='<tr><td class=textblack nowrap valign=top align=right><a href="#" onclick="enablepopups();return false;">Enable Quick Help</a>: &nbsp;</td><td class=textblack>Turn on Mouse-Over help. Move your mouse over the item in question for a description window.<br>&nbsp;</td></tr>';
 }
 var m_contact='<tr><td class=textblack nowrap valign=top align=right><a href="contactus.asp?helpid='+helpid+'&ts=1">Contact Support</a>: &nbsp;</td><td class=textblack>Contact us if you still need help.</td></tr>';
 var explanationhtml='<table align=center cellpadding=0 cellspacing=0>'+m_description+m_mover+m_extra+m_contact+'</table>';
 msgbox_loadstyle(2);
 msgbox_dialog_close(callingobj,section_title,explanationhtml,0,callback);
 msgbox_loadstyle(0);
}
function gethelprecord(helpid){
 //returns [title,extras,description]
 var lastpos=helpid.lastIndexOf('_');
 if (lastpos==-1) return [,0,];
 var catid=helpid.substring(0,lastpos);
 var detailid=helpid.substring(lastpos+1,helpid.length);
 if (!eval('(self.h'+catid+')')) return [,0,];
 var source=eval('h'+catid);
 var searchfor='~A'+helpid+'~';
 var pos1=source.indexOf(searchfor);
 if (pos1==-1) return [,0,];
 var pos2=source.indexOf('~Z'+helpid+'~',pos1);
 if (pos2==-1) return [,0,];
 var record=source.substring(pos1+searchfor.length,pos2);
 return eval('[\''+record.replace(/'/g,'\\\'').replace(/~mn~/g,'\',\'')+'\']');
}
function helpiconover(what){
 var searchfor='vgfxa/helpicon3.gif';
 if (what.src.indexOf(searchfor)>0)
  what.src='vgfxa/helpicon3b.gif';
}
function helpiconout(what){
 var searchfor='vgfxa/helpicon3b.gif';
 if (what.src.indexOf(searchfor)>0)
  what.src='vgfxa/helpicon3.gif';
}
var waitmbsid=0;//used for "waiting on data" msgbox - on close, make sure we close the right one, not always mbsid
function msgbox_waitfordata(callback){
 var content='<img src=vgfxa/waiting.gif width=37 height=37 align=left hspace=10 vspace=5> Please wait while website data is being transferred. This may take up to twenty seconds to process. If it takes longer than twenty seconds then it might indicate that our servers are too busy. Consider clicking the Cancel button and try again after a brief pause.';
 var laststyleid=currentstyleid;
 msgbox_loadstyle(2);
 msgbox_dialog_cancel(null,'Transferring Website Data... (please wait)',content,0,callback);
 msgbox_loadstyle(laststyleid);
 waitmbsid=mbsid;
}
function msgbox_waitforsave(callback){
 var content='<img src=vgfxa/waiting.gif width=37 height=37 align=left hspace=10 vspace=5> Please wait while your changes are being saved. This may take up to twenty seconds to process. If it takes longer than twenty seconds then it might indicate that our servers are too busy. Consider clicking the Cancel button and try again after a brief pause.';
 var laststyleid=currentstyleid;
 msgbox_loadstyle(2);
 msgbox_dialog_cancel(null,'Saving Changes... (please wait)',content,0,callback);
 msgbox_loadstyle(laststyleid);
 waitmbsid=mbsid;
}
function msgbox_closewait(){
 setTimeout('msgbox_close('+waitmbsid+','+msgbox_currentid[waitmbsid]+')',500);
}







function dopopwatch(){
 if (pup==null)
  pup=getobj("pupdiv");
 if (pup_content==null)
  pup_content=getobj("pupdiv_content");
 
 getScrollXY();
 thisx=cursorx+10;
 thisy=cursory+10;
 relativex=thisx-scrollOffsetX+windowmaxx;
 relativey=thisy-scrollOffsetY+windowmaxy;
 if (relativex>windowWidth)
  thisx-=windowmaxx+20;//relativex-windowWidth;
 if (relativey >windowHeight)
  thisy-=windowmaxy+20;
 if (thisx<0)
  thisx=0;
 if (thisy<0)
  thisy=0;
 moveit(pup,thisx+addx,thisy+addy)
 setTimeout(dopopwatch,updatems);
}
var doingdomouseout=0;
function domouseout(e){
 getWindowSize();
 doingdomouseout=1;
 setTimeout(dodomouseout,1000);
}
function dodomouseout(){
 if (doingdomouseout==1){
  pup.style.display='none';
 }
}
function mouseoverpop(){
 doingdomouseout=0;
}
function domouseover(e,obj) {
 if (!e) var e = window.event;
 doingdomouseout=0
 if (pup==null)
  pup=getobj("pupdiv");
 if (pup_content==null)
  pup_content=getobj("pupdiv_content");
 
 mouseovercontent(this);
 
 if (pup.style.display=='none'){
  pup.style.display='block';
 }
 windowmaxx=getwidth(pup);
 windowmaxy=getheight(pup);
 
	var xcoord = 0;
	var ycoord = 0;
	if (e.pageX || e.pageY) 	{
		xcoord = e.pageX;
		ycoord = e.pageY;
	}
	else if (e.clientX || e.clientY) 	{
		xcoord = e.clientX + document.body.scrollLeft	+ document.documentElement.scrollLeft;
		ycoord = e.clientY + document.body.scrollTop	+ document.documentElement.scrollTop;
	}
 cursorx=xcoord;
 cursory=ycoord;
}
function generalpupinit(){
 if( document.body.captureEvents && Event.MOUSEMOVE ) {//Netscape
   document.body.captureEvents( Event.MOUSEMOVE );
 }
 dopopwatch();
}
function writesmallpanehtml(){
 var bgcolor='#EEEE00';
 var textclass='textblack';
 var htmlinner='<div width=350 id="pup_content" name="pup_content" class='+textclass+' style="text-align:left;background-color:'+bgcolor+';padding-top:2px;"></div>'
 htmlinner=generateborder_start(htmlinner,350,bgcolor,bgcolor,'#404040')
 changetext('pupdiv',htmlinner);
}

function togglepopups(){
 if (showhelppane)
  disablepopups();
 else
  enablepopups();
}
function enablepopups(){
 if (!getobj('helptoggle')){
  currentehelpswitchid[mbsid]=0;
  mb_fadeboxout(mbsid);
  return;
 }
 changetext('helptoggle','Disable Quick Help');
 getobj('helptoggle').className='textlink2';
 getobj('helptoggleimg').src='vgfxa/helpicon3c.gif';
 msgbox_dialog_continue(referenceobj[mbsid],'Popups','<div align=left class=textblack style="padding:5px;">Move your mouse over anything within this page to get detailed description of that element. To turn this feature off, click the Question Mark help button and select the "Disable Quick Help" option.</div>',switchid_1)
 lasthelpid=-1;
 showhelppane=true;
}
function disablepopups(){
 if (!getobj('helptoggle')) return;
 changetext('helptoggle','Enable Quick Help');
 getobj('helptoggle').className='textlink';
 getobj('helptoggleimg').src='vgfxa/helpicon3.gif';
 showhelppane=false;
 msgbox_clickedbutton(0);
}
function helpmousemove(evobj,obj,helpid){
 if (!showhelppane) return;
 currenthelpid=helpid;
 obj.style.backgroundColor='#EEEE00';
 domouseover(evobj,obj);
}
function helpmouseout(evobj,obj){
 obj.style.backgroundColor='';
 domouseout(evobj);
}
function mouseovercontent(what){
 if (!showhelppane) return;
 if (currenthelpid==lasthelpid) return;
 var helpdata=gethelprecord(currenthelpid);
 var title=helpdata[0];
 var content=helpdata[2];
 var html='';
 if (title==null){
  html='<b>Help ID#'+currenthelpid+'</b><br> Help index not found! Please contact support.';
 } else {
  if (title!='')
   html='<b>'+title+'</b><br>';
  html+=content;
 }
 html='<div align=left class=textblack style="padding:5px;">'+html+'</div>'
 changetext('pup_content',html);
 lasthelpid=currenthelpid;
}
function gethelpswitch(id){
 return ((g_hs&id)==id);
}
function sethelpswitch(id){
 var thisurl= g_ur+"vasap_inc/aj_helpswitch.asp?cr="+g_cr+"&id="+id;
 loadXMLurl(thisurl);
 if (gethelpswitch(id))
  g_hs-=id;
}





var sessiontimeoutid=0;
var updategse_callback=null;
function updategse(cb,doupd,neint){
 if (doupd==null) doupd=0;
 if (neint==null) neint=0;
 updategse_callback=cb;
 var thisurl=g_ur+"vasap_inc/aj_checkto.asp?cr="+g_cr+"&doupd="+doupd+"&neint="+neint;
// alert('updategse with doupd='+doupd+' and neint='+neint);
 loadXMLurl(thisurl,null,updategse_done);
}
function updategse_done(responsetext){
 var r=responsetext;//returns actual seconds till session expire
 if (!isnumeric(r)) return;//alert('notnumeric'+r);
 g_sx=r*1;
 if (updategse_callback!=null)
  updategse_callback();
}
function sessiontimeoutwarning(thistid){
 if (thistid!=sessiontimeoutid-1) return;
 //first call server to find out the actual session timeout. May have changed if second browser window open.
 updategse(stwcheckdone);
}
function stwcheckdone(){
 if (g_sx>warnseconds()+10){
  extendsessiontimeout(false);
 } else {
  var minutes=Math.round(warnseconds()/60+.5);
  var content='Within '+printminutes(minutes)+' your session will expire due to inactivity. This happens when you haven\'t clicked anything for a while. By clicking "OK" you will remain signed on for another '+printminutes(Math.round(g_sx/60))+' even if you are inactive. If you do not click OK then you will be automatically signed off and will need to sign on again before you are given access to confidential information.';
  var buttonset='1:OK - Keep me signed on;2:Customize expire time';
  msgbox_open(null,'Session Warning',encapsulate(content),buttonset,'handle_stw_response(thisbid)');
 }
}
function handle_stw_response(bid){
 extendsessiontimeout();
 //if (msgbox_bid[mbsid]==2){
 if (bid==2){//the reason we do not rely on msgbox_bid[mbsid] is because if ie5 then fadeout kills the msgbox stack id before we can use it here
  var formcontent='<div align=center><form name="stwform" id="stwform" action="#" method=post onsubmit="return false;"><select name="newexpire" id="newexpire" class=select_dark><option value="5">5 Minutes</option><option value="10">10 Minutes</option><option value="20">20 Minutes</option><option value="40">40 Minutes</option><option value="60">1 Hour</option><option value="120">2 Hours</option><option value="240">4 Hours</option></select></form></div>';
  var content='Select the amount of time that you would like us to keep you signed on in the event that you are inactive. This value is the maximum amount of time that you could close your browser or walk away from your computer, and still remain signed on. If you are using a public computer, please keep this number low for your own security. Keep in mind that no matter what value you select here, you can always sign off at any time.'+formcontent;
  var buttonset='3:Save Changes;1:Cancel';
  msgbox_open(null,'Session Settings',encapsulate(content),buttonset,'handle_stw_response(thisbid)');
  autoselectlist("stwform.newexpire",g_si/60);
 }
 //if (msgbox_bid[mbsid]==3){
 if (bid==3){
  if (document.stwform){
   g_si=selectedvalue(document.stwform.newexpire)*60;
   g_sx=g_si;
   extendsessiontimeout(true,g_sx);
  }
 }
 //msgbox_bid[mbsid]=-1;
}
function extendsessiontimeout(sendpost,neint){
 if (sendpost==null) sendpost=true;
 if (neint==null) neint=0;
 if (sessiontimeoutid>0 && sendpost){
  updategse(extendsessiontimeout_continue,1,neint);
  return;
 }
 extendsessiontimeout_continue();
}
function extendsessiontimeout_continue(){
 setTimeout('sessiontimeoutwarning('+(sessiontimeoutid)+')',(g_sx-warnseconds())*1000);
 setTimeout('dosessiontimeout('+(sessiontimeoutid)+')',g_sx*1000)
 sessiontimeoutid++;
}
function dosessiontimeout(thistid){
 //first verify the timeout
 if (thistid==sessiontimeoutid-1){
  updategse(dosessiontimeout_continue);
 }
}
function dosessiontimeout_continue(){
 if (g_sx>5){
  if (g_sx>warnseconds()){
   //if msgbox is open then close it
   if (lastmsgboxwindowtitle[mbsid]=='Session Warning'){
    currentehelpswitchid[mbsid]=0;
    mb_fadeboxout(mbsid);
   }
  }
  extendsessiontimeout(false);
  return;
 }
 document.location.href=g_ur+"signon.asp?f=timeout"
}
function warnseconds(){
 return g_sx*sessiontimeoutwarning_percent+sessiontimeoutwarning_minimum;
}


function onloadmsg(msg,helpswitch){
 addloadcommand('msgbox_dialog_ok(null,domnshow,"'+prepjs(msg)+'",'+helpswitch+')');
}
function printminutes(x){
 if (x<60){
  if (x>1)
   return x+' minutes';
  else
   return x+' minute';
 } else {
  var h=Math.round(x/6)/10;
  if (h>1)
   return h+' hours';
  else
   return h+' hour';
 }
}
addloadcommand('writesmallpanehtml()');
addloadcommand('generalpupinit()');
