﻿function ShowCommentForm(hyperlink, commentform) {
    if ($("#" + commentform).hasClass("CommentFormOpen")) {
        $("#" + commentform).removeClass("CommentFormOpen");
        $("#" + commentform).hide();
    }
    else {
        $("#" + commentform).addClass("CommentFormOpen");
        $("#" + commentform).slideDown();
    }
}

//Wall attach function
function showUploadSection(uploadSectionId) {
    if ($('#CurrentOpenUploadSection').val() == uploadSectionId) {
        hideUploadSection($('#CurrentOpenUploadSection').val());
        $('#SpanLinkButtonPost').show();
    }

    else {
        $('#SpanLinkButtonPost').hide();
        if ($('#CurrentOpenUploadSection').val() != "")
            hideUploadSection($('#CurrentOpenUploadSection').val());

        $('#CurrentOpenUploadSection').val(uploadSectionId);
        //$('#' + uploadSectionId).slideDown(200); // Funkar dåligt i IE7
        $('#' + uploadSectionId).show();

    }
}

function hideUploadSection(uploadSectionId) {
    resetVideoUpload();
    $('#' + uploadSectionId).hide();
    $('#CurrentOpenUploadSection').val("");
}

function collapseUploadSection() {
    if ($('#CurrentOpenUploadSection').length && $('#CurrentOpenUploadSection').val() != "") {
        hideUploadSection($('#CurrentOpenUploadSection').val());
        $('#SpanLinkButtonPost').show();
    }
}

function resetVideoUpload() {
    $('.uploadVideo').hide();
    $('.attachYoutube').hide();
    $('.AttachVideo, .pickUpload').show();
}

function pickUpload(k) {
    if (k == 'attachYoutube')
        $('.AttachVideo').hide();
    $('.AttachVideo .pickUpload, .AttachVideo .seperator').hide();
    $('.' + k).show();
    return false;
}

function validateVideoFormat(format) {
    return true;
    format = format.toLowerCase();
    return format.match("wmv" + "$") == "wmv" || format.match("avi" + "$") == "avi" || format.match("mpg" + "$") == "mpg" || format.match("mpeg" + "$") == "mpeg" || format.match("mov" + "$") == "mov" || format.match("mkv" + "$") == "mkv" || format.match("vob" + "$") == "vob" || format.match("3gp" + "$") == "3gp" || format.match("mp4" + "$") == "mp4";
}

function ConfirmationMessage(text) {
    confirmation(text);
}

// Wall functions
function RemoveWallEntryQuestion(text, entryId, listItem) {
    confirm(text, "RemoveWallEntry('" + entryId + "', '" + listItem + "');");
}

function RemoveWallEntry(entryId, listItem) {
    Dvoted.CMS.Services.AjaxScriptService.RemoveWallEntry(entryId, listItem, RemoveWallEntry_Callback);
}

function RemoveWallEntryCommentQuestion(text, commentId, listItem) {
    confirm(text, "RemoveWallEntryComment('" + commentId + "', '" + listItem + "');");
}

function RemoveWallEntryComment(commentId, listItem) {
    Dvoted.CMS.Services.AjaxScriptService.RemoveWallEntryComment(commentId, listItem, RemoveWallEntry_Callback);
}

function RemoveWallEntry_Callback(result) {
    if (result) {
        $('#' + result[1]).slideUp();
    }
    else {
        confirmation("System error - Please try again later");
    }
}

function ValidateComment(obj) {
    var textarea = $(obj).parent().find("textarea");
    return textarea.val().trim() != "";
}
