﻿function IsNull(txt) { return typeof (txt) == 'undefined' || txt == null || txt.length == 0; }
function IsZero(txt) { txt = parseInt(txt); return isNaN(txt) || txt == 0; }
function ToInte(txt) { txt = parseInt(txt); if (isNaN(txt)) { txt = 0; } return txt; }

function BoxShow(elm, wid, hei) {
    $("<div id=\"mtWins_PaOve\"></div>").appendTo("body").click(function() { $("#mtWins_PaOve,#mtWins_PaBox").remove(); });
    $("<div id=\"mtWins_PaBox\"></div>").appendTo("body").click(function() { $("#mtWins_PaOve,#mtWins_PaBox").remove(); }).css({ width: wid, height: hei, top: $(window).scrollTop() + ($(window).height() - hei) / 2, left: $(window).scrollLeft() + ($(window).width() - wid) / 2 }).append(elm);
}

function DotRoll(elm) {
    $("body,html").animate({ scrollTop: $("a[name='" + elm + "']").offset().top }, 500);
}

function CommPost(idx) {
    var nuName = $("#ncUsername").val(), nuMail = $("#ncUsermail").val(), nuSite = $("#ncUsersite").val(), ncText = $("#ncContent").val();
    $("#CommentPostMSG").show().children("dd").html(PubLAN.mcPostComment); $("#ncSubmit").attr("disabled", "disabled");
    $.post("../Service.ashx?act=CommPost", { ncParent: idx, ncUsername: nuName, ncUsermail: nuMail, ncUsersite: nuSite, ncContent: ncText }, function(txt) {
        if (txt.substr(0, 6) == "Error:") { $("#CommentPostMSG").show().children("dd").html(txt.substr(6, txt.length)); }
        else { $("#ncContent").val(""); $("#CommentPostMSG").hide(); $("#NoComments").remove(); $("#coList").append(txt); }
        $("#ncSubmit").attr("disabled", "");
    });
}

function CommList(art, idx) {
    $.get("../Service.ashx?act=CommList&var=" + art + "&idx=" + idx, function(txt) {
        var dat = txt.split("<!-- COMMENTPGSPLITHR -->"); $("#coList").html(dat[0]); $("#coListMPG").html(dat[1]);
    });
}

function CommCite(idx, aut) {
    var citeTxt = "[" + idx + "@" + aut + "]", commTxt = $("#ncContent").val();
    if (IsNull(commTxt)) { $("#ncContent").val(citeTxt); }
    else if (commTxt.indexOf(citeTxt) == -1) {
        citeTxt = $("#ncContent").val() + "\r\n" + citeTxt;
        $("#ncContent").val(citeTxt);
    }
    DotRoll("CommentPostAnchor");
}

function EnatView(id) {
    var wTxt = $("#PwdVar_" + id).val();
    $.get(SitePath + "Service.ashx?act=EnatView&aid=" + id + "&awd=" + wTxt, function(txt) {
        if (txt.substr(0, 6) == "Error:") {
            $("#PwdErr_" + id).html(txt.substr(6, txt.length)).show();
        } else {
            $("#PwdForm_" + id).hide();
            $("#PwdTxt_" + id).html(txt).show();
        }
    });
}


$(document).ready(function() {
    $("img.Image,img.Picture").each(function() {
        if (ToInte($(this).attr("width")) > 600) {
            var oIMA = new Image(); oIMA.src = $(this).attr("src"); var tWid = oIMA.width; oIMA = null; $(this).css({ 'width': (tWid > 600) ? 600 : tWid, 'display': 'inline' });
        }
        $(this).attr("title", PubLAN.mvClickViewAll).click(function() {
            var oIMA = new Image(); oIMA.src = $(this).attr("src"); BoxShow(oIMA, oIMA.width, oIMA.height); oIMA = null;
        });
    });
    $("#CommentList ol li a.cite").live("mouseover", function() {
        var oID = ToInte($(this).attr("href").replace(/.*#CommentAnchor_(\d)/, "$1"));
        if (oID > 0) {
            var oOF = $(this).offset();
            if ($("#Comm-" + oID).length == 0) {
                $("<ol id=\"mtWins_PaAlt\" class=\"colist\"></ol>").appendTo("body").css({ top: oOF.top + 22, left: oOF.left }).load(SitePath + "Service.ashx?act=CommView&cid=" + oID).hide().fadeIn(200);
            } else {
                $("<ol id=\"mtWins_PaAlt\" class=\"colist\"></ol>").appendTo("body").css({ top: oOF.top + 22, left: oOF.left }).append($("#Comm-" + oID).clone().attr("id", "")).hide().fadeIn(200);
            }
        }
    }).live("mouseout", function() {
        $("#mtWins_PaAlt").show().fadeOut(300, function() { $(this).remove(); });
    });
});
