/*
Usage:
	<div class="ch-mainnavi">
	<table border="0" cellpadding="0" cellspacing="0" width="100%" height="100%">
	<tr>
	<td nowrap><a href="#" name="ch_mainnavi" id="ch_mainnavi_1" class="ch-mainnavilink" onmouseover="ch_mouseover(this);" onmouseout="ch_mouseout(this);" onmousedown="ch_mousedown(this);" onmouseup="ch_mouseup(this);">Sivuston hallinta</a></td>
	<td nowrap width="100%" style="text-align:right;"><img src="images/ch_logo_cubicle.gif" alt="" width="62" height="23" border="0" onclick="alert('Cubicle Application Framework\nVersion 0.5\n&copy; 2005 Kateetti Oy\nAll rights reserved.');"></td>
	</tr>
	</table>
	</div>

	<div id="ch_mainnavi_1_div" class="ch-subnavi" onmouseout="ch_hiliteRow();">
	<table border="0" cellpadding="0" cellspacing="0" class="ch-subnavi">
	<tr class="ch-subnavi-row" onmouseover="ch_hiliteRow(this);" onclick="ch_closeMenu(); location.href='';">
	<td class="ch-subnavi-icon"><img src="images/ch_icon_new.gif" alt="" width="24" height="20" border="0"></td>
	<td class="ch-subnavi-text"><a href="">Testilinkki</a></td>
	<td class="ch-subnavi-more"><img src="images/px.gif" alt="" width="15" height="20" border="0"></td>
	</tr>
	<tr class="ch-subnavi-row" onmouseover="ch_hiliteRow(this);" onclick="ch_closeMenu(); location.href='';">
	<td class="ch-subnavi-icon"><img src="images/px.gif" alt="" width="24" height="20" border="0"></td>
	<td class="ch-subnavi-text"><a href="">Testilinkki 2</a></td>
	<td class="ch-subnavi-more"><img src="images/ch_subnavi_more.gif" alt="" width="15" height="20" border="0"></td>
	</tr>
	<tr><td colspan="3" class="ch-subnavi-separator"></td></tr>
	<tr class="ch-subnavi-row" onmouseover="ch_hiliteRow(this);" onclick="ch_closeMenu(); location.href='';">
	<td class="ch-subnavi-icon"><img src="images/px.gif" alt="" width="24" height="20" border="0"></td>
	<td class="ch-subnavi-text"><a href="">Testilinkki 3</a></td>
	<td class="ch-subnavi-more"><img src="images/px.gif" alt="" width="15" height="20" border="0"></td>
	</tr>
	</table>
	</div>
*/

var ch_menuOpen = false;
var ch_notWindow = false;

var ch_old_onclick = null;

function ch_onclick(e, b) {
	if (!e) e = window.event;
	if (ch_notWindow) { ch_notWindow = false; /*alert("menu click");*/ return; }
//	alert("window click");
	if (ch_menuOpen) {
		ch_closeMenu();
	}
	if (ch_old_onclick&&e) ch_old_onclick(e);
}

function ch_closeMenu() {
	var obs = document.getElementsByName("ch_mainnavi");
	for (var i=0; i < obs.length; i++) if (obs[i].className == "ch-mainnavilink-down") {
		obs[i].className = "ch-mainnavilink";
		document.getElementById(obs[i].id + "_div").style.display = "none";
	}
	ch_menuOpen = false;
}

function ch_openMenu(id, dX, dY) {
	var div = document.getElementById(id+"_div");
	var el = document.getElementById(id);
	el.className = "ch-mainnavilink-down";
	div.style.left = pos_getAbsX(el)+dX+"px";
	div.style.top = pos_getAbsY(el)+el.offsetHeight+dY+"px";
	div.style.display = "block";
	ch_menuOpen = true;
	if (document.all)
	{
		var trouble=document.getElementsByTagName('SELECT');
		for (var i=0;i<trouble.length;i++) ch_drag_hack_toggle_mask(trouble[i],'on');
	}
}

function ch_mouseover(el) {
	if (ch_menuOpen) {
		ch_closeMenu();
		ch_openMenu(el.id, 0, -1);
		return;
	}
	el.className = "ch-mainnavilink-hover";
}

function ch_mouseout(el) {
	if (ch_menuOpen) return;
	el.className = "ch-mainnavilink";
}

function ch_mousedown(el) {
	if (ch_menuOpen) {
		ch_closeMenu();
		el.className = "ch-mainnavilink-hover";
		return;
	}
	ch_openMenu(el.id, 0, -1);
}

function ch_mouseup(el) {
	ch_notWindow = true;
	if (ch_menuOpen) return;
	el.className = "ch-mainnavilink-hover";
}

function ch_dehiliteRow() {
	var rows = document.getElementsByTagName("TR");
	for (var j=0; j<rows.length; j++) if(rows[j].over) {
		rows[j].over = null;
		for (var i=0; i<rows[j].childNodes.length; i++) if (rows[j].childNodes[i].tagName == "TD") {
			rows[j].childNodes[i].className = rows[j].childNodes[i].className.substring(0,15);
		}
 	}
}

function ch_hiliteRow(el) {
	if (el) { } else {
		ch_dehiliteRow();
		return;
	}
	if (el.over) return;
	ch_dehiliteRow();
	el.over = true;
	for (var i=0; i<el.childNodes.length; i++) if (el.childNodes[i].tagName == "TD") {
		el.childNodes[i].className = el.childNodes[i].className + "-hover";
	}
}

function ch_init()
{
	//if (document.all) setTimeout("ch_toggle_dropdown_hack(false);",100);
	if (document.all) ch_toggle_dropdown_hack(false);
	ch_old_onclick = (window.onclick)?window.onclick:document.body.onclick;
//	window.onclick = ch_onclick;
	document.body.onclick = ch_onclick;
	if (ch_onload) ch_onload();
}

var ch_onload = window.onload;
window.onload = ch_init;


























//###################################################################################
//#
//#  Hack for handling dropdown lists which are shown through floating
//#  elements in Internet Explorer browsers:
//#  1) add a lookalike-mask for "SELECT"-elements
//#  2) hide "SELECT"-elements
//#  3) expose original element onmouseover
//#
//###################################################################################
var ch_drag_hack_hidden=new Array();
function ch_drag_hack_toggle_mask(el,on_off)
{
	if (!el) return;
	if (!el.ownerDocument) return;
	if (!el.style) return;
	var mask=el.ownerDocument.getElementById(el.id+'_mask');
	try
	{
		if (on_off=='off')
		{
			mask.style.display='none';
			el.style.display='';
		}
		else
		{
			mask.style.width=el.clientWidth;
			mask.style.height=el.clientHeight;
			mask.style.display='';
			el.style.display='none';
		}
	}
	catch (e)
	{
	}
}
function ch_drag_hack_update_mask(el, disable_automask)
{
	if (el.options==null) return;
	var text="";
	var focushandler=' onmouseover="var e=document.getElementById(\''+el.id+'\');ch_drag_hack_toggle_mask(e);e.onblur=\'ch_drag_hack_toggle_mask(this);\';" ';
	if (disable_automask) focushandler='';
	var maskstyle=' style="width:'+el.clientWidth+'px;height:'+el.clientHeight+'px;" ';
	if (el.size>1||el.multiple)
	{
		for (var j=0;j<el.options.length;j++)
		{
			if (el.options[j].selected) text+='<div class="ch_drag_mask_selected">'+el.options[j].text+'</div>';
			else text+="<div class=\"ch_drag_mask_item\">"+el.options[j].text+'</div>';
		}
	}
	else
	{
		text+="<span class=\"ch_drag_mask_item\" style=\"wrap:left\">"+(el.options.length>0?el.options[el.selectedIndex].text:"")+"</span><br><br><br>";
	}
	ch_set_inner_html(el.ownerDocument.getElementById(el.id+'_mask'),text);
}
var ch_drag_ids=1;
function ch_drag_new_id()
{
	ch_drag_ids++;
	return "drag_item_"+ch_drag_ids;
}
function ch_init_dropdown_hack()
{
	if (!document.all) return;
	if (browser && browser.isIE && browser.versionMajor>=7) return;
	// hide dropdowns
	var els=document.getElementsByTagName('SELECT');
	var new_index=ch_drag_hack_hidden.length;
	for (var i=0;i<els.length;i++)
	{
		if (!els[i].id) els[i].id=ch_drag_new_id();
		if (document.getElementById(els[i].id+'_mask')) continue;
		if (els[i].offsetWidth==0) continue; // cannot help if dimensions are unknown...
		if (!els[i].style) continue; // cannot help if there is no style
		els[i].onmouseout="setTimeout('ch_drag_hack_toggle_mask(document.getElementById(\\\'"+els[i].id+"\\\'),\\\'on\\\');',1000);";
		els[i].oldonchange=els[i].onchange;
		els[i].onchange="ch_drag_hack_update_mask(this);if (this.oldonchange) this.oldonchange();";
		ch_drag_hack_hidden[ch_drag_hack_hidden.length]=els[i];
	}
	for (var i=new_index;i<ch_drag_hack_hidden.length;i++)
	{
		var el=ch_drag_hack_hidden[i];
		var id=el.id;
		var maskstyle=' style="width:'+el.clientWidth+'px;height:'+el.clientHeight+'px;" ';
		el.style.display='none';
		var outer="<span "+maskstyle+">"+ch_get_outer_html(el);
		var text="";
		var focushandler=' onmouseover="var e=document.getElementById(\''+id+'\');ch_drag_hack_toggle_mask(e,\'off\');"  onmouseout="if (this.style.display!=\'none\') {var e=document.getElementById(\''+id+'\');ch_drag_hack_toggle_mask(e,\'on\');}" ';
		outer+='<span class=\"ch_drag_mask\" id="'+id+'_mask" '+focushandler+maskstyle+'></span>';
		outer+="</span>";
		//alert(outer);
		ch_set_outer_html(el,outer);
		ch_drag_hack_update_mask(document.getElementById(id));
	}
}
function ch_toggle_dropdown_hack(hack_enabled,retry)
{
	if (!document.all) return;
	if (browser && browser.isIE && browser.versionMajor>=7) return;
	try
	{
	if (ch_drag_hack_hidden.length==0)
	{
    	var els=document.getElementsByTagName('SELECT');
    	var new_index=ch_drag_hack_hidden.length;
    	for (var i=0;i<els.length;i++)
    	{
    		if (!els[i].id) els[i].id=ch_drag_new_id();
    		if (document.getElementById(els[i].id+'_mask')) continue;
    		//if (els[i].offsetWidth==0) continue; // cannot help if dimensions are unknown...
    		if (!els[i].style) continue; // cannot help if there is no style
    		//els[i].onmouseout="setTimeout('ch_drag_hack_toggle_mask(document.getElementById(\\\'"+els[i].id+"\\\'),\\\'on\\\');',1000);";
			els[i].oldonchange=els[i].onchange;
			els[i].onblur="ch_drag_hack_update_mask(this);";
    		ch_drag_hack_hidden[ch_drag_hack_hidden.length]=els[i];
    	}
    	for (var i=new_index;i<ch_drag_hack_hidden.length;i++)
    	{
    		var el=ch_drag_hack_hidden[i];
    		var id=el.id;
    		var maskstyle=' style="width:'+el.clientWidth+'px;height:'+el.clientHeight+'px;" ';
			if (el.clientWidth==0) maskstyle=' style="width:50px;height:15px;" ';
    		el.style.display='none';
    		var outer="<span "+maskstyle+">"+ch_get_outer_html(el);
    		var text="";
			var focushandler='';
    		//var focushandler=' onmouseover="var e=document.getElementById(\''+id+'\');ch_drag_hack_toggle_mask(e,\'off\');"  onmouseout="if (this.style.display!=\'none\') {var e=document.getElementById(\''+id+'\');ch_drag_hack_toggle_mask(e,\'on\');}" ';
    		outer+='<span class=\"ch_drag_mask\" id="'+id+'_mask" '+focushandler+maskstyle+'></span>';
    		outer+="</span>";
    		//alert(outer);
    		ch_set_outer_html(el,outer);
    		ch_drag_hack_update_mask(document.getElementById(id),true);
			ch_drag_hack_toggle_mask(document.getElementById(ch_drag_hack_hidden[i].id),hack_enabled?'on':'off');
    	}
	}
	else
	for (var i=0;i<ch_drag_hack_hidden.length;i++)
		ch_drag_hack_toggle_mask(document.getElementById(ch_drag_hack_hidden[i].id),hack_enabled?'on':'off');
	}
	catch (e)
	{
		if (retry) ; else setTimeout("ch_toggle_dropdown_hack("+(hack_enabled?'true':'false')+",1);",2000);
	}
}

//###################################################################################
//#
//#  InnerHTML and OuterHTML DOM compatibility functions
//#
//###################################################################################

function ch_set_inner_html(e, value)
{
	if (e==null) return;
	if (e.innerHTML!=null) {e.innerHTML=value;return;}
	var r = e.ownerDocument.createRange();
	r.selectNodeContents(e);
	r.deleteContents();
	var df = r.createContextualFragment(value);
	e.appendChild(df);
}

function ch_set_outer_html(e, value)
{
	if (e==null) return;
	if (e.outerHTML!=null) {e.outerHTML=value;return;}
	var r = e.ownerDocument.createRange();
	r.setStartBefore(e);
	var df = r.createContextualFragment(value);
	e.parentNode.replaceChild(df, e);
}

function ch_get_outer_html(node)
{
	if (node.outerHTML!=null) return node.outerHTML;
	var str = "";
	var _leafElems = new Array("IMG", "HR", "BR", "INPUT");
	var leafElems = new Array();
	for (var i=0; i<_leafElems.length; i++) leafElems[_leafElems[i]] = true;
	switch (node.nodeType)
	{
	case 1: // ELEMENT_NODE
		str += "<" + node.nodeName;
		for (var i=0; i<node.attributes.length; i++)
		{
			if (node.attributes.item(i).nodeValue == null) continue;
			str += " "
			str += node.attributes.item(i).nodeName;
			str += "=\"";
			str += node.attributes.item(i).nodeValue;
			str += "\"";
		}
		if (node.childNodes.length == 0 && leafElems[node.nodeName]) str += ">";
		else
		{
			str += ">";
			str += get_inner_html(node);
			str += "</" + node.nodeName + ">"
		}
		break;

	case 3:   //TEXT_NODE
		str += node.nodeValue;
		break;

	case 4: // CDATA_SECTION_NODE
		str += "<![CDATA[" + node.nodeValue + "]]>";
		break;

	case 5: // ENTITY_REFERENCE_NODE
		str += "&" + node.nodeName + ";"
		break;

	case 8: // COMMENT_NODE
		str += "<!--" + node.nodeValue + "-->"
		break;
	}
	return str;
}





function ce_notify(){ce_showMessage("info",arguments);}
function ce_error(){ce_showMessage("error",arguments);}
function ce_warning(){ce_showMessage("warning",arguments);}
function ce_showMessage(t,a){try{ce_oNotify.newMessage(t,a);}catch(e){ce_initNotify();ce_oNotify.newMessage(t,a);}}
function ce_initNotify()
{
	this.container=document.createElement("div");
	this.container.id="notifydiv";
	this.content=document.createElement("div");
	this.content.className="notifycontent";
	this.control=document.createElement("div");
	this.control.className="notifycontrol";
	this.container.appendChild(this.content);
	this.container.appendChild(this.control);
	this.prev=document.createElement("A");this.prev.href="javascript:void(0)";this.prev.onclick=function(){ce_oNotify.go(-1);};this.prev.appendChild(document.createTextNode("<"));
	this.next=document.createElement("A");this.next.href="javascript:void(0)";this.next.onclick=function(){ce_oNotify.go(1);};this.next.appendChild(document.createTextNode(">"));
	this.loaded=true;
	if (document.readyState!=null && document.readyState!=undefined && document.readyState!="complete")
	{
		window.notoldonload=window.onload;
		window.onload=function(){
			document.body.appendChild(ce_oNotify.container);
			ce_oNotify.show();
			ce_oNotify.loaded=true;
			if(window.notoldonload!=null&&window.notoldonload!=undefined)window.notoldonload();
		}
		this.loaded=false;
	}
	else
	{
		t=document.createElement("img");t.src=(appurl?appurl+"/":"")+"images/ch_showmessages.gif";t.onmouseover=function(){ce_oNotify.show();};t.id="notifyshow";
		document.body.appendChild(t);
		document.body.appendChild(this.container);
	}
	this.messages = new Array();
	this.shown = -1;
	this.shownMessages = 0;
	this.tmp = 0;
	this.visible = false;
	this.delay = -1;
	this.timer = null;

	this.mouseover = function(){clearTimeout(ce_oNotify.timer);ce_oNotify.timer=null;ce_oNotify.delay=-1;ce_oNotify.showControls();};
 	this.newMessage = function (type, contentArray)
	{
		var text="";for(var i=0;i<contentArray.length;i++)text+=contentArray[i];if(text=="")return;
		if(type!="info"&&type!="warning"&&type!="error")type="info";
		var d=new Date();
		var h=d.getHours().toString();h=h.length<2?"0"+h:h;
		var m=d.getHours().toString();m=m.length<2?"0"+m:m;
		this.messages.push(new Array(type, "["+h+":"+m+"] "+text));
		if(this.loaded)this.show();
	}
	this.update = function (h)
	{
		if(this.container){ }else return;
		this.container.style.display="none";
		this.container.style.width=parseInt(document.body.clientWidth)+"px";
		this.container.style.display="";
		this.container.style.left=document.all?parseInt(document.body.scrollLeft)+"px":"0px";
		if(h!=null&&h!=undefined) { if(h>0)h=-h; this.container.style.top=h+"px"; }
	}
	this.scrollUp = function ()
	{
		this.container.onmouseover=null;
		var h=parseInt(this.container.offsetHeight);
		if(this.tmp++>20){this.container.style.top=-h*2+"px";tmp=0;}
		var y=-parseInt(this.container.style.top);
		if(y<h)
		{
			var k=(y/h)+0.03;
			y=y+k*100;
			y=-y;
			this.container.style.top=Math.round(y)+"px";
			if(-y<h)setTimeout(this.scrollUp,100);
			else {this.tmp=0;this.visible=false;this.shown=-1;if(this.shownMessages<this.messages.length)this.show();}
		}
	}
	this.scrollDown = function ()
	{
		if(this.tmp++>20){this.container.style.top="0px";tmp=0;}
		var t=parseInt(this.container.style.top);
		var y=-t;
		var h=parseInt(this.container.offsetHeight);
		if(y!=0)
		{
			var k=1-(h-y)/h;
			y=(k*.45)*h;
			y=(y<0?0:-Math.round(y));
			if(y==t)y=0;
			this.container.style.top=Math.round(y)+"px";
			if(y!=0)setTimeout(this.scrollDown,100);
			else{this.tmp=0;this.delay=3;this.container.onmouseover=this.mouseover;this.timeout(); }
		}
	}
	this.timeout = function ()
	{
		if(this.delay==0){this.timer=null;this.delay=-1;this.showDelay();this.scrollUp();}
		else if(this.delay==-1){this.timer=null;this.showDelay();return;}
		else{this.showDelay();this.delay--;this.timer=setTimeout(ce_oNotify.timeout,1000);}
	}
	this.showDelay = function(){this.control.innerHTML=this.delay==-1?"":"("+this.delay+")";}
	this.showControls = function(){
		this.control.innerHTML="";
		if(this.shown<=0)this.prev.style.visibility="hidden";
		else this.prev.style.visibility="visible";
		if(this.shown>=this.messages.length-1)this.next.style.visibility="hidden";
		else this.next.style.visibility="visible";
		this.control.appendChild(this.prev);
		this.control.appendChild(document.createTextNode(' '+(this.shown+1)+'/'+this.messages.length+' '));
		this.control.appendChild(this.next);
	}
	this.go = function(d)
	{
		this.shown+=isNaN(parseInt(d))?0:parseInt(d);
		if(this.shown<0)this.shown=0;
		else if(this.shown>this.messages.length-1)this.shown=this.messages.length-1;
		if(this.shownMessages<this.shown+1)this.shownMessages=this.shown+1;
		this.container.className="notify"+this.messages[this.shown][0];
		this.content.innerHTML=this.messages[this.shown][1];
		this.showControls();
	}
	this.show = function (msg)
	{
		if(this.visible)return;
		if(msg==null||msg==undefined)msg=(this.shownMessages<this.messages.length)?this.shownMessages:this.shownMessages-1;
		if(msg<0||msg>=this.messages.length)return;
		this.container.className="notify"+this.messages[msg][0];
		this.content.innerHTML=this.messages[msg][1];
		this.update(parseInt(this.container.offsetHeight));
		if(this.shownMessages<msg+1)this.shownMessages=msg+1;
		this.shown=msg;
		this.visible = true;
		this.scrollDown();
	}
	this.hide = this.scrollUp;

	var t=document.createElement("img");t.src=(appurl?appurl+"/":"")+"images/ch_b_close.gif";t.onclick=function(){ce_oNotify.hide();};
	this.container.appendChild(t);
	if(document.all){this.oldonscroll=window.onscroll;window.onscroll=function(){ce_oNotify.container.style.left=parseInt(document.body.scrollLeft)+"px";}}
	this.oldonresize=window.onresize;
	window.ce_oNotify=this;
	window.onresize=function(){setTimeout(ce_oNotify.update,10,null);if(ce_oNotify.oldonresize!=null&&ce_oNotify.oldonresize!=undefined)ce_oNotify.oldonresize();}
}


/* Sortable tables (just add class 'sortable') ***************************************************************************/
function ce_initTableSort()
{
	function innit(h,n){h=" "+h+" ";if(h.indexOf(" "+n+" ")>=0)return true;return false;}
	window.oTableSort={
		addtotal:function(el,n,notext)
		{
			var row=document.createElement("TR");
			addClass(row,"sortabletotal");
			var cell=document.createElement("TD");
			cell.colSpan=el.rows[0].cells.length;
			if(notext)cell.appendChild(document.createTextNode(n+" "));
			else cell.appendChild(document.createTextNode(n+" | "+oTableSort.gettext(el.rows[el.rows.length-1].cells[oTableSort.col])));
			row.appendChild(cell);
			el.appendChild(row);
		},
		gettext:function(el)
		{
			if(el.innerText) return el.innerText;
			if(el.textContent) return el.textContent;
			return "";
		},
		getvalue:function(el)
		{
			var t=el.getAttribute("sortvalue");if(t)return t;
			return oTableSort.gettext(el);
		},
		sortrows:function(a,b)
		{
			var t1=oTableSort.getvalue(a.cells[oTableSort.col]);
			var t2=oTableSort.getvalue(b.cells[oTableSort.col]);
			if (t1<t2) return -1;
			if (t1>t2) return 1;
			return 0;
		},
		sortby:function (el,col,count)
		{
			while(el.nodeName!="TABLE"&&el.parentNode)el=el.parentNode;
			if(el.nodeName!="TABLE")return;
			var ocol = el.getAttribute("sortcol");
			if (col==ocol) var dir = (el.getAttribute("sortdir")==1)?0:1;
			else var dir=1;
			oTableSort.col=col;
			if(ocol!=null)
			{
				var cell = el.tHead.rows[el.tHead.rows.length-1].cells[ocol];
				cell.style.backgroundImage="none";
				cell.style.paddingRight=cell.oldpadding?cell.oldpadding:0;
			}
			var cell = el.tHead.rows[el.tHead.rows.length-1].cells[col];
			cell.style.backgroundImage="url('"+(appurl?appurl+"/":"")+"images/ch_tablesort"+dir+".gif')";
			cell.style.backgroundRepeat="no-repeat";
			cell.style.backgroundPosition="right";
			cell.oldpadding=cell.style.paddingRight;
			cell.style.paddingRight="15px";
			for(var j=0;j<el.tBodies.length;j++)
			{
				if(hasClass(el.tBodies[j],"nosort"))continue;
				var newRows = new Array();
				for(var i=0;i<el.tBodies[j].rows.length;i++)
				{
					if(count&&hasClass(el.tBodies[j].rows[i],"sortabletotal"))
					{
						el.tBodies[j].removeChild(el.tBodies[j].rows[i]);
						i--;
					} else newRows.push(el.tBodies[j].rows[i]);
				}
				newRows.sort(oTableSort.sortrows);
				if(!dir)newRows.reverse();
				var s1=oTableSort.getvalue(newRows[0].cells[oTableSort.col]),s2="",k=0;
				for(var i=0;i<newRows.length;i++)
				{
					if(count)
					{
						s2=oTableSort.getvalue(newRows[i].cells[oTableSort.col]);
						if(s1!=s2)
						{
							s1=s2;
							oTableSort.addtotal(el.tBodies[j],k);
							k=0;
						}
						k++;
					}
					el.tBodies[j].appendChild(newRows[i]);
				}
				if(count)
				{
					oTableSort.addtotal(el.tBodies[j],k);
					oTableSort.addtotal(el.tBodies[j],newRows.length,true);
				}
			}
			el.setAttribute("sortcol",col);
			el.setAttribute("sortdir",dir);
			if(window.ce_oStripeTable)ce_oStripeTable.stripe(el);
		},
		col:0
	};
	var tables = document.getElementsByTagName("table");
	for (var i=0;i<tables.length;i++)if(hasClass(tables[i],"sortable") && tables[i].getAttribute("sortInitialized")!=1)with(tables[i])
	{
		if(tHead&&tBodies)
		{
			if(tBodies.length<1)continue;
			if(tBodies[0].rows.length<1)continue;
			var s="false";
			if(innit(className,"count"))s="true";
			for(var j=0;j<tHead.rows[tHead.rows.length-1].cells.length;j++)if(!hasClass(tHead.rows[tHead.rows.length-1].cells[j],"nosort"))
			{
				eval("tHead.rows[tHead.rows.length-1].cells[j].onclick=function(){oTableSort.sortby(this,"+j+","+s+");}");
				tHead.rows[tHead.rows.length-1].cells[j].style.cursor="pointer";
			}
			tables[i].setAttribute("sortInitialized", 1);
		}
	}
}
if(window.addEventListener){window.addEventListener('load',ce_initTableSort,false);}else if(window.attachEvent){window.attachEvent('onload',ce_initTableSort);}


/* Stripe tables (just add class="zebra") ************************************/
function ce_initStripeTable()
{
	window.ce_oStripeTable={
		stripe:function(t)
		{
			if(t==null||t==undefined) return;;
			if(hasClass(t,"zebra"))for(var j=0;j<t.tBodies.length;j++)
			{
				var b=t.tBodies[j];
				var odd=false;
				for(var k=0;k<b.rows.length;k++)
				{
					if(odd){removeClass(b.rows[k],"evenrow");addClass(b.rows[k],"oddrow");}
					else{addClass(b.rows[k],"evenrow");removeClass(b.rows[k],"oddrow");}
					odd=!odd;
				}
			}
		}
	};

	var t=document.getElementsByTagName("TABLE");
	for(var i=0;i<t.length;i++)ce_oStripeTable.stripe(t[i]);
}
if(window.addEventListener){window.addEventListener('load',ce_initStripeTable,false);}else if(window.attachEvent){window.attachEvent('onload',ce_initStripeTable);}

/* Highlight rows (just add class="highlight") *******************************/
function ce_initRowHighlight(base_element)
{
	window.ce_oRowHighlight={
		highlight:function(e)
		{
			if(e==null||e==undefined)return;if(e.nodeName!="TR")return;
			addClass(e,"highlight");
		},
		dehighlight:function(e)
		{
			if(e==null||e==undefined)return;if(e.nodeName!="TR")return;
			removeClass(e,"highlight");
		}
	};

	if(!base_element || !base_element.getElementsByTagName) base_element = document;
	if(base_element.nodeName=="TABLE") var t=new Array(base_element);
	else var t=base_element.getElementsByTagName("TABLE");
	for(var i=0;i<t.length;i++)
	{
		if(hasClass(t[i],"highlight"))for(var j=0;j<t[i].tBodies.length;j++)for(var k=0;k<t[i].tBodies[j].rows.length;k++)if(!t[i].tBodies[j].rows[k].className.match(/(^| )no-highlight($| )/))
		{
			t[i].tBodies[j].rows[k].onmouseover=function(){ce_oRowHighlight.highlight(this);}
			t[i].tBodies[j].rows[k].onmouseout=function(){ce_oRowHighlight.dehighlight(this);}
		}
	}
}
if(window.addEventListener){window.addEventListener('load',ce_initRowHighlight,false);}else if(window.attachEvent){window.attachEvent('onload',ce_initRowHighlight);}

