//Setup and attch functions when the document loads
jQuery(document).ready( function() {
    
    //Store the target of focus for later testing
    var target = null;
    jQuery('form :input').focus(function() {
        target = this.id;
    });
        
    jQuery("form").submit(function() {
        //Is the last target the search box or the search button?
        if(target == "plc_lt_zoneSearch_SearchBox_txtWord" || target == "plc_lt_zoneSearch_SearchBox_btnSearch")
        {
            var searchText = jQuery("#plc_lt_zoneSearch_SearchBox_txtWord").val();
            var searchBaseURL = "http://search.nazarene.org/search?site=default_collection&client=ftmdefault&output=xml_no_dtd&proxystylesheet=ftmdefault"
            var newLoc = searchBaseURL + "&q=" + searchText;
            window.location.href = newLoc;
        }
        else
        {
            window.location.href = "/error.html";
        }
        return false;
    });
});    
