/**
@desc This file helps in keeping track of state changes. XXXXX
@req Need helper.js
**/


/* This class helps in syncronizing AJAX state changes*/ 
function AjaxState (IFrameId) 
{
	var l=new Logger(false);
	var IFrameId=IFrameId;
		
	function setIFrameSrc(state)
	{
		$(IFrameId).src="http://kd103363:85/%21AjaxDummyIFrameParser?sState=" + state;	
	}
	
	
	this.pSetIFrameSrc=function (state)
	{
		setIFrameSrc(state);
	}
	/** This function returns the urls hash.
	@return hash The hash at the end of the url e.g. 
	http://kd103363:85/!GetDefaultIndexPage#prodTab2  => prodTab2
	*/
	function getUrlHash() 
	{
		var url=window.location.href;
		var  hash= url.replace(/.*#(.*)/,"$1");
		
		return hash;	
	}
	
	/**Public version of getUrlHash **/
	this.pGetUrlHash = function ()
	{
		return getUrlHash();
	}
	
	/** This function reads the content of the IFrame body
	@return body The content of IFrame body 
	**/ 
	function getIFrameState()
	{
		var body=window[IFrameId].document.body.innerHTML;
		body=body.strip();
		return body;
	}
	
	/** Public access to getIFrameState**/
	this.pGetIFrameState=function ()
	{
		return getIFrameState();
	}
	
	
	this.pGetIFrameHash = function()
	{
		return getIFrameHash();
	}
	
	/** This function set the hash at the end of the actual url. It is used for state changes
	@param hash The hash that should be added
	*/
	function setHash(hash)
	{
		window.location.hash ="#" + hash;
		//to keep track of state changes
		this.state=hash;
	}
	
	/** Public version of setHash */
	this.pSetHash = function(hash)
	{
		setHash(hash);
	}
	
	/*This function starts the process of continiously checking for an url hash change
	@param callback A callback function to be called everytime the check should be performed.function(){that.checkMe();}
	@param ms Time in milliseconds to call the callback
	e.g. ajaxState.pStartStateCheck(function(){that.checkMe();},1000); */
	function startStateCheck(callback,ms)
	{
		l.log("starting state check");	
		var interval_var = window.setInterval(callback, ms);
	}
	
	/*Public version of startStateCheck*/
	this.pStartStateCheck =function(callback,ms)
	{
		startStateCheck(callback,ms);
	}

	
	
	
}


