var cPath = (window.getRelativeWebRoot ? window.getRelativeWebRoot() : '') + 'js/';
document.write ('<SCR' + 'IPT LANGUAGE="JavaScript1.2" SRC="'+ cPath +'Lib/BPage.js" TYPE="text/javascript"><\/SCR' + 'IPT>');

// Nur ben�tigt, wenn zus�tzliche Javascript-Funktionen auf jeder Seite ben�tigt werden.

function setSearchFocus (cFieldname) {
  var oSearchField = document.forms[0].elements[cFieldname];
  if (oSearchField && oSearchField.focus) oSearchField.focus();
}

function _openAdditor (cParams) {
  var cURL = (window.getRelativeWebRoot ? window.getRelativeWebRoot() : '') + 'Additor/Custom/Additor.php?' + cParams + '&Javascript=1';
//	if (SID > ' ') cURL += '&SID=' + SID;
  var cPath = window.location.pathname;
  cPath = cPath.substr (0, cPath.lastIndexOf ('/')+1);
  cURL = (CONFIG['Server']['SecureEditMode'] ? 'https://' : 'http://') + (window.location.hostname + '/' + cPath + cURL).replace ('//', '/');
  openAdditorWindow (SID, cURL);
  return (1);
}


function setCookie (name, value, expires, path, domain, secure) {
  var now = new Date();
  if (expires) expires = expires * 1000 * 60 * 60 * 24;
  var expires_date = new Date(now.getTime() + (expires));
  document.cookie = name + "=" +escape(value) +
  ((expires) ? ";expires=" + expires_date.toGMTString() : "") +
  ((path) ? ";path=" + path : "") +
  ((domain) ? ";domain=" + domain : "") +
  ((secure) ? ";secure" : "");
}

function getCookie(check_name) {
  var allCookies = document.cookie.split( ';' );
  var name = '';
  var value = '';
  var found = false;

  for (i=0; i < allCookies.length; i++) {
    cookie = allCookies[i].split( '=' );
    name = cookie[0].replace(/^\s+|\s+$/g, '');
    if (name == check_name) {
      found = true;
      if (cookie.length > 1) value = unescape( cookie[1].replace(/^\s+|\s+$/g, '') );
      return value;
    }
    cookie = null;
    name = '';
  }
  if (!found) return null;
}

function searchOnFocus (bFocus) {
  var oIn = document.getElementById('search');
  var cStr = oIn.value;
  if (bFocus) {
    if (cStr == 'Suche') oIn.value = '';
  } else {
    if (cStr == '') oIn.value = 'Suche';
  }
}


function replacePage (cUrl) {
 	//alert('replacePage( '+cUrl+')');
   var xhrOptions = {
        url: cUrl,
        handleAs: "text",
        timeout: 300000,
        preventCache: true,
        load: function(response, ioArgs) {
          var oldContent = document.getElementById('content');
          var newHtml = document.createElement("div");
          newHtml.innerHTML = response;
          var newContent = findContentNode(newHtml);
          if (newContent != null) oldContent.parentNode.replaceChild (newContent, oldContent);
         },
        error: function(response, ioArgs) {
          console.error("HTTP status code: ", ioArgs.xhr.status);
        }
      };
  dojo.xhrGet(xhrOptions);
}

function reloadPage (cUrl) {
  if (cUrl != "") window.location = cUrl
}

function findContentNode (node) {
  var child = node.firstChild;
  while (child != null) {
    if (child.nodeType == 1 && child.nodeName == 'DIV' && child.getAttribute('id') == 'content')
      return (child);
    else if (child.nodeName == 'DIV' || child.nodeName == 'BODY') {
      var sub = findContentNode (child);
      if (sub != null) return (sub);
    }
    child = child.nextSibling;
  }
  return (null);
}

function toggleDownloadFiles(nodeA) {
  var nodeTbody = nodeA.parentNode.parentNode.parentNode.nextSibling;
  var nodeShowfiles = nodeA.firstChild;
  var isClosed = nodeTbody.className.match(/closed/);
  var nodes = new Array(nodeTbody, nodeShowfiles);
  for (var i in nodes) {
    var node = nodes[i];
    if (isClosed)
      node.className = node.className.replace (/ ?closed/, '');
    else
      node.className += ' closed'
  }
}

function unCryptMailto (s){
   var Ergebnis;
   s = rot13(s) + '';
   if (CONFIG['AntiSpamMail']['At']) {
     var regAusdruck = new RegExp("(.*)" + CONFIG['AntiSpamMail']['At'] + "(.*)", "g")
     Ergebnis = regAusdruck.exec(s);
     if (Ergebnis && Ergebnis.length > 1) location.href="mailto:" + Ergebnis[1] + "@" + Ergebnis[2];
   }
}

var rot13map = null;
function rot13(a) {
  if (rot13map == null) {
    rot13map = new Array();
    var s = "abcdefghijklmnopqrstuvwxyz";
    for (var i=0; i<s.length; i++) rot13map[s.charAt(i)] = s.charAt((i+13)%26);
    for (var i=0; i<s.length; i++) rot13map[s.charAt(i).toUpperCase()] = s.charAt((i+13)%26).toUpperCase();
  }
  var s = "";
  for (var i=0; i<a.length; i++) {
    var b = a.charAt(i);
    s	+= (b>='A' && b<='Z' || b>='a' && b<='z' ? rot13map[b] : b);
  }
  return s;
}
