﻿///<reference path="jquery-vsdoc.js"/>

//UserIcon
$(document).ready(function() {
    var userHead = $("div.div_user_pic,div.div_user_pic_s");

    userHead.hover(function() {
        $("span.bar", this).slideDown("normal");
    }, function() {
        //$("span.bar", this).slideUp("normal");
        var bar = $("span.bar", this);
        setTimeout(function() { bar.slideUp("normal"); }, 500);
    });

    userHead.each(function() {
        var fb = $("span.span_fb", this);
        $("a[rel='AddContact']", this).click(function() {
            fb.html("添加成功");
            fb.fadeIn("normal");
            setTimeout(function() { fb.fadeOut("normal"); }, 2000);
        });
    });

});



//调整Sidebar高度
function SidebarHeight(strA, strB) {
    var a = document.getElementById(strA);
    var b = document.getElementById(strB);
    if (a != null && b != null) {
        if (a.clientHeight < b.clientHeight) {
            a.style.height = b.clientHeight + "px";
        }
        else {
            b.style.height = a.clientHeight + "px";
        }
    }
}

//滚动条定位
function showScrollItem(clientID) {
    var item = document.getElementById(clientID);
    if (item)
        item.scrollIntoView();
}

//浮动层的显示与隐藏
function showFloat(cover, id) {
    var objCover = document.getElementById(cover);
    var objId = document.getElementById(id);
    var scrollW = document.documentElement.scrollWidth;
    var scrollH = document.documentElement.scrollHeight;
    objCover.style.width = scrollW + "px";
    objCover.style.height = scrollH + "px";
    objCover.style.display = "block";
    objId.style.display = "block";
}
function hideFloat(cover, id) {
    var objCover = document.getElementById(cover);
    var objId = document.getElementById(id);
    objCover.style.display = "none";
    objId.style.display = "none";
}

//全选
function checkAll(chk, eleName) {
    var state = chk.checked;

    var ele = document.getElementById(eleName);

    if (ele) {
        var control = ele.getElementsByTagName('input');

        for (var i = 0; i < control.length; i++) {
            if (control[i] != chk) {
                control[i].checked = state;
            }
        }
    }
}

function showAllSelect() {
    var control = document.getElementsByTagName('select');
    for (var i = 0; i < control.length; i++) {
        control[i].style.display = "";
    }
}

function hideAllSelect() {
    var control = document.getElementsByTagName('select');
    for (var i = 0; i < control.length; i++) {
        control[i].style.display = "none";
    }
}

function SwitchShow(strA, strB) {
    var a = document.getElementById(strA);
    var b = document.getElementById(strB);
    if (a != null && b != null) {
        a.style.display = "none";
        b.style.display = "";
    }
}

function selectTag(showContent, selfObj) {
    // 操作标签
    var tag = document.getElementById("ulTag").getElementsByTagName("li");
    var taglength = tag.length;
    for (i = 0; i < taglength; i++) {
        if (tag[i].className != "more") {
            tag[i].className = "";
        }
    }
    selfObj.parentNode.className = "active";

    // 操作内容
    for (i = 0; j = document.getElementById("tagContent" + i); i++) {
        j.style.display = "none";
    }
    document.getElementById(showContent).style.display = "block";
}

//设置图片最大尺寸
function RatImg(Img, w, h) {
    var image = new Image();
    image.src = Img.src;

    var x = image.width;
    var y = image.height;

    if (x > w) {
        var bl_x = w / x;
        var bl_y = h / y;
        if (bl_x < bl_y) {
            bl = bl_x;
        }
        else {
            bl = bl_y;
        }
        x = x * bl;
        y = y * bl;
    }
    else {
        if (y > h) {
            bl = h / y;
            y = h;
            x = x * bl;
        }
    }

    Img.width = x;
    Img.height = y;
}

//设定文本框内按回车键时触发的事件
function setEnterKeyAction(input, func) {
    $(input).keypress(function(e) {
        var code = (e.keyCode ? e.keyCode : e.which);
        if (code == 13) {
            func();
        }
    });
}