function CreerListe(nom, hauteur, largeur, max) {
        this.disp = new Array();
        this.max=max;
	this.nom=nom; this.hauteur=hauteur; this.largeur=largeur;
	this.search="";
	this.nb=0; 
	this.Add=AjouterItem;
	this.Afficher=AfficherListe;
	this.MAJ=MAJListe;
}

function AfficherListe() {
	var Z="<SELECT name="+this.nom+" size="+this.hauteur+" style='width:"+this.largeur+"'>";
	if (this.nb > this.max) {
		Z+="<OPTION selected=\"1\" value=\"\">Please type a search criteria</OPTION>";
	}else{
		for (var i=0; i<this.nb; i++) {
			Z+="<OPTION  value=\""+this[i]+"\">"+this.disp[i]+"</OPTION>"		
		}
	}
	
	Z+="</SELECT>"
	document.write(Z);
}


function AjouterItem(val,item) {
	this[this.nb]=val
	this.disp[this.nb]=item
	
	//alert(this[0]);
	//alert(this.disp[0]);
	this.nb++;
}

function MAJListe(txt,f) {

	if (txt!=this.search ) {
		this.search=txt

		var n = document.createElement("SELECT");
		n.name=this.nom;
		n.id = this.nom;
		n.setAttribute("name",this.nom);
		n.setAttribute("size",f.elements[this.nom].getAttribute("size"));

		var n2 = document.createElement("OPTIONS");
		n.insertBefore(n2);
		f.elements[this.nom].replaceNode(n);

		var total = 0;
                for (var i=0; i<this.nb; i++) {
			if ( this.disp[i].toUpperCase().indexOf(txt.toUpperCase()) >= 0 ) {
				total += 1;
			}
		}

		if (total > this.max ) {
			if (txt==''){
				var o=new Option('Please type a search criteria...','');
				f.elements[this.nom].options[f.elements[this.nom].options.length]=o;
			}else{
				var o=new Option('Too many result...','');
				f.elements[this.nom].options[f.elements[this.nom].options.length]=o;
			}
		}else{
			for (var i=0; i<this.nb; i++) {
				//if ( this.disp[i].substring(0,txt.length).toUpperCase()==txt.toUpperCase() ) {
				if ( this.disp[i].toUpperCase().indexOf(txt.toUpperCase()) >= 0 ) {
					var o=new Option(this.disp[i], this[i]);
					f.elements[this.nom].options[f.elements[this.nom].options.length]=o;
				}
			}
		}
		if (f.elements[this.nom].options.length==1) {
			f.elements[this.nom].selectedIndex=0;
		}
	}
}

function ListeCheck(valeur,f) {
	f.MAJ(valeur,document.forms(0));
}
