﻿
//NEWS SEARCH
//used to activate the News2\NewsLeftMenu.ascx search section
function SetNewsSearch(jqRefAdvancedSearchButton, jqRefFullSearchButton, jqRefAdvancedSearchTxtBox) {
    
    //SetDefaultButton($(jqRefAdvancedSearchButton));

    $(".CheckSearch").click(function () {
        if ($(jqRefAdvancedSearchTxtBox).val() == "Search")
            return false;
    });

    $("#aToggleSearch").click(function () {
        if ($("#divKeywordSearch").css("display") == "none") {
            $("#divKeywordSearch").css("display", "");
            $("#divAdvancedSearch").css("display", "none");
            $("#aToggleSearch").html("Advanced Search");

            //SetDefaultButton($(jqRefAdvancedSearchButton));
        }
        else {
            $("#divKeywordSearch").css("display", "none");
            $("#divAdvancedSearch").css("display", "");
            $("#aToggleSearch").html("Simple Search");

            //($(jqRefFullSearchButton));
        }

        return false;
    });
}

//END NEWS SEARCH

//NEWS CATEGORY MENU
//used to activate the News2\NewsLeftMenu.ascx category/menu section
function SetMenuOpen(jqRefLink) {
    $(jqRefLink).click();
}

function ToggleMenu(event) {
    var ImagesPath = event.data.ImagesPath;

    var ClosedLinkText = $(this).find("span").html();

    $($(this).attr("href")).slideDown(700);
    $(this).find("img").attr("src", ImagesPath + "News/BlueArrowUp.gif");
    $(this).find("span").html(ClosedLinkText.replace("More", "Fewer"));
    $(this).find("input:hidden").val(1);

    $(this).unbind("click");

    $(this).click(function () {
        $($(this).attr("href")).slideUp(700);
        $(this).find("img").attr("src", ImagesPath + "News/BlueArrowDown.gif");
        $(this).find("span").html(ClosedLinkText);
        $(this).find("input:hidden").val(0);

        $(this).bind("click", { ImagesPath: ImagesPath }, ToggleMenu);

        return false;
    });

    return false;
}

function SetToggleNewsMenu(ImagesPath) {
    $(".OpenMenu").bind("click", { ImagesPath: ImagesPath }, ToggleMenu);
}

//END NEWS CATEGORY MENU

//NEWS TABS
//used to activate the News2\TabArticleList.ascx tab section

function SetNewsTabs() {
    $(".HideTab").hide();

    $(".TabTable td").click(function () {
        if ($(this).hasClass("SelectedTab") == false) {
            var TabUniqueID = $(this).attr("class");
            var ActiveTabID = $(this).find("a").html();

            $(".TabTable ." + TabUniqueID).removeClass("SelectedTab");

            $(this).addClass("SelectedTab");
            $("." + TabUniqueID + " .Tab").hide();

            $("#" + TabUniqueID + "_" + ActiveTabID).show();
        }

        return false;
    });
}

//END NEWS TABS

//TOOLS

//To activate add the class "ClearInput" to the text boxs and call the function
function ActivateClearInput() {
    $(".ClearInput").focusin(function () {
        var Value = $(this).val();

        if (!$(this).hasClass("Clicked")) {
            $(this).val("");
            $(this).addClass("Clicked");

            $(this).blur(function () {
                if ($(this).val() == "") {
                    $(this).val(Value);
                    $(this).removeClass("Clicked");
                }
            });
        }
    });
}

function SetDefaultButton(jqRefButton) {
    $("form input").keypress(function (e) {
        if ((e.which && e.which == 13) || (e.keyCode && e.keyCode == 13)) {
            $(jqRefButton).click();
            return false;
        } else {
            return true;
        }
    });
}
