var loadForm = function (e) {
	Event.observe($('choice1'),'change',changeCouncil);
	Event.observe($('choice2'),'change',changeCouncil);
	Event.observe($('choice3'),'change',changeCouncil);
	Event.observe($('choice4'),'change',changeCouncil);
}

var changeCouncil = function (e) {
	cID = Event.element(e).id.substring(6,7);
	
	new Ajax.Request('/getCouncils/'+Event.element(e).value+'/', {
		method: 'get',
		onSuccess: function(transport) {
			sc1 = $('c'+cID+'c1');
			sc2 = $('c'+cID+'c2');
			sc3 = $('c'+cID+'c3');
			sc4 = $('c'+cID+'c4');
			
			for (i=0,j=sc1.options.length-1;j>i;j--) {
				sc1.remove(j);
			}
			for (i=0,j=sc2.options.length-1;j>i;j--) {
				sc2.remove(j);
			}
			for (i=0,j=sc3.options.length-1;j>i;j--) {
				sc3.remove(j);
			}
			for (i=0,j=sc4.options.length-1;j>i;j--) {
				sc4.remove(j);
			}
			xxml = transport.responseXML;
			landen = xxml.getElementsByTagName('land');
			k= 1;
			for (i=0,j=landen.length;i<j;i++) {
				sc1.options[k] = new Option(landen[i].getAttribute('naam'),landen[i].getAttribute('id'));
				sc2.options[k] = new Option(landen[i].getAttribute('naam'),landen[i].getAttribute('id'));
				sc3.options[k] = new Option(landen[i].getAttribute('naam'),landen[i].getAttribute('id'));
				sc4.options[k] = new Option(landen[i].getAttribute('naam'),landen[i].getAttribute('id'));
				k++;
			}
			Element.addClassName($('c'+cID),'show');
	 	}
	});
}

Event.observe(window,'load',loadForm);