/**
 * phajax.js
 * PHP and Ajax library
 * (c) 2006 creative-mindworks.de
 * @author Christian Klaproth, klaproth@creative-mindworks.de
 */
 
var phajaxRequest = false;
var phajaxResponseTargetId = "";
var phajaxInProgressFlag = false;
  
/**
 * Sends a phajax request to the server. Alerts the user, if the request object
 * cannot be correctly created.
 * @param url_string the request url including possible GET parameters
 * @target_id id of the target element to be updated with the contents of the response
 */
function SendPhajaxRequest(url_string, target_id, progress_flag) {
    if (phajaxRequest) {
        phajaxRequest.abort();
    }
    phajaxRequest = false;
    phajaxResponseTargetId = target_id;
    phajaxInProgressFlag = progress_flag;
    try {
        phajaxRequest = new XMLHttpRequest();
    } catch (ex) {
        try {
            phajaxRequest = new ActiveXObject("Msxml12.XMLHTTP");
        } catch (ex) {
            try {
                phajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
            } catch (ex) {}
        }
    }
    if (!phajaxRequest) {
        alert("Technischer Fehler: Es konnte kein phajax-Request gesendet werden.");
        return false;
    }
    phajaxRequest.onreadystatechange = ReceivePhajaxResponse;
    phajaxRequest.open('GET', url_string, true);
    phajaxRequest.send(null);
}
      
function ReceivePhajaxResponse() {
    if (phajaxRequest) {
        if (phajaxRequest.readyState == 4) {
            if (phajaxRequest.status == 200) {
                var phajaxContent = phajaxRequest.responseText;
                document.getElementById(phajaxResponseTargetId).innerHTML = phajaxContent;
            } else {
                alert("Technischer Fehler: Die phajax-Anfrage konnte vom Server nicht beantwortet werden.\n" + 
                    phajaxRequest.status + ": " + phajaxRequest.responseText);
            }
        } else {
            if (phajaxInProgressFlag) {
                document.getElementById(phajaxResponseTargetId).innerHTML = "Bitte warten...";
            }
        }
    }
}


