
// ===================================================================================
//  js_geber_lib
// ===================================================================================
function geber_lib_activateLibrary(pagePath)
{
  geber_lib_detectBasePath(pagePath);
}

var geber_lib_onloadFuncArray;

function geber_lib_addLoadEvent(func) 
{
    if (document.all)
    {
        try { attachEvent("onload", func); return;}
        catch (e) 
        { }
    }
    else
    {
        window.addEventListener("load", func, true);
        return;
    }


  // initialise the onload handler
  if (geber_lib_onloadFuncArray == null)
  {
      geber_lib_onloadFuncArray = new Array();

      var oldonload = window.onload;
      window.onload = function() 
      {
          for (var funcIdx=0; funcIdx <  geber_lib_onloadFuncArray.length; funcIdx++)
               geber_lib_onloadFuncArray[funcIdx]();
      }
  }

  geber_lib_onloadFuncArray[geber_lib_onloadFuncArray.length] = func;
}




   // geber_lib_stripTags
   // ---------------------------------------------------------------------------------------------------------------------------------------------------------
   /**
    * stripps all the tags from the provided text
    */
    function geber_lib_stripTags(text)
    {
        if (!text || (typeof(text) != "string") || (text.length <= 0)) 
            return "";

        // strip off all javascript tags
        text = text.replace(/<script.*<\/script[^>]*>/gi, "");


        // strip off all stye tags
        text = text.replace(/<style.*<\/style[^>]*>/gi, "");
        text = text.replace(/<head.*<\/head[^>]*>/gi, "");

        // strip off all other tags
        text = text.replace(/<[^>]*>/gi, "");

        // strip off all invalid characters
        text = text.replace(/[^-_,;:\/&\w+0-9a-zA-Z|"'\.]/gi, "");

        return text;
    }

function geber_lib_getQueryParameter(paramName)
{
       var query = window.location.search.toString();

       if (!query || (query.length <= 0)) 
           return "";

       if ((paramName == null) || (typeof(paramName) != "string") || (paramName.length <= 0))
         paramName = "q";

       query = query.match(new RegExp("^.*[?&]" + paramName + "=(.*)$"));
       if (!query) return "";

       query = query[1];
       query = unescape(query);

       // get rid of invalid whitespace characters
       query = query.replace(/[\r\n\t]+/gi, ' ') ;
       var re = new RegExp("[" + String.fromCharCode(0) + "-" + String.fromCharCode(31)  + 
                                   String.fromCharCode(96) + "]", "gi") ;     
       query = query.replace(re, '');

       // convert fixed size space
       re = new RegExp(String.fromCharCode(160) + "+", "gi") ;
       query = query.replace(re, ' ') ;

       // strip off extra query paramaters
       query = query.replace(/&(amp;)?([^;]*=.*)?$/gi, "");

       // tags are invalid
       if (query.match(/<.?(script|style)/gi))
           return "";      

       // clean up the query string
       query = geber_lib_stripTags(query);
       query = query.replace(/[^-_:;,0-9a-zA-Z\w\/\.=]/gi, "");
       return query;
}


function geber_lib_writeDocument(htmlText)
{
    document.write(htmlText);
}

var geber_lib_pageBaseURL = "/";
function geber_lib_getBaseURLPath()
{
    if (geber_lib_pageBaseURL)
        return geber_lib_pageBaseURL;
    else return "/";
}

function geber_lib_redirectToPath(pagePath)
{
    if (!pagePath || typeof(pagePath) != "string" || pagePath.length <= 0)
        return false;

    var baseURIPath = geber_lib_getBaseURLPath();
    if (!baseURIPath || typeof(baseURIPath) != "string" || baseURIPath.length <= 0)
        return false;

    var targetPath = "";
    if (pagePath.substring(0, 3) == "../")
    {
        baseURIPath = window.location.pathname;
        while (pagePath.substring(0, 3) == "../")
        {
            baseURIPath = geber_lib_dirname(baseURIPath);
            pagePath = pagePath.substr(3);
        }
 
        if (!baseURIPath || baseURIPath.length <= 0)
            baseURIPath = "";

        targetPath = baseURIPath + "/" + pagePath;
    }

    if (pagePath.substring(0, 1) == "/" && baseURIPath.substring(baseURIPath.length-1, baseURIPath.length) == "/")
        targetPath = baseURIPath.substring(0, baseURIPath.length-1) + pagePath;
    else
        targetPath = baseURIPath + pagePath;

    if (targetPath && targetPath.length > 0)
    {
        window.location.href =  targetPath;
        return true;
    }
    return false;
}

function geber_lib_detectBasePath(currentPagePath)
{
   if (!currentPagePath)
       return;

   currentPagePath = String(currentPagePath).replace(new RegExp("^/(de|en|fr|it|es)/"), "/");

   var newPageBaseURL = String(window.location.pathname);
   var pos = newPageBaseURL.indexOf(currentPagePath);

   if (pos < 0) // detect some special pages
       pos = newPageBaseURL.indexOf("/serviceseiten/suche");
   if (pos < 0) // detect some special pages
       pos = newPageBaseURL.indexOf("/servicepages/search");
   if (pos < 0) // detect some special pages
       pos = newPageBaseURL.indexOf("/servicepages");
   if (pos < 0) // detect some special pages
       pos = newPageBaseURL.indexOf("/serviceseiten");


   if (pos >= 0)
       geber_lib_pageBaseURL = newPageBaseURL.substring(0, pos);
   else
       geber_lib_pageBaseURL = "/";

   if (geber_lib_pageBaseURL == "")
       geber_lib_pageBaseURL = "/";

}

function geber_lib_dirname(fileName)
{
      if (!fileName) return fileName;
      fileName = String(fileName);
     
      if (fileName.length <= 0) return fileName;

      var pathSeparator = "/";
      if (String(window.location.protocol).match(/file/i) && navigator.platform.match(/Win/i) && navigator.userAgent.match(/MSIE/))
          pathSeparator = "\\";

      var idx = fileName.lastIndexOf(pathSeparator);
      if (idx && (idx >= 0)) 
          return fileName.substring(0, idx);
      else
          return fileName;
}

function glossary_addLinkBackButton() 
{
    var content = document.getElementById("description");
    if (!content) content = document.getElementById("bodyContent");
    if (!content) content = document.getElementById("content");
    if (!content) return;
    
   
    var links = content.getElementsByTagName("a");
    for (var i=0; i<links.length; i++) {
       if (links[i].href.match(/\?/))
           links[i].href=links[i].href + "&back=1";
        else
           links[i].href=links[i].href + "?back=1";
    }
}



function print_setImg() {   
    var a = document.getElementById("mainbar");
    for(var i = 0; i < a.getElementsByTagName("img").length; i++) {
      if (document.formular.setImg[0].checked) 
        a.getElementsByTagName("img")[i].style.display="inline";
      if (document.formular.setImg[1].checked) 
        a.getElementsByTagName("img")[i].style.display="none";
    }
  }

var operabar = (window.opera ? "=yes" : "");

function sendPopUp(newLocation) {
  var w = 640;
  var h = 405;
 	
  return PopUpOpenWindow(newLocation, 'popup', 'resizable=yes, status=no, toolbar=no, scrollbars' + operabar, w, h); 
}

function printPopUp(newLocation) {
  var w = 626;
  var h = 500;
  
  var operabar = "";
  if (window.opera) operabar = "=yes";
  
   return PopUpOpenWindow(newLocation, 'popup', 'resizable=yes, status=no, toolbar=no, scrollbars' + operabar, w, h); 
}

function resizePrintPopUp() {
  var w = 626;
  var h = 560;
  var browser = geber_getBrowser();  

  h = h + browser.extraStatusBarHeight;
  if (opener)
      window.resizeTo(w, h);
}

function glossaryPopUp(newLocation) {
  var h = 350;
  var w = 450;
 
  return PopUpOpenWindow(newLocation, 'glossary', 'resizable=yes, status=no, toolbar=no, scrollbars' + operabar, w, h);
}


function tablePopUp(newLocation, preferedWidth) {

  var w = (preferedWidth && !isNaN(preferedWidth))? preferedWidth : 800;
  var h = 500;

  return PopUpOpenWindow(newLocation, 'tablePopUp', 'scrollbars,resizable=yes,location=no,status=no,toolbar=no,', w, h);
}

function imagePopUp(newLocation, w, h) 
{
  w += 15;
  h += 32;
   return PopUpOpenWindow(newLocation, 'imagePopUp', 'resizable=yes,location=no,status=no,toolbar=no,', w, h);
}

function popUp(URL, Height, Width, Resizable, Toolbar, Scrollbars, id)
{
	var szWndOptions = "";
	var szToolbar = (Toolbar=="ja")?"yes":"no";	
	var szScrollbars = (Scrollbars=="ja")?"yes":"no";
	var szResizable = (Resizable=="ja")?"yes":"no";
	szWndOptions += ",resizable=" + szResizable
	szWndOptions += ",scrollbars=" + szScrollbars
	szWndOptions += ",toolbar=" + szToolbar
	szWndOptions += ",menubar=" + szToolbar
	szWndOptions += ",status=" + szToolbar
	szWndOptions += ",directories=no"
	szWndOptions += ",copyhistory=no"
	szWndOptions += ",location=no"

	return PopUpOpenWindow(URL, id, szWndOptions, Width, Height);
}

function PopUpOpenWindow(newLocation, name, specialFeatures, w, h)
{
  var popUpWindow;
  try
  {
      var browser = geber_getBrowser();  

      /* increase size because status bar is always visible on Windows XP */
      h = h + browser.extraStatusBarHeight;
  }
  catch (e)
  {
      var Ergebnis = navigator.userAgent.match(/Windows NT ([5-9]).([0-9])/);
      if (navigator.userAgent.match(/firefox/i) || Ergebnis && Ergebnis[2] && Ergebnis[1] && ((Ergebnis[2] >= 1) || (Ergebnis[2] > 5))) 
      {
           if (navigator.userAgent.match(/ MSIE/))
               h = h+20;
           else
               h = h+15;
      }
  }

  // for popup within search
  if (!newLocation.match(/^(https?|file|ftp):\/\//i) && typeof(geberPopUpBaseURL) == 'string' && geberPopUpBaseURL != null && geberPopUpBaseURL.length > 0)
      newLocation = geberPopUpBaseURL + "/" + newLocation;

  if (!specialFeatures)
      specialFeatures = "";

  try
  {
    popUpWindow = window.open(newLocation, name, specialFeatures +  ',width=' + w + ',height=' + h);
  }
  catch (e)
  {
    return false;
  }  
  
  try
  {
    popUpWindow.resizeTo(w, h);
  }
  catch (e) {}
  
  try
  {
    popUpWindow.focus();
  }
  catch (e) {}

  return true;

}
// -----------------------------------------------------------------------------------------------
// statistics
// -----------------------------------------------------------------------------------------------

function geber_preLoadGWSImage(simple)
{
    if (!simple)
        window.setTimeout("geber_doPreLoadGWSImage(false)", 200);
    else
        window.setTimeout("geber_doPreLoadGWSImage(true)", 200);

}

function geber_doPreLoadGWSImage(simple)
{
    if (String(window.location.hostname).match(/iedit.geber.at/) || String(window.location.protocol).match(/file/))
          return;

    var pageURL = escape(window.location);
    var referrer = document["referrer"]==null?'':escape(document.referrer);

    if ((referrer == "" || referrer.length <= 0) && (opener))
    {
        try {referrer = escape(opener.location); } catch(e) {}
    }
    var imageURL = "http://gws.geber.at/baca/gws.gif?js=1&ref=" +
                  referrer + "&pg=" + pageURL;

    imageURL += "&screen=" + screen.width + "x" + screen.height;
    var browser = null;
    try
    {
        browser = geber_getBrowser();
        if (browser && !browser.hasDetectedPlugins())
            browser.detectPlugins();
    }
    catch (e) {}

    if (!simple && browser && browser.hasDetectedPlugins())
    {
        if (browser)
        {
             imageURL += "&p_wai=" + (browser.isWAI ? "1" : "0");

             if (browser.hasFlash)
                 imageURL += "&p_flash=1&p_flash_v=" + browser.flashVersion;
             else
                 imageURL += "&p_flash=0";
             if (browser.hasPDF)
                 imageURL += "&p_pdf=1&p_pdf_v=" + browser.pdfVersion;
             else
                 imageURL += "&p_pdf=0";
             if (browser.hasJava)
                 imageURL += "&p_java=" + (browser.isJavaEnabled ? "1" : "-1" ) + "&p_java_v=" + (browser.javaVersion ? browser.javaVersion : "0");
             else
                 imageURL += "&p_java=0";
             if (browser.hasQuickTime)
                 imageURL += "&p_qt=1&p_qt_v=" + browser.quickTimeVersion;
             else
                 imageURL += "&p_qt=0";
             if (browser.hasWMedia)
                 imageURL += "&p_wm=1&p_wm_v=" + browser.wmediaVersion;
             else
                 imageURL += "&p_wm=0";
             if (browser.hasRealPlayer)
                 imageURL += "&p_real=1&p_real_v=" + browser.realPlayerVersion;
             else
                 imageURL += "&p_real=0";
             if (browser.hasDirector)
                 imageURL += "&p_director=1&p_director_v=" + browser.directorVersion;
             else
                 imageURL += "&p_director=0"; 
         }
     }
 

     var myImg = new Image();
     myImg.src = imageURL;
}

   function geber_table_handlemouseover(row)
   {
       geber_table_addclassname(row, "highlightmouseover");
   }

   function geber_table_handlemouseout(row)
   {
       geber_table_removeclassname(row, "highlightmouseover");
   }


   function geber_table_handlemouseclick(row)
   {
       if (row == null) return;
       if (row.className == null || row.className == "" || row.className.indexOf("highlightclick") < 0)
           geber_table_addclassname(row, "highlightclick");
       else
           geber_table_removeclassname(row, "highlightclick");
   }




   function geber_table_addclassname(item, name)
   {
       if (item == null || name == null || typeof(name) != "string" || name == "") return;
       try
       {
           if (item.className == null || item.className == "")
           {
               item.className = name;
           }
           else if (item.className.length < name.length ||
                 (item.className != name && item.className.indexOf(" " + name + " ") < 0 &&
                  item.className.substr(item.className.length - name.length - 1) != " " + name &&
                  item.className.substring(0, name.length+1) != name +" " 
                 )
              )
           {
               item.className += " " + name;
           }
       } catch(e) {alert(e);}
   }

   function geber_table_removeclassname(item, name)
   {
       if (item == null || name == null || typeof(name) != "string" || name == "") return;
       try
       {
           if (item.className == name)
               item.className = "";

           else if (item.className != null && item.className != "" && item.className.length > name.length)
           {
               var pos = item.className.indexOf(" " + name + " ");
               if (pos >= 0)
                   item.className = item.className.substring(0, pos+1) + item.className.substr(pos+1 + name.length + 1);

               else if (item.className.substr(item.className.length - name.length - 1) == " " + name)
                   item.className = item.className.substr(0, item.className.length - name.length - 1);

               else if (item.className.substring(0, name.length+1) == name + " ")
                   item.className = item.className.substr(name.length+1);
           }
       } catch(e) {alert(e);}
   }




function geber_perfomOnLoad()
{
   try {
      // for the glossary popups
      tt_RegisterEventHandlers();
   } catch (e) {}
}
geber_lib_addLoadEvent(geber_perfomOnLoad);
