function sort(table, cell, dir, typ, strTouSep, strDesSep) {
  function trim(str) { return str.replace(/^\s*|\s*$/g, ''); }
  function text(row) { return row.cells[cell].innerText; }
  function compareTxt(a, b) {
    try { var aa = text(a).toUpperCase(); } catch(e) {}
    try { var bb = text(b).toUpperCase(); } catch(e) {}
    if (!aa && bb) { return 1; }
  	if (aa && !bb) { return -1; }
  	if (!aa && !bb) { return 0; }
    var ret = aa < bb ? -1 : (aa > bb ? 1 : 0);
  	return dir == 'asc' ? ret : -ret;
  }
  function compareNum(a, b) {
  	var re = new RegExp( '\\' + strTouSep, 'g');
    try { var aa = parseFloat(text(a).replace(re, '').replace(strDesSep, '.')); } catch(e) {}
    try { var bb = parseFloat(text(b).replace(re, '').replace(strDesSep, '.')); } catch(e) {}
    if (!aa && bb) { return 1; }
  	if (aa && !bb) { return -1; }
  	if (!aa && !bb) { return 0; }
    return dir == 'asc' ? aa - bb : bb - aa;
  }
  function compareDat(a, b) {
    try { if (TesDat(trim(text(a)) ,strDatSep, strDatFor)) { var aa = new Date(arrDate[0] + '/' + arrDate[1] + '/' + arrDate[2]); } } catch(e) {}
  	try { if (TesDat(trim(text(b)) ,strDatSep, strDatFor)) { var bb = new Date(arrDate[0] + '/' + arrDate[1] + '/' + arrDate[2]); } } catch(e) {}
    if (!aa && bb) { return 1; }
  	if (aa && !bb) { return -1; }
  	if (!aa && !bb) { return 0; }
    var ret = aa < bb ? -1 : (aa > bb ? 1 : 0);
    return dir == 'asc' ? ret : -ret;
  }
  var arr = [], sortfun, rows = table.rows, count = rows.length - 1, first = rows[0], last = rows[count];
  for (var i = 0; i < count; i++) {arr.push(rows[i+1]); }
  switch (typ) {
    case "num": sortfun = compareNum; break;
    case "dat": sortfun = compareDat; break;
    default : sortfun = compareTxt;
  }
  arr.sort(sortfun);
  for (var i = 0; i < count; i++) {
    arr[i].parentNode.appendChild(arr[i]);
  }
  //last.parentNode.appendChild(last);
}
function OBJ_tagName(Obj) {
try { return Obj.tagName.toLowerCase() } catch(e) { return "" }
}
function Ord(Col,Sor,typ,obj) {
	var table = obj;
	if(table && table.nodeType == 3) { table = table.parentNode; }
	for( ; table; table = table.parentNode) {
		if(OBJ_tagName(table) == "table") { break; }
	}
	if(obj.ord == 0){
		obj.ord = 1;
		dir="des"
	}else{
		obj.ord = 0;
		dir="asc"
	}
	sort(table,Col-1 ,dir,typ,'.',',');
}
