$.ajaxSetup({
cache: false
});
function popup(nom_de_la_page, nom_interne_de_la_fenetre)
{
window.open (nom_de_la_page, nom_interne_de_la_fenetre, config='height=700, width=600, toolbar=no, menubar=no, scrollbars=yes, resizable=no, location=no, directories=no, status=no')
return 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
	$("#searchForm").submit( function() {
	//On recherche le mot a la page 0
	//search($('#searchinput').val(),"0");
		var hash = "search('"+$('#searchinput').val()+"','0');";
		hash = hash.replace(/^.*#/, '');
		// moves to a new page. 
		// pageload is called at once. 
		// hash don't contain "#", "?"
		$.historyLoad(hash);
	return false;
	});

	$("#infolettre").submit( function() {
		
		
		//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" )
			{
			$("div#erreurinfolettre").html('Inscription r&eacute;ussie');
			}
			else if(msg == "already" || msg == "\nalready" || msg == "\r\nalready")
			{
						$("div#erreurinfolettre").html('Vous &ecirc;tes d&eacute;j&agrave; inscrit');

			}
			else if(msg == "error"  || msg == "\nerror" || msg == "\r\nerror")
			{
						$("div#erreurinfolettre").html('Veuillez v&eacute;rifier les informations inscrites');

			}
			else
			{
						$("div#erreurinfolettre").html('Veuillez utiliser le script correctement');
			}
			
			
					
					// on désactive l'affichage du formulaire et on affiche un message de bienvenue à la place
				

			}
			});
	
	return false;
	});

	
});

    
//CHARGEMENT AU DEMARAGE || CHANGEMENT DE PAGE


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

 $(window).load(function(){
					
$.historyInit(pageload, "jquery_history.html");	

return false;
		
}); 
 
///MENU

function test(){
//alert('test');
}
function stripslashes(str) {
str=str.replace(/\\'/g,'\'');
str=str.replace(/\\"/g,'"');
str=str.replace(/\\0/g,'\0');
str=str.replace(/\\\\/g,'\\');
return str;
}
function lastblog(){
$.ajax({
			url: "php/blog/lastblog.php",
			async: true,
  		    success: function(msg){
			//alert(msg);

		$("div#boite_gauche_fond").html(msg);
		

									//Lorsqu'on clique

									}
		   
 });	
}
 function listblog()
{
//alert('listblog');
	var hash = "listbloginit();";
		hash = hash.replace(/^.*#/, '');
		// moves to a new page. 
		// pageload is called at once. 
		// hash don't contain "#", "?"
		$.historyLoad(hash);
 }
 
 function listbloginit()//
{
$.ajax({	
			async: true,
			url: "php/blog/blog.php",
			 success: function(msg){
					$("div#blogue").html(msg);
					// on désactive l'affichage du formulaire et on affiche un message de bienvenue à la place
				

		   }
 });
 archives('off');
 }
 function get_blog(id)
{
archives('on');
	var hash = "get_blog_init('"+id+"');";
		hash = hash.replace(/^.*#/, '');
		// moves to a new page. 
		// pageload is called at once. 
		// hash don't contain "#", "?"
		$.historyLoad(hash);
 }
 function get_blog_init(id)
{
 
$("div#blogue").html("<div id='loader'><img  src='images/ajax-loader.gif'></div>");

$.ajax({	
			
			type: "POST",
			url: "php/blog/get_blog.php",
			data: "id="+id,
  		    success: function(msg){
			//alert(msg);
					$("div#blogue").html(msg);
					// on désactive l'affichage du formulaire et on affiche un message de bienvenue à la place
				

		   }
 });
 archives('on');
 } 
function get_article(id,art)
{
archives('on');
	var hash = "get_article_init('"+id+"','"+art+"');";
		hash = hash.replace(/^.*#/, '');
		// moves to a new page. 
		// pageload is called at once. 
		// hash don't contain "#", "?"
		$.historyLoad(hash);
 }
 function get_article_init(id,art)
{
//$("div#contenuRight").html("<div id='loader'><img  src='images/ajax-loader.gif'></div>");
//alert('get_article');
$.ajax({	
			
			type: "POST",
			url: "php/blog/get_article.php",
			data: "id="+id+"&art="+art,
  		    success: function(msg){
			//alert(msg);
					$("div#blogue").html(msg);
					// on désactive l'affichage du formulaire et on affiche un message de bienvenue à la place
				

		   }
 });
archives('on');
 }





 
 //##################################################################
//ARCHIVE
function get_archives()
{
archives('on');
	var hash = "get_archives_init();";
		hash = hash.replace(/^.*#/, '');
		// moves to a new page. 
		// pageload is called at once. 
		// hash don't contain "#", "?"
		$.historyLoad(hash);
 }
function get_archives_init(){

		$.ajax({	
			async: true,
			url: "php/blog/get_som_arch.php",
			 success: function(msg){
			// alert(msg);
			$("div#blogue").html(msg);
			}
		});
	
}
function get_month(date)
{
archives('on');
	var hash = "get_month_init('"+date+"');";
		hash = hash.replace(/^.*#/, '');
		// moves to a new page. 
		// pageload is called at once. 
		// hash don't contain "#", "?"
		$.historyLoad(hash);
 }
function get_month_init(date){

		$.ajax({
			type: "POST",		
			async: true,
			url: "php/blog/get_month_search.php",
			data: "getdate="+date,
			 success: function(msg){
			$("div#blogue").html(msg);
		
			}
		});
	
}
function archives(option){

	if(option == "on"){
		$.ajax({	
			async: true,
			url: "php/blog/get_arch.php",
			 success: function(msg){
			$("div#archives").html(msg);
			}
		});
		
	}else{
		$.ajax({	
			async: true,
			url: "php/blog/get_arch.php",
			 success: function(msg){
		
		
	var presentation = "<h2>Municipalité<br />de Lac-Beauport</h2>"
    +"<p>"
    +"La qualité de vie, l’environnement, la famille et la tranquillité sont des valeurs partagées par l’ensemble de la communauté lac-beauportoise. La préservation de ce milieu de vie exceptionnel constitue une priorité dans les actions politiques et citoyennes. "
    +"</p>"
    +"<p>"
    +"<a class=\"flecheDroite\" href=\"http://www.lac-beauport.ca/\" target=\"_blank\">En savoir plus sur Lac-Beauport</a>"
    +"</p>";
	$("div#archives").html(presentation+msg);
		}
		});
	}

}


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

function search(mot,page,ob,direction,searchaction)
{
archives('on');
$("div#colRightBlog").html("<div id='loader'><img  src='images/ajax-loader.gif'></div>");

//alert(mot);
		$.ajax({
		
		   type: "POST",
		   url: "php/blog/get_search.php",
		   data: "search="+mot+"&page="+page+"&ob="+ob+"&direction="+direction+"&searchaction="+searchaction,
		    success: function(msg){
				//alert(msg);
			
				$("div#colRightBlog").html(msg);
				},
		    
			error: function(){
			alert('Erreur AJAX : 0006 - Cette erreur est normalement temporaire, veuillez recommencer l\'opération...\n etienne.latulippe@oragecommunication.com');
			}
			
		});
	
}
//même recherche..par page
function searchpage(mot,page,ob,direction,searchaction)
{
if(undefined===window.searchaction){
window.searchaction = [];
}
		var hash = "search('"+mot+"','"+page+"','"+ob+"','"+direction+"','"+searchaction+"');";
		hash = hash.replace(/^.*#/, '');
		// moves to a new page. 
		// pageload is called at once. 
		// hash don't contain "#", "?"
		$.historyLoad(hash);	
//return false;		
}

//##################################################################
//



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#blogue").html(hash);
			
		}
		else{
			// start page
			nom = nom+'#'+hash;
			window.location.replace(nom);
		}
	}
	function list_t(total){
//alert(total);
$.ajax({
		   type: "POST",
		   url: "php/nouvelles/list-t.php",
		   data: "nb="+total,
		   success: function(msg){
		   	$("div#nouvelles").html(msg);
			 }
		});
}
function list_s(){

$.ajax({ 
		   type: "POST",
		   url: "php/nouvelles/list-s.php",
		   success: function(msg){
		  // alert(msg);
		   	$("div#nouvellesBig").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);
					
				}
				
			 }
		});
}

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

				window.location.href="nouvelles.html";
				}

}
	function sem_t(total){
//alert(total);
$.ajax({
		   type: "POST",
		   url: "php/semaine/list-t.php",
		   data: "nb="+total,
		   success: function(msg){
		   	$("div#semaine").html(msg);
			 }
		});
}
function sem_s(){

$.ajax({ 
		   type: "POST",
		   url: "php/semaine/list-s.php",
		   success: function(msg){
		  // alert(msg);
		   	$("div#nouvellesBig").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);
					
				}
				
			 }
		});
}

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

				window.location.href="nouvelles.html";
				}

}
	function pro_t(total){
//alert(total);
$.ajax({
		   type: "POST",
		   url: "php/prochainement/list-t.php",
		   data: "nb="+total,
		   success: function(msg){
		   	$("div#prochainement").html(msg);
			 }
		});
}
function pro_s(){

$.ajax({ 
		   type: "POST",
		   url: "php/prochainement/list-s.php",
		   success: function(msg){
		// alert(msg);
		   	$("div#prochainementBig").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);
					
				}
				
			 }
		});
}
	// function accueil_statics(total){
// // // // alert(total);
// $.ajax({
		   // type: "POST",
		   // url: "php/statics/accueil.inc",
		    // success: function(msg){
		   	// $("div#bienvenue").html(msg);
								// $("[rel=PopUp]").attr("onClick", "return popup(this.href,this.title);");

			 // }
		// });
// }	
// function accueil_espacejeunesse(total){
// // // // alert(total);
// $.ajax({
		   // type: "POST",
		   // url: "php/statics/espacejeunesse.inc",
		    // success: function(msg){
			// // // // // alert(msg);
		   	// $("div#espacejeunesse").html(msg);
								// $("[rel=PopUp]").attr("onClick", "return popup(this.href,this.title);");
			 // }
		// });
// }	
function pro_l(){
if(window.location.href.indexOf('?') != -1)
				{
				//alert('ok');
					var ask = window.location.href.split('?');
					var ask = ask[1];
					$.ajax({ 
						   type: "POST",
						   url: "php/prochainement/list-l.php",
						   data: "id="+ask,
						   success: function(msg){
						   //alert(msg);
								$("div#prochainementBig").html(msg);
							}
					});
					
				}else{
				//alert('KO');

				window.location.href="prochainement.html";
				}

}

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

var PreSimpleSwapOnload =(window.onload)? window.onload : function(){};
window.onload = function(){PreSimpleSwapOnload(); SimpleSwapSetup();}


