
function inputSelectLineItem(iValue, iText, iParent) {
    var self = this;
    this.parent = iParent;
    this.value  = iValue;
    this.text   = iText;

    this.container = null;

    this.over = function() {
        this.container.style.fontWeight = "normal";
        this.container.style.color = "black";
        this.container.style.textDecoration = "none";
    }

    this.out = function() {
        if (this.parent.lastItem == this) this.over();
        else {
            this.container.style.fontWeight = "normal";
            this.container.style.color = "#0063DC";
            this.container.style.textDecoration = "underline";
        }
    }

    this.select = function() {
        this.parent.selectItem(this);
    }

    this.construct = function() {
        this.container = document.createElement("SPAN");
        this.container.style.cursor = "pointer";
        this.container.innerHTML = this.text;
        this.container.onmouseover = function() { self.over(); }
        this.container.onmouseout = function() { self.out(); }
        this.container.onclick = function() { self.select(); }

        this.parent.container.appendChild(this.container);
        
        this.out();
    }

    this.construct();
}

function inputSelectLine(iName, iObj) {
    var self = this;
    this.name = iName;
    this.container = iObj;
    this.inputElement = null;

    this.options = new Array();
    this.selectedIndex = -1;
    this.lastItem = null;
    this.onchange = null;

    this.insertItem = function(iValue, iText) {
        if (this.options.length != 0) {
            var spaceEl = document.createElement("SPAN");
            spaceEl.innerHTML = "&nbsp;&nbsp;|&nbsp;&nbsp;";
            this.container.appendChild(spaceEl);
        }

        this.options[this.options.length] = new inputSelectLineItem(iValue, iText, this);
    }

    this.selectItemIndex = function(iIndex) {
        if (iIndex != this.selectedIndex) {
            var tmpItem = this.lastItem;
            this.lastItem = this.options[iIndex];
            this.selectedIndex = iIndex;
            this.inputElement.value = this.options[iIndex].value;
            if (tmpItem != null) tmpItem.out();
            this.lastItem.over();

            if (this.onchange != null) this.onchange();
        }
    }

    this.selectItem = function(iRef) {
        var founded = false;
        var pos = 0;

        while (!founded && pos < this.options.length)
            if (this.options[pos] == iRef) founded = true;
            else pos++;

        if (founded)
            this.selectItemIndex(pos);
    }

    this.selectItemValue = function(iValue) {
        var founded = false;
        var pos = 0;
        
        while (!founded && pos < this.options.length)
            if (this.options[pos].value == iValue) founded = true;
            else pos++;
            
        if (founded)
            this.selectItemIndex(pos);
    }

    this.construct = function() {
        this.inputElement = document.createElement("INPUT");
        this.inputElement.type = "hidden";
        this.inputElement.name = this.name;
        this.inputElement.value = 0;
        
        this.container.innerHTML = "";
        this.container.appendChild(this.inputElement);
    }

    this.construct();
}

