
var tableauTri = new Array();

function checkValeursPourleTri(first)
{

	//tabIndexVisibles = indexVisibles.split(",");
	var listeTri = document.getElementById("tri_recherche_tourisme");


	// mettre dans un tableau tous les éléments de la liste déroulante
	if(first==true) {
		for(var i=0; i<listeTri.length; i++) {
			var itemListeTri = listeTri[i];
			tableauTri.push(new Array(itemListeTri.id, itemListeTri.value, itemListeTri.text, itemListeTri.selected, itemListeTri.className));
		}
	}


	// vider la liste
	listeTri.length = 0;


	// mettre le lieu
	var lieu = document.createElement('option');
	var indexLieu = 0;
  lieu.id = (tableauTri[indexLieu])[0];
  lieu.value = (tableauTri[indexLieu])[1];
  lieu.text = (tableauTri[indexLieu])[2];
  lieu.selected = (tableauTri[indexLieu])[3];
  try {listeTri.add(lieu, null);}
  catch(ex) {listeTri.add(lieu);}


	// mettre la thématique si besoin
	var indexThematique = getTabIndex('thematique');
	var thematiques = trim(document.getElementById('thematiques').value);
	if(thematiques == (tableauTri[indexThematique])[4])
	{
		var thematique = document.createElement('option');

		thematique.id = (tableauTri[indexThematique])[0];
	  thematique.value = (tableauTri[indexThematique])[1];
	  thematique.text = (tableauTri[indexThematique])[2];
	  thematique.selected = (tableauTri[indexThematique])[3];
	  try {listeTri.add(thematique, null);}
	  catch(ex) {listeTri.add(thematique);}
	}



	// mettre la province si besoin
	var provinces = trim(document.getElementById('provinces').value);
	if(provinces == '')
	{
		var province = document.createElement('option');
		var indexProvince = getTabIndex('province');
		province.id = (tableauTri[indexProvince])[0];
	  province.value = (tableauTri[indexProvince])[1];
	  province.text = (tableauTri[indexProvince])[2];
	  province.selected = (tableauTri[indexProvince])[3];
	  try {listeTri.add(province, null);}
	  catch(ex) {listeTri.add(province);}
	}



	// mettre le mot clé si besoin
	var mots = trim(document.getElementById('mots').value);
	if(mots != '')
	{
		var motCle = document.createElement('option');
		var indexMotCle = getTabIndex('mot_cle');
		motCle.id = (tableauTri[indexMotCle])[0];
	  motCle.value = (tableauTri[indexMotCle])[1];
	  motCle.text = (tableauTri[indexMotCle])[2];
	  motCle.selected = (tableauTri[indexMotCle])[3];
	  try {listeTri.add(motCle, null);}
	  catch(ex) {listeTri.add(motCle);}
	}
}


function getTabIndex(id)
{
	for(var i=0; i<tableauTri.length; i++) {
		var item = tableauTri[i];
		if(item[0] == id) return i;
	}
	return -1;
}

function trim(string) {
	return string.replace(/(^\s*)|(\s*$)/g,'');
}


/*
function tmp(item, valueEmpty)
{
	if(item=='mots') {
		var value = trim(document.getElementById(item).value);
		if(value == valueEmpty) {
			document.getElementById("mot_cle").style.display="none";
			document.getElementById("mot_cle").selected="";
		}
		else {
			document.getElementById("mot_cle").style.display="block";
		}
	}



	else if(item=='provinces') {
		var value = trim(document.getElementById(item).value);
		if(value == valueEmpty) {
			document.getElementById("province").style.display="block";
		}
		else {
			document.getElementById("province").style.display="none";
			document.getElementById("province").selected="";
		}
	}


	else if(item=='thematiques') {
		var value = trim(document.getElementById(item).value);
		if(value == valueEmpty) {
			document.getElementById("thematique").style.display="block";
		}
		else {
			document.getElementById("thematique").style.display="none";
			document.getElementById("thematique").selected="";
		}
	}
}*/


