// GetTime
function GetTime()
{
	var d = new Date();
	return d.getTime();
}

// Panel Class
function Panel(panelId)
{
	this.panelId = panelId;
	this.OnHideCallback = null;
	this.OnShowCallback = null;
}

Panel.prototype.FillFromRemotDataSource = function(URL, callbackFunc)
{
	jQuery(this.panelId).load(URL, "", callbackFunc);
}

Panel.prototype.OnHide = function(callbackFunc)
{
	this.OnHideCallback = callbackFunc;
}

Panel.prototype.OnShow = function(callbackFunc)
{
	this.OnShowCallback = callbackFunc;
}

Panel.prototype.Show = function()
{
	jQuery(this.panelId).css("visibility", "visible");
	if( this.OnShowCallback != null )
	{
		this.OnShowCallback();
	}
}

Panel.prototype.SetContent = function(data)
{
	jQuery(this.panelId).html(data);
}

Panel.prototype.IsVisible = function()
{
	if( jQuery(this.panelId).css("visibility").toUpperCase() == "visible" )
	{
		return true;
	}
	return false;	
}

Panel.prototype.Hide = function()
{
	jQuery(this.panelId).css("visibility", "hidden");
	if( this.OnHideCallback != null )
	{
		this.OnHideCallback();
	}
}

Panel.prototype.Undock = function()
{
	jQuery(this.panelId).css("position", "absolute");
}

Panel.prototype.Dock = function()
{
	jQuery(this.panelId).css("position", "relativ");
}

Panel.prototype.CenterScreen = function()
{
	if( jQuery(window).height() > jQuery(this.panelId).height())
	{
		jQuery(this.panelId).css("top", (jQuery(window).height() / 2) -(jQuery(this.panelId).height() / 2));
	}
	else
	{
		jQuery(this.panelId).css("top", 10);
	}

	if( jQuery(window).width() > jQuery(this.panelId).width())
	{
		jQuery(this.panelId).css("left", (jQuery(window).width() / 2) -(jQuery(this.panelId).width() / 2));
	}
	else
	{
		jQuery(this.panelId).css("left", 10);
	}
}

Panel.prototype.SetSize = function(width, height)
{
	jQuery(this.panelId).css("width", width);
	jQuery(this.panelId).css("height", height);
}

Panel.prototype.SetPostition = function(left, top)
{
	jQuery(this.panelId).css("left", left);
	jQuery(this.panelId).css("top", top);
}

// Label Class
function Label(labelId)
{
	this.labelId = labelId;
}

Label.prototype.Show = function()
{
	jQuery(this.labelId).css("visibility", "visible");
}

Label.prototype.Hide = function()
{
	jQuery(this.labelId).css("visibility", "hidden");
}

Label.prototype.SetText = function(Text)
{
	jQuery(this.labelId).text(Text);
}

Label.prototype.SetHtml = function(Html)
{
	jQuery(this.labelId).html(Html);
}

// ListBox Class
function ListBox() { }
function ListBox(listBoxId)
{
	this.listBoxId = listBoxId;
	this.id = listBoxId;
}

ListBox.prototype.ClearItems = function()
{
	jQuery(this.listBoxId).html("");
}

ListBox.prototype.AddItem = function(Text, Value)
{
	var tmp = jQuery(this.listBoxId).html();
	jQuery(this.listBoxId).html(tmp + "<option value='" + Value + "'>" + Text + "</option>");
}

ListBox.prototype.FillFromRemotDataSource = function(URL, callbackFunc)
{
	jQuery(this.listBoxId).load(URL, "", callbackFunc);
}

ListBox.prototype.GetSelectedItem = function()
{
	return jQuery(this.listBoxId).attr("value");
}

ListBox.prototype.Show = function()
{
	jQuery(this.listBoxId).css("visibility", "visible");
}

ListBox.prototype.Hide = function()
{
	jQuery(this.listBoxId).css("visibility", "hidden");
}

ListBox.prototype.Enable = function()
{
	jQuery(this.listBoxId).attr("disabled", false);
}

ListBox.prototype.Disable = function()
{
	jQuery(this.listBoxId).attr("disabled", true);
}

ListBox.prototype.ChangeEventHandler = function(Handler)
{
	jQuery(this.listBoxId).change(Handler);
}

ListBox.prototype.DoChange = function()
{
	jQuery(this.listBoxId).change();
}


// TextBox Class
function TextBox(textBoxId)
{
	this.textBoxId = textBoxId;
	this.isHighlight = false;
}

TextBox.prototype.GetText = function()
{
	if( jQuery(this.textBoxId).attr("value") == undefined || jQuery(this.textBoxId).attr("value") == null )
	{
		return "";
	}
	else
	{
		return jQuery(this.textBoxId).attr("value");
	}
}

TextBox.prototype.Focus = function()
{
	jQuery(this.textBoxId).focus();
}

TextBox.prototype.SetText = function(Text)
{
	if( Text == null || Text == undefined )
	{
		jQuery(this.textBoxId).attr("value", "");		
	}
	else
	{
		jQuery(this.textBoxId).attr("value", Text);
	}
}

TextBox.prototype.Hide = function()
{
	jQuery(this.textBoxId).css("visibility", "hidden");
}

TextBox.prototype.Enable = function()
{
	jQuery(this.textBoxId).attr("disabled", false);
}

TextBox.prototype.Disable = function()
{
	jQuery(this.textBoxId).attr("disabled", true);
}

TextBox.prototype.BlurEventHandler = function(Handler)
{
	jQuery(this.textBoxId).blur(Handler);
}

TextBox.prototype.Blur = function()
{
	jQuery(this.textBoxId).blur();
}

TextBox.prototype.Highlight = function(color)
{
	if( this.isHighlight == false )
	{
		this.oldColor = jQuery(this.textBoxId).css("border-color");
		jQuery(this.textBoxId).css("border-color", color);
		this.isHighlight = true;
	}
}
TextBox.prototype.ClearHighlight = function()
{
	if( this.isHighlight == true )
	{
		jQuery(this.textBoxId).css("border-color", this.oldColor);
		this.isHighlight = false;
	}
}

// Button Class
function Button(buttonId)
{
	this.buttonId = buttonId;
}

Button.prototype.Show = function()
{
	jQuery(this.buttonId).css("visibility", "visible");
}

Button.prototype.Hide = function()
{
	jQuery(this.buttonId).css("visibility", "hidden");
}

Button.prototype.Enable = function()
{
	jQuery(this.buttonId).attr("disabled", false);
}

Button.prototype.Disable = function()
{
	jQuery(this.buttonId).attr("disabled", true);
}

Button.prototype.ClickEventHandler = function(Handler)
{
	jQuery(this.buttonId).click(Handler);
}

// DatePicker Class
function DatePicker() { }
function DatePicker(containerId)
{
	this.containerId = containerId;
	jQuery(this.containerId).datepicker()
}

// Dialog Class
function Dialog() { }
function Dialog(containerId)
{
    this.containerId = containerId;
	if( this.containerId == null || this.containerId == undefined) { return; }
    jQuery(this.containerId).dialog({autoOpen:false});
    var self = this;
    jQuery(this.containerId).dialog("option", "buttons", { "Abbruch" : function() { self.AbortClick() } , "OK" : function() { self.OKClick() } });
    this.SetTitle("Dialog Box " + this.containerId);
}

Dialog.prototype.Show = function()
{
    jQuery(this.containerId).dialog("option", "modal", false);
    jQuery(this.containerId).dialog("open");
}

Dialog.prototype.ShowMessageBox = function()
{
    var self = this;
	jQuery(this.containerId).dialog("option", "buttons", { "OK" : function() { self.OKClick() } });
	jQuery(this.containerId).dialog("option", "modal", true);
    jQuery(this.containerId).dialog("open");
}

Dialog.prototype.ShowErrorBox = function(ErrorMessage)
{
	this.SetTitle("Fehler:");
	this.SetContent(ErrorMessage);
	this.ShowMessageBox();
}

Dialog.prototype.ShowModal = function()
{
    jQuery(this.containerId).dialog("option", "modal", true);
    jQuery(this.containerId).dialog("open");
}

Dialog.prototype.Close = function()
{
	jQuery(this.containerId).dialog("close");
}

Dialog.prototype.OKClick = function()
{
    //alert("ERROR: Not Implemented OK CLick");
    jQuery(this.containerId).dialog("close");
}

Dialog.prototype.AbortClick = function()
{
    //alert("ERROR: Not Implemented Abort CLick");
    jQuery(this.containerId).dialog("close");
}

Dialog.prototype.SetTitle = function(title)
{
    jQuery(this.containerId).dialog("option", "title", title);
}

Dialog.prototype.SetPosition = function(x, y)
{
	jQuery(this.containerId).dialog("option", "top", y);
	jQuery(this.containerId).dialog("option", "left", x);
}

Dialog.prototype.SetSize = function(width, height)
{
	jQuery(this.containerId).dialog("option", "width", width);
	jQuery(this.containerId).dialog("option", "height", height);
}

Dialog.prototype.SetMinBounds = function(minWidth, minHeight)
{
	jQuery(this.containerId).dialog("option", "minWidth", minWidth);
	jQuery(this.containerId).dialog("option", "minHeight", minHeight);
}

Dialog.prototype.SetContent = function(data)
{
	jQuery(this.containerId).html(data);
}
