function trace(message)
{
    var textarea = document.getElementById("trace");
    textarea.value = textarea.value + message + "\n";
}

function Array2(n1,n2)
{
    var i;
    var a = new Array(n1);
    for (i = 0; i < n1; i++) {
        a[i] = new Array(n2);
    }
    return a;
}

function Array3(n1,n2,n3)
{
    var i;
    var a = new Array(n1);
    for (i = 0; i < n1; i++) {
        a[i] = new Array2(n2,n3);
    }

    return a;
}

function clearList(list)
{
    while (list.length > 0) {
        list.remove(0);
    }
}

function setListOptionsWithNumber(id,from,to)
{
    var list = document.getElementById(id);
    clearList(list);

    var i;
    for (i = from; i <= to; i++) {
        var option = document.createElement('option');
        option.text = i;
        if (getBrowser() == "ie") {
            list.add(option);   // IE only
        }
        else {
            list.add(option, null);
        }
    }
    list.selectedIndex = list.length-1;
}

function setListOptions(id,arr)
{
    var list = document.getElementById(id);
    clearList(list);

    var i;
    for (i = 0; i < arr.length; i++) {
        var option = document.createElement('option');
        option.text = arr[i];
        if (getBrowser() == "ie") {
            list.add(option);   // IE only
        }
        else {
            list.add(option, null);
        }
    }
}

function selectIndex(id, index)
{
    var listCtl = document.getElementById(id);
    listCtl.selectedIndex = index;
}

function replaceList(id, newList)
{
    if (newList.length <= 0) {
        throw "replaceList: newList.length <= 0";
    }

    var listCtl = document.getElementById(id);
    var preIndex = listCtl.selectedIndex;
    var nextIndex;
    if (preIndex < 0) {
        nextIndex = 0;
    }
    else {
        var preText = listCtl.options[preIndex].text;
        for (nextIndex = 0; nextIndex < newList.length; nextIndex++) {
            if (preText == newList[nextIndex]) {
                break;
            }
        }
        if (nextIndex == newList.length) {
			nextIndex = 0;
//			if (listCtl.selectedIndex > nextIndex) 
//				nextIndex--;  // Ã£Áö ¸øÇÑ °æ¿ì ¸¶Áö¸· °Í.
//			else
//				nextIndex = listCtl.selectedIndex;
        }
    }

    setListOptions(id, newList);
    listCtl.selectedIndex = nextIndex;

    return nextIndex;
}

function newNumList(from, to)
{
    var list = new Array(to-from+1);
    var i;
    var val = from;
    for (i = 0; i < to-from+1; i++) {
        list[i] = val++;
    }
    return list;
}

var browser = "";
function getBrowser()
{
    if (browser == "") {
        var name = navigator.appName;
        if (name.match("Microsoft") != null) {
            browser = "ie";
        }
        else {
            browser = "netscape";
        }
    }
    return browser;
}
