/************** CHARGEMENT PAGE *****************************/
jQuery(document).ready(function(){
    rolloverPanier();
    loadAddNewsletter('#inscription_newsletter');
});
/************** CHARGEMENT PAGE *****************************/


// PENDING : a normaliser
function rolloverPanier(){
    jQuery("#panier").mouseenter(function(event){
        //if(jQuery("#nb-prod-panier").text() > 0){
            jQuery("#panier").css('cursor', 'pointer');
            var pos = jQuery("#panier").position();

            jQuery.ajax({
                type: "POST",
                url: '/js/ajax/show_panier.php',
                success: function(html){
                    // création de la div
                    if (!jQuery("#rollover_panier").attr('id')) {
                        jQuery("<div></div>").hide().attr("id", "rollover_panier").css({
                            'right': '0px',
                            'position': 'absolute',
                            'top': '20px',
                            'z-index': '3000'
                        }).html(html).appendTo("#header_client").show();
                    }else{
                        jQuery("#rollover_panier").html(html);
                    }

                    jQuery("#rollover_panier").mouseenter(function(event){
                        jQuery("#rollover_panier").css('display','block');
                        jQuery("#panier").css('background','#000000');
    										jQuery("#panier").css('color','#ffffff');
                    });
                    jQuery("#rollover_panier").mouseleave(function(event){
                        jQuery("#rollover_panier").css('display','none');
                        jQuery("#panier").css('background','#ffffff');
    										jQuery("#panier").css('color','#000000');
                    });
                    jQuery("#panier").mouseleave(function(event){
                        jQuery("#rollover_panier").css('display','none');
                        jQuery("#panier").css('background','#ffffff');
    										jQuery("#panier").css('color','#000000');
                    });
                    
                    jQuery("#form-"+jQuery(this).attr('id')).submit(function(){
                    });   								
                }
            });
            jQuery("#rollover_panier").show();
       // }
    });
    
    jQuery("panier").mouseleave(function(event){
        jQuery("#rollover_panier").css('display','none');
        jQuery("#panier").css('background','#ffffff');
    		jQuery("#panier").css('color','#000000');
    });
}


//Affichage du sous menu au rollover
function initMenu(){

    jQuery("#menu a.lien_menu_principal").each(function(i){

        jQuery(this).mouseenter(function(event){
            jQuery("#sous-" + jQuery(this).attr("id")).css('visibility', 'visible');
        });

        jQuery(this).mouseleave(function(event){
            jQuery("#sous-" + jQuery(this).attr("id")).css('visibility', 'hidden');
            jQuery(".sous-" + jQuery(this).attr("id")).css('visibility', 'hidden');
        });
    });

    jQuery(".sous-categorie").each(function(i){
        jQuery(this).mouseenter(function(event){
            jQuery("#" + jQuery(this).attr("id").substr(5)).addClass('onrollover');
            jQuery(this).css('visibility', 'visible');
        });

        jQuery(this).mouseleave(function(event){
            jQuery(this).removeClass('hover');
            jQuery("#" + jQuery(this).attr("id").substr(5)).removeClass('onrollover');
            jQuery(this).css('visibility', 'hidden');
        });
    });
}





function loadChangeImage(){

    jQuery("#liste-mini-visuel .mini-visuel").each(function(i){
        jQuery(this).css('cursor', 'pointer').click(function(){
            var idVisu = jQuery(this).attr('id');
            jQuery("#grand-visuel img:first").attr('src', jQuery("#grand-"+idVisu+" img").attr('src'));
            jQuery("#grand-visuel img:first").parents('a.jqzoom').attr('href', jQuery("#popup-"+idVisu+" img").attr('src'));     // pour le zoom produit
            jQuery("#loupe-visuel").unbind('click');
            
            jQuery("#loupe-visuel").click(function(){
                jQuery("body").popup({
                    popup:{
                        css:{
                            'width':'700px',
                            'height':'320px',
                            'border':'1px solid #C6C6C6'
                        },
                        removeOnClick:{
                            0:'#popup'
                        }
                    },
                    content: jQuery("#popup-"+idVisu).html()
                    
                });
            });
        });
    });
	
    jQuery("#loupe-visuel").css('cursor', 'pointer').click(function(){	
        jQuery("body").popup({
            popup:{
                removeOnClick:{
                    0:'#close'
                },
                css:{
                    'width':'585px',
                    'height':'600px',
                    'padding' : '5px',
                    'border' : '1px solid #FFF'
                }
            },
            ajax:'/js/ajax/galerie_image.php?'+jQuery("#add-panier").serialize()
            //content: jQuery("#popup-"+jQuery("#liste_images_cachees .mini-visuel:first").attr('id')).html()
        });
    });
}

function changeImagePopup(mon_id){
	
		var Obj2 = getElementsByClassName('image_show'); 
		//Enlève la classe mini-visuel des autres images
		if(Obj2){
			for (var i = 0; i < Obj2.length; i++) {
				Obj2[i].className='image_hidden';
			} 
		}

		Obj = document.getElementById('image_'+mon_id);
		if(Obj){
			Obj.className='image_show';
		}
}

function loadPopupAttr(){
    jQuery(".liste-opts .img-attr").each(function(i){
        if(jQuery("#popup-"+this.id).attr('id')){
            jQuery(this).css('cursor', 'pointer').click(function(){
                jQuery("body").popup({
                    popup:{
                        css:{
                            'width':'700px',
                            'height':'320px',
                            'border':'1px solid #C6C6C6'
                        },
                        removeOnClick:{
                            0:'#popup'
                        }
                    },
                    content: jQuery("#popup-"+this.id).html()
                });
            });
        }
    });
}

function loadAddNewsletter(node){
    alterneText("#newsletter_email", 'Votre email ici');

    
    jQuery(node).submit(function(){
        jQuery("body").popup({
            popup:{
                removeOnClick:{
                    0:'#btn-close-popup',
                    1:'#close'
                }
            },
            ajax:'/js/ajax/addNewsletter.php',
            data:jQuery(node).serialize()
        });
        return false;
    });
}

function loadAjoutPanier(){

    jQuery("#btn-ajout-fprod").css('cursor', 'pointer').click(function(){
    		if(jQuery("#btn-ajout-fprod").hasClass('clickable')) {
        jQuery("body").popup({
            popup:{
                removeOnClick:{
                    0:'#btn-close-popup',
                    1:'#continuer'
                }
            },
            ajax:'/js/ajax/update-panier.php',
            data:jQuery("#add-panier").serialize(),
            callback:'updateProdPanier()'
        });
      } else {
      	jQuery("#selection_taille").css('color','red');
      	jQuery("#selection_longueur").css('color','red');
      	return false;
      }
    });
}

function addFastPanier(idForm){
    jQuery("body").popup({
        popup:{
            removeOnClick:{
                0:'#btn-close-popup',
                1:'#btn-continue-achat',
                2:'#close',
                3:'#continuer'
            }
        },
        ajax:'/js/ajax/update-panier.php',
        data:jQuery("#"+idForm).serialize(),
        callback:'updateProdPanier()'
    });
}


function AllTemoignage(){

    jQuery(".temoignage").css('cursor', 'pointer').click(function(){
    jQuery("body").popup({
        type: "POST",
        popup:{
            removeOnClick:{
                0:'#close'
            }
        },
        ajax:'/js/ajax/temoignage.php',
        data: 'id='+jQuery(this).attr('id')
    });
    });

    jQuery("#ajouter_un_temoignage").css('cursor', 'pointer').click(function(){
    jQuery("body").popup({
        popup:{
            removeOnClick:{
                0:'#close'
            }
        },
        ajax:'/js/ajax/ajout-temoignage.php'
    });
    });
}

function updateProdPanier(){
    jQuery.ajax({
        type: "POST",
        url: "/js/ajax/update_prod_panier.php",
        success: function(msg){
            val = msg.split('|');
            jQuery("#nb-prod-panier").html(val[0]);
            jQuery("#prix_panier").html(val[1]+' &euro;');
        }
    });
}

function loadPagePanier(){

    jQuery(".btn-qte-plus").css('cursor', 'pointer').click(function(){
        jQuery("#new-"+jQuery(this).attr('id')).attr('value', parseInt(jQuery("#value-"+jQuery(this).attr('id')).attr('value'))+1);
        jQuery("#form-"+jQuery(this).attr('id')).submit();
    });

    jQuery(".btn-qte-moins").css('cursor', 'pointer').click(function(){
        jQuery("#new-"+jQuery(this).attr('id')).attr('value', parseInt(jQuery("#value-"+jQuery(this).attr('id')).attr('value'))-1);
        jQuery("#form-"+jQuery(this).attr('id')).submit();
    });

    jQuery(".delete-produit").css('cursor', 'pointer').click(function(){
        jQuery("#form-"+jQuery(this).attr('id')).submit();
    });

    jQuery("#port select").each(function(){
        jQuery(this).change(function(){
            jQuery("#port").submit();
        });
    });
    
    jQuery("#port .checklivraison").each(function(){
        jQuery(this).click(function(){
            jQuery("#port").submit();
        });
    });

    toolTipLivraison();
}

function loadPageCoord(){
	
    jQuery("#new_adresse_livraison_id").change(function(){
        jQuery("#flag").attr('value', '4');
        jQuery('#coordonnees').submit();
    });
    
    jQuery("#pays_id").change(function(){
        jQuery("#flag").attr('value', '3');
        jQuery('#coordonnees').submit();
    });

    toolTipLivraison();
}

function loadPageRecap(){
    jQuery("#liste-paiement .paiement").css('cursor', 'pointer').click(function(){
        jQuery("#"+jQuery(this).attr('id')+" input:radio").attr('checked', 'checked');
    });

    toolTipLivraison();
}

function toolTipLivraison(){
    jQuery(".infos-livraison").each(function(){
        jQuery(this).css('cursor','help');
        jQuery(this).mouseenter(function(event){

            if(jQuery("#popup-"+jQuery(this).attr('id')).attr('id')){
                jQuery("#popup-"+jQuery(this).attr('id')).css({
                    'display':'block',
                    'top':event.pageY + 10,
                    'left':event.pageX + 10
                });
            }else{
                jQuery("<div></div>")
                .html(jQuery("#"+jQuery(this).attr('id')+"-contenu").html())
                .attr('id', "popup-"+jQuery(this).attr('id'))
                .addClass('tool-tip-livraison')
                .css({
                    'top':event.pageY + 10,
                    'left':event.pageX + 10,
                    'position':'absolute'
                })
                .appendTo("body");
            }
        });

        jQuery(this).mouseleave(function(){
            jQuery("#popup-"+jQuery(this).attr('id')).css('display', 'none');
        });

    });
}

function loadSendMail(){
    jQuery("#contact").submit(function(){
        jQuery.ajax({
            type: "POST",
            url: "/js/ajax/contact.php",
            data: jQuery(this).serialize(),
            success: function(msg){
                jQuery("#contenu-contact").html(msg);
                loadSendMail();
            }
        });
        return false;
    });
}

function loadSendRetour(){
    jQuery("#retour").submit(function(){
        jQuery.ajax({
            type: "POST",
            url: "/js/ajax/retour.php",
            data: jQuery(this).serialize(),
            success: function(msg){
                jQuery("#contenu-retour").html(msg);
                loadSendRetour();
            }
        });
        return false;
    });
}

function loadInscNewsletter(){
    jQuery("#newsletter").submit(function(){
        jQuery.ajax({
            type: "POST",
            url: "/js/ajax/addNewsletter.php",
            data: jQuery(this).serialize(),
            success: function(msg){
                jQuery("#contenu-contact").html(msg);
            }
        });
        
        return false;
    });
}

function loadFicheProduit(){
    loadChangeImage();
    loadPopupAttr();
    loadAjoutPanier();

    jQuery(".jqzoom").jqzoom({
        zoomType: 'standard',
        title: false,
        showPreload: false,
        zoomWidth: 260,
        zoomHeight: 380,
        position: 'right',
        xOffset : 36,
        yOffset : -8
    });
    
    selectAttribut();
    fp_onglet();
    
}

function alterneText(id, text){
    jQuery(id).focus(function(){
        if (jQuery(this).attr('value') == text) {
            jQuery(this).attr('value', '');
        }
    });
    jQuery(id).blur(function(){
        if (jQuery(this).attr('value') == '') {
            jQuery(this).attr('value', text);
        }
    });
}

function loadMenu(){
    jQuery(".lien_menu_rayon").css('cursor', 'pointer').click(function(){
        jQuery(".lien_menu_rayon").removeClass('lien_menu_rayon_select');
        jQuery(this).addClass('lien_menu_rayon_select');
        jQuery(".sous_menu_rayon").removeClass('sous_menu_rayon_hidden');
        jQuery(".sous_menu_rayon").addClass('sous_menu_rayon_hidden');
        jQuery("#sous-"+jQuery(this).attr('id')).removeClass('sous_menu_rayon_hidden');
    });
}


function loadSlideShow(){

    jQuery("#promo").showcase({
        animation: {
            type: "horizontal-slider",
            stopOnHover: true,
            speed: 600
        },
        navigator:{
            position: "bottom-left",
            css: {
                top: "190px",
                height: "40px",
                "z-index": 1100
                
            },
            showNumber: true,
            item: {
                css: {
                    height:"30px",
                    "line-height":"28px",
                    width:"50px",
                    color: "#ffffff",
                    "font-weight":"bold",
                    "font-size":"18px",
                    backgroundColor: "transparent",
                    border: "none",
                    background:"url(/styles/images/conteneur/left/btn_slideshow.png) no-repeat",
                    margin: "0px 15px 0px 0px",
                    "text-align": "center",
                    "vertical-align": "middle"
                },
                cssHover: {
                    color: "#333333",
                    backgroundColor: "transparent",
                    border: "none",
                    background:"url(/styles/images/conteneur/left/btn_slideshow_select.png) no-repeat"
                },
                cssSelected: {
                    color: "#333333",
                    backgroundColor: "transparent",
                    border: "none",
                    background:"url(/styles/images/conteneur/left/btn_slideshow_select.png) no-repeat"
                }
            }
        },
        titleBar: {
            enabled: false
        }
    });
}


/***********************/
function in_array(value, tableau){
    var a=false;
    for(var i=0;i<tableau.length;i++){
        if(value == tableau[i]){
            a=true;
            break;
        }
    }
    return a;
}
/***********************/


/** SPEC JEANS-HOMME **/
function showhide_header_pop(obj,act) {
	var popDiv = '#'+obj.id+'_pop';
	if(act=="show") {
		jQuery(obj).css('backgroundColor', '#000000');
		jQuery(obj).css('color', '#ffffff');
		jQuery(popDiv).css('display', 'block');
	}
	else {
		if(act=="hide") {
			jQuery(obj).css('backgroundColor', '#ffffff');
			jQuery(obj).css('color', '#000000'); 
			jQuery(popDiv).css('display', 'none');
		}
	}
}

function showHideDetail(div,act) {
	var popDiv = '#produit_bloc_div_'+div;
	var lienDiv = '#produit_lienDiv_'+div;
	if(act=="show") {
		if(jQuery(popDiv).css('display')=='none'){
			jQuery(lienDiv).css('backgroundColor', '#000000');
			jQuery(lienDiv).css('color', '#ffffff');
			jQuery(popDiv).css('display', 'block');
			
			
			var isTaille = div.substr(0,7);
			if(isTaille == "taille_") {
				var produit_id = div.substr(7);
			  jQuery.ajax({
			    type: "POST",
			    url: "/js/ajax/infoTaille.php",
			    data:"produit_id="+produit_id,
			    success: function(msg){
	
			      jQuery("#produit_bloc_div_taille_"+produit_id).html(msg);
			    }
			  });     				
			}
			
		} else {
			jQuery(lienDiv).css('backgroundColor', '#FFFFFF');
			jQuery(lienDiv).css('color', '#000000');
			jQuery(popDiv).css('display', 'none');
		}
	}
	else {
		jQuery(lienDiv).css('backgroundColor', '#ffffff');
		jQuery(lienDiv).css('color', '#000000');
		jQuery(popDiv).css('display', 'none');
	}
}

function show(div) {
		jQuery('#'+div).css('display', 'block');
}

function showtaille(div,div2) {
		var pos = jQuery('#'+div2).position();
		jQuery('#'+div).css('display', 'block');
		jQuery('#'+div).css('top', pos.top+20);
		jQuery('#'+div).css('left', pos.left-40);
		jQuery('#'+div).css('bottom', 0);
}


function hide(div) {
		jQuery('#'+div).css('display', 'none');
}

function dropmenu(obj1,obj2) {
		jQuery(document).ready(function() {
    jQuery(obj1).click(function () {
         jQuery(obj2).toggle("slow");
      });
  });
}

function homeSearch(obj,valeur_id,valeur_nom) {
	jQuery('#'+obj).attr('value', valeur_id);
	var TheDiv = '#home_recherche_'+obj;
	jQuery(TheDiv).attr('innerHTML', valeur_nom);
	var obj2 = "#home_div_recherche_"+obj;
  jQuery(obj2).toggle("slow");
  jQuery('#home_div_recherche_btn').css('backgroundColor', '#990000');
  jQuery(TheDiv).css('color', '#990000');
  
}

function changeImgGd(obj1,obj2,idImage) {

	jQuery('#a_grand-visuel').attr('href', obj1);
	jQuery('#img_grand-visuel').attr('src', obj2);
	
	
	if(idImage > 0){
		jQuery('#loupe-visuel').css('display', 'block');
		//Attribue la classe nécessaire à l'image cachée qui doit appaître en grand
		var Obj2 = getElementsByClassName('mini-visuel'); 
		//Enlève la classe mini-visuel des autres images
		if(Obj2){
			for (var i = 0; i < Obj2.length; i++) {
				Obj2[i].className='';
			} 
		}
		Obj = document.getElementById('visu-'+idImage);
		if(Obj){
			Obj.className='mini-visuel';
		}
	} else {
		jQuery('#loupe-visuel').css('display', 'none');
	}
}

function getElementsByClassName(classname, node) { 
	if (!node) { 
		node = document.getElementsByTagName('body')[0];
	} 
	var a = [], re = new RegExp('\\b' + classname + '\\b'); 
	els = node.getElementsByTagName('*'); 
	for (var i = 0, j = els.length; i < j; i++) {
	 	if ( re.test(els[i].className)){ 
	 		a.push(els[i]); 
	 	} 
	} 
	if(a.length > 0){
		return a;
	} else {
		return false;
	}
}

function selectAttribut() {

	jQuery('li.disable2').each(function() {
		TheOption = this.id;
		TheOption_value = this.id.split('_');
		var nb_option = jQuery('#attribut_nb_option').attr('innerHTML');
		var last_selected = TheOption_value[1];
		var str_data = 'produit_id='+jQuery("#add-panier #produit_id").attr('value')+'&nb_option='+nb_option+'&';
		jQuery('li.disable2').each(function() {
				arrAttribut = this.id.split('_');
				str_data+= arrAttribut[1]+'='+arrAttribut[2]+'&';
		});
		
      jQuery.ajax({
          type: "POST",
          url: "/js/ajax/selectAttribut.php",
          data: str_data+'last='+last_selected+'&',
          success: function(msg){

          		val = msg.split('|');

          		if(val[0] != 'attribut') {
              	jQuery("#fp_selection_info_select1").attr('style','margin:0;float:left;');
              	jQuery("#btn-ajout-fprod").removeClass('clickable');
              	jQuery("#btn-ajout-fprod-img").attr('src','/styles/images/produit/chevron_panier.png');
              	if(val[0] == 'option1') {
              		jQuery("span#option_valeur_nom1").attr('innerHTML', val[1]);
              		jQuery("span#option_valeur_nom1").attr('style','color:red');
              		jQuery("span#option_valeur_nom2").attr('innerHTML', '');
              		jQuery("span#option_valeur_nom2").attr('style','');
              	}
              	if(val[0] == 'option2') { 
              		jQuery("span#option_valeur_nom2").attr('innerHTML', val[1]);
              		jQuery("span#option_valeur_nom1").attr('style','');
              		jQuery("span#option_valeur_nom1").attr('innerHTML', '');
              		jQuery("span#option_valeur_nom2").attr('style','color:red');
              	}

              	jQuery("#add-panier #produit_attribut_id").attr('value','-1');
              	
              	jQuery('li.attribut_valeur').each(function() {
              		arrAttribut = this.id.split('_');

              			jQuery('li.attribut_valeur.selected').each(function() {
              				if(this.id != TheOption) {
		              			jQuery(this).removeClass('selected');
		              		}
	              		});
              		
              			//alert(TheOption_value[1] + " " + arrAttribut[1] + " > " + arrAttribut[2] + " : " + val[2]);
              			
	              		if(!in_array_dedi(arrAttribut[2],val[2]) && TheOption_value[1] != arrAttribut[1]) {
	              			jQuery(this).addClass('disable');
	              		}
	              		else {
	              			jQuery(this).removeClass('disable');
	              		}

              	});
              }
          }
      });
		
	});

	jQuery('li.attribut_valeur').each(function() {
		
		jQuery(this).click(function () {
			if(!jQuery(this).hasClass('disable')) {
			jQuery(this).toggleClass('selected');
			//desélectionne une option si on a cliqué sur une autre valeur de l'option
			TheOption = this.id;
			TheOption_value = this.id.split('_');
			if(jQuery(this).hasClass('selected')) {
				jQuery('li.attribut_valeur.selected').each(function() {
					arrOption = this.id.split('_');
					if(this.id != TheOption && TheOption_value[1] == arrOption[1]) {
						jQuery(this).removeClass('selected');
						jQuery(this).removeClass('disable');
					}
				});
			}
			//--
			
			var nb_option = jQuery('#attribut_nb_option').attr('innerHTML');
			var last_selected = TheOption_value[1];
			var str_data = 'produit_id='+jQuery("#add-panier #produit_id").attr('value')+'&nb_option='+nb_option+'&';
			jQuery('li.disable2').each(function() {
				arrAttribut = this.id.split('_');
				str_data+= arrAttribut[1]+'='+arrAttribut[2]+'&';
			});
			jQuery('li.attribut_valeur.selected').each(function() {
				arrAttribut = this.id.split('_');
				str_data+= arrAttribut[1]+'='+arrAttribut[2]+'&';
			});
			
      jQuery.ajax({
          type: "POST",
          url: "/js/ajax/selectAttribut.php",
          data: str_data+'last='+last_selected+'&',
          success: function(msg){

          		val = msg.split('|');

          		if(val[0] == 'attribut') {
              	jQuery("#add-panier #produit_attribut_id").attr('value', val[1]);
              	jQuery("span#option_valeur_nom1").attr('innerHTML', val[2]);
              	jQuery("span#option_valeur_nom2").attr('innerHTML', val[3]);
              	jQuery("#fp_selection_info_select1").attr('style','margin:0;float:left;color:red;');
              	jQuery("#btn-ajout-fprod-img").attr('src','/styles/images/produit/chevron_panier_valide.png');
              	jQuery("#btn-ajout-fprod").addClass('clickable');
              	jQuery("#selection_taille").css('color','black');
              	jQuery("#selection_longueur").css('color','black');
              	jQuery("#popup_valider").attr('onclick','removePopup()');
   
              }
              else {
              	jQuery("#fp_selection_info_select1").attr('style','margin:0;float:left;');
              	jQuery("#btn-ajout-fprod").removeClass('clickable');
              	jQuery("#btn-ajout-fprod-img").attr('src','/styles/images/produit/chevron_panier.png');
              	if(val[0] == 'option1') {
              		jQuery("span#option_valeur_nom1").attr('innerHTML', val[1]);
              		jQuery("span#option_valeur_nom1").attr('style','color:red');
              		jQuery("span#option_valeur_nom2").attr('innerHTML', '');
              		jQuery("span#option_valeur_nom2").attr('style','');
              	}
              	if(val[0] == 'option2') { 
              		jQuery("span#option_valeur_nom2").attr('innerHTML', val[1]);
              		jQuery("span#option_valeur_nom1").attr('style','');
              		jQuery("span#option_valeur_nom1").attr('innerHTML', '');
              		jQuery("span#option_valeur_nom2").attr('style','color:red');
              	}

              	jQuery("#add-panier #produit_attribut_id").attr('value','-1');
              	
              	jQuery('li.attribut_valeur').each(function() {
              		arrAttribut = this.id.split('_');

              			jQuery('li.attribut_valeur.selected').each(function() {
              				if(this.id != TheOption) {
		              			jQuery(this).removeClass('selected');
		              		}
	              		});
              		
              			//alert(TheOption_value[1] + " " + arrAttribut[1] + " > " + arrAttribut[2] + " : " + val[2]);
              			
	              		if(!in_array_dedi(arrAttribut[2],val[2]) && TheOption_value[1] != arrAttribut[1]) {
	              			jQuery(this).addClass('disable');
	              		}
	              		else {
	              			jQuery(this).removeClass('disable');
	              		}

              	});
              }
          }
      });
      
      return false;
      
    }
   	});
	});
}

function in_array_dedi(val,tab) {
	var bool = false;
	tab = tab.substring(1,tab.length-1);
	tab = tab.split(',');

	for(i=0;i<tab.length;i++)
	{
	   if(tab[i]==val)
	   {	
			bool=true;
			break;
		}
	}
	return bool;
}

function openCms(page_id,idp) {
	if(!idp) {
		idp = '';
	}
	$("body").popup({
  	popup:{
  		
      removeOnClick:{
          0:'#popup_retour',
          1:'#popup_valider',
          2:'#croix_popup'
      }, 		
  		
    	css:{
        'background':'#ffffff',
        'border':'#1E3C7B 1px solid',    		
        'width':'680px',
        'height':'439px'
      }
    },
    ajax:'/js/ajax/openCms.php',
    data:"cms_page_id="+page_id+"&idp="+idp
  });			
}

function openVideo(video_url) {
	$("body").popup({
  	popup:{
  		
      removeOnClick:{
          0:'#popup_retour',
          1:'#popup_valider',
          3:'#croix_blanche_popup'
      }, 		
  		
    	css:{
        'background':'#ffffff',
        'border':'#000 1px solid',    		
        'width':'750px',
        'height':'480px'
      }
    },
    ajax:'/js/ajax/openVideo.php',
    data:"video_url="+video_url
  });			
}

function cocheCase(mon_id){

	var str_data = '';
	var nb_checked = 0;

	Obj=document.getElementById('compareprod_'+mon_id)	
	if(Obj){
		Obj.checked = !Obj.checked;
		jQuery('#compareprod_'+mon_id).toggleClass('checked');
	}

	if(jQuery('#compareprod_'+mon_id).attr('checked') == true) {
		nb_checked = 0;
		jQuery('input.checked').attr('value','1').each(function() {
			
			arrProduit = this.id.split('_');

			str_data+='produit'+nb_checked+'='+arrProduit[1]+'&';
			nb_checked = nb_checked + 1;
		});
	}
	else {
		nb_checked = 0;
	}
	
		if(nb_checked == 2) {
			
			$("body").popup({
		  	popup:{
		  		
		      removeOnClick:{
		          0:'#popup_retour',
		          1:'#popup_valider'
		      }, 		
		  		
		    	css:{
		        'background':'#ffffff',
		        'border':'#1E3C7B 1px solid',    		
		        'width':'656px',
		        'height':'424px'
		      }
		    },
		    ajax:'/js/ajax/compareProduit.php',
		    data:str_data
		  });	
		  
		  jQuery('input.checkbox_compare').each(function() {
		  	jQuery(this).removeClass('checked');
		  	jQuery(this).attr('checked',false);
		  	nb_checked = 0;
		  });
	
		 return false;
	
	}  
	
}

function compareProduit() {
	
	var str_data = '';
	var nb_checked = 0;
	jQuery('input.checkbox_compare').each(function() {

		jQuery(this).click(function () {
				jQuery(this).toggleClass('checked');
				if(jQuery(this).attr('checked') == true) {
					nb_checked = 0;
					jQuery('input.checked').attr('value','1').each(function() {
						arrProduit = this.id.split('_');
						str_data+='produit'+nb_checked+'='+arrProduit[1]+'&';
						nb_checked = nb_checked + 1;
					});
				}
				else {
					nb_checked = 0;
				}
				
				
				if(nb_checked == 2) {
					
					$("body").popup({
				  	popup:{
				  		
				      removeOnClick:{
				          0:'#popup_retour',
				          1:'#popup_valider'
				      }, 		
				  		
				    	css:{
				        'background':'#ffffff',
				        'border':'#1E3C7B 1px solid',    		
				        'width':'656px',
				        'height':'424px'
				      }
				    },
				    ajax:'/js/ajax/compareProduit.php',
				    data:str_data
				  });	
				  
				  jQuery('input.checkbox_compare').each(function() {
				  	jQuery(this).removeClass('checked');
				  	jQuery(this).attr('checked',false);
				  	nb_checked = 0;
				  });

   			 return false;

			}  
  	});
  });
}

function removePopup(){
    $("#popup").fadeOut(function(){
        $("#popup").remove();
        $("#bg-popup").remove();
        $("select").css('visibility', 'visible');
    });
}

function openProduit(produit_id) {
	$("body").popup({
  	popup:{
  		
      removeOnClick:{
          0:'#popup_retour',
          1:'#popup_c'

      }, 		
  		
    	css:{
        'background':'#ffffff',
        'border':'#1E3C7B 1px solid',    		
        'width':'655px',
        'height':'380px'
      }
    },
    ajax:'/js/ajax/openProduit.php',
    data:"produit_id="+produit_id
  });		

}

function fp_onglet() {
	jQuery('p.fp_infos_onglet').each(function() {

		jQuery(this).click(function () {
			
			jQuery('p.fp_infos_onglet').each(function() {
				jQuery(this).removeClass('selected'); 
  		});
			
				jQuery(this).toggleClass('selected'); 
				
  	});
  	
  });
} 

function listing_seach() {
	jQuery('li.mg_recherche_affine_li p').each(function() {

		jQuery(this).click(function () {
			/*
			jQuery('li.mg_recherche_affine_li').each(function() {
				jQuery(this).removeClass('selected'); 
  		});
			*/
			jQuery(this).toggleClass('selected'); 
				
  	});
  	
  });
	
}

/*** TEMOIGNAGE ***/

function AnnulerAvis(){
  jQuery("#deposer_avis").toggle("slow");
}

function displayAvis(){
	jQuery("#img_note li").each(function(element){
		
			jQuery(this).mouseenter(function () {
				var chaine=this.id;
				var pos=chaine.length-1;
				var num=chaine.substr(pos,1);
				for(i=1;i<=num;i++){
					jQuery('#img_note_'+i).addClass('active');
				}
				jQuery('#notation_defaut').setStyle('display', 'none');
				jQuery('#notation_nom').setStyle('display', 'block');
				jQuery('#notation_nom').attr('innerHTML',jQuery('#txt_note_'+num).value);
			});
			
			jQuery(this).click(function () {
				for(i=1;i<=5;i++){
					jQuery('#img_note_'+i).removeClass('active_click');
				}
				
				var chaine=this.id;
				var pos=chaine.length-1;
				var num=chaine.substr(pos,1);
				for(i=1;i<=num;i++){
					jQuery('#img_note_'+i).addClass('active_click');
				}
				jQuery('#temoignage_etoile_id').attr('value',num);
				jQuery('#notation_nom_nom').attr('value',jQuery('#notation_nom').attr('innerHTML'));
			});
			
			jQuery(this).mouseleave(function () {
				for(i=1;i<=5;i++){
					jQuery('#img_note_'+i).removeClass('active');
				}
				if(jQuery('#temoignage_etoile_id').attr('value')==0){
					jQuery('#notation_nom').setStyle('display', 'none');
					jQuery('#notation_defaut').setStyle('display', 'block');
				}else{
					jQuery('#notation_nom').attr('innerHTML',jQuery('notation_nom_nom').attr('value'));
				}
			});
			
		});

}

function initAvis(id){
	for(i=1;i<=id;i++){
		jQuery('#img_note_'+i).addClass('active');
	}
	//jQuery('#notation_defaut').setStyle('display', 'none');
	//jQuery('#notation_nom').setStyle('display', 'block');
	//jQuery('#notation_nom').attr('innerHTML',jQuery('#txt_note_'+id).attr('value'));
}

function sendAvis(idForm){
  jQuery("#"+idForm).submit(function(){
        jQuery.ajax({
            type: "POST",
            url: "/js/ajax/validAvis.php",
            data: jQuery(this).serialize(),
            success: function(msg){
                jQuery("#conteneur_depose_avis").html(msg);
            }
        });
        return false;
    });
}

function updatehitAvis(idAvis,valeur) {
	
	var str_data = "";
	
	if(valeur == '+') str_data = "plus=1";
	else if(valeur == '-') str_data = "moins=1";
	
	jQuery.ajax({
      type: "POST",
      url: "/js/ajax/updatehitAvis.php",
      data:"temoignage_id="+idAvis+"&"+str_data,
      success: function(msg){
				alert(msg);
      }
  });
}

/*** // TEMOIGNAGE ***/

function calculTailleConseillee(valeur,type_conseille){
	var produit_id = jQuery('#produit_id').attr('value');
	jQuery.ajax({
      type: "POST",
      url: "/js/ajax/calculTailleConseillee.php",
      data:"valeur="+valeur+"&type="+type_conseille+"&produit_id="+produit_id,
      success: function(msg){
				jQuery('#taille_conseillee'+type_conseille).attr('innerHTML',msg);
      }
  });
}

function validmail(email) {
   var re = /^([a-zA-Z0-9_\.\-\+])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
   ret = re.test(email);

   return ret;
}
var wait;
function toogleFormInsc() {
	if(validmail(jQuery('#client_email').attr('value')))
	{
		clearTimeout(wait);
		wait = window.setTimeout("toogleFormInscTrue()",1000);
	}
	else
	{
		//jQuery('#client_email').removeClass('valid');
		//jQuery('#client_email').addClass('error');			
	}
}
function toogleFormInscTrue() {

	if(jQuery('#register input#client_email').hasClass('error') == false && jQuery('#form_register_all').css('display') == 'none')
	{
		jQuery.ajax({
	      type: "POST",
	      url: "/js/ajax/valid_email.php",
	      data:"client_email="+jQuery('#client_email').attr('value'),
	      success: function(msg){
	      	if(msg!="")
	      	{
	      		jQuery('#errmsg').attr('innerHTML',msg);
	      		jQuery('#client_email').removeClass('valid');
	      		jQuery('#client_email').addClass('error');
	      	}
	      	else
	      	{
	      		jQuery('#client_email').addClass('valid');
	      		jQuery('#form_register_all').toggle('slow'); 
	      	}
	      }
	  });		
		
		
	}
}

function toogle_checkbox_livraison() {
	jQuery('p.checkbox_coordonnees').each(function() {
		
		jQuery(this).click(function () {
			
			if(!jQuery(this).hasClass('checkbox_selected')) {
				jQuery('p.checkbox_coordonnees').each(function() {
					jQuery(this).toggleClass('checkbox_selected');
				});
	
				 jQuery("#formulaire_coordonnees_livraison").toggle("slow");
				 jQuery("#coord_adresse_facturation").toggle("slow");
			}
			
		});
	});
}

function checkbox_paiement(id, valeur_id) {

		jQuery('p.checkbox_paiement').each(function() {
			jQuery(this).removeClass('checkbox_selected');
			jQuery('#'+id).addClass('checkbox_selected');
			jQuery('#paiement_id').attr('value', valeur_id);
		});

		
}


function panierModifProd(produit_id,attribut_id,qte) {
	$("body").popup({
  	popup:{
  		
      removeOnClick:{
          0:'#popup_retour',
          1:'#popup_valider'
      }, 		
  		
    	css:{
        'background':'#ffffff',
        'border':'#1E3C7B 1px solid',    		
        'width':'476px',
        'height':'340px'
      }
    },
    ajax:'/js/ajax/panierModifProd.php',
    data:"produit_id="+produit_id+"&produit_attribut_id="+attribut_id+"&qte="+qte
  });			
}

function size_finder_checkbox_cuisses() {
	jQuery('span.size_finder_checkbox_cuisses').each(function() {
		
		jQuery(this).click(function () {
			if(!jQuery(this).hasClass('checkbox_selected')) {
				jQuery('span.size_finder_checkbox_cuisses').each(function() {
					jQuery(this).removeClass('checkbox_selected');
				});
			}
			jQuery(this).addClass('checkbox_selected');
			
			var str_data = this.id.substring(this.id.lastIndexOf("_"));
			var valeur_id = str_data.substring(1,2);
			
			if(jQuery("#size_finder_cuisses").attr('value') == valeur_id) {
				jQuery("#size_finder_cuisses").attr('value','');
				jQuery('span.size_finder_checkbox_cuisses').each(function() {
					jQuery(this).removeClass('checkbox_selected');
				});
			} else {
				jQuery("#size_finder_cuisses").attr('value',valeur_id);
			}
		});
	});
}

function size_finder_checkbox_hanches() {
	jQuery('span.size_finder_checkbox_hanches').each(function() {
		
		jQuery(this).click(function () {
			if(!jQuery(this).hasClass('checkbox_selected')) {
				jQuery('span.size_finder_checkbox_hanches').each(function() {
					jQuery(this).removeClass('checkbox_selected');
				});
			}
			jQuery(this).addClass('checkbox_selected');

			var str_data = this.id.substring(this.id.lastIndexOf("_"));
			var valeur_id = str_data.substring(1,2);
			if(jQuery("#size_finder_hanches").attr('value') == valeur_id) {
				jQuery("#size_finder_hanches").attr('value','');
				jQuery('span.size_finder_checkbox_hanches').each(function() {
					jQuery(this).removeClass('checkbox_selected');
				});
			} else {
				jQuery("#size_finder_hanches").attr('value',valeur_id);
			}
			
		});
	});
}

function size_finder_checkbox_allure() {
	jQuery('span.size_finder_checkbox_allure').each(function() {
		
		jQuery(this).click(function () {
			if(!jQuery(this).hasClass('checkbox_selected')) {
				jQuery('span.size_finder_checkbox_allure').each(function() {
					jQuery(this).removeClass('checkbox_selected');
				});
			}
			jQuery(this).addClass('checkbox_selected');

			var str_data = this.id.substring(this.id.lastIndexOf("_"));
			var valeur_id = str_data.substring(1,2);
			
			if(jQuery("#size_finder_allure").attr('value') == valeur_id) {
				jQuery("#size_finder_allure").attr('value','');
				jQuery('span.size_finder_checkbox_allure').each(function() {
					jQuery(this).removeClass('checkbox_selected');
				});
			} else {
				jQuery("#size_finder_allure").attr('value',valeur_id);
			}
			
		});
	});
};



function verifsizefinder() {
	
	if(jQuery("#size_finder_allure").attr('value')=='' || jQuery("#size_finder_taille").attr('value')=='' || jQuery("#size_finder_poids").attr('value')=='' || jQuery("#size_finder_pointure").attr('value')=='' || jQuery("#size_finder_cuisses").attr('value')=='' || jQuery("#size_finder_hanches").attr('value')=='' || jQuery("#size_finder_confort_cuisse").attr('value')=='' || jQuery("#size_finder_confort_bas").attr('value')=='' || jQuery("#size_finder_allure").attr('value')=='') {
		jQuery("#err_sizefinder").html('Pour d&eacute;terminer votre coupe n\'oubliez pas tous les crit&egrave;res');
		return false;
	} else {
		jQuery("#size_finder_form").submit();
	}
}

function trackevt(category, action) {
  try {
    var pageTracker=_gat._getTracker("UA-17183224-1");
    pageTracker._trackEvent(category, action);
  }catch(err){}
}
