// JavaScript Document

var ToolbarIcon = {};

ToolbarIcon.save = "save";
ToolbarIcon.cancel = "cancel";
ToolbarIcon.close = "close";
ToolbarIcon.list = "list";
ToolbarIcon.newitem = "new";
ToolbarIcon.images = "images";
ToolbarIcon.prev= "prev";
ToolbarIcon.next = "next";
ToolbarIcon.apply = "apply";
ToolbarIcon.preview = "preview";
ToolbarIcon.folder = "folder";

var ToolbarItem = {};

 

ToolbarItem = function(toolbarid, icon, handle, title) {
	
	var tb = Utils.getElementById(toolbarid);
	
	var newdiv = document.createElement('div');
	newdiv.setAttribute('class','toolbaritem toolbaritem_' + icon);
	newdiv.setAttribute('title',title);
	

	
	var newdiv2 = document.createElement('div');
	var text = document.createTextNode(title);
	newdiv2.appendChild(text);
	
	newdiv.appendChild(newdiv2);
	
	tb.appendChild(newdiv);
 
	Utils.addEventListener(newdiv, "click", handle);
	
};


var Toolbar = {};

Toolbar = function(id) {
	this.items = Array();
	
	this.id = id;
	
};

 

Toolbar.prototype.addSubmit = function(icon, name, title, form) {
	
	var handle = function() {
		var formhandle = Utils.getElementById(form);
		
		switch (name)  {
			// workaround, falls es doppelte objekte gibt			
			case 'btntask_Apply' : 	 Utils.Form.addInput(form, 'task', 'Apply'); break;
			case 'btntask_Save' : 	 Utils.Form.addInput(form, 'task', 'Save'); break;
			default : Utils.Form.addInput(form, name, name); break;
		}
		
		
		Control.submit(form);
	};
	
	var item = new ToolbarItem(this.id, icon, handle, title);
	this.items.push(item);
};

Toolbar.prototype.addJS = function(icon, handle, title) {
	var item = new ToolbarItem(this.id, icon, handle, title);
	this.items.push(item);
	
};

Toolbar.prototype.addLink = function(icon, url, title, popup) {
	
	var handle = function() {
		
		if (popup) {
			window.open(url, "popup");	
		} else {
			document.location.href=url;
		}
	};
		
	var item = new ToolbarItem(this.id, icon, handle, title);
	this.items.push(item);
};
