// DANARIS 2000 Javascript Library.js v1.0.2, Februar 2007, 12:00:00 CET

// Copyright (c) 2006, 2007 Daniel Neumann (http://www.danaris.de)
// 
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
// 
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
// For details, see the DANARIS.de web site: http://www.danaris.de/

/* Basic Bereich, die in einer Website vorkommen können/müssen:                                                                                                                               
                                                                                                                                                                                              
  HTML:                                                                                                                                                                                       
  <!-- DEBUG & ERROR Bereiche -->                                                                                                                                                             
  <div id="ErrorArea"></div>                                                                                                                                                                  
  <div id="DebugArea">                                                                                                                                                                        
    <div style="border-bottom: 1px solid #C80000; text-align:center; margin-bottom: 5px; color:black"><b>JS DEBUGGER by DN</b></div>                                                          
  </div>                                                                                                                                                                                      
  <!-- /DEBUG & ERROR Bereiche -->                                                                                                                                                            
                                                                                                                                                                                              
  CSS:                                                                                                                                                                                        
  #ErrorArea{ position: absolute; top: 10px; left: 1010px; width: 220px; height: auto; padding: 5px; overflow: visible; color: #CC0000; font: normal 10px Arial; }                            
  #DebugArea{ position: absolute; top: 50px; left: 1010px; width: 220px; height: auto; padding: 5px; overflow: visible; color: #999999; font: normal 10px Arial; border: 1px dotted #B9D1D3; }
  .testCSS  { padding: 10px; background-color: Yellow; color: Red; font: bold 11px sans; }                                                                                                    
                                                                                                                                                                                            */

/* Event Listener                      */
/* addEvent(window, 'load', DEBUGGER); */
function addEvent(obj, evType, func){
  if (obj.addEventListener){ 
    obj.addEventListener(evType, func, false); 
    return true; 
  }else if (obj.attachEvent){ 
    var r = obj.attachEvent("on"+evType, func); 
    return r; 
  }else { 
    return false; 
  }
}
/* Funktion die testet, ob ein Bereich existiert */
function DEF_ID(wer){
  if( document.getElementById(wer) ){
    return true;
  }else{
    return false;
  }
}
/* Funktion die testet, ob ein Bereich existiert */
function DEF_NAME(wer){
  if( document.getElementsByName(wer)[0] ){
    return true;
  }else{
    return false;
  }
}
/* SHOW Funktion */
function SHOW(wer){
  if( DEF_ID(wer) ){
    document.getElementById(wer).style.display='block';
    return true;
  }else{
    ERROR("SHOW Funktion: Bereich " + wer + " ist nicht definiert.");
    return false;
  } 
}
/* HIDE Funktion */
function HIDE(wer){
  if( DEF_ID(wer) ){
    document.getElementById(wer).style.display='none';
    //if(DEBUGMODE) ECHO('HIDE -> ' + wer);
  }else{
    ERROR("HIDE Funktion: Bereich " + wer + " ist nicht definiert.");
  } 
}
/* ERROR Funktion */
ErrorArea = 'ErrorArea';
ERROR = function(was){
  if( DEF_ID(ErrorArea) && DEBUGMODE){
    if(was != ''){
      document.getElementById(ErrorArea).innerHTML += '<b style="font: bold 11px Arial;">ERROR:</b> ' + was + '<br />';
      myTimeOut = window.setTimeout("countdown(" + ErrorArea + ")", 10000);
    }
  }
}
/* writeInto Funktion */
function writeInto(was, wem){
  if( DEF_ID(wem)){
    if(was != ''){
      document.getElementById(wem).innerHTML = was;
    }
  }else{
    ERROR( wem + ' is not defined!' );
  }
}
/* Countdown Funktion, die einen Bereich nach x Sekunden "entleert" */
function countdown(was){
  if( DEF_ID(was) ){
    document.getElementById(was).innerHTML = '';
    window.clearTimeout(myTimeOut);
  }
  //delete myTimeOut;
}
/* DEBUGGER */
DebugArea = 'DebugArea';
function ECHO(was){
  if( DEF_ID(DebugArea) && DEBUGMODE ){
    document.getElementById(DebugArea).innerHTML += was + '<br />';
  }else{
    ERROR("DEBUG Funktion: Bereich " + DebugArea + " ist nicht definiert.");
  } 
}
/* SetStyle */ 
function setStyle(was, wem, add){
  //ECHO("&lt;setStyle&gt;");
  if( DEF_ID(wem) ){
    //ECHO("&nbsp;&nbsp;ID Style add: " + was + " -> " + wem);
    if(add == 'add'){
      document.getElementById(wem).className += was;
    }else{
      document.getElementById(wem).className = was;
    }
  }
  if( document.getElementsByName(wem)[0] ){
    //ECHO("&nbsp;&nbsp;NAME Style add: " + was + " -> " + wem );
    if(add == 'add'){
      document.getElementsByName(wem)[0].className = was;
    }else{
      document.getElementsByName(wem)[0].className = was;
    }
  }else{
    //ECHO("&nbsp;&nbsp;setStyle Funktion: Bereich " + wem + " ist nicht definiert.");
  } 
  //ECHO("&lt;/setStyle&gt;");
}
/* Redirect */
function redirect(url){
  document.location.href = url;
}
/* Popup */
function fenster(url,fenster,params){
  fInstanz = window.open(url, fenster, params); 
  if(typeof(fInstanz) != 'undefined'){
    fInstanz.focus();
    return fInstanz;
  }else{
    return false;
  }
}
/* Small Browser Check */
function checkBrowser(){

  /* Test auf IE7 */
  myappVersion = navigator.appVersion;
  var Ergebnis = myappVersion.search(/MSIE 7.+/);

  if(window.XMLHttpRequest){
    if (Ergebnis != -1){
      return 'IE7';
    }else{
      return 'MOZ';
    }
  }else{
    // IE < 7
    return 'IE';
  }
}

/* fenster('http://myurl.de', 'Popup','width=901,height=675') */

var ajaxRefreshTimeout = 5000;
var naviLastClicks = "";
var activTimeout = new Object();

function getURL( url, my_id, callback_func, optional_var ){
  var req, callback_func, url;
  if(typeof(callback_func) == "undefined" || callback_func == "") {
    callback_func = "processStateChange";
  }
  if(url != "") {
    if(url.indexOf("?") == -1) {
      url += "?";
    } else {
      url += "&";
    }
    url += (new Date().getTime());
    if(window.XMLHttpRequest) { 
      // Non-IE browsers oder IE 7
      req = new XMLHttpRequest();
      req.onreadystatechange = function() {
        eval(callback_func)(req,my_id,optional_var,url);
      }
      try {
        req.open("GET", url, true);
        var isbusy = true;
      } catch(e) {
        var tmp = 'FEHLER: ' + e; 
        var isbusy = false;
      }
      if(isbusy){
        req.send(null);
      }
    } else if(window.ActiveXObject) {
      // IE < 7
      try { 
        req = new ActiveXObject("Msxml2.XMLHTTP"); 
      } catch(e) {
          try {
            req = new ActiveXObject("Microsoft.XMLHTTP");
          } catch(e) {
            // Error
          }
      }
      if(req) {
        req.onreadystatechange = function() {
          eval(callback_func)(req,my_id,optional_var,url);
        }
        try { 
          req.open("GET", url, true);
          var isbusy = true;
        } catch(e) {
          // Error
          var isbusy = false;
        }
        if(isbusy){
          req.send();
        }
      }
    } else {
      // AJAX geht nicht
    }
  }
}

function processStateChange(req, my_id, optional_var, url) {
  // Complete
  if(req.readyState == 4) {
    // OK response
    if(req.status == 200) {
      if( DEF_ID(my_id) ){
        document.getElementById(my_id).innerHTML = req.responseText;
      }
    } else {
      if( DEF_ID(my_id) ){
        var myText = "\n";
        myText += '<table style="isplay:none"><tr><td class="font_18">' + req.responseText + '</td></tr></table><br />';
        document.getElementById(my_id).innerHTML = myText;
      }else{
        // Berich nicht definiert
      }
    }
  }
}

DEBUGMODE = false;
/* INIT Funktion, wenn DEBUGMODE */
function INIT(wie){
  if( !parent.opener ){
    if(wie){
      /* DEBUG MODUS generell einschalten */
      DEBUGMODE = true;
      //ECHO('<div style="border-bottom: 1px solid #C80000; text-align:center; margin-bottom: 5px; color:black"><b>JS DEBUGGER by DANARIS</b></div>');
      //ECHO('<style type="text/css"> #DebugArea{ position: absolute; top: 10px; left: 1060px; width: 230px; height: auto; padding: 5px; overflow: visible; color: #000000; font: normal 10px Arial; border: 1px dotted #B9D1D3; } #ErrorArea{ position: relative; top: 0px; left: 0px; width: auto; height: auto; padding: 5px; overflow: visible; color: #CC0000; font: normal 10px Arial; } .testCSS  { padding: 10px; background-color: Yellow; color: Red; font: bold 11px sans; } .bold { font: bold 11px Arial,sans; color: Black; letter-spacing: 1px; } nobr { background-color: White; } </style> ');
    }else{
      DEBUGMODE = false;
    }
  }else{
    if( DEF_ID('DebugArea') ){
      HIDE('DebugArea');
      //alert("hide -> DebugArea");
    }
  }
}