BwCalendar.drawLayout = function()
{
	this.style.width = "200px";
	
	var frame = BwFrame.newInstance();
	
	var table = document.createElement ("table");
	table.style.tableLayout = "fixed";
	
	frame.contentContainer.appendChild (table);
	
	var thead = document.createElement ("tbody");
	table.appendChild (thead);
	
	var tr = document.createElement("tr");
	thead.appendChild (tr);

	var td = document.createElement("td");
	td.style.textAlign = "left";
	tr.appendChild (td);
	
	this.leftButtonContainer = td;
	
	td = document.createElement ("td");
	td.style.textAlign = "center";
	td.colSpan = 5;
	tr.appendChild (td);

	this.currentDateLabelContainer = td;
	
	var td = document.createElement("td");
	td.style.textAlign = "right";
	tr.appendChild (td);
	
	this.rightButtonContainer = td;
	
	tr = document.createElement("tr");
	thead.appendChild (tr);
	
	for (var i = 0; i < 7; i++)
	{
		td = document.createElement("td");
		this.dayLabelContainer[i] = td;
		tr.appendChild (td);
	}
	
	var tbody = document.createElement ("tbody");
	table.appendChild (tbody);
	
	this.calendarContainer = tbody;

	this.appendChild (frame);
};

BwCalendar.drawLeftButton = function ()
{
	var b = BwStockIcon.newInstance ("left.png");
	return b;
};

BwCalendar.drawRightButton = function ()
{
	var b = BwStockIcon.newInstance ("right.png");
	return b;
};

BwCalendar.drawCurrentDateLabel = function (m, y)
{
	return BwLabel.newInstance (m + "&nbsp;" + y);
};

BwCalendar.drawWeekDayLabel = function (l)
{
	return BwLabel.newInstance (l);
};

BwCalendar.clearCalendarContainer = function ()
{
	var tbody = this.calendarContainer;
	while (tbody.firstChild != null) {
		tbody.removeChild (tbody.firstChild);
	}
};

BwCalendar.drawWeekContainer = function ()
{
	var el = document.createElement ("tr");
	return el;
};

BwCalendar.drawDayContainer = function ()
{
	var td = document.createElement ("td");
	td.style.textAlign = "center";
	td.style.verticalAlign = "middle";
	td.style.width = "22px";
	td.style.height = "20px";
	
	return td;
};

BwCalendar.drawDayLabel = function (l)
{
	var el = BwLabel.newInstance (l);
	return el;
};

BwCalendar.setDayLabelStyle = function (dl, selected)
{
	if (!selected)
	{
		dl.style.background = "";
		dl.style.color = "";
	}
	else
	{
		dl.style.background = "url(Hula/icons/dateSelected.jpg) no-repeat center";
		dl.style.color = "#ffffff";
	}
};

BwFrame.draw = function ()
{
	var table = document.createElement ('table');
	table.border = '0px';
	table.cellSpacing = '0px';
	table.cellPadding = '0px';
	table.style.borderCollapse = 'collapse';
	table.style.tableLayout = 'fixed';
	
	var colgroup = document.createElement ("colgroup");
	table.appendChild (colgroup);
	
	var col = document.createElement ("col");
	col.style.width="1px";
	colgroup.appendChild (col);
	
	col = document.createElement ("col");
	col.style.width="3px";
	colgroup.appendChild (col);
	
	col = document.createElement ("col");
	colgroup.appendChild (col);
	
	col = document.createElement ("col");
	col.style.width="3px";
	colgroup.appendChild (col);
	
	col = document.createElement ("col");
	col.style.width="1px";
	colgroup.appendChild (col);
	
	var tbody = document.createElement ('tbody');
	table.appendChild (tbody);

	var tr = document.createElement ('tr');
	tbody.appendChild (tr);
	
	var td = document.createElement ('td');
	td.onmousedown = function(){return false;};
	td.colSpan = 2;
	td.rowSpan = 2;
	td.style.width = '4px';
	td.style.height = '4px';
	tr.appendChild (td);

	var img = BwStockIcon.newInstance ("frame_small/top_left.png");
	img.style.width = "4px";
	img.style.height = "4px";
	img.style.MozUserSelect="none";
	img.style.MozUserInput="disabled";
	img.style.MozUserFocus="ignore";
	td.appendChild (img);
	
	td = document.createElement ('td');
	td.style.height = '1px';
	td.style.backgroundColor = '#aaaaaa';
	tr.appendChild (td);

	td = document.createElement ('td');
	td.onmousedown = function(){return false;};
	td.colSpan = 2;
	td.rowSpan = 2;
	td.style.width = '4px';
	td.style.height = '4px';
	tr.appendChild (td);

	img = BwStockIcon.newInstance ("frame_small/top_right.png");
	img.style.width = "4px";
	img.style.height = "4px";
	img.style.MozUserSelect="none";
	img.style.MozUserInput="disabled";
	img.style.MozUserFocus="ignore";
	td.appendChild (img);
	
	tr = document.createElement ('tr');
	tbody.appendChild (tr);

	td = document.createElement ('td');
	td.style.height = '3px';
	td.style.backgroundColor = '#ffffff';
	tr.appendChild (td);
	
	tr = document.createElement ('tr');
	tbody.appendChild (tr);

	td = document.createElement ('td');
	td.style.width='1px';
	td.style.backgroundColor='#aaaaaa';
	tr.appendChild (td);
	
	td = document.createElement ('td');
	td.style.width='3px';
	td.style.backgroundColor = '#ffffff';
	tr.appendChild (td);
	
	td = document.createElement ('td');
	td.style.backgroundColor = '#ffffff';
	tr.appendChild (td);
	
	var div = document.createElement ('div');
	td.appendChild (div);
	
	this.contentContainer = div;
	
	td = document.createElement ('td');
	td.style.width='3px';
	td.style.backgroundColor = '#ffffff';
	tr.appendChild (td);
	
	td = document.createElement ('td');
	td.style.width='1px';
	td.style.backgroundColor='#aaaaaa';
	tr.appendChild (td);
	
	tr = document.createElement ('tr');
	tbody.appendChild (tr);
	
	var td = document.createElement ('td');
	td.onmousedown = function(){return false;};
	td.colSpan = 2;
	td.rowSpan = 2;
	td.style.width = '4px';
	td.style.height = '4px';
	tr.appendChild (td);

	var img = BwStockIcon.newInstance ("frame_small/bottom_left.png");
	img.style.width = "4px";
	img.style.height = "4px";
	img.style.MozUserSelect="none";
	img.style.MozUserInput="disabled";
	img.style.MozUserFocus="ignore";
	td.appendChild (img);
	
	td = document.createElement ('td');
	td.style.height = '3px';
	td.style.backgroundColor = '#ffffff';
	tr.appendChild (td);

	td = document.createElement ('td');
	td.onmousedown = function(){return false;};
	td.colSpan = 2;
	td.rowSpan = 2;
	td.style.width = '4px';
	td.style.height = '4px';
	tr.appendChild (td);

	img = BwStockIcon.newInstance ("frame_small/bottom_right.png");
	img.style.width = "4px";
	img.style.height = "4px";
	img.style.MozUserSelect="none";
	img.style.MozUserInput="disabled";
	img.style.MozUserFocus="ignore";
	td.appendChild (img);
	
	tr = document.createElement ('tr');
	tbody.appendChild (tr);
	
	td = document.createElement ('td');
	td.style.height="1px";
	td.style.backgroundColor = '#aaaaaa';
	tr.appendChild (td);
	
	return table;
};

BwLabel.updateLabelStyle = function (enabled)
{
	this.style.fontFamily = "Verdana, Arial, Helvetica";
	this.style.fontSize = "8pt";
	
	this.disabled = !enabled;

	if (navigator.product=="Gecko") {
		this.style.opacity = (enabled) ? '1' : '0.4';
	}
};

BwList.drawHeaderCellSortIndicator = function (index)
{
	var s = "none.gif";
	var i = BwStockIcon.newInstance (s);
	i.style.width = "9px";
	i.style.height = "6";
	i.style.marginLeft = "5px";
	i.style.marginRight = "5px";
	
	return i;
};

BwList.updateHeaderCellSortIndicator = function (sortIndicator, index)
{
	var s = (this.sortedColumnIndex == index) ?  ((this.sortedAscending) ? "asc.png" : "desc.png") : "none.gif";  
	sortIndicator.setSource (s);
};

BwList.drawHeaderCell = function (index)
{
	var f = BwFrame.newInstance();
	f.firstChild.style.width="100%";
	
	var c = f.contentContainer;
	c.style.whiteSpace = "nowrap";
	c.style.overflow = "hidden";
	c.style.MozUserSelect="none";
	c.style.MozUserInput="disabled";
	c.style.MozUserFocus="ignore";
	
	f.titleContainer = c;
	f.sortIndicatorContainer = c;
	
	return f;
};

BwList.drawHeaderCellTitle = function (index)
{
	var t = BwLabel.newInstance (this.columns[index].name);
	return t;
};

BwList.updateRowsStyle = function ()
{
	var s = this.sortedColumnIndex;
	var odd = true;
	
	var attached = (this.listTable.tbody.parent != null);
	if (attached) this.listTable.removeChild (this.listTable.tbody);
	
	var r = this.listTable.tbody.firstChild;
	while (r != null)
	{
		if (r.style.display != 'none')
		{
			odd = !odd;
			
			r.style.backgroundColor = (odd) ? "#ffffff" : "#eaeaea";
			
			var cells = r.childNodes;
			var cl = cells.length;
			for (var j = 0; j < cl; j++)
			{
				var c = cells[j];
				c.vAlign="middle";
				c.style.textAlign = this.columns[j].align;
				
				if (r.selected)
				{
					c.style.backgroundColor = "#c8c8c8";
				}
				else
				{
					c.style.backgroundColor = (s == j) ? ((odd) ? "#eaeaea" : "#dedfde") : "";
				}
			}
		}

		r = r.nextSibling;
	}
	
	if (attached) this.listTable.appendChild (this.listTable.tbody);
};

BwList.updateHeaderContainerStyle = function ()
{
	this.header.style.backgroundColor="#dedfde";
};

BwList.updateListContainerStyle = function ()
{
	this.list.style.backgroundColor="#eaeaea";
};

BwList.drawAsyncActivityIndicator = function ()
{
	var el = BwStockIcon.newInstance ("wait.gif");
	el.style.position = "relative";
	
	el.style.top = (this.list.clientHeight / 2) + 'px';
	el.style.left = (this.list.clientWidth / 2) + 'px';

	return el;
};

BwNotebookPage.setStyle = function ()
{
	if (this.style.borderLeft == "") {
		this.style.borderLeft = "2px solid #aaaaaa";
	}
	if (this.style.borderRight == "") {
		this.style.borderRight = "2px solid #aaaaaa";
	}
	if (this.style.borderBottom == "") {
		this.style.borderBottom = "2px solid #aaaaaa";
	}
};

BwNotebook.drawTabBar = function ()
{
	var bar = document.createElement ('div');
	bar.style.borderBottom="2px solid #aaaaaa";
	bar.style.padding="4px";
	bar.style.paddingBottom="0px";
	
	var spacer = document.createElement ('div');
	spacer.style.clear = "both";
	bar.appendChild (spacer);
	
	this.tabBar = bar;
	
	return bar;
};

BwNotebook.drawTab = function (content, index)
{
	var tab = document.createElement ('div');
	var s = tab.style;
	s.cssFloat = "left";
	s.styleFloat = "left";
	s.position = "relative";
	s.marginTop = "2px";
	s.paddingBottom = "2px";
	s.paddingLeft = "11px";
	s.paddingRight = "11px";
	s.color = "#777777";
	s.top = "2px";
	s.border = "1px solid #c8c8c8";
	s.borderBottom = "none";

	if (index + 1 < this.pages.length)
	{
		s.borderRight = "none";
	}

	if (index == this.selected + 1)
	{
		s.borderLeft = "none";
	}
	
	tab.appendChild (content);
	
	return tab;	
};

BwNotebook.drawSelectedTab = function (content, index)
{
	var tab = document.createElement ('table');
	var s = tab.style;
	s.cssFloat = "left";
	s.styleFloat = "left";
	s.position = "relative";
	s.top = "2px";
	s.borderCollapse = "collapse";
	tab.cellSpacing="0px";
	tab.cellPadding="0px";
	
	var colgroup = document.createElement ('colgroup');
	tab.appendChild (colgroup);

	var col = document.createElement ('col');
	col.style.width = "2px";
	colgroup.appendChild (col);
	
	col = document.createElement ('col');
	colgroup.appendChild (col);
	
	col = document.createElement ('col');
	col.style.width = "2px";
	colgroup.appendChild (col);
	
	var tbody = document.createElement ("tbody");
	tab.appendChild (tbody);
	
	var tr = document.createElement ('tr');
	tr.style.height = "2px";
	tbody.appendChild (tr);
	
	var td = document.createElement ('td');
	tr.appendChild (td);
	
	var img = BwStockIcon.newInstance ("notebook/tab_selected_top_left.png");
	img.style.width = "2px";
	img.style.height = "2px";
	td.appendChild (img);
	
	td = document.createElement ('td');
	td.style.backgroundColor = "#aaaaaa";
	tr.appendChild (td);
	
	td = document.createElement ('td');
	tr.appendChild (td);
	
	img = BwStockIcon.newInstance ("notebook/tab_selected_top_right.png");
	img.style.width = "2px";
	img.style.height = "2px";
	td.appendChild (img);
	
	tr = document.createElement ('tr');
	tr.style.height = "1px";
	tbody.appendChild (tr);
	
	td = document.createElement ('td');
	td.style.backgroundColor = "#aaaaaa";
	tr.appendChild (td);
	
	td = document.createElement ('td');
	td.style.backgroundColor = "#ffffff";
	tr.appendChild (td);
	
	td = document.createElement ('td');
	td.style.backgroundColor = "#aaaaaa";
	tr.appendChild (td);
	
	tr = document.createElement ('tr');
	tbody.appendChild (tr);
	
	td = document.createElement ('td');
	td.style.backgroundColor = "#aaaaaa";
	tr.appendChild (td);
	
	td = document.createElement ('td');
	td.style.backgroundColor = "#ffffff";
	td.style.paddingLeft = "10px";
	td.style.paddingRight = "10px";
	td.style.paddingBottom = "2px";
	td.style.color = "#777777";
	tr.appendChild (td);
	
	td.appendChild (content);
	
	td = document.createElement ('td');
	td.style.backgroundColor = "#aaaaaa";
	tr.appendChild (td);
	
	tr = document.createElement ('tr');
	tr.style.height = "2px";
	tbody.appendChild (tr);
	
	td = document.createElement ('td');
	tr.appendChild (td);
	
	img = BwStockIcon.newInstance ("notebook/tab_selected_bottom_left.png");
	img.style.width = "2px";
	img.style.height = "2px";
	td.appendChild (img);
	
	td = document.createElement ('td');
	td.style.backgroundColor = "#ffffff";
	tr.appendChild (td);
	
	td = document.createElement ('td');
	tr.appendChild (td);
	
	img = BwStockIcon.newInstance ("notebook/tab_selected_bottom_right.png");
	img.style.width = "2px";
	img.style.height = "2px";
	td.appendChild (img);
	
	return tab;	
};




BwTable.drawHierarchyIndicator = function (depth, hasChild)
{
	var img = BwStockIcon.newInstance (hasChild ? "opened.png" : "none.gif");
	img.style.marginLeft = (depth * 13) + "px";
	img.style.width = "13px";
	img.style.height = "13px";
	img.align = "center";

	return img;
};

BwTextfield.updateStyle = function ()
{
	this.input.style.border = "none";
	this.style.border = "1px solid #aaaaaa";
	this.style.margin = "2px";
};

BwWindow.draw = function ()
{
	var table = document.createElement ('table');
	table.cellSpacing = '0px';
	table.cellPadding = '0px';
	table.style.borderCollapse = 'collapse';
	
	var colgroup = document.createElement ("colgroup");
	table.appendChild (colgroup);
	
	var col = document.createElement ("col");
	col.style.width="2px";
	colgroup.appendChild (col);
	
	col = document.createElement ("col");
	col.style.width="10px";
	colgroup.appendChild (col);
	
	col = document.createElement ("col");
	colgroup.appendChild (col);
	
	col = document.createElement ("col");
	col.style.width="10px";
	colgroup.appendChild (col);
	
	col = document.createElement ("col");
	col.style.width="2px";
	colgroup.appendChild (col);
	
	var tbody = document.createElement ('tbody');
	table.appendChild (tbody);

	var tr = document.createElement ('tr');
	tbody.appendChild (tr);

	var td = document.createElement ('td');
	td.colSpan = 2;
	td.style.width = '12px';
	td.style.height = '12px';
	tr.appendChild (td);

	var img = BwStockIcon.newInstance ("titlebar/top_left.png");
	img.style.width = '12px';
	img.style.height = '12px';
	img.onmousedown=function(){return false;};
	td.appendChild (img);
	
	
	td = document.createElement ('td');
	td.style.height = '2px';
	td.style.backgroundColor = '#aaaaaa';
	tr.appendChild (td);

	td = document.createElement ('td');
	td.colSpan = 2;
	td.style.width = '12px';
	td.style.height = '12px';
	tr.appendChild (td);

	img = BwStockIcon.newInstance ("titlebar/top_right.png");
	img.style.width = '12px';
	img.style.height = '12px';
	img.onmousedown=function(){return false;};
	td.appendChild (img);
	
	tr = document.createElement ('tr');
	tbody.appendChild (tr);

	td = document.createElement ('td');
	td.style.width = '2px';
	td.style.backgroundColor = '#aaaaaa';
	tr.appendChild (td);

	td = document.createElement ('td');
	td.style.width = '10px';
	td.style.backgroundColor = '#aaaaaa';
	tr.appendChild (td);

	td = document.createElement ('td');
	td.style.backgroundColor = '#aaaaaa';
	tr.appendChild (td);
	
	var tb = document.createElement ('table');
	tb.cellSpacing = '0px';
	tb.cellPadding = '0px';
	tb.style.borderCollapse = 'collapse';
	tb.style.position = 'relative';
	tb.style.position = 'relative';
	tb.style.top = '-5px';
	tb.style.left = '-5px';
	tb.style.height = '20px';
	tb.style.color = "#ffffff";
	tb.style.fontWeight = "bold";
	tb.style.width = "100%";
	td.appendChild (tb);
	
	var tbbody = document.createElement ('tbody');
	tb.appendChild (tbbody);
	
	var tbtr = document.createElement ('tr');
	tbbody.appendChild (tbtr);
	
	
	var tbtd = document.createElement ('td');
	tbtr.appendChild (tbtd);
	
	this.titleContainer = tbtd;
	
	tbtd = document.createElement ('td');
	tbtd.style.textAlign = "right";
	tbtd.style.width = "10px";
	tbtr.appendChild (tbtd);
	
	this.controlsContainer = tbtd;

	td = document.createElement ('td');
	td.style.width = '10px';
	td.style.backgroundColor = '#aaaaaa';
	tr.appendChild (td);
	
	td = document.createElement ('td');
	td.style.width = '2px';
	td.style.backgroundColor = '#aaaaaa';
	tr.appendChild (td);
	
	this.titlebar_bottom_right = td;
	
	tr = document.createElement ('tr');
	tbody.appendChild (tr);
	
	td = document.createElement ('td');
	td.style.width='2px';
	td.style.backgroundColor='#aaaaaa';
	tr.appendChild (td);

	td = document.createElement ('td');
	td.colSpan = 3;
	
	td.style.backgroundColor='#ffffff';
	tr.appendChild (td);
	
	this.contentContainer = td;
	
	td = document.createElement ('td');
	td.style.width='2px';
	td.style.backgroundColor='#aaaaaa';
	tr.appendChild (td);
	
	tr = document.createElement ('tr');
	tbody.appendChild (tr);
	
	td = document.createElement ('td');
	td.colSpan = "2";
	td.rowSpan = "2";
	td.style.width="12px";
	td.style.height="12px";
	tr.appendChild (td);

	img = BwStockIcon.newInstance ("frame_big/bottom_left.png");
	img.style.width = '12px';
	img.style.height = '12px';
	td.appendChild (img);
	
	td = document.createElement ('td');
	td.style.height="10px";
	td.style.backgroundColor='#ffffff';
	tr.appendChild (td);
	
	td = document.createElement ('td');
	td.colSpan = "2";
	td.rowSpan = "2";
	td.style.width="12px";
	td.style.height="12px";
	tr.appendChild (td);

	img = BwStockIcon.newInstance ("frame_big/bottom_right.png");
	img.style.width = '12px';
	img.style.height = '12px';
	td.appendChild (img);
	
	tr = document.createElement ('tr');
	tbody.appendChild (tr);

	td = document.createElement ('td');
	td.style.height = '2px';
	td.style.backgroundColor = '#aaaaaa';
	tr.appendChild (td);

	return table;
};

