var _U = "undefined";

<!-- ------------------------------------------------------------------- -->

var oPopup = null;
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 = "";

	if( oPopup == null )
	{
		oPopup = window.createPopup();
	}

    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);
}

// ***************************************************************************
//
// The following function uses virtual key codes to determine
// what key or key combination has been pressed by the user.
// The default value is CTRL + SHIFT + F5. The F5 key has a
// Virtual-Key Code of 116 (or 0x74 in hexadecimal). The codes 
// for the other typical Function keys, F1 through F12 are 
// 112 (0x70) through 123 (0x7B) respectively. For a complete 
// list of virtual-key codes please refer to the following URL:
// http://msdn.microsoft.com/library/default.asp?url=/library/en-us/winui/WinUI/WindowsUserInterface/UserInput/VirtualKeyCodes.asp
// Alternatively, do a Google search on the term "Virtual-Key Codes" 
// and you should find some useful information.
//
// You may also use the HTML code below to create a test page that 
// you can use to capture the values of the keys being pressed.
//
// ***************************************************************************
//  Alter the fnCheckKey method to change the key command that enables
//  Contributor Mode. Utilize the following HTML source code to help
//  identify the key codes you wish to use for your key commands.
//
//  <html><head><script>
//  function load() { document.body.attachEvent('onkeydown', logKeyDown); }
//  function logKeyDown()
//  {
//   var IsShiftKeyDown = (event.shiftKey) ? "yes<br>" : "no<br>";
//   var IsCtrlKeyDown = (event.ctrlKey) ? "yes<br>" : "no<br>";
//   output.innerHTML += "Key Code: "
//    + event.keyCode + "<br>"
//    + "Is Shift Key Down?: "
//    + IsShiftKeyDown
//    + "Is Ctrl Key Down?: "
//    + IsCtrlKeyDown
//    + "<br>";
//  }
//  </script></head>
//  <body onload="load()"><center>
//  <b>Press a key to reveal its Key Code:</b><br><br>
//  <div id="output"></div>
//  </center>
//  </body>
//  <html>
// ***************************************************************************

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 GetCookie(sName)
{
  var aCookie = document.cookie.split("; ");
  for (var i=0; i < aCookie.length; i++)
  {
    var aCrumb = aCookie[i].split("=");
    if (sName == aCrumb[0])
      return unescape(aCrumb[1]);
  }
  return null;
}

<!-- ------------------------------------------------------------------- -->

function fnToggle()
{
	try
	{
		var newURL = "";
		var contributor = GetCookie( "SSContributor" );
		if( contributor != null && contributor == "true" ) // disable
		{
			var splitUrl = window.location.href.split("?");
			newURL = splitUrl[0];
			var queryString = splitUrl[1];

			// Remove the legacy SSContributor value from the query string and use
			// the cookie from now on. Note that there may also be a previewId
			// value to get rid of.

			if( queryString != undefined && queryString != null && queryString.length > 0 )
			{
				if (queryString.search(/SSContributor=true/) >= 0)
					queryString = queryString.replace(/[&]?SSContributor=true/gi,"");

				if (queryString.search(/previewId=0/) >= 0)
					queryString = queryString.replace(/[&]?previewId=0/gi,"");

				// Check if there were any other query string params that should
				// be passed along.
				if( queryString.length > 0 )
				{
					if( queryString.charAt(0) == '&' )
					{
						if( queryString.length > 1 )
							newURL += "?" + queryString.substr(1);
					}
					else
					{
						newURL += "?" + queryString;
					}
				}
			}

			document.cookie = "SSContributor=false; path=/;"
			document.cookie = "previewId=; path=/;"
		}
		else
		{
			document.cookie = "SSContributor=true; path=/;";
		}

		if( newURL.length > 0 )
		{
			<!-- We have changed the URL so we need to force a navigate -->
			<!-- to the new url.                                        -->
			window.location = newURL;
		}
		else
		{
			<!-- This is a change to the cookie only so just reload the -->
			<!-- same page with the new cookie values.                  -->
			window.location.reload(true);
		}
	}
	catch(e)
	{
		fnLog(e, "fnToggle", this.name);
	}
}

<!-- ------------------------------------------------------------------- -->

function fnLaunchContributorClient()
{
	try
	{
		var app = document.getElementById("ssContributor");

		if (typeof app != _U && app != null)
		{
			if (typeof app.EditContributorFile != _U) // this is required in Designer AssignDataFile dialog
			{
				app.EditContributorFile(document);
			}
		}
	}
	catch(e)
	{
		fnLog(e, "fnLaunchContributorClient", this.name);
	}
}

<!-- ------------------------------------------------------------------- -->

function fnSwitchContributionRegionFile(strSiteId, strNodeId, strRegionId, bUseSecondary, strDocName)
{
	try
	{
		var app = document.getElementById("ssContributor");

		if (typeof app != _U && app != null)
		{
			if (typeof app.SwitchContributorFile != _U)  // this is required in Designer AssignDataFile dialog
			{
				app.SwitchContributorFile(document, strSiteId, strNodeId, strRegionId, bUseSecondary, strDocName);
			}
		}
	}
	catch(e)
	{
		fnLog(e, "fnSwitchContributionRegionFile", this.name);
	}
}

<!-- ------------------------------------------------------------------- -->

function fnShowContributorModeDiff(strCurrentUrl)
{
	try
	{
		var app = document.getElementById("ssContributor");

		if (typeof app != _U && app != null)
		{
			if (typeof app.CompareFiles != _U)  // this is required in Designer AssignDataFile dialog
			{
				var splitUrl = window.location.href.split("?");
				var newUrl = splitUrl[0] + "?";
				var queryString = splitUrl[1];

				// Remove the legacy SSContributor value from the query string and use
				if( queryString != undefined && queryString != null && queryString.length > 0 )
				{
					if (queryString.search(/SSContributor=true/) >= 0)
						queryString = queryString.replace(/[&]?SSContributor=true/gi,"");

					if (queryString.search(/previewId=0/) >= 0)
						queryString = queryString.replace(/[&]?previewId=0/gi,"");

					// Check if there were any other query string params that should
					// be passed along.
					if( queryString.length > 0 )
					{
						if( queryString.charAt(0) == '&' )
						{
							if( queryString.length > 1 )
								newUrl += queryString.substr(1) + "&";
						}
						else
						{
							newUrl += queryString + "&";
						}
					}
				}

				var url1 = newUrl + "SSContributor=false";
				var url2 = newUrl + "SSContributor=true&SSHideContributorUI=1"

				document.cookie = "SSContributor=false; path=/;"
				document.cookie = "previewId=; path=/;"

				// alert( strCurrentUrl + "\n" + url1 + "\n" + url2 );

				app.CompareFiles(url1, url2, true, false);
			}
		}
	}
	catch(e)
	{
		fnLog(e, "fnShowContributorModeDiff", this.name);
	}
}

<!-- ------------------------------------------------------------------- -->

function fnContributorImageToggle()
{
	try
	{
		var o = event.srcElement;

		if (typeof o != _U && o != null
			&& typeof o.src != _U && o.src != null)
		{
			if (o.src.search(/StellentDot_edit.gif/gi) >= 0)
			{
				o.src = o.src.replace(/StellentDot_edit.gif/gi, "StellentDot_edit_over.gif");
			}
			else if (o.src.search(/StellentDot_edit_over.gif/gi) >= 0)
			{
				o.src = o.src.replace(/StellentDot_edit_over.gif/gi, "StellentDot_edit.gif");
			}
			else if (o.src.search(/StellentDot_locked.gif/gi) >= 0)
			{
				o.src = o.src.replace(/StellentDot_locked.gif/gi, "StellentDot_locked_over.gif");
			}
			else if (o.src.search(/StellentDot_locked_over.gif/gi) >= 0)
			{
				o.src = o.src.replace(/StellentDot_locked_over.gif/gi, "StellentDot_locked.gif");
			}
			else if (o.src.search(/StellentDot_workflow.gif/gi) >= 0)
			{
				o.src = o.src.replace(/StellentDot_workflow.gif/gi, "StellentDot_workflow_over.gif");
			}
			else if (o.src.search(/StellentDot_workflow_over.gif/gi) >= 0)
			{
				o.src = o.src.replace(/StellentDot_workflow_over.gif/gi, "StellentDot_workflow.gif");
			}
		}
	}
	catch(e)
	{
		fnLog(e, "fnContributorImageToggle", this.name);
	}
}

<!-- ------------------------------------------------------------------- -->

function fnContributorModeImageOnMouseDown()
{
	try
	{
		this.X = event.offsetX;
		this.Y = event.offsetY;
	}
	catch(e)
	{
		fnLog(e, "fnContributorModeImageOnMouseDown", this.name);
	}
}

<!-- ------------------------------------------------------------------- -->

function fnContributorModeImageOnDrag()
{
	try
	{
		this.style.left = event.clientX-this.X + document.body.scrollLeft;
		this.style.top = event.clientY-this.Y + document.body.scrollTop;
	}
	catch(e)
	{
		fnLog(e, "fnContributorModeImageOnDrag", this.name);
	}
}

<!-- ------------------------------------------------------------------- -->

function fnInit()
{
	try
	{
		if (!SSForceContributor)
		{
			if (typeof document.body != _U && document.body != null)
			{
				document.body.attachEvent('onkeydown', fnCheckKey);

				if ( SSContributor && !SSHideContributorUI )
				{
					var oImg = document.createElement("IMG");
					oImg.style.border = "solid black 1px";
					oImg.style.padding = 20;
					oImg.style.position = "absolute";
					oImg.style.cursor = "move";
					oImg.style.top = 15;
					oImg.style.left = document.body.clientWidth - 225;
					oImg.ondrag = fnContributorModeImageOnDrag;
					oImg.onmousedown = fnContributorModeImageOnMouseDown;
					oImg.src = g_HttpRelativeWebRoot + "images/sitestudio/" + g_strLanguageId + "/contributorMode.jpg";

					document.body.insertBefore(oImg);
				}
			}
		}
	}
	catch(e)
	{
		fnLog(e, "fnInit", this.name);
	}
}

<!-- ------------------------------------------------------------------- -->

function fnLog( e, fn, f )
{
	alert(f + "\n" + fn + "\n" + e.name + "\n" + e.description + "\n" );
}

<!-- ------------------------------------------------------------------- -->

var is_mac = (navigator.userAgent.indexOf("Mac") != -1);

if( document.all && !is_mac)
{
	window.onload = fnInit;
}

<!-- ------------------------------------------------------------------- -->
