/************** CHARGEMENT PAGE *****************************/
jQuery(document).ready(function(){
    rolloverPanier();
    loadAddNewsletter('#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({
                            'left': (pos.left-255)+'px',
                            'position': 'absolute',
                            'top': (pos.top+80)+'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("#rollover_panier").mouseleave(function(event){
                        jQuery("#rollover_panier").css('display','none');
                    });
                    jQuery("#panier").mouseleave(function(event){
                        jQuery("#rollover_panier").css('display','none');
                    });
                }
            });
            jQuery("#rollover_panier").show();
        }
    });
    
    jQuery("panier").mouseleave(function(event){
        jQuery("#rollover_panier").css('display','none');
    });
}

function ViewPopupFerme()
{
	jQuery("body").popup({
		popup:{
  		
      removeOnClick:{
          0:'#close'
      }
    },
    background:{
      	removeOnClick:false
    },
    removeOnClick:{
          0:'#close'
      }, 
    ajax:'/js/ajax/popupsiteferme.php'
  });	
	
}

function ViewPopup(popup_id)
{
	jQuery("body").popup({
  	popup:{
  		
      removeOnClick:{
          0:'#close'
      }
    },
    ajax:'/js/ajax/popup.php',
    data:'popup_id='+popup_id
  });	
	
}

//Affichage du sous menu au rollover
function initMenu(){

    jQuery("#menuheader a.lien_menu_principal").each(function(i){

        jQuery(this).mouseenter(function(event){
            jQuery("#ssmenu_" + jQuery(this).attr("id")).css('visibility', 'visible');
        });

        jQuery(this).mouseleave(function(event){
            jQuery("#ssmenu_" + jQuery(this).attr("id")).css('visibility', 'hidden');
        });
    });

    jQuery(".ssmenu").each(function(i){
        jQuery(this).mouseenter(function(event){
            jQuery("#" + jQuery(this).attr("id").substr(7)).addClass('onrollover');
            jQuery(this).css('visibility', 'visible');
        });

        jQuery(this).mouseleave(function(event){
            jQuery(this).removeClass('hover');
            jQuery("#" + jQuery(this).attr("id").substr(7)).removeClass('onrollover');
            jQuery(this).css('visibility', 'hidden');
        });
    });
}





function loadChangeImage(){
   /* jQuery(".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':'650px',
                            'height':'650px',
                            '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':'650px',
                    'height':'650px',
                    'border':'1px solid #C6C6C6'
                }
            },
            content: jQuery("#popup-visu").html()
        });
    });
}

function zoomMini(idImg){
	jQuery("body").popup({
      popup:{
          removeOnClick:{
              0:'#popup'
          },
          css:{
              'width':'650px',
              'height':'650px',
              'border':'1px solid #C6C6C6'
          }
      },
      content: jQuery("#popup-visu-"+idImg).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'
                }
            },
            ajax:'/js/ajax/addNewsletter.php',
            data:jQuery(node).serialize()
        });
        return false;
    });
}

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'
            }
        },
        ajax:'/js/ajax/update-panier.php',
        data:jQuery("#"+idForm).serialize(),
        callback:'updateProdPanier()'
    });
}

function popupoffert(txt){
    jQuery("body").popup({
        popup:{
            removeOnClick:{
                0:'#btn-close-popup',
                1:'#btn-continue-achat',
                2:'#close',
                3:'#continuer'
            }
        },
        background:{
		      	removeOnClick:false
		    },
        ajax:'/js/ajax/popupoffert.php',
        data:'txt='+txt
    });
}

function addFastPanierMulti(idForm){
    jQuery("body").popup({
        popup:{
            removeOnClick:{
                0:'#btn-close-popup',
                1:'#btn-continue-achat',
                2:'#close',
                3:'#continuer'
            }
        },
        ajax:'/js/ajax/update-panier-multi.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){
					jQuery("#nbph").html(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('#formcoordonnees').submit();
    });
    
    jQuery("#livraison_zone_id").change(function(){
        jQuery("#flag").attr('value', '3');
        jQuery('#formcoordonnees').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 - 15,
                    'left':event.pageX + 25
                });
            }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 - 15,
                    'left':event.pageX + 25,
                    'position':'absolute'
                })
                .appendTo("body");
            }
        });

        jQuery(this).mouseleave(function(){
            jQuery("#popup-"+jQuery(this).attr('id')).css('display', 'none');
        });

    });
}

function loadSendMail(){

        jQuery.ajax({
            type: "POST",
            url: "/js/ajax/contact.php",
            data: jQuery("#contact").serialize(),
            success: function(msg){
                jQuery("#contenu-contact").html(msg);
            }
        });

}
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();


}

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("#slide").showcase({
        animation: {
            type: "horizontal-slider",
            stopOnHover: true,
            speed: 600
        },
        navigator:{
            position: "bottom-left",
            css: {
                top: "190px",
                height: "40px",
                "z-index": 1100
                
            },
            showNumber: false,
            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;
}
/***********************/


function envoyerAmi(produit_id)
{
	jQuery("body").popup({
  	popup:{
  		
      removeOnClick:{
          0:'#ami_retour',
          1:'#popup_valider',
          2:'#close'
      }, 		
  		
    	css:{
        'width':'309px',
        'height':'370px'
      }
    },
    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')) jQuery('#popup').html(req);
		  }
		});			
		
}

//Ajoute le panier au mémo
function addMemo(idForm, url){
    jQuery("body").popup({
        popup:{
            removeOnClick:{
                0:'#btn-close-popup',
                1:'#btn-continue-achat',
                2:'#close',
                3:'#continuer_visite'
            }
        },
        ajax:'/js/ajax/update-memo.php',
        data:jQuery("#"+idForm).serialize(),
        callback:"updateInfoMemo()"
    });
}

function updateInfoMemo(){
    jQuery.ajax({
      type: "POST",
      url: "/js/ajax/getInfoMemo.php",
      success: function(msg){
          jQuery("#nb-memo").html(msg);
      }
    })
}


function calcul_produit_classique(){

        jQuery.ajax({
            type: "POST",
            url: "/js/ajax/produit/produit_classique.php",
            data: jQuery("#select_quantite").serialize(),
            success: function(msg){
                jQuery("#commander").html(msg);
            }
        });

}

function calcul_produit_perso(){

        jQuery.ajax({
            type: "POST",
            url: "/js/ajax/produit/produit_perso.php",
            data: jQuery("#select_quantite").serialize(),
            success: function(msg){
                jQuery("#commander").html(msg);
            }
        });

}

function calcul_produit_kit(){

        jQuery.ajax({
            type: "POST",
            url: "/js/ajax/produit/produit_kit.php",
            data: jQuery("#select_quantite").serialize(),
            success: function(msg){
                jQuery("#attribut").html(msg);
            }
        });

}


function calcul_produit_couleur(){

        jQuery.ajax({
            type: "POST",
            url: "/js/ajax/produit/produit_couleur.php",
            data: jQuery("#select_quantite_att").serialize(),
            success: function(msg){
                jQuery("#gauche_fiche_produit").html(msg);
            }
        });

}

function select_parent_color_sans_taille(){

        jQuery.ajax({
            type: "POST",
            url: "/js/ajax/produit/produit_couleur.php",
            data: jQuery("#select_parent_couleur").serialize(),
            success: function(msg){
                jQuery("#gauche_fiche_produit").html(msg);
            }
        });
        
        jQuery('#attribut_parent').css('border-bottom','none');

}

function select_parent_color_bycouleur(idprod,offre_cadeau_id,qteoffert){

        jQuery.ajax({
            type: "POST",
            url: "/js/ajax/produit/produit_couleur.php",
            data: "produit_id="+idprod+"&offre_cadeau_id="+offre_cadeau_id+"&qteoffert="+qteoffert+"&selectbycolor=1",
            success: function(msg){
                jQuery("#gauche_fiche_produit").html(msg);
            }
        });
        
        jQuery('#attribut_parent').css('border-bottom','none');

}

function select_parent_color_byref(idprod,offre_cadeau_id,qteoffert){

        jQuery.ajax({
            type: "POST",
            url: "/js/ajax/produit/produit_couleur.php",
            data: "produit_id="+idprod+"&offre_cadeau_id="+offre_cadeau_id+"&qteoffert="+qteoffert+"&selectbyref=1",
            success: function(msg){
                jQuery("#gauche_fiche_produit").html(msg);
            }
        });
        
        jQuery('#attribut_parent').css('border-bottom','none');

}

function calcul_produit_taille(){

        jQuery.ajax({
            type: "POST",
            url: "/js/ajax/produit/produit_taille.php",
            data: jQuery("#select_quantite_att").serialize(),
            success: function(msg){
                jQuery("#gauche_fiche_produit").html(msg);
            }
        });

}

function calcul_produit_multi_by_couleur(){

        jQuery.ajax({
            type: "POST",
            url: "/js/ajax/produit/produit_multi_by_couleur.php",
            data: jQuery("#select_taille_couleur").serialize(),
            success: function(msg){
                jQuery("#content_ajax").html(msg);
            }
        });
        
        jQuery("#seltail1").removeClass('noactive');

}

function select_parent_color(){

        jQuery.ajax({
            type: "POST",
            url: "/js/ajax/produit/produit_multi_parent_color.php",
            data: jQuery("#select_parent_couleur").serialize(),
            success: function(msg){
                jQuery("#content_color").html(msg);
            }
        });
        
        jQuery("#attribut_parent").css('border-bottom','none');

}

function select_quantite_color(){

        jQuery.ajax({
            type: "POST",
            url: "/js/ajax/produit/produit_multi_quantite_color.php",
            data: jQuery("#select_quantite_couleur").serialize(),
            success: function(msg){
                jQuery("#content_color").html(msg);
            }
        });


}




function calcul_produit_multi_by_ref(){

        jQuery.ajax({
            type: "POST",
            url: "/js/ajax/produit/produit_multi_by_ref.php",
            data: jQuery("#select_taille_ref").serialize(),
            success: function(msg){
                jQuery("#content_ajax").html(msg);
            }
        });
        
        jQuery("#seltail2").removeClass('noactive');

}

function calcul_produit_multi_by_ref_with_ref(){

        jQuery.ajax({
            type: "POST",
            url: "/js/ajax/produit/produit_multi_by_ref.php",
            data: jQuery("#fromnewref").serialize(),
            success: function(msg){
                jQuery("#content_ajax").html(msg);
            }
        });
        
        jQuery("#seltail2").removeClass('noactive');

}

function selectcouleurperso(idprod,idatt){

        jQuery.ajax({
            type: "POST",
            url: "/js/ajax/produit/selectcouleurperso.php",
            data: "produit_id="+idprod+"&produit_attribut_id="+idatt,
            success: function(msg){
                jQuery("#bigimgperso").attr('src',msg);
                jQuery("#produit_attribut_id").attr('value',idatt);
                calcul_produit_perso();
            }
        });
        

}

function changemotif(idprod,idcat,idcoul){

        jQuery.ajax({
            type: "POST",
            url: "/js/ajax/produit/changemotif.php",
            data: "produit_id="+idprod+"&motifcategorie_id="+idcat+"&motifcouleur_id="+idcoul,
            success: function(msg){
            		jQuery("#contentmotif").html(msg);
            		jQuery("#carousselmotif").easySlider({
				            auto: false,
				            speed: 0,
				            nbDiv: 4,
				            prevId: 'precmvcar',
				            prevText: '<img src="/styles/images/index/precmv.jpg" class="png img_nav" width="13" height="22" />',
				            nextId: 'suivmvcar',
				            nextText: '<img src="/styles/images/index/suivmv.jpg" class="png img_nav" width="13" height="22" />',
				            continuous: true
				        });
				        changeimagemotif(idprod,idcat,idcoul);
            }
        });
}

function changeimagemotif(idprod,idcat,idcoul){
	jQuery.ajax({
		type: "POST",
		url: "/js/ajax/produit/changeimagemotif.php",
		data: "produit_id="+idprod+"&motifcategorie_id="+idcat+"&motifcouleur_id="+idcoul,
		success: function(msg){
			var tab = msg.split('|');
			motifselect(tab[0],tab[1],tab[2]);
			jQuery("#motif_couleur_id").attr('value',tab[3]);
			jQuery("#motif_couleur_nom").attr('value',tab[4]);
			jQuery("#motif_categorie_id").attr('value',tab[5]);
			jQuery("#motif_categorie_nom").attr('value',tab[6]);
			calcul_produit_perso();
		}
	});
}

function changeimagemotif2(idprod){
	jQuery.ajax({
		type: "POST",
		url: "/js/ajax/produit/changeimagemotif2.php",
		data: "produit_id="+idprod,
		success: function(msg){
			var tab = msg.split('|');
			motifselect(tab[0],tab[1],tab[2]);
			jQuery("#motif_couleur_id").attr('value',tab[3]);
			jQuery("#motif_couleur_nom").attr('value',tab[4]);
			jQuery("#motif_categorie_id").attr('value',tab[5]);
			jQuery("#motif_categorie_nom").attr('value',tab[6]);
			calcul_produit_perso();
		}
	});
}

function ongletmotif(idprod){
	jQuery("#image_perso").attr('value','');
	jQuery("#image_perso_name").attr('value','');
	jQuery.ajax({
		type: "POST",
		url: "/js/ajax/produit/ongletmotif.php",
		data: "produit_id="+idprod,
		success: function(msg){
			jQuery("#contentmotif").html(msg);
			jQuery("#carousselmotif").easySlider({
				auto: false,
				speed: 0,
				nbDiv: 4,
				prevId: 'precmvcar',
				prevText: '<img src="/styles/images/index/precmv.jpg" class="png img_nav" width="13" height="22" />',
				nextId: 'suivmvcar',
				nextText: '<img src="/styles/images/index/suivmv.jpg" class="png img_nav" width="13" height="22" />',
				continuous: true
			});
			changeimagemotif2(idprod);
		}
	});
}

function ongletimage(idprod){
	jQuery("#motif_couleur_id").attr('value','');
	jQuery("#motif_couleur_nom").attr('value','');
	jQuery("#motif_categorie_id").attr('value','');
	jQuery("#motif_categorie_nom").attr('value','');
	jQuery("#motif_id").attr('value','');
	jQuery("#motif_nom").attr('value','');
	jQuery("#motif_image").attr('value','');
	jQuery("#imgemplacementmotif").attr('src','/styles/images/fiche_produit/tmp.png');
	jQuery.ajax({
		type: "POST",
		url: "/js/ajax/produit/ongletimage.php",
		data: "produit_id="+idprod,
		success: function(msg){
			jQuery("#contentmotif").html(msg);
		}
	});
}

function motifselect(idmotif,imgmotif,motifnom){
	
	jQuery(".amotif").removeClass('motifselected');
	jQuery("#imgemplacementmotif").attr('src',imgmotif);
	jQuery("#idmotif"+idmotif).addClass('motifselected');
	jQuery("#motif_id").attr('value',idmotif);
	jQuery("#motif_nom").attr('value',motifnom);
	jQuery("#motif_image").attr('value',imgmotif);
	calcul_produit_perso();
}

function nuancier(idForm){
	
	jQuery("body").popup({
		popup:{
			removeOnClick:{
				0:'#close'
			},
			css:{
				'width':'580px'
			}
		},
		ajax:'/js/ajax/nuancier.php',
		data:jQuery("#"+idForm).serialize()
	});
	
}

function selectColor(idcolor){
    jQuery(".imgunatt").css('border', '1px solid #C9C9C9');
    jQuery(".unatt").css('background', '#ffffff');
    jQuery("#imgunatt"+idcolor).css('border', 'red 1px solid');
    jQuery("#unatt"+idcolor).css('background', '#C9C9C9');
}

function displaynews(){
    jQuery(".tbi").removeClass('title_bloc_index');
    jQuery(".tbi").addClass('title_bloc_index2');
    jQuery("#news").removeClass('title_bloc_index2');
    jQuery("#news").addClass('title_bloc_index');
    jQuery(".cbi").css('display', 'none');
    jQuery("#bnews").css('display', 'block');
    
}

function displaymv(){
    jQuery(".tbi").removeClass('title_bloc_index');
    jQuery(".tbi").addClass('title_bloc_index2');
    jQuery("#tmv").removeClass('title_bloc_index2');
    jQuery("#tmv").addClass('title_bloc_index');
    jQuery(".cbi").css('display', 'none');
    jQuery("#meilventes").css('display', 'block');
    
}

function displayba(){
    jQuery(".tbi").removeClass('title_bloc_index');
    jQuery(".tbi").addClass('title_bloc_index2');
    jQuery("#tba").removeClass('title_bloc_index2');
    jQuery("#tba").addClass('title_bloc_index');
    jQuery(".cbi").css('display', 'none');
    jQuery("#ba").css('display', 'block');
}

function checkImgPerso(){
	jQuery("#imgemplacementmotif").attr('src','/styles/images/loadinfo.gif');
	
	var contenu = "";
	if(navigator.appName=="Microsoft Internet Explorer")
		contenu = document.frames["iframePhoto"].document.body.innerHTML;
	else
		contenu =document.getElementById('iframePhoto').contentDocument.body.innerHTML;
	
	if(contenu == "") {
		setTimeout("checkImgPerso()",1000);
	} else
	{
		/*if(contenu.indexOf("err")==-1)
		{
			persoUpdateImage(contenu);
		} else {
			setTimeout("checkImgPerso()",1000);
		}*/
		persoUpdateImage(contenu);
		
	}
}

function persoUpdateImage(img)
{
	jQuery.ajax({
		type: "POST",
		url: "/js/ajax/produit/uploadimageperso.php",
		data: jQuery("#uploadimage").serialize(),
		success: function(msg){
			modifimageperso();
		}
	});
}

function modifimageperso() {
	jQuery.ajax({
		type: "POST",
		url: "/js/ajax/produit/modifimageperso.php",
		data: 'produit_id='+jQuery("#produit_id").attr('value'),
		success: function(msg){
			if(msg != "") 
			{
				if(msg == "err_ext") {
					jQuery("#imgemplacementmotif").attr('src','/styles/images/fiche_produit/tmp.png');
					jQuery("#errupload").html('Votre image ne pas d\'extension correct');
				} else if(msg == "err_taille") {
					jQuery("#imgemplacementmotif").attr('src','/styles/images/fiche_produit/tmp.png');
					jQuery("#errupload").html('Votre image doit avoir un taille minimum de 600X600 pixels');
				} else if(msg == "err_poid") {
					jQuery("#imgemplacementmotif").attr('src','/styles/images/fiche_produit/tmp.png');
					jQuery("#errupload").html('Votre image doit avoir un poid minimum de 200Ko');
				} else {
					var tab = msg.split('|');
					jQuery("#imgemplacementmotif").attr('src',tab[0]);
					jQuery("#image_perso").attr('value',tab[1]);
					jQuery("#image_perso_name").attr('value',tab[2]);
					jQuery("#errupload").html('');
					calcul_produit_perso();
				}
			}
		}
	});
}

function modiftext(newtexte) {
	var nbbr = false;

	while (newtexte.search("\n") != -1) {
		if(!nbbr) {
			newtexte = newtexte.replace("\n","<br />");
		} else {
			newtexte = newtexte.replace("\n"," ");
		}
		nbbr = true;
	}
	
	jQuery('#textepersodynamique').html(newtexte);
	jQuery('#texte_texte').attr('value',newtexte);
	calcul_produit_perso();
}

function maxlength(newtexte,length) {
	if(newtexte.value.length>length) {
		newtexte.value=newtexte.value.substr(0,length); 
	
	}
}

