
/* ******************************************** */
/* JSPopup */
/* ******************************************** */

var browser = new Browser();
var popupObj = new Object();

popupObj.zIndex = 0;
zIndexEncours=0;

var topPopup = 0;
var leftPopup = 0;

var laPopup = '';
var laLargeurPopup = 0;
var laHauteurPopup = 0;

window.onresize = function() {

  if ( laPopup != '' ) {
    showCenterPopup ( laPopup , laLargeurPopup , laHauteurPopup );
  }
}

function showCenterPopup ( anId , aWidth , anHeight )
{
  var laLargeurDispo;
  var laHauteurDispo;

  if ( laPopup == '' ) {
    laPopup = anId;
    laLargeurPopup = aWidth;
    laHauteurPopup = anHeight;
  }

  if ( window.innerHeight ) {
    //mozilla
    w = window.innerWidth;
    h = window.innerHeight;
  } 
  else {
    //IE
    w = document.body.offsetWidth - 10;
    h = document.body.offsetHeight - 70;
  }

  topPopup = Math.round( ( w - laLargeurPopup ) / 2 );
  leftPopup = Math.round( ( h - laHauteurPopup ) / 2 );

  showPopup( null , laPopup );
}

function showInformationPopup ( anId )
{
  topPopup = 200;
  leftPopup = 250;
  showPopup( null , anId );
}

function showPopupAPCom( anId ) {
  topPopup = 160;
  leftPopup = 125;
  showPopup( null , anId );
}

function showPopupConvention( anId ) {
  topPopup = 5;
  leftPopup = 5;
  showPopup( null , anId );
}

function showPopupALFr( anId ) {
  topPopup = 160;
  leftPopup = 125;
  showPopup( null , anId );
}

function showPopupIC( anId ) {
  topPopup = 160;
  leftPopup = 775;
  showPopup( null , anId );
}

function showPopupDirectIC ( anId ) {
  topPopup = 160;
  leftPopup = 410;
  showPopup( null , anId );
}

function showPopupErreurIc( anId , top , left ) {
  topPopup = top;
  leftPopup = left;
  showPopup( null , anId );
}

function showPopupErreurIc( anId ) {
  topPopup = 200;
  leftPopup = 200;
  showPopup( null , anId );
}

function showPopupErreur( anId ) {

  topPopup = 200;
  leftPopup = 200;
  showPopup( null , anId );
}

function showPopupSupport( anId ) {
  topPopup = 82;
  leftPopup = 30;
  switchPopup ( null , anId );
}

function switchPopup( event , anId ) {

  var thePopup = document.getElementById( anId )

  if ( thePopup != null ) {

    if ( thePopup.style.visibility == "visible" ) {
      hidePopup( anId );
    }
    else {
      showPopup( null , anId );
    }

  }

}

var thePopupMem;
var anIdMem;

function showPopup( event , anId ) {


  var thePopup = document.getElementById( anId )

  thePopupMem = thePopup;
  anIdMem = anId;

  if ( thePopup != null ) {

    var x, y;

    if ( event == null ) {

      x = leftPopup;
      y = topPopup;

    }
    else {

      if ( browser.isIE == true ) {
        x = window.event.clientX + document.documentElement.scrollLeft + document.body.scrollLeft;
        y = window.event.clientY + document.documentElement.scrollTop + document.body.scrollTop;
      }
      else if ( browser.isNS == true ) {
        x = event.clientX + window.scrollX;
        y = event.clientY + window.scrollY;
      }

    }

    thePopup.style.left = x + "px";
    thePopup.style.top = y + "px";
    thePopup.style.visibility = "visible";
    thePopup.style.display = "block";
    thePopup.style.cursor = "default";

    if ( browser.isIE == true )
        putHideFrame(thePopup,anId);

    zIndexEncours++;
    thePopup.style.zIndex = "" + zIndexEncours;
  }
}
function putHideFrame(anDiv,anId) { 

if ( browser.isIE == true )
{
  var d = document.getElementById(anId);
  var f = document.getElementById("iframeAide"); 
  var addBool = false;
  var decalageTop = 0;
  var decalageLeft = 0;

  zIndexEncours++;

  if ( f == null )
  {
    f = document.createElement("iframe");

    f.setAttribute("id","iframeAide");
    f.id = "iframeAide";
    f.src = "javascript:'<html></html>'";
    f.style.border="none";    
    f.setAttribute("frameborder","0"); 
    f.setAttribute("scrolling","no");

    addBool = true;
  }

  var ntop = GetDomOffset(anDiv,'offsetTop') + decalageTop;
  var nleft = GetDomOffset(anDiv,'offsetLeft') + decalageLeft;

  with(f.style){ 
     position   = "absolute"; 
     width      = d.offsetWidth+"px"; 
     height     = d.offsetHeight+"px";
     top        = ntop +"px"; 
     left       = nleft +"px"; 
     zIndex     = "1"; 
  } 

  if ( addBool ) {
    document.body.appendChild(f);
  }
  f.style.display = 'block';
}
}

function GetDomOffset( Obj, Prop ) {
  var iVal = 0;
  while (Obj && Obj.tagName != 'BODY') {
    eval('iVal += Obj.' + Prop + ';');
    Obj = Obj.offsetParent;
  }
  return iVal;
}

function hidePopup( anId ) {

  var thePopup = document.getElementById( anId );

  if ( browser.isIE == true )
  {
  var f = document.getElementById("iframeAide"); 

  if ( f != null )
    f.style.display = 'none';
  }

  if ( thePopup != null ) {
    thePopup.style.visibility = "hidden";
    thePopup.style.display = "none";
  }
}

function hidePopupIC( anId ) {

  var thePopup = document.getElementById( anId );

  if ( thePopup != null ) {
    thePopup.style.visibility = "hidden";
//    thePopup.style.display = "none";
  }
}

function Browser() {

  var ua, s, i;

  this.isIE = false;
  this.isNS = false;
  this.isMac = false;
  this.isSafari = false;
  this.version = null;
  this.drag = true;

  ua = navigator.userAgent;
  s = "Mac";
  if ( ( ua.indexOf( s )) >= 0 ) {
    this.isMac = true;
    this.drag = false;
    return;
  }
  s = "Safari";
  if ( ( ua.indexOf( s ) ) >= 0 ) {
    this.isSafari = true;
    return;
  }
  s = "MSIE";
  if ( ( i = ua.indexOf( s ) ) >= 0 ) {
    this.isIE = true;
    this.version = parseFloat(ua.substr(i + s.length));
    if (this.version<5.5) this.drag = false;
    return;
  }
  s = "Netscape";
  if ( ( i = ua.indexOf( s ) ) >= 0 ) {
    this.isNS = true;
    this.version = parseFloat(ua.substr(i + s.length));
    return;
  }
  // Treat Opera as IE5
  s = "Opera";
  if ( ( i = ua.indexOf( s ) ) >= 0 ) {
    this.isIE = true;
    this.version = 5;
    return;
  }
  s = "Firefox";
  if ( ( i = ua.indexOf( s ) ) >= 0 ) {
    this.isNS = true;
    this.version = 7.0;
    return;
  }
  s = "Firebird";
  if ( ( i = ua.indexOf( s ) ) >= 0 ) {
   this.isNS = true;
   this.version = 7.0;
   return;
  }
  // Treat any other "Gecko" browser as NS 6.1.
  s = "Gecko";
  if ( ( i = ua.indexOf( s ) ) >= 0 ) {
   this.isNS = true;
   this.version = 6.1;
   return;
  }
}

function showPopupAlertePannel( event , anId ) {

  showPopup( event , anId )
}

function dragStartPopup( event , anId ) {

  var el;
  var x, y;

  if ( browser.isIE == true )
  {
    var f = document.getElementById("iframeAide"); 

    if ( f != null )
      f.style.display = 'none';
  }

  if ( anId != null ) {

    popupObj.elNode = document.getElementById( anId );

  } 
  else {
    if ( browser.isIE == true ) {
      popupObj.elNode = window.event.srcElement;
    } 
    else if ( browser.isNS == true ) {
      popupObj.elNode = event.target;
    }
    
    if ( popupObj.elNode.nodeType == 3 ) {
      popupObj.elNode = popupObj.elNode.parentNode;
    }
  }

  // Get cursor position with respect to the page.
  if ( browser.isIE == true ) {
    x = window.event.clientX + document.documentElement.scrollLeft + document.body.scrollLeft;
    y = window.event.clientY + document.documentElement.scrollTop + document.body.scrollTop;
  }
  else if ( browser.isNS == true ) {
    x = event.clientX + window.scrollX;
    y = event.clientY + window.scrollY;
  }

  // Save starting positions of cursor and element.
  popupObj.cursorStartX = x;
  popupObj.cursorStartY = y;


  zIndexEncours++;
  popupObj.elNode.style.zIndex  = zIndexEncours;

  popupObj.elStartLeft = parseInt( popupObj.elNode.offsetLeft , 10 );
  popupObj.elStartTop = parseInt( popupObj.elNode.style.top , 10 );

  if ( isNaN( popupObj.elStartLeft ) ) popupObj.elStartLeft = 0;
  if ( isNaN( popupObj.elStartTop ) ) popupObj.elStartTop = 0;

  if ( browser.isIE == true ) {
    document.attachEvent( "onmousemove" , dragPopupGo );
    document.attachEvent( "onmouseup" , dragPopupStop );
    window.event.cancelBubble = true;
    window.event.returnValue = false;
  }
  else if ( browser.isNS == true ) {
    document.addEventListener( "mousemove" , dragPopupGo, true );
    document.addEventListener( "mouseup" , dragPopupStop, true );
    event.preventDefault();
  }
}

function dragPopupGo( event ) {

  var x, y;

  if ( browser.isIE == true ) {
    x = window.event.clientX + document.documentElement.scrollLeft + document.body.scrollLeft;
    y = window.event.clientY + document.documentElement.scrollTop + document.body.scrollTop;
  }
  else if ( browser.isNS == true ) {
    x = event.clientX + window.scrollX;
    y = event.clientY + window.scrollY;
  }

  popupObj.elNode.style.left = ( popupObj.elStartLeft + x - popupObj.cursorStartX ) + "px";
  popupObj.elNode.style.top = ( popupObj.elStartTop + y - popupObj.cursorStartY ) + "px";

  if ( browser.isIE == true ) {
    window.event.cancelBubble = true;
    window.event.returnValue = false;
  }
  else if ( browser.isNS == true ) {
    event.preventDefault();
  }
}

function dragPopupStop( event ) {

  if ( browser.isIE == true ) {
    document.detachEvent( "onmousemove" , dragPopupGo );
    document.detachEvent( "onmouseup" , dragPopupStop );
  }
  else if ( browser.isNS == true ) {
    document.removeEventListener( "mousemove" , dragPopupGo , true );
    document.removeEventListener( "mouseup" , dragPopupStop , true );
  }
  if ( browser.isIE == true )
    putHideFrame(thePopupMem, anIdMem);
}


