window.addEvent('domready', function() {
//creation de l'input du moteur de recherche
var div_recherche = new Element("div", {
	"id" : "recherche"
});
div_recherche.injectAfter("page");
var url = "recherchenbl.php";
var myAjax = new Ajax(url).request();
myAjax.addEvent("onSuccess", function(resultat){
	//alert ("saut de ligne dans recherche = "+resultat);
	var ObjJson = Json.evaluate(resultat);
	var recherchenbL = ObjJson.recherchenbL;
	var visible = ObjJson.visible;
	if (visible == "oui"){
	div_recherche.setHTML("<a class='recherche' onSubmit='RechercheRequest()' onclick='RechercheRequest()'><span><img src='images/loupe.png' border='0'>&nbsp;Recherchez dans le site&nbsp;</span></a>"+recherchenbL+"<input onChange=\"RechercheRequest()\" onSubmit='RechercheRequest()' id=\"inputrecherche\" name=\"inputrecherche\" type='text' value=''>");
	}
});
var div_mouline = new Element("div", {
"id" : "mouline"
});
div_mouline.injectAfter("page");
div_mouline.setHTML("<img src=\"images/mouline.gif\" style=\"height:30px; width:30px;\">");
//reload de la page
var paramget = window.location.search;
var paramhash = parent.location.hash;

if ((paramget.indexOf("?a=page",0)==-1) && (paramhash == "")){
var pageactive = "page100000";
window.location.replace("accueil.php#"+pageactive);
}
if ((paramget.indexOf("?a=page",0)!=-1) && (paramhash == "")){
var pageactive = paramget.substring(3,14);
window.location.replace("accueil.php#"+pageactive);
}
if (paramhash != ""){
	var pageactive = paramhash.substring(1,11); 
	}
if (!window.ie) { //**********firefox, opera, safari
	var div_refreshfx = new Element("div", {
	"id" : "refreshfx"
	});
	div_refreshfx.injectAfter("page");
	div_refreshfx.setHTML(0);
	pollHash();
	}
if (window.ie)  makeNewHash(); //*********************ie
});
//*********************************************
function AffichePageRequest(pageactive)
{
	if (document.getElementById("init").innerHTML == "1" ){
	stop();
	}
	$("mouline").effect("opacity", {duration:100}).start(0,1);
	if (window.ie) 
	{
		parent.location.hash = pageactive;
		makeNewHash(); //*********ie
	}
	if (!window.ie)  //**********firefox, opera, safari
	{
		clearInterval(histofirefox);
		parent.location.hash = pageactive;
		var url = "page.php";
		var options = {method : "get", data : "a="+pageactive }; 

		var myAjax = new Ajax(url, options).request();
		myAjax.addEvent("onSuccess", function(resultat){
		$("page").setHTML(resultat);
		$("mouline").effect("opacity").start(1,0);
		verifsidiapo(pageactive);
		//****************
			//AfficheSpecif(pageactive);
		//****************
		$("refreshfx").setHTML(1);
		handleHistory();
		});
	}
}	
// historique ie
function makeNewHash() 
{
		var pageHash = parent.location.hash;
    var iframe = document.createElement("iframe");
			with(iframe){
				name = "historyFrame";
				id = "historyFrame";
				}
			document.appendChild(iframe);			 
    
    new Fx.Style("historyFrame", "opacity").set(0);

    var doc =  document.getElementById("historyFrame").contentWindow.document;
    doc.open("javascript:'<html></html>'");
    doc.write("<html><head><scri" + "pt type=\"text/javascript\">parent.onFrameLoaded(\""+ pageHash + "\");</scri" + "pt></head><body></body></html>");
    doc.close();
}
function onFrameLoaded(diesepage) 
{
		if (diesepage == "") diesepage = "#page100000";
	
		if (parseInt(diesepage.length) == 11) var pageactive = diesepage.substring(1,11);
		if (parseInt(diesepage.length) == 10) var pageactive = diesepage ;
						
		var url = "page.php";
		var options = {method : "get", data : "a="+pageactive }; 
	
		var myAjax = new Ajax(url, options).request();
		myAjax.addEvent("onSuccess", function(resultat){
			parent.location.hash = diesepage;
			$("page").setHTML(resultat);
			verifsidiapo(pageactive);
			$("mouline").effect("opacity").start(1,0);
		//*************************
  		//AfficheSpecif(pageactive);
  	//*************************
		});
}
// fin historique ie
// historique firefox, opera, safari
function pollHash() 
{
  handleHistory();
 	histofirefox = setInterval("handleHistory();", 200);
}
var expectedHash="";
function handleHistory()
{
  //alert ('expectedHash='+expectedHash);
  var divrefreshfxspeed = $("refreshfx").getText();
	if (divrefreshfxspeed == "0") {
		if ( parent.location.hash != expectedHash ) {
				expectedHash = parent.location.hash;
				var nouvellepage = expectedHash.substring(1,11);
				     		
				var url = "page.php";
				var options = {method : "get", data : "a="+nouvellepage }; 
	
				var myAjax = new Ajax(url, options).request();
				myAjax.addEvent("onSuccess", function(resultat){
				$("page").setHTML(resultat);
				verifsidiapo(nouvellepage);
				//*************************
					//AfficheSpecif(nouvellepage);
				//*************************
				});
			}	
	}		
	if (divrefreshfxspeed == "1") {
	expectedHash = parent.location.hash;
	$("refreshfx").setHTML(0);
	histofirefox = setInterval("handleHistory();", 200);
	}
}
// fin historique firefox, opera, safari
function RechercheRequest(pageactive)
{
	var recherche = $("inputrecherche").getValue();
	if (recherche != "")
	{
	$("mouline").effect("opacity", {duration:100}).start(0,1);
	var url = "recherche.php";
	var options = {method : "post", data : "inputrecherche="+recherche }; 
	  
	  //alert ("inputrecherche="+recherche);
		
		var myAjax = new Ajax(url, options).request();
		myAjax.addEvent("onSuccess", function(resultat){
				new Fx.Style("mouline", "opacity").start(1,0);
			 //alert (resultat);
			 if (resultat!="vide")
			 {
			 //$("#rubrique").css("paddingLeft","20px");
			 $("rubrique").setHTML(resultat);
			 }
			});
	}
}
function EnvoiMessageRequest()
{
	$("mouline").effect("opacity", {duration:100}).start(0,1);
	
	var nom = $("nom").getValue();
	var tel = $("tel").getValue();
	var email = $("email").getValue(); 
	var message = $("message").getValue();
	
	var url = "envoimessage.php";
		var options = {method : "post", data : "nom="+nom+"&tel="+tel+"&email="+email+"&message="+message }; 
	
		var myAjax = new Ajax(url, options).request();
		myAjax.addEvent("onSuccess", function(resultat){
				new Fx.Style("mouline", "opacity").start(1,0);
			 //alert (resultat);
				if (resultat=="envoye")
				alert("Votre message a été envoyé avec succes.\nUne copie vous est adressée a l'adresse que vous avez indiquée");
				else alert(resultat);
				});
}		
function ChoixLangRequest(lang,page)
{
	$("mouline").effect("opacity", {duration:100}).start(0,1);
	
	var url = "choixlang.php";
		var options = {method : "post", data : "lang="+lang }; 
	
		var myAjax = new Ajax(url, options).request();
		myAjax.addEvent("onSuccess", function(resultat){
				new Fx.Style("mouline", "opacity").start(1,0);
			 //alert (resultat);
				AffichePageRequest(page) ;
				});
}
function AccesProtegeRequest(pageactive)
{
	$("mouline").effect("opacity", {duration:100}).start(0,1);
	var nomespace = $("nomespace").getValue();
	var mdpespace = $("mdpespace").getValue();	
	var url = "espaceprotege.php";
	//alert ("nomespace = "+nomespace+"mdpespace = "+mdpespace);
	
	var options = {method : "post", data : "nomespace="+nomespace+"&mdpespace="+mdpespace }; 
	
	var myAjax = new Ajax(url, options).request();
	myAjax.addEvent("onSuccess", function(resultat){
			$("mouline").effect("opacity").start(1,0);
			var ObjJson = Json.evaluate(resultat);
			var retour = ObjJson.retourespace.info;
			
			if (retour=="Bienvenue sur l\'Espace Client") AffichePageRequest("page910000");
			if (retour=="Erreur d\'identification") AffichePageRequest(pageactive);
			alert (retour);
			});
}			
function QuitteAccesProtegeRequest()
{
	$("mouline").effect("opacity", {duration:100}).start(0,1);
	var c1 = "oui";
	var c2 = "oui";
	
	var url = "espaceprotege.php";
	var options = {method : "post", data : "accesclient="+c1+"&supprimer="+c2 }; 
	
	var myAjax = new Ajax(url, options).request();
	myAjax.addEvent("onSuccess", function(resultat){
			$("mouline").effect("opacity").start(1,0);
			var ObjJson = Json.evaluate(resultat);
			var retour = ObjJson.retourespace.info;
			AffichePageRequest("page100000");
			alert (retour);
			});
}
function AccesTelechargement(pagedetelechargement)
{
	$("mouline").effect("opacity", {duration:100}).start(0,1);
		
	//alert (pagedetelechargement);	
	var url = "espacetelechargement.php";
	
	var myAjax = new Ajax(url).request();
	myAjax.addEvent("onSuccess", function(resultat){
			$("mouline").effect("opacity").start(1,0);
			//alert ("resultat ="+resultat);
			if (resultat == "acces") AffichePageRequest(pagedetelechargement);
			if (resultat == "identification") alert("merci de vous identifier");
			});
}
function montre(elmt)
{
//alert (elmt);
$(elmt).setOpacity(1);
}

function cache(elmt)
{
$(elmt).setOpacity(0);
}

