function feature(a,lng,recover){
	
	this.loc=a;
	
	this.lng=lng;
	this.init();
	
	this.recover=recover;
}

feature.prototype.init=function(){
	
	
	new Ajax.Request('../../script/amfphp/gateway2.php?s=Feature&m=GetFamily&a0='+this.lng, {
	  onSuccess: function(transport){feature.buildFamily(transport.responseText)}
	});

}


feature.prototype.buildFamily=function(s){
		var temp=eval(s);
		var a=new Array();
		a.push({data:"",label:this.loc["feature"]});
		for (var i=0;i<temp.length;i++){
			a.push({data:temp[i]["id"],label:temp[i]["titre"]});
		}
		$('family').innerHTML=this.buildListBox(a,"lstfamily","","feature.makeCategory");
		
		
		
		
		if (this.recover=="_"){
			//this.makeCategory($("lstfamily"));

		}else{
			var temp=this.recover.split("_");
			$("lstfamily").value=temp[0];
			this.makeCategory($("lstfamily"));
		}
}
feature.prototype.makeCategory=function(e){
	var a=e.value;
	new Ajax.Request('../../script/amfphp/gateway2.php?s=Feature&m=GetCategory&a0='+this.lng+"&a1="+a, {
	  onSuccess: function(transport){feature.buildCategory(transport.responseText)}
	});
}
feature.prototype.buildCategory=function(s){
		
		var temp=eval(s);
		
		if (temp.length>0){
			var a=new Array();
			for (var i=0;i<temp.length;i++){
				
				a.push({data:temp[i]["id"],label:temp[i]["titre"]});
			}
			$('category').innerHTML=this.buildListBox(a,"lstcategory","","feature.makeSearch");
			
			if (this.recover==""){
				this.makeSearch($('lstcategory').value);
			}else{
				var temp=this.recover.split("_");
			//	alert(temp[1]);
				if (temp[1]!=""){
					$("lstcategory").value=temp[1];
					this.recover="";
					this.makeSearch($("lstfamily"));
				}else{
					this.makeSearch($('lstcategory').value);
				}
				
			}
		
		}else{
			$('category').innerHTML="";	
			$('resultsearch').innerHTML="";
		}
		
}



feature.prototype.buildListBox=function(a,id,selected,action,arg){
	
		arg=(arg==undefined)?"":","+arg;
		var maker=(action==undefined || action=='')?"":" onChange=\"javascript:"+action+"(this"+arg+")\" ";
		var s='<select name="'+id+'" id="'+id+'" '+maker+' >';
		for (var i=0;i<a.length;i++){

		  if (selected!=a[i]["data"]){
         	 s+='<option value="'+a[i]["data"]+'" >'+a[i]["label"]+'</option>';
		  }else{
			 s+='<option value="'+a[i]["data"]+'"  selected="selected">'+a[i]["label"]+'</option>';
			  
		  }
		 
		}
		s+='</select>';
		return s;
}


feature.prototype.makeSearch=function(){
	
	a1=($("lstfamily")!=undefined)?$("lstfamily").value:"";
	a2=($("lstcategory")!=undefined)?$("lstcategory").value:"";
	
	new Ajax.Request('../../script/amfphp/gateway2.php?s=Feature&m=GetManuel&a0='+this.lng+'&a1='+a1+'&a2='+a2, {
	  onSuccess: function(transport){feature.buildSearch(transport.responseText)}
	});
}
feature.prototype.buildSearch=function(s){

	

		var temp=eval(s);
		
		if (temp.length>0){
		var s="";
		if (temp[0]["logo"].length>0) s+="<img src='../../files/files_feature/"+temp[0]["logo"][0]["chemin"]+"' />"
		s+="<h1>"+temp[0]["titre"]+"</h1>";
        s+="<div id='article'>"+temp[0]["article"]+"</div>";
		s+="<br>";
		if (temp[0]["image"].length>0) s+="<img src='../../files/files_feature/"+temp[0]["image"][0]["chemin"]+"' />"
	
				$('resultsearch').innerHTML=s
		
		}else{
				$('resultsearch').innerHTML="";
		}
}
