var loading_html='<img src="images/loading.gif">';
function setInnerText(divID, text)
{
if (divID)
{
var el = (document.getElementById) ? document.getElementById(divID) : document.all[divID];
if(el) { el.innerHTML = text; }else alert('[AJAX] div "'+divID+'" not found');
}
}
// create Object
function GetHttpRequest()
{
if (window.XMLHttpRequest)
return new XMLHttpRequest();// Mozilla, Safari, Opera, IE>=7
else if (window.ActiveXObject)
{
try
{
return new ActiveXObject('Msxml2.XMLHTTP'); // IE 5
} catch (e)
{
try
{
return new ActiveXObject('Microsoft.XMLHTTP'); // IE 6
} catch (e) {}
}
}else
{
alert("Your browser does not support AJAX.");
}
return null;
}
function request_get(xmlHttp,serverscript,params)
{
if(xmlHttp)
{
xmlHttp.open("GET", serverscript+'?'+params, true);
xmlHttp.send(null);
}else alert('HttpRequest wurde nicht erstellt!');
}
function request_post(xmlHttp,serverscript,params)
{
if(xmlHttp)
{
xmlHttp.open("POST", serverscript, true);
//Send the proper header information along with the request
xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
xmlHttp.setRequestHeader("Content-length", params.length);
xmlHttp.setRequestHeader("Connection", "close");
xmlHttp.send(params);
}else alert('HttpRequest wurde nicht erstellt!');
}
function ajax_request(divID, url, params,callback)
{
var xmlHttp = GetHttpRequest();
if (xmlHttp)
{
if(callback == undefined) //if callback defined no loading-image
setInnerText(divID,loading_html);
xmlHttp.onreadystatechange = function()
{
if(xmlHttp.readyState == 4)
{
if(callback != undefined && typeof callback == 'function')
callback(divID, xmlHttp.responseText);
else
setInnerText(divID, xmlHttp.responseText);
}
}
request_post(xmlHttp,url,params);
}
return false;
}