/* Brian Loomis shared this snippet of code with me */

function makeSublist(parent,child,blankSubselect,childVal)
{
	
        $("body").append("<select style='display:none' id='"+parent+child+"'></select>");
        $('#'+parent+child).html($("#"+child+" option"));
        var parentValue = $('#'+parent).attr('value');
        
        $('#'+child).html($("#"+parent+child+" .sub_"+parentValue).clone());
        
        if (! typeof childVal == "undefined") {
			$("#"+child+' option[@value="'+ childVal +'"]').attr('selected','selected');        	
        }
        $('#'+parent).change( 
                function()
                {
                	
                        var parentValue = $('#'+parent).attr('value');
                        
                        $('#'+child).html($("#"+parent+child+" .sub_"+parentValue).clone());
                        
                        
                        if(! (typeof(blankSubselect) == "undefined")) {
                        	
                        	if ($('#'+child+' option').size()>0) {
                        		
                        		$('#'+child).prepend("<option selected='selected' value='" + blankSubselect + "'> -- Select -- </option>");
                        	}
                        } else {
                        	
                        	alert(' not prepending '); 
                        }
                        
                        $('#'+child).trigger("change");
                        
                        $('#'+child).focus();
                }
        );
}

/*        $(document).ready(function()
        {
                makeSublist('child','grandsun', true, '');        
                makeSublist('parent','child', false, '1');        
        });
*/


