/**
 * Javascript SwatTableViewCheckboxColumn component
 *
 * @param id string Id of the matching {@link SwatTableViewCheckboxColumn}.
 * @param table SwatTableView A reference to the javascript object that
 * 		  represents the {@link SwatTableView}
 **/
function SwatTableViewCheckboxColumn(id, table) {
	var self = this;

	this.id = id;
	this.table = table;
	this.check_all = null; //a reference to a checkall widget (if it exists - set by the SwatCheckAll widget)
	this.check_list = new Array();

	//get all checkboxes with name = id + [] and that are contained in the
	//correct table view. Note: getElementsByName doesn't work from a node
	//element.
	var table_node = document.getElementById(this.table.id);
	var items = table_node.getElementsByTagName('input');
	for (i = 0; i < items.length; i++)
		if (items[i].name == id + '[]')
			this.check_list[i] = items[i]; 


	var is_ie = (document.addEventListener) ? false : true;

	for (i = 0; i < this.check_list.length; i++) {
		this.highlightRow(this.check_list[i]);

		if (is_ie)
			this.check_list[i].attachEvent("onclick", eventHandler);
		else 
			this.check_list[i].addEventListener("change", eventHandler, false);
	}

	function eventHandler(event) {
		var node = (is_ie) ? event.srcElement : event.target;
		self.highlightRow(node);

		self.checkAllInit();
	}
}

SwatTableViewCheckboxColumn.prototype.checkAllInit = function() {
	if (this.check_all == null)
		return;

	var count = 0;
	for (i = 0; i < this.check_list.length; i++)
		if (this.check_list[i].checked)
			count++;
		else if (count > 0)
			break; //can't possibly be all checked or none checked

	this.check_all.setState(count == this.check_list.length);
}

SwatTableViewCheckboxColumn.prototype.checkAll = function(checked) {
	for (i = 0; i < this.check_list.length; i++) {
		this.check_list[i].checked = checked;
		this.highlightRow(this.check_list[i]);
	}
}

SwatTableViewCheckboxColumn.prototype.highlightRow = function(node) {
	if (this.table)
		this.table.highlightRow(node, node.checked);
}

@@ -66,72 +66,62 @@
 ram 
-id 
 string 
-I
+i
 d 
-of 
 the 
-matching %7B@link SwatTableViewC
+unique identifier of the c
 heckbox
-C
+ c
 olumn
-%7D
 .%0A *
@@ -128,22 +128,16 @@
  @param 
-table 
 SwatTabl
@@ -146,22 +146,13 @@
 iew 
-A reference to
+table
  the
@@ -178,15 +178,8 @@
 that
-%0A * %09%09 
  rep
@@ -193,33 +193,53 @@
  the
- %7B@link SwatT
+%0A *                             t
 able
-View%7D
+-view.
 %0A 
-*
 */%0Af
@@ -284,17 +284,17 @@
 , table)
- 
+%0A
 %7B%0A%09var s
@@ -346,34 +346,13 @@
 le;%0A
+%0A
 %09
-this.check_all = null; 
 //
+ 
 a re
@@ -428,16 +428,40 @@
 widget)%0A
+%09this.check_all = null;%0A
 %09this.ch
@@ -491,10 +491,15 @@
 %0A%0A%09/
-/g
+*%0A%09 * G
 et a
@@ -563,18 +563,19 @@
 in the%0A%09
-//
+ * 
 correct 
@@ -579,17 +579,17 @@
 ct table
- 
+-
 view. No
@@ -613,15 +613,18 @@
 Name
+()
  does
-n'
+ no
 t wo
@@ -639,18 +639,19 @@
 a node%0A%09
-//
+ * 
 element.
@@ -651,16 +651,21 @@
 lement.%0A
+%09 */%0A
 %09var tab
@@ -800,24 +800,26 @@
 length; i++)
+ %7B
 %0A%09%09if (items
@@ -840,16 +840,18 @@
  + '%5B%5D')
+ %7B
 %0A%09%09%09this
@@ -865,22 +865,22 @@
 list
-%5Bi%5D = 
+.push(
 items%5Bi%5D
 ; %0A%0A
@@ -879,119 +879,12 @@
 s%5Bi%5D
-; %0A%0A%0A%09var is_ie = (document.addEventListener) ? false : true;%0A%0A%09for (i = 0; i %3C this.check_list.length; i++) %7B%0A
+);%0A%09
 %09%09th
@@ -895,39 +895,29 @@
 ighlightRow(
-this.check_list
+items
 %5Bi%5D);%0A%0A%09%09if 
@@ -913,16 +913,17 @@
 i%5D);%0A%0A%09%09
+%09
 if (is_i
@@ -924,39 +924,30 @@
  (is_ie)%0A%09%09%09
-this.check_list
+%09items
 %5Bi%5D.attachEv
@@ -974,24 +974,25 @@
 Handler);%0A%09%09
+%09
 else %0A%09%09%09thi
@@ -988,31 +988,22 @@
 lse %0A%09%09%09
-this.check_list
+%09items
 %5Bi%5D.addE
@@ -1048,17 +1048,79 @@
 alse);%0A%09
-%7D
+%09%7D%0A%09%7D%0A%0A%09var is_ie = (document.addEventListener) ? false : true;
 %0A%0A%09funct
@@ -1142,17 +1142,18 @@
 r(event)
- 
+%0A%09
 %7B%0A%09%09var 
@@ -1322,17 +1322,17 @@
 nction()
- 
+%0A
 %7B%0A%09if (t
@@ -1682,17 +1682,17 @@
 checked)
- 
+%0A
 %7B%0A%09for (
@@ -1887,17 +1887,17 @@
 on(node)
- 
+%0A
 %7B%0A%09if (t

Make this better. - Fix documentation and brace style. - Use array.push() instead of adding with indexes. I can't believe this ever worked. - Put initialization loop stuff inside the list finding loop. This is a bit more efficient.