/**
* Common base classes used globaly.
* Classes included in this file:
*     Padding
*     Border
*     RectangleBorder
*     Font
*     Background
*     Size
*     Point
*     Rectangle
*     BasicEventObjectBase
*     ImageObjectBase
*     ImageIcon
*     ImageButton
*     SimpleControl
*     VisibleControl
*     Control
* Pre-existing objects modified in this file:
*     Utils
* Enumerators included in this file:
*     Direction
*     VerticalAlignment
*     HorizontalAlignment
*     ContentAlignment
*     BorderStyle
*     FontStyle
*     FontVariant
*     FontWeight
*     BackgroundRepeat
*     BackgroundAttachment
*     BackgroundPosition
* This file requires the use of the following files:
*     base.js
**/
Utils.GetBrowserSize = function()
{
	var v_size = new Size(0, 0);
	if(Utils.IsIE) // IE
	{
		v_size.Width = document.documentElement.clientWidth <= 0 ? document.body.clientWidth : document.documentElement.clientWidth;
		v_size.Height = document.documentElement.clientHeight <= 0 ? document.body.clientHeight : document.documentElement.clientHeight;
	}
	else // Mozilla browsers.
	{
	    v_size.Width = Utils.GetIntValue(window.innerWidth);
	    v_size.Height = Utils.GetIntValue(window.innerHeight);
	}
	return v_size;
}
Utils.GetBrowserSizeWithScoll = function()
{
    var v_size = new Size(0, 0);
    if (window.innerHeight && window.scrollMaxY) // Firefox 
    {
        v_size.Width = window.innerWidth + window.scrollMaxX;
        v_size.Height = window.innerHeight + (window.scrollMaxY > 0 ? window.scrollMaxY : 0);
    }
    else if (document.body.scrollHeight >= document.body.offsetHeight) // all but Explorer Mac
    {
        v_size.Width = (document.documentElement.clientWidth > document.body.scrollWidth) ? document.documentElement.clientWidth : document.body.scrollWidth;
        v_size.Height = (document.documentElement.clientHeight > document.body.scrollHeight) ? document.documentElement.clientHeight : document.body.scrollHeight;
    }
    else // works in Explorer 6 Strict, Mozilla (not FF) and Safari
    {
        v_size.Width = document.body.offsetWidth + document.body.offsetLeft;
        v_size.Height = document.body.offsetHeight + document.body.offsetTop;
    }
    return v_size;
}
Utils.GetMouseLocation = function(e)
{
	var v_loc = new Point(0, 0);
	if(e.pageX || e.pageY)
	{
		v_loc.X = e.pageX;
		v_loc.Y = e.pageY;
	}
	else if(e.clientX || e.clientY)
	{
		if(document.body.scrollLeft || document.body.scrollTop)
		{
			v_loc.X = e.clientX + document.body.scrollLeft;
			v_loc.Y = e.clientY + document.body.scrollTop;
		}
		else
		{
			v_loc.X = e.clientX + document.documentElement.scrollLeft;
			v_loc.Y = e.clientY + document.documentElement.scrollTop;
		}
	}
	return v_loc;
}
Utils.GetElementSize = function(p_elementId)
{
	var v_size = new Size(0, 0);
	var v_element = $(p_elementId);
	if (v_element == null)
	{
	    throw new Error('Element with ID of "' + p_elementId + '" does not exist!');
	}
	if(Utils.IsIE)
	{
		v_size.Width = Utils.GetIntValue(v_element.offsetWidth);
		v_size.Height = Utils.GetIntValue(v_element.offsetHeight);
	}
	else
	{
		var v_cs = document.defaultView.getComputedStyle(v_element, '');
		var v_tmp = v_cs.getPropertyValue('width');
		v_size.Width = Utils.GetIntValue(v_tmp.split('px')[0]);
		v_tmp = v_cs.getPropertyValue('height');
		v_size.Height = Utils.GetIntValue(v_tmp.split('px')[0]);
	}
	return v_size;
}
Utils.GetElementBounds = function(p_elementIdOrElement)
{
	var v_bounds = new Rectangle(0, 0, 0, 0);
	var v_element = null;
	if(TypeOf(p_elementIdOrElement) == 'String')
	{
	    v_element = $(p_elementIdOrElement);
	    if (v_element == null)
	    {
	        throw new Error('Element with ID of "' + p_elementIdOrElement + '" does not exist!');
	    }
	}
	else
	{
	    if (p_elementIdOrElement == null)
	    {
	        throw new Error('p_elementIdOrElement is null!');
	    }
	    v_element = p_elementIdOrElement;
	}
	
	v_bounds.X = Utils.GetIntValue(v_element.offsetLeft);
	v_bounds.Y = Utils.GetIntValue(v_element.offsetTop);
	v_bounds.Width = Utils.GetIntValue(v_element.offsetWidth);
	v_bounds.Height = Utils.GetIntValue(v_element.offsetHeight);
	return v_bounds;
}
Utils.GetPageScrollOffest = function()
{
    return Utils.IsIE ? new Point(document.documentElement.scrollLeft <= 0 ? document.body.scrollLeft : document.documentElement.scrollLeft, document.documentElement.scrollTop <= 0 ? document.body.scrollTop : document.documentElement.scrollTop) : new Point(window.pageXOffset, window.pageYOffset);
}
Utils._ToolTipDiv = null;
Utils._ToolTipHideDelayTimer = null;
Utils.ShowToolTipAt = function(p_elementId, p_classNameOrOptions, p_x, p_y, p_displayTime)
{
    var v_element = $(p_elementId);
    if (v_element == null)
    {
        throw new Error('Element with ID of "' + p_elementId + '" does not exist!');
    }
    Utils.ShowToolTipTextAt(v_element.innerHTML, p_classNameOrOptions, p_x, p_y, p_displayTime);
    return;
}
Utils.ShowToolTipTextAt = function(p_text, p_classNameOrOptions, p_x, p_y, p_displayTime)
{
    p_x = TypeOf(p_x) != 'Number' ? 0 : p_x;
    p_y = TypeOf(p_y) != 'Number' ? 0 : p_y;
    p_displayTime = TypeOf(p_displayTime) != 'Number' ? 0 : p_displayTime;
    if (Utils._ToolTipDiv == null)
    {
        Utils._ToolTipDiv = document.createElement('div');
        Utils._ToolTipDiv.setAttribute('id', 'utils_tooltip_div');
        document.body.insertBefore(Utils._ToolTipDiv, document.body.firstChild);
    }
    Utils._ToolTipDiv.innerHTML = p_text;
    if (TypeOf(p_classNameOrOptions) == 'String')
    {
        Utils._ToolTipDiv.className = p_classNameOrOptions;
    }
    else
    {
        Utils.SetDomFromOptions(Utils._ToolTipDiv, p_classNameOrOptions);
    }
    Utils._ToolTipDiv.style.display = 'block';
    Utils._ToolTipDiv.style.position = 'absolute';
    Utils._ToolTipDiv.style.zIndex = 9999;
    var v_browser_size = Utils.GetBrowserSize();
    var v_element_size = Utils.GetElementSize('utils_tooltip_div');
    var v_scroll_offset = Utils.GetPageScrollOffest();
    Utils._ToolTipDiv.style.left = p_x + v_element_size.Width > v_browser_size.Width + v_scroll_offset.X ? (p_x - 5 - v_element_size.Width).ToCssString() : p_x.ToCssString();
    // TODO: fix the "infinite loop" that seems to be caused by the following code in Mozilla based browsers.
    Utils._ToolTipDiv.style.top = Utils.IsIE && p_y + v_element_size.Height > v_browser_size.Height + v_scroll_offset.Y ? (p_y - 23 - v_element_size.Height).ToCssString() : p_y.ToCssString();
    // End bug fix TODO.
    if (p_displayTime > 0)
    {
        Utils._ToolTipHideDelayTimer = setTimeout('Utils._InternalToolTipHide();', p_displayTime);
    }
    return;
}
Utils.ShowToolTipText = function(p_event, p_text, p_classNameOrOptions, p_displayTime, p_xOffset, p_yOffset)
{
	p_xOffset = TypeOf(p_xOffset) != 'Number' ? 0 : p_xOffset;
	p_yOffset = TypeOf(p_yOffset) != 'Number' ? 0 : p_yOffset;
	var v_mouse_loc = Utils.GetMouseLocation(p_event);
	Utils.ShowToolTipTextAt(p_text, p_classNameOrOptions, v_mouse_loc.X + p_xOffset, v_mouse_loc.Y + p_yOffset + 18, p_displayTime);
	return;
}
Utils.ShowToolTip = function(p_event, p_elementId, p_classNameOrOptions, p_displayTime, p_xOffset, p_yOffset)
{
    var v_element = $(p_elementId);
    if (v_element == null)
    {
        throw new Error('Element with ID of "' + p_elementId + '" does not exist!');
    }
    Utils.ShowToolTipText(p_event, v_element.innerHTML, p_classNameOrOptions, p_displayTime, p_xOffset, p_yOffset);
    return;
}
Utils.HideToolTip = function(p_delay)
{
	if(Utils._ToolTipHideDelayTimer != null)
	{
		clearTimeout(Utils._ToolTipHideDelayTimer);
		Utils._ToolTipHideDelayTimer = null;
	}
	p_delay = TypeOf(p_delay) != 'Number' ? 0 : p_delay;
	if (p_delay > 0)
	{
	    setTimeout('Utils._InternalToolTipHide();', p_delay);
	}
	else
	{
	    Utils._InternalToolTipHide();
	}
	return;
}
Utils._InternalToolTipHide = function()
{
	Utils._ToolTipMouseYOffset = 0;
	if(Utils._ToolTipDiv != null)
	{
		document.body.removeChild(Utils._ToolTipDiv);
		Utils._ToolTipDiv = null;
		Utils._ToolTipCurrentVisible = null;
	}
	return;
}
Utils.GetElementsByClassName = function getElementsByClass(p_className, p_node)
{
    var classElements = [];
    if (p_node == null)
    {
        p_node = document;
    }
    if (p_node.getElementsByClassName)
    {
        var tempCollection = p_node.getElementsByClassName(p_className);
        for (var i = 0; i < tempCollection.length; i++)
        {
            classElements.push(tempCollection[i]);
        }
    }
    else
    {
        var els = p_node.getElementsByTagName('*');
        var elsLen = els.length;
        var pattern = new RegExp('(^|\\s)' + p_className + '(\\s|$)');
        for (var i = 0; i < elsLen; i++)
        {
            if (pattern.test(els[i].className))
            {
                classElements.push(els[i]);
            }
        }
    }
    return classElements;
}
Utils.HasClass = function(p_element, p_class)
{
    return p_element.className.match(new RegExp('(\\s|^)' + p_class + '(\\s|$)'));
}
Utils.AddClass = function(p_element, p_class)
{
    if (!Utils.HasClass(p_element, p_class))
    {
        p_element.className += ' ' + p_class;
    }
    return;
}
Utils.RemoveClass = function(p_element, p_class)
{
    if (Utils.HasClass(p_element, p_class))
    {
        p_element.className = p_element.className.replace(new RegExp('(\\s|^)' + p_class + '(\\s|$)'), ' ');
    }
    return;
}
Utils.SetDomFromOptions = function(p_element, p_options)
{
    if (p_options == null || p_options == undefined)
    {
        return;
    }
    if (TypeOf(p_options.CssClassName) == 'String')
    {
        p_element.className = p_options.CssClassName;
    }
    if (TypeOf(p_options.Size) == 'Size')
    {
        if (p_options.Size.Width > 0)
        {
            p_element.style.width = p_options.Size.Width;
        }
        if (p_options.Size.Height > 0)
        {
            p_element.style.height = p_options.Size.Height;
        }
    }
    else
    {
        if (TypeOf(p_options.Width) == 'Number' && p_options.Width > 0)
        {
            p_element.style.width = p_options.Width.ToCssString();
        }
        else if (TypeOf(p_options.Width) == 'String')
        {
            p_element.style.width = p_options.Width;
        }
        if (TypeOf(p_options.Height) == 'Number' && p_options.Height > 0)
        {
            p_element.style.height = p_options.Height.ToCssString();
        }
        else if (TypeOf(p_options.Height) == 'String')
        {
            p_element.style.height = p_options.Height;
        }
    }
    if (TypeOf(p_options.Background) == 'Background')
    {
        p_element.style.background = p_options.Background.ToCssString();
    }
    else if (TypeOf(p_options.Background) == 'String')
    {
        p_element.style.background = p_options.Background;
    }
    if (TypeOf(p_options.Padding) == 'Padding')
    {
        p_element.style.padding = p_options.Padding.ToCssString();
    }
    else if (TypeOf(p_options.Padding) == 'String')
    {
        p_element.style.padding = p_options.Padding;
    }
    if (TypeOf(p_options.Font) == 'Font')
    {
        p_element.style.font = p_options.Font.ToCssString();
    }
    else if (TypeOf(p_options.Font) == 'String')
    {
        p_element.style.font = p_options.Font;
    }
    if (TypeOf(p_options.Border) == 'Border')
    {
        p_element.style.border = p_options.Border.ToCssString();
    }
    else if (TypeOf(p_options.Border) == 'RectangleBorder')
    {
        p_options.Border.SetCssDomProperties(p_element);
    }
    else if (TypeOf(p_options.Border) == 'String')
    {
        p_element.style.border = p_options.Border;
    }
    if (TypeOf(p_options.Opacity) == 'Opacity')
    {
        p_options.Opacity.SetCssDomProperties(p_element);
    }
    else if (TypeOf(p_options.Opacity) == 'Number' || TypeOf(p_options.Opacity) == 'String')
    {
        new Opacity(p_options.Opacity).SetCssDomProperties(p_element);
    }
    if (TypeOf(p_options.ForeColor) == 'String')
    {
        p_element.style.color = p_options.ForeColor;
    }
    if (TypeOf(p_options.TextAlign) == 'Number')
    {
        ContentAlignment.SetCssDomProperties(p_element, p_options.TextAlign);
    }
    else if (TypeOf(p_options.TextAlign) == 'String')
    {
        p_element.style.textAlign = p_options.TextAlign;
    }
    return;
}
/**************************************************************************/
Direction = {};
Direction.Horizontal = 1;
Direction.Vertical = 2;
VerticalAlignment = {};
VerticalAlignment.Top    = 'top';
VerticalAlignment.Middle = 'middle';
VerticalAlignment.Bottom = 'bottom';
HorizontalAlignment = {};
HorizontalAlignment.Left   = 'left';
HorizontalAlignment.Center = 'center';
HorizontalAlignment.Right  = 'right';
ContentAlignment = {};
ContentAlignment.BottomCenter = 1;
ContentAlignment.BottomLeft   = 2;
ContentAlignment.BottomRight  = 3;
ContentAlignment.MiddleCenter = 4;
ContentAlignment.MiddleLeft   = 5;
ContentAlignment.MiddleRight  = 6;
ContentAlignment.TopCenter    = 7;
ContentAlignment.TopLeft      = 8;
ContentAlignment.TopRight     = 9;
ContentAlignment.CreateCssString = function(p_contentAlignment)
{
	if(!p_contentAlignment) { throw new Error('p_contentAlignment is not a valid value!'); }

	switch(p_contentAlignment)
	{
		case ContentAlignment.BottomCenter: return 'text-align: center; vertical-align: bottom;'; break;
		case ContentAlignment.BottomLeft:   return 'text-align: left; vertical-align: bottom;'; break;
		case ContentAlignment.BottomRight:  return 'text-align: right; vertical-align: bottom;'; break;
		case ContentAlignment.MiddleCenter: return 'text-align: center; vertical-align: middle;'; break;
		case ContentAlignment.MiddleLeft:   return 'text-align: left; vertical-align: middle;'; break;
		case ContentAlignment.MiddleRight:  return 'text-align: right; vertical-align: middle;'; break;
		case ContentAlignment.TopCenter:    return 'text-align: center; vertical-align: top;'; break;
		case ContentAlignment.TopLeft:      return 'text-align: left; vertical-align: top;'; break;
		case ContentAlignment.TopRight:     return 'text-align: right; vertical-align: top;'; break;
		default: throw new Error('p_contentAlignment is not a regonized value.'); break;
	}
	return '';
}
ContentAlignment.SetCssDomProperties = function(p_element, p_contentAlignment)
{
	if(!p_element) { throw new Error('p_element is null!'); }
	if(!p_contentAlignment) { throw new Error('p_contentAlignment is not a valid value!'); }

	switch(p_contentAlignment)
	{
		case ContentAlignment.BottomCenter:
			p_element.style.textAlign = 'center';
			p_element.style.verticalAlign = 'bottom';
			break;
		case ContentAlignment.BottomLeft:
			p_element.style.textAlign = 'left';
			p_element.style.verticalAlign = 'bottom';
			break;
		case ContentAlignment.BottomRight:
			p_element.style.textAlign = 'right';
			p_element.style.verticalAlign = 'bottom';
			break;
		case ContentAlignment.MiddleCenter:
			p_element.style.textAlign = 'center';
			p_element.style.verticalAlign = 'middle';
			break;
		case ContentAlignment.MiddleLeft:
			p_element.style.textAlign = 'left';
			p_element.style.verticalAlign = 'middle';
			break;
		case ContentAlignment.MiddleRight:
			p_element.style.textAlign = 'right';
			p_element.style.verticalAlign = 'middle';
			break;
		case ContentAlignment.TopCenter:
			p_element.style.textAlign = 'center';
			p_element.style.verticalAlign = 'top';
			break;
		case ContentAlignment.TopLeft:
			p_element.style.textAlign = 'left';
			p_element.style.verticalAlign = 'top';
			break;
		case ContentAlignment.TopRight:
			p_element.style.textAlign = 'right';
			p_element.style.verticalAlign = 'top';
			break;
		default:
			p_element.style.textAlign = '';
			p_element.style.verticalAlign = '';
			throw new Error('p_contentAlignment is not a regonized value.');
			break;
	}
	return;
}
/**************************************************************************/
function OptionBase()
{
    return;
}
OptionBase.prototype.LoadOptions = function(p_options)
{
    if (p_options == undefined || p_options == null)
    {
        return;
    }
    for (var v_option_name in p_options)
    {
        if (v_option_name != 'ToString' && v_option_name != 'GetHashCode' && v_option_name != 'SetValue')
        {
            if (this[v_option_name] != undefined && this[v_option_name] != null && typeof (this[v_option_name].LoadOptions) == 'function')
            {
                this[v_option_name].LoadOptions(p_options[v_option_name]);
            }
            else
            {
                this[v_option_name] = p_options[v_option_name];
            }
        }
    }
    return;
}
/**************************************************************************/
function Padding(p_allOrTop, p_right, p_bottom, p_left)
{
	this.Top    = 0;
	this.Right  = 0;
	this.Bottom = 0;
	this.Left   = 0;
	this.Set(p_allOrTop, p_right, p_bottom, p_left);
	return;
}
Extend(Padding, OptionBase);
Padding.prototype.Set = function(p_allOrTop, p_right, p_bottom, p_left)
{
	if((TypeOf(p_allOrTop) == 'Number' || TypeOf(p_allOrTop) == 'String')
		&& !(TypeOf(p_right) == 'Number' || TypeOf(p_right) == 'String')
		&& !(TypeOf(p_bottom) == 'Number' || TypeOf(p_bottom) == 'String')
		&& !(TypeOf(p_left) == 'Number' || TypeOf(p_left) == 'String'))
	{
		this.Top = this.Right = this.Bottom = this.Left = Utils.GetIntValue(p_allOrTop);
	}
	else if((TypeOf(p_allOrTop) == 'Number' || TypeOf(p_allOrTop) == 'String')
		&& (TypeOf(p_right) == 'Number' || TypeOf(p_right) == 'String')
		&& (TypeOf(p_bottom) == 'Number' || TypeOf(p_bottom) == 'String')
		&& (TypeOf(p_left) == 'Number' || TypeOf(p_left) == 'String'))
	{
		this.Top    = Utils.GetIntValue(p_allOrTop);
		this.Right  = Utils.GetIntValue(p_right);
		this.Bottom = Utils.GetIntValue(p_bottom);
		this.Left   = Utils.GetIntValue(p_left);
	}
	return;
}
Padding.prototype.ToCssString = function() { return this.Top.ToCssString() + ' ' + this.Right.ToCssString() + ' ' + this.Bottom.ToCssString() + ' ' + this.Left.ToCssString(); }
Padding.prototype.toString = function() { return this.ToString(); }
Padding.prototype.ToString = function() { return '[top=' + this.Top.toString() + ',right=' + this.Right.toString() + ',bottom=' + this.Bottom.toString() + ',left=' + this.Left.toString() + ']'; }
Padding.prototype.GetType = function() { return 'Padding'; }
Padding.prototype.GetHashCode = function() { return this.Top + this.Right + this.Bottom + this.Left; }
Padding.prototype.CopyTo = function(p_value) { p_value.Set(this.Top, this.Right, this.Bottom, this.Left); return; }
/**************************************************************************/
BorderStyle = {}
BorderStyle.None   = 'none';
BorderStyle.Hidden = 'hidden';
BorderStyle.Dotted = 'dotted';
BorderStyle.Dashed = 'dashed';
BorderStyle.Solid  = 'solid';
BorderStyle.Double = 'double';
BorderStyle.Groove = 'groove';
BorderStyle.Ridge  = 'ridge';
BorderStyle.Inset  = 'inset';
BorderStyle.Outset = 'outset';
function Border(p_width, p_style, p_color)
{
	this.Width = 0;
	this.Style = BorderStyle.Solid;
	this.Color = '#000000';
	this.Set(p_width, p_style, p_color);
	return;
}
Extend(Border, OptionBase);
Border.prototype.Set = function(p_width, p_style, p_color)
{
	if(TypeOf(p_width) == 'Number' || TypeOf(p_width) == 'String') { this.Width = Utils.GetIntValue(p_width); }
	if(p_style) { this.Style = p_style; }
	if(p_color) { this.Color = p_color; }
	return;
}
Border.prototype.ToCssString = function() { return this.Width.ToCssString() + ' ' + this.Style + ' ' + this.Color; }
Border.prototype.toString = function() { return this.ToString(); }
Border.prototype.ToString = function() { return '[width=' + this.Width.toString() + ',style=' + this.Style + ',color=' + this.Color + ']'; }
Border.prototype.GetType = function() { return 'Border'; }
Border.prototype.GetHashCode = function() { return this.Width.toString() + this.Style + this.Color; }
Border.prototype.CopyTo = function(p_value) { p_value.Set(this.Width, this.Style, this.Color); return; }
/**************************************************************************/
function RectangleBorder(p_width, p_style, p_color)
{
	this.Top    = new Border(p_width, p_style, p_color);
	this.Bottom = new Border(p_width, p_style, p_color);
	this.Left   = new Border(p_width, p_style, p_color);
	this.Right  = new Border(p_width, p_style, p_color);
	return;
}
Extend(RectangleBorder, OptionBase);
RectangleBorder.prototype.Set = function(p_width, p_style, p_color)
{
	this.Top.Set(p_width, p_style, p_color);
	this.Bottom.Set(p_width, p_style, p_color);
	this.Left.Set(p_width, p_style, p_color);
	this.Right.Set(p_width, p_style, p_color);
	return;
}
RectangleBorder.prototype.SetCssDomProperties = function(p_element)
{
	p_element.style.borderTop    = this.Top.ToCssString();
	p_element.style.borderBottom = this.Bottom.ToCssString();
	p_element.style.borderLeft   = this.Left.ToCssString();
	p_element.style.borderRight  = this.Right.ToCssString();
	return;
}
RectangleBorder.prototype.LoadOptions = function(p_options)
{
    if (p_options != undefined && p_options != null)
    {
        if (p_options['Width'] != undefined || p_options['Style'] != undefined || p_options['Color'] != undefined)
        {
            this.Set(p_options['Width'], p_options['Style'], p_options['Color']);
            return;
        }
        RectangleBorder.superClass.LoadOptions.call(this, p_options);
    }
    return;
}
RectangleBorder.prototype.ToCssString = function() { return 'border-top: ' + this.Top.ToCssString() + '; border-bottom: ' + this.Bottom.ToCssString() + '; border-left: ' + this.Left.ToCssString() + '; border-right: ' + this.Right.ToCssString() + ';'; }
RectangleBorder.prototype.toString = function() { return this.ToString(); }
RectangleBorder.prototype.ToString = function() { return 'Top=' + this.Top.ToString() + '\nBottom=' + this.Bottom.ToString() + '\nLeft=' + this.Left.ToString() + '\nRight=' + this.Right.ToString(); }
RectangleBorder.prototype.GetType = function() { return 'RectangleBorder'; }
RectangleBorder.prototype.GetHashCode = function() { return this.Top.GetHashCode() + this.Right.GetHashCode() + this.Bottom.GetHashCode() + this.Left.GetHashCode(); }
RectangleBorder.prototype.CopyTo = function(p_value) { this.Top.CopyTo(p_value.Top); this.Bottom.CopyTo(p_value.Bottom); this.Left.CopyTo(p_value.Left); this.Right.CopyTo(p_value.Right); return; }
/**************************************************************************/
FontStyle = {}
FontStyle.Normal  = 'normal';
FontStyle.Italic  = 'italic';
FontStyle.Oblique = 'oblique';
FontVariant = {}
FontVariant.Normal    = 'normal';
FontVariant.SmallCaps = 'small-caps';
FontWeight = {}
FontWeight.Normal  = 'normal';
FontWeight.Bold    = 'bold';
FontWeight.Bolder  = 'bolder';
FontWeight.Lighter = 'lighter';
function Font(p_family, p_size, p_weight, p_style, p_variant)
{
	this.Family  = 'verdana';
	this.Size    = '12px';
	this.Style   = FontStyle.Normal;
	this.Variant = FontVariant.Normal;
	this.Weight  = FontWeight.Normal;
	this.Set(p_family, p_size, p_weight, p_style, p_variant);
	return;
}
Extend(Font, OptionBase);
Font.prototype.Set = function(p_family, p_size, p_weight, p_style, p_variant)
{
	if(p_family) { this.Family = p_family; }
	if(p_size) { this.Size = p_size; }
	if(p_style) { this.Style = p_style; }
	if(p_variant) { this.Variant = p_variant; }
	if(p_weight) { this.Weight = p_weight; }
	return;
}
Font.prototype.ToCssString = function() { return this.Style + ' ' + this.Variant + ' ' + this.Weight + ' ' + this.Size + ' ' + this.Family; }
Font.prototype.toString = function() { return this.ToString(); }
Font.prototype.ToString = function() { return '[style=' + this.Style + ',variant=' + this.Variant + ',weight=' + this.Weight + ',size=' + this.Size + ',family=' + this.Family + ']'; }
Font.prototype.GetType = function() { return 'Font'; }
Font.prototype.GetHashCode = function() { return this.Family + this.Size + this.Style + this.Variant + this.Weight; }
Font.prototype.CopyTo = function(p_value) { p_value.Set(this.Family, this.Size, this.Weight, this.Style, this.Variant); return; }
/**************************************************************************/
BackgroundRepeat = {}
BackgroundRepeat.Both       = 'repeat';
BackgroundRepeat.Horizontal = 'repeat-x';
BackgroundRepeat.Vertical   = 'repeat-y';
BackgroundRepeat.None       = 'no-repeat';
BackgroundAttachment = {}
BackgroundAttachment.Scroll = 'scroll';
BackgroundAttachment.Fixed  = 'fixed';
BackgroundPosition = {}
BackgroundPosition.TopLeft      = 'top left';
BackgroundPosition.TopMiddle    = 'top center';
BackgroundPosition.TopRight     = 'top right';
BackgroundPosition.MiddleLeft   = 'center left';
BackgroundPosition.Middle       = 'center center';
BackgroundPosition.MiddleRight  = 'center right';
BackgroundPosition.BottomLeft   = 'bottom left';
BackgroundPosition.BottomMiddle = 'bottom center';
BackgroundPosition.BottomRight  = 'bottom right';
function Background(p_color, p_image, p_repeat, p_position, p_attachment)
{
	this.Color      = 'transparent';
	this.BGImage    = 'none';
	this.Repeat     = BackgroundRepeat.Both;
	this.Position   = BackgroundPosition.TopLeft;
	this.Attachment = BackgroundAttachment.Scroll;
	this.Set(p_color, p_image, p_repeat, p_position, p_attachment);
	return;
}
Extend(Background, OptionBase);
Background.prototype.Set = function(p_color, p_image, p_repeat, p_position, p_attachment)
{
	if(p_color) { this.Color = p_color; }
	if(p_image) { this.BGImage = p_image; }
	if(p_repeat) { this.Repeat = p_repeat; }
	if(p_position) { this.Position = p_position; }
	if(p_attachment) { this.Attachment = p_attachment; }
	return;
}
Background.prototype.ToCssString = function() { return this.Color + ' ' + this.BGImage + ' ' + this.Repeat + ' ' + this.Attachment + ' ' + this.Position; }
Background.prototype.toString = function() { return this.ToString(); }
Background.prototype.ToString = function() { return '[color=' + this.Color + ',image=' + this.BGImage + ',repeat=' + this.Repeat + ',attachment=' + this.Attachment + ',position=' + this.Position + ']'; }
Background.prototype.GetType = function() { return 'Background'; }
Background.prototype.GetHashCode = function() { return this.Color + this.BGImage + this.Repeat + this.Position + this.Attachment; }
Background.prototype.CopyTo = function(p_value) { p_value.Set(this.Color, this.BGImage, this.Repeat, this.Position, this.Attachment); return; }
/**************************************************************************/
function Size(p_width, p_height)
{
	this.Width  = 0;
	this.Height = 0;
	this.Set(p_width, p_height);
	return;
}
Extend(Size, OptionBase);
Size.prototype.Set = function(p_width, p_height)
{
	if((TypeOf(p_width) == 'Number' || TypeOf(p_width) == 'String') && (TypeOf(p_height) == 'Number' || TypeOf(p_height) == 'String'))
	{
		this.Width  = Utils.GetIntValue(p_width);
		this.Height = Utils.GetIntValue(p_height);
	}
	return;
}
Size.prototype.ToAttributeString = function()
{
	var v_text = '';
	if(this.Width > 0) { v_text += ' width="' + this.Width.toString() + '"'; }
	if(this.Height > 0) { v_text += ' height="' + this.Height.toString() + '"'; }
	return v_text;
}
Size.prototype.ToCssString = function()
{
	var v_text = '';
	if(this.Width > 0) { v_text += ' width: ' + this.Width.ToCssString() + ';'; }
	if(this.Height > 0) { v_text += ' height: ' + this.Height.ToCssString() + ';'; }
	return v_text;
}
Size.prototype.toString = function() { return this.ToString(); }
Size.prototype.ToString = function() { return '[width=' + this.Width.toString() + ',height=' + this.Height.toString() + ']'; }
Size.prototype.GetType = function() { return 'Size'; }
Size.prototype.GetHashCode = function() { return this.Width + this.Height; }
Size.prototype.CopyTo = function(p_value) { p_value.Set(this.Width, this.Height); return; }
/**************************************************************************/
function Point(p_x, p_y)
{
	this.X = 0;
	this.Y = 0;
	this.Set(p_x, p_y);
	return;
}
Extend(Point, OptionBase);
Point.prototype.Set = function(p_x, p_y)
{
	if((TypeOf(p_x) == 'Number' || TypeOf(p_x) == 'String') && (TypeOf(p_y) == 'Number' || TypeOf(p_y) == 'String'))
	{
		this.X = parseInt(p_x);
		this.Y = parseInt(p_y);
	}
	return;
}
Point.prototype.ToCssString = function() { return ' left: ' + this.X.ToCssString() + '; top: ' + this.Y.ToCssString() + ';'; }
Point.prototype.toString = function() { return this.ToString(); }
Point.prototype.ToString = function() { return '(' + this.X.toString() + ',' + this.Y.toString() + ')'; }
Point.prototype.GetType = function() { return 'Point'; }
Point.prototype.GetHashCode = function() { return this.X + this.Y; }
Point.prototype.CopyTo = function(p_value) { p_value.Set(this.X, this.Y); return; }
/**************************************************************************/
function Rectangle(p_x, p_y, p_width, p_height)
{
	this.X      = 0;
	this.Y      = 0;
	this.Width  = 0;
	this.Height = 0;
	this.Set(p_x, p_y, p_width, p_height);
	return;
}
Extend(Rectangle, OptionBase);
Rectangle.prototype.Set = function(p_x, p_y, p_width, p_height)
{
	if((TypeOf(p_x) == 'Number' || TypeOf(p_x) == 'String') && (TypeOf(p_y) == 'Number' || TypeOf(p_y) == 'String') && (TypeOf(p_width) == 'Number' || TypeOf(p_width) == 'String') && (TypeOf(p_height) == 'Number' || TypeOf(p_height) == 'String'))
	{
		this.X      = parseInt(p_x);
		this.Y      = parseInt(p_y);
		this.Width  = Utils.GetIntValue(p_width);
		this.Height = Utils.GetIntValue(p_height);
	}
	return;
}
Rectangle.prototype.SetSize = function(p_sizeOrWidth, p_height)
{
	if(TypeOf(p_sizeOrWidth) == 'Number') { this.Set(this.X, this.Y, p_sizeOrWidth, p_height); }
	else if(TypeOf(p_sizeOrWidth) == 'Size') { this.Set(this.X, this.Y, p_sizeOrWidth.Width, p_sizeOrWidth.Height); }
	else { throw new Error('p_sizeOrWidth is not a valid value.'); }
	return;
}
Rectangle.prototype.SetLocation = function(p_pointOrX, p_y)
{
	if(TypeOf(p_pointOrX) == 'Number') { this.Set(p_pointOrX, p_y, this.Width, this.Height); }
	else if(TypeOf(p_pointOrX) == 'Point') { this.Set(p_pointOrX.X, p_pointOrX.Y, this.Width, this.Height); }
	else { throw new Error('p_pointOrX is not a valid value.'); } 
	return;
}
Rectangle.prototype.Size     = function() { return new Size(this.Width, this.Height); }
Rectangle.prototype.Location = function() { return new Point(this.X, this.Y); }
Rectangle.prototype.Top      = function() { return this.Y; }
Rectangle.prototype.Bottom   = function() { return this.Y + this.Height; }
Rectangle.prototype.Left     = function() { return this.X; }
Rectangle.prototype.Right    = function() { return this.X + this.Width; }
Rectangle.prototype.ContainsPoint = function(p_x, p_y) { return (this.X <= p_x) && (p_x < this.X + this.Width) && (this.Y <= p_y) && (p_y < this.Y + this.Height); }
Rectangle.prototype.ContainsRectangle = function(p_rectangle) { return (this.X <= p_rectangle.X) && (p_rectangle.X + p_rectangle.Width <= this.X + this.Width) && (this.Y <= p_rectangle.Y) && (p_rectangle.Y + p_rectangle.Height <= this.Y + this.Height); }
Rectangle.prototype.Inflate = function(p_sizeOrWidth, p_height)
{
	if(TypeOf(p_sizeOrWidth) == 'Number')
	{
		this.X -= p_sizeOrWidth;
		this.Y -= p_height;
		this.Width += 2 * p_sizeOrWidth;
		this.Height += 2 * p_height;
	}
	else if(TypeOf(p_sizeOrWidth) == 'Size')
	{
		this.X -= p_sizeOrWidth.Width;
		this.Y -= p_sizeOrWidth.Height;
		this.Width += 2 * p_sizeOrWidth.Width;
		this.Height += 2 * p_sizeOrWidth.Height;
	}
	else { throw new Error('p_sizeOrWidth is not a valid value.'); }
	return;
}
Rectangle.prototype.Offset = function(p_pointOrX, p_y)
{
	if(TypeOf(p_pointOrX) == 'Number')
	{
		this.X += p_pointOrX;
		this.Y += p_y;
	}
	else if(TypeOf(p_sizeOrWidth) == 'Point')
	{
		this.X += p_pointOrX.X;
		this.Y += p_pointOrX.Y;
	}
	else { throw new Error('p_pointOrX is not a valid value.'); }
	return;
}
Rectangle.prototype.Intersect = function(p_rectangle)
{
	var v_x = Math.max(this.X, p_rectangle.X);
	var v_w = Math.min(this.X + this.Width, p_rectangle.X + p_rectangle.Width);
	var v_y = Math.max(this.Y, p_rectangle.Y);
	var v_h = Math.min(this.Y + this.Height, p_rectangle.Y + p_rectangle.Height);
	if(v_w >= v_x && v_h >= v_y) { this.Set(v_x, v_y, v_w - v_x, v_h - v_y); }
	this.Set(0, 0, 0, 0);
	return;
}
Rectangle.prototype.IntersectsWith = function(value)
{
    return (value.X < this.X + this.Width)
        && (this.X < value.X + value.Width)
        && (value.Y < this.Y + this.Height)
        && (this.Y < value.Y + value.Height);
}
Rectangle.prototype.ToCssString = function()
{
	var v_text = '';
	v_text += ' left: ' + this.X.ToCssString() + ';';
	v_text += ' top: ' + this.Y.ToCssString() + ';';
	if(this.Width > 0) { v_text += ' width: ' + this.Width.ToCssString() + ';'; }
	if(this.Height > 0) { v_text += ' height: ' + this.Height.ToCssString() + ';'; }
	return v_text;
}
Rectangle.prototype.toString = function() { return this.ToString(); }
Rectangle.prototype.ToString = function() { return '{X=' + this.X.toString() + ',Y=' + this.Y.toString() + ',Width=' + this.Width.toString() + ',Height=' + this.Height.toString() + '}'; }
Rectangle.prototype.GetType = function() { return 'Rectangle'; }
Rectangle.prototype.GetHashCode = function() { return this.X + this.Y + this.Width + this.Height; }
Rectangle.prototype.CopyTo = function(p_value) { p_value.Set(this.X, this.Y, this.Width, this.Height); return; }
/**************************************************************************/
function Opacity(p_percent)
{
	this.Percent = 0;
	this.Set(p_percent);
	return;
}
Extend(Opacity, OptionBase);
Opacity.prototype.Set = function(p_percent)
{
    if (TypeOf(p_percent) == 'Number' || TypeOf(p_percent) == 'String')
    {
        this.Percent = (parseInt(p_percent) > 0 && parseFloat(p_percent) <= 1) ? (parseInt(p_percent) / 100) : parseFloat(p_percent);
        this.Percent = this.Percent > 100 ? 100 : this.Percent;
        this.Percent = this.Percent < 0 ? 0 : this.Percent;
    }
    return;
}
Opacity.prototype.ToCssString = function()
{
    if (Utils.IsIE)
    {
        return 'alpha(opacity = ' + (this.Percent * 100).toString() + ')';
    }
    return this.Percent.toString();
}
Opacity.prototype.SetCssDomProperties = function(p_element)
{
    if (Utils.IsIE)
    {
        p_element.style.filter = this.ToCssString();
    }
    else
    {
        p_element.style.opacity = this.ToCssString();
    }
    return;
}
Opacity.prototype.toString = function() { return this.ToString(); }
Opacity.prototype.ToString = function() { return this.Percent.toString(); }
Opacity.prototype.GetType = function() { return 'Opacity'; }
Opacity.prototype.GetHashCode = function() { return this.Percent; }
Opacity.prototype.CopyTo = function(p_value) { p_value.Set(this.Percent); return; }
/**************************************************************************/
function BasicEventObjectBase()
{
	this.Click       = null;
	this.DoubleClick = null;
	this.MouseDown   = null;
	this.MouseUp     = null;
	this.MouseOver   = null;
	this.MouseMove   = null;
	this.MouseOut    = null;
	this.KeyPress    = null;
	this.KeyDown     = null;
	this.KeyUp       = null;
	return;
}
Extend(BasicEventObjectBase, OptionBase);
BasicEventObjectBase.prototype.ToString = function() { return this.GetType(); }
BasicEventObjectBase.prototype.toString = function() { return this.ToString(); }
BasicEventObjectBase.prototype.GetType = function() { return 'BasicEventObjectBase'; }
BasicEventObjectBase.prototype.GetHashCode = function() { return ''; }
BasicEventObjectBase.prototype.OnClick = function(e, p_element) { if(this.Click) { this.Click(e, this); } return; }
BasicEventObjectBase.prototype.OnDoubleClick = function(e, p_element) { if(this.DoubleClick) { this.DoubleClick(e, this); } return; }
BasicEventObjectBase.prototype.OnMouseDown = function(e, p_element) { if(this.MouseDown) { this.MouseDown(Utils.GetMouseLocation(e), e, this); } return; }
BasicEventObjectBase.prototype.OnMouseUp = function(e, p_element) { if(this.MouseUp) { this.MouseUp(Utils.GetMouseLocation(e), e, this); } return; }
BasicEventObjectBase.prototype.OnMouseOver = function(e, p_element) { if(this.MouseOver) { this.MouseOver(e, this); } return; }
BasicEventObjectBase.prototype.OnMouseMove = function(e, p_element) { if(this.MouseMove) { this.MouseMove(Utils.GetMouseLocation(e), e, this); } return; }
BasicEventObjectBase.prototype.OnMouseOut = function(e, p_element) { if(this.MouseOut) { this.MouseOut(e, this); } return; }
BasicEventObjectBase.prototype.OnKeyPress = function(e, p_element) { if(this.KeyPress) { this.KeyPress(e, this); } return; }
BasicEventObjectBase.prototype.OnKeyDown = function(e, p_element) { if(this.KeyDown) { this.KeyDown(e, this); } return; }
BasicEventObjectBase.prototype.OnKeyUp = function(e, p_element) { if(this.KeyUp) { this.KeyUp(e, this); } return; }
/**************************************************************************/
function ImageObjectBase(p_visible, p_titleText, p_altText, p_cursor, p_id)
{
	ImageObjectBase.baseConstructor.call(this);
	this.Id        = String(p_id);
	this.Visible   = p_visible;
	this.Size      = new Size(0, 0);
	this.AltText   = String(p_altText);
	this.TitleText = String(p_titleText);
	this.Cursor    = String(p_cursor);
	this.Padding   = new Padding(0, 0, 0, 0);
	this.Parent    = null;
	return;
}
Extend(ImageObjectBase, BasicEventObjectBase);
ImageObjectBase.prototype.SetCursor = function(p_cursor)
{
	if(TypeOf(p_cursor) != 'String') { throw new Error('p_cursor is not a string!'); }
	this.Cursor = p_cursor;
	if(this.Visible)
	{
	    var v_element = document.getElementById(this.Id);
	    if(v_element == null) { throw new Error('Element with an ID of "' + this.Id + '" does not exist!'); }
	    v_element.style.cursor = this.Cursor;
	}
	return;
}
ImageObjectBase.prototype.Refresh = function()
{
	if(this.Visible == true && this.Id && this.Id.length > 0)
	{
		var v_element = document.getElementById(this.Id);
		if(v_element != null)
		{
			this.RefreshImageObject(v_element);
		}
	}
	return;
}
ImageObjectBase.prototype.Render = function(p_renderElementId, p_onClick, p_onDoubleClick, p_onMouseDown, p_onMouseUp, p_onMouseOver, p_onMouseMove, p_onMouseOut, p_onKeyPress, p_onKeyDown, p_onKeyUp)
{
	var v_element = document.getElementById(p_renderElementId);
	if(v_element != null)
	{
		v_element.innerHTML = this.GetRenderHtml(p_onClick, p_onDoubleClick, p_onMouseDown, p_onMouseUp, p_onMouseOver, p_onMouseMove, p_onMouseOut, p_onKeyPress, p_onKeyDown, p_onKeyUp);
	}
	else
	{
		throw new Error('ImageObjectBase.Render() -> NULL render element!');
	}
	return;
}
ImageObjectBase.prototype.ToString = function() { return this.GetRenderHtml(); }
ImageObjectBase.prototype.GetType = function() { return 'ImageObjectBase'; }
ImageObjectBase.prototype.GetHashCode = function() { return this.Id; }
ImageObjectBase.prototype.RefreshImageObject = function(p_element) { return; }
ImageObjectBase.prototype.GetRenderHtml = function(p_onClick, p_onDoubleClick, p_onMouseDown, p_onMouseUp, p_onMouseOver, p_onMouseMove, p_onMouseOut, p_onKeyPress, p_onKeyDown, p_onKeyUp) { return ''; }
/**************************************************************************/
function ImageIcon(p_icon, p_altText, p_titleText)
{
	ImageIcon.baseConstructor.call(this, false, p_titleText, p_altText, 'default', '');
	this.Icon = !p_icon ? '' : String(p_icon);
	return;
}
Extend(ImageIcon, ImageObjectBase);
ImageIcon.prototype.GetType = function() { return 'ImageIcon'; }
ImageIcon.prototype.GetHashCode = function() { return this.Icon; }
ImageIcon.prototype.RefreshImageObject = function(p_element)
{
	p_element.src = this.Icon;
	p_element.title = this.TitleText;
	p_element.alt = this.AltText;
	if (this.Size.Width > 0)
	    p_element.style.width = this.Size.Width.ToCssString();
	if (this.Size.Height > 0)
	    p_element.style.height = this.Size.Height.ToCssString();
	p_element.style.cursor = this.Cursor;
	p_element.style.padding = this.Padding.ToCssString();
	return;
}
ImageIcon.prototype.GetRenderHtml = function(p_onClick, p_onDoubleClick, p_onMouseDown, p_onMouseUp, p_onMouseOver, p_onMouseMove, p_onMouseOut, p_onKeyPress, p_onKeyDown, p_onKeyUp)
{
	var v_sb = new StringBuilder();
	if(this.Visible == true && this.Icon != null)
	{
		v_sb.Append('<img src="').Append(this.Icon).Append('" border="0" alt="').Append(this.AltText).Append('" title="').Append(this.TitleText).Append('"')
			.Append(this.Size.ToAttributeString())
			.Append(Utils.CreateAttributeString('onclick', p_onClick))
			.Append(Utils.CreateAttributeString('ondblclick', p_onDoubleClick))
			.Append(Utils.CreateAttributeString('onmousemove', p_onMouseMove))
			.Append(Utils.CreateAttributeString('onkeypress', p_onKeyPress))
			.Append(Utils.CreateAttributeString('onkeydown', p_onKeyDown))
			.Append(Utils.CreateAttributeString('onkeyup', p_onKeyUp))
			.Append(Utils.CreateAttributeString('onmouseover', p_onMouseOver))
			.Append(Utils.CreateAttributeString('onmouseout', p_onMouseOut))
			.Append(Utils.CreateAttributeString('onmousedown', p_onMouseDown))
			.Append(Utils.CreateAttributeString('onmouseup', p_onMouseUp))
			.Append(Utils.CreateAttributeString('id', this.Id))
			.Append(Utils.CreateAttributeString('style', Utils.CreateCssPropertyString('padding', this.Padding.ToCssString()) + Utils.CreateCssPropertyString('cursor', this.Cursor)))
			.Append(' />');
	}
	return v_sb.ToString();
}
ImageIcon.prototype.CopyTo = function(p_obj)
{
	this.Size.CopyTo(p_obj.Size);
	this.Padding.CopyTo(p_obj.Padding);
	p_obj.Id        = this.Id;
	p_obj.Visible   = this.Visible;
	p_obj.AltText   = this.AltText;
	p_obj.TitleText = this.TitleText;
	p_obj.Cursor    = this.Cursor;
	p_obj.Icon      = this.Icon;
	return;
}
/**************************************************************************/
function ImageButton(p_titleText, p_altText)
{
	ImageButton.baseConstructor.call(this, true, p_titleText, p_altText, 'default', '');
	this.IconNormal = '';
	this.IconHover  = '';
	this.IconClick  = '';
	this._DivFlag   = false;
	return;
}
Extend(ImageButton, ImageObjectBase);
ImageButton.prototype.SetIcons = function(p_normal, p_hover, p_click)
{
	if(p_normal) { this.IconNormal = String(p_normal); }
	if(p_hover) { this.IconHover = String(p_hover); }
	if(p_click) { this.IconClick = String(p_click); }
	return;
}
ImageButton.prototype.GetType = function() { return 'ImageButton'; }
ImageButton.prototype.GetHashCode = function() { return this.IconNormal + this.IconHover + this.IconClick; }
ImageButton.prototype.RefreshImageObject = function(p_element)
{
	if(this._DivFlag == false)
	{
		p_element.src = this.IconNormal;
		p_element.title = this.TitleText;
		p_element.alt = this.AltText;
		p_element.style.cursor = this.Cursor;
		p_element.style.padding = this.Padding.ToCssString();
		if(this.Size.Width > 0)
		{
			p_element.style.width = this.Size.Width.ToCssString();
		}
		if(this.Size.Height > 0)
		{
			p_element.style.height = this.Size.Height.ToCssString();
		}
	}
	else
	{
		p_element.innerHTML = this.AltText;
		p_element.title = this.TitleText;
		p_element.style.cursor = this.Cursor;
		p_element.style.padding = this.Padding.ToCssString();
		if(this.Size.Width > 0)
		{
			p_element.style.width = this.Size.Width.ToCssString();
		}
		if(this.Size.Height > 0)
		{
			p_element.style.height = this.Size.Height.ToCssString();
		}
	}
	return;
}
ImageButton.prototype.GetRenderHtml = function(p_onClick, p_onDoubleClick, p_onMouseDown, p_onMouseUp, p_onMouseOver, p_onMouseMove, p_onMouseOut, p_onKeyPress, p_onKeyDown, p_onKeyUp)
{
	var v_sb = new StringBuilder();
	if(this.Visible == true)
	{
		var v_attributes = (new StringBuilder(Utils.CreateAttributeString('onclick', p_onClick)))
			.Append(Utils.CreateAttributeString('ondblclick', p_onDoubleClick))
			.Append(Utils.CreateAttributeString('onmousemove', p_onMouseMove))
			.Append(Utils.CreateAttributeString('onkeypress', p_onKeyPress))
			.Append(Utils.CreateAttributeString('onkeydown', p_onKeyDown))
			.Append(Utils.CreateAttributeString('onkeyup', p_onKeyUp))
			.Append(Utils.CreateAttributeString('id', this.Id))
			.Append(Utils.CreateAttributeString('style', Utils.CreateCssPropertyString('padding', this.Padding.ToCssString()) + Utils.CreateCssPropertyString('cursor', this.Cursor)));

		if(this.IconNormal != null && this.IconNormal.length > 0)
		{
			this._DivFlag = false;
			v_sb.Append('<img src="').Append(this.IconNormal).Append('" border="0" alt="').Append(this.AltText).Append('" title="').Append(this.TitleText).Append('"')
				.Append(this.Size.ToAttributeString())
				.Append(v_attributes.ToString());
			if(this.IconHover != null && this.IconHover.length > 0)
			{
				v_sb.Append(Utils.CreateAttributeString('onmouseover', 'this.src = \'' + this.IconHover + '\';' + p_onMouseOver))
					.Append(Utils.CreateAttributeString('onmouseout', 'this.src = \'' + this.IconNormal + '\';' + p_onMouseOut));
			}
			else
			{
				v_sb.Append(Utils.CreateAttributeString('onmouseover', p_onMouseOver))
					.Append(Utils.CreateAttributeString('onmouseout', p_onMouseOut));
			}

			if(this.IconClick != null && this.IconClick.length > 0)
			{
				v_sb.Append(Utils.CreateAttributeString('onmousedown', 'this.src = \'' + this.IconClick + '\';' + p_onMouseDown))
					.Append(Utils.CreateAttributeString('onmouseup', 'this.src = \'' + this.IconNormal + '\';' + p_onMouseUp));
			}
			else
			{
				v_sb.Append(Utils.CreateAttributeString('onmousedown', p_onMouseDown))
					.Append(Utils.CreateAttributeString('onmouseup', p_onMouseUp));
			}
			v_sb.Append(' />');
		}
		else
		{
			this._DivFlag = true;
			v_sb.Append('<div title="').Append(this.TitleText).Append('"')
				.Append(v_attributes.ToString())
				.Append(Utils.CreateAttributeString('onmousedown', p_onMouseDown))
				.Append(Utils.CreateAttributeString('onmouseup', p_onMouseUp))
				.Append(Utils.CreateAttributeString('onmouseover', p_onMouseOver))
				.Append(Utils.CreateAttributeString('onmouseout', p_onMouseOut))
				.Append('>').Append(this.AltText).Append('</div>');
		}
	}
	return v_sb.ToString();
}
/**************************************************************************/
function SimpleControl(elementId, instanceName)
{
    SimpleControl.baseConstructor.call(this);
    this.ElementId = String(elementId);
    this.Name = String(instanceName);
    this.Size = this.DefaultSize();
    this.Border = this.DefaultBorder();
    this.Background = this.DefaultBackground();
    this.Padding = this.DefaultPadding();
    this.Font = this.DefaultFont();
    this.ForeColor = this.DefaultForeColor();
    this.Cursor = this.DefaultCursor();
    this.TextAlign = this.DefaultTextAlign();
    this.Text = '';
    this.ToolTipText = '';
    this.CssClassName = '';
    this.Identifier = null;
    this.Parent = null;
    this.IsRendered = false;
    return;
}
Extend(SimpleControl, BasicEventObjectBase);
SimpleControl.prototype.GetType = function()
{
    return 'SimpleControl';
}
SimpleControl.prototype.GetHashCode = function()
{
    return this.Name;
}
SimpleControl.prototype.ToString = function()
{
    return this.Name;
}
SimpleControl.prototype.DefaultSize = function()
{
    return new Size(100, 100);
}
SimpleControl.prototype.DefaultBorder = function()
{
    return new RectangleBorder(1, BorderStyle.Solid, '#000000');
}
SimpleControl.prototype.DefaultBackground = function()
{
    return new Background('#FFFFFF');
}
SimpleControl.prototype.DefaultPadding = function()
{
    return new Padding(0, 0, 0, 0);
}
SimpleControl.prototype.DefaultFont = function()
{
    return new Font('verdana', '12px');
}
SimpleControl.prototype.DefaultForeColor = function()
{
    return '#000000';
}
SimpleControl.prototype.DefaultCursor = function()
{
    return 'default';
}
SimpleControl.prototype.DefaultTextAlign = function()
{
    return ContentAlignment.MiddleCenter;
}
SimpleControl.prototype.Refresh = function()
{
    if (this.IsRendered)
    {
        var v_element = $(this.ElementId);
        v_element.innerHTML = this.Text;
        this.SetCssDomProperties(v_element);
    }
    return;
}
SimpleControl.prototype.Render = function()
{
    var v_element = $(this.ElementId);
    v_element.innerHTML = this.Text;
    this.SetCssDomProperties(v_element);
    this.AttatchEventsToElement(v_element);
    this.IsRendered = true;
    return;
}
SimpleControl.prototype.SetText = function(text)
{
    this.Text = text;
    this.RefreshText();
    return;
}
SimpleControl.prototype.SetTextFromElement = function(elementId, doNotRemove)
{
    var v_element = $(elementId);
    this.Text = v_element.innerHTML;
    if (!doNotRemove)
    {
        v_element.innerHTML = '';
    }
    this.RefreshText();
    return;
}
SimpleControl.prototype.RefreshText = function()
{
    if (this.IsRendered)
    {
        $(this.ElementId).innerHTML = this.Text;
    }
    return;
}
SimpleControl.prototype.SetCursor = function(cursor)
{
    this.Cursor = cursor;
    if (this.IsRendered)
    {
        $(this.ElementId).style.cursor = this.Cursor;
    }
    return;
}
SimpleControl.prototype.SetCssDomProperties = function(element)
{
    this.SetElementSize(element);
    this.Border.SetCssDomProperties(element);
    element.style.background = this.Background.ToCssString();
    element.style.padding = this.Padding.ToCssString();
    element.style.font = this.Font.ToCssString();
    element.style.color = this.ForeColor;
    element.style.cursor = this.Cursor;
    ContentAlignment.SetCssDomProperties(element, this.TextAlign);
	element.title = this.ToolTipText;
	element.className = this.CssClassName;
	return;
}
SimpleControl.prototype.SetElementSize = function(element)
{
    element.style.width = (this.Size.Width > 0) ? this.Size.Width.ToCssString() : '';
    element.style.height = (this.Size.Height > 0) ? this.Size.Height.ToCssString() : '';
	return;
}
SimpleControl.prototype.GetSizeStyleString = function(builder)
{
    builder.Append(Utils.CreateCssPropertyString('width', (this.Size.Width > 0) ? this.Size.Width.ToCssString() : '100%'))
		.Append(Utils.CreateCssPropertyString('height', (this.Size.Height > 0) ? this.Size.Height.ToCssString() : '100%'));
	return;
}
SimpleControl.prototype.GetBorderStyleString = function(builder)
{
    builder.Append(this.Border.ToCssString());
    return;
}
SimpleControl.prototype.GetStyleString = function(builder)
{
    this.GetSizeStyleString(builder);
    this.GetBorderStyleString(builder);
    builder.Append(Utils.CreateCssPropertyString('background', this.Background.ToCssString()))
		.Append(Utils.CreateCssPropertyString('padding', this.Padding.ToCssString()))
		.Append(Utils.CreateCssPropertyString('font', this.Font.ToCssString()))
		.Append(Utils.CreateCssPropertyString('color', this.ForeColor))
		.Append(Utils.CreateCssPropertyString('cursor', this.Cursor))
		.Append(ContentAlignment.CreateCssString(this.TextAlign));
	return;
}
SimpleControl.prototype.AttatchEventsToElement = function(element)
{
    element.setAttribute('onclick', this.Name + '.OnClick(event,this);');
	element.setAttribute('ondblclick', this.Name + '.OnDoubleClick(event,this);');
	element.setAttribute('onmousedown', this.Name + '.OnMouseDown(event,this);');
	element.setAttribute('onmouseup', this.Name + '.OnMouseUp(event,this);');
	element.setAttribute('onmouseover', this.Name + '.OnMouseOver(event,this);');
	element.setAttribute('onmousemove', this.Name + '.OnMouseMove(event,this);');
	element.setAttribute('onmouseout', this.Name + '.OnMouseOut(event,this);');
	element.setAttribute('onkeypress', this.Name + '.OnKeyPress(event,this);');
	element.setAttribute('onkeydown', this.Name + '.OnKeyDown(event,this);');
	element.setAttribute('onkeyup', this.Name + '.OnKeyUp(event,this);');
	return;
}
SimpleControl.prototype.GetEventAttributeString = function(builder)
{
    builder.Append(Utils.CreateAttributeString('onclick', this.Name + '.OnClick(event,this);'))
		.Append(Utils.CreateAttributeString('ondblclick', this.Name + '.OnDoubleClick(event,this);'))
		.Append(Utils.CreateAttributeString('onmousemove', this.Name + '.OnMouseMove(event,this);'))
		.Append(Utils.CreateAttributeString('onkeypress', this.Name + '.OnKeyPress(event,this);'))
		.Append(Utils.CreateAttributeString('onkeydown', this.Name + '.OnKeyDown(event,this);'))
		.Append(Utils.CreateAttributeString('onkeyup', this.Name + '.OnKeyUp(event,this);'))
		.Append(Utils.CreateAttributeString('onmouseover', this.Name + '.OnMouseOver(event,this);'))
		.Append(Utils.CreateAttributeString('onmouseout', this.Name + '.OnMouseOut(event,this);'))
		.Append(Utils.CreateAttributeString('onmousedown', this.Name + '.OnMouseDown(event,this);'))
		.Append(Utils.CreateAttributeString('onmouseup', this.Name + '.OnMouseUp(event,this);'));
    return;
}
/**************************************************************************/
function VisibleControl(p_elementId, p_instanceName)
{
	VisibleControl.baseConstructor.call(this, p_elementId, p_instanceName);
	this.Visible = true;
	this.VisibleChanged = null;
	return;
}
Extend(VisibleControl, SimpleControl);
VisibleControl.prototype.GetType = function() { return 'VisibleControl'; }
VisibleControl.prototype.OnVisibleChanged = function() { if(this.VisibleChanged) { this.VisibleChanged(this); } return; }
VisibleControl.prototype.SetVisibleCore = function(p_value)
{
	if(this.Visible != p_value)
	{
		this.Visible = p_value;
		if(this.IsRendered == true) { this.OnVisibleChanged(); }
	}
	return;
}
/**************************************************************************/
function Control(p_elementId, p_instanceName)
{
	Control.baseConstructor.call(this, p_elementId, p_instanceName);
	this.Location = this.DefaultLocation();
	this.Bounds   = new Rectangle(this.Location.X, this.Location.Y, this.Size.Width, this.Size.Height);
	this.Move     = null;
	this.Resize   = null;
	return;
}
Extend(Control, VisibleControl);
Control.prototype.GetType = function() { return 'Control'; }
Control.prototype.DefaultLocation = function() { return new Point(0, 0); }
Control.prototype.OnMove = function() { if(this.Move) { this.Move(this); } return; }
Control.prototype.OnResize = function() { if(this.Resize) { this.Resize(this); } return; }
Control.prototype.Show = function() { this.SetVisibleCore(true); this.Refresh(); return; }
Control.prototype.Hide = function() { this.SetVisibleCore(false); this.Refresh(); return; }
Control.prototype.SetCssDomProperties = function(p_element)
{
	this.SetElementLocationAndVisibility(p_element);
	Control.superClass.SetCssDomProperties.call(this, p_element);
	return;
}
Control.prototype.SetElementLocationAndVisibility = function(p_element)
{
	if(this.Visible == false)
	{
		p_element.style.display  = 'none';
		p_element.style.position = 'absolute';
		p_element.style.left     = '0px';
		p_element.style.top      = '0px;';
	}
	else
	{
		var v_flag = false;
		p_element.style.display = 'block';
		if(this.Location.X > 0) { v_flag = true; p_element.style.left = this.Location.X.ToCssString(); }
		if(this.Location.Y > 0) { v_flag = true; p_element.style.top = this.Location.Y.ToCssString(); }
		p_element.style.position = v_flag == true ? 'absolute' : 'static';
	}
	return;
}
Control.prototype.MoveTo = function(p_x, p_y)
{
	if(TypeOf(p_x) != 'Number') { throw new Error('p_x is not numeric!'); }
	if(TypeOf(p_y) != 'Number') { throw new Error('p_y is not numeric!'); }
	this.SetBounds(p_x, p_y, this.Size.Width, this.Size.Height);
	return;
}
Control.prototype.ResizeTo = function(p_width, p_height)
{
	if(TypeOf(p_width) != 'Number') { throw new Error('p_width is not numeric!'); }
	if(TypeOf(p_height) != 'Number') { throw new Error('p_height is not numeric!'); }
	this.SetBounds(this.Location.X, this.Location.Y, p_width, p_height);
	return;
}
Control.prototype.SetBounds = function(p_x, p_y, p_width, p_height)
{
	this.SetBoundsCore(p_x, p_y, p_width, p_height);
	return;
}
Control.prototype.SetBoundsCore = function(p_x, p_y, p_width, p_height)
{
	var v_move_flag = this.Location.X != p_x || this.Location.Y != p_y;
	var v_resize_flag = this.Size.Width != p_width || this.Size.Height != p_height;
	this.Location.Set(p_x, p_y);
	this.Size.Set(p_width, p_height);
	this.SyncBoundsRect();
	if(v_move_flag) { this.OnMove(); }
	if(v_resize_flag) { this.OnResize(); }
	return;
}
Control.prototype.SyncBoundsRect = function()
{
	this.Bounds.Set(this.Location.X, this.Location.Y, this.Size.Width, this.Size.Height);
	return;
}