/*
 * (c) Jeroen Peters
 */
 
document.write("<SCR" + "IPT LANGUAGE='JavaScript1.2' SRC='/scripts/param.js' TYPE='text/javascript'><\/SCR" + "IPT>");

IE5 = ((document.getElementById && document.all)  ? true : false);
IE4 = (document.all ? true : false);
NS6 = ((document.getElementById && !document.all) ? true : false);
NS4 = (document.layers ? true : false);

function winIsOpen(winHandle) {
// bestaat window al?
  return (winHandle != null && !winHandle.closed);
}
                
function openWin(url, options) {
  openWinEx(url, "", options);
}

function openWinEx(url, winName, options) {
// options: (* = default)
//  position   : *'center' || 'default || 'fixed'
//  width      :  integer value (*70% screen width)
//  height     :  integer value (*60% screen height)
//  left       :  integer value (only used if position == 'fixed') 
//  top        :  integer value (only used if position == 'fixed')
//  location   :  'yes' || *'no'
//  personalbar:  'yes' || *'no'
//  toolbar    :  'yes' || *'no'
//  menubar    : *'yes' ||  'no'
//  status     :  'yes' || *'no'
//  scrollbars : *'yes' ||  'no'
//  resizable  : *'yes' ||  'no'
  this.aOptions = parseParamString(options, ";", "=")
  var winHandle;
  var sFeatures = '';

  setDefault('position'   , 'center');
  setDefault('width'      , (screen.width/100)*70);
  setDefault('height'     , (screen.height/100)*60);
  setDefault('left'       , 0       );
  setDefault('top'        , 0       );
  setDefault('location'   , 'no'   );
  setDefault('personalbar', 'no'    );
  setDefault('toolbar'    , 'no'   );
  setDefault('menubar'    , 'yes'   );
  setDefault('status'     , 'no'   );
  setDefault('scrollbars' , 'yes'   );
  setDefault('resizable'  , 'yes'   );

  // Bepaal window grootte
  sFeatures = 'width=' + getOption('width') + ',height=' + getOption('height');
  
  // bepaal window positie
  if (getOption('position') == 'center') {
    aOptions['left'].value =  (screen.width  - getOption('width') ) / 2;
    aOptions['top' ].value =  (screen.height - getOption('height')) / 3;
  } 
  if (getOption('position') != 'default') {
    sFeatures = sFeatures + (NS6 || NS4 ? ',screenX=' : ',left=') + getOption('left') + 
      (NS6 || NS4 ? ",screenY=" : ",top=") + getOption('top');
  }
  
  // overige opties
  sFeatures = sFeatures + 
    ',location='    + getOption('location') + 
    ',personalbar=' + getOption('personalbar') + 
    ',toolbar='     + getOption('toolbar') + 
    ',menubar='     + getOption('menubar') + 
    ',status='      + getOption('status') + 
    ',scrollbars='  + getOption('scrollbars') + 
    ',resizable='   + getOption('resizable');
  
  winHandle = window.open(url, winName, sFeatures);
  return winHandle
}

function setDefault(optionName, defValue) {
  if ( typeof(this.aOptions[optionName]) == 'undefined' ) {
    // option bestaat niet - voeg optie toe met default waarde
    this.aOptions[optionName] = this.aOptions[this.aOptions.length] = 
      { name: optionName, value: defValue };    
  }
}

function getOption(optionName) {
  result = '';
  
  if ( typeof(this.aOptions[optionName]) != 'undefined' ) 
    result = this.aOptions[optionName].value;
    
  return result;
}

var winHandler = null;

function popImage(img, width, height, bgColor) {
  // Initialize optional vars.
  if (!bgColor) {
    bgColor = "#696969";
  }
  if (!width || !height) {
    var imgObj = new Image();
    imgObj.src = img;
    if (!width) {
      width = imgObj.width + 25;
    }
    if (!height)
      height = imgObj.height + 25;
  }

  // Close existing window
  if (winIsOpen(winHandler))
    winHandler.close();

  // Create new window
  var dimStr = "width=" + width + "; height=" + height;
  winHandler = openWinEx("", "imgWin", dimStr + ";menubar=no;resizable=no;scrollbars=no");

  // Create html and place picture
  winHandler.document.open("text/html");
  winHandler.document.writeln('\<html\>\<body style="background-color: ' + bgColor + '; margin: 0px; padding:0px"\>');
  
  winHandler.document.writeln('\<table width="100%" height="100%" border="0" cellspacing="1"\>');
  winHandler.document.writeln('  \<tr>\n    \<td style="text-align: center; vertical-align: middle;">');
  winHandler.document.writeln('      \<a href="javascript:self.close()"><img style="border:none;" src="' + img + '" alt=""\></a>');
  winHandler.document.writeln('    \<\/td>\n  <\/tr>');
  winHandler.document.writeln('\<\/table>');
  winHandler.document.writeln('\<\/body\>\<\/html\>');
  winHandler.document.close();
  winHandler.focus();
} 
