/* Script is inspired on the example in the book "JavaServer Faces 2.0" (by Burns and Schalk), page 355. */

if (!window["busyIndicator"]) {
	var busyIndicator = {};
}
busyIndicator.onEvent = function onEvent(data) {
	var status = data.status;
	var element = document.getElementById(busyIndicator.spinnerComponentID);
	if (status === "begin") { // turn on busy indicator
		element.style.display = "inline";
	} else { // turn off busy indicator, on either "complete" or "success"
		element.style.display = "none";
	}
};

jsf.ajax.addOnEvent(busyIndicator.onEvent);

busyIndicator.init = function init(spinnerComponentID) {
	busyIndicator.spinnerComponentID = spinnerComponentID;
};
