

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);
}

<!-- ------------------------------------------------------------------- -->

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 )
		{
			window.location.href = newURL;
		}
		else
		{
			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" );
}

<!-- ------------------------------------------------------------------- -->

if( document.all )
{
	window.onload = fnInit;
}

<!-- ------------------------------------------------------------------- -->

