﻿$(document).ready(function() {
    if (document.getElementById('hfLogin').value == "false") {
        alert("Session has expired, please login again");
        parent.window.location.href = "http://www.locallinkup.com";
    }
});

function cancel() {
    parent.hideModalWindow('editNewsModal');
}

function saveBlog() {
    if (document.getElementById('hfBlogID').value != "") {
        var strURL = parent.document.getElementById('hfHandlerURL').value + "/updateBlogHandler.ashx";
        $.post(strURL, {
            compID: parent.document.getElementById('hfCompanyID').value,
            blogID: document.getElementById('hfBlogID').value,
            head: document.getElementById('headlineText').value,
            cont: document.getElementById('detailsText').value
        }, function(data) {
            if (data == "success") {
                parent.showMessage('news_item_updated', 3000, "small");
                parent.hideModalWindow('editNewsModal');
            }
        });
    }
    else {
        if (document.getElementById('headlineText').value != "" && document.getElementById('headlineText').value != "[News Headline]") {
            if (document.getElementById('detailsText').value != "" && document.getElementById('detailsText').value != "[News Content]") {
                var strURL = parent.document.getElementById('hfHandlerURL').value + "/addBlogHandler.ashx";
                $.post(strURL, {
                    plID: parent.document.getElementById('hfPlinkID').value,
                    title: document.getElementById('headlineText').value,
                    cont: document.getElementById('detailsText').value
                }, function(data) {
                    parent.showMessage('news_item_updated', 3000, "small");
                    parent.hideModalWindow('editNewsModal');
                });
            }
            else {
                parent.showMessage('blog_description', 3000, "small");
            }
        }
        else {
            parent.showMessage('blog_headline', 3000, "small");
        }
    }
}

function deleteBlog() {
    parent.confirmDeleteNews(document.getElementById('hfBlogID').value);
}

function setHelpText(id) {
    parent.setWizardText(id);
}
