
//Ajax Klasse
function Ajax(){
   this.url = '';
   this.params = '';
   this.method = 'GET';
   this.onSucess = '';
   this.onError = function(emsg){
    alert(emsg);
   }
   this.refreshurl = '';
}

Ajax.prototype.doRequest = function(){

    if(!this.url){
        this.onError("Es wurde keine Url angegeben. Der Request wird abgebrochen.");
        return false;
    }
    if(!this.method){
       this.method = 'GET';
    }
    else{
       this.method= this.method.toUpperCase();
    }
    
    this.refreshurl = this.refreshurl;
    
    var xmlHttpRequest = getHTTPRequest();
    if(!xmlHttpRequest){
        this.onError("Es konnte kein xmlHttpRequest-Objekt erschaffen werden.");
        return false;                                                                          
    }
    
    //zugriff auf Klasse für readyStadeHandeler
    var _this = this;

    switch(this.method){

     case "GET": xmlHttpRequest.open(this.method, this.url+"?"+this.params, true);
                 xmlHttpRequest.onreadystatechange = readyStateHandler;
                 if( xmlHttpRequest.overrideMimeType){
                         xmlHttpRequest.overrideMimeType('text/xml; charset=ISO-8859-1');  
                 }
                 xmlHttpRequest.send(null);
                 break; 
     case "POST": xmlHttpRequest.open(this.method, this.url, true);
                  xmlHttpRequest.onreadystatechange = readyStateHandler;
                  if( xmlHttpRequest.overrideMimeType){
                         xmlHttpRequest.overrideMimeType('text/xml; charset=ISO-8859-1');  
                 }
                 xmlHttpRequest.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded'); 
                 xmlHttpRequest.send(this.params);
                 break;        
    }//end switch case
    
    function readyStateHandler(){
       if(xmlHttpRequest.readyState < 4){ 
          return false;
       }
       if((xmlHttpRequest.status == 200)||(xmlHttpRequest.status == 304) ){ 
            if(_this.onSuccess){
                _this.onSuccess(xmlHttpRequest.responseText, xmlHttpRequest.responseXML);
                _this.refreshurl =  this.refreshurl; 
            }
            else{
                if(_this.onError){
                  _this.onError("Es trat ein Fehler bei der Übertragung aus.\n" + "["+ xmlHttpRequest.status + " "+ xmlHttpRequest.statusText + "]");
                }
            }//end else
       }//end if   
    }//end function     
  
    function getHTTPRequest(){
      
        var meinRequest = null;
                
        if(window.XMLHttpRequest){
            //alle Broswer außer IE
            meinRequest = new XMLHttpRequest();
        }//end if
       
        else if(window.ActiveXObject){
            try{ //IE 
                meinRequest = new ActiveXObject("Msxml2.XMLHTTP");
            }
            catch(e){
                //für IE6 oder älter
                var XmlHttpVersions = new Array('MSXML2.XMLHTTP.6.0', 'MSXML2.XMLHTTP.5.0', 'MSXML2.XMLHTTP', 'Microsoft.XMLHTTP');
                for (var i = 0; i < XmlHttpVersions.length && !meinRequest; i++  ){
                   try{ //IE 
                        meinRequest = new ActiveXObject(XmlHttpVersions[i]);    
                    }
                    catch(e){
                        _this.onError("Error:"+e.name+"\n"+e.message);
                    }//end catch     
                }//end for
                
            }//end catch
        }//end else
        return  meinRequest;
    }//end function  
    
}//end class function  


function load(spinnid, LID){
   spinnid == null ? spinnid = 'limg' : ''; 
   LID == null ? LID = 'loadK' : '';
  
   var loadElement = document.getElementById(spinnid);
   //if(loadElement.hasChildNodes()!= true){ 
       var p = document.createElement('img');
       p.setAttribute('id', LID); 
       p.src = 'images/spinner.gif';
       loadElement.appendChild(p);
   //}
}//end function

function loaded(spinnid, LID){
    spinnid == null ? spinnid = 'limg' : '';
    LID == null ? LID = 'loadK' : '';
         
    var loadElement = document.getElementById(spinnid);
    knoten = document.getElementById(LID);
    loadElement.removeChild(knoten);  
}//end function