/************** CHARGEMENT PAGE *****************************/
jQuery(document).ready(function(){
    rolloverPanier();
    rollover_account();
    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){
                	
                		data = html.split('|___|');
                		if(data[1]) {
                			// création de la div
	                    if (!jQuery("#rollover_panier").attr('id')) {
	                        jQuery("<div></div>").hide().attr("id", "rollover_panier").css({
	                            'left': (pos.left)+'px',
	                            'position': 'absolute',
	                            'top': (pos.top+48)+'px',
	                            'width': '150px',
	                            'z-index': '3000'
	                        }).html(data[0]).appendTo("body").show();
	                    }else{
	                        jQuery("#rollover_panier").html(data[0]);
	                    }
                			
                		}
                		else {
	                    // création de la div
	                    if (!jQuery("#rollover_panier").attr('id')) {
	                        jQuery("<div></div>").hide().attr("id", "rollover_panier").css({
	                            'left': (pos.left-170)+'px',
	                            'position': 'absolute',
	                            'top': (pos.top+48)+'px',
	                            'z-index': '3000'
	                        }).html(html).appendTo("body").show();
	                    }else{
	                        jQuery("#rollover_panier").html(html);
	                    }
                  	}
                    
                    jQuery("#rollover_panier").mouseenter(function(event){
                        jQuery("#rollover_panier").css('display','block');
                         jQuery('#panier').css('background','transparent url("/styles/images/header/bg_header_mon_panier_hover.png") top left no-repeat');
                    });
                    jQuery("#rollover_panier").mouseleave(function(event){
                        jQuery("#rollover_panier").css('display','none');
                        jQuery('#panier').css('background','transparent url("/styles/images/header/bg_header_mon_panier.png") top left no-repeat');
                    });
                    jQuery("#panier").mouseleave(function(event){
                        jQuery("#rollover_panier").css('display','none');
                    });

                    loadPagePanier();

                }
            });
            jQuery("#rollover_panier").show();
            jQuery('#panier').css('background','transparent url("/styles/images/header/bg_header_mon_panier_hover.png") top left no-repeat');
            jQuery("#panier_texte").addClass('active');
        //}
    });
    
    jQuery("#panier").mouseleave(function(event){
        jQuery("#rollover_panier").css('display','none');
        jQuery('#panier').css('background','transparent url("/styles/images/header/bg_header_mon_panier.png") top left no-repeat');
        jQuery("#panier_texte").removeClass('active');
        
    });
}


function rollover_account() {
	/*
	jQuery("#mon_compte").mouseenter(function(event){
		jQuery('#rollover_mon_compte').css('display','block');
		jQuery('#mon_compte').css('background','transparent url("/styles/images/header/bg_header_mon_compte_hover.png") top left no-repeat');
		jQuery("#mon_compte_texte").addClass('active');
		
	});
	
	 jQuery("#mon_compte").mouseleave(function(event){
	 	jQuery('#rollover_mon_compte').css('display','none');
	 	jQuery('#mon_compte').css('background','transparent url("/styles/images/header/bg_header_mon_compte.png") top left no-repeat');
	 	jQuery("#mon_compte_texte").removeClass('active');
	});
	*/
	jQuery("#mon_compte").each(function(i){
    jQuery(this).mouseenter(function(event){
    		jQuery('#rollover_mon_compte').css('display','block');
        jQuery('#mon_compte').css('background','transparent url("/styles/images/header/bg_header_mon_compte_hover.png") top left no-repeat');
        jQuery("#mon_compte_texte").addClass('active');
    });
    jQuery(this).mouseleave(function(event){
    		jQuery('#rollover_mon_compte').css('display','none');
        jQuery('#mon_compte').css('background','transparent url("/styles/images/header/bg_header_mon_compte.png") top left no-repeat');
        jQuery("#mon_compte_texte").removeClass('active');
    });  	
  });  
	
}


//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 initMenu(){

	jQuery("li[id^=menu_li_]").each(
	
		function(intIndex){

			jQuery(this).mouseenter(
				function() {

					var liId = jQuery(this).attr('id'); 	
					jQuery(this).addClass('active');
			 		jQuery("#ss_"+liId).css('display', 'block');	
			 		jQuery("#"+liId).css('position', 'relative');	
				}
			);
			
			jQuery(this).mouseleave(	
				function() {
					var liId = jQuery(this).attr('id'); 
			 		jQuery("#ss_"+liId).css('display', 'none');
					jQuery(this).removeClass('active');	
					jQuery("#"+liId).css('position', '');	
					
					jQuery("#ss_"+liId).css('margin-left', the_margin_left+'px');
				}			
			);
			
		}
		
	);
	
}




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:'#popup'
                },
                css:{
                    'width':'700px',
                    'height':'320px',
                    'border':'1px solid #C6C6C6'
                }
            },
            content: jQuery("#popup-"+jQuery("#liste-mini-visuel .mini-visuel:first").attr('id')).html()
        });
    });
}

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'
                },
                css:{
					        'width':'676px',
					        'height':'63px',
					        'background':'transparent url("/styles/images/popup/bg_add_newsletter.png") top left no-repeat'
					      }
            },
            ajax:'/js/ajax/addNewsletter.php',
            data:jQuery(node).serialize()
        });
        return false;
    });
}

function addCallBack() {
	

        jQuery("body").popup({
            popup:{
                removeOnClick:{
                    0:'#btn-close-popup',
                    1:'#close'
                },
                css:{
					        'width':'676px',
					        'height':'390px',
					        'background':'#ffffff url("/styles/images/popup/bg_add_newsletter.png") top left no-repeat'
					      }
            },
            ajax:'/js/ajax/addCallBack.php'
        });

    	
}
function validCallBack(idForm) {
		jQuery.ajax({
			type: "POST",
		  url: '/js/ajax/validCallback.php',
		  data:jQuery('#'+idForm).serialize(),
		  success: function(req) {
				if(jQuery('#deposer_avis')) jQuery('#deposer_avis').html(req);
		  }
		});			
}
function loadAjoutPanier(){

    jQuery(".plus").css('cursor', 'pointer').click(function(){
        jQuery("#case-"+this.id).attr('value',(parseInt(jQuery("#case-"+this.id).attr('value'))+1));
        jQuery("#qte-"+jQuery(this).attr('id')).attr('value', parseInt(jQuery("#case-"+jQuery(this).attr('id')).attr('value')));
    });
	
    jQuery(".moin").css('cursor', 'pointer').click(function(){
        if ((parseInt(jQuery("#case-"+this.id).attr('value'))-1) > 0) {
            jQuery("#case-"+this.id).attr('value',(parseInt(jQuery("#case-"+this.id).attr('value'))-1));
            jQuery("#qte-"+jQuery(this).attr('id')).attr('value', parseInt(jQuery("#case-"+jQuery(this).attr('id')).attr('value')));
        }
    });
	
    jQuery("#btn-ajout-fprod").css('cursor', 'pointer').click(function(){
        jQuery("body").popup({
            popup:{
                removeOnClick:{
                    0:'#close',
                    1:'#continuer'
                }
            },
            ajax:'/js/ajax/update-panier.php',
            data:jQuery("#add-panier").serialize(),
            callback:'updateProdPanier()'
        });
    });
}

function addFastPanier(idForm){
    jQuery("body").popup({
        popup:{
            removeOnClick:{
                0:'#btn-close-popup',
                1:'#btn-continue-achat',
                2:'#close',
                3:'#continuer'
            },
            
            css:{
		        'width':'676px',
		        'height':'367px',
		        'background':'transparent url("/styles/images/popup/bg_add_panier.png") top left no-repeat'
		      }
        },
        ajax:'/js/ajax/update-panier.php',
        data:jQuery("#"+idForm).serialize(),
        callback:'updateProdPanier()'
    });
}

function addFastPanierPack(idForm){
    jQuery("body").popup({
        popup:{
            removeOnClick:{
                0:'#btn-close-popup',
                1:'#btn-continue-achat',
                2:'#close',
                3:'#continuer'
            },
            
            css:{
		        'width':'676px',
		        'height':'367px',
		        'background':'transparent url("/styles/images/popup/bg_add_panier.png") top left no-repeat'
		      }
        },
        ajax:'/js/ajax/add-fast-multi.php',
        data:jQuery("#composant_kit").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){

        }
    });
}

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();
        });
    });

    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();
    toolTipLivraisonImg();
}

function toolTipLivraisonImg(){
    jQuery(".img-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 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 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();

    jQuery(".jqzoom").jqzoom({
        zoomType: 'reverse',
        title: false,
        showPreload: false,
        zoomWidth: 360,
        zoomHeight: 150,
        position: 'right',
        xOffset : 20,
        yOffset : 5
    });
}

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: "188px",
                height: "52px",
                "z-index": 110
                
            },
            showNumber: true,
            item: {
                css: {
                    height:"29px",
                    "line-height":"29px",
                    width:"29px",
                    color: "#7b7b7b",
                    "font-weight":"bold",
                    "font-size":"18px",
                    backgroundColor: "transparent",
                    border: "none",
                    background:"url(/styles/images/home/btn_slideshow.png) no-repeat",
                    margin: "0px 10px 0px 0px",
                    "text-align": "center",
                    "vertical-align": "middle"
                },
                cssHover: {
                    color: "#ffffff",
                    backgroundColor: "transparent",
                    border: "none",
                    background:"url(/styles/images/home/btn_slideshow_actif.png) no-repeat"
                },
                cssSelected: {
                    color: "#ffffff",
                    backgroundColor: "transparent",
                    border: "none",
                    background:"url(/styles/images/home/btn_slideshow_actif.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;
}
/***********************/


function envoyerAmi(produit_id)
{
	jQuery("body").popup({
  	popup:{
  		
      removeOnClick:{
          0:'#ami_retour',
          1:'#popup_valider',
          2:'#close'
      }, 		
  		
    	css:{
        'width':'676px',
        'height':'367px',
        'background':'transparent url("/styles/images/popup/bg_add_panier.png") top left no-repeat'
      }
    },
    ajax:'/js/ajax/popupEnvoyerAmi.php',
    data:"produit_id=" + produit_id
  });		

}

function removePopup(){
    jQuery("#popup").fadeOut(function(){
        jQuery("#popup").remove();
        jQuery("#bg-popup").remove();
        jQuery("select").css('visibility', 'visible');
    });
}

function checkamis(on) {
		jQuery.ajax({
			type: "POST",
		  url: '/js/ajax/popupEnvoyerAmi.php',
		  data:jQuery('#formamis').serialize(),
		  success: function(req) {
				if(jQuery('#popup_ajout_newsletter')) jQuery('#popup_ajout_newsletter').html(req);
		  }
		});			
}


function initOngletHome() {
	
	jQuery('li[id^=home_onglet_]').each(function(){

		 jQuery(this).click(function(){
			var theId = this.id;
			var num_id = theId.slice(12,theId.length);
			
			jQuery('li[id^=home_onglet_]').each(function(){
				var theIdBis = this.id;
				var num_id_bis = theIdBis.slice(12,theIdBis.length);
				jQuery(this).children("img").attr('src','/styles/images/home/home_onglet_'+num_id_bis+'_inactif.png');
			});
			
			jQuery(this).children("img").attr('src','/styles/images/home/home_onglet_'+num_id+'_actif.png');
			
			
			jQuery('div[id^=home_onglet_conteneur_]').each(function(){
				jQuery(this).css('display','none');
			});
			
			jQuery('#home_onglet_conteneur_'+num_id).css('display','block');
			
		});
	});
	
}

function reloading(param_url) {
	window.location.href = param_url;
} 

function changeAttribut(idatt){
		jQuery("#produit_attribut_id").attr('value',idatt);
		jQuery.ajax({
			type: "POST",
		  url: '/js/ajax/updateAttributPrix.php',
		  data:'produit_attribut_id='+idatt,
		  success: function(req) {
				if(jQuery('#fp_info_stockprix')) jQuery('#fp_info_stockprix').html(req);
		  }
		});		

}


function initOngletFP() {
	
	jQuery('li[id^=produit_onglet_]').each(function(){

		 jQuery(this).click(function(){
			var theId = this.id;
			var num_id = theId.slice(15,theId.length);
			
			jQuery('li[id^=produit_onglet_]').each(function(){
				var theIdBis = this.id;
				var num_id_bis = theIdBis.slice(15,theIdBis.length);
				jQuery(this).children("img").attr('src','/styles/images/produit/produit_onglet_'+num_id_bis+'_inactif.png');
			});
			
			jQuery(this).children("img").attr('src','/styles/images/produit/produit_onglet_'+num_id+'_actif.png');
			
			
			jQuery('div[id^=fiche_produit_onglet_]').each(function(){
				jQuery(this).css('display','none');
			});
			
			jQuery('#fiche_produit_onglet_'+num_id).css('display','block');
			
		});
	});
	
}

function initOngletFPP() {
	
	jQuery('li[id^=produit_perso_onglet_]').each(function(){

		 jQuery(this).click(function(){
			var theId = this.id;
			var num_id = theId.slice(21,theId.length);
			
			jQuery('li[id^=produit_perso_onglet_]').each(function(){
				var theIdBis = this.id;
				var num_id_bis = theIdBis.slice(21,theIdBis.length);
				jQuery(this).children("img").attr('src','/styles/images/produit/produit_perso_onglet_'+num_id_bis+'_inactif.png');
			});
			
			jQuery(this).children("img").attr('src','/styles/images/produit/produit_perso_onglet_'+num_id+'_actif.png');
			
			
			jQuery('div[id^=fiche_produit_perso_onglet_]').each(function(){
				jQuery(this).css('display','none');
			});
			
			jQuery('#fiche_produit_perso_onglet_'+num_id).css('display','block');
			jQuery('#fp_perso_add_panier_e').css('display','block');
		});
	});
	
}

function initOngletFPPChoix() {
	
	jQuery('li[id^=fp_perso_choix_onglet_]').each(function(){

		 jQuery(this).click(function(){
			var theId = this.id;
			var num_id = theId.slice(22,theId.length);
			
			jQuery('li[id^=fp_perso_choix_onglet_]').each(function(){
				var theIdBis = this.id;
				var num_id_bis = theIdBis.slice(22,theIdBis.length);
				jQuery(this).children("img").attr('src','/styles/images/produit/fp_perso_choix_onglet_'+num_id_bis+'_inactif.png');
			});
			
			jQuery(this).children("img").attr('src','/styles/images/produit/fp_perso_choix_onglet_'+num_id+'_actif.png');
			
			
			jQuery('div[id^=fp_perso_dimensions_onglet_]').each(function(){
				jQuery(this).css('display','none');
			});

      /*
			jQuery('div[id^=fp_perso_standard_perso_]').each(function(){
				jQuery(this).css('display','none');
			});
			*/

			jQuery('div[id^=produit_delai_livraison_]').each(function(){
				jQuery(this).css('display','none');
			});
			
			jQuery('div[id^=fp_perso_add_panier_]').each(function(){
				jQuery(this).css('display','none');
			});
			
			
			
			jQuery('#fp_perso_dimensions_onglet_'+num_id).css('display','block');
			
      //jQuery('#fp_perso_standard_perso_'+num_id).css('display','block');




			jQuery('#produit_delai_livraison_'+num_id).css('display','block');
			jQuery('#fp_perso_add_panier_'+num_id).css('display','block');


      var nb_finition_standard = jQuery("#finition_standard").html();
      var nb_finition_mesure = jQuery("#finition_mesure").html();


      if(num_id == 1) {
        if(nb_finition_standard == 0 && nb_finition_mesure == 0) {
          jQuery('#bloc_droit_finition').css('display','none');
        }else{
          jQuery('#bloc_droit_finition').css('display','block');
        }
        
        if(nb_finition_standard == 0 && nb_finition_mesure == 0) {
          jQuery('#fp_perso_choix_droit_actif_1').css('display','none');
        }
        else if(nb_finition_standard == 0 && nb_finition_mesure > 0) {
        	jQuery('#fp_perso_choix_droit_actif_1').css('display','block');
        }
        
        
        
        if(nb_finition_mesure == 0) {
          jQuery('#fp_perso_choix_droit_inactif_1').css('display','none');
        }else{
          jQuery('#fp_perso_choix_droit_inactif_1').css('display','block');
        }

        jQuery("#fp_perso_standard_perso_1").css("display", "block");
        jQuery("#fp_perso_standard_perso_2").css("display", "none");

      }

      if(num_id == 2) {
        if(nb_finition_mesure == 0 && nb_finition_standard == 0) {
          jQuery('#bloc_droit_finition').css('display','none');
        }else{
          jQuery('#bloc_droit_finition').css('display','block');
        }
        if(nb_finition_mesure == 0) {
          jQuery('#fp_perso_choix_droit_actif_2').css('display','none');
        }
        /*
        if(nb_finition_standard == 0) {
          jQuery('#fp_perso_choix_droit_inactif_2').css('display','none');
        }else{
          jQuery('#fp_perso_choix_droit_inactif_2').css('display','block');
        }
        */
        if(nb_finition_standard == 0 && nb_finition_mesure == 0) {
          jQuery('#fp_perso_choix_droit_actif_1').css('display','none');
        }
        else if(nb_finition_standard == 0 && nb_finition_mesure > 0) {
        	jQuery('#fp_perso_choix_droit_actif_1').css('display','block');
        }


        	jQuery("#fp_perso_standard_perso_1").css("display", "none");
        	jQuery("#fp_perso_standard_perso_2").css("display", "block");

      }

			jQuery('#fp_perso_add_panier_e').css('display','block');
/*
      jQuery.ajax({
          type: 'POST',
          url: '/js/ajax/afficheFinition.php',
          data:'num_id=' + num_id + '&nb_finition_standard=' + nb_finition_standard + '&nb_finition_mesure=' + nb_finition_mesure,
          success: function(msg){
            jQuery('#bloc_droit_finition').html(msg);
          }
      });
*/


		});
	});
	
}

function inscr_on(elts,etat) {
  
	if(etat == 1) {
		jQuery('#'+elts).addClass('inscr_on');
	}else if(etat == 2) {
    
		jQuery('#'+elts).removeClass('inscr_on');

		var elts_form = elts.split('form_');
		jQuery.ajax({
			type: "POST",
		  url: '/js/ajax/form_inscrcompte.php',
		  data:jQuery('#inscription').serialize()+'&data='+elts_form[1],
		  success: function(req) {
		  	if(req == "false" || req == "false_len" || req == "false_parrain" || req == "false_confirm" || req == "false_email") {
          
		  		jQuery('#'+elts).addClass('error_inscr_form');

          if(!document.getElementById('err'+elts_form[1]) && req == "false") {
            jQuery('#'+elts).append('<label id="err'+elts_form[1]+'" for="'+elts_form[1]+'" generated="true" class="error">Information obligatoire</label>');
          }

          jQuery('#'+elts+' label').each(function(i){
            if(jQuery(this).hasClass("valid")) {
              jQuery(this).css("display","none");
            }
          });
          if(elts_form[1] == "client_password") {
            jQuery("#min_carac").css("display","none");
          }
				}
				else {

          jQuery('#'+elts+' label').each(function(i){
            if(jQuery(this).hasClass("valid")) {
              jQuery(this).css("display","inline");
            }
          });

					jQuery('#err'+elts_form[1]).remove();
					jQuery('#'+elts).removeClass('error_inscr_form');
          if(elts_form[1] == "client_password") {
            jQuery("#min_carac").css("display","none");
          }
				}
		  }
		});		
		
/*
		jQuery("label[class^=error valid]").each(function(i){
			jQuery(this).parent().each(function(i){
				jQuery(this).parent().removeClass('error_inscr_form');
			});
		});
*/
	}
	else {
		jQuery('#'+elts).removeClass('inscr_on');

    jQuery('#'+elts+' label').each(function(i){
      if(jQuery(this).hasClass("valid")) {
        jQuery(this).css("display","inline");
      }
    });

		jQuery("label[class^=error valid]").each(function(i){
			jQuery(this).parent().each(function(i){
				jQuery(this).parent().removeClass('error_inscr_form');
			});
		});
		
	}
}

function modif_on(elts,etat) {

	if(etat == 1) {
		jQuery('#'+elts).addClass('inscr_on');
	}else if(etat == 2) {

		jQuery('#'+elts).removeClass('inscr_on');

		var elts_form = elts.split('form_');
		jQuery.ajax({
			type: "POST",
		  url: '/js/ajax/form_inscrcompte.php',
		  data:jQuery('#form_inscription').serialize()+'&data='+elts_form[1]+'&modif=1',
		  success: function(req) {
		  	if(req == "false" || req == "false_len" || req == "false_confirm") {

		  		jQuery('#'+elts).addClass('error_inscr_form');

          if(!document.getElementById('err'+elts_form[1]) && req == "false") {
            jQuery('#'+elts).append('<label id="err'+elts_form[1]+'" for="'+elts_form[1]+'" generated="true" class="error">Information obligatoire</label>');
          }

          jQuery('#'+elts+' label').each(function(i){
            if(jQuery(this).hasClass("valid")) {
              jQuery(this).css("display","none");
            }
          });
          if(elts_form[1] == "client_password") {
            jQuery("#min_carac").css("display","none");
          }
				}
				else {

          jQuery('#'+elts+' label').each(function(i){
            if(jQuery(this).hasClass("valid")) {
              jQuery(this).css("display","inline");
            }
          });

					jQuery('#err'+elts_form[1]).remove();
					jQuery('#'+elts).removeClass('error_inscr_form');
          if(elts_form[1] == "client_password") {
            jQuery("#min_carac").css("display","none");
          }
				}
		  }
		});

/*
		jQuery("label[class^=error valid]").each(function(i){
			jQuery(this).parent().each(function(i){
				jQuery(this).parent().removeClass('error_inscr_form');
			});
		});
*/
	}
	else {
		jQuery('#'+elts).removeClass('inscr_on');

    jQuery('#'+elts+' label').each(function(i){
      if(jQuery(this).hasClass("valid")) {
        jQuery(this).css("display","inline");
      }
    });

		jQuery("label[class^=error valid]").each(function(i){
			jQuery(this).parent().each(function(i){
				jQuery(this).parent().removeClass('error_inscr_form');
			});
		});

	}
}



function qteprodmoins(idProd,idForm)
{

	if(document.getElementById('qte_'+idProd).value>0)
	{
		document.getElementById('qte_'+idProd).value = parseInt(document.getElementById('qte_'+idProd).value) - 1;
		RecalculPrix(idProd,idForm);	
	}
}

function qteprodplus(idProd,idForm)
{
	if(document.getElementById('qte_'+idProd).value<99)
	{
		document.getElementById('qte_'+idProd).value = parseInt(document.getElementById('qte_'+idProd).value) + 1;
		RecalculPrix(idProd,idForm);	
	}
}

function RecalculPrix(lolid,formID)
{
		jQuery.ajax({
        type: 'POST',
        url: '/js/ajax/calculPrixProduit.php',
        data:'idProduit=' + lolid + '&qte=' + document.getElementById('qte_'+lolid).value,
        success: function(msg){
        		data = msg.split('|_______|');

						jQuery("#att_prix_"+lolid).html(data[0]);
						jQuery.ajax({
				        type: 'POST',
				        url: '/js/ajax/calculMontantProduit.php',
				        data:jQuery("#"+formID).serialize(),
				        success: function(msg){
										jQuery("#montant_prix1").html(msg);
										jQuery("#montant_prix_total1").attr('value',msg);
				        }
				    });

        }
    });
    
    
		
}


function qteprodmoinsM(idProd,idForm,indice)
{

	if(document.getElementById('qte_'+idProd).value>0)
	{
		document.getElementById('qte_'+idProd).value = parseInt(document.getElementById('qte_'+idProd).value) - 1;
		RecalculPrixM(idProd,idForm,indice);
	}
}

function qteprodplusM(idProd,idForm,indice)
{
	if(document.getElementById('qte_'+idProd).value<99)
	{
		document.getElementById('qte_'+idProd).value = parseInt(document.getElementById('qte_'+idProd).value) + 1;
		RecalculPrixM(idProd,idForm,indice);	
	}
}

function RecalculPrixM(lolid,formID,indice)
{
		jQuery.ajax({
        type: 'POST',
        url: '/js/ajax/calculPrixProduitSurMesure.php',
        data:jQuery("#"+formID).serialize()+'&indice='+indice+'&idProduit=' + lolid,
        success: function(msg){
        		data = msg.split('|_______|');


							jQuery("#att_prix_"+data[2]).html(data[0]);
							jQuery.ajax({
					        type: 'POST',
					        url: '/js/ajax/calculMontantProduitSurMesure.php',
					        data:jQuery("#"+formID).serialize(),
					        success: function(msg){
											jQuery("#montant_prix2").html(msg);
											jQuery("#montant_prix_total2").attr('value',msg);
					        }
					    });
							
						

        }
    });
    
    
		
}




function qteprodmoinsMP(idProd,idForm,indice)
{

	if(document.getElementById('qte_'+idProd).value>0)
	{
		document.getElementById('qte_'+idProd).value = parseInt(document.getElementById('qte_'+idProd).value) - 1;
		RecalculPrixMP(idProd,idForm,indice);
	}
}

function qteprodplusMP(idProd,idForm,indice)
{
	if(document.getElementById('qte_'+idProd).value<99)
	{
		document.getElementById('qte_'+idProd).value = parseInt(document.getElementById('qte_'+idProd).value) + 1;
		RecalculPrixMP(idProd,idForm,indice);	
	}
}

function RecalculPrixMP(lolid,formID,indice)
{
		jQuery.ajax({
        type: 'POST',
        url: '/js/ajax/calculPrixProduitSurMesurePoutre.php',
        data:jQuery("#"+formID).serialize()+'&indice='+indice+'&idProduit=' + lolid,
        success: function(msg){
        		data = msg.split('|_______|');
							jQuery("#att_prix_"+data[2]).html(data[0]);
							jQuery.ajax({
					        type: 'POST',
					        url: '/js/ajax/calculMontantProduitSurMesurePoutre.php',
					        data:jQuery("#"+formID).serialize(),
					        success: function(msg){
											jQuery("#montant_prix2").html(msg);
											jQuery("#montant_prix_total2").attr('value',msg);
					        }
					    });
							
						

        }
    });
    
    
		
}




function addLigneTabSurMesure(idTab,idProd) {
	var insert = true;
	jQuery("input[id^=indice]").each(function(i){
		var idLigne = jQuery(this).attr('value');
		if(idTab == idLigne) insert = false;
	});
	
	if(insert) {
		jQuery.ajax({
	        type: 'POST',
	        url: '/js/ajax/addLigneTabSurMesure.php',
	        data:'id='+idTab+'&produit_id='+idProd,
	        success: function(msg){
	        	 jQuery('#surmesure_tab tr:last').after(msg);
	
	        }
	    });
	 }
}

function addLigneTabSurMesurePoutre(idTab,idProd) {
	var insert = true;
	jQuery("input[id^=indice]").each(function(i){
		var idLigne = jQuery(this).attr('value');
		if(idTab == idLigne) insert = false;
	});
	
	if(insert) {
		jQuery.ajax({
	        type: 'POST',
	        url: '/js/ajax/addLigneTabSurMesurePoutre.php',
	        data:'id='+idTab+'&produit_id='+idProd,
	        success: function(msg){
	        	 jQuery('#surmesure_tab tr:last').after(msg);
	
	        }
	    });
	 }
}

function sauvegarder_panier() {
	jQuery("body").popup({
  	popup:{
  		
      removeOnClick:{
          1:'#popup_valider',
          2:'#close'
      }, 		
  		
    	css:{
        'width':'676px',
		    'height':'367px',
		    'background':'transparent url("/styles/images/popup/bg_add_panier.png") top left no-repeat'
      }
    },
    ajax:'/js/ajax/popupValiderPanier.php',
    data:""
  });			
}

function checkpanier(on) {
		jQuery.ajax({
			type: "POST",
		  url: '/js/ajax/popupValiderPanier.php',
		  data:jQuery('#formamis').serialize(),
		  success: function(req) {
				if(jQuery('#popupclassique')) jQuery('#popupclassique').html(req);
		  }
		});			
}


function updateEcoleBoulle(lolid)
{
		jQuery.ajax({
        type: 'POST',
        url: '/js/ajax/updateEcoleBoulle.php',
        data:'id=' + lolid,
        success: function(msg){
						jQuery("#boulle_listing_conteneur").html(msg);
        }
    });
    
    
		
}

function addTemoignage(idProd) {
	jQuery("body").popup({
  	popup:{
  		
      removeOnClick:{
          1:'#popup_valider',
          2:'#close'
      }, 		
  		
    	css:{
        'width':'676px',
		    'height':'367px',
		    'background':'transparent url("/styles/images/popup/bg_add_panier.png") top left no-repeat'
      }
    },
    ajax:'/js/ajax/addTemoignage.php',
    data:"produit_id="+idProd
  });	
}

function validTemoignage(idForm) {
		jQuery.ajax({
			type: "POST",
		  url: '/js/ajax/validTemoignage.php',
		  data:jQuery('#'+idForm).serialize(),
		  success: function(req) {
				if(jQuery('#deposer_avis')) jQuery('#deposer_avis').html(req);
		  }
		});			
}
function IsNumericTest(sText) {
   var ValidChars = "0123456789.";
   var IsNumber=true;
   var Char;


   for (i = 0; i < sText.length && IsNumber == true; i++)
      {
      Char = sText.charAt(i);
      if (ValidChars.indexOf(Char) == -1)
         {
         IsNumber = false;
         }
      }
   return IsNumber;

}

function nbVirguleTest(sText) {
		var TropVirgule=true;
	 	decimal = sText.split('.');
		if(decimal[1] && decimal[1].length >=2) {
			TropVirgule = false;
		}
		
		return TropVirgule;

}

function checkSaisieL(valeur,idChamp, min, max) {
  
    if (!IsNumericTest(valeur)) {
            alert('Ce n\'est pas un chiffre');
            jQuery('#'+idChamp).attr('value','');
    }else if(!nbVirguleTest(valeur)) {
            alert('Vous ne pouvez pas saisir au dixième de mm près');
            jQuery('#'+idChamp).attr('value','');
    }else if(valeur < min || valeur > max) {
        if(valeur<min) {
            alert('Veuillez saisir un chiffre supérieur ou égale à '+min);
        }else if(valeur>max) {
            alert('Veuillez saisir un chiffre inférieur ou égale à '+max);
        }
        jQuery('#'+idChamp).attr('value','');
    }
}
function verifDimension(valeur1, valeur2,idProduit,index) {
    /*if(valeur1 >= 25 && valeur2 >= 25){
        jQuery.ajax({
            type: "GET",
            url: '/js/ajax/verifDimension.php?finition=1&produit_id='+idProduit+'&index='+index,
            success: function(req) {
                if(jQuery('#div_usinage_'+index)) jQuery('#div_usinage_'+index).html(req);
            }
        });        
        jQuery.ajax({
            type: "GET",
            url: '/js/ajax/verifDimension.php?finition=2&produit_id='+idProduit+'&index='+index,
            success: function(req) {
                if(jQuery('#contenu-finition-'+index)) jQuery('#contenu-finition-'+index).html(req);
            }
        }); 
    }else*/
    if((valeur1 > 0 && valeur2 > 0) && (valeur1 < 25 || valeur2 < 25))
    {
        jQuery("#usinage\\["+index+"\\]").val(4);
        jQuery.ajax({
            type: "POST",
            url: "/js/ajax/ShowHideOptionFinition.php",
            data: 'produit_id='+idProduit+'&usinage_id=4&valeurIndex='+index,
            success: function(msg){
                jQuery("#contenu-finition-"+index).html(msg);
            }
        });           
        jQuery("body").popup({
            popup:{
                removeOnClick:{
                    0:'#btn-close-popup',
                    1:'#btn-continue-achat',
                    2:'#close',
                    3:'#continuer'
                },

                css:{
                            'width':'676px',
                            'height':'367px',
                            'background':'transparent url("/styles/images/popup/bg_add_panier.png") top left no-repeat'
                          }
            },
            type: "GET",
            ajax:'/js/ajax/verifDimension.php',
            data:'nogood=1'
        });
    }
}

function lockLogin(etat) {
	if(etat) {

		jQuery('#mon_compte').unbind('mouseleave');

	  // Menu compte
	  jQuery("#mon_compte").each(function(i){
	    jQuery(this).mouseenter(function(event){
	    		jQuery("#rollover_mon_compte").css('display', 'block');
	    		jQuery("#mon_compte").css('background', 'transparent url(/styles/images/header/bg_header_mon_compte.png) no-repeat top left');
	    });

	  });
	}else{
	  // Menu compte
	  jQuery("#mon_compte").each(function(i){
	    jQuery(this).mouseenter(function(event){
	    		jQuery("#rollover_mon_compte").css('display', 'block');
	    		jQuery("#mon_compte").css('background', 'transparent url(/styles/images/header/bg_header_mon_compte_hover.png) no-repeat top left');
	    });
	    jQuery(this).mouseleave(function(event){
	    		jQuery("#rollover_mon_compte").css('display', 'none');
	    		jQuery("#mon_compte").css('background', 'transparent url(/styles/images/header/bg_header_mon_compte.png) no-repeat top left');
	    });
	  });
	}
}

function showImageSousCat(varId,varImg,varImgDefault) {
	if(varImg != '') {
		jQuery("#sous_menu_image_"+varId).html('<img src="'+varImg+'" alt="" style="display:block;margin:auto;text-align:center;margin-top:15px;" />');
	}
	else if(varImgDefault != '') {
		jQuery("#sous_menu_image_"+varId).html('<img src="'+varImgDefault+'" alt="" style="display:block;margin:auto;text-align:center;margin-top:15px;" />');
	}
	else {
		jQuery("#sous_menu_image_"+varId).html('');
	}
}

function toolTipProd() {
	toolTipLivraison();
  toolTipLivraisonImg();
}

function ShowHideOptionFinition(idProduit,valeurIndex,idUsinage) {

    var valeurLongueur = jQuery("#longueur_"+valeurIndex).val()
    var valeurLargueur = jQuery("#largeur_"+valeurIndex).val()


    if(valeurLargueur < 25 || valeurLongueur < 25)
    {
        jQuery("#usinage\\["+valeurIndex+"\\]").val(4);
        jQuery.ajax({
            type: "POST",
            url: "/js/ajax/ShowHideOptionFinition.php",
            data: 'produit_id='+idProduit+'&usinage_id=4&valeurIndex='+valeurIndex,
            success: function(msg){
                jQuery("#contenu-finition-"+valeurIndex).html(msg);
            }
        });         
        jQuery("body").popup({
            popup:{
                removeOnClick:{
                    0:'#btn-close-popup',
                    1:'#btn-continue-achat',
                    2:'#close',
                    3:'#continuer'
                },

                css:{
                            'width':'676px',
                            'height':'367px',
                            'background':'transparent url("/styles/images/popup/bg_add_panier.png") top left no-repeat'
                          }
            },
            type: "GET",
            ajax:'/js/ajax/verifDimension.php',
            data:'nogood=1'
        });
    }else{
        jQuery.ajax({
            type: "POST",
            url: "/js/ajax/ShowHideOptionFinition.php",
            data: 'produit_id='+idProduit+'&usinage_id='+idUsinage+'&valeurIndex='+valeurIndex,
            success: function(msg){
                jQuery("#contenu-finition-"+valeurIndex).html(msg);
            }
        });        
    }
}

function calculKit() {
	jQuery.ajax({
		type: "POST",
		url: "/js/ajax/calculKit.php",
		data: jQuery("#composant_kit").serialize(),
		success: function(msg){
			jQuery("#composant_kit").html(msg);
		}
	}); 
}

function calculKitConseil() {
	jQuery.ajax({
		type: "POST",
		url: "/js/ajax/calculKitConseil.php",
		data: jQuery("#composant_kit").serialize(),
		success: function(msg){
			jQuery("#composant_kit").html(msg);
		}
	}); 
}

function changeImgGd(obj1,obj2,idImage) {
	jQuery('#zoom1').attr('href', obj1);
	jQuery('#img_grand-visuel').attr('src', obj2);
  jQuery('.cloud-zoom, .cloud-zoom-gallery').CloudZoom();
}


function addFastEchantillon(idForm){
    jQuery("body").popup({
        popup:{
            removeOnClick:{
                0:'#btn-close-popup',
                1:'#btn-continue-achat',
                2:'#close',
                3:'#continuer',
                4:'#exit-ech'
            },
            
            css:{
		        'width':'676px',
		        'height':'367px',
		        'background':'transparent url("/styles/images/popup/bg_add_panier.png") top left no-repeat'
		      }
        },
        ajax:'/js/ajax/echantillon-panier.php',
        data:jQuery("#"+idForm).serialize()
        //callback:'updateProdPanier()'
    });
}

function dlPDF(idConseil) {
	jQuery("body").popup({
  	popup:{
  		
      removeOnClick:{
          1:'#popup_valider',
          2:'#close'
      }, 		
  		
    	css:{
        'width':'676px',
		    'height':'367px',
		    'background':'transparent url("/styles/images/popup/bg_add_panier.png") top left no-repeat'
      }
    },
    ajax:'/js/ajax/dlConseil.php',
    data:"conseil_id="+idConseil
  });	
}

function validConseil(idForm) {
		jQuery.ajax({
			type: "POST",
		  url: '/js/ajax/validConseil.php',
		  data:jQuery('#'+idForm).serialize(),
		  success: function(req) {
				if(jQuery('#deposer_avis')) jQuery('#deposer_avis').html(req);
		  }
		});			
}

function Rebour(dates) {
	//date = 2011-09-03 00:00:00
	var arrDate = dates.split(' ');
	var DateTmp = arrDate[0].split('-');
	var TimeTmp = arrDate[1].split(':');
	// y - m - d - h - m - s
	
	var chaineDate = "";

	if(DateTmp[1]=="01"){
		chaineDate = chaineDate+"Jan";
	}else if(DateTmp[1]=="02") {
		chaineDate = chaineDate+"Feb";
	}else if(DateTmp[1]=="03") {
		chaineDate = chaineDate+"Mar";
	}else if(DateTmp[1]=="04") {
		chaineDate = chaineDate+"Apr";
	}else if(DateTmp[1]=="05") {
		chaineDate = chaineDate+"May";
	}else if(DateTmp[1]=="06") {
		chaineDate = chaineDate+"Jun";
	}else if(DateTmp[1]=="07") {
		chaineDate = chaineDate+"Jul";
	}else if(DateTmp[1]=="08") {
		chaineDate = chaineDate+"Aug";
	}else if(DateTmp[1]=="09") {
		chaineDate = chaineDate+"Sep";
	}else if(DateTmp[1]=="10") {
		chaineDate = chaineDate+"Oct";
	}else if(DateTmp[1]=="11") {
		chaineDate = chaineDate+"Nov";
	}else if(DateTmp[1]=="12") {
		chaineDate = chaineDate+"Dec";
	}
	chaineDate = chaineDate+" "+DateTmp[2];
	chaineDate = chaineDate+" "+TimeTmp[0]+":"+TimeTmp[1]+":"+TimeTmp[2];
	chaineDate = chaineDate+" "+DateTmp[0];
	
	//year, month, day, hours, minutes, seconds
	var Affiche=document.getElementById("pvf_flash");
	var date1 = new Date();
	var date2 = new Date (chaineDate);
	var sec = (date2 - date1) / 1000;
	var n = 24 * 3600;
	if (sec > 0) {
		j = Math.floor (sec / n);
		h = Math.floor ((sec - (j * n)) / 3600);
		mn = Math.floor ((sec - ((j * n + h * 3600))) / 60);
		sec = Math.floor (sec - ((j * n + h * 3600 + mn * 60)));
		
		if(j<10)
			j = "0"+j;
		if(h<10)
			h = "0"+h;		
		if(mn<10)
			mn = "0"+mn;			
		if(sec<10)
			sec = "0"+sec;						
		Affiche.innerHTML = j +" "+ h +" "+ mn +" "+ sec;
		window.status = j +" "+ h +" "+ mn +" "+ sec;
	}
	tRebour=setTimeout ("Rebour('"+dates+"');", 1000);
}


function Rebour_listing(dates, div) {
	//date = 2011-09-03 00:00:00
	var arrDate = dates.split(' ');
	var DateTmp = arrDate[0].split('-');
	var TimeTmp = arrDate[1].split(':');
	// y - m - d - h - m - s
	
	var chaineDate = "";

	if(DateTmp[1]=="01"){
		chaineDate = chaineDate+"Jan";
	}else if(DateTmp[1]=="02") {
		chaineDate = chaineDate+"Feb";
	}else if(DateTmp[1]=="03") {
		chaineDate = chaineDate+"Mar";
	}else if(DateTmp[1]=="04") {
		chaineDate = chaineDate+"Apr";
	}else if(DateTmp[1]=="05") {
		chaineDate = chaineDate+"May";
	}else if(DateTmp[1]=="06") {
		chaineDate = chaineDate+"Jun";
	}else if(DateTmp[1]=="07") {
		chaineDate = chaineDate+"Jul";
	}else if(DateTmp[1]=="08") {
		chaineDate = chaineDate+"Aug";
	}else if(DateTmp[1]=="09") {
		chaineDate = chaineDate+"Sep";
	}else if(DateTmp[1]=="10") {
		chaineDate = chaineDate+"Oct";
	}else if(DateTmp[1]=="11") {
		chaineDate = chaineDate+"Nov";
	}else if(DateTmp[1]=="12") {
		chaineDate = chaineDate+"Dec";
	}
	chaineDate = chaineDate+" "+DateTmp[2];
	chaineDate = chaineDate+" "+TimeTmp[0]+":"+TimeTmp[1]+":"+TimeTmp[2];
	chaineDate = chaineDate+" "+DateTmp[0];
	
	//year, month, day, hours, minutes, seconds
	var Affiche=document.getElementById(div);
	var date1 = new Date();
	var date2 = new Date (chaineDate);
	var sec = (date2 - date1) / 1000;
	var n = 24 * 3600;
	if (sec > 0) {
		j = Math.floor (sec / n);
		h = Math.floor ((sec - (j * n)) / 3600);
		mn = Math.floor ((sec - ((j * n + h * 3600))) / 60);
		sec = Math.floor (sec - ((j * n + h * 3600 + mn * 60)));
		
		if(j<10)
			j = "0"+j;
		if(h<10)
			h = "0"+h;		
		if(mn<10)
			mn = "0"+mn;			
		if(sec<10)
			sec = "0"+sec;						
		Affiche.innerHTML = j +" "+ h +" "+ mn +" "+ sec;
		window.status = j +" "+ h +" "+ mn +" "+ sec;
	}
	tRebour=setTimeout ("Rebour_listing('"+dates+"', '"+div+"');", 1000);
}

function erreurQte(){
    jQuery("body").popup({
        popup:{
            removeOnClick:{
                0:'#btn-close-popup',
                1:'#btn-continue-achat',
                2:'#close',
                3:'#continuer'
            },
            
            css:{
		        'width':'676px',
		        'height':'367px',
		        'background':'transparent url("/styles/images/popup/bg_add_panier.png") top left no-repeat'
		      }
        },
        ajax:'/js/ajax/errQtePanier.php'
    });
}

