﻿/// <reference path="MbScripts/ChallengeBrainstorm.js" />

window.setInterval('_sesssionPinger()', 120000);

function _sesssionPinger() {
    $.ajax({
        type: 'get',
        url: '/Javascript/SessionPinger',
        cache: false,
        success: function(msg) {
            var inboxcount = $('.inboxcount').text().replace("(", "").replace(")", "");

            if (inboxcount != msg) {
                $('.inboxcount').text('(' + msg + ')');
            }
        }
    });
}

mb = {
    $hideElementByid: function(id) {
        /// <summary>hides the element by it's id</summary>
        /// <param name="id">the elements id</param>
        $('#' + id).hide();
    },

    $showElementByid: function(id) {
        /// <summary>shows the element by it's id</summary>
        /// <param name="id">the elements id</param>
        $('#' + id).show();
    },

    $hideElementByclass: function(classname) {
        /// <summary>hide elements that has the class</summary>
        /// <param name="classname">targets classname</param>
        $('.' + classname).hide();
    },

    $showElementByclass: function(classname) {
        /// <summary>show elements that has the class</summary>
        /// <param name="classname">targets classname</param>
        $('.' + classname).show();
    },

    $clearElementByid: function(id) {
        /// <summary>clears the element by it's id</summary>
        /// <param name="id">the elements id</param>
        $('#' + id).html('');
    },

    $clearElementByclass: function(classname) {
        /// <summary>clear elements that has the class</summary>
        /// <param name="classname">targets classname</param>
        $('.' + classname).html('');
    },

    $RemainingCharsLeft: function(maxChars, returnElementId, elementToCount) {
        if ($("#" + elementToCount).val() == '') {
            $("#" + returnElementId).html(maxChars);
        }
        if ($("#" + elementToCount).val() != '') {
            if ((maxChars - $("#" + elementToCount).val().length) > 0) {
                $("#" + returnElementId).html(maxChars - $("#" + elementToCount).val().length);
            }
            else {
                $("#" + returnElementId).html(0);
                $("#" + elementToCount).val($("#" + elementToCount).val().substring(0, maxChars));
                //alert("We will only save the first " + maxChars + " chars");
            }
        }
    },

    Challenge: {
        Brainstorm: {
            $loadProposalComments: function(proposalId, challengeId) {
                loadProposalComments(proposalId, challengeId);
            },
            $loadProposalCommentsAndScroll: function(proposalID, challengeID, contributionID) {
                loadProposalCommentsAndScroll(proposalID, challengeID, contributionID);
            },
            $scrollToContribution: function(text, ID) {
                scrollToContribution(text, ID);
            },
            $sortComments: function(proposalId, sortType) {
                sortComments(proposalId, sortType);
            },
            $showDiv: function(show, proposalId) {
                /// <summary>hides or shows the manage div for that proposal.</summary>
                /// <param name="show">true if it's to be shown, else false</param>
                /// <param name="proposalId">proposal ID for the div</param>
                showDiv(show, proposalId);
            },
            $voteForContribution: function(contributionID) {
                /// <summary>votes the contribution one up</summary>
                voteForContribution(contributionID);
            },
            $submitProposal: function(challengeId, title, content, temporaryToken) {
                /// <summary>saves a new proposal</summary>
                /// <param name="challengeId">The challenge ID for the proposal</param>
                /// <param name="title">The title for the proposal</param>
                /// <param name="content">The content for the proposal</param>
                /// <param name="temporaryToken">The temporaryToken for the proposal, used for attachments</param>
                submitProposal(challengeId, title, content, temporaryToken);
            },
            $submitContribution: function(proposalID, content, contributionType, temporaryToken, challengeID) {
                /// <summary>saves a new contribution</summary>
                /// <param name="challengeId">The challenge ID for the contribution</param>
                /// <param name="title">The title for the contribution</param>
                /// <param name="content">The content for the contribution</param>
                /// <param name="temporaryToken">The temporaryToken for the contribution, used for attachments</param>
                /// <param name="proposalID">The proposal ID for the contribution</param>
                submitContribution(proposalID, content, contributionType, temporaryToken, challengeID);
            },
            $removeContribution: function(contributionId, proposalId, challengeId) {
                removeContribution(contributionId, proposalId, challengeId);
            },
            $closeComments: function(proposalId) {
                closeComments(proposalId);
            },
            $closeAllComments: function() {
                closeAllComments();
            },
            $addToConcept: function(proposalID, type, challengeId) {
                addToConcept(proposalID, type, challengeId);
            },
            $editProposal: function(proposalID, challengeID) {
                editProposal(proposalID, challengeID);
            },
            $deleteProposal: function(proposalId, challengeId) {
                deleteProposal(proposalId, challengeId);
            },
            $updateProposal: function(proposalID, challengeID) {
                updateProposal(proposalID, challengeID);
            },
            $sortProposals: function(challengeID, sortCriteria, sortDirection) {
                sortProposals(challengeID, sortCriteria, sortDirection);
            }
        },
        Concept: {
            test: function() {
            }
        }
    }
}