var ooom=new Object;

function ps$(e) {
  if(typeof(e)!='string') return e;
  if(document.getElementById) e=document.getElementById(e);
  else if(document.all) e=document.all[e];
  else e=null;
  return e;
}

function addLoadEvent( func)   {
   var oldonload = window.onload;
   if( typeof window.onload != 'function')   {
      window.onload = func;
   } else {
      window.onload = function() {
        oldonload();
        func();
   }  }
}

var cssClass = {};  // a namespace object

cssClass.is = function(e, c) {
   var retval = false;
   if( typeof e != "object") return retval;
   var classes = e.className;
   if( classes) {
     if( classes == c) retval = true;
     else retval = (classes.search("\\b" + c + "\\b") != -1)
   }
   return retval;
}
 
cssClass.add = function(e, c) {
   if( !cssClass.is(e, c) && typeof e == "object" )  {
      if( e.className) c = " " + c;
      e.className += c;
   }
}

ooom.log=function( )  {
   if( typeof console=='object' && console.log != null) {
      console.log( arguments);
   }
}

cssClass.remove = function(e, c) {
   if( !e || !c) return; // alert( "cssClass.remove for null, c=" + c);
   if( cssClass.is(e, c)  )  {
      e.className = e.className.replace( new RegExp("\\b" + c + "\\b\\s*", "g"), "");
   }
}


displayObject = function( obj, message)  {
   message = " displayObject " + message + " ";
   if( typeof obj == 'function')  {
      alert( message + ": is a function!!!");
   } else if( typeof obj != 'object')  {
      alert( message + ": not an object");
      return;
    }
    var propertylist = "";
    var functionlist = "";
    var nullprops = "";
    var i = 0;
    for( var name in obj) {
       var value = obj[name];
       var typeofval = typeof value;
       if( typeofval == 'function') {
         functionlist += name + "\n";
       } else if( !(obj[ name]) || obj[ name] == null)  {
          nullprops += name + ", ";
       } else {
          propertylist += "[ " + i++ + "]" + name + "(" + typeof obj[name] + ")=" + obj[ name] + "#\n";
          if( i % 33 == 0)   {
             alert( message + "properties:\n" + propertylist);
             propertylist = "";
          }
       }
    }
    alert( message + "last properties:\n" + propertylist);
    if( functionlist)   {
       alert( message + "Functions:\n" + functionlist);
    }
    if( nullprops) alert( message + "NullProps:\n" + nullprops);
}


function xAddEventListener(e,eventType,eventListener,useCapture)
{
  if(!(e=ps$(e))) return;
  eventType=eventType.toLowerCase();

  if(e.addEventListener) { /* alert( "addEventListener:addEventListener, e.addEventListener=" + typeof( e.addEventListener) + "# eventType=" + eventType);*/ 
     e.addEventListener(eventType,eventListener,useCapture); 
  } else if(e.attachEvent) { 
            e.attachEvent('on'+eventType,eventListener); 
  } 
}

function xRemoveEventListener(e,eventType,eventListener,useCapture)
{
  if(!(e=ps$(e))) return;
  eventType=eventType.toLowerCase();
  if( e==window) {
     if(eventType=='resize') { window.xREL=null; return; }
     if(eventType=='scroll') { window.xSEL=null; return; }
  }
  var eh='e.on'+eventType+'=null';
  if(e.removeEventListener) e.removeEventListener(eventType,eventListener,useCapture);
  else if(e.detachEvent) e.detachEvent('on'+eventType,eventListener);
  else eval(eh);
}

function getEvTargetObj( obj)  {
  var targetObj = null;
    // ooom.log( "getEvTargetObj Anfang:" + typeof obj );
  if( window.event && window.event.srcElement) { // IE6
      targetObj = window.event.srcElement
      // alert("IE target OBj");
  } else if( obj && obj.target )  { // DOM 2.0
      targetObj = obj.target;
      // ooom.log("FFox target OBj");
  }
  return targetObj
}

function setTextOfEl( elId, textToSet)  {
   var tabEl = ps$(elId);
   if( tabEl && typeof textToSet=="string")  {
       var elChs = tabEl.childNodes;
       var i = 0;
       while( i<elChs.length)  {
          var textEl = elChs[i++];
          if( textEl && textEl.nodeType == 3)   {
             i=elChs.length;
             textEl.nodeValue = textToSet;
}  }   }  }

function getTextOfEl( elId)  {
   var retval="";
   var tabEl = ps$(elId);
   if( tabEl)  {
       var elChs = tabEl.childNodes;
       var i = 0;
       while( i<elChs.length)  {
          var textEl = elChs[i++];
          if( textEl && textEl.nodeType == 3)   {
             i=elChs.length;
             retval=textEl.nodeValue;
}  }   }  return retval; }

function addTextOfEl( elId, textToSet)  {
   var tabEl = ps$( elId);
   if( tabEl && textToSet)  {
       var elChs = tabEl.childNodes;
       var i = 0;
       while( i<elChs.length)  {
          var textEl = elChs[i++];
          if( textEl && textEl.nodeType == 3)   {
             i=elChs.length;
             textEl.nodeValue = textEl.nodeValue + textToSet;
          }
       }
   }   
}

function xDef() {
  for(var i=0; i<arguments.length; ++i){if(typeof(arguments[i])=='undefined') return false;}
  return true;
}
function xStr() {
  for(var i=0; i<arguments.length; ++i){if(typeof(arguments[i])!='string') return false;}
  return true;
}
function xNum() {
  for(var i=0; i<arguments.length; ++i){if(typeof(arguments[i])!='number') return false;}
  return true;
}
function xShow(e) { return xVisibility(e, 1); }
function xHide(e) { return xVisibility(e, 0); }
function xVisibility(e, bShow) {
  if(!(e=ps$(e))) return null;
  if(e.style && xDef(e.style.visibility)) {
    if (xDef(bShow)) e.style.visibility = bShow ? 'visible' : 'hidden';
    return e.style.visibility;
  }
  return null;
}

function oTop(e) {
  if(!(e=ps$(e)) || !xDef(e.style) ) { ooom.log(" xTop for El not defined!!"); return 0 ;
  } 
  var eS=e.style;
  if(xStr(eS.top)) {
     e.at$ooom$top=parseInt(eS.top);
  } else if(xDef(eS.pixelTop)) {
     e.at$ooom$top=eS.pixelTop;
  } 

  if( xDef(e.offsetTop) && (!xDef(e.at$ooom$top) || isNaN( e.at$ooom$top)) ) {
     e.at$ooom$top=e.offsetTop;
  }
  return e.at$ooom$top;
}

function oLeft(e) {
  if(!(e=ps$(e)) || !xDef(e.style) ) { ooom.log(" ooLeft: El not defined!!"); return 0 ;
  } else if( xNum(e.at$ooom$left)) return e.at$ooom$left;
  var eS=e.style;
  if(xStr(eS.left)) {
   // alert("es.left="+eS.left + "#");
     e.at$ooom$left=parseInt(eS.left);
  } else if(xDef(eS.pixelLeft)) {
   // alert("es.pixelLeft="+eS.pixelLeft);
     e.at$ooom$left=eS.pixelLeft;
  } 
  if( xDef(e.offsetLeft) && (!xDef(e.at$ooom$left) || isNaN( e.at$ooom$left)) ) {
   // alert("es.offsetLeft="+e.offsetLeft);
     e.at$ooom$left=e.offsetLeft;
  }
   // alert("oLeft End, e.at$ooom$left="+e.at$ooom$left + "#");
  return e.at$ooom$left;
}

function oWidth(e) {
  if(!(e=ps$(e)) || !xDef(e.style) ) { ooom.log(" ooWidth: El not defined!!"); return 0 ;
  } else if( xNum(e.at$ooom$Width)) return e.at$ooom$Width;
  var eS=e.style;
  if(xStr(eS.width)) {
     e.at$ooom$width=parseInt(eS.width);
  } else if(xDef(eS.pixelWidth)) {
     e.at$ooom$width=eS.pixelWidth;
  }
  if( xDef(e.offsetWidth) && (!xDef(e.at$ooom$width) || isNaN( e.at$ooom$width)) ) {
     e.at$ooom$width=e.offsetWidth;
  }
  return e.at$ooom$width;
}

function oHeight(e) {
  if(!(e=ps$(e)) || !xDef(e.style) ) { ooom.log(" ooHeight: El not defined!!"); return 0 ;
  } else if( xNum(e.at$ooom$height)) return e.at$ooom$height;
  var eS=e.style;
  if(xStr(eS.height)) {
     e.at$ooom$height=parseInt(eS.height);
  } else if(xDef(eS.pixelHeight)) {
     e.at$ooom$height=eS.pixelHeight;
  }
  if( xDef(e.offsetHeight) && (!xDef(e.at$ooom$height) || isNaN( e.at$ooom$height)) ) {
     e.at$ooom$height=e.offsetHeight;
  }
  return e.at$ooom$height;
}

ooom.isIE=function() {
  if( !xDef(ooom.bIsIE)) {;
    var sUAg=navigator.userAgent;
	 ooom.bIsIE=sUAg.indexOf("compatible")>1 && sUAg.indexOf("MSIE")>1 && sUAg.indexOf("Opera")==-1;
  }
  return ooom.bIsIE;
}

ooom.getPos=function(e_elemRef, s_coord) {
	var n_pos = 0, n_offset,
		e_elem = e_elemRef;

	while (e_elem) {
		n_offset = e_elem["offset" + s_coord];
		n_pos += n_offset;
		e_elem = e_elem.offsetParent;
		if(e_elem)  {
	   }
	}
	return n_pos;
}

var HTTP=new Object();

HTTP.READY_STATE_UNINITIALIZED=0;
HTTP.READY_STATE_LOADING=1;
HTTP.READY_STATE_LOADED=2;
HTTP.READY_STATE_INTERACTIVE=3;
HTTP.READY_STATE_COMPLETE=4;

HTTP._factory = null;
HTTP._factoryArt = 0;
HTTP._factories = [
   function() { HTTP._factoryArt=1; return new XMLHttpRequest(); },
   function() { HTTP._factoryArt=2; return new ActiveXObject("Msxml2.XMLHTTP"); },
   function() { HTTP._factoryArt=3; return new ActiveXObject("Microsoft.XMLHTTP"); }
];

HTTP.newRequest = function() {
   if( HTTP._factory != null) return HTTP._factory();
   for( var i=0; i < HTTP._factories.length; i++)  {
      try {
         var factory = HTTP._factories[ i];
         var request = factory();
         if( request != null)   {
            HTTP._factory = factory;
            return request;
         }  
      } catch( E)  {
         continue;
   }  }
   HTTP._factory = function() { throw new Error( "XHTMLRequest not supported"); }
   HTTP._factory();
}
   
function mycallback(){
}
function myerrorRout(){
   ooom.log("base_support: myerrorRout");
}

function httprequest() {
  var loader=new HTTP.ContentLoader( 'images/plan_524p426.jpg', mycallback, myerrorRout, 'GET');
}

HTTP.ContentLoader=function(url,onload,onerror,method,callerObj,contentType,params){
  this.req=null;
  this.onload=onload;
  this.contentType=contentType;
  this.onerror=(onerror)? onerror : this.defaultError;
  this.caller=callerObj;
  this.loadXMLDoc(url,(method? method: "GET"),contentType,params);
}

HTTP.ContentLoader.prototype.loadXMLDoc = function(url,method,contentType,params) {
  if(method=="GET"){
     if( params) url+="?"+params;
     params=null;
  } else if(!contentType && method=="POST"){
    contentType='application/x-www-form-urlencoded';
  }
  this.req = HTTP.newRequest();  
  if (this.req){
    try{
      var loader=this;
      this.url=url;
      this.req.onreadystatechange=function(){
        loader.onReadyState.call(loader);
      }
        // ooom.log(" open request, url=" + url + "#");
      this.req.open(method,url,true);
      if (contentType){
        this.req.setRequestHeader('Content-Type', contentType);
      }
        // ooom.log(" send request");
      this.req.send(params);
    }catch (err){
      this.onerror.call(this);
    }
  }
 }

HTTP.ContentLoader.prototype.onReadyState = function(){
  var req=this.req;
  var ready=req.readyState;
  if (ready==HTTP.READY_STATE_COMPLETE){
        // ooom.log(" ready state complete ");
    var httpStatus=req.status;
    if (httpStatus==200 || httpStatus==0){
        // ooom.log(" ready state complete, httpStatus= " + httpStatus);
      if( typeof this.contentType =='string')  { //IE requires this test
        // ooom.log(" ready state complete, string ");
        this.responseText=req.responseText;
      }
      if(typeof this.caller=='object')  {
        // ooom.log(" ready state complete, object, call wirh responseText ");
        this.onload.call(this.caller, this.responseText);
      } else {
        // ooom.log(" ready state complete, NOT an object, call wirhOUT responseText ");
        this.onload.call(this);
      }
    }else{
      // ooom.log( "call on error");
      this.onerror.call(this);
    }
  }
}

HTTP.ContentLoader.prototype.defaultError = function(){
    ooom.log(" defaultError");
  ooom.log("error fetching data!"
    +"\n\nreadyState:"+this.req.readyState
    +"\nstatus: "+this.req.status
    +"\nheaders: "+this.req.getAllResponseHeaders());
}

function xHeight(e,uH) {
  if(!(e=ps$(e))) return 0;
  if (xNum(uH)) {
    if (uH<0) uH = 0;
    else uH=Math.round(uH);
  } else uH=-1;
  var css=xDef(e.style);
  if(css && xDef(e.offsetHeight) && xStr(e.style.height)) {
	if(uH>=0) xSetCH(e, uH);
	uH=e.offsetHeight;
  } else if(css && xDef(e.style.pixelHeight)) {
	 if(uH>=0) e.style.pixelHeight=uH;
	 uH=e.style.pixelHeight;
  }
  return uH;
}

ooom.xClientHeight=function() {
  var h=0;
  if(document.compatMode == 'CSS1Compat' && document.documentElement && document.documentElement.clientHeight)
    h=document.documentElement.clientHeight;
  else if(document.body && document.body.clientHeight)
    h=document.body.clientHeight;
  else if(xDef(window.innerHeight,document.height)) {
   h=window.innerHeight;
    if(document.height>window.innerHeight) h-=16;
  }
  return h;
}


ooom.setTop=function (e,iY) {
  if(!(e=ps$(e)) || !xNum(iY) || !(css=xDef(e.style)) ) return;
  if(xStr(e.style.top)) {
    e.style.top=iY+'px';
  } else if(xDef(e.style.pixelTop)) {
    e.style.pixelTop=iY;
  }
}


ooom.centerWindow=function() {
  var pbar=ps$('div_breite'); 
  if( pbar)   {
     var browserHeight=ooom.xClientHeight();
     var objHeight=xHeight(pbar);
     var topNew=0;
     if( isNaN( browserHeight) || isNaN( objHeight) ) {
     } else {
        topNew=Math.round( (browserHeight - objHeight)/2);  
        if( topNew < 0) topNew = 0;
     }
     if( document.body.style.marginTop != null )  {
         document.body.style.marginTop=topNew+'px';
      }
     var chNodes = pbar.childNodes;
     var count = chNodes.length;
     for( var i = 0; i < count; i++)  {
    	var chNode =  chNodes[ i];
    	if( chNode.nodeName=="DIV" && xDef(chNode.id))  {
           ooom.centerVertIE( chNode);
    	}
     }
  }
}

ooom.centerVertIE=function( chNode) {
  var top=oTop( chNode);
  if( top==null || top==0) top = 1;
  else top = 0;
  ooom.setTop( chNode, top);
}

ooom.initResizeAction=function( ) {
   var oldonresize = window.onresize;
   if( typeof window.onresize != 'function')   {
      window.onresize = ooom.centerWindow;
   } else {
      window.onresize = function() {
        oldonresize();
        ooom.centerWindow();
   }  }
   ooom.centerWindow();
   //setTimeout( ooom.initMenues, 100);
}


ooom.cbf=function( responseText)  {
   // ooom.log("menuText=" + responseText.substring( 0, 20));
   ooom.scriptEl.text=responseText;
   // ooom.log("scriptEl created");
   document.body.appendChild( ooom.scriptEl);
    // ooom.log("appended");
   new menu (MENU_ITEMS, MENU_TPL, ooom.point);
    // ooom.log("menu object created.");
   var psa=ps$('psid');
   if( psa && psem )  {
      setTextOfEl( psa, psem[1]);
      if( typeof psa.href=="string")  {
         psa.href=psem[0];
      }     
   }
    // ooom.log("about to create select items");
    new menu (Select_ITEMS, MENU_TPL, ooom.point);
    // ooom.log("select items created.");
    if( typeof ooom.nextasyncall=='function') {
      ooom.nextasyncall.call( this);
    }
}
 
ooom.asyncError=function() {
   ooom.log( "Transfer error");
}

ooom.getRelPath=function() {
 var pn=location.pathname;
 var sch='/';
 var lastSlash=pn.lastIndexOf('/');
 if( lastSlash<=0) {
   sch='\\';
   lastSlash=pn.lastIndexOf('\\');
 }

 var aP="./lehrer";
 if( lastSlash >= 7 && pn.substring( lastSlash-7, lastSlash+1)== sch+"lehrer"+sch)  {
   ooom.point=".";
   aP=".";
 }
 return aP;
}

ooom.initMenues=function() {
 ooom.scriptEl = document.createElement("script");
 var rp=ooom.getRelPath();
 ooom.point=((rp==".")? rp: ""); 
  // ooom.log("fetch menu");
  new HTTP.ContentLoader( rp+"/m_91008.js", ooom.cbf, null, 'GET',this,'text');
}

ooom.initIndividualBeavior = function( changedInputField, anchorToFire)  {
  var fieldEl = ps$( changedInputField); 
  var fieldChangedEl = ps$( anchorToFire);
  if( fieldEl && fieldChangedEl)  {
      fieldEl.onclick = function()  { 
        window.location = fieldChangedEl.href;
      };
  }
}

ooom.initClicks=function( imgs)  {
   var ar=imgs.split(',');
   for(i=0;i<ar.length;i++) {
      ooom.initIndividualBeavior("img_"+ar[i], "a_"+ar[i]);
} }

ooom.statCB=function( responseText){
   // ooom.log("call back " + responseText + "#");
}

ooom.setCookie=function( cv, expireDate)  {
   var nd = new Date();
   nd.setTime( expireDate);
   var sCookie=cv+"; expires="+ nd.toGMTString();
   document.cookie=sCookie;
}

ooom.getCookie=function( name)  {
   var retval;
   var cv=document.cookie;
   if(cv && cv.indexOf(name)==0)  {
      retval=cv.substring(name.length);
   }
   return retval;
}

ooom.accs=function( )  {
   var now=new Date();
   nc=now.getFullYear()+"."+(now.getMonth()+1)+"."+now.getDate()+" " + now.getHours() + ":"+now.getMinutes()+":"+now.getSeconds();
   coo=ooom.getCookie("ooomat=");
   var blpos=nc.indexOf(" ");
   if( blpos > 7 && coo && coo.substring(0,10)==nc.substring(0,10))  {
     nc=coo;
   } else {
     ooom.setCookie( "ooomat="+nc, now.getTime()+9999000);
   }
  var re = document.referrer;
  if( re.indexOf("google")>=0)  {
   var qidx=re.indexOf('&q=');
   if(!qidx) qidx=re.indexOf('&source=');
   if( qidx>6) re="google: " + escape( re.substring(qidx+3) );
  }
  if( re && re.indexOf("http://www.")==0)  {
    re=escape( re.substring(11) );
  }
  var m=document.lastModified;
  if( m && m.indexOf(",")==3) m=m.substring(5);
  var i=getTextOfEl( 'pageid');
  if( !i) i="0";
  var rp=ooom.getRelPath();
   // ooom.log("id:"+ i + ", re=" + re);
  new HTTP.ContentLoader( rp+"/statistics.php", ooom.statCB, myerrorRout, 'GET', null,'text',"pageid="+i+"&modif="+m+"&coo="+nc+"&ref="+re); 
}

ooom.initResizeAction();
addLoadEvent( ooom.initMenues);
addLoadEvent( ooom.accs);
