﻿jQuery(document).ready(function() {
    $("#lnkWelcomeMat").click(function() {
        $("*[id$='WelcomeMat']").hide();
    });
});

function SubmitNewsFlash(inputMessageID, textNewsFlashTimeID, textCurrentNewsfeedMessageID, flashdiv) {
    //debugger; 
    var thisInput = $("*[id$='" + inputMessageID + "']");
    if (thisInput.attr("class") != 'watermarked' && (thisInput.val().length > 0 && thisInput.val().length <= 140)) {
        var recentText = $("*[id$='" + inputMessageID + "']").attr("value").replace(/^\s+|\s+$/g, "").replace(/'/g, "''").replace(/"/g, "\\u0022");
        
        $('#addNewsFlash').addClass('on');
        try {

            $.ajax({
                type: "POST",
                url: "/Services/DynamicPanelService.asmx/AddNewsFlash",
                data: '{"newsItem":"' + recentText + '"}',
                contentType: "application/json; charset=utf-8",
                dataType: "json",
                async: false,
                success: function (msg) {
                    $("*[id$='newsflashContainer']").show();
                    var ret = eval('(' + msg.d + ')');
                    $("*[id$='" + textNewsFlashTimeID + "']").text('Last Updated - ' + ret.CreatedDate);
                    $("*[id$='" + inputMessageID + "']").attr("value", "");
                    $("*[id$='" + textCurrentNewsfeedMessageID + "']").html(ret.LinkedDescription);
                    $("*[id$='" + flashdiv + "']").show('slow');
                    $("*[id$='" + inputMessageID + "']").blur();
                    $('#newsflashContainer .comments').hide();
                    $('#newsflashContainer .viewAll').hide();
                    thisInput.height(thisInput.css('line-height')).css("background-color", "#FFF").siblings('.charsLeft').html("");
                    document.location = "#newsflashUpdated";
                    $('#addNewsFlash').removeClass('on');
//                    try {
//                        if (ret.FirstOfTheDay == "Y") {
//                            var currentTokens = $('.GAME_TOKENS:first').html();
//                            if (!isNaN(currentTokens)) {
//                                $('.GAME_TOKENS').html(parseInt(currentTokens) + 100);
//                            }
//                        }
//                    }
//                    catch (e) {

//                    }
                }
            });
        } catch (err) {
            alert(err);
        }
        
    }
    else {
        $("*[id$='" + inputMessageID + "']").css("background-color", "#F9F2E0");
    }
    return false;
}

var $nf = $('div.newsflash blockquote p span').html();
if ($nf) {
    if ($nf.length === 0) {
        $('div.newsflash blockquote').hide();
    }
}

if ($('div.newsflash blockquote p span em').html()) {
    if ($('div.newsflash blockquote p span em').html().length === 0) {
        $('div.newsflash blockquote').hide();
    }
}

$('#addNewsFlash').live('click', function() {
    $('div.newsflash blockquote').show();
});
