// Vars globales

var browser=navigator.appName;
var globalNavegador = false;  // Para la gestión de directos true: netscape, false: others
var globalPosiciones = new Array();

if (browser=="Netscape"){
    globalNavegador = true;
} else {
    globalNavegador = false;
}

function SortableTable(oTable, oSortTypes) {

	this.sortTypes = oSortTypes || [];

	this.sortColumn = null;
	this.descending = null;

	var oThis = this;
	this._headerOnclick = function (e) {
		oThis.headerOnclick(e);
	};

	if (oTable) {
		this.setTable( oTable );
		this.document = oTable.ownerDocument || oTable.document;
	}
	else {
		this.document = document;
	}


	// only IE needs this
	var win = this.document.defaultView || this.document.parentWindow;
	this._onunload = function () {
		oThis.destroy();
	};
	if (win && typeof win.attachEvent != "undefined") {
		win.attachEvent("onunload", this._onunload);
	}
}

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;

SortableTable.prototype.onsort = function () {};

// default sort order. true -> descending, false -> ascending
SortableTable.prototype.defaultDescending = false;

// shared between all instances. This is intentional to allow external files
// to modify the prototype
SortableTable.prototype._sortTypeInfo = {};

SortableTable.prototype.setTable = function (oTable) {
	if ( this.tHead )
		this.uninitHeader();
	this.element = oTable;
	this.setTHead( oTable.tHead );
	this.setTBody( oTable.tBodies[0] );
};

SortableTable.prototype.setTHead = function (oTHead) {
	if (this.tHead && this.tHead != oTHead )
		this.uninitHeader();
	this.tHead = oTHead;
	this.initHeader( this.sortTypes );
};

SortableTable.prototype.setTBody = function (oTBody) {
	this.tBody = oTBody;
};

SortableTable.prototype.setSortTypes = function ( oSortTypes ) {
	if ( this.tHead )
		this.uninitHeader();
	this.sortTypes = oSortTypes || [];
	if ( this.tHead )
		this.initHeader( this.sortTypes );
};

// adds arrow containers and events
// also binds sort type to the header cells so that reordering columns does
// not break the sort types
SortableTable.prototype.initHeader = function (oSortTypes) {
	if (!this.tHead) return;
	var cells = this.tHead.rows[0].cells;
	var doc = this.tHead.ownerDocument || this.tHead.document;
	this.sortTypes = oSortTypes || [];
	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 = "images/blank.png";
			//c.appendChild(img);
			if (this.sortTypes[i] != null)
				c._sortType = this.sortTypes[i];
			if (typeof c.addEventListener != "undefined")
				c.addEventListener("click", this._headerOnclick, false);
			else if (typeof c.attachEvent != "undefined")
				c.attachEvent("onclick", this._headerOnclick);
			else
				c.onclick = this._headerOnclick;
		}
		else
		{
			c.setAttribute( "_sortType", oSortTypes[i] );
			c._sortType = "None";
		}
	}
	this.updateHeaderArrows();
};

// 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.updateHeaderArrows = function () {
	if (!this.tHead) return;
	var cells = this.tHead.rows[0].cells;
	var l = cells.length;
	var img;
	for (var i = 0; i < l; i++) {
		if (cells[i]._sortType != null && cells[i]._sortType != "None") {
			img = cells[i].lastChild;
			//if (i == this.sortColumn)
			//	img.className = "sort-arrow " + (this.descending ? "descending" : "ascending");
			//else
			//	img.className = "sort-arrow";
		}
	}
};

SortableTable.prototype.headerOnclick = function (e) {
	// find TD element
	//var el = e.target || e.srcElement;
	//while (el.tagName != "TD")
	//	el = el.parentNode;

	//this.sort(SortableTable.msie ? SortableTable.getCellIndex(el) : el.cellIndex);
    var algo;
};

// IE returns wrong cellIndex when columns are hidden
SortableTable.getCellIndex = function (oTd) {
	var cells = oTd.parentNode.childNodes
	var l = cells.length;
	var i;
	for (i = 0; cells[i] != oTd && i < l; i++)
		;
	return i;
};

SortableTable.prototype.getSortType = function (nColumn) {
	return this.sortTypes[nColumn] || "String";
};

// only nColumn is required
// if bDescending is left out the old value is taken into account
// if sSortType is left out the sort type is found from the sortTypes array

SortableTable.prototype.sort = function (nColumn, bDescending, sSortType) {
	if (!this.tBody) return;
	if (sSortType == null)
		sSortType = this.getSortType(nColumn);

	// exit if None
	if (sSortType == "None")
		return;

	if (bDescending == null) {
		if (this.sortColumn != nColumn)
			this.descending = this.defaultDescending;
		else
			this.descending = !this.descending;
	}
	else
		this.descending = bDescending;
    this.descending = false; // ##############3

	this.sortColumn = nColumn;

	if (typeof this.onbeforesort == "function")
		this.onbeforesort();

	var f = this.getSortFunction(sSortType, nColumn);
	var a = this.getCache(sSortType, nColumn);
	var tBody = this.tBody;
	
	
	
	
	if(globalCarrera){
		var l = a.length;
        for (var i = 0; i < l; i++) {
            //elemento = a[i].element;
            //almacenamos datos
            
            if(globalNavegador){
                
                a[i].element.childNodes[1].textContent = i + 1;
            } else {
                a[i].element.childNodes[0].innerText = i + 1;
                
            }
        }
	} 
	
    
    
    
    if(!globalCarrera){
		a.sort(f);
        // Cogemos el mejor tiempo
        elemento = a[0].element;
        nodos = elemento.childNodes;
            
        for (x = 0; x<nodos.length; x++)
        {
            s = SortableTable.getInnerText(nodos[x]);    
                       
            if (s.split(".").length>2)   //##################
            {
                var parts = s.split(".");   //##################
                var mejor_tiempo = new Date(0);
                mejor_tiempo.setHours(parts[0]);
                mejor_tiempo.setMinutes(parts[1],parts[2],parts[3]);
            }
            s = '';
        }
        
        var l = a.length;
        var posicion = 0;
        for (var i = 0; i < l; i++) {
            var cs = a[i].element;
            var nodos = cs.childNodes;
            var s = '';
            var lo = nodos.length;
            
            // Ponemos la pocision
            posicion = i + 1;
            if(globalNavegador){
                nodos[1].textContent = posicion.toString();
            } else {
                nodos[0].innerText = posicion.toString();
            }
            
            //Ponemos la diferencia
            if(globalNavegador){
                var parts = nodos[13].textContent.split('.'); //##################
            } else {
                var parts = nodos[6].innerText.split('.');  //##################
            }
            var tiempo = new Date(0);
            tiempo.setHours(parts[0]);
            tiempo.setMinutes(parts[1],parts[2],parts[3]);
            diferencia = new Date(0);
            diferencia = tiempo - mejor_tiempo;

            var tiempo_final = new Date(0);
            tiempo_final.setHours('00');
            tiempo_final.setMilliseconds(diferencia);
            
            // Confeccionamos el tiempo
            var horas   = '00' + tiempo_final.getHours();
            var minutes = '00' + tiempo_final.getMinutes();
            var seconds = '00' + tiempo_final.getSeconds();
            var miliseconds = '000'+ tiempo_final.getMilliseconds();

            var horas   = horas.substring(horas.length-2,horas.length);
            var minutes = minutes.substring(minutes.length-2,minutes.length);
            var seconds = seconds.substring(seconds.length-2,seconds.length);
            var miliseconds = miliseconds.substring(miliseconds.length-3,miliseconds.length);
            
            
            if(i>0){
                if(globalNavegador){
                    a[i].element.childNodes[15].textContent = horas+':'+minutes+'\''+seconds+'\'\''+miliseconds;
                    
                } else {
                    a[i].element.childNodes[7].innerText = horas+':'+minutes+'\''+seconds+'\'\''+miliseconds;
                }
            } else {
                if(globalNavegador){
                    a[i].element.childNodes[15].textContent = '';
                } else {
                    a[i].element.childNodes[7].textContent = '';
                }
            }
        }  
    } 
    var l = a.length;
    var posicion = 0;
    var estado = ''
    for (var i = 0; i < l; i++) {
        elemento = a[i].element;
        nodos = elemento.childNodes;
        estado = '';
        
        for(var y=0; y<nodos.length;y++){
            if(globalNavegador){
                if(i%2!=0 && y%2!=0) nodos[y].style.background='#eee';
        //        if(i==0 && y%2!=0) nodos[y].style.fontWeight= 'bold';
            } else {
                if(i%2!=0) nodos[y].style.background='#eee';
        //        if(i==0) nodos[y].style.fontWeight='bold';
            }
        }
        
        //elemento.setAttribute('color','red');
        //Ponemos format del tiempo
        if(globalNavegador){
            var parts = nodos[13].textContent.split('.');  //##################
            nodos[13].textContent = parts[0] + ':' + parts[1] + '\'' + parts[2] + '\'\'' + parts[3];
        } else {
            var parts = nodos[6].innerText.split('.');  //##################
            nodos[6].innerText = parts[0] + ':' + parts[1] + '\'' + parts[2] + '\'\'' + parts[3];
        }
        
        //Formateamos
        
        
        if(globalNavegador){
            if (globalCarrera)  a[i].element.childNodes[15].textContent = '--';
            estado = a[i].element.childNodes[5].textContent;
        } else {
            if (globalCarrera)  a[i].element.childNodes[7].innerText = '--';
            estado = a[i].element.childNodes[2].innerText;
        }
            
        switch (estado) {
	        case 'in': //ELEMENT_NODE
                var img     = document.createElement('IMG');
                img.setAttribute('src', 'images/in.gif');
                if(globalNavegador){
                    a[i].element.childNodes[5].textContent = '';
                    a[i].element.childNodes[5].appendChild(img);
                } else {
	                a[i].element.childNodes[2].innerText = '';
                    a[i].element.childNodes[2].appendChild(img);
                }
		        break;
            case 'out': //ELEMENT_NODE
                var img     = document.createElement('IMG');
                img.setAttribute('src', 'images/out.gif');
                if(globalNavegador){
                    a[i].element.childNodes[5].textContent = '';
                    a[i].element.childNodes[5].appendChild(img);
                } else {
	                a[i].element.childNodes[2].innerText = '';
                    a[i].element.childNodes[2].appendChild(img);
                }
	            break;
            case 'incidente': //ELEMENT_NODE
                var img     = document.createElement('IMG');
                img.setAttribute('src', 'images/incidente.gif');
                if(globalNavegador){
                    a[i].element.childNodes[5].textContent = '';
                    a[i].element.childNodes[5].appendChild(img);
                } else {
		            a[i].element.childNodes[2].innerText = '';
                    a[i].element.childNodes[2].appendChild(img);
                }
		        break;
            case 'investigado': //ELEMENT_NODE
                var img     = document.createElement('IMG');
                img.setAttribute('src', 'images/investigado.gif');
                if(globalNavegador){
                    a[i].element.childNodes[5].textContent = '';
                    a[i].element.childNodes[5].appendChild(img);
                } else {
	                a[i].element.childNodes[2].innerText = '';
                    a[i].element.childNodes[2].appendChild(img);
                }
	            break;
            case 'boxes': //ELEMENT_NODE
                var img     = document.createElement('IMG');
                img.setAttribute('src', 'images/boxes.gif');
                if(globalNavegador){
                    a[i].element.childNodes[5].textContent = '';
                    a[i].element.childNodes[5].appendChild(img);
                } else {
		            a[i].element.childNodes[2].innerText = '';
                    a[i].element.childNodes[2].appendChild(img);
                }
		        break;
            }
            
    }
    // Ponemos las posiciones  
    // Rellenamos la primera vez
    globalPosicionestemporal = new Array();
    var l = a.length;
    
    if (globalPosiciones.length==0)
    {
        for (var i = 0; i < l; i++) {
            //elemento = a[i].element;
            //almacenamos datos
            var spanelement = document.createElement("span");
            var belement = document.createElement("b");
            if(globalNavegador){
                spanelement.textContent='.';
                belement.textContent = a[i].element.childNodes[1].textContent + 'º';
                a[i].element.childNodes[1].textContent = '';
                globalPosiciones[i] = new Array(a[i].element.childNodes[3].textContent,'.');
                a[i].element.childNodes[1].appendChild(spanelement);
                a[i].element.childNodes[1].appendChild(belement);
            } else {
                spanelement.innerText='.';
                belement.innerText = a[i].element.childNodes[0].innerText + 'º';
                a[i].element.childNodes[0].innerText = '';
                globalPosiciones[i] = new Array(a[i].element.childNodes[1].innerText,'.');
                a[i].element.childNodes[0].appendChild(spanelement);
                a[i].element.childNodes[0].appendChild(belement);
            }
        }
    } else {
        // Comprobamos que los arrays son iguales
        var iguales = true;
        for (var i = 0; i < l; i++) {
            //elemento = a[i].element;
            //almacenamos datos
            //var spanelement = document.createElement("span");
            if(globalNavegador){
                globalPosicionestemporal[i] = new Array(a[i].element.childNodes[3].textContent,'.');
                if(globalPosiciones[i][0]!=a[i].element.childNodes[3].textContent) iguales = false;
            } else {
                globalPosicionestemporal[i] = new Array(a[i].element.childNodes[1].innerText,'.');
                if(globalPosiciones[i][0]!=a[i].element.childNodes[1].innerText) iguales = false;
            }
        }
        // Son iguales
        
        if(iguales)
        {
            
            for (var i = 0; i < l; i++) {
                //elemento = a[i].element;
                var spanelement = document.createElement("span");
                var belement = document.createElement("b");
                var textTemporal = '';
                if(globalNavegador){
                    spanelement.textContent=globalPosiciones[i][1];
                    belement.textContent = a[i].element.childNodes[1].textContent + 'º';
                    a[i].element.childNodes[1].textContent = '';
                    //a[i].element.childNodes[1].textContent = a[i].element.childNodes[1].textContent + ' ' + globalPosiciones[i][1];
                    a[i].element.childNodes[1].appendChild(spanelement);
                    a[i].element.childNodes[1].appendChild(belement);
                } else {
                    spanelement.innerText=globalPosiciones[i][1];
                    belement.innerText = a[i].element.childNodes[0].innerText + 'º'
                    a[i].element.childNodes[0].innerText = '';
                    //a[i].element.childNodes[0].innerText = a[i].element.childNodes[0].innerText + ' ' + globalPosiciones[i][1];
                    a[i].element.childNodes[0].appendChild(spanelement);
                    a[i].element.childNodes[0].appendChild(belement);
                }
            }
        
        
        } else {
            // Han cambiado los datos
            for (var i = 0; i < l; i++) {
            //elemento = a[i].element;
            //almacenamos datos
                
                if(globalNavegador){
                    //globalPosiciones[i] = new Array(a[i].element.childNodes[3].textContent,'=');
                    var dorsal = a[i].element.childNodes[3].textContent;
                } else {
                    //globalPosiciones[i] = new Array(a[i].element.childNodes[1].innerText,'=');
                    var dorsal = a[i].element.childNodes[1].innerText;
                }
                var lon = globalPosiciones.length;
                for (var z = 0; z < lon; z++) {
                    if (dorsal == globalPosiciones[z][0]) {
                        if (z==i) 
                        {
                            var spanelement = document.createElement("span");
                            var belement = document.createElement("b");
                            if(globalNavegador){
                                spanelement.textContent='.';
                                belement.textContent = a[i].element.childNodes[1].textContent + 'º';
                                a[i].element.childNodes[1].textContent = '';
                                globalPosicionestemporal[i] = new Array(a[i].element.childNodes[3].textContent,'.');
                                //a[i].element.childNodes[1].textContent = a[i].element.childNodes[1].textContent + ' =';
                                a[i].element.childNodes[1].appendChild(spanelement);
                                a[i].element.childNodes[1].appendChild(belement);
                            } else {
                                spanelement.innerText='.';
                                belement.innerText = a[i].element.childNodes[0].innerText + 'º';
                                a[i].element.childNodes[0].innerText = '';
                                globalPosicionestemporal[i] = new Array(a[i].element.childNodes[1].innerText,'.');
                                //a[i].element.childNodes[0].innerText = a[i].element.childNodes[0].innerText + ' =';
                                a[i].element.childNodes[0].appendChild(spanelement);
                                a[i].element.childNodes[0].appendChild(belement);
                            }
                        } else {
                            var spanelement = document.createElement("span");
                            var belement = document.createElement("b");
                            var pos = (z+1)-(i+1);
                            var carac = '';
                            if (pos>0){
                                carac = '+' + pos.toString();
                            } else {
                                carac =  pos.toString();
                            }
                            
                            if(globalNavegador){
                                spanelement.textContent=carac;
                                belement.textContent = a[i].element.childNodes[1].textContent + 'º';
                                a[i].element.childNodes[1].textContent = '';
                                globalPosicionestemporal[i] = new Array(a[i].element.childNodes[3].textContent, carac);
                                //a[i].element.childNodes[1].textContent = a[i].element.childNodes[1].textContent + ' (' + carac + ')';
                                a[i].element.childNodes[1].appendChild(spanelement);
                                a[i].element.childNodes[1].appendChild(belement);
                            } else {
                                spanelement.innerText=carac;
                                belement.innerText=a[i].element.childNodes[0].innerText + 'º';
                                a[i].element.childNodes[0].innerText = '';
                                globalPosicionestemporal[i] = new Array(a[i].element.childNodes[1].innerText, carac);
                                //a[i].element.childNodes[0].innerText = a[i].element.childNodes[0].innerText + ' (' + carac + ')';
                                a[i].element.childNodes[0].appendChild(spanelement);
                                a[i].element.childNodes[0].appendChild(belement);
                            }
                        }
                    
                    }
                }
            }
            globalPosiciones = globalPosicionestemporal;
        }
    }
    
    // Cambiamos el color a los que pierden posicion
    var l = a.length;
    
    var estado = '=';
    for (var i = 0; i < l; i++) {
        var estado = false;
        if(globalNavegador){
            var posi = a[i].element.childNodes[1].textContent;
            if(posi.indexOf('-')>-1){
                //nodos[i].style.fontWeight= 'bold';
                estado = '-';
            }
            if(posi.indexOf('+')>-1){
                //nodos[i].style.fontWeight= 'bold';
                estado = '+';
            }
        } else {
            var posi = a[i].element.childNodes[0].innerText;
            if(posi.indexOf('-')>-1){
                estado = '-';
            }
            if(posi.indexOf('+')>-1){
                //nodos[i].style.fontWeight= 'bold';
                estado = '+';
            }
        }
        if(estado!='='){
            
            var color = '';
            if (estado=='-') {
                color='red';
            }
            if (estado=='+') {
                color='green';
            }
            elemento = a[i].element;
            nodos = elemento.childNodes;
            //estado = '';
            
            for(var y=0; y<nodos.length;y++){
                if(globalNavegador){
                    if(y%2!=0) nodos[y].style.color=color;
                    
                } else {
                    if(y%2!=0) nodos[y].style.color=color;
                    
                }
            }
        }
    }
        
	if (this.descending)
		a.reverse();

	if (SortableTable.removeBeforeSort) {
		// remove from doc
		var nextSibling = tBody.nextSibling;
		var p = tBody.parentNode;
		p.removeChild(tBody);
	}
    
	// insert in the new order
	var l = a.length;
	for (var i = 0; i < l; i++)
		tBody.appendChild(a[i].element);
        

	if (SortableTable.removeBeforeSort) {
		// insert into doc
		p.insertBefore(tBody, nextSibling);
	}

	this.updateHeaderArrows();

	this.destroyCache(a);

	if (typeof this.onsort == "function")
		this.onsort();
};

SortableTable.prototype.asyncSort = function (nColumn, bDescending, sSortType) {
	var oThis = this;
	this._asyncsort = function () {
		oThis.sort(nColumn, bDescending, sSortType);
	};
	window.setTimeout(this._asyncsort, 1);
};

SortableTable.prototype.getCache = function (sType, nColumn) {
	if (!this.tBody) return [];
	var rows = this.tBody.rows;
	var l = rows.length;
	var a = new Array(l);
	var r;
	for (var i = 0; i < l; i++) {
		r = rows[i];
		a[i] = {
			value:		this.getRowValue(r, sType, nColumn),
			element:	r
		};
	};
	return a;
};

SortableTable.prototype.destroyCache = function (oArray) {
	var l = oArray.length;
	for (var i = 0; i < l; i++) {
		oArray[i].value = null;
		oArray[i].element = null;
		oArray[i] = null;
	}
};

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.getSortFunction = function (sType, nColumn) {
	if (this._sortTypeInfo[sType])
		return this._sortTypeInfo[sType].compare;
	return SortableTable.basicCompare;
};

SortableTable.prototype.destroy = function () {
	this.uninitHeader();
	var win = this.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;
	this.document = null;
	this._headerOnclick = null;
	this.sortTypes = null;
	this._asyncsort = null;
	this.onsort = null;
};

// 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.basicCompare = function compare(n1, n2) {
	if (n1.value < n2.value)
		return -1;
	if (n2.value < n1.value)
		return 1;
	return 0;
};

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.setHours(parts[0]);
	d.setMinutes(parts[1],parts[2],parts[3]);
	//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