// JavaScript Document

objXHR = null;
booXml = false;
strHtmlId = null;

/***************************************************/
/* Fonction d'appelle de procedure AJAX            */
/***************************************************/
	
function ajax_animation(url)
{
 if(url != "aucun")
	Ajax('js/ajax.php','action=animation&lien='+url ,'POST','newwindow');
}

function ajax_selecteur(id,w)
{
	document.getElementById("flag_reseau").style.width = w+'px';
	restoreReseau(w);
	Ajax('js/ajax.php','action=selecteur&id='+id,'POST','choixrub');
}


function startReseau (w) {
	
	$("#reseau2").stop().queue(function(){
		$(this).animate({width: w}, 300);
		$(this).dequeue();
	});
}

function restoreReseau(rw2) {
	rw2 = document.getElementById("flag_reseau").style.width;
	$("#reseau2").stop().queue(function(){
		$(this).animate({width: rw2}, 300);
		$(this).dequeue();
	});
}

function change_banniere()
{
	var swf = new Array();
	swf["1"] = 'arbre-final-txt.swf';
	swf["2"] = 'haltere-final-txt.swf';
	swf["3"] = 'F1-final-txt.swf';
	swf["4"] = 'peche-final-txt.swf';
	swf["5"] = 'plante-final-txt.swf';
	swf["6"] = 'pyramide-final-txt.swf';
	swf["7"] = 'ski-final-txt.swf';
	
	var x = Math.random()*7;  
	x = Math.floor(x);
	x = x+1;
	
	document.getElementById('animation').innerHTML = "";
	$("#animation").flash({
	src:"images/banniere/"+swf[x],
	wmode:"transparent",
	width:1023,
	height:177 },{ version:8});
	//Ajax('js/ajax.php','action=flash','POST','animation');
}

function change_banniere2()
{
	var swf = new Array();
	swf["1"] = 'popcorn-final-txt.swf';
	swf["2"] = 'G8-final-txt.swf';
	swf["3"] = 'papillon-final-txt.swf';
	
	var x = Math.random()*3;  
	x = Math.floor(x);
	x = x+1;
	
	document.getElementById('animation').innerHTML = "";
	$("#animation").flash({
	src:"images/banniere/"+swf[x],
	wmode:"transparent",
	width:1023,
	height:257 },{ version:8});
	//Ajax('js/ajax.php','action=flash','POST','animation');
}

function ajax_affiche_news(id)
{	
	var li = document.getElementsByTagName('li');
	for(i=0;i<li.length; i++)
		{
			li[i].style.color = "#000";
		}
	document.getElementById('item_rub_'+id).style.color = "red";
	Ajax('js/ajax.php','action=news&id='+id,'POST','newsletterYes');
}


/***************************************************/
/* Chargement + insertion des élément PHP charger  */
/***************************************************/

function Ajax(strFile, strParam, booMethod, strIdName)
{
	
	booXml = false;
	strHtmlId = strIdName;
	
	if(booMethod == false)
	{
		strMethod = 'GET';
	}
	else
	{
		strMethod = 'POST';
	}
	Init(strFile, strParam, strMethod);
}

function Init(strFile, strParam, strMethod )
{
	if(window.XMLHttpRequest)
	{
		objXHR = new XMLHttpRequest();
	}
	else
	{
		try
		{
			objXHR = new ActiveXObject("Microsoft.XMLHTTP");
		}
		catch(e)
		{
			alert(e);
		}
	}
	if(objXHR)
	{	
		objXHR.onreadystatechange = Load;
		objXHR.open( strMethod, strFile, true );
		if(strMethod == 'POST')
		{
			objXHR.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");	
		}
		objXHR.send(strParam);
	}
	else
	{
		alert("Votre navigateur n'est pas compatible avec Ajax !");
	}
	
}

function Load(){
	if(objXHR.readyState == 4)
	{
		if(objXHR.status == 200)
		{
			if(booXml == true)
			{
				if(objXHR.responseXML)
				{
					var xmlDocument = objXHR.responseXML.documentElement;
					//var x = xmlDocument.getElementsByTagName("configuration")[0].childNodes[0];
					for(i=0; i<xmlDocument.childNodes.length; i++)
					{
						if(xmlDocument.childNodes[i].nodeType == 1)
						{
							document.getElementById(xmlDocument.childNodes[i].nodeName).innerHTML = xmlDocument.childNodes[i].firstChild.nodeValue;
						}
					}
				}
			}
			else
			{
				document.getElementById(strHtmlId).innerHTML = objXHR.responseText;
			}
		}
	}
} 