
/*----------------------------------------------------------------------------\
|                            Dynamic Table 1.12                               |
|-----------------------------------------------------------------------------|
|                         Created by Erik Arvidsson                           |
|                  (http://webfx.eae.net/contact.html#erik)                   |
|                      For WebFX (http://webfx.eae.net/)                      |
|-----------------------------------------------------------------------------|
| A DOM 1 based script that allows an ordinary HTML table to be sortable.     |
|-----------------------------------------------------------------------------|
|                  Copyright (c) 1998 - 2004 Erik Arvidsson                   |
|-----------------------------------------------------------------------------|
| This software is provided "as is", without warranty of any kind, express or |
| implied, including  but not limited  to the warranties of  merchantability, |
| fitness for a particular purpose and noninfringement. In no event shall the |
| authors or  copyright  holders be  liable for any claim,  damages or  other |
| liability, whether  in an  action of  contract, tort  or otherwise, arising |
| from,  out of  or in  connection with  the software or  the  use  or  other |
| dealings in the software.                                                   |
| - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - |
| This  software is  available under the  three different licenses  mentioned |
| below.  To use this software you must chose, and qualify, for one of those. |
| - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - |
| The WebFX Non-Commercial License          http://webfx.eae.net/license.html |
| Permits  anyone the right to use the  software in a  non-commercial context |
| free of charge.                                                             |
| - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - |
| The WebFX Commercial license           http://webfx.eae.net/commercial.html |
| Permits the  license holder the right to use  the software in a  commercial |
| context. Such license must be specifically obtained, however it's valid for |
| any number of  implementations of the licensed software.                    |
| - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - |
| GPL - The GNU General Public License    http://www.gnu.org/licenses/gpl.txt |
| Permits anyone the right to use and modify the software without limitations |
| as long as proper  credits are given  and the original  and modified source |
| code are included. Requires  that the final product, software derivate from |
| the original  source or any  software  utilizing a GPL  component, such  as |
| this, is also licensed under the GPL license.                               |
|-----------------------------------------------------------------------------|
| 2003-01-10 | First version                                                  |
| 2003-01-19 | Minor changes to the date parsing                              |
| 2003-01-28 | JScript 5.0 fixes (no support for 'in' operator)               |
| 2003-02-01 | Sloppy typo like error fixed in getInnerText                   |
| 2003-07-04 | Added workaround for IE cellIndex bug.                         |
| 2003-11-09 | The bDescending argument to sort was not correctly working     |
|            | Using onclick DOM0 event if no support for addEventListener    |
|            | or attachEvent                                                 |
| 2004-01-13 | Adding addSortType and removeSortType which makes it a lot     |
|            | easier to add new, custom sort types.                          |
| 2004-01-27 | Switch to use descending = false as the default sort order.    |
|            | Change defaultSortOrder to suit your needs.                   |
| 2004-03-14 | Improved sort type None look and feel a bit                    |
| 2004-08-26 | Made the handling of tBody and tHead more flexible. Now you   |
|            | can use another tHead or no tHead, and you can chose some      |
|            | other tBody.                                                  |
| 2004-02-18 | Added detection of an empty tBody element that is inserted    |
|            | by IE when a table is dynamically created. Added filtering     |
|            | functionality. dTb.                                            |
|-----------------------------------------------------------------------------|
| Created 2003-01-10 | All changes are in the log above. | Updated 2005-02-18 |
\----------------------------------------------------------------------------*/


// Does removeBeforeSort matter anymore?





SortableTable.gecko = navigator.product == "Gecko";
SortableTable.msie = /msie/i.test(navigator.userAgent);
// Mozilla is faster when doing the DOM manipulations on
// an orphaned element. MSIE is not
SortableTable.removeBeforeSort = SortableTable.gecko;
// default sort order. true -> descending, false -> ascending

SortableTable.prototype.defaultSortOrder = false;
// shared between all instances. This is intentional to allow external files
// to modify the prototype
SortableTable.prototype._sortTypeInfo = {};
SortableTable.prototype._filterTypeInfo = {};

function SortableTable(oTable, oSortTypes, oFilterForm) {	
	this.sortTypes = oSortTypes || [];
	this.sortColumn = null;
	this.sortOrder = null;
	var oThis = this;
	if (oTable) {
		this.setTable(oTable);
	}		
	if (oFilterForm) {
		this.setFilterForm(oFilterForm);
	}	
	this.setSortTypes(oSortTypes);
	// only IE needs this
	var win = document.defaultView || document.parentWindow;
	this._onunload = function () {
		oThis.destroy();
	};
	if (win && typeof win.attachEvent != "undefined") {
		win.attachEvent("onunload", this._onunload);
	}
}


SortableTable.prototype.sort = function (sortColumn, sortOrder, sortType) {
// only sortColumn is required
// sortOrder is a boolean value indicating either column ascension or descension
// if sortOrder is null the columns previous sortOrder value is taken into account
// if sortType is null the sort type is found from the sortTypes array
// ToDo! for efficiency the sort function should only sort the unfiltered rows

	if (sortType === null || "undefined") {
		sortType = this.getSortType(sortColumn);
	}
	if (this.sortedColumn == sortColumn) {
		this.sortOrder = !this.sortOrder;		
		this.sortCache.reverse();
		this.sortedColumn = sortColumn;
	}	
	else {
		this.sortOrder = this.defaultSortOrder;
		var sortFunction = this.getSortFunction(sortType);
		if (this.sortCache) {
			this.destroyCache(this.sortCache);
		}
		this.sortCache = this.getCache(sortType, sortColumn);
		this.sortCache.sort(sortFunction);
		this.sortedColumn = sortColumn;
	}	
	this.onSort();
}


SortableTable.prototype.onSort = function(){
	/* Function called after the table is sorted */
	this.buildSortedTable();
	this.colorTableRows(this.sortCache);
}


SortableTable.prototype.colorTableRows = function(cache) {
	if (cache) {
		l = cache.length;
		displayedRows = 0;
		for (var i = 0; i < l; i++) {
			if (cache[i].element.style.display === "") {
				displayedRows += 1;			
				cache[i].element.className = "";
				cache[i].element.className = displayedRows % 2 ? "odd" : "even";
			}
		}
	}
	else {
		var rows = this.tBody.rows;	
		var l = rows.length;
		for (var i = 0; i < l; i++) {
			rows[i].className = i % 2 ? "odd" : "even";
		}
	}
}

	
SortableTable.prototype.buildSortedTable = function () {
	/* Build a DOM table object from a sort cache*/
	if (SortableTable.removeBeforeSort) {
		var nextSibling = this.tBody.nextSibling;
		var parentNode = this.tBody.parentNode;
		parentNode.removeChild(this.tBody);
	}
	var l = this.sortCache.length;
	for (var i = 0; i < l; i++) {
		this.tBody.appendChild(this.sortCache[i].element);
	}	
	if (SortableTable.removeBeforeSort) {
		parentNode.insertBefore(this.tBody, nextSibling);
	}	
	this.updateHeaderArrows();	
}


SortableTable.prototype.setTable = function (oTable) {
	if (this.tHead) {
		this.uninitHeader();
	}
	this.element = oTable;
	this.setTHead(oTable.tHead);
	// if more than one tBody exists the table was dynamically created by IE
	// use the second tbody as the first is blank
	// ToDo! should add dynamic table building functionality here
	if (oTable.tBodies.length == 2 && !SortableTable.removeBeforeSort) {
		this.setTBody(oTable.tBodies[1]);
	}
	else {
		this.setTBody(oTable.tBodies[0]);
	}
	l = this.tBody.rows.length
}


SortableTable.prototype.setTHead = function (oTHead) {
	if (this.tHead && this.tHead != oTHead) {
		this.uninitHeader();
	}
	this.tHead = oTHead;
}


SortableTable.prototype.setTBody = function (tBody) {
	this.tBody = tBody;
}


SortableTable.prototype.setSortTypes = function (oSortTypes) {
	if (this.tHead) {
		this.uninitHeader();
	}
	this.sortTypes = oSortTypes || [];
	if (this.tHead) {
		this.initHeader(this.sortTypes);
	}
}


SortableTable.prototype.setFilterForm = function (oFilterForm) {
	this.oFilterForm = oFilterForm;
	if (this.oFilterForm) {
		this.appliedFilters = [];
		this.addFilterConstructorToForm(this.oFilterForm);
	}
}


SortableTable.prototype.addFilterConstructorToForm = function (oFilterForm) {
	var columns = this.tHead.rows[0].cells;
	if (this.oFilterForm.firstChild) {
		this.oFilterForm.removeChild(this.oFilterForm.firstChild)
	}
	
	this.oFilterFieldSet = document.createElement("fieldset");
	this.oFilterColumn = document.createElement("select");
	this.oFilterType = document.createElement("select");
	this.oFilterValue = document.createElement("input");
	this.oFilterValue.setAttribute("type", "text");
	this.oFilterAddRemove = document.createElement("button");
	this.oFilterAddRemove.setAttribute("type", "button");
	this.oFilterAddRemove.setAttribute("name", "add_remove");
	var oFilterValueLabel = document.createElement("label");
	oFilterValueLabelText = document.createTextNode("Predicted IC50 [nM] < ");
	this.oFilterAddText = document.createTextNode("Add Filter");
	this.oFilterRemoveText = document.createTextNode("Remove Filter")
	this.oFilterColumn.setAttribute("class", "filter_column");
	this.oFilterColumn.style.display = "none";
	this.oFilterType.setAttribute("class", "filter_type");
	this.oFilterType.style.display = "none";
	this.oFilterValue.setAttribute("class", "filter_value");
	this.oFilterAddRemove.setAttribute("class", "filter_add");
	oFilterValueLabel.setAttribute("for", this.oFilterValue.getAttribute("id"));
	oFilterValueLabel.appendChild(oFilterValueLabelText);
	this.oFilterAddRemove.appendChild(this.oFilterAddText);
	var oFilterColumnsOption = document.createElement("option");
	oFilterColumnsOption.setAttribute("value", "IC50 [nM]");
	oFilterColumnsOptionText = document.createTextNode("Score");
	oFilterColumnsOption.appendChild(oFilterColumnsOptionText);
	this.oFilterColumn.appendChild(oFilterColumnsOption);
	this.oFilterFieldSet.appendChild(this.oFilterColumn);
	this.oFilterFieldSet.appendChild(this.oFilterType);
	this.oFilterFieldSet.appendChild(oFilterValueLabel);	
	this.oFilterFieldSet.appendChild(this.oFilterValue);
	this.oFilterFieldSet.appendChild(this.oFilterAddRemove);
	this.oFilterForm.insertBefore(this.oFilterFieldSet, this.oFilterForm.childNodes.firstChild || null);
	this.setFilterFormTypes(this.oFilterType);	
	if (typeof this.oFilterAddRemove.addEventListener != "undefined") {
		this.oFilterAddRemove.addEventListener("click", associateObjWithEvent(this, "addRemoveOnClick"), false);
	}
	else {
		this.oFilterAddRemove.onclick = associateObjWithEvent(this, "addRemoveOnClick");
	}	
}


SortableTable.prototype.setFilterFormTypes = function (oFilterType) {
	for (sType in this._filterTypeInfo) {		
		filter_type_option = document.createElement("option");
		filter_type_option.setAttribute("value", this._filterTypeInfo[sType].type);
		filter_type_option_text = document.createTextNode(this._filterTypeInfo[sType].type);
		filter_type_option.appendChild(filter_type_option_text);
		oFilterType.appendChild(filter_type_option);
	}
}


function associateObjWithEvent(obj, methodName) {
    return (function (e) {
        e = e||window.event;
		//this refers to the object the event was instantiated on
		//when an event occurs obj and methodName
		//are still available because of closure
        return obj[methodName](e, this);
    })
}


SortableTable.prototype.initHeader = function (oSortTypes) {
	// adds arrow containers and events
	// also binds sort type to the header cells so that reordering columns does
	// not break the sort types
	// ToDo! Image switching should be done using CSS
	if (!this.tHead) {
		return;
	}
	var cells = this.tHead.rows[0].cells;
	var doc = this.tHead.ownerDocument || this.tHead.document;
	var l = cells.length;
	var img, c;
	for (var i = 0; i < l; i++) {
		c = cells[i];
		if (this.sortTypes[i] != null && this.sortTypes[i] != "None") {
			img = doc.createElement("IMG");
			img.src = "http://66.88.142.60:82/images/blank.png";
			c.appendChild(img);
			if (this.sortTypes[i] != null)
				c._sortType = this.sortTypes[i];
			if (typeof c.addEventListener != "undefined") {
				c.addEventListener("click", associateObjWithEvent(this, "headerOnclick"), false);
			}
			else {
				c.onclick = associateObjWithEvent(this, "headerOnclick");
			}
		}
		else
		{
			c.setAttribute( "_sortType", oSortTypes[i] );
			c._sortType = "None";
		}
	}
	this.updateHeaderArrows();
}	


SortableTable.prototype.headerOnclick = function (event, element) {
	while (element.tagName != "TD"){
		element = element.parentNode;
	}
	this.sort(SortableTable.msie ? SortableTable.getCellIndex(element) : element.cellIndex);
}


SortableTable.prototype.addFilter = function () {
	/* Add a filter to the filter stack.
	   Filtered items are hidden using the CSS display proptery. */
	var display = "none"
	var header_cells = this.tHead.rows[0].cells;
	// Opera loses its reference to filterForm.
	this.filterForm = document.getElementById("filter_form");
	this.oFilterColumn = this.filterForm.firstChild.childNodes[0];
	var sFilterColumnValue = this.oFilterColumn.options[0].value
	var sFilterTypeValue = this.oFilterType.options[0].value

	var sFilterValueValue = this.oFilterValue.value	
	if (sFilterColumnValue == "" || sFilterTypeValue == "" || sFilterValueValue == "") {
		alert("Please enter a cutoff value");
		return false;
	}
	this.appliedFilters.push({
							  sFilterColumnValue: 	sFilterColumnValue,
							  sFilterTypeValue: 	sFilterTypeValue,
							  sFilterValueValue: 	sFilterValueValue});	
	var oNewFilter = this.appliedFilters[this.appliedFilters.length - 1];
	
	for (j = 0; j < header_cells.length; j++) {
		if (SortableTable.getInnerText(header_cells[j]) === oNewFilter["sFilterColumnValue"]) {
			this.nFilterColumn = j;
			var oFilterCache = this.getCache(null, this.nFilterColumn);
		}
	}		
	var filterFunction = this.getFilterFunction(oNewFilter["sFilterTypeValue"]);	
	oFilterCache = filterFunction(oFilterCache, oNewFilter["sFilterValueValue"], display);	
	this.buildFilteredTable(oFilterCache);
	this.colorTableRows(oFilterCache);
	return true;
}


SortableTable.prototype.removeFilter = function () {
	var display = ""
	var oRemovedFilter = this.appliedFilters[this.appliedFilters.length - 1];
	var header_cells = this.tHead.rows[0].cells;	
	for (j = 0; j < header_cells.length; j++){
		if (SortableTable.getInnerText(header_cells[j]) == oRemovedFilter["sFilterColumnValue"]){
			this.nFilterColumn = j;
			var oFilterCache = this.getCache(null, this.nFilterColumn);
		}
	}		
	var filterFunction = this.getFilterFunction(oRemovedFilter["sFilterTypeValue"]);	
	oFilterCache = filterFunction(oFilterCache, oRemovedFilter["sFilterValueValue"], display);
	this.buildFilteredTable(oFilterCache);
	this.appliedFilters.splice(i - 1, 1);
	this.colorTableRows(oFilterCache);
	this.destroyCache(oFilterCache);
}


SortableTable.prototype.buildFilteredTable = function (filterCache){
	// ToDo! Should this.tBody be detached from DOM here for speed??
	if (filterCache && filterCache.length > 0){
		for (var i = 0; i < filterCache.length; i++) {
		this.tBody.appendChild(filterCache[i].element);
		}
	}
}


SortableTable.prototype.addRemoveOnClick = function (event, element){	
	var oFilterAddRemove = element	
	if (this.oFilterAddRemove.getAttribute("class") == "filter_add") {
		if (this.addFilter() == true) {
			oFilterAddRemove.replaceChild(this.oFilterRemoveText, this.oFilterAddText);
			oFilterAddRemove.setAttribute("class", "filter_remove");
			this.oFilterForm.insertBefore(this.oFilterFieldSet, this.oFilterForm.childNodes.firstChild || null);
		}
	}
	else if (this.oFilterAddRemove.getAttribute("class") == "filter_remove"){		
		this.removeFilter()
		oFilterAddRemove.replaceChild(this.oFilterAddText, this.oFilterRemoveText);
		oFilterAddRemove.setAttribute("class", "filter_add");
		this.oFilterForm.reset();
	}
}


SortableTable.getCellIndex = function (td_element) {
	// IE returns wrong cellIndex when columns are hidden
	var cells = td_element.parentNode.childNodes
	var l = cells.length;
	var i;
	for (i = 0; cells[i] != td_element && i < l; i++) {
		continue;
	}
	return i;
}

SortableTable.prototype.getSortType = function (nColumn) {
	return this.sortTypes[nColumn] || "String";
}


SortableTable.prototype.getCache = function (sType, nColumn) {

	if (!this.tBody) {
		return [];
	}
	var rows = this.tBody.rows;
	var l = rows.length;
	var a = new Array();
	var r;
	
	for (var i = 0; i < l; i++) {
		r = rows[i];
		z = {
			value:		this.getRowValue(r, sType, nColumn),
			element:	r
			};
		a.push(z);
	}
	return a;
}

SortableTable.prototype.getRowValue = function (oRow, sType, nColumn) {
	// if we have defined a custom getRowValue use that
	if (this._sortTypeInfo[sType] && this._sortTypeInfo[sType].getRowValue)
		return this._sortTypeInfo[sType].getRowValue(oRow, nColumn);

	var s;
	var c = oRow.cells[nColumn];
	if (typeof c.innerText != "undefined")
		s = c.innerText;
	else
		s = SortableTable.getInnerText(c);
	return this.getValueFromString(s, sType);
};

SortableTable.getInnerText = function (oNode) {
	var s = "";
	var cs = oNode.childNodes;
	var l = cs.length;
	for (var i = 0; i < l; i++) {
		switch (cs[i].nodeType) {
			case 1: //ELEMENT_NODE
				s += SortableTable.getInnerText(cs[i]);
				break;
			case 3:	//TEXT_NODE
				s += cs[i].nodeValue;
				break;
		}
	}
	return s;
};

SortableTable.prototype.getValueFromString = function (sText, sType) {
	if (this._sortTypeInfo[sType])
		return this._sortTypeInfo[sType].getValueFromString( sText );
	return sText;
	/*
	switch (sType) {
		case "Number":
			return Number(sText);
		case "CaseInsensitiveString":
			return sText.toUpperCase();
		case "Date":
			var parts = sText.split("-");
			var d = new Date(0);
			d.setFullYear(parts[0]);
			d.setDate(parts[2]);
			d.setMonth(parts[1] - 1);
			return d.valueOf();
	}
	return sText;
	*/
	}

SortableTable.prototype.getFilterFunction = function (sType) {
	if (this._filterTypeInfo[sType])
		return this._filterTypeInfo[sType].filter;
	return SortableTable.basicFilter;
};

SortableTable.prototype.getSortFunction = function (sType) {
	if (this._sortTypeInfo[sType])
		return this._sortTypeInfo[sType].compare;
	return SortableTable.basicCompare;
};

SortableTable.prototype.updateHeaderArrows = function () {
	var cells = this.tHead.rows[0].cells;
	var l = cells.length;
	for (var i = 0; i < l; i++) {
		if (cells[i]._sortType != null && cells[i]._sortType != "None") {
			var img = cells[i].lastChild;
			if (i === this.sortedColumn){			
				img.className = "sort_arrow " + (this.sortOrder ? "descending" : "ascending");
			}
			else{
				img.className = "sort_arrow";
			}
		}
	}
}

// remove arrows and events
SortableTable.prototype.uninitHeader = function () {
	if (!this.tHead) return;
	var cells = this.tHead.rows[0].cells;
	var l = cells.length;
	var c;
	for (var i = 0; i < l; i++) {
		c = cells[i];
		if (c._sortType != null && c._sortType != "None") {
			c.removeChild(c.lastChild);
			if (typeof c.removeEventListener != "undefined")
				c.removeEventListener("click", this._headerOnclick, false);
			else if (typeof c.detachEvent != "undefined")
				c.detachEvent("onclick", this._headerOnclick);
			c._sortType = null;
			c.removeAttribute( "_sortType" );
		}
	}
}

SortableTable.prototype.destroyCache = function (oArray) {
	var l = oArray.length;
	for (i = oArray.length - 1; i >= 0; i -= 1) {
		oArray[i].value = null;
		oArray[i].element = null;
		oArray.splice(i);		
	}
};

SortableTable.prototype.destroy = function () {
	this.uninitHeader();
	var win = document.parentWindow;
	if (win && typeof win.detachEvent != "undefined") {	// only IE needs this
		win.detachEvent("onunload", this._onunload);
	}
	this._onunload = null;
	this.element = null;
	this.tHead = null;
	this.tBody = null;
	document = null;
	this.sortTypes = null;
	this._asyncsort = null;
};

SortableTable.prototype.addFilterType = function (sType, fFilterFunction) {
	this._filterTypeInfo[sType] = {
		type:	sType,
		filter:	fFilterFunction || SortableTable.basicFilter
	}
}

SortableTable.prototype.removeFilterType = function (sType) {
	delete this._filterTypeInfo[sType];
}

// Adds a sort type to all instance of SortableTable
// sType : String - the identifier of the sort type
// fGetValueFromString : function ( s : string ) : T - A function that takes a
//    string and casts it to a desired format. If left out the string is just
//    returned
// fCompareFunction : function ( n1 : T, n2 : T ) : Number - A normal JS sort
//    compare function. Takes two values and compares them. If left out less than,
//    <, compare is used
// fGetRowValue : function( oRow : HTMLTRElement, nColumn : int ) : T - A function
//    that takes the row and the column index and returns the value used to compare.
//    If left out then the innerText is first taken for the cell and then the
//    fGetValueFromString is used to convert that string the desired value and type

SortableTable.prototype.addSortType = function (sType, fGetValueFromString, fCompareFunction, fGetRowValue) {
	this._sortTypeInfo[sType] = {
		type:				sType,
		getValueFromString:	fGetValueFromString || SortableTable.idFunction,
		compare:			fCompareFunction || SortableTable.basicCompare,
		getRowValue:		fGetRowValue
	};
}

// this removes the sort type from all instances of SortableTable
SortableTable.prototype.removeSortType = function (sType) {
	delete this._sortTypeInfo[sType];
}

SortableTable.prototype.asyncSort = function (nColumn, bDescending, sortType) {
	var oThis = this;
	this._asyncsort = function () {
		oThis.sort(nColumn, bDescending, sortType);
	};
	window.setTimeout(this._asyncsort, 1);
}



SortableTable.prototype.addClassName = function(el, sClassName) {
	/* Adds an inline CSS class name attribute to an XHTML element */
	var classes = el.className.split(" ");
	var l = classes.length;
	for (var i = 0; i < l; i++) {
		if (classes[i] === sClassName)
			return;
	}
	classes[l] = sClassName;
	el.className = classes.join(" ").replace( /(^\s+)|(\s+$)/g, "" );
}

SortableTable.prototype.removeClassName = function (el, sClassName) {
	/* Removes an inline CSS class name from an XHTML element */
	var classes = el.className.split(" ");
	var l = classes.length;
	for (var i = 0; i < l; i++) {
		if (classes[i] === sClassName) {
			classes.splice(i, 1)
		}
	}
	el.className = classes.join(" ").replace( /(^\s+)|(\s+$)/g, "" );
}

SortableTable.basicCompare = function compare(n1, n2) {
	if (n1.value < n2.value){
		return -1;
	}
	if (n2.value < n1.value){
		return 1;
	}
	return 0;
}

SortableTable.basicFilter = function compare(n1, n2) {
	return;
}

SortableTable.idFunction = function (x) {
	return x;
}

SortableTable.toUpperCase = function (s) {
	return s.toUpperCase();
}

SortableTable.toDate = function (s) {
	var parts = s.split("-");
	var d = new Date(0);
	d.setFullYear(parts[0]);
	d.setDate(parts[2]);
	d.setMonth(parts[1] - 1);
	return d.valueOf();
}

// add sort types
SortableTable.prototype.addSortType("Number", Number);
SortableTable.prototype.addSortType("CaseInsensitiveString", SortableTable.toUpperCase);
SortableTable.prototype.addSortType("Date", SortableTable.toDate);
SortableTable.prototype.addSortType("String");
// None is a special case