﻿
//Open the overlay
function openOverlay(NewsID) {
    //debugger;
    //Get hidden field variables
    var servicePath = $("input[id$='hf_WebsiteDomainPath']").val() + "GetNewsItem";

    $.ajax({ type: "POST",
        contentType: "application/json; charset=utf-8",
        url: servicePath,
        data: '{"NewsID": "' + NewsID + '"}',
        dataType: "json",
        error: function(XMLHttpRequest, textStatus, errorThrown) {
            debugger;
            alert("Sorry, we are unable to load the News Detail at this time.");
            //alert(XMLHttpRequest);
            //alert(textStatus);
            //alert(errorThrown);
        },
        success: function(data) {
            loadNewsDetail(data.d);

            if (overlayAPI.isOpened == true) {
                overlayAPI.close();
            }

            overlayAPI.load();
        }
    });
}


//Populate the News Detail
function loadNewsDetail(data) {

    var newsDetail = data;

    //debugger;

    $("#NewsDescription").html(newsDetail.Description);
    $("#NewsTitle").html(newsDetail.Title);
    $("#NewsDatePublished").html(formatJSONDate(Date(newsDetail.DatePublished)));

}


    //Format a date from JSON
    function formatJSONDate(jsonDate) {
    
        var date = "";
        var newDate = dateFormat(date, "mm/dd/yyyy");

        return newDate; 
        
    }
    