﻿/*******************************
     Constants
*******************************/

var TIP_STYLE = {
    width: 300,
    background: "#ffb515",
    color: "#000000",
    textAlign: "left",
    border: { width: 10, radius: 10, color: "#ff9915" },
    padding: 12,
    tip: true
};

var TIP_RIGHT = {
    position: { corner: { target: "rightMiddle", tooltip: "leftMiddle" }, adjust: { x: 27} },
    show: { when: { event: "focus"} },
    hide: { when: { event: "blur"} },
    style: TIP_STYLE
};

var TIP_TOP_RIGHT = {
    position: { corner: { target: "rightTop", tooltip: "bottomLeft" }, adjust: { x: 20} },
    show: { when: { event: "focus"} },
    hide: { when: { event: "blur"} },
    style: TIP_STYLE
};

var TIP_LEFT = {
    position: { corner: { target: "leftMiddle", tooltip: "rightMiddle" }, adjust: { x: -27} },
    show: { when: { event: "focus"} },
    hide: { when: { event: "blur"} },
    style: TIP_STYLE
};


/*******************************
    Site wide set up
*******************************/
$(document).ready(function () {
    initialisePopups();
    initialiseSearchbox();
});


/* Popups */
function initialisePopups() {
    $("a.popup").click(function () {
        window.open(this.href);
        return false;
    });
}

/* Global search box */
function initialiseSearchbox() {

    var rootUrl = $("#rootUrl").val();
    var defaultGlobalSearch = "Search";

    // Set the default text for the search box
    $("#globalSearch").val(defaultGlobalSearch);

    // If the default text is in the search box, then clear it on focus
    $("#globalSearch").focus(function () {
        if ($("#globalSearch").val() == defaultGlobalSearch)
            $("#globalSearch").val("");
    });

    // If the search box contains the default text or is empty when the button is clicked, then prevent form submission
    $("#globalSearch").click(function (event) {
        if ($("#globalSearch").val() == defaultGlobalSearch || $("#globalSearch").val() == "")
            event.preventDefault();
    });

}
