$.ajaxSetup({
cache: false
});

function addslashes(str) {
str=str.replace(/\\/g,'\\\\');
str=str.replace(/\'/g,'\\\'');
str=str.replace(/\"/g,'\\"');
str=str.replace(/\0/g,'\\0');
return str;
}
function stripslashes(str) {
str=str.replace(/\\'/g,'\'');
str=str.replace(/\\"/g,'"');
str=str.replace(/\\0/g,'\0');
str=str.replace(/\\\\/g,'\\');
return str;
}

function GetCookie (name) {
         if(document.cookie) { 
                  index = document.cookie.indexOf(name);
                  if ( index != -1) {
                           nDeb = (document.cookie.indexOf( "=", index) + 1);
                           nFin = document.cookie.indexOf( ";", index);
                           if (nFin == -1) {nFin = document.cookie.length;}
                           return unescape(document.cookie.substring(nDeb, nFin));
                  }
         }
         return null;
}


function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}
function eraseCookie(name) {
	createCookie(name,"",-1);
}
$(document).ready( function () {

 	$("#recherche").submit( function() {
		init_recherche();
		return false;
	});

});


//BOUTON DE CONNECTION
$(window).load(function(){
$("div#oldContent").html($("div#colContenu").html());
while($("div#oldContent").html().indexOf('gestion') != -1){
$("div#oldContent").html($("div#oldContent").html().replace("gestion", "nogest"));
}
    
 $( "#oldContent a" ).each(

     function( intIndex ){
    	if($( this ).attr('name') != ''){
     	$( this ).attr('name',$( this ).attr('name')+'_tmp');
	}
     }
      
     );
$.historyInit(pageload, "jquery_history.html");	

			$("a.remote").click(function(){
									var hash = $(this).attr('href');
									
									hash = hash.replace(/^.*#/, '');
									hash = hash.split(':')
									// moves to a new page. 
									// pageload is called at once. 
									// hash don't contain "#", "?"
									//alert(hash[1]);
								
									$.historyLoad(hash[1]);
									
									
									return false;
									});
									
									var hash = window.location.href;
									hash = hash.split('#')
									//alert(hash[1]);
									//alert(hash[0].indexOf('liste_beautes')); 
									//alert(window.location.href.indexOf('#'));
									if(typeof(hash[1])!='undefined'){
									$.historyLoad(hash[1]);
									}		




//Initialisation du calendrier

//IFCONNECT
$.ajax({
		   type: "POST",
		   url: "php/login/ifconnect.php",
		   data: "action=ifconnect",
		   success: function(msg){
			//alert(msg);
				if(msg!=0) // si la connexion en php a fonctionnée
				{	
								$("div#container").html(msg);

					//$("div#body").html("oki");
					
					// on désactive l'affichage du formulaire et on affiche un message de bienvenue à la place
				}
				else // si la connexion en php n'a pas fonctionnée
				{				
					
				}
		   }
		});
return false;
});

 

 function recherche(motClef,page){
	$("div#colContenu").html("<center><img src='/fr/images/ajax-loader.gif'></center>");
 $.ajax({
		   type: "POST",
		   url: "/fr/php/recherche/recherche.php",
		   data: "mot="+ motClef,
		   success: function(msg){
			//alert('RESULTATS'+msg);
				if(msg!=0) // si la connexion en php a fonctionnée
				{	
					$("div#colContenu").html(msg);
				}
		   }
		});

 }
 
 function init_recherche(){
 	//On recherche le mot a la page 0
var motClef = encodeURIComponent(addslashes($("#rechercheInput").val()));
		var hash = "recherche('"+motClef+"','0');";
		hash = hash.replace(/^.*#/, '');
		// moves to a new page. 
		// pageload is called at once. 
		// hash don't contain "#", "?"
		$.historyLoad(hash);

 }
 
  function pageload(hash) {

								//le nom de la page qui load le script
								var nom = window.location.pathname;
								nom = nom.split("/");
								nom = nom[nom.length - 1];
								//nom = nom.substr(0, nom.lastIndexOf("."));
								nom = nom.replace(new RegExp("(%20)", "g"), "");
								if(nom.indexOf('#')!=-1){var sentinelle = 1}
								nom = nom.replace("#", "");
								//On initialise l'historique du menu 
								
								
		if(hash && hash.indexOf("(") != -1) {
			// restore ajax loaded state
			if($.browser.msie) {
				// jquery's $.load() ne prend pas les caractères trop spéciaux ex: ë
				hash = encodeURIComponent(hash);
			}
			
			hash = "<script type='text\/javascript'>"+hash+"<\/script>";
			hash = unescape(hash);
			
			$("div#colContenu").html(hash);
			
		}
		else if(hash != ""){
			nom = nom+'#'+hash;
			window.location.replace(nom);
		}else{
		if($("div#oldContent").html() != ""){
		$("div#colContenu").html($("div#oldContent").html());
		}
		}
	}
	
	
/* http://www.kryogenix.org/code/browser/searchhi/ */
/* Modified 20021006 to fix query string parsing and add case insensitivity */
/* Modified 20070316 to stop highlighting inside nosearchhi nodes */
/* Modified 20081217 to do in-page searching and wrap up in an object */
/* Modified 20081218 to scroll to first hit like 
   http://www.woolyss.free.fr/js/searchhi_Woolyss.js and say when not found */

searchhi = {
  highlightWord: function(node,word) {
    // Iterate into this nodes childNodes
    if (node.hasChildNodes) {
	    for (var hi_cn=0;hi_cn<node.childNodes.length;hi_cn++) {
		    searchhi.highlightWord(node.childNodes[hi_cn],word);
	    }
    }

    // And do this node itself
    if (node.nodeType == 3) { // text node
	    tempNodeVal = node.nodeValue.toLowerCase();
	    tempWordVal = word.toLowerCase();
	    if (tempNodeVal.indexOf(tempWordVal) != -1) {
		    var pn = node.parentNode;
		    // check if we're inside a "nosearchhi" zone
		    var checkn = pn;
		    while (checkn.nodeType != 9 && 
		    checkn.nodeName.toLowerCase() != 'body') { 
		    // 9 = top of doc
			    if (checkn.className.match(/\bnosearchhi\b/)) { return; }
			    checkn = checkn.parentNode;
		    }
		    if (pn.className != "recherche") {
			    // word has not already been highlighted!
			    var nv = node.nodeValue;
			    var ni = tempNodeVal.indexOf(tempWordVal);
			    // Create a load of replacement nodes
			    var before = document.createTextNode(nv.substr(0,ni));
			    var docWordVal = nv.substr(ni,word.length);
			    var after = document.createTextNode(nv.substr(ni+word.length));
			    var hiwordtext = document.createTextNode(docWordVal);
			    var hiword = document.createElement("span");
			    hiword.className = "recherche";
			    hiword.appendChild(hiwordtext);
			    pn.insertBefore(before,node);
			    pn.insertBefore(hiword,node);
			    pn.insertBefore(after,node);
			    pn.removeChild(node);
			    searchhi.found += 1;
			    if (searchhi.found == 1) pn.scrollIntoView();
		    }
	    }
    }
  },


  
  process: function(wordstring) {
    searchhi.found = 0;
	if(wordstring != null){
    var words = wordstring.split("+");
    for (w=0;w<words.length;w++) {
	//alert(words[w]);
	    searchhi.highlightWord(document.getElementsByTagName("body")[0],words[w]);
    }
    if (searchhi.found === 0) {
      searchhi.nohits();
    }
	eraseCookie('recherche');
	}
  },
  
  nohits: function() {
  },

  init: function() {
              searchhi.process(decodeURI(GetCookie('recherche')));
              return false;       
  }
  
  
}; 


function getUrlVars()
{
var vars = [], hash;
var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');
 
for(var i = 0; i < hashes.length; i++)
{
hash = hashes[i].split('=');
vars.push(hash[0]);
vars[hash[0]] = hash[1];
}
 
return vars;
}
var getvars = getUrlVars();
(function(i) {
	var u =navigator.userAgent;var e=/*@cc_on!@*/false; var st = setTimeout;
	if(/webkit/i.test(u)){st(function(){
		var dr=document.readyState;
		if(dr=="loaded"||dr=="complete")
			{i()}
		else{st(arguments.callee,10);}},10);}
	else if((/mozilla/i.test(u)&&!/(compati)/.test(u)) || (/opera/i.test(u))){
		document.addEventListener("DOMContentLoaded",i,false); } else if(e){     (
	function(){var t=document.createElement('doc:rdy');try{t.doScroll('left');
	i();t=null;}catch(e){st(arguments.callee,0);}})();}else{window.onload=i;}})(searchhi.init);









