ajaxBusy=0;
ajaxObj = [0];

function ajaxObjRequest(type)
{
var index = ajaxObj.length;
for (var i=0; i<ajaxObj.length; i++)
{
if (!ajaxObj[i])
{
index = i;
break;
}
}
if (window.ActiveXObject) {
try
{
ajaxObj[index] = new ActiveXObject("Msxml2.XMLHTTP");
}
catch (e)
{
try
{
ajaxObj[index] = new ActiveXObject("Microsoft.XMLHTTP");
}
catch (e){}
}
}
else if (window.XMLHttpRequest)
{
ajaxObj[index] = new XMLHttpRequest();
if (ajaxObj[index].overrideMimeType)
{
ajaxObj[index].overrideMimeType('text/' + type);
}
}
else {alert("err!");}
return (index);
}

function localRequest(url, cback, reqType)
{
var temp;
if (!reqType){reqType = 'html';}
if (!cback){cback = function(){};}
reqType=reqType.toLowerCase();
var index = ajaxObjRequest(reqType);
debug.print("ajaxrequest " + index + " - " + url);
ajaxBusy++;
document.getElementById("busy").style.display="block";
ajaxObj[index].open('GET', url, true);
ajaxObj[index].onreadystatechange = function() {
if (ajaxObj[index].readyState == 4 && ajaxObj[index].status == 200) {
if (reqType=="xml"){checkBusy();cback(ajaxObj[index].responseXML);}else{checkBusy();cback(ajaxObj[index].responseText);}
ajaxObj[index] = null;
}
};
ajaxObj[index].send(null);
}

function checkBusy()
{
ajaxBusy--;
debug.print(ajaxBusy);
if (ajaxBusy==0){document.getElementById("busy").style.display="none";}
}

function ajaxRequest(url, cback, reqType)
{
url="php/ajaxrequest.php?url="+url+"&type="+reqType+"&sid=" + new Date().getTime();
localRequest(url,cback,reqType);
}

function userdataLoad(cback, username, sid, dataname)
{
url="php/userdataLoad.php?dataname="+dataname+"&username="+username+"&sid=" + sid;
localRequest(url,cback,"xml");
}

function updateShortcut(cback, username, sid, id, x, y)
{
url="php/updateshortcut.php?username="+username+"&sid=" + sid + "&id="+id + "&x="+x + "&y="+y;
localRequest(url,cback,"xml");
}

function updatePrefs(cback, username, sid, id, x, y)
{
url="php/updateshortcut.php?username="+username+"&sid=" + sid + "&id="+id + "&x="+x + "&y="+y;
localRequest(url,cback,"xml");
}

function functionCall(functionName, parameters, cback)
{
url="php/"+functionName+".php?username="+username+"&sid=" + new Date().getTime();

if (parameters){
for(var i in parameters){
url+="&"+i+"="+parameters[i];
}
}
alert(url);

if (!cback){cback=function(){};}

localRequest(url,cback,"html");
}
