﻿function openFixedPopup(url, title, articleLink) {
    var link = url + "?Title=" + title + "&ArticleLink=" + articleLink;
    var width = 500;
    var height = 500;
    var top = (screen.height - height) / 2;
    var left = (screen.width - width) / 2;
    window.open(link, '', 'width=' + width + ',height=' + height + ',left=' + left + ',top=' + top + ',resizable=no,scrollbars=no', false);
}
if (typeof (AGFS) == "undefined")
    AGFS = {};
if (typeof (AGFS.Article) == "undefined")
    AGFS.Article = {};
AGFS.Article.ArticleDetail =
{
    Content: '',
    _dateCurrent: '',
    //Chi tiết tin tức
    //Hiển thị nội dung chi tiết của bài tin, tổng số lượt đọc, quay lại trang, bản in, email
    LoadDetailArticles: function (ArticleID, TabID, ModuleID) {
        var ArticleSearch = "#ArticleSearch" + ModuleID;
        var ArticlePaging = "#ArticleIndex" + ModuleID;
        var ArticleList = "#ArticleList" + ModuleID;
        $(ArticleSearch).hide();
        $(ArticlePaging).html('');
        $(ArticleList).html('');
        var Content = '';
        var loading = "<div style='clear:both;'/><div class='AL_Loading_Div' ><img  src='" + ImageInfo.Loading + "'  style='height:30px;'/>";
        $(ArticleList).html(loading);
        var m_path = "/Handler/AG.Article/GetDetailArticles.ashx?ArticleId=" + ArticleID;
        var formatDate = "";
        if (agLanguageName == "vi-VN")
            formatDate = "dd/MM/yyyy hh:mm tt";
        else if (agLanguageName == "en-US")
            formatDate = "MM/dd/yyyy hh:mm tt";
        $.ajax({
            type: "GET",
            url: m_path,
            dataType: "xml",
            success: function (XML) {
                var count = 0;
                $(XML).find("News_Articles").each(function () {
                    if (count == "0") {
                        var date = $(this).find("DisplayDate").text();
                        AGFS.Article.ArticleDetail._dateCurrent = AGFS.DateUtils.convertDateToString($(this).find("DisplayDate").text(), "yyyy-MM-dd HH:mm:ss");
                        //Title
                        Content += "<div class='M_AD_Title'>";
                        date = AGFS.DateUtils.convertDateToString(date, formatDate);
                        if ($(this).find('Source').text().length > 0) {
                            var source = $(this).find('Source').text() + ' - ';
                        }
                        else {
                            var source = "";
                        }
                        if ($(this).find('Source').text().length > 0) {
                            var source_end = ArticleListInfo.Source + $(this).find('Source').text();
                        }
                        else {
                            var source_end = "";
                        }
                        if (agLanguageName = 'vi-VN') {
                            Content += $(this).find('Title').text() + "<div class='M_AD_Date'>&nbsp;" + date + "</div>";
                        }
                        Content += "</div>";
                        //Lead
                        if ($(this).find('Lead').text().length > 0) {
                            Content += '<div class="M_AD_Lead">';
                            Content += $(this).find('Lead').text();
                            Content += '</div>';
                        }
                        var strContent = $(this).find('Content').text();
                        Content += '<div class="M_AD_Content">';
                        if (strContent.indexOf("&lt;") != '-1') {
                            strContent = AGFS.EncoderUtils.htmlDecode(strContent);
                        }
                        strContent = strContent.replace("Times New Roman", "Arial").replace("pt;", "px;");
                        Content += strContent;
                        Content += "</div>";
                        Content += "<div class='M_NVS_Source'>" + source_end + "</div>";
                        Content += "<div class='clear'></div>";
                        Content += '<div class="lineSeperate"></div>';
                        Content += "<div class='M_AD_NextList' Id='NextArticle1" + ModuleID + "'></div>";
                        Content += "<div class='M_AD_NextList' Id='NextArticle2" + ModuleID + "'></div>";
                        Content += '<div class="M_AD_LastUpdate" Id="LastUpdate' + ModuleID + '"></div>';
                        var Id = $(this).find('Id').text();
                        Content += '<div style="font:12px arial;text-align:right;margin-top:15px">' + ArticleDetailInfo.ReadNumber + '';
                        Content += '<span class="M_AD_Count" Id="Count' + Id + '"></span></div>';
                        Content += "<div class='M_AD_Bottom1' Id='Bottom" + ModuleID + "'></div>";
                        // Chuỗi Content dùng để in
                        AGFS.Article.ArticleDetail.Content = Content;
                        var ModuleIdOther = parseInt(ModuleID) + 1000;
                        Content += "<div class='M_Clear'></div><div class='M_AD_Title_2'>" + ArticleDetailInfo.OtherArticles + "</div><div ID='ArticleList" + ModuleIdOther + "'></div><div ID='ArticleIndex" + ModuleIdOther + "'></div>";
                        $(ArticleList).html(Content);
                        $(".csAB08E6E9").ready(function () {
                            $(".csAB08E6E9").css("font-size", "10pt");
                        });
                        $(".cs2D1EE927").ready(function () {
                            $(".cs2D1EE927").css("font-size", "10pt");
                        });
                        AGFS.Article.ArticleDetail.LoadCountAndUpdate(Id);
                        AGFS.Article.ArticleDetail.LoadBottomGoHomeSendMail(ModuleID, ArticleID);
                        AGFS.Article.Search.SearchAD(ModuleID, '1');
                    }
                    //count++;
                });
                if ($(XML).find('Title').text().length == 0)
                    Content = "<div style=\"color:red;\">" + Warning.FileNotFound + "</div>";
            }
        });
    },
    LoadDetailFullText: function (ArticleID, TabID, ModuleID) {
        var ArticleSearch = "#ArticleSearch" + ModuleID;
        var ArticlePaging = "#ArticleIndex" + ModuleID;
        var ArticleList = "#ArticleList" + ModuleID;
        $(ArticleSearch).html('');
        $(ArticlePaging).html('');
        $(ArticleList).html('');
        var Content = '';
        var loading = "<div style='clear:both;'/><div class='AL_Loading_Div' ><img  src='" + ImageInfo.Loading + "'  style='height:30px;'/>";
        $(ArticleList).html(loading);
        var formatDate = "";
        if (agLanguageName == "vi-VN")
            formatDate = "dd/MM/yyyy  - HH:mm:ss";
        else if (agLanguageName == "en-US")
            formatDate = "MM/dd/yyyy - HH:mm:ss";
        var m_path = "/Handler/AG.Article/GetDetailArticles.ashx?ArticleId=" + ArticleID;
        $.ajax({
            type: "GET",
            url: m_path,
            dataType: m_path,
            success: function (XML) {
                var count = 0;
                $(XML).find("News_Articles").each(function () {
                    if (count == "0") {
                        var date = $(this).find("DisplayDate").text();
                        AGFS.Article.ArticleDetail._dateCurrent = AGFS.DateUtils.convertDateToString($(this).find("DisplayDate").text(), "yyyy-MM-dd HH:mm:ss");
                        Content += "<div class='M_AD_Title'>" + $(this).find("Title").text() + "</div><div style='clear:both;'/><div style='font-weight:normal;font-size:12px; color:#727272;float:left;padding:0 10px;'>&nbsp;" + $(this).find('Source').text() + AGFS.DateUtils.convertDateToString($(this).find("DisplayDate").text(), formatDate) + "</div>";
                        Content += "<div style='clear:both;'></div>";
                        //Lead
                        if ($(XML).find('Lead').text().length > 0) {
                            Content += '<br/><br/><div class="M_AD_Lead">';
                            Content += $(this).find('Lead').text();
                            Content += '</div>';
                        }
                        var strContent = $(this).find('Content').text();
                        Content += '<div class="M_AD_Content">';
                        if (strContent.indexOf("&lt;") != '-1') {
                            strContent = AGFS.EncoderUtils.htmlDecode(strContent);
                        }
                        strContent = strContent.replace("Times New Roman", "Arial").replace("pt;", "px;");
                        Content += strContent;
                        Content += "</div>";
                        if ($(this).find('Source').text().length > 0) {
                            Content += "<div class='M_AD_Source'><a>" + ArticleListInfo.Source + " &nbsp;" + $(this).find('Source').text() + "&nbsp;</a></div>";
                            Content += "<div class='clear'></div>";
                        }
                        Content += '<div class="M_AD_LastUpdate" Id="LastUpdate' + ModuleID + '"></div>';
                        Content += '<div class="M_AD_Count" Id="Count' + Id + '"></div>';
                        Content += '<div class="lineSeperate"/>';
                        Content += "<div class='M_AD_NextList' Id='NextArticle1" + ModuleID + "'></div>";
                        Content += "<div class='M_AD_NextList' Id='NextArticle2" + ModuleID + "'></div>";
                        Content += "<div class='M_AD_Bottom' Id='Bottom" + ModuleID + "'></div>";
                        // Chuỗi Content dùng để in
                        AGFS.Article.ArticleDetail.Content = Content;
                        var ModuleIdOther = parseInt(ModuleID) + 1000;
                        Content += "<div class='M_Clear'><div class='M_AD_Title_2'>" + ArticleDetailInfo.OtherArticles + "</div><div ID='ArticleList" + ModuleIdOther + "'></div><div ID='ArticleIndex" + ModuleIdOther + "'></div>";
                        $(ArticleList).html(Content);
                        AGFS.Article.ArticleDetail.LoadBottomGoHomeSendMail(ModuleID, ArticleID);
                        AGFS.Article.Search.SearchNextFullText(ModuleID, '1');
                    }
                    count++;
                });
                //if ($(XML).find('Title').text().length == 0)
                //  Content = "<div style=\"color:red;\">" + Warning.FileNotFound + "</div>";
            }
        });
    },
    //Chi tiết tin khi click vào hiện lên phân hiển thị mở rộng
    LoadListDetailArticlesExpand: function (Url, ArticleID) {
        var strUrl = "/Handler/AG.News/GetDetailArticles.ashx?ArticleID=" + ArticleID;
        $.ajax({
            type: "GET",
            url: url,
            dataType: "xml",
            success: function (XML) {
                if ($(XML).find('Title').text().length == 0) {
                    strContent = "<div style=\"color:red;\">Không tìm thấy file này</div>";
                }
                else {
                    var strContent = $(XML).find('Content').text();
                    var divName = "#DivContent" + ArticleID;
                    var priviousDiv = "#DivContent" + previousArticleID;
                    $(priviousDiv).html('');
                    if (priviousDiv != divName)
                        $(priviousDiv).hide();
                    $(divName).html(AGFS.EncoderUtils.htmlDecode("<div style='padding-right:10px;'>" + strContent + "</div>"));
                    $(divName).toggle("slow ");
                    previousArticleID = ArticleID;
                }
            },
            error: function displayError(request, errorType, errorThrown) {
            }
        });
    },

    //Hiển thị nội dung chi tiết tin tuyển dụng
    isOpen: 0,
    previousArticleID: -1,
    LoadScoll: function (ArticleId) {
        var url = "/Handler/AG.Article/GetDetailArticles.ashx?ArticleId=" + ArticleId;
        $.ajax({
            type: "GET",
            url: url,
            dataType: "xml",
            success: function (XML) {
                if ($(XML).find('Title').text().length == 0) {
                    strContent = "<div style=\"color:red;\">Không tìm thấy file này</div>";
                }
                else {
                    var strContent = $(XML).find('Content').text();
                    var divName = "#CareerDetail" + ArticleId;
                    var priviousDiv = "#CareerDetail" + AGFS.Article.ArticleDetail.previousArticleID;
                    $(divName).html(AGFS.EncoderUtils.htmlDecode("<div style='padding:10px 150px 10px 20px; font:11px Arial; color:#727272;'>" + strContent + "</div>"));
                    if (priviousDiv != divName) {
                        AGFS.Article.ArticleDetail.isOpen = 1;
                        $(divName).show();
                        $(priviousDiv).hide();
                    }
                    else {
                        if (AGFS.Article.ArticleDetail.isOpen == 0) {
                            $(divName).toggle("slow ");
                            AGFS.Article.ArticleDetail.isOpen = 1;
                        }
                        else {
                            $(divName).hide();
                            AGFS.Article.ArticleDetail.isOpen = 0;
                        }
                    }
                    AGFS.Article.ArticleDetail.previousArticleID = ArticleId;
                }
            },
            error: function displayError(request, errorType, errorThrown) {
            }
        });
    },
    LoadBottomGoHomeSendMail: function (ModuleID, ArticleID) {
        var ObjectModuleName = '#ObjectModuleID' + ModuleID;
        var CollectionParam = $(ObjectModuleName).text();
        var TabLink = ModuleUtils.GetTabLink(CollectionParam);
        var ContentBottom = '<div style="clear: both"/><div align="right" class="AD_LBGH_Div">';
        ContentBottom += '<a onclick="AGFS.Article.ArticleDetail.GoBackList(\'' + ModuleID + '\')" style="cursor:pointer;" ';
        ContentBottom += 'title="' + ArticleDetailInfo.GoBack + '" class="AD_LBGH_A"><img border="0" alt="" src="/DeskTopModules/AG.Article/App/Images/S_ToBack.jpg" /> ';
        ContentBottom += ArticleDetailInfo.Back;
        ContentBottom += '</a>';
        ContentBottom += '<span id="inSpan' + ModuleID + '" style="padding:0 15px"></span>';
        ContentBottom += '<span id="MailSpan' + ModuleID + '"></span>';
        $('#Bottom' + ModuleID).html('');
        $('#Bottom' + ModuleID).html(ContentBottom);
        AGFS.Article.ArticleDetail.LoadPrint(ModuleID, ArticleID);
        AGFS.Article.ArticleDetail.LoadSendMail(ModuleID, ArticleID);
    },

    GoBackList: function (ModuleID) {
        var temp = location.hash.replace('#', '');
        location.hash = '#AL,' + ModuleID;
        var ArticleSearch = "#ArticleSearch" + ModuleID;
        $(ArticleSearch).show();
    },
    LoadCountAndUpdate: function (Id) {
        var urlhander = '/Handler/AG.Article/GetArticleReadCount.ashx?Id=' + Id;
        var content = '';
        $.ajax({
            type: 'POST',
            url: urlhander,
            dataType: 'html',
            success: function (result) {
                var countArticle = "#Count" + Id;
                $(countArticle).ready(function () {
                    $(countArticle).html(result);
                });
            }
        });
    },
    TempPrint: function (ArticleId) {
        AGFSLib.Printf(AGFS.Article.ArticleDetail.Content, ArticleId);
    },

    LoadPrint: function (ModuleID, ArticleID) {
        var temp = location.hash.replace('#', '');
        var ObjectModuleName = '#ObjectModuleID' + ModuleID;
        var CollectionParam = $(ObjectModuleName).text();
        var urlFilePath = ModuleUtils.GetXmlDetail(CollectionParam);

        var contentIN = "<a class='aPrint' onclick='AGFS.Article.ArticleDetail.TempPrint(" + ArticleID + ")' style='cursor:pointer;' >";
        contentIN += " <img border=\"0\" style='width:15px' src=\"/DesktopModules/AG.Article/App/Images/S_News_Print.gif\" alt=\"\" />&nbsp;&nbsp;" + ArticleDetailInfo.Print + "</a>&nbsp;"
        $('#inSpan' + ModuleID).html(contentIN);
    },

    LoadSendMail: function (ModuleID, ArticleID) {
        contentMail += ' <span style="font-family: Arial;"> &#160;<a title="' + ArticleDetailInfo.SendMail + '" >';
        var articleLink = document.location.href;
        var contentMail = ' <span style="font-family: Arial;"> &#160;<a title="' + ArticleDetailInfo.SendMail + '" style="cursor:pointer;" onclick="openFixedPopup(\'/DesktopModules/AG.Article/App/SendMail-Print/SendMail.aspx\',\'\',\'' + articleLink + '\')" >';
        contentMail += '<img border="0" src="/DeskTopModules/AG.Article/App/Images/S_News_Email.gif" alt="" />&#160; </a>';
        contentMail += '<a style="cursor:pointer;font:12px arial"  onclick="openFixedPopup(\'/DesktopModules/AG.Article/App/SendMail-Print/SendMail.aspx\',\'' + articleLink + '\')" style="font-family: Arial; font-size: 13px; color: rgb(0, 0, 0);" >Email </a>';
        contentMail += '</span>';
        $('#MailSpan' + ModuleID).html(contentMail);
    }
};
