function do_search_change(selectedId) {
    var subOptions = document.getElementById("sub_category_id").options;
    
    for (var i = subOptions.length -1; i > 0; i--) {
        subOptions[i] = null;
    }
    
    for (var i in menuData[selectedId]) {
        subOptions.add(new Option(menuData[selectedId][i].name, i));
    }
}

function do_sub_search_change() {
    with (document.getElementById("main_category_id")) {
        var mainCategoryId = options[selectedIndex].value;
    }
    
    with (document.getElementById("sub_category_id")) {
        var subCategoryId = options[selectedIndex].value;
    }
    
    var subOptions = document.getElementById("sub_sub_category_id").options;
    
    for (var i = subOptions.length -1; i > 0; i--) {
        subOptions[i] = null;
    }
    
    try {
        for (var i in menuData[mainCategoryId][subCategoryId].sub) {
            subOptions.add(new Option(menuData[mainCategoryId][subCategoryId].sub[i], i));
        }
    } catch(e) {
        //
    }
}

function do_void() {
}

function getAtPlace(place) {
    if (place > 1) {
        return getAtPlace(place - 1) + getAtPlace(place - 2);
    } else if (place == 1) {
        return 1;
    } else if (place == 0) {
        return 1;
    }
}

var globalHeightPerLine = 10;

function openMenu(index, count, instant) {
    if (index >= 0 && document.getElementById("category_" + index) && document.getElementById("category_" + index).style.display != "inline") {
        var selObj = null;
        
        for (var i = 0; i < 100; i++) {
            var obj = document.getElementById("category_" + i);
            if (index == i) {
                selObj = obj;
            } else {
                if (obj) {
                    obj.style.display = "none";
                }
            }
        }

        var offset = 0;
        selObj.style.overflow = "hidden";
        selObj.style.height = "1px";
        selObj.style.display = "block";
        
        if (!instant) {
            var timer = setInterval(function() {
                selObj.style.height = getAtPlace(offset) + "px";
                if (getAtPlace(offset++) >= globalHeightPerLine * count) {
                    selObj.style.display = "inline";
                    clearInterval(timer);
                }
            }, 40);
        } else {
            selObj.style.display = "inline";
        }
    }
}

function openSMenu(index, mainIndex, mainCount, count) {
    if (count > 0 && document.getElementById("sub_category_" + mainIndex + "_" + index).style.display != "inline") {
        var selObj = null;
        
        for (var i = 1; i <= mainCount; i++) {
            var obj = document.getElementById("sub_category_" + mainIndex + "_" + i);
            if (index == i) {
                selObj = obj;
            } else {
                obj.style.display = "none";
            }
        }

        var offset = 0;
        selObj.style.overflow = "hidden";
        selObj.style.height = "1px";
        selObj.style.display = "block";
        
        var subTimer = setInterval(function() {
            selObj.style.height = getAtPlace(offset) + "px";
            if (getAtPlace(offset++) >= globalHeightPerLine * count) {
                selObj.style.display = "inline";
                clearInterval(subTimer);
            }
        }, 40);
    }
}