window.dhtmlHistory.create();

window.onload = function() {
	dhtmlHistory.initialize();
	dhtmlHistory.addListener(historyChange);
}

function savePageToLeave() {	
	var savedPageName = "savedPage";																						
	var savedPage = document.getElementById("wrapper").innerHTML;    
	dhtmlHistory.add(savedPageName, savedPage);	
	if (window.dhtmlHistory.isIE) {
		var address = self.location.href.split('#')[0] + "#" + savedPageName;
		self.location.href = address;
	}
}

function historyChange(newLocation, historyData) {
	if (newLocation.match("savedPage") != null) {
		document.getElementById("wrapper").innerHTML = historyData; 
	}
}
