//----------------------------------------------------
function LogOut(bIsAnoUser, bCanConnectTrusted, event) {
//----------------------------------------------------
  if (window.top.UpNavigate) {
    if (window.top.UpNavigate.wndShowUser && !window.top.UpNavigate.wndShowUser.closed) {
      window.top.UpNavigate.wndShowUser.close();
    }
    if (window.top.UpNavigate.SearchWin && !window.top.UpNavigate.SearchWin.closed) {
      window.top.UpNavigate.SearchWin.close();
    }
    if (window.top.UpNavigate.wndWait && !window.top.UpNavigate.wndWait.closed) {
      window.top.UpNavigate.wndWait.close();
    }
    if (window.top.wndPicker && !window.top.wndPicker.closed) {
      window.top.wndPicker.close();
    }
    if (self.wndLogin && !self.wndLogin.closed) {
      self.wndLogin.close();
    }
  }

  if (bCanConnectTrusted) {
    window.top.location.href='dashboard/script/login/logout_abandon.asp';
  } else {
    window.top.location.href='dashboard/script/login/logout_abandon.asp';
  }
  return;
}

//----------------------------------------------------
function ResetTimeout() {
//----------------------------------------------------
  blank.location.reload();
  if ( !l_bAno ) g_lSessionSeconds = g_lFullSession;
}

//--------------------------------------------------
function ShowSessionTimeOutWarning() {
//--------------------------------------------------
  wndSess = window.open('dashboard/script/login/logout_warning.asp',"wndSess","dependent=yes,resizable=yes,width=420,height=270");
}

//----------------------------------------------------
function SessionTimer() {
//----------------------------------------------------
  l_lWidth = parseInt((g_lSessionSeconds / g_lFullSession)*100,10);
  document.getElementById('timer').style.width = l_lWidth+"%";

  if ( g_lSessionSeconds >= 120 ) {
    l_strTimeLeft = g_sStill + parseInt(g_lSessionSeconds/60) + g_sMinuteLogOff;
  } else {
    l_strTimeLeft = g_sStill + parseInt(g_lSessionSeconds) + g_sSecondsLogOff;
  }
  document.getElementById('timerspacer').setAttribute('tooltip', l_strTimeLeft + g_sDoubleClick);
}

//----------------------------------------------------
function SessionCountdown() {
//----------------------------------------------------
  SessionTimer();
  g_lSessionSeconds -= 1;
  if ( g_lSessionSeconds == 30 ) ShowSessionTimeOutWarning();
  if ( g_lSessionSeconds <= 0 ) document.location.href = l_strLOQuery;
  l_lTimeOutVar = window.setTimeout("SessionCountdown()",1000);
}

//----------------------------------------------------
function SetTargetFrame(p_lTarget) {
//----------------------------------------------------
  var l_lTarget = parseInt(p_lTarget);
  var l_lMax    = parseInt(g_aWindowNames.length)-1;
  var l_strTargetFrame;

  // reset all tabs inactive
  for ( var i=0; i<=l_lMax; i++ ) {
    document.getElementById(g_aWindowNames[i]).className = 'tqtabframe_inactive';
    document.getElementById('iframenav'+i).className = "tqtaskinactive";
  }

  l_strTargetFrame = g_aWindowNames[p_lTarget];
  // set current tabs active
  document.getElementById(l_strTargetFrame).className = 'tqtabframe_active';
  document.getElementById('iframenav'+l_lTarget).className = "tqtaskactive";
  // load frame if needed
  var l_sUrlCheck = g_aWindowUrl[p_lTarget];
  var l_sUrlFrame = window[l_strTargetFrame].location.href;
  if ( l_sUrlFrame.indexOf('dashboard/script/sites/pleasewait.asp') > 0 || /about:blank/.test(l_sUrlFrame) ) window[l_strTargetFrame].location.href = g_aWindowUrl[p_lTarget];

}

//----------------------------------------------------
function SetNotifyFrame(p_sTarget) {
//----------------------------------------------------
  var l_lMax = parseInt(g_aWindowNames.length)-1;
  try {
    for ( var i=0; i<=l_lMax; i++ ) {
      // set tab notify if not active
      var l_bFound = eval('/'+p_sTarget+'/.test(' + g_aWindowNames[i] + '.location.href)');
      if ( l_bFound ) {
        if ( document.getElementById('iframenav'+i).className == "tqtaskactive" ) return;
        document.getElementById('iframenav'+i).className = "tqtasknotify";
      }
    }
  } catch(e) {};
}

//----------------------------------------------------
function AJAX(){
//----------------------------------------------------
  try {
    temp = new XMLHttpRequest()
  } catch(e) {
    try {
      temp = new ActiveXObject("Msxml2.XMLHTTP");
    } catch(e) {
      try {
        temp = new ActiveXObject("Microsoft.XMLHTTP");
      } catch(e) {
        alert("NO AJAX SUPPORT AVAILABLE!!!");
        temp = null;
      }
    }
  }
  if (temp.overrideMimeType) temp.overrideMimeType('text/html')
  return temp;
}

//----------------------------------------------------
function reloadAJAX(targetWindow,action) {
//----------------------------------------------------
  var URL = targetWindow.document.location.href;
  var request = new AJAX();
  if ( request==null ) return false;
  var param = String();
  /\?/.test(URL) ? param="&rnd="+Date.parse(Date()) : param="?rnd="+Date.parse(Date());
  request.open('GET', URL+param, true);
  request.send(null);
  request.onreadystatechange = function(){action(request)};
  return true;
}

//------------------------------------------------------------------------------
function ResizeScndLvl(that) {
//------------------------------------------------------------------------------
  if ( typeof top.informerFullScreen == 'undefined' ) {
    top.informerFullScreen = new Boolean(false);
  }
  if ( top.informerFullScreen == false ) {
    setFullScreen(that);
  } else {
    unsetFullScreen(that);
  }
}

//------------------------------------------------------------------------------
function setFullScreen(that) {
//------------------------------------------------------------------------------
  top.document.getElementById('dashboard').style.display = 'none';
  top.document.getElementById('dashboardcontainer').style.display = 'none';
  top.document.getElementById('iframenavcontainer').style.display = 'none';
  top.informerFullScreen = true;
  that.className = that.className.replace(/maximize/,'minimize');
  that.blur();
}

//------------------------------------------------------------------------------
function unsetFullScreen(that) {
//------------------------------------------------------------------------------
  top.document.getElementById('dashboard').style.display = '';
  top.document.getElementById('dashboardcontainer').style.display = '';
  top.document.getElementById('iframenavcontainer').style.display = '';
  top.informerFullScreen = false;
  that.className = that.className.replace(/minimize/,'maximize');
  that.blur();
}

//----------------------------------------------------
function updateInformerSelector(request) {
//----------------------------------------------------
  if ( request.readyState==4 && request.status==200 ) {
    if ( request.responseText.length>0 ) {
      if ( oldContent != request.responseText ) {
        $id('tqinformerselector').contentWindow.document.location.reload();
        oldContent = request.responseText;
      } else {
      }
    }
  } else if ( request.readyState==4 && request.status!=200 ) {
    request.abort();
  }
}

//------------------------------------------------
function RefreshCounter() {
//------------------------------------------------
  g_lRefreshSeconds -= 1;
  if ( g_lRefreshSeconds < 1 ) {
    reloadAJAX($id('tqinformerselector').contentWindow,updateInformerSelector);
    g_lRefreshSeconds = g_lRefreshSecondsInitial;
  }
  g_lRefresh = window.setTimeout("RefreshCounter()",1000);
}

//------------------------------------------------
function loadViewer(p_lAppId) {
//------------------------------------------------
  var l_lMax    = parseInt(g_aWindowNames.length)-1;

  for ( var i=0; i<=l_lMax; i++ ) {
    if ( top.g_aWindowNames[i]=='viewer' ) {
      top.SetTargetFrame(i);
      top.viewer.location.href = top.g_aWindowUrl[i] + '?rq_lAppId='+p_lAppId;
    }
  }
}


