$.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() {
		addinfolettre();
		return false;
	});

	
});
function addinfolettre(){
		$.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>');
			}
			else if(msg == "already" || msg == "\nalready" || msg == "\r\nalready")
			{
				$('#erreurinfolettre').html('<b>Vous &ecirc;tes d&eacute;j&agrave; inscrit</b>');
			}
			else if(msg == "error"  || msg == "\nerror" || msg == "\r\nerror")
			{
				$('#erreurinfolettre').html('<b>Veuillez v&eacute;rifier les informations inscritent</b>');
			}
			else
			{
				$('#erreurinfolettre').html('<b>Veuillez utiliser le script correctement</b>');
			}
			
			
					
					// 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(){
								
							
			if(window.location.href.indexOf('boutique.html') > 0 && window.location.href.indexOf('#') == -1){
			$("div#pageint").html("<div id='loader'><img  src='img/ajax-loader2.gif'></div>");

			window.location.replace(window.location.href+"#l_scat('46','1','s','0','','');");
			
			
$.ajax({	 
			async: false,
			type: "POST",
			url: "php/cat/get_product.php",
			data: "cat=46&cat_name=1&cat_parent=s&page=0&ob=&direction=",
			success: function(msg){
			//alert(msg);
					

					
				$("div#pageint").html(msg);
					Shadowbox.init({ skipSetup: true }); Shadowbox.setup(); 
					// on désactive l'affichage du formulaire et on affiche un message de bienvenue à la place
				

		   }
 });
	}

								$("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;
									});
	
	var fct = window.location.pathname;
	fct = fct.split("#");		
	
$.historyInit(pageload, fct[0]);

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 stripslashes(str) {
str=str.replace(/\\'/g,'\'');
str=str.replace(/\\"/g,'"');
str=str.replace(/\\0/g,'\0');
str=str.replace(/\\\\/g,'\\');
return str;
}
function l_scat(cat,cat_parent,cat_name,page,ob,direction)// 
{

//cat_name = stripslashes(cat_name);
$("div#pageint").html("<div id='loader'><img  src='img/ajax-loader2.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: false,
			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#pageint").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_unique_product_init(pd_id)
{
scrollTo(0,290);
$("div#pageint").html("<div id='loader'><img  src='img/ajax-loader2.gif'></div>");

$.ajax({	
			
			type: "POST",
			url: "php/cat/get_unique_product.php",
			data: "pd_id="+pd_id,
  		    success: function(msg){
			//alert(msg);
					$("div#pageint").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#pageint").html("<div id='loader'><img  src='img/ajax-loader2.gif'></div>");

$.ajax({	
			
			type: "POST",
			url: "php/blog/get_article.php",
			data: "id="+id+"&art="+art,
  		    success: function(msg){
			//alert(msg);
					$("div#pageint").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='img/ajax-loader3.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();
			}
 });
}
//##################################################################
//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#pageint").html("<div id='loader'><img  src='img/ajax-loader2.gif'></div>");
//alert('panier');
$.ajax({	
			async: false,
			url: "php/cat/panier.php",
			success: function(msg){
			//alert(msg);
			$("div#pageint").html(msg);
			Shadowbox.init({ skipSetup: true }); Shadowbox.setup(); 				

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

function search(mot,page,ob,direction,searchaction)
{
$("div#pageint").html("<div id='loader'><img  src='img/ajax-loader2.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#pageint").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#pageint").html("<div id='loader'><img  src='images/ajax-loader2.gif'></div>");
//panier();
		$.ajax({	
		
					type: "POST",
					data: "action="+mode,
					url: "php/login/checkout.php",
					success: function(msg){
					//alert(msg);
					$("div#pageint").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#pageint").html(hash);
			//alert(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();}


