var winReference = null;

function openPositionedWindow(url, name, width, height, x, y, status, scrollbars, moreProperties, openerName) {
  var agent = navigator.userAgent.toLowerCase();
  if (agent.indexOf("mac") != -1 && agent.indexOf("msie") != -1 && (agent.indexOf("msie 4") != -1 || agent.indexOf("msie 5.0") != -1) ) {
    height += (status) ? 17 : 2;
  }
  
  width += (scrollbars != '' && scrollbars != null && agent.indexOf("mac") == -1) ? 16 : 0;
  var properties = 'width=' + width + ',height=' + height + ',screenX=' + x + ',screenY=' + y + ',left=' + x + ',top=' + y + ((status) ? ',status' : '') + ',scrollbars' + ((scrollbars) ? '' : '=no') + ((moreProperties) ? ',' + moreProperties : '');
  var reference = openWindow(url, name, properties, openerName);
  return reference;
}

function openMaxedWindow(url, name, scrollbars, openerName) {
  var x, y = 0;
  var width  = 600;
  var height = 800;
  if (screen) {
    if (screen.availLeft) {
      x = screen.availLeft;
      y = screen.availTop;
    }
    width  = screen.availWidth - 6;
    height = screen.availHeight - 29;
  }
  var reference = openPositionedWindow(url, name, width, height, x, y, false, scrollbars, openerName);
  return reference;
}


function openWindow(url, name, properties, openerName) {
  var agent = navigator.userAgent.toLowerCase();
  if (agent.indexOf("msie") != -1 && parseInt(navigator.appVersion) == 4 && agent.indexOf("msie 5") == -1 && agent.indexOf("msie5") == -1 && agent.indexOf("win") != -1 && url.indexOf('http://') == 0) {
    winReference = window.open('about:blank', name, properties);
    setTimeout('if (winReference && !winReference.closed) winReference.location.replace("' + url + '")', 300);
  } else {
    winReference = window.open(url, name, properties);
  }
  setTimeout('if (winReference && !winReference.closed) winReference.focus()', 200);
  if (openerName) self.name = openerName;
  //return winReference;
}

