


////////////////////////////////////////////////////////////////////////////////////////////////////////
// Handler for Search Button Click
////////////////////////////////////////////////////////////////////////////////////////////////////////
function on_SearchButtonClick()
{
	//store the url of the calling page
	var calling_page = document.URL;
    
    //gather the text entered into the criteria edit control
	var search_criteria = document.getElementsByName('searchCriteria')[0].value;
	
	//rem the following out for real usage - only for debug
	//alert( (calling_page + "   " + search_criteria) );
    
    //the call below results in redirection to server side processing page and then results page
    InvokeContentSearch( calling_page, search_criteria );
}
 

////////////////////////////////////////////////////////////////////////////////////////////////////////
// Invokes Server Side Search Processing Page
////////////////////////////////////////////////////////////////////////////////////////////////////////
function InvokeContentSearch(CallingPage, SearchCriteria)
{
    //code for gathering criteria from edit controls and assembling 
    //into a Search Criteria XML stream, which is passed to the 
    //server-side search page
    
	// DEBUG
	//alert("CallingPage: " + CallingPage + "; criteria: " + SearchCriteria);
	//alert("document.location.hostname: " + document.location.hostname);

	var page_url = document.location.protocol + "//" + document.location.hostname + "/Processors/SearchGateway.aspx";
	var clean_calling_page = StripQueryString(CallingPage);
	var query_str = "?Requestor=" + clean_calling_page + "&SearchCriteria=" + SearchCriteria;
    var complete_url = page_url + query_str;

	// DEBUG
	//alert("complete_url: " + complete_url);
    
    //url below should reflect valid production url to consumer site
    top.location = complete_url;
}
 
function StripQueryString( URLWithQueryString )
{
	//store the url of the calling page
	var url = URLWithQueryString;
	var clean_url = "";
	var idx = url.indexOf("?Requestor=");
	if(idx > -1) 
	{ 
		clean_url = url.substring(0, idx); 
	}
	else
	{
		clean_url = url;
	}
	return clean_url;
}


////////////////////////////////////////////////////////////////////////////////////////////////////////
// Encodes Potentially Invalid Data Into HTML Acceptable Data
////////////////////////////////////////////////////////////////////////////////////////////////////////
function EncodeSourceURLAndSearchParams(ThisPageURL, SearchCriteria)
{
 
    //base-64 encode the strings and append the second to the first

    var encoded_url_str = ""
    var encoded_criteria_str = ""
    var encoded_qry_str = (encoded_url_str  + encoded_criteria_str );
    return encoded_qry_str ;

}
 
 
