/*  2015-11-07  RS1Lib.js JavaScript functions

    Dr. Rolf Schröder
    Möörkenweg 37
    21029 Hamburg, Deutschland
    http://www.rschr.de
*/

//------------------------------------- General functions ----------------------------------

if(top!=self) top.location=self.location; // Don't squeeze page into a frame!

function NewWindow(url,name,features)
//       #########
{
   MyWindow = window.open( url, name, features);
   if (window.focus) {MyWindow.focus();}  
}

function langQuery()  // If tag name "meta" with name="language" and content="lang"
//       #########    // is found in the page, the return value is "lang", else "". 
{
  var s = document.getElementsByTagName("meta"); // read all meta-tags
  for( i=0; i < s.length; i++)  // search the meta-tags for name="language"
  { if(s[i].name.toLowerCase() == "language")
    { return s[i].content.toLowerCase();         //  return content as string
    }
  }
  return "";                                     // return "" if no language given
}

function writeLinks(list)
//       ##########   writes a line of links inside the page,
//                    link list defined as array of strings inside the page.
{
  var j;
  document.write("<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\" width=\"100%\">\n");
  document.write("<tr>\n");
  document.write("<td><h4>" + "Übersicht:" + "<\/h4><\/td>\n");
  for( j = 0; j < list.length; j++)			
  { document.write("<td width=\"2%\" ><\/td>\n");
    if( j < 10 )
    { document.write("<td nowrap><h5><a href=\"#L0" + j + "\" onclick=\"location.replace(this.href); return false\">&nbsp;" + list[j] + "&nbsp;<\/a><\/h5><\/td>\n");}
    else
    { document.write("<td nowrap><h5><a href=\"#L" + j + "\" onclick=\"location.replace(this.href); return false\">&nbsp;" + list[j] + "&nbsp;<\/a><\/h5><\/td>\n");}
  }
  document.write("<td width=\"86%\" ><\/td>\n");
  document.write("<\/tr>\n");
  document.write("<\/table>\n");
}

function writeRubrik(Rname)
//       ###########
{
  document.write("<table>\n");
  document.write("<tr>\n");
  document.write("<td style=\"width:50%;\"><hr><\/td>\n");
  document.write("<td nowrap><h3>&nbsp;" + Rname + "&nbsp;<\/h3><\/td>\n");
  document.write("<td style=\"width:50%;\"><hr><\/td>\n");
  document.write("<\/tr>\n");
  document.write("<\/table>\n");
} 

//-------------------------------------- E-Mail-Functions ----------------------------------

function obscure( Name, Domain, Text)
//       #######
//
// The three parameters Name, Domain, and Text are of type string,
// the third parameter 'Text' is optional. Its content replaces
// the otherwise displayed e-mail-address. 
//
{  
   function Rint(n)                   // Random integer r: 1 <= r <= n 
   { return Math.floor( n*Math.random() + 1 );  
   }      
   function s2h(str)                  // Replaces chars randomly by three 
   { var s = "", i, z1 = 0, z2, cod;  // different HTML character notations,
     for( i = 0; i < str.length; i++) // namely direct notation,    
     { cod = str.charCodeAt(i);       // decimal notation, and
       z2 = Rint(3);                  // hexadecimal notation.
       while( z2 == z1 ) { z2 = Rint(3); } // Avoids repetitions.
       z1 = z2;
       switch( z1 )
       { case 1: s += "&#"  + cod.toString(10) + ";"; break;
         case 2: s += "&#x" + cod.toString(16) + ";"; break;
         case 3: s += String.fromCharCode(cod); break;
       } 
     }
     return s;
   }
   Name = s2h(Name);
   Domain = s2h(Domain);
   if( arguments.length < 3 )
   { Text = Name + "&#x24D0;" + Domain;
   }
   document.write("<a href=\""
               + s2h(decodeURIComponent("%6D%61%69%6C%74%6F%3A"))
               + Name + decodeURIComponent("%40") + Domain + "\">"
               + Text + "</a>");
}

//----------------------------------- Date-Time-functions ----------------------------------

function iso_date_format(t)
//       ###############
{
    var Year    = t.getUTCFullYear();
    var Month   = t.getUTCMonth() + 1;
    var Day     = t.getUTCDate();
    var Hours   = t.getUTCHours();
    var Minutes = t.getUTCMinutes();
    var Seconds = t.getUTCSeconds();

    if (Month   < 10  ) Month   =  "0" + Month;
    if (Day     < 10  ) Day     =  "0" + Day;
    if (Hours   < 10  ) Hours   =  "0" + Hours;
    if (Minutes < 10  ) Minutes =  "0" + Minutes;
    if (Seconds < 10  ) Seconds =  "0" + Seconds;

    return Year+"-"+Month+"-"+Day+"&nbsp;"+Hours+":"+Minutes+":"+Seconds+"&nbsp;UTC";
}

function last_modified_UTC()
//       #################
{
    d = new Date(document.lastModified);  // Date obj. of document
    document.write(iso_date_format(d));
}

function now_UTC()
//       #######
{
    d = new Date();
    document.write(iso_date_format(d));
}

//----------------------------------- Table Function ---------------------------------------

function displayTable( list, mailColumn, urlColumn, typeColumn)
//       ############
{
  function write_sorted_column(initial)
  {
    var sorted = [];
    for (i=1; i < list.length; i++)
    { if ( sorted.indexOf(list[i][typeColumn]) == -1 ) sorted.push(list[i][typeColumn]);   
    }
    sorted = sorted.sort();
    sorted.unshift(initial);
    for( i=0; i < sorted.length; i++)
    {  if( i > 0 && i < sorted.length - 1)
       { document.write(sorted[i] + ", "); }
       else
       { document.write(sorted[i]); }
    }     
  }
  function cut( str, n )
  {
    if ( str.length > n )
    { return str.slice(0,n-1) + "…"; }
    else
    { return str; }
  }
  function write_mail(str)
  {
    var mail_list, k, len;
    mail_list = str.split("<br>");
    len = mail_list.length;
    document.write("<td class=\"m\">");
    for(k = 0; k < len; k++)
    { document.write("<a href=\"mailto:" + mail_list[k].replace(/<br>/gi,",") + "\">" + mail_list[k] + "<\/a>");
      if(k < len-1) document.write("<br>");
    }
    document.write("<\/td>");    
  }      
  function write_html(str)
  {
    var html_list, k, len;
    html_list = str.split("<br>");
    len = html_list.length;
    document.write("<td class=\"m\">");
    for(k = 0; k < len; k++)
    { document.write("<a href=\"" + html_list[k] + "\" target=\"_blank\">" + cut(html_list[k],30) + "<\/a>");
      if(k < len-1) document.write("<br>");
    }
    document.write("<\/td>");
  }
  //----------- main ---------- 
  var i, j;
  if(typeof typeColumn != "undefined") write_sorted_column("Typen: ");
  document.write("<table class=\"sortable\" rules=\"all\">\n");
  document.write("<tr>\n");       // Header
  document.write("<th class=\"m\">" + " " + "<\/th>"); // first column to number consecutively
  for( j = 0; j < list[0].length; j++)			// header line of table
  { document.write("<th class=\"m\">" + list[0][j] + "<\/th>");  
  }
  document.write("<\/tr>\n");
  for( i = 1; i < list.length; i++)  // table lines
  { document.write("<tr>\n");
    document.write("<td class=\"m\" style=\"text-align:right;\">" + i + "<\/td>");
    for( j = 0; j < list[i].length; j++)  // colums
    { if( list[i][j].length == 0 )
      { document.write("<td class=\"m\"> <\/td>"); }
      else
      { if( j == mailColumn )
        { write_mail(list[i][j]) }
		else if( j == urlColumn )
        { write_html(list[i][j]) }
        else
        { document.write("<td class=\"m\">" + list[i][j] + "<\/td>"); }
      }	  
    }
    document.write("<\/tr>\n");
  }  
  document.write("<\/table>\n");
}

//----------------------------------- Several Bottom Features ------------------------------

function bottom()
//       ######
{
    var c;
	switch( langQuery() )
	{ case "de": c = "Seit ";
	  break;
	  case "en":
	  case ""  : c = "Since ";
	  break;
	  case "ru": c = "C ";
	  break;
	}
    document.write("<a href=\"http://login.1und1.de/\" target=\"_blank\">" + c + "2000-11-29:&nbsp;" + "</a>");
    document.write("<a href=\"http://kis.hosteurope.de/\" target=\"_blank\"><img src=\"http://www.rschr.de/Bilder/Dragon.gif\" border=\"0\" width=\"114\" height=\"35\" title=\"Dragon\" alt=\"Dragon\"></a>" + "&nbsp;");
    document.write("<a href=\"http://www.rschr.de/PHP/counter.txt\" target=\"_blank\"><img src=\"http://www.rschr.de/PHP/counter.php\" border=\"0\" title=\"rschr_counter\" alt=\"rschr_counter\"></a>");
    document.write("&nbsp;<a href=\"http://validator.w3.org/check?uri=referer\" target=\"_blank\"><img src=\"http://www.w3.org/Icons/valid-html401\" title=\"Valid HTML 4.01!\" alt=\"Valid HTML 4.01!\" border=\"0\"></a>");
    document.write("&nbsp;<a href=\"http://jigsaw.w3.org/css-validator/check/referer\" target=\"_blank\"><img src=\"http://jigsaw.w3.org/css-validator/images/vcss\" title=\"Valid CSS!\" alt=\"Valid CSS!\" border=\"0\"></a>");    
}
