/* showmap.js  Display HIM-messages in maps  HaCon 01/2007 */
var fts = false;
var ftsResultColorize = true;

/* Returns the absolute x-position of element el */
function absLeft(el) {
   return (el.offsetParent)?
      el.offsetLeft+absLeft(el.offsetParent) : el.offsetLeft;
   }

/* Returns the absolute y-position of element el */
function absTop(el) {
   return (el.offsetParent)?
      el.offsetTop+absTop(el.offsetParent) : el.offsetTop;
   }

function e() {/* cool */
   var element = arguments[0];
   element = document.getElementById(element);
   return element;
   }

/* Show message containers */
function showContainer(id, iconPixPos ){
   hideAllContainer();
   /* get current icon position */
   y = iconPixPos.y;
   x = iconPixPos.x;
   y = y + messageToIconOffsetY;
   if (x >= maxXforMessages){/* x correction */
      x -= messageToIconOffsetX;
      x -= maxXCorrector;
      x += 10;
      }
   else{
      x = x + messageToIconOffsetX;
      }
   e('mBox'+id).style.left=x;
   e('mBox'+id).style.top=y;
   e('mBox'+id).style.zIndex=99;
   e('mBox'+id).style.display='block';
   }

/* Hide message containers */
function hideAllContainer(){/* identify and hide all message icons etc. */
   elementIndex = 0;
   elementCollector = e('mapContent').getElementsByTagName('div');
   while (elementIndex<elementCollector.length)
      {
      if(elementCollector[elementIndex].id.indexOf('icon')!= -1)
         {
         e(elementCollector[elementIndex].id).style.zIndex=11;
         e(elementCollector[elementIndex].id).style.zIndex=11;
         }
      if(elementCollector[elementIndex].id.indexOf('mBox')!= -1)
         {
         e(elementCollector[elementIndex].id).style.display='none';
         e(elementCollector[elementIndex].id).style.zIndex=11;
         }
      elementIndex++;
      }
   }

function hideContainer(id){
   e('mBox'+id).style.display='none';
   e('mBox'+id).style.zIndex=11;
   }

/* Show crosshair */
function highlightMessageIcon(x,y){
   e('crossX').style.top=y+8;
   e('crossX').style.left=0;
   e('crossX').style.display='block';
   e('crossX').style.zIndex=8;
   e('crossY').style.top=0;
   e('crossY').style.left=x+8;
   e('crossY').style.display='block';
   e('crossY').style.zIndex=8;
   }
/* Hide crosshair */
function stopHighlighting(){
   e('crossX').style.display='none';
   e('crossY').style.display='none';
   }

/* close window */
function setShowMapCloseLink(){
  if(window.opener && e('showMapClose')){
     closeLink = '<a class=\"btnAsLink\" onmouseover=\"window.status=\''+closeText+'\'; return true\" onmouseout=\"window.status=\'\'; return true\" href=\"javascript:window.close();\">'+closeText+'<a>';
     e('showMapClose').innerHTML = closeLink;
     }
  }

/* sbb_him_showmap_filter.js HaCon mib a&f 2007-03 */

prepare = false;
initial = false;

var sr = new Array(); /* Matrix zum Speichern der Sortiereihenfolge */
sr[0] = new Array(0,0,0,0,0);
sr[1] = new Array(0,0,0,0,0);
sr[2] = new Array(0,0,0,0,0);
sr[3] = new Array(0,0,0,0,0);
sr[4] = new Array(0,0,0,0,0);
sr[5] = new Array(0,0,0,0,0);

uicSort = null;

/*
Störung     == typeIndexMapping[2]
Verspätung  == typeIndexMapping[3]
Info        == typeIndexMapping[0]
Baustelle   == typeIndexMapping[1]
Busersatz   == typeIndexMapping[4]
*/
var typeIndexMapping =  new Array(2,1,4,3,0); /* Message type (Störung etc.) -> map sort order by priority-index */

/* Initialer Aufruf bei 'onload' */
function createTable(){
  /* Initiales Einblenden des Filterblockes */
  if(e('mapActionMenu'))
     e('mapActionMenu').style.display='';
     e('himTableStatic').style.display='none';

  if(prepare == false) prepareTable();
  initialSortTable();
  /* initial filter by date */
  initial = true;
  filterTableByDate(e('filterDateBegin').value,e('filterDateEnd').value);
  initial = false;
  }

function prepareTable() /* prepare some values like date objects etc.*/
   {
   for (var st=0;st<him.length;st++)
      {
      for (var rowNr = 0;rowNr<him[st].length;rowNr++)
         {
         if(typeof him[st][rowNr] != 'undefined')
            {
            /* Fuer die Sortierung: Ersetze HTML-Entities durch 'Umlaute' und speichere in separaten Spalten */
            him[st][rowNr][24] = replaceUmlaute(him[st][rowNr][3]);
            him[st][rowNr][25] = replaceUmlaute(him[st][rowNr][4]);

            /* Create dateobjs -> for sorting by date */
            him[st][rowNr][22] = new Date(him[st][rowNr][7], him[st][rowNr][6]-1, him[st][rowNr][5], him[st][rowNr][14], him[st][rowNr][15], "00");
            him[st][rowNr][23] = new Date(him[st][rowNr][10], him[st][rowNr][9]-1, him[st][rowNr][8], him[st][rowNr][17], him[st][rowNr][18], "00");

            /* Create dateobjs -> for sorting by date */
            /* Format: 23.01.2007 14:41:00 */
            var mTimeStamp = him[st][rowNr][43].split(' ')
            var mTsDay     = mTimeStamp[0].split('.')[0];
            var mTsMonth   = mTimeStamp[0].split('.')[1]-1;
            var mTsYear    = mTimeStamp[0].split('.')[2];
            var mTsHour    = mTimeStamp[1].split(':')[0];
            var mTsMinutes = mTimeStamp[1].split(':')[1];
            var mTsSeconds = mTimeStamp[1].split(':')[2];
            him[st][rowNr][44] = new Date(mTsYear,mTsMonth,mTsDay,mTsHour,mTsMinutes,mTsSeconds);
            }
         }
      }
   prepare = true;
   }

function prepareDateFilter(date, hh){
   var prepareDate = date.split(".");
   var yy = "20"+prepareDate[2];
   var mm = prepareDate[1]-1;
   var dd = prepareDate[0];
   return new Date(yy,mm,dd,hh,0,0);
   }

function resetInitview(){
   for (var n=0;n<=5;n++)
      {
      initView[n] = 0;
      }
   }

function filterByType()
  {
  if(typeof him == 'undefined' && archiv == true)
     {
     }
  else
     filterTableByDate(e('filterDateBegin').value,e('filterDateEnd').value);
  }

function filterTableByDate(date1,date2)
   {

   if(document.getElementById('filterFreitext'))
     {
     var ftValue = document.getElementById('filterFreitext').value;
     ftValue = encode(ftValue);
     fts = (ftValue!="")? true : false;
     }

   typeFilter = 5;   /* initial value */
   if(updateMode == "customerInternal" || updateMode == "himuser")
      {
      for (var d=0;d<=5;d++)
         {
         if(e('mdt'+d) && e('mdt'+d).checked == true)
            typeFilter = e('mdt'+d).value;
         }
      }

   // Remove all map objects
   if (useMap)
     hgMapCtrl.clear();

   if(e('messageDisplayType'))
      e('messageDisplayType').selectedIndex=0;
   var fS = prepareDateFilter(date1, 0); /* Set filter Begin == fS */
   var fE = prepareDateFilter(date2, 24); /* Set filter End == fE */
   if(fS > fE)
      {
      alert(unescape(checkDateFilterText)); /* Die Eingabe ist unsinnig! */
      }
   else
      {
      resetInitview();
      for (var t=0;t<him.length;t++)
         {
         for (var rowNr = 0;rowNr<him[t].length;rowNr++)
            {
            if(typeof him[t][rowNr] != 'undefined')
               {
               if (him[t][rowNr][46] == "")
                  {
                  him[t][rowNr][46] = new Date(him[t][rowNr][33], him[t][rowNr][32]-1, him[t][rowNr][31], him[t][rowNr][37], him[t][rowNr][38], "00");
                  }
               if (him[t][rowNr][47] == "")
                  {
                  him[t][rowNr][47] = new Date(him[t][rowNr][36], him[t][rowNr][35]-1, him[t][rowNr][34], him[t][rowNr][39], him[t][rowNr][40], "00");
                  }
               dS = him[t][rowNr][46];
               dE = him[t][rowNr][47];

               /* fts filter */
               if(fts)
                 {
                 if(((him[t][rowNr][12].indexOf(ftValue) != -1) || (him[t][rowNr][13].indexOf(ftValue) != -1) || (him[t][rowNr][30].indexOf(ftValue) != -1)) && ((t == 3 && initial) || ((dS < fE && dE >= fS) && (him[t][rowNr][2] == typeFilter || typeFilter>4))))
                   {
                   initView[t] = 1;
                   him[t][rowNr][21] = true; /* Show this messages */

                   /* Colorize */
                   if(ftsResultColorize)
                     {
                     var text_51 = him[t][rowNr][12];/* Header       */
                     var text_52 = him[t][rowNr][13];/* Text, Lead   */
                     var text_53 = him[t][rowNr][30];/* Line, Product*/
                     var ftsExp = eval ("/"+ftValue+"/g");
                     him[t][rowNr][51] = text_51.replace(ftsExp,"<span style=\"background-color:#FA0;\">"+ftValue+"<\/span>");
                     him[t][rowNr][52] = text_52.replace(ftsExp,"<span style=\"background-color:#FA0;\">"+ftValue+"<\/span>");
                     him[t][rowNr][53] = text_53.replace(ftsExp,"<span style=\"background-color:#FA0;\">"+ftValue+"<\/span>");
                     }
                   if(archiv == false)
                     handleMapIcon(him[t][rowNr][0],true)
                   }
                 else
                   {
                   him[t][rowNr][21] = false; /* Hide this messages */
                   if(archiv == false)
                     handleMapIcon(him[t][rowNr][0],false)
                   }
                 }
               /* don't filter country messages if initial sort dS < fE because FE is 00:00 on the next day */
               else if((t == 3 && initial) || ((dS < fE && dE >= fS) && (him[t][rowNr][2] == typeFilter || typeFilter>4)))
                 {
                 initView[t] = 1;
                 him[t][rowNr][21] = true; /* Show this messages */
                 if(archiv == false)
                   handleMapIcon(him[t][rowNr][0],true)
                 }
               else
                 {
                 him[t][rowNr][21] = false; /* Hide this message */
                 if(archiv == false)
                   handleMapIcon(him[t][rowNr][0],false)
                 }
               }
            }
         }
      }
   if(e('messageTable') && e('himTable') && e('himTable').hasChildNodes())
      e('himTable').removeChild(e('messageTable'));
   drawTable();
   }

function handleMapIcon(idx,visibility)/* Hide/Show icons on map */
   {
   if( visibility && useMap )
     // Show this message in the map
     hgMapCtrl.showMessageByNumber( idx+1 );
   }

function showAllMessages(){
   //e('macroMs').style.display='';
   if(e('messageDisplayType'))
      e('messageDisplayType').selectedIndex=0;
   for (var t=0;t<him.length;t++)
      {
      for (var rowNr = 0;rowNr<him[t].length;rowNr++)
         {
         if(typeof him[t][rowNr] != 'undefined')
            {
            initView[t] = 1;
            him[t][rowNr][21] = true; /* Show this messages */

            if(archiv == false)
               handleMapIcon(him[t][rowNr][0],true)
            }
         }
      }

   if(e('messageTable') && e('himTable') && e('himTable').hasChildNodes())
      e('himTable').removeChild(e('messageTable'));
   drawTable();
   }


function replaceUmlaute(s0){/* Daten liegen in unsichtbarer Spalte zum sortieren */
   s1 = s0.replace(/&#214;/g,"Oe");
   s2 = s1.replace(/&#196;/g,"Ae");
   s3 = s2.replace(/&#220;/g,"Ue");
   s4 = s3.replace(/&#246;/g,"oe");
   s5 = s4.replace(/&#228;/g,"ae");
   s6 = s5.replace(/&#252;/g,"ue");
   return s6;
   }

function encode(at){
      var t = at.replace(/'/g, "&#39;");
      t = t.replace(/À/g, "$#192;");
      t = t.replace(/à/g, "&#224;");
      t = t.replace(/Â/g, "&#194;");
      t = t.replace(/â/g, "&#226;");
      t = t.replace(/Æ/g, "&#198;");
      t = t.replace(/æ/g, "&#230;");
      t = t.replace(/Ç/g, "&#199;");
      t = t.replace(/ç/g, "&#231;");
      t = t.replace(/È/g, "&#200;");
      t = t.replace(/è/g, "&#232;");
      t = t.replace(/É/g, "&#201;");
      t = t.replace(/é/g, "&#233;");
      t = t.replace(/Ê/g, "&#202;");
      t = t.replace(/ê/g, "&#234;");
      t = t.replace(/Ë/g, "&#203;");
      t = t.replace(/ë/g, "&#235;");
      t = t.replace(/Î/g, "&#206;");
      t = t.replace(/î/g, "&#238;");
      t = t.replace(/Ï/g, "&#207;");
      t = t.replace(/ï/g, "&#239;");
      t = t.replace(/Ô/g, "&#212;");
      t = t.replace(/ô/g, "&#244;");
      t = t.replace(/Œ/g, "&#338;");
      t = t.replace(/œ/g, "&#339;");
      t = t.replace(/Ù/g, "&#217;");
      t = t.replace(/ù/g, "&#249;");
      t = t.replace(/Û/g, "&#219;");
      t = t.replace(/û/g, "&#251;");
      t = t.replace(/Ÿ/g, "&#376;");
      t = t.replace(/ÿ/g, "&#255;");
      t = t.replace(/Ö/g, "&#214;");
      t = t.replace(/Ä/g, "&#196;");
      t = t.replace(/Ü/g, "&#220;");
      t = t.replace(/ö/g, "&#246;");
      t = t.replace(/ä/g, "&#228;");
      t = t.replace(/ü/g, "&#252;");
      t = t.replace(/Ì/g, "&#204;");
      t = t.replace(/ì/g, "&#236;");
      t = t.replace(/Í/g, "&#205;");
      t = t.replace(/í/g, "&#237;");
      t = t.replace(/Ò/g, "&#210;");
      t = t.replace(/ò/g, "&#242;");
      t = t.replace(/Ó/g, "&#211;");
      t = t.replace(/ó/g, "&#243;");
      t = t.replace(/Ú/g, "&#218;");
      t = t.replace(/ú/g, "&#250;");
      return t;
    }

/* Draw the table */
function drawTable()
   {
   nnm = new Array();
   //var initialSort =  new Array(4,2,0,1,3,5); /* Initiale Sortierung aller 'fuenf' MatchType-Tabellen */
   var initialSort =  new Array(5,0,1,2,3,4); /* Initiale Sortierung aller 'sechs' MatchType-Tabellen */

   document.getElementById('himTable').innerHTML='';

   /* The complete table */
   var tableCode = '<table class="himmessages" cellspacing="0" id="messageTable" style="width:'+cMapWidth+'px;">';

   /* Schleife über das Array 'him' -> enthaelt alle MatchType-Tabllen */
   for(var t=0;t<him.length;t++)
      {
      st = initialSort[t]; /* ersetze him Index durch Sortierindex 'initialSort' durch SBB vorgegeben */

      /* Pruefe ob initial eine Tabelle fuer einen Typ angezeigt werden soll */
      if(initView[st] == 1)
         {
         var curColSpan = 8;
         if (updateMode == "customerInternal")
            {
            curColSpan ++;
            }

         /* Followup column */
         if (updateMode == "himuser")
            {
            curColSpan++;
            }

         /* Ueberschriften der Tabellen-Zellen */
         tableCode += '<tr><th class="first headline" colspan="'+curColSpan+'">'+th_texts[st][7]+'</th></tr>';

         /* GLOBAL = 4, REGION = 2, LINE/NORMAL = 0, LOCATION = 1,
            COUNTRY/MACRO = 3, TRAIN = 5 */

         /* Ueberschriften der Tabellen-Zellen */
         tableCode += '<tr><th class="icon first"><a href="javascript:sortTable('+st+',2)">'+th_texts[st][0]+'</a></th>'+
                      '<th class="number"><a href="javascript:sortTable('+st+',0)">'+tNumber+'</a><a name="'+th_texts[st][1]+'"></a></th>';
         if(st == 0 || st == 5)
            {
            tableCode += '<th class="message"><a href="javascript:sortTable('+st+',22)">'+th_texts[st][4]+'</a></th>'+
                         '<th class="message"><a href="javascript:sortTable('+st+',24)">'+th_texts[st][2]+'</a></th>'+
                         '<th class="message"><a href="javascript:sortTable('+st+',25)">'+th_texts[st][3]+'</a></th>'+
                         '<th class="message"><a href="javascript:sortTable('+st+',30)">'+th_texts[st][6]+'</a></th>'+
                         '<th class="message"><a href="javascript:sortTable('+st+',12)">'+th_texts[st][5]+'</a></th>';
            }
         else
            {
            tableCode += '<th class="message"><a href="javascript:sortTable('+st+',22)">'+th_texts[st][3]+'</a></th>'+
                         '<th class="message" colspan="2"><a href="javascript:sortTable('+st+',24)">'+th_texts[st][2]+'</a></th>'+
                         '<th class="message"><a href="javascript:sortTable('+st+',30)">'+th_texts[st][5]+'</a></th>'+
                         '<th class="message"><a href="javascript:sortTable('+st+',12)">'+th_texts[st][4]+'</a></th>';
            }
         if (updateMode == "customerInternal")
            tableCode += '<th class="message"><a href="javascript:sortTable('+st+',48)">'+th_texts[st][8]+'</a></th>';

         tableCode += '<th class="message timestamp"><a href="javascript:sortTable('+st+',44)">'+th_texts[st][9]+'</a></th>';

         /* Followup column */
         if (updateMode == "himuser")
         {
            tableCode += '<th><a title="'+tFollowupMessages+'">'+th_texts[st][10]+'</a></th>';
         }

         tableCode += '</tr>';

         /* Set the data */
         for (var rowNr = 0;rowNr<him[st].length;rowNr++)
            {
            if(him[st][rowNr][21] == true && him[st][rowNr][26] == true) /* visibility -> changed by filters AND 'display' */
               {
               icon = (him[st][rowNr][1] != null) ? countryIcons[him[st][rowNr][1]]+' ' :'';
               no = him[st][rowNr][0] + 1;
               tableCode += '<tr id="messageTableRowForMessageNumber_' + no + '" >';
               //tableCode += '<td class="icon first">'+messageTypeCode[him[st][rowNr][2]] +'</td>';
               tableCode += '<td class="icon first"><img src="'+messageTypeCode[him[st][rowNr][2]].src +'" alt="" style="width:16px;height:16px"></td>';
               //tableCode += '<td class="icon first" id="row'+rowNr+'"></td>';
               //document.getElementById('row'+rowNr).appendChild(messageTypeCode[him[st][rowNr][2]]);
               tableCode += '<td class="nr">'+ no +'</td>';

               /* JS calendar ? */
               tableCode += (him[st][rowNr][11] == true) ? createServicedaysCalendar(st,rowNr) : createDatePeriod(st,rowNr);

               if(him[st][rowNr][20]==0 || him[st][rowNr][20]==5) /* match location type == 0 -> Fahrten/Routen/Linien */
                  {
                  tableCode += '<td class="dep">'+ him[st][rowNr][3] +'&nbsp;</td><td class="arr">'+ him[st][rowNr][4] +'&nbsp;</td>';
                  }
               else if(him[st][rowNr][20]!=4) /* match location type != 4 -> Station/Region/Ausland */
                  {
                  tableCode += '<td class="dep" colspan="2">'+icon+him[st][rowNr][3] +'</td>';
                  }

               /* Message */
               if(him[st][rowNr][20]==4)
                  {
                  /* Line | Journey | Products -> Not available in Global messages */
                  tableCode += '<td class="message" colspan="4">'+ createMessageText(st,rowNr) + '</td>';
                  }
               else
                  {
                  /* Line | Journey | Products */
                  if(fts && ftsResultColorize)
                    mot = (him[st][rowNr][53] == null)? '&nbsp;':him[st][rowNr][53];
                  else
                    mot = (him[st][rowNr][30] == null)? '&nbsp;':him[st][rowNr][30];
                  tableCode += '<td class="message">'+mot+'&nbsp;</td>';
                  tableCode += '<td class="message">'+ createMessageText(st,rowNr) + '</td>';
                  }

               /* user id */
               tableCode += (updateMode == "customerInternal") ? createID(st,rowNr):'';


               /* Timestamp of message */
               if(him[st][rowNr][43] != null)
                  {
                  var mTimeStamp = him[st][rowNr][43].split(' ')
                  var mTsDay     = mTimeStamp[0].split('.')[0];
                  var mTsMonth   = mTimeStamp[0].split('.')[1];/* Monat OHNE '-1', da kein 'date-obj' sondern 'string' */
                  var mTsYear    = mTimeStamp[0].split('.')[2].substring(2,4); /* Jahr nur zweistellig */
                  var mTsHour    = mTimeStamp[1].split(':')[0];
                  var mTsMinutes = mTimeStamp[1].split(':')[1];
                  var mTsSeconds = mTimeStamp[1].split(':')[2];
                  var tsCode = mTsDay+'.'+mTsMonth+'.'+mTsYear+'<br>'+mTsHour+':'+mTsMinutes;
                  }
               else
                  var tsCode = '&nbsp;';

               tableCode += '<td class="message timestamp">'+ tsCode + '</td>';

               /* Followup */
               if (updateMode == "himuser")
                  {
                   tableCode += '<td>';
                   var imageFollowup = '';
                   var urlFollowup = urlHimInfoAbsolute + 'action=show_followup_messages&numberObjects=1&objectState_0=1&object.0='+him[st][rowNr][48]+'&buttonShowMessageHierarchySelected&popupVersion';
                   if (him[st][rowNr][49] == 0) //parent == 0
                      {
                      if (him[st][rowNr][50].length > 0 ) // childs
                         {
                          tableCode += '<a href="javascript:openPopup(\''+urlFollowup+'\',\'\',50,50,800,600,\'001000\')">'+imgFollowupRoot+'</a>';
                         }
                      else
                         {
                        tableCode += '&nbsp;';
                         }
                      }
                   else
                      {
                      if (him[st][rowNr][50].length > 0 ) // childs
                         {
                          tableCode += '<a href="javascript:openPopup(\''+urlFollowup+'\',\'\',50,50,800,600,\'001000\')">'+imgFollowupNode+'</a>';
                         }
                      else
                         {
                          tableCode += '<a href="javascript:openPopup(\''+urlFollowup+'\',\'\',50,50,800,600,\'001000\')">'+imgFollowupLeaf+'</a>';
                         }
                      }
                   tableCode += '</td>';
                  }

               tableCode += '</tr>';

               if((st == 4 || st == 3) && archiv == false && mapIsGlobal == true)
                  {
                  selectForeignMessages(him[st][rowNr][0],him[st][rowNr][1],him[st][rowNr][3]);
                  }

               }
            }
         tableCode += '<tr><td colspan="'+curColSpan+'" style="border:none;line-height:10px;">&nbsp;</td></tr>';
         }
      }

   tableCode += '</table>';

   e('himTable').innerHTML = tableCode;

   /* no map in archiv available -> disable fm-container */
   if(archiv == false && mapIsGlobal == true){
      displayForeignMessages();
      }
   }

function selectForeignMessages(mIndex,uicCode,countryName)
   {
   if(typeof nnm[uicCode] == 'undefined')/* keep first found message per 'end' uiccode */
      {
      nnm[uicCode] = new Array(mIndex,1,countryName);
      }
   else
      {
      nnm[uicCode][1]++; /* count messages per uicCode */
      }
   }

function displayForeignMessages()
   {
   fmCode = '';
   /* Auslandsmeldungen -> n == uicode !!! */
   for(var n=0;n<nnm.length;n++)
      {
      if(typeof nnm[n] != 'undefined')
         {
         /* Set neighbour countries here */
         if(n == 80 || n == 81 || n == 83 || n == 87)
           {
           if (e('macro'+n))
             {
             e('macro'+n).innerHTML = countryIcons[n] + ' <a style="text-decoration:none;" href="#himMessagesForeignCountry" onclick="sortTable(3,1,'+n+')">'+nnm[n][2]+'</a>&nbsp;'+nnm[n][1];
             }
           }
         else
           {
           fmCode += countryIcons[n] + ' <a style="text-decoration:none;" href="#himMessagesForeignCountry" onclick="sortTable(3,1,'+n+')">'+nnm[n][2]+'</a>&nbsp;'+nnm[n][1] +'<br>';
           }
         }
      }
   if(fmCode.length > 0)
      {
      if (e('macroMs'))
        e('macroMs').style.display = '';
      if (e('fmm'))
        e('fmm').innerHTML = fmCode;
      }
   else if (e('macroMs'))
      {
      e('macroMs').style.display = 'none';
      }
   }

function sortTable(table,col)
   {
   if(arguments[2])/* Gibt es ein weiteres Sortierkriterium ? */
      {
      uicSort = parseInt(arguments[2]);
      }
   if(sr[table][col] == 0) /* Pruefe Wert in Sortiermatrix */
      {
      sr[table][col] = (uicSort != null)? 0:1;  /* Setze Wert in Sortiermatrix */
      sortBy = col;        /* Setze Spalte zum Sortieren */
      him[table].sort(compare); /* Sortiere Tabelle 'him[table]' nach Spalte 'sortBy' */
      }
   else
      {
      sr[table][col] = (uicSort != null)? 1:0;
      sortBy = col;
      him[table].sort(compare2);
      }
   if(e('messageTable') && e('himTable') && e('himTable').hasChildNodes())
      e('himTable').removeChild(e('messageTable'));
   drawTable();
   uicSort = null;
   }

function initialSortTable()/* Sortiere alle Tabellen 'him[table]' initial zuerst nach Typ und anschliessend nach Spalte 'sortBy' */
   {
   sortBy = 22; /* period begin */
   him[0].sort(compareInitial);
   him[1].sort(compareInitial);
   him[2].sort(compareInitial);
   him[4].sort(compareInitial);
   him[5].sort(compareInitial);
   sortBy = 24; /* Länder Name -> Umlautersetzt */
   him[3].sort(compareInitial);
   }

/* Sortiere -> Absteigend */
function compare2(x,y)
   {
   return compare(y,x);
   }

function compareInitial(x,y)
   {
   /* Länder name -> Umlautersetzt */
   if (sortBy == 24)
     return compare(x,y);

   /* 1st: sort by column 2 -> messagetype */
   var res = (1*typeIndexMapping[y[2]]-1*typeIndexMapping[x[2]]);

   /* 2nd: sort by 'sortBy' -> set in 'initialSortTable' */
   if(res == 0)
      return compare(y,x);

   return (res);
   }

/* Sortiere -> Aufsteigend */
function compare(x,y)
   {
   res = 0; /* init */

   /* zwei Zahlen */
   if(isNaN(x[sortBy]) == false && isNaN(y[sortBy]) == false)
      {
      if(x[sortBy] == uicSort && uicSort != null) /* Sort by UICcode -> clicked country always on top of table */
         {
         res = -1;
         }
      else if(y[sortBy] == uicSort && uicSort != null)
         {
         res = 1;
         }
      else
         {
         res = y[sortBy] - x[sortBy];
         }
      }
   /* zahl und string */
   else if(isNaN(x[sortBy]) == false)
      {
      res = -1;
      }
   else if(isNaN(y[sortBy]) == false)
      {
      res = 1;
      }
   /* zwei strings */
   else if(x[sortBy].toLowerCase() < y[sortBy].toLowerCase())
      {
      res = -1;
      }
   else if(y[sortBy].toLowerCase() < x[sortBy].toLowerCase())
      {
      res = 1;
      }
   /* zwei (in lowercase) "gleiche" strings */
   else if(x[sortBy] < y[sortBy])
      {
      res = -1;
      }
   else if(y[sortBy] < x[sortBy])
      {
      res = 1;
      }

   return(res)
   }


/* createServicedaysCalendar */
function createServicedaysCalendar(st,rowNr)
   {
   return '<td valign="top"><span onmouseover="createCalDiv(\''+him[st][rowNr][5]+'.'+him[st][rowNr][6]+'.'+him[st][rowNr][7]+'\',\''+him[st][rowNr][8]+'.'+him[st][rowNr][9]+'.'+him[st][rowNr][10]+'\',\''+him[st][rowNr][41]+'\');tooltip( event, \'calendar_container\' )">'+imgCalendar+'</span></td>';
   }

/* Period of validity */
function createDatePeriod(st,rowNr)
   {
   return '<td class="date">'+him[st][rowNr][5]+'.'+him[st][rowNr][6]+'.'+him[st][rowNr][7]+'&nbsp;'+unTillText+'&nbsp;'+him[st][rowNr][8]+'.'+him[st][rowNr][9]+'.'+him[st][rowNr][10]+'<br>'+
      him[st][rowNr][14]+':'+him[st][rowNr][15]+':'+him[st][rowNr][16]+'&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'+him[st][rowNr][17]+':'+him[st][rowNr][18]+':'+him[st][rowNr][19]+'</td>';
   }

function createMessageText(st,rowNr)
   {
   if (him[st][rowNr][45] != null)
     curLabel = him[st][rowNr][45].split('|');
   else
     curLabel = '';

   messageLink = '';
   if (him[st][rowNr][28] != null) {
     curUrl = him[st][rowNr][28].split('|');
     for (var i=0;i<curUrl.length;i++) {
       if (i==0)
         messageLink +='<br><br>'+linkText+':';
       messageLink +='<br><a href="'+ curUrl[i]+'" target="_blank">';
       if (i<curLabel.length)
         messageLink += curLabel[i];
       else
         messageLink += linkText;
       messageLink +='</a>';
       }
     }

   if(fts && ftsResultColorize)
     return '<strong>'+ him[st][rowNr][51] +'</strong><br>'+ him[st][rowNr][52] + messageLink;
   else
     return '<strong>'+ him[st][rowNr][12] +'</strong><br>'+ him[st][rowNr][13] + messageLink;
   }

function createID(st,rowNr)
   {
   idText = (him[st][rowNr][48] != null) ? him[st][rowNr][48]:'&nbsp;';
   return '<td class="message">'+idText+'</td>';
   }
/* oebb_him_tooltip.js */

/* Removes the div with id "tipDiv" if mouseEvent is outside this div. */
function tooltipActiveMouseMove( mouseEvent )
{
    if ( !mouseEvent )
        mouseEvent = window.event;

    var tipDiv = document.getElementById( "tipDiv" );
    var tipFrame = document.getElementById( "tipFrame" );

    var tipX1 = absLeft( tipDiv );
    var tipY1 = absTop( tipDiv );

    var tipX2 = tipX1 + tipDiv.offsetWidth;
    var tipY2 = tipY1 + tipDiv.offsetHeight;

    scrollPos = getScrollPos();

    var evX = mouseEvent.clientX + scrollPos.x;
    var evY = mouseEvent.clientY + scrollPos.y;

    if ( (evX < tipX1) || (evX > tipX2 ) ||
         (evY < tipY1) || (evY > tipY2 ) )
        {
        document.onmousemove = null;
        document.body.removeChild( tipDiv );

        if ( tipFrame )
            document.body.removeChild( tipFrame );
        }
}

/* Returns the window's width */
function getWindowWidth()
{
    if (self.innerWidth) // all except Explorer
        {
        return self.innerWidth;
        }
    else if (document.documentElement && document.documentElement.clientWidth)
    // Explorer 6 Strict Mode
        {
        return document.documentElement.clientWidth;
        }
    else if (document.body) // other Explorers
        {
        return document.body.clientWidth;
        }
}

/* Returns the window's height */
function getWindowHeight()
{
    if (self.innerHeight) // all except Explorer
        {
        return self.innerHeight;
        }
    else if (document.documentElement && document.documentElement.clientHeight)
   // Explorer 6 Strict Mode
        {
        return document.documentElement.clientHeight;
        }
    else if (document.body) // other Explorers
        {
        return document.body.clientHeight;
        }
}

// returns the scroll left and top for the browser viewport.
function getScrollPos() {
   if ( document.body.scrollTop != undefined ) {   // IE model
      var ieBox = document.compatMode != "CSS1Compat";
      var cont = ieBox ? document.body : document.documentElement;
      return { x : cont.scrollLeft, y : cont.scrollTop };
   }
   else {
      return { x : window.pageXOffset, y : window.pageYOffset };
   }
}
/*
   Shows a tooltip at position "mouseEvent".
   The content is taken from "tip".
   Creates a div with id "tipDiv".

   If "linkText" is defined, the function tries to find an "a" tag, that
   is the target of the mouse event. If an "a"-tag is found and has an "href"
   link the link will be included at the bottom of the tooltip with link's
   text = "linkText".
*/
function tooltip( mouseEvent, tip, linkText )
{
   if ( !mouseEvent )
        mouseEvent = window.event;

   var tipElem = document.getElementById( tip );
   var tipContent = tipElem.innerHTML;
   var tipDiv = document.getElementById( "tipDiv" );
   var tipFrame = document.getElementById( "tipFrame" );

   // Remove old tooltip:
    if (tipDiv)
       {
      document.body.removeChild( tipDiv );
      }
    if (tipFrame)
       {
      document.body.removeChild( tipFrame );
      }

    tipDiv = document.createElement( "div" );

    scrollPos = getScrollPos();

    //    alert( "scroll position " + scrollPos.x + "/" + scrollPos.y );

    tipDiv.setAttribute( "id", "tipDiv" );
    tipDiv.className = "tooltip";

    tipDiv.style.display="block";
    tipDiv.style.visibility="visible";

    document.body.appendChild( tipDiv );

    tipDiv.innerHTML = tipContent;

    if ( undefined != linkText )
        {
        var targetLink = mouseEvent.target;
        if ( !targetLink )
            {
            targetLink = mouseEvent.srcElement;
            }

        while ( targetLink && ((targetLink.nodeName != "A") && (targetLink.nodeName != "a") ))
            {
            targetLink = targetLink.parentNode;
            }

        if( targetLink && (undefined != targetLink.href) )
            {
            tipDiv.innerHTML += "<div>"
                + "<a href=\""
                + targetLink.href
                + "\" >"
                + linkText
                + "</a></div>" ;
            }
        }

    var yPOS = mouseEvent.clientY + 5 + scrollPos.y - tipDiv.offsetHeight;
    if(showMap == true){
       //var xPOS = mouseEvent.clientX - tipDiv.offsetWidth + scrollPos.x;
       var xPOS = mouseEvent.clientX - 130;
       }
    else {
       var xPOS = mouseEvent.clientX - 45 + scrollPos.x;
       }

    // Outside correction
    var newTopPos = yPOS + 20;
    if (newTopPos < 0) newTopPos = 0;

    var newLeftPos = xPOS + 20;
    if (newLeftPos < 0) newLeftPos = 0;

    tipDiv.style.top  = newTopPos + "px";
    tipDiv.style.left = newLeftPos + "px";

    // Exploder hack to hide selects behind the tooltip
    if ( navigator.appName.search(/Explorer/) != -1 )
        {
        tipFrame = document.createElement( "iframe" );

        tipFrame.setAttribute( "id", "tipFrame" );
        tipFrame.setAttribute( "src", "about:blank" );
        tipFrame.setAttribute( "scrolling", "no" );
        tipFrame.setAttribute( "frameborder", "0" );

        tipFrame.style.top    = tipDiv.style.top;
        tipFrame.style.left   = tipDiv.style.left;
        tipFrame.style.width  = tipDiv.offsetWidth;
        tipFrame.style.height = tipDiv.offsetHeight;


        tipFrame.style.position = "absolute";
        tipFrame.style.zIndex = 254;

        document.body.appendChild( tipFrame );
        }
    document.onmousemove = tooltipActiveMouseMove;
}

