$.ajaxSetup({
cache: false
});

$(document).ready( function () {

//FORMULAIRE DE RECHERCHE
//produits
	$("#searchForm").submit( function() {
	//On recherche le mot a la page 0
	//search($('#searchinput').val(),"0");
//alert('init search');
	var hash = "search('"+addslashes($('#nom').val())+"','"+addslashes($('#someDropDown :selected').val())+"','"+addslashes($('#sub :selected').val())+"','"+addslashes($('#mun :selected').val())+"','0');";
		hash = hash.replace(/^.*#/, '');
		// moves to a new page. 
		// pageload is called at once. 
		// hash don't contain "#", "?"
		$.historyLoad(hash);
	return false;
	});


	
});

    
//CHARGEMENT AU DEMARAGE || CHANGEMENT DE PAGE


$(window).load(function(){
$.ajax({
		   type: "POST",
		   url: "/fr/php/login/ifconnect.php",
		   data: "action=ifconnect",
		   success: function(msg){
		//	alert(msg);
				if(msg!=0) // si la connexion en php a fonctionnée
				{	
				
								$("div#containerg").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
				{				
				
				}
		   }
		});

$.ajax({
			url: "php/recherche/search.php",
			async: true,
  		    success: function(msg){
			//alert(msg);

		$("div#boutiqueMenu").html(msg);
		 $("div#menufade").slideDown("normal");

									//Lorsqu'on clique

									}
});

$.ajax({
			url: "php/blog/lastblog.php",
			async: true,
  		    success: function(msg){
			//alert(msg);

		$("div#lastblog").html(msg);
		 $("div#lastblog").slideDown("normal");

									//Lorsqu'on clique

									}
		   
 });	
 								
									$("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 "#", "?"
									$.historyLoad(hash[1]);
									return false;
									});
									
$.historyInit(pageload); 
return 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 search(mot,cat,scat,mun,page,ob,direction,searchaction)
{
if( cat != 'X' || scat != 'Sous-catégories' || mun != 'X'){
$("div#contenuRight").html("<div id='loader'><img  src='../../js/images/ajax-loader.gif'></div>");

if(mot == 'Nom')mot = '';
if(ob === 'undefined')ob = '';
if(direction === 'undefined')direct = '';
if(searchaction === 'undefined')searchaction = '';


//alert('form in progresse');
//alert("search="+mot+"&cat="+cat+"&scat="+scat+"&mun="+mun+"&page="+page+"&ob="+ob+"&direction="+direction+"&searchaction="+searchaction);
var url = "get_search_artistes.php";
if(cat == 1){
url = "get_search_artistes.php";
}else if(cat == 2)
{
url = "get_search_events.php";
}else if(cat == 3){
url = "get_search_org.php";
}
//alert(url);	
	$.ajax({
		
		   type: "POST",
		   url: "/php/recherche/"+url,
		   data: "nom="+mot+"&cat="+cat+"&scat="+scat+"&ville="+mun+"&page="+page+"&ob="+ob+"&direction="+direction+"&searchaction="+searchaction,
		    success: function(msg){
				//alert(msg);
				$("div#repertoire_bas").html(msg);
				//Shadowbox.init({ skipSetup: true }); Shadowbox.setup(); 				
				},
		    
			error: function(){
			//search(mot,cat,scat,mun,page,ob,direction,searchaction);
			}
			
		});
	}
}
function get_unique(pd_id,cat)
{

	var hash = "get_unique_init('"+pd_id+"','"+cat+"');";
		hash = hash.replace(/^.*#/, '');
		// moves to a new page. 
		// pageload is called at once. 
		// hash don't contain "#", "?"
		$.historyLoad(hash);
 }
 function get_unique_init(pd_id,cat)
{
//alert(cat);
scrollTo(0,290);
var url = "";
if(cat == 1){
url = "get_unique_artistes.php";
}else if(cat == 2)
{
url = "get_unique_events.php";
}else if(cat == 3){
url = "get_unique_org.php";
}
$.ajax({	
			async:false,
			type: "POST",
			url: "/php/recherche/"+url,
			data: "id="+pd_id,
  		    success: function(msg){
		 	//alert(msg);
				$("div#repertoire_bas").html(msg);
				
					// on désactive l'affichage du formulaire et on affiche un message de bienvenue à la place
				

		   }
 });
 }
 function searchp(mot,cat,scat,mun,page,ob,direction,searchaction)
{
//alert('search');
	var hash = "search('"+addslashes(mot)+"','"+addslashes(cat)+"','"+addslashes(scat)+"','"+addslashes(mun)+"','"+addslashes(page)+"','"+addslashes(ob)+"','"+addslashes(direction)+"','"+addslashes(searchaction)+"');";
		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#repertoire_bas").html(hash);
			
		}
		else{
			// start page
			nom = nom+'#'+hash;
			window.location.replace(nom);
		}
	}

