﻿///<reference path="/js/jquery-1.3.2.js"/>
$(document).ready(function() {
    var show = $("#talkout").show();
    if (show) {
        $("#talkout").hide();
    }  
  $("#divForm").show();
});

function showtalk() {
   $("#divForm").slideToggle();
}

function seecontent(ID) {

    var id = '#' + ID;
    $(id).slideToggle();
}
/************************支持，反对********************************/
function votecomment(ID, type) {
    if (type == 0) {
        Support(ID);
    }
    else if (type == 1) {
        Against(ID);
    }
}
function Against(ID) {
    var sAgainst = "sAgainst_" + ID;
    $.ajax({
        type: "POST",
        url: "/article/Ajax.aspx",
        data: { "ID": ID, "type": 1, "Action": "votecomment" },
        dataType: "json",
        success: Support_Complete(sAgainst)
    });
}
function Support(ID) {
    var sSupport = "sSupport_" + ID;
    $.ajax({
        type: "POST",
        url: "/article/Ajax.aspx",
        data: { "ID": ID, "type": 0, "Action": "votecomment" },
        dataType: "json",
        success: Support_Complete(sSupport)
    });
}
function Support_Complete(sID) {
    try {
        var sid = '#' + sID;
        var result = parseInt($(sid).html()) + 1;
        $(sid).text(result);
        alert("谢谢參與！");
    }
    catch (e) {
        alert("錯誤!" + e);
    }
}
/************************投票********************************/
function vote(ID) {
    var getvalue = "";
    var rblist = document.getElementsByName("radiobutton");
    for (var i = 0; i < rblist.length; i++) {
        if (rblist[i].checked) {
            getvalue = rblist[i].value;
            $.ajax({
                type: "POST",
                url: "/article/Ajax.aspx",
                data: { "NewsID": ID, "VoteType": getvalue, "Action": "vote" },
                dataType: "json",
                success: Vote_Complete(getvalue)
            });
        }
        else if (rblist[0].checked == false && rblist[1].checked == false && rblist[2].checked == false) {
            alert("請選擇滿意度!");
            return;
        }
    }
}
function Vote_Complete(voteType) {
    try {
        if (voteType == "1") {
            var result = parseInt($('#' + 'txtgood').html()) + 1;
            $('#' + 'txtgood').text(result);
        }
        else if (voteType == "2") {
            var result1 = parseInt($('#' + 'txtGeneral').html()) + 1;
            $('#' + 'txtGeneral').text(result1);
        }
        else if (voteType == "3") {
            var result2 = parseInt($('#' + 'txtBad').html()) + 1;
            $('#' + 'txtBad').text(result2);
        }
        alert("谢谢參與！");
    }
    catch (e) {
        alert("錯誤!" + e);
    }
}
/************************提交评论********************************/
function addComments(ID) {
    var NickName = $("#iNickName").val();
    var Content = $("#iContent").val();
    var vCode = $("#ivCode").val();
    if (NickName.length == 0) {
        $("#error").text("請留下大名!");
        $("#error").fadeIn("fast");
        $("#iNickName").focus();
        return false;
    }
    else if (Content.length == 0) {
        $("#error").text("請說點什麼!(250字內)");
        $("#error").fadeIn("fast");
        $("#iContent").focus();
        return false;
    }
    else if (Content.length > 250) {
        $("#error").text("內容過多!(250字內)");
        $("#error").fadeIn("fast");
        $("#iContent").focus();
        return false;
    }
    else if (vCode.length == 0) {
        $("#error").text("請輸入驗證碼");
        $("#error").fadeIn("fast");
        $("#ivCode").focus();
        return false;
    }
  $("#error").html("評論提交中……");
    $.ajax({
        type: "POST",
        url: "/article/Ajax.aspx",
        data: { "NewsID": ID, "NickName": NickName, "vCode": vCode,
            "Content": Content, "Action": "addComments"
        },
        dataType: "html",
        cache: false,
        success: function(msg) {
            alert(msg);
            return false;
        },
        error: function(msg, status) {
        if (status == 'error') {
             $("#error").text(status);
            }
        }
    });
}

/******************** 点击复制当前地址******************************/
function CopyURL() {
    var myHerf = top.location.href;
    var title = document.title;
    if (window.clipboardData) {
        var tempCurLink = title + "\n" + myHerf;
        var ok = window.clipboardData.setData("Text", tempCurLink);
        if (ok) alert("複制地址成功，按Ctrl + V ,粘貼到MSN、QQ上發給你的好友們吧 ！");
    } else { alert("對不起，目前此功能只支持IE，請直接複制地址欄的地址！"); }
} 