/**
 * This file is copyright Four Point Two Software Ltd.
 *
 * mikey@fourpointtwo.co.nz
 * www.fourpointtwo.co.nz
 */

var TopProducts = new Class({

	domNode: null,

	initialize: function(formId)
	{
		this.domNode				= $(formId);

		this.domNode.getElements('input[type=radio]').each(function(item){
			item.addEvent('click', this.searchTopProducts.bindWithEvent(this));
		}, this);

		this.domNode.getElement('#reset').addEvent('click', this.resetForm.bindWithEvent(this));
	},

	searchTopProducts: function(event)
	{
		this.domNode.set('send', {method: 'post'
													 , url: '/top-products/search.phtml'
													 , onSuccess: this.onSuccess.bind(this) });
		this.domNode.send();
	},

	onSuccess: function(responseText, responseXML)
	{
		$('topProductResults').innerHTML = responseText;
	},

	resetForm: function(event)
	{
		this.domNode.getElements('input[type=radio]').each(function(item){
			item.checked = false;
		}, this);
		this.searchTopProducts(null);
	}
});