

//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
//
// neolease.js
// Javascript functions for Neolease website
//
// FASTBOIL                     1.0         10/04/2009
// http://www.fastboil.net
// hot@fastboil.net
//
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

//============================================================================//
//                             Layout                                         //
//============================================================================//
var h;
var fullMinHeight = 600;
var goLayout = false;

//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
// function setLayout
// Object : Setting div height
// FASTBOIL                     1.0         10/04/2009
// http://www.fastboil.net
// hot@fastboil.net
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
function setLayout() {
  if (goLayout) {
    goLayout = false;
    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;
    var contentHeight = fullHeight;
    if (document.getElementById('neoheader')) contentHeight-=document.getElementById('neoheader').offsetHeight;
    if (document.getElementById('neofootercontent')) contentHeight-=document.getElementById('neofootercontent').offsetHeight+5;

    if (document.getElementById('neofull'))    document.getElementById('neofull').style.height = fullHeight+'px';
    if (document.getElementById('neoleft'))    document.getElementById('neoleft').style.height = fullHeight+'px';
    if (document.getElementById('neofooter'))  document.getElementById('neofooter').style.top = (fullHeight-document.getElementById('neofooter').offsetHeight)+'px';
    if (document.getElementById('neocontent')) document.getElementById('neocontent').style.height = contentHeight+'px';
    if (document.getElementById('neobottom'))  document.getElementById('neobottom').style.top = (fullHeight-document.getElementById('neobottom').offsetHeight)+'px';

//    var textHeight = contentHeight;
//    if (document.getElementById('title') && document.getElementById('text')) document.getElementById('text').style.height = (contentHeight-document.getElementById('title').offsetHeight-20)+'px';
    goLayout = true;
  }
}

//============================================================================//
//                             On load                                        //
//============================================================================//

//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
// function neoOnLoad
// Object : To be called onLoad
// FASTBOIL                     1.0         10/04/2009
// http://www.fastboil.net
// hot@fastboil.net
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
function neoOnLoad() {
  goLayout = true;
  setLayout();
}

//============================================================================//
//                            Ajax                                            //
//============================================================================//
function menu(url) {
    fbGetUrlDiv('neomenu',url+'&fct=mc','');
    fbGetUrlDivContent(url+'&fct=pc','');
}

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;
        if (anId=='neocontent') Scroller.reset('neocontent');
    }
}

function fbGetUrlDivContent(url,innerhtml) {
  if (document.getElementById('neocontent')) {
    var xReq=getXmlHttpRequest();
    var obj=document.getElementById('neocontent');
    if (innerhtml != '') fbShowWaiting(obj,innerhtml);
    xReq.open("GET",url,true);
    xReq.onreadystatechange=function(){fbEventGetUrlDivContent(xReq);};
    xReq.send(null);
  }
}

var timeoutContent;
var delayContent = 10;
var stepContent = 9;

function fbEventGetUrlDivContent(xRequest) {
    if (xRequest.readyState==4) {
        clearTimeout(timeoutContent);
        var divHeight = document.getElementById('neocontent').offsetHeight;
        document.getElementById('neocontent').style.height = '0px';
        document.getElementById('neocontent').innerHTML=xRequest.responseText;
        showContent(divHeight);
    }
}

function showContent(reqHeight) {
    cHeight = document.getElementById('neocontent').offsetHeight;
    newHeight = cHeight+stepContent;
    if (newHeight>=reqHeight) {
        document.getElementById('neocontent').style.height = (reqHeight)+'px';
        Scroller.reset('neocontent');
    }
    else {
        document.getElementById('neocontent').style.height = (newHeight)+'px';
        timeoutContent = setTimeout('showContent('+reqHeight+')',delayContent);
    }
}

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...");
    }
}


