var outputDiv = "";
var xmlhttp;

function ajaxPost(targetUrl, data, outputDivArg)
{
    outputDiv = outputDivArg;
    
    try
    {
     // Moz supports XMLHttpRequest. IE uses ActiveX.
     // browser detction is bad. object detection works for any browser
     xmlhttp = window.XMLHttpRequest ? new XMLHttpRequest() : new ActiveXObject("Microsoft.XMLHTTP");
    }
    catch (e)
    {
      // browser doesn't support ajax. handle however you want
      window.alert("Please get an updated browser that supports AJAX. All modern browsers support AJAX.");
    }
    
    // the xmlhttp object triggers an event everytime the status changes
    // triggeredMethod() handles the events
    xmlhttp.onreadystatechange = triggeredMethod;
    
    // open takes in the HTTP method and url.
    xmlhttp.open("POST", targetUrl, true);
    
    //Send the proper header information along with the request
    xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
    xmlhttp.setRequestHeader("Content-length", data.length);
    xmlhttp.setRequestHeader("Connection", "close");
    
    // send the request. if this is a POST request we would have
    // sent post variables: send("name=aleem&gender=male)
    // Moz is fine with just send(); but
    // IE expects a value here, hence we do send(null);
    xmlhttp.send(data);
    
}

function triggeredMethod()
{
    
    // if the readyState code is 4 (Completed)
    // and http status is 200 (OK) we go ahead and get the responseText
    // other readyState codes:
    // 0=Uninitialised 1=Loading 2=Loaded 3=Interactive
    if ((xmlhttp.readyState == 4) && (xmlhttp.status == 200))
    {
	//ajaxResponse = xmlhttp.responseText;
	document.getElementById(outputDiv).innerHTML = xmlhttp.responseText;
    }
}

