windowDlg = null;
lastDlg = null;
currFrameForDlg=null;
wOpener=null;
fOpener=null;
isDep=1;
openWnds=new Array(0);
isModalDlgFromMain=false;
agt=navigator.userAgent.toLowerCase();
nav5up = parseInt(navigator.appVersion) >= 5;
nav  = ((agt.indexOf('mozilla')!=-1) && (agt.indexOf('spoofer')==-1)
                && (agt.indexOf('compatible') == -1) && (agt.indexOf('opera')==-1)
                && (agt.indexOf('webtv')==-1));
if (nav && nav5up) isDep=0;

// for open nonmodal window
function showWindow( url, dlgw, dlgh, wname, scroll, resize ){
        //new
//  sTimer.StopTimer();
        //
  var dx = (screen.availWidth - dlgw) / 2;
  var dy = (screen.availHeight - dlgh) / 2;
  var res=null
  if(topFrame.fOpener) res=topFrame.fOpener.findWnd(wname);
  else res=findWnd(wname);
  if (res==null){
          var name=new Date();
          name='w'+name.getTime().toString();
          res = window.open(url, (wname==null  || wname.length<1)? name : wname , 'height=' + dlgh +
                                ',width=' + dlgw + ',left=' + dx + ',top=' + dy +
                                ',scrollbars=' + ( scroll ? '1' : '0') +
                                ',resizable='+( resize ? '1' : '0')+
                                ',alwaysRaised=1');
          if(topFrame.fOpener) topFrame.fOpener.openWnds[topFrame.fOpener.openWnds.length]=res;
          else openWnds[openWnds.length]=res;

  } else {
          res.focus();
  }
  return res;
}

// for open nonmodal  window without session timer and independent from app (for print screens for ex)
function showPrintWindow( url, dlgw, dlgh){
          var name=new Date();
          name='w'+name.getTime().toString();
          res = window.open(url, name, 'height=' + dlgh + ',width=' + dlgw + ',left=0,top=0,scrollbars=1,resizable=1');
  return res;
}

// for open modal window dialog
function showModalDlg(url,dlgw,dlgh,currFrame){
  // if (windowDlg != null) return ;
  if(currFrame) currFrameForDlg=currFrame;
  else  currFrameForDlg=null;
  //new
  //sTimer.StopTimer();
  if(isModalDlgFromMain) sTimer.StopTimer();
  //
  var dx = (screen.availWidth - dlgw) / 2;
  var dy = (screen.availHeight - dlgh) / 2;
  if(window.showModalDialog){
    return showModalDialog(url,self,"status:0;dialogWidth:"+dlgw+"px;dialogHeight:"+dlgh+"px;dialogLeft:" + dx + "px;dialogTop:" + dy + "px;edge:sunken;scroll=0;help=0");
  } else {
    var name=new Date();
    name='w'+name.getTime().toString();
    return window.open(url,name,'height=' + dlgh + ',width=' + dlgw + ',left=' + dx + ',top=' + dy + ',status=0,modal=yes,scrollbars=0,toolbar=0,titlebar=0,dependent='+isDep);
  }
}


// for open modal window dialog
function showModalDlgScroll(url,dlgw,dlgh,currFrame){
  // if (windowDlg != null) return ;
  if(currFrame) currFrameForDlg=currFrame;
  else  currFrameForDlg=null;
  //new
  //sTimer.StopTimer();
  if(isModalDlgFromMain) sTimer.StopTimer();
  //
  var dx = (screen.availWidth - dlgw) / 2;
  var dy = (screen.availHeight - dlgh) / 2;
  if(window.showModalDialog){
    return showModalDialog(url,self,"status:0;dialogWidth:"+dlgw+"px;dialogHeight:"+dlgh+"px;dialogLeft:" + dx + "px;dialogTop:" + dy + "px;edge:sunken;scroll=1;help=0");
  } else {
    var name=new Date();
    name='w'+name.getTime().toString();
    return window.open(url,name,'height=' + dlgh + ',width=' + dlgw + ',left=' + dx + ',top=' + dy + ',status=0,scrollbars=0,toolbar=0,titlebar=0,dependent='+isDep);
  }
}

function showDlg(url,dlgw,dlgh,currFrame){
    var ret = showModalDlg(url,dlgw,dlgh,currFrame);
		return ret;
}

// for open question.jsp window
function showQuestion(text,cx,cy,currFrame,defbtn){
  if( !cx ) cx = 360;
  if( !cy ) cy = 180;
  var url='question.jsp?text='+text;
  if(defbtn) url=url+'&default='+defbtn;
  showDlg(url,cx,cy,currFrame);
}

// for open question.jsp window with actions
// Request Parameter ab=no - set Action Button is NO
function showQuestionActions(text,ab,action1,action2,cx,cy,currFrame,defbtn){
  var url=text+"&ab="+ab+"&action="+action1+"&action2="+action2;
  showQuestion(url,cx,cy,currFrame,defbtn);
}

function showQuestion2Actions(text,btn1,btn2,action1,action2,def,cx,cy,currFrame){
  var url="question2b.jsp?text=" + text +
        "&action1=" + action1 + "&action2=" + action2 +
        "&name1=" + btn1 + "&name2=" + btn2 +
        "&default=" + def;
  if( !cx ) cx = 360;
  if( !cy ) cy = 180;
  showDlg(url,cx,cy,currFrame);
}

function showQuestion3Actions(text,btn1,btn2,btn3,action1,action2,action3,def,cx,cy,currFrame){
  var url="question3b.jsp?text=" + text +
        "&action1=" + action1 + "&action2=" + action2 + "&action3=" + action3 +
        "&name1=" + btn1 + "&name2=" + btn2 + "&name3=" + btn3 +
        "&default=" + def;
  if( !cx ) cx = 360;
  if( !cy ) cy = 180;
  showDlg(url,cx,cy,currFrame);
}

// for open error.jsp window
function showError( text, cx, cy ){
  text = toUrl(text);
  // var r = /[+]/gi;
  // text = text.replace(r, "%2B");
  if( !cx ) cx = 360;
  if( !cy ) cy = 180;
  var ret = showDlg( "error.jsp?text=" + text, cx , cy );
	if( ret )
		ret.focus();
}

// for open error.jsp window with action parameter
function showErrorAction( text, action, cx, cy ){
  text = text+ "&action=" + action;
  return showError( text , cx , cy );
}

function focusToDlg() {
  if( windowDlg && windowDlg.focus ) windowDlg.focus();
}

function closeDlg()
{
  if( windowDlg  ) {
    try{
            if(windowDlg.closeDlg) {
                    windowDlg.closeDlg();
            } else {
                    windowDlg.close();
            }
   } catch(e){}
  }
  window.close();
}

function closeWnd()
{
   if(openWnds && openWnds.length>0){
        var numWnd=openWnds.length;
        for(var i=0;i<numWnd;i++){
                try{
                        if(openWnds[i] && openWnds[i].closeWnd) openWnds[i].closeWnd();
                } catch(e){}
        }
  }
  closeDlg();
}

function loadDlg(){
  if(window.opener){
    wOpener=window.opener;
  } else {
    if (self.dialogArguments) {
        wOpener=self.dialogArguments;
    } else {
    wOpener=window;
    }
  }
  //new
  if(wOpener.isModalDlgFromMain){
          isModalDlgFromMain=true;
  }
  //new
  if (wOpener.fOpener) {
    fOpener=wOpener.fOpener;
  } else {
    fOpener=wOpener;
  }
  if (wOpener != window ) wOpener.windowDlg = window;
  fOpener.lastDlg = window;
  if ( fOpener.t ) t=fOpener.t;
  if ( fOpener && fOpener.sTimer && fOpener.sTimer.alertTime ) sTimer.alertTime=fOpener.sTimer.alertTime;
  if(isModalDlgFromMain && ReStartSessionTimer) ReStartSessionTimer();
}

function unloadDlg(){
  try {
          if( wOpener && wOpener.windowDlg) {
                  wOpener.windowDlg=null;
          }
          if(fOpener && fOpener.lastDlg){
                  fOpener.lastDlg=wOpener;
                  //new
                  // wOpener.ContinueSessionTimer(sTimer.counter);
                  //new
                  if(isModalDlgFromMain) wOpener.ContinueSessionTimer(sTimer.counter);
                  //
          }
  } catch ( e ) {}
}

function loadWnd(){
  if(window.opener){
    wOpener=window.opener.topFrame;
  } else {
    wOpener=window;
  }
  if (wOpener.fOpener) {
    fOpener=wOpener.fOpener;
  } else {
    fOpener=wOpener;
  }
  if ( fOpener && fOpener.t ){
          t=fOpener.t;
          if ( fOpener.sTimer.alertTime ) sTimer.alertTime=fOpener.sTimer.alertTime;
          // new (SessTimer on fOpener restart)
         // ReStartSessionTimer();
          fOpener.ReStartSessionTimer();
          // new
  }
}

function unloadWnd(){
  try {
     // new (SessTimer on fOpener restart not needed)
    // wOpener.ContinueSessionTimer(sTimer.counter);
    // new (SessTimer on fOpener restart)
    if(windowDlg && windowDlg.closeDlg) windowDlg.closeDlg();
    wOpener.delWnd(window);
  } catch ( e ) {}
}

function delWnd(wnd){
  if(topFrame.fOpener){
          for(var k=0; k<topFrame.fOpener.openWnds.length; k++) {
            if(topFrame.fOpener.openWnds[k] == wnd) {
              topFrame.fOpener.openWnds.splice(k,1);
              break;
            }
          }
  }
  for(var k=0; k<openWnds.length; k++) {
    if(openWnds[k] == wnd) {
      openWnds.splice(k,1);
      break;
    }
  }
}

function findWnd(sname){
  var wnd=null;
  if(sname!=null && sname.length>0){
          for(var k=0; k<openWnds.length; k++) {
                  try{
                  if(openWnds[k] && openWnds[k].close){
                          if (openWnds[k].name!=null && openWnds[k].name == sname) {
                                  wnd=openWnds[k];
                                  break;
                          }
                  } else {
                          openWnds.splice(k,1);
                  }
                  }catch(e){
                  }
          }
  }
  return wnd;
}

function unloadModalWnd()
{
    if (windowDlg && windowDlg.onClose)
        windowDlg.onClose();
    else if (windowDlg && windowDlg.close)
        windowDlg.close();
}

function toUrl(str)
{
    return encodeURIComponent(str);
}