/*
catalogues = new Array("bib","vid");
intit = new Array();
intit['bib'] = new Array("Type de document ", "Auteur ", "Sujet ");
intit['vid'] = new Array("Genre ", "Réalisateur ", "Mots-clé ");
intit['col'] = new Array("Type d'objet ", "Auteur, artiste ", "Iconographie ");
intit['arc'] = new Array("Type d'objet ", "Auteur, artiste ", "Iconographie ");
intit['dsc'] = new Array("Type d'objet ", "Musicien ", "Thème ");
*/

/*
tri_champs = new Array("deno","aut","titre");
tri = new Array();
tri['col'] = new Array("type objet","auteur","titre");
tri['arc'] = new Array("type de document","photographe","titre");
tri['bib'] = new Array("type objet","auteur","titre");
tri['vid'] = new Array("genre","réalisateur","titre");
tri['dsc'] = new Array("genre","musicien","titre");
*/

function selectItem(li) {
//	if (li.extra) {
//		alert("That's '" + li.extra[0] + "' you picked.")
//	}
//        document.forms[0].elements[5].focus();
//      $("input[name='mots']").focus();
}

function formatItem(row) {
//	return row[0] + "<br><i>" + row[1] + "</i>";
	return row[0] + "&nbsp;(<i>" + row[1] + "</i>)";
}

/*
function modif_options(num) {
  for (i=0;i<3;i++)
    document.forms['formulaire'].tri.options[i] = new Option(tri[num][i],triv[i]);
}
*/

$(document).ready(function() {

  $("a.catalogue").click(function() {
    cat = $(this).attr("id");
    $("#recherche").load(this.href, function () {
        document.formulaire.deno.focus();
	});
    document.formulaire.catalog.value = cat;

    $("#catalogues > a").each(function(){
      if ($(this).attr("id")==cat) {
        $(this).removeClass("nonchoix");
        $(this).addClass("choix");
      }
      else {
        $(this).removeClass("choix");
        $(this).addClass("nonchoix");
      }
    });
	
    return false;
  });
/*
  $("input.saisie").each(function(){
    $(this).click(function(){
      chp = $(this).attr("name");
	  $("span." + chp).css("font-weight", "bold");
    });
  });
*/
  $("#catalogues > a").each(function(){
    cat = document.formulaire.catalog.value;
    if ($(this).attr("id")==cat) {
      $(this).removeClass("nonchoix");
      $(this).addClass("choix");
    }
    else {
      $(this).removeClass("choix");
      $(this).addClass("nonchoix");
    }
  });

    adresse = $("#" + cat).attr("href");
    $("#recherche").load(adresse);

/*
if (cat=="vid") {
  $("#denovid").autocomplete("liste.php", { minChars:1, matchSubset:1, matchContains:1, cacheLength:10, onItemSelect:selectItem, extraParams:{ chp:'deno', cat:'vid' }, formatItem:formatItem, selectOnly:1 });
  $("#autvid").autocomplete("liste.php", { minChars:2, matchSubset:1, matchContains:1, cacheLength:10, onItemSelect:selectItem, extraParams:{ chp:'aut', cat:'vid' }, formatItem:formatItem, selectOnly:1 });
  $("#titrevid").autocomplete("liste.php", { minChars:2, matchSubset:10, matchContains:1, cacheLength:10, onItemSelect:selectItem, extraParams:{ chp:'titre', cat:'vid' }, formatItem:formatItem, selectOnly:1 });
  $("#geovid").autocomplete("liste.php", { minChars:2, matchSubset:10, matchContains:1, cacheLength:10, onItemSelect:selectItem, extraParams:{ chp:'geo', cat:'vid' }, formatItem:formatItem, selectOnly:1 });
  $("#sujetvid").autocomplete("liste.php", { minChars:2, matchSubset:10, matchContains:1, cacheLength:10, onItemSelect:selectItem, extraParams:{ chp:'suj', cat:'vid' }, formatItem:formatItem, selectOnly:1 });
}
else if (cat=="bib") {
  $("#denobib").autocomplete("liste.php", { minChars:1, matchSubset:1, matchContains:1, maxItemsToShow:15, cacheLength:10, onItemSelect:selectItem, extraParams:{ chp:'deno', cat:'bib' }, formatItem:formatItem, selectOnly:1 });
  $("#autbib").autocomplete("liste.php", { minChars:2, matchSubset:1, matchContains:1, maxItemsToShow:15, cacheLength:10, onItemSelect:selectItem, extraParams:{ chp:'aut', cat:'bib' }, formatItem:formatItem, selectOnly:1 });
  $("#titrebib").autocomplete("liste.php", { minChars:2, matchSubset:10, matchContains:1, maxItemsToShow:15, cacheLength:10, onItemSelect:selectItem, extraParams:{ chp:'titre', cat:'bib' }, formatItem:formatItem, selectOnly:1 });
  $("#geobib").autocomplete("liste.php", { minChars:2, matchSubset:10, matchContains:1, maxItemsToShow:15, cacheLength:10, onItemSelect:selectItem, extraParams:{ chp:'geo', cat:'bib' }, formatItem:formatItem, selectOnly:1 });
  $("#sujetbib").autocomplete("liste.php", { minChars:2, matchSubset:10, matchContains:1, maxItemsToShow:15, cacheLength:10, onItemSelect:selectItem, extraParams:{ chp:'suj', cat:'bib' }, formatItem:formatItem, selectOnly:1 });
}
else if (cat=="col") {
  $("#denocol").autocomplete("liste.php", { minChars:1, matchSubset:1, matchContains:1, cacheLength:10, onItemSelect:selectItem, extraParams:{ chp:'deno', cat:'col' }, formatItem:formatItem, selectOnly:1 });
  $("#autcol").autocomplete("liste.php", { minChars:2, matchSubset:1, matchContains:1, cacheLength:10, onItemSelect:selectItem, extraParams:{ chp:'aut', cat:'col' }, formatItem:formatItem, selectOnly:1 });
  $("#titrecol").autocomplete("liste.php", { minChars:2, matchSubset:10, matchContains:1, cacheLength:10, maxItemsToShow:15, onItemSelect:selectItem, extraParams:{ chp:'titre', cat:'col' }, formatItem:formatItem, selectOnly:1 });
  $("#geocol").autocomplete("liste.php", { minChars:2, matchSubset:10, matchContains:1, cacheLength:10, onItemSelect:selectItem, extraParams:{ chp:'geo', cat:'col' }, formatItem:formatItem, selectOnly:1 });
  $("#sujetcol").autocomplete("liste.php", { minChars:2, matchSubset:10, matchContains:1, cacheLength:10, onItemSelect:selectItem, extraParams:{ chp:'suj', cat:'col' }, formatItem:formatItem, selectOnly:1 });
}
*/
});

