﻿function SubmitComment(valgroup, pop) {
    if (Page_ClientValidate(valgroup)) {
        return true;
    }
    else {
        return false;
    }
}

function comment_begin(sender, args) {
    // This is a shitty way to determine if this is a cancel event
    if (args._postBackElement.className == 'cancelComment') {
    }
    else {
        // FRAGILE (French) - handle w/ care...if layout of comment box changes, then BOOM!
        $('#' + args._postBackElement.id).parent().find('.waitPopup').modal({ minWidth: 100, minHeight: 100 });
    }
}

function comment_end(sender, args) {
    $.modal.close();

    var parg = args.get_dataItems()[sender._postBackSettings.sourceElement.id];
    if (parg != undefined) {
        window.location.href = parg;
        /* $('html, body').animate({
            scrollTop: $(parg).offset().top
        }, 500); */
        window.location.reload(true);
    }
    
    $.clearwatermarks();
    $.addwatermarks();
}

function do_expand(toExpand) {
    if (toExpand.css("display") == "none") {
        toExpand.slideDown(500);
    }
    else {
        toExpand.slideUp(500);
    }
}

$(document).ready(function() {
    Sys.WebForms.PageRequestManager.getInstance().add_beginRequest(comment_begin);
    Sys.WebForms.PageRequestManager.getInstance().add_endRequest(comment_end);

    $('a.addCommentLink').click(function() {
        var toExpand = $(this).parent().next().find('> .commentForm');
        do_expand(toExpand);
        return false;
    });
    $('a.replyCommentLink').click(function() {
        var toExpand = $(this).parent().find('.commentForm');
        do_expand(toExpand);
        return false;
    });
});