// JavaScript Document

// Messages d'erreur
var ERROR_VIDE="Vous devez saisir un ou des mots clés ou une date."
var ERROR_CHOIX="Vous devez sélectionner un tribunal ou un organisme."
var ERROR_SWORD="Votre recherche contient l'un des mots suivants : l', le, la, les, d', du, de, des, un, une, c', ce, ces, cette, n', ne, s', se, sa, ses, il, ils, elle, elles, qu', que. Veuillez refaire votre recherche en les omettant. Consultez l'aide pour plus d'information."

var NS = (window.Event) ? 1 : 0;
if (!NS) document.onkeypress = checkKey;


function checkKey(e) {
  var code = (NS) ? e.which : event.keyCode;
  if( code == 13 ) ListeMC();
}


function erase () {
	if(document.getElementById("listemc_cour"))
		document.listemc.cour.selectedIndex=0;
	document.listemc.mots_cles.value="";
	document.listemc.champs.selectedIndex=0;
	document.listemc.date.value="";
}


function HidePage() {
   if (document.getElementById){
   		document.getElementById("waitmsg").style.display = "";
   		document.getElementById("searchpage").style.display = "none";
   }
}

function ListeMC () {
	var fixedStr;
	var fixedStr2;
	var strSearch;
	 
	// recherche vide
	if (document.listemc.mots_cles.value == "" && document.listemc.date.value == "") {
		error(document.listemc.mots_cles, ERROR_VIDE, 1);
		return;
	}

	var selectmenu=document.getElementById("listemc_cour");
	var courid=selectmenu.options[selectmenu.selectedIndex].value;

	var radiotri=document.listemc.tri;
	var tri="pert";
	for (i=0;i<radiotri.length;i++) {
		if (radiotri[i].checked) {
			tri = radiotri[i].value;
		}
	}

	if (validate_search_generic (document.listemc.mots_cles) == "_CANCEL_SEARCH_" ) return;
	foundStopword=0;
	fixedStr = fix_search_stopword(document.listemc.mots_cles.value);
	if (foundStopword > 0) {
			error(document.listemc.mots_cles, ERROR_SWORD, 0);
			return;
			//alert("Erreur No" + gGoThrough);
			//gGoThrough = true;
	}	
	//alert("stopword :\n\n" + fixedStr);
	fixedStr = fix_search_generic(document.listemc.mots_cles.value);
	//alert("fix_search_generic :\n\n" + fixedStr2);
	fixedStr2 = fix_search_motscle(fixedStr);
	fixDate = fix_search_date(document.listemc.date.value);
	if (fixDate == "_CANCEL_SEARCH_" ) return;

	if (gGoThrough > 0) {
			//error(document.listemc.mots_cles, ERROR_SWORD, 0);
			alert("Erreur No" + gGoThrough);
			gGoThrough = true;
	}
	else {
		strSearch = courid + "_" + fixedStr2 + "_" + document.listemc.champs.selectedIndex;
		strSearch += "_" + fixDate;
		strSearch += "_" + tri;
		HidePage();
		strSearch = "/index.php?type=listemc&recher=" + strSearch;
		location = strSearch;
	}
}


function ListeC () {
	var strSearch;
	
	// Option du menu qui n'est pas un tribunal
	var selectmenu=document.getElementById("listec_cour");
	var courid=selectmenu.options[selectmenu.selectedIndex].value;

	var radiotri=document.listec.tri;
	var tri="date";
	for (i=0;i<radiotri.length;i++) {
		if (radiotri[i].checked) {
			tri = radiotri[i].value;
		}
	}

	strSearch = courid + "_" + document.listec.annee.options[document.listec.annee.selectedIndex].value;
	strSearch += document.listec.mois.options[document.listec.mois.selectedIndex].value;
	strSearch += "_" + tri;
	
	HidePage();
	strSearch = "/index.php?type=listec&recher=" + strSearch;
	location = strSearch;
}


// EX:  error(document.form.elements[i], "Champ obligatoire non rempli.", 1);
function error(objet, msg, area) {
   erreur = true;
   alert(msg);
   objet.focus();
   if (document.all) {
      if (area==1)
         objet.style.background="#C0C0FF";
      if (area==2)
         objet.style.color="#CC3300";
   }
}


function nocolor(obj) {
   if (document.all) {
      obj.style.background="white";
      obj.style.color="black";
   }
}


function selectdefault (obj, value) {
	for (var i=0; i < obj.length; i++) {
		if (obj.options[i].value == value) {
			obj.selectedIndex=i;  
			return;
		}
	} 
}

function MakeLink(argFrame,argID,argKey,argClass,argOverClass,argOutClass,argOnClick,argTexte,argAutreAttribut) {
	// Version pour le SJ
	document.write(argTexte);  
}

function signet(url, title){
	
	if (window.sidebar) // firefox
		window.sidebar.addPanel(title, url, "");
	else if(window.opera && window.print){ // opera
		var elem = document.createElement('a');
		elem.setAttribute('href',url);
		elem.setAttribute('title',title);
		elem.setAttribute('rel','sidebar');
		elem.click();
	}
	else if(document.all)// ie
		window.external.AddFavorite(url, title);
}
