// -------------------------------------------------------------------------
//  API Fenêtres JavaScript
//  PREFIXE : wind0
// -------------------------------------------------------------------------

// Hauteur & Largeur fixe (IE 100x100  , NS 100x150 + hauteur titre)
var shr_wind0_gintWindowFixedWidth  = 300;
var shr_wind0_gintWindowFixedHeight = 300;

// -------------------------------------------------------------------------
//  Ouverture d'une nouvelle fenêtre
// -------------------------------------------------------------------------
//  [IN] string pstrName        Nom de la fenêtre
//  [IN] string pstrURL         URL a appeler
//  [IN] string pstrListOptions Parametres d'ouverture
//  [IN] int    pintWidth       Largeur de fenetre
//  [IN] int    pintHeight      Hauteur de fenetre
// -------------------------------------------------------------------------

function shr_wind0_OpenWindow(pstrName, pstrURL, pstrListOptions, pintWidth, pintHeight)
{
 var lstrListOptions; // Liste des options
 var lobjWindowName; // Instance fenêtre courant
 var lstrContents; // Buffer contenu fenêtre

 if (pintWidth == 0) pintWidth = shr_wind0_gintWindowFixedWidth;
 if (pintHeight == 0) pintHeight = shr_wind0_gintWindowFixedHeight;

 // Options par defaut
 if (pstrListOptions == '')
   { pstrListOptions = 'dependent=Yes,toolbar=No,location=No,directories=No,status=Yes,menuBar=No,scrollbars=Yes,resizable=Yes,'; }

 // Ajouter Largeur & Hauteur à liste Options + centrer fenêtre
 lstrListOptions = pstrListOptions + 'Width=' + pintWidth + ',Height=' + pintHeight + ',top=' + ((screen.availHeight-pintHeight)/2) + ',left=' + ((screen.availWidth-pintWidth)/2);

 // Completer les URL en path relatif
 if (pstrURL.substring(0,1) == '.')
   { pstrURL = tool0_gstrBaseHref + pstrURL; }

 // Impossibilite de reutiliser une fenetre deja ouverte a partir de son nom
 // si le protocole http/https est different pour l'appelant et l'appelle
 if (  (pstrName != '')
     &&(pstrURL.substring(0,5) != tool0_gstrBaseHref.substring(0,5)) )
   { pstrName = ''; }
 else
   {
    if (  (pstrName != '')
        &&(pstrURL.substring(0,5) == 'https') )
      { pstrName += 'SSL'; }
   }

 // Ouverture fenetre
 lobjWindowName = window.open('',pstrName,lstrListOptions);

 if (lobjWindowName != null)
   {
    // Première ouverture ou réutilisation d'une fenêtre déjà ouverte
    if (lobjWindowName.opener)
      {
       if (  (!lobjWindowName.document.body)
           ||(lobjWindowName.document.body.innerHTML == '') )
         { lobjWindowName.opener.m_blnFirstUse = true; }
       else
         { lobjWindowName.opener.m_blnFirstUse = false; }
      }

    // Contenu initial
    lstrContents = '';
    lstrContents += '<html><body>';
    lstrContents += '<span style="font-family: arial; font-size: 10px;">Chargement en cours ...<span>';
    lstrContents += '</body></html>';
    lobjWindowName.document.write(lstrContents);

    // Appel URL
    lobjWindowName.location.replace(pstrURL);

    // Prendre le focus
    lobjWindowName.focus();
   }
}



// -------------------------------------------------------------------------
//  Redimensionner une fenêtre
// -------------------------------------------------------------------------

function shr_wind0_ResizeWindow()
{
 var lintAddWidth; // Largeur de la fenêtre (hors partie client)
 var lintAddHeight; // Hauteur de la fenêtre (hors partie client)
 var lintWidth; // Largeur de la fenêtre
 var lintHeight; // Hauteur de la fenêtre
 var lintX; // Position gauche de la fenêtre
 var lintY; // Position haute de la fenêtre
 var lobjHeaderSize; // Entête du site
 var lobjBodySize; // Corp + pied du site

 // Desactive le gestionnaire d'erreur
 // ERREUR : clic pendant l'ouverture de la popup
 window.onerror=shr_tool0_OnError;

 // Retailler Fenêtre avec Hauteur & Largeur fixees
 window.resizeTo(shr_wind0_gintWindowFixedWidth, shr_wind0_gintWindowFixedHeight);
 window.onerror='';

 // Calculer Hauteur & Largeur à ajouter (Différence entre Fenêtres)
 if (typeof document.all != 'undefined')
   {
    lintAddWidth  = shr_wind0_gintWindowFixedWidth  - document.body.clientWidth + parseInt(document.body.currentStyle.paddingLeft) + parseInt(document.body.currentStyle.paddingRight);
    lintAddHeight = shr_wind0_gintWindowFixedHeight - document.body.clientHeight + parseInt(document.body.currentStyle.paddingTop) + parseInt(document.body.currentStyle.paddingBottom);
   }
 else
   {
    lintAddWidth  = window.outerWidth  - window.innerWidth  + 15;
    lintAddHeight = window.outerHeight - window.innerHeight + 25;
   }

 // Taille interieure fenêtre
 lobjBodySize =  shr_tool0_GetElementByID('TOOL0_BODY_SIZE');
 lintWidth  = lobjBodySize.offsetWidth;
 lintHeight = lobjBodySize.offsetHeight;

 // Taille avec Entete
 lobjHeaderSize = shr_tool0_GetElementByID('TOOL0_HEADER_SIZE');
 if (lobjHeaderSize)
   {
    if (lobjHeaderSize.offsetWidth > lintWidth)
	  { lintWidth = lobjHeaderSize.offsetWidth; }

    lintHeight += lobjHeaderSize.offsetHeight;
   }

 // Ajouter les bordures
 lintWidth  += lintAddWidth;
 lintHeight += lintAddHeight;

 // Limite de l'ecran
 lintMargin = 80;
 if (lintWidth > window.screen.width-lintMargin)
   { lintWidth = window.screen.width-lintMargin; }
 if (lintHeight > window.screen.height-lintMargin)
   { lintHeight = window.screen.height-lintMargin; }

 // Desactive le gestionnaire d'erreur
 // ERREUR : Acces interdit a window.opener en https
 // ERREUR : clic pendant l'ouverture de la popup
 window.onerror=shr_tool0_OnError;

 // Re-tailler Fenêtre avant le centrage
 window.resizeTo(lintWidth, lintHeight);

 // Centrer la fenetre uniquement lors de l'ouverture initiale
 if (  (!window.opener)
     ||(typeof window.opener.m_blnFirstUse == 'undefined')
     ||(window.opener.m_blnFirstUse) )
   {
    // Centrer Fenêtre
    lintX = ((window.screen.width /2) - ((lintWidth) /2));
    lintY = ((window.screen.height/2) - ((lintHeight)/2));
    window.moveTo(lintX, lintY);
   }

 // Re-tailler Fenêtre apres le centrage
 window.resizeTo(lintWidth, lintHeight);

 // Restore le gestionnaire d'erreur
 window.onerror='';

 // Forcer Largeurs container
 lobjBodySize.width = '100%';
 if (lobjHeaderSize)
   { lobjHeaderSize.width = '100%'; }
}


// -------------------------------------------------------------------------
//  Rafraichissement de la fenetre parent
// -------------------------------------------------------------------------

function shr_wind0_RefreshOpener()
{
 // Desactive le gestionnaire d'erreur
 window.onerror=shr_tool0_OnError;

 // Rafraichir fenetre parent
 if (  (window.opener)
     &&(!window.opener.closed) )
   {
    var lstrHRef = window.opener.location.href;

    // Supprimer valeur scroll
    lstrHRef = lstrHRef.replace(/[?&]pintScrollLeft=\d+/g, '');
    lstrHRef = lstrHRef.replace(/[?&]pintScrollTop=\d+/g, '');

    if (lstrHRef.search(/\?/g) == -1)
      { lstrHRef += '?'; }
    else
      { lstrHRef += '&'; }

    // Nouvelle valeur scroll
    lstrHRef += 'pintScrollLeft=' + shr_tool0_GetScrollLeft(window.opener);
    lstrHRef += '&pintScrollTop=' + shr_tool0_GetScrollTop(window.opener);

    window.opener.location.replace(lstrHRef);
   }

 // Restore le gestionnaire d'erreur
 window.onerror='';
}


// -------------------------------------------------------------------------
//  Rafraichissement de la fenetre courante
// -------------------------------------------------------------------------

function shr_wind0_Refresh()
{
 // Rafraichir fenetre
 var lstrHRef = window.location.href;

 // Supprimer valeur scroll
 lstrHRef = lstrHRef.replace(/[?&]pintScrollLeft=\d+/g, '');
 lstrHRef = lstrHRef.replace(/[?&]pintScrollTop=\d+/g, '');

 if (lstrHRef.search(/\?/g) == -1)
   { lstrHRef += '?'; }
 else
   { lstrHRef += '&'; }

 // Nouvelle valeur scroll
 lstrHRef += 'pintScrollLeft=' + shr_tool0_GetScrollLeft();
 lstrHRef += '&pintScrollTop=' + shr_tool0_GetScrollTop();

 window.location.replace(lstrHRef);
}

