
$(function(){

	if($(".submitbutton").length>0){
		$(".submitbutton").each(function(){
			$(this).hover(
				function(){
					$(this).css({"background-color":""});
					$(this).css({"color":""});
					$(this).removeClass().addClass("formbutton submitbutton hover");
				},
				function(){
					$(this).css({"background-color":""});
					$(this).css({"color":""});
					$(this).removeClass().addClass("formbutton submitbutton");
				}				
			);
		});
	}
	if($(".resetbutton").length>0){
		$(".resetbutton").each(function(){
			$(this).hover(
				function(){
					$(this).css({"background-color":""});
					$(this).css({"color":""});
					$(this).removeClass().addClass("formbutton resetbutton hover");
				},
				function(){
					$(this).css({"background-color":""});
					$(this).css({"color":""});
					$(this).removeClass().addClass("formbutton resetbutton");
				}				
			);
		});
	}
	if($(".navformbutton").length>0){
		$(".navformbutton").not(".selectedbutton").each(function(){
			$(this).hover(
				function(){
					$(this).css({"background-color":""});
					$(this).css({"color":""});
					$(this).removeClass().addClass("formbutton navformbutton hover");
				},
				function(){
					$(this).css({"background-color":""});
					$(this).css({"color":""});
					$(this).removeClass().addClass("formbutton navformbutton");
				}				
			);
		});
	}
	
	/*if($(".link a table").length>0){
		$(".link a table").each(function(){
			$(this).hover(
				function(){
					$(this).removeClass().addClass("hover");
				},
				function(){
					$(this).removeClass().addClass("");
				}				
			);
		});
	}*/
	if($(".link table").length>0){
		$(".link table").each(function(){
			$(this).hover(
				function(){
					$(this).removeClass().addClass("hover");
				},
				function(){
					$(this).removeClass().addClass("");
				}				
			);
		});
	}
	
	if($(".catalog_list_products .items tr .thumb_catalog").length>0){
		$(".catalog_list_products .items tr .thumb_catalog").each(function(){
			
			$(this).hover(
				function(){
					if($(this).attr("class") == 'thumb thumb_catalog left'){
						$(this).removeClass().addClass("thumb thumb_catalog left hover");
						$(this).next().removeClass().addClass("thumb thumb_catalog right hover");
					}
					if($(this).attr("class") == 'thumb thumb_catalog right'){
						$(this).removeClass().addClass("thumb thumb_catalog right hover");
						$(this).prev().removeClass().addClass("thumb thumb_catalog left hover");
					}
				},
				function(){
					if($(this).attr("class") == 'thumb thumb_catalog left hover'){
						$(this).removeClass().addClass("thumb thumb_catalog left");
						$(this).next().removeClass().addClass("thumb thumb_catalog right ");
					}
					if($(this).attr("class") == 'thumb thumb_catalog right hover'){
						$(this).removeClass().addClass("thumb thumb_catalog right");
						$(this).prev().removeClass().addClass("thumb thumb_catalog left ");
					}
				}				
			);
		});
	}
	
	
	

	

  	
  	
  
  
	
	
	function getInitPosition(largeur_popin){
		var posx = ( window.document.body.offsetWidth - largeur_popin) / 2;
		//alert('largeur popin : ' + largeur_popin + ' largeur fenetre : ' + window.document.body.offsetWidth + ' position x : ' +  posx);
		/*if(document.all){
			alert('position x : ' +  posx = posx / 2);
		}*/
		return posx+'px';
	}
	
	if($(".product_infos_zooms .close").length>0){
		$(".product_infos_zooms .close span").each(function(){
			$(this).click(function(){
				$(".product_infos_zooms").hide();
			});
		});
	}
	
	if($(".vignet_1").length>0){
		$(".vignet_1").each(function(){
			$(this).click(function(){
				$(".product_infos_zooms_wrapper .zoom_1").show();
				$(".product_infos_zooms_wrapper .zoom_2").hide();
				$(".product_infos_zooms_wrapper .zoom_3").hide();
				$(".product_infos_zooms").show();
				//alert($(".product_infos_zooms_wrapper .zoom_1").width());
				var x = getInitPosition($(".product_infos_zooms_wrapper .zoom_1").width());
				$(".product_infos_zooms").attr("style","left:"+x);
				$(".product_infos_zooms").show();
			},function(){});
		});
	}
	if($(".vignet_2").length>0){
		$(".vignet_2").each(function(){
			$(this).click(function(){
				$(".product_infos_zooms_wrapper .zoom_1").hide();
				$(".product_infos_zooms_wrapper .zoom_2").show();
				$(".product_infos_zooms_wrapper .zoom_3").hide();
				$(".product_infos_zooms").show();
				//alert($(".product_infos_zooms_wrapper .zoom_2").width());
				var x = getInitPosition($(".product_infos_zooms_wrapper .zoom_2").width());
				$(".product_infos_zooms").attr("style","left:"+x);
				$(".product_infos_zooms").show();
			},function(){});
		});
	}
	if($(".vignet_3").length>0){
		$(".vignet_3").each(function(){
			$(this).click(function(){
				$(".product_infos_zooms_wrapper .zoom_1").hide();
				$(".product_infos_zooms_wrapper .zoom_2").hide();
				$(".product_infos_zooms_wrapper .zoom_3").show();
				$(".product_infos_zooms").show();
				//alert($(".product_infos_zooms_wrapper .zoom_3").width());
				var x = getInitPosition($(".product_infos_zooms_wrapper .zoom_3").width());
				$(".product_infos_zooms").attr("style","left:"+x);
				$(".product_infos_zooms").show();
			},function(){});
		});
	}
	
	if($(".picto_print").length>0){
		$(".picto_print").click(function(){
		    $(".column_2").printArea({mode: "popup"});
		});
	}
	
	if($(".search_queryfield").length>0){
		$(".search_queryfield").click(function(){
		    $(this).val("");
		});
	}
	
	if($("table#attach_quicksearch tbody tr").length>0){
		var qs = $("table#attach_quicksearch tbody tr").quicksearch({
	  		position: "before",
	  		attached: "table#attach_quicksearch",
	  		stripeRowClass: ['odd', 'even'],
	  		labelText: "Recherche",
			inputText: "",
			loaderText: "Merci de patienter...",
	  		delay: 100
		});
		qs.reset_cache();
	}
	
	//Direct access produits : champs dynamiques dependants
	//--------------------------------------------------------
	if($(".directaccess_products_form").length>0){
		$(".directaccess_products_form").each(function(){
			var form = $(this);
			$(this).children(".without_js").hide();
			$(this).children(".with_js").show();
		});
	}
	//Direct access produits : disabled
	//-----------------------------------------------
	if($(".directaccess_products_form").length>0){
		$(".directaccess_products_form").each(function(){
			var form = $(this);
			$(this).children(".with_js").children().children(".queryfield_sousfamille").attr("disabled","disabled");
			$(this).children(".with_js").children().children(".queryfield_famille").each(function(){
				if($(this).val()!=null && $(this).val()!=''){
					form.children(".with_js").children().children(".queryfield_sousfamille").removeAttr("disabled");
				}else{
					form.children(".with_js").children().children(".queryfield_sousfamille").attr("disabled","disabled");
				}
				$(this).change(function(){	
					if($(this).val()!=null && $(this).val()!=''){
						form.children(".with_js").children().children(".queryfield_sousfamille").removeAttr("disabled");
					}else{
						form.children(".with_js").children().children(".queryfield_sousfamille").attr("disabled","disabled");
					}
				});
			});
		});
	}
	
	
	
	
});

$(document).ready(function() {
	$('input[name="InputField-24"]').parent().parent().hide();
	$('input[name="InputField-25"]').parent().parent().hide();
	$('input[name="InputField-26"]').parent().parent().hide();
	
    $('form.hasPopinHidden').submit(function(e) {
    	if($('input[name="InputField-24"]').parent().parent().css('display') == 'none'){
    		$('input[name="InputField-24"]').parent().parent().show();
    		$('input[name="InputField-25"]').parent().parent().show();
    		$('input[name="InputField-26"]').parent().parent().show();
    		return false;
    	}else{
    		return true;
    	}
    });
});

function actionOnchangeFamille(form,label, mytab){
			//return;
			//alert('changement sous-familles...');
			form.sousfamille.options.length=0;
			var o = new Option(label, '');
		    form.sousfamille.options[form.sousfamille.options.length] = o;
			//alert('changement sous-familles: remise à zero OK');
			var selectedvalue = '';
			if(form.famille.selectedIndex!=null && form.famille.selectedIndex>0){
				selectedvalue = form.famille.options[form.famille.selectedIndex].value;
			}
			//alert('changement sous-familles: selectedvalue = ' + selectedvalue);
			var tab2 = mytab.split('][');
			var lignes = new Array();
			for(j=0; j< tab2.length; j++){
				var tab3 = tab2[j].replace('[','').replace(']','').split(',');
				var ligne = new Array();
				for(k=0; k< tab3.length; k++){
					ligne.push(tab3[k]);
				}
				lignes.push(ligne);
			}
			for(i=0; i<lignes.length; i++){
				var ligne = lignes[i];
				if(ligne[0]==selectedvalue){
					var o = new Option(ligne[2],ligne[1]);
		    		form.sousfamille.options[form.sousfamille.options.length] = o;
				}
			}
			//alert('changement sous-familles... OK');
			//alert($(".queryfield_famille").html());
		}
