
// ----------------------------------------------------
// Fonction de RAZ d'une Frame :
// ----------------------------------------------------

function lsClearWindow(pWindow)
{
  var theDoc = pWindow.document;
  theDoc.open();
  theDoc.writeln("<HTML>");
  theDoc.writeln("<HEAD></HEAD>");
  theDoc.writeln("<BODY BGCOLOR=" + top.bgColor + ">");
  theDoc.writeln("</BODY>");
  theDoc.writeln("</HTML>");
  theDoc.close();
}

// ----------------------------------------------------
// Submit query
// ----------------------------------------------------

function lsSubmitQueryFromForm()
{
  lsClearWindows();

  // Query
  var queryForm = top.lsQueryFrame.document.forms.lsQueryForm;
  if (queryForm.query.value == "") { return true; }
  queryForm.query.value = queryForm.query.value.replace(/\’/g, "'");// Attention \%u2019 != '
  queryForm.query.value = queryForm.query.value.replace(/\%u2019;?/g, "'");

  if (queryForm.query.value == "" || queryForm.query.value == " ") return;

  // Search engine
  var selectedEngine = "";
  if (queryForm.searchEngineSelect)
  {
    selectedEngine = queryForm.searchEngineSelect.options[queryForm.searchEngineSelect.selectedIndex].value;

    top.searchMode = "";
    if (selectedEngine == "gradual")
    {
        top.searchMode = "gradual";
        top.gradualLevel = 1;
        selectedEngine = top.levelAnswerGradual[top.gradualLevel];
    }
  }

  top.lsSubmitQuery(queryForm.query.value, selectedEngine);
  return true;
}

// ----------------------------------------------------
function lsSubmitQuery(pQuery, pSearchEngine)
{
  var returnCode = top.lsDemoMain.answer(encode(pQuery), null, pSearchEngine, top.lsTempFrame,
                                         "top.lsSubmitQueryCb", null);
  if (returnCode != LS_ERROR.SUCCESSFUL)
  {
    alert("Error " + returnCode + " while submitting query \"" + pQuery + "\"");
  }
  return true;
}

// ----------------------------------------------------
// Affichage des réponses ou gestion d'une erreur
// ----------------------------------------------------

function lsSubmitQueryCb(pLsStatus, pLsResult)
{
  if (pLsStatus.lastError != top.LS_ERROR.SUCCESSFUL)
  {
    // Erreur lors de l'interrogation
    lsDemoPrintError(pLsStatus);
    // We clear the answer window, and give back the focus to query window.
    lsClearWindows();

    //    this.document.lsQueryForm.query.focus(); Correction GK 28/10/2002
    top.lsQueryFrame.document.forms.lsQueryForm.query.focus();
  }
  else
  {
    // Pas d'erreur

    // Récupérer la question nettoyée
    // Nécessaire pour le redressage orthographique
    var sanitizedQuery = pLsResult.sanitizedQuery.replace(/&#8217;/g, "'");
    sanitizedQuery = sanitizedQuery.replace(/&#34;/g, "\"");
    sanitizedQuery = sanitizedQuery.replace(/\\/g, "\\\\");
    var index = sanitizedQuery.indexOf("@@");
    if (index > 0)
    {
        sanitizedQuery = sanitizedQuery.substring(0, index);
    }
    top.lsQueryFrame.document.forms.lsQueryForm.query.value = sanitizedQuery;

    // S'il y a des corrections, on doit afficher une boîte de dialogue permettant à l'utilisateur
    //   de modifier sa question à partir de propositions de corrections.
    // On coupe donc la frame de réponse en deux parties verticales :
    //   - la partie du haut contiendra ledit dialogue.
    //   - la partie du bas contiendra la frame de réponse habituelle.
    var errorNumber = 0;
    var isCorrectionPresent = false;
    var isCoherent = true;
    for (iterWord in pLsResult.queryAnalysis.words)
    {
      var currentWord = pLsResult.queryAnalysis.words[iterWord];
      if (currentWord.corrections && currentWord.corrections.length > 0)
      {
        isCorrectionPresent = true;
      }
      if (currentWord.wordAnalysis.known == LS_WORD_KNOWN.NO && currentWord.wordAnalysis.occurrencesInIndex == 0)
      {
        ++errorNumber;
      }
      if ((currentWord.corrections && currentWord.corrections.length > 0) &&
          (!currentWord.queryOffsets || !currentWord.queryOffsets.length))
      {
        isCoherent = false;
      }
    }

    if (isCorrectionPresent || errorNumber > 0)
    {
      lsPrintAnswerAndCorrections(parent.lsAnswerFrame.document, pLsResult, errorNumber, isCorrectionPresent, isCoherent, top.bgColor);
    }
    else
    {
      lsPrintAnswer(parent.lsAnswerFrame.document, pLsResult, top.bgColor);
    }
  }
}
// ----------------------------------------------------
// Affichage d'un éventuel message d'erreur
// ----------------------------------------------------

function lsDemoPrintError(pLsStatus)
{
  var message = "Error ";
  if (pLsStatus.lastError == top.LS_ERROR.SERVER_ERROR)
  {
    message += pLsStatus.lastServerError;
    message += " in Tacsy server calling :\n  ";
    var serverMessage = pLsStatus.lastServerMessage;
    var regexp = /<BR>/g;
    serverMessage = serverMessage.replace(regexp, "\n  ");
    regexp = /&#8217;/g;
    serverMessage = serverMessage.replace(regexp, "'");
    message += serverMessage;
  }
  else
  {
    message += pLsStatus.lastError;
  }
  alert(message);
}
// ----------------------------------------------------
// Gestion et affichage des traces d'analyse
// ----------------------------------------------------

function lsAnalysisTrace(pAnswerDoc, pLsResult)
{
  top.__QUERY_ANALYSIS__ = pLsResult.queryAnalysis;    // We must record the query analysis...
  pAnswerDoc.writeln("<FONT SIZE=-1>");
  var useClausesBoolean = (pLsResult.queryAnalysis.clauses == null) ? "false" : "true";
  var actualQuery = pLsResult.initialQuery.replace(/&#34;/g, "");
  pAnswerDoc.write("<A HREF=\"javascript:void(null)\" onClick='top.lsAnalyzeQuery(\"" + actualQuery + "\", top.LS_QUERY_MODE.RUNTIME, " + useClausesBoolean + ",null,null)'>");
  pAnswerDoc.writeln(stringAnalysisTrace);
  pAnswerDoc.writeln("</A></FONT>");
}

// ----------------------------------------------------
function lsPrintWordAnalysis(pDoc, pWord, pLemmaBeginTag, pLemmaEndTag)
{
  pDoc.write(pLemmaBeginTag + pWord.lemma + pLemmaEndTag);
  pDoc.write("<FONT SIZE=-1>");
  pDoc.write(":" + pWord.category);
  pDoc.write(":" + pWord.relevance);
  pDoc.write("</FONT>");
}

// ----------------------------------------------------
function lsPrintQueryClause(pDoc, pLsQueryAnalysis, pClause)
{
  pDoc.writeln("<TR>");
  pDoc.writeln("<TD>" + pClause.weight + "</TD>");
  var clauseWordIndex = 0;
  for (wordIndex in pLsQueryAnalysis.words)
  {
    pDoc.writeln("<TD>");
    if (wordIndex == pClause.wordsIndices[clauseWordIndex])
    {
      var currentWord = pLsQueryAnalysis.words[wordIndex];
      //pDoc.write("<A HREF=#W" + wordIndex + ">");
      pDoc.write(currentWord.wordAnalysis.lemma, "&nbsp;");
      //pDoc.write("</A>");
      ++clauseWordIndex;
    }
    else
    {
      pDoc.write("&nbsp;");
    }
    pDoc.writeln("</TD>");
  }
  pDoc.writeln("</TR>");
}

// ----------------------------------------------------
function lsPrintQueryAnalysis(pLsQueryAnalysis, pAnswerNumber, pQueryNumber, pExpansionSortCriteria)
{
  var itemBeginTag = "";
  var itemEndTag   = "";
  var textHeader = "";

  switch(pLsQueryAnalysis.queryMode)
  {
  case top.LS_QUERY_MODE.INDEXING :
    textHeader = stringIndexHeader;
    windowName = "Indexation";
    windowTitle = "Trace d'Indexation/Matching";
    break;
  case top.LS_QUERY_MODE.RUNTIME  :
    textHeader = stringQueryHeader;
    windowName = "Analyse";
    windowTitle = "Trace d'Analyse";
    break;
  default :
  case top.LS_QUERY_MODE.NONE     :
    textHeader = "";
    break;
  }

  var analysisWindow = window.open("", windowName,
                                   'toolbar=no,titlebar=no,Height=300,Width=400,outerHeight=300,outerWidth=400,resizable=yes,scrollbars=yes');
  analysisWindow.focus();
  var analysisDoc = analysisWindow.document.open();

  analysisDoc.writeln("<HTML>");
  analysisDoc.writeln("<HEAD><TITLE>" + windowTitle + "</TITLE><HEAD>" );

  analysisDoc.writeln("<BODY BGCOLOR=" + top.bgColor + ">");
  analysisDoc.writeln(textHeader + "<B><I>" + pLsQueryAnalysis.initialQuery + "</I></B><HR>");

  if (!pLsQueryAnalysis.words || !pLsQueryAnalysis.words.length)
  {
    analysisDoc.writeln("<I>" + stringEmptyAnalysis + "</I><BR>");
  }
  else
  {
    // The matches.
    var currentMatchQuery = null;
    if (pAnswerNumber != null)
    {
      currentMatchQuery = top.__LSRESULT__.answerArray[pAnswerNumber].matchQueryArray[pQueryNumber];
      analysisDoc.writeln(itemBeginTag + stringMatchingHeader + itemEndTag + "<BR>");
      // We re-order the user query's words by their linear position.
      var linearUserWords = new Array();
      for (wordIndex in top.__LSRESULT__.queryAnalysis.words)
      {
        var currentWord = top.__LSRESULT__.queryAnalysis.words[wordIndex];
        linearUserWords[(currentWord.linearPosition < 0) ? wordIndex : currentWord.linearPosition] = currentWord;
      }
      for (wordIndex = 0; wordIndex < linearUserWords.length; ++wordIndex)
      {
        var currentWord = linearUserWords[wordIndex];
        var currentMatchWord = currentMatchQuery.userMatchWords[currentWord.analysisPosition];
        var beginWordTag = "- ";
        var endWordTag   = "";
        if (currentMatchWord.userMatch > 0)
        {
          beginWordTag = "- <B>";
          endWordTag   = "</B>";
        }
        analysisDoc.write(beginWordTag + currentWord.wordAnalysis.lemma + endWordTag);
        if (currentMatchWord.userMatch > 0)
        {
          var actualMatchWord = null;
          var distance = 0;
          if (currentMatchWord.userMatch == 1)
          {
            actualMatchWord = currentWord.wordAnalysis;
          }
          else
          {
            actualMatchWord = currentWord.expansions[currentMatchWord.userMatch - 2].wordAnalysis;
            distance = currentWord.expansions[currentMatchWord.userMatch - 2].distance;
          }
          analysisDoc.write(" => " + actualMatchWord.lemma);
          if (distance)
          {
            analysisDoc.write(" ( " + distance + " )");
          }
        }
        analysisDoc.writeln("<BR>");
      }
      analysisDoc.writeln("<HR>");
    }

    // The clauses.
    if (pLsQueryAnalysis.clauses && pLsQueryAnalysis.clauses.length > 0)
    {
      //analysisDoc.writeln("<BR>");
      analysisDoc.writeln("<TABLE BORDER=1>");
      analysisDoc.writeln(itemBeginTag + "Clauses" + itemEndTag + "<BR>");
      for (clauseIndex in pLsQueryAnalysis.clauses)
      {
        var currentClause = pLsQueryAnalysis.clauses[clauseIndex];
        lsPrintQueryClause(analysisDoc, pLsQueryAnalysis, currentClause);
      }
      analysisDoc.writeln("</TABLE><HR>");
    }

    // The words themselves...

    // Is there an expansion (in order to display the select box) ?
    var isExpansionHere = false;
    for (wordIndex in pLsQueryAnalysis.words)
    {
      if (pLsQueryAnalysis.words[wordIndex].expansions != null)
      {
        isExpansionHere = true;
        break;
      }
    }
    var actualSortExpansion = (pExpansionSortCriteria == null) ? pLsQueryAnalysis.expansionSortCriteria : pExpansionSortCriteria;
    if (isExpansionHere)
    {
      analysisWindow.__MY_QUERY_ANALYSIS__ = pLsQueryAnalysis;
      analysisDoc.writeln( stringExpansionSortOrder );
      analysisDoc.writeln("<SELECT onChange='window.opener.lsPrintQueryAnalysis(__MY_QUERY_ANALYSIS__, " + pAnswerNumber + ", " + pQueryNumber + ", parseInt(this.options[this.options.selectedIndex].value))'>");
     for (sortIndex in sortExpansionStrings)
      {
        analysisDoc.write("<OPTION VALUE=" + sortIndex);
        if (sortIndex == actualSortExpansion)
        {
          analysisDoc.write(" SELECTED");
        }
        analysisDoc.write(">");
        analysisDoc.writeln(sortExpansionStrings[sortIndex]);
      }
      analysisDoc.writeln("</SELECT>");
      analysisDoc.writeln("<HR>");
    }

    for (wordIndex in pLsQueryAnalysis.words)
    {
      var currentWord = pLsQueryAnalysis.words[wordIndex];
      analysisDoc.write("<A NAME=W" + wordIndex + ">");
      var beginWordTag = "";
      var endWordTag   = "";
      if (currentMatchQuery && currentMatchQuery.indexMatchWords &&
          currentMatchQuery.indexMatchWords[wordIndex])
      {
        beginWordTag = "<B>";
        endWordTag   = "</B>";
      }
      lsPrintWordAnalysis(analysisDoc, currentWord.wordAnalysis, beginWordTag, endWordTag);
      analysisDoc.write("</A>");
      analysisDoc.writeln("<BR>");
      if (currentWord.expansions && (actualSortExpansion != LS_EXPANSION_SORT_CRITERIA.NONE))
      {
        // We sort the expansions
        currentWord.sortExpansions(actualSortExpansion);
        for (expansionIndex in currentWord.expansions)
        {
          //analysisDoc.writeln("<BR>");
          var currentExpansion = currentWord.expansions[expansionIndex];
          analysisDoc.write("&nbsp;&nbsp;&nbsp;&nbsp;");
          lsPrintWordAnalysis(analysisDoc, currentExpansion.wordAnalysis, "", "");
          analysisDoc.write (" <FONT SIZE=-1>(" + currentExpansion.distance + ")</FONT>");
          analysisDoc.writeln("<BR>");
        }
      }
    }
  }
  analysisDoc.writeln("<HR>");
  analysisDoc.writeln("<CENTER>");
  analysisDoc.writeln("<FORM ACTION=\"javascript:window.close();\">");
  analysisDoc.writeln("<INPUT TYPE=SUBMIT VALUE=Close>");
  analysisDoc.writeln("</FORM>");
  analysisDoc.writeln("</CENTER>");
  analysisDoc.writeln("</BODY>");
  analysisDoc.writeln("</HTML>");
  analysisDoc.close();
}

// ----------------------------------------------------

function lsAnalyzeQueryCb(pLsStatus, pLsQueryAnalysis, pAnswerNumber, pQueryNumber)
{
  if (pLsStatus.lastError != top.LS_ERROR.SUCCESSFUL)
  {
    lsDemoPrintError(pLsStatus);
  }
  else
  {
    lsPrintQueryAnalysis(pLsQueryAnalysis, pAnswerNumber, pQueryNumber, null);
  }
}

// ----------------------------------------------------
function lsAnalyzeQuery(pQuery, pQueryMode, pUseClauses, pAnswerNumber, pQueryNumber)
{
  top.lsDemoMain.analyze(pQuery,
                         pQueryMode,
                         pUseClauses,
                         pQueryMode == top.LS_QUERY_MODE.INDEXING ? top.lsTempFrameAnalysis : top.lsTempFrame,
                         "top.lsAnalyzeQueryCb",
                         pAnswerNumber + "," + pQueryNumber);
  return true;
}
// ----------------------------------------------------
function displayEngines(pLsStatus, pSearchEngines, pCallBackData)
{
  var theSelect = top.lsQueryFrame.document.forms.lsQueryForm.searchEngineSelect;
  theSelect.options.length = 0;

  for (var iterEngine in pSearchEngines)
  {
    var currentEngine = pSearchEngines[iterEngine];
    var currentLabel = currentEngine.alias;
    if (top.searchEngineLabel[currentEngine.alias])
    {
      currentLabel = top.searchEngineLabel[currentEngine.alias];
    }
    var newOption = new Option(currentLabel, currentEngine.alias);
    theSelect.options[theSelect.options.length] = newOption;
  }
}
// ----------------------------------------------------
function calculateMhcScore(currentClass)
{
  // ftouitou;05/12/3; Pour affiner les scores, on calcule un MHC simplifié...
  var currentMhcUserScore     = top.mhcUserFactor     * currentClass.userScore;
  var currentMhcDistanceScore = top.mhcDistanceFactor * currentClass.distanceScore;
  var currentMhcIndexScore    = top.mhcIndexFactor    * currentClass.indexScore;
  var mhcSumFactor = top.mhcUserFactor + top.mhcDistanceFactor + top.mhcIndexFactor;
  var currentMhcScore = (currentMhcUserScore + currentMhcDistanceScore + currentMhcIndexScore) / mhcSumFactor;
  return currentMhcScore;
}

// -------------------------------------------------------
// Dialogue de correction ortho-phonétique
// -------------------------------------------------------
function LsCorrectionOffset(pOffset, pWord)
{
  this.offset = pOffset;
  this.word   = pWord;     // Référence sur un LsQueryWord.
}

// ----------------------------------------------------
function lsCompareOffset(p1, p2)
{
  return (p1.offset - p2.offset);
}

// -------------------------------------------------------
// Dialogue de correction ortho-phonétique (suite)
// ----------------------------------------------------
function lsMakeCorrectionString()
{
  var dialogDoc = top.lsAnswerFrame.lsDialogFrame.document;
  //  dialogDoc.open();
  var correctionArray = top.correctionArray;
  var correctionForm = dialogDoc.forms._corrections;
  // On doit récupérer les corrections courantes, et former la chaîne corrigée, qu'on
  //   placera dans le formulaire initial de question...

  // Récupération des corrections courantes.
  var correctionPrefix = "_correction_";
  for (var iterElement = 0; iterElement < correctionForm.elements.length; ++iterElement)
  {
    var currentElement = correctionForm.elements[iterElement];
    if (currentElement.name.indexOf(correctionPrefix) != 0) { continue; }
    var currentCorrection = "";
    if (currentElement.options)
    { // Des corrections ont été proposées pour le mot courant dans une "select box"...
      currentCorrection = currentElement.options[currentElement.options.selectedIndex].text;
    }
    else
    { // Aucune correction proposée pour le mot courant; simple "edit box" proposée...
      currentCorrection = currentElement.value;
    }
    var currentIndex = parseInt(currentElement.name.substring(correctionPrefix.length), 10);
    correctionArray[currentIndex] = currentCorrection;
  }

  // Formation de la question corrigée.
  var correctedQuery = correctionArray.join("");

  // Remplacement dans le formulaire initial.
  top.lsQueryFrame.document.forms.lsQueryForm.query.value = correctedQuery;
}

// ----------------------------------------------------
function lsMakeCorrectionArray(pLsResult, pArray)
{
  // Il faut construire un tableau dont chaque élément comporte :
  //    - l'offset d'une correction
  //    - une référence vers le LsWord correspondant.
  // Tableau trié selon l'ordre croissant des offsets...

  // Construction du tableau.
  var iterWord = 0;
  for (iterWord in pLsResult.queryAnalysis.words)
  {
    var currentWord = pLsResult.queryAnalysis.words[iterWord];
    if (!currentWord.queryOffsets || !currentWord.queryOffsets.length) { continue; }
    var iterOffset = 0;
    for (iterOffset in currentWord.queryOffsets)
    {
      var currentOffset = currentWord.queryOffsets[iterOffset];
      var newOffset = new LsCorrectionOffset(currentOffset, currentWord);
      pArray[pArray.length] = newOffset;
    }
  }

  // Tri du tableau.
  pArray.sort(lsCompareOffset);
}

// -------------------------------------------------------
// Fonctions pour la validation des résultats par l'utilisateur
// -------------------------------------------------------

function lsSubmitValidation()
{
  myAnswerDoc = top.__ANSWER_DOC__;

  myAnswerDoc.lsValidation.target = "lsTempValidation";
  if (myAnswerDoc.lsValidation.sent.value == top.qualityLabelSubmitted)
  {
    alert(top.validationAlreadySent);
    return false;
  }
//    var checkedButton = "";
//    var myComment = top.lsAnswerFrame.document.lsValidation.commentaire;
//    for (var i in top.satisfactions)
//    {
//      if (myComment[i].checked == true) 
//      {
//        checkedButton = myComment[i].value;    
//      }
//    }

  if (myAnswerDoc.lsValidation.commentaire.value == ""
      || myAnswerDoc.lsValidation.commentaire.value == -1)
//    || checkedButton == "")
//    || top.lsAnswerFrame.document.lsValidation.commentaire.value == "default")
//    || top.lsAnswerFrame.document.lsValidation.commentaire.value == undefined)
  {
    alert(top.noValidationToSend);
    return false;
  }
  myAnswerDoc.lsValidation.sent.value = top.qualityLabelSubmitted;
  return true;
}

// -------------------------------------------------------
function printValidationFormBegin(pAnswerDoc)
{
    //  pAnswerDoc.writeln("<FORM method=GET accept-charset='ISO-8859-1' action='" + top.lsDemoMain.lrCgiAlias + "/tacsyValid.sh' name=lsValidation onSubmit='return top.lsSubmitValidation();'>");
  pAnswerDoc.writeln("<FORM method=GET accept-charset='ISO-8859-1' action='" + top.lsDemoMain.lrCgiAlias + "/lrValidCgi' name=lsValidation onSubmit='return top.lsSubmitValidation();'>");
}

// -------------------------------------------------------
function printValidationForm(pAnswerDoc, query, application)
{
  // form avec champs hidden, question, application
  pAnswerDoc.write("<input type=\"hidden\" name=\"_host\" value=\"");
  pAnswerDoc.write(top.lsDemoMain.lsServerHost);
  pAnswerDoc.writeln("\">");
  pAnswerDoc.write("<input type=\"hidden\" name=\"_port\" value=\"");
  pAnswerDoc.write(top.lsDemoMain.lsServerPort);
  pAnswerDoc.writeln("\">");
  pAnswerDoc.writeln("<input type=\"hidden\" name=\"_action\" value=\"lsValidationForm\">");
  pAnswerDoc.write("<input type=\"hidden\" name=\"query\" value=\"");
  var queryForm = top.lsQueryFrame.document.forms.lsQueryForm;
  pAnswerDoc.write(queryForm.query.value);
  //pAnswerDoc.write(query);
  pAnswerDoc.writeln("\">");
  pAnswerDoc.write("<input type=\"hidden\" name=\"_application\" value=\"");
  pAnswerDoc.write(application);
  pAnswerDoc.writeln("\">");
  top.__ANSWER_DOC__ = pAnswerDoc;
}

// -------------------------------------------------------
function printValidationFormEnd(pAnswerDoc)
{
  pAnswerDoc.writeln("</FORM>");
}

// -------------------------------------------------------
function lsChangeValidation()
{
  if (top.lsAnswerFrame.document.lsValidation.sent.value == top.qualityLabelSubmitted) 
  {
    top.lsAnswerFrame.document.lsValidation.sent.value = top.qualityLabelToSubmit;
  }
}

// -------------------------------------------------------
function printValidationChoice(pAnswerDoc, count, answerPath)
{
  //  réponses en hidden avec valeur de validation
  var name = "select" + count;
  var path = "path" + count;
  // to do path and answer
  pAnswerDoc.write("<input type=\"hidden\" name=\"");
  pAnswerDoc.write(path);
  pAnswerDoc.write("\" value=\"");
  pAnswerDoc.write(answerPath);
  pAnswerDoc.writeln("\">");
  pAnswerDoc.write("<select name=\"");
  pAnswerDoc.write(name);
  pAnswerDoc.write("\" size=\"1\"");
  pAnswerDoc.writeln(" onChange=\"top.lsChangeValidation()\">");
  for (i=0; i<top.qualityLabelArray.length; i++)
  {
    pAnswerDoc.write("<option value=\"");
    pAnswerDoc.write(i);
    pAnswerDoc.write("\">");
    pAnswerDoc.write(top.qualityLabelArray[i]);
    pAnswerDoc.writeln("</option>");
  }
  pAnswerDoc.writeln("</select>");
}

// -------------------------------------------------------
function printValidationCommentArea(pAnswerDoc)
{
 pAnswerDoc.write("<textarea name=commentaire rows=2 cols=60");
 pAnswerDoc.writeln(" onChange=\"top.lsChangeValidation()\"></textarea>");
}

// -------------------------------------------------------
function printValidationSubmitButton(pAnswerDoc)
{
 pAnswerDoc.writeln("<INPUT NAME=sent TYPE=SUBMIT VALUE='" + top.qualityLabelToSubmit + "'>");
}
// -------------------------------------------------------
    // public method for url encoding
    function encode(string)
 {
        string = string.replace(/\r\n/g,"\n");
        var utftext = "";

        for (var n = 0; n < string.length; n++) {

            var c = string.charCodeAt(n);

            if (c < 128) {
                utftext += String.fromCharCode(c);
            }
            else if((c > 127) && (c < 2048)) {
                utftext += String.fromCharCode((c >> 6) | 192);
                utftext += String.fromCharCode((c & 63) | 128);
            }
            else {
                utftext += String.fromCharCode((c >> 12) | 224);
                utftext += String.fromCharCode(((c >> 6) & 63) | 128);
                utftext += String.fromCharCode((c & 63) | 128);
            }

        }

        return utftext;
    }

    // public method for url decoding
    function decode(utftext)
 {
        var string = "";
        var i = 0;
        var c = c1 = c2 = 0;

        while ( i < utftext.length ) {

            c = utftext.charCodeAt(i);

            if (c < 128) {
                string += String.fromCharCode(c);
                i++;
            }
            else if((c > 191) && (c < 224)) {
                c2 = utftext.charCodeAt(i+1);
                string += String.fromCharCode(((c & 31) << 6) | (c2 & 63));
                i += 2;
            }
            else {
                c2 = utftext.charCodeAt(i+1);
                c3 = utftext.charCodeAt(i+2);
                string += String.fromCharCode(((c & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63));
                i += 3;
            }

        }

        return string;
    }

