/*
** Abilitation Common JavaScript Library (CommonLib.js)
**
** Written by: Neil Martin
** Date: 8th Decemmber 2004
*/


function getDialogWidth( w ) {
  return (w < 0) ? (screen.availWidth / Math.abs(w)) : (screen.availWidth < (w / 0.9)) ? (screen.availWidth * 0.9) : w;
}

function getDialogHeight( h ) {
  return (h < 0) ? (screen.availHeight / Math.abs(h)) : (screen.availHeight < (h / 0.9)) ? (screen.availHeight * 0.9) : h;
}

function getDialogLeft( x, dlgWidth ) {
  return (x >= 0) ? x : (screen.availWidth - dlgWidth) / Math.abs(x);
}

function getDialogTop( y, dlgHeight ) {
  return (y >= 0) ? y : (screen.availHeight - dlgHeight) / Math.abs(y);
}


function positionWindow( x, y, iWidth, iHeight ) {
  var width = getDialogWidth( iWidth );
  var height = getDialogHeight( iHeight );
  var left = getDialogLeft( x, width );
  var top = getDialogTop( y, height );

  self.moveTo( left, top );
  self.resizeTo( width, height );
}


function loadWindow( szURL, szName, x, y, iWidth, iHeight, bScrollBars, bResizable ) {
  var width = getDialogWidth( iWidth );
  var height = getDialogHeight( iHeight );
  var left = getDialogLeft( x, width );
  var top = getDialogTop( y, height );

  var szFeatures = 'menubar=no, status=no, toolbar=no,';
  szFeatures = szFeatures + 'left=' + left.toString() + ', ';
  szFeatures = szFeatures + 'top=' + top.toString() + ', ';
  szFeatures = szFeatures + 'width=' + width.toString() + ', ';
  szFeatures = szFeatures + 'height=' + height.toString() + ', ';
  if (bScrollBars) {
    szFeatures = szFeatures + 'scrollbars=yes, ';
  } else {
    szFeatures = szFeatures + 'scrollbars=no, ';
  }
  if (bResizable) {
    szFeatures = szFeatures + 'resizable=yes';
  } else {
    szFeatures = szFeatures + 'resizable=no';
  }
  return window.open( szURL, szName, szFeatures );
}
