// WebDozerClt.Web.Url Version 1.0
// José Proença
// 2007-06-18

// References: WebDozerClt
if (!('WebDozerClt' in this))
	alert('Error WebDozerClt.Web.Url.00. WebDozerClt not found.');

// References: WebDozerClt.Project
if (!('Project' in WebDozerClt))
	alert('Error WebDozerClt.Web.Url.00. WebDozerClt.Project not found.');

// References: WebDozerClt.Web
if (!('Web' in WebDozerClt))
	alert('Error WebDozerClt.Web.Url.00. WebDozerClt.Project not found.');

if (!('Url' in WebDozerClt.Web))
	WebDozerClt.Web.Url = new Object();
	
WebDozerClt.Web.Url.QueryString = function(url)
{
	var querystring = url;
	var nIdx = url.indexOf('?');
	if (nIdx >= 0)
		querystring = querystring.substr(nIdx+1);
	else
		querystring = '';

	this.items = new Object();
	if (querystring.length > 0)
	{
		var args = querystring.split('&');
		for (var i = 0; i < args.length; i++)
		{
			var pair = args[i].split('=');

			temp = unescape(pair[0]).split('+');
			temp0 = temp.join(' ');
			
			temp = unescape(pair[1]).split('+');
			temp1 = temp.join(' ');
			
			this.items[temp0.toLowerCase()] = temp1;
		}
	}
	
    this.get = function(strKey, strDefault)
		{
			var value = this.items[strKey.toLowerCase()];
			if ( value == undefined || value == null)
				value = strDefault;
			
			return value;
		}
}


WebDozerClt.Web.Url.BuildProjectURL = function(path)
{
	var url = null;
	if ('ApplicationVDir' in WebDozerClt.Project.Configuration)
		url = WebDozerClt.Project.Configuration.ApplicationVDir;
	else if ('OnlineURL' in WebDozerClt.Project.Configuration)
		url = WebDozerClt.Project.Configuration.OnlineURL;
	
	if (url == null)
		alert('Error WebDozerClt.Web.Url.01. ApplicationVDir and OnlineURL not configured.');
	else
	{
		if (url.length == 0 || url.substr(url.length-1) != '/')
			url += '/';
		
		if (typeof(path) != 'undefined')
			url += path;
	}
	return url;
}


WebDozerClt.Web.Url.AddQueryParam = function(url, name, value)
{
	var nIdx = url.indexOf('?');
	if (nIdx < 0)
		url += '?';
	else
		url += '&';

	return (url + escape(name) + "=" + escape(value));
}

WebDozerClt.Web.Url.MakeAbsolute = function(URL)
{
	var strAbsUrl = URL;
	var nSlash = URL.indexOf("/");
	var nProtocolSeparator = URL.indexOf("://");

	if ((nSlash <= 0) || (nProtocolSeparator < 0))
	{
		if (nSlash != 0)
			URL = "/"+URL;
		strAbsUrl = window.location.protocol + "//" + window.location.host + URL;
	}
	
	return strAbsUrl;
}

