var config = {
    globalpath: "/server/ajax.aspx",
    userpath: "/server/user/ajax.aspx",
    taskpath: "/server/task/ajax.aspx",
    activepath: "/server/active/ajax.aspx",
    chatpath: "/server/chat/ajax.aspx",
    managerpath: "/manager/server.aspx"
}
var _bbsdomail = "http://bbsuochuang.vicp.net/";
var _cookie_domail = {
    all: ""
}

function PrintCreaditText(cdt) {
    if (!cdt) { return; }
    var sb = "";
    sb += "<div class='cdtWord'>";
    for (i = 0; i < cdt.length; i++) {
        sb += "<span id='cdt_" + i.toString() + "' class='cdt_" + i.toString() + "'>" + cdt.charAt(i) + "</span>";
    }
    sb += "</div>";
    document.write(sb);
}
function PrintExpText(exp) {
    if (!exp) { return; }
    var sb = "";
    sb += "<div class='expWord'>";
    for (i = 0; i < exp.length; i++) {
        sb += "<span id='exp_" + i.toString() + "' class='exp_" + i.toString() + "'>" + exp.charAt(i) + "</span>";
    }
    sb += "</div>";
    document.write(sb);
}

function ShowErrImg(img, obj) {
    if (img) {
        obj.src = img;
    } else {
        obj.src = "/images/noface_5858.jpg";
    }
}

/* 显示遮罩层 */
function showBK() {
    if (!$('#bk_layer').length) {
        $("body").append("<div id='bk_layer' style='width:100%;height:" + Math.max(document.documentElement.scrollHeight, document.documentElement.clientHeight) + "px;filter:alpha(opacity=60);opacity:0.6;z-index:10000;position:absolute;left:0px;top:0px;background:#000;' >");
    }
    else $('#bk_layer').show();
}
/* 关闭遮罩层 */
function closeBK() { $('#bk_layer').hide(); }

/* POP窗口登陆 */
var obj_dialog_login;
function show_login() {
    if (typeof (DIALOG) == 'undefined') { $import(".js.dialog.dialog"); }
    if (typeof (DIALOG.DialogLogin) == 'undefined') $import(".js.dialog.login");
    var dialog_login = $("#dialog_login");
    if (!dialog_login.length) {
        $("body").append("<div id='dialog_login' style='z-index:100000;width:300px;height:260px;overflow:hidden;border:solid 1px #dbdbdb;position:absolute;left:" + ((document.body.clientWidth / 2) - 125) + "px;top:" + (document.documentElement.scrollTop + 200) + "px;'><p>登  陆</p></div>");
        dialog_login = $("#dialog_login");
        obj_dialog_login = new DIALOG.DialogLogin("dialog_login");
        obj_dialog_login.show();
    }
    else {
        dialog_login.css({ left: (document.body.clientWidth / 2) - 125, top: (document.documentElement.scrollTop + 200) });
        obj_dialog_login.show();
    }
}



function bk_login() {
    showBK();
    show_login();
}
/* js的出错信息控制 */
var _errorRtn = false;
window.onerror = function() { return _errorRtn; }

/* 页面卸载时提示的字符串 */
config.pageclosestring = "";
config.pagecloseshow = false;

function PromptOnClose(evt) { return config.pageclosestring; }
window.onbeforeunload = function(evt) {
    if (config.pagecloseshow) {
        var e = evt ? evt : window.event; return PromptOnClose(evt);
    }
}

$(document).ready(function() {
    DropSearchMenu();
});
function DropSearchMenu() {
    $(".sc_menu li").click(function() {
        SetSearchType($(this).html());
        $(".sc_menu ul").fadeOut();
    });
}

function SetSearchType(str) {
    $("#searchType").html(str);
}

/* 留言框 */
var addmessage_dialog = null;
function AddMessageBoard(fuid) {

    var div_dialog = $("#div_addmessage_dialog");

    if (div_dialog.length == 0) {
        $("body").append("<div id='div_addmessage_dialog' style='background:#fff;z-index:100000;width:324px;height:140px;overflow:hidden;border:solid 0px #dbdbdb;position:absolute;left:" + ((document.body.clientWidth / 2) - 125) + "px;top:" + (document.documentElement.scrollTop + 100) + "px;'></div>");
    }

    if (typeof (DIALOG) == 'undefined') {
        $import(".js.dialog.dialog");
    }

    if (typeof (DIALOG.DialogAddMessage) == 'undefined') {
        $import(".js.dialog.addfrined");
    }

    addmessage_dialog = new DIALOG.DialogAddMessage("div_addmessage_dialog", fuid);

    div_dialog.css({ left: (document.body.clientWidth / 2) - 125, top: (document.documentElement.scrollTop + 200) });

    div_dialog.show();

}

/* 聊天框 */
var chat_dialog = null;
function GetMessageBox(fuid) {
    AUTO_REC_NEW_MSG = false;
    var div_dialog = $("#div_chat_dialog");
    if (div_dialog.length == 0) {
        $("body").append("<div id='div_chat_dialog' style='background:#fff;z-index:100000;width:506px;height:485px;overflow:hidden;border:3px solid #009900;cursor:move;position:absolute;left:" + ((document.body.clientWidth / 2) - 125) + "px;top:" + (document.documentElement.scrollTop + 100) + "px;'></div>");
    }
    if (typeof (DIALOG) == 'undefined') {
        $import(".js.dialog.dialog");
    }

    if (typeof (DIALOG.DialogChat) == 'undefined') {
        $import(".js.dialog.chat");
    }

    chat_dialog = new DIALOG.DialogChat("div_chat_dialog", fuid);
    //$("#user_chat_dialog").before("<p style='height:20px;line-height:20px;'><a href='javascript:;' style='float:right;'>关 闭</a></p>");
    div_dialog.css({ left: (document.body.clientWidth / 2) - 125, top: (document.documentElement.scrollTop + 200) });
    div_dialog.show();

    $("#NEW_MSG_CLUE").fadeOut();
}
/* 搜索 */
function doSearch() {
    //var __type = $("#searchType").html();
    var __type = document.getElementById("searchType").value;
    var __key = $("#searchKey").val();
    top.location.href = "/search.aspx?type=" +encodeURI( __type) + "&key=" +encodeURI( __key);
}
function _doSearch() {
    //var __type = $("#searchType").html();
    var __type = document.getElementById("searchType").value;
    var __key = $("#searchKey").val();
    top.location.href = "/search.aspx?type=" +encodeURI( __type) + "&key=" +encodeURI( __key);
}
function _doSearch1() {
   // var __type = $("#searchType").html();
    var __type = document.getElementById("searchType").value;
    var __key = $("#searchKey1").val();
    top.location.href = "/search.aspx?type=" +encodeURI( __type) + "&key=" +encodeURI( __key);
}
function _doSearch2() {
   // var __type = $("#searchType").html();
    var __type = document.getElementById("searchType").value;
    var __key = $("#searchKey2").val();
    top.location.href = "/search.aspx?type=" +encodeURI( __type) + "&key=" +encodeURI( __key);
}

function GET_NEW_MSG() {
    if (window.parent != window.self) {
        return;
    }

    var islogined = Cookies.getCookie("uinfo");

    if ($.trim(islogined) == "") AUTO_REC_NEW_MSG = false;

    if (!AUTO_REC_NEW_MSG) return;

    $.getJSON(config.chatpath, { t: "getnewmsg" }, function(r) {
        if (r != null || r != "") {
            if (!r) { return; }
            SHOW_NEW_MSG(r.DATA[0].userid, r.DATA[0].realname, r.DATA[0].face);
        }
    });

    window.setTimeout(GET_NEW_MSG, 5000);
}

//是否自动接收聊天请求
var AUTO_REC_NEW_MSG = true;
//消息模板
var NEW_MSG_TEMPLATE = "<div id='NEW_MSG_CLUE'><p>来自 「{realname}」 的聊天请求</p><div><a href='/{userid}/'><img onload='thumbImg(this,48,48)' onerror='this.src=\"/images/noface_5858.jpg\"' src='{img}' style='float:left;margin:0px 10px 0px 10px;' /></a><a href='javascript:;' onclick=\"GetMessageBox({userid})\" class='link3'>接受</a> <a class='link3' href='javascript:CLOSE_NEW_MSG();'>拒绝</a> <br /> <a href=\"/{userid}/\">进入它的空间</a></div></div>";

function SHOW_NEW_MSG(userid, realname, img) {
    if ($("#NEW_MSG_CLUE").length > 0) {
        $("#NEW_MSG_CLUE").fadeIn();
    }
    else {
        var __tmp = NEW_MSG_TEMPLATE.replace("{userid}", userid).replace("{userid}", userid).replace("{userid}", userid).replace("{realname}", realname).replace("{img}", img);
        $(document.body).append(__tmp);
        $("#NEW_MSG_CLUE").css({ top: document.documentElement.scrollTop + document.documentElement.clientHeight - $("#NEW_MSG_CLUE").height() - 5 });

        $("#NEW_MSG_CLUE").fadeIn();

        $(window).scroll(function() {
            var NEW_MSG_BOX_TOP = document.documentElement.scrollTop + document.documentElement.clientHeight - $("#NEW_MSG_CLUE").height() - 5;
            $("#NEW_MSG_CLUE").css({ top: NEW_MSG_BOX_TOP });
        });
    }
}

function CLOSE_NEW_MSG() {
    $("#NEW_MSG_CLUE").fadeOut();
}

var UCH = new Object();
UCH.iplocal = decodeURI(escape(Cookies.getCookie("iplocal")));
var UCH_COOKIE_INFO = Cookies.getCookie("uinfo");
if (UCH_COOKIE_INFO != "") {
    $.each(UCH_COOKIE_INFO.split('&'), function(i, n) {
        var __o = n.split('=');
        UCH[__o[0]] = decodeURI(escape(__o[1].toString()));
    });
}

function CheckIPLocal() {
    if (!confirm("您确认要接受该任务或参加此活动吗？\n\n点击下面的确定就意味着您必须严格的按照规则完成该任务或活动！")) {
        return false;
    }
    return true;
}

function ShowDivMsg(msg, offset) {
    var msgdiv = $("#MSG_DIV");
    var closeBtn = "<p style='text-align:right;'><a class='link3' href='javascript:;' onclick='$(this).parent().parent().hide()'>关闭</a></p>";
    if (msgdiv.length == 0) {
        $("<div id='MSG_DIV' style='cursor:pointer;display:none;background:#fff;position:absolute;width:320px;height:auto;border:solid 1px #d1d1d1;border-width:1px 2px 2px 1px; padding:0px 20px 20px 20px; font-size:13px; line-height:190%;'></div>").appendTo($(document.body));
        msgdiv = $("#MSG_DIV");
    }
    if (offset) {
        msgdiv.html(closeBtn + msg);
        msgdiv.css({ left: offset.left, top: offset.top }).fadeIn();
    }
}

/* 显示或者隐藏回复输入框 */
function showcmttxt(o) {
    $("#" + o).toggle();
}

var replyTemplate = "<div class='reply_div'><p><span style='float:left;'><a href='../space/index.aspx?uid={userid}'>{realname}</a> 的回复</span><span style='float:right'>{adddate}</span></p><div class='replystr'>{reply}</div></div>";

function getReplyStr(str) {
    if (UCH.uid == 'undefined' || UCH.realname == 'undefined') {
        location.href = "/login.aspx?returl=" + location.href;
        return;
    }
    return replyTemplate.replace("{userid}", UCH.uid).
    replace("{realname}", UCH.realname).
    //replace("{adddate}", (new Date()).format("yyyy-MM-dd hh:mm:ss")).
    replace("{reply}", str);
}