$.ajaxSetup({
cache: false
});


$("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;
									});

$(document).ready( function () {


//FORMULAIRE DE RECHERCHE
//produits

	
});
		function infolettre() {
		
		
		//alert($('#info-courriel').val());
	//	alert($('#info-nom').val());
		
		$.ajax({	
			async: true,
			type: "POST",
			url: "php/login/infolettre.php",
			data: "mail="+$('#info-courriel').val()+"&nom="+$('#info-nom').val()+"&lang=fr",
  		    success: function(msg){
			
			//alert(msg);
			
			if(msg == "add" || msg == "\nadd" || msg == "\r\nadd" )
			{
				$('#erreurinfolettre').html('<b>Inscription r&eacute;ussie</b>');
				$('#erreurinfolettre').removeClass("hidden");
			}
			else if(msg == "already" || msg == "\nalready" || msg == "\r\nalready")
			{
				$('#erreurinfolettre').html('<b>Vous &ecirc;tes d&eacute;j&agrave; inscrit</b>');
				$('#erreurinfolettre').removeClass("hidden");
			}
			else if(msg == "error"  || msg == "\nerror" || msg == "\r\nerror")
			{
				$('#erreurinfolettre').html('<b>Veuillez v&eacute;rifier les informations inscritent</b>');
				$('#erreurinfolettre').removeClass("hidden");
			}
			else
			{
				$('#erreurinfolettre').html('<b>Veuillez utiliser le script correctement</b>');
				$('#erreurinfolettre').removeClass("hidden");
			}
			
			
					
					// on désactive l'affichage du formulaire et on affiche un message de bienvenue à la place
				

			}
			});
	
	
	}
    
//CHARGEMENT AU DEMARAGE || CHANGEMENT DE PAGE


$(window).load(function(){


//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;

 								

									
					
								
$.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 "#", "?"
									if(!hash[1]){
									listblog();	
									}else{
									$.historyLoad(hash[1]);
									}
									
									return false;
									});

return false;
		
});
 
///MENU


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







//##################################################################
//RECHERCHE
 

function ouvre_popup(id_pic) {
alert("--");
 }
 
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#colRightBlog").html(hash);
			
		}
		else{
			// start page
			nom = nom+'#'+hash;
			window.location.replace(nom);
		}
	}
	
//ROLL OVER ###################################################################
function SimpleSwap(el,which){
  el.src=el.getAttribute(which || "origsrc");
}

function SimpleSwapSetup(){
  var x = document.getElementsByTagName("img");
  for (var i=0;i<x.length;i++){
    var oversrc = x[i].getAttribute("oversrc");
    if (!oversrc) continue;
      
    // preload image
    // comment the next two lines to disable image pre-loading
    x[i].oversrc_img = new Image();
    x[i].oversrc_img.src=oversrc;
    // set event handlers
    x[i].onmouseover = new Function("SimpleSwap(this,'oversrc');");
    x[i].onmouseout = new Function("SimpleSwap(this);");
    // save original src
    x[i].setAttribute("origsrc",x[i].src);
  }
}


//NOUVELLES #########################################################################
function list_t(total){
//alert(total);
$.ajax({	async:false,
		   type: "POST",
		   url: "php/nouvelles/list-t.php",
		   data: "nb="+total,
		   success: function(msg){
		   	$("div#nouvelles").html(msg);
			 }
		});
		$(".animFleche")
	.css({backgroundPosition: "0px 3px"})
	.hover(function(){
		$(this).stop().animate({backgroundPosition: "2px 3px"}, 200);
	}, function() {
		$(this).stop().animate({backgroundPosition: "0px 3px"}, 200);
	});
}
function list_s(){

$.ajax({ async:false,
		   type: "POST",
		   url: "php/nouvelles/list-s.php",
		   success: function(msg){
		  // alert(msg);
		   	$("div#nouvellesFull").html(msg);
			//alert(window.location.href.indexOf('#'));
			if(window.location.href.indexOf('#') != -1)
				{
				
					var ancre = window.location.href.split('#');
					var ancre = ancre[1];
					ancre = document.getElementById(ancre).offsetTop;
					scrollTo(0,ancre);
					
				}
				
			 }
		});
		$(".animFleche")
	.css({backgroundPosition: "0px 3px"})
	.hover(function(){
		$(this).stop().animate({backgroundPosition: "2px 3px"}, 200);
	}, function() {
		$(this).stop().animate({backgroundPosition: "0px 3px"}, 200);
	});

}
function list_l(){
if(window.location.href.indexOf('?') != -1)
				{
				//alert('ok');
					var ask = window.location.href.split('?');
					var ask = ask[1];
					$.ajax({ 
							async:false,
						   type: "POST",
						   url: "php/nouvelles/list-l.php",
						   data: "id="+ask,
						   success: function(msg){
						   //alert(msg);
								$("div#nouvellesFull").html(msg);
							}
					});
					
				}else{
				//alert('KO');

				window.location.href="nouvelles.html";
				}
				$(".animFleche")
	.css({backgroundPosition: "0px 3px"})
	.hover(function(){
		$(this).stop().animate({backgroundPosition: "2px 3px"}, 200);
	}, function() {
		$(this).stop().animate({backgroundPosition: "0px 3px"}, 200);
	});


}

function login()
{
var shapass = SHA256($('#motdepasse').val());
//alert(shapass);	 
	$.ajax({	
			async: false,
			type: "POST",
			url: "php/login/login.php",
			data: "action=login&loginftp="+$('#utilisateur').val()+"&passftp="+shapass,
  		    success: function(msg){
			//alert(msg);
			if(msg !='0')
			{
			window.parent.location.href ="zonemembres.php";
			}
			else
			{
			$('#connectionerror').html('Nom d\'utilisateur ou mot de passe invalide!');
			}

			}
			});
	
}
function logout()
{
		$.ajax({	
			async: true,
			url: "php/login/logout.php",
		    type: "POST",
			data: "action=logout",
			success: function(msg){
			//alert(msg);
			if(msg !='0')
			{
			window.location.reload();		
			}

			}
			});
		
	
}
