/* ALIGNEMENT VERTICAL */
// Recupere la taille de la fenetre pour un alignement vertical
function getWindowHeight() {
    var windowHeight = 0;
    if (typeof(window.innerHeight) == 'number') {
        windowHeight = window.innerHeight;
    }
    else {
        if (document.documentElement && document.documentElement.clientHeight) {
            windowHeight = document.documentElement.clientHeight;
        }
        else {
            if (document.body && document.body.clientHeight) {
                windowHeight = document.body.clientHeight;
            }
        }
    }
    return windowHeight;
}

// Effectue l'alignement vertical sur l'identifiant 'content'
function setContents() {
    if (document.getElementById) {
        var windowHeight = getWindowHeight();
        if (windowHeight > 0) {
            var contentElement = document.getElementById('content_vertical');
            if(contentElement != null){
                var contentHeight = contentElement.offsetHeight;
                if (contentHeight == 0) contentHeight = windowHeight;
                //alert(windowHeight + " - " + contentHeight);
                if (windowHeight - contentHeight >= 0) {
                    contentElement.style.position = 'relative';
                    contentElement.style.top = ((windowHeight / 2) - (contentHeight / 2)) + 'px';
                }
                else {
                    contentElement.style.position = 'static';
                }
            }
        }
    }
    montre();
}
/**********************************************************/

/* Navigation au travers des menus verticaux-horizontaux */
function montre(id) {
    var d = document.getElementById(id);
        for (var i = 1; i<=20; i++) {
            if (document.getElementById('niveau'+i)) {
                document.getElementById('niveau'+i).style.display='none';
            }
        }
    if (d) {d.style.display='block';}
}
/**********************************************************/

/* Montre ou cache un element */
function montre_statut(id,statut) {
    var d = document.getElementById(id);
    if(statut != ""){
        if (d) {d.style.display=statut;}
    }
    else{
        if (d) {
            if(d.style.display == "block"){statut = "none";}
            else statut = "block";
            d.style.display=statut;
        }
    }
}
/**********************************************************/

function addToFavorites(anchor){
    if (window.external){
        window.external.AddFavorite(anchor.getAttribute('href'), anchor.getAttribute('title'));
    }
}
/* Confirmation suppression */
function confirm_delete(){
    var valret;
    valret = confirm("Confirmez-vous la suppression de cet élément ?");
    return valret;
}
/******************************************************/

// Initialisation à l'ouverture de la page
window.onload = function() {
    setContents();
}

// Initialisation au moment du redimensionnement de la page
window.onresize = function() {
    setContents();
}
/******************************************************/
/* Fonction d'ouverture d'une popup */
function OuvrirPop(theURL,features,h,w){
    splits = theURL.split(".");
    window.open(theURL,splits[0],features+',width='+w+',height='+h+',top='+((screen.height-h)/2)+',left='+((screen.width-w)/2));
}
    
// hide the first ul element of the current element
function timeoutHide()
{
    // start the timeout
    eval( "timeout" + this.id + " = window.setTimeout('hideUlUnder( \"" + this.id + "\" )', " + timeout + " );");
}

// hide the ul elements under the element identified by id
function hideUlUnder( id )
{   
    document.getElementById(id).getElementsByTagName('ul')[0].style['visibility'] = 'hidden';
    document.getElementById(id).getElementsByTagName('a')[0].className = 'linkOut';
}

// show the first ul element found under this element
function show()
{
    // show the sub menu
    this.getElementsByTagName('ul')[0].style['visibility'] = 'visible';
    var currentNode=this;
    while(currentNode)
    {
            if( currentNode.nodeName=='LI')
            {
                currentNode.getElementsByTagName('a')[0].className = 'linkOver';
            }
            currentNode=currentNode.parentNode;
    }
    // clear the timeout
    eval ( "clearTimeout( timeout"+ this.id +");" );
    hideAllOthersUls( this );
}

// hide all ul on the same level of  this list item
function hideAllOthersUls( currentLi )
{
    var lis = currentLi.parentNode;
    for ( var i=0; i<lis.childNodes.length; i++ )
    {
        if ( lis.childNodes[i].nodeName=='LI' && lis.childNodes[i].id != currentLi.id )
        {
            hideUlUnderLi( lis.childNodes[i] );
        }
    }
}

// hide all the ul wich are in the li element
function hideUlUnderLi( li )
{
    var as = li.getElementsByTagName('a');
    for ( var i=0; i<as.length; i++ )
    {
        as.item(i).className="";
    }
    var uls = li.getElementsByTagName('ul');
    for ( var i=0; i<uls.length; i++ )
    {
        uls.item(i).style['visibility'] = 'hidden';
    }
} 

// Permet d'afficher une image en grand
function Affichegrande(cheminImage,texte)
{
    newImage = new Image;
    newImage.src = cheminImage;
    html = '<HTML><HEAD><TITLE>'+texte+'</TITLE><meta http-equiv="Pragma" content="no-cache"></HEAD><BODY leftmargin=0 marginwidth=0 topmargin=0 marginheigth=0 oncontextmenu="return false"><CENTER>'+
    '<a href="#" onClick="window.close()"><IMG SRC="'+cheminImage+'" BORDER=0 NAME=monImage alt="'+texte+'"border="0" onLoad="window.resizeTo(document.monImage.width+20,document.monImage.height+80); window.moveTo((screen.width-document.monImage.width)/2,5)"> </a></CENTER></BODY></HTML>';
    ouvrirImage = window.open('','_blank','toolbar=0,location=0,menuBar=0,scrollbars=0,resizable=0');
    ouvrirImage.document.write(html);
}

var strUrl = "ajax.php";
var xmlhttp;

function getXmlRequest() {
  try
    {
    if (is_ie5up) xmlhttp=new ActiveXObject("Msxml2.XMLHTTP");
    // Firefox, Opera 8.0+, Safari
    else xmlhttp=new XMLHttpRequest();
    }
  catch (e)
    {
    // Internet Explorer
    try
      {
      xmlhttp=new ActiveXObject("Msxml2.XMLHTTP");
      }
    catch (e)
      {
      try
        {
        xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
        }
      catch (e)
        {
        alert("Your browser does not support AJAX!");
        return false;
        }
      }
    }
    return xmlhttp;
}

function checkDisponibilite(id_lieu,debut,fin)
{
  url = strUrl + "?id_lieu=" + id_lieu + "&debut=" + debut + "&fin=" + fin;
  //alert(url);
  xmlhttp=getXmlRequest();
  if (xmlhttp)
  {
    xmlhttp.open("GET", url, false);
    xmlhttp.send(null);
    if(xmlhttp.responseText != ""){
        alert("Le lieu sélectionné n'est pas libre à la période sélectionnée. Veuillez adapter votre choix !");
        return false;
    }
    else return true;
  }               
  
}
