/*
 * Implements HTML 5 Style place holder text support for the search box.
 * @author Raajkumar Subramaniam
 *
 * Requirements:
 * 1. The header must load jQuery 1.5.2 or later.
 * 2. The page must contain an input box with identifier "searchBox"
 * 3. This script must be add to the page.
 * 4. The CSS may include an emptyInputBox style.
 */
//The following code block will be executed when the document is ready.
$(function(){
    //Find and cache the search input box
    var searchBox = $('#searchBox');

    //Type will be "text" if the browser does not support type="search"
    if (searchBox.attr("type") === "text") {
        //Get the place holder text from the value attribute.
        placeHolderText = searchBox.attr("placeholder");

        //Show the place holder text by default
        searchBox.addClass("emptyInputBox").val(placeHolderText);

        //Add a focus event handler to clear the search text box, if the current value is the place holder text.
        searchBox.focus(function() {
            if($(this).val()=== placeHolderText) {
                $(this).removeClass("emptyInputBox").val('');
            }
        });

        //Add a blur event handler to put the place holder text back, if the search text box is empty.
        searchBox.blur(function() {
            if($(this).val()=== '') {
                $(this).addClass("emptyInputBox").val(placeHolderText);
            }
        });
    }
});
