﻿// global.js
// Copyright  2005 by Thomas A. Osthege. All Rights Reserved.
// 11/05/2005

// window.onError= null;

setFontSize();

// adjust fontsize according to cookie
function setFontSize()
 {
  if (document.cookie.indexOf('dated=yes')== -1)
   {
    if (!document.getElementById)
     {
    	alert('If you are using a version 4.x or lower browser, this website may not appear precisely as intended.\n'
    		+ 'This was done in compliance with W3C Web Standards and Accessibility conventions.\n'
    		+ 'Please visit http://webstandards.org for more information\n'
    		+ 'Style Switching will not be available to you for this site.\n\n'
    		+ 'Wenn Sie einen Browser mit einer Version 4.x oder älter verwenden, wird diese Website nicht korrekt angezeigt.\n'
    		+ 'Dies entspricht den W3C-Standards und -Vereinbarungen.\n'
    		+ 'Weitere Informationen finden Sie auf http://webstandards.org.\n'
    		+ 'Das Wechseln des Designs ist nicht möglich.');
      document.cookie= 'dated=yes; path=/';
      return false;
     }
  
    var valuePosInCookie= document.cookie.indexOf('fontsize=');
    if (valuePosInCookie >= 0)
     {
      var fontSize= parseInt(document.cookie.substr(valuePosInCookie + 9, 2));
      document.write('<style>body{font-size: ' + fontSize + 'px;}</style>\n');
     }
   }
 }

// alert(document.body.currentStyle.display);
// setFontSize();
// document.write('<style>body{font-size: 6px;}</style>\n');

// set fontsize cookie
function adjustFontSize(changeBy)
 {
  if (!document.getElementById)
   {
	alert('You are using a version 4.x or lower browser so Style Switching is not available to you for this site.\n\n'
	    + 'Sie verwenden einen Browser mit einer Version 4.x oder älter. Deshalb ist ein Designwechsel nicht möglich.');
   }
  else
   {
    var fontSize= parseInt(getDocTextSize()) + changeBy;
    if (fontSize >= 6)
     {
      var expDate= new Date();
      expDate.setTime(expDate.getTime() + (1000*3600*24*365));
      document.cookie= 'fontsize=' + fontSize + '; expires=' + expDate.toGMTString() + '; path=/';
      document.location.reload();
     }
   }
 }

function getDocTextSize() 
{
  if (!document.getElementsByTagName)
    return 0;

  var size = 0;
  var body = document.getElementsByTagName('body')[0];

  if (body.style && body.style.fontSize)
    size = body.style.fontSize;
  else if (typeof(getComputedStyle) != 'undefined')
    size = getComputedStyle(body,'').getPropertyValue('font-size');
  else if (body.currentStyle)
    size = body.currentStyle.fontSize;
  return size;
}

// Get param from browsers infoline (behind '?')
function getpar(paramname)
 {
  var searchval= window.location.search;

  searchval= unescape(searchval);
  searchval= '&' + searchval.substr(1, searchval.length - 1);

  var valpos= searchval.toLowerCase().indexOf('&' + paramname.toLowerCase() + '=');
  var valposstring= '';

  if (valpos > -1) 
  	valposstring= searchval.substring(valpos + paramname.length + 2, searchval.length);

  var endpos= valposstring.indexOf('&');
  var parval= '';
  
  if (endpos < 0) 
  	endpos= valposstring.length;

  if (endpos > 0) 
  	parval= valposstring.substring(0, endpos);

  return parval;
 }

// toggle display status of a div
function doToggle(theItem)
{
  if (document.getElementById(theItem).currentStyle.display == '')
    document.getElementById(theItem).currentStyle.display = 'none';
  else
    document.getElementById(theItem).currentStyle.display = '';
}

function DisplayTheLastModifiedDate()
 {
  var LastModifiedDateAndTime = new Date(document.lastModified)
  var LastModifiedDay = LastModifiedDateAndTime.getDate()
  var LastModifiedMonth = (LastModifiedDateAndTime.getMonth() + 1) // You must add one because it returns the previous month.
  var LastModifiedYear = LastModifiedDateAndTime.getYear()
  var LastModifiedDate = ''
  if (LastModifiedDay < 10)
    LastModifiedDay = '0' + LastModifiedDateAndTime.getDate()
  if (LastModifiedMonth < 10)
    LastModifiedMonth = '0' + (LastModifiedDateAndTime.getMonth() + 1)
  if (LastModifiedYear < 100)
    LastModifiedYear = '20' + LastModifiedDateAndTime.getYear()
  LastModifiedDate = LastModifiedDay + '/' + LastModifiedMonth + '/' + LastModifiedYear
  document.write(LastModifiedDate)
 }

// Displays the URL of the current page (not frame page)
function DisplayTheDocumentNameAndPath()
 {
  var DocumentNameAndPath = new String(document.location)
  document.write(DocumentNameAndPath)
 }


// Replaces the active document with the specified URL
function GoToURL(URL)
 {
  if (URL == '[object]')
    document.location.href= URL.options[URL.selectedIndex].value;
  else
    document.location.href= FileLocation = URL;
 }


// Navigates back one throught the History list
function GoBack()
 {
  parent.history.back()
 }

function OpenPopupWindow(URL)
 {
  window.open(URL,'PopupWindow','LEFT=10,Top=10,HEIGHT=380,WIDTH=610,resizable=yes,scrollbars=yes,status=yes,toolbar=yes,directories=no,menubar=no,location=no');
 }

function OpenHelpWindow(URL)
 {
  window.open(URL,'HelpWindow','LEFT=110,Top=110,HEIGHT=380,WIDTH=280,resizable=no,scrollbars=yes,status=no,toolbar=no,directories=no,menubar=no,location=no');
 }

function ChangeBackColor(Element, Color)
 {
  Element.currentStyle.background = Color;
 }


// Test theField for theSize Characters
function TestField(theField,theSize,theName,theLang)
{
  with(theField)
  {
    if (value == '')
    {
      if (theLang == 'de')
        alert('Bitte geben Sie einen Wert für "'+theName+'" an.');
      else
        alert('Please enter a value for "'+theName+'".');
      focus();
      return false;
    }
    if (value.length < theSize)
    {
      if (theLang == 'de')
        alert('"'+theName+'" muss mindestens '+theSize+' Zeichen lang sein.');
      else
        alert('"'+theName+'" must have at least '+theSize+' Characters.');
      focus();
      return false;
    }
  }
  return true;
}


// Test theField for a valid email address
function TestEmail(theField,theName,theLang)
{
  if (!TestField(theField,8,theName,theLang)) return false;

  with(theField)
  {
    if ((value.indexOf('@') < 1) ||
        (value.indexOf('.') < 1))
    {
      if (theLang == 'de')
        alert('"'+theName+'" ist keine gültige Email-Adresse.');
      else
        alert('"'+theName+'" is not a valid email address.');
      focus();
      return false;
    }
  }
  return true;
}


// Test Email field and submit
function SubmitNow(theLang)
{
  with(document.Form1)
  {
    if (TestEmail(Email,'Email',theLang)) 
    {
      FBAUTORESPONDTO.value = FBFROM.value = FBREPLYTO.value = Email.value;
      submit();
      return true;
    }
  }
  return false;
}

// add to favorites german
function addToFavoritesDe()
{
if (window.external)
  window.external.AddFavorite(location.href, document.title);
else
  alert('Leider unterstützt Ihr Browser diese Funktion nicht. Bitte verwenden Sie stattdessen Strg+D.'); 
}

// add to favorites english
function addToFavoritesEn()
{
if (window.external)
  window.external.AddFavorite(location.href, document.title);
else
  alert('Sorry! Your browser doesn\'t support this function. Please press CTRL+D to bookmark this page instead.'); 
}
