
var _TABCONTROL_PROXY = 'index2.php?option=com_dtab&no_html=1&';
var _TABCONTROL_EDIT_CONTAINER_WIDTH = 600;
var _TABCONTROL_EDIT_CONTAINER_HEIGHT = 400;
var _TABCONTROL_TOOL_UP = '<img src="components/com_dtab/images/move-up.gif">';
var _TABCONTROL_TOOL_DOWN = '<img src="components/com_dtab/images/move-down.gif">';
var _TABCONTROL_TOOL_ADD = '<img src="components/com_dtab/images/add.gif">';
var _TABCONTROL_TOOL_DELETE = '<img src="components/com_dtab/images/delete.gif">';
var _TABCONTROL_EDIT_TOOLS_CLASS = 'tc_edit_tools';

var _tabs = new Object()

$(document).ready(tc_init)

function tc_init() {
	$('div.tab').each(linkTab);
}

function linkTab(object, element) {
	var parser = new RegExp('tab\\[(.*)\\]');
	var match = parser.exec(element.id);
	if (match && match.length > 1) {
		loadTab(element, match[1]);
	}
}

function loadTab(element, tab) {
	element.innerHTML = '<div id="_tab_control_'+tab+'"></div>';
	ajax.get(_TABCONTROL_PROXY + 'task=proxy&id='+tab, 'onTabLoaded', tab);
}
	
function onTabLoaded(content, request) {
	eval(content);
	getTab(request.attachment).fetch();
}

function getTab(id) {
	return _tabs[id];
}

function tfslinks_action(action, id, type) {
	var url = 'index2.php?no_html=1&option=com_tfslinks&no_html=1&brief=1&task='+action+'&id='+id;
	if (type) {
		url += '&type='+type;
	}
	ajax.get(url, 'tfslinks_actionComplete');
}
	
function tfslinks_actionComplete(content, request) {
	if (content != '') {
		alert(content);
	}
}

function TabCollection(id,domId,prefix,current) {
	_tabs[id] = this;

	this.id = id;
	this.domId = domId;
	this.prefix = prefix;
	this.current = current;
	this.pages = new Object();
	this.labels = new Array();
	this.editing = false;
	
	this.addPage = function(pageId, domId, name, caption, order, selectAction, current, total) {
		this.pages[pageId] = new TabPage(this, pageId, domId, name, caption, order, selectAction, current, total);
		this.labels.push(new TabPageLabel(this, pageId, domId, name, caption));
	}
	
	this.getPage = function(pageId) {
		return this.pages[pageId];
	}
	
	this.showPage = function(pageId) {
		for (id in this.pages) {
			var page = this.pages[id];
			document.getElementById(page.domId+'_button').className = this.prefix + 'tc_button_' + ((page.id == pageId) ? 'active' : 'inactive');
			document.getElementById(page.domId).className = this.prefix + 'tc_page_' + ((page.id == pageId) ? 'active' : 'inactive');
		}
		this.setCurrent(pageId);
		
	} 

	this.setCurrent = function(pageId) {
		ajax.get(_TABCONTROL_PROXY+'task=select&id='+this.id+'&tab='+pageId, 'getTab('+this.id+').onSetCurrent', pageId);
	}
	
	this.onSetCurrent = function(content, request) {
	}
	
	this.fetch = function() {
		ajax.get(_TABCONTROL_PROXY+'task=draw&id='+this.id, 'getTab('+this.id+').onPageFetched');
	}
	
	this.onPageFetched = function(content,request) {
		this.draw(content);
		
		/*
		*  We have to initialize the new actions if there are any "thickbox" actions.
		*/
		if (window.tb_init) {
			tb_init('a.thickbox, area.thickbox, input.thickbox');
		}
	} 

	this.getEditContainer = function() {
		var container = document.getElementById('tc-popup-edit-container');
		if (!container) {
			document.body.innerHTML += '<div id="tc-popup-edit-container"></div>';
			container = document.getElementById('tc-popup-edit-container');
		}
		
		container.style.top  	= this.getScrollTop() + (this.getClientHeight() - _TABCONTROL_EDIT_CONTAINER_HEIGHT) / 2 + "px";
		container.style.left 	= this.getScrollLeft() + (this.getClientWidth() - _TABCONTROL_EDIT_CONTAINER_WIDTH) / 2 + "px";
		container.style.width 	= _TABCONTROL_EDIT_CONTAINER_WIDTH+"px";
		container.style.height	= _TABCONTROL_EDIT_CONTAINER_HEIGHT+"px";
		container.className 	= 'tc_edit_container_open';
		return document.getElementById('tc-popup-edit-container');
	}
	
	this.isEditing = function() {
		var container = document.getElementById('tc-popup-edit-container');
		if (container && container.className != 'tc_edit_container_closed') {
			container.className = 'tc_edit_container_flash';
			setTimeout('getTab('+this.id+').unflash()', 150);
			return true;
		}
		return false;
	}
	
	this.unflash = function() {
		var container = document.getElementById('tc-popup-edit-container');
		if (container && container.className != 'tc_edit_container_closed') {
			container.className = 'tc_edit_container_open';
		}
	}
	
	this.hideEditContainer = function() {
		var container = document.getElementById('tc-popup-edit-container');
		if (container) {
			container.className 	= 'tc_edit_container_closed';
			container.style.top  	= "-1px";
			container.style.left 	= "-1px";
			container.style.width 	= "0px";
			container.style.height	= "0px";
		}
	}
	
	this.getClientWidth = function() {
		return this.chooseDimensions(
			window.innerWidth ? window.innerWidth : 0,
			document.documentElement ? document.documentElement.clientWidth : 0,
			document.body ? document.body.clientWidth : 0
		);
	}
	
	this.getClientHeight = function() {
		return this.chooseDimensions(
			window.innerHeight ? window.innerHeight : 0,
			document.documentElement ? document.documentElement.clientHeight : 0,
			document.body ? document.body.clientHeight : 0
		);
	}
	
	this.getScrollLeft = function() {
		return this.chooseDimensions(
			window.pageXOffset ? window.pageXOffset : 0,
			document.documentElement ? document.documentElement.scrollLeft : 0,
			document.body ? document.body.scrollLeft : 0
		);
	}

	this.getScrollTop = function() {
		return this.chooseDimensions(
			window.pageYOffset ? window.pageYOffset : 0,
			document.documentElement ? document.documentElement.scrollTop : 0,
			document.body ? document.body.scrollTop : 0
		);
	}
	
	this.chooseDimensions = function(n_win, n_docel, n_body) {
		var n_result = n_win ? n_win : 0;
		if (n_docel && (!n_result || (n_result > n_docel)))
			n_result = n_docel;
		return n_body && (!n_result || (n_result > n_body)) ? n_body : n_result;
	}
	
	this.edit = function() {
		if (!this.isEditing() && !this.editing) {
			this.editing = true
			ajax.get(_TABCONTROL_PROXY+'task=edit&id='+this.id, 'getTab('+this.id+').onEditFetched')
		}
	}

	this.onEditFetched = function(content,request) {
		this.getEditContainer();
		this.drawEdit(content);
		this.updatePages();
	} 
	
	this.updatePages = function() {
		var container = document.getElementById(this.domId+'_edit_pages');
		while (container.rows.length > 1) {
			container.deleteRow(container.rows.length-1);
		}
		for (var index=0; index < this.labels.length; ++index) {
			var row = container.insertRow(container.rows.length);
			this.labels[index].edit(row, index);
		}
	}
	
	this.pageUp = function(index) {
		if (index > 0) {
			this.capturePages();
			this.swapPages(index-1);
			this.updatePages();
		}
	}

	this.pageDown = function(index) {
		if (index < this.labels.length - 1) {
			this.capturePages();
			this.swapPages(index);
			this.updatePages();
		}
	}

	this.pageAdd = function(index) {
		this.capturePages();
		this.labels.splice(index + 1, 0, new TabPageLabel(this, 0, '', '', ''));
		this.updatePages();
	}

	this.pageDelete = function(index) {
		this.capturePages();
		this.labels.splice(index, 1);
		this.updatePages();
	}
			
	this.swapPages = function(index) {
		var top = this.labels[index];
		this.labels[index] = this.labels[index+1];
		this.labels[index+1] = top;
	}
	
	this.capturePages = function() {
		for (var index=0; index < this.labels.length; ++index) {
			this.labels[index].capture(index);
		}
	}

	this.draw = function(content) {
		var container = document.getElementById('_tab_control_'+this.id);
		container.innerHTML = content;
	}
	
	this.drawEdit = function(content) {
		var container = this.getEditContainer();
		container.innerHTML = content;
	}
	
	this.save = function() {
		if (this.editing) {
			this.capturePages();
			
			var form = document.getElementById(this.domId+'_edit');
			var values = new Array();
			
			for (var i=0; i < form.elements.length; ++i) {
				if (form.elements[i].name) {
					var value = encodeURIComponent(form.elements[i].name);
					value += '=';
					value += encodeURIComponent(form.elements[i].value);
					values.push(value);
				}
			}    
			ajax.post(_TABCONTROL_PROXY + 'task=save&id=' + this.id, values.join('&'), 'getTab(' + this.id + ').onSaved');
			this.editing = false;
		}
	}
	
	this.onSaved = function(content, request) {
		if (content == '') {
			this.hideEditContainer();
			this.refresh();
		}
		else {
			this.drawEdit(content);
		}
	}
	
	this.refresh = function() {
		ajax.get(_TABCONTROL_PROXY + 'task=proxy&id=' + this.id, 'getTab(' + this.id + ').onRefresh');
	}
	
	this.onRefresh = function(content, request) {
		eval(content);
		getTab(this.id).fetch();
	}
	
	this.cancel = function() {
		this.editing = false;
		this.hideEditContainer();
		this.fetch();
	}
}

function TabPageLabel(owner, id, domId, name, caption) {
	this.owner = owner;
	this.id = id;
	this.domId = domId;
	this.name = name;
	this.caption = caption;
	
	this.clone = function() {
		return new TabColumn(this.owner, this.name, this.caption, this.column_name, this.width, this.format_type, this.format_specifier, this.action, this.action_label);
	}
	
	this.edit = function(row, index) {
		var cell = row.insertCell(0);
		cell.className = _TABCONTROL_EDIT_TOOLS_CLASS;
		cell.innerHTML = '<a href="javascript:getTab('+this.owner.id+').pageUp('+index+')" title="Move Up">'+_TABCONTROL_TOOL_UP+'</a><a href="javascript:getTab('+this.owner.id+').pageDown('+index+')" title="Move Down">'+_TABCONTROL_TOOL_DOWN+'</a><a href="javascript:getTab('+this.owner.id+').pageAdd('+index+')" title="Add Page">'+_TABCONTROL_TOOL_ADD+'</a><a href="javascript:getTab('+this.owner.id+').pageDelete('+index+')" title="Delete Page">'+_TABCONTROL_TOOL_DELETE+'</a>';

		cell = row.insertCell(1);
		cell.innerHTML = '<input type="hidden" name="page['+index+'][id]" value="'+this.id+'"><input type="text" id="page['+index+'][name]" name="page['+index+'][name]" value="'+this.name+'">';

		cell = row.insertCell(2);
		cell.innerHTML = '<input type="text" id="page['+index+'][caption]" name="page['+index+'][caption]" value="'+this.caption+'">';
	}
	
	this.capture = function(index) {
		this.name = document.getElementById('page['+index+'][name]').value
		this.caption = document.getElementById('page['+index+'][caption]').value
	}
	
	this.empty = function() {
		return (this.name == '') && (this.caption == '') && (this.column_name == '') && (this.width == '') && (this.format_type == '') && (this.format_specifier == '') && (this.action == '') && (this.action_label == '')
	}	
}

function TabPage(owner, id, domId, name, caption, order, selectAction, current, total) {
	this.owner = owner;
	this.id = id;
	this.domId = domId;
	this.name = name;
	this.caption = caption;
	this.order = order;
	this.current = current;
	this.pages = total;
	this.selectAction = selectAction;
//replace(/&amp;/g, '&');
	this.editing = false;
	this.columns = new Array();
	this.bindings = new Array();
	this.configuredColumns = new Array();
	this.queryColumns = new Array();
	this.paging = false;
	this.sortMenuOpened = false;

	this.setPageInfo = function(current,pages) {
		this.current = Number(current);
		this.pages = Number(pages);
	}
		
	this.next = function() {
		if (!this.paging && this.current < this.pages) {
			this.paging = true;
			this.current++;
			this.fetch();
		}
	}

	this.previous = function() {
		if (!this.paging && this.current > 1) {
			this.paging = true;
			this.current--;
			this.fetch();
		}
	}
	
	this.fetch = function() {
		ajax.get(_TABCONTROL_PROXY + 'task=draw&id=' + owner.id + '&tab=' + this.id + '&page=' + this.current, 'getTab(' + this.owner.id + ').getPage(' + this.id + ').onPageFetched');
	}
	
	this.onPageFetched = function(content,request) {
		this.draw(content);
		
		var max = document.getElementById(this.domId+'-max-pages');
		var current = document.getElementById(this.domId+'-current-page');
		if (max && current) {
			this.setPageInfo(current.value, max.value);
		}
		this.paging = false;

		/*
		*  We have to initialize the new actions if there are any "thickbox" actions.
		*/
		if (window.tb_init) {
			tb_init('a.thickbox, area.thickbox, input.thickbox');
		}
	} 

	this.getXML = function(callback) {
		ajax.get(_TABCONTROL_PROXY + 'task=xml&id=' + owner.id + '&tab=' + this.id + '&page=' + this.current, 'getTab(' + this.owner.id + ').getPage(' + this.id + ').onXML', callback);
	}
	
	this.onXML = function(content,request) {
		try {
			if (request.attachment) {
				if (typeof(request.attachment) == 'string') {
					eval(request.attachment+'('+content+')');
				}
			}
		}
		catch (error) {
			alert(error.description);
		}
	} 
	
	this.draw = function(content) {
		var container = document.getElementById(this.domId+'_content');
		container.innerHTML = content;
	}
	
	this.drawEdit = function(content) {
		var container = this.owner.getEditContainer();
		container.innerHTML = content;
	}
	
	this.addColumn = function(name, caption, column_name, width, format_type, format_specifier, action, action_label, sort_descending) {
		this.configuredColumns.push(new TabColumn(this, name, caption, column_name, width, format_type, format_specifier, action, action_label, sort_descending));
	}
	
	this.addBinding = function(name, binding) {
		this.bindings.push(new TabPageBinding(this, name, binding));
	}
	
	this.edit = function() {
		if (!this.owner.isEditing()) {
			this.owner.showPage(this.id);
			if (!this.editing) {
				this.editing = true;
				ajax.get(_TABCONTROL_PROXY + 'task=edit&id=' + owner.id + '&tab=' + this.id, 'getTab(' + this.owner.id + ').getPage(' + this.id + ').onEditFetched');
			}
		}
	}

	this.onEditFetched = function(content,request) {
		this.drawEdit(content);
		this.columns = new Array();
		for (var index=0; index < this.configuredColumns.length; ++index) {
			this.columns.push(this.configuredColumns[index].clone());
		}
		this.updateColumns();
		this.updateBindings();
		var query = document.getElementById(this.domId+'_edit_query');
		if (query) {
			this.onQueryChanged(query);
		}
	} 

	this.updateColumns = function() {
		var container = document.getElementById(this.domId+'_edit_columns');
		while (container.rows.length > 1) {
			container.deleteRow(container.rows.length-1);
		}
		
		if (this.columns) {
			for (var index=0; index < this.columns.length; index=index+1) {
				var row = container.insertRow(container.rows.length);
				this.columns[index].edit(row, index);
			}
		}
	}

	this.columnUp = function(index) {
		if (index > 0) {
			this.captureColumns();
			this.swapColumns(index-1);
			this.updateColumns();
		}
	}

	this.columnDown = function(index) {
		if (index < this.columns.length - 1) {
			this.captureColumns();
			this.swapColumns(index);
			this.updateColumns();
		}
	}

	this.columnAdd = function(index) {
		this.captureColumns();
		this.columns.splice(index + 1, 0, new TabColumn(this, '', '', '', '', '', '', '', ''));
		this.updateColumns();
	}

	this.columnDelete = function(index) {
		this.captureColumns();
		this.columns.splice(index, 1);
		this.updateColumns();
	}
			
	this.swapColumns = function(index) {
		var top = this.columns[index];
		this.columns[index] = this.columns[index+1];
		this.columns[index+1] = top;
	}

	this.captureColumns = function() {
		for (var index=0; index < this.columns.length; ++index) {
			this.columns[index].capture(index);
		}
	}
			
	this.save = function() {
		if (this.editing) {
			this.captureColumns();
			
			var form = document.getElementById(this.domId+'_edit');
			var values = new Array();
			
			for (var i=0; i < form.elements.length; ++i) {
				if (form.elements[i].name) {
					var value = encodeURIComponent(form.elements[i].name);
					value += '=';
					if (form.elements[i].type && form.elements[i].type == 'checkbox') {
						value += (form.elements[i].checked ? 1 : 0);
					}
					else {
						value += encodeURIComponent(form.elements[i].value);
					}
					values.push(value);
				}
			}    
			ajax.post(_TABCONTROL_PROXY + 'task=save&id=' + owner.id + '&tab=' + this.id, values.join('&'), 'getTab(' + this.owner.id + ').getPage(' + this.id + ').onPageSaved');
			this.editing = false;
		}
	}

	this.onPageSaved = function(content,request) {
		if (content == '') {
			this.owner.hideEditContainer();
			this.owner.refresh();
		}
		else {
			this.drawEdit(content);
		}
		this.columns = new Array();
		
		/*
		*  We have to initialize the new actions if there are any "thickbox" actions.
		*/
		if (window.tb_init) {
			tb_init('a.thickbox, area.thickbox, input.thickbox');
		}
	} 
	
	this.cancel = function() {
		this.editing = false;
		this.owner.hideEditContainer();
		this.fetch();
	}

	this.onQueryChanged = function(control) {
		ajax.post(_TABCONTROL_PROXY + 'task=columns&id='+this.owner.id+'&tab='+this.id, 'query='+encodeURIComponent(control.value), 'getTab('+this.owner.id+').getPage('+this.id+').onQueryValidated');
	}
	
	this.onQueryValidated = function(content, request) {
		if (content.search(/^columns:/i) == -1) {
			this.setEditMessage(content);
		}
		else {
			this.setEditMessage('');
			this.queryColumns = content.substring(8).split(',');
			this.updateColumns();						
		}
	}
	
	this.setEditMessage = function(message) {
		var container = document.getElementById(this.domId+'_edit_message');
		if (container) {
			container.innerHTML = message;
		}
		else {
			alert(message);
		}
	}
	
	this.getColumnSelect = function(row,value) {
		var html = '<select id="column['+this.domId+']['+row+'][column_name]" name="column['+this.domId+']['+row+'][column_name]">';
		for (var index=0;index < this.queryColumns.length;++index) {
			html += '<option value="'+this.queryColumns[index]+'"';
			if (value == this.queryColumns[index]) {
				html += ' selected';
			}
			html += '>'+this.queryColumns[index]; 
		}
		html += '</select>';
		return html;
	}
	
	this.selectItems = function() {
		var selected = new Array();
		var count = 0;
		var form = document.getElementById(this.domId+'_form');
		if (form) {
			var parser = new RegExp('_tcps\\['+this.domId+'\\]\\[(.*)\\]');
			for (var index=0;index < form.elements.length;++index) {
				var match = parser.exec(form.elements[index].name);
				if (match) {
					if (form.elements[index].checked) {
						selected.push('id['+(count++)+']='+match[1]);
					}
				} 
			}
		}
		
		/*
                * ELS 11/20/2008: Hotfix to handle expansion of select action by some mambots that replace the & with the html meta value.  
		*/
                var action = this.selectAction.replace(/&amp;/g, "&");
                ajax.post(action, selected.join('&'), 'getTab('+this.owner.id+').getPage('+this.id+').onSelectionComplete');
	}
	
	this.onSelectionComplete = function(content, request) {
		if (content != '') {
			alert(content);
		}
		var form = document.getElementById(this.domId+'_form');
		if (form) {
			var parser = new RegExp('_tcps\\['+this.domId+'\\]\\[(.*)\\]');
			for (var index=0;index < form.elements.length;++index) {
				var match = parser.exec(form.elements[index].name);
				if (match) {
					form.elements[index].checked = false;
				} 
			}
		}
	}
	
	this.bindingAdd = function(index) {
		this.captureBindings();
		this.bindings.splice(index + 1, 0, new TabPageBinding(this, '', ''));
		this.updateBindings();
	}

	this.bindingDelete = function(index) {
		this.captureBindings();
		this.bindings.splice(index, 1);
		this.updateBindings();
	}

	this.captureBindings = function() {
		for (var index=0; index < this.bindings.length; ++index) {
			this.bindings[index].capture(index);
		}
	}

	this.updateBindings = function() {
		var container = document.getElementById(this.domId+'_edit_bindings');
		while (container.rows.length > 1) {
			container.deleteRow(container.rows.length-1);
		}
		
		if (this.bindings) {
			for (var index=0; index < this.bindings.length; index=index+1) {
				var row = container.insertRow(container.rows.length);
				this.bindings[index].edit(row, index);
			}
		}
	}
	
	this.sort = function(column) {
		ajax.get(_TABCONTROL_PROXY + 'task=draw&id=' + owner.id + '&tab=' + this.id + '&page=' + this.current + '&so-' + this.id + '=' + column, 'getTab(' + this.owner.id + ').getPage(' + this.id + ').onPageFetched');
	}
	
	this.onSortMenu = function() {
		var menu = document.getElementById(this.domId+'_sort_menu');
		if (menu) {
			this.sortMenuOpened = !this.sortMenuOpened;
			menu.style.display = this.sortMenuOpened ? 'block' : 'none';
		}
	}
	
	this.onSortMenuItemFocused = function(item) {
//		var item = document.getElementById(id);
		if (item) {
			item.className = 'tc_sort_menu_item_focused';
		}
	}

	this.onSortMenuItemBlurred = function(item) {
//		var item = document.getElementById(id);
		if (item) {
			item.className = 'tc_sort_menu_item';
		}
	}
}

function TabColumn(owner, name, caption, column_name, width, format_type, format_specifier, action, action_label, sort_descending) {
	this.owner = owner;
	this.name = name;
	this.caption = caption;
	this.column_name = column_name;
	this.width = width;
	this.format_type = format_type;
	this.format_specifier = format_specifier;
	this.action = action;
	this.action_label = action_label;
	this.sort_descending = sort_descending;

	this.clone = function() {
		return new TabColumn(this.owner, this.name, this.caption, this.column_name, this.width, this.format_type, this.format_specifier, this.action, this.action_label, this.sort_descending);
	}
	
	this.edit = function(row, index) {
		var column = 0;
		var cell = row.insertCell(column++);
		cell.className = _TABCONTROL_EDIT_TOOLS_CLASS;
		cell.innerHTML = '<a href="javascript:getTab('+this.owner.owner.id+').getPage('+this.owner.id+').columnUp('+index+')" title="Move Up">'+_TABCONTROL_TOOL_UP+'</a><a href="javascript:getTab('+this.owner.owner.id+').getPage('+this.owner.id+').columnDown('+index+')" title="Move Down">'+_TABCONTROL_TOOL_DOWN+'</a><a href="javascript:getTab('+this.owner.owner.id+').getPage('+this.owner.id+').columnAdd('+index+')" title="Add Column">'+_TABCONTROL_TOOL_ADD+'</a><a href="javascript:getTab('+this.owner.owner.id+').getPage('+this.owner.id+').columnDelete('+index+')" title="Delete Column">'+_TABCONTROL_TOOL_DELETE+'</a>';
		
		cell = row.insertCell(column++);
		cell.innerHTML = '<input type="text" id="column['+this.owner.domId+']['+index+'][name]" name="column['+this.owner.domId+']['+index+'][name]" value="'+this.name+'">';
		
		cell = row.insertCell(column++);
		cell.innerHTML = '<input type="text" id="column['+this.owner.domId+']['+index+'][caption]" name="column['+this.owner.domId+']['+index+'][caption]" value="'+this.caption+'">';

		cell = row.insertCell(column++);
		cell.innerHTML = this.owner.getColumnSelect(index, this.column_name);

		cell = row.insertCell(column++);
		cell.innerHTML = '<input type="checkbox" id="column['+this.owner.domId+']['+index+'][sort_descending]" name="column['+this.owner.domId+']['+index+'][sort_descending]"'+(this.sort_descending?' CHECKED':'')+'>'

		cell = row.insertCell(column++);
		cell.innerHTML = '<input type="text" id="column['+this.owner.domId+']['+index+'][width]" name="column['+this.owner.domId+']['+index+'][width]" value="'+this.width+'">'

		cell = row.insertCell(column++);
 		cell.innerHTML = '<input type="text" id="column['+this.owner.domId+']['+index+'][format_type]" name="column['+this.owner.domId+']['+index+'][format_type]" value="'+this.format_type+'">'

		cell = row.insertCell(column++);
		cell.innerHTML = '<input type="text" id="column['+this.owner.domId+']['+index+'][format_specifier]" name="column['+this.owner.domId+']['+index+'][format_specifier]" value="'+this.format_specifier+'">'

		cell = row.insertCell(column++);
		cell.innerHTML = '<input type="text" id="column['+this.owner.domId+']['+index+'][action]" name="column['+this.owner.domId+']['+index+'][action]" value="'+this.action+'">'

		cell = row.insertCell(column++);
		cell.innerHTML = '<input type="text" id="column['+this.owner.domId+']['+index+'][action_label]" name="column['+this.owner.domId+']['+index+'][action_label]" value="'+this.action_label+'">'
	}
	
	this.capture = function(index) {
		this.name = document.getElementById('column['+this.owner.domId+']['+index+'][name]').value;
		this.caption = document.getElementById('column['+this.owner.domId+']['+index+'][caption]').value;
		this.width = document.getElementById('column['+this.owner.domId+']['+index+'][width]').value;
 		this.format_type = document.getElementById('column['+this.owner.domId+']['+index+'][format_type]').value;
		this.format_specifier = document.getElementById('column['+this.owner.domId+']['+index+'][format_specifier]').value;
		this.action = document.getElementById('column['+this.owner.domId+']['+index+'][action]').value;
		this.action_label = document.getElementById('column['+this.owner.domId+']['+index+'][action_label]').value;
		this.sort_descending = document.getElementById('column['+this.owner.domId+']['+index+'][sort_descending]').checked?1:0;

		var select = document.getElementById('column['+this.owner.domId+']['+index+'][column_name]');
		if (select.selectedIndex != -1 ) {
			this.column_name = select.options[select.selectedIndex].value;
		}
		else {
			this.column_name = '';
		}
	}
	
	this.empty = function() {
		return (this.name == '') || (this.caption == '') || (this.column_name == '');
	}	
}

function TabPageBinding(owner, name, binding) {
	this.owner = owner;
	this.name = name;
	this.binding = binding;

	this.clone = function() {
		return new TabPageBinding(this.owner, this.name, this.binding);
	}
	
	this.edit = function(row, index) {
		var cell = row.insertCell(0);
		cell.className = _TABCONTROL_EDIT_TOOLS_CLASS;
		cell.innerHTML = '<a href="javascript:getTab('+this.owner.owner.id+').getPage('+this.owner.id+').bindingAdd('+index+')" title="Add Binding">'+_TABCONTROL_TOOL_ADD+'</a><a href="javascript:getTab('+this.owner.owner.id+').getPage('+this.owner.id+').bindingDelete('+index+')" title="Delete Binding">'+_TABCONTROL_TOOL_DELETE+'</a>';
		
		cell = row.insertCell(1);
		cell.innerHTML = '<input type="text" id="binding['+this.owner.domId+']['+index+'][name]" name="binding['+this.owner.domId+']['+index+'][name]" value="'+this.name+'">';
		
		cell = row.insertCell(2);
		cell.innerHTML = '<input type="text" id="binding['+this.owner.domId+']['+index+'][binding]" name="binding['+this.owner.domId+']['+index+'][binding]" value="'+this.binding+'">';
	}
	
	this.capture = function(index) {
		this.name = document.getElementById('binding['+this.owner.domId+']['+index+'][name]').value;
		this.binding = document.getElementById('binding['+this.owner.domId+']['+index+'][binding]').value;
	}
	
	this.empty = function() {
		return (this.binding == '');
	}	
}
 

