// Reno - 2003-03-13 09:27:20 - V1.0.0
//*******************************************************************************
//-------------------------------------------------------------------------------
// WINUTILS.JS
//-------------------------------------------------------------------------------
//*******************************************************************************

function getWindowWidth(win) {
	if (!win) win=window;
  if (win.innerWidth) return win.innerWidth;
  if (win.document.documentElement && document.documentElement.clientWidth) return win.document.documentElement.clientWidth;
  if (win.document.body) return win.document.body.clientWidth;
  return -1;
} // function getWindowWidth

function getWindowHeight(win) {
	if (!win) win=window;
  if (win.innerHeight) return win.innerHeight;
  if (win.document.documentElement && document.documentElement.clientHeight) return win.document.documentElement.clientHeight;
  if (win.document.body) return win.document.body.clientHeight;
  return -1;
} // function getWindowHeight

// centre la fenetre sur l'ecran
function center(win){
	if (!win) win = window;
		
	win.moveTo((screen.availWidth-getWindowWidth(win))/2,(screen.availHeight-getWindowHeight(win))/2);
  win.focus();
	return win;
}

// Test l'existence d'une fenetre
function ExistsWin(pWin)
{
	if (pWin && pWin.open && !pWin.closed)
		return pWin;
	else
		return false;
}

function Pop2Print(strUrl, strName, isizeX, isizeY) {
  var iPop2Print = null;
  iPop2Print = window.open(strUrl, strName, 'width='+isizeX+',height='+isizeY+',toolbar=no,scrollbars=yes,statusbar=no,menubar=yes,left=15,top=15,resizable=yes,personalbar=no,locationbar=no');
  if (iPop2Print) iPop2Print.focus();
  if (! isMinIE4) iPop2Print.print();
}

function PopWindow(strUrl, strName) {
  var iPopWindow = null;
  iPopWindow = window.open(strUrl, strName);
  if (iPopWindow) iPopWindow.focus();
}

function Pop2Show(strUrl, strName, isizeX, isizeY) {
  var iPop2Show = null;
  iPop2Show = window.open(strUrl, strName, 'width='+isizeX+',height='+isizeY+',toolbar=no,scrollbars=no,statusbar=no,menubar=no,left=15,top=15,resizable=yes,personalbar=no,locationbar=no');
//  if (iPop2Show) iPop2Show.focus();
}

function Pop2ShowSta(strUrl, strName, isizeX, isizeY) { // avec status
  var P2S = null;
  P2S = window.open(strUrl, strName, 'width='+isizeX+',height='+isizeY+',toolbar=no,scrollbars=no,statusbar=yes,menubar=no,left=15,top=15,resizable=yes,personalbar=no,locationbar=no');
  if (P2S) P2S.focus();
}

function Pop2ShowR(strUrl, strName, isizeX, isizeY) { // non resizable
  var P2S = null;
  P2S = window.open(strUrl, strName, 'width='+isizeX+',height='+isizeY+',toolbar=no,scrollbars=no,statusbar=no,menubar=no,left=15,top=15,resizable=no,personalbar=no,locationbar=no');
  if (P2S) P2S.focus();
}

function Pop2ShowS(strUrl, strName, isizeX, isizeY) { // avec scroll
  var P2S = null;
  P2S = window.open(strUrl, strName, 'width='+isizeX+',height='+isizeY+',toolbar=no,scrollbars=yes,statusbar=no,menubar=no,left=15,top=15,resizable=no,personalbar=no,locationbar=no');
  if (P2S) P2S.focus();
}

function Pop2ShowSR(strUrl, strName, isizeX, isizeY) { // avec scroll + resizable
  var P2S = null;
  P2S = window.open(strUrl, strName, 'width='+isizeX+',height='+isizeY+',toolbar=no,scrollbars=yes,statusbar=no,menubar=no,left=15,top=15,resizable=yes,personalbar=no,locationbar=no');
  if (P2S) P2S.focus();
}

function Pop2ShowC(strUrl, strName, isizeX, isizeY, bScroll) {
  cxx = (screen.width / 2) - (isizeX / 2);
  cyy = (screen.height / 2) - (isizeY / 2);
  var Pop2Show = null;
  if (bScroll)
    Pop2Show = window.open(strUrl, strName, 'width='+isizeX+',height='+isizeY+',toolbar=no,scrollbars=yes,statusbar=no,menubar=yes,left='+cxx+',top='+cyy+',resizable=no,personalbar=no,locationbar=no');
  else 
    Pop2Show = window.open(strUrl, strName, 'width='+isizeX+',height='+isizeY+',toolbar=no,scrollbars=no,statusbar=no,menubar=yes,left='+cxx+',top='+cyy+',resizable=no,personalbar=no,locationbar=no');
  if (Pop2Show) Pop2Show.focus();
}

function Pop2ShowCNM(strUrl, strName, isizeX, isizeY, bScroll, bFocus) {
  cxx = (screen.width / 2) - (isizeX / 2);
  cyy = (screen.height / 2) - (isizeY / 2);
  var Pop2S = null;
  if (bScroll)
    Pop2S = window.open(strUrl, strName, 'width='+isizeX+',height='+isizeY+',toolbar=no,scrollbars=yes,statusbar=no,menubar=no,left='+cxx+',top='+cyy+',resizable=no,personalbar=no,locationbar=no');
  else 
    Pop2S = window.open(strUrl, strName, 'width='+isizeX+',height='+isizeY+',toolbar=no,scrollbars=no,statusbar=no,menubar=no,left='+cxx+',top='+cyy+',resizable=no,personalbar=no,locationbar=no');
  if (bFocus && Pop2S) Pop2S.focus();
}

function PopImg(fic, x, y, sTitle, bScroll, bInTable, sClose) {
  var oPopImg = null;
  var sPopImg = '';

  var cxx = (screen.width / 2) - (x / 2);
  var cyy = (screen.height / 2) - (y / 2);
  var sScr = (bScroll) ? "yes" : "no";
  var sClose = (sClose) ? sClose : "Cliquez pour fermer la fen&ecirc;tre";
  oPopImg=window.open('','pop','width='+x+',height='+y+',toolbar=no,scrollbars='+sScr+',statusbar=no,titlebar=no,menubar=no,left='+cxx+',top='+cyy+',resizable=no,personalbar=no,locationbar=no');
  var sStartJS = '<scr'+''+'ipt language="JavaScript" > \
    function setClientSize(win, W, H)  {\
      win.resizeTo(W, H); \
      var cp = document.createElement("div"); \
      cp.style.position = "absolute"; \
      cp.style.width = "0px"; \
      cp.style.height = "0px"; \
      cp.style.right = "0px"; \
      cp.style.bottom = "0px"; \
      document.body.appendChild(cp); \
      var current_width = cp.offsetLeft; \
      var current_height = cp.offsetTop; \
      var dw = W - current_width; \
      var dh = H - current_height; \
      win.resizeBy(dw, dh); \
      document.body.removeChild(cp); \
      return { missed_width: dw, missed_height: dh }; \
    } \
    function PopImgShow(fic, isIENS6, x, y) { \
      var im = document.getElementById("im"); \
      im.src = fic; \
      while (isIENS6 && !im.complete) { \
        setTimeout("PopImgShow(\'"+fic+"\', "+parseInt(isIENS6)+", "+x+", "+y+");", 1500); \
        return; \
      } \
      var popimgonload = document.getElementById("popimgonload"); \
      popimgonload.style.display="none"; \
      var aim = document.getElementById("aim"); \
      aim.style.display="block"; \
      setClientSize(window, x, y); \
    } ';
  sStartJS += 'var im = new Image();im.src="'+fic+'";</scr'+''+'ipt>';
  sStart = '<div id="popimgonload" name="popimgonload" class="popimg" style="position:absolute;top:0px;left:0px;z-index:10;background-color:#FFF;color:#000;width:'+x+'px;height:'+y+'px;padding-top:'+Math.floor(y/2)+'px;text-align:center;"><h2>En cours de chargement...</h2></div>';
  sPopImg = '<html><head><title>'+sTitle+'</title>';
  sEnd = '<scr'+''+'ipt language="JavaScript" >';
  isOK = (isIENS6) ? 1 : 0;
  sEnd += "PopImgShow('"+fic+"',"+parseInt(isOK)+", "+x+", "+y+");";
  sEnd += "</script>";

  sPopImg += sStartJS+'</head><body style="margin:0;padding:0">'+sStart+'<a href="javascript:self.close();" id="aim" style="display:none;position:absolute;top:0px;left:0px;z-index:0;" title="'+sClose+'"><img src="/images/im_shim.gif" id="im" style="position:relative;margin:0;padding:0;border:0" alt="'+sClose+'"></a>';
  sPopImg += sEnd+'</body></html>';
  oPopImg.document.clear();
  oPopImg.document.open();
  oPopImg.document.write(sPopImg);
  oPopImg.document.close();
  oPopImg.focus();
}

function FullEcran(strUrl) {
  var Fen_imprim = null;
  Fenl=screen.width-50;
  FenL=screen.height-100;
  Fen_imprim = window.open(strUrl,'Pleinecran','width='+Fenl+',height='+FenL+',top=0,left=0,resizable=yes,toolbar=yes,scrollbars=yes,menubar=yes,statusbar=no');
  Fen_imprim.focus();
}

// Fenetre sans barre du haut ! IE seulement
var splashWin, autoCloseTimeoutHandle, ontopIntervalHandle;
function Pop2ShowNoBar(sUrl, sName, width, height, left, top, autoCloseTime) {

	var w = window.screen.width;
	var h = window.screen.height;
	var l = (left != null) ? left : (w-width)/2;
	var t = (top != null) ? top : (h-height)/2;
	
	splashWin = window.open(sUrl, sName, 'fullscreen=1,toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=0,resizable=0');

	splashWin.blur();	// Hide while updating
	window.focus();
	
	splashWin.resizeTo(width,height);
	splashWin.moveTo(l, t);

	splashWin.focus();
	
	ontopIntervalHandle = splashWin.setInterval("window.opener.splashWin.focus();", 50);
	splashWin.document.body.onbeforeunload = function() {
		// Splash is being closed. no need to close it again
		window.clearInterval(autoCloseTimeoutHandle);
		window.onbeforeunload = null;
	};
	
	splashWin.document.body.onload = function() {splashWin.setInterval("window.opener.splashWin.focus();", 50);};
	
	window.clearTimeout(autoCloseTimeoutHandle);	// in case some one calls this twice	
	if (autoCloseTime != null && autoCloseTime > 0) {
		autoCloseTimeoutHandle = window.setTimeout("splashWin.close()", autoCloseTime);
	}
	
	window.onbeforeunload = function() {splashWin.close();};	// Close splash when this page is unloaded
}