﻿// JScript 文件

// 窗体加载后事件
$(document).ready(function ()
{
    // 信息鼠标悬浮和离开改变字体颜色
    $(".context_1 ul li").hover(function()
    {
        $(this).css("color", "#E00015");
    }, function()
    {
        $(this).css("color", "#2A2A2A");
    }).click(function() // 信息点击事件
    {
        if(this.value == "0" || this.value == "" || this.value == "-1")
        {
            if(this.id != "" && !isNaN(this.id))
            {
                // alert(this.id);
                window.open(newsPath + "News/News.aspx?id=" + this.id);
            }
        }
        else
        {
            window.open(newsPath + "News/NewsList.aspx?cid=" + this.value + "&gid=" + $(".hideGidClass").val());
        }
    });

    // 信息鼠标悬浮和离开改变字体颜色
    $(".context_2 ul li").hover(function()
    {
        $(this).css("color", "#E00015");
    }, function()
    {
        $(this).css("color", "#2A2A2A");
    }).click(function() // 信息点击事件
    {
        if(this.id != "" && !isNaN(this.id))
        {
            // alert(this.id);
            window.open(webPath + "Announ/Announce.aspx?id=" + this.id);
        }
    });

    // 信息鼠标悬浮和离开改变字体颜色
    $(".context_3 ul li").hover(function()
    {
        $(this).css("color", "#E00015");
    }, function()
    {
        $(this).css("color", "#2A2A2A");
    }).click(function() // 信息点击事件
    {
        if(this.id != "" && !isNaN(this.id))
        {
            window.open(newsPath + "News/News.aspx?id=" + this.id);
        }
    });
    
    // 信息鼠标悬浮和离开改变字体颜色
    $(".hot_Desc ul li").hover(function()
    {
        $(this).css("color", "#E00015");
    }, function()
    {
        $(this).css("color", "#2A2A2A");
    }).click(function() // 信息点击事件
    {
        if(this.id != "" && !isNaN(this.id))
        {
            window.open(newsPath + "News/News.aspx?id=" + this.id);
        }
    });
    
    // 信息鼠标悬浮和离开改变字体颜色
    $(".hot_Desc_1 ul li").hover(function()
    {
        $(this).css("color", "#E00015");
    }, function()
    {
        $(this).css("color", "#2A2A2A");
    }).click(function() // 信息点击事件
    {
        if(this.id != "" && !isNaN(this.id))
        {
            window.open(webPath + "Announ/Announce.aspx?id=" + this.id);
        }
    });

    // 更多按钮点击事件
    $(".more").click(function()
    {
        window.open(newsPath + "News/News_Index.aspx?gid=" + this.id);
    });

    // 更多按钮点击事件
    $(".moreZ").click(function()
    {
        window.open(webPath + "News/ExhibList.aspx?gid=" + this.id);
    });
    
    // 获取登录信息
    if($("#loginIn")[0])
    {
        isLogined = ($(".isLoginIn").val() == "1");
        if(!isLogined)
        {
            numkey = Math.round(numkey * 10000);
            
            $.getJSON(bbsHost + "eric-ashx/GetCurrentUser.ashx?jsoncallback=?", {"temp" : numkey}, function(data)
            {
                // 当数据不为空时，将数据赋给容器，并显示
                if(data.BFlag == "True")
                {
                    isLogined = true;
                    
                    uid = data.Id;
                    uName = data.Uname;
                    pwd = data.Pwd;
                    showName = data.ShowName;
                    
                    if(data.IsManage == "True")
                    {
                        IsManage = true;
                    }
                    
                    $(".lblUName").html(unescape(unescape(showName)));
                    
                    // 设置登录 Div
                    SetLoginDiv();
                    // 将登录信息赋值到站点 Session
                    SetSessionValue();
                }
                else
                {
                    $("#loginOut").show();
                    $("#loginIn").hide();
                }
            });
        }
        else
        {
            uid = $(".uid").val();
            // 显示登录 DIV
            SetLoginDiv();
        }
    }
    
    $(".btnLogin").click(function()
    {
        var $Uname = $("#txtName");
        var $Pwd = $("#txtPwd");
        var $Code = $("#txtValiCode");
        
        uName = $Uname.val();
        pwd = $Pwd.val();
        var txtCode = $Code.val();
        
        if($.trim(uName) == "")
        {
            alert("登录失败：用户名不能为空！");
            $Uname.focus();
            return false;
        }
        else if($.trim(pwd) == "")
        {
            alert("登录失败：密码不能为空！");
            $Pwd.focus();
            return false;
        }
        else if($.trim(txtCode) == "")
        {
            alert("登录失败：验证码不能为空！");
            $Code.focus();
            return false;
        }
        
        numkey = Math.round(numkey * 10000);
        
        $.getJSON(webPath + "Ajax/Operator/ValiCode.ashx", {"code" : txtCode, "temp" : numkey}, function(validate)
        {
            if(validate[0].bFlag == "True")
            {
                $.getJSON(bbsHost + "eric-ashx/User_Login.ashx?jsoncallback=?",
                    {"username" : uName, "pwd" : pwd, "temp" : numkey}, function(data)
                {
                    // 当数据不为空时，将数据赋给容器，并显示
                    if(data.BFlag == "True")
                    {
                        isLogined = true;
                        
                        uid = data.Id;
                        pwd = data.Pwd;
                        showName = data.ShowName;
                        
                        if(data.IsManage == "True")
                        {
                            IsManage = true;
                        }
                        
                        $(".lblUName").html(uName);
                        
                        alert("操作提示：登录成功！");
                        
                        // 设置登录 Div
                        SetLoginDiv();
                        // 将登录信息赋值到站点 Session
                        SetSessionValue();
                    }
                    else
                    {
                        alert("登录失败：您输入的用户名或密码有误！");
                    }
                });
                
                // if(!isLogined) alert("登录失败：服务器忙，请稍后再试！");
            }
            else
            {
                alert("登录失败：您输入的验证码错误！\n若看不清楚，请点击验证码图片，更换验证码！");
                
                // 更换验证码图片
                changeWeb();
            }
        });
        
        return false;
    });
    
    // 用户退出事件
    $(".btnLoginOut").click(function()
    {
        $.getJSON(bbsHost + "eric-ashx/User_Logout.ashx?jsoncallback=?", function(data)
        {
            // 当数据不为空时，将数据赋给容器，并显示
            if(data.BFlag == "True")
            {
                ClearSessionValue();
                isLogined = false;
                $("#loginIn").hide();
                $("#loginOut").show();
                alert("操作成功：退出成功！");
            }
        }); 
    });
    
    $("#btnSearch").click(function()
    {
        if($(".search_keyword").val() != "")
        {
            var hrefSearch = $(".all_search").val();
            if(hrefSearch == "2")
            {
                hrefSearch = busyPath + "Search/search_news.aspx?keyWord=" + escape($(".search_keyword").val());
            }
            else if(hrefSearch == "3")
            {
                hrefSearch = busyPath + "Search/search_study.aspx?keyWord=" + escape($(".search_keyword").val());
            }
            else if(hrefSearch == "4")
            {
                hrefSearch = busyPath + "Search/search_enter.aspx?keyWord=" + escape($(".search_keyword").val());
            }
            else
            {
                hrefSearch = busyPath + "Search/Search.aspx?keyWord=" + escape($(".search_keyword").val());
            }
            window.open(hrefSearch);
        }
        else
        {
            alert("搜索的关键词不能为空，请输入搜索的关键词！");
        }
    });
});

// 显示登录 DIV
function SetLoginDiv()
{
    $("#loginOut").hide();
    $("#loginIn").show();
}

// 清除 Session 值
function ClearSessionValue()
{
    numkey = Math.round(numkey * 10000);
    $("#txtName").val("");
    $("#txtPwd").val("");
    $("#txtValiCode").val("");
    $.getJSON(webPath + "Ajax/Operator/ClearSession.ashx", {"temp" : numkey}, function(data)
    {
        // 当数据不为空时，将数据赋给容器，并显示
        if(data[0].bFlag == "True")
        {
            isLogined = false; 
        }
    });
}

// 顶一下
function Ding(id)
{
    numkey = Math.round(numkey * 10000);
    $.getJSON(webPath + "Ajax/News/ModifyTopDown.ashx?jsoncallback=?", {"id" : id, "state" : 1, "temp" : numkey}, function(data)
    {
        var leng = data.length;
        if(leng > 0)
        {
            var ret = data[0].Result;
            if(ret == "1")
            {
                $up = $("#u_" + id);
                var click_value = 0;
                try
                {
                    click_value = parseInt($.trim($up.html())) + 1;
                }
                catch(e)
                {
                    click_value = 1;
                }
                $up.html(click_value);
            }
            else if(ret == "2")
            {
                alert(data[0].Msg);
            }
        }
        else
        {
            alert("操作失败：服务器忙，请稍后再试！");
        }
    });
}

// 踩一下
function Cai(id)
{
    numkey = Math.round(numkey * 10000);
    $.getJSON(webPath + "Ajax/News/ModifyTopDown.ashx?jsoncallback=?", {"id" : id, "state" : 2, "temp" : numkey}, function(data)
    {
        var leng = data.length;
        if(leng > 0)
        {
            var ret = data[0].Result;
            if(ret == "1")
            {
                $down = $("#d_" + id);
                var click_value = 0;
                try
                {
                    click_value = parseInt($.trim($down.html())) + 1;
                }
                catch(e)
                {
                    click_value = 1;
                }
                $down.html(click_value);
            }
            else if(ret == "2")
            {
                alert(data[0].Msg);
            }
        }
        else
        {
            alert("操作失败：服务器忙，请稍后再试！");
        }
    });
}

// 跳转到个人空间
function ToSpace()
{
    window.location.href = bbsHost + "?space/" + uid;
}
