/*
 * (c) K.Munteanu
 * ajaxmaster@munteanu.de 
*/  

function getXmlHttp() {
  var xmlHttp;
  try {
    // Firefox, Opera 8.0+, Safari, IE7+
    xmlHttp=new XMLHttpRequest();
  } catch (e) {
    // Internet Explorer
    try {
      // IE6
      xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
    } catch (e) {
      try {
        // IE <= 5.5
        xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
      } catch (e) {
        alert("Your browser does not support AJAX!");
        return false;
      }
    }
  }
  return xmlHttp;
}

/*function ajaxGet(xmlHttp,url,funct) {
  if (!xmlHttp) return;
  xmlHttp.onreadystatechange=function() {
    if(xmlHttp.readyState==4) {
      eval(funct);
    }
  }
  xmlHttp.open("GET",url,true);
  xmlHttp.send(null);
}*/

function ajaxPost(url,funct,params) {
  var xmlHttp = getXmlHttp();
  if (!xmlHttp) return;
  xmlHttp.onreadystatechange=function() {
    if(xmlHttp.readyState==4) {
      eval(funct);
    }
  }
  xmlHttp.open("POST",url,true);
  xmlHttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
  xmlHttp.send(params);
}

function ajaxGet(url,funct) {
  var req = getXmlHttp();
  if (!req) return;
  req.onreadystatechange=function() {
    if(req.readyState==4) {
      funct(req);
    }
  }
  req.open("GET",url,true);
  req.send(null);
}

function ajPost(xmlHttp,url,funct,params) {
  if (!xmlHttp) return;
  xmlHttp.onreadystatechange = funct;
  xmlHttp.open("POST",url,true);
  xmlHttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
  xmlHttp.send(params);
}

function ajaxPostReplace(url,params,id) {
  var req = getXmlHttp();
  var obj = document.getElementById(id);
  obj.style.width = obj.offsetWidth+'px';
  obj.style.height = obj.offsetHeight+'px';
  obj.innerHTML = '';
  req.onreadystatechange = function() {
    if (req.readyState==4) {
      obj.innerHTML = req.responseText;
      obj.style.width = ''; 
      obj.style.height = '';  
    }
  };
  req.open("POST",url,true);
  req.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
  req.setRequestHeader("X-Requested-With", "XMLHttpRequest");
  req.send(params);
}

function ajaxGetReplace(url,id) {
  var req = getXmlHttp();
  var obj = document.getElementById(id);
  obj.style.width = obj.offsetWidth+'px';
  obj.style.height = obj.offsetHeight+'px';
  obj.innerHTML = '<p style="text-align:center;">Bitte warten...</p>';
  req.onreadystatechange = function() {
    if (req.readyState==4) {
      obj.innerHTML = req.responseText;
      obj.style.width = ''; 
      obj.style.height = '';  
    }
  };
  req.open("GET",url,true);
  req.setRequestHeader("X-Requested-With", "XMLHttpRequest");
  req.send(null);
}
