var selectButton = Class.create();

selectButton.prototype = 
{
	initialize: function(e) 
	{
		this.e = e;
		this.setEvents(e);
	},
	
	doRequest: function()
	{
		var option = 
		{
			method : 'post',
			parameters : Form.serialize('selectForm'),
			onComplete: function(t){activeButton.afterRequest(t);}
		};
			
		new Ajax.Request('ajax/update.php', option);
	},
	
	afterRequest: function(t)
	{
		//alert(t.responseText);
		switch(t.responseText)
		{
			case 'selectUpdated':
				writeResponse('je persoonsgegevens zijn aangepast');
				success();
				this.updateAfterRequest();
				break;
			default:
				writeResponse('ooops... foutje. probeer het nog een keer');
				error();
		}
	},
	
	updateAfterRequest: function()
	{
		refreshContent(new Array('studySelect','yearSelect','studyHeader','yearHeader'));
	},
	
	setEvents: function(e)
	{
		Event.observe(e, 'mouseover', this.doMouseover.bindAsEventListener(this), false);
		Event.observe(e, 'mouseout', this.doMouseout.bindAsEventListener(this), false);
		Event.observe(e, 'change', this.doClick.bindAsEventListener(this), false);
		
		e.onclick = function()
		{
			return false;
		};	
		
		e.onmouseover = function()
		{
			return false;
		};
		
		e.onmouseout = function()
		{
			return false;
		};
	},
	
	doClick: function()
	{
		activeButton = this;
		this.doRequest();
		this.e.blur();
	},
	
	doMouseover: function()
	{
		
		this.e.style.cursor = 'pointer';
	},
	
	doMouseout: function()
	{
		
	}	
}
	
function initSelectButton()
{
	buttons = document.getElementsByClassName('selectButton');
	for(i = 0; i < buttons.length; i++)
	{
		button = new selectButton(buttons[i]);
	}
}

//Event.observe(window, 'load', initLoginButton, false);

