﻿/**********************************/
function show(textid, listid) {
    var txtName = $("#" + textid);
    var tooltip = $("#" + listid);
    var pos = txtName.position();
    tooltip.css("top", pos.top + txtName.outerHeight());
    tooltip.css("left", pos.left - parseInt(tooltip.css("margin-left")));
    var paddingWidth = tooltip.outerWidth() - tooltip.width(); //测试得出：PaddingWidth=(tooltip.innerWidth-tooltip.width)/2; InnerWidth=OuterWidth
    tooltip.width(txtName.outerWidth() - paddingWidth);        //alert(tooltip.innerWidth() + " "+tooltip.width()+" "  + tooltip.outerWidth());
    tooltip.show();
    

}

function hide(listid) {
    $("#" + listid).hide();
}
function bindlist(textid, listid, arr, fn) {

    if (arr.length == 0) {
        $("#" + listid).empty();
        $("#" + listid).hide();
        $("#" + textid).attr("cvalue", "0");
        $("#"+  textid).attr("ccode","");
        return;
    }

    var html = "<ul displytype=\"list\">";
    for (var i = 0; i < arr.length; i++) {

        html += "<li ccode=\""+arr[i].code+"\" cvalue=\"" + arr[i].id + "\"  displytype=\"list\">";
        html += arr[i].name;
        html += "</li>";
    }
    html += "</ul>";

    $("#" + listid).html(html);
    $("#" + listid + " li").click(function() {

        var cvalue = $(this).attr("cvalue");
        var ccode = $(this).attr("ccode");
        $("#" + textid).attr("cvalue", cvalue);
        $("#" + textid).attr("ccode", ccode);
        $("#" + textid).val($(this).text());
        $("#" + listid).hide();

        if ($.isFunction(fn)) {
            fn();
        }
    });

    $("#" + listid + " ul").addClass("ulCss");
    $("#" + listid + " li").addClass("liCss");
    $("#" + listid + " li").hover(
                 function() {
                     $(this).removeClass("liCss");
                     $(this).addClass("liOverCss");
                 },
                 function() {
                     $(this).removeClass("liOverCss");
                     $(this).addClass("liCss");
                 }
                 );

}
/****************************************/
//casecade dropdown list with select html control
/****************************************/

function bindDropList(id, arr, fn) {
    //            debugger;
    $("#" + id).html("");
    var optionHtml = "<option ccode='' value=\"0\">请选择</option>";
    for (var i = 0; i < arr.length; i++) {
        optionHtml += "<option ccode=\"" + arr[i].code + "\" value=\"" + arr[i].id + "\">" + arr[i].name + "</option>";
        //                alert(arr[i].code);
    }
    $("#" + id).append(optionHtml);
    if ($.isFunction(fn)) {
        fn();
    }
}