var con = init_ajax();

function init_ajax() 
{
    try { return new XMLHttpRequest(); } catch(e) {}
    try { return new ActiveXObject("Microsoft.XMLHTTP"); } catch (e) {}
    try { return new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) {}    
    alert("Upgrade your browser to use this application.");
    return null;
}

function ping(agent, method, data)
{
    msg = "method="+method+"&"+data;
    con.open("POST","agents/"+agent+".php",false);
    con.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
    if (data==null)
	    con.setRequestHeader("Content-length", 0);
    else
        con.setRequestHeader("Content-length", msg.length);
    con.setRequestHeader("Connection", "close");
    con.send(msg);
	return con.responseText;
}

function find_nulls(data)
{
    for (field in data)
    {
        if (data[field] == "")
        {
            //alert('Incomplete field '+field);
            return true;
        }
    }
    return false;
}

function encode_data(data)
{
    var data_string = "";
    for (field in data)
    {
        data_string += field+"="+data[field]+"&";
    }
    return data_string;
}
