Category.prototype.constructor = Category;

	function Category(curcat,typec,se_ids){		
		this.curcat = curcat;
		this.typec = typec;
		this.closeable=true;
		this.se_ids = se_ids;
		this.compt=0;
		this.comptchecked=0;
		this.IE = document.all?true:false;
		this.Categorie = document.getElementById('SS_CATEGORIE');
		this.DivCategory = document.getElementById('div_category');
		this.id_div=document.getElementById('masqueIECat');
		this.checklist = new Array();
		this.list = new Array();
		this.Init();
		}
	
 Category.prototype.Init = function(){
		if(this.curcat=='auto'){
			switch(this.typec) {
   				case 'ft':
       					this.categorielist = new Array('40,41,42,43,44,45,46,47');
       					this.checklist[0]=new Array('40','41','42','43','44','45,46','47');
       					break;
   				case 'cote':
   				      this.categorielist = new Array('40,41,42,43,44,45,46,47,48');
       					this.checklist[0]=new Array('40','41','42','43','44','45,46','47','48');
       					break;
   				case 're':
   							this.categorielist = new Array('40,41,42,43,44,45,46,47,48,49');
   				      this.checklist[0]=new Array('40','41','42','43','44','45,46','47','48','49');
			          break
			}
		}
		else if(this.curcat=='moto')
		{
			switch(this.typec) {
   					case 'cote':
   					      this.categorielist = new Array('60,61,62,63,64,65,66,67,68,69,70,71');
    	   					this.checklist[0]=new Array('60','61','62','63','64','65','66','67','68','69','70','71');
    	   					break;
   					case 're':
   								this.categorielist = new Array('60,61,62,63,64,65,66,67,68,69,72');
   					      this.checklist[0]=new Array('60','61','62','63','64','65','66','67','68','69','72');
				          break	
				        }		
		}
		else
		{
			this.categorielist = new Array('80,81,82,83,84');
			this.checklist[0]=new Array('80','81','82','83','84');
		}
	this.fill_cat();
	}

	Category.prototype.fill_cat = function(){
		var k,i;
		var se_id = this.se_ids.split(',');
			this.comptchecked=0;
		for(k=0;k< this.categorielist.length;k++){
		    for(i=0;i< se_id.length;i++){
				  if(document.getElementById(se_id[i])!=null){
				  	 this.Categorie.value+=(this.Categorie.value!=''?',':'')+document.getElementById(se_id[i]).value;
				  	 document.getElementById(se_id[i]).checked=true;
				  	 	this.comptchecked++;
				  }else if(se_id[i]=='45'&&document.getElementById(se_id[i]+',46')!=null)
				  {
				  	this.Categorie.value+=(this.Categorie.value!=''?',':'')+document.getElementById('45,46').value;
				  	document.getElementById('45,46').checked=true;
				  		this.comptchecked++;
				  } 		    	
			  }
			var nb=0;  
			for(j=0;j<this.checklist[k].length;j++){
	 			if(document.getElementById(this.checklist[k][j]).checked) nb++; 
	  	}  
	 }
	 if(this.comptchecked==this.checklist[0].length) document.getElementById(this.categorielist[0]).checked=true; 
  }
  
 
  
  Category.prototype.ChangeSousCategorie	= function(id){
		this.comptchecked=0;
		var nb,k;
		var ss_cat = document.getElementById(id);
		if(!ss_cat) return;
			
		for(k=0;k<this.categorielist.length;k++){
			nb=0;
			var i=0;
			while(i< this.checklist[k].length){
				if(document.getElementById(this.checklist[k][i]).checked)nb++;
					i++;
				}

			if(nb!=i) this.Categorie.value='';
				for(i=0;i< this.checklist[k].length;i++){          
			 		if(this.checklist[k][i]==id&&!ss_cat.checked )
			    	document.getElementById(this.categorielist[k]).checked=false;
		    }
	 }
	 this.Categorie.value='';
	 for(k=0;k<this.categorielist.length;k++){
		if(this.checklist[k].length==0&&document.getElementById(this.categorielist[k]).checked) this.Categorie.value+=(this.Categorie.value!=''?',':'')+document.getElementById(this.categorielist[k]).value;
	 		for(i=0;i<this.checklist[k].length;i++){
	 			if(document.getElementById(this.checklist[k][i]).checked){
	  			this.Categorie.value+=(this.Categorie.value!=''?',':'')+document.getElementById(this.checklist[k][i]).value;
	  		  this.comptchecked++;
	  		}
	  	}
	 }
  if(this.Categorie.value=='') this.Categorie.value= this.categorielist.join(',');
 }
	
	
	Category.prototype.ChangeCategorie	= function(id){
	 var nb=0;
	 this.comptchecked=0;
	 this.Categorie.value='';
	 for(k=0;k<this.categorielist.length;k++){
	 	if(this.categorielist[k]==id){
	 		for(i=0;i<this.checklist[k].length;i++){
	 			if(document.getElementById(this.categorielist[k]).checked)	
	 			{ 
	  			document.getElementById(this.checklist[k][i]).checked= true;
	  			this.comptchecked++;
	  		}
	  		else
	  			document.getElementById(this.checklist[k][i]).checked= false;
	  	}
	  }
	 } 
	 for(k=0;k<this.categorielist.length;k++)
	 		this.Categorie.value+=(this.Categorie.value!=''?',':'')+document.getElementById(this.categorielist[k]).value;
 }
 
 Category.prototype.getnbCat = function(){
	var cat,Tcat;
	cat = this.categorielist.join(',');
	Tcat = cat.split(/,/);  
	 return Tcat.length; 
	}
 
 Category.prototype.filter_ss_cat = function(ss_cat_found){
	var cat,val,i;
	val='';
	cat = this.categorielist.join(',');
	cat = cat.split(/,/); 
	var T_cat_found = ss_cat_found.split(/;/);
	for(i=0;i<T_cat_found.length;i++) T_cat_found[i] = T_cat_found[i].replace(/[0-9]*P/,'');
	i=0;
	this.comptchecked=0;
	while (i<cat.length){ 
		j=0;
		if(cat[i]!='46'&&cat[i]!='45') 
			document.getElementById(cat[i]).checked=false;
		else if(cat[i]=='45'||cat[i]=='46')
			document.getElementById('45,46').checked=false;	
		while (j<T_cat_found.length){
		 	if(cat[i]==T_cat_found[j]&&cat[i]!=''&&T_cat_found[j]!='')
		 	{
		 		if (cat[i]!='45'&&cat[i]!='46'){
  	 	 		document.getElementById('div_'+cat[i]).style.display='';
  	 	 		if(this.se_ids.match( new RegExp('(,|^)'+cat[i]+'(,|$)')))
  	 	 		{
  	 	 			document.getElementById(cat[i]).checked=true;
  	 	 			this.comptchecked++;
  	 	 		}
		 	 		val+=(val!='' ? ',':'')+document.getElementById(cat[i]).value;
		 		}else	if((cat[i]=='45'||cat[i]=='46')){
		 	 		document.getElementById('div_45_46').style.display='';
		 	 		if (!document.getElementById('45,46').checked) val+=(val!='' ? ',':'')+document.getElementById('45,46').value;
  	 	 		if(this.se_ids.match( new RegExp('(,|^)'+cat[i]+'(,|$)'))) 
  	 	 		{
  	 	 			if (!document.getElementById('45,46').checked) this.comptchecked++;
  	 	 			document.getElementById('45,46').checked=true;
  	 	 		}
		 	 	}
		 	}
		j=j+1;
	 }
	i=i+1;
	}
	
	this.compt=0;
	this.checklist[0] = new Array();
	T_cat_found=this.BubleSort(T_cat_found);
	for(k=0;k<T_cat_found.length;k++){
 		if(T_cat_found[k]=='45'||T_cat_found[k]=='46'){
 			this.checklist[0][this.compt]= '45,46';
 			this.compt++;
 		}else if(T_cat_found[k]!='46'&&T_cat_found[k]!='45'){
 				this.checklist[0][this.compt]=T_cat_found[k];
 			  this.compt++;
 			}	
 	}
	if(this.compt == this.comptchecked) 
		document.getElementById(this.categorielist[0]).checked=true;
 	document.getElementById(this.categorielist[0]).value= val;
	}
 
 Category.prototype.BubleSort = function(T){
	var max_ = T.length-1;
	var swap;
	var ok = true;
	var loop = 0;
	while(ok){
		ok = false;
		for(var i=loop;i<max_;i++){
			if(T[i]>T[i+1]){
				swap = T[i+1];
				T[i+1] = T[i];
				T[i] = swap;
				if(!ok){
					loop =(i-1>-1?i-1:i)
					ok = true;
				}
			}
		}
	}
	return T;
 }
	
	Category.prototype.display_div = function(val){
		this.masqueForIe6();
		var display = this.DivCategory.style.display;
		if(display=='none')
			this.DivCategory.style.display ='';
		else
			this.DivCategory.style.display ='none';
		this.closeable =false;
	}
	
	Category.prototype.close_div = function(){		
	 if(this.closeable)
			this.DivCategory.style.display ='none';
	 this.closeable =true;
	 this.masqueForIe6();
	}
	
	Category.prototype.masqueForIe6 = function(){
	 var display = this.DivCategory.style.display;
	 if(this.IE&&this.id_div!=null&&display=='none')
		this.id_div.style.display='';			
	 if(this.IE&&this.id_div!=null&&display=='')
		this.id_div.style.display='none';
	}		
