tableソート


弟は初めて投稿して、みんなに指導することを望みます
HTMLページ
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<TITLE> New Document </TITLE>
<META NAME="Generator" CONTENT="EditPlus">
<META NAME="Author" CONTENT="">
<META NAME="Keywords" CONTENT="">
<META NAME="Description" CONTENT="">
</HEAD>

<BODY>
<TABLE id="orderTable" style="border:#C0CACD solid 1px; ">
	<TR>
		<TD class="orderTd" dataType="num">  </TD>
		<TD class="orderTd">  </TD>
		<TD class="orderTd" dataType="num">  </TD>
		<TD class="orderTd" dataType="num">  </TD>
		<TD class="orderTd" dataType="char">  </TD>
	</TR>
	<TBODY>   
		<TR>
			<TD>01023</TD>
			<TD>  </TD>
			<TD>23</TD>
			<TD>2009090233</TD>
			<TD>    </TD>
		</TR>
		<TR>
			<TD>09234</TD>
			<TD>  </TD>
			<TD>34</TD>
			<TD>20100931</TD>
			<TD>    </TD>
		</TR>
		<TR>
			<TD>034512</TD>
			<TD>  </TD>
			<TD>12</TD>
			<TD>20080323</TD>
			<TD>    </TD>
		</TR>
		<TR>
			<TD>45445</TD>
			<TD>  </TD>
			<TD>43</TD>
			<TD>20010923</TD>
			<TD>    </TD>
		</TR>
	</TBODY>
</TABLE>
</BODY>
</HTML>

Script
<script>
(function(){
	var d = document, 
	$ = function(id){return d.getElementById(id)}, 
	ot = $("orderTable"), 
	hds = ot ? ot.rows[0].getElementsByTagName("td") : "", 
	tClass = "orderTd", 
	orderT = function(){
		var odb = ot.getElementsByTagName("tbody")[1], 
			tv = new Array(), 
			nodb = d.createElement("tbody"), 
			otype = this.orderType || "desc";

		this.orderType = otype == "desc" ? "asc" : "desc";
		//        ,  
		for(var i=1, ci; ci=ot.rows[i]; i++){
			tv[i-1] = [ci.cells[this.index].innerHTML, i];
		}
	
		//  
		if(this.dataType && this.dataType == "num"){
			tv.sort(function(a, b){
				return otype == "desc" ? +a[0]- +b[0] : +b[0]- +a[0];
			})
		}else{
			tv.sort(function(a, b){
				return otype == "desc" ? a[0].localeCompare(b[0]) : b[0].localeCompare(a[0]);
			})
		}

		//    tbody, tr, td
		for(var i=0, ci; ci=tv[i]; i++){
			var otr = ot.rows[ci[1]];
			ot.appendChild(nodb);
			ntr = d.createElement("tr");
			nodb.appendChild(ntr);
			for(var j=0, cj; cj=otr.cells[j]; j++){
				ntd = d.createElement("td");
				ntd.innerHTML = cj.innerHTML;
				ntr.appendChild(ntd);
			}
		}

		//    tbody
		ot.removeChild(odb);
	};

	//      td  onclick  
	for(var i=0, ci; ci=hds[i]; i++){
		ci.index = i;
		if(ci.className && ci.className == tClass){
			ci.style.cursor = "pointer";
			ci.onclick = orderT;
		}
	}
})()
</script>

皆さんが足りないところを与えてくれることを願っています.