+
+/*
+********************************************************************************
+** AJAX HELPER CLASS ***********************************************************
+********************************************************************************
+*/
+var pzHttpRequest = function ( url, errorHandler ) {
+ this.request = null;
+ this.url = url;
+ this.errorHandler = errorHandler || null;
+ this.async = true;
+
+ if ( window.XMLHttpRequest ) {
+ this.request = new XMLHttpRequest();
+ } else if ( window.ActiveXObject ) {
+ try {
+ this.request = new ActiveXObject( 'Msxml2.XMLHTTP' );
+ } catch (err) {
+ this.request = new ActiveXObject( 'Microsoft.XMLHTTP' );
+ }
+ }
+};
+
+pzHttpRequest.prototype =
+{
+ get: function ( params, callback )
+ {
+ this._send( 'GET', params, '', callback );
+ },
+
+ post: function ( params, data, callback )
+ {
+ this._send( 'POST', params, data, callback );
+ },
+
+ load: function ()
+ {
+ this.async = false;
+ this.request.open( 'GET', this.url, this.async );
+ this.request.send('');
+ if ( this.request.status == 200 )
+ return this.request.responseXML;
+ },
+
+ _send: function ( type, params, data, callback )
+ {
+ this.callback = callback;
+ var context = this;
+ this.async = true;
+ this.request.open( type, this._urlAppendParams(params), this.async );
+ this.request.onreadystatechange = function () {
+ context._handleResponse();
+ }
+ this.request.send(data);
+ },
+
+ _urlAppendParams: function (params)
+ {
+ var getUrl = this.url;
+
+ var sep = '?';
+ var el = params;
+ for (var key in el) {
+ if (el[key] != null) {
+ getUrl += sep + key + '=' + encodeURIComponent(el[key]);
+ sep = '&';
+ }
+ }
+ return getUrl;
+ },
+
+ _handleResponse: function ()
+ {
+ if ( this.request.readyState == 4 ) {
+ // pick up pazpr2 errors first
+ if ( this.request.responseXML
+ && this.request.responseXML.documentElement.nodeName == 'error'
+ && this.request.responseXML.getElementsByTagName("error")
+ .length ) {
+ var errAddInfo = '';
+ if ( this.request.responseXML.getElementsByTagName("error")[0]
+ .childNodes.length )
+ errAddInfo = ': ' +
+ this.request.responseXML
+ .getElementsByTagName("error")[0]
+ .childNodes[0].nodeValue;
+ var errMsg =
+ this.request.responseXML.getElementsByTagName("error")[0]
+ .getAttribute("msg");
+ var errCode =
+ this.request.responseXML.getElementsByTagName("error")[0]
+ .getAttribute("code");
+
+ var err = new Error(errMsg + errAddInfo);
+ err.code = errCode;
+
+ if (this.errorHandler) {
+ this.errorHandler(err);
+ }
+ else {
+ throw err;
+ }
+ } else if ( this.request.status == 200 ) {
+ this.callback( this.request.responseXML );
+ } else {
+ var err = new Error("Pz2.js: HTTP request error (AJAX). Code: "
+ + this.request.status + " Info: "
+ + this.request.statusText );
+ err.code = 'HTTP';
+
+ if (this.errorHandler) {
+ this.errorHandler(err);
+ }
+ else {
+ throw err;
+ }
+ }
+ }
+ }
+};
+
+/*
+********************************************************************************
+** XML HELPER FUNCTIONS ********************************************************
+********************************************************************************
+*/
+
+// DOMDocument
+
+if ( window.ActiveXObject) {
+ var DOMDoc = document;
+} else {
+ var DOMDoc = Document.prototype;
+}
+
+DOMDoc.newXmlDoc = function ( root )
+{
+ var doc;
+
+ if (document.implementation && document.implementation.createDocument) {
+ doc = document.implementation.createDocument('', root, null);
+ } else if ( window.ActiveXObject ) {
+ doc = new ActiveXObject("MSXML2.DOMDocument");
+ doc.loadXML('<' + root + '/>');
+ } else {
+ throw new Error ('No XML support in this browser');
+ }
+
+ return doc;
+}
+
+
+DOMDoc.parseXmlFromString = function ( xmlString )
+{
+ var doc;
+
+ if ( window.DOMParser ) {
+ var parser = new DOMParser();
+ doc = parser.parseFromString( xmlString, "text/xml");
+ } else if ( window.ActiveXObject ) {
+ doc = new ActiveXObject("MSXML2.DOMDocument");
+ doc.loadXML( xmlString );
+ } else {
+ throw new Error ("No XML parsing support in this browser.");
+ }
+
+ return doc;
+}
+
+DOMDoc.transformToDoc = function (xmlDoc, xslDoc)
+{
+ if ( window.XSLTProcessor ) {
+ var proc = new XSLTProcessor();
+ proc.importStylesheet( xslDoc );
+ return proc.transformToDocument(xmlDoc);
+ } else if ( window.ActiveXObject ) {
+ return document.parseXmlFromString(xmlDoc.transformNode(xslDoc));
+ } else {
+ alert( 'Unable to perform XSLT transformation in this browser' );
+ }
+}
+
+// DOMElement
+
+Element_removeFromDoc = function (DOM_Element)
+{
+ DOM_Element.parentNode.removeChild(DOM_Element);
+}
+
+Element_emptyChildren = function (DOM_Element)
+{
+ while( DOM_Element.firstChild ) {
+ DOM_Element.removeChild( DOM_Element.firstChild )
+ }
+}
+
+Element_appendTransformResult = function ( DOM_Element, xmlDoc, xslDoc )
+{
+ if ( window.XSLTProcessor ) {
+ var proc = new XSLTProcessor();
+ proc.importStylesheet( xslDoc );
+ var docFrag = false;
+ docFrag = proc.transformToFragment( xmlDoc, DOM_Element.ownerDocument );
+ DOM_Element.appendChild(docFrag);
+ } else if ( window.ActiveXObject ) {
+ DOM_Element.innerHTML = xmlDoc.transformNode( xslDoc );
+ } else {
+ alert( 'Unable to perform XSLT transformation in this browser' );
+ }
+}
+
+Element_appendTextNode = function (DOM_Element, tagName, textContent )
+{
+ var node = DOM_Element.ownerDocument.createElement(tagName);
+ var text = DOM_Element.ownerDocument.createTextNode(textContent);
+
+ DOM_Element.appendChild(node);
+ node.appendChild(text);
+
+ return node;
+}
+
+Element_setTextContent = function ( DOM_Element, textContent )
+{
+ if (typeof DOM_Element.textContent !== "undefined") {
+ DOM_Element.textContent = textContent;
+ } else if (typeof DOM_Element.innerText !== "undefined" ) {
+ DOM_Element.innerText = textContent;
+ } else {
+ throw new Error("Cannot set text content of the node, no such method.");
+ }
+}
+
+Element_getTextContent = function (DOM_Element)
+{
+ if ( typeof DOM_Element.textContent != 'undefined' ) {
+ return DOM_Element.textContent;
+ } else if (typeof DOM_Element.text != 'undefined') {
+ return DOM_Element.text;
+ } else {
+ throw new Error("Cannot get text content of the node, no such method.");
+ }
+}
+
+/* do not remove trailing bracket */