﻿/*--
标题：工具条
设计：王集鹄
博客：http://blog.csdn.net/zswang
日期：2008年11月9日
--*/

if (!Common.scripts["Toolbar"]) {
	loadCss("/Scripts/Toolbar.css?version=2010040401");
	Common.scripts["Toolbar"] = true;
}

function Toolbar(parent) {
	this.parent = typeof parent == "object" ? parent : document.body;
	this.div_toolbar = document.createElement("div");
	this.div_toolbar.className = "Toolbar";
	this.parent.appendChild(this.div_toolbar);
}

Toolbar.prototype.addButton = function(hint, icon, format, click) {
	var result = document.createElement("a");
	result.input = document.createElement("input");
	result.input.type = "button";
	result.className = "a_button";
	result.input.className = "input_button";
	result.title = hint;
	result.appendChild(result.input);
	result.href = "javascript:void(0);";
	if (format == "css")
		result.input.className = "input_button " + icon;
	else result.input.style.backgroundImage = "url(" + icon + ")";
	result.input.onfocus = function() { this.blur(); };
	if (typeof click == "function") result.onclick = click;
	this.div_toolbar.appendChild(result);
	return result;
}

Toolbar.prototype.deleteButton = function(button) {
	if (typeof button != "object") return false;
	button.parentNode.removeChild(button);
	return true;
}

Toolbar.prototype.addSeparator = function() {
	var result = document.createElement("input");
	result.type = "button";
	result.disabled = "true";
	result.className = "input_separator";
	this.div_toolbar.appendChild(result);
	return result;
}

Toolbar.prototype.deleteSeparator = function(separator) {
	if (typeof separator != "object") return false;
	separator.parentNode.removeChild(separator);
	return true;
}

Toolbar.prototype.dispose = function() {
	this.disposed = true;
	for (var i in this) {
		if (this[i].disposed) continue;
		if (typeof this[i].dispose == "function") this[i].dispose();
		if (typeof this[i].parentNode == "object")
			this[i].parentNode.removeChild(this[i]);
		delete this[i];
	}
}