/* BvDImageButton */

function EnableButton (id, enabled, tooltip)
{
	p = FindImageInArray (id);
	if (p >= 0 && document.images [id])
	{
		Image_Enabled [p] = (enabled)? "1": "0";
		if(enabled)
		{
			document.images [id].src = Image_On [p];
			document.images [id].style.cursor = 'auto';
		}
		else
		{
			document.images [id].src = Image_Greyed [p];
			document.images [id].style.cursor = 'default';
		}
		if (tooltip != null)
			document.images [id].title = tooltip;
	}
}

function IsEnabled (id)
{
	p = FindImageInArray (id);
	if (p >= 0)
	{
		return (Image_Enabled[p] == "1" || Image_Enabled[p] == true);
	}
	return false;
}

function FindImageInArray (id)
{
	if(typeof (Image_Ids) == "undefined")
		return -1;												 
	for(var index=0; index < Image_Ids.length; index++)
		if (Image_Ids [index] == id )
			return index;
	return -1;
}

function LaunchClickEvent(id)
{
	var buttonObj = document.getElementById(id);
	if(buttonObj != null)
	{
		if(typeof(buttonObj.click) != "undefined")
			buttonObj.click();
		else
			eval(buttonObj.parentNode.href);  // For Firefox
	}
}

function ImgBnClk(causesValidation, IEPatchEnabled, ANode, validateFunction)
{
	if (ANode)
	{
		var clientID = ANode.firstChild.id;
		if (!IsEnabled(clientID))
			return false;
	}
		
	if ((causesValidation == 1) && (typeof(Page_ClientValidate)=='function') && !Page_ClientValidate())
		return false;
		
	if(validateFunction != null && !validateFunction())
		return false;

	if (IEPatchEnabled == 1)
		document.body.style.cursor='progress';
    else
        BvdPageDisplayProgressCursor = false;		
	
	return true;
}


/* ConfirmedImageButtonControl */
				
function ConfImgBnClk(confirmationMessage)
{
	if (typeof(Page_ClientValidate)=='function' && !Page_ClientValidate())
		return false;
	
	return confirm(confirmationMessage);
}
