/*
 *	This URLUtil object is responsible for redirecting 
 *   html/jsp pages to a different location
 */
function URLUtil()
{
	/**
	 *	Generates url and goes to it. This function always adds version parameter to the url
	 *	@param a_action the some action to be done (i.e. "GetDocument.do")
	 *	@param a_props the map of all parameters to be sent
	 *	@param a_destWnd the destination window (the same by default)
	 *	@param a_bReplace boolean that specifies kind of operation reload(defualt) or replace
	 */
	this.openLinkUnified = function(a_action, a_props, a_destWnd, a_bReplace)
	{
		var destWnd = a_destWnd || window;
		var bReplace = a_bReplace || false;

		var sHref = this.generateLinkUnified(a_action, a_props);

		if (bReplace)
			destWnd.document.location.replace(sHref);
		else
			destWnd.document.location = sHref;
	}
	
	/**
	 *	Generates url returns it. This function always adds version parameter to the url
	 *	@param a_action the some action to be done (i.e. "GetDocument.do")
	 *	@param a_props the map of all parameters to be sent
	 */
	this.generateLinkUnified = function(a_action, a_props)
	{
		var sHref = a_action + '?';
		
		var bFirstParam = true;

		for (i in a_props)
		{
			if (bFirstParam)
				bFirstParam = false;
			else
				sHref += '&';

			sHref += i + '=' + encodeURIComponent(a_props[i]);
		}

		return this.getVerifiedUrl(sHref,version);
	}
	
	/**
	 *	Goes to the url
	 *	@param url the url to redirect
	 *	@versionNo the version of the jsp ( specified in the JspRoot tag library )
	 *
	 */
	this.getVerifiedUrl = function(url,versionNo)	
	{
		var attributeDelimiter = "?";
		if(url.indexOf("?") != -1)
			attributeDelimiter = "&";
		url = url + attributeDelimiter + "version="+versionNo ;
		return url ;
	}
}

//create a static instance if URLUtil
var URLUtil = new URLUtil();

