if (typeof AWAW == "undefined") {
    var AWAW = {};
}


if (typeof $ == "undefined") {
    function $(elmId) {
        return document.getElementById(elmId);
    }
}


/**
 * replace element.innerHTML via AJAX
 * @method ajaxRequest
 * @static
 * @param   p.elmId     element ID whose innerHTML will be replaced, could be null
 * @param   p.uri       Fully qualified path of resource, could be null if p.formId available
 * @param   p.method    HTTP transaction method, default 'GET' or formId's method
 * @param   p.formId    form element ID to request, default null
 * @param   p.postData  POST body, default null
 * @param   p.callback  a function which AJAX success will callback, defualt null
 */
AWAW.ajaxRequest = function (p) {
    var handleSuccess = function(o) {
        if (o.getResponseHeader['Content-Type'].match(/javascript/i)) {
            eval(o.responseText);
        } else if (p.elmId) {
            $(p.elmId).innerHTML = o.responseText;
            var a = o.responseText.split(/\s*<\/script>/i);
            for (var b in a) {
                var c = a[b].split(/<script[^>]*>\s*/i);
                if (c.length > 1) eval(c[1]);
            }
        }
        if (p.callback) p.callback();
    };
    var callback = { success: handleSuccess };
    var httpUri = p.uri;
    var httpMethod = p.method;
    if (p.formId) {
        YAHOO.util.Connect.setForm(p.formId);
        if (!httpUri) httpUri = $(p.formId).action;
        if (!httpMethod) httpMethod = $(p.formId).method;
    }
    if (!httpMethod) httpMethod = 'GET';
    YAHOO.util.Connect.asyncRequest(httpMethod, httpUri, callback, p.postData);
};


