+ var newStart = this.currentStart - (step * this.currentNum );
+ this.show( newStart > 0 ? newStart : 0 );
+ },
+
+ showPage: function(pageNum)
+ {
+ //var page = pageNum || 1;
+ this.show(pageNum * this.currentNum);
+ }
+};
+
+/*
+********************************************************************************
+** AJAX HELPER CLASS ***********************************************************
+********************************************************************************
+*/
+var pzHttpRequest = function ( url, errorHandler ) {
+ this.maxUrlLength = 2048;
+ this.request = null;
+ this.url = url;
+ this.errorHandler = errorHandler || null;
+ this.async = true;
+ this.requestHeaders = {};
+
+ 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 =
+{
+ safeGet: function ( params, callback )
+ {
+ var encodedParams = this.encodeParams(params);
+ var url = this._urlAppendParams(encodedParams);
+ if (url.length >= this.maxUrlLength) {
+ this.requestHeaders["Content-Type"]
+ = "application/x-www-form-urlencoded";
+ this._send( 'POST', this.url, encodedParams, callback );
+ } else {
+ this._send( 'GET', url, '', callback );
+ }
+ },
+
+ get: function ( params, callback )
+ {
+ this._send( 'GET', this._urlAppendParams(this.encodeParams(params)),
+ '', callback );
+ },
+
+ post: function ( params, data, callback )
+ {
+ this._send( 'POST', this._urlAppendParams(this.encodeParams(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;
+ },
+
+ encodeParams: function (params)
+ {
+ var sep = "";
+ var encoded = "";
+ for (var key in params) {
+ if (params[key] != null) {
+ encoded += sep + key + '=' + encodeURIComponent(params[key]);
+ sep = '&';
+ }
+ }
+ return encoded;
+ },
+
+ _send: function ( type, url, data, callback)
+ {
+ var context = this;
+ this.callback = callback;
+ this.async = true;
+ this.request.open( type, url, this.async );
+ for (var key in this.requestHeaders)
+ this.request.setRequestHeader(key, this.requestHeaders[key]);
+ this.request.onreadystatechange = function () {
+ context._handleResponse(url); /// url used ONLY for error reporting
+ }
+ this.request.send(data);
+ },
+
+ _urlAppendParams: function (encodedParams)
+ {
+ if (encodedParams)
+ return this.url + "?" + encodedParams;
+ else
+ return this.url;
+ },
+
+ _handleResponse: function (savedUrlForErrorReporting)
+ {
+ if ( this.request.readyState == 4 ) {
+ // pick up appplication errors first
+ var errNode = null;
+ if (this.request.responseXML &&
+ (errNode = this.request.responseXML.documentElement)
+ && errNode.nodeName == 'error') {
+ var errMsg = errNode.getAttribute("msg");
+ var errCode = errNode.getAttribute("code");
+ var errAddInfo = '';
+ if (errNode.childNodes.length)
+ errAddInfo = ': ' + errNode.childNodes[0].nodeValue;
+
+ 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.request.responseXML == null) {
+ if (this.request.responseText != null) {
+ //assume JSON
+
+ var json = null;
+ var text = this.request.responseText;
+ if (typeof window.JSON == "undefined")
+ json = eval("(" + text + ")");
+ else {
+ try {
+ json = JSON.parse(text);
+ }
+ catch (e) {
+ // Safari: eval will fail as well. Considering trying JSON2 (non-native implementation) instead
+ /* DEBUG only works in mk2-mobile
+ if (document.getElementById("log"))
+ document.getElementById("log").innerHTML = "" + e + " " + length + ": " + text;
+ */
+ try {
+ json = eval("(" + text + ")");
+ }
+ catch (e) {
+ /* DEBUG only works in mk2-mobile
+ if (document.getElementById("log"))
+ document.getElementById("log").innerHTML = "" + e + " " + length + ": " + text;
+ */
+ }
+ }
+ }
+ this.callback(json, "json");
+ } else {
+ var err = new Error("XML response is empty but no error " +
+ "for " + savedUrlForErrorReporting);
+ err.code = -1;
+ 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("HTTP response not OK: "
+ + this.request.status + " - "
+ + this.request.statusText );
+ err.code = '00' + this.request.status;
+ if (this.errorHandler) {
+ this.errorHandler(err);
+ }
+ else {
+ throw err;
+ }
+ }
+ }