if(Forms == null) var Forms = {};

Forms.Buttons = {

	AllButtons : null
	,
	Setup : function()
	{

		Forms.Buttons.AllButtons = document.getElementsByClassName("button");
	
		for(var x=0; x < Forms.Buttons.AllButtons.length; x++)
		{
		
			var thisButton = Forms.Buttons.AllButtons[x];
						
						
			
			thisButton.onmouseover = 
			thisButton.onfocus = 
			function(){Forms.Buttons.addCssClass(this, "hover");}		
			
			thisButton.onmouseout = 
			thisButton.onblur = 
			function(){
				Forms.Buttons.removeCssClass(this, "hover");
				Forms.Buttons.removeCssClass(this, "active");
			}	
			
			thisButton.onmousedown = 
			function() {Forms.Buttons.addCssClass(this, "active");}
			
			thisButton.onmouseup = 
			function(){Forms.Buttons.removeCssClass(this, "active");}	
			
			thisButton.onclick = 
			function()
			{
				var returnValue = true;
				Forms.Buttons.addCssClass(this, "loading");				
				Forms.Buttons.LastButtonClicked = this;
				if(Forms.Validation && this.className.indexOf("no-validate") >= 0)
				{
					Forms.Validation.DoValidate = false;
				}		
				if(this.className.indexOf("delete") >= 0)
				{
					returnValue = confirm("Are you sure you want to use this Delete item?");
				}
				if(this.className.indexOf("remove") >= 0)
				{
					returnValue = confirm("Are you sure you want to use this Remove item?");
				}						
				return returnValue;	
			}
			
		}// end for	
	
	}
	,
	Reset : function()
	{
		for(var x=0; x < Forms.Buttons.AllButtons.length; x++)
		{
			var thisButton = Forms.Buttons.AllButtons[x];
			Forms.Buttons.removeCssClass(thisButton, "loading");
		}
	}
	,
	addCssClass : function(theButton, newCssClass)
	{
		
		newCssClass = "-" + newCssClass;
		
		if(theButton.className.indexOf("button-small") > -1)
		{
			document.addCssClass(theButton, "button-small" + newCssClass);		
		}
		if(theButton.className.indexOf("button-medium") > -1)
		{
			document.addCssClass(theButton, "button-medium" + newCssClass);		
		}
		if(theButton.className.indexOf("button-large") > -1)
		{
			document.addCssClass(theButton, "button-large" + newCssClass);		
		}
		if(theButton.className.indexOf("button-xlarge") > -1)
		{
			document.addCssClass(theButton, "button-xlarge" + newCssClass);		
		}						
	}
	,
	removeCssClass : function(theButton, newCssClass)
	{
		
		newCssClass = "-" + newCssClass;
		
		if(theButton.className.indexOf("button-small") > -1)
		{
			document.removeCssClass(theButton, "button-small" + newCssClass);		
		}
		if(theButton.className.indexOf("button-medium") > -1)
		{
			document.removeCssClass(theButton, "button-medium" + newCssClass);		
		}
		if(theButton.className.indexOf("button-large") > -1)
		{
			document.removeCssClass(theButton, "button-large" + newCssClass);		
		}
		if(theButton.className.indexOf("button-xlarge") > -1)
		{
			document.removeCssClass(theButton, "button-xlarge" + newCssClass);		
		}						
	}	

}

window.addToOnload(Forms.Buttons.Setup);

