// Search box

$(document).ready(function()
  {
    // If the search box has the default value in it and we select it, we clear the box.
    $("#search_text").bind('focus', function()
      {
        if ($(this).attr('value') == $(this).attr('defaultValue'))
        {
          $(this).attr('value', '');
        }
      });
    
    // If the search box is empty when we switch focus, we repopulate it with the default text.
    $("#search_text").bind('blur', function()
      {
        if ($(this).attr('value') == '')
        {
          $(this).attr('value', $(this).attr('defaultValue'));
        }
      });
      
      
      //Button click
            $(".btnSearch").click(function(event)
            {
                Search();         
            });  
            
            //Press enter on search text box
            $("#search_text").keypress(function(event)
            {       
            
                var keyCode = null;

                if( event.which ) 
                {
                        keyCode = event.which;
                } 
                else if( event.keyCode ) 
                {
                    keyCode = event.keyCode;
                }
               
                if( 13 == keyCode ) 
                {                    
                     Search();
                    return false;
                }
                return true;
            }); 
            
            
          var Search = function()
	      {
	            var searchText = $("#search_text").val();	      
                if(searchText.length > 1)
                    window.location = "Search.aspx?keyword=" + searchText;
                else
                    alert('Please enter a search phrase');
	      };
      
  });

