function make_favorite_pgm() {
	var this_view = null;
	var favorite_pgm_info = {num:"", pgm_name: "", dir_name: ""};
	var source = $("#favoriteTemplate").html();
	var template = Handlebars.compile(source);
	var html = null;
	$('#'+active_base+' .fav_list').html("").show();
	$('#'+active_base+' .fav_edit').hide();
	$('#'+active_base+' .btn_favedit').val(langs.getText("common","btn_edit")).show();
	$('#'+active_base+' .btn_favsave').val(langs.getText("common","btn_save")).hide();
	$('#'+active_base+' .btn_favback').val(langs.getText("common","btn_back")).hide();
	$('#'+active_base+' .btn_favclear').val(langs.getText("common","clear")).hide();
	
	if (active_base == "tab_function_base") {
		this_view = func_menuList_view;
	} else {
		this_view = pgm_menuList_view;
	}
	
	_.each(this_view.collection.models, function (item) {
		favorite_pgm_info.dir_name = item.attributes.name;
      _.each(item.attributes.children, function (child) {
         if ((child.auth && child.fav) || ((active_base == "tab_function_base") && child.fav)) {
            favorite_pgm_info.num = child.num;
            favorite_pgm_info.pgm_name = child.name;

				html = template(favorite_pgm_info);
				$('#'+active_base+' .fav_list').append(html);
         }
      }, this);
   }, this);
   
   $(document).trigger("Resize_pane");
}

$(document).on('click', '.btn_favedit', function (e) {
	var this_view = null;
	$('#'+active_base+' .fav_list').hide();
	$('#'+active_base+' .fav_edit').html("").show();
	$('#'+active_base+' .btn_favedit').val(langs.getText("common","btn_edit")).hide();
	$('#'+active_base+' .btn_favsave').val(langs.getText("common","btn_save")).show();
	$('#'+active_base+' .btn_favback').val(langs.getText("common","btn_back")).show();
	$('#'+active_base+' .btn_favclear').val(langs.getText("common","clear")).show();
	
	if (active_base == "tab_pgm_base") {
		this_view = pgm_menuList_view;
	} else if (active_base == "tab_function_base") {
		this_view = func_menuList_view;
	}
	
	$('#'+active_base+' .fav_edit').append("<span style='margin-left:20px'>"+langs.getText("p97","info")+"</span><br><table class='table table-bordered' style='margin-left:20px'><tbody></tbody></table>");
	_.each(this_view.collection.models, function (item) {
		$('#'+active_base+' .fav_edit table tbody').append("<tr><th style='background-color:#D9EDF7'>"+item.attributes.name+"</th><td></td></tr>");
      _.each(item.attributes.children, function (child) {
			if (((active_base == "tab_pgm_base") && child.auth) || (active_base == "tab_function_base")) {
				$('#'+active_base+' .fav_edit table tr:last td').append("<input type='checkbox' value='"+child.num+"' style='margin-right:10px'>"+child.name+"<br>");
				if (child.fav) {
					$('#'+active_base+' .fav_edit table input:checkbox:last').attr('checked','checked');
				}
			}
      }, this);
      if (!$('#'+active_base+' .fav_edit table tr:last td').children('input').length) {
			$('#'+active_base+' .fav_edit table tr:last').remove();
      }
   }, this);
   
   $(document).trigger("Resize_pane");
});

$(document).on('click', '.btn_favback', function (e) {
	$('#'+active_base+' .fav_list').show();
	$('#'+active_base+' .fav_edit').hide();
	$('#'+active_base+' .btn_favedit').show();
	$('#'+active_base+' .btn_favsave').hide();
	$('#'+active_base+' .btn_favback').hide();
	$('#'+active_base+' .btn_favclear').hide();
});

$(document).on('click', '.btn_favsave', function (e) {
   var pre_msg = new Array();
   var send_msg = "";
   var range_type = [];
   var range = [];

	_.each($('#'+active_base+' .fav_edit table input:checkbox'), function(item) {
		if (item.checked) {
			pre_msg.push(item.value);
		}
	});
	debug_mode.flag && console.log(pre_msg);
	
	if (active_base == "tab_pgm_base") {
		send_msg += "{\"FAVORITE_PGMLIST\":\"";
	} else if (active_base == "tab_function_base") {
		send_msg += "{\"FAVORITE_FUNCLIST\":\"";
	}
	_.each(pre_msg, function(item, i) {
		if (active_base == "tab_pgm_base") {
			send_msg += item + ": 1";
      } else if (active_base == "tab_function_base") {
			send_msg += "'" + item + "': 1";
      }
      if (i != pre_msg.length - 1) {
         send_msg += ", ";
      }
	});
	send_msg += "\"}";
	debug_mode.flag && console.log(send_msg);
   packet.setPacket(1, range_type, range, send_msg);
   sendMsg(packet.main, "pgm97", packet.type, packet.range, packet.msg);
});

$(document).on('click', '.btn_favclear', function (e) {
	$('#'+active_base+' .fav_edit table input:checkbox:checked').removeAttr("checked");
});

$(document).on('click', '.fav_edit table input:checkbox', function (e) {
	if ($('#'+active_base+' .fav_edit table input:checkbox:checked').length > 20) {
		return false;
	}
});

$(document).on('click', '.fav_button', function (e) {
   var tab_str = "";
   
   if (active_base == "tab_pgm_base") {
		tab_str = "pgm"+$(this).attr('name');
   } else if (active_base == "tab_function_base") {
		tab_str = $(this).attr('name');
   }
   
	var sel_id = "#"+tab_str;
	var ch_flag = false;
	_.each($('.custom_span_menu .pgm a'), function(item, i) {
		if($('.custom_span_menu .pgm a:eq(' + i + ')').attr('href') == sel_id) {
			$('.custom_span_menu .pgm:eq(' + i + ')').addClass('active');
			if($('.custom_span_menu .pgm:eq(' + i + ')').parents('.nav-list').children('.active').length > 1) {
				ch_flag = false;
				$('.custom_span_menu .pgm:eq(' + i + ')').siblings().removeClass('active');
			} else {
				ch_flag = true;
				$('.custom_span_menu .pgm').removeClass('active');
				$('.custom_span_menu .pgm:eq(' + i + ')').addClass('active');
			}
			return false;
		}
	});
	
	if(ch_flag) {
		$('.accordion-body').removeClass('in');
		$('.accordion-body')['height'](0);
		$("#accordion2 .accordion-toggle").removeClass('active');
		$("#accordion2 .accordion-toggle").children('img').remove();
		
		$('.accordion-body .active').parents('.accordion-body').addClass('in');
		$('.accordion-body .active').parents('.accordion-body')['height']('100%');
		$('.accordion-body .active').parents('.accordion-group').children('.accordion-heading').children('.accordion-toggle').addClass('active');
		$('.accordion-body .active').parents('.accordion-group').children('.accordion-heading').children('.accordion-toggle').append("<img src='img/a.png' style='float:right; margin-top:6px;' />");
	}

   var tab_title = $(this).children('.fav_pgmname').text();
   var tab_index = 0;
   var existed = false;
   var range_type = [];
   var range = [];

   $('#' + active_base + ' .nav-list li').removeClass("active");

   $('#' + active_base + ' .nav-tabs-main li').removeClass("active");
   $('#' + active_base + ' .tab-content-main .tab-pane-main').removeClass("active");

   var i = 1;

   _.each($('#' + active_base + ' .nav-tabs-main li'), function (item) {
      if (("#" + tab_str) === $('#' + active_base + ' .nav-tabs-main li:eq(' + i + ')').children().attr("href")) {
         existed = true;
         tab_index = i;
      }
      i++
   }, this);

   if (existed === true) {
      $('#' + active_base + ' .nav-tabs-main li:eq(' + tab_index + ')').addClass("active").html("<a href=\"#" + tab_str + "\" data-toggle=\"tab\">" + tab_title + "<img src='img/refresh_icon.png' class='icon_refresh' title='" + langs.getText("toolTip","tip_refreshtab") + "' /><img src='img/close_icon.png' class='icon_remove' title='" + langs.getText("toolTip","tip_closetab") + "' /></a>");
      $('#' + active_base + ' .tab-content-main .tab-pane-main:eq(' + tab_index + ')').addClass("active");
   } else {
      $('#' + active_base + ' .nav-tabs-main').append("<li title=\"" + tab_title + "\" class=\"active\"><a href=\"#" + tab_str + "\" data-toggle=\"tab\">" + tab_title + "<img src='img/refresh_icon.png' class='icon_refresh' title='" + langs.getText("toolTip","tip_refreshtab") + "' /><img src='img/close_icon.png' class='icon_remove' title='" + langs.getText("toolTip","tip_closetab") + "' /></a></li>");
      $('#' + active_base + ' .tab-content-main').append("<div class=\"tab-pane tab-pane-main active\" id=" + tab_str + "></div>");
      if(active_base == "tab_pgm_base") {
			$('.tab_scrlbar_util .tab_list .tab_list_pgm ul').append("<li class='tab_name'><a href='#" + tab_str + "' data-toggle='tab'>" + tab_title + "</a></li>");
		} else if(active_base == "tab_function_base") {
			$('.tab_scrlbar_util .tab_list .tab_list_func ul').append("<li class='tab_name'><a href='#" + tab_str + "' data-toggle='tab'>" + tab_title + "</a></li>");
		} else if(active_base == "tab_maintenance") {
			$('.tab_scrlbar_util .tab_list .tab_list_mnt ul').append("<li class='tab_name'><a href='#" + tab_str + "' data-toggle='tab'>" + tab_title + "</a></li>");
		} else if(active_base == "tab_stn_base") {
			$('.tab_scrlbar_util .tab_list .tab_list_stn ul').append("<li class='tab_name'><a href='#" + tab_str + "' data-toggle='tab'>" + tab_title + "</a></li>");
		}
   }

   ap.active_pgm = tab_str;
   ap.render_pgm = ap.active_pgm;

   if (active_base == "tab_pgm_base") {
      if (existed === true) {
         $("#" + ap.render_pgm).html("");
      }
      packet.setPacket(0, range_type, range, "{}");
      pgm_models.get_model(ap.render_pgm, true, packet);
   } else if (active_base == "tab_function_base") {
      if (existed === true) {
         ap.render_pgm = $("#" + tab_str + " .tab-content-sub .active").attr("id");
         $("#" + ap.render_pgm).html("");
         packet.setPacket(0, range_type, range, "{}");
         pgm_models.get_model(ap.render_pgm, true, packet);
      } else {
         pgm_models.get_func_model(tab_str, true);
      }
   }

   tab_history[0] = tab_history[1];
   tab_history[1] = tab_title;

   //debug_mode.flag && console.log("tab_history[0] : "+tab_history[0]+"  tab_history[1] : "+tab_history[1]);
   $(document).trigger("Resize_pane");
});