function notice(a,lng){
	
	this.loc=a;
	
	this.lng=lng;
	this.init();
}

notice.prototype.init=function(){
	
	
	new Ajax.Request('../../script/amfphp/gateway2.php?s=Notice&m=GetFamily&a0='+this.lng, {
	  onSuccess: function(transport){notice.buildFamily(transport.responseText)}
	});

}


notice.prototype.buildFamily=function(s){
		
		var temp=eval(s);
		var a=new Array()
		a.push({data:"",label:this.loc["family"]});
		for (var i=0;i<temp.length;i++){
			
			a.push({data:temp[i]["id"],label:temp[i]["titre"]});
		}
		$('family').innerHTML=this.buildListBox(a,"lstfamily","","notice.makeCategory");
}
notice.prototype.makeCategory=function(e){
	
	var a=e.value;
	new Ajax.Request('../../script/amfphp/gateway2.php?s=Notice&m=GetCategory&a0='+this.lng+"&a1="+a, {
	  onSuccess: function(transport){notice.buildCategory(transport.responseText)}
	});

}
notice.prototype.buildCategory=function(s){
		
		var temp=eval(s);
		var a=new Array()
		a.push({data:"",label:this.loc["category"]});
		for (var i=0;i<temp.length;i++){
			
			a.push({data:temp[i]["id"],label:temp[i]["titre"]});
		}
		$('category').innerHTML=this.buildListBox(a,"lstcategory","","notice.makeProduct");
		
		//reset
		$('product').innerHTML="";
		$('resultsearch').innerHTML="";
		$("titlesearch").hide();
		
		//auto next
		if (a.length==2){
			$('lstcategory').value=a[1]["data"];
			this.makeProduct($('lstcategory').value);

			
		}

}



notice.prototype.makeProduct=function(e){

	var a=e.value;

	new Ajax.Request('../../script/amfphp/gateway2.php?s=Notice&m=GetProduct&a0='+this.lng+'&a1='+$("lstfamily").value+'&a2='+$("lstcategory").value, {
	  onSuccess: function(transport){notice.buildProduct(transport.responseText)}
	});

}
notice.prototype.buildProduct=function(s){
		

		var temp=eval(s);
		var a=new Array()
		a.push({data:"",label:this.loc["product"]});
		for (var i=0;i<temp.length;i++){
			
			a.push({data:temp[i]["id"],label:temp[i]["titre"]});
		}
		$('product').innerHTML=this.buildListBox(a,"lstproduct","","notice.makeSearch");
		
		//reset
		
		$('resultsearch').innerHTML="";
		$("titlesearch").hide();
		
		
		//auto next
		if (a.length==2){
			$('lstproduct').value=a[1]["data"];

		}
		if (a.length<=2){
			this.makeSearch($('lstproduct').value);			
		}
		
		if (a.length<=2){
			$('lstproduct').hide();
			
		}else{
			$('lstproduct').show();
		}
}



notice.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;
}


notice.prototype.makeSearch=function(){
	
	a1=($("lstfamily")!=undefined)?$("lstfamily").value:"";
	a2=($("lstcategory")!=undefined)?$("lstcategory").value:"";
	a3=($("lstproduct")!=undefined)?$("lstproduct").value:"";
	
	new Ajax.Request('../../script/amfphp/gateway2.php?s=Notice&m=GetManuel&a0='+this.lng+'&a1='+a1+'&a2='+a2+'&a3='+a3, {
	  onSuccess: function(transport){notice.buildSearch(transport.responseText)}
	});
}
notice.prototype.buildSearch=function(s){
		
		$("titlesearch").show();

		var temp=eval(s);
		var s="<ul>";
		for (var i=0;i<temp.length;i++){
			s+="<li>";
			s+="<a href='../../files/files_manuel/"+temp[i]["chemin"]+"' target='_blank' >"+this.loc["download"]+"</a> - <span class='tsearch'>"+temp[i]["titre"]+"</span>";
			s+="</li>";
		}
		if (temp.length==0) s+="<li>"+a["noresult"]+"</a>";
		s+="</ul>";
		$('resultsearch').innerHTML=s
}
