var waiting = false;
var funcQueue = new Array();
var funcLoop = false;
var xmlHttp=null;
function ajaxQCall(url, myForm, FuncToCall)
{
    var inputs = "";
    var elem = myForm.elements;
    for(var i = 0; i < elem.length; i++)
    {
        inputs += "&"+elem[i].id+"=";
        value = iValue(elem[i]);
        if(typeof value == 'string')
            inputs += escape(value)
        else if(typeof value == 'boolean')
            inputs += (value? "true":"false")
        else
            inputs+= value;
    }
    alert(inputs);
    ajaxCall(url, inputs, FuncToCall);
}
function ajaxCall(url, inputs, FuncToCall)
{
    functionToRun = function()
    {
        runAjax(url, inputs, function(){
            FuncToCall();
            waiting=false;
        })
    };
    funcQueue.push(functionToRun);
    if(!funcLoop)
    {
        funcLoop = true;
        callNextFunc();
    }
}
function callNextFunc()
{
    if (!waiting)
    {
        if(funcQueue.length > 0)
        {
            waiting = true;
            func = funcQueue.shift();
            func();
            window.setTimeout("callNextFunc()", 5);
        }
        else
        {
            funcLoop = false;
            waiting = false;
        }
    }
    else
    {
        window.setTimeout("callNextFunc()", 5);
    }
    return;
}
function runAjax(url, inputs, FuncToCall)
{
    // Firefox, Opera 8.0+, Safari
    try
    {
        xmlHttp=new XMLHttpRequest();
    }
    catch (e)
    {
        // Internet Explorer
        try
        {
            xmlHttp=new ActiveXObject('Msxml2.XMLHTTP');
        }
        catch (e)
        {
            xmlHttp=new ActiveXObject('Microsoft.XMLHTTP');
        }
    }
    if (xmlHttp==null)
    {
        alert ('Ajax Error!');
        return;
    }

    xmlHttp.open('POST', url, true);
    xmlHttp.setRequestHeader('If-Modified-Since', 'Sat, 1 Jan 2000 00:00:00 GMT');
    //xmlHttp.setRequestHeader('Content-Type','multipart/form-data; charset=UTF-8');
    xmlHttp.setRequestHeader('Content-Type','application/x-www-form-urlencoded; charset=UTF-8');
    xmlHttp.setRequestHeader('Content-length', inputs.length);
    xmlHttp.setRequestHeader('Connection', 'close');
    xmlHttp.onreadystatechange=function () { runFunction(FuncToCall) };
    if(inputs == "")
        inputs = null;
    xmlHttp.send(inputs);
}
function runFunction(objFn)
{
    if (xmlHttp.readyState==4 && xmlHttp.status == 200)
    {
        objFn();
        ajaxReplyJs();
    }
}
function ajaxReplyJs()
{
    if (document.getElementById('replyJs'))
    { eval(document.getElementById('replyJs').innerHTML); }
}
function isEmpty(field, text)
{
    if (field.value == "")
        field.value = text;
}
function editMe(field, text)
{
    if (field.value == text)
        field.value = "";
}
function fieldValue(field, text)
{
    if (field.value == text)
        return "";
    else
        return field.value;
}

        

