﻿
function SelectListFunc()
{
    var reciever = null;

    this.SetValue = function(val, name)
    {
        if (reciever != null)
        {
            reciever.setAttribute("val", val);
            reciever.innerHTML = name;
            this.Close();
            var accMethod = reciever.getAttribute("amt");
            if (accMethod != null && accMethod != "" && accMethod != undefined)
            {
                eval(accMethod);
            }
        }
    }

    this.SetHook = function(target, evt)
    {
        if (window.event)
        {
            event.cancelBubble = true;
        }
        else
        {
            evt.stopPropagation();
        }
        var v = $("_SelectListDiv");
        if (v.style.display != "none" && reciever != null && reciever.id == target.id)
        {
            v.style.display = "none";
            return;
        }
        reciever = target;

        var point = getPos(target);
        v.style.left = point.x + "px";
        v.style.top = point.y + target.offsetHeight + "px";
        v.style.width = target.offsetWidth - 2 + "px";

        var val = reciever.getAttribute("va");
        val = val.split(",");
        var vil = reciever.getAttribute("vi");
        vil = vil.split(",");
        var str = "";
        for (var i = 0; i < val.length; i++)
        {
            str += "<div class='commonPopChildDiv' onmouseover=\"this.className='commonPopChildDiv_Act'\" onmouseout=\"this.className='commonPopChildDiv'\" onclick=\"SelectList.SetValue('" + vil[i] + "', '" + val[i] + "')\">" + val[i] + "</div>";
        }
        if (val.length > 10)
        {
            v.className = "commonPopDivMul";
            v.style.height = "204px";
        }
        else
        {
            v.className = "commonPopDiv";
            if (val.length == 0)
            {
                v.style.height = "104px";
            }
            else
            {
                v.style.height = val.length * 20 + 4 + "px";
            }
        }

        v.innerHTML = str
        v.style.display = "block";
    }

    this.Close = function()
    {
        var v = $("_SelectListDiv");
        if (v)
        {
            v.style.display = "none";
        }
    }
}
document.write("<div id='_SelectListDiv' class='commonPopDiv'></div>");
var SelectList = new SelectListFunc();