// fonction permettant de transformer les espaces en " and " et de filtrer les caractères accentués
function replaceChars(entry) {
	out = " "; // replace this
	add = "$and$"; // with this
	out2 = "$" ;// replace this (2nd part)
	add2 = " " ; // with this
	
	veaigu="é";
	vegrave="è";
	vecirc="ê";
	vetrem="ë";
	ve="e";

	vagrave="à";
	vacirc="â";
	va="a";

	vicirc="î";
	vitrem="ï";
	vi="i";

	vugrave="ù";
	vucirc="û";
	vutrem="ü";
	vu="u";

	vocirc="ô";
	vo="o";

	vcedil="ç"
	vc="c"

	temp = "" + entry; // temporary holder
	
	// effacer les blancs surnuméraires, en fin de chaine
	while (''+temp.charAt(temp.length-1)==' ') {
		temp = temp.substring(0, temp.length-1);
	}

	// 1ere étape : remplacer " " par "$and$"
	while (temp.indexOf(out)>-1) {
		pos= temp.indexOf(out);
		temp = "" + (temp.substring(0, pos) + add + 
		temp.substring((pos + out.length), temp.length));
	}

	// 2e étape : remplacer "$" par " "
	while (temp.indexOf(out2)>-1) {
	pos= temp.indexOf(out2);
	temp = "" + (temp.substring(0, pos) + add2 + 
	temp.substring((pos + out.length), temp.length));
	}
	
	// 3e étape : remplacer é par e
	while (temp.indexOf(veaigu)>-1) {
		pos= temp.indexOf(veaigu);
		temp = "" + (temp.substring(0, pos) + ve + 
		temp.substring((pos + 1), temp.length));
	}

	// 4e étape : remplacer è par e
	while (temp.indexOf(vegrave)>-1) {
		pos= temp.indexOf(vegrave);
		temp = "" + (temp.substring(0, pos) + ve + 
		temp.substring((pos + 1), temp.length));
	}

	// et ainsi de suite pour tous les caractères accentués
	while (temp.indexOf(vecirc)>-1) {
		pos= temp.indexOf(vecirc);
		temp = "" + (temp.substring(0, pos) + ve + 
		temp.substring((pos + 1), temp.length));
	}

	while (temp.indexOf(vetrem)>-1) {
		pos= temp.indexOf(vetrem);
		temp = "" + (temp.substring(0, pos) + ve + 
		temp.substring((pos + 1), temp.length));
	}

	while (temp.indexOf(vagrave)>-1) {
		pos= temp.indexOf(vagrave);
		temp = "" + (temp.substring(0, pos) + va + 
		temp.substring((pos + 1), temp.length));
	}
	
	while (temp.indexOf(vacirc)>-1) {
		pos= temp.indexOf(vacirc);
		temp = "" + (temp.substring(0, pos) + va + 
		temp.substring((pos + 1), temp.length));
	}

	while (temp.indexOf(vicirc)>-1) {
		pos= temp.indexOf(vicirc);
		temp = "" + (temp.substring(0, pos) + vi + 
		temp.substring((pos + 1), temp.length));
	}

	while (temp.indexOf(vitrem)>-1) {
		pos= temp.indexOf(vitrem);
		temp = "" + (temp.substring(0, pos) + vi + 
		temp.substring((pos + 1), temp.length));
	}

	while (temp.indexOf(vugrave)>-1) {
		pos= temp.indexOf(vugrave);
		temp = "" + (temp.substring(0, pos) + vu + 
		temp.substring((pos + 1), temp.length));
	}

	while (temp.indexOf(vucirc)>-1) {
		pos= temp.indexOf(vucirc);
		temp = "" + (temp.substring(0, pos) + vu + 
		temp.substring((pos + 1), temp.length));
	}

	while (temp.indexOf(vutrem)>-1) {
		pos= temp.indexOf(vutrem);
		temp = "" + (temp.substring(0, pos) + vu + 
		temp.substring((pos + 1), temp.length));
	}

	while (temp.indexOf(vocirc)>-1) {
		pos= temp.indexOf(vocirc);
		temp = "" + (temp.substring(0, pos) + vo + 
		temp.substring((pos + 1), temp.length));
	}

	while (temp.indexOf(vcedil)>-1) {
		pos= temp.indexOf(vcedil);
		temp = "" + (temp.substring(0, pos) + vc + 
		temp.substring((pos + 1), temp.length));
	}

return temp;
}


// Definition des paramètres permettant de construire la Query, qui ne contient pas de case à cocher
function construireRequete() {

	descriptifTheme=document.recherche.uniterme.value;
	
	req="";
	

	if(descriptifTheme!="") {
		req+=replaceChars(descriptifTheme);
	}
	
	
	return req;
}


					
function executerRecherche() {

	BaseHref="http://www.inrs.fr/inrs-pub/inrs01.nsf/";
	SearchView="inrs01_search_view";
	SearchOrder="4";
	SearchWV="True";
	SearchFuzzy="False";
	Start="1";
	Max="all";
	Count="200";

	StrRequete = construireRequete();

	urlRecherche = BaseHref + SearchView+"/?SearchView=" 
					+ "&Query="+StrRequete
					+ "&SearchMax="+Max
					+ "&Start="+Start
					+ "&SearchOrder="+SearchOrder
					+ "&SearchWV="+SearchWV
					+ "&SearchFuzzy="+SearchFuzzy
					+ "&Count="+Count;
frm=encodeURIComponent(urlRecherche);
window.open("frame_constr.html?frame="+frm,"_self");

}



/*B*/
function onKeyDownH(e)
{
   var output_string;

   switch (emod) {
   case "IE4+":
      e = window.event;
      /*C*/
      alt = (e.altKey) ? true : false;
      ctrl = (e.ctrlKey) ? true : false;
      shift = (e.shiftKey) ? true : false;

      output_string = " alt: "+alt+"\n ctrl: "+ctrl+"\n shift: "+shift;

      /*D*/
      if (e.keyCode == 13) {executerRecherche();}
   break;
   case "NN4":
      /*E*/
      alt = ((e.modifiers & Event.ALT_MASK) == Event.ALT_MASK);
      ctrl = ((e.modifiers & Event.CTRL_MASK) == Event.CTRL_MASK);
      shift = ((e.modifiers & Event.SHIFT_MASK) == Event.SHIFT_MASK);

      output_string = " alt: "+alt+"\n ctrl: "+ctrl+"\n shift: "+shift;

      /*F*/
      if (e.which == 13) {executerRecherche();}
   break;
   case "W3C":
      alt = (e.altKey) ? true : false;
      ctrl = (e.ctrlKey) ? true : false;
      shift = (e.shiftKey) ? true : false;

      output_string = " alt: "+alt+"\n ctrl: "+ctrl+"\n shift: "+shift;

      if (e.which == 13) {executerRecherche();}
   break;
	 }

   /*G*/
   return true;
}

function onloadH(e)
{
   /*get the event model*/
   emod = (e) ? (e.eventPhase) ? "W3C" : "NN4" : (window.event) ? "IE4+" : "unknown";

   /*A*/
   if (emod == "NN4") {
      document.captureEvents(Event.KEYDOWN); }

   document.onkeydown = onKeyDownH;
   return true;
}

/*define the event handler for the onload event*/
window.onload = onloadH;

/*global vars*/
var emod; /*the event model*/
var alt = false;
var ctrl = false;
var shift = false;

























function openRef(referenceInrs,ancre,nomFichier,targetCible){
	if(referenceInrs==null || referenceInrs=="") alert("Ce lien n'est pas actif");
	else {
		if(nomFichier==null || nomFichier=="")
		{
			if(ancre!="") ancre="#"+ancre;
			urlCible = "../../../IntranetObject-accesParReference/"+referenceInrs+"/$File/Visu.html"+ancre;
		}
		else {
			urlCible = "../../../IntranetObject-accesParReference/"+referenceInrs+"/$File/"+nomFichier;
		}
	}
	if(targetCible=="popup")
	{
		window.open(urlCible,'','width=640, height=480, left=150, top=75, resizable=yes, scrollbars=yes');
	}
	else {
		window.location.href = urlCible;
	}
}






function ExecRechPc(theme) {

	BaseHref="/inrs-pub/inrs01.nsf/"
	SearchView="inrs01_pc_view";
	SearchOrder="4";
	SearchWV="False";
	SearchFuzzy="False";
	Start="1";
	Max="all";
	Count="200";

	urlRecherche = BaseHref + SearchView+"/?SearchView=" 
					+ "&Query=([motsCles] CONTAINS "+theme+")"
					+ "&SearchMax="+Max
					+ "&Start="+Start
					+ "&SearchOrder="+SearchOrder
					+ "&SearchWV="+SearchWV
					+ "&SearchFuzzy="+SearchFuzzy
					+ "&Count="+Count;
	
	if (top.frames.length == 0) {
		opener.location.href = urlRecherche;
	}
	else {
		window.location.href = urlRecherche;
	}
}




