/**
 * Toolbar Section
 */
var currentId = 1;
var elementType = "p";
var numChildren = 4;
var FOCUS_OFF_ATTRIBUTES = "#f0f0e6 2px solid";
var FOCUS_ON_ATTRIBUTES = "#AB00A0 2px solid";

function ClearChildFocus()
{	
	var focusedChild = document.getElementById(elementType+currentId);
	focusedChild.style.border = FOCUS_OFF_ATTRIBUTES;
	if(focusedChild)
	{
		// Needed to update IE styling
		focusedChild.className += "";
	}
}

function RemoveChildFocus()
{
	var focusedChild = document.getElementById(elementType+currentId);
	focusedChild.style.border = FOCUS_OFF_ATTRIBUTES;
	if(focusedChild)
	{
	// Needed to update IE styling
	focusedChild.className += "";
	}
	return false;
}

function AddChildFocus(childId)
{
	var focusedChild = document.getElementById(elementType+childId);
	if(focusedChild)
	{
		currentId=childId;
		if(IsElementDisabled()=="false")
		{
			var toolbarObj = axs.id("customToolbar");
			if(UseStates)
			{
			toolbarObj.setAttribute("aria-activedescendant",elementType+childId);
			}
			focusedChild.style.border = FOCUS_ON_ATTRIBUTES;
			// Needed to update IE styling
			focusedChild.className += "";
			currentId=childId;
		}
	}
}

function ExecuteButtonAction(i)
{
	document.getElementById(i).onclick();
	return;
}

function getCurrentButtonID()
{
	return elementType+currentId;
}

function IsElementDisabled()
{
	disabled=axs.id(getCurrentButtonID()).getAttribute("aria-disabled")
	if(disabled)
	{
		return disabled;	
	}
	else
	{
	 return false;
	}
}
function getNextButtonID()
{	
	if (currentId < numChildren)
	{
		RemoveChildFocus();
		lastId = currentId;
		currentId = currentId + 1;

		while(IsElementDisabled()=="true")
		{
			
			currentId = currentId + 1;
			if(currentId > numChildren)
			{
				currentId = lastId;  // this means all remaining elements were disabled
				break;
			}

		}
		
		AddChildFocus(currentId);
	}
	return elementType+currentId;
}

function getPrevButtonID()
{
	if (currentId > 1)
	{
		RemoveChildFocus();
		lastId = currentId;
		currentId = currentId - 1;
		while(IsElementDisabled()=="true")
		{
		currentId = currentId -1;
		if(currentId < 1)
		{
			currentId=lastId;  // this means all remaining elements were disabled
			break;
		}
		}
		AddChildFocus(currentId);
	}
	return elementType+currentId;
}


