var yPadding = 60;   // The amount to pad the window by vertically
var xPadding = 10;   // The amount to pad the window by horizontally
var w;               // Screen Width
var h;               // Screen Height
var sWidth = 490;    // The width of the window to be spawned
var sHeight = 460;   // The height of the window to be spawned

if (parseInt(navigator.appVersion) > 3) {
  w = screen.width;
  h = screen.height;
} else if (navigator.javaEnabled() == true) {
  w = java.awt.Toolkit.getDefaultToolkit().getScreenSize().width;
  h = java.awt.Toolkit.getDefaultToolkit().getScreenSize().height;
} else {
  w = 640;
  h = 480;
}
if (w < sWidth + (2 * xPadding)) {
  sWidth = w - (2 * xPadding);
}
if (h < sHeight + (2 * yPadding)) {
  sHeight = h - (2 * yPadding);
}

function newEquipmentWindow(equipID, e) {
  ySpawnPoint = e.screenY;
  xSpawnPoint = e.screenX;

  if (ySpawnPoint + sHeight + yPadding > h)
    ySpawnPoint = h - sHeight - yPadding;
  if (ySpawnPoint < yPadding)
    ySpawnPoint = yPadding;

  if (xSpawnPoint + sWidth + xPadding > w)
    xSpawnPoint = w - sWidth - xPadding;
  if (xSpawnPoint < xPadding)
    xSpawnPoint = xPadding;

  window.open('details.php?hide_navbar=1&equip_id=' + equipID, 'equipmentDetailsWindow',
              'toolbar=no,status=no,location=no,menubar=no,directories=no,width=' + sWidth +
              ',height=' + sHeight + ',left=' + xSpawnPoint + ',top=' + ySpawnPoint +
              ',resizeable=yes,scrollbars=yes');
}

function updateView() {
  if (! document.forms['view'].elements['view'].value.length) return false;
  document.forms['view'].submit();
  return true;
}

