// Dialog functions
  var dialogId = "terminateSessionDialog";
  var disabledAllDivId = "disabledAllDiv";
  var popupTimeTimerId = "popupTimeTimer";
  var submitLinkId = "pbPopupScr:pppt4"

  function clickYes(){
    closePopupDialog(); 
  } 
    
// End of dialog functions

// Timer functions
  var popupTimerIntervalMSec; 
  var currMainTimer;
  var currPopupTimer;
  var currPopupTimeTimer;
  var popupDurationMSec;  
  var oldX = undefined;
  var oldY = undefined;


  function myClickHandler(evt){ 
    if ( !evt ) {
      evt = window.event;
    } 

    if ( evt.type == "mousemove" ) {
        if ( oldX != evt.clientX &&  oldY != evt.clientY ) {
          oldX = evt.clientX;
          oldY = evt.clientY;
        } else {
          return;
        }
    }
    
    var dialog = document.getElementById(dialogId);
    if(dialog.style.display == "block"){
      return;
    }
    clearInterval(currMainTimer);
    currMainTimer=setInterval("openPopupDialog()", popupTimerIntervalMSec);
  }
  
  function startTimer(timerPeriod, timerLife){    
    //see function in cyberBrowserUtils.js
    if(!isCyberBrowser()){
      return;
    }
    
    if(document.getElementById(dialogId)==null){      
      return;
    }
    
    popupTimerIntervalMSec = timerPeriod*1000; 
    popupDurationMSec = timerLife*1000;
    
    currMainTimer=setInterval("openPopupDialog()", popupTimerIntervalMSec);
    if (document.attachEvent) {
      document.attachEvent("onmousemove", myClickHandler);
      document.attachEvent("onkeydown", myClickHandler);
      document.attachEvent("onclick", myClickHandler);
    } else if (document.addEventListener) {
      document.addEventListener("mousemove", myClickHandler, true); 
      document.addEventListener("keydown", myClickHandler, true); 
      document.addEventListener("click", myClickHandler, true); 
    }
  }
  
  /**
  *
  */
  function closePopupDialog(isRedirect){
    
    var disabledAllDiv = document.getElementById(disabledAllDivId);
    var dialog = document.getElementById(dialogId);
    dialog.style.display = "none";
    disabledAllDiv.style.display = "none";
    clearInterval(currPopupTimer);
    clearInterval(currMainTimer);
    clearInterval(currPopupTimeTimer);
    if(isRedirect){
      var ref = document.getElementById(submitLinkId);      
      document.location.href = ref.href;
      return;     
    }
    currMainTimer=setInterval("openPopupDialog()", popupTimerIntervalMSec);
    
  } 
  
  function openPopupDialog(){
    currPopupTimer = setInterval("closePopupDialog(true)", popupDurationMSec + 1000);
    clearInterval(currMainTimer); 
    var dialog = document.getElementById(dialogId);   
    var disabledAllDiv = document.getElementById(disabledAllDivId);
    dialog.style.display = "block";
    disabledAllDiv.style.display = "block";   
    disabledAllDiv.style.height = document.body.offsetHeight+"px";
    disabledAllDiv.style.width = document.body.offsetWidth+"px";
    moveToCenter(dialog);   
    var timeTimer = document.getElementById(popupTimeTimerId);
    timeTimer.innerHTML = popupDurationMSec/1000;
    currPopupTimeTimer = setInterval("changePopupTime()", 1000);
  }
  
  function changePopupTime(){
    var timeTimer = document.getElementById(popupTimeTimerId);
    timeTimer.innerHTML = (parseInt(timeTimer.innerHTML)-1);
  }
  
  //startTimer();
  //window.captureEvents(Event.CLICK);
  //window.onClick = myClickHandler;
  // End of dialog functions
  
  //Utils
  function isClickInDialog(ev) {
      //  var tt=new Event();
   var dialog = document.getElementById(dialogId);   
     if(dialog.componentFromPoint)  {         //IE   
        var result1 = dialog.componentFromPoint(ev.clientX, ev.clientY);    
        if (result1 == "outside") {
            return false;
        }
    return true;
      }else  if(ev.target!=null){               
          if(ev.clientX<dialog.offsetLeft ||
           ev.clientX>(dialog.offsetLeft+dialog.offsetWidth)
                || ev.clientY<dialog.offsetTop
                || ev.clientY>(dialog.offsetTop+dialog.offsetHeight)){                  
                 return false;
           }
      return true;
      }          
    }
  
  function moveToCenter(dialog){
    var scrollArray = getScrollXY();
    var winL = (document.documentElement.clientWidth - dialog.offsetWidth) / 2 + scrollArray[0];
        var winT = (document.documentElement.clientHeight - dialog.offsetHeight) / 2 + scrollArray[1];
    dialog.style.left = winL+"px";
    dialog.style.top = winT+"px";
  }
  
  function getScrollXY() {
    var scrOfX = 0, scrOfY = 0;
    if( typeof( window.pageYOffset ) == 'number' ) {
      //Netscape compliant
      scrOfY = window.pageYOffset;
      scrOfX = window.pageXOffset;
    } else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
      //DOM compliant
      scrOfY = document.body.scrollTop;
      scrOfX = document.body.scrollLeft;
    } else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
      //IE6 standards compliant mode
      scrOfY = document.documentElement.scrollTop;
      scrOfX = document.documentElement.scrollLeft;
    }
    return [ scrOfX, scrOfY ];
  }

