window.onload=function() {montre();news();getNewBackground();getNewForme();setFooter();};
var page_actuelle = "news";

function montre(id) 
{
	var d = document.getElementById(id);
	for (var i = 1; i<=10; i++) 
	{
		if (document.getElementById('smenu'+i)) 
		{
			document.getElementById('smenu'+i).style.display='none';
		}
	}
	if (d) 
	{
		d.style.display='block';
	}
}

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 news()
{	
	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/news.php",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("contenu").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_contenu(pIdButton)
{	
	page_actuelle = pIdButton;
	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/" + pIdButton + ".php",true);
	xhr.send(null); 
}

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+50;
	
	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 +"; background-image: url(imgs/fondnews2.gif)";
	}
	if (page_actuelle == "newscomplet")
	{
		styleDiv = " height:"+ height +"; background-image: url(imgs/fondnews2.gif)";
	}
	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)
{
	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)
{
	var height = heightdiv('scroll',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);
	}
	if (document.all) 
	{
		document.getElementById('footer').style.setAttribute("cssText",styleDiv);
	}
	else
	{
		document.getElementById('footer').setAttribute("style",styleDiv);
	}
}

function getNewBackground()
{	
	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)
		{
			if (window.opera) 
			{
				document.getElementById("body").style.backgroundImage = "url('imgs/trameok/" + xhr.responseText + "')";
			}
			else if (document.all) 
			{
				document.getElementById("body").style.setAttribute("cssText","background-image:url(imgs/trameok/" + xhr.responseText +");");
			}
			else
			{
				document.getElementById("body").setAttribute("style","background-image: url(imgs/trameok/" + xhr.responseText +");");
			}
		}
	}

	xhr.open("POST","scripts/getBackgroundImage.php",true);
	xhr.send(null);
}

function traiteXmlFormes(pXml)
{
	var arrayFormes = pXml.getElementsByTagName("forme");
	var i=0;
	for(i;i<arrayFormes.length;i++)
	{
		var idDiv = "shape_"  + 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 bottom = arrayChild[2].firstChild.nodeValue;
		var left = arrayChild[3].firstChild.nodeValue;
		var height = arrayChild[4].firstChild.nodeValue;


		var styleDiv = "top:"+ top +";bottom:"+ bottom +"%;left:"+ left +";position:absolute;"
		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()
{	
	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",true);
	xhr.send(null);
}

function mailanonyme(){
var sb_domain = "free.fr"
var sb_user = "marie.mairet"
var sb_recipient = sb_user + "@" + sb_domain 
var sb_url = "mailto:" + sb_recipient
document.write(sb_recipient.link(sb_url));
}

function mailanonyme2(){
var sb_domain = "hotmail.com"
var sb_user = "da.afonso"
var sb_recipient = sb_user + "@" + sb_domain 
var sb_url = "mailto:" + sb_recipient
document.write(sb_recipient.link(sb_url));
}
