function ativaOptionsDisabled(){
	    var sels = document.getElementsByTagName('select');
	    for(var i=0; i < sels.length; i++){
	        sels[i].onchange= function(){
	            if(this.options[this.selectedIndex].disabled){
	                if(this.options.length<=1){
	                    this.selectedIndex = -1;
	                }else if(this.selectedIndex < this.options.length - 1){
							  this.selectedIndex++;
							  if(this.options[this.selectedIndex].disabled){
							  		this.selectedIndex++;
							  }
	                }else{
	                    this.selectedIndex--;
							  if(this.options[this.selectedIndex].disabled){
							  		this.selectedIndex--;
							  }
	                }
	            }
	        }
	        if(sels[i].options[sels[i].selectedIndex].disabled){
	            sels[i].onchange();
	        }
	        for(var j=0; j < sels[i].options.length; j++){ //colocando o estilo
	            if(sels[i].options[j].disabled){
	                sels[i].options[j].style.color = '#CCC';
	            }
	        }
	    }
	}

function resetResult(){
	$("showResults").hide();
    $("loadingRadioCheck").hide();
	Element.update($('ResultCountTxt'), '&nbsp;0 '+$('nbProducts').value);	

}

function setResultTo(count){
	if( count>0 && !isNaN(count) ){ 
		if( count>1 ) Element.update($('ResultCountTxt'), count+' '+$('nbProducts').value);
		else Element.update($('ResultCountTxt'), count+' '+$('nbProduct').value);
        
        $('loadingRadioCheck').hide();
        $('ResultCountTxt').show();
		$("showResults").show();
	}else resetResult();
}


function finalDefaultChecked(field1,field2,field3,cpt1,cpt2,cpt3){

    if((cpt1 == 0 && cpt2 == 0)){
        $(field1).previousSiblings()[0].show();
        $(field2).previousSiblings()[0].show();
        $(field3).checked = true;
        
		$(field1).ancestors()[1].descendants()[0].addClassName("off");
        $(field1).ancestors()[1].descendants()[0].hide();                    
        myParent = $(field1).ancestors()[1];
	    myParent.descendants().each(function(elmt2,i){
	        if(elmt2.className == "clearButton"){
		        elmt2.show();
		    }
		});
        
        $(field2).ancestors()[1].descendants()[0].addClassName("off");
        $(field2).ancestors()[1].descendants()[0].hide();                    
        myParent = $(field2).ancestors()[1];
	    myParent.descendants().each(function(elmt2,i){
	        if(elmt2.className == "clearButton"){
		        elmt2.show();
		    }
		});
    }
    
    if((cpt1 == 0 && cpt3 == 0)){
        $(field1).previousSiblings()[0].show();
        $(field3).previousSiblings()[0].show();
        $(field2).checked = true;
        
		$(field1).ancestors()[1].descendants()[0].addClassName("off");
        $(field1).ancestors()[1].descendants()[0].hide();                    
        myParent = $(field1).ancestors()[1];
	    myParent.descendants().each(function(elmt2,i){
	        if(elmt2.className == "clearButton"){
		        elmt2.show();
		    }
		});
        
        $(field3).ancestors()[1].descendants()[0].addClassName("off");
        $(field3).ancestors()[1].descendants()[0].hide();                    
        myParent = $(field3).ancestors()[1];
	    myParent.descendants().each(function(elmt2,i){
	        if(elmt2.className == "clearButton"){
		        elmt2.show();
		    }
		});
    }
    
   if((cpt2 == 0 && cpt3 == 0)){
        $(field2).previousSiblings()[0].show();
        $(field3).previousSiblings()[0].show();
        $(field1).checked = true;
        
		$(field2).ancestors()[1].descendants()[0].addClassName("off");
        $(field2).ancestors()[1].descendants()[0].hide();                    
        myParent = $(field1).ancestors()[1];
	    myParent.descendants().each(function(elmt2,i){
	        if(elmt2.className == "clearButton"){
		        elmt2.show();
		    }
		});
        
        $(field3).ancestors()[1].descendants()[0].addClassName("off");
        $(field3).ancestors()[1].descendants()[0].hide();                    
        myParent = $(field3).ancestors()[1];
	    myParent.descendants().each(function(elmt2,i){
	        if(elmt2.className == "clearButton"){
		        elmt2.show();
		    }
		});
    }  
    
}

/**********************BAGAGES*********************************/
function isEnoughtDataBG(color){

	$('ResultCountTxt').hide();
    
    if ($$("#selecteurForm .off").length == 0) {
           //reset des couleurs quand aucun crit�re selectionn� 
          $$('.colors button').each(function(color, i){
                color.previousSiblings()[0].hide();
          });
          
          //reset de tous les champs quand aucun crit�res selectionn�s
          
          $$('.masque3').each(function(masque, i){
                masque.hide();
          });
          
          
    }

    //controle champs cas uniquement peu importe selectionn�

	/*var roulette = "";
	var volume = "";
	var emplacement = "";
	var usage = "";
	var taille = "";
	var prix = "";
	var matiere = "";
    var bagtest = "";

	if( $('bgtype1').checked ) 	bagtest	= $('bgtype1').value;
	if( $('bgtype2').checked ) 	bagtest 	= $('bgtype2').value;
		
	if( $('roue1').checked )		roulette= $('roue1').value;
	if( $('roue2').checked )		roulette= $('roue2').value;
	if( $('roue3').checked )		roulette= $('roue3').value;		
	
	if( $('more1').checked )		volume 	= $('more1').value;
	if( $('more2').checked )		volume 	= $('more2').value;
	if( $('more3').checked )		volume 	= $('more3').value;		

	if( $('habi1').checked )		emplacement	= $('habi1').value;		
	if( $('habi2').checked )		emplacement	= $('habi2').value;	
	if( $('habi3').checked )		emplacement	= $('habi3').value;			
	
	if( $('loisirs').checked )	usage 	= $('loisirs').value;		
	if( $('business').checked )	usage 	= $('business').value;	
	
	if( $('petit').checked ) 	taille 	= $('petit').value;
	if( $('moyen').checked ) 	taille 	= $('moyen').value;
	if( $('grand').checked ) 	taille 	= $('grand').value;

	if( $('prix1').checked ) 	prix 	= $('prix1').value;
	if( $('prix2').checked ) 	prix 	= $('prix2').value;
	if( $('prix3').checked ) 	prix 	= $('prix3').value;
	
	if( $('cuir').checked )		matiere = $('cuir').value;		
	if( $('toile').checked )		matiere = $('toile').value;	

  
	if(bagtest== "" && roulette == "" && volume == "" && emplacement == "" && usage == "" && taille == "" && prix == "" && matiere == "")
	{
		return false;
	}	*/	

	if(color == 1)
	{
		$("showResults").hide();
        return true;
	 }

	if($$("#selecteurForm .off").length == 1)
	{
		$("showResults").hide();
        return true;
	 }
	 
	var cpt = 0;

	if($$("#selecteurForm .off").length >= 2) cpt=2;
	 
	 
	if(cpt < 2){
		$("showResults").hide();
		return false;
	}	 
	
	if(cpt == 2)
	{
	 	return true;
	 }
}

function getResultCountBG(color){
	var type 	= '';
	var usage	= '';
	var taille	= '';
	var prix	= '';
	var matiere	= '';
	
	var roulette= '';		
	var volume	= '';		
	var emplacement	= '';		
	
	if( $('bgtype1').checked ) 	type 	= $('bgtype1').value;
	if( $('bgtype2').checked ) 	type 	= $('bgtype2').value;	
		
	if( $('roue1').checked )		roulette= $('roue1').value;
	if( $('roue2').checked )		roulette= $('roue2').value;
	if( $('roue3').checked )		roulette= $('roue3').value;		
	
	if( $('more1').checked )		volume 	= $('more1').value;
	if( $('more2').checked )		volume 	= $('more2').value;
	if( $('more3').checked )		volume 	= $('more3').value;		

	if( $('habi1').checked )		emplacement	= $('habi1').value;		
	if( $('habi2').checked )		emplacement	= $('habi2').value;	
	if( $('habi3').checked )		emplacement	= $('habi3').value;			
	
	if( $('loisirs').checked )	usage 	= $('loisirs').value;		
	if( $('business').checked )	usage 	= $('business').value;	
	
	if( $('petit').checked ) 	taille 	= $('petit').value;
	if( $('moyen').checked ) 	taille 	= $('moyen').value;
	if( $('grand').checked ) 	taille 	= $('grand').value;

	if( $('prix1').checked ) 	prix 	= $('prix1').value;
	if( $('prix2').checked ) 	prix 	= $('prix2').value;
	if( $('prix3').checked ) 	prix 	= $('prix3').value;
	
	if( $('cuir').checked )		matiere = $('cuir').value;		
	if( $('toile').checked )		matiere = $('toile').value;	
			
	genre = $('genre').value;
	rubrique = $('rub_id').value;
	
	var url = '/FRONT/LONGCHAMP/include/SearchAjax.php';	
	
	new Ajax.Request(url, {
		method: 'post',
	  	parameters: { 
	  		bgtype: type,
	  		roue: roulette,
	  		more: volume,
	  		habi: emplacement,
	  		smlx: taille,
	  		echl: prix,
	  		look: usage,
	  		color: $F('color'),
	  		mmix: matiere,
	  		genre: genre,
	  		rubrique: rubrique,
	  		attributsId: $('attributsId').value,
            vel: $('vel').value
	  	},
		onSuccess: function(msg) {
			var myResult = msg.responseText.evalJSON();	
		
		//reinitialisation des boutons
			$('bgtype1').previousSiblings()[0].hide();
			$('bgtype2').previousSiblings()[0].hide();	
		
			$('roue1').disabled= false;
			$('roue2').disabled= false;
			$('roue3').disabled= false;		
	
			$('more1').disabled= false;
			$('more2').disabled= false;
			$('more3').disabled= false;		

			$('habi1').disabled= false;		
			$('habi2').disabled= false;	
			$('habi3').disabled= false;	
			
			$('loisirs').previousSiblings()[0].hide();
			$('business').previousSiblings()[0].hide();
			
			$('petit').previousSiblings()[3].hide();	
			$('moyen').previousSiblings()[2].hide();
			$('grand').previousSiblings()[2].hide();	
				
			$('prix1').previousSiblings()[0].hide();
			$('prix2').previousSiblings()[0].hide();
			$('prix3').previousSiblings()[0].hide();
				

				
				$('cuir').previousSiblings()[0].hide();
				$('toile').previousSiblings()[0].hide();
				 if (!color) {
                     $$('.colors button').each(function(color, i){
                         color.previousSiblings()[0].hide();
                     });
                 }	
				var cptbgtype1 = 0;					
				var cptbgtype2 = 0;	
				
				var cptroue1 = 0;					
				var cptroue2 = 0;	
				var cptroue3 = 0;	
				
				var cptmore1 = 0;					
				var cptmore2 = 0;	
				var cptmore3 = 0;	
			
				var cpthabi1 = 0;					
				var cpthabi2 = 0;	
				var cpthabi3 = 0;					
				
				var cptloisirs = 0;
				var cptbusiness = 0;
				
				var cptpetit = 0;	
				var cptmoyen = 0;	
				var cptgrand = 0;	
				
				var cptprix1 = 0;	
				var cptprix2 = 0;	
				var cptprix3 = 0;

				var cptcuir = 0;
				var cpttoile = 0;
					
				var cptcolors = new Array(13);
				//loop over article attributs
				myResult.attributs.each(function(elmt,e) { 
					
					if( $('bgtype1').value ==  elmt ) 	cptbgtype1++;
					if( $('bgtype2').value ==  elmt ) cptbgtype2++;
	
					if( $('roue1').value ==  elmt ) 	cptroue1++;
					if( $('roue2').value ==  elmt ) 	cptroue2++;
					//if( $('roue3').value ==  elmt ) 	cptroue3++;
	
					if( $('more1').value ==  elmt ) 	cptmore1++;
					if( $('more2').value ==  elmt ) 	cptmore2++;
				//	if( $('more3').value ==  elmt ) 	cptmore3++;
					
					if( $('habi1').value ==  elmt ) 	cpthabi1++;
					if( $('habi2').value ==  elmt ) 	cpthabi2++;
					//if( $('habi3').value ==  elmt ) 	cpthabi3++;
	
					if( $('loisirs').value ==  elmt ) 	cptloisirs++;
					if( $('business').value ==  elmt ) 	cptbusiness++;
	
					if( $('petit').value ==  elmt ) 	cptpetit++;
					if( $('moyen').value ==  elmt ) 	cptmoyen++;
					if( $('grand').value ==  elmt ) 	cptgrand++;
	
					if( $('prix1').value ==  elmt) 	cptprix1++;
					if( $('prix2').value ==  elmt) 	cptprix2++;
					if( $('prix3').value ==  elmt)	cptprix3++;
	
					if( $('loisirs').value ==  elmt)		cptloisirs++;	
					if( $('business').value ==  elmt )	cptbusiness++;	
		
					if( $('cuir').value ==  elmt)		cptcuir++;	
					if( $('toile').value ==  elmt)		cpttoile++;	

                     if (!color) {
                         $$('.colors button').each(function(color, i){
                             tab_color = color.id.split('_');
                             if (parseInt(tab_color[1], 10) == elmt) {
                                 cptcolors[i] = 1;
                             }
                         });
                     }	
				});
			
				
				if(cptbgtype1 == 0) $('bgtype1').previousSiblings()[0].show();
				if(cptbgtype2 == 0) $('bgtype2').previousSiblings()[0].show();
				
				if(cptroue1 == 0 || $('roue3').checked) $('roue1').disabled= true;
				if(cptroue2 == 0 || $('roue3').checked) $('roue2').disabled= true;
				if(cptroue1 > 0 || cptroue2 > 0) $('roue3').disabled= true;
                if(cptroue1 > 0 && cptroue2 > 0) $('roue3').disabled= false;
				
				if(cptmore1 == 0 || $('more3').checked) $('more1').disabled= true;
				if(cptmore2 == 0 || $('more3').checked) $('more2').disabled= true;
				if(cptmore1 > 0 || cptmore2 > 0) $('more3').disabled= true;
				if(cptmore1 > 0 && cptmore2 > 0) $('more3').disabled= false;
                
				if(cpthabi1 == 0 || $('habi3').checked) $('habi1').disabled= true;
				if(cpthabi2 == 0 || $('habi3').checked) $('habi2').disabled= true;
				if(cpthabi1 > 0 || cpthabi2 > 0) $('habi3').disabled= true;
                if(cpthabi1 > 0 && cpthabi2 > 0) $('habi3').disabled= false;
				
				if(cptpetit == 0) $('petit').previousSiblings()[3].show();
				if(cptmoyen == 0) $('moyen').previousSiblings()[2].show();
				if(cptgrand == 0) $('grand').previousSiblings()[2].show();
								
				if(cptprix1 == 0) $('prix1').previousSiblings()[0].show();
				if(cptprix2  == 0) $('prix2').previousSiblings()[0].show();
				if(cptprix3  == 0) $('prix3').previousSiblings()[0].show();

                if (cptloisirs == 0 && cptbusiness != 0) {
                    $('loisirs').previousSiblings()[0].show();
                    $('business').checked = true;
					$('loisirs').ancestors()[1].descendants()[0].addClassName("off");
                    $('loisirs').ancestors()[1].descendants()[0].hide();
                    myParent = $('loisirs').ancestors()[1];
			        myParent.descendants().each(function(elmt2,i){
				        if(elmt2.className == "clearButton"){
					        elmt2.show();
				        }
			        });
                    
                }    
				if (cptbusiness == 0 && cptloisirs != 0) {
                    $('business').previousSiblings()[0].show();
                    $('loisirs').checked = true;
					$('business').ancestors()[1].descendants()[0].addClassName("off");
                    $('business').ancestors()[1].descendants()[0].hide();                    
                    myParent = $('business').ancestors()[1];
			        myParent.descendants().each(function(elmt2,i){
				        if(elmt2.className == "clearButton"){
					        elmt2.show();
				        }
			        });
                }
                
                /*
                if(cptloisirs  == 0) $('loisirs').previousSiblings()[0].show();
				if(cptbusiness  == 0) $('business').previousSiblings()[0].show();
				*/				
				if (cptcuir == 0 && cpttoile != 0) {
                    $('cuir').previousSiblings()[0].show();
                    $('toile').checked = true;
					$('cuir').ancestors()[1].descendants()[0].addClassName("off");
                    $('cuir').ancestors()[1].descendants()[0].hide();
                    myParent = $('cuir').ancestors()[1];
			        myParent.descendants().each(function(elmt2,i){
				        if(elmt2.className == "clearButton"){
					        elmt2.show();
				        }
			        });
                    
                }    
				if (cpttoile == 0 && cptcuir != 0) {
                    $('toile').previousSiblings()[0].show();
                    $('cuir').checked = true;
					$('toile').ancestors()[1].descendants()[0].addClassName("off");
                    $('toile').ancestors()[1].descendants()[0].hide();                    
                    myParent = $('toile').ancestors()[1];
			        myParent.descendants().each(function(elmt2,i){
				        if(elmt2.className == "clearButton"){
					        elmt2.show();
				        }
			        });
                }    
				 if (!color) {
                     $$('.colors button').each(function(color, i){
                         if (cptcolors[i] == 1) {
                             color.previousSiblings()[0].hide();
                         }
                         else {
                             color.previousSiblings()[0].show();
                         }
                     });
                 }
            
				if($$("#selecteurForm .off").length == 1)
				{
                    $('ResultCountTxt').hide();
                    
					resetResult();
				}
				else
				{
					setResultTo(myResult.total)	;
				}
				$('loadingRadioCheck').hide();
		}
		,
	  	onLoading : function(xhr){
            
           
	  		/*if($$("#selecteurForm .off").length > 1)
			{*/
                $('loadingRadioCheck').show();
	  			$('ResultCountTxt').hide();
                
	  		/*}*/
	  		$('bgtype1').previousSiblings()[0].show();
			$('bgtype2').previousSiblings()[0].show();	
		
			$('roue1').disabled= true;
			$('roue2').disabled= true;
			$('roue3').disabled= true;		
	
			$('more1').disabled= true;
			$('more2').disabled= true;
			$('more3').disabled= true;		

			$('habi1').disabled= true;		
			$('habi2').disabled= true;	
			$('habi3').disabled= true;	
			
			$('loisirs').previousSiblings()[0].show();
			$('business').previousSiblings()[0].show();
			
			$('petit').previousSiblings()[3].show();	
			$('moyen').previousSiblings()[2].show();
			$('grand').previousSiblings()[2].show();	
				
			$('prix1').previousSiblings()[0].show();
			$('prix2').previousSiblings()[0].show();
			$('prix3').previousSiblings()[0].show();
				
			$('cuir').previousSiblings()[0].show();
			$('toile').previousSiblings()[0].show();
			 if (!color) {
                 $$('.colors button').each(function(color, i){
                     color.previousSiblings()[0].show();
                 });
             }
	  		
	  	}
	  	,
	  	onFailure : resetResult()
	});	
	
	
	
}

function AddEventBGOn(div, event){
	Event.observe($(div), event, function(){
		
		// on d�sactive le masque courant
		
		$(div).up(".formBloc").getElementsBySelector(".masque")[0].addClassName("off")			
		if( isEnoughtDataBG() ){
			getResultCountBG();	
		}else{
			resetResult();
		}
	});							
}


function initAjaxSearchBG(){			
	
	AddEventBGOn('bgtype1', 		'click');	
	AddEventBGOn('bgtype2', 		'click');	
			
	AddEventBGOn('roue1', 		'click');	
	AddEventBGOn('roue2', 		'click');	
	AddEventBGOn('roue3', 		'click');	
	
	AddEventBGOn('more1', 		'click');
	AddEventBGOn('more2', 		'click');	
	AddEventBGOn('more3', 		'click');
	
	AddEventBGOn('habi1', 		'click');
	AddEventBGOn('habi2', 		'click');
	AddEventBGOn('habi3', 		'click');			

	AddEventBGOn('petit', 	'click');	
	AddEventBGOn('moyen', 	'click');	
	AddEventBGOn('grand', 	'click');	
	
	AddEventBGOn('prix1', 	'click');	
	AddEventBGOn('prix2', 	'click');	
	AddEventBGOn('prix3', 	'click');	
	
	AddEventBGOn('loisirs', 		'click');	
	AddEventBGOn('business', 	'click');		
	
	AddEventBGOn('cuir', 		'click');	
	AddEventBGOn('toile', 	'click');	
	
	
	
	$$('.colors button').each(function(elmt,i){		
		Event.observe(elmt, 'click', function(){									
			$('color').value = (i+1);
			
			if( isEnoughtDataBG(1) ){
				getResultCountBG(1);	
			}else{
				resetResult();
			}			
		});	
	});		
}

/*****************FIN BAGAGES *****************************/

/**************SACS**************************************/
function isEnoughtDataSac(color){
		
    $('ResultCountTxt').hide();   
    

    if ($$("#selecteurForm .off").length == 0) {
           //reset des couleurs quand aucun crit�re selectionn� 
          $$('.colors button').each(function(color, i){
                color.previousSiblings()[0].hide();
          });
          
          //reset de tous les champs quand aucun crit�res selectionn�s
          
          $$('.masque3').each(function(masque, i){
                masque.hide();
          });
          
          
    }
    
   //Bug IE sur les couleurs 
   if(color == 1) {
       	$("showResults").hide();
	 	return true;
   }
        
	if($$("#selecteurForm .off").length == 1)
	{
		$("showResults").hide();
	 	return true;
	 }
	 
	var cpt = 0;

	if($$("#selecteurForm .off").length >= 2) cpt=2;
	 
	 
	if(cpt < 2){
		$("showResults").hide();
		return false;
	}	 
	
	if(cpt == 2)
	{
	 	return true;
	 }
	
}

function getResultCountSac(color){
	var porte 	= '';
	var taille	= '';
	var prix	= '';
	var style	= '';
	var matiere	= '';
	
	
	/*var fields = array('main','epaule','petit','grand','prix1','prix2','prix3','mode','sport','classique','cuir','toile','newy');
	
	fields.each(function(elmt,e) { 
		
	
	}*/
	if( $('main').checked ) 	porte 	= $('main').value;
	if( $('epaule').checked ) 	porte 	= $('epaule').value;
	
	if( $('petit').checked ) 	taille 	= $('petit').value;
	if( $('moyen').checked ) 	taille 	= $('moyen').value;
	if( $('grand').checked ) 	taille 	= $('grand').value;
	
	if( $('prix1').checked ) {	
		prix 	= $('prix1').value;
	}
	if( $('prix2').checked ){ 	
		prix 	= $('prix2').value;
	}
	if( $('prix3').checked ){	
		prix 	= $('prix3').value;
	}
	
	if( $('mode').checked )		style 	= $('mode').value;		
	if( $('sport').checked )	style 	= $('sport').value;		
	if( $('classique').checked )style 	= $('classique').value;		
		
	if( $('cuir').checked )		matiere = $('cuir').value;		
	if( $('toile').checked )	matiere = $('toile').value;		
	
	if( $('newy').checked ){	
		nouveau = $('newy').value;
	} else {
		nouveau = '';
	}	
	
	genre = $('genre').value;
	rubrique = $('rub_id').value;
	
	var url = '/FRONT/LONGCHAMP/include/SearchAjax.php';	
	
	
	new Ajax.Request(url, {
		method: 'post',
	  	parameters: { 
	  		porte: porte,
	  		smlx: taille,
	  		echl: prix,
	  		look: style,
	  		color: $F('color'),
	  		mmix: matiere,
	  		genre: genre,
	  		rubrique: rubrique,
	  		nouveau: nouveau,
	  		attributsId: $('attributsId').value,
            vel: $('vel').value
	  	},
	
		onSuccess: function(msg) {
				var myResult = msg.responseText.evalJSON();	
				
				//reinitialisation des boutons
				$('main').previousSiblings()[0].hide();
				$('epaule').previousSiblings()[0].hide();		
				$('petit').previousSiblings()[2].hide();	
				$('moyen').previousSiblings()[2].hide();
				$('grand').previousSiblings()[2].hide();	
				$('prix1').previousSiblings()[0].hide();
				$('prix2').previousSiblings()[0].hide();
				$('prix3').previousSiblings()[0].hide();
				$('mode').previousSiblings()[0].hide();
				$('sport').previousSiblings()[0].hide();
				$('classique').previousSiblings()[0].hide();
				$('cuir').previousSiblings()[0].hide();
				$('toile').previousSiblings()[0].hide();
                if (!color) {
                    $$('.colors button').each(function(color, i){
                        color.previousSiblings()[0].hide();
                    });
                }	
                
                $('newy').disabled = false;
                
				var cptmain = 0;					
				var cptepaule = 0;	
				var cptpetit = 0;	
				var cptmoyen = 0;	
				var cptgrand = 0;	
				var cptprix1 = 0;	
				var cptprix2 = 0;	
				var cptprix3 = 0;
				var cptmode = 0;
				var cptsport = 0;
				var cptclassique = 0;
				var cptcuir = 0;
				var cpttoile = 0;	
				var cptcolors = new Array(13);
                var cptnewy = 0;
				//loop over article attributs
				myResult.attributs.each(function(elmt,e) { 
					
					if( $('main').value ==  elmt ) 	cptmain++;
					if( $('epaule').value ==  elmt ) cptepaule++;
	
					if( $('petit').value ==  elmt ) 	cptpetit++;
					if( $('moyen').value ==  elmt ) 	cptmoyen++;
					if( $('grand').value ==  elmt ) 	cptgrand++;
	
					if( $('prix1').value ==  elmt) 	cptprix1++;
					if( $('prix2').value ==  elmt) 	cptprix2++;
					if( $('prix3').value ==  elmt)	cptprix3++;
	
					if( $('mode').value ==  elmt)		cptmode++;	
					if( $('sport').value ==  elmt )	cptsport++;	
					if( $('classique').value ==  elmt) cptclassique++;	
		
					if( $('cuir').value ==  elmt)		cptcuir++;	
					if( $('toile').value ==  elmt)		cpttoile++;	
                    if (!color) {
                        $$('.colors button').each(function(color, i){
                            tab_color = color.id.split('_');
                            if (parseInt(tab_color[1], 10) == elmt) {
                                cptcolors[i] = 1;
                            }
                        });
                    }
                    
                    if( $('newy').value ==  elmt) cptnewy++;
                    
						
				});	
				
				if(cptmain == 0) $('main').previousSiblings()[0].show();
				
				if(cptepaule == 0) $('epaule').previousSiblings()[0].show();	
				
				
                if(cptpetit == 0) $('petit').previousSiblings()[2].show();
				
				if(cptmoyen == 0) $('moyen').previousSiblings()[2].show();
					
				if(cptgrand == 0) $('grand').previousSiblings()[2].show();
				
				
                if(cptprix1 == 0) $('prix1').previousSiblings()[0].show();
				
				if(cptprix2  == 0) $('prix2').previousSiblings()[0].show();
				
				if(cptprix3  == 0) $('prix3').previousSiblings()[0].show();
                
				
				if(cptmode  == 0) $('mode').previousSiblings()[0].show();
				
				if(cptsport  == 0) $('sport').previousSiblings()[0].show();
				
				if(cptclassique  == 0) $('classique').previousSiblings()[0].show();
                
                //finalDefaultChecked($('petit'),$('moyen'),$('grand'),cptpetit,cptmoyen,cptgrand);
                //finalDefaultChecked($('prix1'),$('prix2'),$('prix3'),cptprix1,cptprix2,cptprix3);
                //finalDefaultChecked($('mode'),$('sport'),$('classique'),cptmode,cptsport,cptclassique);

				if (cptcuir == 0 && cpttoile != 0) {
                    $('cuir').previousSiblings()[0].show();
                    $('toile').checked = true;
					$('cuir').ancestors()[1].descendants()[0].addClassName("off");
                    $('cuir').ancestors()[1].descendants()[0].hide();
                    myParent = $('cuir').ancestors()[1];
			        myParent.descendants().each(function(elmt2,i){
				        if(elmt2.className == "clearButton"){
					        elmt2.show();
				        }
			        });
                    
                }    
				if (cpttoile == 0 && cptcuir != 0) {
                    $('toile').previousSiblings()[0].show();
                    $('cuir').checked = true;
					$('toile').ancestors()[1].descendants()[0].addClassName("off");
                    $('toile').ancestors()[1].descendants()[0].hide();                    
                    myParent = $('toile').ancestors()[1];
			        myParent.descendants().each(function(elmt2,i){
				        if(elmt2.className == "clearButton"){
					        elmt2.show();
				        }
			        });
                } 
                
                if (!color) {
                    $$('.colors button').each(function(color, i){
                        if (cptcolors[i] == 1) {
                            color.previousSiblings()[0].hide();
                        }
                        else {
                            color.previousSiblings()[0].show();
                        }
                    });
                }
                if(cptnewy != 0){
                     $('newy').disabled = false;   
                }
                else
                {
                   $('newy').disabled = true;   
                }
                                 
                
				if($$("#selecteurForm .off").length == 1)
				{
                    $('ResultCountTxt').hide();
                    $('loadingRadioCheck').hide();
					resetResult();
				}
				else
				{
					setResultTo(myResult.total)	;
				}
				
		}
		,
	  	onLoading : function(xhr){
            
            
	  	/*	if($$("#selecteurForm .off").length > 1)
			{*/
                $('loadingRadioCheck').show();
	  		/*}	*/
	  		$('main').previousSiblings()[0].show();
			$('epaule').previousSiblings()[0].show();		
			$('petit').previousSiblings()[2].show();	
			$('moyen').previousSiblings()[2].show();
			$('grand').previousSiblings()[2].show();	
			$('prix1').previousSiblings()[0].show();
			$('prix2').previousSiblings()[0].show();
			$('prix3').previousSiblings()[0].show();
			$('mode').previousSiblings()[0].show();
			$('sport').previousSiblings()[0].show();
			$('classique').previousSiblings()[0].show();
			$('cuir').previousSiblings()[0].show();
			$('toile').previousSiblings()[0].show();
            if (!color) {
                $$('.colors button').each(function(color, i){
                    color.previousSiblings()[0].show();
                });
            }
            $('newy').disabled = true;
	  	}
	  	,
	  	onFailure : resetResult()
	});	
	
	
	
}

function AddEventSacOn(div, event){	

	Event.observe($(div), event, function(){
		
		// on d�sactive le masque courant sauf dans le cas du bouton nouveaute

        if($(div).id !='newy'){
		    $(div).up(".formBloc").getElementsBySelector(".masque")[0].addClassName("off");
		}
		if( isEnoughtDataSac() ){
			getResultCountSac();	
		}else{
			resetResult();
		}
	});							
}

function initAjaxSearchSac(){			

	AddEventSacOn('main', 		'click');
	AddEventSacOn('epaule', 	'click');	
	AddEventSacOn('petit', 	'click');	
	AddEventSacOn('moyen', 	'click');	
	AddEventSacOn('grand', 	'click');	
	AddEventSacOn('prix1', 	'click');	
	AddEventSacOn('prix2', 	'click');	
	AddEventSacOn('prix3', 	'click');	
	AddEventSacOn('mode', 		'click');	
	AddEventSacOn('sport', 	'click');		
	AddEventSacOn('classique', 'click');		
	AddEventSacOn('cuir', 		'click');	
	AddEventSacOn('toile', 	'click');	
	AddEventSacOn('newy', 	'click');		

	$$('.colors button').each(function(elmt,i){		
		Event.observe(elmt, 'click', function(){									
			$('color').value = (i+1);

			if( isEnoughtDataSac(1) ){
				getResultCountSac(1);	
			}else{
				resetResult();
			}			
		});	
	});		
}

/******************************FIN SACS***************************************/
/***********************PM***************************************************/

function isEnoughtDataPM(){
	/*
	if ($('selecteurForm').name == "selecteurPm") var cpt = 2;
	else var cpt = 0;
	// on compte les masques à "off"
	$$('#selecteurForm .masque').each(function(elmt,i){
		if((elmt.ancestors()[0].tagName != "LI")&&(elmt.className.indexOf("off") != -1)) cpt++;
	});
	*/
    //reset des couleurs quand aucun crit�re selectionn� 
    if ($$("#selecteurForm .off").length == 0) {
          $$('.colors button').each(function(color, i){
                color.previousSiblings()[0].hide();
          });
    }
	var allIsChecked = false;
    if (($('tune1').checked || $('tune2').checked || $('tune3').checked)){
         allIsChecked = true;
        $("showResults").hide();  
        $('ResultCountTxt').hide();        
    }
 
    if (($('cheq1').checked || $('cheq2').checked || $('cheq3').checked)){
        allIsChecked = true;
        $("showResults").hide();   
        $('ResultCountTxt').hide();        
    }
   
    if (($('papr1').checked || $('papr2').checked || $('papr3').checked)){
        allIsChecked = true;
        $("showResults").hide();
        $('ResultCountTxt').hide();    
    }
     
    if (($('bift1').checked || $('bift2').checked || $('bift3').checked)){
        allIsChecked = true;
        $("showResults").hide();   
        $('ResultCountTxt').hide(); 
    }
      
    if (($F('card') != 'rien')) {
        allIsChecked = true;
        $("showResults").hide();
        $('ResultCountTxt').hide();
    }
    
   if (($('tune1').checked || $('tune2').checked || $('tune3').checked) &&
   ($('cheq1').checked || $('cheq2').checked || $('cheq3').checked) &&
   ($('papr1').checked || $('papr2').checked || $('papr3').checked) &&
   ($('bift1').checked || $('bift2').checked || $('bift3').checked) &&
   ($F('card') != 'rien')) {
        allIsChecked = true;
        $("showResults").show();
   }
    
    if(allIsChecked == false){
        //reset des couleurs quand aucun crit�re selectionn� 
        $$('.colors button').each(function(color, i){
            color.previousSiblings()[0].hide();
        });
    }
    
    
	return allIsChecked;
	/*
	if(cpt < 2)	return false;
	else return true;
	*/
}

function getResultCountPM(color){
	var monaie	= '';
	var chequier= '';
	var papier	= '';
	var billet	= '';
	var carte	= '';
	var prix	= '';
	var matiere	= '';	
	
	if( $('tune1').checked )		monaie= $('tune1').value;		
	if( $('tune2').checked )		monaie= $('tune2').value;				
	if( $('tune3').checked )		monaie= $('tune3').value;	

	if( $('cheq1').checked )		chequier	= $('cheq1').value;			
	if( $('cheq2').checked )		chequier	= $('cheq2').value;
	if( $('cheq3').checked )		chequier	= $('cheq3').value;				

	if( $('papr1').checked )		papier		= $('papr1').value;			
	if( $('papr2').checked )		papier		= $('papr2').value;	
	if( $('papr3').checked )		papier		= $('papr3').value;						
	
	if( $('bift1').checked )		billet		= $('bift1').value;			
	if( $('bift2').checked )		billet		= $('bift2').value;			
	if( $('bift3').checked )		billet		= $('bift3').value;			
			
	if( $F('card') != 'rien' )				carte 	= $F('card');			
		
	if( $('prix1').checked ) 	prix 	= $('prix1').value;	
	if( $('prix2').checked ) 	prix 	= $('prix2').value;	
	if( $('prix3').checked ) 	prix 	= $('prix3').value;	
		
	if( $('cuir').checked )		matiere = $('cuir').value;
	if( $('toile').checked )		matiere = $('toile').value;
		
	
	genre = $('genre').value;
	rubrique = $('rub_id').value;		
		
	var url = '/FRONT/LONGCHAMP/include/SearchAjax.php';	

	new Ajax.Request(url, {
		method: 'post',				
	  	parameters: {   			  			  		
	  		PMmonaie: monaie,
	  		PMchequier: chequier,
	  		PMpapier: papier,
	  		PMbillet: billet,
	  		PMcarte: carte,	  		
	  		echl: prix,	  			  	
	  		color: $F('color'),
	  		mmix: matiere,
	  		genre: genre,
	  		rubrique: rubrique,
	  		attributsId: $('attributsId').value,
            vel: $('vel').value	  		
	  	},	  	
		onSuccess: function(msg) {
				var myResult = msg.responseText.evalJSON();	
 
				//reinitialisation des boutons
				$('tune1').disabled=false; 
				$('tune2').disabled=false;
				$('tune3').disabled=false;
				
				$('cheq1').disabled=false;
				$('cheq2').disabled=false;
				$('cheq3').disabled=false;

				$('papr1').disabled=false;
				$('papr2').disabled=false;
				$('papr3').disabled=false;		
				
				$('bift1').disabled=false;
				$('bift2').disabled=false;
				$('bift3').disabled=false;	

				$('prix1').previousSiblings()[0].hide();
				$('prix2').previousSiblings()[0].hide();
				$('prix3').previousSiblings()[0].hide();

				$('cuir').previousSiblings()[0].hide();
				$('toile').previousSiblings()[0].hide();
              
                $('card').disabled=false;  
                    
                 if (!color) {
                     $$('.colors button').each(function(color, i){
                         color.previousSiblings()[0].hide();
                     });
                 }
                 
				var cpttune1 = 0;	
				var cpttune2 = 0;	
				var cpttune3 = 0;
                
                var cptcheq1 = 0;	
				var cptcheq2 = 0;	
				var cptcheq3 = 0;
                
                var cptpapr1 = 0;	
				var cptpapr2 = 0;	
				var cptpapr3 = 0;
                
                var cptbift1 = 0;	
				var cptbift2 = 0;	
				var cptbift3 = 0;

				var cptprix1 = 0;	
				var cptprix2 = 0;	
				var cptprix3 = 0;
				
				var cptcuir = 0;
				var cpttoile = 0;	
                
                var cptcard1 = 0;
                var cptcard2 = 0;
                var cptcard3 = 0;
				
				var cptcolors = new Array(13);
				//loop over article attributs

				myResult.attributs.each(function(elmt,e) { 

					if( $('tune1').value ==  elmt) 	cpttune1++;
					if( $('tune2').value ==  elmt) 	cpttune2++;
					if( $('tune3').value ==  elmt)	cpttune3++;
                    
                    if( $('cheq1').value ==  elmt) 	cptcheq1++;
					if( $('cheq2').value ==  elmt) 	cptcheq2++;
					if( $('cheq3').value ==  elmt)	    cptcheq3++;
                    
                    if( $('papr1').value ==  elmt) 	cptpapr1++;
					if( $('papr2').value ==  elmt) 	cptpapr2++;
					if( $('papr3').value ==  elmt)	cptpapr3++;
                    
                    
                    if( $('bift1').value ==  elmt) 	    cptbift1++;
					if( $('bift2').value ==  elmt) 	    cptbift2++;
					if( $('bift3').value ==  elmt)      cptbift3++;

					if( $('prix1').value ==  elmt) 	cptprix1++;
					if( $('prix2').value ==  elmt) 	cptprix2++;
					if( $('prix3').value ==  elmt)	    cptprix3++;
                    //if ($F('card') != 'rien') {
                        if ($('card').options[1].value == elmt) 
                            cptcard1++;
                        if ($('card').options[2].value == elmt) 
                            cptcard2++;
                        if ($('card').options[3].value == elmt) 
                            cptcard3++;
                    //}
					if( $('cuir').value ==  elmt)		cptcuir++;	
					if( $('toile').value ==  elmt)		cpttoile++;	
                     if (!color) {
                         $$('.colors button').each(function(color, i){
                             tab_color = color.id.split('_');
                             if (parseInt(tab_color[1], 10) == elmt) {
                                 cptcolors[i] = 1;
                             }
                         });
                     }
					
				});		


				if(cpttune1 == 0 || $('tune3').checked) $('tune1').disabled=true;
				if(cpttune2  == 0 || $('tune3').checked) $('tune2').disabled=true;
				if(cpttune1 > 0 || cpttune2 > 0) $('tune3').disabled= true;
                if(cpttune1 > 0 && cpttune2 > 0) $('tune3').disabled= false;

				if(cptcheq1 == 0 || $('cheq3').checked) $('cheq1').disabled=true;
				if(cptcheq2  == 0 || $('cheq3').checked) $('cheq2').disabled=true;
				if(cptcheq1 > 0 || cptcheq2 > 0) $('cheq3').disabled= true;
                if(cptcheq1 > 0 && cptcheq2 > 0) $('cheq3').disabled= false;

				if(cptpapr1 == 0  || $('papr3').checked) $('papr1').disabled=true;
				if(cptpapr2  == 0 || $('papr3').checked) $('papr2').disabled=true;
			    if(cptpapr1 > 0 || cptpapr2 > 0) $('papr3').disabled= true;
                if(cptpapr1 > 0 && cptpapr2 > 0) $('papr3').disabled= false;

				if(cptbift1 == 0  || $('bift3').checked) $('bift1').disabled=true;
				if(cptbift2  == 0  || $('bift3').checked) $('bift2').disabled=true;
				if(cptbift1 > 0 || cptbift2 > 0) $('bift3').disabled= true;
                if(cptbift1 > 0 && cptbift2 > 0) $('bift3').disabled= false;

				if (cptprix1 == 0) {
                    //$('prix1').disabled = true;
                    $('prix1').previousSiblings()[0].show();
                }    
				if (cptprix2 == 0) {
                   // $('prix2').disabled = true;
                    $('prix2').previousSiblings()[0].show();
                }    
				if(cptprix3  == 0){
                   // $('prix3').disabled = true;
                    $('prix3').previousSiblings()[0].show();
                } 
                
               // if ($F('card') == 'rien') {
                     if (cptcard1 == 0) 
                         $('card').options[1].disabled = "disabled";
                     if (cptcard2 == 0) 
                         $('card').options[2].disabled = "disabled";
          
                     if (cptcard3 == 0) 
                         $('card').options[3].disabled = "DISABLED";
                    var Nom_Browser = navigator.appName;     
                    if ( Nom_Browser == "Microsoft Internet Explorer" )
                        ativaOptionsDisabled();
              // }
               
				if (cptcuir == 0 && cpttoile != 0) {
                    $('cuir').previousSiblings()[0].show();
                    $('toile').checked = true;
					$('cuir').ancestors()[1].descendants()[0].addClassName("off");
                    $('cuir').ancestors()[1].descendants()[0].hide();
                    myParent = $('cuir').ancestors()[1];
			        myParent.descendants().each(function(elmt2,i){
				        if(elmt2.className == "clearButton"){
					        elmt2.show();
				        }
			        });
                    
                }    
				if (cpttoile == 0 && cptcuir != 0) {
                    $('toile').previousSiblings()[0].show();
                    $('cuir').checked = true;
					$('toile').ancestors()[1].descendants()[0].addClassName("off");
                    $('toile').ancestors()[1].descendants()[0].hide();                    
                    myParent = $('toile').ancestors()[1];
			        myParent.descendants().each(function(elmt2,i){
				        if(elmt2.className == "clearButton"){
					        elmt2.show();
				        }
			        });
                }
                 if (!color) {
                     $$('.colors button').each(function(color, i){
                         if (cptcolors[i] == 1) {
                             color.previousSiblings()[0].hide();
                         }
                         else {
                             color.previousSiblings()[0].show();
                         }
                     });
                 }


                if( ($('tune1').checked || $('tune2').checked || $('tune3').checked) && 
        	    ($('cheq1').checked || $('cheq2').checked || $('cheq3').checked ) &&		
        	    ($('papr1').checked || $('papr2').checked || $('papr3').checked ) &&		
        	    ($('bift1').checked || $('bift2').checked || $('bift3').checked ) &&		
        	    ($F('card') != 'rien' ))		
                {
                    setResultTo(myResult.total)	;
				} 
                else
                {
                    $('ResultCountTxt').hide();
					
                    resetResult();
                }

                
	  	}		,
	  	onLoading : function(xhr){
	  		Element.update($('ResultCountTxt'), $('searchProgress').value);	
            $('loadingRadioCheck').show();
	  		
	  		$('tune1').disabled = true;
			$('tune2').disabled = true;
			$('tune3').disabled = true;
				
			$('cheq1').disabled = true;
			$('cheq2').disabled = true;
			$('cheq3').disabled = true;

			$('papr1').disabled = true;
			$('papr2').disabled = true;
			$('papr3').disabled = true;		
				
			$('bift1').disabled = true;
			$('bift2').disabled = true;
			$('bift3').disabled = true;
             if ($F('card') == 'rien')
            $('card').disabled=true;  

			$('prix1').previousSiblings()[0].show();
			$('prix2').previousSiblings()[0].show();
			$('prix3').previousSiblings()[0].show();

			$('cuir').previousSiblings()[0].show();
			$('toile').previousSiblings()[0].show();
			 if (!color) {
                 $$('.colors button').each(function(color, i){
                     color.previousSiblings()[0].show();
                 });
             }	
	  		
	  	}
	  	,
	  	onFailure : resetResult() 	
	});	
			
}

function AddEventPMOn(div, event){	
	Event.observe($(div), event, function(){
		if( isEnoughtDataPM() ){
			getResultCountPM();	
		}else{
			resetResult();
		}
	});							
}

function initAjaxSearchPM(){			
	
	AddEventPMOn('tune1', 		'click');	
	AddEventPMOn('tune2', 		'click');	
	AddEventPMOn('tune3', 		'click');
	
	AddEventPMOn('cheq1', 		'click');	
	AddEventPMOn('cheq2', 		'click');
	AddEventPMOn('cheq3', 		'click');
	
	AddEventPMOn('papr1', 		'click');	
	AddEventPMOn('papr2', 		'click');
	AddEventPMOn('papr3', 		'click');
	
	AddEventPMOn('bift1', 		'click');	
	AddEventPMOn('bift2', 		'click');
	AddEventPMOn('bift3', 		'click');
	
	AddEventPMOn('card', 		'change');	
	
	AddEventPMOn('prix1', 	'click');	
	AddEventPMOn('prix2', 	'click');	
	AddEventPMOn('prix3', 	'click');	

	AddEventPMOn('cuir', 		'click');	
	AddEventPMOn('toile', 	'click');	
	

	$$('.colors button').each(function(elmt,i){		
		Event.observe(elmt, 'click', function(){									
			$('color').value = (i+1);
			if( isEnoughtDataPM() ){
				getResultCountPM(1);	
			}else{
				resetResult();
			}			
		});	
	});		
}


/************************FIN PM*********************************************/



