 window.dhtmlHistory.create({   
     toJSON: function(o) {  
        return $.toJSON(o);  
     },  
     fromJSON: function(s) {  
        return $.evalJSON(s);  
     }  
});  
 
window.onload = function() {
	dhtmlHistory.initialize();
	dhtmlHistory.addListener(historyChange);};


function callHSTest(hash,val) {
	historyStorage.put(hash,val);}

/*set up test cases for historyStorage*/



function historyChange(newLocation, historyData) {
	var historyMsg = (typeof historyData == "object" && historyData != null
		? historyStorage.toJSON(historyData)
		: historyData
	);
	page(newLocation);
};

/* Our event handler to add history change events */
addHistoryEvent = function(un, deux) {
	dhtmlHistory.add(un ,deux);}

/*basic Ajax wrapper*/
function getXHR() {
	if (window.XMLHttpRequest) {
		return new XMLHttpRequest();
	} else if (window.ActiveXObject) {
		return new ActiveXObject("Microsoft.XMLHTTP");
	}
}

/* Converts pointy brackets into their HTML escape code equivalents so we can print out XML. */
function prettyPrintXml(content) {
	if (content == null) {
		return null;
	}
	content = content.replace(/</g, "&lt;");
	content = content.replace(/>/g, "&gt;<br />");
	return content;
}


function logTopSubscriptions() {
	log(prettyPrintXml(historyStorage.get('mySubscriptions')));
}
/* Gets the top 100 blog subscriptions as an OPML outline. - for a historyStorage test case */
function loadTopSubscriptions() {
	log("Loading top subscriptions...");
	var url = "rshTestPageTop100.opml";
	var request = getXHR();
	var processRequest = function() {
		if (request.readyState == 4) {
			if (request.status == 200) {
				historyStorage.put("mySubscriptions", request.responseText);
				log("Top subscriptions loaded");
				log('Put complex XML document into key "mySubscriptions"');
				log('<a href="javascript:logTopSubscriptions();">Click here to log the entire XML document.</a> Warning: it\'s huge.');
				topLoaded = true;
			}
			else {
				var message = "There was a problem retrieving the subscription list: " + request.statusText
				log(message);
			}
		}
	};
	request.onreadystatechange = processRequest;
	request.open("GET", url, true);
	request.send("");
}


