if (typeof(addEvent) == "undefined") {
	function addEvent(objid, evname, funcname) {/*<<<*/
		if (obj = document.getElementById(objid)) {
			addEventToObject(obj, evname, funcname);
		}
	}
}
/*>>>*/
if (typeof(addEventToObject) == "undefined") {
function addEventToObject(obj, evname, funcname) { /*<<<*/
	if (typeof(obj) == "undefined") return;
	if (evname.substr(0,2) != "on") {
		evname = "on"+evname; // allow events to be passed by their names
	}
	if (funcname.indexOf(")")) {
		nfbr = "";
	} else {
		nfbr = "()"; // make sure that the new function is called as a fn
	}
	if (obj) {
		eval ("var oldfunc = obj."+evname);
		if (typeof oldfunc != 'function') {
			str = "obj."+evname+" = function () {"+funcname+nfbr+"}";
			eval(str);
		} else {
			eval("obj."+evname+" = function() {\noldfunc();\n"+funcname+";\n}");
		}
	}
}
}
/*>>>*/
if (typeof(dotoggle) == "undefined") {/*<<<*/
	function dotoggle(btn, toolbarid) {
		if (typeof(all_toolbar_buttons[toolbarid] != "undefined")) {
			for (var idx in all_toolbar_buttons[toolbarid]) {
				if (obj = document.getElementById(all_toolbar_buttons[toolbarid][idx])) {
					obj.className = "opbutton1";
				}
			}
		}
		if (btn.className == "opbutton1") {
			btn.className = "opbutton1d";
		} else {
			btn.className = "opbutton1";
		}
	}
}
/*>>>*/
function disable_all_toolbar_buttons(disable, toolbarid) {/*<<<*/
	if (typeof(disable) == "undefined") disable = true;
	if (typeof(all_toolbar_buttons) == "undefined") {
		return;
	}
	for (var idx in all_toolbar_buttons) {
		if ((typeof(toolbarid) != "undefined") && (toolbarid != idx)) continue;
		for (var idx2 in all_toolbar_buttons[idx]) {
			if (btn = document.getElementById(all_toolbar_buttons[idx][idx2])) {
				disable_toolbar_btn(btn, disable);
			}
		}
	}
}
/*>>>*/
function donothing() {/*<<<*/
// does nothing...
}
/*>>>*/
function in_array(el, arr) {/*<<<*/
	if (typeof(arr) == "undefined") return false;
	for (var idx in arr) {
		if (arr[idx] == el) return true;
	}
	return false;
}
/*>>>*/
function disable_toolbar_btn_byid(btnid, disable) {/*<<<*/
	if (obj = document.getElementById(btnid)) {
		disable_toolbar_btn(obj, disable);
	}
}
/*>>>*/
function disable_toolbar_btn (btn, disable) {/*<<<*/
	if (typeof(disable) == "undefined") {
		disable = true;
	}
	if (disable) {
		disable=true;	// ensure boolean
	} else {
		disable=false;
	}
	if (typeof(toolbar_button_states[btn.id]) != "undefined") {
		if (toolbar_button_states[btn.id] == disable) {
			return;
		}
	}
	if (typeof(btn.disabled) == "undefined") {
		if (typeof(stored_toolbar_scripts[btn.id]) == "function") {
			got_script = true;
		} else {
			got_script = false;
		}
		if (disable) {
			if (!got_script) {
				stored_toolbar_scripts[btn.id] = btn.onclick;
			}
			btn.onclick = donothing;
			btn.onmousedown = donothing;
			btn.onmouseup = donothing;
			btn.className = 'opbutton2';
			if (obj = document.getElementById("tbbtntext_"+btn.id)) {
				obj.className = "opbutton2";
			}
		} else {
			if (got_script) {
				if ((typeof(toolbar_toggle_buttons) == "undefined") || (!in_array(btn.id, toolbar_toggle_buttons))) {
					btn.onmousedown = function () {
						this.className="opbutton1d";
					};
					btn.onmouseup = function () {
						this.className="opbutton1";
					};
				}
				btn.onclick=stored_toolbar_scripts[btn.id];
				btn.className = "opbutton1";
				if (obj = document.getElementById("tbbtntext_"+btn.id)) {
					obj.className = "opbutton1";
				}
			}
		}
	} else {
		btn.disabled = disable;
	}
	toolbar_button_states[btn.id] = disable;
}
/*>>>*/

var all_toolbar_buttons = new Array();
var stored_toolbar_scripts = new Array();
var toolbar_button_states = new Array();

