Event.observe(window, 'load', function() {
	setMainHeight();
});

getPowiatSelect = function(woj)
{
	new Ajax.Request(DOC_ROOT + 'user/api/powiat/'+woj, {
		method: 'post',
		onSuccess: function(transport) {
			$('powiat_td').update(transport.responseText);
		},
		onCreate: function(transport) {
			$('powiat_td').update(loading_gif);
		}
	});
}

setMiastoGetPowWoj = function(miasto)
{
	new Ajax.Request(DOC_ROOT + 'user/api/miasto/'+miasto, {
		method: 'post',
		onSuccess: function(transport) {
			$('miasto_execute').update(transport.responseText);
		}
	});
}


var badanie = function (div, data) {

	this.div = div;
	this.url = DOC_ROOT + 'user/api/badanie/';
	if (!data) this.data = {};
	else this.data = data;
	
	this.load = function(action)
	{
		if (action) this.data.action = action;
		div = this.div;
		data = this.data;
		
		new Ajax.Request(this.url, {
			method: 'post',
			parameters: data,
			onSuccess: function(transport) {
				$(div).update(transport.responseText);
			},
			onCreate: function(transport) {
				$(div).update(loading_gif);
			}
		});
	}
	
	this.flushFormData = function()
	{
		this.data.form = {};
	}
	
	this.setPacjent = function(pacjent_id)
	{
		this.data.pacjent_id = pacjent_id;
		badanie.load('badanie_formularz');
	}
	
	this.addPacjent = function()
	{
		this.load('pacjent_dodaj');
	}
	
	this.saveForm = function(frm)
	{
		this.data.form = $(frm.id).serialize();
		this.load();
	}
	
	this.setPesel = function(value)
	{
		if (value.length > 10)
		{
			this.pesel = value;
			this.data.pesel = value;
			this.data.action = 'pacjent_po_peselu';
			data = this.data;
			
			new Ajax.Request(this.url, {
				method: 'post',
				parameters: data,
				onSuccess: function(transport) {
					$('pesel_msg').update(transport.responseText);
				},
				onCreate: function(transport) {
					$('pesel_msg').update("Sprawdzam!");
				}
			});
		}
		else
		{
			$('pesel_msg').update("Pesel za krótki!");
		}
	}
}

setMainHeight = function()
{
	var page_size = getPageSize();
	new_center_height = (page_size[3] + getPageScroll() - 330);
	old_center_height = $('center').getHeight();
	if (old_center_height < new_center_height) { $('center').setStyle({minHeight: new_center_height + 'px'}); }
}
