function rollIn(token, image, type) 
{
	if ( image == null )
		image = token;
	if ( type == null )
		type = "jpg";
	
	document.getElementById(token).src = "/images/" + image + "_flip." + type;
}
function rollOut(token, image, type) {
	if ( image == null )
		image = token;
	if ( type == null )
		type = "jpg";
	document.getElementById(token).src = "/images/" + image + "." + type;
}

function changeClass( id, newclass )
{
	document.getElementById(id).className = newclass;
}

function confirmDeleteItem( itemId )
{
	if ( confirm("Do you really wish to delete this entry?") )
	{
		document.location.href = "/delitem.php?iid=" + itemId;
	}
}

function addFurniture()
{
	var tables = document.getElementsByTagName("table");
	var i;
	for ( i = 0; i < tables.length; i++ )
	{
		if ( tables[i].className != "furniture")
			continue;

		var colour;
		if ( tables[i].getAttribute("col") == null )
			colour = "grey";
		else
			colour = tables[i].getAttribute("col");

		var tbody = tables[i].getElementsByTagName("tbody")[0];
		// add a header and a footer.
		var footer = document.createElement("tr");
		var header = document.createElement("tr");
		for ( var k = 0; k < 3; k++)
		{
			var x = document.createElement("td");
			var y = document.createElement("td");
			x.innerHTML = y.innerHTML = " &nbsp;";
			if ( k != 1 )
			{
				x.setAttribute("width", "24");
				y.setAttribute("width", "24");
			}
			else
			{
				;
			}
			footer.appendChild(x);
			header.appendChild(y);
		}
		tbody.insertBefore(header, tables[i].getElementsByTagName("tr")[0]);
		tbody.appendChild(footer);

		tables[i].setAttribute("cellspacing", 0);
		tables[i].setAttribute("cellpadding", 0);

		// Iterate through rows
		var rows = tables[i].getElementsByTagName("tr");
		var j;
		for ( j = 0; j < rows.length; j++ )
		{
			var cells = rows[j].getElementsByTagName("td");
			// first row
			if ( j == 0 )
			{
				cells[0].className = "furnTL furnTL_" + colour;
				cells[1].className = "furnTC furnTC_" + colour;
				cells[2].className = "furnTR furnTR_" + colour;
			}
			// last row
			else if ( j == rows.length - 1)
			{
				cells[0].className = "furnBL furnBL_" + colour;
				cells[1].className = "furnBC furnBC_" + colour;
				cells[2].className = "furnBR furnBR_" + colour;
			}
			else
			{
				cells[0].className = "furnC furnC_" + colour;
				cells[0].setAttribute("colspan", 3);
			}
		}
		
	}

}


/**
 * Form Processing
 */


function validateRequiredField(field,message)
{
	with (field)
		{
		if (value==null||value=="")
	    {
			if ( message != null )
				alert(message);
	    	return false;
	    }
	  	else
	    {
	    	return true;
	    }
	 }
}
