var _U = "undefined";

var oPopup = window.createPopup();
function contextMenu( dataID )
{
    var oNodeListActions = document.getElementById( dataID ).XMLDocument.selectNodes("actions/action");
    var numNodes = oNodeListActions.length;
    var divTagStyle = "STYLE='white-space:nowrap; background:#cccccc; border:1px solid black; border-top:1px solid white; border-left:1px solid white; height:20px; color:black; font-family:verdana; font-weight:bold; padding:2px; padding-left:10px; font-size:8pt; cursor:hand' ";
    var divTagActions = "onmouseover='this.style.background=\"#ffffff\"' onmouseout='this.style.background=\"#cccccc\"'";
    var menu = "";

    for( n = 0; n < numNodes; n++ )
    {
        var oNodeAction = oNodeListActions.item( n );

        menu = menu + "<div ";
        menu = menu + divTagStyle;
        menu = menu + divTagActions;
        menu = menu + ">";
        menu = menu + oNodeAction.xml;
        menu = menu + "</div>";
    }
    oPopup.document.body.innerHTML = menu;

    var popupBody = oPopup.document.body;

    // The following popup object is used only to detect what height the
    // displayed popup object should be using the scrollHeight property.
    // This is important because the size of the popup object varies
    // depending on the length of the definition text. This first
    // popup object is not seen by the user.
    oPopup.show(0, 0, 100, 0);
    var realHeight = popupBody.scrollHeight;
    var realWidth = popupBody.scrollWidth + 10;

    // Hides the dimension detector popup object.
    oPopup.hide();

    // Shows the actual popup object with correct height.
    oPopup.show(0, 15, realWidth, realHeight, event.srcElement);
}

function postCheckoutAndOpen(cgiurl, stellentInstance, WebdavBaseUrl, checkOutAndOpenCab, the_dDocName, the_dDocTitle, the_dExtension )
{
	var applet =  document["CheckoutAndOpenApplet_" + stellentInstance];
	var strTypeof = typeof(applet);
	
	if (strTypeof.toLowerCase() != "object")
	{
		var strObject 	 = "";

		strObject		+= "<OBJECT ";
		strObject		+= "ID='CheckoutAndOpenApplet_" + stellentInstance + "' ";
		strObject		+= "CLASSID='CLSID:D2DB3391-D1DF-461D-BCC6-182B7FA32753' ";
		strObject		+= "CODEBASE='" + checkOutAndOpenCab + "' ";
		strObject		+= "WIDTH='0' ";
		strObject		+= "HEIGHT='0' ";
		strObject		+= "HSPACE='0' ";
		strObject		+= "VSPACE='0' ";
		strObject		+= "> ";
		strObject		+= "</OBJECT>";

		document.body.insertAdjacentHTML("beforeEnd", strObject);
	}

	var applet =  document["CheckoutAndOpenApplet_" + stellentInstance];
	if (applet != null)
	{
		var nativeAppIsOdma = false;
		if ((the_dExtension == "doc") || (the_dExtension =="fm") || (the_dExtension == "bk") || (the_dExtension == "book") || (the_dExtension == "vsd") || (the_dExtension == "ppt") || (the_dExtension == "wpd") || (the_dExtension == "lwp"))
		{
			nativeAppIsOdma = true;
		}
		var canOpenOdma = false;

		try	{ canOpenOdma = applet.canOpenOdma(cgiurl);	} catch(e) { return; }


		var coao_flags = "";
		if (nativeAppIsOdma && canOpenOdma && coao_flags.indexOf("webdavonly") == -1)
		{
			var docname = "" + the_dDocName;
			var isactivated = applet.openOdma(cgiurl, docname);

			if (!isactivated)
			{
				alert("Unable to open the content item using ODMA.");
			}
			else
			{
				//window.setTimeout("location.href=document.URL",10000);
			}
		}
		else if (coao_flags.indexOf("odmaonly") == -1)
		{
			if (WebdavBaseUrl != "")
			{
				if (WebdavBaseUrl.substr(WebdavBaseUrl.length - 1,1) != '/')
				{
					WebdavBaseUrl = WebdavBaseUrl + '/';
				}
				var startDelimiter = "";
				var endDelimiter = "";
				if (startDelimiter == "")
				{
					startDelimiter = "[";
				}
				if (endDelimiter == "")
				{
					endDelimiter = "]";
				}
				var webdavurl = WebdavBaseUrl + startDelimiter + the_dDocName + endDelimiter + " " + the_dDocTitle + "." + the_dExtension;
				var isactivated = applet.openWebdav(webdavurl);

				if (!isactivated)
				{
					alert("Unable to open the content item using WebDAV.");
				}
				else
				{
					//window.setTimeout("location.href=document.URL",10);
				}
			}
			else
			{
				alert("Unable to open the content item using either ODMA or WebDAV.\nThe ODMA client may not be configured to use this server.\nThe 'webdavbaseurl' configuration variable is missing.");
			}
		}
		else
		{
			alert("Unable to open the content item using ODMA.");
		}
	}
	else
	{
		alert("Unable to find the CheckOutAndOpenInNative Applet.");
	}
}

function fnLaunchContributorClient()
{
	try
	{
		var app = document.getElementById("ssContributor");

		if (typeof app != _U && app != null)
		{
			app.EditContributorFile(document);
		}
	}
	catch(e)
	{
		fnLog(e, "fnLaunchContributorClient", this.name);
	}
}

function fnInit(contributorModeImage)
{
	try
	{	
		if (typeof document.body != _U && document.body != null)
		{
			document.body.attachEvent('onkeydown', fnCheckKey);

			if ( isContributionMode() )
			{
				var oDiv = document.createElement("span");
				oDiv.style.height = 20;
				oDiv.style.width = 200;
				oDiv.style.backgroundColor = "white";
				oDiv.style.font = "normal 10pt courier";
				oDiv.style.border = "solid black 1px";
				oDiv.style.padding = 10;
				oDiv.style.position = "absolute";
				oDiv.style.top = 15;
				oDiv.textAlign = "center";
				oDiv.innerHTML = "<img align='absmiddle' src='" + contributorModeImage + "'>";

				document.body.insertBefore(oDiv);

				oDiv.style.setExpression("left", "document.body.clientWidth - 225");
				document.recalc(true);
			}
		}		
	}
	catch(e)
	{
		//fnLog(e, "fnInit", this.name);
	}
}

function fnCheckKey()
{
	try
	{
		if (event.ctrlKey && event.shiftKey)
		{
			switch (event.keyCode)
			{
				// F5
				case 116:
					fnToggle();
					break;

				default:
					break;
			}
		}
	}
	catch(e)
	{
		//fnLog(e, "fnCheckKey", this.name);
	}
}

<!-- ------------------------------------------------------------------- -->

function fnToggle()
{
	try
	{
		if (GetCookie("IsInContributionMode")== "true") // disable
		{
			SetCookie("IsInContributionMode","false",null,"/");
		}
		else // enable
		{
			SetCookie("IsInContributionMode","true",null,"/");
		}
		window.location = window.location.href;
	}
	catch(e)
	{
		//fnLog(e, "fnToggle", this.name);
	}
}

function isContributionMode()
{
	if(document.URL.length > 0)
	{
		// Set Contribution cookie if one doesn't exist
		if(GetCookie("IsInContributionMode") == null)
		{
			SetCookie("IsInContributionMode","false",null,"/");
			return false;
		}
		
		if(GetCookie("IsInContributionMode") == "true")
		{
			return true;
		}
	}
	return false;
}

