﻿function ad_display() {
    var ad1 = "<a href=\"http://www.vancl.com/WebSource/WebSource.aspx?source=cacard&url=http://www.vancl.com/\" target=\"_blank\"><img src=\"http://union.vancl.com/adpic.aspx?w=360&h=120\" border=\"0\" /></a>";
    var ad2 = "<a href=\"http://www.vancl.com/WebSource/WebSource.aspx?source=cacard&url=http://www.vancl.com/\" target=\"_blank\"><img src=\"http://union.vancl.com/adpic.aspx?w=560&h=90\" border=\"0\" /></a>";
    // $("#head_categorylist").html("<div style=\"display:block;margin-bottom:8px;margin-top:8px;\">" + ad2 +"<br/>"+ "</div>");
}


// common.js

//focus
function setfocus(boxid) {
    document.getElementById(boxid).focus();
}

/** common **/
function hide(id) {
    var e = document.getElementById(id); if (e != null) e.style.display = "none";
}
function show(id) {
    var e = document.getElementById(id); if (e != null) e.style.display = "";
}

/* close window */
function closeIt() {
    self.close();
}
function doClose() {
    setTimeout("closeIt()", 1800);
}

/* close tip */
function close_tip() {
    document.getElementById("userad_tip").className = "hidden";
    dazaza.DataAccess.MyAjax.Close_Tip();

}

function emitEmotion(em) {
    var t = document.getElementById("Story_view1_tbRe");
    if (t != null) t.value += " " + em + " ";

    var tb = document.getElementById("_ctl0__ctl0_tbRe");
    if (tb != null) tb.value += " " + em + " ";
}

function Search(key) {
    if (key != "") {
        window.location = "http://www.diglog.com/search.aspx?key=" + escape(key);
    }
}


function RegCheckName() {
    var name = document.getElementById("Register_box1_tbName").value;

    $("#msg_name").html("<img src=http://img.diglog.com/images/snake.gif>loading...");
    $.ajax({
        type: "post",
        url: "/ajax.aspx?act=regcheckname",
        dataType: "html",
        data: "name=" + name,
        success: function(result) {
            $("#msg_name").html(result);
        }
    });
}

function RegCheckNickName() {
    var name = document.getElementById("Register_box1_tbName").value;
    var nickname = document.getElementById("Register_box1_tbNickName").value;

    $("#msg_nickname").html("<img src=http://img.diglog.com/images/snake.gif>loading...");
    $.ajax({
        type: "post",
        url: "/ajax.aspx?act=regchecknickname",
        dataType: "html",
        data: "nickname=" + nickname + "&name=" + name,
        success: function(result) {
            $("#msg_nickname").html(result);
        }
    });
}


function showHeaderLoginForm() {
    $("#headerLogin").show("slow");
}





function check_english(input) {
    for (var i = 0; i < input.value.length; ++i) {
        var c = input.value.charAt(i);
        if ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || (c >= '0' && c <= '9'))
            continue;
        if (c == '_')
            continue;
        return false;
    }
    return true;
}


function checkEmail(input) {
    var ret = false;
    if (input.value.indexOf(" ") <= 0) {
        var at_index = input.value.indexOf("@");
        var c_index = input.value.lastIndexOf(".");
        ret = (at_index > 0 && c_index > 2 && (at_index + 1) < c_index && c_index < input.value.length - 1);
    }
    return ret;
}



//************************************************************
// mark.js
//************************************************************

//display state from the cookie

function mark_up(infoid) {
    $("#up" + infoid).html('<img src=http://img.diglog.com/images/snake.gif width=16 height=16>');

    $("#mark" + infoid).fadeOut("slow");


    $("#mark" + infoid).toggleClass("digg_over");
    $("#mark" + infoid).fadeIn("slow");
    //$("#mark"+infoid).html(result);
    $("#up" + infoid).html("");

}

function storypage_mark(infoid) {
    $("#dig1").html('<img src=http://img.diglog.com/images/snake.gif width=16 height=16>');
    $("#dig1" + infoid).fadeOut("slow");
    //validate the cookie
    if ($.cookie('MarkedInfoID') != null && $.cookie('MarkedInfoID') != '') {
        var a = $.cookie('MarkedInfoID').split('|');
        for (var i = 0; i < a.length; i++) {
            if (a[i] != '' && a[i] == infoid) {
                $("#mark" + infoid).toggleClass("digg_over");
                $("#mark" + infoid).fadeIn("slow");
                $("#up" + infoid).html("");
                return;
            }
        }
    }

    $.ajax({
        type: "post",
        url: "/ajax.aspx?act=mark",
        dataType: "html",
        data: "infoid=" + infoid,
        success: function(result) {
            if (result == "login") {
                alert("需要登录");
            }
            else {
                $("#dig1").toggleClass("digg_over");
                $("#dig1").fadeIn("slow");
            }

        }
    });
}


function mark_up_v1(infoid) {
    $("#up" + infoid).html('<img src=http://img.diglog.com/images/snake.gif width=16 height=16>');
    //$("#mark"+infoid).html('<img border=0 src=http://img.diglog.com/images/snake.gif width=16 height=16>');
    $("#mark" + infoid).fadeOut("slow");
    //validate the cookie
    if ($.cookie('MarkedInfoID') != null && $.cookie('MarkedInfoID') != '') {
        var a = $.cookie('MarkedInfoID').split('|');
        for (var i = 0; i < a.length; i++) {
            if (a[i] != '' && a[i] == infoid) {
                $("#mark" + infoid).toggleClass("digg_over");
                $("#mark" + infoid).fadeIn("slow");
                //$("#mark"+infoid).html(result);
                $("#up" + infoid).html("");
                return;
            }
        }
    }

    $.ajax({
        type: "post",
        url: "/ajax.aspx?act=mark",
        dataType: "html",
        data: "infoid=" + infoid,
        success: function(result) {
            if (result == "login") {
                //window.location="http://www.diglog.com/signin.aspx";
            }
            else {
                $("#mark" + infoid).toggleClass("digg_over");
                $("#mark" + infoid).fadeIn("slow");
                //$("#mark"+infoid).html(result);
                $("#up" + infoid).html("");
            }

        }
    });
}





function GetSigninMessage() {
    $.ajax({
        type: "post",
        url: "/ajax.aspx?act=getsigninmessage",
        dataType: "html",
        data: "",
        success: function(result) {
            $("#SigninMessage").html(result);
        }
    });

    ad_display();
}

function GetSubFeedCode() {
    var diglog_rss = "http://feed.feedsky.com/diglog";
    var google = "<a href=\"http://fusion.google.com/add?feedurl=" + diglog_rss + "\" title=\"订阅到google\"><img src=/images/subfeed/google.gif border=0></a>";
    var qq = "<a title=订阅到QQ邮箱 href=\"http://mail.qq.com/cgi-bin/feed?u=" + diglog_rss + "\"><img src=/images/subfeed/qqmail.gif border=0></a>";
    var xianguo = "<a title=订阅到鲜果 href=\"http://www.xianguo.com/subscribe.php?url=" + diglog_rss + "\"><img border=0 src=/images/subfeed/xianguo.gif></a>";
    var zhuaxia = "<a title=订阅到抓虾 href=\"http://www.zhuaxia.com/add_channel.php?url=" + diglog_rss + "\"><img border=0 src=/images/subfeed/zhuaxia.gif></a>";
    var youdao = "<a title=订阅到有道 href=\"http://reader.youdao.com/b.do?keyfrom=feedsky&url=" + diglog_rss + "\"><img border=0 src=/images/subfeed/yodao.gif></a>";
    var more = "<a href=\"/subfeed.aspx\">更多...</a>";
    document.write("订阅本站到: ");
    document.write(qq);
    document.write(xianguo);
    document.write(zhuaxia);
    document.write(youdao);
    document.write(google);
    document.write(more);
}
function GetShareCode(infoid, url, title) {
    var google = "&nbsp;&nbsp;<a href=\"javascript:(function(){var a=window,b=document,c=encodeURIComponent,d=a.open('http:\/\/www.google.com\/bookmarks\/mark?op=edit&amp;output=popup&amp;bkmk='+c(b.location)+'&amp;title='+c(b.title),'bkmk_popup','left='+((a.screenX||a.screenLeft)+10)+',top='+((a.screenY||a.screenTop)+10)+',height=420px,width=550px,resizable=1,alwaysRaised=1');a.setTimeout(function(){d.focus()},300)})();\"><img src=\"/images/shareto/google.gif\" alt=\"添加到Google书签\" border=0 align=absMiddle><\/a>";
    var sina = "&nbsp;&nbsp;<a href=\"javascript:void((function(s,d,e){try{}catch(e){}var f='http:\/\/v.t.sina.com.cn\/share\/share.php?',u=d.location.href,p=['url=',e(u),'&title=',e(d.title),'&appkey=2924220432'].join('');function a(){if(!window.open([f,p].join(''),'mb',['toolbar=0,status=0,resizable=1,width=620,height=450,left=',(s.width-620)\/2,',top=',(s.height-450)\/2].join('')))u.href=[f,p].join('');};if(\/Firefox\/.test(navigator.userAgent)){setTimeout(a,0)}else{a()}})(screen,document,encodeURIComponent));\"><img src=\"http:\/\/tjs.sjs.sinajs.cn\/t3\/style\/images\/toolbar\/s_org.gif\" border=\"0\" title=\"分享到新浪微博\" \/><\/a>&nbsp;";
    var qq = "&nbsp;&nbsp;<a href=\"http:\/\/sns.qzone.qq.com\/cgi-bin\/qzshare\/cgi_qzshare_onekey?url=" + url + "\" target=\"_blank\" style=\"color:#000000;text-decoration:none;font-size:12px;font-weight:normal\"><img border=\"0\" align=\"absmiddle\" src=\"/images/shareto/ico_Qzone.gif\" title=\"分享到QQ空间\" target=\"_blank\" \/><\/a>&nbsp;";
    var baidu = "&nbsp;&nbsp;<a href=\"javascript:window.open('http:\/\/cang.baidu.com\/do\/add?it='+encodeURIComponent(document.title.substring(0,76))+'&iu='+encodeURIComponent(location.href)+'&fr=ien#nw=1','_blank','scrollbars=no,width=600,height=450,left=75,top=20,status=no,resizable=yes'); void 0\" ><IMG alt=添加到百度搜藏 src=\"http:\/\/cang.baidu.com\/-\/remote\/fav1.jpg\" align=absMiddle border=0><\/a> &nbsp;";
    var kaixin = "&nbsp;&nbsp;<a href=\"javascript:d=document;t=d.selection?(d.selection.type!='None'?d.selection.createRange().text:''):(d.getSelection?d.getSelection():'');void(kaixin=window.open('http:\/\/www.kaixin001.com\/~repaste\/repaste.php?&amp;rurl='+escape(d.location.href)+'&amp;rtitle='+escape('" + title + "')+'&amp;rcontent='+escape('" + title + "'),'kaixin'));kaixin.focus();\"><img src=\"/images/shareto/kaixin001.gif\" alt=\"转贴到开心网\" border=0 align=absMiddle><\/a> ";
    var renren = "&nbsp;&nbsp;<a href=\"javascript:void((function(s,d,e){if(\/xiaonei\.com\/.test(d.location))return;var%20f='http:\/\/share.xiaonei.com\/share\/buttonshare.do?link=',u=d.location,l=d.title,p=[e(u),'&amp;title=',e(l)].join('');function%20a(){if(!window.open([f,p].join(''),'xnshare',['toolbar=0,status=0,resizable=1,width=626,height=436,left=',(s.width-626)\/2,',top=',(s.height-436)\/2].join('')))u.href=[f,p].join('');};if(\/Firefox\/.test(navigator.userAgent))setTimeout(a,0);else%20a();})(screen,document,encodeURIComponent));\"><img src=\"/images/shareto/renren.gif\" alt=\"分享到校内人人网\" border=0 align=absMiddle><\/a>";
    document.write(sina);
    document.write(qq);
    document.write(google);
    document.write(baidu);
    document.write(kaixin);
    document.write(renren);
}

function GetStoryMark(infoid, posttime, mark) {
    $("#mark" + infoid).html("<img src=http://img.diglog.com/images/snake.gif border=0> ");
    $.ajax({
        type: "post",
        url: "/ajax.aspx?act=getstroymark",
        dataType: "html",
        data: "infoid=" + infoid + "&posttime=" + posttime + "&mark=" + mark,
        success: function(result) {
            $("#mark" + infoid).html(result);
        }
    });
}


//**************************************************************
//comment mark
//*************************************************************
function Comment_Mark_Up(CommentID, InfoPoster) {
    $("#Comment_digg_button" + CommentID).html("<img src=http://img.diglog.com/images/snake.gif width=16 height=16>");
    $.ajax({
        type: "post",
        url: "/ajax.aspx?act=commentmarkup",
        dataType: "html",
        data: "commentid=" + CommentID + "&infoposter=" + InfoPoster,
        success: function(result) {
            $("#C_Mark_Span" + CommentID).html(result);
            $("#Comment_digg_button" + CommentID).html("");
            $("#Comment_digg_button" + CommentID).hide();
        }
    });
}

function Comment_Mark_Down(CommentID, InfoPoster) {
    $("#Comment_digg_button" + CommentID).html("<img src=http://img.diglog.com/images/snake.gif width=16 height=16>");
    $.ajax({
        type: "post",
        url: "/ajax.aspx?act=commentmarkdown",
        dataType: "html",
        data: "commentid=" + CommentID + "&infoposter=" + InfoPoster,
        success: function(result) {
            $("#C_Mark_Span" + CommentID).html(result);
            $("#Comment_digg_button" + CommentID).html("");
            $("#Comment_digg_button" + CommentID).hide();
        }
    });
}

function EditComment(KeyID) {
    var EditCommentBox = document.getElementById("EditCommentBox" + KeyID);
    var DisplayCommentBox = document.getElementById("DisplayCommentBox" + KeyID);
    var EditCommentLink = document.getElementById("EditCommentLink" + KeyID);
    var EditCommentTextarea = document.getElementById("EditCommentTextarea" + KeyID);
    hide("EditCommentLink" + KeyID);
    show("EditCommentBox" + KeyID);
    EditCommentBox.className = "text";

    $("#EditCommentLink" + KeyID).hide("slow");
    $("#EditCommentBox" + KeyID).slideDown("slow");
    $("#EditCommentBox" + KeyID).addClass("text");
    $.ajax({
        type: "post",
        url: "/ajax.aspx?act=editcomment",
        dataType: "html",
        data: "keyid=" + KeyID,
        success: function(result) {
            DisplayCommentBox.style.display = "none";
            EditCommentTextarea.value = result;
        }
    });
}

function EditComment_Post(KeyID) {
    var EditCommentBox = document.getElementById("EditCommentBox" + KeyID);
    var EditCommentTextarea = document.getElementById("EditCommentTextarea" + KeyID);
    var comment = EditCommentTextarea.value;
    var DisplayCommentBox = document.getElementById("DisplayCommentBox" + KeyID);
    var EditCommentLink = document.getElementById("EditCommentLink" + KeyID);
    $.ajax({
        type: "post",
        url: "/ajax.aspx?act=editcommentpost",
        dataType: "html",
        data: "keyid=" + KeyID + "&comment=" + comment,
        success: function(result) {
            EditCommentLink.style.display = "";
            EditCommentBox.style.display = "none";
            DisplayCommentBox.style.display = "";
            DisplayCommentBox.className = "text";
            DisplayCommentBox.innerHTML = result;
        }
    });
}

function EditComment_Cancel(KeyID) {
    var EditCommentBox = document.getElementById("EditCommentBox" + KeyID);
    var DisplayCommentBox = document.getElementById("DisplayCommentBox" + KeyID);
    var EditCommentLink = document.getElementById("EditCommentLink" + KeyID);
    EditCommentLink.style.display = "";
    EditCommentBox.style.display = "none";
    DisplayCommentBox.style.display = "";
    DisplayCommentBox.className = "text";
}

//************************* 
function RefershCodeImage(guid) {

}

var isChange = 0;

function DisplayCheckCode() {
    if (isChange == 0) {
        //document.getElementById("code-comment").style.display = "inline";
        $("#code-comment").slideDown();
        ChangeCheckCode();
    }
}

function ChangeCheckCode() {
    isChange = 1;
    var img_ValidateCode = document.getElementById("imgCheckCode");
    var timeStamp = new Date().getTime();
    img_ValidateCode.style.display = "inline";
    img_ValidateCode.src = "/CheckCode/CheckCode.aspx?timeStamp=" + timeStamp;
}

function commentSubmit() {
    //validate

    var commentName = $("#commentName").attr("value");
    var commentBlog = $("#commentBlog").attr("value");
    var comment = $("#Story_view1_tbRe").attr("value");
    var commentCode = $("#commentCode").attr("value");
    var commentInfoID = $("#commentInfoID").attr("value");

    var reid = $("#reID").attr("value");

    if (reid == null) reid = "";

    if (commentCode == null) {
        commentCode = "";
    }

    if (commentName == null) {
        commentName = "";
    }
    commentName = commentName.replace(/(^\s*)|(\s*$)/g, "");
    if (commentName == "") {
        alert('请填写名字');
        $("#commentName").css("background-color", "#FFFF78");
        for (var i = 0; i < 3; i++) {
            $("#commentName").fadeOut();
            $("#commentName").fadeIn();
        }

        return;
    }

    if (comment == null) {
        comment = "";
    }
    comment = comment.replace(/(^\s*)|(\s*$)/g, "");

    if (comment == "") {
        alert('请填写评论');
        $("#Story_view1_tbRe").css("background-color", "#FFFF78");
        for (var i = 0; i < 2; i++) {
            $("#Story_view1_tbRe").fadeOut();
            $("#Story_view1_tbRe").fadeIn();
        }
        return;
    }

    if (commentCode == "") {
        alert('请填写验证码');
        $("#commentCode").css("background-color", "#FFFF78");
        for (var i = 0; i < 2; i++) {
            $("#commentCode").fadeOut();
            $("#commentCode").fadeIn();
        }
        return;
    }

    $("#msg").html("<img src=http://img.diglog.com/images/snake.gif> 正在提交评论 ... ");
    $("#msg").show("slow");

    $.ajax({
        type: "post",
        url: "/ajax.aspx?act=postcomment",
        dataType: "html",
        data: "name=" + commentName + "&blog=" + commentBlog + "&comment=" + comment + "&code=" + commentCode + "&infoid=" + commentInfoID + "&reid=" + reid,
        success: function(result) {
            if (!isNaN(result.substring(0, 1))) {
                if (1 == 1) {
                    $("#msg").hide("slow");
                    $("#Story_view1_tbRe").attr("value", "");

                    //                    ary = result.split('|');
                    //                    result = ary[1];
                    alert('发表评论成功!');

                    GetCommentList(commentInfoID, 1);

                }

            }
            else {
                $("#msg").html(result);
            }
        }
    });
}


function GetCommentList(infoid, pageIndex) {
    $("#cmt_list").html("<img src=http://img.diglog.com/images/snake.gif border=0> 正在加载评论... ");
    $.ajax({
        type: "post",
        url: "/ajax.aspx?act=getcommentlist",
        dataType: "html",
        data: "infoid=" + infoid + "&pageindex=" + pageIndex,
        success: function(result) {
        $("#cmt_list").html(result);
        }
    });
}


function InitCommentFrom() {

    //no comment
    ////    $("#commentSbtBtn").attr("disabled", "true");
    ////    $("#commentregisterlink").show();
    ////    $("#code-comment").hide();

    ////    $.ajax({
    ////        type: "post",
    ////        url: "/ajax.aspx?act=issignin",
    ////        dataType: "html",
    ////        data: "",
    ////        success: function(result) {
    ////            ary = result.split('|');
    ////            result = ary[0];
    ////            if (result == "0") {
    ////                $("#commentIsSignin").attr("value", "0");
    ////                $("#commentName").attr("value", "");
    ////                //$("#codeImage").attr("src", "/code-comment.aspx?code=" + ary[1]);
    ////                //$("#myCode").attr("value", ary[1]);
    ////                $("#commentSbtBtn").attr("disabled", "true");
    ////                $("#commentregisterlink").show();
    ////                $("#code-comment").hide();
    ////            }
    ////            else {
    ////                $("#commentName").attr("disabled", "true");
    ////                $("#commentName").attr("value", result);
    ////                $("#code-comment").hide();
    ////                $("#commentIsSignin").attr("value", "1");
    ////            }
    ////        }
    ////    });
}


function reComment(keyid, postername) {
    $("#reID").attr("value", keyid);
    $("#rePosterName").html(postername);
    $("#reCommentContent").html($("#DisplayCommentBox" + keyid).html());
    $("#reComment").slideDown("slow");
}

function reCommentCancel() {
    $("#reComment").slideUp("slow");
    $("#reID").attr("value", "");
}
