function BrowserInfo() {
  var agent = window.navigator.userAgent;
  if (agent.indexOf("MSIE") != -1) {
      var start = agent.indexOf("MSIE");
      this.name = "MSIE";
      this.version = parseFloat(agent.substring(start + 5, agent.indexOf(";", start)));
  } else if (agent.indexOf("Firefox") != -1) {
      var start = agent.indexOf("Firefox");
      this.name = "Firefox";
      this.version = agent.substring(start + 8, agent.length);
      var firstDec = this.version.indexOf(".") + 1;
      while (this.version.indexOf(".", firstDec) != -1)
        this.version = this.version.substring(0, firstDec) + this.version.substring(firstDec).replace(".", "");
      this.version = parseFloat(this.version);
  } else {
      this.name = "Unknown";
      this.version = 0;
  }
}

var info = new BrowserInfo();
var userAgent = window.navigator.userAgent
var isIE = (window.navigator.userAgent.indexOf("MSIE") != -1);
var isIE6 = (info.name == "MSIE" && info.version < 7);
var isFireFox = (window.navigator.userAgent.indexOf("Firefox") != -1);


var popWindow;
var noClose=0;

function ShowPop(what, MyHeight) {
   // Prevent the on-click event from closing the window that it's also opening!
   noClose = 1;

  // Get the height
  PopEndHeight = MyHeight;
  if (!(PopEndHeight)) {
    PopEndHeight = 150;
  }

  // Pop the window, and position
  var width = 352 + 32;
  var aPosn = GetOuterPosn();
  var aSize = GetInnerSize();
  var LeftPos = aPosn[0] + ((aSize[0] - width) / 2);
  var TopPos = aPosn[1] + 100;
  popWindow = window.open(what, 'heropop',
         'left=' + LeftPos + ',top=' + TopPos + ',width=' + width + ',height=' + PopEndHeight + ',toolbar=0,resizable=0,location=0,scrollbars=0,menubar=0,status=0');
  popWindow.moveTo(LeftPos, TopPos);
  popWindow.focus();

  // Add an event so that activity on the back window closes the pop
  setTimeout('AddClicker()', 500);
  return false;
}

function AddClicker() {
  if (window.attachEvent) {
    window.attachEvent('onclick', ClosePop);
  } else {
    window.onclick = ClosePop;
  }
  noClose = 0;
}

function ClosePop() {
  // Close the window
  if (noClose == 0) {
    popWindow.close();
    // Now cancel events on window
  }
  CancelEvents();
}

function CancelEvents() {
  noClose = 0;
  if (window.detachEvent) {
     window.detachEvent('onclick');
  } else {
     window.onclick = '';
  }
  return false;
}

function ClosePop2() {
  // Close the window
  window.opener.CancelEvents();
  self.close();
  return false;
}

// This is an ettempt to keep Safari Happy. But it failed.

function launchNewWindow(what) {
  var launched = 0;
  if (!isIE) {
    if (window.opener) {
        if (window.opener.launchNewWindow) {
          window.opener.launchNewWindow(what);
          launched = 1;
      }
    }
  }
  if (launched == 0) {
    var r=Math.floor(Math.random()*1000);
    var newWindow = window.open(what,'','');
    // This is a fix for safari on a Mac
    if (newWindow.innerWidth && window.screenLeft) { // all except Explorer
      var x = newWindow.innerWidth;
      if (x < 400) {
        newWindow.resizeTo(window.opener.innerWidth, window.opener.innerHeight);
        newWindow.moveTo(window.opener.screenLeft + 20, window.opener.screenTop + 20);
      }
    }
    newWindow.focus();
  }
  return ClosePop2();
}

function GetOuterPosn() {
  var x,y;
  if (document.all) {
      x = window.screenLeft;
      y = window.screenTop;
  } else {
      x = window.screenX;
      y = window.screenY;
  }
  return [x,y];
}

/* Generic functions for chackign windo position */
function GetInnerSize () {
  var x,y;
  if (self.innerHeight) { // all except Explorer
    x = self.innerWidth;
    y = self.innerHeight;
  } else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
    x = document.documentElement.clientWidth;
    y = document.documentElement.clientHeight;
  } else if (document.body) { // other Explorers
    x = document.body.clientWidth;
    y = document.body.clientHeight;
  }
  return [x,y];
}

/* Generic functions for chackign windo position */
function GetScrollPos () {
  var x,y;
  var x = document.body.scrollLeft;
  var y = document.body.scrollTop;
  if (x == 0) {
    if (window.pageYOffset) {
        x = window.pageXOffset;
        y = window.pageYOffset;
    } else {
        x = (document.body.parentElement) ? document.body.parentElement.scrollLeft : 0;
        y = (document.body.parentElement) ? document.body.parentElement.scrollTop : 0;
    }
  }
  return [x,y];
}

