
//
//Changed search around so we can catch any form submit from the aspForm
//This allows us to send to an error page if it wasn't for the subscription form
//
$(document).ready( function(){
    //Store the target of focus for later testing
    var target = null;
    jQuery('#aspnetForm :input').focus(function() {
        target = this.id;
    });
    
    //catch all aspnetForm submits - all other forms would have been created by us.
    $("#aspnetForm").submit( function(){
        //If the target was the search input field or the search icon, then do a search.
        if(target.match(/_SearchTextBox$/) || target.match(/_SearchButton$/))
        {
            var searchBox = target.replace("_SearchButton", "_SearchTextBox");
            var searchBaseURL = "http://search.nazarene.org/search?site=default_collection&client=nazdefault&output=xml_no_dtd&proxystylesheet=nazdefault&btnG=Google%20Search";
            window.location = searchBaseURL + "&q=" + $("#" + searchBox).val(); 
        }
        else
        {
            window.location.href = "/contactus.html?formerror=1";
        }
        
        return false;
    });
});



////function checkSearchBox(e)
//{
//	if( window.event ) e = window.event;
//	
//	if(e.keyCode == 13)
//	{
//		doSearch();
//	}
//}
//

//
////Setup and attch functions when the document loads
//$(document).ready( function() {
//		//Get the current search box pieces
//		var searchbox = document.getElementById("ctl00_SearchTextBox");
//		var old_searchbutton = document.getElementById("ctl00_SearchButton");
//	
//		//create the new button
//		var new_searchlink = document.createElement("a");
//			new_searchlink.setAttribute("href", "javascript:void()");
//			new_searchlink.setAttribute("id", "newSearchLink");
//		var new_searchbutton = document.createElement("img");
//			new_searchbutton.setAttribute("src", "/App_Images/search_button.gif");
//			new_searchbutton.setAttribute("id", "newSearchLink");
//			
//			new_searchlink.appendChild(new_searchbutton);
//	
//		//Swap in the new search button
//		old_searchbutton.parentNode.appendChild(new_searchlink);
//		old_searchbutton.parentNode.removeChild(old_searchbutton);
//		
//		//add a listener to the box to update link
//		document.getElementById("newSearchLink").onclick = doSearch;
//		searchbox.onkeypress = checkSearchBox;
//		
//	} );
//        
        

