
// async ajax request
function ajaxReqA (sReturnDiv, sProgram, sArg1, sArg2) {

	var sProgram = (sProgram == null) ? "echo" : sProgram;
	var sArg1 = (sArg1 == null) ? "x" : sArg1;
	var sArg2 = (sArg2 == null) ? "x" : sArg2;

	var sReq = 
         "ajaxrequest.php?program=" + sProgram +
                                "&a=" + sArg1 +
                                "&b=" + sArg2;


	var oXHR = zXmlHttp.createRequest();
        var statusText = "";

	oXHR.open("get", sReq, true);

	oXHR.onreadystatechange = function () {

		if (oXHR.readyState == 4) {

		  if (oXHR.status == 200 || oXHR.status == 304) {

			ajaxRespA (oXHR.responseText, false, sReturnDiv);

		  } else {

			try {
					
				$statusText = oXHR.statusText;
			}
			catch (e) {

				$statusText = "Trouble accessing status text";
			}	

			ajaxRespA ($statusText, true, sReturnDiv);
		  }
		}            
	};

	oXHR.send(null);
} // end ajaxReqA
       
// async ajax response 
function ajaxRespA (sText, sError, sReturnDiv) { 

	if (sError) {

		alert ('HTTP Response Error: ' + sText);

	// } else if (sText.substring(0,4) != 'DONE') {

		// alert ('Invalid response code - ' + sText);

	} else {

		if (sText.substring(4) != '') {

			if (sReturnDiv == null) {

				// alert (sText.substring(4));
			
			} else {

				var respDiv = document.getElementById(sReturnDiv);
				respDiv.innerHTML = sText.substring(4);

/* @todo trying to round the popup window, doesn't currently work

				if (sReturnDiv == 'ajaxpopupcontent') {

					Nifty("div#ajaxpopupcontent","all");
					alert ('Nifty!');
				}
*/
		
				if (sReturnDiv == 'ajaxmessage') {
					respDiv.style.display = "block";
				}
			}
		}
	} 
} // end ajaxRespA


// sync ajax request
function ajaxReqS (sReturnDiv, sProgram, sArg1, sArg2) {

        var sProgram = (sProgram == null) ? "echo" : sProgram;
        var sArg1 = (sArg1 == null) ? "x" : sArg1;
        var sArg2 = (sArg2 == null) ? "x" : sArg2;

        var sReq =
         "ajaxrequest.php?program=" + sProgram +
                                "&a=" + sArg1 +
                                "&b=" + sArg2;


        var oXHR = zXmlHttp.createRequest();

        oXHR.open("get", sReq, false); // false means do a sync request

        oXHR.onreadystatechange = function () {

                if (oXHR.readyState == 4) {

                  if (oXHR.status == 200 || oXHR.status == 304) {

                        ajaxRespS (oXHR.responseText, false, sReturnDiv);

                  } else {


                        try {

                                $statusText = oXHR.statusText;
                        }
                        catch (e) {

                                $statusText = "Trouble accessing status text";
                        }

                        ajaxRespS ($statusText, true, sReturnDiv);
                  }

                }
        };

        oXHR.send(null);
} // end ajaxReqS

// sync ajax response
function ajaxRespS (sText, sError, sReturnDiv) {   

// teb jan 18, 2009 sync requests don't seem to display alerts...


        if (sError) {

                alert ('HTTP Response Error: ' + sText);

//        } else if (sText.substring(0,4) != 'DONE') {

  //              alert ('Invalid response code - ' + sText);

        } else {

                if (sText.substring(4) != '') {

                        if (sReturnDiv == null) {

                                // alert (sText.substring(4));

                        } else {

                                var respDiv = document.getElementById(sReturnDiv);
                                respDiv.innerHTML = sText.substring(4);

                                if (sReturnDiv == 'ajaxmessage') {
                                        respDiv.style.display = "block";
                                }
                        }
                }
        }
} // end ajaxRespS
