// Jquery cookie disclaimer created by Sach @ Emperor Jan 2012

$(document).ready(function () {

    if (window.location.href.indexOf("regulatory-news") != -1) {

        if ($.cookie('Disclaimeryes') == null) {
            $("iframe").hide();
            // window.location.replace("disclaimer.aspx");
        };
    };

    if (window.location.href.indexOf("announcements") != -1) {

        if ($.cookie('Disclaimeryes') == null) {
            $(".news_archive").hide();
            // window.location.replace("disclaimer.aspx");
        };
    };

    // Gets value from end of query string and put it in an array
    function getUrlVars() {
        var vars = [], hash;
        var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');
        for (var i = 0; i < hashes.length; i++) {
            hash = hashes[i].split('=');
            vars.push(hash[0]);
            vars[hash[0]] = hash[1];
        }
        return vars;
    }

    // For homepage news links
    $("a.disclaimerlink").on("click", function (e) {
        e.preventDefault();
        window.location = this.href + '?url=announcements.aspx';
    });

    // Custom links 
    if ($.cookie('Disclaimeryes') == null) {
        $("a[href='announcements.aspx']").on("click", function (e) {
            e.preventDefault();
            window.location = this.href + '?url=announcements.aspx';
        });
    };

    if ($.cookie('Disclaimeryes') == null) {
        $("a[href='regulatory-news.aspx']").on("click", function (e) {
            e.preventDefault();
            window.location = this.href + '?url=regulatory-news.aspx';
        });
    };

    if ($.cookie('Disclaimeryes') == null) {
        $("a[href='regulatory-news.aspx']").attr("href", "disclaimer.aspx");
    };

    if ($.cookie('Disclaimeryes') == null) {
        $("a[href='announcements.aspx']").attr("href", "disclaimer.aspx");
    };

    // Change href link of disclaimer accept to value from query string
    var first = getUrlVars()["url"];
    $("a#accept").attr("href", first);

    //    if (document.referrer.indexOf("announcements.aspx") >= 0) {
    //        $("a#accept").attr("href", "announcements.aspx");
    //    }

    //    if (document.referrer.indexOf("regulatory-news.aspx") >= 0) {
    //        $("a#accept").attr("href", "regulatory-news.aspx");
    //    };


    if ($.cookie('Disclaimeryes') == null) {
        $("a.disclaimerlink").attr("href", "disclaimer.aspx");
    };

    $("a#accept").click(function () {
        $.cookie('Disclaimeryes', 'Yes', { expires: null, path: '/' });
        //window.location.replace("regulatory-news.aspx");
    });

    $("a#decline").click(function () {
        $cookie('Disclaimeryes', null);
        //window.location.replace("decline.aspx");
    });

});





