function popupresize (widthId, doMove) {
  if (window.opener || window.dialogHeight) {
    if (document.getElementById) {
      dwidth = document.getElementById(widthId).offsetWidth;
      dheight = document.getElementById(widthId).offsetHeight;
    }
    if (screen.availHeight)  maxHeight = screen.availHeight - 100;  else  maxHeight = 500;
    if (screen.availWidth)   maxWidth  = screen.availWidth  - 100;  else  maxWidth  = 700;
    if (dheight > maxHeight)  dheight = maxHeight;
    if (dwidth  > maxWidth)   dwidth = maxWidth;

    if (dwidth < 10)  dwidth  = 600;
    if (dheight < 10) dheight = 500;
    
    /* was resp. 30 en 40 */
    /* beter = 10 en 30 */
    dwidth += 18;
    dheight += 40;
    if (window.dialogHeight) {
      window.dialogHeight = (dheight -5) + 'px';
      window.dialogWidth = (dwidth -5) + 'px';
      window.dialogLeft = (self.screen.width/2 - dwidth / 2) + 'px';
      window.dialogTop = (self.screen.height/2 - dheight / 2) + 'px';
    } else {
      // mozilla kent een method sizeToContent. handig!
      if (window.sizeToContent) {
        window.sizeToContent();
      } else {
        window.resizeTo(dwidth, dheight);
      }
      if (doMove != false) {
        window.moveTo(self.screen.width/2 - dwidth / 2, self.screen.height / 2 - dheight / 2);
      }
    }
  }
}
function popupResize (widthId, doMove, resizeHeight) {
  newPopupResize(widthId, doMove, resizeHeight);
}



function newPopupResize(widthId, doMove, resizeHeight) {
  if (!window.opener) {
    return false;
  }

	var maxWidth = 700;
	var maxHeight = 500;
	if (screen.availHeight) {
		maxHeight = screen.availHeight - 100;
	}
	if (screen.availWidth) {
		maxWidth  = screen.availWidth  - 100;
	}
  var widthEl = document.getElementById(widthId);
  var x = Math.min(widthEl.offsetWidth, maxWidth);
  var y = Math.min(widthEl.offsetHeight, maxHeight);

	if (resizeHeight != false) {
    window.resizeTo(x + 10, y + 60);
  } else {
    window.resizeTo(x + 10, -1);
  }

  if (window.innerHeight) {
    var winHeight = window.innerHeight;
  } else if (document.body.clientHeight) {
    var winHeight = document.body.clientHeight;
  }
  if (window.innerWidth) {
    var winWidth = window.innerWidth;
  } else if (document.body.clientWidth) {
    var winWidth = document.body.clientWidth;
  }

  if (!winWidth || !winHeight) {
    return false;
  }

  var paddingX = 0;
  var paddingY = 0;
  if (isNaN(parseInt(document.body.style.paddingLeft))) {
    // geen padding in de style-declaratie van de body. probeer met getStyle ...
    if (isNaN(parseInt(getStyle(document.body, 'paddingLeft')))) {
      // lukt ook niet via getStyle-manier : standaardpadding = 2
      paddingX += 4;
    } else {
      // getStyle-manier
      paddingX += parseInt(getStyle(document.body, 'paddingLeft'));
    }
  } else {
    // padding is in style-declaratie meegegeven
    paddingX += parseInt(document.body.style.paddingLeft);
  }

  if (isNaN(parseInt(document.body.style.paddingRight))) {
    if (isNaN(parseInt(getStyle(document.body, 'paddingRight')))) {
      paddingX += 4;
    } else {
      paddingX += parseInt(getStyle(document.body, 'paddingRight'));
    }
  } else {
    paddingX += parseInt(document.body.style.paddingRight);
  }

  if (isNaN(parseInt(document.body.style.paddingTop))) {
    if (isNaN(parseInt(getStyle(document.body, 'paddingTop')))) {
      paddingY += 4;
    } else {
      paddingY += parseInt(getStyle(document.body, 'paddingTop'));
    }
  } else {
    paddingY += parseInt(document.body.style.paddingTop);
  }

  if (isNaN(parseInt(document.body.style.paddingBottom))) {
    if (isNaN(parseInt(getStyle(document.body, 'paddingBottom')))) {
      paddingY += 4;
    } else {
      paddingY += parseInt(getStyle(document.body, 'paddingBottom'));
    }
  } else {
    paddingY += parseInt(document.body.style.paddingBottom);
  }

  var deltaX = x - winWidth + paddingX + 6; // 2 voor de zekerheid
  var deltaY = y - winHeight + paddingY + 2; // 2 voor de zekerheid

  //alert('window width: '+winWidth+', height: '+winHeight + '\n' + 'resized to width: '+x+', height: '+y+ '\nmod x: '+(x-winWidth)+', y: '+(y-winHeight) + '\n' + 'paddingX: ' + paddingX + ', paddingY: ' + paddingY + '\ndeltaX = ' + deltaX + ', deltaY = ' + deltaY);

  if (resizeHeight != false) {
    window.resizeBy(deltaX, deltaY);
  } else {
    window.resizeBy(deltaX, 0);
  }

  if (doMove != false) {
    popupCenter();
  }
}


function syncLabelColumns() {
    els = document.getElementsByTagName('TD');
    var maxWidth = 0;
    for (var i = 0; i < els.length; i++) {
        el = els[i];
        if (el.className == 'desc') {
            if (el.offsetWidth > maxWidth) {
                maxWidth = el.offsetWidth;
            }
        }
    }
    for (i = 0; i < els.length; i++) {
        el = els[i];
        if (el.className == 'desc') {
            el.style.width = maxWidth + 'px';
        }
    }
}







function getStyle(el,styleProp) {
	if (window.getComputedStyle) {
    // mozilla-manier. let op regexp-replace! om van bijv. paddingBottom 'padding-bottom' te maken
    styleProp = styleProp.replace(/([A-Z])/g, '-$1').toLowerCase();
		var y = window.getComputedStyle(el,null).getPropertyValue(styleProp);
	} else if (el.currentStyle) {
    // ie-manier
		var y = eval('el.currentStyle.' + styleProp);
  }
	return y;
}



function popupCenter () {
  if (document.body.offsetWidth && window.moveTo) {
    dwidth  = document.body.offsetWidth;
    dheight = document.body.offsetHeight;
    window.moveTo (self.screen.width / 2 - dwidth / 2, self.screen.height / 2 - dheight / 2);
  }
}
/*
// DOM2
if ( typeof window.addEventListener != "undefined" )
  document.addEventListener( "keypress", sluiten, true );
// IE
// else
if ( typeof window.attachEvent != "undefined" )
	document.attachEvent( "onkeypress", sluiten);
*/
function sluiten(evt) {
  if (evt && evt.keyCode) {
    var keycode = evt.keyCode;
  } else if (event && event.keyCode) {
    var keycode = event.keyCode;
  }
  switch (keycode) {
    case 27:
      window.close();
      break;
    case 116:
      //window.location.reload();
      break;
  }
  return true;
}

function openSimplePopup(target, width, height, titel) 
	{
	if(!width){
        width = 450;
	}
	if(!height){
        height = 200;
	}
	if(!titel){
        titel = "MusicFromNL";
	}
    if (screen.width) {
        ls = screen.width / 2 - width / 2;
    } else {
        ls = 50;
    }
    if (screen.height) {
        ts = screen.height / 2 - height / 2;
    } else {
        ts = 50;
    }
    window.open (target, titel,'left='+ls+',top='+ts+',width='+width+',height='+height+',toolbar=no,menubar=no,status=no,directories=no,resizable=yes,scrollbars=yes,modal=1');
}


function redirectOpener(target)
{
    if (window.opener){
        window.opener.location=target;
		window.close();
	}
}