
  /////////////////////////////////////////////////////
  //                                                 //
  //          C-NOOFS Forecast Viewer v0.6           //
  //               Web User Interface                //
  //                                                 //
  /////////////////////////////////////////////////////

/**
 * Constructor to create a group of checkboxes
 * @param name Name of this group
 * @param options Array of options to present
 * @param labels Array of labels to assign each option
 */
CheckboxGroup = function(name, options, labels)
{
 	this._boxes = new Object();
	this.container = document.createElement("div");
	this.id = "CBG_" + name;
	
		for ( cbkey in options )
		{
			var Option = options[cbkey];
						
				var Box = document.createElement("input");
				Box.type = "checkbox";
				Box.name = name + "_" + Option;
				Box.value = Option;
			
			this.container.appendChild(Box);
			this._boxes[Option] = Box;
			
				var Span = document.createElement("span");
				Span.innerHTML = "&nbsp;" + labels[Option] + "&nbsp;&nbsp;&nbsp;";
			this.container.appendChild(Span);
		}
}

/**
 * Associative array of checkboxes managed here
 * @type Array of Checkboxes
 */
CheckboxGroup.prototype._boxes;

/**
 * Stores the HTMLDivElement container for this group
 * @return HTMLDivElement
 */
CheckboxGroup.prototype.container;

/**
 * Returns the HTMLDivElement container managed by this group
 * @return HTMLDivElement
 */
CheckboxGroup.prototype.getContainer = function()
{
	return this.container;
}

/**
 * Return a list of selected boxes
 */
CheckboxGroup.prototype.getSelected = function()
{
 	var selVals = []
 	var box;
 	
	for ( box in this._boxes )
	{
		if ( this._boxes[box].checked )
		{
			selVals.push(this._boxes[box].value);
		}
	}
	return selVals;
}


/**
 * Set the handler to callback when the user changes an input
 * @param callback Callback function to call on change of input
 */
CheckboxGroup.prototype.setChangeHandler = function(callback)
{
 	var box;
 	
	for ( box in this._boxes )
	{
		var tmp = new YAHOO.util.Element(this._boxes[box]);
		tmp.on("click", callback);
	}
}

