/**
* Purpose: You give me a location, I will save it
* so when the back button is pressed, the localCallback
* is called with the appropriate location.
* Example usage: people.js
*
* This js requires rsh.js
*/

/* init as per rsh.js */
window.dhtmlHistory.create({
    toJSON: function(o) {
            return Object.toJSON(o);
    }
    , fromJSON: function(s) {
            return s.evalJSON();
    }
});

/** Init and set callback */
function initializeDhtmlHistory(callback) {
  dhtmlHistory.initialize();
  dhtmlHistory.addListener(handleHistoryChange);
  dhtmlHistory.defaultLocation = window.location
  dhtmlHistory.localCallback = callback
}

/**Callback. */
function handleHistoryChange(location, pageData) {
    if (dhtmlHistory.localCallback){
        if (location == '') {
                location = dhtmlHistory.defaultLocation;
        }
        dhtmlHistory.localCallback(location);
    }
}

/* Use this to save page history */
function addZaadzPageToHistory(url) {
    dhtmlHistory.add(url, null);
}

