<!-- MENU-LOCATION=NONE -->
<HTML>
<HEAD>
<!-- Copyright 2001, 2002, 2003 Macromedia, Inc. All rights reserved. -->
<TITLE>Custom Styles</TITLE>
<SCRIPT LANGUAGE="javascript" SRC="../../Shared/MM/Scripts/CMN/string.js"></SCRIPT>

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


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

function receiveArguments(){
	var alignment = arguments[0];
	var valign = (alignment == "top" || alignment == "middle" || alignment == "bottom" || alignment == "vDefault");
	var dom = dw.getDocumentDOM();
	var theSel = dom.getSelection(true);
	var node = null;
	// If there's more than one cell selected, apply change
	// to all.
	if (theSel.length > 2){
		for (var i=0; i < theSel.length; i=i+2){
			node = dom.offsetsToNode(theSel[i],theSel[i+1]);
			// If the alignment is a vertical one, set valign. 
			if (valign){
				if (alignment == "vDefault"){
					if (node.getAttribute("valign")){
						node.removeAttribute("valign");
					}
				}else{
					node.setAttribute("valign",alignment);
					// Adjust remaining offsets by amount of text just added.
					for (var j=i+2; j < theSel.length; j++){
						theSel[j] = theSel[j] + new String(' valign="' + alignment + '"').length;
					}
				}
			// Otherwise, set align.
			}else{
				if (alignment == "Default"){
					if (node.getAttribute("align")){
						node.removeAttribute("align");
					}
				}else{
					node.setAttribute("align",alignment);
					// Adjust remaining offsets by amount of text just added.
					for (var j=i+2; j < theSel.length; j++){
						theSel[j] = theSel[j] + new String(' align="' + alignment + '"').length;
					}
				}
			}		
		}
	}else{
		node = dom.offsetsToNode(theSel[0],theSel[1]);
		if (node.nodeType == 'Node.TEXT_NODE') node = node.parentNode;
		while (node.parentNode && (node.tagName != 'TD' || node.tagName != 'TH')){
			node = node.parentNode;
		}
		// If the alignment is a vertical one, set valign. 
		if (valign){
			if (alignment == "vDefault"){
				if (node.getAttribute("valign")){
					node.removeAttribute("valign");
				}
			}else{
				node.setAttribute("valign",alignment);
			}
		// Otherwise, set align.
		}else{
			if (alignment == "Default"){
				if (node.getAttribute("align")){
					node.removeAttribute("align");
				}
			}else{
				node.setAttribute("align",alignment);
			}
		}
	}
}

function canAcceptCommand()
{
	return ((dw.getFocus() == 'document' && dw.getDocumentDOM().getFocus() == 'body') || dw.getFocus() == 'textView' || dw.getFocus() == 'html') && dw.getDocumentDOM() && dw.getDocumentDOM().getParseMode() == 'html';
}

function isCommandChecked(){
//  var bChecked = false;
//	var allMatch = true;
//	var alignment = arguments[0];
//	var valign = (alignment == "top" || alignment == "middle" || alignment == "bottom" || alignment == "vDefault");
//	var selAlign = null;
///	var dom = dw.getDocumentDOM();
//	var theSel = dom.getSelection(true);
//	var nodes = new Array();
//	if (theSel > 2){
//		for (var i=0; i < theSel.length; i=i+2){
//			nodes.push(dom.offsetsToNode(theSel[i],theSel[i+1]));
//		}
//		// If the alignment is a vertical one, check valign. 
//		if (valign){		
//			selAlign = nodes[0].getAttribute("valign");
//			if (selAlign) selAlign = selAlign.toLowerCase();
//			for (var p=1; p < nodes.length; p++){
//				if (selAlign){
//					if (nodes[i].getAttribute("valign") && nodes[i].getAttribute("valign").toLowerCase() != selAlign){
//						allMatch = false;
//						break;
//					}
//				}else{
//					if (nodes[i].getAttribute("valign") != selAlign){
//						allMatch = false;
//						break;
///					}
//				}
//			}
//		// Otherwise, check align.
//		}else{
//			selAlign = nodes[0].getAttribute("align");
//			if (selAlign) selAlign = selAlign.toLowerCase();
//			for (var p=1; p < nodes.length; p++){
//				if (selAlign){
//					if (nodes[i].getAttribute("align") && nodes[i].getAttribute("align").toLowerCase() != selAlign){
//						allMatch = false;
//						break;
//					}
//				}else{
//					if (nodes[i].getAttribute("align") != selAlign){
//						allMatch = false;
//						break;
//					}
//				}
//			}
//		}
//	
//		if (allMatch){
//			if (alignment == "vDefault" || alignment == "Default"){
//				bChecked = (selAlign == null);
//			}else{
//				bChecked = (alignment == selAlign);
//			}
//		} 
//	}else{
//		var node = dom.offsetsToNode(theSel[0],theSel[1]);
//		if (node.nodeType == 'Node.TEXT_NODE') node = node.parentNode;
//		while (node.parentNode && node.tagName != 'TD'){
//			node = node.parentNode;
//		}
//		if (valign){
//			if (alignment == "vDefault"){
//				bChecked = (node.getAttribute("valign") == null);
//			}else{
//				bChecked = (alignment == node.getAttribute("valign"));
//			}
//		}else{
//			if (alignment == "Default"){
//				bChecked = (node.getAttribute("align") == null);
//				bChecked = true;
//			}else{
//				bChecked = (alignment == node.getAttribute("align"));
//			}
//		}
//	}
//	return bChecked;
	return false;
}
// -->   
</SCRIPT>
</HEAD>
<BODY>
</BODY>
</HTML>
