$(document).ready(function () {

    // clicking a link to login, make the login form flash
    $('a#subscriber-login').click(function () {
        $('div#login').animate({ backgroundColor: '#CCC' }, 300, function () {
            $('div#login').animate({ backgroundColor: '#fff' }, 300).animate({ backgroundColor: '#CCC' }, 300, function () {
                $('div#login').animate({ backgroundColor: '#fff' }, 300);
            });
        });
    });

    // make the subscription types more appealing, hover on/off change bg color
    /*$('table.subscription-type .info').hover(
    function() {
    $(this).animate({ backgroundColor: "#EAEAEA" }, 300);
    },
    function() {
    $(this).stop();
    $(this).css("background-color", "#FFF").css("cursor", "normal");
    }
    );*/

    //sub button, next or add to basket
    setButtonText();
    function setButtonText() {
        if ($('table.subscription-type input#_ctl0_cphMain_chbSiteLicence').length > 0) {
            $('a#_ctl0_cphMain_btnDisplayPrices').html("Add to basket");
            if ($('table.subscription-type input#_ctl0_cphMain_chbSiteLicence:checked').length > 0) {
                $('a#_ctl0_cphMain_btnDisplayPrices').html("Next");
            }
        }
    }
    $('table.subscription-type input').click(function () { setButtonText(); });

    //hide the next button if seleting 25+ IP licence as this cant be brought online, call us
    setButtonDisplay();
    function setButtonDisplay() {
        if ($('table.subscription-type input#_ctl0_cphMain_chbSite25plus').length > 0) {
            $('a#_ctl0_cphMain_btnDisplaySiteLicencePrices').show();
            if ($('table.subscription-type input#_ctl0_cphMain_chbSite25plus:checked').length > 0) {
                $('a#_ctl0_cphMain_btnDisplaySiteLicencePrices').hide();
            }
        }
    }
    $('table.subscription-type input').click(function () { setButtonDisplay(); });

    // Show or hide the Blue Lines panel in homepages.
    $("div.sub-blue-box").click(function () {
        $("div.sub-blue-box-full").show("normal");
        return false;
    });

    $("div.sub-blue-box-full p.close-link a").click(function () {
        $("div.sub-blue-box-full").hide("normal");
        return false;
    });

    // Highlights map area in footer when hovering on country name.
    // We used the title attribute as some countries have spaces or invalid characters for the image filename.
    // Please note capitalization of the images!

    $("div.map-navigation li a").hover(function () {
        var countryName = $(this).attr("title");
        $("div.map-navigation #small-map").attr("src", "/resources/1/images/maps/small/" + countryName + ".gif?random=2");
    }, function () {
        $("div.map-navigation #small-map").attr("src", "/resources/1/images/maps/small/africa-map-small.gif?random=2");
    });

    // tooltips for main home page article image
    if ($("div.main-news .tooltip").length > 0) {
        $('div.main-news .tooltip').hide();
        $("div.main-news div.lead-article-image img").qtip({
            content: $('.tooltip').html(),
            position: 'bottomRight',
            hide: {
                fixed: true
            },
            style: {
                background: '#fff',
                color: '#000',
                width: 130,
                fontSize: 10,
                border: {
                    width: 3,
                    radius: 5
                },
                padding: 5,
                textAlign: 'left',
                tip: true,
                name: 'light'
            }
        });
    }

    // maps
    $("div#maps a[rel='map']").colorbox({ transition: "elastic" });

    // custom postback for master asp.net form as it's getting messed up with the URL rewriting
    $("form#aspnetForm").attr("action", "/" + $("form#aspnetForm").attr("action"));
});

$(document).ready(function () {
    if ($('.header #txtUserName').val() == "Username") {
        $('.header #txtUserName').addClass("light-grey");
    }

    if ($('.header #txtTextPassword').val() == "Password") {
        $('.header #txtTextPassword').addClass("light-grey");
    }
});
 
function ClearUserNameTextBox() {
    $(document).ready(function () {
        if ($('.header #txtUserName').val() == "Username") {
            $('.header #txtUserName').val("").removeClass("light-grey");
            $('.header #txtPassword').val("");
        }

        if ($('.header #txtUserName').val() != "Username") {
            $('.header #txtTextPassword').attr("style", "display:none");
            $('.header #txtPassword').attr("style", "display:block");
        }
    });
}

function SetUserNameTextBox() {
    $(document).ready(function () {
        if ($('.header #txtUserName').val() == "") {
            $('.header #txtUserName').val("Username").addClass("light-grey");
            $('.header #txtTextPassword').attr("style", "display:inline");
            $('.header #txtPassword').attr("style", "display:none");
        }

        if ($('.header #txtTextPassword').val() == "") {
            $('.header #txtTextPassword').val("Password").addClass("light-grey");
        }
    });
}

function ClearUserNameTextBox1() {
    $(document).ready(function() {
        if ($('.login #_ctl0_cphMain_txtUserName').val() == "Username") {
            $('.login #_ctl0_cphMain_txtUserName').val("");
            $('.login #_ctl0_cphMain_txtPassword').val("");
            $('.login #_ctl0_cphMain_txtUserName').addClass("light-grey");
        }

        if ($('.login #_ctl0_cphMain_txtUserName').val() != "Username") {
            $('.login #_ctl0_cphMain_txtUserName').removeClass("light-grey");
            $('.login #_ctl0_cphMain_txtTextPassword').attr("style", "display:none");
            $('.login #_ctl0_cphMain_txtPassword').attr("style", "display:inline");
            $('.login #_ctl0_cphMain_txtPassword').removeClass("light-grey");
        }
    });
}

function SetUserNameTextBox1() {
    $(document).ready(function() {
        if ($('.login #_ctl0_cphMain_txtUserName').val() == "") {
            $('.login #_ctl0_cphMain_txtUserName').val("Username");
            $('.login #_ctl0_cphMain_txtUserName').addClass("light-grey");
            $('.login #_ctl0_cphMain_txtTextPassword').attr("style", "display:inline");
            $('.login #_ctl0_cphMain_txtPassword').attr("style", "display:none");
        }

        if ($('.login #_ctl0_cphMain_txtTextPassword').val() == "") {
            $('.login #_ctl0_cphMain_txtTextPassword').val("Password");
            $('.login #_ctl0_cphMain_txtPassword').addClass("light-grey");
        }
    });
}

function ClearForgotPasswordTextBox() {
    $(document).ready(function() {
        if ($('fieldset.#forgot .txtEmailAddress').val() == "Your email address")
            $('fieldset.#forgot .txtEmailAddress').val("");
    });
}

function SetForgotPasswordTextBox() {
    $(document).ready(function() {
        if ($('fieldset.#forgot .txtEmailAddress').val() == "")
            $('fieldset.#forgot .txtEmailAddress').val("Your email address");
    });
} 
