var BUTTON_INCLUDED = true;

// test to see that the AbstractWidget class is defined.
if ( typeof ABSTRACT_WIDGET_INCLUDED == "undefined" )
{
	alert("Fatal Error: you need to include \"AbstractWidget.js\" before you can subclass it.");
}

function ActionButton(browserAbstractionLayer, instanceName, className)
{
	//Image is a subclass of AbstractWidget
	this.base = AbstractWidget;
	this.base(browserAbstractionLayer, instanceName);

	// default values for all inherited classes. Override these in the subclass, not here.
	this.ButtonObj = null;
	this.ButtonHeadObj = null;
	this.ButtonTailObj = null;
	this.ButtonBodyObj = null;
	this.ButtonBodyBackGroundObj = null;
	
	this.imagePath = g_widgetPath + "Buttons/images" + className + "/";
	this.HEAD_IMAGE_NORMAL = this.imagePath + "normal/button_head.gif";
	this.BODY_IMAGE_NORMAL = this.imagePath + "normal/button_body.gif";
	this.TAIL_IMAGE_NORMAL = this.imagePath + "normal/button_tail.gif";
	this.IsActive = false;
	this.Enabled = true;

	this.HEAD_IMAGE_OVER = this.imagePath + "over/button_head.gif";
	this.BODY_IMAGE_OVER = this.imagePath + "over/button_body.gif";
	this.TAIL_IMAGE_OVER = this.imagePath + "over/button_tail.gif";

	this.HEAD_IMAGE_ACTIVE = this.imagePath + "active/button_head.gif";
	this.BODY_IMAGE_ACTIVE = this.imagePath + "active/button_body.gif";
	this.TAIL_IMAGE_ACTIVE = this.imagePath + "active/button_tail.gif";

	//Button method declarations
	this.draw			= drawMethod;
	this.activate	    = activateMethod;
	this.move			= moveMethod;
	this.mouseOver		= mouseOverMethod;
	this.mouseOut		= mouseOutMethod;
	this.setActive		= setActiveMethod;
	this.setInActive	= setInActiveMethod;
	this.setCaption		= setCaptionMethod;
	this.enable			= enableMethod;
	this.disable		= disableMethod;

	function drawMethod(Caption,hFunction,TooltipText,Width) 
	{
		// write the HTML	
		document.write('<div title="' + TooltipText + '">');	
		document.write('<table class="ButtonNormal' + className + '" border="0" align="left" id="' + this.instanceName + WIDGET_DIV_DELIMITER + 'Button" cellpadding="0" cellspacing="0">');
		document.write('<tr>');
		document.write('<td class="ButtonHead' + className + '" align="right">');
		document.write('<img class="ButtonHeadImg' + className + '" border="0" id="' + this.instanceName + WIDGET_DIV_DELIMITER + 'buttonHead" ');
		document.write('src="' + this.HEAD_IMAGE_NORMAL + '">');
		document.write('<\/td>');
		
		document.write('<td width="' + Width + '" align="center" valign="middle" class="ButtonBody' + className + '" ');
		document.write('style="text-align:center;background-image:url(' + this.BODY_IMAGE_NORMAL + ');background-repeat:repeat-x;" id="' + this.instanceName + WIDGET_DIV_DELIMITER + 'buttonBodyBackGround" >');
		document.write('<div  class="ButtonBodyNormal' + className + '" id="' + this.instanceName + WIDGET_DIV_DELIMITER + 'buttonBody"><nobr>' + Caption + '<\/nobr><\/div>' );
		document.write('<\/td>');
			
		document.write('<td class="ButtonTail' + className + '" align="right">');
		document.write('<img border="0" class="ButtonTailImg' + className + '" id="' + this.instanceName + WIDGET_DIV_DELIMITER + 'buttonTail" ');
		document.write('src="' + this.TAIL_IMAGE_NORMAL + '">');
		document.write('<\/td>');
		document.write('<\/tr>');
		document.write('<\/table>');
		document.write('<\/div>');
		
		// make references to these newly draw objects
		this.ButtonHeadObj = this.browserAbstractionLayer.getElementById(this.instanceName + WIDGET_DIV_DELIMITER + "buttonHead");
		this.ButtonBodyBackGroundObj = this.browserAbstractionLayer.getElementById(this.instanceName + WIDGET_DIV_DELIMITER + "buttonBodyBackGround");
		this.ButtonBodyObj = this.browserAbstractionLayer.getElementById(this.instanceName + WIDGET_DIV_DELIMITER + "buttonBody");
		this.ButtonTailObj = this.browserAbstractionLayer.getElementById(this.instanceName + WIDGET_DIV_DELIMITER + "buttonTail");
		this.ButtonObj = this.browserAbstractionLayer.getElementById(this.instanceName + WIDGET_DIV_DELIMITER + "Button");
		
		// attach event handlers

    this.browserAbstractionLayer.addEventHandler(this.ButtonObj,"OVER","mouseOverHandler");
    this.browserAbstractionLayer.addEventHandler(this.ButtonObj,"OUT","mouseOutHandler");
    this.browserAbstractionLayer.addEventHandler(this.ButtonObj,"DOWN","mouseDownHandler");

		this.hFunction = hFunction;

		
	} // end of drawMethod

	function setCaptionMethod(sCaption)
	{
		this.ButtonBodyObj.innerHTML = sCaption; 
	}

	function setInActiveMethod()
	{
		this.ButtonHeadObj.src = this.HEAD_IMAGE_NORMAL;
		this.ButtonBodyBackGroundObj.style.backgroundImage = "url(" + this.BODY_IMAGE_NORMAL + ")";
		this.ButtonTailObj.src = this.TAIL_IMAGE_NORMAL;
		if (this.Enabled)
		{ this.ButtonBodyObj.className = 'ButtonBodyNormal' + className;
			this.ButtonObj.className='ButtonNormal' + className;
	  }else
		{ this.ButtonBodyObj.className='ButtonBodyDisabled' + className;
			this.ButtonObj.className='ButtonDisabled' + className;
		}
		this.IsActive = false;
	}

	function setActiveMethod()
	{
		this.ButtonHeadObj.src = this.HEAD_IMAGE_ACTIVE;
		this.ButtonBodyBackGroundObj.style.backgroundImage = "url(" + this.BODY_IMAGE_ACTIVE + ")";
		this.ButtonTailObj.src = this.TAIL_IMAGE_ACTIVE;
		this.ButtonBodyObj.className='ButtonBodyActive' + className;
		this.ButtonObj.className='ButtonActive' + className;
		
		this.IsActive = true;
	}
	
	function activateMethod(x,y) 
	{	
		if (this.Enabled)
		{
			this.setActive();

			if (this.hFunction != null)
			{
				eval(this.hFunction);	// activate this function
			}		

			this.setInActive();	
		}
	}
	function moveMethod(x,y) 
	{
		//document.writeln('move ' + x + y);
	}

	function mouseOverMethod(x,y) 
	{
		if (this.Enabled)
		{
			this.browserAbstractionLayer.setCursor(this.ButtonObj, "pointer");
		
			if (this.IsActive == false)
			{
				this.ButtonHeadObj.src = this.HEAD_IMAGE_OVER;
				this.ButtonBodyBackGroundObj.style.backgroundImage = "url(" + this.BODY_IMAGE_OVER + ")";
				this.ButtonTailObj.src = this.TAIL_IMAGE_OVER;
				this.ButtonBodyObj.className='ButtonBodyActive' + className ;
				this.ButtonObj.className='ButtonActive' + className ;
			}
		}
	}
	
	function mouseOutMethod(x,y) 
	{
		this.browserAbstractionLayer.setCursor(this.ButtonObj, "default");

		if (this.Enabled)
		{
			if (this.IsActive == false)
			{
				this.ButtonHeadObj.src = this.HEAD_IMAGE_NORMAL;
				this.ButtonBodyBackGroundObj.style.backgroundImage = "url(" + this.BODY_IMAGE_NORMAL + ")";
				this.ButtonTailObj.src = this.TAIL_IMAGE_NORMAL;
	  		this.ButtonBodyObj.className = 'ButtonBodyNormal' + className;
 			  this.ButtonObj.className='ButtonNormal' + className ;
			}
		}
	}

	function enableMethod()
	{
		this.Enabled = true;
	}
	
	function disableMethod()
	{
		this.Enabled = false;
		this.browserAbstractionLayer.setCursor(this.ButtonObj, "default");
		this.setInActive();
	}


} //end of Image class

// this line sets up the object hierarchy
ActionButton.prototype = new AbstractWidget;
