$.ajaxSetup({
cache: false
});



//BOUTON DE CONNECTION

$(function(){
 $.ajax({async: false,type: "POST",url: "php/login/ifconnect.php",data: "action=ifconnect",success: function(msg){
if(msg){
$("div#buffer").html(msg);
}
}}); 
});

$(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() {
		$.ajax({	
			async: true,
			type: "POST",
			url: "php/login/infolettre.php",
			data: "mail="+$('#info-courriel').val()+"&nom="+$('#info-nom').val()+"&lang=en",
  		    success: function(msg){
			
			//alert(msg);
			
			if(msg == "add")
			{alert('Inscription success');}
			else if(msg == "already")
			{
			alert('You are already registered');
			}
			else if(msg == "error")
			{alert("Please check your informations");
			}
			else
			{alert("Veuillez utiliser le script correctement");}
			
			
					Shadowbox.init({ skipSetup: true }); Shadowbox.setup(); 
					// on désactive l'affichage du formulaire et on affiche un message de bienvenue à la place
				

			}
			});
	
	return false;
	});

	
});

    
//CHARGEMENT AU DEMARAGE || CHANGEMENT DE PAGE


$(window).load(function(){

$.ajax({
			url: "php/cat/menu.php",
			async: true,
  		    success: function(msg){
			//alert(msg);

		$("div#boutiqueMenu").html(msg);
		 $("div#menufade").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;
		
});
 
///MENU

function l_cat(cat,cat_parent,cat_name)
{
//Menu Dynamique
if($('#item'+cat).css('display') != "block")
{
				$('.ul_item').css('display','none');
				$('a.ul_item').css('font-weight','normal');
				$('#item'+cat).css('display','block');
				$('a#item'+cat).css('font-weight','bolt');
				var action =  $("li a#id"+cat+"init:first").attr('href');
				
				action =action.replace("javascript:","");
				pageload(action);
						
}else
{
				$('.ul_item').css('display','none');
				$('a.ul_item').css('font-weight','normal');
}



}

function l_scat(cat,cat_parent,cat_name,page,ob,direction)// 
{

$("div#contenuRight").html("<div id='loader'><img  src='images/ajax-loader.gif'></div>");
				if($('#item'+cat_parent).css('display') != "block")
				{
				$('.ul_item').css('display','none');
				$('a.ul_item').css('font-weight','normal');
				$('#item'+cat_parent).css('display','block');
				$('a#item'+cat_parent).css('font-weight','bolt');
				}
$('.remotem').removeClass('remotem');
$('#style'+cat).addClass('remotem');
if(!page){page = "0"};
$.ajax({	
			async: true,
			type: "POST",
			url: "php/cat/get_product.php",
			data: "cat="+cat+"&cat_name="+cat_name+"&cat_parent="+cat_parent+"&page="+page+"&ob="+ob+"&direction="+direction,
  		    success: function(msg){
			//alert(msg);
					
				$("div#contenuRight").html(msg);
					Shadowbox.init({ skipSetup: true }); Shadowbox.setup(); 
					// on désactive l'affichage du formulaire et on affiche un message de bienvenue à la place
				

		   }
 });
 }
  function l_rabais(cat,cat_parent,cat_name,page,ob,direction)// 
{

//cat_name = stripslashes(cat_name);
$("div#contenuRight").html("<div id='loader'><img  src='images/ajax-loader.gif'></div>");
				if($('#item'+cat_parent).css('display') != "block")
				{
				$('.ul_item').css('display','none');
				$('a.ul_item').css('font-weight','normal');
				$('#item'+cat_parent).css('display','block');
				$('a#item'+cat_parent).css('font-weight','bolt');
				}
$('.remotem').removeClass('remotem');
$('#style'+cat).addClass('remotem');
if(!page){page = "0"};
$.ajax({	
			async: true,
			type: "POST",
			url: "php/cat/get_rabais.php",
			data: "cat="+cat+"&cat_name="+cat_name+"&cat_parent="+cat_parent+"&page="+page+"&ob="+ob+"&direction="+direction,
  		    success: function(msg){
			//alert(msg);
					
				$("div#contenuRight").html(msg);
					Shadowbox.init({ skipSetup: true }); Shadowbox.setup(); 
					// on désactive l'affichage du formulaire et on affiche un message de bienvenue à la place
				

		   }
 });
 }
 function l_scatpage(cat,cat_parent,cat_name,page,ob,direction)
{
scrollTo(0,290);
		var hash = 'l_scat("'+cat+'","'+cat_parent+'","'+cat_name+'","'+page+'","'+ob+'","'+direction+'");';
		hash = hash.replace(/^.*#/, '');
		// moves to a new page. 
		// pageload is called at once. 
		// hash don't contain "#", "?"
		$.historyLoad(hash);
}
function get_unique_product(pd_id)
{
	var hash = "get_unique_product_init('"+pd_id+"');";
		hash = hash.replace(/^.*#/, '');
		// moves to a new page. 
		// pageload is called at once. 
		// hash don't contain "#", "?"
		$.historyLoad(hash);
 }
  function get_rabais(cat,cat_parent,cat_name,page,ob,direction)
{
		scrollTo(0,290);
		var hash = 'l_rabais("'+cat+'","'+cat_parent+'","'+cat_name+'","'+page+'","'+ob+'","'+direction+'");';
		hash = hash.replace(/^.*#/, '');
		// moves to a new page. 
		// pageload is called at once. 
		// hash don't contain "#", "?"
		$.historyLoad(hash);
 }
 function get_unique_product_init(pd_id)
{
scrollTo(0,290);
$("div#contenuRight").html("<div id='loader'><img  src='images/ajax-loader.gif'></div>");

$.ajax({	
			
			type: "POST",
			url: "php/cat/get_unique_product.php",
			data: "pd_id="+pd_id,
  		    success: function(msg){
			//alert(msg);
					$("div#contenuRight").html(msg);
					Shadowbox.init({ skipSetup: true }); Shadowbox.setup(); 
					// on désactive l'affichage du formulaire et on affiche un message de bienvenue à la place
				

		   }
 });
 }
 function 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){
			//alert(msg);
					
					$("div#contenuRight").html(msg);
					Shadowbox.init({ skipSetup: true }); Shadowbox.setup(); 
					// on désactive l'affichage du formulaire et on affiche un message de bienvenue à la place
				

		   }
 });
 }
 function get_blog(id)
{
	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#contenuRight").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#contenuRight").html(msg);
					Shadowbox.init({ skipSetup: true }); Shadowbox.setup(); 
					// on désactive l'affichage du formulaire et on affiche un message de bienvenue à la place
				

		   }
 });
 } 
function get_article(id,art)
{
	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>");

$.ajax({	
			
			type: "POST",
			url: "php/blog/get_article.php",
			data: "id="+id+"&art="+art,
  		    success: function(msg){
			//alert(msg);
					$("div#contenuRight").html(msg);
					Shadowbox.init({ skipSetup: true }); Shadowbox.setup(); 
					// on désactive l'affichage du formulaire et on affiche un message de bienvenue à la place
				

		   }
 });
 }
function addtocart(pd_id,pd_qty,span)
{
scrollTo(0,290);
var	span_default = $('span#'+span).html();	

$("span#"+span).html("<img src='php/images/ajax-loader.gif'>");	

$.ajax({	
		
			type: "POST",
			url: "php/cat/addtocart.php",
			data: "id="+ pd_id +"&qty="+pd_qty,
  		    success: function(msg){
			//alert(msg);
			panier();
			
			}
 });
}

function modtocart(pd_id,pd_qty)
{

$.ajax({	
		
			type: "POST",
			url: "php/cat/modtocart.php",
			data: "id="+ pd_id +"&qty="+pd_qty,
  		    success: function(msg){
			//alert(msg);
			panier();
			return false;
			}
	
		
 });
return false;
}

function updatecart()
{
$(":input[name=pd_qty]").each(     function(){  
      	pd_id = this.id.replace('pd_qty_','');
		pd_qty = $('#'+this.id).val();
		//pd_qty = document.getElementById(this.id).getAttribute("value");
		//alert(pd_qty);
		$.ajax({	
					async: false,
					type: "POST",
					url: "php/cat/modtocart.php",
					data: "id="+ pd_id +"&qty="+pd_qty,
					success: function(msg){
					}
		 });
		
}); 
panier();
}

function deltocart()
{
$(":input[type=checkbox][checked]").each(     function(){  
      	pd_id = this.id.replace('supp','');
		$.ajax({	
					async: false,
					type: "POST",
					url: "php/cat/deltocart.php",
					data: "id="+pd_id,
					success: function(msg){
					}
		 });
		
}); 
 panier();
}


function deletecart()
{

$.ajax({	
		
			
			url: "php/cat/deletecart.php",
			success: function(msg){
			//alert(msg);
			panier();
			}
 });
}
function list()
{
scrollTo(0,290);

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

window.location.href="http://www.annalsofsaintanne.ca/boutique/eng/";
}
//##################################################################
//PANIER
function panier()
{
var hash = "panierinit();";
		hash = hash.replace(/^.*#/, '');
		// moves to a new page. 
		// pageload is called at once. 
		// hash don't contain "#", "?"
		$.historyLoad(hash);
}
function panierinit()
{
$("div#contenuRight").html("<div id='loader'><img  src='images/ajax-loader.gif'></div>");

$.ajax({	
		
			url: "php/cat/panier.php",
			success: function(msg){
			//alert(msg);
			$("div#contenuRight").html(msg);
				Shadowbox.init({ skipSetup: true }); Shadowbox.setup(); 				

					
			}
 });
}
//##################################################################
//RECHERCHE

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

//alert(mot);
		$.ajax({
		
		   type: "POST",
		   url: "php/cat/get_search.php",
		   data: "search="+mot+"&page="+page+"&ob="+ob+"&direction="+direction+"&searchaction="+searchaction,
		    success: function(msg){
				//alert(msg);
			
				$("div#contenuRight").html(msg);
				Shadowbox.init({ skipSetup: true }); Shadowbox.setup(); 				
				},
		    
			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)
{
scrollTo(0,290);
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 searchpagebyname(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 checkout(mode)
{
	var hash = "checkoutinit('"+mode+"');";
		hash = hash.replace(/^.*#/, '');
		// moves to a new page. 
		// pageload is called at once. 
		// hash don't contain "#", "?"
		$.historyLoad(hash);
}

function checkoutinit(mode)
{
$("div#contenuRight").html("<div id='loader'><img  src='images/ajax-loader.gif'></div>");
//panier();
		$.ajax({	
		
					type: "POST",
					data: "action="+mode,
					url: "php/login/checkout.php",
					success: function(msg){
					$("div#contenuRight").html(msg);
					}
					
		 });
}

function checkoutabo(mode,abo)
{
	var hash = "checkoutaboinit('"+mode+"','"+abo+"');";
		hash = hash.replace(/^.*#/, '');
		// moves to a new page. 
		// pageload is called at once. 
		// hash don't contain "#", "?"
		$.historyLoad(hash);

}

function checkoutaboinit(mode,abo)
{
$("div#contenuRight").html("<div id='loader'><img  src='images/ajax-loader.gif'></div>");

		$.ajax({	
		
					type: "POST",
					data: "action="+mode+"&abo="+abo,
					url: "php/login/checkoutabo.php",
					success: function(msg){
					//alert(msg);
					$("div#contenuRight").html(msg);
					}
					
		 });
}


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#contenuRight").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);
  }
}

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


