﻿
function LoadVideoPreview(element, hidLoadVideoPreview, hidVideoURL)
{
    var url = $(element).value;
 
    if(url == null){ return ""; }

    var results;

    //YouTube
    results = url.match("[\\?&]v=([^&#]*)");

    if (results != null )
    {
        $(hidVideoURL).value = url;
        $(hidLoadVideoPreview).value = results[1];
        
        __doPostBack(hidLoadVideoPreview,'');
    }
}

function AddCommentBox(id, mid, photo, commentTypeID, hidNewsFeedID, hidMemberInfoID, hidComment, hidPostComment, hidCommentTypeID)
{

    $('post_comment_' + id).innerHTML = "<table style=\"width: 100%;\" cellspacing=\"0\" cellpadding=\"0\"><tr><td style=\"width: 60px;\">&nbsp;</td><td valign=\"top\"><img src=\"" + photo + "\" style=\"border: solid 2px #484848;\"></td><td valign=\"top\"><table cellspacing=\"0\" cellpadding=\"0\" border=\"0\"><tr><td align=\"right\" valign=\"top\"><textarea id=\"comment_" + id + "\" rows=\"2\" cols=\"20\" style=\"width: 400px; height: 35px;\" class=\"textbox_black_plain_sm\" onblur=\"RemoveCommentBox(" + id + "," + mid + ",'" + photo + "'," + commentTypeID + ",'" + hidNewsFeedID + "','" + hidMemberInfoID + "','" + hidComment + "','" + hidPostComment + "','" + hidCommentTypeID + "');\"></textarea></td></tr>" +
    "<tr><td align=\"right\" valign=\"top\"><input type=\"button\" class=\"black_button_sm\" value=\"Comment\" onclick=\"PostNewsFeedComment('" + hidNewsFeedID + "','" + hidMemberInfoID + "', '" + hidComment + "', '" + hidPostComment + "','" + hidCommentTypeID + "'," + commentTypeID + "," + id + "," + mid + ", '" + photo + "');\" /></td></tr></table></td></tr></table>";

    setTimeout( "$('comment_" + id + "').focus()", 10 );
    
}

function RemoveCommentBox(id, mid, photo, commentTypeID, hidNewsFeedID, hidMemberInfoID, hidComment, hidPostComment, hidCommentTypeID)
{

    if($("comment_" + id).value == '')
        $('post_comment_' + id).innerHTML = "<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\" width=\"100%\"><tr><td style=\"width: 60px;\">&nbsp;</td><td><input id=\"post_comment_text_" + id + "\" type=\"text\" class=\"textbox_black_plain_sm\" value=\"Write a comment...\" style=\"width: 460px;\" onfocus=\"AddCommentBox(" + id + "," + mid + ",'" + photo + "'," + commentTypeID + ",'" + hidNewsFeedID + "','" + hidMemberInfoID + "','" + hidComment + "','" + hidPostComment + "','" + hidCommentTypeID + "');\"></td></tr></table>";
    
}

function PostNewsFeedComment(hidNewsFeedID, hidMemberInfoID, hidComment, hidPostComment, hidCommentTypeID, commentTypeID, id, mid, photo)
{

    $(hidNewsFeedID).value = id;
    $(hidMemberInfoID).value = mid;
    $(hidCommentTypeID).value = commentTypeID;
    $(hidComment).value = $('comment_' + id).value;
    $(hidPostComment).value = 1; //Post Comment
    
    $('comment_' + id).value = "";
    RemoveCommentBox(id, mid, photo, commentTypeID, hidNewsFeedID, hidMemberInfoID, hidComment, hidPostComment, hidCommentTypeID);
    
    __doPostBack(hidPostComment,'');
    
}

function PostNewsFeed(hidPostComment, hidComment)
{

    $(hidComment).value = $('comment').value;
    $(hidPostComment).value = 3; //Post NewsFeed
    
    $('comment').value = "";
    
    __doPostBack(hidPostComment,'');
    
}

function AppendComment(nFID, nFTID, ANCID, html)
{
    var newDIV = document.createElement('div');

    newDIV.setAttribute('id', nFID + "_" + nFTID + "_" + ANCID);
    
    newDIV.innerHTML = html;

    newDIV.style.marginBottom = "2px";
    
    $('comments_' + nFID).appendChild(newDIV);
}

function DeleteNewsFeedComment(nFID, nFTID, aNCID, hidNewsFeedID, hidPostComment, hidAssociatedNCID, hidCommentTypeID)
{
    $('comments_' + nFID).removeChild($(nFID + "_" + nFTID + "_" + aNCID));
    
    $(hidNewsFeedID).value = nFID;
    $(hidAssociatedNCID).value = aNCID;
    $(hidCommentTypeID).value = nFTID;
    
    $(hidPostComment).value = 2; //Delete Comment
    
    __doPostBack(hidPostComment,'');
}