Object.extend = function(destination, source) {
  for (var property in source) {
    destination[property] = source[property];
  }
  return destination;
}

function TTAjaxRequest(sUrl,oOptions,pRefObj, funcSuccess){
  var pRefObj  = pRefObj || window;
  this.Options = {
    method:'GET',
    params:'',
    async:true
    
  };
  Object.extend(this.Options,oOptions || {});
  this.Url = sUrl;
  if(this.Options.method.toUpperCase()=='GET' && this.Options.params!=''){
    if(this.Url.indexOf('?')!=-1)
      this.Url += "&"+this.Options.params;
    else
      this.Url += "?"+this.Options.params;
  }
  this.onStateChange = function(){
    if (!pRefObj || !pRefObj.xmlReq) {
      this.onStateChange = null;
      return;
    }
    if(pRefObj.xmlReq.readyState == 4){
      if(pRefObj.xmlReq.status == 200 || pRefObj.xmlReq.status == 304){
        if(pRefObj.xmlReq.responseText==""){
          pRefObj.onAjaxError();
        }else{
          pRefObj.onAjaxSuccess(funcSuccess);
        }
      }else{
        pRefObj.onAjaxError();
      }
    }
  };
  
    var xmlRequest = false;
  
    // Mozilla, Opera, Safari sowie Internet Explorer (ab v7)
    if (!xmlRequest && typeof(XMLHttpRequest)!='undefined') {
        xmlRequest = new XMLHttpRequest();
    }
  
    if (!xmlRequest) {
        // Internet Explorer 6 und älter
        try {
            xmlRequest = new ActiveXObject("Msxml2.XMLHTTP");
        } catch(e) {
            try {
                xmlRequest = new ActiveXObject("Microsoft.XMLHTTP");
            } catch(e) {
                xmlRequest = false;
            }
        }        
    }
  
  if (xmlRequest) {
    pRefObj.xmlReq = xmlRequest;
    pRefObj.xmlReq.open(this.Options.method, this.Url, this.Options.async);
    pRefObj.xmlReq.onreadystatechange = this.onStateChange;
    if(this.Options.method.toUpperCase()=='GET'){
      pRefObj.xmlReq.send(null);
    } else {
      pRefObj.xmlReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
      pRefObj.xmlReq.send(this.Options.params);
    }
    try {
      if(navigator.userAgent.indexOf('Gecko') != -1 && !this.Options.async &&
          pRefObj.xmlReq.onreadystatechange == null) {
        this.onStateChange();
      }
    } catch(e) {}
  }
  
    return xmlRequest;  
}