jQuery(document).ready(function(){
    //*************************
    // BEGIN: Hide selected 'other' fields based on corresponding drop down state
    //*************************
    
    // the following array is JSON. In the future, if more flexibility is wanted in the use of this function,
    // the JSON can be set per page based on existing controls.
    var element_pairs = {
        "pairs":[
            {
                "select":"selection\\.busInd",
                "input":"selection\\.otherBusinessType"
            },
            {
                "select":"addAcct\\.title",
                "input":"selection\\.otherTitle"
            }
        ] 
    }; // end Pairs
    
    // check to see if all the specified elements actually exist on the page:
    var allElementsExist = true;
    $.each(element_pairs.pairs, function(index, pair){
        if($('#' + pair.select).length <= 0 || $('#' + pair.input).length <= 0)
        {
            allElementsExist = false;
        }
    });
    
    // if they do:
    if(allElementsExist)
    {
        $.each(element_pairs.pairs, function(index, pair){
            //initially hide the inputs
            $('#tr_' + pair.input).hide();
               
            //on select change, show/hide the corresponding inputs
            $('#' + pair.select).change(function(){
                    
                var selected = $('#' + pair.select + ' option:selected');
                      
                if(selected.val() == "99")
                {
                    $('#tr_' + pair.input).show();
                }
                else
                {
                    $('#tr_' + pair.input).hide();
                    // and wipe the fields:
                    $('#' + pair.input).val('');
                }
            }); // end select change event handler
            
            // now trigger it so they do the right thing from the beginning.
            $('#' + pair.select).trigger('change');
            
        }); // end pairs event handler setup
    } // end if allElementsExist
    //*************************
    // END: Hide selected 'other' fields based on corresponding drop down state
    //*************************
}); // end on doc ready

