var flash = 0;
var plug  = 0;

if (navigator.userAgent.match(/MSIE (\d\.\d\d?)/) && !navigator.userAgent.match(/Opera/)) {
   if (RegExp.$1 >= 4.0) var FlashIE = true;
   plug = 0;
}
else {
  for(i=0; i<navigator.plugins.length; ++i) {
      if (navigator.plugins[i].name.match(/Flash/))        {
           flash = 1;
           break;
      }
  }
  plug = 1;
}

function dialog(url, titel, width, height, resizable) {
 showModalDialog(url, titel, 'dialogHeight:'+height+'px; dialogWidth:'+width+'px; resizable:'+resizable+'; status:no');
}

function openURL(siteURL, titel, width, height) {
  var page = window.open(siteURL, titel,'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,copyhistory=no,hotkeys=no,width='+width+',height='+height+',left=50,top=75');
  page.resizeTo(width, height);
}

function showMessage(titel, message) {
  // Ab dieser Zeichenzahl kommt ein Scrollbar in die Glossare
  scrollbarlength=250;
  scb='no';
  if (message.length > scrollbarlength) scb = 'yes';

  infoBox = window.open('','Info','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars='+scb+',resizable=yes,copyhistory=no,hotkeys=no,width=220,height=175,left=40,top=120');
  with(infoBox.document){
   open();

   writeln('<HTML><HEAD><TITLE>'+titel+'</TITLE></HEAD>');

   writeln('<BODY TOPMARGIN="0" onload="focus();"><table cellspacing="0" cellpadding="10" border="0" onload="focus();"><tr valign="top">');
   writeln('<td class="subheadbold"><b>'+titel+'</b></td></tr>');
   writeln('<tr valign="top"><td class="standard">'+message+'</td></tr></table></BODY></HTML>');

   close();
   infoBox.resize
   infoBox.focus();
  }
}


function setPointer(theRow, theAction){
    var theDefaultColor = "#FFFFFF";
    var thePointerColor = "#CCFFCC";
    var theMarkColor    = "#FFCC99";
    var theCells = null;

    if ((thePointerColor == '' && theMarkColor == '')
        || typeof(theRow.style) == 'undefined') {
        return false;
    }

    if (typeof(document.getElementsByTagName) != 'undefined') {
        theCells = theRow.getElementsByTagName('td');
    }
    else if (typeof(theRow.cells) != 'undefined') {
        theCells = theRow.cells;
    }
    else {
        return false;
    }

    var rowCellsCnt  = theCells.length;
    var domDetect    = null;
    var currentColor = null;
    var newColor     = null;
    if (typeof(window.opera) == 'undefined'
        && typeof(theCells[0].getAttribute) != 'undefined') {
        currentColor = theCells[0].getAttribute('bgcolor');
        domDetect    = true;
    }

    else {
        currentColor = theCells[0].style.backgroundColor;
        domDetect    = false;
    }

    if (currentColor == ''
        || currentColor.toLowerCase() == theDefaultColor.toLowerCase()) {
        if (theAction == 'over' && thePointerColor != '') {
            newColor = thePointerColor;
        }
        else if (theAction == 'click' && theMarkColor != '') {
            newColor = theMarkColor;
        }
    }

    else if (currentColor.toLowerCase() == thePointerColor.toLowerCase()) {
        if (theAction == 'out') {
            newColor = theDefaultColor;
        }
        else if (theAction == 'click' && theMarkColor != '') {
            newColor = theMarkColor;
        }
    }

    else if (currentColor.toLowerCase() == theMarkColor.toLowerCase()) {
        if (theAction == 'click') {
            newColor = (thePointerColor != '')? thePointerColor : theDefaultColor;
        }
    }


    if (newColor) {
        var c = null;
        if (domDetect) {
            for (c = 0; c < rowCellsCnt; c++) {
                theCells[c].setAttribute('bgcolor', newColor, 0);
            }
        }

        else {
            for (c = 0; c < rowCellsCnt; c++) {
                theCells[c].style.backgroundColor = newColor;
            }
        }
    }

    return true;
}

function setCellMarker(theCell){
    var theDefaultColor = "#FFFFFF";
    var theMarkColor    = "#FF5F00";

    if (typeof(theCell.style) == 'undefined') {
        return false;
    }

    var domDetect    = null;
    var currentColor = null;
    var newColor     = null;

    if (typeof(window.opera) == 'undefined' && typeof(theCell.getAttribute) != 'undefined') {
        currentColor = theCell.getAttribute('bgcolor');
        domDetect    = true;
    }
    else {
        currentColor = theCell.style.backgroundColor;
        domDetect    = false;
    }

    if (currentColor == '' || currentColor.toLowerCase() == theDefaultColor.toLowerCase()) {
       newColor = theMarkColor;
    }
    else if (currentColor.toLowerCase() == theMarkColor.toLowerCase()) {
        newColor = theDefaultColor;
    }

    if (newColor) {
        var c = null;
        if (domDetect) {
            theCell.setAttribute('bgcolor', newColor, 0);
        }
        else {
            theCell.style.backgroundColor = newColor;
        }
    }

    return true;
}

/////// Get Elements By ClassName
  var getElementsByClassName = function()
{
    // native
    if (document.getElementsByClassName)
    {
        return function(className, nodeName, parentElement)
        {
            var s = (parentElement || document).getElementsByClassName(className);

            if (nodeName && nodeName != '*')
            {
                nodeName = nodeName.toUpperCase();
                return Array.filter(s, function(el) { return el.nodeName == nodeName; });
            }
            else
                return [].slice.call(s, 0);
        }
    }

    // xpath
    if (document.evaluate)
    {
        return  function(className, nodeName, parentElement)
        {
            if (!nodeName) nodeName = '*';
            if (!parentElement) parentElement = document;

            var results = [], s, i = 0, element;

            s = document.evaluate(
                ".//" + nodeName + "[contains(concat(' ', @class, ' '), ' " + className + " ')]",
                parentElement,
                null,
                XPathResult.ORDERED_NODE_SNAPSHOT_TYPE,
                null
            );

            while ((element = s.snapshotItem(i++)))
                results.push(element);

            return results;
        }
    }

    // generic
    return function(className, nodeName, parentElement)
    {
        if (!nodeName) nodeName = '*';
        if (!parentElement) parentElement = document;

        var results = [], s, i = 0, element;
        var re = new RegExp('(^|\\s)' + className + '(\\s|$)'), elementClassName;

        s = parentElement.getElementsByTagName(nodeName);

        while ((element = s[i++]))
        {
            if (    (elementClassName = element.className) &&
                (elementClassName == className || re.test(elementClassName))
            )
                results.push(element);
        }

        return results;
    }
}();
