// Copyright (c) 2002-2004 ComponentOne L.L.C. All rights reserved.
// Version 1.0.20044.68, 02-Sep-2004

var isIE = (navigator.userAgent.indexOf('MSIE') != -1);

var tbDatas = [];
var dragObj = null;
var deltaX = 0;
var deltaY = 0;

//INIT STUFF
function c1c_topicbar_init(id, canDrag, collapsePb, expandPb, clickPb, selectPb, autoCollapse, btnStyle, blankUrl)
{
	var tb = document.getElementById(id);
	
	tbDatas[id] = new c1c_innerInit(id, tb, canDrag, collapsePb, expandPb, clickPb, selectPb, autoCollapse, btnStyle, blankUrl);
	
	if (!tbDatas[id].expandedGroup)
		tbDatas[id].btnStyle = false;
	
	if (! tbDatas[id].btnStyle && tb)
		tb.style.height = 0;
	else
		if (tbDatas[id].expandedGroup)
		{
			var row = c1c_getGroupContentRow(tbDatas[id].expandedGroup);
			row = row.cells[0].firstChild; //group table
			row = row.rows[row.rows.length - 1].cells[0].firstChild; //body table
			c1c_setHeight(row, tbDatas[id].availHeight);
		}
		
	c1c_getHeadersPos(tb, tbDatas[id].headers);		 
			
	if (isIE)
	{			
		document.attachEvent("onmousemove", c1c_docOnMouseMove);
		document.attachEvent("onmouseup", c1c_docOnMouseUp);
		document.attachEvent("onselectstart", c1c_docOnSelectStart);
	}
	else
	{
		document.onmousemove = c1c_docOnMouseMove;
		document.onmouseup = c1c_docOnMouseUp;
		document.onselectstart = c1c_docOnSelectStart;
	}		
}


function c1c_innerInit(id, tb, canDrag, collapsePb, expandPb, clickPb, selectPb, autoCollapse, btnStyle, blankUrl)
{
	this.selectedItem = c1c_getSelectedItem(tb);
	this.expandedGroup = c1c_getExpandedGroup(tb);
	this.groupsDragStatus = c1c_getByName("__" + id + "_GDSF");
	this.groupsStatus = c1c_getByName("__" + id + "_GSF");
	this.selectionStatus = c1c_getByName("__" + id + "_SSF");
	this.canDrag = (canDrag == 1);
	this.collapsePb = (collapsePb == 1);
	this.expandPb = (expandPb == 1);
	this.clickPb = (clickPb == 1);
	this.selectPb = (selectPb == 1);
	this.headers = new Array();
	this.init = false;
	this.autoCollapse = (autoCollapse == 1);
	this.btnStyle = (btnStyle == 1);
	this.blankUrl = blankUrl;
	
	this.height = (tb) ? tb.offsetHeight : 0;
	this.availHeight = 0;
	
	if (this.btnStyle)
		this.availHeight = c1c_getAvailHeight(tb, this.expandedGroup, this.height);
}


function c1c_getAvailHeight(tb, expdGroup,  height)
{
	var res = height;
	
	var grpRows = tb.rows[0].cells[0].firstChild.rows; //group rows
	for (var i = 0; i < grpRows.length; i++)
	{
		var tmp = grpRows[i].cells[0].firstChild; //group table;
		if (tmp.rows.length == 2)
		{
			var tab = tmp.rows[0].cells[0].firstChild; //header table
			res -= tab.offsetHeight;
			if (!c1c_canToggle(tab))
			{
				tab = tmp.rows[1].cells[0].firstChild; //body table;
				res -= tab.offsetHeight;
			}
		}
	}
	
	return res;
}


function c1c_getHeadersPos(tb, headers)
{
	if (tb && headers)
	{
		var grpRows = tb.rows[0].cells[0].firstChild.rows;
		for (var i = 0; i < grpRows.length; i++)
		{
			var grpTable = grpRows[i].cells[0].firstChild;
			if (grpTable.rows.length == 2)
			{
				var ht = grpTable.rows[0].cells[0].firstChild;
				headers[i] = new c1c_coords(c1c_findPosX(ht), c1c_findPosY(ht), ht.offsetWidth, ht.offsetHeight, ht);
			}
		}
	}
}


function c1c_dragObj(id, idx, obj, lh, hdr)
{
	this.dragFromTopicId = id;
	this.groupIdx = idx;
	this.o = obj;
	this.o.style["zIndex"] = "1";
	this.lastHighlight = lh;
	this.header = hdr;
}


function c1c_coords(x, y, w, h, hdr)
{
	this.x = x;
	this.y = y;
	this.width = w;
	this.height = h;
	this.xx = x + w;
	this.yy = y + h;
	this.header = hdr;
}


//DOC STUFF (Drag-n-drop)
function c1c_docOnSelectStart(e)
{
	if (dragObj || c1c_getTopicBar(e.srcElement))
		return false;
}


function c1c_onHeaderMouseDown(src, e)
{
	if (dragObj == null && c1c_canDrag(src))
	{
		dragObj = new c1c_dragObj(c1c_getTopicBarId(src), c1c_getGroupIdx(src), document.getElementById("c1c_dragItem"), src, src); 
		 
		if (dragObj != null)
		{
			dragObj.o.style.height = src.offsetHeight;
			dragObj.o.style.width = src.offsetWidth;
			dragObj.o.style.left = c1c_findPosX(src); 
			dragObj.o.style.top = c1c_findPosY(src); 
			
			var evt = c1c_e(e);
			deltaX = parseInt(dragObj.o.style.left) - evt.x;
			deltaY = parseInt(dragObj.o.style.top) - evt.y;
		
			//dragObj.o.innerHTML = src.outerHTML;
			dragObj.o.appendChild(src.cloneNode(true));
		
			c1c_clearNode(dragObj.o.firstChild);
		}
	}
}


function c1c_docOnMouseMove(e)
{
	if (dragObj != null && c1c_e(e).leftBtn)
	{
		dragObj.o.style["zIndex"] = "10000";
		if (dragObj.o.style.visibility != "visible")
		{
			dragObj.o.style.visibility = "visible";
			dragObj.o.firstChild.style.cursor = "";
		}
	
		var hdr = c1c_isMouseOverHeader(e, dragObj.dragFromTopicId);
		
		if (dragObj && dragObj.lastHighlight && hdr != dragObj.lastHighlight)
		{
			c1c_onHeaderMouseOut(dragObj.lastHighlight, null);
			dragObj.lastHighlight = null;
		}

		if (hdr && hdr != dragObj.lastHighlight) // if (hdr)
		{
			c1c_onHeaderMouseOver(hdr, null); 
			dragObj.lastHighlight = hdr;
		}
			
		var evt = c1c_e(e);
		dragObj.o.style.left = deltaX + evt.x;
		dragObj.o.style.top = deltaY + evt.y;
	}
}


function c1c_docOnMouseUp(e)
{
	if (dragObj != null)
	{
		dragObj.o.style.visibility = "hidden";
		dragObj.o.firstChild.style.cursor = "pointer";
		dragObj.o.removeChild(dragObj.o.firstChild);
		
		var hdr = c1c_isMouseOverHeader(e, dragObj.dragFromTopicId);
		if (hdr != null)
		{
			//hdr.style.cursor = "pointer";
			
			if (dragObj.lastHighlight != null)
				c1c_onHeaderMouseOut(dragObj.lastHighlight, null);
		
			var row = c1c_getGroupContentRow(dragObj.header);
			var src = row.cloneNode(true);
			var dst = c1c_getGroupContentRow(hdr);
		
			var srcIdx = row.rowIndex;	
			var dstIdx = dst.rowIndex;
			
			var isItems = c1c_getAttribute(row, "items");
					
			var grpsTable = c1c_upToTag(row, "TABLE"); 
			grpsTable.deleteRow(srcIdx);
			
			row = grpsTable.insertRow(dstIdx);

			if (isIE)
				row.appendChild(src.firstChild);
			else
				c1c_copyContent(src, row);
				//row.innerHTML = src.innerHTML;
				
			if (isItems)
				row.setAttribute("items", 1);
				
			var tb = c1c_getTopicBar(hdr);
			var id = c1c_getAttribute(tb, "id");
			
			tbDatas[id].selectedItem = c1c_getSelectedItem(tb);
			tbDatas[id].expandedGroup = c1c_getExpandedGroup(tb);  
			
			c1c_getHeadersPos(document.getElementById(id), tbDatas[id].headers);  

			if (tbDatas[id].selectionStatus.value != "")
				tbDatas[id].selectionStatus.value = tbDatas[id].selectedItem;
				
			tbDatas[id].groupsDragStatus.value += srcIdx + ":" + dstIdx + ";";
			
			c1c_refreshGroupsStatus(id, srcIdx, dstIdx);
			
			hdr = c1c_isMouseOverHeader(e, dragObj.dragFromTopicId);
			if (hdr)
				c1c_onHeaderMouseOver(hdr, null);
		}
		
		dragObj.header = null;
		dragObj.lastHighlight = null;
		dragObj = null;
	}
}


function c1c_refreshGroupsStatus(id, srcIdx, dstIdx)
{
	var val = tbDatas[id].groupsStatus.value;
	if (val)
	{
		var grps = val.split(";");
		val = "";
		
		for (var i = 0; i < grps.length - 1; i++)
		{
			if (grps[i] == srcIdx)
				grps[i] = dstIdx;
			else
			{
				if (grps[i] > srcIdx)
					grps[i]--;
				
				if (grps[i] >= dstIdx)
					grps[i]++;
			}
				
			val += grps[i] + ";";
		}
	}

	tbDatas[id].groupsStatus.value = val;	
}


//e == null when calling from code
function c1c_onHeaderMouseOver(src, e)
{
	if (!src.disabled && !(dragObj && e))
	{
		var expanded = c1c_isVisible(c1c_getHeaderContentRow(src).nextSibling);
		var applyStyle = c1c_getAttribute(src, (expanded) ? "movExpandedStyle" : "movCollapsedStyle");

		if (applyStyle)
			c1c_setHeaderStyle(src, applyStyle);
		else
		{
			applyStyle = c1c_getAttribute(src, (expanded) ? "expandedStyle" : "collapsedStyle");
			if (applyStyle)
				c1c_setHeaderStyle(src, applyStyle);
			else
				c1c_resetHeaderImages(src);
		}
		
		if (c1c_canDrag(src) || c1c_canToggle(src))
			src.style.cursor = "pointer";
	}
}	


//e == null when calling from code
function c1c_onHeaderMouseOut(src, e)
{
	if (!src.disabled && !(dragObj && e))
	{
		var expanded = c1c_isVisible(c1c_getHeaderContentRow(src).nextSibling);
		var applyStyle = c1c_getAttribute(src, (expanded) ? "expandedStyle" : "collapsedStyle");

		c1c_resetHeaderImages(src);	
			
		if (applyStyle != null)
			c1c_setHeaderStyle(src, applyStyle);		
	}
}


function c1c_toggleGroup(src, e)
{
	e.cancelBubble = true;
	
	if (!src.disabled)
	{
		src = c1c_upToTag(src, "TABLE");

		var id = c1c_getTopicBarId(src);
		var row = c1c_getHeaderContentRow(src);
	
		if (tbDatas[id].btnStyle && c1c_isVisible(row.nextSibling) && tbDatas[id].expandedGroup == src)
			return; 
		
		if (c1c_canToggle(src))
		{
			c1c_toggleVisibility(row.nextSibling); //body row
			var expanded = c1c_isVisible(row.nextSibling);

			c1c_updateGroupsStatus(row);
			
			if (tbDatas[id].expandedGroup)
				c1c_onHeaderMouseOut(tbDatas[id].expandedGroup, null); 
			
			if (tbDatas[id].autoCollapse && tbDatas[id].expandedGroup && src != tbDatas[id].expandedGroup)
			{
				if (tbDatas[id].btnStyle)
					c1c_setHeight(row.nextSibling.cells[0].firstChild, tbDatas[id].availHeight);  

				row = c1c_getHeaderContentRow(tbDatas[id].expandedGroup);
	
				if (expanded)
				{ 
					if (tbDatas[id].btnStyle)
						c1c_setHeight(row.nextSibling.cells[0].firstChild, "0"); 

					c1c_toggleVisibility(row.nextSibling); //body row
					c1c_onHeaderMouseOut(tbDatas[id].expandedGroup, null); 
					c1c_updateGroupsStatus(row);
				}
			}
	
			tbDatas[id].expandedGroup = (expanded) ? src : null;
		
			if ((tbDatas[id].expandPb && expanded) || (tbDatas[id].collapsePb && !expanded))
				__doPostBack(id, "");
			else
			{
				c1c_getHeadersPos(document.getElementById(id), tbDatas[id].headers);  
				
				if (!tbDatas[id].autoCollapse)
					c1c_onHeaderMouseOver(src, e); //mouse always over header
				else
				{
					var hdr = c1c_isMouseOverHeader(e, id)
					if (hdr)
						c1c_onHeaderMouseOver(hdr, e);
					else
						c1c_onHeaderMouseOut(src, e); 
				}
			}
		}
	}
}


function c1c_onItemMouseOver(src, e)
{
	if (!src.disabled && !dragObj)
	{
		var id = c1c_getTopicBarId(src);
		
		var itemInfo = c1c_getGroupItemInfo(src);
	
		if (tbDatas[id].selectedItem != itemInfo)
		{
			var applyStyle = c1c_getAttribute(src, "movStyle");

			if (applyStyle != null)
				c1c_setItemStyle(src, applyStyle, id);
		}
	
		if (c1c_isSpecified(src.onclick) || c1c_isSpecified(src.ondblclick))
		{
			src.style.cursor = "pointer";
	
			var href = c1c_getHref(src);
			if (href)
				window.defaultStatus = href;
		}
	}
}


function c1c_onItemMouseOut(src, e)
{
	if (!src.disabled && !dragObj)
	{
		var id = c1c_getTopicBarId(src);
		var itemInfo = c1c_getGroupItemInfo(src);
	
		if (tbDatas[id].selectedItem != itemInfo)
		{
			var applyStyle = c1c_getAttribute(src, "itemStyle");

			if (applyStyle != null)
				c1c_setItemStyle(src, applyStyle, id);
			else
			{
				src.style.cssText = "";
				c1c_resetItemContent(src, id);
			}
		}
	
		window.defaultStatus = "";
	}
}


function c1c_onItemClick(src, e)
{
	var id = c1c_getTopicBarId(src);
	var itemInfo = c1c_getGroupItemInfo(src);
	
	//if (tbDatas[id].selectedItem != itemInfo)
	//{
		var tmp = tbDatas[id].selectedItem;
		tbDatas[id].selectedItem = itemInfo;

		tbDatas[id].selectionStatus.value = itemInfo;		
		
		if (tbDatas[id].clickPb || c1c_checkItemCausesValidation(src) || (tbDatas[id].selectPb && !c1c_isSelected(src)))
			__doPostBack(id, "");
		else
		{
			if (tmp)
			{
				tmp = c1c_getItemByItemInfo(id, tmp);
				tmp.removeAttribute("selected");
				c1c_onItemMouseOut(tmp, e);
			}
	
			var applyStyle = c1c_getAttribute(src, "selectedStyle");
			if (applyStyle != null)
				c1c_setItemStyle(src, applyStyle, id);
			
			src.setAttribute("selected", "1");
		}
	//}
	
	var href = c1c_getHref(src);
	if (href)
		window.open(href, c1c_getTarget(src));
		
	e.cancelBubble = true;
}


function c1c_getHref(itemDiv)
{
	var res = ""
	
	if (itemDiv)
	{
		var a = itemDiv.getElementsByTagName("A");
		if (a)
			res = c1c_getAttribute(a[0], "h_ref");
	}
	
	return res;
}

function c1c_getTarget(itemDiv)
{
	var res = ""
	
	if (itemDiv)
	{
		var a = itemDiv.getElementsByTagName("A");
		if (a)
			res = c1c_getAttribute(a[0], "target");
	}
	
	return res;
}



function c1c_getItemByItemInfo(id, info)
{
	var tb = document.getElementById(id);
	var inf = info.split(":");
		
	var grpRow = tb.rows[0].cells[0].firstChild.rows[parseInt(inf[0])];
	var grpTable = grpRow.cells[0].firstChild;
	grpTable =  grpTable.rows[grpTable.rows.length - 1].cells[0].firstChild; // body
	
	return grpTable.childNodes[parseInt(inf[1])];
}


//HEADER STUFF
function c1c_canToggle(o)
{
	return (c1c_getAttribute(o, "banToggle") == null);
}


function getCaptionImg(hdrTable)
{
	return hdrTable.rows[0].cells[0].firstChild;
}


function getIndicatorImg(hdrTable)
{
	return hdrTable.rows[0].cells[2].firstChild;
}


function c1c_resetHeaderImages(hdrTable)
{
	if (hdrTable.style.backgroundImage)
		hdrTable.style.backgroundImage = "";
		
	obj = getCaptionImg(hdrTable);
	c1c_setVisibility(obj, false);
		
	obj = getIndicatorImg(hdrTable);
	c1c_setVisibility(obj, false);
}


function c1c_setHeaderStyle(table, styleStr)
{
	c1c_resetHeaderImages(table);
	table.style.cssText = "";
	styleStr += "width:100%";
	table.className = "";
	
	var ss = styleStr.split(";");
	
	for (var i = 0; i < ss.length; i++)
	{
		var pair = c1c_splitTwice(ss[i], ":");
		if (pair.length == 2)
		{
			if (pair[0] == "className")
				table.className = pair[1];
			else
				if (pair[0] == "captionImg")
				{
					var captImg = getCaptionImg(table); 
					captImg.src = pair[1];
					c1c_setVisibility(captImg, true);
				}
				else
					if (pair[0] == "indicatorImg")
					{
						var indImg = getIndicatorImg(table);
						indImg.src = pair[1];
						c1c_setVisibility(indImg, true);
					}
					else
						table.style[pair[0]] = pair[1];
		}
	}
}


function c1c_updateGroupsStatus(o)
{
	var o = c1c_getGroupContentRow(o);
	var id = c1c_getTopicBarId(o);
	
	if (tbDatas[id].init == 0)
	{
		tbDatas[id].groupsStatus.value = "";
		tbDatas[id].init = 1;
	}
	
	var tmp = tbDatas[id].groupsStatus.value.split(";");

	tbDatas[id].groupsStatus.value = "";
	var f = false;
			
	for (var i = 0; i < tmp.length - 1; i++)
		if (tmp[i] != o.rowIndex)
			tbDatas[id].groupsStatus.value += tmp[i] + ";";
		else
			f = true;
					
	if (!f)
		tbDatas[id].groupsStatus.value += o.rowIndex + ";";
}


//ITEMS STUFF
function c1c_resetItemContent(div, id)
{	
	if (div.childNodes.length > 2)
	{
		if (div.childNodes[1].tagName == "BR")
			div.removeChild(div.childNodes[1]);
			
		//if (div.childNodes[1].tagName == "SPAN")
		var bi = c1c_getBlankImage(div.getElementsByTagName("IMG")); 
		if (bi)
			div.removeChild(bi);
		
		//if (div.childNodes[1].tagName == "IMG") //blank image
		//	div.removeChild(div.childNodes[1]);
		
		if (div.firstChild.tagName == "A")
		{
			var tmp = div.firstChild.cloneNode(true);
			div.removeChild(div.firstChild);
			div.appendChild(tmp);
		}
		
		/*var tmp = document.createElement("SPAN");	
		tmp.innerHTML = "&nbsp;";
		tmp.style["textDecoration"] = "none";*/
		var tmp = document.createElement("IMG");
		tmp.setAttribute("src", tbDatas[id].blankUrl);
		tmp.setAttribute("align", "AbsMiddle");
		tmp.setAttribute("border", "0");
		tmp.setAttribute("b", "1");
		div.insertBefore(tmp, div.lastChild);
	}
}


function c1c_updateItemContent(div, imgPos)
{
	if (div.childNodes.length > 2)
	{
		if (imgPos == "Far")
		{
			var tmp = div.childNodes[1].cloneNode(true); //span
			div.removeChild(div.childNodes[1]);
			div.appendChild(tmp);
			
			var img = div.firstChild.cloneNode(true);
			div.removeChild(div.firstChild);
			div.appendChild(img);
		}
		else
			if (imgPos == "Bottom")
			{
				div.removeChild(div.childNodes[1]); //span
					
				var img = div.firstChild.cloneNode(true);
				div.removeChild(div.firstChild);
				var br = document.createElement("BR");
				div.appendChild(br);
				div.appendChild(img);
			}
			else
				if (imgPos == "Top")
				{
					div.removeChild(div.childNodes[1]); //span
						
					var br = document.createElement("BR");
					div.insertBefore(br, div.lastChild);
				}
	}
}


function c1c_getItemImagePosition(div)
{
	var res = "None";
	
	if (div.childNodes.length > 2)
	{
		if (div.childNodes[0].tagName == "A")
		{
			if (div.childNodes[1].tagName == "BR")
				res = "Bottom";
			else
				res = "Far";
		}
		else //[0] == "IMG"
		{
			if (div.childNodes[1].tagName == "BR")
				res = "Top";
			else
				res = "Near";
		}
	}
	
	return res;
}

function c1c_getBlankImage(imgs)
{
	var res = null;
	
	if (imgs)
		for (var i = 0; (i < imgs.length) && (!res); i++)
			if (c1c_getAttribute(imgs[i], "b"))
				res = imgs[i];

	return res;
}

function c1c_setItemStyle(div, styleStr, id)
{
	div.style.cssText = "";
	styleStr += "width:100%";
	div.className = "";

	var ss = styleStr.split(";");
	for (var i = 0; i < ss.length; i++)
	{
		var pair = c1c_splitTwice(ss[i], ":");

		if (pair.length == 2)
			if (pair[0] == "className")
				div.className = pair[1];
			else
				if (pair[0] == "itemImgPos")
				{
					if (c1c_getItemImagePosition(div) != pair[1])
					{
						c1c_resetItemContent(div, id);
						c1c_updateItemContent(div, pair[1]);
					}
				}
				else
					if (pair[0] == "imgTxSp")
					{
						var imgs = div.getElementsByTagName("IMG");
						if (imgs && imgs.length > 1) //blank image present
						{
							var bi = c1c_getBlankImage(imgs);
							bi.setAttribute("width", parseInt(pair[1]));
						}
					}
					else
						div.style[pair[0]] = pair[1];
	}
}


//MISC//
function c1c_isMouseOverHeader(e, id)
{
	var hdrs = tbDatas[id].headers;
	var evt = c1c_e(e);

	for (var i = 0; i < hdrs.length; i++)
		if (evt.x > hdrs[i].x && evt.x < hdrs[i].xx && evt.y > hdrs[i].y && evt.y < hdrs[i].yy)			
			if (dragObj == null || i != dragObj.groupIdx)
				return hdrs[i].header;
				
	return null;
}


//return header table
function c1c_getExpandedGroup(o)
{
	var res = null;
	if (o)
	{
		var grpRows = o.rows[0].cells[0].firstChild.rows;
	
		for (var i = 0; i < grpRows.length && res == null; i++)
		{
			var grp = grpRows[i].cells[0].firstChild;

			if ((grp.rows.length == 2) && c1c_isVisible(grp.rows[1]) && c1c_canToggle(grp.rows[0].cells[0].firstChild))
				res = grp.rows[0].cells[0].firstChild;
		}
	}
	
	return res;
}


function c1c_getSelectedItem(tb)
{
	var res = null;
	
	if (tb)
	{
		var grpRows = tb.rows[0].cells[0].firstChild.rows;
	
		for (var i = 0; i < grpRows.length && res == null; i++)
		{
			if (c1c_getAttribute(grpRows[i], "items"))
			{
				var grpTable = grpRows[i].cells[0].firstChild;
				var body = grpTable.rows[grpTable.rows.length - 1].cells[0].firstChild;
				//var items = body.rows[0].cells[0].firstChild.rows;
						
				for (var j = 0; j < body.childNodes.length && res == null; j++)
				{
					var itemDiv = body.childNodes[j];

					if (c1c_isSelected(itemDiv))
						res = i + ":" + c1c_getIdx(itemDiv); //#grpoup:#item
				}
			}
		}
	}
	
	return res;
}


function c1c_getIdx(obj)
{
	var res = -1;
	
	if (obj)
	{
		var prnt = c1c_getParent(obj);
		if (prnt)
			for (var i = 0; i < prnt.childNodes.length; i++)
				if (prnt.childNodes[i].tagName == obj.tagName)
				{
					res++;
					if (prnt.childNodes[i] == obj)
						return res;
				}
	}
	
	return res;
}


function c1c_getGroupItemInfo(itemDiv)
{
	var o = c1c_upToTag(itemDiv, "TABLE"); //group table
	var o = c1c_upToTag(o, "TR"); //group row
	
	return o.rowIndex + ":" + c1c_getIdx(itemDiv);
}


function c1c_getHeaderContentRow(o)
{
	while (o != null && c1c_getAttribute(o, "hdrrow") == null)
		o = c1c_getParent(o);

	return o;
}

function c1c_canDrag(o)
{
	var id = c1c_getTopicBarId(o);
	return tbDatas[id].canDrag; 
}

function c1c_getGroupContentRow(o)
{
	o = c1c_getHeaderContentRow(o);
	if (o)
	{
		o = c1c_getParent(o);
		o = c1c_upToTag(o, "TR"); 
	}
	
	return o;
}

function c1c_getGroupIdx(hdrTable)
{
	if (hdrTable != null)
		return c1c_getGroupContentRow(hdrTable).rowIndex; 
	else
		return -1;
}

function c1c_isSelected(itemDiv)
{
	return c1c_getAttribute(itemDiv, "selected");
}


function c1c_isVisible(o)
{
	return (!o.style.display || o.style.display == "");
}


function c1c_toggleVisibility(o)
{
	c1c_setVisibility(o, !c1c_isVisible(o));
}


function c1c_setVisibility(o, visible)
{
	o.style.display = (visible) ? "" : "none";
}


function c1c_getAttribute(o, name)
{
	if (o != null)
	{
		if (o.getAttribute)
			return o.getAttribute(name);
	
		if (o.attributes)
		{
			var atr = o.attributes[name];
			return (atr) ? val.value : null;
		}
		else
			return o[name];	
	}
	else
		return null;
}


function c1c_upToTag(o, name)
{
	var res = o;
	
	while (res != null && res.tagName != name)
		res = c1c_getParent(res);

	return res;
}


function c1c_getTopicBar(o)
{
	while (o != null && c1c_getAttribute(o, "tbtop") == null)
		o = c1c_getParent(o);

	return o;
}


function c1c_getTopicBarId(o)
{
	o = c1c_getTopicBar(o);
	return c1c_getAttribute(o, "id");
}

function c1c_getParent(o)
{
	if (o != null)
		return (o.parentElement) ? o.parentElement : o.parentNode;
	else
		return null;
}

function c1c_findPosX(o)
{
	var res = 0;
  
	if (o)
	do 
	{
		res += o.offsetLeft + ((o.border == undefined || o.border == "") ? 0 : parseInt(o.border));
		o = o.offsetParent;
	} 
	while (o != null);
   
   	return res;
}


function c1c_findPosY(elem)
{
	var res = 0;

	if (elem)
	do 
	{
		res += elem.offsetTop + ((elem.border == undefined || elem.border == "") ? 0 : parseInt(elem.border));
		elem = elem.offsetParent;
	} 
	while (elem != null);
   
	return res;
}

function c1c_isSpecified(val)
{
	return (val && (typeof(val) != "undefied")) ? true : false;
}


function c1c_setHeight(o, val)
{
	//if (o.style && o.style["height"])
	if (o.style)
		o.style["height"] = val;
	else
		o.setAttribute("height", val);
}


function c1c_splitTwice(str, ch)
{
	var res = new Array();

	if (str)
	{
		var i = str.indexOf(ch);
		
		if (i >= 0)
		{
			res[0] = str.substr(0, i);
			res[1] = str.substr(i + 1, str.length);
		}
	}

	return res;
}

//CROSSBROWSER
function c1c_getByName(name)
{
	var o = document.getElementById(name);
	if (!o)
	{
		for (var i = 0; i < document.forms.length; i++)
		if (typeof(document.forms[i].elements[name]) != "undefined")
		{
			o = document.forms[i].elements[name]
			break;				
		}
	}
	
	return o;
}


function c1c_e(e)
{
	var o = new Object();
	
	o.x = (isIE) ? e.x : e.pageX;
	o.y = (isIE) ? e.y : e.pageY;
	o.leftBtn = (isIE) ? (e.button == 1) : true;
	
	return o;
}


function c1c_cleanNode(dest)
{
	while (child = dest.firstChild) dest.removeChild(child);
}


function c1c_copyContent(from, to)
{
	c1c_cleanNode(to);
	
	if (isIE)
	{
		var tmp = to.cloneNode(false);
		tmp.innerHTML = from.innerHTML;
		to.replaceNode(tmp);
	}
	else
		for (var child = from.firstChild; child; child = child.nextSibling)
			c1c_copyNodeDOM(child, to);
}

function c1c_copyNodeDOM(node, to)
{
	var newNode;

	switch (node.nodeType)
	{
		case 1: // ELEMENT_NODE
			newNode = document.createElement(node.nodeName.toLowerCase());

			for (var i = 0; i < node.attributes.length; i++)
			{
				var value = node.attributes[i].nodeValue;

				if (node.attributes[i].specified && value != null)
					newNode.setAttribute(node.attributes[i].nodeName.toLowerCase(), value);
			}

			c1c_copyContent(node, newNode);
			break;

		case 3:   //TEXT_NODE
			newNode = document.createTextNode(node.nodeValue);
			break;
	}

	if (newNode)
	{
		var addedNode;
		addedNode = to.appendChild(newNode);
		if (node.form)
			addedNode.value = node.value;
	}
}


function c1c_clearNode(o)
{
	c1c_clear(o, 0); 
}

function c1c_clear(o, level)
{
	while (o != null)
	{
		if (o.onmouseout)
			o.onmouseout =  null;
		
		if (o.onmouseover)
			o.onmouseover = null;
		
		if (o.onclick)
			o.onclick = null;
			
		if (o.ondblclick)
			o.ondblclick = null;
		
		if (c1c_getAttribute(o, "id"))
			o.removeAttribute("id");
		
		c1c_clear(o.firstChild, level + 1);
		
		if (level == 0)
			return;
	
		o = o.nextSisbling;
	}
}

//PAGE VALIDATION
// returns true if item has attribute "CausesValidation"
function c1c_checkItemCausesValidation(obj)
{
	return c1c_getAttribute(obj, "CausesValidation");
}

document.writeln('<div id="c1c_dragItem" style="cursor:move;position:absolute;visibility:hidden;filter:progid:DXImageTransform.Microsoft.BasicImage(Invert=1,Opacity=0.45); z-index:0"></div>');