// --------------------------------------------------------------
// ---------------------------- Funktionen fuer Popups START
// --------------------------------------------------------------

// --------------------------------------------------------
// Funktionen zum Ein/Aus-Blenden der Popups START

function sPopupName2sPopupId(sPopupName) {
   return "div_kanji_auswahl_menu_" + sPopupName
}



function fn_sPopupName2oPopupStyle(sPopupName) {
   var sPopupId = sPopupName2sPopupId(sPopupName)
   if (bNavigator_Nav4) var oPopupStyle = eval('document.' + sPopupId)
   if (bNavigator_DOM) var oPopupStyle = document.getElementById(sPopupId).style

   return oPopupStyle
}


// Global definition
// Beim Einblenden eines Menus wird dessen Name in gsPopupName_current gespeichert,
// damit dieses Menu beim Aufruf von popup_hide ausgeblendet werden kann.
// Gleichzeitig kann nur ein einziges Menu sichtbar sein.
var gsPopupName_current = null;


// Globals: gsPopupName_current set
function popup_show(sPopupName, oCaller) {
   popup_hide()

   gsPopupName_current = sPopupName

   var iMenuLeft = 0
   var iMenuTop = 0

   var iTerminatingCounter = 0
// s = ""
   while (oCaller.tagName != "BODY" && iTerminatingCounter++ < 10) {
// s = s + " " + oCaller.tagName + oCaller.offsetLeft + "," + oCaller.offsetTop
      iMenuLeft += oCaller.offsetLeft
      iMenuTop += oCaller.offsetTop
      oCaller = oCaller.offsetParent
   }
   if (bNavigator_msie) {
      iMenuLeft += 2
      iMenuTop += 1
   }

// alert(s)

   var popup_xPos = iMenuLeft - 3; // padding=2, border=1
   var popup_yPos = iMenuTop + 16; // die Images sind 16 pixel hoch
// alert("iMenuTop=" + iMenuTop + " iMenuLeft=" + iMenuLeft + " popup_xPos=" + popup_xPos + " popup_yPos=" + popup_yPos)

   var oPopupStyle = fn_sPopupName2oPopupStyle(sPopupName);
// alert("bNavigator_Nav4=" + bNavigator_Nav4 + ", bNavigator_DOM=" + bNavigator_DOM + ", oPopupStyle=" + oPopupStyle)

   if (bNavigator_Nav4 && oPopupStyle == undefined) {
      // bgarz 20010626
      // Netscape liefert beim ersten Laden der Seite immer einen Fehler, weil er
      // 'document.popup_div_' + sPopupName noch nicht kennt. Warum?
      // Deswegen breche ich an dieser Stelle die Ausfuehrung ab. Dann gibt es halt keine popups...
      //              alert(sPopupName + ' ' + oPopupStyle + ' undefined');
      //              var str = 'document.popup_div_' + sPopupName;
      //              alert(str + ' ' + document.popup_div_LU0035763456 + ' ' + document.popup_div_LU0035763456.left)
      return;
   } else {
      oPopupStyle.top  = popup_yPos;
      oPopupStyle.left = popup_xPos;

// alert("oPopupStyle.left=" + oPopupStyle.left + ", oPopupStyle.top=" + oPopupStyle.top + ", oPopupStyle.visibility=" + oPopupStyle.visibility)

      if (bNavigator_Nav4) oPopupStyle.visibility = "show";
      if (bNavigator_DOM) oPopupStyle.visibility = "visible";
   }
}


// Globals: gsPopupName_current used
function popup_hide() {
   fn_clearTimeout_PopupHide()

   if (gsPopupName_current) {
      oPopupStyle = fn_sPopupName2oPopupStyle(gsPopupName_current);

      if (bNavigator_Nav4) oPopupStyle.visibility = "hide";
      if (bNavigator_DOM) oPopupStyle.visibility = "hidden";

      window.status = ""
   }

   void(0);
}

// Funktionen zum Ein/Aus-Blenden der Popups END
// --------------------------------------------------------


// --------------------------------------------------------
// Timer functionen zum Verschwindenlassen der Popups START

// Global definition
// Timer-Objekt zum Ausblenden von Popups
var oTimer_PopupHide = null


// globals: oTimer_PopupHide used and set
function fn_setTimeout_PopupHide() {
   if(oTimer_PopupHide)
      fn_clearTimeout_PopupHide()

   oTimer_PopupHide = setTimeout("popup_hide();", 6000)
   //Test window.status = 's' + window.status
}


// globals: oTimer_PopupHide used and set
function fn_clearTimeout_PopupHide() {
   if(oTimer_PopupHide) {
      oTimer_PopupHide = clearTimeout(oTimer_PopupHide)
      //Test window.status = 'C' + window.status
   }
}

// Timer functionen zum Verschwindenlassen der Popups ENDE
// --------------------------------------------------------


// --------------------------------------------------------
// Funktionen zum Ein/Aus-Blenden der Menues mit den verschiedenen Antworten START


// Global definition
// Das zuletzt vom User ausgewaehlte popup-Menu gehoert zu dem Exercise giExerciseNr_current
// und der Frage giQuestionNr_current. Diese beiden Variablen werden beim ueberfahren des
// Fragezeichens gesetzt, bevor das popup-Menu angezeigt wird. Wenn der User nun eine Antwort
// aus dem Menu auswaehlt ist dann bekannt, dass sich die Antwort auf die Frage giQuestionNr_current
// in dem Exercise giExerciseNr_current bezieht.
var giExerciseNr_current
var giQuestionNr_current


// Blende das menu mit den moeglichen Antworten ein, wenn der User mit der Maus ueber eine
// unbeantwortete Frage faehrt.
// globals giExerciseNr_current set
//         giQuestionNr_current set
//         gaiExerciseNr_iQuestionNr2iMenuNr used
//         gaiExerciseNr_iQuestionNr2bCorrectAnswerGiven used
function fn_onMouseOver_iExerciseNr_iQuestionNr2showMenu(iExerciseNr, iQuestionNr) {
   // Das Menu soll nur dann eingeblendet werden, wenn die Frage noch unbeantwortet ist
   var bCorrectAnswerGiven = gaiExerciseNr_iQuestionNr2bCorrectAnswerGiven[iExerciseNr][iQuestionNr]
// alert("bCorrectAnswerGiven=" + bCorrectAnswerGiven)
   if (!bCorrectAnswerGiven) {
      giExerciseNr_current = iExerciseNr
      giQuestionNr_current = iQuestionNr

      // Welches Menu soll eingeblendet werden?
      var iMenuNr = gaiExerciseNr_iQuestionNr2iMenuNr[iExerciseNr][iQuestionNr]
      var sMenuId = iMenuNr2sMenuId(iMenuNr)

      // Unter welchem Fragezeichen soll das Menu eingeblendet werden?
      // Das Menu wurde durch onMouseOver ueber dem Fragezeichen zur Frage iQuestionNr im Exercise
      // iExerciseNr aufgerufen:
      var sImgId = iExerciseNr_iQuestionNr_iImgNr2sImgId(iExerciseNr, iQuestionNr, 0) // Das Fragezeichen
      var oCaller = document.images[sImgId]
//alert("iMenuNr=" + iMenuNr + ", sMenuId=" + sMenuId + ", sImgId=" + sImgId + ", oCaller=" + oCaller)
      popup_show(sMenuId, oCaller)

      window.status = "Please select the correct answer."
   }
}


// Starte das PopupHide-Timeout, wenn der User mit der Maus aus einer unbeantworteten Frage faehrt.
// globals: gaiExerciseNr_iQuestionNr2bCorrectAnswerGiven used
function fn_onMouseOut_iExerciseNr_iQuestionNr2setTimeout_PopupHide(iExerciseNr, iQuestionNr) {
   var bCorrectAnswerGiven = gaiExerciseNr_iQuestionNr2bCorrectAnswerGiven[iExerciseNr][iQuestionNr]
   if (!bCorrectAnswerGiven) {
      fn_setTimeout_PopupHide()
   }
}



// xxxxxxxxxxxxxx NICHT BENUTZT!
// Uebernommen von: http://www.quirksmode.org/js/events_mouse.html
// Soll onMouseLeave vom IE simulieren.
// Funktioniert nicht richtig, weil wenn das DIV zu schnell verlassen wird, merkt das
// der Browser gar nicht... D.h. tg.nodeName != 'DIV' und die Ausfuehrung wird beendet.
function fn_DIV_onMouseOut2setTimeout_PopupHide(e) {
   if (!e) var e = window.event;
   var tg = (window.event) ? e.srcElement : e.target;
   if (tg.nodeName != 'DIV') return;
   var reltg = (e.relatedTarget) ? e.relatedTarget : e.toElement;
   while (reltg != tg && reltg.nodeName != 'BODY')
   reltg= reltg.parentNode
   if (reltg== tg) return;
   // Mouseout took place when mouse actually left layer
   // Handle event
   fn_setTimeout_PopupHide()
}

// Funktionen zum Ein/Aus-Blenden der Menues mit den verschiedenen Antworten START
// --------------------------------------------------------


// --------------------------------------------------------------
// ---------------------------- Funktionen fuer Popups ENDE
// --------------------------------------------------------------



// --------------------------------------------------------------
// ----------- Funktionen zur Auswahl der richtigen Antwort START
// --------------------------------------------------------------


// Ist die Antwort sKanjiWriting auf die Frage iQuestionNr in Exercise iExerciseNr korrekt?
// globals: gaiExerciseNr_iQuestionNr2lsKanjiWriting_correctAnswer used
function iExerciseNr_iQuestionNr_sKanjiWriting2bAnswerIsCorrect(iExerciseNr, iQuestionNr, sKanjiWriting) {
   var lsKanjiWriting_correctAnswer = gaiExerciseNr_iQuestionNr2lsKanjiWriting_correctAnswer[iExerciseNr][iQuestionNr]
   var asKanjiWriting_correctAnswer = lsKanjiWriting_correctAnswer.split(";")
   var bAnswerIsCorrect = 0
   for (var i=0; i<asKanjiWriting_correctAnswer.length && !bAnswerIsCorrect; i++) {
      bAnswerIsCorrect = (sKanjiWriting == asKanjiWriting_correctAnswer[i])
   }
   return bAnswerIsCorrect
}


// Liefert eine (von moeglicherweise mehreren) korrekte Antwort auf die Frage iQuestionNr
// im Exercise iExerciseNr.
// globals: gaiExerciseNr_iQuestionNr2lsKanjiWriting_correctAnswer used
function iExerciseNr_iQuestionNr2sKanjiWriting_correctAnswer(iExerciseNr, iQuestionNr) {
   var lsKanjiWriting_correctAnswer = gaiExerciseNr_iQuestionNr2lsKanjiWriting_correctAnswer[iExerciseNr][iQuestionNr]
   var asKanjiWriting_correctAnswer = lsKanjiWriting_correctAnswer.split(";")
   // Waehle die erste moegliche korekte Antwort:
   var sKanjiWriting_correctAnswer = asKanjiWriting_correctAnswer[0]
   return sKanjiWriting_correctAnswer
}


// Blende die Antwort sKanjiWriting fuer die Frage Nr iQuestionNr in dem Exercise iExerciseNr ein.
function fn_iExerciseNr_iQuestionNr_sKanjiWriting2set_AntwortGifs(iExerciseNr, iQuestionNr, sKanjiWriting) {
   var iImgNr
   var sImgId
   for (iImgNr=0; iImgNr<sKanjiWriting.length / 4; iImgNr++) {
      var sKanjiEuc = sKanjiWriting.slice(4*iImgNr, 4*iImgNr + 4)
      sImgId = iExerciseNr_iQuestionNr_iImgNr2sImgId(iExerciseNr, iQuestionNr, iImgNr)
      if (sKanjiEuc == "UNVE") {
         // Das Fragezeichen anzeigen:
         document.images[sImgId].src = '../Images/UNVERIF.gif'
      } else {
         document.images[sImgId].src = '../Kanji16/' + sKanjiEuc + '.gif'
      }
      // Das Gif sichtbar machen:
      document.images[sImgId].style.display = ""
   }

   // Mache alle leeren gifs, die von der eingeblendeten Antwort nicht benutzt werden, unsichtbar:
   sImgId = iExerciseNr_iQuestionNr_iImgNr2sImgId(iExerciseNr, iQuestionNr, iImgNr)
   while (document.images[sImgId]) {
      document.images[sImgId].src = '../Kanji16/a1a0.gif'
      document.images[sImgId].style.display = "none"
      sImgId = iExerciseNr_iQuestionNr_iImgNr2sImgId(iExerciseNr, iQuestionNr, iImgNr++)
   }
}


// Bearbeite die Antwort sKanjiWriting des Users. Auf welche Frage in welchem Exercise sich diese
// Antwort bezieht, ist in den globalen Variablen giExerciseNr_current und giQuestionNr_current
// festgelegt, die beim Ueberfahren eines Fragezeichens gesetzt werden.
// globals giExerciseNr_current used
//         giQuestionNr_current used
function fn_processUsersAnswer(sKanjiWriting) {
   fn_processAnswer(giExerciseNr_current, giQuestionNr_current, sKanjiWriting)
}


// Bearbeite die Antwort sKanjiWriting auf die Frage iQuestionNr in der Uebung iExerciseNr.
// globals gaiExerciseNr_iQuestionNr2bCorrectAnswerGiven used
function fn_processAnswer(iExerciseNr, iQuestionNr, sKanjiWriting) {
   // popup_hide() nicht noetig, weil popup_hide() schon durch einen Klick auf Body aufgerufen wird

   // Die vom User ausgewaehlte Antwort einblenden:
   fn_iExerciseNr_iQuestionNr_sKanjiWriting2set_AntwortGifs(iExerciseNr, iQuestionNr, sKanjiWriting)

   //Test alert("Users answer:" + sKanjiWriting + ' correct answers:' + gaiExerciseNr_iQuestionNr2lsKanjiWriting_correctAnswer[iExerciseNr][iQuestionNr])
   if (iExerciseNr_iQuestionNr_sKanjiWriting2bAnswerIsCorrect(iExerciseNr, iQuestionNr, sKanjiWriting)) {
      // Die Antwort ist richtig.
      gaiExerciseNr_iQuestionNr2bCorrectAnswerGiven[iExerciseNr][iQuestionNr] = 1

      // Den AntwortStatus-Smilie setzen: richtige Antwort
      // Gibt es noch unbeantwortete Fragen? D.h. gibt es noch Fragezeichen?
      var bEsGibtNochUnbeantworteteFragen = 0
      var iQuestionNr_total = gaiExerciseNr2iQuestionNr_total[iExerciseNr]
      for (var iQuestionNr=0; iQuestionNr<iQuestionNr_total && !bEsGibtNochUnbeantworteteFragen; iQuestionNr++) {
         bEsGibtNochUnbeantworteteFragen = !gaiExerciseNr_iQuestionNr2bCorrectAnswerGiven[iExerciseNr][iQuestionNr]
         //Test if (bEsGibtNochUnbeantworteteFragen) alert(iExerciseNr + ' ' + iQuestionNr)
      }

      // Wenn es keine unbeantwortete Fragen mehr gibt, dann soll sogar das Supergut-Smilie smilie_blague.gif erscheinen,
      // ansonsten soll nur das normale Gut-Smilie smilie_heureux.gif erscheinen:
      var sAntwortStatus = bEsGibtNochUnbeantworteteFragen?"Answer_correct":"allAnswers_correct"
      iExerciseNr_sAntwortStatus2set_AntwortStatusImg(iExerciseNr, sAntwortStatus)

   } else {
      // Die Antwort ist falsch oder es soll das Fragezeichen eingeblendet werden.
      gaiExerciseNr_iQuestionNr2bCorrectAnswerGiven[iExerciseNr][iQuestionNr] = 0

      // Den AntwortStatus-Smilie setzen: falsche Antwort
      var sAntwortStatus = "Answer_incorrect"
      iExerciseNr_sAntwortStatus2set_AntwortStatusImg(iExerciseNr, sAntwortStatus)

      // Blende nach kurzer Zeit (z.B. 500 ms) wieder das Fragezeichen ein, sofern es nicht
      // gerade eingeblendet wurde:
      if (sKanjiWriting != "UNVE") {
         setTimeout("fn_iExerciseNr_iQuestionNr_sKanjiWriting2set_AntwortGifs(" + iExerciseNr + ',' + iQuestionNr + "," + "'UNVE'" + ")",500)
      }
   }
}


// Global definition
// Moegliche Icons als reaktion auf die Antwort des users
var sAntwortStatus2sAntwortStatusImg_Src = new Array()
sAntwortStatus2sAntwortStatusImg_Src["Answer_incorrect"]   = "../Icons/smilie_triste.gif"
sAntwortStatus2sAntwortStatusImg_Src["Answer_correct"]     = "../Icons/smilie_heureux.gif"
sAntwortStatus2sAntwortStatusImg_Src["allAnswers_correct"] = "../Icons/smilie_blague.gif"
sAntwortStatus2sAntwortStatusImg_Src["resetExercise"]      = "../Icons/smilie_indifferent.gif"

// Global definition
// Moegliche Meldungen in der Status-Zeile
var sAntwortStatus2sAntwortStatus_StatusTxt = new Array()
sAntwortStatus2sAntwortStatus_StatusTxt["Answer_incorrect"]   = "Last Answer was incorrect."
sAntwortStatus2sAntwortStatus_StatusTxt["Answer_correct"]     = "Last Answer was correct."
sAntwortStatus2sAntwortStatus_StatusTxt["allAnswers_correct"] = "All Answers are correct."
sAntwortStatus2sAntwortStatus_StatusTxt["resetExercise"]      = "Exercise reset."

// Abhaengig davon, ob die Antwort des Users richtig/falsch war, blende das entsprechende
// Icon sAntwortStatusImg ein und zeige eine Meldung in der Status-Zeile.
// globals sAntwortStatus2sAntwortStatusImg_Src used
//         sAntwortStatus2sAntwortStatus_StatusTxt used
function iExerciseNr_sAntwortStatus2set_AntwortStatusImg(iExerciseNr, sAntwortStatus) {
   var sAntwortStatusImgId = iExerciseNr2sAntwortStatusImgId(iExerciseNr)
   var sAntwortStatusImgSrc = sAntwortStatus2sAntwortStatusImg_Src[sAntwortStatus]
   document.images[sAntwortStatusImgId].src = sAntwortStatusImgSrc

   var sSpanId = "id_solution_span" + iExerciseNr
   if (sAntwortStatus == "allAnswers_correct") {
   // Die Zeilen mit sRomajiWriting und sTranslation einblenden:
      document.getElementById(sSpanId).style.display = ""
   } else {
      document.getElementById(sSpanId).style.display = "none"
   }

   window.status = sAntwortStatus2sAntwortStatus_StatusTxt[sAntwortStatus]
}


// --------------------------------------------------------------
// ----------- Funktionen zur Auswahl der richtigen Antwort ENDE
// --------------------------------------------------------------


// --------------------------------------------------------------
// ----------- Funktionen fuer onMouseOver, onMouseOut etc. START
// --------------------------------------------------------------


function fn_onMouseOver_sAntwortStatusImg(iExerciseNr) {
   var sAntwortStatusImgId = iExerciseNr2sAntwortStatusImgId(iExerciseNr)

   // Sind im Moment alle Antworten korrekt angezeigt?
   // Dies ist der Fall, wenn das AntwortStatus-Smilie = "smilie_blague.gif" ist.
   var bAlleAntwortenKorrekt = document.images[sAntwortStatusImgId].src.search(/smilie_blague.gif/) != -1
   window.status = bAlleAntwortenKorrekt?"Click to reset the exercise!":"Click to show the correct answers!"
}


// Beim Aufruf dieser Funktion werden fuer das Exercise iExerciseNr abwechselnd
// alle Antworten korrekt angezeigt oder alle Fragen resetet.
//
// Globals: gaiExerciseNr2iQuestionNr_total used
//          gaiExerciseNr_iQuestionNr2lsKanjiWriting_correctAnswer used
function fn_toggleShowCorrectAnswers_ResetExercise(iExerciseNr) {
   var sAntwortStatusImgId = iExerciseNr2sAntwortStatusImgId(iExerciseNr)

   // Sind im Moment alle Antworten korrekt angezeigt?
   // Dies ist der Fall, wenn das AntwortStatus-Smilie = "smilie_blague.gif" ist.
   var bAlleAntwortenKorrekt = document.images[sAntwortStatusImgId].src.search(/smilie_blague.gif/) != -1

   var iQuestionNr_total = gaiExerciseNr2iQuestionNr_total[iExerciseNr]
   for (var iQuestionNr=0; iQuestionNr<iQuestionNr_total; iQuestionNr++) {
      var sKanjiWriting
      if (bAlleAntwortenKorrekt) {
         // Das Exercise reseten, alle Fragezeichen anzeigen.
         // Das Fragezeichen als Antwort waehlen:
         sKanjiWriting = "UNVE"
      } else {
         // Alle Antworten korrekt anzeigen.
         // Die korrekte Antwort aus der globalen Variablen holen:
         sKanjiWriting = iExerciseNr_iQuestionNr2sKanjiWriting_correctAnswer(iExerciseNr, iQuestionNr)
      }
      // Die Antwort setzen:
      fn_processAnswer(iExerciseNr, iQuestionNr, sKanjiWriting)
   }

   if (bAlleAntwortenKorrekt) {
      // Den AntwortStatus-Smilie zurueck setzen: noch keine Antwort gewaehlt
      var sAntwortStatus = "resetExercise"
      iExerciseNr_sAntwortStatus2set_AntwortStatusImg(iExerciseNr, sAntwortStatus)
   } else {
      // Den AntwortStatus-Smilie setzen: alle Antworten wurden soeben korrekt angezeigt
      var sAntwortStatus = "allAnswers_correct"
      iExerciseNr_sAntwortStatus2set_AntwortStatusImg(iExerciseNr, sAntwortStatus)
   }

   void(0)
}

// --------------------------------------------------------------
// ----------- Funktionen fuer onMouseOver, onMouseOut etc. ENDE
// --------------------------------------------------------------




// --------------------------------------------------------------
// ----------- Funktionen zum Erzeugen des HTML-Codes der Uebungen START
// --------------------------------------------------------------


function get_hIntroductionMessageTable() {
   var ahRes = new Array()

   ahRes[ahRes.length] = '<table border=0 cellpadding=3 cellspacing=0 width=95% align=center style="border:1px solid black">'
   ahRes[ahRes.length] = ' <tr>'
   ahRes[ahRes.length] = '  <td>'

   ahRes[ahRes.length] = '<h3>How to work with these exercises?</h3>'

   ahRes[ahRes.length] = 'In these exercises you should <b>select a missing word</b> from a list of words in order to complete'
   ahRes[ahRes.length] = ' a sentence correctly.'

   ahRes[ahRes.length] = '<br>'
   ahRes[ahRes.length] = '<br>'
   ahRes[ahRes.length] = 'When you move the mouse over a question mark <img src=../Images/UNVERIF.gif> within an exercise a list of'
   ahRes[ahRes.length] = ' possible words is displayed.'
   ahRes[ahRes.length] = ' Please select the correct one.'
//   ahRes[ahRes.length] = ' Sometimes there are more than one correct selections.'
   ahRes[ahRes.length] = ' Sometimes the correct selection is a blank.'

   ahRes[ahRes.length] = '<br>'
   ahRes[ahRes.length] = '<br>'
   ahRes[ahRes.length] = 'The icon <img src=../Icons/smilie_indifferent.gif> in front of the exercise indicates an <b>unsolved exercise</b>,'
   ahRes[ahRes.length] = ' <img src=../Icons/smilie_triste.gif> indicates that your last selection was <b>incorrect</b>,'
   ahRes[ahRes.length] = ' <img src=../Icons/smilie_heureux.gif> indicates that your last selection was <b>correct</b>,'
   ahRes[ahRes.length] = ' <img src=../Icons/smilie_blague.gif> indicates that the <b>exercise is solved</b>.'

   ahRes[ahRes.length] = '<br>'
   ahRes[ahRes.length] = '<br>'
   ahRes[ahRes.length] = ' You can click on the icons <img src=../Icons/smilie_indifferent.gif>, <img src=../Icons/smilie_triste.gif> and'
   ahRes[ahRes.length] = ' <img src=../Icons/smilie_heureux.gif> to <b>show the solution</b> of the exercise.'
   ahRes[ahRes.length] = ' You can click on the icon <img src=../Icons/smilie_blague.gif> to <b>reset</b> the exercise.'
   ahRes[ahRes.length] = '  </td>'
   ahRes[ahRes.length] = ' </tr>'
   ahRes[ahRes.length] = '</table>'

   return ahRes.join("")
} // end of: function get_hIntroductionMessageTable



function iMenuNr_lsKanjiWriting2hDropDownMenu(iMenuNr, lsKanjiWriting) {
   var sMenuId = iMenuNr2sMenuId(iMenuNr)
   var sPopupName = sMenuId

   var ahRes = new Array()
   ahRes[ahRes.length] = '<DIV class="class_kanji_auswahl_menu"'
   ahRes[ahRes.length] = ' id="' + sPopupName2sPopupId(sMenuId) + '"'
   ahRes[ahRes.length] = ' onMouseOver="fn_clearTimeout_PopupHide(); return true;"'
   if (bNavigator_DOM) {
      ahRes[ahRes.length] = ' onMouseLeave=fn_setTimeout_PopupHide();' // funktioniert nur fuer IE
   } else {
      ahRes[ahRes.length] = ' onMouseOut=fn_DIV_onMouseOut2setTimeout_PopupHide()' // soll onMouseLeave simulieren
   }
   ahRes[ahRes.length] = '>'

   ahRes[ahRes.length] = '<table bgcolor="#eeeeee" border=0 cellpadding=2 cellspacing=0>'

   var asKanjiWriting = lsKanjiWriting.split(";")
   var iMaxKanjiLength = lsKanjiWriting2iMaxKanjiLength(lsKanjiWriting)
if(asKanjiWriting.length == 1 && asKanjiWriting[0] != "") {
 alert("Nur ein Eintrag iMenuNr=" + iMenuNr + ' asKanjiWriting[0]=' + asKanjiWriting[0])
}
   for (var i=0; i<asKanjiWriting.length; i++) {
      var sClass = iRowNr_sCellType2sClass(i,"td") 
      ahRes[ahRes.length] = ' <tr class="' + sClass + '">'
      ahRes[ahRes.length] = '  <td>'
      ahRes[ahRes.length] = '<a href="javascript:fn_processUsersAnswer(' + "'" + asKanjiWriting[i] + "'" + ');">'

      // Mit leeren Gifs auf die Breite der breitesten Antwort auffuellen:
      var iPad = iMaxKanjiLength - (asKanjiWriting[i].length / 4)
      for (var j=0; j<iPad; j++)
      asKanjiWriting[i] += "a1a0" // Leeres Gif
      // ACHTUNG: sKanjiWriting2hKanjiWriting muss angepasst werden, damit keine Links zu KanjiInfoSystem angelegt werden.
      var bNoKanjiLinks_To_KanjiInfoSystem = 1
      ahRes[ahRes.length] = sKanjiWriting2hKanjiWriting(asKanjiWriting[i], bNoKanjiLinks_To_KanjiInfoSystem)

      ahRes[ahRes.length] = '</a>'
      ahRes[ahRes.length] = '</td>'
      ahRes[ahRes.length] = ' </tr>'
   }

   ahRes[ahRes.length] = '</table>'
   ahRes[ahRes.length] = '</DIV>'

// Test
//document.writeln("<pre>")
//document.writeln(ahRes.join("\n").replace(/</g,"&lt;"))
//document.writeln("</pre>")

   return ahRes.join("")
} // function iMenuNr_lsKanjiWriting2hDropDownMenu(iMenuNr, lsKanjiWriting)



function iExerciseNr_iQuestionNr_iImgNr2sImgId(iExerciseNr, iQuestionNr, iImgNr) {
   return "img_Exercise" + iExerciseNr + "_Question" + iQuestionNr + "_Img" + iImgNr
}

function iExerciseNr2sAntwortStatusImgId(iExerciseNr) {
   return "img_AntwortStatus_Exercise" + iExerciseNr
}

function iMenuNr2sMenuId(iMenuNr) {
   return "menu_" + iMenuNr
}

// ";a4ac;a4ce;a4e2;a4cf;a4c1a4c2a4c1a4c2" -> 4
function lsKanjiWriting2iMaxKanjiLength(lsKanjiWriting) {
   var asKanjiWriting = lsKanjiWriting.split(";")
   var iMaxKanjiLength = 0
   for (var i=0; i<asKanjiWriting.length; i++) {
      var iKanjiLength = asKanjiWriting[i].length / 4
      if (iMaxKanjiLength < iKanjiLength)
      iMaxKanjiLength = iKanjiLength
   }

   return iMaxKanjiLength
}


// Global definition
// globale Variable mit den korrekten Antworten pro Exercise und Frage.
// Zu einer Frage koennen mehrere Antworten richtig sein;
// die korrekten Antworten sind in der Liste lsKanjiWriting_correctAnswer
// enthalten.
var gaiExerciseNr_iQuestionNr2lsKanjiWriting_correctAnswer = new Array()

// Global definition
// globale Variable mit dem Menu-Bezeichner iMenuNr pro Exercise und Frage.
var gaiExerciseNr_iQuestionNr2iMenuNr = new Array()

// Global definition
// globale Variable mit der Information, ob die Frage korrekt beantwortet wurde, pro Exercise und Frage.
var gaiExerciseNr_iQuestionNr2bCorrectAnswerGiven = new Array()

// Global definition
// globale Variable mit der Anzahl der Fragen pro Exercise:
var gaiExerciseNr2iQuestionNr_total = new Array()


// "a4b5# a4d0" --> <img src="../Kanji16/a4b5.gif" border=0 width=16 height=16><img Fragezeichen> <img src="../Kanji16/a4d0...
// Globals: gaiExerciseNr_iQuestionNr2lsKanjiWriting_correctAnswer set
//          gaiExerciseNr_iQuestionNr2iMenuNr set
//          gaiExerciseNr_iQuestionNr2bCorrectAnswerGiven set
//          gaiExerciseNr2iQuestionNr_total set
//          glsKanjiWriting_currentMenu set
//          giMenuNr_currentMenu used
//          sAntwortStatus2sAntwortStatusImg_Src used
function sKanjiWriting_SpaceSeparated_Exercise2hKanjiWriting(iExerciseNr, sKanjiWriting_SpaceSeparated_Exercise) {
   var sRegExp_Pattern = /([^#]*)(#[^#]*#)(.*)/
   var sRegExp_Separator = /#/
   var sKanjiWriting_SpaceSeparated_Rest = sKanjiWriting_SpaceSeparated_Exercise
   var ahRes = new Array()
   var iQuestionNr = 0

   // Das smilie vor der eigentlichen Frage zeigt den AntwortStatus an:
   var sAntwortStatusImgId = iExerciseNr2sAntwortStatusImgId(iExerciseNr)
   var sAntwortStatusImg_Src = sAntwortStatus2sAntwortStatusImg_Src["resetExercise"]
   ahRes[ahRes.length] = '<a'
   ahRes[ahRes.length] = ' href="javascript:fn_toggleShowCorrectAnswers_ResetExercise(' + iExerciseNr + ')"'
   // return true in onMouseOver notwendig, damit status-Zeile nicht von der Link-Target-Angabe ueberschrieben wird.
   ahRes[ahRes.length] = ' onMouseOver="fn_onMouseOver_sAntwortStatusImg(' + iExerciseNr + '); return true;"'
   ahRes[ahRes.length] = ' onMouseOut="window.status=' + "''" + '; return true;"'
   ahRes[ahRes.length] = '>'
   ahRes[ahRes.length] = '<img id="' + sAntwortStatusImgId + '" src="' + sAntwortStatusImg_Src + '" width=20 height=20 border=0>'
   ahRes[ahRes.length] = '</a>'
   ahRes[ahRes.length] = '&nbsp;&nbsp;'

   // Das Array mit den korrekten Antworten fuer alle Fragen in diesem Exercise anlegen:
   gaiExerciseNr_iQuestionNr2lsKanjiWriting_correctAnswer[iExerciseNr] = new Array()

   // Das Array mit dem iMenuNr fuer alle Fragen in diesem Exercise anlegen:
   gaiExerciseNr_iQuestionNr2iMenuNr[iExerciseNr] = new Array()

   // Das Array mit der Information, ob die jeweilige Frage in dem Exercise korrekt beantwortet wurde:
   gaiExerciseNr_iQuestionNr2bCorrectAnswerGiven[iExerciseNr] = new Array()

   while (sRegExp_Separator.test(sKanjiWriting_SpaceSeparated_Rest)) {
      sRegExp_Pattern.exec(sKanjiWriting_SpaceSeparated_Rest)
      var sKanjiWriting_SpaceSeparated_firstPart = RegExp.$1
      var lsKanjiWriting_correctAnswer = RegExp.$2
      sKanjiWriting_SpaceSeparated_Rest = RegExp.$3

      // Zeige den Teil des Satzes bis zum naechsten Fragezeichen:
      ahRes[ahRes.length] = sKanjiWriting_SpaceSeparated2hKanjiWriting(sKanjiWriting_SpaceSeparated_firstPart)

      // Die umklammernden # aus der Liste der korrekten Antworten entfernen:
      lsKanjiWriting_correctAnswer = lsKanjiWriting_correctAnswer.replace(/#/g,'')

      // Die korrekte Antwort zu der aktuellen Frage in der globalen Variablen speichern:
      gaiExerciseNr_iQuestionNr2lsKanjiWriting_correctAnswer[iExerciseNr][iQuestionNr] = lsKanjiWriting_correctAnswer

      // Die korrekte Antwort in die Liste der in das Menu aufzunehmenden Antworten hinzufuegen:
      glsKanjiWriting_currentMenu = glsKanjiWriting_currentMenu + ";" + lsKanjiWriting_correctAnswer

      // Das verwendete Menu in der globalen Variablen speichern:
      gaiExerciseNr_iQuestionNr2iMenuNr[iExerciseNr][iQuestionNr] = giMenuNr_currentMenu

      // Alle Fragen sind zuerst unbeantwortet:
      gaiExerciseNr_iQuestionNr2bCorrectAnswerGiven[iExerciseNr][iQuestionNr] = 0

      // -----------------------
      // Zeige das Fragezeichen.
      // Wenn man ueber das Fragezeichen faehrt, wird das Menu iMenuNr angezeigt.
      var iImgNr = 0 // das Fragezeichen ist das 0-te Gif
      var sImgId  = iExerciseNr_iQuestionNr_iImgNr2sImgId(iExerciseNr, iQuestionNr, iImgNr)

      // Fuer NS4 soll A benutzt werden, weil onMouseOver/Out bei NS4 nur mit A funktioniert.
      // Fuer andere Browser soll SPAN benutzt werden.
      var sTag = (bNavigator_Nav4 ? "a" : "span")
      ahRes[ahRes.length] = '<' + sTag
      if (bNavigator_Nav4) {
         ahRes[ahRes.length] = ' href="javascript:void(0)"'
      }
      ahRes[ahRes.length] = ' onMouseOver="javascript:fn_onMouseOver_iExerciseNr_iQuestionNr2showMenu(' + iExerciseNr + ',' + iQuestionNr + '); return true;"'
      ahRes[ahRes.length] = ' onMouseOut="javascript:fn_onMouseOut_iExerciseNr_iQuestionNr2setTimeout_PopupHide(' + iExerciseNr + ',' + iQuestionNr + '); return true;"'
      ahRes[ahRes.length] = '>'
      ahRes[ahRes.length] = '<img id="' + sImgId + '" src="../Images/UNVERIF.gif" width=16 height=16 border=0>'
      ahRes[ahRes.length] = '</' + sTag + '>'

      // -----------------------
      // Lege leere Gifs an, die spaeter durch die vom User gewaehlte Antwort ersetzt werden.
      var iMaxKanjiLength = 10
      //Test ahRes[ahRes.length] = iMaxKanjiLength + sKanjiWriting_correctAnswer 
      for (var iImgNr=1; iImgNr<iMaxKanjiLength; iImgNr++) {
         var sImgId = iExerciseNr_iQuestionNr_iImgNr2sImgId(iExerciseNr, iQuestionNr, iImgNr)
         ahRes[ahRes.length] = '<img id="' + sImgId + '" src="../Kanji16/a1a0.gif" width=16 height=16 border=0'
         if (bNavigator_DOM) {
            ahRes[ahRes.length] = ' style="display:none"'
         }
         ahRes[ahRes.length] = '>'
      }

      iQuestionNr++
   }

   // Zeige das letzte Stueck des Satzes, das ohne Fragen ist.
   ahRes[ahRes.length] = sKanjiWriting_SpaceSeparated2hKanjiWriting(sKanjiWriting_SpaceSeparated_Rest)

   // Die Anzahl der Fragen pro Exercise speichern:
   var iQuestionNr_total = iQuestionNr
   gaiExerciseNr2iQuestionNr_total[iExerciseNr] = iQuestionNr_total

   return ahRes.join("")
} // end of: function sKanjiWriting_SpaceSeparated_Exercise2hKanjiWriting



// --------------------------------------------------------------
// ----------- Funktionen zum Erzeugen des HTML-Codes der Uebungen ENDE
// --------------------------------------------------------------



function fn_lsWord2lsWord_SortedUnique(lsWord) {

   var asWord = lsWord.split(";")
   var asWord_SortedUnique = new Array()
   var asWord_bereitsBeruecksichtigt = new Array()

   for (e in asWord) {
//Test      document.writeln(e + ' ' + asWord[e] + '<br>')
      var sWord = asWord[e]
      if (asWord_bereitsBeruecksichtigt[sWord])
         continue
      asWord_bereitsBeruecksichtigt[sWord] = 1
      asWord_SortedUnique[asWord_SortedUnique.length] = sWord
   }

   asWord_SortedUnique.sort()
   return asWord_SortedUnique.join(";")
}



// Global definition
var giExerciseNr_currentExercise = 0

// Global definition
var gaiExerciseNr2hKanjiWriting = new Array()


// Globals: giExerciseNr_currentExercise used and set
//          gaiExerciseNr2hKanjiWriting set
function fn_create_an_exercise(sMixedSentence_sKanjiWriting_SpaceSeparated_Exercise, sRomajiWriting, sTranslation) {
   // Entferne das erste und das letzte @ aus sMixedSentence_sKanjiWriting_SpaceSeparated_Exercise:
   var sKanjiWriting_SpaceSeparated_Exercise = sMixedSentence_sKanjiWriting_SpaceSeparated_Exercise.replace(/@/g,"")

   var hKanjiWriting = sKanjiWriting_SpaceSeparated_Exercise2hKanjiWriting(giExerciseNr_currentExercise, sKanjiWriting_SpaceSeparated_Exercise)

   var ahRenshuuTable = new Array()

   ahRenshuuTable[ahRenshuuTable.length] = '<table border=0 cellpadding=3 cellspacing=0 width=95% align=center style="border:1px solid black">'

   var sClass = iRowNr_sCellType2sClass(giExerciseNr_currentExercise, "td") 
   ahRenshuuTable[ahRenshuuTable.length] = ' <tr class="' + sClass + '">'
   ahRenshuuTable[ahRenshuuTable.length] = '  <td>'
   ahRenshuuTable[ahRenshuuTable.length] = hKanjiWriting

   var sSpanId = "id_solution_span" + giExerciseNr_currentExercise
   ahRenshuuTable[ahRenshuuTable.length] = '  <span id="' + sSpanId + '" + style="display:none">'

   ahRenshuuTable[ahRenshuuTable.length] = '  <br>'
   ahRenshuuTable[ahRenshuuTable.length] = '<img src="../Images/1pix.gif" width=20 height=20>&nbsp;&nbsp;'
   ahRenshuuTable[ahRenshuuTable.length] = sRomaji2hRomaji(sRomajiWriting, giExerciseNr_currentExercise)
   ahRenshuuTable[ahRenshuuTable.length] = '  </span>'

   ahRenshuuTable[ahRenshuuTable.length] = '  <br>'
   ahRenshuuTable[ahRenshuuTable.length] = '<img src="../Images/1pix.gif" width=20 height=20>&nbsp;&nbsp;'
   ahRenshuuTable[ahRenshuuTable.length] = sTranslation

   ahRenshuuTable[ahRenshuuTable.length] = '  </td>'
   ahRenshuuTable[ahRenshuuTable.length] = ' </tr>'
   ahRenshuuTable[ahRenshuuTable.length] = '</table>'

   gaiExerciseNr2hKanjiWriting[gaiExerciseNr2hKanjiWriting.length] = ahRenshuuTable.join("")

   giExerciseNr_currentExercise++
}



// Global definition
var giMenuNr_currentMenu = 0

// Global definition
var glsKanjiWriting_currentMenu = ""

// Global definition
var gaiMenuNr2hDropDownMenu = new Array()

// Globals: glsKanjiWriting_currentMenu set
function fn_start_a_group_of_exercises() {
   glsKanjiWriting_currentMenu = ""
}


// Globals: giMenuNr_currentMenu used and set
//          glsKanjiWriting_currentMenu used
//          gaiMenuNr2hDropDownMenu set
function fn_finish_a_group_of_exercises() {
   // Erstes ";" aus der Liste glsKanjiWriting_currentMenu entfernen, dann eindeutig sortieren:
   var lsKanjiWriting = fn_lsWord2lsWord_SortedUnique(glsKanjiWriting_currentMenu.replace(/;/,''))
   var hDropDownMenu = iMenuNr_lsKanjiWriting2hDropDownMenu(giMenuNr_currentMenu, lsKanjiWriting)

   gaiExerciseNr2hKanjiWriting[gaiExerciseNr2hKanjiWriting.length] = "<br>"

   giMenuNr_currentMenu++

   gaiMenuNr2hDropDownMenu[gaiMenuNr2hDropDownMenu.length] = hDropDownMenu
}




// Globals: gaiExerciseNr2hKanjiWriting used
//          gaiMenuNr2hDropDownMenu used
function fn_writeln_hRenshuuTables(iLessonNr) {
   document.writeln(get_hIntroductionMessageTable())
   document.writeln("<br>")
   document.writeln(gaiExerciseNr2hKanjiWriting.join(""))
   document.writeln(gaiMenuNr2hDropDownMenu.join(""))
}

