/*
 * Copyright 2007 Kelvin W Sherlock
 *
 *
 */
 
function do_change(form, name)
{
	var x = form[name];
	if (x)
	{
		window.location = form.action + '/' + x.value;
		return false;
	}
	return true;
}

function mouse(node, inout)
{
	var cells = node.cells;
	var size = cells.length;

	/*
	cells.item(size - 1).style.borderRightStyle = 'solid';
	cells.item(size - 1).style.borderRightWidth = '1px';
	cells.item(size - 1).style.borderRightColor = '#000000';
	*/
	cells.item(0).style.borderLeft = inout ? 'solid black 1px' : '';
	cells.item(size - 1).style.borderRight = inout ? 'solid black 1px' : '';
}

function do_filter(self)
{
	var n = self;
	var $i = 0;
	while($i != 2)
	{
		n = n.nextSibling;
		if (!n) return;
		if (n.nodeType == 1) $i++;
	}
	
	if (self.value == 'between')
	{
		n.style.visibility = 'visible';	
	}
	else
	{
		n.style.visibility = 'hidden';		
	}
}

function add_field(src)
{
	var dest = document.getElementById('fs');
	if (dest)
	{
		var e = clone(src);
		dest.appendChild(e);
	}
}

function clone(e)
{
	var out;
	var i;
	
	if (!e) return null;
	switch (e.nodeType)
	{
		// Element Node
	case 1:
		out = document.createElement(e.tagName);
		break;
		// text data
	case 3:
		out = document.createTextNode(e.data);
		return out;
		break;
	default:
		return null;
	}
	
	if (e.attributes)
	{
		for (i = 0; i < e.attributes.length; i++)
		{
			attr = e.attributes[i];
			if (!attr) continue;
			if (!attr.specified) continue;
			out.setAttribute(attr.name, attr.value);
		}
	}
	
	if (window.ActiveXObject)
	{
		if (e.onclick) out.onclick = e.onclick;
		if (e.onchange) out.onchange = e.onchange;
		out.style.visibility = e.style.visibility;
	}
	
	if (e.childNodes)
	{
		for(i = 0; i < e.childNodes.length; i++)
		{
			x = clone(e.childNodes[i]);
			if (x == null) continue;
			out.appendChild(x);	
		}
	}
	
	// must do this after children are added for select...
	if (e.tagName == 'INPUT' || e.tagName == 'SELECT')
	{
		if (e.type != 'text') out.value = e.value;
	}
	
	return out;
}