var currentSortCol=-1;var currentSortReversed=false;window.onerror=function(msg,url,lineNum)
{alert("Error: "+msg+" line: "+lineNum);}
function strcmp(a,b)
{try{if(a<b)return-1;if(a==b)return 0;return 1;}catch(ex){alert("strcmp error with a: "+a+"b: "+b);throw ex;}}
function strtrim(str)
{str=str.replace(/^\s+/,'');str=str.replace(/\s+$/,'');return str;}
function cellText(row,index)
{var tds=row.getElementsByTagName("td");var td=tds[index];var text="";var stack=new Array();stack.push(td);while(stack.length>0){var node=stack.pop();if(node.nodeType==3){text+=node.nodeValue;}
else{var i,len=node.childNodes.length;for(i=len-1;i>=0;i--){stack.push(node.childNodes[i]);}}}
text=strtrim(text);if(text==undefined){throw new Error("wtf");}
return text;}
function rowDate(row)
{var text=cellText(row,1);var vals=text.split("-");var d=new Date(parseInt(vals[0]),parseInt(vals[1]),parseInt(vals[2]));return d;}
function orderByTextInCol(col,removeTHE)
{return function(aa,bb){var a=cellText(aa,col);var b=cellText(bb,col);a=a.toLowerCase();b=b.toLowerCase();if(removeTHE){a=a.replace(/the\s*/,'');b=b.replace(/the\s*/,'');}
return strcmp(a,b);}}
function orderByDateCol(a,b)
{a=rowDate(a);b=rowDate(b);if(a<b)return-1;if(a==b)return 0;return 1;}
function setDataType(cValue)
{var isDate=new Date(cValue);if(isDate=="NaN")
{if(isNaN(cValue))
{cValue=cValue.toUpperCase();return cValue;}
else
{var myNum;myNum=String.fromCharCode(48+cValue.length)+cValue;return myNum;}}
else
{var myDate=new String();myDate=isDate.getFullYear()+" ";myDate=myDate+isDate.getMonth()+" ";myDate=myDate+isDate.getDate();+" ";myDate=myDate+isDate.getHours();+" ";myDate=myDate+isDate.getMinutes();+" ";myDate=myDate+isDate.getSeconds();return myDate;}}
function sortTable(col,tableId)
{var table=document.getElementById(tableId);var rows;var i,len;var reverse=false;if(col==currentSortCol){reverse=!currentSortReversed;}
rows=new Array();len=table.rows.length;for(i=1;i<len;i++){rows.push(table.rows[i]);}
var body=rows[0].parentNode;len=rows.length;var order=null;if(col==1)
order=orderByDateCol;if(col==0||col==3)
order=orderByTextInCol(col,true);else
order=orderByTextInCol(col,false);rows.sort(order);if(reverse)
rows.reverse();for(i=0;i<len;i++)
{body.removeChild(rows[i]);}
for(i=0;i<len;i++)
{body.appendChild(rows[i]);}
currentSortCol=col;currentSortReversed=reverse;}