EW = new function () {

  this.historyBackReferenz = function(){
    var newURL = "";
    try{
      var path = document.location.href;
      path = path.split( '/' );
      this.log( "historyBack path.length: " + path.length );
      var path2 = path[ path.length-1 ].split( '?');
      for( var i = 0; i < (path.length-1); i++ ){
        var prepath = "";
        if( i > 0){
          prepath = "/";
        }
        newURL += prepath + path[i];
        EW.log( i + ": " + path[i] );
      }
      if( typeof( path[4] ) != undefined ){
      	var tmpArr = path[4].split("?");
      	if( tmpArr[0] == "referenzen.php" ){
      	  newURL += '/' + tmpArr[0];
      	}
      }
      EW.log( "newURL: " + newURL );
      document.location.href = newURL;
    }catch( e ){
      this.log( "historyBack ERROR: " + e );
    }
  }

  this.historyBackArticle = function(){
    var newURL = "";
    try{
      var path = document.location.href;
      path = path.split( '/' );
      this.log( "historyBack path.length: " + path.length );
      var path2 = path[ path.length-1 ].split( '?');
      for( var i = 0; i < (path.length-1); i++ ){
        var prepath = "";
        if( i > 0){
          prepath = "/";
        }
        newURL += prepath + path[i];
        EW.log( i + ": " + path[i] );
      }
      if( typeof( path[4] ) != undefined ){
      	var tmpArr = path[4].split("?");
      	if( tmpArr[0] == "news.php" ){
      	  newURL += '/' + tmpArr[0];
      	}
      }
      EW.log( "newURL: " + newURL );
      document.location.href = newURL;
    }catch( e ){
      this.log( "historyBack ERROR: " + e );
    }
  }

  this.popup = function( file, w, h, s, pName ) {
    var zeit = new Date();
    var ms = zeit.getTime();
    var scroll = "no";
    var wName = "EWPopUp_" + ms;
    if( pName && pName != "" ){
      wName = pName;
    }
    if ( s == 1 ){
      scroll = "yes";
    }
    open( file, wName,
            +'location=0,'
            +'menubar=0,'
            +'scrollbars='+scroll+','
            +'toolbar=0,'
            +'status=0,'
            +'top=50,left=50,'
            +'width='+w+',height='+h);
    EW.log( "PopUp opened with this Name: " + wName );
  }

  this.expressInstallSwfurl = 'http://www.adobe.com/go/getflashplayer_de';
  
  this.writeFlash = function( pURL, pID, pWidth, pHeight, pVersion, flashVars, params, attributes ){
    var output = "";
    var postfix = "";
    try{
      var search = location.search.replace( /\?/g, "" );
      if( search != "" ){
        postfix = "?" + search;
      }
      swfobject.embedSWF( pURL + postfix, pID, pWidth, pHeight, pVersion, this.expressInstallSwfurl, flashVars, params, attributes );
    }catch( e ){
      if( e == "TypeError: n has no properties" ){
        output = "DIV Bereich mit der ID " + pTarget + " ist undefined";
      }
      this.log( "writeFlash ERROR: " + output + " --> " +  e );
    }
  }    


  this.log = function( pWhat ){
    try{
      if( navigator.userAgent.indexOf('Firefox') >= 0 ){
        console.log( "EW: " + pWhat );
      }
    }catch( e ){}
  }
  
  /* Event Listener                      */
  /* EW.addEvent( window, 'load', FUNKTION ); */
  this.addEvent = function( 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; 
    }
  }

  this.getURL = function( url, my_id, callback_func, optional_var,  method){
    EW.log( "getURL: " + url );
    var req, callback_func, url, optional_var;
    if(typeof(callback_func) == "undefined" || callback_func == "") {
      callback_func = "EW.processStateChange";
    }
   if(typeof(method) == "undefined" || callback_func == "") {
      method = "GET";
    }
    if(url != "") {
      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(method, url, true);
          var isbusy = true;
        } catch(e) {
          EW.log( "ERROR: method: "+method+" | getURL: " + 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
              EW.log( "ERROR: method:"+method+" | getURL: " + e );
            }
        }
        if(req) {
          req.onreadystatechange = function() {
            eval( callback_func )(req,my_id,optional_var,url);
          }
          try { 
            req.open(method, url, true);
            var isbusy = true;
          } catch(e) {
            // Error
            EW.log( "ERROR: method:"+method+" | getURL: " + e );
            var isbusy = false;
          }
          if(isbusy){
            req.send();
          }
        }
      } else {
        // AJAX geht nicht
        EW.log( "ERROR: method:"+method+" | getURL: " + "AJAX geht nicht" );
      }
    }
  }

  this.processStateChange = function( req, my_id, optional_var, url ) {
    // Complete
    if( req.readyState == 4 ) {
      // OK response
      if(req.status == 200) {
        if( document.getElementById( my_id ) ){
          this.loading = true;
          document.getElementById( my_id ).innerHTML = req.responseText;
        }
      } else {
        if( document.getElementById( my_id ) ){
          var myText = "\n";
          myText += '<table style="display:none"><tr><td class="font_18">' + req.responseText + '</td></tr></table><br />';
          document.getElementById( my_id ).innerHTML = myText;
        }else{
          // Bereich nicht definiert
        }
      }
    }else{
      if( this.loading == true ){
        this.loading = false;
        var myText = "\n";
        myText += '<table width="100%" height="600"><tr valign="middle" align="center"><td class="font_18"><img src=""></td></tr></table><br />';
        document.getElementById( my_id ).innerHTML = myText;
      }
    }
  }
  
}();

EW_Sizer = new function() {
  this.basics = {};
  this.basics.minWidth  = 1000;
  this.currentWidth = 0;

  this.init = function(){
    if( this.currentWidth != this.getWidth() ){
      this.currentWidth = this.getWidth();
      if( this.getWidth() > this.getMinWidth() ){
        var padding = ( this.getWidth() - this.getMinWidth() ) / 2;
        document.getElementById( 'seite' ).style.left = padding + "px";
        document.getElementById( 'seite' ).style.position = "absolute";
        EW.log( "EW_Sizer.init: minWidth: " + this.getMinWidth() + " --> width: " + this.getWidth() + " --> moved to left: " + padding + "px" );
      }
    }
  }
  
  // GETTER
  this.getWidth = function(){
    if( typeof( window.innerWidth ) != "undefined" ){
      return window.innerWidth;
    }else{
      return document.body.clientWidth;
    }
  }
  
  this.getMinWidth = function(){ 
    return this.basics.minWidth;
  }
    
}


function INIT(){
  try{
    window.setInterval("EW_Sizer.init()", 250);
  }catch( e ){ 
    Sport1.log( "ERROR: INIT: " + e );
  }
}
EW.addEvent( window, 'load', INIT );

