(function(a){a.fn.selectChain=function(b){var d={key:"id",value:"label",loadingText:"Bezig met laden..",errorText:"Er is een onbekende fout opgetreden"};var c=a.extend({},d,b);if(!(c.target instanceof a)){c.target=a(c.target)}return this.each(function(){var e=a(this);e.change(function(){var h=null;if(c.depends!=null){if(!(c.depends instanceof a)){c.depends=a(c.depends)}}if(typeof c.data=="string"){h=c.data+"&"+this.name+"="+e.val();if(c.depends!=null){for(var g=0;g<c.depends.length;g++){h=h+"&"+c.depends.get(g).name+"="+a(c.depends.get(g)).val()}}}else{if(typeof c.data=="object"){h=c.data;h[this.name]=e.val();if(c.depends!=null){for(var g=0;g<c.depends.length;g++){h[c.depends.get(g).name]=a(c.depends.get(g)).val()}}}}c.target.empty();if(c.loadingText.length>0){var f=document.createElement("OPTION");f.text=c.loadingText;c.target.get(0).options[0]=f}a.ajax({url:c.url,data:h,type:(c.type||"get"),dataType:"json",success:function(l){c.target.empty();var k=[],m=0,n=null;for(m=0;m<l.length;m++){n=document.createElement("OPTION");n.value=typeof l[m]=="object"?l[m][c.key]:l[m];n.text=typeof l[m]=="object"?l[m][c.value]:l[m];c.target.get(0).options[m]=n}setTimeout(function(){c.target.find("option:first").attr("selected","selected").parent("select").trigger("change")},0)},error:function(j,i,k){if(c.errorText.length>0){alert(c.errorText)}}})})})}})(jQuery);
