var inschrijven=Class.create({initialize:function(url){this.url=url;this.refresh(null);this.setHandlers()},refresh:function(type){var params={};switch(type){case'reeks':params={reeks:$('reeksen').value,locatie:null};break;case'locatie':params={reeks:null,locatie:$('locaties').value};break};new Ajax.Request(this.url,{method:'post',parameters:params,onSuccess:this.fill.bind(this)})},refreshByReeks:function(){this.refresh('reeks');this.removeErrors()},refreshByLocatie:function(){this.refresh('locatie');this.removeErrors()},removeErrors:function(){$$('.form_select').each(function(el){Element.removeClassName(el,'error')})},fill:function(transport){this.data=transport.responseText.evalJSON(true);this.fillSelect('reeksen',this.data.reeksen);this.fillSelect('locaties',this.data.locaties);this.fillSelect('tijden',this.data.tijden);$('colleges').innerHTML='';var colleges=this.data.colleges;for(var i=0;i<colleges.length;i++){var span=document.createElement('span');span.appendChild(document.createTextNode(colleges[i].title));$('colleges').appendChild(span)}},fillSelect:function(field,arr){$(field).innerHTML='';for(var i=0;i<arr.length;i++){var option=document.createElement('option');option.value=arr[i].id;option.appendChild(document.createTextNode(arr[i].title));if(arr[i].active){option.setAttribute('selected','selected');if(field=='reeksen')$('kosten').innerHTML=arr[i].kosten};$(field).appendChild(option)}},setHandlers:function(){Event.observe($('locaties'),'change',this.refreshByLocatie.bind(this));Event.observe($('reeksen'),'change',this.refreshByReeks.bind(this))}})
