<!-- MENU-LOCATION=NONE -->
<html xmlns:MMString="http://www.macromedia.com/schemes/data/string/">
<HEAD>
<!-- Copyright 2000, 2001, 2002, 2003, 2004, 2005 Macromedia, Inc. All rights reserved. -->
<TITLE><MMString:loadString id="Menus/MM/Text_CustomStyles/title" /></TITLE>
<SCRIPT LANGUAGE="javascript" SRC="../../Shared/MM/Scripts/CMN/string.js"></SCRIPT>
<script type="text/javascript" src="../../Shared/Common/Scripts/dwscripts.js"></script>
<SCRIPT LANGUAGE="javascript">
<!--
//--------------- LOCALIZEABLE GLOBALS---------------

var MENU_None = dw.loadString('Menus/MM/Text_CustomStyles/MENU_None');

//--------------- END LOCALIZEABLE   ---------------
function isBodyOrIsInBody(node)
{
	var result = false;
	var parent = node.parentNode;
	if(node.nodeType == Node.ELEMENT_NODE && node.tagName == "BODY")
	{
		return true;
	}
	while (parent && parent.nodeType == Node.ELEMENT_NODE)
	{
		if (parent.tagName == "BODY")
		{
			result = true;
			break;
		}
		parent = parent.parentNode;
	}

	return result;
}

function receiveArguments()
{
	var styleName = arguments[0];
	// live edit needs to be handled separately
	var browser = dw.getBrowser();
    if(browser && browser.isLiveEditingInProgress())
	{
		//TO-DO based on the new TextEditing commit Workflow
	}
	else
	{	
		if (styleName == "(None)")
			dw.getDocumentDOM('document').applyCSSStyle('','');
		else
			dw.getDocumentDOM('document').applyCSSStyle('',styleName);
	}
}

function canAcceptCommand()
{
	// live edit needs to be handled separately
	if(dw.getFocus() == 'browser' )
	{
		var browser = dw.getBrowser();
		if(browser)
		{
			if(browser.isLiveEditingInProgress())
			{
				//TO-DO based on the new TextEditing commit Workflow
				return false;
			}
			else if( (dw.getDocumentDOM() && dw.getDocumentDOM().getHideDisplaysInLiveView()) || !browser.isSelectedTagEditable())
			{
				return false;
			}
		}
	}
    var bCanAccept = dwscripts.canApplyStyle();
	
	if (!bCanAccept) // If it's not acceptable, return now.
		return bCanAccept;

	// If bCanAccpt is OK, check one more thing to make sure that
	// the class will not be applied to some tag in the body (#191812)
	if (dw.getDocumentDOM() != null){
	  var selarray = dw.getDocumentDOM().getSelection(true);
	  var obj = dw.getDocumentDOM().offsetsToNode(selarray[0],selarray[1]);
	  bCanAccept = false;
	  if (selarray.length >= 2 && (obj.nodeType == Node.ELEMENT_NODE || obj.nodeType == Node.TEXT_NODE || obj.nodeType == Node.COMMENT_NODE ))
		{
		   if (isBodyOrIsInBody(obj))
			  bCanAccept = true;
		}
	}
	
	return bCanAccept;
}

function isCommandChecked()
{
	if (dw.getDocumentDOM() == null) 
		return false;

	var bChecked = false;
	var cssStyle = arguments[0];
	
	if (cssStyle == "(None)")
	{
		bChecked = (dw.cssStylePalette.getSelectedStyle() == '');
	}
	else
	{
		bChecked = (dw.cssStylePalette.getSelectedStyle() == cssStyle);
	}

	return bChecked;
}

// getDynamicContent returns the contents of a dynamically generated menu.
// returns an array of strings to be placed in the menu, with a unique
// identifier for each item separated from the menu string by a semicolon.
//
// return null from this routine to indicate that you are not adding any
// items to the menu
function getDynamicContent(itemID)
{
	var cssStyles = new Array();
	cssStyles[0] = new String(MENU_None + ";id='(None)'"); // add the base "None" style
	var dwCSS = dw.cssStylePalette.getStyles();
	var i;

	if (dwCSS.length > 0)
	{
		for (i=0; i<dwCSS.length; i++)
		{
			cssStyles[i+1] = new String(dwCSS[i]);
			cssStyles[i+1] += ";id='"+escQuotes(dwCSS[i])+"'"; // each item needs an ID
		}
	}

	// For multiple applied classes, add an item for whitespace delimited string so it can be checked
	cssApplied = dw.cssStylePalette.getSelectedStyle().split(' ');
	if (cssApplied.length > 1)
	{
		cssStyles[i+1] = new String(dw.cssStylePalette.getSelectedStyle());
		cssStyles[i+1] += ";id='" + escQuotes(dw.cssStylePalette.getSelectedStyle()) + "'";
	}

	return cssStyles;
}
// -->   
</SCRIPT>
</HEAD>
<BODY>
</BODY>
</HTML>
