
var ContentSaveSucceeded = true;
var DialogParams = "dialogHeight:500px;dialogWidth:620px;resizable:yes;status:no;help:no;";
var Mso_TargetHiddenField=null;

//var TargetHiddenField = null;
function RTCOpenTextEditor(targetUrl, hdnActionID, spWebId, varWebPart, nameSpace, dialogParameters) {
	var unescapeTargetUrl=unescape(targetUrl); 
	var nameSpaceContent= "";
	if ((nameSpace != null) && (nameSpace != ""))
		nameSpaceContent += nameSpace;
	else 
		nameSpaceContent += "Steria.RichTextContent";
	nameSpaceContent += "#Content";
//	var nameSpaceContent="Steria.RichTextContent#Content";		
	var ActionField = document.getElementById(hdnActionID);
	if ((dialogParameters != null) && (dialogParameters != ""))
		DialogParams = dialogParameters;
	var oArgs = new Object();
	
	if (varWebPart.Properties.Item(nameSpaceContent) != null)
		oArgs.value = varWebPart.Properties.Item(nameSpaceContent).Value;
	else
		oArgs.value = "";
	oArgs.value = varWebPart.Properties.Item(nameSpaceContent).Value
	oArgs.LCID = "1044";
	oArgs.docBodyDirection = "ltr";
	oArgs.dir = "ltr";
	oArgs.spWebId = spWebId;

//	oArgs.spWebId = spWebId;

	oArgs.SaveButton=1; 
	try
	{
	    var themeLinkTag = document.getElementById("onetidThemeCSS");
	    if (themeLinkTag != null)
	    {
		    var themeAbsoluteUrl;
		    themeHref = themeLinkTag.href;
		    themeAbsoluteUrl = location.protocol + "//" +  location.host;
		    if (themeHref.charAt(0) !='/') 
		    {
			var lastDelimeter = location.pathname.lastIndexOf('/');
			if (lastDelimeter >= 0)
			{
			    themeAbsoluteUrl = themeAbsoluteUrl  + 
					location.pathname.substring(0, lastDelimeter + 1);
			}
		    }
		    themeAbsoluteUrl = themeAbsoluteUrl + themeHref;
		    oArgs.Theme = themeAbsoluteUrl
	    }
	}
	catch (e)
	{
	}
	oArgs.BaseURL = location.href;

//		oArgs.value=document.getElementById(contentElementId).value; 	
//		oArgs.value=document.getElementById(webPartId).Content;
	var retVal = window.showModalDialog(unescapeTargetUrl, oArgs, DialogParams);	
	
//	'dialogHeight:500px;dialogWidth:620px;resizable:yes;status:no;help:no;'
	try {
	ActionField.value = "none";
	if ((typeof(retVal)!="undefined") && (!ContentSaveSucceeded || retVal!=varWebPart.Properties.Item(nameSpaceContent).Value)) {
		ContentSaveSucceeded = false;
//			TargetHiddenField.value = "true";	
//				document.getElement("varPartWPQ10").Content = retVal;
		if (retVal != null)
			varWebPart.Properties.Item(nameSpaceContent).Value = retVal;
		ActionField.value = "none";
		varWebPart.Save(false, SaveCallBack);
//			document.forms[MSOWebPartPageFormName].submit(); 

//			document.forms["_ctl5"].submit();
//			document.Forms[0].submit();
		}
	} catch (e) {
		alert(MSOStrings.ContentEditorSaveFailed + e.message); 
	}
}		


function SaveCallBack(saveSucceeded, soapExceptionText, soapStatus)
{
	ContentSaveSucceeded=saveSucceeded;
	if (ContentSaveSucceeded)
	{
//		TargetHiddenField.value="true";
		//ActionField.value = "none";
		document.forms[MSOWebPartPageFormName].submit(); 
		return;
	}
	else
	{
		if (soapStatus == "401")	
		{
			alert(MSOStrings.AccessDenied)
		}
		else
		{
			alert(MSOStrings.ContentEditorSaveFailed + " " + soapExceptionText); 
		}
	}
}

function OpenEditMode(url, hdnClientID, action) 
{
	document.forms[MSOWebPartPageFormName].action= url;
//	alert(document.forms[MSOWebPartPageFormName].Action);
	var hdnAction=document.getElementById(hdnClientID); 
	hdnAction.value=action; 
	document.forms[MSOWebPartPageFormName].submit();
}

