﻿/*
JavaScript functions to improve the performance of the PPR interface.
*/
$(document).ready(function () {

    //save the language text for the search text.
    var searchMessage = $('#txtSearchInput').val();

    //Clears the helper text when the user clicks on it with the mouse so they can
    //begin typing their query.
    $('#txtSearchInput').focus(function () {
        $(this).val('');
    }
	);

    //set the helpful search message back if the search box loses focus.
    $('#txtSearchInput').focusout(function () {
        if ($(this).val() == '') {
            $(this).val(searchMessage);
        }
    });


    //Respond to the enter key when it is pressed in the textbox.
    $('#txtSearchInput').keydown(function (e) {


        if (e.keyCode == 13) {
            e.preventDefault();

            var searchInput = $('txtSearchInput').val();

            if (searchInput != searchMessage) {
                var searchPage = $('#hdnSearchPage').val();
                window.location = searchPage + '?search=' + $.URLEncode($('#txtSearchInput').val());
            }
        }
    });


    $('#btnSearch').click(function (e) {
        e.preventDefault();

        var searchInput = $('txtSearchInput').val();

        if (searchInput != searchMessage) {
            var searchPage = $('#hdnSearchPage').val();
            window.location = searchPage + '?search=' + $.URLEncode($('#txtSearchInput').val());
        }
    });

})

