
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
//
// egc.js
// Javascript functions for EGC website
//
// FASTBOIL                     1.0         20/01/2010
// http://www.fastboil.net
// hot@fastboil.net
//
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

var groupdescriptionIdArr = new Array();
var groupdescriptionValueArr = new Array();
var groupdescriptionTimeout;
var groupdescriptionDelay = 5;
var groupdescriptionStep = 10;

function actionGroupDescription(idGroup) {
  clearTimeout(groupdescriptionTimeout);

  rank = inArray(groupdescriptionIdArr,idGroup);
  if (rank>=0)
    groupdescriptionValueArr[rank] = !groupdescriptionValueArr[rank];
  else {
    rank = groupdescriptionIdArr.length;
    groupdescriptionIdArr.push(idGroup);
    groupdescriptionValueArr.push(true);
  }

  if (groupdescriptionValueArr[rank]) {
    for(var i=0,l=groupdescriptionValueArr.length;i<l;i++) {
      if(groupdescriptionValueArr[i]) {
        groupdescriptionValueArr[i] = false;
        startHideGroupDescription(groupdescriptionIdArr[i]);
      }
    }
    groupdescriptionValueArr[rank] = true;
    startShowGroupDescription(idGroup);
  }
  else
    startHideGroupDescription(idGroup);

}

function startShowGroupDescription(idGroup) {
  if (document.getElementById('groupcontainer_'+idGroup) && document.getElementById('groupcontent_'+idGroup)) {
    reqHeight = document.getElementById('groupcontent_'+idGroup).offsetHeight;
    showGroupDescription(idGroup,reqHeight);
  }
}

function showGroupDescription(idGroup,reqHeight) {
  cHeight = document.getElementById('groupcontainer_'+idGroup).offsetHeight;
  newHeight = cHeight+groupdescriptionStep;

  if (newHeight>=reqHeight) {
    document.getElementById('groupcontainer_'+idGroup).style.height = reqHeight+'px';
  }
  else {
    document.getElementById('groupcontainer_'+idGroup).style.height = newHeight+'px';
    groupdescriptionTimeout = setTimeout('showGroupDescription('+idGroup+','+reqHeight+')',groupdescriptionDelay);
  }
}


function startHideGroupDescription(idGroup) {
  if (document.getElementById('groupcontainer_'+idGroup) && document.getElementById('groupcontent_'+idGroup)) {
    hideGroupDescription(idGroup);
  }
}

function hideGroupDescription(idGroup) {
  if (document.getElementById('groupcontainer_'+idGroup)) {
    cHeight = document.getElementById('groupcontainer_'+idGroup).offsetHeight;
    newHeight = cHeight-groupdescriptionStep;

    if (newHeight<=0) {
      document.getElementById('groupcontainer_'+idGroup).style.height = '0px';
    }
    else {
      document.getElementById('groupcontainer_'+idGroup).style.height = newHeight+'px';
      groupdescriptionTimeout = setTimeout('hideGroupDescription('+idGroup+')',groupdescriptionDelay);
    }
  }
}

function inArray(myArray,myVal) {
    for(var i=0,l=myArray.length;i<l;i++)
      if(myArray[i]==myVal) return i;
    return -1;
}


// Show/Hide - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

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';
        }
    }
}

// Ajax - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

function fbGetUrlDiv(id,url,innerhtml) {
    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 fbSendAjaxFormTargetDiv(idForm,baseurl,targetId,innerhtml) {

    var xReq=getXmlHttpRequest();
    var i;
    var url="";
    var myForm=document.getElementById(idForm);

    if (myForm) {
        var first=true;
        for(i=0;i<myForm.elements.length;i++) {
            var elmt=myForm.elements[i];
            var type=elmt.nodeName.toLowerCase();
            var ok=true;

            if (type=="input") {
                switch (elmt.type.toLowerCase()) {
                case "radio":
                case "checkbox":
                    if (!elmt.checked) ok=false;
                    break;

                case "submit":
                case "image":
                    ok=false;
                    break;
                }
            }
            else if ((type!="select") && (type!="textarea")) ok=false;
            if (ok) {
                if (first) first=false;
                else url+="&";
                url+=elmt.name+"="+elmt.value.replace(/%/g,"%25").replace(/&/g,"%26").replace(/=/g,"%3D").replace(/ /g,"%20");
            }
        }
    }

    var obj=document.getElementById(targetId);
    if (innerhtml!='') fbShowWaiting(obj,innerhtml);

    xReq.open("POST",baseurl,true);
    xReq.onreadystatechange=function(){fbEventGetUrlDiv(xReq,targetId);};
    xReq.setRequestHeader("Content-type","application/x-www-form-urlencoded"); 
    xReq.send(url);
}




function setCalendar(url) {
  fbGetUrlDiv('calendar',url,'');
}





function msgGetfocusHeight(obj) {
  obj.rows=3;
}

function msgLostfocusHeight(obj) {
  if (mytrim(obj.value)=='') obj.rows=1;
}

function mytrim(myString) {
  return myString.replace(/^\s+/g,'').replace(/\s+$/g,'')
} 



// 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];
    }
}

// INFOBULLE
/* ------------ marche que sous chrome --------------------
function GetId(id) {
  return document.getElementById(id);
}
var i=false; // La variable i nous dit si la bulle est visible ou non
 
function showinfo(text) {
  if(i==false && text != "") {

    info = document.createElement('div');
    info.id = 'info';
    info.className = 'infobulle';

    info.position = 'absolute';
    info.style.visibility = "visible";

    info.style.left = (event.x + 15)+"px";
    info.style.top = (event.y + 10)+"px";

    info.innerHTML = text;
    document.body.appendChild(info);

    i=true;
  }
}
function hideinfo() {
  if(i==true) {
    info = document.getElementById('info');
    document.body.removeChild(info);

    //GetId("info").style.visibility="hidden"; // Si la bulle est visible on la cache
    i=false;
  }
}
*/


//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
// functions to display an Alt informations
// Object :
// FASTBOIL                     1.0         20/01/2010
// http://www.fastboil.net
// hot@fastboil.net
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

var divCreated = 0;
var divPreview;
var divInnerHTML = "";

function getMouseCoordinates(event) {
  if (divInnerHTML!="") {
    ev = event || window.event;
    myLeft = ev.clientX+10;
    myTop = ev.clientY+10;
    myWidth = 150;
    myHeight = 150;
    myLeft = Math.max(0,Math.min(myLeft + document.body.scrollLeft,document.body.clientWidth + document.body.scrollLeft - myWidth));
    myTop = Math.max(0,Math.min(myTop + document.body.scrollTop,document.body.clientHeight + document.body.scrollTop - myHeight));
    showPreview(myLeft,myTop,myWidth,myHeight);
  }
  else
    hidediv('divpreview');

  if (divInnerHTMLCal!="") {
    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 showPreview(left,top,width,height) {
  if (divCreated==0) {
    divCreated++;
    divPreview = document.createElement('div');
    divPreview.setAttribute('id', 'divpreview');
    divPreview.style.position = 'absolute';
    document.body.appendChild(divPreview);
    divPreview.style.backgroundColor = '#FFFFFF';
    divPreview.style.borderColor = '#212121';
    divPreview.style.borderWidth = '1px';
    divPreview.style.borderStyle = 'solid';
    divPreview.style.padding = '3px';
  }
  if (divPreview) {
    divPreview.style.top = myTop+'px';
    divPreview.style.left = myLeft+'px';
    divPreview.innerHTML = divInnerHTML;
    divPreview.style.visibility = 'visible';
    showdiv('divpreview');
  }
}
function setAltInnerHTML(myStr) {
  divInnerHTML = myStr;
}

// INFOBULLE
// Mouse coordinates - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

var divCreatedCal = 0;
var divInfos;
var divInnerHTMLCal = "";

function showInfos(left,top,width,height) {

  if (divCreatedCal==0) {
    divCreatedCal++;
    divInfos = document.createElement('div');
    divInfos.setAttribute('id', 'divInfos');
    divInfos.style.position = 'absolute';
    divInfos.style.width = '200px';
    document.body.appendChild(divInfos);
    divInfos.style.backgroundColor = '#FFFFFF';
    divInfos.style.padding = '5px';
    divInfos.style.textAlign = 'left';
    divInfos.style.border = '1px solid #002F4C';
  }
  if (divInfos) {
    divInfos.innerHTML = divInnerHTMLCal;
    divInfos.style.top = (document.body.scrollTop+myTop+25)+'px';
    divInfos.style.left = (document.body.scrollLeft+myLeft-100)+'px';
    divInfos.style.visibility = 'visible';
    showdiv('divInfos');
  }
}
function setInfos(myStr,mouseCenter) {
  divCenter = mouseCenter;
  divInnerHTMLCal = myStr;
}


