<!-- 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_FontFamilies/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---------------

// Changed from "Default Paragraph Font" for space reasons.
var MENU_Default = dw.loadString('Menus/MM/ccText_FontFamilies/MENU_Default');
var MENU_EditFontList = dw.loadString('Menus/MM/ccText_FontFamilies/MENU_EditFontList');

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

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

    return show;
    
}

function receiveArguments(){
	var fontFamily = arguments[0];
	var dom = dw.getDocumentDOM();

	// prevent the user from setting the new
	// text style to be the separator line -------
	if (fontFamily[0] == '-')
	{
		return;
	}

	if (fontFamily == "MM_EditFont")
	{
	    dw.editFontList();
	}
	else if (fontFamily != "*")
	{
		if (dw.getFocus(true) == 'document')
		{
	  		if (fontFamily == "0Font")
	  			dom.applyFontMarkup('face','');
  			else
  				dom.applyFontMarkup('face',fontFamily);

/*
			if (getFontTag() == "font")
			{
				// Clear any <span>-applied font face in addition to adding or
				// removing the <font> tag.
				dom.removeFontMarkupAsStyle('font-family');
 			 	if (fontFamily == "0Font")
  				    dom.removeFontMarkup('face');
				else
  				    dom.applyFontMarkup('face',fontFamily);
			}
			else
			{
				// Clear any <font>-applied font face in addition to adding or
				// removing the <span> tag.
				dom.removeFontMarkup('face');
				if (fontFamily == "0Font") 
					dom.removeFontMarkupAsStyle('font-family');
				else
				{
					//double-byte font names has to be wrapped around with quotes
					if (hasDoubleByteChar(fontFamily)) {
						var fontFamilyList = fontFamily.split( "," );
						fontFamily = "";
						for (var i = 0; i < fontFamilyList.length; i++)
						{
							fontFamilyList[i] = Trim(fontFamilyList[i]);
							fontFamily = fontFamily + "'" + fontFamilyList[i] + "'";
							if (i != fontFamilyList.length-1)	// don't add , if it's the last font name
								fontFamily = fontFamily + ",";
						}
					}
					dom.applyFontMarkupAsStyle('font-family',fontFamily);
				}
			}
*/
		}
    }
}

function canAcceptCommand() {
    
    if (dw.isPreviewMode())
        return false;
        
	if (!getShowFontsAndSizes())
		return false;
		
  var retVal = false;
  if (dw.getFocus() == 'document') {
    retVal = true;
    var dom = dw.getDocumentDOM();
    if (CCWorkspaceManager.getManager(dw.getDocumentDOM()).IsCurrentPageXML()) return false;
	if (dom)
	{
		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 fonts = new Array();
		var i;
		var dwFnt = getFontList();
		var firstFont;

		if (dwFnt.length > 0){
			for (i=0; i<dwFnt.length; i++){
				//Japanese font family contains Win only or Mac only fonts so if we only display the first font in the menu, 
				//Windows font will be displayed on Mac. We display the entire font family for J version on Mac.
				//Update: We need to do this for Korean as well.  Listing only the first font of each family isn't
				//sufficient for Korean users.
				if ((dreamweaver.appVersion.indexOf('ja') != -1 && navigator.platform.charAt(0) == "M") || (dreamweaver.appVersion.indexOf('ko') != -1)) 
					firstFont = dwFnt[i];	
				else 
				firstFont = dw.getTokens(dwFnt[i],",'\"")[0];

				fonts[i] = new String(firstFont);

				// Don't escape quotes here.  This is now done by Dreamweaver
				// when ever getDynamicContent() is called.
//				fonts[i] += ";id='"+escQuotes(new String(dwFnt[i]))+"'";
				fonts[i] += ";id='"+new String(dwFnt[i])+"'";
			}
		}
	    fonts.sort();
		fonts.unshift(new String(MENU_Default + ";id='0Font'")); // start with the base "Default" font
		fonts.push("------------------");
		fonts.push(new String(MENU_EditFontList + ";id='MM_EditFont'"));
		return fonts;
	}

function getCurrentValue(){
	var dom = dw.getDocumentDOM();
	var fontCascade = "";
	if (dw.getFocus() == 'document')
	{
		fontCascade = dom.getCSSStyleProperties(true).fontFamily;
	}

	if (fontCascade == "*")
		return "";
	if (!fontCascade || fontCascade == "")
		return "0Font";

	if ((dreamweaver.appVersion.indexOf('ja') != -1 && navigator.platform.charAt(0) == "M") || (dreamweaver.appVersion.indexOf('ko') != -1)) {
		//Japanese font family contains Win only or Mac only fonts so 
		//if we only display the first font in the menu, 
		//Windows font will be displayed on Mac. We display the entire 
		//font family for J version. If the current cascade is different from 
		//one of our build-in cascades, display the current one.
		//Update: We need to do this for Korean as well.  Listing only the first font of each family isn't
		//sufficient for Korean users.
		var dwFnt = getFontList();
		fontCascade = fontCascade.replace(/\'/g, '');
		for (i = 0; i < dwFnt.length; i++)
		{
			//Is the current cascade same as build-in font family?
			//If so, use it in font menu.
			if (fontCascade == dwFnt[i]) 
				return dwFnt[i];
		}
		return fontCascade;
	}
	else {
		// In general, we only want to display the first font in the
		// cascade.
		// Special handling: If the first font in the cascade matches the
		// first font in one of our built-in font strings, return the
		// built-in cascade instead, so we select the existing item
		// instead of creating a new item.
		var firstFont = dw.getTokens(fontCascade, ",'\"")[0];
		var lowerFirstFont = firstFont.toLowerCase();
		var dwFnt = getFontList();
		for (i = 0; i < dwFnt.length; i++)
		{
			if (lowerFirstFont == dw.getTokens(dwFnt[i], ",'\"")[0].toLowerCase())
				return dwFnt[i];
		}
		return firstFont;
	}
}
// -->   
</SCRIPT>
</HEAD>
<BODY>
</BODY>
</HTML>
