function radiocell_find(parent,name,type)
{
	return choicecell_find(parent,name,type);
}

function radiocell_onclick(cell)
{
	return choicecell_onclick(cell);
}

function radiocell_ondblclick(cell)
{
	return choicecell_ondblclick(cell);
}

function checkboxcell_onclick(cell)
{
	return choicecell_onclick(cell);
}

function choicecell_find(parent)
{
	if (parent == null) return null;
	if (parent.nodeName.toLowerCase() == "a" || parent.nodeName.toLowerCase() == "input" && (parent.type.toLowerCase() == "radio" || parent.type.toLowerCase() == "checkbox" || parent.type.toLowerCase() == "text")) return parent;
	for (var i = 0; i < parent.childNodes.length; ++i)
	{
		var sub = choicecell_find(parent.childNodes[i]);
		if (sub != null) return sub;
	}
	return null;
}

function choicecell_onclick(cell)
{
	var srcType = event.srcElement.nodeName.toLowerCase();
	if (srcType == 'input' || srcType == 'textarea' || srcType == 'select') return;
	var ctl = choicecell_find(cell);
	if (event.srcElement == ctl) return;
	if (!ctl) return;
	if (ctl.disabled) return;
	ctl.checked = ctl.type.toLowerCase() == "radio" || !ctl.checked;
	ctl.focus();
	ctl.onclick();
	return false;
}

function choicecell_ondblclick(cell)
{
	var srcType = event.srcElement.nodeName.toLowerCase();
	if (srcType == 'input' || srcType == 'textarea' || srcType == 'select') return;
	var ctl = choicecell_find(cell);
	if (event.srcElement == ctl) return;
	if (!ctl) return;
	if (ctl.disabled) return;
	ctl.checked = ctl.type.toLowerCase() == "radio" || !ctl.checked;
	ctl.focus();
	ctl.ondblclick();
	return false;
}

function scrollComponent(id,top,left,n)
{
	var comp = getComponent(id);
	if (comp != null)
	{
		comp.scrollTop = top;
		comp.scrollLeft = left;
		if (n < 5)
		{
			setTimeout("scrollComponent('" + id + "'," + top + "," + left + "," + (n + 1) + ");",200);
		}
	}
}

var lasttimer = null;
var starttime = null;

function doTimer(id,intv,tim)
{
	var inp = getComponent(id);
	if (inp == null) return;
	var tick = new Date().getTime() - starttime;
	var rest = tick % intv;
	if (rest != 0) tick -= rest
	if (tick > tim) tick = tim;
	inp.value = tick;
	inp.onchange();
	if (parseInt(inp.value) >= tim) immediateEvent(true,id,"ontimer",inp.value,null);
}

function startTimer(id1,intv,tim)
{
	if (lasttimer != null) clearInterval(lasttimer);
	starttime = new Date().getTime();
	lasttimer = setInterval("doTimer('" + id1 + "'," + intv + "," + tim + ");",intv);
}

function scale_onclick(sid,hid,val,did,dis)
{
	var table = document.getElementById(sid);
	var value = document.getElementById(hid);
	if (value.value == val) return;
	var display = document.getElementById(did);
	var row = table.rows[0];
	var curCell = row.cells[parseInt(value.value)];
	var nextCell = row.cells[val];
	curCell.style.backgroundImage = 'url(/image_root/scale_blank.gif)';
	nextCell.style.backgroundImage = 'url(/image_root/scale_arrow.gif)';
	value.value = val;
	if (display != null) display.innerHTML = dis;
	immediateEvent(true,sid,'onscale',val,true);
}

function scale_onmousemove(sid,hid,val,did,dis)
{
	if (event.button == 1) scale_onclick(sid,hid,val,did,dis);
}