function Cell2Form(CELL)
{
	if (CELL.firstChild.nodeType == 1)
	{
		return true;
	}
	var strXML = "<td>" + CELL.innerHTML + "</td>";
	var strXslPath = "Cell2Form2.xsl";
	
	new Ajax.Request(strXslPath, 
			{
				method: "get",
				onComplete: _transform
			});

	function _transform(REQ)
	{
		var strForm = Transform(strXML,REQ.responseXML);
		CELL.innerHTML=strForm;
		CELL.firstChild.firstChild.select();
	}
}

function Transform(strXML,docXSL)
{
	var parser = new DOMParser();
	var xml = parser.parseFromString(strXML,"text/xml");
	xml.async=false;
	var processor = new XSLTProcessor();
	processor.importStylesheet(docXSL);
	var xmlDom = processor.transformToDocument(xml);

	var serializer = new XMLSerializer();	
	var result = serializer.serializeToString(xmlDom.documentElement);
	return result;
}

function SaveAndClose(CELL)
{
	var cellName = CELL.title;
	var cellValue = CELL.firstChild.firstChild.value;
	var presID = CELL.parentNode.id;
	new Ajax.Request("SaveCell.jsp", 
			{
				method: "get",
				parameters: "field=" + cellName + "&value=" + cellValue + "&pid=" + presID,
				onComplete: _result
			});
			
	function _result(REQ)
	{
		if (REQ.responseText.indexOf("success") >= 0)
		{
			CELL.innerHTML = cellValue;
			Blink(CELL,1000,"Saved","Normal");
		}
		else
		{
			alert(REQ.responseText);
		}
	}
}

function Blink(ELEM,TIME,ON,OFF,TIMEPAST)
{
	var timePast = (typeof TIMEPAST != "undefined") ? TIMEPAST + 100 : 0;
	ELEM.className = (ELEM.className == ON) ? OFF : ON;

	if (timePast < TIME)
	{
		setTimeout(function () { Blink(ELEM,TIME,ON,OFF,timePast) },100);
	}
	else
	{
		ELEM.className = OFF;
	}
}