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' onclick='RechercheRequest()'><span>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;\">");
if (parent.location.hash != "")
	{
	var pageactive = parent.location.hash.substring(1,11);
	AffichePageRequest(pageactive);
	}
});
//fonction ajax de récuperation de l'URL
function AffichePageRequest(pageactive,style)
{
	$("mouline").effect("opacity", {duration:100}).start(0,1);
	parent.location.hash = pageactive;
		if (window.ie) 
		{
		makeNewHash(pageactive);	//IE
		}
			else
			{
				if (window.opera && window.history)  //opera
				{     
					var div_timer = new Element("div", {
						"styles" : {"visibility" : "hidden"},
						"id" : "test_timer"
						});
						div_timer.injectAfter("page");
				 	var div_img = new Element("div", {
						"styles" : {"visibility" : "hidden"},
						"id" : "div_img"
						});
						div_img.injectAfter("test_timer");
				  var img = new Element("img", {
							"src" : "javascript:location.href='javascript:onTick()';",
						  "id" : "img"
						});
						img.injectInside("div_img");
				 	history.navigationMode = "compatible";
				  timerCookie = window.setTimeout("onTick()", 100);
					$("test_timer").setText("1");
				}
				else
				{
				pollHash(); //les autres firefox, safari
				}
			}
}	
// affichage page a partir du hash
function AffichePageHash(pageactive) 
{
	if (parent.location.hash != "")
	{							
		//alert ("dans onFrameLoaded urlactive="+urlactive);
		var urlactive = parent.location.hash.substring(1,11);
		//alert ("urlhash="+urlactive);				
						
		AffichePageRequest(urlactive);//ReinitBandeau();FonduBandeauRequest();
	}
	else {AffichePageRequest(pageactive)};//ReinitBandeau();FonduBandeauRequest();}
}
// fin affichage page a partir du hash
// historique IE
function makeNewHash(pageactive) 
{
		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 = {update : $("page"), method : "get", data : "a="+pageactive }; 
	
		var myAjax = new Ajax(url, options).request();
		myAjax.addEvent("onSuccess", function(resultat){
			parent.location.hash = diesepage;
			new Fx.Style("mouline", "opacity").start(1,0);
			
		//*************************
  		AfficheSpecif();
  	//*************************
		});
}
// fin historique IE
// historique firefox
var expectedHash="";
function handleHistory()
{
  //alert ('expectedHash='+expectedHash);
  if ( parent.location.hash != expectedHash )
  {
    expectedHash = parent.location.hash;
    var nouvellepage = expectedHash.substring(1,11);
    if (nouvellepage == "") nouvellepage = "page100000";
    //alert (newoption);
      		
		var url = "page.php";
		var options = {update : $("page"), method : "get", data : "a="+nouvellepage }; 
	
				var myAjax = new Ajax(url, options).request();
				myAjax.addEvent("onSuccess", function(resultat){
																			
			 	//*************************
  				AfficheSpecif();
  			//*************************
			});
  }
}
function pollHash() 
{
  handleHistory();
  $("mouline").effect("opacity").start(1,0);
  window.setInterval("handleHistory();", 200);
}
// fin historique firefox
//historique opera
function onTick() 
{
  pageactive = document.location.hash.substring(1,11);
  //alert ("pageactive="+pageactive);				
	window.clearTimeout(timerCookie);
 	$("test_timer").setText("0");
	
	var url = "page.php";
	var options = {update : $("page"), method : "get", data : "a="+pageactive }; 
	
			var myAjax = new Ajax(url, options).request();
			myAjax.addEvent("onSuccess", function(resultat){
			$("mouline").effect("opacity").start(1,0);
			window.clearTimeout(timerCookie);
    	$("test_timer").setText("0");
    	
    	//*************************
  			AfficheSpecif();
  		//*************************
    	});
	          
  if ($("test_timer").getText() == 0) timerCookie = window.setTimeout(onTick, 100);
  $("test_timer").setText("1");
}
//fin historique opera
function RechercheRequest(pageactive)
{
	$("mouline").effect("opacity", {duration:100}).start(0,1);
	var recherche = $("inputrecherche").getValue();
	
	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);
			 }
			 if (resultat=="vide")
			 {
			 if (parent.location.hash!="")AffichePageHash(pageactive);
			 if (parent.location.hash=="")window.location.replace("accueil.php");;
			 }
			});
}
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);
}
