function makeSublist(parent,child,isSubselectOptional,childVal) {
	jQuery("body").append("<select style='display:none' id='"+parent+child+"'></select>");
	jQuery('#'+parent+child).html(jQuery("#"+child+" option"));

	var parentValue = jQuery('#'+parent).attr('value');
	jQuery('#'+child).html(jQuery("#"+parent+child+" .sub_"+parentValue).clone());

	childVal = (typeof childVal == "undefined")? "" : childVal ;
	jQuery("#"+child).val(childVal).attr('selected','selected');

	jQuery('#'+parent).change(function(){
		var parentValue = jQuery('#'+parent).attr('value');
		jQuery('#'+child).html(jQuery("#"+parent+child+" .sub_"+parentValue).clone());
		if(isSubselectOptional) jQuery('#'+child).prepend("<option value='none' selected='selected'> -- Select -- </option>");
		jQuery('#'+child).trigger("change");
		jQuery('#'+child).focus();
	});
}

jQuery().ready(function() {
	makeSublist('child','grandsun', true, '');
	makeSublist('parent','child', false, '1');

	jQuery("#grandsun").change(function() {
		var option = jQuery(this).val();
		if (option.substr(0, 4) == 'http') {
			window.location = option;
		}
	});
});
