﻿$(document).ready(function() {
    var se = "_select";

    NewAjax("div_header", "Com/header.aspx", "", "");

    Getcontent_login();

    GetdocClickTop();

    Getdashboard();

    GetFund_sort();

    Getnew_video();
    
    NewAjax("div_Showarticle", "index/GetArticle.aspx", function() { GetArticle(se); }, { Type: "3" });
});

function GetArticle(se) {
    $("li[t]").each(function() {
        $(this).click(function() {
            if ($(this).attr("class") != "tag" + $(this).attr("t") + se) {
                NewAjax("div_Showarticle", "index/GetArticle.aspx", function() {
                    GetArticle(se);
                }, { Type: $(this).attr("t") });
            }
        });
    });
}

function Getcontent_login() {
    NewAjax("div_content_login", "index/content_login.aspx", function() {
        $(".member_logout a").each(function() {
            $(this).click(function() {
                NewAjax("", "index/ClearSession.aspx", function() {
                    top.location = "index.aspx";
                }, "");
            });
        });
    }, "");
}

function GetdocClickTop() {
    NewAjax("div_click_top", "index/funds_topBuy.aspx", function() {
        NewAjax("div_tag01", "index/GetAboutFund.aspx", "", "");
        NewAjax("div_tag02", "index/GetPurchaseFund.aspx", "", "");

        $("div[Cont]").each(function() {
            $(this).click(function() {
                if ($(this).html().indexOf('STRONG') < 0 || $(this).html().indexOf('strong') < 0) {
                    unBindFundName();

                    var vCss = $(this).attr("class");
                    $("ul[id^='div_']").hide();
                    $("#div_" + vCss).show();

                    var C = $(this).attr("Cont");
                    $(this).html("<strong>" + C + "</strong>");
                }
            });
        });

        $("#div_tag02").hide();
    }, "");
}

function unBindFundName() {
    $("div[Cont]").each(function() {
        if ($(this).html().indexOf('STRONG') > 0 || $(this).html().indexOf('strong') > 0) {
            var C = $(this).attr("Cont");
            $(this).html("<a href='javascript:void(0);'>" + C + "</a>");
        }
    });
}

function Getdashboard() {
    var strShowManage = $("#hi_showManage").val();
    if (strShowManage.substr(2, 1) == "0" && strShowManage.substr(3, 1) != "0" && strShowManage.substr(7, 1) != "0") {
        //基金風雲榜
        NewAjax("div_dashboard", "index/billboard.aspx", "", "");
    }
    else if (strShowManage.substr(2, 1) != "0" && strShowManage.substr(3, 1) == "0" && strShowManage.substr(7, 1) != "0") {
        //基金投資氣氛儀板表
        NewAjax("div_dashboard", "index/Getdashboard.aspx", "", "");
    }
    else if (strShowManage.substr(2, 1) != "0" && strShowManage.substr(3, 1) != "0" && strShowManage.substr(7, 1) == "0") {
        //廣告
        NewAjax("div_dashboard", "index/GetAdv.aspx?adv=B", "", "");
    }
    else if (strShowManage.substr(2, 1) == "0" || strShowManage.substr(3, 1) == "0" || strShowManage.substr(7, 1) == "0") {
        if (strShowManage.substr(2, 1) == "0" && strShowManage.substr(3, 1) == "0" && strShowManage.substr(7, 1) == "0") {
            var num = GetRandomNum(1, 3);
            if (num == "1") {
                //基金風雲榜
                NewAjax("div_dashboard", "index/billboard.aspx", "", "");
            }
            else if (num == "2") {

                //基金投資氣氛儀板表
                NewAjax("div_dashboard", "index/Getdashboard.aspx", "", "");
            }
            else {
                //廣告
                NewAjax("div_dashboard", "index/GetAdv.aspx?adv=B", "", "");
            }
        }
        else if (strShowManage.substr(2, 1) == "0" && strShowManage.substr(3, 1) == "0" && strShowManage.substr(7, 1) != "0") {
            var num = GetRandomNum(1, 2);
            if (num == "1") {
                //基金風雲榜
                NewAjax("div_dashboard", "index/billboard.aspx", "", "");
            }
            else if (num == "2") {
                //基金投資氣氛儀板表
                NewAjax("div_dashboard", "index/Getdashboard.aspx", "", "");
            }
        }
        else if (strShowManage.substr(2, 1) == "0" && strShowManage.substr(3, 1) != "0" && strShowManage.substr(7, 1) == "0") {
            var num = GetRandomNum(1, 2);
            if (num == "1") {
                //基金風雲榜
                NewAjax("div_dashboard", "index/billboard.aspx", "", "");
            }
            else if (num == "2") {
                //廣告
                NewAjax("div_dashboard", "index/GetAdv.aspx?adv=B", "", "");
            }
        }
        else if (strShowManage.substr(2, 1) != "0" && strShowManage.substr(3, 1) == "0" && strShowManage.substr(7, 1) == "0") {
            var num = GetRandomNum(1, 2);
            if (num == "1") {
                //基金投資氣氛儀板表
                NewAjax("div_dashboard", "index/Getdashboard.aspx", "", "");
            }
            else if (num == "2") {
                //廣告
                NewAjax("div_dashboard", "index/GetAdv.aspx?adv=B", "", "");
            }
        }
    }
}

function Getnew_video() {
    var strShowManage = $("#hi_showManage").val();
    if (strShowManage.substr(0, 1) == "0" && strShowManage.substr(1, 1) != "0" && strShowManage.substr(6, 1) != "0") {
        //線上影音
        NewAjax("div_new_video", "index/new_video.aspx", "", "");
    }
    else if (strShowManage.substr(0, 1) != "0" && strShowManage.substr(1, 1) == "0" && strShowManage.substr(6, 1) != "0") {
        //台股觀點
        NewAjax("div_new_video", "index/point.aspx", "", "");
    }
    else if (strShowManage.substr(0, 1) != "0" && strShowManage.substr(1, 1) != "0" && strShowManage.substr(6, 1) == "0") {
        //廣告
        NewAjax("div_new_video", "index/GetAdv.aspx?adv=A", "", "");
    }
    else if (strShowManage.substr(0, 1) == "0" || strShowManage.substr(1, 1) == "0" || strShowManage.substr(6, 1) == "0") {
    if (strShowManage.substr(0, 1) == "0" && strShowManage.substr(1, 1) == "0" && strShowManage.substr(6, 1) == "0") {
            var num = GetRandomNum(1, 3);
            if (num == "1") {
                //線上影音
                NewAjax("div_new_video", "index/new_video.aspx", "", "");
            }
            else if (num == "2") {
                //台股觀點
                NewAjax("div_new_video", "index/point.aspx", "", "");
            }
            else {
                //廣告
                NewAjax("div_new_video", "index/GetAdv.aspx?adv=A", "", "");
            }
        } else if (strShowManage.substr(0, 1) == "0" && strShowManage.substr(1, 1) == "0" && strShowManage.substr(6, 1) != "0") {
            var num = GetRandomNum(1, 2);
            if (num == "1") {
                //線上影音
                NewAjax("div_new_video", "index/new_video.aspx", "", "");
            }
            else if (num == "2") {
                //台股觀點
                NewAjax("div_new_video", "index/point.aspx", "", "");
            }
        }
        else if (strShowManage.substr(0, 1) == "0" && strShowManage.substr(1, 1) != "0" && strShowManage.substr(6, 1) == "0") {
            var num = GetRandomNum(1, 2);
            if (num == "1") {
                //線上影音
                NewAjax("div_new_video", "index/new_video.aspx", "", "");
            }
            else if (num == "2") {
                //廣告
                NewAjax("div_new_video", "index/GetAdv.aspx?adv=A", "", "");
            }
        }
        else if (strShowManage.substr(0, 1) != "0" && strShowManage.substr(1, 1) == "0" && strShowManage.substr(6, 1) == "0") {
            var num = GetRandomNum(1, 2);
            if (num == "1") {
                //台股觀點
                NewAjax("div_new_video", "index/point.aspx", "", "");
            }
            else if (num == "2") {
                //廣告
                NewAjax("div_new_video", "index/GetAdv.aspx?adv=A", "", "");
            }
        }
    }
}

//基金排行榜
function GetFund_sort() {
    var strShowManage = $("#hi_showManage").val();
    if (strShowManage.substr(4, 1) == "0" && strShowManage.substr(5, 1) != "0") {
        //投票
        swfobject.embedSWF('flashs/swf/vote.swf', 'vote', '480', '221', '9.0.45', 'expressinstall.swf', { xml: "flashs/xml/Getvote.aspx", addVote: "flashs/xml/AddVote.aspx" }, {}, { id: 'vote' });
    }
    else if (strShowManage.substr(4, 1) != "0" && strShowManage.substr(5, 1) == "0") {
        //投資試算
        swfobject.embedSWF('flashs/swf/calculate-s.swf', 'vote', '480', '221', '9.0.45', 'expressinstall.swf', { xml: "flashs/xml/GetFund.aspx", xml2: "flashs/xml/Getnetworth.aspx", gourl: "TradeHelp/fundCount.aspx" }, {}, { id: 'vote' });
    }
    else if (strShowManage.substr(4, 1) == "0" && strShowManage.substr(5, 1) == "0") {
        var num = GetRandomNum(1, 2);
        if (num == "1") {
            //投票
            swfobject.embedSWF('flashs/swf/vote.swf', 'vote', '480', '221', '9.0.45', 'expressinstall.swf', { xml: "flashs/xml/Getvote.aspx", addVote: "flashs/xml/AddVote.aspx" }, {}, { id: 'vote' });
        }
        else {
            //投資試算
            swfobject.embedSWF('flashs/swf/calculate-s.swf', 'vote', '480', '221', '9.0.45', 'expressinstall.swf', { xml: "flashs/xml/GetFund.aspx", xml2: "flashs/xml/Getnetworth.aspx", gourl: "TradeHelp/fundCount.aspx" }, {}, { id: 'vote' });
        }
    }
}

function GetRandomNum(Min, Max) {
    var Range = Max - Min;
    var Rand = Math.random();
    return (Min + Math.round(Rand * Range));
}