function IsBrowserIE()
{
	var sAgent = navigator.userAgent.toLowerCase() ;

	// Internet Explorer
	if ( sAgent.indexOf("msie") != -1 && sAgent.indexOf("mac") == -1 && sAgent.indexOf("opera") == -1 )
	{
		return true ;
	}

	return false ;
}

function XmlHttp() {
    var req;

    try {
        if (window.XMLHttpRequest) {
            req = new XMLHttpRequest();

            if (req.readyState == null) {
                req.readyState = 1;

                req.addEventListener("load", function () {
                    req.readyState = 4;

                    if (typeof req.onreadystatechange == "function")
                        req.onreadystatechange();
                }, false);
            }

            return req;
        }

        if (window.ActiveXObject) {
            var prefixes = ["MSXML5", "MSXML4", "MSXML3", "MSXML2", "MSXML", "Microsoft"];

            for (var i = 0; i < prefixes.length; i++) {
                try {
                    req = new ActiveXObject(prefixes[i] + ".XmlHttp");
                    return req;
                } catch (ex) {}
            }
        }
    } catch (ex) {}

    throw new Error("XmlHttp Objects not supported by client browser");
}


XmlHttp.prototype = new Object;


XmlHttp.create = function () {
    return new XmlHttp();
}









function XmlDocument() {
    var req;

    try {
        if (window.ActiveXObject) {
            var libraries = ["MSXML2.DOMDocument.5.0", "MSXML2.DOMDocument.4.0", "MSXML2.DOMDocument.3.0", "MSXML2.DOMDocument", "Microsoft.XmlDom"];

            for (var i = 0; i < libraries.length; i++) {
                try {
                    req = new ActiveXObject(libraries[i]);
                    return req;
                } catch (ex) {}
            }
        } else if (document.implementation && document.implementation.createDocument) {
            req = document.implementation.createDocument("", "", null);
            req.addEventListener("load", function () { this.readyState = 4; }, false);
            req.readyState = 4;

            return req;
        }
    } catch (ex) { }

    throw new Error("XmlDocument Objects not supported by client browser");
}


XmlDocument.prototype = new Object;


XmlDocument.create = function () { return new XmlDocument(); }


if (window.XMLHttpRequest) {
    (function () {
        var _xmlDocumentPrototype = XmlDocument.prototype;

        _xmlDocumentPrototype.__proto__ = { __proto__ : _xmlDocumentPrototype.__proto__ };

        var _p = _xmlDocumentPrototype.__proto__;


        _p.createNode = function (aType, aName, aNamespace) {
            switch (aType) {
                case 1:
                    if (aNamespace && aNamespace != "")
                        return this.createElementNS(aNamespace, aName);
                    else
                        return this.createElement(aName);

                case 2:
                    if (aNamespace && aNamespace != "")
                        return this.createAttributeNS(aNamespace, aName);
                    else
                        return this.createAttribute(aName);

                case 3:
                default:
                    return this.createTextNode("");
            }
        };


        _p.loadXML = function (sXml) {
            var d = (new DOMParser()).parseFromString(sXml, "text/xml");

            while (this.hasChildNodes())
                this.removeChild(this.lastChild);

            for (var i = 0; d < d.childNodes.length; i++)
                this.appendChild(this.importNode(d.childNodes[i], true));
        };


        _p.__load__ = _xmlDocumentPrototype.load;


        _p.load = function (sURI) {
            this.readyState = 0;
            this.__load__(sURI);
        };


        _p.setProperty = function (sName,sValue) {
            if (sName == "SelectionNamespaces") {
                this.__selectionNamespaces__ = {};
                var parts = sValue.split(/\s+/);
                var re = /^xmlns\:([^=]+)\=((\"([^\"]*)\")|(\'([^\']*)\'))$/;

                for (var i = 0; i < parts.length; i++) {
                    re.test(parts[i]);
                    this.__selectionNamespaces__[RegExp.$1] = RegExp.$4 || RegExp.$6;
                }
            }
        };

        if (!IsBrowserIE())
        {

	        _p.__defineSetter__("onreadystatechange", function (f) {
	            if(this.__onreadystatechange__)
	                this.removeEventListener("load", this.__onreadystatechange__, false);

	            this.__onreadystatechange__ = f;

	            if (f) this.addEventListener("load", f, false);

	            return f;
	        });


	        _p.__defineGetter__("onreadystatechange", function () {
	            return this.__onreadystatechange__;
	        });
        }

        XmlDocument.__mozHasParseError__ = function (oDoc) {
            return !oDoc.documentElement ||
                    oDoc.documentElement.localName == "parsererror" &&
                    oDoc.documentElement.getAttribute("xmlns") == "http://www.mozilla.org/newlayout/xml/parsererror.xml";
        };

        if (!IsBrowserIE())
        {

	        _p.__defineGetter__("parseError", function() {
	            var hasError = XmlDocument.__mozHasParseError__(this);
	            var res = { errorCode: 0, filepos: 0, line: 0, linepos: 0, reason: "", srcText: "", url:"" };

	            if (hasError) {
	                res.errorCode= -1;

	                try {
	                    res.srcText = this.getElementsByTagName("sourcetext")[0].firstChild.data;
	                    res.srcText = res.srcText.replace(/\n\-\^$/,"");
	                } catch (ex) { res.srcText = ""; }

	                try {
	                    var s = this.documentElement.firstChild.data;
	                    var re = /XML Parsing Error\:(.+)\nLocation\:(.+)\nLine Number(\d+)\,Column(\d+)/;
	                    var a = re.exec(s);
	                    res.reason = a[1];
	                    res.url = a[2];
	                    res.line = a[3];
	                    res.linepos = a[4];
	                } catch (ex) { res.reason = "Unknown"; }
	            }

	            return res;
	        });


	        var _nodePrototype = Node.prototype;


	        _nodePrototype.__proto__ = { __proto__ : _nodePrototype.__proto__ };


	        _p = _nodePrototype.__proto__;


	        _p.__defineGetter__("xml", function() {
	            return (new XMLSerializer()).serializeToString(this, "text/xml");
	        });


	        _p.__defineGetter__("baseName", function() {
	            var lParts = this.nodeName.split(":");

	            return lParts[lParts.length - 1];
	        });


	        _p.__defineGetter__("text", function() {
	            var sb = new Array(this.childNodes.length);

	            for (var i = 0; i < this.childNodes.length; i++)
	                sb[i] = this.childNodes[i].text;

	            return sb.join("");
	        });
        }


        _p.selectNodes = function (sExpr) {
            var d = (this.nodeType == 9) ? this : this.ownerDocument;
            var nsRes = d.createNSResolver((this.nodeType == 9) ? this.documentElement : this);
            var nsRes2;

            if (d.__selectionNamespaces__) {
                nsRes2 = function (s) {
                    if (s in d.__selectionNamespaces__)
                        return d.__selectionNamespaces__[s];

                    return nsRes.lookupNamespaceURI(s);
                };
            } else nsRes2 = nsRes;

            var xpRes = d.evaluate(sExpr, this, nsRes2, 5, null);
            var res = [];
            var item;

            while ((item = xpRes.iterateNext()))
                res.push(item);

            return res;
        };


        _p.selectSingleNode = function (sExpr) {
            var d = (this.nodeType == 9) ? this : this.ownerDocument;
            var nsRes = d.createNSResolver((this.nodeType == 9) ? this.documentElement : this);
            var nsRes2;

            if(d.__selectionNamespaces__) {
                nsRes2 = function (s) {
                    if (s in d.__selectionNamespaces__)
                        return d.__selectionNamespaces__[s];

                    return nsRes.lookupNamespaceURI(s);
                };
            } else nsRes2 = nsRes;

            var xpRes = d.evaluate(sExpr, this, nsRes2, 9, null);

            return xpRes.singleNodeValue;
        };


        _p.transformNode = function (oXsltNode) {
            var d = (this.nodeType == 9) ? this : this.ownerDocument;
            var processor = new XSLTProcessor();

            processor.importStylesheet(oXsltNode);

            var df = processor.transformToFragment(this, d);

            return df.xml;
        };


        _p.transformNodeToObject = function (oXsltNode, oOutputDocument) {
            var d = (this.nodeType == 9) ? this : this.ownerDocument;
            var outDoc = (oOutputDocument.nodeType == 9) ? oOutputDocument : oOutputDocument.ownerDocument;
            var processor = new XSLTProcessor();

            processor.importStylesheet(oXsltNode);

            var df = processor.transformToFragment(this, d);

            while (oOutputDocument.hasChildNodes())
                oOutputDocument.removeChild(oOutputDocument.lastChild);

            for (var i = 0; i < df.childNodes.length; i++)
                oOutputDocument.appendChild(outDoc.importNode(df.childNodes[i],true));
        };


        if (!IsBrowserIE())
        {
	        var _attrPrototype = Attr.prototype;


	        _attrPrototype.__proto__ = { __proto__ : _attrPrototype.__proto__ };


	        _p = _attrPrototype.__proto__;


	        _p.__defineGetter__("xml", function() {
	            var nv = (new XMLSerializer()).serializeToString(this);

	            return this.nodeName + "=\"" + nv.replace(/\"/g,"&quot;") + "\"";
	        });


	        var _textPrototype = Text.prototype;


	        _textPrototype.__proto__ = { __proto__ : _textPrototype.__proto__ };


	        _p = _textPrototype.__proto__;


	        _p.__defineGetter__("text", function() {
	            return this.nodeValue;
	        });
        }
    })();
}

pAjaxParser.getJsType = function (v) {
    switch (typeof v) {
        case "object":
            if (v == null || v == undefined)
                throw new Error("Could not set null value as RPC param");
            else if (v.constructor == Date)
                return "dateTime";
            else if (v.constructor == Array)
                return "array";
            else return "struct";

        case "string":
            if (v.substr(0, 1) != "0" && parseFloat(v) == v)
                return "number";
            else if (v.length > 100 || (v.indexOf("<") >= 0 || v.indexOf(">") >= 0))
                return "text";

            return "string";

        default:
            return typeof v;
    }
}


pAjaxParser.jsDateToIso8601 = function (d) {
    function preZero(n) { return (n > 9) ? String(n) : "0" + n; };

    return d.getFullYear() + preZero(d.getMonth() + 1) + preZero(d.getDate()) + "T" + preZero(d.getHours()) + ":" + preZero(d.getMinutes()) + ":" + preZero(d.getSeconds());
}


pAjaxParser.iso8601ToJsDate = function (s) {
    var d = new Date;

    d.setFullYear(s.substring(0, 4), s.substring(4, 6) - 1, s.substring(6, 8));
    d.setHours(s.substring(9, 11), s.substring(12, 14), s.substring(15, 17), 0);

    return d;
}


pAjaxParser.jsToXmlNode = function (v, xmlDoc) {
    switch (pAjaxParser.getJsType(v)) {
        case "number":
        case "string":
            return xmlDoc.createTextNode(v);

        case "text":
            return xmlDoc.createCDATASection(v);

        case "boolean":
            return xmlDoc.createTextNode(v ? "true" : "false");

        case "dateTime":
            return xmlDoc.createTextNode(pAjaxParser.jsDateToIso8601(v));

        case "array":
            var el = xmlDoc.createElement("data");

            for (var i = 0; i < v.length; i++)
                el.appendChild(pAjaxParser.jsToXmlValueNode("pAjaxItem-" + i, v[i], xmlDoc));

            return el;

        case "struct":
            var el = xmlDoc.createElement("data");

            for (var p in v) {
            	if (typeof v[p] != "function")
				    el.appendChild(pAjaxParser.jsToXmlValueNode(p, v[p], xmlDoc));
            }

            return el;
    }

    throw new Error("Unknown JavaScript Type");
}


pAjaxParser.jsToXmlValueNode = function (n, v, xmlDoc) {
    n = n.replace("[", "__91__");
    n = n.replace("]", "__93__");

	var el = xmlDoc.createElement(n);
    var o = pAjaxParser.jsToXmlNode(v, xmlDoc);

	el.setAttribute("type", pAjaxParser.getJsType(v));

    if (o.nodeName == "data" && !o.getAttribute("type")) {
       	while (o.hasChildNodes())
			el.appendChild(o.firstChild);
	} else el.appendChild(o);

    return el;
}


pAjaxParser.jsToUrlString = function (n, v) {
    var str = "";

    switch (pAjaxParser.getJsType(v)) {
        case "string":
        case "text":
            str += "&" + n + "=" + pAjaxParser.encodeURI(v);
            break;

        case "number":
            str += "&" + n + "=" + v;
            break;

        case "boolean":
            str += "&" + n + "=" + (v ? "true" : "false");
            break;

        case "dateTime":
            str += "&" + n + "=" + pAjaxParser.encodeURI(pAjaxParser.jsDateToIso8601(v));
            break;

        case "array":
            for (var i = 0; i < v.length; i++)
                str += pAjaxParser.jsToUrlString(n + "[" + i + "]", v[i]);
            break;

        case "struct":
            for (var p in v)
                str += pAjaxParser.jsToUrlString(n + "[" + p + "]", v[p]);
            break;
    }

    return str;
}


// Correctly handle URI encoding, preventing bug of browsers to convert special chars (ie: � as ü)
pAjaxParser.encodeURI = function (str) {
    var newStr = ""; var dec;
    var itens = "0123456789ABCDEF";

    for (var i = 0; i < str.length; i++) {
        dec = (str.charAt(i)).charCodeAt(0);

        // 0-9 (48-57), A-Z (65-90), a-z (97-122)
        if (!(dec >= 48 && dec <= 57) && !(dec >= 65 && dec <= 90) && !(dec >= 97 && dec <= 122))
            newStr += "%" + String(itens.charAt((dec - (dec % 16)) / 16) + itens.charAt(dec % 16));
        else newStr += str.charAt(i);
    }

    return newStr;
}


// Handle URI decoding
pAjaxParser.decodeURI = function (str) {
    var newStr = ""; var hex;
    var itens = "0123456789ABCDEF";

    for (var i = 0; i < str.length; i++) {
        if (str.charAt(i) == "%") {
            hex = String(str.charAt(i + 1) + str.charAt(i + 2));
            newStr += String.fromCharCode(parseInt(hex, 16));
            i = i + 2;
        } else {
            newStr += str.charAt(i);

            if (str.charAt(i) == "%" && str.charAt(i + 1) == "%") i++;
        }
    }

    return newStr;
}


pAjaxParser.parseXmlResponse = function (xml) {
    if (xml.parseError && xml.parseError.reason != "") {
        var error = xml.parseError;

        alert("Detailed Description of XML Parse Error:\n\nError Code: " + error.errorCode +
          "\nFile Pos: " + error.filePos + "\nLine: " + error.line +
          "\nLine Pos: " + error.linePos + "\nURL: " + error.url +
          "\nSRC Text: " + error.srcText + "\nReason: " + error.reason);

        throw new Error("XML Parse Error\n\nReason: " + xml.parseError.reason);
    } else if (xml && xml.documentElement != null) {
        var root = xml.documentElement;

        if (root.tagName == "pAjaxError") {
            var e = new Error(pAjaxParser.__getFirstChildElement__(root).text);
            pAjaxParser.__setError__(e);
        }

        return pAjaxParser.xmlRootNodeToJs(root);
    }

    throw new Error("Invalid XML document returned from RPC server");
}


pAjaxParser.xmlNodeToJs = function (oNode) {
    if (oNode.nodeType == 3)
        return oNode.data;

    switch (oNode.getAttribute("type")) {
        case "string":
            return oNode.text;

        case "text":
            return oNode.firstChild.text;

        case "dateTime":
            return pAjaxParser.iso8601ToJsDate(oNode.text);

        case "boolean":
            return (oNode.text == "true") ? 1 : 0;

        case "number":
            return Number(oNode.text);

        case "array":
            var nodeList = oNode.childNodes;
            var res = [];

            for (var i = 0; i < nodeList.length; i++) {
                if (nodeList[i].nodeType == 1)
                    res.push(pAjaxParser.xmlNodeToJs(nodeList[i]));
            }

            return res;

        case "struct":
            var members = oNode.childNodes;
            var o = {};
            var name, value;
            var re = /pAjaxItem-([0-9]*)/i;

            for (var i = 0; i < members.length; i++) {
                if (members[i].nodeType == 1) {
                    name = (!(re.test(members[i].tagName))) ? members[i].tagName : (String(members[i].tagName)).replace(re, "$1");
                    value = pAjaxParser.xmlNodeToJs(members[i]);

                    o[name] = value;
                }
            }

            return o;

        default:
            return undefined;
    }
}


pAjaxParser.xmlValueNodeToJs = function (n) {
    var c = pAjaxParser.__getFirstChildElement__(n) || n.firstChild;

    if (c) return pAjaxParser.xmlNodeToJs(c);

    return "";
}


pAjaxParser.xmlRootNodeToJs = function (oNode) {
    var o = {};
    var name, value;
    for (var i = 0; i < oNode.childNodes.length; i++) {
        name = oNode.childNodes[i].tagName;
        value = pAjaxParser.xmlNodeToJs(oNode.childNodes[i]);

        o[name] = value;
    }

    return o.result;
}


pAjaxParser.__getFirstChildElement__ = function (p) {
    var c = p.firstChild;

    while (c) {
        if (c.nodeType == 1) return c;
        c = c.nextSibling;
    }

    return null;
}


pAjaxParser.__getLastChildElement__ = function (p) {
    var c = p.lastChild;

    while (c) {
        if (c.nodeType == 1) return c;
        c = c.previousSibling;
    }

    return null;
}


function pAjaxParser() {}

pAjax.__debugMode__ = false;

pAjax.debug = function (msg) {
    if (pAjax.__debugMode__) alert("pAjax Debug Console:\n\n" + msg);
}

pAjax.getDebugMode = function () { return pAjax.__debugMode__; }
pAjax.setDebugMode = function (bValue) { pAjax.__debugMode__ = bValue; }
pAjax.enableDebugMode = function () { pAjax.setDebugMode(true); }
pAjax.disableDebugMode = function () { pAjax.setDebugMode(false); }


function pAjax() {
    this.__request__ = null;

    if (typeof this.onInit == "function") this.onInit();
}

var _p = pAjax.prototype;


_p.prepare = function (sFuncName, sRequestType) {
    return this.__request__ = new pAjaxRequest(this, sFuncName, sRequestType);
}


_p.getRequest = function () { return this.__request__; }
_p.getReadyState = function () { return this.__request__.getReadyState(); }
_p.getResponse = function () { return this.__request__.getResponse(); }
_p.getXML = function () { return this.__request__.getXML(); }
_p.getText = function () { return this.__request__.getText(); }
_p.getError = function () { return this.__request__.getError(); }
// Backward compatibility
_p.getData = function () { return this.getResponse(); }
_p.toString = function () { return "[object pAjax]"; }




pAjaxRequest.GET = String("GET");
pAjaxRequest.POST = String("POST");

pAjaxRequest.ASYNC = true;
pAjaxRequest.SYNC = false;


function pAjaxRequest(oAjax, sFuncName, sRequestType) {
    this.__ajax__ = oAjax;
    this.__params__ = [];
    this.__URI__ = document.location.href;

    pAjax.debug("XmlHttp Object s being created");

    this.__setFunctionName__(sFuncName);
    this.__xmlHttp__ = XmlHttp.create();

    var oThis = this;
    this.__onreadystatechange__ = function () { oThis.__onreadystatechange(); };

    this.setRequestType(sRequestType);
    this.setUsername(null);
    this.setPassword(null);
}

var _p = pAjaxRequest.prototype;


_p.abort = function () { if (this.__xmlHttp__) this.__xmlHttp__.abort(); }


_p.execute = function (syncType) {
    if (syncType == null) syncType = pAjaxRequest.ASYNC;

    if (typeof syncType == "string")
        syncType = (syncType.toUpperCase() == "SYNC") ? pAjaxRequest.SYNC : pAjaxRequest.ASYNC;

    this.__exec__(syncType);
}


_p.async = function () { this.__exec__(pAjaxRequest.ASYNC); }
_p.sync = function () { this.__exec__(pAjaxRequest.SYNC); }


_p.__exec__ = function (bSync) {
    delete this.__cachedResponse__;

    if (typeof this.__ajax__.onCreate == "function") this.__ajax__.onCreate();

    var xmlDoc = this.__compileXML__();
    var uri = this.__compileURI__();
    var data = (this.__requestType__ == pAjaxRequest.POST) ? xmlDoc.xml : "null";

    this.abort();
    this.__xmlHttp__.open(this.__requestType__, String(uri), bSync, this.__username__, this.__password__);

    // Using Sync calls, Mozilla does not fire onreadystatechange event, but fires onload
    // Also, IE fires onreadystatechange and does not have onload event defined
    if (bSync) this.__xmlHttp__.onreadystatechange = this.__onreadystatechange__;
    else if (typeof this.__xmlHttp__.onload == "undefined") {
        var oThis = this;

        this.__xmlHttp__.onreadystatechange = function () {
            if (oThis.getReadyState() == 4) oThis.__onreadystatechange__();
        };
    } else this.__xmlHttp__.onload = this.__onreadystatechange__;

    pAjax.debug("FUNCTION: " + this.__funcName__ + "\n\nMODE: " + (bSync ? "Asynchronous" : "Synchronous") + "\n\nURI: " + uri + "\n\nPOST:\n" + data);

    // Addon to prevent weird Apache behaviour (encode is necessary to work in Mozilla)
    if (this.__requestType__ == pAjaxRequest.POST)
        this.__xmlHttp__.setRequestHeader("Post-Data", pAjaxParser.encodeURI(data));

    this.__xmlHttp__.send(xmlDoc);
}


_p.__compileXML__ = function () {
    var xmlDoc;

    if (this.__requestType__ == pAjaxRequest.POST) {
        xmlDoc = XmlDocument.create();
        xmlDoc.appendChild(xmlDoc.createElement("pAjaxCall"));

        var methodCall = xmlDoc.documentElement;

        var methodName = xmlDoc.createElement("pAjaxMethod");
        methodName.appendChild(xmlDoc.createTextNode(this.__funcName__));
        methodCall.appendChild(methodName);

        var methodParams = xmlDoc.createElement("pAjaxParams");
        methodCall.appendChild(methodParams);

        for (var item in this.__params__) {
        	if (typeof this.__params__[item] != "function")
		    	methodParams.appendChild(pAjaxParser.jsToXmlValueNode(item, this.__params__[item], xmlDoc));
        }

        return xmlDoc;
    }

    return null;
}


_p.__compileURI__ = function () {
    var uri = this.__URI__;

    if (this.__requestType__ == pAjaxRequest.GET) {
        var params = (function (itens) {
            var aStrItens = [];

            for (var p in itens) {
				if (typeof p[itens] != "function")
					aStrItens.push(pAjaxParser.jsToUrlString(p, itens[p]));
			}

            return aStrItens.join("");
        })(this.__params__);

        uri += ((this.__URI__.indexOf("?") == -1) ? "?" : "&") + "function=" + this.__funcName__;
        uri += params + "&rnd=" + (new Date()).getTime();
    }

    return uri;
}


_p.__onreadystatechange = function () {
    if (typeof this.__ajax__.onChange == "function") this.__ajax__.onChange();

	//alert("Status: " + this.__xmlHttp__.status);
    if (this.__xmlHttp__.readyState == 4 && this.__xmlHttp__.status == 200) {
        this.__cachedResponse__ = this.__xmlHttp__.responseXML;

        if (!this.errorOccurred() && this.__cachedResponse__.xml == "")
            throw new Error("Unknown RPC Error\n\n\n" + this.getText());


        if (this.getError() != null && typeof this.__ajax__.onError == "function")
        	this.__ajax__.onError();
        else {
			pAjax.debug("Recieved:\n\n" + this.__cachedResponse__.xml);

			if (typeof this.__ajax__.onLoad == "function") this.__ajax__.onLoad();
		}

        this.__dispose__();
    }
}


_p.__dispose__ = function () {
    delete this.__xmlHttp__.onreadystatechange;
    this.__xmlHttp__ = null;
}


_p.__setFunctionName__ = function (sFuncName) { this.__funcName__ = sFuncName; }


_p.setFormParam = function (oFormName) {
	if (typeof oFormName == "string") {
		oFormName = document.forms[oFormName] || document.getElementById(oFormName);
    }

    var sFormName = oFormName.name || oFormName.id;
    var c_params = new Object();

	for (var i = 0; i < oFormName.elements.length; i++) {
		var el = oFormName.elements[i];

		if (el.type && el.type != undefined) {
			switch (el.type) {
				case "text": case "password": case "hidden":
				case "textarea": case "button": case "submit":
                    c_params[el.name] = el.value;
					//this.setParam(el.name, el.value);
					break;

				case "select-one":
					if (el.selectedIndex >= 0) {
						c_params[el.name] = el.options[el.selectedIndex].value;
                        //this.setParam(el.name, el.options[el.selectedIndex].value);
					}

					break;

				case "select-multiple":
					var a = [];

					for (var j = 0; j < el.options.length; j++) {
						if (el.options[j].selected) {
							a.push(el.options[j].value);
						}
					}
                    paramName = el.name.replace("[", "");
                    paramName = paramName.replace("]", "");
                    c_params[paramName] = a;
					//this.setParam(el.name, a);
					break;

				case "checkbox": case "radio":
					if (el.checked || el.selected) {
                        c_params[el.name] = el.value
						//this.setParam(el.name, el.value);
					}

					break;

				default:
					// Does nothing
					break;
			}
		}
	}

    this.setParam(sFormName, c_params);
}


_p.getError = function () {
	if (this.errorOccurred() && this.__xmlHttp__.responseXML != null) {
		return this.__xmlHttp__.responseXML.parseError;
	} else if (this.errorOccurred()) {
		return this.__xmlHttp__.responseText;
	}

	return null;
}


_p.errorOccurred = function () {
	if (!(typeof this.__xmlHttp__.responseXML == "object" && this.__xmlHttp__.responseXML != null)) {
		return true;
	}

	return (this.__xmlHttp__.responseXML.parseError && this.__xmlHttp__.responseXML.parseError.errorCode != 0);
}


_p.setParam = function (sParamName, sParamValue) {
   if (sParamValue == null) delete this.__params__[sParamName];
   else this.__params__[sParamName] = sParamValue;
}

_p.getParam = function (sParamName) { return this.__params__[sParamName]; }
_p.delParam = function (sParamName) { this.setParam(sParamName); }
_p.getResponse = function () { return pAjaxParser.parseXmlResponse(this.__cachedResponse__); }
_p.getXML = function () { return this.__cachedResponse__.documentElement.childNodes[0].xml; }
_p.getText = function () { return this.__xmlHttp__.responseText; }
_p.getReadyState = function () { return this.__xmlHttp__.readyState; }
_p.getXmlHttp = function () { return this.__xmlHttp__; }
_p.getLoaded = function () { return this.getReadyState() == 4; }
_p.getLoading = function () { return this.getReadyState() < 4; }
_p.setRequestType = function (sRequestType) { this.__requestType__ = String(sRequestType) || pAjaxRequest.GET; }
_p.getRequestType = function () { return this.__requestType__; }
_p.setURI = function (sURI) { this.__URI__ = sURI; }
_p.getURI = function () { return this.__URI__; }
_p.setUsername = function (sUsername) { this.__username__ = sUsername; }
_p.setPassword = function (sPassword) { this.__password__ = sPassword; }
_p.toString = function () { return "[object pAjaxRequest]"; }




function pAjaxCall(uri, method, callback) {
    var ajax = new pAjax();
    var req = ajax.prepare(method, pAjaxRequest.GET);

    if (uri != null) req.setURI(uri);

    if (arguments.length > 3) {
        var a = [];

        for (var i = 3; i < arguments.length; i++)
            a.push(arguments[i]);

        req.setParam("param", ((a.length == 1) ? a.pop() : a));
    }

    ajax.onLoad = function () { callback.call(this, this.getResponse()); }
    req.async();
}

