
var remoteWindow = null;
var nChecks = 0;
var fSkipCheck = false;

function Init()
{
  GetBrowserInfo();
}

function Refresh()
{
  if (nChecks > 0) return;
  RefreshIt();
}

function RefreshPage()
{
  if (nChecks > 0) return;
  setTimeout( "RefreshIt();", 100 );
}

function RefreshIt()
{
  if (nChecks > 0) return;
  if (remoteWindow) {
    remoteWindow = null;
    var sz = location.search;
    var iStart = sz.indexOf("AutoLaunch=");
    var szURL;
    if (iStart != -1) {
      var iEnd = sz.indexOf("&", iStart);
      if (iEnd == -1) {
        szNewSearch = sz.substring(0,iStart-1);
      } else {
        szNewSearch = sz.substring(0,iStart-1) + sz.substring(iEnd,sz.length);
      }
      if (szNewSearch.substring(0,1) == "&") {
        szNewSearch = "?" + szNewSearch.substring(1);
      }
      szURL = location.protocol + "//" + location.hostname + location.port + location.pathname + szNewSearch + location.hash;
      location.replace(szURL);
    } else {
      location.reload(true);
    }
  }
}

function ConfirmDelete(szLocation)
{
  var szMsg = "\nYou are about to delete this saved item.\n\n" +
              "Are you sure you want to do this?";
  if (confirm(szMsg)) {
    return true;
  } else {
    return false;
  }
}

function OpenActivityWindow(szURL, szWidth, szHeight, fNoScrollBars, fDoSkipCheck, iOffset)
{
  if (szURL.indexOf("Bees.htm") != -1) {
    if (getCookie("BeeDisable=") == "true") {
      alert("Sorry, The Bee Hive has been disabled by your administrator on this machine.");
      return;
    }
  }
  // The /empty.htm is needed by AOL, otherwise it will not let you set focus.
  if (szURL == null) szURL = "/empty.htm";
  if (typeof szUserState == "undefined" || szUserState == null || szUserState == "Subscribed") {
    if (szWidth == null) szWidth = "797";
    if (szHeight == null) szHeight = "544";
  } else {
    if (szWidth == null) szWidth = "955";
    if (szHeight == null) szHeight = "675";
  }
  if (isMac) {
    szMenuBar = "yes";
  } else {
    szMenuBar = "no";
  }
  if (fNoScrollBars) {
    szScrollbars = "no";
  } else {
    szScrollbars = "yes";
  }
  szResize = "yes";
  iWidth = parseInt(szWidth);
  iHeight = parseInt(szHeight);

  if (iHeight > screen.availHeight-34) iHeight = screen.availHeight-34;
  if (iWidth > screen.availWidth) iWidth = screen.availWidth;

  iLeft = ((screen.availWidth)/2) - (iWidth / 2);
  if (iLeft < 0) iLeft = 0;
  iTop = ((screen.availHeight-34)/2) - (iHeight / 2);
  if (iTop < 0) iTop = 0;
  if(iOffset != null) {
	iTop += iOffset;
	iLeft += iOffset;
  }
  if (!isIE) {
 	 remoteWindow = window.open(szURL ,"",
                             "width="+ iWidth + 
                             ",height=" + iHeight + 
                             ",status=no,menubar=" + szMenuBar + "," +
                             "toolbar=no,scrollbars=" + szScrollbars + ",resizable=" + szResize +
			     ",ScreenX=" + iLeft + ",ScreenY=" + iTop);
  } else {
 	 remoteWindow = window.open(szURL ,"",
                             "width="+ iWidth + 
                             ",height=" + iHeight + 
                             ",status=no,menubar=" + szMenuBar + "," +
                             "toolbar=no,scrollbars=" + szScrollbars + ",resizable=" + szResize +
			     ",top=" + iTop + ",left=" + iLeft );
  }
  if (fSkipCheck == true || fDoSkipCheck == true) {
    fSkipCheck = false;
  } else {
    dtLaunch = new Date();
    iLaunch = dtLaunch.getTime();
    winIntervalCheck = remoteWindow;
    interval = window.setInterval("checkWindow();", 500);
  }
  intPopup = setInterval("checkPopup();", 1000);
}

function checkPopup()
{
  clearInterval(intPopup );
  if (isOnL3() && (remoteWindow == null || remoteWindow.closed)) {
  //alert("Detected popup blocker.");
    window.location.href = "/PopupStopper.htm";
  }
}

function clearRefresh()
{
	winIntervalCheck = null;
	window.clearInterval(interval);
}

function checkWindow()
{
  dtCheck = new Date();
  iCheck = dtCheck.getTime();
  if (winIntervalCheck == null || winIntervalCheck.closed) {
    winIntervalCheck = null;
    window.clearInterval(interval);
    RefreshPage();
  }
}

function isOnL3()
{
  return (window.location.href.indexOf("/com/L3") >= 0);
}
