//targetDivId = "contextMenu";
//contextMenuWidth = 110;

function getStyleObject(obj)
	{
	var theObj;
	if (document.layers)
		{
		if (typeof obj == "string")
			{ return document.layers[obj]; }
		else
			{ return obj; }
		}

	if (document.all)
		{
		if (typeof obj == "string")
			{ return document.all(obj).style; }
		else
			{ return obj.style; }
		}

	if (document.getElementById)
		{
		if (typeof obj == "string")
			{ return document.getElementById(obj).style; }
		else
			{ return obj.style; }
		}
	return null;
	}

function getHtmlObject(obj)
	{
	var theObj;
	if (document.layers)
		{
		if (typeof obj == "string")
			{ return document.layers[obj]; }
		else
			{ return obj; }
		}

	if (document.all)
		{
		if (typeof obj == "string")
			{ return document.all(obj); }
		else
			{ return obj; }
		}

	if (document.getElementById)
		{
		if (typeof obj == "string")
			{ return document.getElementById(obj); }
		else
			{ return obj; }
		}
	return null;
	}

function getActivationMenuHTML(menuHolderName, pageId, contextMenuWidth)
	{
	var tempHTML;
	tempHTML = "<div id=\"" + menuHolderName +"Xctx\" style=\"position:absolute; border: solid 1px #999999; width:" + contextMenuWidth + "px; padding: 2px; background-color: #FFFFFF; z-index:101\">"
		+	"<table width=\"100%\" cellspacing=\"0\" cellpadding=\"2\" bgcolor=\"#FFFFFF\" style=\"font-family: Verdana, sans-serif; font-size: 11px;\">"
		+		"<tr onclick=\"openActivationWindow('" + menuHolderName + "', '" + pageId + "', 'activate', 'true');\" style=\"cursor: pointer;\"><td onmouseover=\"this.style.backgroundColor='#BBB7C7';\" onmouseout=\"this.style.backgroundColor='';\">Activate this page</td></tr>"
		//+		"<tr onclick=\"openActivationWindow('" + menuHolderName + "', '" + pageId + "', 'activate', 'true');\" style=\"cursor: pointer;\"><td onmouseover=\"this.style.backgroundColor='#BBB7C7';\" onmouseout=\"this.style.backgroundColor='';\">Activate incl. paragraphs</td></tr>"
		+		"<tr onclick=\"openActivationWindow('" + menuHolderName + "', '" + pageId + "', 'activatesub');\" style=\"cursor: pointer;\"><td onmouseover=\"this.style.backgroundColor='#BBB7C7';\" onmouseout=\"this.style.backgroundColor='';\">Activate incl. sub pages</td></tr>"
		+		"<tr><td style=\"padding:1px;\"><img src=\""+contextPath+"/genrep-common/docroot/globalLib/images/icons/magnolia/hr.gif\" width=\"100%\" height=\"6\" /></td></tr>"
		+		"<tr onclick=\"openActivationWindow('" + menuHolderName + "', '" + pageId + "', 'deactivate');\" style=\"cursor: pointer;\"><td onmouseover=\"this.style.backgroundColor='#BBB7C7';\" onmouseout=\"this.style.backgroundColor='';\">De-activate</td></tr>"
		+	"</table>"
		+ "</div>";
	return tempHTML;
}

function getParagraphActivationMenuHTML(menuHolderName, pageId, contextMenuWidth)
	{
	var tempHTML;
	tempHTML = "<div id=\"" + menuHolderName +"Xctx\" style=\"position:absolute; border: solid 1px #999999; width:" + contextMenuWidth + "px; padding: 2px; background-color: #FFFFFF; z-index:101\">"
		+	"<table width=\"100%\" cellspacing=\"0\" cellpadding=\"2\" bgcolor=\"#FFFFFF\" style=\"font-family: Verdana, sans-serif; font-size: 11px;\">"
//		+		"<tr onclick=\"openActivationWindow('" + menuHolderName + "', '" + pageId + "', 'activate');\" style=\"cursor: pointer;\"><td onmouseover=\"this.style.backgroundColor='#BBB7C7';\" onmouseout=\"this.style.backgroundColor='';\">Activate this page</td></tr>"
		+		"<tr onclick=\"openActivationWindow('" + menuHolderName + "', '" + pageId + "', 'activatesub');\" style=\"cursor: pointer;\"><td onmouseover=\"this.style.backgroundColor='#BBB7C7';\" onmouseout=\"this.style.backgroundColor='';\">Activate this paragraph</td></tr>"
		+		"<tr><td style=\"padding:1px;\"><img src=\""+contextPath+"/genrep-common/docroot/globalLib/images/icons/magnolia/hr.gif\" width=\"100%\" height=\"6\" /></td></tr>"
		+		"<tr onclick=\"openActivationWindow('" + menuHolderName + "', '" + pageId + "', 'deactivate');\" style=\"cursor: pointer;\"><td onmouseover=\"this.style.backgroundColor='#BBB7C7';\" onmouseout=\"this.style.backgroundColor='';\">De-activate</td></tr>"
		+	"</table>"
		+ "</div>";
	return tempHTML;
}


function printActivationMenu(menuHolderName, pageId, contextMenuWidth, e)
	{
	if(contextMenuWidth > 0) { /* Do nothing */ }
	else { contextMenuWidth = 150; }

	var contextMenuDiv = getHtmlObject(menuHolderName);

	if(contextMenuDiv.innerHTML == "")
		{
		contextMenuDiv.innerHTML = getActivationMenuHTML(menuHolderName, pageId, contextMenuWidth);

		var isOpera = (navigator.userAgent.indexOf('Opera') != -1);
		var isIE = (!isOpera && navigator.userAgent.indexOf('MSIE') != -1)
		var posx = 0;
		var posy = 0;
		if (!e)
			{ var e = window.event; }

		if (e.pageX || e.pageY)
			{
			posx = e.pageX;
			posy = e.pageY;
			}
		else if (e.clientX || e.clientY)
			{
			posx = e.clientX;
			posy = e.clientY;
			if (isIE)
				{
				posx += document.body.scrollLeft;
				posy += document.body.scrollTop;
				}
			}
		//Adjusting for mor natural position
		posy = posy + 15;
		posx = posx -20;

		if((posx + contextMenuWidth) > document.body.clientWidth)
			{
			posx -= (posx + contextMenuWidth) - document.body.clientWidth;
			posx = (posx < 0) ? 0 : posx;
			}

		if((posy + getHtmlObject( menuHolderName + "Xctx" ).clientHeight) > document.body.clientHeight)
			{
			posy -= (posy + getHtmlObject( menuHolderName + "Xctx" ).clientHeight) - document.body.clientHeight;
			posy = (posy < 0) ? 0 : posy;
			}

		with(document.getElementById(menuHolderName + "Xctx").style)
			{
			top = posy + "px";
			left = posx + "px";
			}

		}
	else
		{ clearActivationMenu(menuHolderName); }

}

function printParagraphActivationMenu(menuHolderName, pageId, contextMenuWidth, e)
	{
	if(contextMenuWidth > 0) { /* Do nothing */ }
	else { contextMenuWidth = 150; }

	var contextMenuDiv = getHtmlObject(menuHolderName);

	if(contextMenuDiv.innerHTML == "")
		{
		contextMenuDiv.innerHTML = getParagraphActivationMenuHTML(menuHolderName, pageId, contextMenuWidth);

		var isOpera = (navigator.userAgent.indexOf('Opera') != -1);
		var isIE = (!isOpera && navigator.userAgent.indexOf('MSIE') != -1)
		var posx = 0;
		var posy = 0;
		if (!e)
			{ var e = window.event; }

		if (e.pageX || e.pageY)
			{
			posx = e.pageX;
			posy = e.pageY;
			}
		else if (e.clientX || e.clientY)
			{
			posx = e.clientX;
			posy = e.clientY;
			if (isIE)
				{
				posx += document.body.scrollLeft;
				posy += document.body.scrollTop;
				}
			}
		//Adjusting for mor natural position
		posy = posy + 15;
		posx = posx -20;

		if((posx + contextMenuWidth) > document.body.clientWidth)
			{
			posx -= (posx + contextMenuWidth) - document.body.clientWidth;
			posx = (posx < 0) ? 0 : posx;
			}

		if((posy + getHtmlObject( menuHolderName + "Xctx" ).clientHeight) > document.body.clientHeight)
			{
			posy -= (posy + getHtmlObject( menuHolderName + "Xctx" ).clientHeight) - document.body.clientHeight;
			posy = (posy < 0) ? 0 : posy;
			}

		with(document.getElementById(menuHolderName + "Xctx").style)
			{
			top = posy + "px";
			left = posx + "px";
			}

		}
	else
		{ clearActivationMenu(menuHolderName); }

}

function clearActivationMenu(menuHolderName)
	{ getHtmlObject(menuHolderName).innerHTML = ""; }

function openActivationWindow(menuHolderName, pageId, actionType, inclParagraphs)
	{
//    document.location.reload();
	
    mgnlOpenWindow("/.magnolia/activatePage.html?path=" + pageId + "&action=" + actionType + "&inclParagraphs=" + inclParagraphs,400, 300)
//    var activationWindow = window.open(contextPath+"/.magnolia/activatePage.html?path=" + pageId + "&action=" + actionType + "&inclParagraphs=" + inclParagraphs, "_blank", "width=300, height=300");
//
//	activationWindow.document.write("<html><head><title>Activation in progress</title></head>");
//	activationWindow.document.write("<body><strong>Activation process: " + actionType + "</strong><br/> Working with:<br/> <code>" + pageId + "</code><br><br> <img src=\""+contextPath+"/genrep-common/docroot/globalLib/images/other/loading.gif\" border=0 /> please wait...");
//	activationWindow.focus();
//	//activationWindow.location = "${pageContext.request.contextPath}/.magnolia/activatePage.html?path=" + pageId + "&action=" + actionType;
//	activationWindow.document.write("<script language=\"JavaScript\">window.url = \""+contextPath+"/.magnolia/activatePage.html?path=" + pageId + "&action=" + actionType + "&inclParagraphs=" + inclParagraphs + "\";</script>");
//	activationWindow.document.write("</body></html>");
//
//	clearActivationMenu(menuHolderName);
//    setTimeout("document.location.reload()", 5000);
    
	}