

	var currentState = '';
	var checkingPageState = false;
	
	var stateTimeout = null;
	var timeInterval = 200;

	function setPageState(currentPage)
	{
		//var loc = (location.href.split('#'))[0];
		//window.location.replace(loc + "#" + pageState);
		setHashValue('page',currentPage);
		
		currentState = currentPage;
	}

	function checkPageState() {
		//Added to fix to cancel multiple attempts to schedule checkPageState calls from other ajax loaded page
		checkingPageState = true;
		
		var page = getHashValue('page');

		
		if (page.length <= 0 || page == ''){
			page = 1;
		}
		
		if (currentState != page ){
			displayPage(page);

			currentState = page;
		}

		
		stateTimeout = setTimeout(checkPageState, timeInterval);
		
		/*var state = window.location.hash.replace("#","");

		if (state == '') {state = 1;}

		if (currentState != state)
		{
			currentState = state;
			displayPage(state);
		}

		stateTimeout = setTimeout(checkPageState, timeInterval);
		*/
	}

	
	
	function getHashValue(name){
	
		var hash = document.location.hash.replace("#","");
				
		var items = hash.split(";");
		
		for(key in items){

			var keyValue = items[key].split(":");
			
			if (keyValue[0] == name){
				return keyValue[1];
			}	
		}
		return "";		
	}

	
	function setHashValue(name, value){
	
		var hash = document.location.hash.substring(1);
		
		var items = hash.split(";");
		var newHash = "";
		var delim = "";
		
		var found = false;
		
		if (items.length > 0){
			for(key in items){
				
				var keyValue = items[key].split(":");
				
				if (keyValue[0] == name){
					found = true;
					keyValue[1] = value;
				}	
				
				if (keyValue[0].length > 0 && (typeof keyValue[1] != 'undefined') ){
					newHash += delim + keyValue[0] + ":" + keyValue[1];
				}
				delim = ";";
			}
		}
		if (! found){
			newHash += ";" + name + ":" + value;
		}
		
		document.location.hash = newHash;		
		
	}