!function(t,e){function o(t){for(var o=0;o<e.length;o++)if(e[o].target_field_id==t)return e[o]}function n(t){var e=t.target,n=o(t.data);return alert("Please choose "+n.controlling_field_name+" first"),e.blur(),!1}function i(t,n,i){var a,d=t.val();null!=i?(a=[])[0]=o(i):a=function(t){for(var o=[],n=0;n<e.length;n++)e[n].controlling_field_id==t&&(o[o.length]=e[n]);return o}(t.attr("id"));for(var _=0;_<a.length;_++){var s,f=[];f[0]=$("#custom_field_"+a[_].target_field_id);for(var p=0;p<f.length;p++){var c,u=f[p];s=u.get(0),n&&(c=u.val()),"text"!=s.type&&"textarea"!=s.type&&"date"!=a[_].fld_type&&(s.options.length=1);var g=!1;if("local"==a[_].lookup_method){for(var h=0;h<a[_].groups.length;h++)for(var v=0;v<a[_].groups[h].keys.length;v++)if("object"==typeof d&&d.indexOf(a[_].groups[h].keys[v])>-1||a[_].groups[h].keys[v]==d){g=!0;for(var y=0;y<a[_].groups[h].options.length;y++)s.options[s.options.length]=a[_].groups[h].options[y];u.unbind("focus.choose_controller"),n?"text"==s.type||"textarea"==s.type?s.value=c:selectOption(s.form,s.name,c):"text"==s.type||"textarea"==s.type?s.value="":s.selectedIndex=0}}else"ajax"==a[_].lookup_method&&$("#report_form").ajaxSubmit({type:"GET",url:"ajax/get_custom_field_dynamic_options.php",dataType:"json",data:{fld_id:a[_].target_field_id},success:r(s)});1==a[_].hide_when_no_options&&l(s,g)}}}function r(t){return function(e,i){var r,a=$(t),d=o(a.attr("id").split("_")[2]);null!=e?(t.options.length=0,$.each(e,function(e,o){return t.options[t.options.length]=new Option(o,e),!0}),$(t).unbind("focus.choose_controller"),r=!0):(t.options.length=0,t.options[0]=new Option("Please choose an option",""),a.bind("focus.choose_controller",d.target_field_id,n),r=!1),1==d.hide_when_no_options&&l(t,r)}}function l(t,e){0==e?$(t.parentNode.parentNode).hide():$(t.parentNode.parentNode).show()}t.custom_field_init_dynamic_options=function(t){for(var o=function(t){i($(t.target),!1)},r=0;r<e.length;r++)if(e[r].target_field_id==t){var l=$("#custom_field_"+e[r].target_field_id);l.bind("focus.choose_controller",e[r].target_field_id,n);var a=$("#"+e[r].controlling_field_id);a.bind("change.change_options",e[r].controlling_field_id,o),i(a,!0,t);break}},t.custom_field_set_new_options=i}(window,dynamic_options);
