// Variables globales
var requete="";
var savreq="";
var question="";
var opet="";
var opou= "";
var flag=false;
//
function Accent(Terme) {
var ACCAPP = "CueaaaaceeeiiiAAEooouuyOUaiounN";
var ACCWIN = "ÇüéâäàåçêëèïîìÄÅÉôöòûùÿÖÜáíóúñÑ";
var i,j;
var CarAns,CarApp;
for (i=0; i<31; i++) {
	CarAns = ACCWIN.charAt(i);
	CarApp = ACCAPP.charAt(i);
        j=Terme.indexOf(CarAns,0);
	while ( j != -1) {
		Terme = Terme.replace(CarAns,CarApp);
        	j=Terme.indexOf(CarAns,0);
	}
}
return Terme;	
}
// Renvoi les termes de l'index
function IndexValue(Val,Target)
{
var chaine = "";
if (Target && Val) {
	// Mettre en commentaire les deux lignes suivantes si on ne veut pas recuperer les
	// termes existants dans la zone de texte
	chaine = eval("document.GENISIS."+Target+".value");
	if (chaine) Val = Val + ';' + chaine;
	eval("document.GENISIS."+Target+'.value=Val');
}
msg.close();
}
// Ouverture fenetre PopUp - Left=100, Top=100 
function OpenWindow(LURL,Lgx,Lgy) {
	msg=open("","Help","location=no,status=no,toolbar=no,directories=no,resizable=yes,menubar=no,scrollbars=yes,height="+Lgx+",width="+Lgy+",left=100,top=100");	
  	msg.location.href=LURL;
  	msg.focus();
}
// Reinitialise le formulaire
function ResetForm() {
	document.GENISIS.reset();
}
// Lire une "Textbox"
function ReadTextBox(CTL,UNI) {
	var src = document.GENISIS.elements[CTL].value;
	if (UNI) { 
		i=src.indexOf(" ",0);
		while ( i != -1) {
			src = src.replace(" ",";");
        		i=src.indexOf(" ",0);
		}
	}
	return src;
}
// Mise en forme requete
// CRI = Opérateur entre champs
// CTL = Element du formulaire (retour d'une fonction)
// TRN = Troncature (caractere $)
// LIB = Libellé en clair
// CDS = Etiquette ISIS
// PRF = Préfixe
// OPE = Opérateur entre articles
function MakeRequest(CRI,CTL,TRN,LIB,CDS,PRF,OPE) {
var but="";
var aff="";
var bis="";
var act="";
var actp = "";
var mot="";
if (OPE==" AND ") {
	act=opet;
} else {
	act=opou;
}
if (CRI==" AND ") {
	actp=opet;
} else {
	actp=opou;
}
decoupe=CTL.split(";");
for (var i in decoupe) {
if (decoupe[i]) {
	mot=Accent(decoupe[i]);
	if (but) {
		but = but + OPE + "\"" + PRF + mot + TRN + "\"" + CDS;
		bis = bis + OPE + "#" + PRF + mot + TRN + "#" + CDS;
		aff = aff + act + decoupe[i];
	} else {
		but = "\"" + PRF + mot + TRN + "\"" + CDS;
		bis = "#" + PRF + mot + TRN + "#" + CDS;
		aff = decoupe[i];
	}
}
}
if (but) {
	aff = "(" + LIB + "=" + aff + ")";
	flag=true;
	if (requete) {
		requete = requete+CRI+"("+but+")";
		savreq = savreq+CRI+"("+bis+")";
	} else {
		requete = "("+but+")";
		savreq = "("+bis+")";
	}
	if (question) {
		question = question+actp+aff;
	} else {
		question = aff;
	}
}
}
// Mise en forme requete
// CTL = Element du formulaire (retour d'une fonction)
// TRN = Troncature (caractere $)
// LIB = Libellé en clair
// CDS = Etiquette ISIS
// PRF = Préfixe
// OPE = Opérateur
function MakeRequestMulti(CRI,CTL,CMB,OPE) {
var chaine="";
chaine=ReadListSimple(CMB);
decoupe=chaine.split("|");
MakeRequest(CRI,ReadTextBox(CTL,decoupe[3]),decoupe[2],decoupe[0],decoupe[1],decoupe[4],OPE);
}

// Lecture "checkBox"
function ReadCheckBox(CTL,IND) {
var terme="";
for (var i=0; i<IND; i++) {
	if (document.GENISIS.elements[CTL][i].checked) {
	if (terme) {
		terme=terme+";"+document.GENISIS.elements[CTL][i].value;
	} else {
		terme=document.GENISIS.elements[CTL][i].value;
	}}
}
return terme;
}
// Lecture "Bouton Radio"
function ReadRadio(CTL) {
for (var i=0; i<document.GENISIS.elements[CTL].length; i++) {
if (document.GENISIS.elements[CTL][i].checked ) return document.GENISIS.elements[CTL][i].value;
}
return "";
}
// Lecture "Liste multiple"
function ReadListMulti(CTL) {
var terme = "";
for (var i=0; i<document.GENISIS.elements[CTL].length; i++) {
if (document.GENISIS.elements[CTL].options[i].selected) {
if (terme == "") {
	terme=document.GENISIS.elements[CTL].options[i].value;
} else {
	terme=terme+";"+document.GENISIS.elements[CTL].options[i].value;
}}}
return terme;
}
// Lecture "Liste simple"
function ReadListSimple(CTL) {
	i=document.GENISIS.elements[CTL].options.selectedIndex;
	if (i < 0) return "";
	return document.GENISIS.elements[CTL].options[i].value;
}
// Ouverture d'un index
// CDS = etiquette isis
// RET = zone texte de retour
// FIC = 0=Base ISIS,1=Image index Index
// TIT = Titre de la fenetre
// PFX = Prefixe
// POS = Premier terme - pour éviter les chiffres
// SMP = 1=Index long, 0=Index court 
// LgX = Largeur fenetre
// LgY = Hauteur fenetre
// PosX = Position LEFT
// PosY = Position TOP
function OpenIndex(CDS,RET,FIC,TIT,PFX,POS,SMP,LgX,LgY,PosX,PosY) {
	var URL=document.REQUEST.t2009.value+"/[in=genisis"+document.REQUEST.t2013.value+"1.in]/";
	if ( FIC == 0 ) {
		URL=URL + "?t2005=" + escape(document.REQUEST.t2005.value);
	} else {
		URL=URL + "?t2005=" + escape(document.REQUEST.t2015.value);
	}
	URL=URL + "&t2006=" + escape(document.REQUEST.t2006.value);
	if (SMP == 1) {
		URL=URL + "&t2008=" + document.REQUEST.t2008.value;
	} else {
		URL=URL + "&t2008=100";
	}
	URL=URL + "&t2009=" + document.REQUEST.t2009.value;
	URL=URL + "&t2010=" + escape(document.REQUEST.t2010.value);
	URL=URL + "&t2011=" + escape(document.REQUEST.t2011.value);
	URL=URL + "&t2012=" + escape(document.REQUEST.t2012.value);
	URL=URL + "&t2013=" + document.REQUEST.t2013.value;
	URL=URL + "&t2014=" + CDS;
	URL=URL + "&t2015=" + RET;
	URL=URL + "&t2016=" + POS;
	URL=URL + "&t2017=" + Accent(TIT);
	URL=URL + "&t2018=" + PFX;
	URL=URL + "&t2020=" + SMP;
	msg=window.open(URL,"Index","location=no,status=no,toolbar=no,directories=no,resizable=yes,menubar=no,scrollbars=yes,height="+LgX+",width="+LgY+",left="+PosX+",top="+PosY);	
  	msg.focus();
}
// Ouverture index multiple
// CTL = Nom de la combobox à utiliser
// RET = zone texte de retour
// LgX = Largeur fenetre
// LgY = Hauteur fenetre
// PosX = Position LEFT
// PosY = Position TOP
function OpenIndexMulti(RET,CTL,LgX,LgY,PosX,PosY) {
	var chaine="";
	chaine=ReadListSimple(CTL);
	decoupe=chaine.split("|");	
	OpenIndex(decoupe[7],RET,decoupe[6],decoupe[5],decoupe[4],"",decoupe[8],LgX,LgY,PosX,PosY);
}
