﻿
//鼠标移上去触发的事件
function OnFocusInputName() {
    if ($('#box_UserName').val() == "用户名") {
        $('#box_UserName').val('');
    }
}

String.prototype.replaceAll1 = function (s1, s2) { return this.replace(new RegExp(s1, "gm"), s2); }
//数据列表
function BindList(pageIndex) {
    var pageSize = 5;
    var mydate = {
        'PageIndex': pageIndex,
        'PageSize': pageSize
    };
    var result = ExecuteHelp("/home/getfeeds", mydate);
    if (result == null || result == "") {
        $("#divList").html("<div>暂无信息...</div>");
        return false;
    }
    var list = eval("(" + result + ")");

    var count = list.length;
    var totalCount = 0;
    var printHtml = '';
    for (var i = 0; i < count; i++) {
        var infoObj = list[i];
        var obj = list[i].data;
        var info = eval("(" + obj + ")");
        var picShow = "";
        if (info.feed_source == "company") {//企业
            picShow = "<a href=\"/company/home/" + info.feed_uid + "\"><img src=\"" + imageServeUrl + "/sysfolder/internship/companyuser/" + info.feed_uid + "/" + info.feed_uid + ".jpg\" onerror=\"this.src='" + imageServeUrl + normalImg + "';\"/ class=\"pic\"></a>";
        } else if (info.feed_source == "personal") { //个人
            picShow = "<a href=\"/personal/main/" + info.feed_uid + "\"><img src=\"" + imageServeUrl + "/sysfolder/internship/personallogo/" + info.feed_uid + "/" + info.feed_uid + ".jpg\" onerror=\"this.src='" + imageServeUrl + normalFace + "';\"/ class=\"pic\"></a>";
        } else {
            picShow = "<a href=\"/team/detail/" + info.feed_uid + "\"><img src=\"" + imageServeUrl + "/sysfolder/internship/teamlogo/" + info.feed_uid + "/" + info.feed_uid + ".jpg\" onerror=\"this.src='" + imageServeUrl + normalImg + "';\"/ class=\"pic\"></a>";
        }
        printHtml += "<li class=\"layout\" id=\"" + infoObj.feed_id + "\">" + picShow + "<div class=\"newsCon\">";

        if (infoObj.type == "weibo") {
            printHtml += "<h3>" + GetFaceContent(infoObj.content) + "</h3>"
        } else {
            printHtml += "<h3>" + infoObj.content + "</h3>"
        }
        printHtml += "<p class=\"mt5\">职业方向：" + info.position_category + "</p>" +
							"</div>" +
						"<span class=\"r time\">" + list[i].Time + "</span>" +
					 "</li>";
    }
    $('.friList').html($('.friList').html() + printHtml);

}

function GetFaceContent(content) {
    if (content != null) {
        var from = content.indexOf("http://");
        var shortUrl = "";
        if (from != -1) {
            var temp = content.substring(from, content.length - 1);
            var to = temp.indexOf(" ");
            if (to == -1) to = temp.length
            shortUrl = temp.substring(0, to);
        }
        if (shortUrl != "") {
            var tar = "<a href=\"" + decodeURI(shortUrl) + "\">" + shortUrl + "</a>";
            content = content.replace(shortUrl, tar);
        }

        var faceURL = imageServeUrl + "sysfolder/expression/miniblog/";
        content = content.replace(/\[拥抱\]/g, "<img src='" + faceURL + "hug.gif' />");
        content = content.replace(/\[呲牙\]/g, "<img src='" + faceURL + "lol.gif' />");
        content = content.replace(/\[示爱\]/g, "<img src='" + faceURL + "kiss.gif' />");
        content = content.replace(/\[呲牙\]/g, "<img src='" + faceURL + "lol.gif' />");
        content = content.replace(/\[可爱\]/g, "<img src='" + faceURL + "loveliness.gif' />");
        content = content.replace(/\[折磨\]/g, "<img src='" + faceURL + "mad.gif' />");
        content = content.replace(/\[难过\]/g, "<img src='" + faceURL + "sad.gif' />");
        content = content.replace(/\[流汗\]/g, "<img src='" + faceURL + "sweat.gif' />");
        content = content.replace(/\[憨笑\]/g, "<img src='" + faceURL + "biggrin.gif' />");
        content = content.replace(/\[大哭\]/g, "<img src='" + faceURL + "cry.gif' />");
        content = content.replace(/\[惊恐\]/g, "<img src='" + faceURL + "funk.gif' />");
        content = content.replace(/\[握手\]/g, "<img src='" + faceURL + "handshake.gif' />");
        content = content.replace(/\[发怒\]/g, "<img src='" + faceURL + "huffy.gif' />");
        content = content.replace(/\[惊讶\]/g, "<img src='" + faceURL + "shocked.gif' />");
        content = content.replace(/\[害羞\]/g, "<img src='" + faceURL + "shy.gif' />");
        content = content.replace(/\[微笑\]/g, "<img src='" + faceURL + "smile.gif' />");
        content = content.replace(/\[偷笑\]/g, "<img src='" + faceURL + "titter.gif' />");
        content = content.replace(/\[调皮\]/g, "<img src='" + faceURL + "tongue.gif' />");
        content = content.replace(/\[胜利\]/g, "<img src='" + faceURL + "victory.gif' />");
        return content;
    }
}

function BoxLogin() {
    var userName = escape($("#box_UserName").val());
    var password = escape($("#box_Password").val());
    var userType = -1;
    if ($("#company").attr("checked") == true) userType = 1;
    if ($("#student").attr("checked") == true) userType = 0;

    var userNameLength = GetLength(userName, false);
    if (userNameLength < 1 || userName == "用户名") {
        $(".missTip").text("请填写用户名");
        $("#box_UserName").val('');
        $(".missTip").show();
        $("#box_UserName").focus();
        return false;
    } else {
        $(".missTip").hide()
    }
    password = password.replace(/\'/g, "");
    var passwordLength = GetLength(password, false);
    if (passwordLength < 1) {
        $(".missTip").text("请填写密码");
        $(".missTip").show();
        $("#box_Password").focus();
        return false;
    } else {
        $(".missTip").hide()
    }
    if (userType == -1) {
        $(".missTip").text("请选择用户类别");
        $(".missTip").show();
        return false;
    } else {
        $(".missTip").hide();
    }

    var result = ExecuteHelp("/account/login", "UserName=" + userName + "&Password=" + password + "&UserType=" + userType);
    if (result == "1") {
        if (userType == 1) {
            window.location.href = "/companyhome/";
        }
        else {
            window.location.reload();
        }
    } else if (result.indexOf("@") > 0) {
        window.location.href = "/account/verification/?email=" + result;
    } else if (result=="3")
    {
        $(".missTip").text("账号未激活");
        $(".missTip").show();
    }
    else if (result.indexOf("Login ok") > 0) {
        result = result.replace("Login ok", "");
        $(window).after(result);
        window.location.reload();
    }
    else {
        $(".missTip").text("用户名或密码错误");
        $(".missTip").show();
    }
}

function onKeyPress(e) {
    var keyCode = null;
    if (e.which)
        keyCode = e.which;
    else if (e.keyCode)
        keyCode = e.keyCode;
    if (keyCode == 13) {
        BoxLogin();
        return false;
    }
    return true;
}

function toPasswordInput(e) {
    var keyCode = null;
    if (e.which)
        keyCode = e.which;
    else if (e.keyCode)
        keyCode = e.keyCode;
    if (keyCode == 13) {
        $("#box_Password").focus();
        return false;
    }
    return true;
}

var pageIndex = 1;
$(function () {
    if (! -[1, ] && $.browser.version == "6.0") {
        document.execCommand("BackgroundImageCache", false, true);
    }
    var scrtime;
    $(".friList").hover(
		        function () { clearInterval(scrtime); },
		        function () { scrtime = setInterval(function () { BoxUp(); }, 3000); }).trigger("mouseleave");
    function BoxUp() {
        try {
            var $ul = $(".friList");
            var liHeight = $ul.find("li:last").innerHeight();
            $ul.animate({ marginTop: +liHeight + "px" }, 800,
			            function () {
			                $ul.find("li:last").prependTo($ul);
			                $ul.css({ marginTop: 0 });
			                $ul.find("li:first").hide().fadeIn(1000);
			            });
        } catch (e) { }
    }
    $('.pwd').focus(function () { $(this).prev('.pwdTxt').text(""); });
    $('.pwd').blur(function () { if ($(this).val() == "") { $(this).prev('.pwdTxt').text("密码"); } });
    $('.uname').focus(function () { $(this).prev('.unameTxt').text(""); });
    $('.uname').blur(function () { if ($(this).val() == "") { $(this).prev('.unameTxt').text("账号"); } });
});

function WeiboLogin(o) {
    var result = ExecuteHelp("/account/sinaweibologin/", "id=" + o.id + "&screenname=" + o.screen_name + "&gender=" + o.gender);
    if (result == 1) {
        window.location.href = "/personalhome/";
    }
    else {
        alert("新浪微博账号登录失败，请联系网站管理员！");
    }
}

WB2.logout();
WB2.anyWhere(function (W) {
    W.widget.connectButton({
        id: "wb_connect_btn",
        callback: {
            login: function (o) {
                WeiboLogin(o);
            },
            logout: function () {
                alert("退出成功！");
            }
        }
    });
});
