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 += 2;
    } 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 += 2;
    } 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 += 2;
    } 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 += 2;
    } else {
      paddingY += parseInt(getStyle(document.body, 'paddingBottom'));
    }
  } else {
    paddingY += parseInt(document.body.style.paddingBottom);
  }

  var deltaX = x - winWidth + paddingX + 2; // 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 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);
  }
}

function openPopup(url) 
{
	window.open(url, 'Cadeau', 'width=700,height=500,scrollbars=1,resizable=0,status=0');
}

function docLoaded() 
{
	var errors = '';
	syncLabelColumns(); 
	popupResize('widthTable', true);
}

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';
        }
    }
}
