function insertRow(oTable){
	oRow = oTable.insertRow();
	return oRow;
}

function insertCell(oRow){
	oCell = oRow.insertCell();
	return oCell;
}

function duplicateTR(oTable){

	rowLength = oTable.rows.length;
		
	targetRow = oTable.rows[rowLength-1];
	
	cellLength = targetRow.cells.length;
	
	
	newRow = oTable.insertRow();
	newRow.style = targetRow.style;
	for(j=0;j<cellLength;j++){
	
		newCell = insertCell(newRow);
		//newCell.width = targetRow.cells[j].width;
		newCell.style = targetRow.cells[j].style;
		
		newCell.innerHTML = targetRow.cells[j].outerHTML;
	}
}


function insertTR(oTable,oContent,classname){
	rowLength = oTable.rows.length;
	targetRow = oTable.rows[rowLength-1];
	
	cellLength = targetRow.cells.length;
	
	if (window.ActiveXObject) {
		newRow = oTable.insertRow();
    } else {
		newRow = oTable.insertRow(targetRow.length);
    }

	newRow.className = targetRow.className;
	for(j=0;j<cellLength;j++){
		if (window.ActiveXObject) {
			newCell = insertCell(newRow);
	    } else {
			newCell = newRow.insertCell(j);
	    }
		//newCell.width = targetRow.cells[j].width;
     	newCell.className = targetRow.cells[j].className;
		if(classname != null) {
			if(typeof(classname) == "string"){
				newCell.className = classname;
			}else{
				newCell.className = classname[j];
			}
		}else{
			newCell.className = targetRow.cells[j].className;
		}
		newCell.innerHTML = oContent[j];
	}
	
	return newRow;
}

function insertTR2Top(oTable,oContent,classname) {

	rowLength = oTable.rows.length;
	targetRow = oTable.rows[rowLength-1];
	cellLength = targetRow.cells.length;
	
	if (cellLength == 1) {
		oTable.deleteRow(1);
		cellLength = 8;
	}
	newRow = oTable.insertRow(1);
	
	for(j=0;j<cellLength;j++){
		if (window.ActiveXObject) {
			newCell = insertCell(newRow);
	    } else {
			newCell = newRow.insertCell(j);
	    }
	    
		if (classname != null) {
			if (typeof(classname) == "string"){
				newCell.className = classname;
			} else{
				newCell.className = classname[j];
			}
		} else {
			newCell.className = className;
		}
		newCell.innerHTML = oContent[j];
	}
	return newRow;
}

function deleteTR(oTable, oCheck){

	cnt = assertCheck(oCheck);

	if(cnt > 0){	
		if(typeof(oCheck.length) != "undefined"){
			for(i=oCheck.length-1;i>=0;i--){
				if(oCheck[i].checked == true) oTable.deleteRow(i+1);		
			}
		}else{
				oTable.deleteRow(1);		
		}
	}else{
		alert("선택된 항목이 없습니다.");
	}
}


function moveUp(oTable, oCheck, exceptCellIndex){
	var index;
	if(assertCheck(oCheck) == 1){
		for(i=0;i<oCheck.length;i++){
			if(oCheck[i].checked){
				if(i==0){
					alert("더 이상 순서를 위로 올릴 수 없습니다.");
					return;
				}else{
					index = i+1;
				}
			}
		}
		switchTR(oTable,oTable.rows[index],oTable.rows[index-1],exceptCellIndex);	
	}else{
		alert("선택된 항목이 없습니다.");
	}

}

function moveDown(oTable, oCheck, exceptCellIndex){
	var index;
	if(assertCheck(oCheck) == 1){
		for(i=0;i<oCheck.length;i++){
			if(oCheck[i].checked){
				if(i==oCheck.length-1){
					alert("더 이상 순서를 아래로 내릴 수 없습니다.");
					return;
				}else{
					index = i+1;	
				}
			}
			
		}
		switchTR(oTable,oTable.rows[index],oTable.rows[index+1],exceptCellIndex);
		
	}else{
		alert("선택된 항목이 없습니다.");
	}
}

function assertCheck(oCheck){
	var cnt = 0;
	
	if(oCheck != null) {
		if(typeof(oCheck.length) != "undefined"){
			for(i=0;i<oCheck.length;i++){
				if(oCheck[i].checked) cnt++;			
			}
		}else{
			if(oCheck.checked) cnt++;
		}
		
	}
	return cnt;
}

function switchTR(oTable, sourceTR, targetTR, exceptCellIndex){
	
	for(i=0;i<sourceTR.cells.length;i++){
		if(i != exceptCellIndex){
		
			dummyHTML = sourceTR.cells[i].outerHTML;
			sourceTR.cells[i].innerHTML = targetTR.cells[i].outerHTML;
			targetTR.cells[i].innerHTML = dummyHTML;
		}
	}
}

/* 입력 샘플
function add(){
	oContent = new Array();
	d = new Date();
	
	oContent[0] = "<input type=\"checkbox\" name=\"check\" value=\"\">";
	oContent[1] = "김태영";
	oContent[2] = "짱짱짱!";
	oContent[3] = d.getMilliseconds();
	
입력될 TR의 className Setting
classname은 array 혹은 String 으로 입력
string 으로 입력시 입력되는 모든 cell들이 같은 classname으로 설정됨
classname 을 입력하지 않으면 입력되는 cell의 바로 이전 row의 cell을 참조하여 설정하게됨.

	classname= "aaa";
	classname = new Array();
	 
	classname[0]="";
	classname[1]="aaa";
	classname[2]="bbb";
	classname[3]="aaa";
	insertTR(document.all['aaaa'],oContent,classname);
}
*/