﻿function openFixedPopup(url, articleLink) {
    var link = url + "?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);
}
AGFS.Article.ArticleDetail =
{
    Content: '',
    //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).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 m_path = "/Handler/AG.News/GetDetailArticles.ashx?ArticleID=" + ArticleID;
        var formatDate = "";
        if (agLanguageName == "vi-VN")
            formatDate = "dd/MM/yyyy ";
        else if (agLanguageName == "en-US")
            formatDate = "MM/dd/yyyy ";
        try {
            $.ajax({
                type: "GET",
                url: m_path,
                dataType: "xml",
                success: function (XML) {
                    if ($(XML).find('Title').text().length == 0) {
                        Content = "<div style=\"color:red;\">" + Warning.FileNotFound + "</div>";
                    }
                    else {
                        var date = $(XML).find("Date").text();
                        var strContent = $(XML).find('Content').text();
                        strContent = strContent.replace("Tahoma", "Arial");
                        //Title
                        Content += "<div style=\"clear:both;\"></div>";
                        Content += "<div class='M_AD_Title'>";
                        date = AGFS.DateUtils.convertDateToString(date, formatDate);
                        if ($(XML).find('Source').text() != undefined) {
                            var source = $(XML).find('Source').text() + '';
                        }
                        else {
                            var source = "";
                        }
                        if (agLanguageName = 'vi-VN') {
                            Content += "<div style='font-weight:normal;font-size:12px; color:#1A65AE; float:left; margin-right:5px'>&nbsp;" + '(' + date + ')' + "</div><div style=\"float:left\">" + $(XML).find('Title').text();
                        }
                        Content += "</div><div style=\"clear:both;\"></div></div>";
                        if ($(XML).find('Image').text().length == 0) {
                            //Lead
                            if ($(XML).find('Lead').text().length > 0) {
                                Content += '<div class="M_AD_Lead">';
                                Content += $(XML).find('Lead').text();
                                Content += '</div>';
                            }
                            Content += '<div class="M_AD_Content">';
                            Content += AGFS.EncoderUtils.htmlDecode(strContent);
                            Content += '</div>';
                            Content += "<div class='clear'></div>";
                        }
                        if ($(XML).find('Image').text().length != 0) {
                            Content += '<div style="margin:11 5 5 5;width:150px;float:left;"><img style="width:150px;"src=\"../../Portals/0/' + $(XML).find('Image').text() + '"/></div>';
                            if ($(XML).find('Lead').text().length > 0) {
                                Content += '<div class="M_AD_Lead">';
                                Content += $(XML).find('Lead').text();
                                Content += '</div>';
                            }
                            Content += '<div class="M_AD_Content">';
                            Content += AGFS.EncoderUtils.htmlDecode(strContent);
                            Content += '</div>';
                            Content += "<div class='clear'></div>";
                            Content += '<div style="clear:both"></div>';
                        }
                        //Content += '<div class="M_AD_LastUpdate" Id="LastUpdate' + ModuleID + '"></div>';
                        if (source == "") { }
                        else { Content += "<div class='M_AD_Source' style='float:right; margin-right:10px'>" + 'Theo : ' + source + "</div>"; }
                        Content += '<div style="float:right; margin-right:10px" class="M_AD_Count" Id="Count' + ModuleID + '"></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.LoadCountAndUpdate(ArticleID, ModuleID);
                        AGFS.Article.ArticleDetail.LoadBottomGoHomeSendMail(ModuleID, ArticleID);
                        AGFS.Article.Search.SearchAD(ModuleID, '1');
                    }
                },
                error: function displayError(request, errorType, errorThrown) {
                    try {
                        if (errorType == 'timeout') {
                        }
                        if (errorType == 'error') {
                        }
                    }
                    catch (err) {
                    }
                }
            });
        }
        catch (Error) {
        }
    },
    LoadDetailArticlesNoLead: 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 m_path = "/Handler/AG.News/GetDetailArticles.ashx?ArticleID=" + ArticleID;
        var formatDate = "";
        if (agLanguageName == "vi-VN")
            formatDate = "dd/MM/yyyy ";
        else if (agLanguageName == "en-US")
            formatDate = "MM/dd/yyyy ";
        try {
            $.ajax({
                type: "GET",
                url: m_path,
                dataType: "xml",
                success: function (XML) {
                    if ($(XML).find('Title').text().length == 0) {
                        Content = "<div style=\"color:red;\">" + Warning.FileNotFound + "</div>";
                    }
                    else {
                        var date = $(XML).find("Date").text();
                        var strContent = $(XML).find('Content').text();
                        strContent = strContent.replace("Tahoma", "Arial");
                        //Title
                        Content += "<div style=\"clear:both;\"></div>";
                        Content += "<div class='M_AD_Title'>";
                        date = AGFS.DateUtils.convertDateToString(date, formatDate);
                        if ($(XML).find('Source').text() != undefined) {
                            var source = $(XML).find('Source').text() + '';
                        }
                        else {
                            var source = "";
                        }
                        if (agLanguageName = 'vi-VN') {
                            Content += "<div style='font-weight:normal;font-size:12px; color:#1A65AE; float:left; margin-right:5px'>&nbsp;" + '(' + date + ')' + "</div><div style=\"float:left\">" + $(XML).find('Title').text();
                        }
                        Content += "</div><div style=\"clear:both;\"></div></div>";
                        if ($(XML).find('Image').text().length == 0) {
                            //Lead
                            //                            if ($(XML).find('Lead').text().length > 0) {
                            //                                Content += '<div class="M_AD_Lead">';
                            //                                Content += $(XML).find('Lead').text();
                            //                                Content += '</div>';
                            //                            }
                            Content += '<div class="M_AD_Content">';
                            Content += AGFS.EncoderUtils.htmlDecode(strContent);
                            Content += '</div>';
                            Content += "<div class='clear'></div>";
                        }
                        if ($(XML).find('Image').text().length != 0) {
                            Content += '<div style="margin:11 5 5 5;width:150px;float:left;"><img style="width:150px;"src=\"../../Portals/0/' + $(XML).find('Image').text() + '"/></div>';
                            //                            if ($(XML).find('Lead').text().length > 0) {
                            //                                Content += '<div class="M_AD_Lead">';
                            //                                Content += $(XML).find('Lead').text();
                            //                                Content += '</div>';
                            //                            }
                            Content += '<div class="M_AD_Content">';
                            Content += AGFS.EncoderUtils.htmlDecode(strContent);
                            Content += '</div>';
                            Content += "<div class='clear'></div>";
                            Content += '<div style="clear:both"></div>';
                        }
                        //Content += '<div class="M_AD_LastUpdate" Id="LastUpdate' + ModuleID + '"></div>';
                        if (source == "") { }
                        else { Content += "<div class='M_AD_Source' style='float:right; margin-right:10px'>" + 'Theo : ' + source + "</div>"; }
                        Content += '<div style="float:right; margin-right:10px" class="M_AD_Count" Id="Count' + ModuleID + '"></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.LoadCountAndUpdate(ArticleID, ModuleID);
                        AGFS.Article.ArticleDetail.LoadBottomGoHomeSendMail(ModuleID, ArticleID);
                        AGFS.Article.Search.SearchAD(ModuleID, '1');
                    }
                },
                error: function displayError(request, errorType, errorThrown) {
                    try {
                        if (errorType == 'timeout') {
                        }
                        if (errorType == 'error') {
                        }
                    }
                    catch (err) {
                    }
                }
            });
        }
        catch (Error) {
        }
    },
    LoadCountAndUpdate: function (ArtilceID, ModuleId) {
        var urlhander = '/Handler/AG.News/GetCountAndDate.ashx?ArticleID=' + ArtilceID;
        $.ajax({
            type: "GET",
            url: urlhander,
            dataType: "xml",
            success: function (result) {
                var NgayThangNam;
                if (agLanguageName == 'en-US') {
                    NgayThangNam = AGFS.DateUtils.ConvertStringToMonthDayYear($(result).find('DATE').text());
                }
                else if (agLanguageName == 'vi-VN') {
                    NgayThangNam = AGFS.DateUtils.ConvertStringToDayMonthYear($(result).find('DATE').text());
                }
                var displayDate = NgayThangNam;
                if ($(result).find('COUNT').text().length > 0) {
                    $("#Count" + ModuleId).html(ArticleDetailInfo.ReadNumber + $(result).find('COUNT').text() + "  ");
                }
                if ($(result).find('DATE').text().length > 0) {
                    $("#LastUpdate" + ModuleId).html(ArticleDetailInfo.LastUpdate + displayDate);
                }
            },
            error: function displayError(request, errorType, errorThrown) {
                try {
                    if (errorType == 'timeout') {
                    }
                    if (errorType == 'error') {
                    }
                }
                catch (err) {
                }
            }
        });
    },

    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; font: 12px arial;"></span>';
        ContentBottom += '<span id="MailSpan' + ModuleID + '" style="font:12px arial;" ></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;
    },

    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 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) {
        var temp = location.hash.replace('#', '');
        var ObjectModuleName = '#ObjectModuleID' + ModuleID;
        var CollectionParam = $(ObjectModuleName).text();
        var urlFilePath = ModuleUtils.GetXmlDetail(CollectionParam);

        var title = '';
        var m_path = "/Handler/AG.News/GetDetailArticles.ashx?ArticleID=" + ArticleID;
        $.ajax({
            type: "GET",
            url: m_path,
            dataType: "xml",
            async: false,
            success: function (XML) {
                title = $(XML).find('Title').text();
            },
            error: function displayError(request, errorType, errorThrown) {
                try {
                    if (errorType == 'timeout') {
                    }
                    if (errorType == 'error') {
                    }
                }
                catch (err) {
                }
            }
        });
        contentMail += ' <span> &#160;<a title="' + ArticleDetailInfo.SendMail + '" >';
        var articleLink = document.location.href;
        var contentMail = ' <span> &#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;"  onclick="openFixedPopup(\'/DesktopModules/AG.Article/App/SendMail-Print/SendMail.aspx\',\'' + document.location.href + '\')" style="font-family: Arial; font-size: 12px; color: rgb(0, 0, 0);" >Email </a>';
        contentMail += '</span>';
        $('#MailSpan' + ModuleID).html(contentMail);
    }
};
