﻿var layerWin = document.getElementById("repalylayer");
if (layerWin != null) {
    $("div.Win_overlay").css("height", document.documentElement.offsetHeight + "px");
    var ft = parseInt(document.documentElement.scrollTop + (document.documentElement.clientHeight - layerWin.offsetHeight) / 2);
    layerWin.style.top = ft + "px";
    var flag = 0;
    var speed = 10;
    var acc = 2;
    var PhotoID = $("#PhotoID").val();
    function move() {
        var t = layerWin.style.top;
        var top = parseInt(t.substring(0, t.length - 2));
        var myhigh = parseInt(document.documentElement.scrollTop + (document.documentElement.clientHeight - layerWin.offsetHeight) / 2);
        if (top < myhigh - speed) { layerWin.style.top = top + speed + "px"; }
        else if (top > myhigh + speed) { layerWin.style.top = top - speed + "px"; }
        setTimeout("move()", 2);
    }
}

function scall() { if (flag == 0) { move(); flag = 1; } }



function closerepaly() {
    $(layerWin).hide();
    $("div.Win_overlay").hide();

}

function Add(version) {
    if (typeof version == 'undefined') version = "";
    if ($("#Content").val() == "" || $("#Content").val() == "在此发表评论！") {
        alert("请输入评论内容");
        $("#Content").focus();
        return;
    }
    if ($("#Content").val().length > 5000) {
        alert("评论内容过长");
        $("#Content").focus();
        return;
    }
    var Info = {};
    Info.Content = $("#Content").val();
    if ($("#hidename").length == 0) {
        Info.Hidename = false;
    }
    else {
        Info.Hidename = $("#hidename")[0].checked;
    }
    Info.PhotoID = PhotoID;
    $.post("/PhotoComment.Add" + version + ".data", Info, function(data) {
        if (data == "ok") {
            alert("发表成功");
            location.reload();
        } else {
            alert(data);
        }
    })
}

function Support(ID) {
    $.post("/PhotoComment.Support.data", { ID: ID, PhotoID: PhotoID }, function(data) {
        self.location.reload();
    })
}

function Del(ID) {
    $.post("/PhotoComment.Del.data", { ID: ID, PhotoID: PhotoID }, function(data) {
        self.location.reload();
    })
}

function Against(ID) {
    $.post("/PhotoComment.Against.data", { ID: ID, PhotoID: PhotoID }, function(data) {
        self.location.reload();
    })
}

function Repaly(version) {
    if (typeof version == 'undefined') version = "";
    if ($("#repalycontent").val() == "" || $("#repalycontent").val() == "在此发表评论！") {
        alert("请输入评论内容");
        $("#repalycontent").focus();
        return;
    }
    var Info = {};
    Info.Content = $("#repalycontent").val();
    //Info.hidename=$("#repalyhidename")[0].checked;
    Info.PhotoID = PhotoID;
    Info.ParentID = repalyid
    $.post("/PhotoComment.Add" + version + ".data", Info, function(data) {
        if (data == "ok") {
            alert("发表成功");
            location.reload();
        } else {
            alert(data);
        }
    })
}

function PreRepaly(id) {
    repalyid = id;
    $(layerWin).show();
    $("#repalycontent").focus();
    $("div.Win_overlay").show();
}

window.onscroll = scall;
