Type.registerNamespace('Vehix.Presentation')
Vehix.Presentation.ToEmpty = function(value)
{
	var result = String(value);
	if (!value)
	{
		result = '';
	}
	return result;
}
Vehix.Presentation.trySetSelectedValue = function(element, value)
{
	var result = false;
	if (element && element.tagName == 'SELECT')
	{
		for (var index = 0; index < element.options.length; index++)
		{
			element.options[index].selected = false;
			if (element.options[index].value == value)
			{

				result = element.options[index].selected = true;

			}
		}
	}
	return result;
}
Vehix.Presentation.tryGetSelectedValue = function(element)
{
	var result = null;
	if (element && element.selectedIndex > -1 && (element.selectedIndex < element.options.length))
	{
		result = element.options[element.selectedIndex].value;
	}
	return result;
}
Vehix.Presentation.tryGetSelectedText = function(element)
{
	var result = null;
	if (element && element.selectedIndex > -1 && (element.selectedIndex < element.options.length))
	{
		result = element.options[element.selectedIndex].text;
	}
	return result;
}

Vehix.Presentation.showElement = function(element, disp)
{
	var sds = "inline";
	if (typeof (disp) != "undefined")
		sds = disp;
	if (typeof (element) != "undefined" && element.style)
		element.style.display = disp;
}

Vehix.Presentation.hideElement = function(element)
{
	if (typeof (element) != "undefined" && element.style)
		element.style.display = "none";
}
Vehix.Presentation.getPosition = function(element)
{
	var l = 0;
	var t = 0;
	do
	{
		t += element.offsetTop;
		l += element.offsetLeft;
	} while (element = element.offsetParent);

	return { top: t, left: l }
}
Vehix.Presentation.overlayInside = function(container, element, topOffset)
{
	var position = Vehix.Presentation.getPosition(container);
	element.style.position = 'absolute';
	element.style.top = position.top + 'px'
	alert(position.top);
	alert(position.left);
	element.style.left = position.left + 'px'
	element.style.width = container.clientWidth + 'px';
	element.style.height = container.clientHeight + 'px';
}
Vehix.Presentation.connectToContainer = function(container, element, offset)
{
	if (typeof (container) != undefined && typeof (element) != undefined && typeof (element.style) != undefined)
	{
		if (typeof (offset) == undefined)
		{
			offset = 0;
		}
		var height = (container.clientHeight - element.clientHeight) - (element.offsetTop + offset);
		element.style.height = (height + element.clientHeight) + 'px';
	}

}
Vehix.Presentation.connectX = function(min)
{
	var height = min;
	for (var index = 1; index < arguments.length; index++)
	{
		if (typeof (arguments[index]) != 'undefined' && typeof (arguments[index].clientHeight) != 'undefined' && arguments[index].clientHeight > height)
		{
			height = arguments[index].clientHeight;
		}
	}

	if (height > min)
	{
		for (var index = 1; index < arguments.length; index++)
		{
			arguments[index].style.height = height + 'px';
		}
	}
}

Vehix.Presentation.SortDirection = function() { }
Vehix.Presentation.SortDirection.prototype =
{
	Ascending: 0,
	Descending: 1
}
Vehix.Presentation.SortDirection.registerEnum('Vehix.Presentation.SortDirection');
Vehix.Presentation.QueryString = function(url)
{
	Vehix.Presentation.QueryString.initializeBase(this);
	this._parse(url);
}
Vehix.Presentation.getCookie = function(name)
{
	var result = null;
	var cookies = document.cookie.split(';');
	for (var index = 0; index < cookies.length; index++)
	{
		var pair = cookies[index].split('=')
		if (decodeURIComponent(pair[0].trim()) == name && pair.length > 0)
		{
			result = decodeURIComponent(pair[1])
			break;
		}
	}
	return result;
}

Vehix.Presentation.setCookie = function(name, value, expires, path, domain)
{
	if (typeof (expires) == 'undefined')
	{
		expires = new Date();
		expires.setTime(expires.getTime() + (3600000 * 24 * 30));
	}
	if (typeof (path) == 'undefined')
	{
		path = '/';
	}
	if (typeof (domain) == 'undefined')
	{
		domain = document.location.hostname;
	}
	if (typeof (value) == 'object')
	{
		value = Sys.Serialization.JavaScriptSerializer.serialize(value);
	}
	document.cookie = encodeURIComponent(name) + '=' + encodeURIComponent(value) + '; path=' + path + '; expires=' + expires.toGMTString() + '; domain=' + domain;
}
Vehix.Presentation.clearCookie = function(name, path, domain)
{
	if (typeof (path) == 'undefined')
	{
		path = '/';
	}
	if (typeof (domain) == 'undefined')
	{
		var segments = document.location.host.split('.');
		while (segments.length > 1)
		{
			Vehix.Presentation.clearCookie('zip', path, segments.join('.'));
			segments = segments.slice(1, segments.length);
		}
	}
	Vehix.Presentation.setCookie(name, '', new Date(), path, domain);
}
Vehix.Presentation.QueryString.prototype =
{
	_parse: function(url)
	{
		if (url && url.length > 0)
		{
			var start = url.indexOf('?');
			if (start > -1)
			{
				start++;
				url = url.substr(start, url.length - start);
				var pairs = url.split('&');
				for (var index = 0; index < pairs.length; index++)
				{
					var pair = pairs[index].split('=');
					if (pair.length > 0)
					{
						this.add(pair[0], pair[1]);
					}
				}
			}
		}
	},
	add: function(key, value)
	{
		if (key && key.length > 0)
		{
			if (this.containsKey(key))
			{
				if (typeof (value) != 'undefined' && value != null)
				{
					value = decodeURIComponent(value);
					this.set_item(key, this.get_item() + ',' + value);
				}
				else
				{
					this.remove(key);
				}
			}
			else if (typeof (value) != 'undefined' && value != null)
			{
				Vehix.Presentation.QueryString.callBaseMethod(this, 'add', [key, decodeURIComponent(value)])
			}
		}
	},
	addIf: function(expression, key, value)
	{
		if (expression)
		{
			this.add(key, value);
		}
	},
	set_item: function(key, value)
	{
		if (!this.containsKey(key))
		{
			this.add(key, value);
		}
		else
		{
			Vehix.Presentation.QueryString.callBaseMethod(this, 'set_item', [key, decodeURIComponent(value)])
		}
	},
	toString: function(url)
	{
		for (var enumerator = this.getEnumerator(); enumerator.moveNext(); )
		{
			url = Vehix.Presentation.QueryString.startOrAppend(url, encodeURIComponent(enumerator.get_key()) + '=' + encodeURIComponent(enumerator.get_current()));
		}
		return url;
	}
}
Vehix.Presentation.QueryString.startOrAppend = function(url, pair)
{
	var result = url;
	if (url.indexOf('?') > -1)
	{
		if ((url.length - 1) != url.indexOf('?'))
		{
			result += '&'
		}
	}
	else
	{
		result += '?'
	}
	result += pair;
	return result;
}
Vehix.Presentation.QueryString.stripQuery = function(url)
{
	var result = url;
	if (result && result.indexOf('?') > -1)
	{
		result = result.substr(0, result.indexOf('?'));
	}
	return result;
}
Vehix.Presentation.QueryString.stripUrl = function(url)
{
	var result = url;
	if (result && result.indexOf('?') - 1 > -1)
	{
		result = result.substr(result.indexOf('?') - 1, result.length);
	}
	return result;
}

Vehix.Presentation.QueryString.registerClass('Vehix.Presentation.QueryString', Vehix.Collections.Dictionary);
Vehix.Presentation.Selector = function()
{
	this._enableChangedEvent = true;
}
Vehix.Presentation.Selector.prototype =
{
	get_enableChangedEvent: function()
	{
		return this._enableChangedEvent;
	},
	set_enableChangedEvent: function(value)
	{
		_enableChangedEvent = value;
	},
	changed: function(field, value)
	{
		if (this._enableChangedEvent)
		{
			var handler = this.get_events().getHandler('onChanged');
			if (handler) handler(this, new Vehix.Presentation.Selector.ChangedEventArgs(field, name))
		}
	}
}
Vehix.Presentation.Selector.registerClass('Vehix.Presentation.Selector', Sys.Component);
Vehix.Presentation.Selector.ChangedEventArgs = function(field, value)
{
	this._field = field;
	this._value = value;
}
Vehix.Presentation.Selector.ChangedEventArgs.prototype =
{
	get_field: function()
	{
		return this._field;
	},
	get_value: function()
	{
		return this._value;
	}
}
Vehix.Presentation.Selector.ChangedEventArgs.registerClass('Vehix.Presentation.Selector.ChangedEventArgs', Sys.EventArgs);