﻿function insertAtCursor(myField, myValue) {
    //IE support
    if (document.selection) {
        myField.focus();
        sel = document.selection.createRange();
        sel.text = myValue;
    }
    //MOZILLA/NETSCAPE support
    else if (myField.selectionStart || myField.selectionStart == '0') {
        var startPos = myField.selectionStart;
        var endPos = myField.selectionEnd;

        myField.value = myField.value.substring(0, startPos)
                  + myValue
                  + myField.value.substring(endPos, myField.value.length);
    } else {
        myField.value += myValue;
    }
}

$(function() {
    setUpContentCommentsControlBehaviour();
});

function ControlAjaxResponseEnd(sender, args) {
    setUpContentCommentsControlBehaviour();
}

function setUpContentCommentsControlBehaviour() {
    $(".reply").click(
                
                function() {
                    $(".pnlAddComment > input[type='hidden']:first").val($(this).siblings("[type=hidden]").val());
                    $(".pnlAddComment").appendTo($(this).parent().parent());
                    $(".pnlAddComment").addClass("comment");
                });
    $("#lnkCancelReply").click(function() {
        $(".pnlAddComment > input[type='hidden']:first").val("-1");
        $(".pnlAddComment").appendTo($("#commentPlaceHolder"));
        $(".pnlAddComment").removeClass("comment");
    });
    $(".addmenu > .youtube").click(function() { $(".addyoutube").siblings().hide(); $(".addyoutube").show() });
    $(".addmenu > .link").click(function() {
        var url = prompt("Url", "http://");
        var desc = prompt("Description", "");
        document.getElementById($(".addCommentBox > textarea").attr("id")).focus();
        insertAtCursor(document.getElementById($(".addCommentBox > textarea").attr("id")), "[url=\"" + url + "\"]" + desc + "[/url]");
    });
    $(".addlinkurl > .shownext").click(function() { $(".addlinkdesc").siblings().hide(); $(".addlinkdesc").show() });
    $(".addimg > .imgurl").click(function() { $(".addimgurl").siblings().hide(); $(".addimgurl").show() });
    $(".addimg > .imgupload").click(function() { $(".addimgupload").siblings().hide(); $(".addimgupload").show() });
    $(".addmenu > .img").click(function() { $(".addimg").siblings().hide(); $(".addimg").show() });
    $(".showmenu").click(function() { $(".addmenu").siblings().hide(); $(".addmenu").show() });
    $(".pnlAddComment").appendTo($("#commentPlaceHolder"));

    $("a.commentImage").colorbox();
    
}

