/* $Id: core.js 5 2007-10-10 15:45:18Z jure.merhar $ */

/* StartUp */

var StartUp = Class.create(); StartUp.prototype =
{
	initialize: function(runnable)
	{
	  Event.onDOMReady(runnable.run.bindAsEventListener(runnable));
	}
}

/* PostBack */

var PostBack = Class.create(); PostBack.prototype =
{
	initialize: function(select, submit)
	{
	  this.select = select;
	  this.submit = submit;
	},

	run: function()
	{
	  var select = $(this.select);
		Event.observe(select, 'change', this.submitForm.bindAsEventListener(select));
		if (typeof this.submit != 'undefined') {
			$(this.submit).remove();
		}
	},

	submitForm: function()
	{
	  this.form.submit();
	}
}

/* RadioToggle */

var RadioToggle = Class.create(); RadioToggle.prototype =
{
	initialize: function(radioHide, radioShow, container)
	{
		this.radioHide = radioHide;
		this.radioShow = radioShow;
		this.container = container;
	},
	
	run: function()
	{
		this.radioHide = $(this.radioHide);
		this.radioShow = $(this.radioShow);
		this.container = $(this.container);
	  var listener = this.toggleForm.bindAsEventListener(this);
		if (this.radioHide && this.radioShow && this.container) {
		  if (this.radioHide.checked) {
	    	this.container.hide();
	    }
		  Event.observe(this.radioHide, 'click', listener);
		  Event.observe(this.radioShow, 'click', listener);
	  }
	},

	toggleForm: function(e)
	{
	  if (Event.element(e) == this.radioShow) {
	    this.container.show();
	  } else {
	    this.container.hide();
	  }
	}
}
