﻿  $(function() { 
    var moveUp = function() {
        //向上移动子项目
        var link = $(this),
		dl = link.parents("div").parents("div");
        dl.next().eq(0).slideToggle("slow", function() {
            //        alert(link.html());
        });
    };


    //登录
        $("#login").click(function() { 
            if ($.trim($("#txtUsername").val()).length == 0) {
                alert("请填写用户名");
                return;
            }
            if ($.trim($("#txtPassword").val()).length == 0) {
                alert("请填写登录密码");
                return;
            }
        
            var username = escape($.trim($("#txtUsername").val()));
            var password = escape($.trim($("#txtPassword").val()));
          
            $.post(
            "/ajax/ajaxuserlogin.aspx",
            { Action: "post",
                username: username,
                password: password
            },
            function(data) {
                if (data == "true") {
                    
                    $("#my_login").hide();
                    $("#my_index").show();
                    sunimage($("#hidSun").val());
                    moonimage($("#hidMoon").val());
                    starimage($("#hidStar").val());
                    window.location.href=window.location.href;
                    $("#my_index").show();
                }
                else {
                    $("#my_login").show();
                    $("#my_index").hide();
                    alert("用户名或者密码不正确！");
                }
            });
      });

    function sunimage(grade){
        if (grade==1){
            $("#usergrade").append("<img src='/images/sun.gif' />");
        }
        else if (grade==2){
            $("#usergrade").append("<img src='/images/sun.gif' /><img src='/images/sun.gif' />");
        }
        else if (grade==3){
            $("#usergrade").append("<img src='/images/sun.gif' /><img src='/images/sun.gif' /><img src='/images/sun.gif' />");
        }
    }
    
    function moonimage(grade){
        if (grade==1){
            $("#usergrade").append("<img src='/images/moon.gif' />");
        }
        else if (grade==2){
            $("#usergrade").append("<img src='/images/moon.gif' /><img src='/images/moon.gif' />");
        }
        else if (grade==3){
            $("#usergrade").append("<img src='/images/moon.gif' /><img src='/images/moon.gif' /><img src='/images/moon.gif' />");
        }
    }
    
    function starimage(grade){
        if (grade==1){
            $("#usergrade").append("<img src='/images/star.gif' />");
        }
        else if (grade==2){
            $("#usergrade").append("<img src='/images/star.gif' /><img src='/images/star.gif' />");
        }
        else if (grade==3){
            $("#usergrade").append("<img src='/images/star.gif' /><img src='/images/star.gif' /><img src='/images/star.gif' />");
        }
    }
    
    function sunimage1(grade){
        if (grade==1){
            $("#usergrade1").append("<img src='/images/sun.gif' />");
        }
        else if (grade==2){
            $("#usergrade1").append("<img src='/images/sun.gif' /><img src='/images/sun.gif' />");
        }
        else if (grade==3){
            $("#usergrade1").append("<img src='/images/sun.gif' /><img src='/images/sun.gif' /><img src='/images/sun.gif' />");
        }
    }
    
    function moonimage1(grade){
        if (grade==1){
            $("#usergrade1").append("<img src='/images/moon.gif' />");
        }
        else if (grade==2){
            $("#usergrade1").append("<img src='/images/moon.gif' /><img src='/images/moon.gif' />");
        }
        else if (grade==3){
            $("#usergrade1").append("<img src='/images/moon.gif' /><img src='/images/moon.gif' /><img src='/images/moon.gif' />");
        }
    }
    
    function starimage1(grade){
        if (grade==1){
            $("#usergrade1").append("<img src='/images/star.gif' />");
        }
        else if (grade==2){
            $("#usergrade1").append("<img src='/images/star.gif' /><img src='/images/star.gif' />");
        }
        else if (grade==3){
            $("#usergrade1").append("<img src='/images/star.gif' /><img src='/images/star.gif' /><img src='/images/star.gif' />");
        }
    }
    
    $("#dailylink").hover(function(){
            $.post(
            "/ajax/ajaxislogin.aspx",
            { Action: "post"
            },
            function(data) {
                if (data == "true") {
                    $("#my_daily").show();
                    $("#my_index").hide();
                    $("#my_login").hide();
                    $("#my_collect").hide();
                    $("#my_msg").hide();
                    $("#my_scheduling").hide();
                    $("#my_firend").hide();
                }
                else {
                }
            })
            
        });
        
        $("#collectlink").hover(function(){
            $.post(
            "/ajax/ajaxislogin.aspx",
            { Action: "post"
            },
            function(data) {
                if (data == "true") {
                    $("#my_collect").show();
                    $("#my_index").hide();
                    $("#my_login").hide();
                    $("#my_daily").hide();
                    $("#my_msg").hide();
                    $("#my_scheduling").hide();
                    $("#my_firend").hide();
                }
                else {
                }
            })
            
        });
        
        $("#msglink").hover(function(){
            $.post(
            "/ajax/ajaxislogin.aspx",
            { Action: "post"
            },
            function(data) {
                if (data == "true") {
                    $("#my_msg").show();
                    $("#my_index").hide();
                    $("#my_login").hide();
                    $("#my_daily").hide();
                    $("#my_collect").hide();
                    $("#my_scheduling").hide();
                    $("#my_firend").hide();
                }
                else {
                }
            })
            
        });
        
        $("#schedulinglink").hover(function(){
            $.post(
            "/ajax/ajaxislogin.aspx",
            { 
                Action: "post"
            },
            function(data) {
                if (data == "true") {
                    $("#my_scheduling").show();
                    $("#my_msg").hide();
                    $("#my_index").hide();
                    $("#my_login").hide();
                    $("#my_daily").hide();
                    $("#my_collect").hide();
                    $("#my_firend").hide();
                }
                else {
                }
            })
            
        });
   
        
         $("#indexlink").hover(function(){
            $.post(
            "/ajax/ajaxislogin.aspx",
            { 
                Action: "post"
            },
            function(data) {
                if (data == "true") {
                    $("#my_index").show();
                    $("#my_msg").hide();
                    $("#my_scheduling").hide();
                    $("#my_login").hide();
                    $("#my_daily").hide();
                    $("#my_collect").hide();
                    $("#my_firend").hide();
                }
                else {
                }
            })
            
        });
   
        $("#friendlink").hover(function(){
            $.post(
            "/ajax/ajaxislogin.aspx",
            { 
                Action: "post"
            },
            function(data) {
                if (data == "true") {
                    $("#my_firend").show();
                    $("#my_msg").hide();
                    $("#my_scheduling").hide();
                    $("#my_login").hide();
                    $("#my_daily").hide();
                    $("#my_collect").hide();
                    $("#my_index").hide();
                }
                else {
                }
            })
            
        });


        //引用主页面中的所有块
//        var els = ['#centerContent_left', '#centerContent_center', '#centerContent_right'];
//        var $els = $(els.toString());

        //绑定相关事件

        $("a.up").bind("click", moveUp);
//        $("#login").bind("click", fnlogin);
//        $("#btnSave").bind("click", saveWebPart);
        
        sunimage($("#hidSun").val());
        moonimage($("#hidMoon").val());
        starimage($("#hidStar").val());
                    
        sunimage1($("#hidSun").val());
        moonimage1($("#hidMoon").val());
        starimage1($("#hidStar").val());
                    
        if($("#hidStatus").val()=="daily"){
            $("#my_login").hide();
            $("#my_index").hide();
            $("#my_scheduling").hide();
            $("#my_firend").hide();
            $("#my_daily").show();
        }
        else if($("#hidStatus").val()=="collect"){
            $("#my_login").hide();
            $("#my_index").hide();
            $("#my_scheduling").hide();
            $("#my_firend").hide();
            $("#my_collect").show();
        }
        else if($("#hidStatus").val()=="msg"){
            $("#my_login").hide();
            $("#my_index").hide();
            $("#my_scheduling").hide();
            $("#my_firend").hide();
            $("#my_msg").show();
        }
        else if($("#hidStatus").val()=="scheduling"){
            $("#my_login").hide();
            $("#my_index").hide();
            $("#my_msg").hide();
            $("#my_firend").hide();
            $("#my_scheduling").show();
        }
        else if($("#hidStatus").val()=="friend"){
            $("#my_login").hide();
            $("#my_index").hide();
            $("#my_msg").hide();
            $("#my_scheduling").hide();
            $("#my_firend").show();
        }
        else{
            $.post(
            "/ajax/ajaxislogin.aspx",
            { 
                Action: "post"
            },
            function(data) {
                if (data == "true") {
                    $("#my_login").hide();
                    $("#my_index").show();
                }
                else {
                     $("#my_login").show();
                    $("#my_index").hide();
                }
            })
            
//            $("#login").bind("click", fnlogin);
        }


        

    });


