
var num = 2;
var lm_iCountLimit = 5;

function add_file(){
    var num2 = (num - 1);
    if (document.all["files"+num2].value != null && document.all["files"+num2].value != "") {
        var oOption = document.createElement("OPTION");
        var fileName = document.all["files"+num2].value;
        oOption.text = fileName;
        oOption.value = num2;
        document.all.oSelect.add(oOption);
        var newDivTag1 = document.createElement("<div>");
        var newDivTag2 = document.createElement("<div>");
        var temp = "<input width=1 type='file' id ='files" + num 
        	+ "' onKeydown='event.returnValue=false;' onpropertychange='add_file()' name='upfile[]"
        	+"' class=input>";
	alert(temp);
        var newFileObject = document.createElement(temp);
        
        var filenum = "files" +num2;
        
        document.all[filenum].onpropertychange = null;
        document.all[filenum].style.display = "none";

        document.all.filetd.insertBefore(newDivTag1, document.all.oSelect);
        document.all.filetd.insertBefore(newFileObject, document.all.oSelect);
        document.all.filetd.insertBefore(newDivTag2, document.all.oSelect);

        if (document.all.oSelect.length >= 5) {
        	document.all["files"+num].onpropertychange = null;
        	document.all["files"+num].style.display = "none";
        }
        num++; 
    } 
}

function del_list() {
    if (document.FormMain.oSelect.selectedIndex != -1 ) {
        var str = document.FormMain.oSelect.options[document.FormMain.oSelect.selectedIndex].text;
        document.FormMain.oSelect.options[document.FormMain.oSelect.selectedIndex]=null;
        var i =0;
        for ( i=1; i < num; i++ ) {
            if (document.all["files"+i] != null) {
                var filename = document.all["files"+i].value;
                if ( filename == str ) {
                    document.all["files"+i].removeNode(true);
                }
            }
        }
        
	if (document.all.oSelect.length < 5) {
		var num2 = num -1;
        	document.all["files"+num2].onpropertychange = null;
        	document.all["files"+num2].style.display = "";
        	document.all["files"+num2].onpropertychange = add_file;
        }        
    } else {
        alert("¼±ÅÃµÈ ÆÄÀÏÀÌ ¾ø½À´Ï´Ù.");
    }
}

