/*
** TABLE OF CONTENTS
**
** 1.  DHTML-LIB
** 2.  Navigation and Window Functions
** 3.  Crossbrowser Window Dimensions
** 4.  Style Funktion
*/

/* ########################################################################################
** 1. DHTML-Bibliothek
** ########################################################################################
*/

var DHTML = false, DOM = false, MSIE4 = false, NS4 = false, OP = false;

if (document.getElementById) {
  DHTML = true;
  DOM = true;
}
else {
  if (document.all) {
    DHTML = true;
    MSIE4 = true;
  }
  else {
    if (document.layers) {
      DHTML = true;
      NS4 = true;
    }
  }
}
if (window.opera) {
  OP = true;
}

function getElement (Mode, Identifier, ElementNumber) {
  var Element, ElementList;
  if (DOM) {
    if (Mode.toLowerCase() == "id") {
      Element = document.getElementById(Identifier);
      if (!Element) {
        Element = false;
      }
      return Element;
    }
    if (Mode.toLowerCase() == "name") {
      ElementList = document.getElementsByName(Identifier);
      Element = ElementList[ElementNumber];
      if (!Element) {
        Element = false;
      }
      return Element;
    }
    if (Mode.toLowerCase() == "tagname") {
      ElementList = document.getElementsByTagName(Identifier);
      Element = ElementList[ElementNumber];
      if (!Element) {
        Element = false;
      }
      return Element;
    }
    return false;
  }
  if (MSIE4) {
    if (Mode.toLowerCase() == "id" || Mode.toLowerCase() == "name") {
      Element = document.all(Identifier);
      if (!Element) {
        Element = false;
      }
      return Element;
    }
    if (Mode.toLowerCase() == "tagname") {
      ElementList = document.all.tags(Identifier);
      Element = ElementList[ElementNumber];
      if (!Element) {
        Element = false;
      }
      return Element;
    }
    return false;
  }
  if (NS4) {
    if (Mode.toLowerCase() == "id" || Mode.toLowerCase() == "name") {
      Element = document[Identifier];
      if (!Element) {
        Element = document.anchors[Identifier];
      }
      if (!Element) {
        Element = false;
      }
      return Element;
    }
    if (Mode.toLowerCase() == "layerindex") {
      Element = document.layers[Identifier];
      if (!Element) {
        Element = false;
      }
      return Element;
    }
    return false;
  }
  return false;
}

function getAttribute (Mode, Identifier, ElementNumber, AttributeName) {
  var Attribute;
  var Element = getElement(Mode, Identifier, ElementNumber);
  if (!Element) {
    return false;
  }
  if (DOM || MSIE4) {
    Attribute = Element.getAttribute(AttributeName);
    return Attribute;
  }
  if (NS4) {
    Attribute = Element[AttributeName]
    if (!Attribute) {
       Attribute = false;
    }
    return Attribute;
  }
  return false;
}

function getContent (Mode, Identifier, ElementNumber) {
  var Content;
  var Element = getElement(Mode, Identifier, ElementNumber);
  if (!Element) {
    return false;
  }
  if (DOM && Element.firstChild) {
    if (Element.firstChild.nodeType == 3) {
      Content = Element.firstChild.nodeValue;
    }
    else {
      Content = "";
    }
    return Content;
  }
  if (MSIE4) {
    Content = Element.innerText;
    return Content;
  }
  return false;
}

function setContent (Mode, Identifier, ElementNumber, Text) {
  var Element = getElement(Mode, Identifier, ElementNumber);
  if (!Element) {
    return false;
  }
  if (DOM && Element.firstChild) {
    Element.firstChild.nodeValue = Text;
    return true;
  }
  if (MSIE4) {
    Element.innerText = Text;
    return true;
  }
  if (NS4) {
    Element.document.open();
    Element.document.write(Text);
    Element.document.close();
    return true;
  }
}

/* ########################################################################################
** 2. Navigation and Window Functions
** ########################################################################################
*/

function sen_JsRedirect(redirectPath)
{
    if (self.location.href)
    {
      self.location.href = redirectPath;
    }
}

function sen_JsSafeRedirect(safetyQuestion,redirectUrl)
{
    Check = confirm(safetyQuestion);
    if (Check == true)
    {
        self.location.href = redirectUrl;
    }
}

function sen_JsOpenWindow(wName,wUrl,wWidth,wHeight)
{
    var extra  = "location=no,menubar=no,scrollbars=yes,status=no,toolbar=no,resizable=yes,";
        extra += "width=" + wWidth + ",height=" + wHeight;
    sen_JsOpenWindowWindow = window.open(wUrl,wName,extra);
}

/* ########################################################################################
** 3. Window Dimensions
** ########################################################################################
*/

// width and height
// The inner dimensions of the window or frame.
function sen_innerSize(w_or_h)
{
   var w,h;
   if (self.innerHeight) // all except Explorer
   {
       w = self.innerWidth;
       h = self.innerHeight;
   }
   else if (document.documentElement && document.documentElement.clientHeight) // Explorer 6 Strict Mode
   {
       w = document.documentElement.clientWidth;
       h = document.documentElement.clientHeight;
   }
   else if (document.body) // other Explorers
   {
       w = document.body.clientWidth;
       h = document.body.clientHeight;
   }
   else
   {
       return FALSE;
   }
   if(w_or_h == 'h') { return h; }
   else              { return w; }
}

// scolling offset
// How much the page has scrolled.
function sen_scrollingOffset(x_or_y)
{
   var x,y;
   if (self.pageYOffset) // all except Explorer
   {
       x = self.pageXOffset;
       y = self.pageYOffset;
   }
   else if (document.documentElement && document.documentElement.scrollTop) // Explorer 6 Strict
   {
       x = document.documentElement.scrollLeft;
       y = document.documentElement.scrollTop;
   }
   else if (document.body) // all other Explorers
   {
       x = document.body.scrollLeft;
       y = document.body.scrollTop;
   }
   else
   {
       return FALSE;
   }
   if(x_or_y == 'x') { return x; }
   else              { return y; }
}


/* ########################################################################################
** 4. Style Function
** ########################################################################################
*/

function sen_SetStyle(Mode, Identifier, StyleKey, StyleVal)
{
  // IE
  if(document.all)
  {
    StyleElement = document.all(Identifier);
    StyleElement.style[StyleKey] = StyleVal;
  }
  // DOM
  else if(DOM)
  {
    if (Mode.toLowerCase() == "id")
    {
      Element = document.getElementById(Identifier);
      if (Element)
      {
        Element.style[StyleKey] = StyleVal;
      }
    }
    if (Mode.toLowerCase() == "name")
    {
      ElementList = document.getElementsByName(Identifier);
      for (var i = 0; i < ElementList.length; i++)
      {
         document.getElementsByName(Identifier)[i].style[StyleKey] = StyleVal;
      }
    }
    if (Mode.toLowerCase() == "tagname") {
      ElementList = document.getElementsByTagName(Identifier);
      for (var i = 0; i < ElementList.length; i++)
      {
          document.getElementsByTagName(Identifier)[i].style[StyleKey] = StyleVal;
      }
    }
    if (Mode.toLowerCase() == "classname") {
      ElementList = document.getElementsByTagName(Identifier);
      for (var i = 0; i < ElementList.length; i++)
      {
        if(document.getElementsByTagName(Identifier)[i].className=="indexlink"){
          document.getElementsByTagName(Identifier)[i].style[StyleKey] = StyleVal;
        }
      }
    }
  } // END else if DOM
} // END f.

/* ########################################################################################
** 5. Forms
** ########################################################################################
*/

function sen_add2formfield(formnr, fieldname, fieldindex, str, nlOn2ndCall) {
  var debug = false;
  var myform; var myfield; var strfield;
  if(!document.forms[formnr])
  {
    if(debug){alert('formnr' + formnr + 'does not exist.');}
  }
  else
  {
    myform = document.forms[formnr];
    if(fieldindex==false) {
      strfield = fieldname;
    } else {
      strfield = fieldname + '[' + fieldindex + ']';
    }
    if(myfield = myform.elements[strfield])
    {
      var getvalue = myfield.value;
      // add newline?
      if(getvalue!='' && nlOn2ndCall )
      {
        str = '\r\n' + str;
      }
      var getvalue = myfield.value;
      var setvalue = getvalue + str;
      myfield.value = setvalue;
      myfield.focus();
    }
    else{if(debug)
    {
      alert('field \'' + strfield + '\' does not exist.');
    }}
  }
}


/* ########################################################################################
** 6. Cookies
** ########################################################################################
*/
function sen_cookieCheck() {
    document.cookie="sen_js_check_cookies_active";
    if(document.cookie=="sen_js_check_cookies_active") {
      return true;
    }
    else {
      return false;
    }
}
function sen_cookieSet(cname, cvalue, minutes)
{
  if (minutes) {
    var date = new Date();
    date.setTime(date.getTime()+(minutes*60*1000));
    var expires = "; expires="+date.toGMTString();
  }
  else {
    var expires = "";
  }
  document.cookie = cname+"="+cvalue+expires+"; path=/";
}
function sen_cookieGet(name)
{
  var nameEQ = name + "=";
  var ca = document.cookie.split(';');
  for(var i=0;i < ca.length;i++) {
    var c = ca[i];
    while (c.charAt(0)==' ') {
      c = c.substring(1,c.length);
    }
    if (c.indexOf(nameEQ) == 0) {
      return c.substring(nameEQ.length,c.length);
    }
  }
  return null;
}
function sen_cookieUnset(name)
{
  sen_cookieSet(name,"",-1);
}

