﻿var SPECIAL_DAYS = {};
if (typeof (AGFS) == 'undefined')
    AGFS = {};
if (typeof (AGFS.Article) == 'undefined')
    AGFS.Article = {};
AGFS.Article.ALProcessData = {
    //dung khoi tao truoc khi search
    InnitData: function (Url, ModuleID) {
        var executeContentJS = "<script> var loading = \"<div style='clear:both;'/><div class='AL_Loading_Div' ><img  src='" + ImageInfo.Loading + "'  style='height:30px;'/></div>\";";
        executeContentJS += "$('#ArticleList" + ModuleID + "').html(loading);";
        executeContentJS += "var ObjectModuleName = '#ObjectModuleID " + ModuleID + "';";
        executeContentJS += " var CollectionParam = $(ObjectModuleName).text();";
        executeContentJS += "var ArticleList = '#ArticleList" + ModuleID + "';";
        executeContentJS += "var ArticleIndex = '#ArticleIndex" + ModuleID + "';";
        executeContentJS += "var TabLink = ModuleUtils.GetTabLink(CollectionParam);";
        executeContentJS += "var NumberRecordFirstPage = ModuleUtils.GetNumberOfRecordFirstPage(CollectionParam);";
        executeContentJS += " var NumberOfRecordPerPage = ModuleUtils.GetNumberOfRecordPerPage(CollectionParam);";
        executeContentJS += "var DetailModule = ModuleUtils.GetDetailModule(CollectionParam);";
        executeContentJS += "var TypeLoad = ModuleUtils.GetDisplayType(CollectionParam);";
        executeContentJS += "var Floor = ModuleUtils.GetFloorID(CollectionParam);";
        executeContentJS += "var Category = ModuleUtils.GetCategory(CollectionParam);";
        executeContentJS += " var content = '';";
        executeContentJS += " var UrlPath = '';";
        executeContentJS += " if (FileUtils.IsXmlFile('" + Url + "' )) {";
        executeContentJS += " UrlPath ='" + Url + "?t=" + AGFS.DateUtils.GetDateTimeNow() + "';";
        executeContentJS += " }";
        executeContentJS += " else {";
        executeContentJS += "  UrlPath = '" + Url + "&?t=" + AGFS.DateUtils.GetDateTimeNow() + "';";
        executeContentJS += " }</script>";
        $('#InnitArticleList').html(executeContentJS);
    },
    //dung de fill du lieu theo moduleId
    FillDataToID: function (ModuleID, NumberOfItem, content) {
        var executeContentJS = "<script>";
        executeContentJS += " $('#ArticleList').html('');";
        executeContentJS += "$('#ArticleList').html(" + content + ");";
        //executeContentJS += " var NumberOfItem = eval(parseInt($(result).find('TotalCount').text()));";
        executeContentJS += "var func = \"AGBB.Paging.SetCurrentPage('" + ModuleID + "',\";";
        executeContentJS += "$(ArticleIndex).html('');";
        executeContentJS += " $(ArticleIndex).html(PagingUtils.DrawPaging(CurrentPage, NumberOfRecordPerPage," + NumberOfItem + ", func));</script>";
        $('#FillDataToID').html(executeContentJS);
    },
    //Dung de su ly loi
    ProcessError: function (Id) {
        var executeContentJS = "<script>";
        executeContentJS += 'var temp = "<div class=\'AL_UD\'>" + ArticleListInfo.UpdateData + "...</div>";';
        executeContentJS += "$(ArticleIndex).html('');";
        executeContentJS += "$(ArticleList).html(temp);}</script>";
        $('#ProcessError').html(executeContentJS);
    }
}
AGFS.Article.URL = {
    GetUrlFullText: function (Page) {
        url = document.location.href;
        var indexkey = url.indexOf("keyword");
        var key = url.substring(indexkey + 8, url.length - 8);
        return '/Handler/AG.News/AL_SearchFullText.ashx?page=' + Page + "&Key=" + key;
    },
    //Lay tin theo nguon
    GetUrlSearchBySourceEndDate: function (pageNumber, moduleId) {
        var ObjectModuleName = '#ObjectModuleID' + moduleId;
        var CollectionParam = $(ObjectModuleName).text();
        var Symbol = $("#selectSource" + moduleId).val();
        //Lấy ngày bắt đầu
        var startDate = $("#Article_BeginDate" + moduleId).val();
        if (startDate == "")
            startDate = "2000-01-01 00:00:00";
        else {
            //Kiểm tra định dạng ngày theo ngôn ngữ
            if (agLanguageName == "vi-VN")
                startDate = AGFS.DateUtils.ConvertStringDayMonthYearToYearMonthDayHourMinusSecond(startDate);
            else if (agLanguageName == "en-US")
                startDate = AGFS.DateUtils.ConvertStringMonthDayYearToYearMonthDayHourMinusSecond(startDate);
        }
        //Lấy ngày kết thúc
        var endDate = $("#Article_EndDate" + moduleId).val();
        if (endDate == "")
            endDate = "2100-01-01 00:00:00";
        else {
            //Kiểm tra định dạng ngày theo ngôn ngữ
            if (agLanguageName == "vi-VN")
                endDate = AGFS.DateUtils.ConvertStringDayMonthYearToYearMonthDayHourMinusSecond(endDate);
            else if (agLanguageName == "en-US")
                endDate = AGFS.DateUtils.ConvertStringMonthDayYearToYearMonthDayHourMinusSecond(endDate);
        }
        var strUrl = "/Handler/AG.News/AGArticle_ListGetBySymCalAndDate.ashx?Symbol=" + Symbol + "&Category=" + ModuleUtils.GetCategory(CollectionParam) + "&BeginDate=" + startDate + "&EndDate=" + endDate + "&NumberOfRecord=" + ModuleUtils.GetNumberOfRecordPerPage(CollectionParam) + "&Page=" + pageNumber;
        return strUrl;
    },
    //Sự kiện khi click vào năm để lấy tin tức theo năm
    GetUrlSearchByYearAndCategory: function (pageNumber, moduleId) {
        var ObjectModuleName = '#ObjectModuleID' + moduleId;
        var CollectionParam = $(ObjectModuleName).text();
        var year = $("#selectYear" + moduleId).val();

        var strUrl = "/Handler/AG.News/AGArticle_GetListByYearAndCategory.ashx?SetOfCategoryID=" + ModuleUtils.GetCategory(CollectionParam) + "&Year=" + year + "&Order=" + ModuleUtils.GetOrder(CollectionParam) + "&OrderBy=" + ModuleUtils.GetOrderBy(CollectionParam) + "&NumberOfRecord=" + ModuleUtils.GetNumberOfRecordPerPage(CollectionParam) + "&Page=" + pageNumber;
        return strUrl;
    },
    GetUrlSearchByYearAndCategory1: function (pageNumber, moduleId) {
        var ObjectModuleName = '#ObjectModuleID' + moduleId;
        var CollectionParam = $(ObjectModuleName).text();
        var currentDate = new Date();
        var year = currentDate.getFullYear();
        var strUrl = "/Handler/AG.News/AGArticle_GetListByYearAndCategory.ashx?SetOfCategoryID=" + ModuleUtils.GetCategory(CollectionParam) + "&Year=" + year + "&Order=" + ModuleUtils.GetOrder(CollectionParam) + "&OrderBy=" + ModuleUtils.GetOrderBy(CollectionParam) + "&NumberOfRecord=" + ModuleUtils.GetNumberOfRecordPerPage(CollectionParam) + "&Page=" + pageNumber;
        return strUrl;
    },
    //Lay Url tu ngay den ngay
    GetUrlByBeginDateEndDate: function (pageNumber, ModuleID) {

        var ObjectModuleName = '#ObjectModuleID' + ModuleID;
        var CollectionParam = $(ObjectModuleName).text();
        //Lấy ngày bắt đầu
        var startDate = $("#Article_BeginDate" + ModuleID).val();
        if (startDate == "")
            startDate = "2000-01-01 00:00:00";
        else {
            //Kiểm tra định dạng ngày theo ngôn ngữ
            if (agLanguageName == "vi-VN")
                startDate = AGFS.DateUtils.ConvertStringDayMonthYearToYearMonthDayHourMinusSecond(startDate);
            else if (agLanguageName == "en-US")
                startDate = AGFS.DateUtils.ConvertStringMonthDayYearToYearMonthDayHourMinusSecond(startDate);
        }

        //Lấy ngày kết thúc
        var endDate = $("#Article_EndDate" + ModuleID).val();
        if (endDate == "")
            endDate = "2100-01-01 00:00:00";
        else {
            //Kiểm tra định dạng ngày theo ngôn ngữ
            if (agLanguageName == "vi-VN")
                endDate = AGFS.DateUtils.ConvertStringDayMonthYearToYearMonthDayHourMinusSecond(endDate);
            else if (agLanguageName == "en-US")
                endDate = AGFS.DateUtils.ConvertStringMonthDayYearToYearMonthDayHourMinusSecond(endDate);
        }

        var strURL = '/Handler/AG.News/ALD.ashx?page=' + pageNumber + '&CategoryID=' + ModuleUtils.GetCategory(CollectionParam) + '&NumberOfItemPerPage=' + ModuleUtils.GetNumberOfRecordPerPage(CollectionParam) + '&BeginDate=' + startDate + '&Enddate=' + endDate;
        return strURL;

    },


    //Lay url tim kiem lichj su kien co khoa
    GetUrlSearchMarketCalendar: function (pageNumber, ModuleID) {
        var obj_Symbol = document.getElementById('AL_Symbol_Dll' + ModuleID);
        var obj_KeyWord = document.getElementById('SearchArticle_KeyWord' + ModuleID);
        var obj_EventType = document.getElementById('Search_EventType_DDL' + ModuleID);
        var obj_PageSize = document.getElementById('SearchArticle_PageSize' + ModuleID);
        var Symbol = obj_Symbol.value;
        AGFS.Article.InnitSearch.GetBeginEndDateByModuleID(ModuleID);
        var dKey = obj_KeyWord.value;
        if (dKey == '') {
            dKey = '-1';
        }
        else {
            dKey = encodeURI(dKey);
        }
        var dNumberOfRecord = obj_PageSize.value;
        if (dNumberOfRecord == '') {
            dNumberOfRecord = NumberOfItemPerPage;
        }
        var dMaCK = obj_Symbol.value;
        if (dMaCK == '') {
            dMaCK = '-1';
        }
        var EventType = encodeURI(obj_EventType.value);
        var strURL = '/Handler/AG.News/MarketCalendar_Search.ashx?page=' + pageNumber + '&Type=' + EventType + '&Symbol=' + dMaCK + '&BeginDate=' + dBegin + '&Enddate=' + dEnd + '&Key=' + dKey + '&NumberOfRecord=' + dNumberOfRecord + '&Category=' + SetOfCategoryID;
        return strURL;
    },
    //Lay url cua tim kiem lich su kien
    GetUrlMarketCalendar: function (pageNumber, ModuleID) {
        AGFS.Article.InnitSearch.GetBeginEndDateByModuleID(ModuleID);
        var obj_Symbol = document.getElementById('AL_Symbol_Dll' + ModuleID);
        var obj_EventType = document.getElementById('Search_EventType_DDL' + ModuleID);
        var Symbol = obj_Symbol.value;
        var dMaCK = obj_Symbol.value;
        if (dMaCK == '') {
            dMaCK = '-1';
        }
        var Language = "";
        if (agLanguageName == "vi-VN") {
            Language = "0";
        }
        else if (agLanguageName == "en-US") {
            Language = "2";
        }
        var EventType = encodeURI(obj_EventType.value);

        // Format "Từ ngày" "Đến ngày" về 1 kiểu dd/mm/yyyy dùng cho handler
        if (agLanguageName == "en-US") {
            if (dBegin != "") {
                var temp = dBegin.split('/');
                dBegin = temp[1] + "/" + temp[0] + "/" + temp[2];
            }
            if (dEnd != "") {
                var temp = dEnd.split('/');
                dEnd = temp[1] + "/" + temp[0] + "/" + temp[2];
            }
        }

        var strURL = '/Handler/AG.News/MarketCalendar_SearchType.ashx?page=' + pageNumber + '&Type=' + EventType + '&Symbol=' + dMaCK + '&BeginDate=' + dBegin + '&Enddate=' + dEnd + '&NumberOfRecord=' + NumberOfItemPerPage + '&language=' + Language;
        return strURL;
    },
    //Lay url theo chuyen muc
    GetUrlSearchByCategory: function (pageNumber, ModuleID) {
        var obj_Symbol = document.getElementById('AL_Symbol_Dll' + ModuleID);
        var obj_Source = document.getElementById('AL_Source_Dll' + ModuleID);
        var obj_Category = document.getElementById('SearchArticle_Categoryddl' + ModuleID);
        AGFS.Article.InnitSearch.GetBeginEndDateByModuleID(ModuleID);
        if (obj_Category.value != '-1') {
            SetOfCategoryID = obj_Category.value;
        }
        var Symbol = obj_Symbol.value;
        var dMaCK = obj_Symbol.value;
        if (dMaCK == '') {
            dMaCK = '-1';
        }
        var strURL = '/Handler/AG.News/ALS_Category.ashx?page=' + pageNumber + '&Symbol=' + dMaCK + '&BeginDate=' + dBegin + '&Enddate=' + dEnd + '&NumberOfRecord=' + NumberOfItemPerPage + '&Category=' + SetOfCategoryID + '&Source=' + obj_Source.value;
        return strURL;
    }
}
//Ham search
AGFS.Article.Search = {
    SearchBySourceEndDate: function (pageNumber, moduleId) {
        var strUrl = AGFS.Article.URL.GetUrlSearchBySourceEndDate(pageNumber, moduleId);
        AGFSLib.App.FillData(strUrl, pageNumber, moduleId);
    },
    SearchBySource: function (pageNumber, moduleId) {
        var strUrl = AGFS.Article.URL.GetUrlSearchBySourceEndDate(pageNumber, moduleId);
        AGFSLib.App.FillData(strUrl, pageNumber, moduleId);
    },
    SearchByBeginDateEndDate: function (pageNumber, ModuleID) {
        var URl = AGFS.Article.URL.GetUrlByBeginDateEndDate(pageNumber, ModuleID);
        AGFSLib.App.FillData(URl, pageNumber, ModuleID);
    },
    SearchNoParam: function (pageNumber, ModuleID) {
        var ObjectModuleName = '#ObjectModuleID' + ModuleID;
        var CollectionParam = $(ObjectModuleName).text();
        var FuncList = ModuleUtils.GetFuncList(CollectionParam);
        var URl = "/Handler/AG.News/AL_GetByCategory.ashx?SetOfCategoryID=" + ModuleUtils.GetCategory(CollectionParam) + "&NumberOfRecord=" + ModuleUtils.GetNumberOfRecordPerPage(CollectionParam) + "&Order=" + ModuleUtils.GetOrder(CollectionParam) + "&OrderBy=" + ModuleUtils.GetOrderBy(CollectionParam) + "&Page=" + pageNumber + "&Floor=" + ModuleUtils.GetFloorID(CollectionParam);
        AGFSLib.App.FillData(URl, pageNumber, ModuleID);
    },
    //truong hop dac biet
    SearchAD: function (ModuleID, pageNumber) {
        var ObjectModuleName = '#ObjectModuleID' + ModuleID;
        var CollectionParam = $(ObjectModuleName).text();
        var FuncList = ModuleUtils.GetFuncList(CollectionParam);
        var URl = "/Handler/AG.News/AL_GetByCategory.ashx?SetOfCategoryID=" + ModuleUtils.GetCategory(CollectionParam) + "&NumberOfRecord=" + ModuleUtils.GetNumberOfRecordPerPage(CollectionParam) + "&Order=" + ModuleUtils.GetOrder(CollectionParam) + "&OrderBy=" + ModuleUtils.GetOrderBy(CollectionParam) + "&Page=" + pageNumber + "&Floor=" + ModuleUtils.GetFloorID(CollectionParam);
        AGFS.Article.ArticleList.LoadListNextArticle(URl, pageNumber, ModuleID);
    },
    FillYearToSelect: function (id, moduleId) {
        var ObjectModuleName = '#ObjectModuleID' + moduleId;
        var CollectionParam = $(ObjectModuleName).text();
        var strContent = "";
        $.ajax({
            type: "GET",
            url: "/Handler/AG.News/ALS_GetYearByCategories.ashx?CategoryId=" + ModuleUtils.GetCategory(CollectionParam),
            dataType: "xml",
            async: false,
            success: function (data) {
                $(data).find("Year").each(function () {
                    strContent += "<option value='" + $(this).text() + "' >" + $(this).text() + "</option>";
                });
            }
        });
        $("#" + id + moduleId).html(strContent);
    },
    SearchListArticleByYearAndCategory: function (pageNumber, moduleId) {

        var strUrl = AGFS.Article.URL.GetUrlSearchByYearAndCategory(pageNumber, moduleId);
        AGFSLib.App.FillData(strUrl, pageNumber, moduleId);
    },
    SearchListArticleByYearAndCategory1: function (pageNumber, moduleId) {

        var strUrl = AGFS.Article.URL.GetUrlSearchByYearAndCategory1(pageNumber, moduleId);
        AGFSLib.App.FillData(strUrl, pageNumber, moduleId);
    },
    FillDateToCombo: function (date, ModuleID) {
        var currentTime = new Date(date);
        var month = currentTime.getMonth() + 1;
        var day = currentTime.getDate();
        var year = currentTime.getFullYear();
        var i = 1;
        var j = 1;
        var k = 2006;
        var contentDay = '';
        var contentMonth = '';
        var contentYear = '';
        contentDay = '<option value="' + day + '" selected="selected" >' + day + '</option>';
        for (i = 1; i <= 31; i++) {
            contentDay += '<option value="';
            contentDay += i;
            contentDay += '">';
            contentDay += i;
            contentDay += '</option>';
        }
        $("#ddlDay" + ModuleID).html(contentDay);
        contentMonth += '<option value="' + month + '" selected="selected" >' + month + '</option>';
        for (j = 1; j <= 12; j++) {
            contentMonth += '<option value="';
            contentMonth += j;
            contentMonth += '">';
            contentMonth += j;
            contentMonth += '</option>';
        }
        $("#ddlMonth" + ModuleID).html(contentMonth);
        contentYear += '<option value="' + year + '" selected="selected" >' + year + '</option>';
        for (k = 2005; k <= year; k++) {
            contentYear += '<option value="';
            contentYear += k;
            contentYear += '">';
            contentYear += k;
            contentYear += '</option>';
        }
        $("#ddlYear" + ModuleID).html(contentYear);
    },

    SearchMarketCalendar: function (Page, ModuleID) {
        $(document).ready(function () {
            var URl = AGBB.URL.GetUrlSearchMarketCalendar(Page, ModuleID);
            AGFSLib.App.FillData(URl, Page, ModuleID);
        });
    },
    SearchByCategory: function (Page, ModuleID) {
        var URl = AGFS.Article.Search.GetUrlSearchByCategory(Page, ModuleID);
        AGFSLib.App.FillData(URl, Page, ModuleID);
    },
    SearchMarketCalendarByDate: function (date, Page, ModuleID) {
        var URl = '/Handler/AG.News/MarketCalendar_SearchByDate_Hander.ashx?page=' + Page + "&Date=" + date;
        AGFSLib.App.FillData(URl, Page, ModuleID);
    },
    SearchMarketCalendarByDateTypeSymbol: function (Page, ModuleID) {
        AGFS.Article.Search.SearchMarketCalendarByDate_CurrentFilter = $("#AL_Symbol_Dll" + ModuleID).val() + "|" + $("#Search_EventType_DDL" + ModuleID).val() + "|" + $("#Article_BeginDate" + ModuleID).val() + "|" + $("#Article_EndDate" + ModuleID).val();
        var URl = AGFS.Article.URL.GetUrlMarketCalendar(Page, ModuleID);
        ModuleUtils.SetFuncSearch('SearchMarketCalendarByDateTypeSymbol', ModuleID);
        ModuleUtils.SetXML(URl, ModuleID);
        AGFSLib.App.FillData(URl, Page, ModuleID);
    }
},
AGFS.Article.InnitSearch = {
    SearchBySource: function (moduleId) {
        var content = "";
        var currentDate = new Date();
        content += "<div class='Search_Source'>";
        content += "<div class='Select_Source'>";
        content += "<select style='float:left' id='selectSource" + moduleId + "' onchange=''>";
        content += "<option  value=''>" + SearchInfo.ChoiseSource + "</option>";
        content += "<option  value='HSX'>HSX</option>";
        content += "<option value='HNX' >HNX</option>";
        content += "<option value='UPCOM'>UPCOM</option>";
        content += "<option value='OTC'>OTC</option>";
        content += "</select>";
        content += "</div>";
        //TU ngay den ngay
        content += '<div class="Search_Date">';
        content += '<div class="Search_Date_Title">' + SearchInfo.FromDate + '</div> <div class="Search_Date_BeginDate_Text">';
        content += ' <input type="text" class="Search_Date_Input" id="Article_BeginDate' + moduleId + '"/> </div>';
        content += '<div class="Search_Date_Title"> &nbsp;&nbsp;&nbsp;&nbsp;' + SearchInfo.ToDate + '</div><div class="Search_Date_BeginDate_Text">  <input type="text" id="Article_EndDate' + moduleId + '" class="Search_Date_Input" /></div>';
        content += '<div class="Search_Date_Button"> <a id="imgSearchByDate' + moduleId + '" onclick="javascript: AGFS.Article.Search.SearchBySourceEndDate(\'1\',\'' + moduleId + '\');"><img src="' + ImageInfo.Search + '"/> </a> </div>';
        content += "<div class='S_Clear'></div></div>";
        $('#ArticleSearch' + moduleId).html('');
        $('#ArticleSearch' + moduleId).html(content);
        AGFS.DateUtils.GetDatePicker('#Article_BeginDate' + moduleId);
        AGFS.DateUtils.GetDatePicker('#Article_EndDate' + moduleId);


    },
    SearchListArticleByYearAndCategory: function (moduleId) {
        var content = "";
        var currentDate = new Date();
        content += "<div class='Search_Year'>";
        content += "<select style='float:left;' id='selectYear" + moduleId + "' onchange='AGFS.Article.Search.SearchListArticleByYearAndCategory(\"1\",\"" + moduleId + "\")'>";
        content += "</select>";
        content += "<div id='Menu_Year' style='float:right'>";
        content += "<div class='YearActive' id='CurrentYear' onclick='AGFS.Article.Search.SearchListArticleByYearAndCategory1(\"1\",\"" + moduleId + "\")'>" + currentDate.getFullYear() + "</div>";
        content += "<div class='YearNormal' id='Archives'>" + ArticleListInfo.Archives + "</div>";
        content += "</div>";
        content += "<div class='Clear'>";
        content += "</div>";
        content += "</div>";
        $('#ArticleSearch' + moduleId).html('');
        $('#ArticleSearch' + moduleId).html(content);
        AGFS.Article.Search.FillYearToSelect("selectYear", moduleId);
        $(document).ready(function () {
            $('#selectYear' + moduleId).css('display', 'none')
            $('#Archives').click(function () {
                $(this).removeClass('YearNormal');
                $(this).addClass('YearActive');
                $('#CurrentYear').removeClass('YearActive');
                $('#CurrentYear').addClass('YearNormal');
                $('#selectYear584').css('display', 'block');

            });
            $('#CurrentYear').click(function () {
                $(this).removeClass('YearNormal');
                $(this).addClass('YearActive');
                $('#Archives').removeClass('YearActive');
                $('#Archives').addClass('YearNormal');
                $('#selectYear584').css('display', 'none')

            });
        });
    },
    GetBeginEndDateByModuleID: function (ModuleID) {
        var Content = "<script> var ObjectModuleName = '#ObjectModuleID" + ModuleID + "'; var CollectionParam = $(ObjectModuleName).text();  var NumberOfItemPerPage = ModuleUtils.GetNumberOfRecordPerPage(CollectionParam);    var SetOfCategoryID = ModuleUtils.GetCategory(CollectionParam);";
        Content += " var obj_BeginDate = document.getElementById('Article_BeginDate" + ModuleID + "');";
        Content += " var obj_EndDate = document.getElementById('Article_EndDate" + ModuleID + "');";
        Content += "var dBegin = obj_BeginDate.value;";
        Content += " var dEnd = obj_EndDate.value;";
        Content += "if (dBegin == '') {  dBegin = '1/1/1900'; }";
        Content += " else {";
        Content += "if (DateInfo.Lang == 'EN') {";
        Content += "dBegin = AGFS.DateUtils.convertDateToString(obj_BeginDate.value,'MM/dd/yyyy');}}";
        Content += "  if (dEnd == '') {"
        Content += "   dEnd = '1/1/2100';";
        Content += "  }";
        Content += "   else {";
        Content += "  if (DateInfo.Lang == 'EN') {";
        Content += "  dEnd = AGFS.DateUtils.convertDateToString(obj_BeginDate.value,'MM/dd/yyyy');";
        Content += "}}</script>";
        // alert(Content);
        $('#BeginEndDateJS').html(Content);
    },
    SearchByBeginDateEndDate: function (ModuleID) {
        var SearchContent = '';
        SearchContent += '<div class="M_ASBDED_Search_Contain">';
        SearchContent += '<div class="M_AL_Search_Title_2">' + SearchInfo.FromDate + '</div> <div class="M_ASBDED_Search_BeginDate_Text">';
        SearchContent += ' <input type="text" class="M_ASBDED_Search_Input" id="Article_BeginDate' + ModuleID + '"/> </div>';
        SearchContent += '<div class="M_AL_Search_Title_2"> &nbsp;&nbsp;&nbsp;&nbsp;' + SearchInfo.ToDate + '</div><div class="M_ASBDED_Search_BeginDate_Text">  <input type="text" id="Article_EndDate' + ModuleID + '" class="M_ASBDED_Search_Input" /></div>';
        SearchContent += '<div class="M_AL_Search_Button"> <a id="imgSearchByDate' + ModuleID + '" onclick="javascript: AGFS.Article.Search.SearchByBeginDateEndDate(\'1\',\'' + ModuleID + '\');"><img src="' + ImageInfo.Search + '"/> </a> </div>';
        SearchContent += '<div class="S_Clear"/></div><div class="S_Clear"/>';
        $('#ArticleSearch' + ModuleID).html('');
        $('#ArticleSearch' + ModuleID).html(SearchContent);
        AGFS.DateUtils.GetDatePicker('#Article_BeginDate' + ModuleID);
        AGFS.DateUtils.GetDatePicker('#Article_EndDate' + ModuleID);
    },

    LoadCategory: function (url, ModuleId) {
        var strContent = "";
        var url = "/Handler/AG.News/MarketCalendar_InitDate.ashx?Year=" + Year;
        var result = '';
        $.ajax({
            type: "GET",
            url: url,
            dataType: "xml",
            async: false,
            success: function (data) {
                strContent += $(data).find("Year").text();
            }
        });
    },
    SearchMarketCalendar: function (ModuleID) {
        $(document).ready(function () {
            var SearchContent = '<div  class="M_AL_Search_Contain">';
            SearchContent += '<div class="M_AL_Search_Contain">';
            SearchContent += '<div class="ASA_Symbol_Line">';
            SearchContent += '<div class="ASA_Title">' + SearchInfo.Symbol + '</div>';
            SearchContent += '<div class="ASA_BeginDate_Text">';
            SearchContent += '<select id="AL_Symbol_Dll' + ModuleID + '" class="M_MKS_DLL">';
            SearchContent += '</select></div></div>';
            SearchContent += '<div class="ASA_Title">' + SearchInfo.FromDate + '</div> <div class="M_AL_Search_BeginDate_Text">';
            SearchContent += ' <input type="text" class="M_AL_Search_Input" id="Article_BeginDate' + ModuleID + '"/> </div>';
            SearchContent += '<div class="M_AL_Search_Title">' + SearchInfo.ToDate + '</div><div class="M_AL_Search_BeginDate_Text" style="padding-left:10px;"><input type="text" id="Article_EndDate' + ModuleID + '" class="M_AL_Search_Input_EndDate" />';
            SearchContent += '</div>';
            SearchContent += '</div></div><div style="padding-bottom:20px; clear:both;" class="clear"/>';
            SearchContent += '<div class="ASA_Symbol_Line">';
            SearchContent += '<div class="ASA_Title">' + MarketCalendarInfo.EventType + '</div><div class="ASA_BeginDate_Text">';
            SearchContent += '<select id="Search_EventType_DDL' + ModuleID + '" class="M_MKS_DLL">';
            SearchContent += '<option value="-1" selected="selected">' + SearchInfo.All + '</option>';
            SearchContent += '<option value="Cash Dividends /Interest pay"> Cash Dividends </option><option value="Dividend in kind">Dividend in kind </option>';
            SearchContent += '<option value="Poll"> Poll</option>';
            SearchContent += '<option value="Sell incentives">Sell incentives</option><option value="Shareholder meeting"> Shareholder meeting </option><option value="Stock Dividends">Stock Dividends</option>';
            SearchContent += ' </select>';
            SearchContent += '</div>'
            SearchContent += '</div>'
            SearchContent += '<div class="ASA_Keywords_Line">';
            SearchContent += '<div class="ASA_Title">' + SearchInfo.KeyWord + '</div>';
            SearchContent += '<div style="float:left">';
            SearchContent += '<input type="text" id="SearchArticle_KeyWord' + ModuleID + '" style="height: 22px; width: 164px;" />';
            SearchContent += '</div></div>';
            SearchContent += '<div class="ASA_Keywords_Line">';
            SearchContent += '<div class="ASA_Title" style="Padding-left:5px;">' + SearchInfo.PageSize + '</div>';
            SearchContent += '<div class="ASA_KeyWord_Text_News">';
            SearchContent += '<input type="text" id="SearchArticle_PageSize' + ModuleID + '" style="height: 22px; width: 170px;min-width:180px;" />';
            SearchContent += '</div></div><div style="clear: both;"/>';
            SearchContent += '<div class="M_AL_Search_ButtonNews"> <a id="imgSearchByDate' + ModuleID + '" onclick="javascript: AGFS.Article.Search.SearchMarketCalendar(\'1\',\'' + ModuleID + '\');"><img src="' + ImageInfo.Search + '"/> </a> </div>';
            $('#ArticleSearch' + ModuleID).html('');
            $('#ArticleSearch' + ModuleID).html(SearchContent);
            ComboUtils.FillToID('AL_Symbol_Dll' + ModuleID, SearchInfo.ChoiseSymbol, URL.GetAllSymbol);
            AGFS.DateUtils.GetDatePicker('#Article_BeginDate' + ModuleID);
            AGFS.DateUtils.GetDatePicker('#Article_EndDate' + ModuleID);
        });
    },
    GetDate: function (Year) {
        var url = "/Handler/AG.News/MarketCalendar_InitDate.ashx?Year=" + Year;
        var result = '';
        $.ajax({
            type: "GET",
            url: url,
            dataType: "xml",
            async: false,
            success: function (data) {
                result = $(data).find("Articles").text();
            }
        });
        return result;
    },
    CurrentDate: '',
    CurrentYear: ($.cookie('Year') == null) ? AGFS.DateUtils.GetYearNow() : $.cookie('Year'),
    //Tìm kiếm cho lịch sự kiện
    //Dùng trong trang Lịch sự kiện
    SearchMarketCalendarByDate: function (ModuleID) {
        $(document).ready(function () {
            var temp = '';
            var SearchContent = "";
            temp = AGFS.Article.InnitSearch.GetDate(AGFS.Article.InnitSearch.CurrentYear);
            SearchContent += '<div class="M_LSK_Sear">';
            SearchContent += '<table class="M_LSK_TableSearch">';
            SearchContent += '<tr class="M_LSK_TrSearch">';
            SearchContent += '<td class="M_LSK_TdSearch"><div class="M_LSK_LabelSearch">' + ArticleListLibInfo.StockSymbol + '</div></td>';
            SearchContent += '<td class="M_LSK_TdSearch"><div class="M_LSK_CategorySearch">';
            SearchContent += '<select id="AL_Symbol_Dll' + ModuleID + '" class="M_LSK_BoxSearch"/>';
            SearchContent += '</div></td>';
            SearchContent += '<td class="M_LSK_TdSearch"><div class="M_LSK_LabelSearch">' + ArticleListLibInfo.Type + '</div></td>';
            SearchContent += '<td colspan="2" class="M_LSK_TdSearch"><div class="LSK_SourceD">';
            SearchContent += '<select id="Search_EventType_DDL' + ModuleID + '" class="M_LSK_BoxSearch"/>';
            SearchContent += '</div></td>';
            SearchContent += '</tr>';
            SearchContent += '<tr class="M_LSK_TrSearch">';
            SearchContent += '<td class="M_LSK_TdSearch"><div class="M_LSK_LabelSearch"> ' + ArticleListLibInfo.DateStart + '</div></td>';
            SearchContent += '<td class="M_LSK_TdSearch"><div class="M_LSK_DateSearch">';
            SearchContent += '<input style="line-height:25px;" type="text" id="Article_BeginDate' + ModuleID + '" class="M_LSK_BoxSearch" />';
            SearchContent += '</div></td>';
            SearchContent += '<td class="M_LSK_TdSearch"><div class="M_LSK_LabelSearch"> ' + ArticleListLibInfo.DateEnd + '</div></td>';
            SearchContent += '<td class="M_LSK_TdSearch"><div class="M_LSK_DateSearch"">';
            SearchContent += '<input type="text" class="M_LSK_BoxSearch" id="Article_EndDate' + ModuleID + '"/> </div>';
            SearchContent += '</div></td>';
            SearchContent += '<td class="M_LSK_TdSearch"><div style="width: 90px;float:left;margin-left:20px;';
            SearchContent += '<a id="imgSearchByDate' + ModuleID + '" onclick="javascript: AGFS.Article.Search.SearchMarketCalendarByDateTypeSymbol(\'1\',\'' + ModuleID + '\');"><img style="cursor:pointer" src="' + ImageInfo.Search + '"/> </a>';
            SearchContent += '</div></td>';
            SearchContent += '</tr>';
            SearchContent += '</table>';
            SearchContent += '</div>';
            $('#ArticleSearch' + ModuleID).html('');
            $('#ArticleSearch' + ModuleID).html(SearchContent);
            AGFS.ComboUtils.FillToID('AL_Symbol_Dll' + ModuleID, SearchInfo.ChoiseSymbol, '/Handler/AG.News/GetAllSymbol.ashx');
            var SearchTypeDDL = 'Search_EventType_DDL' + ModuleID;
            AGFS.ComboUtils.FillToID(SearchTypeDDL, ArticleListLibInfo.ChooseTypeEvent, '/Handler/AG.News/MarketCalendar_GetType.ashx');
            ModuleUtils.SetFuncSearch('SearchMarketCalendarByDateTypeSymbol', ModuleID);
            AGFS.DateUtils.GetDatePicker('#Article_BeginDate' + ModuleID);
            AGFS.DateUtils.GetDatePicker('#Article_EndDate' + ModuleID);
            function dateIsSpecial(year, month, day) {
                if (year != AGFS.Article.InnitSearch.CurrentYear) {
                    AGFS.Article.InnitSearch.CurrentYear = year;
                    var temp = AGFS.Article.InnitSearch.GetDate(AGFS.Article.InnitSearch.CurrentYear);
                    $('#ExcecuteJS').html("<script> " + "var Innit=" + temp + ";</script>");
                    SPECIAL_DAYS = Innit;
                }
                var m = SPECIAL_DAYS[month];
                if (!m) return false;
                for (var i in m) if (m[i] == day) return true;
                return false;
            };

            var YearChange = "0";
            function dateChanged(calendar) {
                //Neu thay doi nam
                var Year = calendar.date.getFullYear();
                var Month = calendar.date.getMonth() + 1;     // integer, 0..11
                var Day = calendar.date.getDate();      // integer, 1..31
                var Dates = Month + "/" + Day + "/" + Year;
                // Beware that this function is called even if the end-user only
                // changed the month/year.  In order to determine if a date was
                // clicked you can use the dateClicked property of the calendar:
                if (calendar.dateClicked) {
                    // OK, a date was clicked, redirect to /yyyy/mm/dd/index.php
                    var y = calendar.date.getFullYear();
                    var m = calendar.date.getMonth() + 1;     // integer, 0..11
                    var d = calendar.date.getDate();      // integer, 1..31
                    // redirect...
                    // window.location = "/" + y + "/" + m + "/" + d + "/index.php";
                    var date = m + "/" + d + "/" + y;
                    AGFS.Article.InnitSearch.CurrentDate = date;
                    AGFS.Article.Search.SearchMarketCalendarByDate(date, 1, ModuleID);
                    ModuleUtils.SetFuncSearch('SearchMarketCalendarByDate', ModuleID);
                    $.cookie("Date", date);
                }
            };
            //            Calendar.setup({
            //                 flat: "cont",
            //                 displayArea: "calendar-container", // ID of the parent element
            //                 flatCallback: dateChanged,          // our callback function
            //                 date: AGFS.Article.InnitSearch.CurrentDate,
            //                 dateStatusFunc: function (date, y, m, d) {
            //                     if (dateIsSpecial(y, m, d)) return "special";
            //                     else return false; // other dates are enabled
            //                }
            //            });
        })
    },
    SearchByCategory: function (ModuleID) {
        var SearchContent = '<div  class="M_AL_Search_Contain">';
        SearchContent += '<div class="M_ASC_Line">';
        SearchContent += '<div class="M_ASC_Title1">' + SearchInfo.Symbol + '</div>';
        SearchContent += '<div class="M_ASC_Div1">';
        SearchContent += '<select id="AL_Symbol_Dll' + ModuleID + '" class="M_ASC_DLL1">';
        SearchContent += '</select></div>';
        SearchContent += '<div class="M_ASC_Title2">' + SearchInfo.FromDate + '</div> <div class="M_ASC_Div2">';
        SearchContent += '<input type="text" class="M_AL_Search_Input" id="Article_BeginDate' + ModuleID + '"/> </div>';
        SearchContent += '<div class="M_ASC_Title3"> &nbsp;&nbsp;&nbsp;&nbsp;' + SearchInfo.ToDate + '</div><div class="M_ASC_Div4">  <input type="text" id="Article_EndDate' + ModuleID + '" class="M_AL_Search_Input" />';
        SearchContent += '</div>';
        SearchContent += '</div><div style="padding-bottom:20px; clear:both" />';
        SearchContent += '<div class="M_ASC_Line"><div class="M_ASC_Title1">' + SearchInfo.Source + '</div>';
        SearchContent += '<div class="M_ASC_Div1">';
        SearchContent += '<select id="AL_Source_Dll' + ModuleID + '" class="M_ASC_DLL1">';
        SearchContent += '<option selected="selected" value="-1">' + SearchInfo.ChoiseSource + '</option>';
        SearchContent += '<option value="HNX"> HNX </option>';
        SearchContent += '<option value="HSX"> HSX </option>';
        SearchContent += '<option value="UBCKNN"> UBCKNN </option>';
        SearchContent += '</select></div>';
        SearchContent += ' <div class="M_ASC_Title2">';
        SearchContent += SearchInfo.News + '</div>';
        SearchContent += '<div class="M_ASC_Div23">';
        SearchContent += '<select id="SearchArticle_Categoryddl' + ModuleID + '" class="M_ASC_DLL2">';
        SearchContent += '</select></div>';
        SearchContent += '<div class="M_ASC_SearchBtn" > <a id="imgSearchByDate' + ModuleID + '" onclick="javascript: AGFS.Article.Search.SearchByCategory(\'1\',\'' + ModuleID + '\');"><img src="' + ImageInfo.Search + '"/> </a> </div>';
        SearchContent += '<div style="padding-bottom:20px"  class="clear"/>';
        $('#ArticleSearch' + ModuleID).html('');
        $('#ArticleSearch' + ModuleID).html(SearchContent);
        ComboUtils.FillToID('AL_Symbol_Dll' + ModuleID, SearchInfo.ChoiseSymbol, URL.GetAllSymbol);
        AGFS.Article.InnitSearch.LoadCategory(URL.CategoryNews, ModuleID);
        AGFS.DateUtils.GetDatePicker('#Article_BeginDate' + ModuleID);
        AGFS.DateUtils.GetDatePicker('#Article_EndDate' + ModuleID);

    }

}
//Ham phan trang la ham goi lai ham search theo so trang
AGFS.Article.Paging = {
    SetCurrentPage: function (ModuleID, Page) {
        var ObjectModuleName = '#ObjectModuleID' + ModuleID;
        var CollectionParam = $(ObjectModuleName).text();
        var FuncSearch = ModuleUtils.GetFuncSearch(CollectionParam);
        switch (FuncSearch) {
            case 'SearchByBeginDateEndDate': AGFS.Article.Search.SearchByBeginDateEndDate(Page, ModuleID); break;
            case 'SearchMarketCalendar': AGFS.Article.Search.SearchMarketCalendar(Page, ModuleID); break;
            case 'SearchMarketCalendarByDateTypeSymbol': AGFS.Article.Search.SearchMarketCalendarByDateTypeSymbol(Page, ModuleID); break;
            case 'SearchBySource': AGFS.Article.Search.SearchBySource(Page, ModuleID); break;
            case 'SearchMarketCalendarByDate': AGFS.Article.Search.SearchMarketCalendarByDate($.cookie('Date'), Page, ModuleID); break;
            case 'FuncSearchFinancialReport': AGFS.Article.Search.FuncSearchFinancialReport(Page, ModuleID); break;
            case 'SearchListArticleByYearAndCategory': AGFS.Article.Search.SearchListArticleByYearAndCategory(Page, ModuleID); break;
            default: AGFS.Article.Search.SearchNoParam(Page, ModuleID); break;
        }
    }
}


