﻿// JScript File

function MakePost()
{
    // use jquery ajax to make the server call
    var threadId = $('#threadId').val();
    var postBody = $('#postBody').val();
    var createdBy = $('#createdBy').val();
    $.post('/CoreCode/Modules/Content/Forum/Assets/ForumAjax.aspx?method=MakePost', { 
        ThreadId: threadId, 
        PostBody: postBody, 
        CreatedBy: createdBy 
        }, function (payload){
            $('#divMakePost').text(payload);
            if(payload == "Thank you, your post has been made.")
            {
                var postList = $('div .forum_post_list');
                var postCount = postList.find('.forum_post,.forum_post_alternate').size();
                var newPost = '<div class="forum_post';
                var dateNow = new Date();
                if((postCount % 2) == 1)
                {
                    newPost += '_alternate';
                } 
                newPost +=  '"><span class="post_author">you on ' + dateNow.getDay() + '/' + dateNow.getMonth() + '/' + dateNow.getFullYear() + '</span><p>' +  postBody + '</p></div>';            
                postList.append(newPost);               
            }
            
    });
}



function MakeThread(fid)
{
    // use jquery ajax to make the server call
    var forumId = $('#forumId' + fid).val();
    var postBody = $('#postBody' + fid).val();
    var postSubject = $('#postSubject' + fid).val();
    var createdBy = $('#createdBy' + fid).val();
    $.post('/CoreCode/Modules/Content/Forum/Assets/ForumAjax.aspx?method=MakeThread', { 
        ForumID: forumId, 
        PostSubject: postSubject, 
        PostBody: postBody, 
        CreatedBy: createdBy
        }, function(payload){
            $('#divMakePost' + fid).text(payload);
            if(payload == "Thank you, your thread has been created.")
            {
                window.location.href = window.location.href;              
            }
    });
}