//popup
function openWindow(url, name, width, height, resizable, toolbar, menubar){
  var args = "";
  if (width){
    width = Math.min(width, screen.availWidth);
    args += "width=" + width + ",left=" + (screen.width - width)/2 + ",";
  }
  if (height){
    height = Math.min(height, screen.availHeight);
    args += "height=" + height + ",top=" + (screen.height - height)/2 + ",";
  }
  if (resizable){args += "resizable,scrollbars,";}
  if (toolbar){args += "toolbar,";}
  if (menubar){args += "menubar,";}
  var newwin = window.open(url, name, args);
  if (!newwin){
    alert("Er kan geen nieuw venster geopend worden.\nEr is waarschijnlijk een 'popup-killer' actief.");
    return false;
  }
  if (newwin.focus){newwin.focus();}
  return newwin;
}
function openModalWindow(url, width, height, resizable, toolbar, menubar){
  window.onfocus = function(){
    if (window.modalwindow){
      try{window.modalwindow.focus();}
      catch(ex){window.modalwindow = false; window.onfocus = null;}
    }
  }
  window.modalwindow = openWindow(url, "_blank", width, height, resizable, toolbar, menubar);
  return window.modalwindow;
}
function closeModalWindow(refresh){
  if (window.opener){
    window.opener.modalwindow = false;
    window.onfocus = null;
    if(refresh){window.opener.location.reload();}
    window.opener.focus();
  }
  window.close();
}