var x_techno = 1;
var x_handi = 1;
var x_prod = 1;
var x_carac = 1;
var x_entre = 1;
var x_ageis_classif = 1;
var x_nb = 0;

var tabparam = new Array;
var tabcompare = new Array;



function add_nb(n) {
 ind=1;
 is_checked=false;
 ind_to_change=0;
 while (ind<x_nb+1) {
 	if (tabcompare[ind]==n) {
 		is_checked=true;
 		ind_to_change=ind;
 		}
 		ind++;
	}
	if (!is_checked) {
 		if (x_nb>3) {
	 		alert("Vous ne pouvez sélectionner plus de 4 produits à comparer");
 			x_nb=x_nb+1;
		}
		else{
	 		x_nb=x_nb+1;
 			tabcompare[x_nb]=n;
		}
	}
	else {
		ind=ind_to_change;
		while(ind+1<x_nb+1) {
			tabcompare[ind]=tabcompare[ind+1];
			ind=ind+1;
		}
		 x_nb=x_nb-1;
	}
}

function test_nb_selected() {
	if (x_nb>1) return true; else {
		alert("Veuillez sélectionner au moins 2 produits à comparer");
		return false;
	}
}

function verif_form() {
	

alert("Please select at least one field goddamnit!!!!");


}

function remove_field(name_field,n) {
	
	
	ind=1;
	end=1;
	/*Memoriser les champs entrees avant l'element a supprimer*/
	while (ind<n) {
	id_type = document.getElementById('champs_'+name_field+ind);
	sel_ind = id_type.selectedIndex;
	
	if (name_field=='techno') {
		tabparam[ind]='<select name="champs_'+name_field+ind+'" id=\'champs_'+name_field+ind+'\' onChange="apply_actb(this.options[this.selectedIndex].value,table_type,\'mot_'+name_field+ind+'\');">';
		tabparam[ind]+='<option value=""> -- Sélectionner un champ </option>';
		if (sel_ind == 1) {
			tabparam[ind]+='<option value="1" SELECTED> Type </option>';
		}
		else {
			tabparam[ind]+='<option value="1"> Type </option>';
		}
		if (sel_ind == 2) {
			tabparam[ind]+='<option value="2" SELECTED> Sstype </option>';
		}
		else {
			tabparam[ind]+='<option value="2"> Sstype </option>';
		}
		if (sel_ind == 3) {
			tabparam[ind]+='<option value="3" SELECTED> Detailtype </option>';
		}
		else {
			tabparam[ind]+='<option value="3"> Detailtype </option>';
		}
	tabparam[ind]+='</select>';
	id_mot = document.getElementById('mot_'+name_field+ind);
	tabparam[ind]+='<input value=\''+id_mot.value+'\' type="text" name="mot_'+name_field+ind+'" id=\'mot_'+name_field+ind+'\' size="30">';
	tabparam[ind]+='<img src="images/bouton_moins.gif" onMouseDown="this.src=\'images/bouton_moins_bleu.gif\'" onMouseOut="this.src=\'images/bouton_moins.gif\'" onMouseOver="this.src=\'images/bouton_moins_bleu.gif\'" alt="Retirer ce critère" Onclick="remove_field(\''+name_field+'\',\''+ind+'\');">';
	tabparam[ind]+='<br>';
	}
	else	if (name_field=='handi') {
		tabparam[ind]='<select name="champs_'+name_field+ind+'" id=\'champs_'+name_field+ind+'\' onChange="apply_actb(this.options[this.selectedIndex].value,table_type,\'mot_'+name_field+ind+'\');">';
		tabparam[ind]+='<option value=""> -- Sélectionner un champ </option>';
			if (sel_ind == 1) {
				tabparam[ind]+='<option value="4" SELECTED> Handicap </option>';
			}
			else {
				tabparam[ind]+='<option value="4"> Handicap </option>';
			}
			if (sel_ind == 2) {
				tabparam[ind]+='<option value="5" SELECTED> Sshandicap </option>';
			}
			else {
				tabparam[ind]+='<option value="5"> Sshandicap </option>';
			}
			if (sel_ind == 3) {
				tabparam[ind]+='<option value="6" SELECTED> Detailhandicap </option>';
			}
			else {
				tabparam[ind]+='<option value="6"> Detailhandicap </option>';
			}
			tabparam[ind]+='</select>';
	id_mot = document.getElementById('mot_'+name_field+ind);
	tabparam[ind]+='<input value=\''+id_mot.value+'\' id=\'mot_'+name_field+ind+'\' size="30">';
	tabparam[ind]+='<img src="images/bouton_moins.gif" onMouseDown="this.src=\'images/bouton_moins_bleu.gif\'" onMouseOut="this.src=\'images/bouton_moins.gif\'" onMouseOver="this.src=\'images/bouton_moins_bleu.gif\'" alt="Retirer ce critère" Onclick="remove_field(\''+name_field+'\',\''+ind+'\');">';
	tabparam[ind]+='<br>';
			
	}
	else	if (name_field=='ageis_classif') {
		tabparam[ind]='<select name="champs_'+name_field+ind+'" id=\'champs_'+name_field+ind+'\' onChange="apply_actb(this.options[this.selectedIndex].value,table_type,\'mot_'+name_field+ind+'\');">';
		tabparam[ind]+='<option value=""> -- Sélectionner un champ </option>';
			if (sel_ind == 1) {
				tabparam[ind]+='<option value="23" SELECTED> Thématique </option>';
			}
			else {
				tabparam[ind]+='<option value="23"> Thématique </option>';
			}
			if (sel_ind == 2) {
				tabparam[ind]+='<option value="24" SELECTED> Finalité </option>';
			}
			else {
				tabparam[ind]+='<option value="24"> Finalité </option>';
			}
			if (sel_ind == 3) {
				tabparam[ind]+='<option value="25" SELECTED> Détail </option>';
			}
			else {
				tabparam[ind]+='<option value="25"> Détail </option>';
			}
			tabparam[ind]+='</select>';
	id_mot = document.getElementById('mot_'+name_field+ind);
	tabparam[ind]+='<input value=\''+id_mot.value+'\' id=\'mot_'+name_field+ind+'\' size="30">';
	tabparam[ind]+='<img src="images/bouton_moins.gif" onMouseDown="this.src=\'images/bouton_moins_bleu.gif\'" onMouseOut="this.src=\'images/bouton_moins.gif\'" onMouseOver="this.src=\'images/bouton_moins_bleu.gif\'" alt="Retirer ce critère" Onclick="remove_field(\''+name_field+'\',\''+ind+'\');">';
	tabparam[ind]+='<br>';
			
	}
	else	if (name_field=='prod') {
		tabparam[ind]='<select name="champs_'+name_field+ind+'" id=\'champs_'+name_field+ind+'\'>';
		tabparam[ind]+='<option value=""> -- Selectionner un champ </option>';
			if (sel_ind == 1) {
				tabparam[ind]+='<option value="10" SELECTED> Nom </option>';
			}
			else {
				tabparam[ind]+='<option value="10"> Nom </option>';
			}
			if (sel_ind == 2) {
				tabparam[ind]+='<option value="11" SELECTED> Description </option>';
			}
			else {
				tabparam[ind]+='<option value="11"> Description </option>';
			}
			if (sel_ind == 3) {
				tabparam[ind]+='<option value="12" SELECTED> Remarques </option>';
			}
			else {
				tabparam[ind]+='<option value="12"> Remarques </option>';
			}
			if (sel_ind == 4) {
				tabparam[ind]+='<option value="13" SELECTED> Mot-clé </option>';
			}
			else {
				tabparam[ind]+='<option value="13"> Mot-clé </option>';
			}
			tabparam[ind]+='</select>';
	id_mot = document.getElementById('mot_'+name_field+ind);
	tabparam[ind]+='<input value=\''+id_mot.value+'\'  type="text" name="mot_'+name_field+ind+'" id=\'mot_'+name_field+ind+'\' size="30">';
	tabparam[ind]+='<img src="images/bouton_moins.gif" onMouseDown="this.src=\'images/bouton_moins_bleu.gif\'" onMouseOut="this.src=\'images/bouton_moins.gif\'" onMouseOver="this.src=\'images/bouton_moins_bleu.gif\'" alt="Retirer ce critère" Onclick="remove_field(\''+name_field+'\',\''+ind+'\');">';
	tabparam[ind]+='<br>';
	
	}
	else	if (name_field=='carac') {
		tabparam[ind]='<select name="champs_'+name_field+ind+'" id=\'champs_'+name_field+ind+'\'>';
		tabparam[ind]+='<option value=""> -- Selectionner un champ </option>';
		id_type=document.getElementById('champs_carac'+ind);
		id_type_source=document.getElementById('champs_carac');
		id_type.length=id_type_source.length;
		nb_item=id_type_source.length;
		k=0;
		while (k<nb_item) {
			if (sel_ind==id_type_source.options[k].value) {
			id_type.options[k].selected=true;
			id_type.options[k].value=id_type_source.options[k].value;
			id_type.options[k].text=id_type_source.options[k].text;
			}
			else {
			id_type.options[k].value=id_type_source.options[k].value;
			id_type.options[k].text=id_type_source.options[k].text;		
			}
			k=k+1;
		}
		
		tabparam[ind]+='</select>';
		id_mot = document.getElementById('mot_'+name_field+ind);
		tabparam[ind]+='<input value=\''+id_mot.value+'\'  type="text" name="mot_'+name_field+ind+'" id=\'mot_'+name_field+ind+'\' size="30">';
		tabparam[ind]+='<img src="images/bouton_moins.gif" onMouseDown="this.src=\'images/bouton_moins_bleu.gif\'" onMouseOut="this.src=\'images/bouton_moins.gif\'" onMouseOver="this.src=\'images/bouton_moins_bleu.gif\'" alt="-" Onclick="remove_field(\''+name_field+'\',\''+ind+'\');">';
		tabparam[ind]+='<br>';
	}
	else if (name_field=='entre') {
			tabparam[ind]='<select name="champs_'+name_field+ind+'" id=\'champs_'+name_field+ind+'\' onChange="apply_actb(this.options[this.selectedIndex].value,table_type,\'mot_'+name_field+ind+'\');">';
			tabparam[ind]+='<option value=""> -- Sélectionner un champ </option>';
			tabparam[ind]+='<option value=""> -- Fournisseur </option>';
			
			if (sel_ind==2) {
			tabparam[ind]+='<option value="7" SELECTED> -- -- Nom (Fournisseur) </option>';
			}
			else {
			tabparam[ind]+='<option value="7"> -- -- Nom (Fournisseur) </option>';	
			}
			if (sel_ind==3) {
			tabparam[ind]+='<option value="15" SELECTED> -- -- Adresse (Fournisseur) </option>';
			}
			else {
			tabparam[ind]+='<option value="15"> -- -- Adresse (Fournisseur) </option>';	
			}
			tabparam[ind]+='<option value=""> -- Distributeur </option>';
			
			if (sel_ind==5) {
			tabparam[ind]+='<option value="8" SELECTED> -- -- Nom (Distributeur) </option>';
			}
			else {
			tabparam[ind]+='<option value="8"> -- -- Nom (Distributeur) </option>';	
			}
			if (sel_ind==6) {
			tabparam[ind]+='<option value="16" SELECTED> -- -- Adresse (Distributeur) </option>';
			}
			else {
			tabparam[ind]+='<option value="16"> -- -- Adresse (Distributeur) </option>';
			}
			tabparam[ind]+='</select>';
	id_mot = document.getElementById('mot_'+name_field+ind);
			tabparam[ind]+='<input value=\''+id_mot.value+'\' id=\'mot_'+name_field+ind+'\' size="30">';
			tabparam[ind]+='<img src="images/bouton_moins.gif" onMouseDown="this.src=\'images/bouton_moins_bleu.gif\'" onMouseOut="this.src=\'images/bouton_moins.gif\'" onMouseOver="this.src=\'images/bouton_moins_bleu.gif\'" alt="Retirer ce critère" Onclick="remove_field(\''+name_field+'\',\''+ind+'\');">';
			tabparam[ind]+='<br>';

	}

		ind=ind+1;
	}
	if (name_field=='prod') {
		end=x_prod;
}
else if (name_field=='techno') {
	
		end=x_techno;
}
else if (name_field=='carac') {
	
		end=x_carac;
}	
else if (name_field=='entre') {
	
		end=x_entre;
}	
else if (name_field=='handi') {
		end=x_handi;
	
}		
else if (name_field=='ageis_classif') {
		end=x_ageis_classif;
	
}		
	/* decalage d'un element*/

	while (ind+1<end) {
	id_type = document.getElementById('champs_'+name_field+(ind+1));
	sel_ind = id_type.selectedIndex;
	
	if (name_field=='techno') {
		tabparam[ind]='<select name="champs_'+name_field+ind+'" id=\'champs_'+name_field+ind+'\' onChange="apply_actb(this.options[this.selectedIndex].value,table_type,\'mot_'+name_field+ind+'\');">';
		tabparam[ind]+='<option value=""> -- Selectionner un champ </option>';
		if (sel_ind == 1) {
			tabparam[ind]+='<option value="1" SELECTED> Type </option>';
		}
		else {
			tabparam[ind]+='<option value="1"> Type </option>';
		}
		if (sel_ind == 2) {
			tabparam[ind]+='<option value="2" SELECTED> Sstype </option>';
		}
		else {
			tabparam[ind]+='<option value="2"> Sstype </option>';
		}
		if (sel_ind == 3) {
			tabparam[ind]+='<option value="3" SELECTED> Detailtype </option>';
		}
		else {
			tabparam[ind]+='<option value="3"> Detailtype </option>';
		}
		tabparam[ind]+='</select>';
	id_mot = document.getElementById('mot_'+name_field+(ind+1));
	tabparam[ind]+='<input value=\''+id_mot.value+'\' id=\'mot_'+name_field+ind+'\' size="30">';
	tabparam[ind]+='<img src="images/bouton_moins.gif" onMouseDown="this.src=\'images/bouton_moins_bleu.gif\'" onMouseOut="this.src=\'images/bouton_moins.gif\'" onMouseOver="this.src=\'images/bouton_moins_bleu.gif\'" alt="-" Onclick="remove_field(\''+name_field+'\',\''+ind+'\');">';
	tabparam[ind]+='<br>';
	}
	else	if (name_field=='handi') {
		tabparam[ind]='<select name="champs_'+name_field+ind+'" id=\'champs_'+name_field+ind+'\' onChange="apply_actb(this.options[this.selectedIndex].value,table_type,\'mot_'+name_field+ind+'\');">';
		tabparam[ind]+='<option value=""> -- Selectionner un champ </option>';
			if (sel_ind == 1) {
				tabparam[ind]+='<option value="4" SELECTED> Handicap </option>';
			}
			else {
				tabparam[ind]+='<option value="4"> Handicap </option>';
			}
			if (sel_ind == 2) {
				tabparam[ind]+='<option value="5" SELECTED> Sshandicap </option>';
			}
			else {
				tabparam[ind]+='<option value="5"> Sshandicap </option>';
			}
			if (sel_ind == 3) {
				tabparam[ind]+='<option value="6" SELECTED> Detailhandicap </option>';
			}
			else {
				tabparam[ind]+='<option value="6"> Detailhandicap </option>';
			}
			tabparam[ind]+='</select>';
	id_mot = document.getElementById('mot_'+name_field+(ind+1));
	tabparam[ind]+='<input value=\''+id_mot.value+'\' type="text" name="mot_'+name_field+ind+'" id=\'mot_'+name_field+ind+'\' size="30">';
	tabparam[ind]+='<img src="images/bouton_moins.gif" onMouseDown="this.src=\'images/bouton_moins_bleu.gif\'" onMouseOut="this.src=\'images/bouton_moins.gif\'" onMouseOver="this.src=\'images/bouton_moins_bleu.gif\'" alt="Retirer ce critère" Onclick="remove_field(\''+name_field+'\',\''+ind+'\');">';
	tabparam[ind]+='<br>';
			
	}
	else	if (name_field=='ageis_classif') {
		tabparam[ind]='<select name="champs_'+name_field+ind+'" id=\'champs_'+name_field+ind+'\' onChange="apply_actb(this.options[this.selectedIndex].value,table_type,\'mot_'+name_field+ind+'\');">';
		tabparam[ind]+='<option value=""> -- Selectionner un champ </option>';
			if (sel_ind == 1) {
				tabparam[ind]+='<option value="23" SELECTED> Thématique </option>';
			}
			else {
				tabparam[ind]+='<option value="23"> Thématique </option>';
			}
			if (sel_ind == 2) {
				tabparam[ind]+='<option value="24" SELECTED> Finalité </option>';
			}
			else {
				tabparam[ind]+='<option value="24"> Finalité </option>';
			}
			if (sel_ind == 3) {
				tabparam[ind]+='<option value="25" SELECTED> Détail </option>';
			}
			else {
				tabparam[ind]+='<option value="25"> Détail </option>';
			}
			tabparam[ind]+='</select>';
	id_mot = document.getElementById('mot_'+name_field+(ind+1));
	tabparam[ind]+='<input value=\''+id_mot.value+'\' type="text" name="mot_'+name_field+ind+'" id=\'mot_'+name_field+ind+'\' size="30">';
	tabparam[ind]+='<img src="images/bouton_moins.gif" onMouseDown="this.src=\'images/bouton_moins_bleu.gif\'" onMouseOut="this.src=\'images/bouton_moins.gif\'" onMouseOver="this.src=\'images/bouton_moins_bleu.gif\'" alt="Retirer ce critère" Onclick="remove_field(\''+name_field+'\',\''+ind+'\');">';
	tabparam[ind]+='<br>';
			
	}
	else	if (name_field=='prod') {
		tabparam[ind]='<select name="champs_'+name_field+ind+'" id=\'champs_'+name_field+ind+'\'>';
	tabparam[ind]+='<option value=""> -- Selectionner un champ </option>';
			if (sel_ind == 1) {
				tabparam[ind]+='<option value="10" SELECTED> Nom </option>';
			}
			else {
				tabparam[ind]+='<option value="10"> Nom </option>';
			}
			if (sel_ind == 2) {
				tabparam[ind]+='<option value="11" SELECTED> Description </option>';
			}
			else {
				tabparam[ind]+='<option value="11"> Description </option>';
			}
			if (sel_ind == 3) {
				tabparam[ind]+='<option value="12" SELECTED> Remarques </option>';
			}
			else {
				tabparam[ind]+='<option value="12"> Remarques </option>';
			}
			if (sel_ind == 4) {
				tabparam[ind]+='<option value="13" SELECTED> Mot-clé </option>';
			}
			else {
				tabparam[ind]+='<option value="13"> Mot-clé </option>';
			}
			tabparam[ind]+='</select>';
	id_mot = document.getElementById('mot_'+name_field+(ind+1));
	tabparam[ind]+='<input value=\''+id_mot.value+'\' type="text" name="mot_'+name_field+ind+'" id=\'mot_'+name_field+ind+'\' size="30">';
	tabparam[ind]+='<img src="images/bouton_moins.gif" onMouseDown="this.src=\'images/bouton_moins_bleu.gif\'" onMouseOut="this.src=\'images/bouton_moins.gif\'" onMouseOver="this.src=\'images/bouton_moins_bleu.gif\'" alt="Retirer ce critère" Onclick="remove_field(\''+name_field+'\',\''+ind+'\');">';
	tabparam[ind]+='<br>';
				
	}
	else	if (name_field=='carac') {
	tabparam[ind]='<select name="champs_'+name_field+ind+'" id=\'champs_'+name_field+ind+'\'>';
		tabparam[ind]+='<option value=""> -- Selectionner un champ </option>';
		id_type=document.getElementById('champs_carac'+ind);
		id_type_source=document.getElementById('champs_carac');
		id_type.length=id_type_source.length;
		nb_item=id_type_source.length;
		k=0;
		while (k<nb_item) {
			if (sel_ind==id_type_source.options[k].value) {
			id_type.options[k].selected=true;
			id_type.options[k].value=id_type_source.options[k].value;
			id_type.options[k].text=id_type_source.options[k].text;
			}
			else {
			id_type.options[k].value=id_type_source.options[k].value;
			id_type.options[k].text=id_type_source.options[k].text;		
			}
			k=k+1;
		}
		
		tabparam[ind]+='</select>';
		id_mot = document.getElementById('mot_'+name_field+(ind+1));
		tabparam[ind]+='<input value=\''+id_mot.value+'\'  type="text" name="mot_'+name_field+ind+'" id=\'mot_'+name_field+ind+'\' size="30">';
		tabparam[ind]+='<img src="images/bouton_moins.gif" onMouseDown="this.src=\'images/bouton_moins_bleu.gif\'" onMouseOut="this.src=\'images/bouton_moins.gif\'" onMouseOver="this.src=\'images/bouton_moins_bleu.gif\'" alt="Retirer ce critère" Onclick="remove_field(\''+name_field+'\',\''+ind+'\');">';
		tabparam[ind]+='<br>';
	}
	else if (name_field=='entre') {
			tabparam[ind]='<select name="champs_'+name_field+ind+'" id=\'champs_'+name_field+ind+'\' onChange="apply_actb(this.options[this.selectedIndex].value,table_type,\'mot_'+name_field+ind+'\');">';
			tabparam[ind]+='<option value=""> -- Selectionner un champ </option>';
			tabparam[ind]+='<option value=""> -- Fournisseur </option>';
			
			if (sel_ind==2) {
			tabparam[ind]+='<option value="7" SELECTED> -- -- Nom (Fournisseur) </option>';
			}
			else {
			tabparam[ind]+='<option value="7"> -- -- Nom (Fournisseur) </option>';	
			}
			if (sel_ind==3) {
			tabparam[ind]+='<option value="15" SELECTED> -- -- Adresse (Fournisseur) </option>';
			}
			else {
			tabparam[ind]+='<option value="15"> -- -- Adresse (Fournisseur) </option>';	
			}
			tabparam[ind]+='<option value=""> -- Distributeur </option>';
			
			if (sel_ind==5) {
			tabparam[ind]+='<option value="8" SELECTED> -- -- Nom (Distributeur) </option>';
			}
			else {
			tabparam[ind]+='<option value="8"> -- -- Nom (Distributeur) </option>';	
			}
			if (sel_ind==6) {
			tabparam[ind]+='<option value="16" SELECTED> -- -- Adresse (Distributeur) </option>';
			}
			else {
			tabparam[ind]+='<option value="16"> -- -- Adresse (Distributeur) </option>';
			}
			tabparam[ind]+='</select>';
			id_mot = document.getElementById('mot_'+name_field+(ind+1));
			tabparam[ind]+='<input value=\''+id_mot.value+'\' type="text" name="mot_'+name_field+ind+'" id=\'mot_'+name_field+ind+'\' size="30">';
			tabparam[ind]+='<img src="images/bouton_moins.gif" onMouseDown="this.src=\'images/bouton_moins_bleu.gif\'" onMouseOut="this.src=\'images/bouton_moins.gif\'" onMouseOver="this.src=\'images/bouton_moins_bleu.gif\'" alt="Retirer ce critère" Onclick="remove_field(\''+name_field+'\',\''+ind+'\');">';
			tabparam[ind]+='<br>';
	}
	
		
		ind=ind+1;
		
	}
	tabparam[ind]=null;
	
	/*afficher le resultat dans le nouveau div*/
	ind=1;
	document.getElementById('my_div_'+name_field).innerHTML='';
	while (ind<end-1) {
		document.getElementById('my_div_'+name_field).innerHTML +=tabparam[ind];
		ind=ind+1;
	}
	
if (name_field=='prod') {
		x_prod=x_prod-1;
}
else if (name_field=='techno') {
	
		x_techno=x_techno-1;
}
else if (name_field=='carac') {
	
		x_carac=x_carac-1;
}	
else if (name_field=='entre') {
	
		x_entre=x_entre-1;
}	
else if (name_field=='handi') {
		x_handi=x_handi-1;
	
}		
else if (name_field=='ageis_classif') {
		x_ageis_classif=x_ageis_classif-1;
	
}	



} 
function add_field(name_field) {
	
		x=1;
		if (name_field=='prod') {
				x=x_prod;
		}
		else if (name_field=='techno') {
			
				x=x_techno;
		}
		else if (name_field=='carac') {
			
				x=x_carac;
		}	
		else if (name_field=='entre') {
			
				x=x_entre;
		}	
		else if (name_field=='handi') {
				x=x_handi;
			
		}
		else if (name_field=='ageis_classif') {
				x=x_ageis_classif;
			
		}
				
	if (x==1) {
		id_type_prev = document.getElementById('champs_'+name_field);
		id_mot_prev = document.getElementById('mot_'+name_field);	
	}
	else {
		id_type_prev = document.getElementById('champs_'+name_field+(x-1));
		id_mot_prev = document.getElementById('mot_'+name_field+(x-1));
	}
	if (id_type_prev.options[id_type_prev.selectedIndex].value=="") {
		
		alert('Choisissez un type avant d\'en ajouter un autre');
	}
	else if  (id_mot_prev.value=="") {
		
		alert('Choisissez un mot cle avant d\'en ajouter un autre');
	}
	else { 

	if (name_field=='techno') {
	document.getElementById('my_div_'+name_field).innerHTML +='<select name="champs_'+name_field+x_techno+'" id=\'champs_'+name_field+x_techno+'\' onChange="apply_actb(this.options[this.selectedIndex].value,table_type,\'mot_'+name_field+x_techno+'\');">';
	document.getElementById('my_div_'+name_field).innerHTML +='</select>';
	id_type = document.getElementById('champs_'+name_field+x_techno);
  id_type.length=4;
	id_type.options[0].value='';
	id_type.options[0].text='- Choisissez un champ -';
	id_type.options[1].value='1';
	id_type.options[1].text='Type';
	id_type.options[2].value='2';
	id_type.options[2].text='Sstype';
	id_type.options[3].value='3';
	id_type.options[3].text='Detailtype';
	document.getElementById('my_div_'+name_field).innerHTML +='<input type="text" name="mot_'+name_field+x_techno+'" id=\'mot_'+name_field+x_techno+'\' size="30">';
	document.getElementById('my_div_'+name_field).innerHTML +='<img src="images/bouton_moins.gif" onMouseDown="this.src=\'images/bouton_moins_bleu.gif\'" onMouseOut="this.src=\'images/bouton_moins.gif\'" onMouseOver="this.src=\'images/bouton_moins_bleu.gif\'" alt="Retirer ce critère" Onclick="remove_field(\''+name_field+'\',\''+x_techno+'\');">';
	document.getElementById('my_div_'+name_field).innerHTML +='<br>';
	}
	else	if (name_field=='handi') {
	document.getElementById('my_div_'+name_field).innerHTML +='<select name="champs_'+name_field+x_handi+'" id=\'champs_'+name_field+x_handi+'\' onChange="apply_actb(this.options[this.selectedIndex].value,table_type,\'mot_'+name_field+x_handi+'\');">';
	document.getElementById('my_div_'+name_field).innerHTML +='</select>';
	id_type = document.getElementById('champs_'+name_field+x_handi);
  id_type.length=4;
	id_type.options[0].value='';
	id_type.options[0].text='-- Selectionner un champ ';
	id_type.options[1].value='4';
	id_type.options[1].text='Handicap';
	id_type.options[2].value='5';
	id_type.options[2].text='Sshandicap';
	id_type.options[3].value='6';
	id_type.options[3].text='Detailhandicap';
	document.getElementById('my_div_'+name_field).innerHTML +='<input type="text" name="mot_'+name_field+x_handi+'" id=\'mot_'+name_field+x_handi+'\' size="30">';
	document.getElementById('my_div_'+name_field).innerHTML +='<img src="images/bouton_moins.gif" onMouseDown="this.src=\'images/bouton_moins_bleu.gif\'" onMouseOut="this.src=\'images/bouton_moins.gif\'" onMouseOver="this.src=\'images/bouton_moins_bleu.gif\'" alt="Retirer ce critère" Onclick="remove_field(\''+name_field+'\',\''+x_handi+'\');">';
	document.getElementById('my_div_'+name_field).innerHTML +='<br>';
	}
	else	if (name_field=='ageis_classif') {
	document.getElementById('my_div_'+name_field).innerHTML +='<select name="champs_'+name_field+x_ageis_classif+'" id=\'champs_'+name_field+x_ageis_classif+'\' onChange="apply_actb(this.options[this.selectedIndex].value,table_type,\'mot_'+name_field+x_ageis_classif+'\');">';
	document.getElementById('my_div_'+name_field).innerHTML +='</select>';
	id_type = document.getElementById('champs_'+name_field+x_ageis_classif);
  id_type.length=4;
	id_type.options[0].value='';
	id_type.options[0].text='-- Selectionner un champ ';
	id_type.options[1].value='23';
	id_type.options[1].text='Thématique';
	id_type.options[2].value='24';
	id_type.options[2].text='Finalité';
	id_type.options[3].value='25';
	id_type.options[3].text='Détail';
	document.getElementById('my_div_'+name_field).innerHTML +='<input type="text" name="mot_'+name_field+x_ageis_classif+'" id=\'mot_'+name_field+x_ageis_classif+'\' size="30">';
	document.getElementById('my_div_'+name_field).innerHTML +='<img src="images/bouton_moins.gif" onMouseDown="this.src=\'images/bouton_moins_bleu.gif\'" onMouseOut="this.src=\'images/bouton_moins.gif\'" onMouseOver="this.src=\'images/bouton_moins_bleu.gif\'" alt="Retirer ce critère" Onclick="remove_field(\''+name_field+'\',\''+x_ageis_classif+'\');">';
	document.getElementById('my_div_'+name_field).innerHTML +='<br>';
	}
	else	if (name_field=='prod') {
	document.getElementById('my_div_'+name_field).innerHTML +='<select name="champs_'+name_field+x_prod+'" id=\'champs_'+name_field+x_prod+'\'>';
	document.getElementById('my_div_'+name_field).innerHTML +='</select>';
	id_type = document.getElementById('champs_'+name_field+x_prod);
  id_type.length=5;
	id_type.options[0].value='';
	id_type.options[0].text='-- Selectionner un champ ';
	id_type.options[1].value='10';
	id_type.options[1].text='Nom';
	id_type.options[2].value='11';
	id_type.options[2].text='Description';
	id_type.options[3].value='12';
	id_type.options[3].text='Remarques';
	id_type.options[4].value='13';
	id_type.options[4].text='Mot-clé';
	document.getElementById('my_div_'+name_field).innerHTML +='<input type="text" name="mot_'+name_field+x_prod+'" id=\'mot_'+name_field+x_prod+'\' size="30">';
	document.getElementById('my_div_'+name_field).innerHTML +='<img src="images/bouton_moins.gif" onMouseDown="this.src=\'images/bouton_moins_bleu.gif\'" onMouseOut="this.src=\'images/bouton_moins.gif\'" onMouseOver="this.src=\'images/bouton_moins_bleu.gif\'" alt="Retirer ce critère" Onclick="remove_field(\''+name_field+'\',\''+x_prod+'\');">';
	document.getElementById('my_div_'+name_field).innerHTML +='<br>';
	}
	else	if (name_field=='carac') {
	document.getElementById('my_div_'+name_field).innerHTML +='<select name="champs_'+name_field+x_carac+'" id=\'champs_'+name_field+x_carac+'\' onChange="apply_actb(this.options[this.selectedIndex].value,table_type,\'mot_'+name_field+x_carac+'\');">';
	document.getElementById('my_div_'+name_field).innerHTML +='</select>';
	id_type = document.getElementById('champs_'+name_field+x_carac);
	id_type_source = document.getElementById('champs_carac');
	id_type.length=id_type_source.length;
	nb_item=id_type_source.length;
	k=0;
		while (k<nb_item) {
			id_type.options[k].value=id_type_source.options[k].value;
			id_type.options[k].text=id_type_source.options[k].text;
			k=k+1;
		}
	document.getElementById('my_div_'+name_field).innerHTML +='<input type="text" name="mot_'+name_field+x_carac+'" id=\'mot_'+name_field+x_carac+'\' size="30">';
	document.getElementById('my_div_'+name_field).innerHTML +='<img src="images/bouton_moins.gif" onMouseDown="this.src=\'images/bouton_moins_bleu.gif\'" onMouseOut="this.src=\'images/bouton_moins.gif\'" onMouseOver="this.src=\'images/bouton_moins_bleu.gif\'" alt="Retirer ce critère" Onclick="remove_field(\''+name_field+'\',\''+x_carac+'\');">';
	document.getElementById('my_div_'+name_field).innerHTML +='<br>';	
	}
	else if (name_field=='entre') {
	document.getElementById('my_div_'+name_field).innerHTML +='<select name="champs_'+name_field+x_entre+'" id=\'champs_'+name_field+x_entre+'\' onChange="apply_actb(this.options[this.selectedIndex].value,table_type,\'mot_'+name_field+x_entre+'\');">';
	document.getElementById('my_div_'+name_field).innerHTML +='</select>';
	id_type = document.getElementById('champs_'+name_field+x_entre);
  id_type.length=7;
	id_type.options[0].value='';
	id_type.options[0].text='-- Selectionner un champ ';
	id_type.options[1].value='';
	id_type.options[1].text='-- Fournisseur';
	id_type.options[2].value='7';
	id_type.options[2].text='-- -- Nom (Fournisseur)';
	id_type.options[3].value='15';
	id_type.options[3].text='-- -- Adresse (Fournisseur)';
	id_type.options[4].value='';
	id_type.options[4].text='-- Distributeur';
	id_type.options[5].value='8';
	id_type.options[5].text='-- -- Nom (Distributeur)';
	id_type.options[6].value='16';
	id_type.options[6].text='-- -- Adresse (Distributeur)';	
	document.getElementById('my_div_'+name_field).innerHTML +='<input name="mot_'+name_field+x_entre+'" id=\'mot_'+name_field+x_entre+'\' size="30">';
	document.getElementById('my_div_'+name_field).innerHTML +='<img src="images/bouton_moins.gif" onMouseDown="this.src=\'images/bouton_moins_bleu.gif\'" onMouseOut="this.src=\'images/bouton_moins.gif\'" onMouseOver="this.src=\'images/bouton_moins_bleu.gif\'" alt="Retirer ce critère" Onclick="remove_field(\''+name_field+'\',\''+x_entre+'\');">';
	document.getElementById('my_div_'+name_field).innerHTML +='<br>';
	}

			if (name_field=='prod') {
				x_prod=x_prod+1;
		}
		else if (name_field=='techno') {
			
				x_techno=x_techno+1;
		}
		else if (name_field=='carac') {
			
				x_carac=x_carac+1;
		}	
		else if (name_field=='entre') {
			
				x_entre=x_entre+1;
		}	
		else if (name_field=='techno') {
				x_techno=x_techno+1;
			
		}
		else if (name_field=='handi') {
				x_handi=x_handi+1;
		}	
		else if (name_field=='ageis_classif') {
				x_ageis_classif=x_ageis_classif+1;
		}		
	}

}
function apply_actb(champ,table_type,mot_cle){

		if (champ==1) {
		var obj = actb(document.getElementById(mot_cle),table_type[0]);

		}
		else if (champ==2) {
		var obj = actb(document.getElementById(mot_cle),table_type[1]);
		}
		else if (champ==3) {
		var obj = actb(document.getElementById(mot_cle),table_type[2]);
		}
		else if (champ==4) {
		var obj = actb(document.getElementById(mot_cle),table_type[3]);
		}
		else if (champ==5) {
		var obj = actb(document.getElementById(mot_cle),table_type[4]);
		}
		else if (champ==6) {
		var obj = actb(document.getElementById(mot_cle),table_type[5]);
		}
		else if (champ==7 || champ==8) {
		var obj = actb(document.getElementById(mot_cle),table_type[6]);
		}
		else if (champ==23) {
		var obj = actb(document.getElementById(mot_cle),table_type[7]);
		}
		else if (champ==24) {
		var obj = actb(document.getElementById(mot_cle),table_type[8]);
		}
		else if (champ==25) {
		var obj = actb(document.getElementById(mot_cle),table_type[9]);
		}
		else {
			var vide=new Array;
			var obj = actb(document.getElementById(mot_cle),vide);
		}
		
		
}

function actb_in_text() {
	with ( document.apercu.value ) {
			insert(document.champs.value+document.mot_cle.value);
		}
}
function actb(obj,ca){
	/* ---- Public Variables ---- */
	this.actb_timeOut = -1; // Autocomplete Timeout in ms (-1: autocomplete never time out)
	this.actb_lim = 8;    // Nombre d'element que l'Autocomplete peut afficher (-1: no limit)
	this.actb_firstText = true; // Limiter l'autocomplete au debut du mot
	this.actb_mouse = true; // Enable Mouse Support
	this.actb_delimiter = new Array(' ',',');  // Delimiter differents autocompletes en meme temps. Set it to empty array for single autocomplete
	this.actb_startcheck = 1; // Show widget only after this number of characters is typed in.
	/* ---- Public Variables ---- */

	/* --- Styles --- */
	this.actb_bgColor = '#888888';
	this.actb_textColor = '#FFFFFF';
	this.actb_hColor = '#000000';
	this.actb_fFamily = 'Verdana';
	this.actb_fSize = '11px';
	this.actb_hStyle = 'text-decoration:underline;font-weight="bold"';
	/* --- Styles --- */

	/* ---- Private Variables ---- */
	var actb_delimwords = new Array();
	var actb_cdelimword = 0;
	var actb_delimchar = new Array();
	var actb_display = false;
	var actb_pos = 0;
	var actb_total = 0;
	var actb_curr = null;
	var actb_rangeu = 0;
	var actb_ranged = 0;
	var actb_bool = new Array();
	var actb_pre = 0;
	var actb_toid;
	var actb_tomake = false;
	var actb_getpre = "";
	var actb_mouse_on_list = 1;
	var actb_kwcount = 0;
	var actb_caretmove = false;
	this.actb_keywords = new Array();
	/* ---- Private Variables---- */
	
	this.actb_keywords = ca;
	var actb_self = this;

	actb_curr = obj;
	
	addEvent(actb_curr,"focus",actb_setup);
	function actb_setup(){
		addEvent(document,"keydown",actb_checkkey);
		addEvent(actb_curr,"blur",actb_clear);
		addEvent(document,"keypress",actb_keypress);
	}

	function actb_clear(evt){
		if (!evt) evt = event;
		removeEvent(document,"keydown",actb_checkkey);
		removeEvent(actb_curr,"blur",actb_clear);
		removeEvent(document,"keypress",actb_keypress);
		actb_removedisp();
	}
	function actb_parse(n){
		if (actb_self.actb_delimiter.length > 0){
			var t = actb_delimwords[actb_cdelimword].trim().addslashes();
			var plen = actb_delimwords[actb_cdelimword].trim().length;
		}else{
			var t = actb_curr.value.addslashes();
			var plen = actb_curr.value.length;
		}
		var tobuild = '';
		var i;

		if (actb_self.actb_firstText){
			var re = new RegExp("^" + t, "i");
		}else{
			var re = new RegExp(t, "i");
		}
		var p = n.search(re);
				
		for (i=0;i<p;i++){
			tobuild += n.substr(i,1);
		}
		tobuild += "<font style='"+(actb_self.actb_hStyle)+"'>"
		for (i=p;i<plen+p;i++){
			tobuild += n.substr(i,1);
		}
		tobuild += "</font>";
			for (i=plen+p;i<n.length;i++){
			tobuild += n.substr(i,1);
		}
		return tobuild;
	}
	function actb_generate(){
		if (document.getElementById('tat_table')){ actb_display = false;document.body.removeChild(document.getElementById('tat_table')); } 
		if (actb_kwcount == 0){
			actb_display = false;
			return;
		}
		a = document.createElement('table');
		a.cellSpacing='1px';
		a.cellPadding='2px';
		a.style.position='absolute';
		a.style.top = eval(curTop(actb_curr) + actb_curr.offsetHeight) + "px";
		a.style.left = curLeft(actb_curr) + "px";
		a.style.backgroundColor=actb_self.actb_bgColor;
		a.id = 'tat_table';
		document.body.appendChild(a);
		var i;
		var first = true;
		var j = 1;
		if (actb_self.actb_mouse){
			a.onmouseout = actb_table_unfocus;
			a.onmouseover = actb_table_focus;
		}
		var counter = 0;
		
		for (i=0;i<actb_self.actb_keywords.length;i++){
			if (actb_bool[i]){
				counter++;
				r = a.insertRow(-1);
				if (first && !actb_tomake){
					r.style.backgroundColor = actb_self.actb_hColor;
					first = false;
					actb_pos = counter;
				}else if(actb_pre == i){
					r.style.backgroundColor = actb_self.actb_hColor;
					first = false;
					actb_pos = counter;
				}else{
					r.style.backgroundColor = actb_self.actb_bgColor;
				}
				r.id = 'tat_tr'+(j);
				c = r.insertCell(-1);
				c.style.color = actb_self.actb_textColor;
				c.style.fontFamily = actb_self.actb_fFamily;
				c.style.fontSize = actb_self.actb_fSize;
				c.innerHTML = actb_parse(actb_self.actb_keywords[i]);
				c.id = 'tat_td'+(j);
				c.setAttribute('pos',j);
				if (actb_self.actb_mouse){
					c.style.cursor = 'pointer';
					c.onclick=actb_mouseclick;
					c.onmouseover = actb_table_highlight;
				}
				j++;
			}
			if (j - 1 == actb_self.actb_lim && j < actb_total){
				r = a.insertRow(-1);
				r.style.backgroundColor = actb_self.actb_bgColor;
				c = r.insertCell(-1);
				c.style.color = actb_self.actb_textColor;
				c.style.fontFamily = 'arial narrow';
				c.style.fontSize = actb_self.actb_fSize;
				c.align='center';
				replaceHTML(c,'\\/');
				if (actb_self.actb_mouse){
					c.style.cursor = 'pointer';
					c.onclick = actb_mouse_down;
				}
				break;
			}
		}
		actb_rangeu = 1;
		actb_ranged = j-1;
		actb_display = true;
		if (actb_pos <= 0) actb_pos = 1;
	}
	function actb_remake(){
		document.body.removeChild(document.getElementById('tat_table'));
		a = document.createElement('table');
		a.cellSpacing='1px';
		a.cellPadding='2px';
		a.style.position='absolute';
		a.style.top = eval(curTop(actb_curr) + actb_curr.offsetHeight) + "px";
		a.style.left = curLeft(actb_curr) + "px";
		a.style.backgroundColor=actb_self.actb_bgColor;
		a.id = 'tat_table';
		if (actb_self.actb_mouse){
			a.onmouseout= actb_table_unfocus;
			a.onmouseover=actb_table_focus;
		}
		document.body.appendChild(a);
		var i;
		var first = true;
		var j = 1;
		if (actb_rangeu > 1){
			r = a.insertRow(-1);
			r.style.backgroundColor = actb_self.actb_bgColor;
			c = r.insertCell(-1);
			c.style.color = actb_self.actb_textColor;
			c.style.fontFamily = 'arial narrow';
			c.style.fontSize = actb_self.actb_fSize;
			c.align='center';
			replaceHTML(c,'/\\');
			if (actb_self.actb_mouse){
				c.style.cursor = 'pointer';
				c.onclick = actb_mouse_up;
			}
		}
		for (i=0;i<actb_self.actb_keywords.length;i++){
			if (actb_bool[i]){
				if (j >= actb_rangeu && j <= actb_ranged){
					r = a.insertRow(-1);
					r.style.backgroundColor = actb_self.actb_bgColor;
					r.id = 'tat_tr'+(j);
					c = r.insertCell(-1);
					c.style.color = actb_self.actb_textColor;
					c.style.fontFamily = actb_self.actb_fFamily;
					c.style.fontSize = actb_self.actb_fSize;
					c.innerHTML = actb_parse(actb_self.actb_keywords[i]);
					c.id = 'tat_td'+(j);
					c.setAttribute('pos',j);
					if (actb_self.actb_mouse){
						c.style.cursor = 'pointer';
						c.onclick=actb_mouseclick;
						c.onmouseover = actb_table_highlight;
					}
					j++;
				}else{
					j++;
				}
			}
			if (j > actb_ranged) break;
		}
		if (j-1 < actb_total){
			r = a.insertRow(-1);
			r.style.backgroundColor = actb_self.actb_bgColor;
			c = r.insertCell(-1);
			c.style.color = actb_self.actb_textColor;
			c.style.fontFamily = 'arial narrow';
			c.style.fontSize = actb_self.actb_fSize;
			c.align='center';
			replaceHTML(c,'\\/');
			if (actb_self.actb_mouse){
				c.style.cursor = 'pointer';
				c.onclick = actb_mouse_down;
			}
		}
	}
	function actb_goup(){
		if (!actb_display) return;
		if (actb_pos == 1) return;
		document.getElementById('tat_tr'+actb_pos).style.backgroundColor = actb_self.actb_bgColor;
		actb_pos--;
		if (actb_pos < actb_rangeu) actb_moveup();
		document.getElementById('tat_tr'+actb_pos).style.backgroundColor = actb_self.actb_hColor;
		if (actb_toid) clearTimeout(actb_toid);
		if (actb_self.actb_timeOut > 0) actb_toid = setTimeout(function(){actb_mouse_on_list=0;actb_removedisp();},actb_self.actb_timeOut);
	}
	function actb_godown(){
		if (!actb_display) return;
		if (actb_pos == actb_total) return;
		document.getElementById('tat_tr'+actb_pos).style.backgroundColor = actb_self.actb_bgColor;
		actb_pos++;
		if (actb_pos > actb_ranged) actb_movedown();
		document.getElementById('tat_tr'+actb_pos).style.backgroundColor = actb_self.actb_hColor;
		if (actb_toid) clearTimeout(actb_toid);
		if (actb_self.actb_timeOut > 0) actb_toid = setTimeout(function(){actb_mouse_on_list=0;actb_removedisp();},actb_self.actb_timeOut);
	}
	function actb_movedown(){
		actb_rangeu++;
		actb_ranged++;
		actb_remake();
	}
	function actb_moveup(){
		actb_rangeu--;
		actb_ranged--;
		actb_remake();
	}

	/* Mouse */
	function actb_mouse_down(){
		document.getElementById('tat_tr'+actb_pos).style.backgroundColor = actb_self.actb_bgColor;
		actb_pos++;
		actb_movedown();
		document.getElementById('tat_tr'+actb_pos).style.backgroundColor = actb_self.actb_hColor;
		actb_curr.focus();
		actb_mouse_on_list = 0;
		if (actb_toid) clearTimeout(actb_toid);
		if (actb_self.actb_timeOut > 0) actb_toid = setTimeout(function(){actb_mouse_on_list=0;actb_removedisp();},actb_self.actb_timeOut);
	}
	function actb_mouse_up(evt){
		if (!evt) evt = event;
		if (evt.stopPropagation){
			evt.stopPropagation();
		}else{
			evt.cancelBubble = true;
		}
		document.getElementById('tat_tr'+actb_pos).style.backgroundColor = actb_self.actb_bgColor;
		actb_pos--;
		actb_moveup();
		document.getElementById('tat_tr'+actb_pos).style.backgroundColor = actb_self.actb_hColor;
		actb_curr.focus();
		actb_mouse_on_list = 0;
		if (actb_toid) clearTimeout(actb_toid);
		if (actb_self.actb_timeOut > 0) actb_toid = setTimeout(function(){actb_mouse_on_list=0;actb_removedisp();},actb_self.actb_timeOut);
	}
	function actb_mouseclick(evt){
		if (!evt) evt = event;
		if (!actb_display) return;
		actb_mouse_on_list = 0;
		actb_pos = this.getAttribute('pos');
		actb_penter();
	}
	function actb_table_focus(){
		actb_mouse_on_list = 1;
	}
	function actb_table_unfocus(){
		actb_mouse_on_list = 0;
		if (actb_toid) clearTimeout(actb_toid);
		if (actb_self.actb_timeOut > 0) actb_toid = setTimeout(function(){actb_mouse_on_list = 0;actb_removedisp();},actb_self.actb_timeOut);
	}
	function actb_table_highlight(){
		actb_mouse_on_list = 1;
		document.getElementById('tat_tr'+actb_pos).style.backgroundColor = actb_self.actb_bgColor;
		actb_pos = this.getAttribute('pos');
		while (actb_pos < actb_rangeu) actb_moveup();
		while (actb_pos > actb_ranged) actb_movedown();
		document.getElementById('tat_tr'+actb_pos).style.backgroundColor = actb_self.actb_hColor;
		if (actb_toid) clearTimeout(actb_toid);
		if (actb_self.actb_timeOut > 0) actb_toid = setTimeout(function(){actb_mouse_on_list = 0;actb_removedisp();},actb_self.actb_timeOut);
	}
	/* ---- */

	function actb_insertword(a){
		if (actb_self.actb_delimiter.length > 0){
			str = '';
			l=0;
			for (i=0;i<actb_delimwords.length;i++){
				if (actb_cdelimword == i){
					prespace = postspace = '';
					gotbreak = false;
					for (j=0;j<actb_delimwords[i].length;++j){
						if (actb_delimwords[i].charAt(j) != ' '){
							gotbreak = true;
							break;
						}
						prespace += ' ';
					}
					for (j=actb_delimwords[i].length-1;j>=0;--j){
						if (actb_delimwords[i].charAt(j) != ' ') break;
						postspace += ' ';
					}
					str += prespace;
					str += a;
					l = str.length;
					if (gotbreak) str += postspace;
				}else{
					str += actb_delimwords[i];
				}
				if (i != actb_delimwords.length - 1){
					str += actb_delimchar[i];
				}
			}
			actb_curr.value = str;
			setCaret(actb_curr,l);
		}else{
			actb_curr.value = a;
		}
		actb_mouse_on_list = 0;
		actb_removedisp();
	}
	function actb_penter(){
		if (!actb_display) return;
		actb_display = false;
		var word = '';
		var c = 0;
		for (var i=0;i<=actb_self.actb_keywords.length;i++){
			if (actb_bool[i]) c++;
			if (c == actb_pos){
				word = actb_self.actb_keywords[i];
				break;
			}
		}
		word = "\"" + word + "\"";
		actb_insertword(word);
		l = getCaretStart(actb_curr);
	}
	function actb_removedisp(){
		if (actb_mouse_on_list==0){
			actb_display = 0;
			if (document.getElementById('tat_table')){ document.body.removeChild(document.getElementById('tat_table')); }
			if (actb_toid) clearTimeout(actb_toid);
		}
	}
	function actb_keypress(e){
		if (actb_caretmove) stopEvent(e);
		return !actb_caretmove;
	}
	function actb_checkkey(evt){
		if (!evt) evt = event;
		a = evt.keyCode;
		caret_pos_start = getCaretStart(actb_curr);
		actb_caretmove = 0;
		switch (a){
			case 38:
				actb_goup();
				actb_caretmove = 1;
				return false;
				break;
			case 40:
				actb_godown();
				actb_caretmove = 1;
				return false;
				break;
			case 13: case 9:
				if (actb_display){
					actb_caretmove = 1;
					actb_penter();
					return false;
				}else{
					return true;
				}
				break;
			default:
				setTimeout(function(){actb_tocomplete(a)},50);
				break;
		}
	}

	function actb_tocomplete(kc){
		if (kc == 38 || kc == 40 || kc == 13) return;
		var i;
		if (actb_display){ 
			var word = 0;
			var c = 0;
			for (var i=0;i<=actb_self.actb_keywords.length;i++){
				if (actb_bool[i]) c++;
				if (c == actb_pos){
					word = i;
					break;
				}
			}
			actb_pre = word;
		}else{ actb_pre = -1};
		
		if (actb_curr.value == ''){
			actb_mouse_on_list = 0;
			actb_removedisp();
			return;
		}
		if (actb_self.actb_delimiter.length > 0){
			caret_pos_start = getCaretStart(actb_curr);
			caret_pos_end = getCaretEnd(actb_curr);
			
			delim_split = '';
			for (i=0;i<actb_self.actb_delimiter.length;i++){
				delim_split += actb_self.actb_delimiter[i];
			}
			delim_split = delim_split.addslashes();
			delim_split_rx = new RegExp("(["+delim_split+"])");
			c = 0;
			actb_delimwords = new Array();
			actb_delimwords[0] = '';
			for (i=0,j=actb_curr.value.length;i<actb_curr.value.length;i++,j--){
				if (actb_curr.value.substr(i,j).search(delim_split_rx) == 0){
					ma = actb_curr.value.substr(i,j).match(delim_split_rx);
					actb_delimchar[c] = ma[1];
					c++;
					actb_delimwords[c] = '';
				}else{
					actb_delimwords[c] += actb_curr.value.charAt(i);
				}
			}

			var l = 0;
			actb_cdelimword = -1;
			for (i=0;i<actb_delimwords.length;i++){
				if (caret_pos_end >= l && caret_pos_end <= l + actb_delimwords[i].length){
					actb_cdelimword = i;
				}
				l+=actb_delimwords[i].length + 1;
			}
			var ot = actb_delimwords[actb_cdelimword].trim(); 
			var t = actb_delimwords[actb_cdelimword].addslashes().trim();
		}else{
			var ot = actb_curr.value;
			var t = actb_curr.value.addslashes();
		}
		if (ot.length == 0){
			actb_mouse_on_list = 0;
			actb_removedisp();
		}
		if (ot.length < actb_self.actb_startcheck) return this;
		if (actb_self.actb_firstText){
			var re = new RegExp("^" + t, "i");
		}else{
			var re = new RegExp(t, "i");
		}

		actb_total = 0;
		actb_tomake = false;
		actb_kwcount = 0;
		for (i=0;i<actb_self.actb_keywords.length;i++){
			actb_bool[i] = false;
			if (re.test(actb_self.actb_keywords[i])){
				actb_total++;
				actb_bool[i] = true;
				actb_kwcount++;
				if (actb_pre == i) actb_tomake = true;
			}
		}

		if (actb_toid) clearTimeout(actb_toid);
		if (actb_self.actb_timeOut > 0) actb_toid = setTimeout(function(){actb_mouse_on_list = 0;actb_removedisp();},actb_self.actb_timeOut);
		actb_generate();
	}
	return this;
}