
/* - jquery.smartforms.js - */
// http://www.shc.edu/portal_javascripts/jquery.smartforms.js?original=1
jQuery.fn.smartforms=function(directives,settings){return this.each(function(){settings=jQuery.extend({display_speed:300,helper_elements:""},settings);settings["helper_elements"]=settings["helper_elements"]+",.smartform_helper";debug=false;if(debug){try{console=console} catch(err){debug=false}}
_contains=function(arr,match){for(i in arr){if(arr[i]==match){return(true)}};return(false)};_process_directives_for_change=function(me,hide_directives,show_directives,do_match_vals){var show_hide_ids={'show':Array(),'hide':Array()};if(hide_directives!=""){jQuery.each(hide_directives, function(index,directive){try{directive["match_values"]=directive["match_values"].split(",")}
catch(err){}
if(!do_match_vals|_contains(directive["match_values"],me.val())){show_hide_ids['hide']=show_hide_ids['hide']+","+directive["affect_ids"]}})}
if(show_directives!=""){jQuery.each(show_directives, function(index,directive){try{directive["match_values"]=directive["match_values"].split(",")}
catch(err){}
match=_contains(directive["match_values"],me.val());if(do_match_vals&match){show_hide_ids['show']=show_hide_ids['show']+","+directive["affect_ids"]}
else if(do_match_vals&!match){show_hide_ids['hide']=show_hide_ids['hide']+","+directive["affect_ids"]}
else{show_hide_ids['show']=show_hide_ids['show']+","+directive["affect_ids"];show_hide_ids['hide']=show_hide_ids['hide']+","+directive["affect_ids"]}})}
return show_hide_ids};_do_hide_show=function(hide_ids,show_ids,speed){if(hide_ids!=""){hide_ids=jQuery(jQuery.unique(jQuery(hide_ids).get()));if(hide_ids.length){if(debug){console.log("hide: ",hide_ids)}
hide_ids=hide_ids.not($(show_ids)).filter(":visible");hide_ids.slideUp(speed)}}
if(show_ids!=""){show_ids=jQuery(jQuery.unique(jQuery(show_ids).get()));if(show_ids.length){if(debug){console.log("show: ",show_ids)}
show_ids.not(":visible").slideDown(speed)}}};_do_toggle=function(hide_ids,show_ids,speed){if(debug){console.log("_do_toggle::\nHIDE: %s\nSHOW:%s",hide_ids,show_ids)}
ids=hide_ids+","+show_ids;if(ids!=","){ids=jQuery(ids);if(ids.length){ids.slideToggle(speed)}}};if(settings["helper_elements"]!=""){if(debug){console.group("hiding helper elements")}
_do_hide_show(settings["helper_elements"],"",0);if(debug){console.groupEnd()}}
jQuery.each(directives, function(index,controller){controller_elem=jQuery(controller['controller_id']);var binder="change";if(controller_elem.attr("type")=="radio"|controller_elem.attr("type")=="checkbox"){binder="click"}
if(debug){console.group("process initial hide on %s \n\ttype:%s\n\tbound to ",controller['controller_id'],controller_elem.attr("type"),binder)}
if(binder=="change"){show_hide_ids=_process_directives_for_change(controller_elem,"",controller['show_directives'],false);_do_hide_show(show_hide_ids["show"],"",0)}
else{_do_hide_show(controller['show_directives'],"",0)}
if(debug){console.groupEnd()};controller_elem.bind(binder,controller, function(){var me=jQuery(this);if(debug){console.group("smart_forms BINDING on %s",me.attr('id'))};if(me.attr("type")=="checkbox"){_do_toggle(controller['hide_directives'],controller['show_directives'],settings["display_speed"])}
else if(binder=="change"){var show_hide_ids=_process_directives_for_change(me,controller['hide_directives'],controller['show_directives'],true);_do_hide_show(show_hide_ids["hide"],show_hide_ids["show"],settings["display_speed"])}
else if(binder=="click"){_do_hide_show(controller['hide_directives'],controller['show_directives'],settings["display_speed"])}
if(debug){console.groupEnd()}})})})};
