﻿//AUTHOR:   Jebb Burditt
//DATE:     July 21, 2010

var searchBoxDefault = "SEARCH";

/*
Example: to make all input fields with class searchInput of form 'form1' search boxes use $("form1").searchInput();
Note: all search box input fields should have class name 'searchInput'
<body>
    <script type="text/javascript">
        $(document).ready(function() {
            $("form1").searchInputify();
        });
    </script>
    
    <form id="form1">
        <input type="text" class="searchInput">
    </form>
</body>
*/

jQuery.fn.searchInputify = function() {
    $(".searchInput:input").each(function(i, el) {
        //searchInput show/hide default text
        $(el).focus(function() {
            if ($(this).attr("value") == searchBoxDefault) $(this).attr("value", "");
        });
        $(el).blur(function() {
            if ($(this).attr("value") == "") $(this).attr("value", searchBoxDefault);
        });
        $(el).blur();
    });
};
