// A popup centered relative to the screen
function popup(url, popupWidth, popupHeight) {
  var screenWidth = screen.availWidth;
  var screenHeight = screen.availHeight;
  
  // Konqueror doesn't like non-integer values, so we round, just to be sure
  var leftPos = Math.round((screenWidth - popupWidth) / 2);
  var topPos = Math.round((screenHeight - popupHeight) / 2);

  window.open(url, 'carPopup', 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=1,width=' + popupWidth + ',height=' + popupHeight + ',left=' + leftPos + ',top=' + topPos);
}
  
function insertOutput(index, prefix, suffix) {
  var kw = document.carActionForm.kw.value;
  var ps = document.carActionForm.ps.value;
  var factor = 1.359;
  
  // kW -> kW/PS
  if(kw != "" && ps == "") {
    ps = Math.round(kw * factor);
  }
  // PS -> kW/PS
  if(kw == "" && ps != "") {
    kw = Math.round(ps / factor);
  }
  document.carActionForm.elements[index].value = prefix + kw + "/" + ps + suffix;
  document.carActionForm.elements[index].focus();
}

// Global variable for the progress popup
var progress = null;
  
// A popup centered relative to the browser window
function progressPopup(url, width, height) {
  if(document.all) {
    // Internet Explorer?
    x = window.screenLeft + document.body.clientWidth / 2 - width / 2;
    y = window.screenTop + document.body.clientHeight / 2 - height / 2;
  }
  else {
    // Netscape & Mozilla?
    x = window.screenX + outerWidth / 2 - width / 2;
    y = window.screenY + outerHeight / 2 - height / 2;
  }
  return window.open(url,'progress','width=' + width + ',height=' + height + ',left=' + x + ',top=' + y);
}
    
// This method is called when the page is unloaded
function unload() {
  // Close the progress popup if there is one
  if(progress != null) {
    progress.close();
  }
}
