<!-- MENU-LOCATION=NONE -->
<html xmlns:MMString="http://www.macromedia.com/schemes/data/string/">
<HEAD>
<!-- Copyright 2001, 2002, 2003 Macromedia, Inc. All rights reserved. -->
<TITLE><MMString:loadString id="Menus/MM/ccText_Sizes/title" /></TITLE>
<SCRIPT LANGUAGE="javascript" SRC="../../Shared/MM/Scripts/CMN/string.js"></SCRIPT>

// remove when preferences API is in place
<SCRIPT LANGUAGE="JavaScript" SRC="../../Toolbars/siteSettings_TEMP.js"></SCRIPT>


<SCRIPT LANGUAGE="javascript">
<!--
//--------------- LOCALIZEABLE GLOBALS---------------

var MENU_Default = dw.loadString('Menus/MM/ccText_Sizes/MENU_Default');

//--------------- END LOCALIZEABLE   ---------------

// Non-localized globals.
var FONT_VALUES = new Array(8,10,12,14,18,24,36);
var SPAN_VALUES = new Array(8,9,10,11,12,14,16,18,20,22,24,26,28,36,48,72);
var PIXEL_VALUES = new Array(11,12,13,15,16,18,21,24,26,29,32,34,37,48,64,96);
var EM_VALUES = new Array(66, 75, 83, 92, 100, 112, 133, 150, 166, 183, 200, 217, 233, 300, 400, 500, 600);
var HEADING_FONT_SIZES = new Array("", "h6", "h5", "h4", "h3", "h2", "h1");

function showIf() {
    var show = true;
    show = getShowFontsAndSizes(); // replace with real API function!
    if (CCWorkspaceManager.getManager(dw.getDocumentDOM()).IsCurrentPageXML()) { show = false; }

    return show;
}

function convertPointsToPixels(pointSize)
{
	for (var i=0; i < SPAN_VALUES.length; i++)
	{
		if (pointSize == SPAN_VALUES[i])
			return PIXEL_VALUES[i];
	}
	return -1;
}

function convertPixelsToPoints(pixelSize)
{
	for (var i=0; i < PIXEL_VALUES.length; i++)
	{
		if (pixelSize == PIXEL_VALUES[i])
			return SPAN_VALUES[i];
	}
	return -1;
}

function convertPointsToFontSizes(pointSize)
{
	for (var i=0; i < FONT_VALUES.length; i++)
	{
		if (FONT_VALUES[i] == pointSize)
			return i + 1;
	}
	return -1;
}

function convertHeadingToFontSize(headingTag)
{
	for (var i=0; i < HEADING_FONT_SIZES.length; i++)
	{
		if (HEADING_FONT_SIZES[i] == headingTag)
			return i;
	}
	return -1;
}

function receiveArguments(){
	var size = arguments[0];
	var dom = dw.getDocumentDOM();
	if (size == '(default)')
		dom.applyFontMarkup('size', '');
	else
		dom.applyFontMarkup('size', size);
/*
	if (getFontTag() == "font"){
		// Clear any <span>-applied size in addition to adding or
		// removing the <font> tag.
		dom.removeFontMarkupAsStyle('font-size');
		if (size == '(default)')
			dom.removeFontMarkup('size');
		else
			dom.applyFontMarkup('size',size);
	}else{
		// Clear any <font>-applied size in addition to adding or
		// removing the <span> tag.
		dom.removeFontMarkup('size');
		if (size == '(default)')
			dom.removeFontMarkupAsStyle('font-size');
		else
			dom.applyFontMarkupAsStyle('font-size',size);
	}
*/
}

function canAcceptCommand(){
    if (dw.isPreviewMode())
        return false;
        
	var retVal = (dw.getFocus() == 'document' && getShowFontsAndSizes());

	if (retVal)
	{
		var dom = dw.getDocumentDOM();
		if (dom)
		{
		    if (CCWorkspaceManager.getManager(dom).IsCurrentPageXML()) return false;
			if (!isSelectionTextuallyModifiable(dom))
			{
				retVal = false;
			}
		}
		else
		{
			retVal = false;
		}
	}

	return retVal;
}

function isCommandChecked(){
	return (getCurrentValue() == arguments[0]);		
}

// 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){
	if (!getShowFontsAndSizes())
		return null;
		
	var sizeList;
	var sizes = new Array();
	if (getFontTag() == "font"){
		for (var i=0; i<FONT_VALUES.length; i++){
			sizes[i] = new String(FONT_VALUES[i]);
			sizes[i] += ";id='"+(i+1)+"'";
		}
	}else{
		if (getFontUnits() == "ems" || getFontUnits() == "%")
		{
			for (var i = 0; i < EM_VALUES.length; i++)
			{
				sizes[i] = new String(EM_VALUES[i]) + "%";
				if(getFontUnits() == "ems")
					sizes[i] += ";id='" + (EM_VALUES[i] / 100.0) + "em'";
				else
					sizes[i] += ";id='" + EM_VALUES[i] + "%'";
			}
		}
		else
		{
		    if (getFontUnits() == "points")
		    {
		    	for (var i=0; i<SPAN_VALUES.length; i++)
		    	{				
				    sizes[i] = new String(SPAN_VALUES[i]);
					sizes[i] += ";id='"+SPAN_VALUES[i]+"pt'";
				}
			}
			else
			{
			    for (var i=0; i < PIXEL_VALUES.length; i++)
			    {
				    sizes[i] = new String(PIXEL_VALUES[i]);
					sizes[i] += ";id='"+convertPointsToPixels(SPAN_VALUES[i])+"px'";
				}
			}
		}
	}
	sizes.unshift(MENU_Default + ";id='(default)'");
	return sizes;
}

function getCurrentValue(){
	var dom = dw.getDocumentDOM();
	sizeProp = dom.getCSSStyleProperties(true).fontSize;
	if (sizeProp == "*")
		return "";

	var suffix = "";
	if (getFontTag() != "font")
	{
		// Ems are special.  We never reflect the underlying pixel/point
		// values when ems are turned on.  Instead, we always show the
		// current em value (expressed as a percentage), and if no em
		// value is set, we show 100%.
		if (getFontUnits() == "ems" || getFontUnits() == "%")
		{
			var result;
			if(getFontUnits() == "ems")
				result = "1em";
			else
				result = "100%";
			if (sizeProp && sizeProp != "" &&
				(sizeProp.slice(sizeProp.length - 1) == "%" || sizeProp.slice(sizeProp.length - 2) == "em") &&
				!isNaN(parseFloat(sizeProp)))
			{
				// See if this em value exists in the menu already.
				// If so, just pass it back--it'll get mapped to a
				// percentage automatically.  Otherwise, pass back
				// a percentage to display in the dropdown.
				var emSize;
				if(sizeProp.slice(sizeProp.length - 2) == "em")
					emSize = Math.floor(parseFloat(sizeProp.slice(0, sizeProp.length - 2)) * 100.0);
				else
					emSize = parseFloat(sizeProp.slice(0, sizeProp.length - 1));
				var bFound = false;
				for (var i = 0; i < EM_VALUES.length; i++)
				{
					if (emSize == EM_VALUES[i])
					{
						bFound = true;
						break;
					}
				}
				if (bFound)
				{
					// Return the ems.  The dropdown will map it to the
					// correct entry.
					result = sizeProp;
				}
				else
				{
					// Return the percentage to show in the dropdown.
					result = emSize + "%";
				}
			}
			return result;
		}
		
		if (getFontUnits() == "pixels")
			suffix = "px";
		else
			suffix = "pt";
	}
	
	var result = sizeProp;
	if (sizeProp && sizeProp != "")
	{
		var sizeUnits = sizeProp.slice(sizeProp.length - 2);
		if (sizeUnits == "pt" || sizeUnits == "px")
		{
			// Sort of silly...To simplify the logic, we always convert
			// to points first.  This means we end up converting to
			// points and then back to pixels if it started out as
			// pixels...
			var sizeVal = parseInt(sizeProp.slice(0, sizeProp.length - 2));
			var ptSize;
			if (sizeUnits == "px")
				ptSize = convertPixelsToPoints(sizeVal);
			else
				ptSize = sizeVal;
			if (getFontTag() == "font")
				result = convertPointsToFontSizes(ptSize);
			else if (getFontUnits() == "points")
				result = ptSize;
			else if (sizeVal > 0)
				result = convertPointsToPixels(ptSize);

			if (result == -1)
				result = sizeProp;
			else if (result && result != "")
				result += suffix;
		}
	}

	if (!result || result == "")
	{
		if (getFontTag() == "font")
			result = "3";
		else if (getFontUnits() == "points")
			result = "12pt";
		else
			result = "16px";
	}
		
	return result;
}

// -->   
</SCRIPT>
</HEAD>
<BODY>
</BODY>
</HTML>
