<!-- Copyright 2005 Macromedia, Inc. All rights reserved. -->
<html xmlns:MMString="http://www.macromedia.com/schemes/data/string/">
<head>
<title><MMString:loadString id="Toolbars/MM/ccBlogEntryTags/title" /></title>
<SCRIPT LANGUAGE="javascript" SRC="../../Shared/MM/Scripts/CMN/ccBlogMetaDataStrings.js"></SCRIPT>
<script language="JavaScript">


	// do these need to be localized?
var separaterChar = ',';
var separaterString = ',';
var paragraphClass = 'tags';
var translatorClass = 'MM_Tags';
var section = 'Tagging Preferences';
var fileUnder = 'Tag Prefix';
var defTagRepo = 'Default Tag Repository';

function LeftTrim(value)
{
	return value.replace(/^\s+/,'');
}

function RightTrim(value)
{
	return value.replace(/\s+$/,'');
}

function receiveArguments(tagstring)
{
	
	var foundIt = false;
		
	if (getCurrentValue() == tagstring)
		return;	
	// need to get the the top bottom preference from registry.
	var prefix = dw.getPreferenceString(section,fileUnder, '');
	var repository = dw.getPreferenceString(section,defTagRepo,'');
	
	// convert the tag string into an array of tag words
	var words = new Array;
	var numWords = 0;
	
	// chop off any leading spaces
	tagstring	=	LeftTrim(tagstring);
	
	while (tagstring.indexOf(separaterChar) !=  -1)
	{
			// store the first word in the array
		words[numWords] = tagstring.substring(0, tagstring.indexOf(separaterChar));
		numWords++;
		
			// lob off the first word
		tagstring = tagstring.substring((tagstring.indexOf(separaterChar)) + 1);
		
			// chop off any leading spaces
		tagstring	=	LeftTrim(tagstring);
		
	}
		// store the last word in the array
	if(tagstring != ''){
		// chop off any leading spaces
		tagstring	=	LeftTrim(tagstring);
		words[numWords] = tagstring;
	}
	
	// build the XHTML code for the array of tags
	var tags = "";
	
	wordcount = words.length;
	if(wordcount > 0)
		tags = prefix;
			
	for (i = 0; i < wordcount; i++)
	{ 
		if (words[i] != '')
		{
			//right trim all the words before writing
			words[i]	=	RightTrim(words[i]);
			
			tags += '<a href="' + repository + words[i] + '" rel="tag">' + words[i] + '</a>';
			if (i != (wordcount - 1))
			{
				tags += separaterString;
			}
		}
	}
	
	theDom = dw.getDocumentDOM();

	// we are going to update a locked section in the dom. so first disable all locked sections.
	// otherwise you get nasty error message.
	theDom.disableLocking();

		// find the tags paragraph and set the XHTML
    paragraphTags = theDom.getElementsByTagName("p");
    paragraphCount = paragraphTags.length;
	for (i = 0; i < paragraphCount; i++)
	{ 
		if (paragraphTags[i].getAttribute("class") == paragraphClass)
		{
			paragraphTags[i].innerHTML = tags;
			foundIt = true;
		}
	}

	// it not found, insert the tags XHTML
	if (foundIt == false && wordcount>0)
	{
		if (tagstring != '')
		{
			var insertString = '<!-- #BeginTags --><p class="' + paragraphClass + '">' + tags + '</p><!-- #EndTags -->'
			
			// deeje 2005-12-21, need to update this to support blog templates!
			//theDom.insertHTML(insertString,0);
			dw.getDocumentDOM().insertBlogMetaTag(TEMPLATE_MM_TAGS,insertString);
		}
	}
	else if(wordcount>0)
	{
		var insertString = '<!-- #BeginTags --><p class="' + paragraphClass + '">' + tags + '</p><!-- #EndTags -->'
		esc = escape(insertString);
		theDom.updateLockedRegion(translatorClass,esc);
	}else{
		var insertString = "";
		esc = escape(insertString);
		theDom.updateLockedRegion(translatorClass,esc);
	}

	// reset the locking.
	theDom.enableLocking();
	
	return;
}

function canAcceptCommand()
{
    var bIsTagReposPresent = '';
    bIsTagReposPresent = dw.getPreferenceString('Tagging Preferences', 'Default Tag Repository', '');
    if(bIsTagReposPresent == '')
        return false;
    else
    	return true;
}

function getCurrentValue()
{
	var value = "";
	// needed because, our javascript engine fidgets with
	// innerHTML for locked regions. This disables it.
	dw.useTranslatedSource(true);
	
	var ptags = dw.getDocumentDOM().getElementsByTagName("p");
	for(j=0;j<ptags.length;j++){
	
		if((ptags.item(j)).getAttribute("class")=="tags")
		{
			atags = (ptags.item(j)).getElementsByTagName("a");
			count = atags.length;
			for (i = 0; i < count; i++)
			{ 
				if (atags[i].getAttribute("rel") == "tag")
				{
					var val = atags[i].innerHTML;
					if(val != ''){
						if (value != '')
							value += separaterString;
						value += val;
					}
				}
			}
			break;
		}
	}
	// reset the fidgetting.
	dw.useTranslatedSource(false);
	
	return value;
}


function getDynamicContent()
{
	var items = new Array;
	return items;
}

function showIf()
{
    var entryType = CCWorkspaceManager.getManager(dw.getDocumentDOM()).getCurBlogEntryType();
    if(entryType == 'posts')
        return true;
    return false;
}

</script>
</head>

<body>
</body>
</html>

