var httpHelper =
{
	/**
	*	Set cookie
	*
	*	@param		name		string		Cookie name.
	*	@param		days		string		Expiration interval (days).
	*	@param		path		string		The path on the server in which the cookie will be available on.
	*	@param		domain		string		The domain that the cookie is available (current domain is by default).
	*	@param		secure		bool		Indicates that the cookie should only be transmitted over a secure HTTPS connection. 
	*										When set to TRUE, the cookie will only be set if a secure connection exists. The default is FALSE.
	*
	*	return		bool		success
	*/
	setCookie: function(name, value, days, path, domain, secure)
	{
		if ('undefined'==days+'')
			days = 30;

		if ('undefined'==path+'')
			path = '/';

		if ('undefined'==domain+'')
			domain = document.domain;

		if (domain.substr(0,4)=='www.')
			domain = domain.substr(3,domain.length);

		if ('undefined'==secure+'')
			secure = false;

		var date = new Date();
		date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000));
		
		expires = "; expires=" + date.toGMTString();
		
		document.cookie = C('base.cookie-prefix') + name + "=" + value + expires + "; path="+path+"; domain="+domain+(secure ? "; secure=true" : "");

		return true;
	},
	
	/**
	*	Deletes cookie
	*
	*	@param		name		string		cookie name
	*
	*	return		void
	*/
	deleteCookie: function(name)
	{
		httpHelper.setCookie(name, "" , -1);
	},

	/**
	*	Returns cookie
	*
	*	@param		name		string		cookie name
	*
	*	return		mixed | null
	*/
	getCookie: function(name)
	{
		name = C('base.cookie-prefix') + name;

		var name2 = name + "=";
		var cookies = document.cookie.split(';');
		
		for (var i = 0; i < cookies.length; i++)
		{
			var cookie = cookies[i];
			
			while (cookie.charAt(0) == ' ')
			{
				cookie = cookie.substring(1, cookie.length);
			}
			
			if (cookie.indexOf(name2) == 0)
			{
				return decodeURI(unescape(cookie.substring(name2.length, cookie.length)));
			}
		}
		
		return null;
	},
	
	/**
	*	Generates URL
	*
	*	@param		url			string		base URL
	*   @param		args		hash		extra URL parameters
	*	@param		dropParams	list		a list of parameters to be removed from URL
	*
	*	return		string
	*/
	makeUrl: function(url, args, dropParams)
	{
		var urlArgs = [];
		
		if (url.match(/^([^?]*)\?(.+)/))
		{
			url = RegExp.$1;
			
			var urlParams = RegExp.$2.split(/&/);

			if (!dropParams)
			{
				for(var i = 0; i<urlParams.length; i++)
				{
					var urlParam = urlParams[i].split(/=/,2);
					if( !( urlParam[0] in args) )
						urlArgs.push(urlParams[i]);
				}
			}
		}
		
		if ('object' == typeof args)
		{
			var a = [];
			for(i in args)
				if(!Object.prototype[i])
					a.push(i+"="+escape(args[i]));
			args = a;
		}

		urlArgs = urlArgs.concat(args).join('&');

		if ( url != '' && urlArgs != '')
			url = url + (url.match(/\?/) ? "&" : "?");

		return url + urlArgs;
	},

	/**
	*	Redirect to the specified URL
	*
	*	@param		url			string		URL to redirect
	*
	*	return		void
	*/
	go: function(url)
	{
		document.location.href = url;
	}
};