//WORKGROUP OBJECT
function WorkGroup( iName )
{
	this.name = iName;
	this.ws = new Array();
	
	this.AddWorkStation = function( iName ){
		this.ws[this.ws.length] = new WorkStation(iName, this.name);
	}
	
	this.RemoveWorkStation = function( iName ){
		var removed = false;
		var replaceStartIndex = 0;
		var x = 0;
		
		// determine if name exists in array.
		for( x = 0; x < this.ws.length; x++ )
		{
			if( this.ws[x].name.toLowerCase() == iName.toLowerCase() )
			{
				replaceStartIndex = x;
				removed = true;
				break;
			}
		}
		
		// move remaining objects up in array.
		if( replaceStartIndex > 0 )
		{
			for( x = replaceStartIndex; x < (this.ws.length - 1); x++ )
				this.ws[x] = this.ws[x + 1];
		}
		
		// decrement arrays length to make sure it's not there anymore.
		this.ws.length--;
		
		return replaced;
	}
	
	this.html = function(){
		var result = "";
		result += '<div id="wkgrp-' + this.name + '" class="workgroup">\n';
		result += '\t<div class="title">\n';
		result += '\t\t<a class="treeToggle" href="javascript: ToggleWorkstationDisplay(\'ws-' + this.name + '\');">+</a>\n';
		result += '\t\t<input type="checkbox" name="workgroup" id="wg-' + this.name + '" value="1" />\n';
		result += '\t\t\t' + this.name + '\n';
		result += '\t</div>\n';
		
		result += '\t<div class="workstations" id="ws-' + this.name + '">\n';
		result += this.wsHtml();
		result += '\t</div>\n';
		result += '</div>\n';
		
		return result;
	}
	
	this.wsHtml = function(){
		var html = '';
		for( var x = 0; x < this.ws.length; x++ )
			html += this.ws[x].html();
		
		return html;
	}
}	// === END WORKGROUP OBJECT ===


// WORKSTATION OBJECT
function WorkStation( iName, iWorkGroup )
{
	this.name = iName;
	this.workGroup = iWorkGroup;
	
	this.html = function(){					
		return '\t\t<div class="workstation"><input type="checkbox" name="workstation" id="wg-' + this.workGroup + '_ws-' + this.name + '" value="1" /> ' + this.name + '</div>\n';
	}
}	// === END WORKSTATION OBJECT ===
