﻿/// <reference path="jquery-vsdoc2.js" />
var contents;
var webname = "raidgold";
var domainname = "com";
var count = 8;
$(function() {
    $("#btn_catacly").click(Catacyl);
    IsVote();
//    $("#txt_UserName").val($("#UserName").val());
    $("#txt_Posts").click(function() { $("#txt_Posts").html("") });
})
//投票
function Vote(name) {
    $(".raidgold a").css("background", "none");
    $(".raidgold a").hide();
    var ip = $("input[type='hidden'][id$=UserIPs]").val();
    AjaxMethod.InsertNum(ip, name, Vote_CallBack);
}

function Vote_CallBack(response) {
    var DataTable = response.value;
    if (DataTable != null && typeof (DataTable) == "object") {
        for (i = 0; i < DataTable.Rows.length; i++) {
            responstr("p", "span_" + DataTable.Rows[i].Name + "", DataTable.Rows[i].num);
        }
        IsVote();
    }
}

function IsVote() {
    var ip = $("input[type='hidden'][id$=UserIPs]").val();
    AjaxMethod.HasVote(ip, IsVote_CallBack);

}
function IsVote_CallBack(response) {
    var reslut = response.value;
    if (reslut == "" || reslut == null) {
         
    }
    else {
        var VoleName = getFeature(reslut, "VoleName");
        if (VoleName != "") {
            $(".raidgold a").css("background", "none");
            $(".raidgold a").hide();
            $("#hasvoted").show();
            $("#unvoted").hide();
            responstr("span", "votedname", VoleName);
        }
        var content = getFeature(reslut, "Content");
        var content = eval("(" + content + ")");
        for (var i = 0; i < content.length; i++) {
            responstr("p", "span_" + content[i].Name + "", content[i].num);
        }
    }
}

//得到配置的值
function getFeature(source, name) {
    var reg = new RegExp("(^|&|\\s)" + name + "\\s*=\\s*([^&]*)(\\s|&|$)", "i");
    if (reg.test(source)) return RegExp.$2;
    return "";
}

function responstr(kjname, kjid, newstr) {
    $("#" + kjid).replaceWith("<" + kjname + " id=" + kjid + ">" + newstr + "</" + kjname + ">");
}


//评论
function Catacyl() {
    var userName = $("input[type='text'][id$=txt_UserNames]").val();
    var posts = $("#txt_Posts").val();
    if (posts == "Since you have come,by the way,leave a message...(450 character limit)" || posts == "") {
        $("#tipspan").css("color", "red");
        return;
    }
    if ($("input[type='checkbox'][id$=chkisguest]").attr("checked")) {
        userName = "just a passing";
    }
    else {
        if (userName == "") {
            $("#tipspan").css("color", "red");
            return;
        }
    }
    $("#tipspan").css("color", "");
    posts = posts.substring(0, 450);
    AjaxMethod.InsetrCatacly(userName, posts, count, Catacyl_CallBack);
}

//格式时间格式
Date.prototype.format = function(format) {

    var o = {

        "M+": this.getMonth() + 1, //month

        "d+": this.getDate(),    //day

        "h+": this.getHours(),   //hour

        "m+": this.getMinutes(), //minute

        "s+": this.getSeconds(), //second

        "q+": Math.floor((this.getMonth() + 3) / 3),  //quarter

        "S": this.getMilliseconds() //millisecond

    };

    if (/(y+)/.test(format)) {

        format = format.replace(RegExp.$1,

(this.getFullYear() + "").substr(4 - RegExp.$1.length));

    }

    for (var k in o) {

        if (new RegExp("(" + k + ")").test(format))

            format = format.replace(RegExp.$1,

RegExp.$1.length == 1 ? o[k] : ("00" + o[k]).substr(("" + o[k]).length));

    }

    return format;

}



//获取系统时间
function formatTime(dt) {
    var date = new Date(dt);
    return date.format("yyyy/MM/dd");
}

function Catacyl_CallBack(response) {
    turnPage(1);
    $("#txt_Posts").val("");
    $("#main").show();
    $("input[type='text'][id$=txt_UserNames]").val("");
}

function DivShow() {
    $('#repeatershow').show();
    $("#jsshow").hide();
}

function getname(name) {
    var orderLength = name.length;
    if (orderLength >= 9 && name.indexOf("@") >= 2) {
        var preOrder = name.substring(name.indexOf("@") - 1, 1);
        var afterOrder = name.substring(name.indexOf("@"), orderLength);
        var midOrder = "****";
        return midOrder + preOrder + afterOrder;
    }
    else {
        return name;
    }
}

