var sX = screen.availWidth;
var sY = screen.availHeight;

// open_popup(mod, func, returnWay, returnMod, returnFunc, extra)
// parameters list:
// mod: the module to use in the popup
// func: the php function to call
// returnWay: either 'return' or 'update'. If 'return', we call back 'returnMod' (see below),
//            and the function 'returnFunc' of that module; else
//            we refresh the opener page calling 'returnFunc' of the module 'mod' itself
// returnMod: the module to return to after the popup has finished its job
// returnFunc: a function to call upon return, either in the calling 'mod' or in the return way, it depends
//             from the value of 'returnWay' (see above)
// extra: any other query parameter in the form key1=value1&key1=value2...

function open_popup(mod, func, returnWay, returnMod, returnFunc, extra) {
  var prefix = "";
  if ( returnMod == 'none' ) {
    prefix = "../../";
  }
  var urlToOpen = prefix+"admin-popup.php?mod="+mod+"&func="+func+"&returnWay="+returnWay+"&returnMod="+returnMod+"&returnFunc="+returnFunc;
  if ( extra != null ) {
    urlToOpen += "&"+extra;
  }
  var w = 780;
  var h = 600;
  var aX = (sX - w)/2;
  var aY = (sY - h)/2;    

  window.open( urlToOpen, "", 
               "toolbar=no,directories=no,scrollbars=yes,width="+w+",height="+h+",top="+aY+",left="+aX );     

  return false;  
}

function chooseImg(oei) {
  window.open("admin.php?mod=mEditor&func=insertImg&callBack=chooseImg_cb&oei="+oei, "Choose Img", 
                        "status=no,modal=yes,width=450,height=450");   
}

function chooseImg_cb(sender) {
  var imgSrc = sender.returnValue.path;
  var oei = sender.returnValue.oei;
  if (imgSrc != null) {
    document.getElementById(oei).value = imgSrc;
  }  
}

function chooseColor(oei) {
  window.open("admin.php?mod=mEditor&func=chooseColor&callback=chooseColor_cb&oei="+oei, "Choose Color", 
      "status=no,modal=yes,width=450,height=450"); 
}

function chooseColor_cb(sender) {
  var col = sender.returnValue.col;
  if (col != null) {
    document.getElementById(sender.returnValue.oei).value = col;
  }
}