window.onload=function() {boot();bootprog()};

function boot()
{	
	var page_actuelle = "presentation";

	if (window.XMLHttpRequest)
	{
		var xhr = new XMLHttpRequest();
	}
	else if(window.ActiveXObject)
	{
		var xhr = new ActiveXObject("Microsoft.XMLHTTP");
	}
	else
	{
		alert("Votre navigateur n'est pas compatible avec AJAX...");
	}
	
	xhr.onreadystatechange = function ()
	{
		if(xhr.readyState == 4)
		{
			document.getElementById("intro").innerHTML=xhr.responseText;
		}
	}

	xhr.open("POST","contenu/"+page_actuelle+".php",true);
	xhr.send(null);
}
function bootprog()
{	
	var page_actuelle = "Detailprog";

	if (window.XMLHttpRequest)
	{
		var xhr = new XMLHttpRequest();
	}
	else if(window.ActiveXObject)
	{
		var xhr = new ActiveXObject("Microsoft.XMLHTTP");
	}
	else
	{
		alert("Votre navigateur n'est pas compatible avec AJAX...");
	}
	
	xhr.onreadystatechange = function ()
	{
		if(xhr.readyState == 4)
		{
			document.getElementById("contenu").innerHTML=xhr.responseText;
		}
	}

	xhr.open("POST","contenu/"+page_actuelle+".php",true);
	xhr.send(null);
}

function maj_contenu(pIdButton)
{	
	page_actuelle = pIdButton;
	if (page_actuelle == "realisations")
	{
		/*alert("You are using MSIE");*/
		div = "scroll_trvx"
	}
	else {
		div = "scroll"
	};
	if (window.XMLHttpRequest)
	{
		var xhr = new XMLHttpRequest();
	}
	else if(window.ActiveXObject)
	{
		var xhr = new ActiveXObject("Microsoft.XMLHTTP");
	}
	else
	{
		alert("Votre navigateur n'est pas compatible avec AJAX...");
	}
	
	xhr.onreadystatechange = function ()
	{
		if(xhr.readyState == 4)
		{
			document.getElementById("contenu").innerHTML=xhr.responseText;
			setHeightScroll(div,35);
			setHeightEnd('tiretF');
			setHeightDiv('reservebloc',12);
		}
	}

	xhr.open("POST","contenu/" + pIdButton + ".php",true);
	xhr.send(null); 
}

function maj_allcontenu(Div,pIdButton)
{	
	var strToSend = "Div=" + Div;

	if (window.XMLHttpRequest)
	{
		var xhr = new XMLHttpRequest();
	}
	else if(window.ActiveXObject)
	{
		var xhr = new ActiveXObject("Microsoft.XMLHTTP");
	}
	else
	{
		alert("Votre navigateur n'est pas compatible avec AJAX...");
	}
	
	xhr.onreadystatechange = function ()
	{
		if(xhr.readyState == 4)
		{
			document.getElementById(Div).innerHTML=xhr.responseText;
		}
	}

	xhr.open("POST","contenu/" + pIdButton + ".php",true);
	xhr.send(null); 
}


function maj_rsltarchive(pIdButton,month)
{	
	if (window.XMLHttpRequest)
	{
		var xhr = new XMLHttpRequest();
	}
	else if(window.ActiveXObject)
	{
		var xhr = new ActiveXObject("Microsoft.XMLHTTP");
	}
	else
	{
		alert("Votre navigateur n'est pas compatible avec AJAX...");
	}


	xhr.onreadystatechange = function ()
	{
		if(xhr.readyState == 4)
		{
			document.getElementById("scroll").innerHTML=xhr.responseText;
			setHeightScroll('scroll',35);
			setHeightEnd('tiretF');
			setHeightDiv('reservebloc',12);
		}
	}
	xhr.open('Post','contenu/'+pIdButton+'.php?month='+month, true);
	xhr.send(null);
}

function maj_archive(id)
{
	var d = document.getElementById(id);
	for (var i = 1; i<=100; i++) 
	{
		if (document.getElementById('archivefull'+i)) 
		{
			document.getElementById('archivefull'+i).style.display='none';
		}
	}
	if (d) 
	{
		d.style.display='block';
	}
}

function maj_slctarchive(pIdButton,num)
{	
	if (window.XMLHttpRequest)
	{
		var xhr = new XMLHttpRequest();
	}
	else if(window.ActiveXObject)
	{
		var xhr = new ActiveXObject("Microsoft.XMLHTTP");
	}
	else
	{
		alert("Votre navigateur n'est pas compatible avec AJAX...");
	}


	xhr.onreadystatechange = function ()
	{
		if(xhr.readyState == 4)
		{
			document.getElementById("scroll").innerHTML=xhr.responseText;
		}
	}
	xhr.open('Post','contenu/'+pIdButton+'.php?num='+num, true);
	xhr.send(null);
}

function maj_newsfull(pIdButton,num)
{	
	var strToSend = "num=" + num;

	if (window.XMLHttpRequest)
	{
		var xhr = new XMLHttpRequest();
	}
	else if(window.ActiveXObject)
	{
		var xhr = new ActiveXObject("Microsoft.XMLHTTP");
	}
	else
	{
		alert("Votre navigateur n'est pas compatible avec AJAX...");
	}
	
	xhr.onreadystatechange = function ()
	{
		if(xhr.readyState == 4)
		{
			document.getElementById("newsfull"+ num).innerHTML=xhr.responseText;
			setHeightScroll('scroll',35);
			setHeightEnd('tiretF');
			setHeightDiv('reservebloc',12);
		}
	}

	xhr.open("POST", "contenu/" + pIdButton + ".php", true);
	xhr.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
    xhr.send(strToSend);
}

function maj_newsclose(pIdButton,num)
{	
	var strToSend = "num=" + num;

	if (window.XMLHttpRequest)
	{
		var xhr = new XMLHttpRequest();
	}
	else if(window.ActiveXObject)
	{
		var xhr = new ActiveXObject("Microsoft.XMLHTTP");
	}
	else
	{
		alert("Votre navigateur n'est pas compatible avec AJAX...");
	}
	
	xhr.onreadystatechange = function ()
	{
		if(xhr.readyState == 4)
		{
			document.getElementById("trvxfull"+ num).innerHTML=xhr.responseText;
		}
	}

	xhr.open("POST", "contenu/" + pIdButton + ".php", true);
	xhr.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
    xhr.send(strToSend);
}

function maj_menu(autor1,autor2,slct)
{	
	var strToSend = "selector=" + autor1 + "_" + autor2 + "_" + slct;

	if (window.XMLHttpRequest)
	{
		var xhr = new XMLHttpRequest();
	}
	else if(window.ActiveXObject)
	{
		var xhr = new ActiveXObject("Microsoft.XMLHTTP");
	}
	else
	{
		alert("Votre navigateur n'est pas compatible avec AJAX...");
	}
	
	xhr.onreadystatechange = function ()
	{
		if(xhr.readyState == 4)
		{
			document.getElementById("menuselector").innerHTML=xhr.responseText;

		}
	}

	xhr.open("POST", "contenu/slctprojects.php", true);
	xhr.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
    xhr.send(strToSend);
	maj_projects(autor1,autor2,slct)
}

function maj_projects(autor1,autor2,slct) {	
	
	var strToSend = "selector=" + autor1 + "_" + autor2 + "_" + slct;

	if (window.XMLHttpRequest)
	{
		var xhr = new XMLHttpRequest();
	}
	else if(window.ActiveXObject)
	{
		var xhr = new ActiveXObject("Microsoft.XMLHTTP");
	}
	else
	{
		alert("Votre navigateur n'est pas compatible avec AJAX...");
	}
	
	xhr.onreadystatechange = function ()
	{
		if(xhr.readyState == 4)
		{
			document.getElementById("scroll_trvx").innerHTML=xhr.responseText;
			setHeightEnd('tiretF');

		}
	}

	xhr.open("POST", "contenu/projects.php", true);
	xhr.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
    xhr.send(strToSend);
}

function maj_lastfull(pIdButton,num)
{	
	var strToSend = "num=" + num;

	if (window.XMLHttpRequest)
	{
		var xhr = new XMLHttpRequest();
	}
	else if(window.ActiveXObject)
	{
		var xhr = new ActiveXObject("Microsoft.XMLHTTP");
	}
	else
	{
		alert("Votre navigateur n'est pas compatible avec AJAX...");
	}
	
	xhr.onreadystatechange = function ()
	{
		if(xhr.readyState == 4)
		{
			document.getElementById(pIdButton + num).innerHTML=xhr.responseText;
		}
	}

	xhr.open("POST", "contenu/"+ pIdButton +".php", true);
	xhr.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
    xhr.send(strToSend);
}

function maj_trvxfull(pIdButton,num)
{	
	var strToSend = "num=" + num;

	if (window.XMLHttpRequest)
	{
		var xhr = new XMLHttpRequest();
	}
	else if(window.ActiveXObject)
	{
		var xhr = new ActiveXObject("Microsoft.XMLHTTP");
	}
	else
	{
		alert("Votre navigateur n'est pas compatible avec AJAX...");
	}
	
	xhr.onreadystatechange = function ()
	{
		if(xhr.readyState == 4)
		{
			document.getElementById("trvxfull"+ num).innerHTML=xhr.responseText;

		}
	}

	xhr.open("POST", "contenu/" + pIdButton + ".php", true);
	xhr.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
    xhr.send(strToSend);
}

function maj_trvxclose(pIdButton,num)
{	
	var strToSend = "num=" + num;

	if (window.XMLHttpRequest)
	{
		var xhr = new XMLHttpRequest();
	}
	else if(window.ActiveXObject)
	{
		var xhr = new ActiveXObject("Microsoft.XMLHTTP");
	}
	else
	{
		alert("Votre navigateur n'est pas compatible avec AJAX...");
	}
	
	xhr.onreadystatechange = function ()
	{
		if(xhr.readyState == 4)
		{
			document.getElementById("trvxfull"+ num).innerHTML=xhr.responseText;
		}
	}

	xhr.open("POST", "contenu/" + pIdButton + ".php", true);
	xhr.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
    xhr.send(strToSend);
}

function maj_imgfull(pIdButton,num,img,legend)
{	
	var strToSend = "num=" + num;
	var strToSend = "img=" + img + "_" + legend;
	
	if (window.XMLHttpRequest)
	{
		var xhr = new XMLHttpRequest();
	}
	else if(window.ActiveXObject)
	{
		var xhr = new ActiveXObject("Microsoft.XMLHTTP");
	}
	else
	{
		alert("Votre navigateur n'est pas compatible avec AJAX...");
	}
	
	xhr.onreadystatechange = function ()
	{
		if(xhr.readyState == 4)
		{
			document.getElementById("imgfull"+ num).innerHTML=xhr.responseText;
		}
	}

	xhr.open("POST", "contenu/" + pIdButton + ".php", true);
	xhr.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
    xhr.send(strToSend);
}

function maj_newsgo(dir,idgo,idback)
{	
	page_actuelle = dir;
	var strToSend = "linkid=" + idgo + "_" + idback;

	if (window.XMLHttpRequest)
	{
		var xhr = new XMLHttpRequest();
	}
	else if(window.ActiveXObject)
	{
		var xhr = new ActiveXObject("Microsoft.XMLHTTP");
	}
	else
	{
		alert("Votre navigateur n'est pas compatible avec AJAX...");
	}
	
	xhr.onreadystatechange = function ()
	{
		if(xhr.readyState == 4)
		{
			document.getElementById('contenu').innerHTML=xhr.responseText;
			setHeightScroll('scroll_trvx',35);
			setHeightEnd('tiretF');
			setHeightDiv('reservebloc',12);
		}
	}

	xhr.open("POST", "contenu/" + dir +".php", true);
	xhr.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
    xhr.send(strToSend);
}

function maj_newsgo2(dir,idgo,idback)
{	
	page_actuelle = "realisations";
	var strToSend = "linkid=" + idgo + "_" + idback;

	if (window.XMLHttpRequest)
	{
		var xhr = new XMLHttpRequest();
	}
	else if(window.ActiveXObject)
	{
		var xhr = new ActiveXObject("Microsoft.XMLHTTP");
	}
	else
	{
		alert("Votre navigateur n'est pas compatible avec AJAX...");
	}
	
	xhr.onreadystatechange = function ()
	{
		if(xhr.readyState == 4)
		{
			document.getElementById('scroll_trvx').innerHTML=xhr.responseText;
			setHeightEnd('tiretF');
		}
	}

	xhr.open("POST", "contenu/" + dir +".php", true);
	xhr.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
    xhr.send(strToSend);
}

function maj_newsreturn(dir,idgo,idback)
{	
	page_actuelle = dir;
	var strToSend = "linkid=" + idgo + "_" + idback;

	if (window.XMLHttpRequest)
	{
		var xhr = new XMLHttpRequest();
	}
	else if(window.ActiveXObject)
	{
		var xhr = new ActiveXObject("Microsoft.XMLHTTP");
	}
	else
	{
		alert("Votre navigateur n'est pas compatible avec AJAX...");
	}
	
	xhr.onreadystatechange = function ()
	{
		if(xhr.readyState == 4)
		{
			document.getElementById('contenu').innerHTML=xhr.responseText;
			setHeightScroll('scroll',35);
			setHeightEnd('tiretF');
			setHeightDiv('reservebloc',12);
		}
	}

	xhr.open("POST", "contenu/" + dir +".php", true);
	xhr.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
    xhr.send(strToSend);
}

function maj_newsreturn2(dir,idgo,idback)
{	
	page_actuelle = "news";
	var strToSend = "linkid=" + idgo + "_" + idback;

	if (window.XMLHttpRequest)
	{
		var xhr = new XMLHttpRequest();
	}
	else if(window.ActiveXObject)
	{
		var xhr = new ActiveXObject("Microsoft.XMLHTTP");
	}
	else
	{
		alert("Votre navigateur n'est pas compatible avec AJAX...");
	}
	
	xhr.onreadystatechange = function ()
	{
		if(xhr.readyState == 4)
		{
			document.getElementById('scroll').innerHTML=xhr.responseText;
			setHeightEnd('tiretF');
		}
	}

	xhr.open("POST", "contenu/" + dir +".php", true);
	xhr.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
    xhr.send(strToSend);
}

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

function findY(pIdDiv)
{
	var  objectDiv=document.getElementById(pIdDiv);
	var posY=document.getElementById(pIdDiv).offsetTop+52;
	
	return posY;
}

function heightdiv(pIdDiv,pBottom)
{
	var screentnav=getWindowHeight();
	var topdiv=screentnav-findY(pIdDiv)-pBottom; 
	return topdiv;
}

function setHeightDiv(pIdDiv,pBottom)
{
	var height = heightdiv(pIdDiv,pBottom);
	var styleDiv = "height:"+ height +";"
	if (page_actuelle == "news")
	{
		styleDiv = " height:"+ height;
	}
	if (window.opera) 
	{
		document.getElementById(pIdDiv).setAttribute("style",styleDiv);
	}
	else if(document.all) 
	{
		document.getElementById(pIdDiv).style.setAttribute("cssText",styleDiv);
	}
	else
	{
		document.getElementById(pIdDiv).setAttribute("style",styleDiv);
	}
}

function setHeightScroll(pIdDiv,pBottom)
{
	if (page_actuelle == "realisations")
	{
		/*alert("You are using MSIE");*/
		pIdDiv = "scroll_trvx"
	}else if(page_actuelle == "focustrvx"){
		pIdDiv = "scroll_trvx"
	} 
	else {
		pIdDiv = "scroll"
	};
	var height = heightdiv(pIdDiv,pBottom);
	var styleDiv = "height:"+ height +";"
	if (window.opera) 
	{
		document.getElementById(pIdDiv).setAttribute("style",styleDiv);
	}
	else if (document.all) 
	{
		document.getElementById(pIdDiv).style.setAttribute("cssText",styleDiv);
	}
	else
	{
		document.getElementById(pIdDiv).setAttribute("style",styleDiv);
	}
}

function setHeightEnd(pIdDiv)
{
	if (page_actuelle == "realisations")
	{
		/*alert("You are using MSIE");*/
		div = "scroll_trvx"
	}
	else {
		div = "scroll"
	};
	var height = heightdiv(div,33)/1.5;
	var styleDiv = "height:"+ height +";"
	if (window.opera) 
	{
		document.getElementById(pIdDiv).setAttribute("style",styleDiv);
	}
	else if (document.all) 
	{
		document.getElementById(pIdDiv).style.setAttribute("cssText",styleDiv);
	}
	else
	{
		document.getElementById(pIdDiv).setAttribute("style",styleDiv);
	}
}

function setFooter()
{	
	var screentnav=getWindowHeight();
	var height=document.getElementById('footer').offsetHeight;
	var top =getWindowHeight()-height;
	var styleDiv = "top:"+ top +";"
	if (window.opera) 
	{
		document.getElementById("footer").setAttribute("style",styleDiv);
		document.getElementById("footer2").setAttribute("style",styleDiv);
	}
	if (document.all) 
	{
		document.getElementById('footer').style.setAttribute("cssText",styleDiv);
		document.getElementById('footer2').style.setAttribute("cssText",styleDiv);
	}
	else
	{
		document.getElementById('footer').setAttribute("style",styleDiv);
		document.getElementById('footer2').setAttribute("style",styleDiv);
	}
}

function mouseover(pIdButton,num)
{
	var strToSend = "num=" + num;

	var arraySpan=document.getElementsByTagName("div");
	var classVar = "";
	if (document.all) 
	{
		classVar = "className";
	}
	else
	{
		classVar = "class";
	}
	for(var i=0;i<arraySpan.length;i++)
	{
		
		if (arraySpan[i].getAttribute(classVar) == "mouseout")
		{
			arraySpan[i].setAttribute(classVar,"mouseout");
		}
	}
	document.getElementById(pIdButton + num).setAttribute(classVar,"mouseover");
}

function mouseout(pIdButton,num)
{
	var strToSend = "num=" + num;

	var arraySpan=document.getElementsByTagName("div");
	var classVar = "";
	if (document.all) 
	{
		classVar = "className";
	}
	else
	{
		classVar = "class";
	}
	for(var i=0;i<arraySpan.length;i++)
	{
		
		if (arraySpan[i].getAttribute(classVar) == "mouseover")
		{
			arraySpan[i].setAttribute(classVar,"mouseover");
		}
	}
	document.getElementById(pIdButton + num).setAttribute(classVar,"mouseout");
}

function activemenu(id) 
{
	var arraySpan=document.getElementsByTagName("a");
	var classVar = "";
	if (document.all) 
	{
		classVar = "className";
	}
	else
	{
		classVar = "class";
	}
	for(var i=0;i<arraySpan.length;i++)
	{
		
		if (arraySpan[i].getAttribute(classVar) == "ActiveMenuItem")
		{
			arraySpan[i].setAttribute(classVar,"NOActiveMenuItem");
		}
	}
	document.getElementById("s" + id).setAttribute(classVar,"ActiveMenuItem");
}
function activearchive(id) 
{
	var arraySpan=document.getElementsByTagName("a");
	var classVar = "";
	if (document.all) 
	{
		classVar = "className";
	}
	else
	{
		classVar = "class";
	}
	for(var i=0;i<arraySpan.length;i++)
	{
		
		if (arraySpan[i].getAttribute(classVar) == "ActiveArchivItem")
		{
			arraySpan[i].setAttribute(classVar,"NOActiveArchivItem");
		}
	}
	document.getElementById("s" + id).setAttribute(classVar,"ActiveArchivItem");
}

function traiteXmlFormes(pXml)
{
	var arrayFormes = pXml.getElementsByTagName("forme");
	var i=0;
	for(i;i<arrayFormes.length;i++)
	{
		var idDiv = "menupict_"  + arrayFormes[i].getAttribute("id");
		var idImg= "img_" + arrayFormes[i].getAttribute("id");
		var arrayChild = arrayFormes[i].childNodes;
		var imgNode = document.createElement("img");
		imgNode.setAttribute("src",arrayChild[0].firstChild.nodeValue);
		//imgNode.setAttribute("id",idImg);
		
		document.getElementById(idDiv).innerHTML = "";
		document.getElementById(idDiv).appendChild(imgNode);
		
		var top = arrayChild[1].firstChild.nodeValue;
		var left = arrayChild[2].firstChild.nodeValue;
		//var height = arrayChild[3].firstChild.nodeValue;
		//var bottom = arrayChild[4].firstChild.nodeValue;


		var styleDiv = "top:"+ top +";left:"+ left +";position:absolute; z-index:0;"
		//var styleDiv = "top:"+ top +";bottom:"+ bottom +"%;left:"+ left +";position:absolute; z-index:0;"
		//var styleImg = "height:"+ height +";width:auto;"
		if (window.opera) 
		{
			document.getElementById(idDiv).setAttribute("style",styleDiv);
			//document.getElementById(idImg).setAttribute("style",styleImg);
		}
		else if (document.all) 
		{
			document.getElementById(idDiv).style.setAttribute("cssText",styleDiv);
			//document.getElementById(idImg).style.setAttribute("cssText",styleImg);
		}
		else
		{
			document.getElementById(idDiv).setAttribute("style",styleDiv);
			//document.getElementById(idImg).setAttribute("style",styleImg);
		}
	}
}

function getNewForme(dir,left,top)
{	
	option = dir + "_" + left + "_" + top;

	if (window.XMLHttpRequest)
	{
		var xhr = new XMLHttpRequest();
	}
	else if(window.ActiveXObject)
	{
		var xhr = new ActiveXObject("Microsoft.XMLHTTP");
	}
	else
	{
		alert("Votre navigateur n'est pas compatible avec AJAX...");
	}
	
	xhr.onreadystatechange = function ()
	{
		if(xhr.readyState == 4)
		{
			//alert(xhr.responseXML);
			traiteXmlFormes(xhr.responseXML);
		}
	}

	xhr.open('POST','scripts/getForme.php?option='+option,true);
	xhr.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	xhr.send(null);
}

function activediap() {
	$(".diaporama1").jDiaporama({
		animationSpeed: "slow",
		delay:4
	});
}

