

//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
//
// fnege.js
// Javascript functions for FNEGE website
//
// FASTBOIL                     1.0         10/01/2010
// http://www.fastboil.net
// hot@fastboil.net
//
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

// Layout - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

var fullMinHeight = 500;

//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
// function
// Object :
// FASTBOIL                     1.0         10/01/2010
// http://www.fastboil.net
// hot@fastboil.net
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
function fnegeOnLoad() {
  hidediv('footer');
  setLayout();
  MM_preloadImages(arguments);
}

//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
// function
// Object :
// FASTBOIL                     1.0         10/01/2010
// http://www.fastboil.net
// hot@fastboil.net
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
function setLayout() {
  if (self.innerHeight) // all except Explorer
    h = self.innerHeight;
  else if (document.documentElement && document.documentElement.clientHeight) // Explorer 6 Strict Mode
    h = document.documentElement.clientHeight;
  else if (document.body) // other Explorers
    h = document.body.clientHeight;

  var fullHeight = h;
  if (fullHeight<fullMinHeight) fullHeight = fullMinHeight;


  if (document.getElementById('content')) {
      if (document.getElementById('content11'))
          document.getElementById('content').style.height = document.getElementById('content11').offsetHeight+'px';
      else {
          if (document.getElementById('content21'))
              document.getElementById('content').style.height = document.getElementById('content21').offsetHeight+'px';
          if (document.getElementById('content22') && document.getElementById('content22').offsetHeight>document.getElementById('content').offsetHeight)
              document.getElementById('content').style.height = document.getElementById('content22').offsetHeight+'px';
      }
  }



  if (document.getElementById('inner-wrap') && document.getElementById('colmain') && document.getElementById('colright')) {

    myHeight = fullHeight - document.getElementById('header').offsetHeight - document.getElementById('footer').offsetHeight;
    colmainH = document.getElementById('colmain').offsetHeight+20;
    if (colmainH>myHeight) myHeight=colmainH;
    colrightH = document.getElementById('colright').offsetHeight;
    if (colrightH>myHeight) myHeight=colrightH;
    document.getElementById('inner-wrap').style.height = myHeight+'px';
    showdiv('footer');
  }


  if (document.getElementById('partnersStripContent_o') && document.getElementById('colmain')) {
    newWidth = document.getElementById('colmain').offsetWidth
               - document.getElementById('partnersStripLeft').offsetWidth
               - document.getElementById('partnersStripRight').offsetWidth;
    document.getElementById('partnersStripContent_o').style.width = newWidth+'px';
  }
}

// Mouse coordinates - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

var divCreated = 0;
var divInfos;
var divInnerHTML = "";
var divCenter = false;

function getMouseCoordinates(event) {
  if (divInnerHTML!="") {
    ev = event || window.event;
    myLeft = ev.clientX;
    myTop = ev.clientY;
    myWidth = 150;
    myHeight = 150;
    //myLeft = Math.max(0,Math.min(myLeft,document.body.clientWidth - myWidth));
    myTop = Math.max(0,Math.min(myTop,document.body.clientHeight - myHeight));
    showInfos(myLeft,myTop,myWidth,myHeight);
  }
  else
    hidediv('divInfos');
}
function showInfos(left,top,width,height) {
  if (divCreated==0) {
    divCreated++;
    divInfos = document.createElement('div');
    divInfos.setAttribute('id', 'divInfos');
    divInfos.style.position = 'absolute';
    document.body.appendChild(divInfos);
    divInfos.style.backgroundColor = '#FFFFFF';
    divInfos.style.padding = '5px';
    divInfos.style.border = '1px solid #002F4C';
  }
  if (divInfos) {
    divInfos.innerHTML = divInnerHTML;

    if (divCenter) {
      divInfos.style.top = (myTop+30)+'px';
      divInfos.style.left = (myLeft-Math.round(divInfos.offsetWidth/2))+'px';
    }
    else {
      divInfos.style.top = (myTop+30)+'px';
      divInfos.style.left = (myLeft+20)+'px';
    }

    divInfos.style.visibility = 'visible';
    showdiv('divInfos');
  }
}
function setInfos(myStr,mouseCenter) {
  divCenter = mouseCenter;
  divInnerHTML = myStr;
}

function showAnnonce(idAnnonce) {
  if (document.getElementById('annonce_o_'+idAnnonce) && document.getElementById('annonce_i_'+idAnnonce)) {
    hidediv('footer');
    if (document.getElementById('annonce_o_'+idAnnonce).offsetHeight>0)
      document.getElementById('annonce_o_'+idAnnonce).style.height = '0px';
    else
      document.getElementById('annonce_o_'+idAnnonce).style.height = document.getElementById('annonce_i_'+idAnnonce).offsetHeight+'px';
    setLayout();
  }
}


// Scroll PartnersStrip - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

var timeoutPartnersStrip;
var initScroll = new Array();
var posOrigin = 10000;
var scrolling;
var delayPartnersStrip = 5;
var stepPartnersStrip = 5;

//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
// function
// Object :
// FASTBOIL                     1.0         10/01/2010
// http://www.fastboil.net
// hot@fastboil.net
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
function pScrollLeft(srcOff,srcOn,longScroll,init) {
  myDiv = 'partnersStripContent';                                                                   initScroll['partnersStripContent']
  offset = document.getElementById(myDiv+'_o').offsetWidth;

  document.stripleft.src = srcOn;
  if (initScroll[myDiv]==null) initScroll[myDiv]=init;
  scrolling = initScroll[myDiv];

  if(scrolling >= 5) {
    document.getElementById(myDiv).style.marginLeft = "-"+(scrolling-=stepPartnersStrip)+"px";
    initScroll[myDiv] = scrolling;
  }
  else {
    document.stripleft.src = srcOff;
    return;
  }
  if(longScroll == true) {
    timeoutPartnersStrip = setTimeout("pScrollLeft('"+srcOff+"','"+srcOn+"',true,"+init+")", delayPartnersStrip);
  }
  else
    document.stripleft.src = srcOff;
}

//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
// function
// Object :
// FASTBOIL                     1.0         10/01/2010
// http://www.fastboil.net
// hot@fastboil.net
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
function pScrollRight(srcOff,srcOn,longScroll,init) {
  myDiv = 'partnersStripContent';
  offset = document.getElementById(myDiv+'_o').offsetWidth;


  document.stripright.src = srcOn;
  if (initScroll[myDiv]==null) initScroll[myDiv]=init;
  scrolling = initScroll[myDiv];

  if(scrolling < (document.getElementById(myDiv).offsetWidth-offset)) {
    document.getElementById(myDiv).style.marginLeft = "-"+(scrolling+=stepPartnersStrip)+"px";
    initScroll[myDiv] = scrolling;
  }
  else {
    document.stripright.src = srcOff;
    return;
  }
  if(longScroll == true) {
    timeoutPartnersStrip = setTimeout("pScrollRight('"+srcOff+"','"+srcOn+"',true,"+init+")", delayPartnersStrip);
  }
  else
    document.stripright.src = srcOff;
}

// Swap Image - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}
function MM_preloadImages() { //v3.0
  var d=document;
  if(d.images) {
    if (!d.MM_p) d.MM_p = new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments;
    for(i=0; i<a.length; i++) {
      //if (a[i].indexOf("#")!=0) {
        d.MM_p[j]=new Image;
        d.MM_p[j++].src=a[i];
      //}
    }
  }
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}


function setCalendar(url) {
  fbGetUrlDiv('calendar',url,'');
}

//============================================================================//
//                            Ajax                                            //
//============================================================================//

function fbGetUrlDiv(id,url,innerhtml) {
  if (document.getElementById(id)) {
    var xReq=getXmlHttpRequest();
    var obj=document.getElementById(id);
    if (innerhtml != '') fbShowWaiting(obj,innerhtml);
    xReq.open("GET",url,true);
    xReq.onreadystatechange=function(){fbEventGetUrlDiv(xReq,id);};
    xReq.send(null);
  }
}

function fbEventGetUrlDiv(xRequest,anId) {
    if (xRequest.readyState==4) {
        document.getElementById(anId).innerHTML=xRequest.responseText;
    }
}

function fbShowWaiting(obj,innerhtml) {
    obj.innerHTML=innerhtml;
}

function getXmlHttpRequest() {
    if (window.XMLHttpRequest) // Firefox
    {
       return(new XMLHttpRequest());
    }
    else if (window.ActiveXObject) // Internet Explorer
    {
        try
        {
            return(new ActiveXObject("Msxml2.XMLHTTP"));
        } 
        catch (e)
        {
            try
            {
                return(new ActiveXObject("Microsoft.XMLHTTP"));
            }
            catch (e)
            {
                alert("Your browser does not support XMLHTTPRequest...");
            }
        }
    }
    else
    { // XMLHttpRequest non supporté par le navigateur
       alert("Your browser does not support XMLHTTPRequest...");
    }
}

function hidediv(myId) {
    if (document.getElementById) { // DOM3 = IE5, NS6
      if (document.getElementById(myId)) document.getElementById(myId).style.visibility = 'hidden';
    }
    else {
        if (document.layers) { // Netscape 4
          if (document.layer[myId]) document.layer[myId].visibility = 'hidden';
        }
        else { // IE 4
          if (document.all[myId]) document.all[myId].style.visibility = 'hidden';
       }
    }
}

function showdiv(myId) {
    if (document.getElementById) { // DOM3 = IE5, NS6
        if (document.getElementById(myId)) document.getElementById(myId).style.visibility = 'visible';
    }
    else {
        if (document.layers) { // Netscape 4
          if (document.layer[myId]) document.layers[myId].visibility = 'visible';
        }
        else { // IE 4
          if (document.all[myId]) document.all[myId].style.visibility = 'visible';
        }
    }
}


