﻿var INDEXPAGE = {
    switchArticle: function(obj) {
        SoDao.G('hotarticlebutton_1').className = "";
        SoDao.G('hotarticlebutton_2').className = "";
        SoDao.G('hotarticlebutton_3').className = "";
        obj.className = "on";
        SoDao.GS('hotarticle_1').display = "none";
        SoDao.GS('hotarticle_2').display = "none";
        SoDao.GS('hotarticle_3').display = "none";
        SoDao.GS('hotarticle_' + obj.id.replace("hotarticlebutton_", "")).display = "block";
    },
    login: function() {
        var un = $('#in_username').val();
        if (!SoDao.isUserName(un)) {
            INDEXPAGE.showLoginTip('username_tip', '用户名输入错误');
            setTimeout("INDEXPAGE.hideLoginTip('username_tip')", 2000);
            return;
        }
        if ((SoDao.getStringLength(un) < 5 || SoDao.getStringLength(un) > 18)) {
            INDEXPAGE.showLoginTip('username_tip', '用户名输入错误');
            setTimeout("INDEXPAGE.hideLoginTip('username_tip')", 2000);
            return;
        }
        var pwd = $('#in_password').val();
        if (SoDao.isEmpty(pwd)) {
            INDEXPAGE.showLoginTip('passpord_tip', '密码不能为空');
            setTimeout("INDEXPAGE.hideLoginTip('passpord_tip')", 2000);
            return;
        }
        if (SoDao.getStringLength(pwd) < 5 || SoDao.getStringLength(pwd) > 32) {
            INDEXPAGE.showLoginTip('passpord_tip', '密码输入错误');
            setTimeout("INDEXPAGE.hideLoginTip('passpord_tip')", 2000);
            return;
        }
        var auto = SoDao.G('setCookieCheck').checked ? "1" : "0";
        INDEXPAGE.showLoginTip('passpord_tip', '登录中......');
        $.post("/inc/Index_GetLoginModule_Login.aspx?dt=" + SoDao.getdatetime(), { SiteFrom: "i.sodao.com", UserName: un, Passpord: pwd, AutoLogin: auto },
                    function(data) {
                        if (data != "success") {
                            INDEXPAGE.showLoginTip('passpord_tip', '登录信息错误');
                            setTimeout("INDEXPAGE.hideLoginTip('passpord_tip')", 2000);
                        }
                        else {
                            SoDao.alertDiv.hide(); INDEXPAGE.showLogin(); INDEXPAGE.showTopLogin();
                        }
                    });
    },
    showLogin: function() {
        $.get("/inc/Index_GetLoginModule.aspx?dt=" + SoDao.getdatetime(), { SiteFrom: "i.sodao.com" },
                    function(data) {
                        SoDao.G('indexLoginModule').innerHTML = data;
                    });
    },
    showLoginTip: function(objid, innerHTML, auotClose) {
        SoDao.G(objid).innerHTML = innerHTML;
        SoDao.G(objid).style.display = "block";
    },
    hideLoginTip: function(objid) {
        SoDao.G(objid).style.display = "none";
    },
    showTopLogin: function() {
        $.get("/inc/Index_GetTopLoginModule.aspx?dt=" + SoDao.getdatetime(), { SiteFrom: "i.sodao.com" },
                    function(data) {
                        SoDao.G('top-bar').innerHTML = data;
                    });
    },
    getMsgCount: function() {
        try {
            $.get("/msg/getcount?dt=" + SoDao.getdatetime(), { un: $('#logineduserName').val() },
                    function(data) {
                        $("#_msgcount").html(data);
                    });
        }
        catch (e) { }
    },
    showAddFriendMsgDialog: function(obj, tousername) {
        var msgObj = SoDao.G(obj.id.replace("_", "b_"));
        if (msgObj.style.display != "block") {
            $.get("/inc/Index_GetAddFriendAndMsg.aspx?dt=" + SoDao.getdatetime(), { SiteFrom: "i.sodao.com", ToUserName: tousername },
                    function(data) {
                        msgObj.innerHTML = data;
                    });
        }
        msgObj.style.display = "block";
    },
    hideAddFriendMsgDialog: function(obj) {
        SoDao.GS(obj.id.replace("_", "b_")).display = "none";
    },
    initProvince: function(objid, code) {
        $.get("/sys/getareadata?dt=" + SoDao.getdatetime(), { pcode: code }, function(data) { $("#" + objid).html(data); });
    },
    searchFriend: function() {

        var url = "/sys/usearchsp?f=sodao";
        url += "&xa=" + $('#drpMinAge').val() + "&da=" + $('#drpMaxAge').val();
        if (SoDao.G("ckBoy").checked) {
            url += "&sex1=1";
        }
        else {
            url += "&sex1=0";
        }
        if (SoDao.G("ckGirl").checked) {
            url += "&sex2=1";
        }
        else {
            url += "&sex2=0";
        }
        if (SoDao.G("ckOther").checked) {
            url += "&sex3=1";
        }
        else {
            url += "&sex3=0";
        }
        url += "&jd=" + INDEXPAGE.searchFriendGetCode();
        url += "&all=" + INDEXPAGE.encodeStr($('#allField').val());
        top.window.location.href = url;
    },
    searchFriendGetCode: function() {
        if ($('#drpCity').val() != "-1") {
            return $('#drpCity').val();
        }
        if ($('#drpProvince').val() != "-1") {
            return $('#drpProvince').val();
        }
        return "";
    },
    encodeStr: function(val) {
        return (val == "" ? "" : (UTF8.Encode(val)));
    },
    userRegNumShow: function() {
        INDEXPAGE.userRegNumShowDo();
        setInterval("INDEXPAGE.userRegNumShowDo()", 1000 * 60);
    },
    userRegNumShowDo: function() {
        $('#userregNum').html('加载中...');
        $.get("/inc/index_GetUserRegNum.aspx?dt=" + SoDao.getdatetime(), { fromsite: "i.sodao.com" }, function(data) { $("#userregNum").html(data); });
    },
    getZuiXinUpdateSpace: function() {
        $('#zuixinupdatespace').html('加载中...');
        $.get("/pagepreview/zuixinupdatespace.shtml?dt=" + SoDao.getdatetime(), { fromsite: "i.sodao.com" }, function(data) { $("#zuixinupdatespace").html(data); });
    }
};