//-----------------------------------------------------------------------
// Finds query variable - nothing else
function FindQueryVar(i_strQueryName)
{
    var a, b, c;
    for(a=Queries.length-1; a>=0; a--) 
    {      
        if (Queries[a].name == i_strQueryName) 
           break;
    } 
    
    if (a<0) 
        alert("Queries for " + i_strQueryName + " not defined!");
   return a; 
}
//---------------------------------------------------------------------
// 
function FindDBaseVar(i_strDBaseName)
{
    var a,b,c;
    for (a = DBases.length -1 ; a >= 0 ; a-- )
    {
        if (DBases[a].dbname == i_strDBaseName)
            break;
    }
    if (a<0)
        alert ("DBase not found : "+ i_strDBaseName);
    return a;
}

//---------------------------------------------------------------------
// This function creates entry in dbases table
function DBase(n, v, u, c_r, m_r)
{
 this.dbname=n;
 this.view=v;
 this.use=u;
 this.current_results=c_r;
 this.max_results=m_r;

 return (this);
}

//---------------------------------------------------------------------
// returns url and search string for document
function GetArnoDocLink( qname, prsid , docid, rank)
{    
    var a = FindQueryVar(qname);
    
    // Here difference between PLWeb & TAWeb
    // TAWeb version
    url = "/arn-cgi/doc_post_doc.pl?x=d&o=l&v=" + this.dbname 
            + "&q=" + Queries[a].text 
            + "&e=" + this.dbname + "." + docid + "." + rank 
            + "&s=" + this.dbname + "prs" + "(" + prsid + ":NUM1)";
    // PLWeb version
    /*url = "/arn-cgi/doc_post_doc.pl?view=" + this.dbname 
            + "&query=" + Queries[a].text 
            + "&doc=" + this.dbname + ":" + docid + ":" + rank 
            + "&search=" + this.dbname + "prs:" + "(" + prsid + ":NUM1)";
    */        
    return url;
}
//---------------------------------------------------------------------
function GetNatDocLink( qname, prsid , docid, rank)
{    
    var a = FindQueryVar(qname);
    
    // Here difference between PLWeb & TAWeb
    // TAWeb version
    url = "/arn-cgi/doc_post_doc.pl?x=d&o=l&v=" + this.dbname 
            + "&q=" + Queries[a].text 
            + "&s=" + this.dbname + "prs" + "(" + prsid + ":LOGREF_1)";
    // PLWeb version
    /*url = "/arn-cgi/doc_post_doc.pl?view=" + this.dbname 
            + "&query=" + Queries[a].text 
            + "&search=" + this.dbname + "prs:" + "(" + prsid + ":LOGREF_1)";
    */
    return url;
}
//---------------------------------------------------------------------
function GetProfDocLink( qname, prsid , docid, rank)
{    
    var a = FindQueryVar(qname);
    
    // Here difference between PLWeb & TAWeb
    // TAWeb version
    url = "/arn-cgi/doc_post_doc.pl?x=d&o=l&v=" + this.dbname 
            + "&q=" + Queries[a].text 
            + "&e=" + this.dbname + "." + docid + "." + rank 
            + "&s=" + this.dbname + "prs" + "(" + prsid + ":REFGUR_1)";
    // PLWeb version
    /*url = "/arn-cgi/doc_post_doc.pl?view=" + this.dbname 
            + "&query=" + Queries[a].text 
            + "&doc=" + this.dbname + ":" + docid + ":" + rank 
            + "&search=" + this.dbname + "prs:" + "(" + prsid + ":REFGUR_1)";
    */
    return url;
}
//---------------------------------------------------------------------
function GetSingleDocLink( qname, prsid , docid, rank)
{
    var a = FindQueryVar(qname);
    
    // Here difference between PLWeb & TAWeb
    // TAWeb version
    url = "/arn-cgi/doc_post_doc.pl?x=d&o=l&v=" + this.dbname 
            + "&q=" + Queries[a].text 
            + "&e=" + this.dbname + "." + docid + "." + rank;
    // PLWeb version
    /*url = "/arn-cgi/doc_post_doc.pl?view=" + this.dbname 
          + "&query=" + Queries[a].text 
          + "&doc=" + this.dbname + ":" + docid + ":"+rank;   
    */
    return url;
}
//---------------------------------------------------------------------

//---------------------------------------------------------------------
// This function initializes DBases table
function InitDBases()
{
 DBases[0] = new DBase("Arcade",   "VArcade",     false,    0, 50);
 DBases[0].GetDocLink = GetSingleDocLink;
 DBases[1] = new DBase("Arno1551", "VArno1551",   false,    0, 50);
 DBases[1].GetDocLink = GetArnoDocLink;
 DBases[2] = new DBase("Arno1751", "VArno1751",   false,    0, 50);
 DBases[2].GetDocLink = GetArnoDocLink;
 DBases[3] = new DBase("Arno1761", "VArno1761",   false,    0, 50);
 DBases[3].GetDocLink = GetArnoDocLink;
 DBases[4] = new DBase("Arno1851", "VArno1851",   false,    0, 50);
 DBases[4].GetDocLink = GetArnoDocLink;
 DBases[5] = new DBase("Leonore",  "VLeonore",    false,    0, 50);
 DBases[5].GetDocLink = GetSingleDocLink;
 DBases[6] = new DBase("Nat",      "VNat",        false,    0, 50);
 DBases[6].GetDocLink = GetNatDocLink;
 DBases[7] = new DBase("Prof",     "VProf",       false,    0, 50);
 DBases[7].GetDocLink = GetProfDocLink;
 DBases[8] = new DBase("Quidam",     "VQuidam",   false,    0, 50);
 DBases[8].GetDocLink = GetSingleDocLink;
}


//---------------------------------------------------------------------
// This function initializes Queries table Arcade entry
function QArcade()
{
 this.name = "Arcade";
 this.ARTISES_EX_FL = "";
 this.TITRE_EX_FL = "";
 this.THEME_EX_FL = "";
 this.TYPE_EX_FL = "";
 this.LOCALISATION_EX_FL = "";
 this.COTE_EX_FL = "";
 this.free = "";
 this.free_fld = "EXPO_1";
 this.LIBRE = "";
 this.RPP = "10";
 this.text = "";
}

//---------------------------------------------------------------------
// This function create CPL Query from  
function BuildArcadeQuery()
{
    var query = "";
    if (this.ARTISES_EX_FL) 
        query += "(" + this.ARTISES_EX_FL + "):ARTISES_EX_FL ";
    if (this.TITRE_EX_FL) 
        query += "(" + this.TITRE_EX_FL + "):TITRE_EX_FL ";
    if (this.THEME_EX_FL) 
        query += "(" + this.THEME_EX_FL + "):THEME_EX_FL ";
    if (this.TYPE_EX_FL) 
        query += "(" + this.TYPE_EX_FL + "):TYPE_EX_FL ";
    if (this.LOCALISATION_EX_FL) 
        query += "(" + this.LOCALISATION_EX_FL + "):LOCALISATION_EX_FL ";
    if (this.COTE_EX_FL) 
        query += "(" + this.COTE_EX_FL + "):COTE_EX_FL ";
    if (this.free && this.free_fld) 
        query += "(" + this.free + "):"+ this.free_fld+ " ";
    if (this.LIBRE) 
        query += this.LIBRE ;
    this.text = escape (query);
}

//---------------------------------------------------------------------
// This function initializes Queries table Arno entry
function QArno()
{
 this.name = "Arno";
 this.DATE_EX_FL1 = "";
 this.DATE_EX_FL2 = "";
 this.NOM_EX_FL = "";
 this.PNOM1 = "";
 this.OBJET_EX_FL = "";
 this.LIEU_EX_FL = "";
 this.NATURE_EX_FL = "";
 this.QUALITAT_EX_FL = "";
 this.PROF_EX_FL = "";
 this.DOMIC_EX_FL = "";
 this.free = "";
 this.free_fld = "padrl";
 this.LIBRE = "";
 this.RPP = "10";
 this.text = "";
}

//---------------------------------------------------------------------
// This function create CPL Query from content of obj  
function BuildArnoQuery()
{
    var query = "";
    if (this.DATE_EX_FL1) {
       if (this.DATE_EX_FL2) {
          query += "(" + this.DATE_EX_FL1 + "<DATE_EX_FL<"  + this.DATE_EX_FL2 + ") ";
       } else {
          query += "(DATE_EX_FL>" + this.DATE_EX_FL1 + ") ";
       }
    } else if (this.DATE_EX_FL2) {
       query += "(DATE_EX_FL<" + this.DATE_EX_FL2 + ") ";
    }
    if (this.NOM_EX_FL) 
        query += "(" + this.NOM_EX_FL + "):NOM_EX_FL ";
    if (this.PNOM1) 
        query += "(" + this.PNOM1 + "):PNOM1 ";
    if (this.OBJET_EX_FL) 
        query += "(" + this.OBJET_EX_FL + "):OBJET_EX_FL ";
    if (this.LIEU_EX_FL) 
        query += "(" + this.LIEU_EX_FL + "):LIEU_EX_FL ";
    if (this.NATURE_EX_FL) 
        query += "(" + this.NATURE_EX_FL + "):NATURE_EX_FL ";
    if (this.QUALITAT_EX_FL) 
        query += "(" + this.QUALITAT_EX_FL + "):QUALITAT_EX_FL ";
    if (this.PROF_EX_FL) 
        query += "(" + this.PROF_EX_FL + "):PROF_EX_FL ";
    if (this.DOMIC_EX_FL) 
        query += "(" + this.DOMIC_EX_FL + "):DOMIC_EX_FL ";
    if (this.free && this.free_fld) 
        query += "(" + this.free + "):"+ this.free_fld+ " ";
    if (this.LIBRE) 
        query += this.LIBRE ;
    this.text = escape (query);
}

//---------------------------------------------------------------------
// This function initializes Queries table Nat entry
function QNat()
{
   this.name = "Nat";
   this.NOM_EX_FL = "";
   this.PRENOMS_EX_FL = "";
   this.DATE_NSS_EX_FL1 = "";
   this.DATE_NSS_EX_FL2 = "";
   this.LIEU_NSS_EX_FL = "";
   this.PAY_NSS_EX_FL = "";
   this.PROF_EX_FL = "";
   this.DOMIC_EX_FL = "";
   this.OUDOS_EX_FL1 = "";
   this.OUDOS_EX_FL2 = "";
   this.NUMDOS_EX_FL = "";
   this.OBJ_EX_FL = "";
   this.LIBRE = "";
   this.RPP = "10";
   this.text = "";
}

//---------------------------------------------------------------------
// This function create CPL Query from content of obj  
function BuildNatQuery()
{
    var query = "";
    if (this.NOM_EX_FL) 
        query += "(" + this.NOM_EX_FL + "):NOM_EX_FL ";
    if (this.PRENOMS_EX_FL) 
        query += "(" + this.PRENOMS_EX_FL + "):PRENOMS_EX_FL ";
    if (this.DATE_NSS_EX_FL1) {
       if (this.DATE_NSS_EX_FL2) {
          query += "(" + this.DATE_NSS_EX_FL1 + "<DATE_NSS_EX_FL<"  + this.DATE_NSS_EX_FL2 + ") ";
       } else {
          query += "(DATE_NSS_EX_FL>" + this.DATE_NSS_EX_FL1 + ") ";
       }
    } else if (this.DATE_NSS_EX_FL2) {
       query += "(DATE_NSS_EX_FL<" + this.DATE_NSS_EX_FL2 + ") ";
    }
    if (this.LIEU_NSS_EX_FL) 
        query += "(" + this.LIEU_NSS_EX_FL + "):LIEU_NSS_EX_FL ";
    if (this.PAY_NSS_EX_FL) 
        query += "(" + this.PAY_NSS_EX_FL + "):PAY_NSS_EX_FL ";
    if (this.PROF_EX_FL) 
        query += "(" + this.PROF_EX_FL + "):PROF_EX_FL ";
    if (this.DOMIC_EX_FL) 
        query += "(" + this.DOMIC_EX_FL + "):DOMIC_EX_FL ";
    if (this.OUDOS_EX_FL1) {
       if (this.OUDOS_EX_FL2) {
          query += "(" + this.OUDOS_EX_FL1 + "<OUDOS_EX_FL<"  + this.OUDOS_EX_FL2 + ") ";
       } else {
          query += "(OUDOS_EX_FL>" + this.OUDOS_EX_FL1 + ") ";
       }
    } else if (this.OUDOS_EX_FL2) {
       query += "(OUDOS_EX_FL<" + this.OUDOS_EX_FL2 + ") ";
    }
    if (this.NUMDOS_EX_FL) 
            query += "(" + this.NUMDOS_EX_FL + "):NUMDOS_EX_FL ";
    if (this.OBJ_EX_FL) 
            query += "(" + this.OBJ_EX_FL + "):OBJ_EX_FL ";
    if (this.LIBRE) 
            query += this.LIBRE ;
    
    this.text = escape (query);
}

//---------------------------------------------------------------------
// This function initializes Queries table Leonore entry
function QLeonore()
{
   this.name = "Leonore";
   this.NOM_EX_FL = "";
   this.PRENOM_EX_FL = "";
   this.LIEU_EX_FL = "";
   this.NSS_EX_FL = "";
   this.LIBRE = "";
   this.RPP = "10";
   this.text = "";
}

//---------------------------------------------------------------------
//
function BuildLeonoreQuery()
{
   var query = "";
   if (this.NOM_EX_FL) 
        query += "(" + this.NOM_EX_FL + "):NOM_EX_FL ";
    if (this.PRENOM_EX_FL) 
        query += "(" + this.PRENOM_EX_FL + "):PRENOM_EX_FL ";
    if (this.LIEU_EX_FL) 
        query += "(" + this.LIEU_EX_FL + "):LIEU_EX_FL ";
    if (this.NSS_EX_FL) 
        query += "(" + this.NSS_EX_FL + "):NSS_EX_FL ";
    if (this.LIBRE) 
        query += this.LIBRE;
    this.text = escape (query);

}

//---------------------------------------------------------------------
// This function initializes Queries table Leonore entry
function QProf()
{
   this.name = "Prof";
   this.PERS_EX_FL = "";
   this.LIEUX_EX_FL = "";
   this.QUALITE_EX_FL = "";
   this.INSTIT_EX_FL = "";
   this.DATE_EX_FL = "";
   this.RPP = "10";
   this.text = "";
}

//---------------------------------------------------------------------
//
function BuildProfQuery()
{
    var query = "";
    if (this.PERS_EX_FL) 
        query += "(" + this.PERS_EX_FL + "):PERS_EX_FL ";
    if (this.LIEUX_EX_FL) 
        query += "(" + this.LIEUX_EX_FL + "):LIEUX_EX_FL ";
    if (this.QUALITE_EX_FL) 
        query += "(" + this.QUALITE_EX_FL + "):QUALITE_EX_FL ";
    if (this.INSTIT_EX_FL) 
        query += "(" + this.INSTIT_EX_FL + "):INSTIT_EX_FL ";
    if (this.DATE_EX_FL) 
       query += "(" + this.DATE_EX_FL + "):DATE_EX_FL ";
    this.text = escape (query);

}


//---------------------------------------------------------------------
// This function initializes Queries table Quidam entry
function QQuidam()
{
   this.name = "Quidam";
   this.NOM_DE_PERSONNES_EX_FL = "";
   this.PRENOMS_EX_FL = "";
   this.DATE_NSS_EX_FL = ""; 
   this.DATE_DDS_EX_FL = "";
   this.DATE_NOMIN_EX_FL = "";
   this.QUALITE_EX_FL = "";
   this.COTE_EX_FL = "";
   this.LIBRE = "";
   this.SEARCH_GROUPE = "";
   this.RPP = "10";
   this.text = "";
}

//---------------------------------------------------------------------
//
function BuildQuidamQuery()
{
   var query = "";
   if (this.NOM_DE_PERSONNES_EX_FL) 
        query += "(" + this.NOM_DE_PERSONNES_EX_FL + "):NOM_DE_PERSONNES_EX_FL ";
    if (this.PRENOMS_EX_FL) 
        query += "(" + this.PRENOMS_EX_FL + "):PRENOMS_EX_FL ";
    if (this.DATE_NSS_EX_FL) 
        query += "(" + this.DATE_NSS_EX_FL + "):DATE_NSS_EX_FL ";
    if (this.DATE_DDS_EX_FL) 
        query += "(" + this.DATE_DDS_EX_FL + "):DATE_DDS_EX_FL ";
    if (this.DATE_NOMIN_EX_FL) 
        query += "(" + this.DATE_NOMIN_EX_FL + "):DATE_NOMIN_EX_FL ";
    if (this.QUALITE_EX_FL) 
        query += "(" + this.QUALITE_EX_FL + "):QUALITE_EX_FL ";
    if (this.COTE_EX_FL) 
        query += "(" + this.COTE_EX_FL + "):COTE_EX_FL ";
    if (this.SEARCH_GROUPE) 
        query += "(" + this.SEARCH_GROUPE + "):SEARCH_GROUPE ";
    if (this.LIBRE) 
        query += this.LIBRE;
    this.text = escape (query);
}


//---------------------------------------------------------------------
// This function initializes Queries table Prof entry
function QAll()
{
   this.name = "All";
   this.NOMS_DE_PERSONNES_FL = "";
   this.NOMS_DE_LIEUX_FL = "";
   this.MATIERES_FL = "";
   this.DATES_FL = "";
   this.LIBRE = "";
   this.RPP = "10";
   this.text = "";
}

//---------------------------------------------------------------------
// This function create CPL Query from  
function BuildAllQuery()
{
    var query = "";
    if (this.NOMS_DE_PERSONNES_FL) {
       query += "(" + this.NOMS_DE_PERSONNES_FL + "):NOMS_DE_PERSONNES_FL ";
    }
    if (this.NOMS_DE_LIEUX_FL) {
       query += "(" + this.NOMS_DE_LIEUX_FL + "):NOMS_DE_LIEUX_FL ";
    }
    if (this.MATIERES_FL) {
       query += "(" + this.MATIERES_FL + "):MATIERES_FL "; 
    }
    if (this.DATES_FL) {
       query += "(" + this.DATES_FL + "):DATES_FL "; 
    }
    if (this.LIBRE) {
       query += this.LIBRE;
    }
    this.text = escape (query);
}

//---------------------------------------------------------------------
// This function initializes Queries table
function InitQueries()
{
// db Arcade
 Queries[0] = new QArcade();
 Queries[0].Init = QArcade;
 Queries[0].BuildQuery = BuildArcadeQuery;
 Queries[0].tophit = 0;

// db Arno
 Queries[1] = new QArno();
 Queries[1].Init = QArno;
 Queries[1].BuildQuery = BuildArnoQuery;
 Queries[1].tophit = 0;

// db Nat
 Queries[2] = new QNat();
 Queries[2].Init = QNat;
 Queries[2].BuildQuery = BuildNatQuery;
 Queries[2].tophit = 0;

// db Leonore
 Queries[3] = new QLeonore();
 Queries[3].Init = QLeonore;
 Queries[3].BuildQuery = BuildLeonoreQuery;
 Queries[3].tophit = 0;

// db simple
 Queries[4] = new QAll();
 Queries[4].Init = QAll;
 Queries[4].BuildQuery = BuildAllQuery;
 Queries[4].tophit = 0;


// db Prof
 Queries[5] = new QProf();
 Queries[5].Init = QProf;
 Queries[5].BuildQuery = BuildProfQuery;
 Queries[5].tophit = 0;


// db Quidam
 Queries[6] = new QQuidam();
 Queries[6].Init = QQuidam;
 Queries[6].BuildQuery = BuildQuidamQuery;
 Queries[6].tophit = 0;
}


//---------------------------------------------------------------------
//
// Global variables used in ARN site
//
//---------------------------------------------------------------------

TotalDBases = 9;
DBases = new Array(TotalDBases);
InitDBases();

TotalQueries = 7;    // 6 expert searches + 1 simple search 
Queries = new Array(TotalQueries);
InitQueries();

MarkedDocs = new Array(0); 
LastOpenedDoc = -1;
LastQuery = "";

Uau = false ; //true = no auth.

