﻿//Check and assign BeautyTip tool tips
function ToolTipCheck() {
    //Get object that start with 'tt'
    $("[id^= 'tt']").each(function() {
        var str = $(this).attr("id").split("-");//using id attr, get name of glossary div
        var aPath = '/Glossary.aspx div#' + str[1];
        $(this).bt({
            ajaxPath: aPath
        });
    });
}

//MENU control
function MenuControl() {
    //Make entire div clickable
    $("ul > .submenu").click(function() {
        window.location = $(this).find("a").attr("href"); return false;
    });

    //menu roll over effects
    $("ul > .submenu").hover(
            function() {
                $(this).fadeOut(200);
                $(this).fadeIn(350);
                $(this).addClass('menuHover');
            },
           function() {
               $(this).removeClass('menuHover');
           }
          );
}

//Event handler for Search for a Location: input box
function LocationSearchInput() {
    //-------------Search a location box--------------------------
    //Put in sample text in input box...enter address or landmark
    loadInputText();
    $("#btnFind").click(function() {
        window.location.replace("/search.aspx?&loc=" + $('#txtWhere').val());
    });

    //Enter keypress within text box
    $("#txtWhere").keypress(function(e) {
        if ((e.which && e.which == 13) || (e.keyCode && e.keyCode == 13)) {
            //button click
            $("#btnFind").click();
            return false;
        } else {
            return true;
        }
    }); //--------------------------------------------------------------
}

//Using title attribute to populate input field...dissapears on focus
//Used in search location input boxes
function loadInputText() {
    $('input[type=text][title!=""]').each(function() {
        if ($.trim($(this).val()) == '') $(this).val($(this).attr('title'));
        if ($(this).val() == $(this).attr('title')) $(this).addClass('sampleText');
    }).focus(switchText).blur(switchText);

    $('form').submit(function() {
        $(this).find('input[type=text][title!=""]').each(function() {
            if ($(this).val() == $(this).attr('title')) $(this).val('');
        });
    });
}

function switchText() {
    if ($(this).val() == $(this).attr('title'))
        $(this).val('').removeClass('sampleText');
    else if ($.trim($(this).val()) == '')
        $(this).addClass('sampleText').val($(this).attr('title'));
}
