var Navigateur = navigator.appName;

if(Navigateur == "Microsoft Internet Explorer")
	var ie = true;
else
	var ie = false;



var IE6 = false 

var strChUserAgent = navigator.userAgent; 
var intSplitStart = strChUserAgent.indexOf("(",0); 
var intSplitEnd = strChUserAgent.indexOf(")",0); 
var strChMid = strChUserAgent.substring(intSplitStart, intSplitEnd); 

if(strChMid.indexOf("MSIE 6") != -1) IE6 = true;

var IE7 = false 

if(strChMid.indexOf("MSIE 7") != -1) IE7 = true;

var IE8 = false 

if(strChMid.indexOf("MSIE 8") != -1) IE8 = true;


function sfHover() {
	var sfEls = document.getElementById("monmenu").getElementsByTagName("li");
	for (var i=0; i<sfEls.length; i++) {
		sfEls[i].onmouseover = function() {
			this.className = this.className.replace(new RegExp(" sfhover"), "");
			this.className += " sfhover";
		}
		sfEls[i].onmouseout = function() {
		this.className = this.className.replace(new RegExp(" sfhover"), "");
		}
	}	
}

// On etend les fonctions de jquery
jQuery.fn.extend({
   findPos : function() {
       obj = jQuery(this).get(0);
       var curleft = obj.offsetLeft || 0;
       var curtop = obj.offsetTop || 0;
       while (obj = obj.offsetParent) {
                curleft += obj.offsetLeft
                curtop += obj.offsetTop
       }
       return {x:curleft,y:curtop};
   }
});


function sous_menu(univers_id,srch) {
	
	$("#le_filtre").css({"visibility": "hidden"});
	
	$("#categorie_id"+univers_id).css({"display": "block"});


  pos = $('#univers_id'+univers_id).findPos();
	
	var posx = (pos.x-320);
	
	$('#image'+univers_id).attr("src",srch);
	
	
	
	
	//$("#categorie_id"+univers_id).css({"top": pos.y, "left" : posx});

}

function hide_sous_menu(univers_id,src) {
	$("#categorie_id"+univers_id).css({"display": "none"});
	$('#image'+univers_id).attr("src",src);
	$("#le_filtre").css({"visibility": "visible"});
}
function setclassname(obj) {
	obj.className = obj.className.replace(new RegExp(" sf"), "");
	obj.className = obj.className.replace(new RegExp(" sfhover"), "");
	obj.className += " sfhover";	
}

function delclassname(obj) {
	obj.className = obj.className.replace(new RegExp(" sfhover"), "");
	obj.className += " sf";	
}

function updateprixproduit(produit_attribut_id, id) {
		
		var produit_id = $('#produit_id').val();

		$.ajax({
			type: "POST",
		  url: '/js/ajax/calcul_prix_maj.php',
		  data:"produit_id="+produit_id+"&produit_attribut_id="+produit_attribut_id,
		  success: function(req) {
				$('#produit_prix').html('<strong>'+parseFloat(req).toFixed(2)+'</strong> &euro; <span class="ttc">TTC</span>');
		  }
		});		
	
		$.ajax({
			type: "POST",
		  url: '/js/ajax/calcul_prix_maj_barre.php',
		  data:"produit_id="+produit_id+"&produit_attribut_id="+produit_attribut_id,
		  success: function(req) {
				if($('#choix_px_sspromo')) $('#choix_px_sspromo').html('<strong>'+parseFloat(req).toFixed(2)+'</strong> &euro; <span class="ttc">TTC</span>');
		  }
		});			
		
		$('.block_attribut').css("color","#000000");
    $('.block_attribut').css("border", "#ffffff 1px solid"); 
          				
		if(produit_attribut_id!=-1){
			$('#produit_attribut_id').val(id);
			$('#produit_attribut_'+id).css("color", "#1E3C7B");
			$('#produit_attribut_'+id).css("border", "#1E3C7B 1px solid");
			$('#lnk_panier').css("display","block");
		}else{
			$('#lnk_panier').css("display","none");
			$('#produit_attribut_id').val('-1');
			$('#produit_attribut_'+id).css("background", "red");
			$('#produit_attribut_'+id).css("color", "#ffffff");
			$("body").popup({
      	popup:{
      		
		      removeOnClick:{
		          0:'#popup_retour',
		          1:'#popup_valider'
		      }, 		
  		      		
      		
	      	css:{
	        	'width':'309px',
	          'height':'238px'
	        }
        },
        data:'produit_attribut_id='+id,
        ajax:'/js/ajax/ErreurAttribut.php'
      });					
		}
		
}

// Ajout au panier
function addPanier(idForm)
{
	$("body").popup({
  	popup:{
  		
      removeOnClick:{
          0:'#popup_retour',
          1:'#popup_valider'
      }, 		
  		
    	css:{
        'width':'309px',
        'height':'216px'
      }
    },
    ajax:'/js/ajax/panier-change.php',
    data:$("#"+idForm).serialize(),
    callback:'updateProdPanier()'
  });	
}

function updateProdPanier(){
  $.ajax({
      type: "POST",
      url: "/js/ajax/update_prod_panier.php",
      success: function(msg){
          $("#nb_header_prod").html(msg);
      }
  });
}


function envoyerAmi(produit_id)
{
	$("body").popup({
  	popup:{
  		
      removeOnClick:{
          0:'#popup_retour',
          1:'#popup_valider'
      }, 		
  		
    	css:{
        'width':'309px',
        'height':'370px'
      }
    },
    ajax:'/js/ajax/popupProduit.php',
    data:"produit_id=" + produit_id
  });		

}

function removePopup(){
    $("#popup").fadeOut(function(){
        $("#popup").remove();
        $("#bg-popup").remove();
        $("select").css('visibility', 'visible');
    });
}

function checkamis(on) {
		$.ajax({
			type: "POST",
		  url: '/js/ajax/popupProduit.php',
		  data:$('#formamis').serialize(),
		  success: function(req) {
				if($('#popup')) $('#popup').html(req);
		  }
		});			
}


function addNewsletter()
{
	$("body").popup({
  	popup:{
  		
      removeOnClick:{
          0:'#popup_retour',
          1:'#popup_valider'
      }, 		
  		
    	css:{
        'width':'309px',
        'height':'205px'
      }
    },
    ajax:'/js/ajax/addNewsletter.php'
  });		

}

function checknewsletter(on) {
		$.ajax({
			type: "POST",
		  url: '/js/ajax/addNewsletter.php',
		  data:$('#formnewsletter').serialize(),
		  success: function(req) {
				if($('#popup')) $('#popup').html(req);
		  }
		});			
}


function openEmballageProduit(idForm, obj) {
	if(obj.checked==true) {
		
		$("body").popup({
	  	popup:{
	  		
	      removeOnClick:{
	          0:'#popup_retour',
	          1:'#popup_valider'
	      }, 		
	  		
	    	css:{
	        'width':'309px',
	        'height':'310px'
	      }
	    },
	    ajax:'/js/ajax/addEmballage.php',
	    data:$(idForm).serialize()
	  });	
	
	}else{
			if($('#emballage')) document.getElementById('emballage').checked=false;
			if($('#emballage_cadeau')) $('#emballage_cadeau').val('');
			if($('#emballage_cadeau_message')) $('#emballage_cadeau_message').val('');
	}
}

function resetEmballage() {
	if($('#emballage')) document.getElementById('emballage').checked=false;
	if($('#emballage_cadeau')) $('#emballage_cadeau').val('');
	if($('#emballage_cadeau_message')) $('#emballage_cadeau_message').val('');	
}


function traitementCadeauPanier(produit_id, produit_attribut_id, pos,obj) {
	if(obj.checked==true) {
		
		$('#panier_desc_message2'+pos).css('display','block');
	
		$("body").popup({
	  	popup:{
	  		
	      removeOnClick:{
	          0:'#popup_retour',
	          1:'#popup_valider'
	      }, 		
	  		
	    	css:{
	        'width':'309px',
	        'height':'310px'
	      }
	    },
	    ajax:'/js/ajax/addEmballagePanier.php',
	    data:"produit_id="+produit_id+"&produit_attribut_id="+produit_attribut_id+"&position="+pos
	  });	

		
	}else{
	
	  $.ajax({
	      type: "POST",
	      data:"produit_id="+produit_id+"&produit_attribut_id="+produit_attribut_id+"&position="+pos+"&del=1",
	      url: "/js/ajax/addEmballagePanier.php",
	      success: function(msg){
	      	getEmballageTotal();
	      	var total = $('#totalPanierA').html();
	      	total = total.replace(' &euro;','');
	      	total = (parseFloat(total));
	      	total = (total-(1)).toFixed(2);
	      	$('#totalPanierA').html(total+" &euro;")
	      	
	      }
	  });
  		
		if($('#produit_emballe_cadeau'+pos)) document.getElementById('produit_emballe_cadeau'+pos).checked=false;
		if($('#panier_desc_message2'+pos)) $('#panier_desc_message2'+pos).css('display','none');
	}		
	
	// On met à jour le prix total
	//getEmballageTotal();	
}


function getEmballageTotal() {
	
	// On met à jour le prix total
	$.ajax({
		type: "POST",
	  url: '/js/ajax/updatePrixEmballage.php',
	  data:"",
	  success: function(req) {
			$('#emballage_prix_total_maj').html(req);
			
			
						

	  }
	});			
}

function addEmballage(produit_id, produit_attribut_id, position, message) {
	
	
	  $.ajax({
	      type: "POST",
	      data:"produit_id="+produit_id+"&produit_attribut_id="+produit_attribut_id+"&position="+position+"&message="+message+"&add=1",
	      url: "/js/ajax/addEmballagePanier.php",
	      success: function(msg){
					getEmballageTotal();
	      	var total = $('#totalPanierA').html();
	      	total = total.replace(' &euro;','');
	      	total = (parseFloat(total));
	      	total = (total+(1)).toFixed(2);
	      	$('#totalPanierA').html(total+" &euro;")					
	      }
	  });
				
}



function initTitle(){
	
  jQuery(".bloc_prod_lst").each(function(i){
    jQuery(this).mouseenter(function(event){
    		jQuery("#produit_bloc_" + jQuery(this).attr("id").substr(10)).fadeTo('fast','0.7');
    		jQuery("#produit_bloc_" + jQuery(this).attr("id").substr(10)).css('display', 'block');
    });
    jQuery(this).mouseleave(function(event){
    		jQuery("#produit_bloc_" + jQuery(this).attr("id").substr(10)).fadeTo('slow','0');
    		jQuery("#produit_bloc_" + jQuery(this).attr("id").substr(10)).css('display', 'none');
    });  	
  });	

}

function updateQte(obj, formulaire, qte, txt) {
	
	var tmp = 0;
	tmp = parseInt(obj.value)+parseInt(qte);
	
	if(tmp==0 && qte == -1) {
		
		if(confirm(txt)) {
			obj.value = parseInt(obj.value)+parseInt(qte);
			formulaire.submit();			
		}
	}else{
		obj.value = parseInt(obj.value)+parseInt(qte);
		formulaire.submit();		
	}
	


}


function openCGV() {
	$("body").popup({
  	popup:{
  		
      removeOnClick:{
          0:'#popup_retour',
          1:'#popup_valider'
      }, 		
  		
    	css:{
        'width':'309px',
        'height':'205px'
      }
    },
    ajax:'/js/ajax/openCGV.php'
  });			
}

function openPanier() {
	$("body").popup({
				
  	popup:{
      removeOnClick:{
          0:'#popup_retour',
          1:'#popup_valider'
      }, 		

      css:{
          'background':'#ffffff',
          'border':'none',
          'width':'782px',
          'height':'382px',
          'z-index':'99999',
          'position':'absolute'
      } 		

    },
    ajax:'/js/ajax/openPanier.php'
  });				
}


function openRemise() {
	$("body").popup({
				
  	popup:{
      removeOnClick:{
          0:'#popup_retour',
          1:'#popup_valider'
      }, 		

      css:{
          'background':'#ffffff',
          'border':'none',
          'width':'782px',
          'height':'382px',
          'z-index':'99999',
          'position':'absolute'
      } 		

    },
    ajax:'/js/ajax/openRemise.php'
  });				
}


function SecureConfirm() {
	if(confirm('Voulez-vous supprimer votre adresse du carnet ?')) {
		return true;
	}else{
		return false;
	}	
}


function openCommande(commande_id) {
	$("body").popup({
				
  	popup:{
      removeOnClick:{
          0:'#popup_retour',
          1:'#popup_valider'
      }, 		

      css:{
          'background':'#ffffff',
          'border':'none',
          'width':'782px',
          'height':'382px',
          'z-index':'99999',
          'position':'absolute'
      } 		

    },
    ajax:'/js/ajax/openCommande.php',
    data:'commande_id='+commande_id
  });				
}


function openCms(page_id) {
	$("body").popup({
  	popup:{
  		
      removeOnClick:{
          0:'#popup_retour2',
          1:'#popup_valider'
      }, 		
  		
    	css:{
        'background':'#ffffff',
        'border':'#1E3C7B 1px solid',    		
        'width':'776px',
        'height':'608px'
      }
    },
    ajax:'/js/ajax/openCms.php',
    data:"cms_page_id="+page_id
  });			
}


function handleSliderChange(e, ui)
{
  var maxScroll = $("#content-scroll").attr("scrollWidth") -
                  $("#content-scroll").width();
  $("#content-scroll").animate({scrollLeft: ui.value *
     (maxScroll / 100) }, 1000);
}

function handleSliderSlide(e, ui)
{
  var maxScroll = $("#content-scroll").attr("scrollWidth") -
                  $("#content-scroll").width();
  $("#content-scroll").attr({scrollLeft: ui.value * (maxScroll / 100) });
}
