//  Copyright 2002, 2003 Macromedia, Inc. All rights reserved.

var helpDoc = MM.HELP_objHorizontalRule;

function receiveArguments()
{
}

function canAcceptCommand()
{
	if ( dw.getDocumentDOM().getCCSharedSetting_TextOnlyInNonTemplates() )
		return false;
	return true;
}

function commandButtons()
{
/*   return new Array(MM.BTN_OK,         "run()",
                    MM.BTN_Cancel,     "window.close()",
                    MM.BTN_Help,       "displayHelp()" );
*/

     return new Array( "PutButtonsOnBottom",
						 "OkButton", MM.BTN_OK,     "run()", 
                         "CancelButton", MM.BTN_Cancel,  "window.close()",
                         "PutButtonOnLeft", MM.BTN_Help,    "displayHelp()");
}

function initializeUI()
{
	var node = dw.getDocumentDOM().getSelectedNode();

	var width = node.getAttribute("width");
	if(width != null && width != "")
	{
		var indexPercent = width.indexOf("%");
		if(indexPercent > 0)
		{
			width = width.substr(0, indexPercent);

			document.theForm.Units.options[1].selected = true;
		}
        document.theForm.Width.value = width;
	}
    else
    {
        document.theForm.Width.value = "";
    }

	var height = node.getAttribute("size");
	if(height != null && height != "")
	{
		document.theForm.Height.value = height;
	}
    else
    {
        document.theForm.Height.value = "";
    }

	if(node.getAttribute("noshade"))
	{
		document.theForm.Shading.checked = false;
	}
}

function verifyHRAttrs(widthValue, heightValue)
{
	var retVal = '';

	var width = parseInt(widthValue);
	var height = parseInt(heightValue);

	if ( (!isNaN(width) && (width < 1) )  
	  || (width != widthValue && widthValue != '') )
	{
		retVal = errMsg(MM.Error_Invalid_Field, widthValue);
	}

	if ( (!isNaN(height) && (height < 1) )  
	  || (height != heightValue && heightValue != '') )
	{
		retVal = errMsg(MM.Error_Invalid_Field, heightValue);
	}


	return retVal;
}

function run()
{
	var node = dw.getDocumentDOM().getSelectedNode();

	var widthValue=document.forms[0].Width.value;
	var heightValue=document.forms[0].Height.value;

	var errStr = '';
	errStr = verifyHRAttrs(widthValue, heightValue);

	if(errStr.length < 1)
	{
		if ((widthValue != null) && (widthValue != ''))
		{
			var widthType = document.forms[0].Units.selectedIndex;
			if(widthType == 1)
			{
				widthValue += "%";
			}
			node.width = widthValue;
		}
        else if (node.getAttribute("width"))
        {
            node.removeAttribute("width");
        }

		if ((heightValue != null) && (heightValue != ''))
		{
			node.size = heightValue;
		}
        else if (node.getAttribute("size"))
        {
            node.removeAttribute("size");
        }

		var shading=document.forms[0].Shading.checked;
		if(!shading)
		{
			node.noshade = "true";
		}
		else
		{
			if(node.getAttribute("noshade"))
			{
				node.removeAttribute("noshade");
			}
		}
		window.close();
	}
	else
	{
		alert(errStr);
		document.forms[0].Width.focus();
	}
}
