// Define the Aminus3 global namespace object
var Champix = window.Champix || {};

// Setup global vars
if (typeof $D == "undefined") {$D = YAHOO.util.Dom;}
if (typeof $E == "undefined") {$E = YAHOO.util.Event;}

/*****************************************************
 Class: Setup
******************************************************/
Champix.Setup = function()
{
	return {
		//--------------------------------------------------
		init : function()
		{
			$E.addListener('searchText', 'keypress', Champix.Search.handleKeySubmit);
			$E.addListener('searchButton', 'click', Champix.Search.submit);
		}
	}
}();

/*****************************************************
 Class: Search
******************************************************/
Champix.Search = function()
{
	return {
		//--------------------------------------------------
		handleKeySubmit : function(e)
		{
			var keyCode = e.keyCode ? e.keyCode : e.which ? e.which : e.charCode;
			
			if (keyCode == 13) // Enter
			{
				$E.stopEvent(e);
				Champix.Search.submit();
			}
		},
	
		//--------------------------------------------------
		submit : function()
		{
			var url = $D.get('searchUrl').value;
			var keyword = $D.get('searchText').value;
			
			if(keyword.length > 0) {
				window.location = url + keyword;
			}
		}
	}
}();

/*****************************************************
 Initialization
******************************************************/
Champix.Setup.init();