//select box를 위한 js

var Ui = {};

Ui.SelectBox = function() {
    this.current = null;
    this.aSelectBox = [];
};

Ui.SelectBox.prototype = {

// selectbox id를 추가.
    add : function(id) {
        this.aSelectBox.push(id);
    },

// 현재 선택된 selectBox의 위치를 셋팅한다.
    setCurrnet : function(id) {
        for (var i = 0; i < this.aSelectBox.length; i++) {
            if (this.aSelectBox[i] == id)  this.current = i;
        }
    },

// pos에 의하여 현재 선택되어 있는 selectBox관련 객체를 가져온다.
    getBox : function(pos) {
        switch (pos) {
            case 'front':
                return document.getElementById(this.aSelectBox[this.current - 1]);
                break;
            case 'currnet':
                return document.getElementById(this.aSelectBox[this.current]);
                break;
            case 'next':
                return document.getElementById(this.aSelectBox[this.current + 1]);
                break;
            default :
                return null;
                break;
        }
    },

// id 값에 해당하는 selectBox를 초기화 한다. vPassId는 제외
    clearBox : function(id,vPassId) {
    	if(vPassId == "Clear"){
   		 	document.getElementById(id).length = 0;
    	}else if(id != vPassId){
	    	document.getElementById(id).length = 1;
   		 	document.getElementById(id).value = 0;
    		document.getElementById(id)[0].selected = 'selected';
		}	          
    },

// 모든 selectBox의 option 값을 초기화 한다.
    clearBoxAll : function() {
        for (var i = 0; i < this.aSelectBox.length; i++) {
            this.clearBox(this.aSelectBox[i]);
        }
    },

// id 값에 해당하는 selectBox 하위의 모든 selectBox를 초기화 한다.
    clearBoxLowThis : function(id,vPassId) {
        var index = this.aSelectBox.length;
        for (var i = 0; i < this.aSelectBox.length; i++) {
            if (this.aSelectBox[i] == id) {
                index = i;
            }
            if (i > index) {       	
                this.clearBox(this.aSelectBox[i],vPassId);
            }
        }
    },

// selectBox의 option을 생성 입력한다.
    setBoxOption : function(id, ajOption, setValue) {
        var selectBox = document.getElementById(id);
        selectBox.length = 0;

        if (setValue == null) setValue = 0;
        for (var i = 0; i < ajOption.length; i++) {
            var option = document.createElement("OPTION");
            option.text = ajOption[i].text;
            option.value = ajOption[i].value;
            selectBox[i] = option;

            if (setValue == option.value) selectBox[i].selected = "selected";
        }
    },

//selectBox의 option중에 현재 선택되어있는 것을 반환한다.
    getBoxOptionIsSelected : function(boxId) {
        var selectBox = document.getElementById(boxId);
        var maxLength = selectBox.length;
        for (var i = 0; i < maxLength; i++) {
            var option = selectBox.getElementsByTagName("OPTION")[i];
            if (option.selected) {
                return option;
            }
        }
    }
}
