var strButtonsHtml = "<br><input type='button' value='Save' onClick='jsStoreContentInHiddenField();'><input type='button' value='Cancel' onClick='jsCancel();'>"

function jsEditText(Element)
{
	var oEditBox = document.getElementById('txtEditBox');
	if(oEditBox)
	{
		alert('WARNING! Please save changes to current edit box before editing a new content.');
	}
	else
	{
		//store text
		var strHTML = Element.innerHTML;
		
		//generate and set the html
		var strNewHtml = "<textarea id='txtTempStorage' style='display:none;'>" + strHTML + "</textarea>"
						+ "<textarea style='width:75%; height:200' id='txtEditBox' name='txtEditBox'>" + strHTML + "</textarea>" 
						+ strButtonsHtml;
		Element.innerHTML = strNewHtml;
		
		//set the focus to the textarea
		document.getElementById('txtEditBox').focus();
		
		//generate the editor
		editor_generate('txtEditBox');
	}
}

function jsCancel()
{
	var oTempStorage = document.getElementById('txtTempStorage');
	var strHTML = oTempStorage.value;
	oTempStorage.parentNode.innerHTML = strHTML;
}

function jsStoreContentInHiddenField()
{
	//get the hidden boxes
	var hidEditBox = document.getElementById("hidEditBox");
	var hidEditBoxID = document.getElementById("hidEditBoxID");
	
	//get the txtEditBox and store contents in hidden
	var oEditBox = document.getElementById("txtEditBox");
	hidEditBox.value = escape(oEditBox.value);
	
	//clear the contents in txtEditBox
	oEditBox.value = '';
	
	//get the parent id
	var oEditBoxParent = oEditBox.parentNode;
	var strEditBoxParentID = oEditBoxParent.id;
	
	//set the id 
	hidEditBoxID.value = strEditBoxParentID.substr(strEditBoxParentID.lastIndexOf('_')+1, strEditBoxParentID.length);
	
	//submit the form
	document.Form1.submit();
}
