
browser = navigator.appName;

function SetHeader (header)
{
  var url = parent.FrameHeading.location.href;
  if (eval ('url.search (/' + header + '\\.html$/)') < 0)
     parent.FrameHeading.location.href = "../header" + header + ".html";
  return;
}

function SetTitle (title)
{
  if (SetTitle.arguments.length == 0)
    title = "Allgemeiner Deutscher Fahrrad-Club / Ortverband Aalen";
  else
    title = "ADFC Aalen: " + title;
  parent.document.title = title;
  return;
}

function SetFrame (url)
{
  if (parent.length == 6 && window.name.match (/FrameDetails/))
    return false;
  else
  {
    if (SetFrame.arguments.length < 1)
      url = document.location.href;
    var slash = url.lastIndexOf ('/');
    var path  = url.slice (0, slash+1);
    var file  = url.slice (slash+1);
    top.name = url;
    top.location.href = path + "../index.html";
    return true;
  };
}


function OpenFrame (url)
{
  if (OpenFrame.arguments.length == 0)
    url = top.name;
  if (url.length > 0 && url.charAt(0) != '_')
  {
    window.location.href = top.name;
    top.name = "";
    return true;
  }
  else
    return false;
}

/* pops up mail form */

winMail = null;
function mailTo (name, subject)
{
   var urlMail = top.location.href; 
   urlMail = urlMail.replace (/[^\/]*$/, 'Kontakt/Anfrage.html');
   if (screen.availHeight < 1096)
      height = screen.availHeight - 100;
   else
      height = 896;
   shape = 'menubar=no,locationbar=no,staus=no,scrollbars,width=672,height=' + height;
   winMail = open (urlMail, 'windowMail', shape);
   var timer = 0;
   while (  winMail.document.formMail)
     if (timer++ > 1048576) break;
   while (! winMail.document.formMail)
     if (timer++ > 1048576) return;
   if (mailTo.arguments.length >= 2)
      winMail.document.formMail.Betreff.value = subject;
   winMail.focus();
   for (index = 0; index < winMail.document.formMail.Empfaenger.length; index++)
   {
      if (winMail.document.formMail.Empfaenger.options[index].text == name) break;
   };
   if (index == winMail.document.formMail.Empfaenger.length)
   {
      if (browser.search (/Microsoft/) < 0)
      {
         newOption = new Option(name,name,true,true);
         winMail.document.formMail.Empfaenger.options[index] = newOption;
      }
      else
      { // workaround: Microsoft cannot add options in foreign window documents //
         index--;
         winMail.document.formMail.Empfaenger.options[index].text  = name;
         winMail.document.formMail.Empfaenger.options[index].value = name;
      }
   };
   winMail.document.formMail.Empfaenger.selectedIndex = index;
   winMail.document.formMail.Empfaenger.options[index].defaultSelected = true;
}


/* builds spoilt mailboxes */

function mailto (user, provider, name, subject, option)
{
  var body = "Bitte%20die%20Buchstaben%20nach%20dem%20letzten%20Punkt%20im%20Adressaten%20umdrehen!";
  var nation = "";
  var point;
  point   = provider.length;
  while (point-- >= 0 && provider.charAt(point) != '.')
    nation  = nation + provider.charAt(point);
  mailbox = user + "&#64;" + provider.slice(0,point+1) + nation;
  if (mailto.arguments.length < 3)
    name = "";
  if (name.length == 0)
    name = mailbox.fixed();
  document.write ("<nobr><a href='mailto:" + mailbox);
  if (mailto.arguments.length >= 4)
    document.write ("?subject=" + subject + "&");
  else
    document.write ("?");
  document.write ("body=" + body + "'>");
  if (mailto.arguments.length <= 4)
    option = -1;
  if (option != 0)
  {
    if (option == 1)
      path = "../";
    else
      path = "";
    document.write ("<img src='" + path + "mail.gif' width=15 height=10 border=0 alt='eMail'>");
  };
  document.write (name + "</a></nobr>");
  return;
}



/* builds spoilt mailboxes */

function letter (user, provider, name, subject, option)
{
  var body = "Bitte%20die%20Buchstaben%20nach%20dem%20letzten%20Punkt%20im%20Adressaten%20umdrehen!";
  var nation = "";
  var point;
  
  if (letter.arguments.length < 2)
    provider = 0;
  if (user < 10)
  {
    option  = user;
    mailbox = "Postfach";
    body    = "ung&uuml;ltige Adressse";
  }
  else if (provider < 10)
  {
    option  = provider;
    mailbox = user;
    body    = "";
  }
  else
  {
    point   = provider.length;
    while (point-- >= 0 && provider.charAt(point) != '.')
      nation  = nation + provider.charAt(point);
    mailbox = user + "&#64;" + provider.slice(0,point+1) + nation;
    if (letter.arguments.length <= 4)
      option = 0;
  };
  if (letter.arguments.length < 3)
    name = "";
  if (name.length == 0)
    name = mailbox.fixed();
  document.write ("<nobr><a href='mailto:" + mailbox);
  if (letter.arguments.length < 4)
    subject = "";
  if (subject == 0)
    subject = "";
  if (subject.length > 0)
    document.write ("?subject=" + subject + "&");
  else
    document.write ("?");
  document.write ("body=" + body + "'>");
  if (option < 0)
    path = "../";
  else
    path = "";
  switch (Math.abs(option))
  {
    case 1:
      document.write ("<img src='" + path + "mail1.gif' width=17 height=17 border=0 alt='eMail'>");
      break;
    case 2:
      document.write ("<img src='" + path + "info1.gif' width=17 height=17 border=0 alt='info'> ");
      break;
  };
  document.write (name + "</a></nobr>");
  return;
}



function dial (number)
{
   var ouput;
   var n;
   var option = 0;
   
   if (number <= 0)
   {
     option = number;
     output = "Telefon";
   }
   else
   {
     if (dial.arguments[1] > 0)
       output = "0" + number;
     else
       output = number;
   };
   for (n = 1; n < dial.arguments.length; n++)
   {
     if (dial.arguments[n] < 0)
       option = dial.arguments[n];
     else
       output = output + "-" + dial.arguments[n];
   };
   switch (option)
   {
     case -1:
       output = "Tel. " + output;
       break;
     case -2:
       output = "<img src='../tel1.gif' width=16 height=17 border=0 alt='Tel'> " + output;
       break;
   }
   document.write (output);
   return;
}


function fax (number)
{
   var ouput;
   var n;
   var option = 0;
   
   if (number <= 0)
   {
     option = number;
     output = "Telefax";
   }
   else
   {
     if (fax.arguments[1] > 0)
       output = "0" + number;
     else
       output = number;
   };
   for (n = 1; n < fax.arguments.length; n++)
   {
     if (fax.arguments[n] < 0)
       option = fax.arguments[n];
     else
       output = output + "-" + fax.arguments[n];
   }
   switch (option)
   {
     case -1:
       output = "Fax. " + output;
       break;
     case -2:
       output = "<img src='../fax1.gif' width=16 height=17 border=0 alt='Fax'> " + output;
       break;
   }
   document.write (output);
   return;
}


/* returns the date in German format, for instance, "23. Februar 1998" */
function Datum (date)
{
  if (Datum.arguments.length == 0)
    date = 0;
  if (date == 0)
    date = new Date();
  var Monat, Jahr;
  var Tag   = date.getDate();
  var month = date.getMonth()+1;
  var year  = date.getYear();
  if (year < 90)
     Jahr = 2000 + year;
  else if (year < 190)
     Jahr = 1900 + year;
  else if (year < 1990)
     Jahr =  100 + year;
  else
     Jahr = year;
  if (month == 1)
     Monat = 'Januar';
  if (month == 2)
     Monat = 'Februar';
  if (month == 3)
     Monat = 'M&auml;rz';
  if (month == 4)
     Monat = 'April';
  if (month == 5)
     Monat = 'Mai';
  if (month == 6)
     Monat = 'Juni';
  if (month == 7)
     Monat = 'Juli';
  if (month == 8)
     Monat = 'August';
  if (month == 9)
     Monat = 'September';
  if (month == 10)
     Monat = 'Oktober';
  if (month == 11)
     Monat = 'November';
  if (month == 12)
     Monat = 'Dezember';
  return (Tag + '. ' + Monat + ' ' + Jahr);
}


function matchLetter (author)
{
  if (author.match (/\s*letter\s*\(\s*(\S+)\s*,\s*(\S+)\s*,\s*(\S+)\s*,\s*(\S+)\s*\)/))
  {
    //alert ("matchLetter is matching 4x");
    this.user     = RegExp.$1;
    this.provider = RegExp.$2;
    this.name     = RegExp.$3;
    this.subject  = RegExp.$4;
    return true;
  };
  if (author.match (/\s*letter\s*\(\s*(\S+)\s*,\s*(\S+)\s*,\s*(\S+)\s*\)/))
  {
    //alert ("matchLetter is matching 3x");
    this.user     = RegExp.$1;
    this.provider = RegExp.$2;
    this.name     = RegExp.$3;
    return true;
  };
  if (author.match (/\s*letter\s*\(\s*(\S+)\s*,\s*(\S+)\s*\)/))
  {
    //alert ("matchLetter is matching 2x");
    this.user     = RegExp.$1;
    this.provider = RegExp.$2;
    return true;
  };
  if (author.match (/\s*letter\s*\(\s*(\S+)\s*\)/))
  {
    //alert ("matchLetter is matching 1x");
    this.name     = RegExp.$1;
    return true;
  }
  else
  {
    //alert ("matchLetter is not matching");
    return false;
  }
}
function writeLetter ()
{
  if (this.user.length == 0 || this.provider.length == 0)
  {
    document.write (this.name);
  }
  else
  {
    letter (this.user, this.provider, this.name, this.subject, this.type);
  }
  return;
}
function Letter (user, provider, name, subject, type)
{
  if (Letter.arguments.length == 1)
  {
    name    = user;
    user = "";
  };
  this.type     = type     || 0;
  this.subject  = subject  || "";
  this.name     = name     || "";
  this.provider = provider || "";
  this.user     = user     || "";
}
Letter.prototype.match = matchLetter;
Letter.prototype.write = writeLetter;


function copyright (date, author, copy)
{
  if (copyright.arguments.length < 3)
    copy = 0;
  if (copy == 0)
    copy = "ADFC Aalen";
  if (copyright.arguments.length < 1)
    date = 0;
  if (date == 0)
    date = new Date (document.lastModified);
  document.write ("<p style='margin-top:2ex;'><hr shade width=80% size=2 align=center color=#003399 style='color:#003399;'><table width=80% align=center class='tiny'><colgroup width=33% span=3></colgroup><tr><td align=left>");
  if (copyright.arguments.length >= 2) author.write ();
  document.write ("</td><td align=middle>&copy; " + copy + "</td><td align=right>" + Datum(date) + "</td></tr></table>");
}


/* opens a popup window */

function popup (url, title, name)
{
  if (popup.arguments.length < 3)
    name = "_popup";
  if (popup.arguments.length < 2)
    title = "";
  title = "&copy; ADFC Aalen " + title;
  var w = window.open (url, name, "location=no,menubar=no,status=no,toolbar=no,resizable=yes,scrollbars=yes,width="+self.outerWidth+",height="+self.outerHeight);
  w.document.title = title;
  w.document.bgColor = "#115599";
//  return w;
}

