pgm_models.get_model = function (pgm, isFirst, p) {
	var real_pgm = ap.render_pgm;

   if (pgm_views[pgm]) {
      debug_mode.flag && console.log(pgm + " exist...");

      _.each(pgm_views[pgm].collection.models[0].attributes.elements, function (tabs, i) {
			_.each(tabs.tab, function (tab, j) {
				if (tab.variable_data) {
					debug_mode.flag && console.log(pgm + " has variable data!!");
					pgm_views[pgm].collection.models[0].attributes.elements[i].tab[j].variable_data.splice(1, pgm_views[pgm].collection.models[0].attributes.elements[i].tab[j].variable_data.length);
					// 특정한 Table 형태 구성을 위해 Dataform과 Variable Data가 따로 떨어져 있을 경우 Funtion Base Program에 이 Variable Data를 삽입하기 위해 Variable Data의 첫번째 자리는 항상 빈 오브젝트로 채우도록 수정
					// 이에 따라 Variable Data 초기화 시에서 1부터 Variable Data의 Length 만큼 초기화 함 (빈 오브젝트는 Render 시에 아무런 영향을 주지 않음)
				}
         });
      });

      pgm_views["selected_pgm"] = pgm_views[pgm];

	   if (active_base == "tab_function_base" || active_base == "tab_install_wizard") {
			for (var idx = 0; idx < pgm_views[ap.render_pgm].collection.models[0].attributes.elements[0].tab.length; idx++) {
				if (pgm_views[ap.render_pgm].collection.models[0].attributes.elements[0].tab[idx].key) {
					real_pgm = pgm_views[ap.render_pgm].collection.models[0].attributes.elements[0].tab[idx].key.split('_')[0];
					break;
				}
			}
		}

      if (active_base == "tab_maintenance" && $('#' + active_base + ' .nav-tabs-main .active').hasClass('add_func')) {
         pgm_views[pgm].render(1);
      } else if (active_base == "tab_user_guide") {
			pgm_views[pgm].render();
		} else if (((active_base == "tab_install_wizard" || active_base == "tab_function_base")) && (pgm_info[real_pgm.replace("pgm","")]) && (pgm_info[real_pgm.replace("pgm","")].auth == 0)) {
			if ((active_base == "tab_function_base") && (pgm_models[ap.active_pgm].elements.length > 1)) {
				if($('#'+ap.render_pgm).index() == 0) {
					$('#'+ap.render_pgm).append("<div class='top_button'><input type='button' class='btn-image btn_next' value=' "+langs.getText("common","btn_next")+" '><br></div>");
				} else if($('#'+ap.render_pgm).index() == pgm_models[ap.active_pgm].elements.length - 1) {
					$('#'+ap.render_pgm).append("<div class='top_button'><input type='button' class='btn-image btn_prev' value=' "+langs.getText("common","btn_prev")+" '><br></div>");
				} else {
					$('#'+ap.render_pgm).append("<div class='top_button'><input type='button' class='btn-image btn_prev' value=' "+langs.getText("common","btn_prev")+" '><input type='button' class='btn-image btn_next' value=' "+langs.getText("common","btn_next")+" '><br></div>");
				}
			}

			if ((active_base == "tab_install_wizard")) {
				if($('#'+ap.render_pgm).index() == 0) {
					$('#'+ap.render_pgm).append("<div class='button'><input type='button' class='btn_next' value=' "+langs.getText("common","btn_next")+" '><br></div>");
				} else if($('#'+ap.render_pgm).index() == (info.NO_OF_INSTALL_WIZARD_STEP - 1)) {
					$('#'+ap.render_pgm).append("<div class='button'><input type='button' class='btn_prev' value=' "+langs.getText("common","btn_prev")+" '><input type='button' class='btn_finish auth_write' value=' "+langs.getText("common","btn_finish")+" '><br></div>");
				} else {
					$('#'+ap.render_pgm).append("<div class='button'><input type='button' class='btn_prev' value=' "+langs.getText("common","btn_prev")+" '><input type='button' class='btn_next' value=' "+langs.getText("common","btn_next")+" '><br></div>");
				}

				if (ap.render_pgm == "iw009") {
					$('.loadingPane').hide();
				}
			}

			$('#'+ap.render_pgm).append("<div class='alert_unauth'>"+langs.getText("error_msg","alert_unauth")+"</div>");

			$(document).trigger("Resize_pane");
      } else {
         hidden_flags[pgm] = false;

         if (isFirst) {
            _.each(pgm_views[pgm].collection.models[0].attributes.elements, function (items) {
               _.each(items.tab, function (item) {
                  if (item.preload) {
                     hidden_flags[pgm] = true;
                  }
               }, this);
            }, this);

            if (hidden_flags[pgm]) {
               pgm_views[pgm].render();
            } else {
               if (active_base == "tab_install_wizard" || active_base == "tab_function_base") {
                  for (var idx = 0; idx < pgm_views[pgm].collection.models[0].attributes.elements[0].tab.length; idx++) {
                     if (pgm_views[pgm].collection.models[0].attributes.elements[0].tab[idx].key) {
                        sendMsg(p.main, pgm_views[pgm].collection.models[0].attributes.elements[0].tab[idx].key.split('_')[0], p.type, p.range, p.msg);
                        break;
                     }
                  }
               } else {
                  sendMsg(p.main, pgm, p.type, p.range, p.msg);
               }

               $(document).unbind("Stand_by");
               $(document).bind("Stand_by", function () {
                  pgm_views[pgm].render();
                  debug_mode.flag && console.log("this pgm : " + pgm + " render event received");
               });
            }
         } else {
            if (active_base == "tab_install_wizard" || active_base == "tab_function_base") {
               for (var idx = 0; idx < pgm_views[pgm].collection.models[0].attributes.elements[0].tab.length; idx++) {
                  if (pgm_views[pgm].collection.models[0].attributes.elements[0].tab[idx].key) {
                     sendMsg(p.main, pgm_views[pgm].collection.models[0].attributes.elements[0].tab[idx].key.split('_')[0], p.type, p.range, p.msg);
                     break;
                  }
               }
            } else {
               sendMsg(p.main, pgm, p.type, p.range, p.msg);
            }

            $(document).unbind("Stand_by");
            $(document).bind("Stand_by", function () {
               pgm_views[pgm].render();
               debug_mode.flag && console.log("this pgm : " + pgm + " render event received");
            });
         }
      }
   } else {
      require(['models/' + pgm + "_model"], function (model) {
         debug_mode.flag && console.log(pgm + " required...");
         pgm_models[pgm] = model;
         var tmp_pgm_model = $.extend(true, {}, pgm_models[pgm]);

         pgm_views[pgm] = new pgm_ModelsView(tmp_pgm_model);

         pgm_name_maps.make_map(pgm);
         pgm_key_maps.make_map(pgm);

         pgm_views["selected_pgm"] = pgm_views[pgm];

         if (pgm_views[pgm]) {
				if (active_base == "tab_function_base" || active_base == "tab_install_wizard") {
					for (var idx = 0; idx < pgm_views[ap.render_pgm].collection.models[0].attributes.elements[0].tab.length; idx++) {
						if (pgm_views[ap.render_pgm].collection.models[0].attributes.elements[0].tab[idx].key) {
							real_pgm = pgm_views[ap.render_pgm].collection.models[0].attributes.elements[0].tab[idx].key.split('_')[0];
							break;
						}
					}
				}

            if (active_base == "tab_maintenance" && $('#' + active_base + ' .nav-tabs-main .active').hasClass('add_func')) {
               pgm_views[pgm].render(1);
				} else if (active_base == "tab_user_guide") {
					pgm_views[pgm].render();
				} else if (((active_base == "tab_install_wizard" || active_base == "tab_function_base")) && (pgm_info[real_pgm.replace("pgm","")]) && (pgm_info[real_pgm.replace("pgm","")].auth == 0)) {
					if ((active_base == "tab_function_base") && (pgm_models[ap.active_pgm].elements.length > 1)) {
						if($('#'+ap.render_pgm).index() == 0) {
							$('#'+ap.render_pgm).append("<div class='top_button'><input type='button' class='btn-image btn_next' value=' "+langs.getText("common","btn_next")+" '><br></div>");
						} else if($('#'+ap.render_pgm).index() == pgm_models[ap.active_pgm].elements.length - 1) {
							$('#'+ap.render_pgm).append("<div class='top_button'><input type='button' class='btn-image btn_prev' value=' "+langs.getText("common","btn_prev")+" '><br></div>");
						} else {
							$('#'+ap.render_pgm).append("<div class='top_button'><input type='button' class='btn-image btn_prev' value=' "+langs.getText("common","btn_prev")+" '><input type='button' class='btn-image btn_next' value=' "+langs.getText("common","btn_next")+" '><br></div>");
						}
					}

					if ((active_base == "tab_install_wizard")) {
						if($('#'+ap.render_pgm).index() == 0) {
							$('#'+ap.render_pgm).append("<div class='button'><input type='button' class='btn_next' value=' "+langs.getText("common","btn_next")+" '><br></div>");
						} else if($('#'+ap.render_pgm).index() == (info.NO_OF_INSTALL_WIZARD_STEP - 1)) {
							$('#'+ap.render_pgm).append("<div class='button'><input type='button' class='btn_prev' value=' "+langs.getText("common","btn_prev")+" '><input type='button' class='btn_finish auth_write' value=' "+langs.getText("common","btn_finish")+" '><br></div>");
						} else {
							$('#'+ap.render_pgm).append("<div class='button'><input type='button' class='btn_prev' value=' "+langs.getText("common","btn_prev")+" '><input type='button' class='btn_next' value=' "+langs.getText("common","btn_next")+" '><br></div>");
						}

						if (ap.render_pgm == "iw009") {
							$('.loadingPane').hide();
						}
					}

					$('#'+ap.render_pgm).append("<div class='alert_unauth'>"+langs.getText("error_msg","alert_unauth")+"</div>");

					$(document).trigger("Resize_pane");
            } else {
               hidden_flags[pgm] = false;
               if (isFirst) {
                  _.each(pgm_views[pgm].collection.models[0].attributes.elements, function (items) {
                     _.each(items.tab, function (item) {
                        if (item.preload) {
                           hidden_flags[pgm] = true;
                        }
                     }, this);
                  }, this);

                  if (hidden_flags[pgm]) {
                     pgm_views[pgm].render();
                  } else {
                     if (active_base == "tab_install_wizard" || active_base == "tab_function_base") {
                        for (var idx = 0; idx < pgm_views[pgm].collection.models[0].attributes.elements[0].tab.length; idx++) {
                           if (pgm_views[pgm].collection.models[0].attributes.elements[0].tab[idx].key) {
                              sendMsg(p.main, pgm_views[pgm].collection.models[0].attributes.elements[0].tab[idx].key.split('_')[0], p.type, p.range, p.msg);
                              break;
                           }
                        }
                     } else {
                        sendMsg(p.main, pgm, p.type, p.range, p.msg);
                     }

                     $(document).unbind("Stand_by");
                     $(document).bind("Stand_by", function () {
                        pgm_views[pgm].render();
                        debug_mode.flag && console.log("this pgm : " + pgm + " render event received");
                     });
                  }
               } else {
                  if (active_base == "tab_install_wizard" || active_base == "tab_function_base") {
                     for (var idx = 0; idx < pgm_views[pgm].collection.models[0].attributes.elements[0].tab.length; idx++) {
                        if (pgm_views[pgm].collection.models[0].attributes.elements[0].tab[idx].key) {
                           sendMsg(p.main, pgm_views[pgm].collection.models[0].attributes.elements[0].tab[idx].key.split('_')[0], p.type, p.range, p.msg);
                           break;
                        }
                     }
                  } else {
                     sendMsg(p.main, pgm, p.type, p.range, p.msg);
                  }

                  $(document).unbind("Stand_by");
                  $(document).bind("Stand_by", function () {
                     pgm_views[pgm].render();
                     debug_mode.flag && console.log("this pgm : " + pgm + " render event received");
                  });
               }
            }
         }
      });
   }
}

var require_pgms = null;

pgm_models.get_func_model = function (func, isFirst) {
   var tmp_pgm_name = null;
   require_pgms = [];
   if (pgm_models[func]) {
      debug_mode.flag && console.log(func + " function exist...");
      make_func_model(func, isFirst);
   } else {
      var equal_flag = false;

      require(['user/' + func], function (model) {
         debug_mode.flag && console.log(func + " function required...");
         pgm_models[func] = model;

			_.each(pgm_models[func].elements, function (items) {
				_.each(items.tab, function (item) {
					if (item.key) {
						equal_flag = false;
						tmp_pgm_name = item.key.split("_", 1).toString();

						_.each(require_pgms, function (pgms) {
							if (pgms === tmp_pgm_name) {
								equal_flag = true;
							}
						});

						if (equal_flag === false) {
							require_pgms.push(tmp_pgm_name);
						}
					}
				});
         });

         _.each(require_pgms, function (pgms, i) {
            debug_mode.flag && console.log("require_pgms[" + i + "] : " + pgms);
         });

         if (require_pgms.length) {
            pgm_models.get_require_models(0, func, isFirst);
         } else {
            make_func_model(func, isFirst);
         }
      });
   }
}

pgm_models.get_require_models = function (idx, func, isFirst) {
   var pgm = require_pgms[idx];

   if (!pgm_views[pgm]) {
      require(['models/' + pgm + "_model"], function (model) {
         debug_mode.flag && console.log(pgm + " required...");

         pgm_models[pgm] = model;
         var tmp_pgm_model = $.extend(true, {}, pgm_models[pgm]);

         pgm_views[pgm] = new pgm_ModelsView(tmp_pgm_model);

         pgm_name_maps.make_map(pgm);
         pgm_key_maps.make_map(pgm);

         ++idx;
         debug_mode.flag && console.log(idx);

         if (require_pgms.length > idx) pgm_models.get_require_models(idx, func, isFirst);
         else make_func_model(func, isFirst);
      });
   } else {
      debug_mode.flag && console.log(pgm + " exist...");

      ++idx;
      debug_mode.flag && console.log(idx);

      if (require_pgms.length > idx) pgm_models.get_require_models(idx, func, isFirst);
      else make_func_model(func, isFirst);
   }
}

function make_func_model(func, isFirst) {
   var range_type = [];
   var range = [];

   if(pgm_models[func].elements.length > 1) {
		var tmp_func_model = new Object;
		var tmp_arr = new Object;
		var keys_pgm_name = "";
		var active_step_width = (60 / pgm_models[func].elements.length) * 1.5;
		var other_step_width = (60 - active_step_width) / (pgm_models[func].elements.length - 1);

		$('#'+ap.active_pgm).append("<ul class='nav nav-tabs nav-tabs-sub'></ul>");
		$('#'+ap.active_pgm).append("<div class='tab-content tab-content-sub'></div>");
		_.each(pgm_models[func].elements, function(col, i) {
			if(col.name) {
				if(i == 0) {
					$('#'+ap.active_pgm+' .nav-tabs-sub').append("<li title=\""+langs.getText("common","title_step")+" "+(i+1)+" ("+col.name+")\" style=\"width:"+active_step_width+"%; text-align:center\"><a>"+langs.getText("common","title_step")+" "+(i+1)+" ("+col.name+")</a></li>");
				} else {
					$('#'+ap.active_pgm+' .nav-tabs-sub').append("<li title=\""+langs.getText("common","title_step")+" "+(i+1)+" ("+col.name+")\" style=\"width:"+other_step_width+"%; text-align:center\"><a>"+langs.getText("common","title_step")+" "+(i+1)+" ("+col.name+")</a></li>");
				}
			} else {
				if(i == 0) {
					$('#'+ap.active_pgm+' .nav-tabs-sub').append("<li title=\""+langs.getText("common","title_step")+" "+(i+1)+"\" style=\"width:"+active_step_width+"%; text-align:center\"><a>"+langs.getText("common","title_step")+" "+(i+1)+"</a></li>");
				} else {
					$('#'+ap.active_pgm+' .nav-tabs-sub').append("<li title=\""+langs.getText("common","title_step")+" "+(i+1)+"\" style=\"width:"+other_step_width+"%; text-align:center\"><a>"+langs.getText("common","title_step")+" "+(i+1)+"</a></li>");
				}
			}
			$('#'+ap.active_pgm+' .tab-content-sub').append("<div class=\"tab-pane tab-pane-sub\" id="+ap.active_pgm+"_tab"+(i+1)+"></div>");
		});
		$('#'+ap.active_pgm+' .nav-tabs-sub li:eq(0)').addClass("active");
		$('#'+ap.active_pgm+' .tab-pane-sub:eq(0)').addClass("active");

		if (!pgm_views[ap.active_pgm+"_tab1"]) {
			_.each(pgm_models[func].elements, function(items, i) {
				ap.render_pgm = ap.active_pgm+"_tab"+(i+1);

				tmp_func_model = $.extend(true, {}, pgm_models[func]);
				tmp_arr = $.extend(true, {}, tmp_func_model.elements[i]);
				tmp_func_model.elements.splice(0, tmp_func_model.elements.length);
				tmp_func_model.elements.push(tmp_arr);
				pgm_views[ap.render_pgm] =  new pgm_ModelsView(tmp_func_model);

				_.each(pgm_views[ap.render_pgm].collection.models[0].attributes.elements[0].tab, function(item, j) {
					if(item.key) {
						keys_pgm_name = item.key.split("_",1).toString();

						debug_mode.flag && console.log("tmp_pgm_name : "+keys_pgm_name+"  item.key : "+item.key);
						if (pgm_key_maps[keys_pgm_name][item.key]) {
							pgm_views[ap.render_pgm].collection.models[0].attributes.elements[0].tab[j] = pgm_key_maps[keys_pgm_name][item.key];
						} else {
							pgm_views[ap.render_pgm].collection.models[0].attributes.elements[0].tab[j] = {};
						}	// If pgm_key_maps[keys_pgm_name][item.key] is undefined (key value is invalid), an empty object will be inserted.
					}
				});
			});
		}

		ap.render_pgm = ap.active_pgm+"_tab1";
   } else {
		if (!pgm_views[func]) {
			var keys_pgm_name = "";
			var tmp_pgm_model = $.extend(true, {}, pgm_models[func]);
			pgm_views[func] = new pgm_ModelsView(tmp_pgm_model);

			_.each(pgm_views[func].collection.models[0].attributes.elements, function (items, i) {
				_.each(items.tab, function (item, j) {
					if (item.key) {
						keys_pgm_name = item.key.split("_", 1).toString();

						debug_mode.flag && console.log("tmp_pgm_name : " + keys_pgm_name + "  item.key : " + item.key);
						if (pgm_key_maps[keys_pgm_name][item.key]) {
							pgm_views[func].collection.models[0].attributes.elements[i].tab[j] = pgm_key_maps[keys_pgm_name][item.key];
						} else {
							pgm_views[func].collection.models[0].attributes.elements[i].tab[j] = {};
						}
					}
				});
			});
		}
   }

	if (active_base == "tab_install_wizard") {
		if (ap.render_pgm == "iw006" && info.NO_OF_COLS) {
			var range = [];
			range_type[0] = "2";
			range[0] = "1-" + info.NO_OF_COLS;

			packet.setPacket(0, range_type, range, "{\"IW_STEP\":\"6\"}");
		} else if (ap.render_pgm == "iw004" && info.NO_OF_STNS) {
			var range = [];
			range_type[0] = "2";
			range[0] = "1-50";
			isFirst = false;

			packet.setPacket(0, range_type, range, "{\"IW_STEP\":\"4\"}");
		} else {
			if (0 < eval(ap.render_pgm.replace("iw","")) && eval(ap.render_pgm.replace("iw","")) <= info.NO_OF_INSTALL_WIZARD_STEP) {
				packet.setPacket(0, range_type, range, "{\"IW_STEP\":\"" + eval(ap.render_pgm.replace("iw","")) + "\"}");
			} else {
				packet.setPacket(0, range_type, range, "{}");
			}
		}
   } else {
		packet.setPacket(0, range_type, range, "{}");
   }

	pgm_models.get_model(ap.render_pgm, isFirst, packet);
}

pgm_name_maps.make_map = function (pgm) {
   var tmpobj = [];

   _.each(pgm_views[pgm].collection.models[0].attributes.elements, function (col) {
      $.map(col.tab, function (item) {
         if (item.tr) {
            _.each(item.tr, function (v) {
               if (v.name) {
                  //debug_mode.flag && console.log("v.name:"+v.name);
                  tmpobj[v.name] = v;
               }
            });
         } else if (item.contents) {
            _.each(item.contents, function (v) {
               if (v.name) {
                  //debug_mode.flag && console.log("v.name:"+v.name);
                  tmpobj[v.name] = v;
               }
            });
         } else if (item.preload) {
            _.each(item.preload, function (v) {
               if (v.name) {
                  //debug_mode.flag && console.log("v.name:"+v.name);
                  tmpobj[v.name] = v;
               }
            });
         } else if (item.struct) {
            _.each(item.struct, function (s) {
               if (s.tr) {
                  _.each(s.tr, function (v) {
                     if (v.name) {
                        tmpobj[v.name] = v;
                     }
                  });
               } else if(s.th) {
                  _.each(s.th, function (v) {
                     if (v.name) {
                        tmpobj[v.name] = v;
                     }
                  });
               }
            });
         } else if (item.table) {
            _.each(item.table, function (v) {
               if (v.name) {
                  tmpobj[v.name] = v;
               }
            });
         } else if (item.th) {
            _.each(item.th, function (v) {
               if (v.name) {
                  tmpobj[v.name] = v;
               }
            });
         }

      });
   });
   pgm_name_maps[pgm] = tmpobj;
}

pgm_key_maps.make_map = function (pgm) {
   var tmpkey = [];

   _.each(pgm_views[pgm].collection.models[0].attributes.elements, function (col) {
      $.map(col.tab, function (item) {
         if (item.key) {
            //debug_mode.flag && console.log("item.key:"+item.key);
            tmpkey[item.key] = item;
         }
      });
   });
   pgm_key_maps[pgm] = tmpkey;
}

function make_stninfo_pgm() {
	var sys_id = null;
	var brd_id = null;

	if (info.SYSTEM_ID == "iPECS eMG80" || info.SYSTEM_ID == "iPECS eMG800") {
		if (info.BOARD_ID == 2) {
			if (info.SYSTEM_ID == "iPECS eMG800") {
				sys_id = "Vertical Summit 800";
				brd_id = "Vertical Summit 800";
			} else {
				sys_id = "Vertical Summit";
				brd_id = "Vertical Summit";
			}
		} else if (info.BOARD_ID == 3) {
			if (info.SYSTEM_ID == "iPECS eMG800") {
				sys_id = "ARIA IP 800";
				brd_id = "ARIA IP 800";
			} else {
				sys_id = "ARIA IP 100";
				brd_id = "ARIA IP 100";
			}
		} else {
			if (info.NCODE == "TKM") {
				sys_id = "OptiCon eMG";
				brd_id = "OptiCon eMG";
			} else {
				sys_id = info.SYSTEM_ID;
				brd_id = "iPECS";
			}
		}
	} else {
		sys_id = info.SYSTEM_ID;
		brd_id = "iPECS";
	}

   var stninfo_contents = {
      STN_NUM: info.STN_NUM,
      BOARD_ID: brd_id,
      SYSTEM_ID: sys_id,
      APP_VERSION: (info.APP_VERSION.match(/[A-Z]-\w+-\w+-\d+.\d+.\d+-\w+/)?(langs.getText("common","info_app")+"("+info.APP_VERSION.split('-')[2][0]+info.APP_VERSION.split('-')[3]+") "+info.APP_VERSION.split('-')[2].match(/\d+/)[0][2]+info.APP_VERSION.split('-')[2].match(/\d+/)[0][3]+"/"+info.APP_VERSION.split('-')[2].match(/\d+/)[0][0]+info.APP_VERSION.split('-')[2].match(/\d+/)[0][1]):(info.APP_VERSION.match(/\w\.\w\w\w \w+\/\w+$/)?(langs.getText("common","info_app")+"("+info.APP_VERSION.match(/\w\.\w\w\w/)+") "+info.APP_VERSION.match(/\w+\/\w+$/)):"-")),
      STATION: langs.getText("common","info_stn"),
      PROGRAM: langs.getText("common","info_program"),
      VERSION: langs.getText("common","info_version")
   };
   var source = $("#stninfoTemplate").html();
   var template = Handlebars.compile(source);
   var html = template(stninfo_contents);

   $('#stninfo_chart').html("");
   $('#stninfo_chart').append(html);
}

function make_aclhelp_pgm() {
   var aclhelp_info = {
      ACLUSAGE: langs.getText("common","acl_usage"),
      ACLUSAGE_TEXT: langs.getText("p2550","aclusage_text"),
      DEFACLACT: langs.getText("common","defaclact"),
      DEFACLACT_TEXT1: langs.getText("p2550","defaclact_text1"),
      DEFACLACT_EXCEPT: langs.getText("p2550","defaclact_except"),
      DEFACLACT_EXCEPT_TEXT: langs.getText("p2550","defaclact_except_text"),
      DEFACLACT_TEXT2: langs.getText("p2550","defaclact_text2"),
      DEFACLACT_TEXT3: langs.getText("p2550","defaclact_text3"),
      DEFACLACT_TEXT4: langs.getText("p2550","defaclact_text4"),
      SORTBTN: langs.getText("p2550","sortbtn"),
      SORTBTN_TEXT: langs.getText("p2550","sortbtn_text"),
      APPLYBTN: langs.getText("p2550","applybtn"),
      APPLYBTN_TEXT: langs.getText("p2550","applybtn_text"),
      STOPBTN: langs.getText("p2550","stopbtn"),
      STOPBTN_TEXT: langs.getText("p2550","stopbtn_text"),
      CLEARBTN: langs.getText("p2550","clearbtn"),
      CLEARBTN_TEXT: langs.getText("p2550","clearbtn_text"),
      SAVEBTN: langs.getText("p2550","savebtn"),
      SAVEBTN_TEXT: langs.getText("p2550","savebtn_text"),
      ACLSET: langs.getText("p2550","aclset"),
      ACLSET1: langs.getText("p2550","aclset1"),
      ACLSET2: langs.getText("p2550","aclset2"),
      ACLSET3: langs.getText("p2550","aclset3"),
      ACLSET1_TEXT: langs.getText("p2550","aclset1_text"),
      ACLSET2_TEXT: langs.getText("p2550","aclset2_text"),
      ACLSET3_TEXT: langs.getText("p2550","aclset3_text"),
      ACLSET3_CASE1: langs.getText("p2550","aclset3_case1"),
      ACLSET3_CASE1_TEXT: langs.getText("p2550","aclset3_case1_text"),
      ACLSET3_CASE2: langs.getText("p2550","aclset3_case2"),
      ACLSET3_CASE2_TEXT: langs.getText("p2550","aclset3_case2_text")
   };
   var source = $("#aclhelpTemplate").html();
   var template = Handlebars.compile(source);
   var html = template(aclhelp_info);

   $('#' + ap.render_pgm).append(html);
}

function make_fileup_pgm(is_iw_first) {
	var iw_flag = false;

	if (active_base == "tab_install_wizard") {
		pgm_name_maps[ap.render_pgm] = {};
		iw_flag = true;
		packet.setPacket(0, [], [], "{\"IW_STEP\":\"" + eval(ap.render_pgm.replace("iw","")) + "\"}");
		sendMsg(packet.main, ap.render_pgm, packet.type, packet.range, packet.msg);
	}

   var fileup_info = {
		IS_IW: iw_flag,
		BTN_NEXT: langs.getText("common","btn_next"),
      INFO: langs.getText("p51","info"),
      ADD_FILE: langs.getText("common","sel_file"),
      AUTH: info.AUTH
   };
   var source = $("#fileuploadTemplate").html();
   var template = Handlebars.compile(source);
   var html = template(fileup_info);

	if (active_base == "tab_install_wizard") {
		$(document).unbind("Stand_by");
		$(document).bind("Stand_by", function () {
			$('#' + ap.render_pgm).append(html);
			$('.loadingPane').hide();

			if (is_iw_first) {
				$(document).unbind("load_fileuploadpgm");
				$(document).bind("load_fileuploadpgm", function () {
					make_file_upload_pgm();
				});
			} else {
				make_file_upload_pgm();
			}
		});
   } else {
		$('#' + ap.render_pgm).append(html);
		make_file_upload_pgm();
   }
}

function make_dbfileup_pgm() {
   var dbfileup_info = {
      INFO: langs.getText("p55","info"),
      ADD_FILE: langs.getText("common","sel_file"),
      AUTH: info.AUTH
   };
   var source = $("#dbfileuploadTemplate").html();
   var template = Handlebars.compile(source);
   var html = template(dbfileup_info);

   $('#' + ap.render_pgm).append(html);

   make_file_upload_pgm();
}

function make_mlfileup_pgm() {
   var mlfileup_info = {
      INFO: langs.getText("p56","info"),
      ADD_FILE: langs.getText("common","sel_file"),
      AUTH: info.AUTH
   };
   var source = $("#mlfileuploadTemplate").html();
   var template = Handlebars.compile(source);
   var html = template(mlfileup_info);

   $('#' + ap.render_pgm).append(html);

   make_file_upload_pgm();
}

function make_vsfprmtup_pgm(p) {
	var UVM_flag = false;

	if (info.SYSTEM_ID == "UCP100" || info.SYSTEM_ID == "UCP600" || info.SYSTEM_ID == "iPECS eMG800") {
		UVM_flag = true;
	}

   pgm_name_maps[ap.render_pgm] = {
      "PPT_VER1": {value: ""},
      "PPT_VER2": {value: ""},
      "PPT_VER3": {value: ""},
      "PPT_VER4": {value: ""},
      "PPT_VER5": {value: ""},
      "PPT_VER6": {value: ""},
      "PPT_VER7": {value: ""},
      "PPT_VER8": {value: ""},
      "PPT_VER9": {value: ""},
      "PPT_VER10": {value: ""},
      "PPT_VER11": {value: ""},
      "PPT_VER12": {value: ""},
      "PPT_VER13": {value: ""},
      "PPT_VER14": {value: ""},
      "PPT_VER15": {value: ""},
      "PPT_VER16": {value: ""},
      "PPT_VER17": {value: ""},
      "PPT_VER18": {value: ""},
      "PPT_VER19": {value: ""},
      "PPT_VER20": {value: ""},
      "PRMTUP_VER_FIRST": {value: ""},
      "PRMTUP_VER_SECOND": {value: ""},
      "PRMTUP_VER_THIRD": {value: ""},
      "PRMTUP_VER_FOUTH": {value: ""},
      "PRMTUP_VER_FIFTH": {value: ""},
      "PRMTUP_VER_SIXTH": {value: ""}
   };

   sendMsg(p.main, ap.render_pgm, p.type, p.range, p.msg);

   $(document).unbind("Stand_by");
   $(document).bind("Stand_by", function () {
		var vsfprmtup_info = {
		IS_UVM: UVM_flag,
		AUTH: info.AUTH,
      PRMTUP_INFO1: langs.getText("p76","prmtup_info1"),
      PRMTUP_INFO2: langs.getText("common","info_dontusespace"),
      ADD_FILE: langs.getText("common","sel_file"),
      PRMTUP_INFO3: langs.getText("p76","prmtup_info3"),
      PRMTUP_INFO4: langs.getText("p76","prmtup_info4"),
      PRMTUP_INFO5: langs.getText("p76","prmtup_info5"),
      PRMTUP_POSITION: langs.getText("common","prmt_position"),
      PRMTUP_LANGUAGE: langs.getText("common","language"),
      PRMTUP_VERSION: langs.getText("common","info_version"),
      PPT1: langs.getText("common","opt_lang_eng")+"("+langs.getText("common","opt_ncode_usa")+")",
      PPT_VER1: pgm_name_maps[ap.render_pgm]["PPT_VER1"].value,
      PPT2: langs.getText("common","opt_lang_rus")+"("+langs.getText("common","opt_ncode_rus")+","+langs.getText("common","opt_ncode_cis")+")",
      PPT_VER2: pgm_name_maps[ap.render_pgm]["PPT_VER2"].value,
      PPT3: langs.getText("common","opt_lang_heb")+"("+langs.getText("common","opt_ncode_isr")+")",
      PPT_VER3: pgm_name_maps[ap.render_pgm]["PPT_VER3"].value,
      PPT4: langs.getText("common","opt_lang_gre")+"("+langs.getText("common","opt_ncode_grc")+")",
      PPT_VER4: pgm_name_maps[ap.render_pgm]["PPT_VER4"].value,
      PPT5: langs.getText("common","opt_lang_fre")+"("+langs.getText("common","opt_ncode_fra")+")",
      PPT_VER5: pgm_name_maps[ap.render_pgm]["PPT_VER5"].value,
      PPT6: langs.getText("common","opt_lang_spa")+"("+langs.getText("common","opt_ncode_esp")+")",
      PPT_VER6: pgm_name_maps[ap.render_pgm]["PPT_VER6"].value,
      PPT7: langs.getText("common","opt_lang_ita")+"("+langs.getText("common","opt_ncode_ita")+")",
      PPT_VER7: pgm_name_maps[ap.render_pgm]["PPT_VER7"].value,
      PPT8: langs.getText("common","opt_lang_dan")+"("+langs.getText("common","opt_ncode_dnk")+")",
      PPT_VER8: pgm_name_maps[ap.render_pgm]["PPT_VER8"].value,
      PPT9: langs.getText("common","opt_lang_swe")+"("+langs.getText("common","opt_ncode_swe")+")",
      PPT_VER9: pgm_name_maps[ap.render_pgm]["PPT_VER9"].value,
      PPT10: langs.getText("common","opt_lang_nor")+"("+langs.getText("common","opt_ncode_nor")+")",
      PPT_VER10: pgm_name_maps[ap.render_pgm]["PPT_VER10"].value,
      PPT11: langs.getText("common","opt_lang_pol")+"("+langs.getText("common","opt_ncode_pol")+")",
      PPT_VER11: pgm_name_maps[ap.render_pgm]["PPT_VER11"].value,
      PPT12: langs.getText("common","opt_lang_ger")+"("+langs.getText("common","opt_ncode_deu")+")",
      PPT_VER12: pgm_name_maps[ap.render_pgm]["PPT_VER12"].value,
      PPT13: langs.getText("common","opt_lang_eng")+"("+langs.getText("common","opt_ncode_aus")+")",
      PPT_VER13: pgm_name_maps[ap.render_pgm]["PPT_VER13"].value,
      PPT14: langs.getText("common","opt_lang_kor")+"("+langs.getText("common","opt_ncode_kor")+")",
      PPT_VER14: pgm_name_maps[ap.render_pgm]["PPT_VER14"].value,
      PPT15: langs.getText("common","opt_lang_chn")+"("+langs.getText("common","opt_ncode_chn")+")",
      PPT_VER15: pgm_name_maps[ap.render_pgm]["PPT_VER15"].value,
      PPT16: langs.getText("common","opt_lang_tur")+"("+langs.getText("common","opt_ncode_tur")+")",
      PPT_VER16: pgm_name_maps[ap.render_pgm]["PPT_VER16"].value,
      PPT17: langs.getText("common","opt_lang_jpn")+"("+langs.getText("common","opt_ncode_jpn")+")",
      PPT_VER17: pgm_name_maps[ap.render_pgm]["PPT_VER17"].value,
      PPT18: langs.getText("common","opt_lang_tha")+"("+langs.getText("common","opt_ncode_tha")+")",
      PPT_VER18: pgm_name_maps[ap.render_pgm]["PPT_VER18"].value,
      PPT19: langs.getText("common","opt_lang_arab")+"("+langs.getText("common","opt_ncode_jor")+")",
      PPT_VER19: pgm_name_maps[ap.render_pgm]["PPT_VER19"].value,
      PPT20: langs.getText("common","opt_lang_por")+"("+langs.getText("common","opt_ncode_por")+")",
      PPT_VER20: pgm_name_maps[ap.render_pgm]["PPT_VER20"].value,
      PRMTUP_FIRST: langs.getText("common","first"),
      PRMTUP_VER_FIRST: pgm_name_maps[ap.render_pgm]["PRMTUP_VER_FIRST"].value,
      PRMTUP_SECOND: langs.getText("common","second"),
      PRMTUP_VER_SECOND: pgm_name_maps[ap.render_pgm]["PRMTUP_VER_SECOND"].value,
      PRMTUP_THIRD: langs.getText("common","third"),
      PRMTUP_VER_THIRD: pgm_name_maps[ap.render_pgm]["PRMTUP_VER_THIRD"].value,
      PRMTUP_FOURTH: langs.getText("common","fourth"),
      PRMTUP_VER_FOUTH: pgm_name_maps[ap.render_pgm]["PRMTUP_VER_FOUTH"].value,
      PRMTUP_FIFTH: langs.getText("common","fifth"),
      PRMTUP_VER_FIFTH: pgm_name_maps[ap.render_pgm]["PRMTUP_VER_FIFTH"].value,
      PRMTUP_SIXTH: langs.getText("common","sixth"),
      PRMTUP_VER_SIXTH: pgm_name_maps[ap.render_pgm]["PRMTUP_VER_SIXTH"].value,
      BTN_SELECTALL: langs.getText("common","btn_selectall"),
      BTN_DEL: langs.getText("common","btn_del")
		};

      var source = $("#VSFPromptUploadTemplate").html();
      var template = Handlebars.compile(source);
      var html = template(vsfprmtup_info);

      $('#' + ap.render_pgm).append(html);
      $('.loadingPane').hide();

      make_file_upload_pgm();

      debug_mode.flag && console.log("this pgm : " + ap.render_pgm + " render event received");
   });
}

function make_vsfindivup_pgm() {
	var UVM_flag = false;

	if (info.SYSTEM_ID == "UCP100" || info.SYSTEM_ID == "UCP600" || info.SYSTEM_ID == "iPECS eMG800") {
		UVM_flag = true;
	}

   var vsfindivup_info = {
		IS_UVM: UVM_flag,
		AUTH: info.AUTH,
      INDIVUP_INFO1: langs.getText("p77","indivup_info1"),
      INDIVUP_INFO2: langs.getText("p77","indivup_info2"),
      INDIVUP_INFO3: langs.getText("common","g711wav_info"),
      INDIVUP_INFO4: langs.getText("common","info_dontusespace"),
      INDIVUP1: langs.getText("common","opt_lang_eng")+"("+langs.getText("common","opt_ncode_usa")+")",
      INDIVUP2: langs.getText("common","opt_lang_rus")+"("+langs.getText("common","opt_ncode_rus")+","+langs.getText("common","opt_ncode_cis")+")",
      INDIVUP3: langs.getText("common","opt_lang_heb")+"("+langs.getText("common","opt_ncode_isr")+")",
      INDIVUP4: langs.getText("common","opt_lang_gre")+"("+langs.getText("common","opt_ncode_grc")+")",
      INDIVUP5: langs.getText("common","opt_lang_fre")+"("+langs.getText("common","opt_ncode_fra")+")",
      INDIVUP6: langs.getText("common","opt_lang_spa")+"("+langs.getText("common","opt_ncode_esp")+")",
      INDIVUP7: langs.getText("common","opt_lang_ita")+"("+langs.getText("common","opt_ncode_ita")+")",
      INDIVUP8: langs.getText("common","opt_lang_dan")+"("+langs.getText("common","opt_ncode_dnk")+")",
      INDIVUP9: langs.getText("common","opt_lang_swe")+"("+langs.getText("common","opt_ncode_swe")+")",
      INDIVUP10: langs.getText("common","opt_lang_nor")+"("+langs.getText("common","opt_ncode_nor")+")",
      INDIVUP11: langs.getText("common","opt_lang_pol")+"("+langs.getText("common","opt_ncode_pol")+")",
      INDIVUP12: langs.getText("common","opt_lang_ger")+"("+langs.getText("common","opt_ncode_deu")+")",
      INDIVUP13: langs.getText("common","opt_lang_eng")+"("+langs.getText("common","opt_ncode_aus")+")",
      INDIVUP14: langs.getText("common","opt_lang_kor")+"("+langs.getText("common","opt_ncode_kor")+")",
      INDIVUP15: langs.getText("common","opt_lang_chn")+"("+langs.getText("common","opt_ncode_chn")+")",
      INDIVUP16: langs.getText("common","opt_lang_tur")+"("+langs.getText("common","opt_ncode_tur")+")",
      INDIVUP17: langs.getText("common","opt_lang_jpn")+"("+langs.getText("common","opt_ncode_jpn")+")",
      INDIVUP18: langs.getText("common","opt_lang_tha")+"("+langs.getText("common","opt_ncode_tha")+")",
      INDIVUP19: langs.getText("common","opt_lang_arab")+"("+langs.getText("common","opt_ncode_jor")+")",
      INDIVUP20: langs.getText("common","opt_lang_por")+"("+langs.getText("common","opt_ncode_por")+")",
      INDIVUP_FIRST: langs.getText("common","first"),
      INDIVUP_SECOND: langs.getText("common","second"),
      INDIVUP_THIRD: langs.getText("common","third"),
      INDIVUP_FOURTH: langs.getText("common","fourth"),
      INDIVUP_FIFTH: langs.getText("common","fifth"),
      INDIVUP_SIXTH: langs.getText("common","sixth"),
      ADD_FILE: langs.getText("common","sel_file")
   };
   var source = $("#VSFPromptIndividualUploadTemplate").html();
   var template = Handlebars.compile(source);
   var html = template(vsfindivup_info);

   $('#' + ap.render_pgm).append(html);

   make_file_upload_pgm();
}

if(info.PHASE >= 2) {
	var SGINDIVUP_INFO2_UVM_NEW = " : 1.wav~202.wav";
	var SGINDIVUP_INFO2_NEW = " : 1.wav~202.wav or x_1.wav~x_202.wav (x: 1~6)";
} else {
	var SGINDIVUP_INFO2_UVM_NEW = " : 1.wav~72.wav";
	var SGINDIVUP_INFO2_NEW = " : 1.wav~72.wav or x_1.wav~x_72.wav (x: 1~6)";
}

function make_vsfsgindivup_pgm() {
	var UVM_flag = false;

	if (info.SYSTEM_ID == "UCP100" || info.SYSTEM_ID == "UCP600" || info.SYSTEM_ID == "iPECS eMG800") {
		UVM_flag = true;
	}

   var vsfsgindivup_info = {
		IS_UVM: UVM_flag,
		AUTH: info.AUTH,
      SGINDIVUP_INFO1: langs.getText("p80","sgindivup_info1"),
      SGINDIVUP_INFO2_UVM: langs.getText("p80","sgindivup_info2") + SGINDIVUP_INFO2_UVM_NEW,
      SGINDIVUP_INFO2: langs.getText("p80","sgindivup_info2") + SGINDIVUP_INFO2_NEW,
      SGINDIVUP_INFO3: langs.getText("common","g711wav_info"),
      SGINDIVUP_INFO4: langs.getText("common","info_dontusespace"),
      SGINDIVUP_FIRST: langs.getText("common","first"),
      SGINDIVUP_SECOND: langs.getText("common","second"),
      SGINDIVUP_THIRD: langs.getText("common","third"),
      SGINDIVUP_FOURTH: langs.getText("common","fourth"),
      SGINDIVUP_FIFTH: langs.getText("common","fifth"),
      SGINDIVUP_SIXTH: langs.getText("common","sixth"),
      ADD_FILE: langs.getText("common","sel_file")
   };
   var source = $("#VSFSGIndividualUploadTemplate").html();
   var template = Handlebars.compile(source);
   var html = template(vsfsgindivup_info);

   $('#' + ap.render_pgm).append(html);

   make_file_upload_pgm();
}

function make_moh_indivup_pgm() {

   var mohindivup_info = {
		AUTH: info.AUTH,
      MOHINDIVUP_INFO1: langs.getText("p782","mohindivup_info1"),
      MOHINDIVUP_INFO3: langs.getText("common","g711wav_info"),
      MOHINDIVUP_1ST: langs.getText("common","first"),
      MOHINDIVUP_2ND: langs.getText("common","second"),
      MOHINDIVUP_3RD: langs.getText("common","third"),
      MOHINDIVUP_4TH: langs.getText("common","fourth"),
      MOHINDIVUP_5TH: langs.getText("common","fifth"),
      MOHINDIVUP_6TH: langs.getText("common","sixth"),
      MOHINDIVUP_7TH: langs.getText("common","seventh"),
      MOHINDIVUP_8TH: langs.getText("common","eighth"),
      MOHINDIVUP_9TH: langs.getText("common","nineth"),
      MOHINDIVUP_10TH: langs.getText("common","tenth"),
      MOHINDIVUP_11TH: langs.getText("common","eleventh"),
      MOHINDIVUP_12TH: langs.getText("common","twelvth"),
      MOHINDIVUP_13TH: langs.getText("common","thirteenth"),
      ADD_FILE: langs.getText("common","sel_file")
   };
   var source = $("#MOHIndividualUploadTemplate").html();
   var template = Handlebars.compile(source);
   var html = template(mohindivup_info);

   $('#' + ap.render_pgm).append(html);

   make_file_upload_pgm();
}

function make_vsfsgdn_pgm(p) {
   pgm_name_maps[ap.render_pgm] = {
      "SGDN_TYPE_DA_1": {value: ""},
      "SGDN_TYPE_DA_2": {value: ""},
      "SGDN_TYPE_DA_3": {value: ""},
      "SGDN_TYPE_DA_4": {value: ""},
      "SGDN_TYPE_DA_5": {value: ""},
      "SGDN_TYPE_DA_6": {value: ""}
   };

   sendMsg(p.main, ap.render_pgm, p.type, p.range, p.msg);

   $(document).unbind("Stand_by");
   $(document).bind("Stand_by", function () {
      var vsfsgdn_info = {
         SGDN_INFO1: langs.getText("p82","sgdn_info1"),
         SGDN_TYPE1: langs.getText("p82","sgdn_type1"),
         SGDN_TYPE_DA_1: pgm_name_maps[ap.render_pgm]["SGDN_TYPE_DA_1"].value,
         SGDN_TYPE2: langs.getText("p82","sgdn_type2"),
         SGDN_TYPE_DA_2: pgm_name_maps[ap.render_pgm]["SGDN_TYPE_DA_2"].value,
         SGDN_TYPE3: langs.getText("p82","sgdn_type3"),
         SGDN_TYPE_DA_3: pgm_name_maps[ap.render_pgm]["SGDN_TYPE_DA_3"].value,
         SGDN_TYPE4: langs.getText("p82","sgdn_type4"),
         SGDN_TYPE_DA_4: pgm_name_maps[ap.render_pgm]["SGDN_TYPE_DA_4"].value,
         SGDN_TYPE5: langs.getText("p82","sgdn_type5"),
         SGDN_TYPE_DA_5: pgm_name_maps[ap.render_pgm]["SGDN_TYPE_DA_5"].value,
         SGDN_TYPE6: langs.getText("p82","sgdn_type6"),
         SGDN_TYPE_DA_6: pgm_name_maps[ap.render_pgm]["SGDN_TYPE_DA_6"].value,
         SGDN_INFO2: langs.getText("common","info_dontusespace"),
         BTN_DOWN: langs.getText("common","download")
      };
      var source = $("#VSFSGDownloadTemplate").html();
      var template = Handlebars.compile(source);
      var html = template(vsfsgdn_info);

      $('#' + ap.render_pgm).append(html);
      $('.loadingPane').hide();

      debug_mode.flag && console.log("this pgm : " + ap.render_pgm + " render event received");
   });
}

function make_vsfsgup_pgm(p) {
	var UVM_flag = false;

	if (info.SYSTEM_ID == "UCP100" || info.SYSTEM_ID == "UCP600" || info.SYSTEM_ID == "iPECS eMG800") {
		UVM_flag = true;
	}

   pgm_name_maps[ap.render_pgm] = {
      "SGUP_LTYPE_FIRST": {value: ""},
      "SGUP_LTYPE_SECOND": {value: ""},
      "SGUP_LTYPE_THIRD": {value: ""},
      "SGUP_LTYPE_FOUTH": {value: ""},
      "SGUP_LTYPE_FIFTH": {value: ""},
      "SGUP_LTYPE_SIXTH": {value: ""}
   };

   sendMsg(p.main, ap.render_pgm, p.type, p.range, p.msg);

   $(document).unbind("Stand_by");
   $(document).bind("Stand_by", function () {
      var vsfsgup_info = {
			IS_UVM: UVM_flag,
			AUTH: info.AUTH,
         SGUP_INFO1: langs.getText("p83","sgup_info1"),
         SGUP_LTYPE: langs.getText("p83","sgup_ltype"),
			SGUP_FIRST: langs.getText("common","first"),
			SGUP_LTYPE_FIRST: pgm_name_maps[ap.render_pgm]["SGUP_LTYPE_FIRST"].value,
			SGUP_SECOND: langs.getText("common","second"),
			SGUP_LTYPE_SECOND: pgm_name_maps[ap.render_pgm]["SGUP_LTYPE_SECOND"].value,
			SGUP_THIRD: langs.getText("common","third"),
			SGUP_LTYPE_THIRD: pgm_name_maps[ap.render_pgm]["SGUP_LTYPE_THIRD"].value,
			SGUP_FOURTH: langs.getText("common","fourth"),
			SGUP_LTYPE_FOUTH: pgm_name_maps[ap.render_pgm]["SGUP_LTYPE_FOUTH"].value,
			SGUP_FIFTH: langs.getText("common","fifth"),
			SGUP_LTYPE_FIFTH: pgm_name_maps[ap.render_pgm]["SGUP_LTYPE_FIFTH"].value,
			SGUP_SIXTH: langs.getText("common","sixth"),
         SGUP_LTYPE_SIXTH: pgm_name_maps[ap.render_pgm]["SGUP_LTYPE_SIXTH"].value,
         SGUP_INFO2: langs.getText("common","info_dontusespace"),
         ADD_FILE: langs.getText("common","sel_file")
      };

      var source = $("#VSFSGUploadTemplate").html();
      var template = Handlebars.compile(source);
      var html = template(vsfsgup_info);

      $('#' + ap.render_pgm).append(html);
      $('.loadingPane').hide();

      make_file_upload_pgm();

      debug_mode.flag && console.log("this pgm : " + ap.render_pgm + " render event received");
   });
}

function make_usrgrtfileup_pgm() {
   var usrgrtfileup_info = {
      INFO: langs.getText("p46","info"),
      INFO2: langs.getText("p46","info2"),
      INFO3: langs.getText("p46","info3"),
      ADD_FILE: langs.getText("common","sel_file"),
      AUTH: info.AUTH
	};

   var source = $("#usrgrtfileuploadTemplate").html();
   var template = Handlebars.compile(source);
   var html = template(usrgrtfileup_info);

   $('#' + ap.render_pgm).append(html);

   make_file_upload_pgm();
}

function make_usrgrtfiledn_pgm(p) {
   pgm_name_maps[ap.render_pgm] = {
      "FILE_EXIST": {value: ""}
   };

   sendMsg(p.main, ap.render_pgm, p.type, p.range, p.msg);

   $(document).unbind("Stand_by");
   $(document).bind("Stand_by", function () {
		var usrgrtfiledn_info = {
			FILE_EXIST: eval(pgm_name_maps[ap.render_pgm]["FILE_EXIST"].value),
			INFO: langs.getText("p47","info"),
			INFO2: langs.getText("p47","info2"),
			NO_FILE_EXIST: langs.getText("p47","no_file_exist"),
			BTN_DOWN: langs.getText("common","download")
		};

   	var source = $("#usrgrtfiledownloadTemplate").html();
		var template = Handlebars.compile(source);
		var html = template(usrgrtfiledn_info);

		$('#' + ap.render_pgm).append(html);
		$('.loadingPane').hide();
   });
}

function make_cdnfileup_pgm() {
   var cdnfileup_info = {
      INFO: langs.getText("p48","info"),
      INFO2: langs.getText("p48","info2"),
      INFO3: langs.getText("p48","info3"),
      ADD_FILE: langs.getText("common","sel_file"),
      AUTH: info.AUTH
	};

   var source = $("#cdnfileuploadTemplate").html();
   var template = Handlebars.compile(source);
   var html = template(cdnfileup_info);

   $('#' + ap.render_pgm).append(html);

   make_file_upload_pgm();
}

function make_cdnfiledn_pgm(p) {
   pgm_name_maps[ap.render_pgm] = {
      "FILE_EXIST": {value: ""}
   };

   sendMsg(p.main, ap.render_pgm, p.type, p.range, p.msg);

   $(document).unbind("Stand_by");
   $(document).bind("Stand_by", function () {
		var cdnfiledn_info = {
			FILE_EXIST: eval(pgm_name_maps[ap.render_pgm]["FILE_EXIST"].value),
			INFO: langs.getText("p49","info"),
			INFO2: langs.getText("p49","info2"),
			NO_FILE_EXIST: langs.getText("p49","no_file_exist"),
			BTN_DOWN: langs.getText("common","download")
		};

		var source = $("#cdnfiledownloadTemplate").html();
		var template = Handlebars.compile(source);
		var html = template(cdnfiledn_info);

		$('#' + ap.render_pgm).append(html);
		$('.loadingPane').hide();
   });
}

function make_hotelrecipt_pgm(p) {
   pgm_name_maps["pgm31321"] = {
      "RCPT_NUM": {
         value: ""
      },
      "RCPT_HOTELNAME": {
         value: ""
      },
      "RCPT_TEL": {
         value: ""
      },
      "RCPT_ADDR": {
         value: ""
      },
      "RCPT_HP": {
         value: ""
      },
      "RCPT_TAXNUM": {
         value: ""
      },
      "RCPT_ROOMNUM": {
         value: ""
      },
      "RCPT_GUESTNAME": {
         value: ""
      },
      "RCPT_COM": {
         value: ""
      },
      "RCPT_MADDR": {
         value: ""
      },
      "RCPT_SADDR": {
         value: ""
      },
      "RCPT_CHKIN": {
         value: ""
      },
      "RCPT_CHKOUT": {
         value: ""
      },
      "RCPT_CURUNIT": {
         value: ""
      },
      "RCPT_ROOMCH": {
         value: ""
      },
      "RCPT_ROOMTAX": {
         value: ""
      },
      "RCPT_ROOMSUM": {
         value: ""
      },
      "RCPT_CALLCH": {
         value: ""
      },
      "RCPT_CALLTAX": {
         value: ""
      },
      "RCPT_CALLSUM": {
         value: ""
      },
      "RCPT_BARCH": {
         value: ""
      },
      "RCPT_BARTAX": {
         value: ""
      },
      "RCPT_BARSUM": {
         value: ""
      },
	   "RCPT_PREPAID": {
         value: ""
      },
      "RCPT_TOTALSUM": {
         value: ""
      },
      "RCPT_DATE": {
         value: ""
      }
   };

	var hotelreceipt_popup = null;

	if (ipktsWebs.readyState == 3) {
      $('<div />').html(langs.getText("common","disconnect_alertmessage1") + "<br>" + langs.getText("common","disconnect_alertmessage2")).dialog({
         modal: true,
         closeOnEscape: false,
         title: langs.getText("common","notification"),
         open: function (event, ui) {
            $(".ui-dialog-titlebar-close").hide();
         },
         buttons: [
				{
					text: langs.getText("common","refresh"),
					click: function () {
						$(this).dialog("destroy");
						location.href = location.href.replace(/#$/, '');
					}
				},
				{
					text: langs.getText("common","cancel"),
					click: function () {
						$(this).dialog("destroy");
					}
				}
			]
      });
      return false;
   } else {
		hotelreceipt_popup = window.open("about:blank", "", "width=700, height=700, resizable=1, scrollbars=1, toolbars=0, statusbars=0, location=0, menubars=0");
   }

	sendMsg(p.main, "pgm31321", p.type, p.range, p.msg);

   $(document).unbind("Stand_by");
   $(document).bind("Stand_by", function () {
		var hotelreceipt_info = {
			RCPT_PRINT: langs.getText("common","btn_print"),
			RCPT_TITLENUM: langs.getText("p3132","simple_num"),
			RCPT_RECEIPT: langs.getText("common","receipt"),
			RCPT_TITLETEL: langs.getText("p3132","simple_tel"),
			RCPT_TITLEADDR: langs.getText("p3132","address"),
			RCPT_TITLEHP: langs.getText("p3132","homepage"),
			RCPT_TITLETAXNUM: langs.getText("p3132","tax_num"),
			RCPT_TITLEROOMNUM: langs.getText("common","room_num"),
			RCPT_TITLENAME: langs.getText("common","name"),
			RCPT_TITLECOM: langs.getText("p3132","company"),
			RCPT_TITLEMADDR: langs.getText("p3132","main_addr"),
			RCPT_TITLESADDR: langs.getText("p3132","sub_addr"),
			RCPT_TITLECHKIN: langs.getText("common","chk_in"),
			RCPT_TITLECHKOUT: langs.getText("common","chk_out"),
			RCPT_CMTHOUR: langs.getText("p3132","one_word_hour"),
			RCPT_ITEM: langs.getText("common","item"),
			RCPT_COST: langs.getText("common","cost"),
			RCPT_TAX: langs.getText("common","tax"),
			RCPT_SUM: langs.getText("common","sum"),
			RCPT_TITLEROOMCH: langs.getText("common","room_charge"),
			RCPT_TITLECALLCH: langs.getText("common","call_charge"),
			RCPT_TITLEBARCH: langs.getText("common","bar_charge"),
			RCPT_TITLEPREPAID: langs.getText("common","prepaid"),
			RCPT_TITLETOTAL: langs.getText("common","total"),
			RCPT_SIGN: langs.getText("p3132","signature"),
			RCPT_NUM: pgm_name_maps["pgm31321"]["RCPT_NUM"].value,
			RCPT_HOTELNAME: pgm_name_maps["pgm31321"]["RCPT_HOTELNAME"].value,
			RCPT_TEL: pgm_name_maps["pgm31321"]["RCPT_TEL"].value,
			RCPT_ADDR: pgm_name_maps["pgm31321"]["RCPT_ADDR"].value,
			RCPT_HP: pgm_name_maps["pgm31321"]["RCPT_HP"].value,
			RCPT_TAXNUM: pgm_name_maps["pgm31321"]["RCPT_TAXNUM"].value,
			RCPT_ROOMNUM: pgm_name_maps["pgm31321"]["RCPT_ROOMNUM"].value,
			RCPT_GUESTNAME: pgm_name_maps["pgm31321"]["RCPT_GUESTNAME"].value,
			RCPT_COM: pgm_name_maps["pgm31321"]["RCPT_COM"].value,
			RCPT_MADDR: pgm_name_maps["pgm31321"]["RCPT_MADDR"].value,
			RCPT_SADDR: pgm_name_maps["pgm31321"]["RCPT_SADDR"].value,
			RCPT_CHKIN: pgm_name_maps["pgm31321"]["RCPT_CHKIN"].value,
			RCPT_CHKOUT: pgm_name_maps["pgm31321"]["RCPT_CHKOUT"].value,
			RCPT_CURUNIT: pgm_name_maps["pgm31321"]["RCPT_CURUNIT"].value,
			RCPT_ROOMCH: pgm_name_maps["pgm31321"]["RCPT_ROOMCH"].value,
			RCPT_ROOMTAX: pgm_name_maps["pgm31321"]["RCPT_ROOMTAX"].value,
			RCPT_ROOMSUM: pgm_name_maps["pgm31321"]["RCPT_ROOMSUM"].value,
			RCPT_CALLCH: pgm_name_maps["pgm31321"]["RCPT_CALLCH"].value,
			RCPT_CALLTAX: pgm_name_maps["pgm31321"]["RCPT_CALLTAX"].value,
			RCPT_CALLSUM: pgm_name_maps["pgm31321"]["RCPT_CALLSUM"].value,
			RCPT_BARCH: pgm_name_maps["pgm31321"]["RCPT_BARCH"].value,
			RCPT_BARTAX: pgm_name_maps["pgm31321"]["RCPT_BARTAX"].value,
			RCPT_BARSUM: pgm_name_maps["pgm31321"]["RCPT_BARSUM"].value,
			RCPT_PREPAID: pgm_name_maps["pgm31321"]["RCPT_PREPAID"].value,
			RCPT_TOTALSUM: pgm_name_maps["pgm31321"]["RCPT_TOTALSUM"].value,
			RCPT_DATE: pgm_name_maps["pgm31321"]["RCPT_DATE"].value
		};

		var source = $("#hotelReceiptTemplate").html();
		var template = Handlebars.compile(source);
		var html = template(hotelreceipt_info);

		$(hotelreceipt_popup).ready(function() {
			hotelreceipt_popup.document.write(html);
		});
      $('.loadingPane').hide();

      debug_mode.flag && console.log("this pgm : pgm31321 render event received");
   });
}

function make_hotelroomch_pgm(p) {
   pgm_name_maps["pgm31322"] = {
      "ROOMCH_NUM": {
         value: ""
      },
      "ROOMCH_HOTELNAME": {
         value: ""
      },
      "ROOMCH_TEL": {
         value: ""
      },
      "ROOMCH_ADDR": {
         value: ""
      },
      "ROOMCH_HP": {
         value: ""
      },
      "ROOMCH_TAXNUM": {
         value: ""
      },
      "ROOMCH_ROOMNUM": {
         value: ""
      },
      "ROOMCH_GUESTNAME": {
         value: ""
      },
      "ROOMCH_COM": {
         value: ""
      },
      "ROOMCH_MADDR": {
         value: ""
      },
      "ROOMCH_SADDR": {
         value: ""
      },
      "ROOMCH_CHKIN": {
         value: ""
      },
      "ROOMCH_CHKOUT": {
         value: ""
      },
      "ROOMCH_CURUNIT": {
         value: ""
      },
      "ROOMCH_ROOMCH": {
         value: ""
      },
      "ROOMCH_ROOMTAX": {
         value: ""
      },
      "ROOMCH_ROOMSUM": {
         value: ""
      },
      "ROOMCH_CALLCH": {
         value: ""
      },
      "ROOMCH_CALLTAX": {
         value: ""
      },
      "ROOMCH_CALLSUM": {
         value: ""
      },
      "ROOMCH_BARCH": {
         value: ""
      },
      "ROOMCH_BARTAX": {
         value: ""
      },
      "ROOMCH_BARSUM": {
         value: ""
      },
	   "ROOMCH_PREPAID": {
         value: ""
      },
      "ROOMCH_TOTALSUM": {
         value: ""
      },
      "ROOMCH_DATE": {
         value: ""
      },
      "ROOMCH_CALLDETAIL": {
         value: ""
      },
      "ROOMCH_BARDETAIL": {
         value: ""
      },
      "ROOMCH_TOTALCALLCNT": {
         value: ""
      },
      "ROOMCH_TOTALBARCNT": {
         value: ""
      },
   };

	var hotelroomch_popup = null;

	if (ipktsWebs.readyState == 3) {
      $('<div />').html(langs.getText("common","disconnect_alertmessage1") + "<br>" + langs.getText("common","disconnect_alertmessage2")).dialog({
         modal: true,
         closeOnEscape: false,
         title: langs.getText("common","notification"),
         open: function (event, ui) {
            $(".ui-dialog-titlebar-close").hide();
         },
         buttons: [
				{
					text: langs.getText("common","refresh"),
					click: function () {
						$(this).dialog("destroy");
						location.href = location.href.replace(/#$/, '');
					}
				},
				{
					text: langs.getText("common","cancel"),
					click: function () {
						$(this).dialog("destroy");
					}
				}
			]
      });
      return false;
   } else {
		hotelroomch_popup = window.open("about:blank", "", "width=700, height=700, resizable=1, scrollbars=1, toolbars=0, statusbars=0, location=0, menubars=0");
   }

	sendMsg(p.main, "pgm31322", p.type, p.range, p.msg);

   $(document).unbind("Stand_by");
   $(document).bind("Stand_by", function () {
		var hotelroomch_info = {
			ROOMCH_PRINT: langs.getText("common","btn_print"),
			ROOMCH_TITLENUM: langs.getText("p3132","simple_num"),
			ROOMCH_RECEIPT: langs.getText("common","receipt"),
			ROOMCH_TITLETEL: langs.getText("p3132","simple_tel"),
			ROOMCH_TITLEADDR: langs.getText("p3132","address"),
			ROOMCH_TITLEHP: langs.getText("p3132","homepage"),
			ROOMCH_TITLETAXNUM: langs.getText("p3132","tax_num"),
			ROOMCH_TITLEROOMNUM: langs.getText("common","room_num"),
			ROOMCH_TITLENAME: langs.getText("common","name"),
			ROOMCH_TITLECOM: langs.getText("p3132","company"),
			ROOMCH_TITLEMADDR: langs.getText("p3132","main_addr"),
			ROOMCH_TITLESADDR: langs.getText("p3132","sub_addr"),
			ROOMCH_TITLECHKIN: langs.getText("common","chk_in"),
			ROOMCH_TITLECHKOUT: langs.getText("common","chk_out"),
			ROOMCH_CMTHOUR: langs.getText("p3132","one_word_hour"),
			ROOMCH_ITEM: langs.getText("common","item"),
			ROOMCH_COST: langs.getText("common","cost"),
			ROOMCH_TAX: langs.getText("common","tax"),
			ROOMCH_SUM: langs.getText("common","sum"),
			ROOMCH_TITLEROOMCH: langs.getText("common","room_charge"),
			ROOMCH_TITLECALLCH: langs.getText("common","call_charge"),
			ROOMCH_TITLEBARCH: langs.getText("common","bar_charge"),
			ROOMCH_TITLEPREPAID: langs.getText("common","prepaid"),
			ROOMCH_TITLETOTAL: langs.getText("common","total"),
			ROOMCH_SIGN: langs.getText("p3132","signature"),
			ROOMCH_STARTTIME: langs.getText("common","start_time"),
			ROOMCH_CO: langs.getText("common","co"),
			ROOMCH_DURATION: langs.getText("common","call_duration"),
			ROOMCH_DIALEDNUM: langs.getText("common","dialed_num"),
			ROOMCH_COUNT: langs.getText("common","count"),
			ROOMCH_REMARK: langs.getText("common","remark"),
			ROOMCH_TITLETOTALCNT: langs.getText("common","total_cnt"),
			ROOMCH_CHARGETIME: langs.getText("common","charge_time"),
			ROOMCH_CHARGESTA: langs.getText("common","charge_sta"),
			ROOMCH_NUM: pgm_name_maps["pgm31322"]["ROOMCH_NUM"].value,
			ROOMCH_HOTELNAME: pgm_name_maps["pgm31322"]["ROOMCH_HOTELNAME"].value,
			ROOMCH_TEL: pgm_name_maps["pgm31322"]["ROOMCH_TEL"].value,
			ROOMCH_ADDR: pgm_name_maps["pgm31322"]["ROOMCH_ADDR"].value,
			ROOMCH_HP: pgm_name_maps["pgm31322"]["ROOMCH_HP"].value,
			ROOMCH_TAXNUM: pgm_name_maps["pgm31322"]["ROOMCH_TAXNUM"].value,
			ROOMCH_ROOMNUM: pgm_name_maps["pgm31322"]["ROOMCH_ROOMNUM"].value,
			ROOMCH_GUESTNAME: pgm_name_maps["pgm31322"]["ROOMCH_GUESTNAME"].value,
			ROOMCH_COM: pgm_name_maps["pgm31322"]["ROOMCH_COM"].value,
			ROOMCH_MADDR: pgm_name_maps["pgm31322"]["ROOMCH_MADDR"].value,
			ROOMCH_SADDR: pgm_name_maps["pgm31322"]["ROOMCH_SADDR"].value,
			ROOMCH_CHKIN: pgm_name_maps["pgm31322"]["ROOMCH_CHKIN"].value,
			ROOMCH_CHKOUT: pgm_name_maps["pgm31322"]["ROOMCH_CHKOUT"].value,
			ROOMCH_CURUNIT: pgm_name_maps["pgm31322"]["ROOMCH_CURUNIT"].value,
			ROOMCH_ROOMCH: pgm_name_maps["pgm31322"]["ROOMCH_ROOMCH"].value,
			ROOMCH_ROOMTAX: pgm_name_maps["pgm31322"]["ROOMCH_ROOMTAX"].value,
			ROOMCH_ROOMSUM: pgm_name_maps["pgm31322"]["ROOMCH_ROOMSUM"].value,
			ROOMCH_CALLCH: pgm_name_maps["pgm31322"]["ROOMCH_CALLCH"].value,
			ROOMCH_CALLTAX: pgm_name_maps["pgm31322"]["ROOMCH_CALLTAX"].value,
			ROOMCH_CALLSUM: pgm_name_maps["pgm31322"]["ROOMCH_CALLSUM"].value,
			ROOMCH_BARCH: pgm_name_maps["pgm31322"]["ROOMCH_BARCH"].value,
			ROOMCH_BARTAX: pgm_name_maps["pgm31322"]["ROOMCH_BARTAX"].value,
			ROOMCH_BARSUM: pgm_name_maps["pgm31322"]["ROOMCH_BARSUM"].value,
			ROOMCH_PREPAID: pgm_name_maps["pgm31322"]["ROOMCH_PREPAID"].value,
			ROOMCH_TOTALSUM: pgm_name_maps["pgm31322"]["ROOMCH_TOTALSUM"].value,
			ROOMCH_DATE: pgm_name_maps["pgm31322"]["ROOMCH_DATE"].value,
			ROOMCH_CALLDETAIL: pgm_name_maps["pgm31322"]["ROOMCH_CALLDETAIL"].value,
			ROOMCH_BARDETAIL: pgm_name_maps["pgm31322"]["ROOMCH_BARDETAIL"].value,
			ROOMCH_TOTALCALLCNT: pgm_name_maps["pgm31322"]["ROOMCH_TOTALCALLCNT"].value,
			ROOMCH_TOTALBARCNT: pgm_name_maps["pgm31322"]["ROOMCH_TOTALBARCNT"].value
		};

		var source = $("#hotelRoomChTemplate").html();
		var template = Handlebars.compile(source);
		var html = template(hotelroomch_info);

		$(hotelroomch_popup).ready(function() {
			hotelroomch_popup.document.write(html);
		});
      $('.loadingPane').hide();

      debug_mode.flag && console.log("this pgm : pgm31322 render event received");
   });
}

function make_stnlabel_pgm() {
	var imagefile = "";
	var image_height = 0;
	var image_width = 0;
	var left_pos = 0;
	var top_pos = 0;
	var sec_col_pos = 0;
	var next_row_pos = 0;
	var no_of_label = 0;
	var label_max_len = 0;
	var label_size = 0;
	var no_of_cols = 2;
	var font_size = 0;

	if (info.STN_ID) {
		switch (info.STN_ID) {
			case "LIP-7004D" :
			case "LDP-7004DS" :
				imagefile = "LDP_LIP_7004.jpg";
				image_height = 46;
				image_width = 17;
				left_pos = 8;
				top_pos = 25;
				sec_col_pos = 0;
				next_row_pos = 44;
				no_of_label = 4;
				label_max_len = 8;
				label_size = 12;
				no_of_cols = 1;
				font_size = 10;
				break;
			case "LIP-7008D" :
			case "LDP-7008DS" :
				imagefile = "LDP_LIP_7008.jpg";
				image_height = 46;
				image_width = 30;
				left_pos = 8;
				top_pos = 25;
				sec_col_pos = 58;
				next_row_pos = 44;
				no_of_label = 8;
				label_max_len = 7;
				label_size = 11;
				no_of_cols = 2;
				font_size = 10;
				break;
			case "LIP-8008D" :
			case "LIP-8008E" :
				imagefile = "LIP_IP-8x15.jpg";
				image_height = 144;
				image_width = 22;
				left_pos = 9;
				top_pos = 170;
				sec_col_pos = 0;
				next_row_pos = 50;
				no_of_label = 8;
				label_max_len = 8;
				label_size = 13;
				no_of_cols = 1;
				font_size = 11;
				break;
			case "LIP-8012D" :
			case "LIP-8012E" :
				imagefile = "LIP_IP-8x20-30.jpg";
				image_height = 185;
				image_width = 23;
				left_pos = 11;
				top_pos = 22;
				sec_col_pos = 0;
				next_row_pos = 57.1;
				no_of_label = 12;
				label_max_len = 8;
				label_size = 13;
				no_of_cols = 1;
				font_size = 11;
				break;
			case "LIP-7016D" :
			case "LDP-7016D" :
				imagefile = "LDP_LIP_7016.jpg";
				image_height = 94;
				image_width = 34;
				left_pos = 8;
				top_pos = 25;
				sec_col_pos = 67;
				next_row_pos = 44;
				no_of_label = 16;
				label_max_len = 8;
				label_size = 12;
				no_of_cols = 2;
				font_size = 10;
				break;
			case "LIP-7024D" :
			case "LIP-7024LD" :
			case "LDP-7024D" :
			case "LDP-7024LD" :
				imagefile = "LDP_LIP_7024.jpg";
				image_height = 141;
				image_width = 34;
				left_pos = 8;
				top_pos = 25;
				sec_col_pos = 67;
				next_row_pos = 44;
				no_of_label = 24;
				label_max_len = 8;
				label_size = 12;
				no_of_cols = 2;
				font_size = 10;
				break;
			case "LIP-8024D" :
			case "LIP-8024E" :
				imagefile = "LIP_IP-8x20-30.jpg";
				image_height = 185;
				image_width = 23;
				left_pos = 11;
				top_pos = 22;
				sec_col_pos = 0;
				next_row_pos = 28.6;
				no_of_label = 24;
				label_max_len = 8;
				label_size = 13;
				no_of_cols = 1;
				font_size = 11;
				break;
		}
	}

	var tmp_labels = null;
	var label_loc = 0;
	var skip_flag = false;
	_.each(pgm_views[ap.render_pgm].collection.models[0].attributes.elements[0].tab, function(items, i) {
		if (items.variable_data) {
			tmp_labels = items.variable_data;

			_.each(tmp_labels, function(item, j) {
				if (skip_flag) {
					return false;
				}
				_.each(item.tr, function(tr, k) {
					if (tr.name && tr.name.match("LABEL_")) {
						label_loc = k;
						skip_flag = true;
					}
				});
			});
		}
	});

   var stnlabel_info = {
      INFO: langs.getText("ps0071","info"),
      PRINT: langs.getText("common","btn_print"),
      IMAGEFILE: imagefile
   };

   var source = $("#stnlabelTemplate").html();
   var template = Handlebars.compile(source);
   var html = template(stnlabel_info);

	var stnlabel_popup = window.open("about:blank", "", "width=600, height=800, resizable=1, scrollbars=1, toolbars=0, statusbars=0, location=0, menubars=0");

	$(stnlabel_popup).ready(function() {
		stnlabel_popup.document.write(html);
		$(stnlabel_popup.document.head).append("<title>" + langs.getText("ps0071","title") + "</title>");

		if (tmp_labels.length == 0) {
			return false;
		}

		var check_bimg = setInterval(function() {
			if($(stnlabel_popup.document).find('#BIMG').length){
				$(document).trigger("set_label");
				clearInterval(check_bimg);
			}
		}, 100);

		$(document).unbind("set_label");
		$(document).bind("set_label", function() {
			$(stnlabel_popup.document).find('#BIMG').css("height", image_height + "mm");
			$(stnlabel_popup.document).find('#BIMG').css("width", image_width + "mm");

			var lpos = left_pos;
			var tpos = top_pos;
			var tpos_sec = eval(tpos);
			var nextrowpos = next_row_pos;
			var seccolpos = sec_col_pos;
			var noofcols = no_of_cols;

			if (no_of_label) {
				for (var i=1; i<=no_of_label; i++) {
					$(stnlabel_popup.document).find('#BIMG').after("<input id='Text" + i + "' type='text' name='LABEL" + i + "' maxlength='16' size='" + label_size + "' value='" + tmp_labels[i-1].tr[label_loc].value + "' readonly='readonly' />");

					$(stnlabel_popup.document).find('#Text' + i).css("position", "absolute").css("font-size", font_size + "px");

					if(noofcols == 1) {
						$(stnlabel_popup.document).find('#Text' + i).css("left", lpos+"px").css("top", tpos+"px");
						tpos = eval(tpos + nextrowpos);
					} else {
						if (eval(i / eval(no_of_label/2)) <= 1) {
							$(stnlabel_popup.document).find('#Text' + i).css("left", lpos+"px").css("top", tpos+"px");
							tpos = eval(tpos + nextrowpos);
						} else {
							$(stnlabel_popup.document).find('#Text' + i).css("left", eval(lpos + seccolpos)+"px").css("top", tpos_sec+"px");
							tpos_sec = eval(tpos_sec + nextrowpos);
						}
					}
				}
			}

			$(stnlabel_popup.document).find('input:text').css("border-width",0).css("background-color","Transparent");
		});
	});
}

function make_licenseup_pgm(is_iw_first) {
	var iw_flag = false;

	pgm_name_maps["pgm89"] = {
		"SERIAL_NO": {value: ""}
	};

	if (active_base == "tab_install_wizard") {
		iw_flag = true;
		packet.setPacket(0, [], [], "{\"IW_STEP\":\"" + eval(ap.render_pgm.replace("iw","")) + "\"}");
	} else {
		packet.setPacket(0, [], [], "{}");
	}

	sendMsg(packet.main, "pgm89", packet.type, packet.range, packet.msg);

	$(document).unbind("Stand_by");
	$(document).bind("Stand_by", function () {
		var fileup_info = {
			IS_IW: iw_flag,
			BTN_PREV: langs.getText("common","btn_prev"),
			BTN_NEXT: langs.getText("common","btn_next"),
			INFO: langs.getText("p89","info"),
			INFO2: langs.getText("p89","info2"),
			SERIAL_NO_TXT: langs.getText("common","serial_no"),
			SERIAL_NO_VAL: pgm_name_maps["pgm89"]["SERIAL_NO"].value,
			ADD_FILE: langs.getText("common","sel_file"),
			AUTH: info.AUTH
		};

		var source = $("#licenseUploadTemplate").html();
		var template = Handlebars.compile(source);
		var html = template(fileup_info);

		$('#' + ap.render_pgm).append(html);
		$('.loadingPane').hide();

		if (is_iw_first) {
			$(document).unbind("load_fileuploadpgm");
			$(document).bind("load_fileuploadpgm", function () {
				make_file_upload_pgm();
			});
		} else {
			make_file_upload_pgm();
		}
	});
}

var devmonitor_popup = null;
$(document).on('click', '.btn_p98_monitor', function () {
	if (!devmonitor_popup || devmonitor_popup.closed) {
		var send_msg = "{\"REQ_DEVSTAT\":\"1\"}";
		var range_type = [];
		var range = [];
		var tbl_str = "";
		var tr_str = "";
		var td_str = "";
		var rt_interval_func = null;

		var source = $("#DevMonitorTemplate").html();
		var template = Handlebars.compile(source);
		var html = template();

		if (ipktsWebs.readyState == 3) {
			$('<div />').html(langs.getText("common","disconnect_alertmessage1") + "<br>" + langs.getText("common","disconnect_alertmessage2")).dialog({
				modal: true,
				closeOnEscape: false,
				title: langs.getText("common","notification"),
				open: function (event, ui) {
					$(".ui-dialog-titlebar-close").hide();
				},
				buttons: [
					{
						text: langs.getText("common","refresh"),
						click: function () {
							$(this).dialog("destroy");
							location.href = location.href.replace(/#$/, '');
						}
					},
					{
						text: langs.getText("common","cancel"),
						click: function () {
							$(this).dialog("destroy");
						}
					}
				]
			});
			return false;
		} else {
			devmonitor_popup = window.open("about:blank", "", "resizable=1, scrollbars=1, toolbars=0, statusbars=0, location=0, menubars=0");
		}

		$(devmonitor_popup).ready(function() {
			devmonitor_popup.document.write(html);
			$(devmonitor_popup.document.head).append("<title>" + langs.getText("p98","btn_monitor") + "</title>");
			$(devmonitor_popup.document.body).css("overflow","auto").css('padding','5px').css("font-family", "Arial, sans-serif, 'Helvetica Neue', Helvetica");

			function rt_dev_monitoring () {
				if (devmonitor_popup && !devmonitor_popup.closed && (ipktsWebs.readyState == 1)) {
					_.each(pgm_views["pgm98"].collection.models[0].attributes.elements, function (tabs, i) {
						_.each(tabs.tab, function (tab, j) {
							if (tab.variable_data) {
								pgm_views["pgm98"].collection.models[0].attributes.elements[i].tab[j].variable_data.splice(1, pgm_views["pgm98"].collection.models[0].attributes.elements[i].tab[j].variable_data.length);
							}
						});
					});

					debug_mode.flag && console.log(send_msg);
					range_type = [];
					range = [];
					packet.setPacket(0, range_type, range, send_msg);
					sendMsg(packet.main, "pgm9800", packet.type, packet.range, packet.msg);

					$(document).unbind("cont_msg_recieved");
					$(document).bind("cont_msg_recieved", function () {
						tbl_str = "";
						$(devmonitor_popup.document.body).find('table').remove();
						_.each(pgm_views["pgm98"].collection.models[0].attributes.elements[0].tab, function(items, i) {
							if (items.table) {
								tr_str = "";
								_.each(items.table, function(item, j) {
									if (item.label) {
										tr_str += "<th> "+item.label+" </th>";
									}
								});
								tr_str = "<tr align='center' bgcolor='#d9edf7'>"+tr_str+"</tr>";
								tbl_str += tr_str;
							}

							if (items.variable_data) {
								_.each(items.variable_data, function(item, j) {
									tr_str = "";
									if (item.tr) {
										_.each(item.tr, function(td, k) {
											td_str = "";
											if(td.label) {
												if(td.name) {
													td_str = td.value;
												} else {
													td_str = td.label;
												}
											} else if(td.br) {
												for(var i=0; i<td.br; i++) {
													td_str += "<br>";
												}
											}

											if(td.cont) {
												tr_str = tr_str.replace(tr_str.split("</td>")[tr_str.split("</td>").length - 2], tr_str.split("</td>")[tr_str.split("</td>").length - 2] + " " + td_str);
											} else {
												tr_str += "<td> "+td_str+" </td>";
											}
										});
										tr_str = "<tr>"+tr_str+"</tr>";
										tbl_str += tr_str;
									}
								});
							}
						});
						tbl_str = "<table class='table table-bordered'>" + tbl_str + "</table>";
						$(devmonitor_popup.document.body).append(tbl_str);
					});
				} else {
					$(document).unbind("cont_msg_recieved");
					devmonitor_popup = null;
					if (rt_interval_func) {
						clearInterval(rt_interval_func);
					}
					return false;
				}
			}

			rt_dev_monitoring();
			setTimeout(rt_dev_monitoring, 1000);
			rt_interval_func = setInterval(rt_dev_monitoring, 10000);
		});
	} else {
		devmonitor_popup.focus();
	}
});

var navbar_fixed_top_width = 0;
var table_css_idx = 0;
var bootstrap_obj = document.styleSheets[0].cssRules?document.styleSheets[0].cssRules:document.styleSheets[0].rules;

$(function () {
	$('body').css("font-family", "Arial, sans-serif, 'Helvetica Neue', Helvetica");

   $('.nav-tabs-main').bind('mousedown', function(evt) {evt.preventDefault()});	// Tab 드래그 방지

   for (var i=0; i<bootstrap_obj.length; i++) {
		if (bootstrap_obj[i].selectorText) {
			if(bootstrap_obj[i].selectorText == "table") {
				table_css_idx = i;
			}
		}
	}

	if (info.PHASE <= 2) {
		$('#mob_user_portal').parents('li').hide();
		$('#mob_user_portal').parents('li').prev('li').hide();
	}

   if ($(window).height() > 480) {
		$('#main_menu').css('visibility','hidden').show();
		if(info.PHASE >= 2.1) {
			$('#btn_to_user_portal').css('visibility','hidden').show();
		}
		$('#menu_change_language').css('visibility','hidden').show();
		$('#newlicense_status').css('visibility','hidden').show();
		$('#account_logout').css('visibility','hidden').show();

		navbar_fixed_top_width = $('a.navbar-brand').outerWidth() + 25 + $('#main_menu').outerWidth(true) + $('#menu_change_language').outerWidth(true) + $('#newlicense_status').outerWidth(true) + $('#btn_to_user_portal').outerWidth(true) + $('#account_logout').outerWidth(true) + eval($('#account_logout').css('right').replace('px', ''));

		$('#main_menu').css('visibility','').hide();
		if(info.PHASE >= 2.1) {
			$('#btn_to_user_portal').css('visibility','').hide();
		}
		$('#menu_change_language').css('visibility','').hide();
		$('#newlicense_status').css('visibility','').hide();
		$('#account_logout').css('visibility','').hide();
   }

   if (($(window).height() > 480) && ($(window).width() > navbar_fixed_top_width)) {
		$('#main_menu').css('left',$('a.navbar-brand').outerWidth() + 25).show();
		$('#main_menu').width($('#menu_admin').outerWidth(true) + $('#menu_mnt').outerWidth(true) + 2);
		$('#menu_change_language').css('right',$('#account_logout').outerWidth(true) + eval($('#account_logout').css('right').replace('px', ''))).show();
		$('#newlicense_status').css('right',eval($('#menu_change_language').css('right').replace('px', '')) + $('#menu_change_language').outerWidth(true)).show();
		if(info.PHASE >= 2.1) {
			$('#btn_to_user_portal').css('right',eval($('#menu_change_language').css('right').replace('px', '')) + $('#menu_change_language').outerWidth(true)).show();
		}
		$('#account_logout').show();

		bootstrap_obj[table_css_idx].style["min-width"] = "50%";
   } else {
		$('.navbar-fixed-bottom').hide();
		if (active_base == "tab_pgm_base" || active_base == "tab_function_base" || active_base == "tab_maintenance" || active_base == "tab_stn_base") {
			$('#list_for_moblie_web').css('max-height', $(window).height() - $('.navbar-fixed-top').height() - 20).css('max-width', $(window).width() - ($('.custom_span_menu').width() + eval($('.custom_span_menu').css('border-right-width').replace('px', ''))) + eval($('.custom_span_menu').css('margin-left').replace('px', '')));
		} else if (active_base == "tab_install_wizard") {
			$('#list_for_moblie_web').css('max-height', $(window).height() - $('.navbar-fixed-top').height() - 20).css('max-width', $(window).width());
		}
		$('#menu_for_moblie_web').addClass('open').show();

		bootstrap_obj[table_css_idx].style["min-width"] = "0";
   }

   if (active_base == "tab_pgm_base" || active_base == "tab_function_base" || active_base == "tab_maintenance" || active_base == "tab_stn_base") {
		$('#' + active_base + ' .nav-tabs-main').css('height',eval($('.nav-tabs-main').css('padding-top').replace('px', '')) + $('#' + active_base + ' .nav-tabs-main li').height() - eval($('#' + active_base + ' .nav-tabs-main').css('border-bottom-width').replace('px', '')));
      $('.row-fluid .custom_span_pgm').css('width', $(window).width() - ($('.custom_span_menu').width() + eval($('.custom_span_menu').css('border-right-width').replace('px', ''))) + eval($('.custom_span_menu').css('margin-left').replace('px', '')));
      if (($(window).height() > 480) && ($(window).width() > navbar_fixed_top_width)) {
			$('.row-fluid .custom_span_menu').css('height', $(window).height() - $('.navbar-fixed-top').height() - $('.navbar-fixed-bottom').height());
			$('.row-fluid .custom_span_pgm').css('height', $(window).height() - $('.navbar-fixed-top').height() - $('.navbar-fixed-bottom').height());
      } else {
			$('.row-fluid .custom_span_menu').css('height', $(window).height() - $('.navbar-fixed-top').height());
			$('.row-fluid .custom_span_pgm').css('height', $(window).height() - $('.navbar-fixed-top').height());
      }
      $('.row-fluid .custom_span_menu #padding_custom_span_menu').css('top',$('.navbar-fixed-top').height()).width(eval($('.custom_span_menu').css('padding-left').replace('px', ''))).height($('.custom_span_menu').outerHeight());
      $('.row-fluid .custom_span_menu .menu_blinker').css('top',($('.row-fluid .custom_span_menu').outerHeight()/2) - ($('.row-fluid .custom_span_menu .menu_blinker').outerHeight()/2));
      $('#' + active_base + ' .nav-tabs-main').css('width', $('.row-fluid .custom_span_pgm ').width() - eval($('.nav-tabs-main').css('margin-left').replace('px', '')) - eval($('.nav-tabs-main').css('margin-right').replace('px', '')) - eval($('.nav-tabs-main').css('padding-left').replace('px', '')) - eval($('.nav-tabs-main').css('padding-right').replace('px', '')));
      if (active_base == "tab_pgm_base" || active_base == "tab_function_base" || active_base == "tab_maintenance") {
			$('.row-fluid .custom_span_menu #accordion').css('width',($('.custom_span_menu').width() + eval($('.custom_span_menu').css('border-right-width').replace('px', ''))) - 20);
      } else if (active_base == "tab_stn_base") {
			$(document).bind("stn_menu_ready", function () {
				$('.row-fluid .custom_span_menu .nav-stn').css('width',($('.custom_span_menu').width() + eval($('.custom_span_menu').css('border-right-width').replace('px', ''))) - eval($('.row-fluid .custom_span_menu .nav-stn').css('padding-right').replace('px', '')) - eval($('.row-fluid .custom_span_menu .nav-stn').css('padding-left').replace('px', '')) - eval($('.row-fluid .custom_span_menu').css('padding-left').replace('px', '')));
			});
      }
   } else if (active_base == "tab_install_wizard") {
      var step_title = "";

      for (var i = 1; i <= info.NO_OF_INSTALL_WIZARD_STEP; i++) {
         if (i == 1) step_title = " " + langs.getText("common","title_step") + " " + i + " (" + langs.getText("iw_common","title_step1") + ") ";
         else if (i == 2) step_title = " " + langs.getText("common","title_step") + " " + i + " (" + langs.getText("iw_common","title_step2") + ") ";
         else if (i == 3) step_title = " " + langs.getText("common","title_step") + " " + i + " (" + langs.getText("iw_common","title_step3") + ") ";
         else if (i == 4) step_title = " " + langs.getText("common","title_step") + " " + i + " (" + langs.getText("iw_common","title_step4") + ") ";
         else if (i == 5) step_title = " " + langs.getText("common","title_step") + " " + i + " (" + langs.getText("iw_common","title_step5") + ") ";
         else if (i == 6) step_title = " " + langs.getText("common","title_step") + " " + i + " (" + langs.getText("iw_common","title_step6") + ") ";
         else if (i == 7) step_title = " " + langs.getText("common","title_step") + " " + i + " (" + langs.getText("iw_common","title_step7") + ") ";
         else if (i == 8) step_title = " " + langs.getText("common","title_step") + " " + i + " (" + langs.getText("iw_common","title_step8") + ") ";
         else if (i == 9) step_title = " " + langs.getText("common","title_step") + " " + i + " (" + langs.getText("iw_common","title_step9") + ") ";

         if (i == info.IW_STEP) {
            $('#' + active_base + ' .nav-tabs-main').append("<li class=\"active\" title=\"" + step_title + "\" style=\"width:11.1%; text-align:center;\"><a>" + step_title + "<img src='img/refresh_icon.png' class='icon_refresh' title='" + langs.getText("toolTip","tip_refreshtab") + "' /></a></li>");
            $('#' + active_base + ' .tab-content-main').append("<div id=\"iw" + String('000' + (i)).slice(-3) + "\" class=\"tab-pane tab-pane-main active\"></div>");
         } else {
            $('#' + active_base + ' .nav-tabs-main').append("<li title=\"" + step_title + "\" style=\"width:11.1%; text-align:center;\"><a>" + step_title + "</a></li>");
            $('#' + active_base + ' .tab-content-main').append("<div id=\"iw" + String('000' + (i)).slice(-3) + "\" class=\"tab-pane tab-pane-main\"></div>");
         }
      }

      $('#' + active_base + ' .nav-tabs-main').css('height',$('#' + active_base + ' .nav-tabs-main li').height() - eval($('#' + active_base + ' .nav-tabs-main').css('border-bottom-width').replace('px', '')));
      if (($(window).height() > 480) && ($(window).width() > navbar_fixed_top_width)) {
			$('.row-fluid .custom_span_iwpgm ').css('height', $(window).height() - $('.navbar-fixed-top').height() - $('.navbar-fixed-bottom').height());
      } else {
			$('.row-fluid .custom_span_iwpgm ').css('height', $(window).height() - $('.navbar-fixed-top').height());
      }

      ap.render_pgm = $('#' + active_base + ' .tab-content-main .active').attr('id');

      if (ap.render_pgm == "iw001") {
			make_fileup_pgm(true);
		} else if (ap.render_pgm == "iw007") {
			make_licenseup_pgm(true);
      } else {
			pgm_models.get_func_model(ap.render_pgm, true);
      }
	} else if (active_base == "tab_user_guide") {
      $('.row-fluid .custom_span_pgm').css('width', $(window).width() - ($('.custom_span_menu').width() + eval($('.custom_span_menu').css('border-right-width').replace('px', ''))) + eval($('.custom_span_menu').css('margin-left').replace('px', '')));
      if (($(window).height() > 480) && ($(window).width() > navbar_fixed_top_width)) {
			$('.row-fluid .custom_span_menu').css('height', $(window).height() - $('.navbar-fixed-top').height() - $('.navbar-fixed-bottom').height());
			$('.row-fluid .custom_span_pgm').css('height', $(window).height() - $('.navbar-fixed-top').height() - $('.navbar-fixed-bottom').height());
      } else {
			$('.row-fluid .custom_span_menu').css('height', $(window).height() - $('.navbar-fixed-top').height());
			$('.row-fluid .custom_span_pgm').css('height', $(window).height() - $('.navbar-fixed-top').height());
      }
      $('.row-fluid .custom_span_menu #padding_custom_span_menu').css('top',$('.navbar-fixed-top').height()).width(eval($('.custom_span_menu').css('padding-left').replace('px', ''))).height($('.custom_span_menu').outerHeight());
      $('.row-fluid .custom_span_menu .menu_blinker').css('top',($('.row-fluid .custom_span_menu').outerHeight()/2) - ($('.row-fluid .custom_span_menu .menu_blinker').outerHeight()/2));
      $('#' + active_base + ' .tab-pane-main').css('padding-top','20px');
      $('#' + active_base + ' .tab-pane-main').css('height', $('.row-fluid .custom_span_pgm ').height());
		$(document).bind("ug_menu_ready", function () {
			$('.row-fluid .custom_span_menu .nav-ug').css('width',($('.custom_span_menu').width() + eval($('.custom_span_menu').css('border-right-width').replace('px', ''))) - eval($('.row-fluid .custom_span_menu .nav-ug').css('padding-right').replace('px', '')) - eval($('.row-fluid .custom_span_menu .nav-ug').css('padding-left').replace('px', '')) - eval($('.row-fluid .custom_span_menu').css('padding-left').replace('px', '')));
		});
		$('.custom_span_menu .pgm:eq(0)').addClass('active');
		pgm_models.get_model("pgmug001", true, packet);
   }
});

$(window).resize(function () {
	if ($('#'+ap.render_pgm).scrollLeft() != 0) {
		$('#'+ap.render_pgm).scrollLeft(0);
	}

   if (($(window).height() > 480) && ($(window).width() > navbar_fixed_top_width)) {
		$('.navbar-fixed-bottom').show();
		$('#menu_for_moblie_web').hide();
		$('#menu_for_moblie_web').removeClass('open');
		$('#main_menu').css('left',$('a.navbar-brand').outerWidth() + 25).show();
		$('#main_menu').width($('#menu_admin').outerWidth(true) + $('#menu_mnt').outerWidth(true) + 10);
		$('#menu_change_language').css('right',$('#account_logout').outerWidth(true) + eval($('#account_logout').css('right').replace('px', ''))).show();
		$('#newlicense_status').css('right',eval($('#menu_change_language').css('right').replace('px', '')) + $('#menu_change_language').outerWidth(true)).show();
		if(info.PHASE >= 2.1) {
			$('#btn_to_user_portal').css('right',eval($('#menu_change_language').css('right').replace('px', '')) + $('#menu_change_language').outerWidth(true)).show();
		}
		$('#account_logout').show();

		bootstrap_obj[table_css_idx].style["min-width"] = "50%";
   } else {
		$('#main_menu').hide();
		$('#menu_change_language').hide();
		$('#menu_change_language').removeClass('open');
		$('#newlicense_status').hide();
		if(info.PHASE >= 2.1) {
			$('#btn_to_user_portal').hide();
		}
		$('#account_logout').hide();
		$('.navbar-fixed-bottom').hide();
		if (active_base == "tab_pgm_base" || active_base == "tab_function_base" || active_base == "tab_maintenance" || active_base == "tab_stn_base") {
			$('#list_for_moblie_web').css('max-height', $(window).height() - $('.navbar-fixed-top').height() - 20).css('max-width', $(window).width() - ($('.custom_span_menu').width() + eval($('.custom_span_menu').css('border-right-width').replace('px', ''))) + eval($('.custom_span_menu').css('margin-left').replace('px', '')));
		} else if (active_base == "tab_install_wizard") {
			$('#list_for_moblie_web').css('max-height', $(window).height() - $('.navbar-fixed-top').height() - 20).css('max-width', $(window).width());
		}
		$('#menu_for_moblie_web').show();

		bootstrap_obj[table_css_idx].style["min-width"] = "0";
   }

   if (active_base == "tab_pgm_base" || active_base == "tab_function_base" || active_base == "tab_maintenance" || active_base == "tab_stn_base") {
		$('#' + active_base + ' .nav-tabs-main').css('height',eval($('.nav-tabs-main').css('padding-top').replace('px', '')) + $('#' + active_base + ' .nav-tabs-main li').height() - eval($('#' + active_base + ' .nav-tabs-main').css('border-bottom-width').replace('px', '')));
      $('.row-fluid .custom_span_pgm ').css('width', $(window).width() - ($('.custom_span_menu').width() + eval($('.custom_span_menu').css('border-right-width').replace('px', ''))) + eval($('.custom_span_menu').css('margin-left').replace('px', '')));
      if (($(window).height() > 480) && ($(window).width() > navbar_fixed_top_width)) {
			$('.row-fluid .custom_span_menu').css('height', $(window).height() - $('.navbar-fixed-top').height() - $('.navbar-fixed-bottom').height());
			$('.row-fluid .custom_span_pgm').css('height', $(window).height() - $('.navbar-fixed-top').height() - $('.navbar-fixed-bottom').height());
      } else {
			$('.row-fluid .custom_span_menu').css('height', $(window).height() - $('.navbar-fixed-top').height());
			$('.row-fluid .custom_span_pgm').css('height', $(window).height() - $('.navbar-fixed-top').height());
      }
      $('.row-fluid .custom_span_menu #padding_custom_span_menu').css('top',$('.navbar-fixed-top').height()).width(eval($('.custom_span_menu').css('padding-left').replace('px', ''))).height($('.custom_span_menu').outerHeight());
      $('.row-fluid .custom_span_menu .menu_blinker').css('top',($('.row-fluid .custom_span_menu').outerHeight()/2) - ($('.row-fluid .custom_span_menu .menu_blinker').outerHeight()/2));
      $('#' + active_base + ' .nav-tabs-main').css('width', $('.row-fluid .custom_span_pgm ').width() - eval($('#' + active_base + ' .nav-tabs-main').css('margin-left').replace('px', '')) - eval($('#' + active_base + ' .nav-tabs-main').css('margin-right').replace('px', '')));
		if($('#' + active_base + ' .nav-tabs-main li').length > 5) {
			var new_scrollLeft = 0;

			for (var i=0; i<$('#'+active_base+' .nav-tabs-main .active').index(); i++) {
				new_scrollLeft += $('#' + active_base + ' .nav-tabs-main li:eq('+i+')').width();
			}
			$('#' + active_base + ' .nav-tabs-main').scrollLeft(new_scrollLeft);
		}
      $('#' + active_base + ' .tab-pane-main').css('height', $('.row-fluid .custom_span_pgm ').height() - $('#' + active_base + ' .nav-tabs-main').height() - eval($('#' + active_base + ' .nav-tabs-main').css('padding-top').replace('px', '')) - eval($('#' + active_base + ' .nav-tabs-main').css('margin-bottom').replace('px', '')) - eval($('#' + active_base + ' .tab-pane-main').css('padding-bottom').replace('px', '')));
      if((active_base == "tab_function_base") && (ap.active_pgm != "favorite_func") && $('#' + ap.active_pgm + ' .tab-pane-sub').length && $('#' + ap.active_pgm+' .nav-tabs-sub').length) {
			$('#' + ap.active_pgm + ' .tab-pane-sub').css('height', $('.row-fluid .custom_span_pgm ').height() - $('#' + active_base + ' .nav-tabs-main').height() - eval($('#' + active_base + ' .nav-tabs-main').css('padding-top').replace('px', '')) - eval($('#' + active_base + ' .nav-tabs-main').css('margin-bottom').replace('px', '')) - eval($('#' + active_base + ' .tab-pane-main').css('padding-bottom').replace('px', '')) - $('#' + ap.active_pgm+' .nav-tabs-sub').height() - eval($('#' + ap.active_pgm+' .tab-content-sub').css('margin-bottom').replace('px', '')) - eval($('#' + ap.active_pgm+' .nav-tabs-sub').css('border-bottom-width').replace('px', '')) - eval($('#' + ap.active_pgm+' .tab-content-sub').css('border-bottom-width').replace('px', '')));
      } else if ((active_base == "tab_maintenance") && $('#' + active_base + ' .nav-tabs-main .active').hasClass('add_func')) {
			$('#' + active_base + ' .tab-pane-main .col-md-3').css('height', $('.row-fluid .custom_span_pgm ').height() - $('#' + active_base + ' .nav-tabs-main').height() - eval($('#' + active_base + ' .nav-tabs-main').css('padding-top').replace('px', '')) - eval($('#' + active_base + ' .nav-tabs-main').css('margin-bottom').replace('px', '')) - eval($('#' + active_base + ' .tab-pane-main').css('padding-bottom').replace('px', '')) - eval($('#' + active_base + ' .tab-pane-main .col-md-3').css('margin-bottom').replace('px', '')));
			$('#' + active_base + ' .tab-pane-main .col-md-9').css('height', $('.row-fluid .custom_span_pgm ').height() - $('#' + active_base + ' .nav-tabs-main').height() - eval($('#' + active_base + ' .nav-tabs-main').css('padding-top').replace('px', '')) - eval($('#' + active_base + ' .nav-tabs-main').css('margin-bottom').replace('px', '')) - eval($('#' + active_base + ' .tab-pane-main').css('padding-bottom').replace('px', '')) - eval($('#' + active_base + ' .tab-pane-main .col-md-9').css('margin-bottom').replace('px', '')));
			$("#" + ap.active_pgm + "_tab .tab-pane-sub").css('height', $("#" + ap.active_pgm).height() - eval($("#" + ap.active_pgm+"_group").css('padding-top').replace('px', '')) - eval($("#" + ap.active_pgm+"_group").css('padding-bottom').replace('px', '')) - $("#" + ap.active_pgm+" .function_name").height() - eval($("#" + ap.active_pgm+" .function_name").css('padding-bottom').replace('px', '')) - eval($("#" + ap.active_pgm+" .function_name").css('margin-bottom').replace('px', '')) - $("#" + ap.active_pgm+" .nav-tabs-sub").height() - eval($("#" + ap.active_pgm+" .nav-tabs-sub").css('margin-bottom').replace('px', '')) - eval($('#' + active_base + ' .tab-pane-main .col-md-9').css('margin-bottom').replace('px', '')));
      }

      $(document).trigger("mod_tab");
   } else if (active_base == "tab_install_wizard") {
		$('#' + active_base + ' .nav-tabs-main').css('height',$('#' + active_base + ' .nav-tabs-main li').height() - eval($('#' + active_base + ' .nav-tabs-main').css('border-bottom-width').replace('px', '')));
      if (($(window).height() > 480) && ($(window).width() > navbar_fixed_top_width)) {
			$('.row-fluid .custom_span_iwpgm ').css('height', $(window).height() - $('.navbar-fixed-top').height() - $('.navbar-fixed-bottom').height());
      } else {
			$('.row-fluid .custom_span_iwpgm ').css('height', $(window).height() - $('.navbar-fixed-top').height());
      }
      $('#' + active_base + ' .tab-pane-main').css('height', $('.row-fluid .custom_span_iwpgm ').height() - $('#' + active_base + ' .nav-tabs-main').height() - eval($('#' + active_base + ' .nav-tabs-main').css('margin-top').replace('px', '')) - eval($('#' + active_base + ' .nav-tabs-main').css('margin-bottom').replace('px', '')) - eval($('#' + active_base + ' .tab-pane-main').css('padding-bottom').replace('px', '')));
   } else if (active_base == "tab_user_guide") {
      $('.row-fluid .custom_span_pgm ').css('width', $(window).width() - ($('.custom_span_menu').width() + eval($('.custom_span_menu').css('border-right-width').replace('px', ''))) + eval($('.custom_span_menu').css('margin-left').replace('px', '')));
      if (($(window).height() > 480) && ($(window).width() > navbar_fixed_top_width)) {
			$('.row-fluid .custom_span_menu').css('height', $(window).height() - $('.navbar-fixed-top').height() - $('.navbar-fixed-bottom').height());
			$('.row-fluid .custom_span_pgm').css('height', $(window).height() - $('.navbar-fixed-top').height() - $('.navbar-fixed-bottom').height());
      } else {
			$('.row-fluid .custom_span_menu').css('height', $(window).height() - $('.navbar-fixed-top').height());
			$('.row-fluid .custom_span_pgm').css('height', $(window).height() - $('.navbar-fixed-top').height());
      }
      $('.row-fluid .custom_span_menu #padding_custom_span_menu').css('top',$('.navbar-fixed-top').height()).width(eval($('.custom_span_menu').css('padding-left').replace('px', ''))).height($('.custom_span_menu').outerHeight());
      $('.row-fluid .custom_span_menu .menu_blinker').css('top',($('.row-fluid .custom_span_menu').outerHeight()/2) - ($('.row-fluid .custom_span_menu .menu_blinker').outerHeight()/2));
      $('#' + active_base + ' .tab-pane-main').css('height', $('.row-fluid .custom_span_pgm ').height());
   }

   $('.loading').css('position', 'fixed').css('display', 'block').css('top', ($('.loadingPane').height() / 2) - ($('.loading').height() / 2)).css('left', ($('.loadingPane').width() / 2) - ($('.loading').width() / 2));
});

$(document).bind("Resize_pane", function () {
   if (active_base == "tab_pgm_base" || active_base == "tab_function_base" || active_base == "tab_maintenance" || active_base == "tab_stn_base") {
		$('#' + active_base + ' .nav-tabs-main').css('height',eval($('.nav-tabs-main').css('padding-top').replace('px', '')) + $('#' + active_base + ' .nav-tabs-main li').height() - eval($('#' + active_base + ' .nav-tabs-main').css('border-bottom-width').replace('px', '')));
		$('#' + active_base + ' .nav-tabs-main').css('width', $('.row-fluid .custom_span_pgm ').width() - eval($('#' + active_base + ' .nav-tabs-main').css('margin-left').replace('px', '')) - eval($('#' + active_base + ' .nav-tabs-main').css('margin-right').replace('px', '')));

		if($('#' + active_base + ' .nav-tabs-main li').length > 5) {
			var new_scrollLeft = 0;

			for (var i=0; i<$('#'+active_base+' .nav-tabs-main .active').index(); i++) {
				new_scrollLeft += $('#' + active_base + ' .nav-tabs-main li:eq('+i+')').width();
			}

			if (((new_scrollLeft + $('#' + active_base + ' .nav-tabs-main li:eq('+$('#'+active_base+' .nav-tabs-main .active').index()+')').width()) > ($('#' + active_base + ' .nav-tabs-main').scrollLeft() + $('#' + active_base + ' .nav-tabs-main').width())) || (new_scrollLeft < $('#' + active_base + ' .nav-tabs-main').scrollLeft())) {
				$('#' + active_base + ' .nav-tabs-main').scrollLeft(new_scrollLeft);
			}
		}

      $('#' + active_base + ' .tab-pane-main').css('height', $('.row-fluid .custom_span_pgm ').height() - $('#' + active_base + ' .nav-tabs-main').height() - eval($('#' + active_base + ' .nav-tabs-main').css('padding-top').replace('px', '')) - eval($('#' + active_base + ' .nav-tabs-main').css('margin-bottom').replace('px', '')) - eval($('#' + active_base + ' .tab-pane-main').css('padding-bottom').replace('px', '')));

      if((active_base == "tab_function_base") && (ap.active_pgm != "favorite_func") && $('#' + ap.active_pgm + ' .tab-pane-sub').length && $('#' + ap.active_pgm+' .nav-tabs-sub').length) {
			$('#' + ap.active_pgm + ' .tab-pane-sub').css('height', $('.row-fluid .custom_span_pgm ').height() - $('#' + active_base + ' .nav-tabs-main').height() - eval($('#' + active_base + ' .nav-tabs-main').css('padding-top').replace('px', '')) - eval($('#' + active_base + ' .nav-tabs-main').css('margin-bottom').replace('px', '')) - eval($('#' + active_base + ' .tab-pane-main').css('padding-bottom').replace('px', '')) - $('#' + ap.active_pgm+' .nav-tabs-sub').height() - eval($('#' + ap.active_pgm+' .tab-content-sub').css('margin-bottom').replace('px', '')) - eval($('#' + ap.active_pgm+' .nav-tabs-sub').css('border-bottom-width').replace('px', '')) - eval($('#' + ap.active_pgm+' .tab-content-sub').css('border-bottom-width').replace('px', '')));
		} else if ((active_base == "tab_maintenance") && $('#' + active_base + ' .nav-tabs-main .active').hasClass('add_func')) {
			$('#' + active_base + ' .tab-pane-main .col-md-3').css('height', $('.row-fluid .custom_span_pgm ').height() - $('#' + active_base + ' .nav-tabs-main').height() - eval($('#' + active_base + ' .nav-tabs-main').css('padding-top').replace('px', '')) - eval($('#' + active_base + ' .nav-tabs-main').css('margin-bottom').replace('px', '')) - eval($('#' + active_base + ' .tab-pane-main').css('padding-bottom').replace('px', '')) - eval($('#' + active_base + ' .tab-pane-main .col-md-3').css('margin-bottom').replace('px', '')));
			$('#' + active_base + ' .tab-pane-main .col-md-9').css('height', $('.row-fluid .custom_span_pgm ').height() - $('#' + active_base + ' .nav-tabs-main').height() - eval($('#' + active_base + ' .nav-tabs-main').css('padding-top').replace('px', '')) - eval($('#' + active_base + ' .nav-tabs-main').css('margin-bottom').replace('px', '')) - eval($('#' + active_base + ' .tab-pane-main').css('padding-bottom').replace('px', '')) - eval($('#' + active_base + ' .tab-pane-main .col-md-9').css('margin-bottom').replace('px', '')));
			$("#" + ap.active_pgm + "_tab .tab-pane-sub").css('height', $("#" + ap.active_pgm).height() - eval($("#" + ap.active_pgm+"_group").css('padding-top').replace('px', '')) - eval($("#" + ap.active_pgm+"_group").css('padding-bottom').replace('px', '')) - $("#" + ap.active_pgm+" .function_name").height() - eval($("#" + ap.active_pgm+" .function_name").css('padding-bottom').replace('px', '')) - eval($("#" + ap.active_pgm+" .function_name").css('margin-bottom').replace('px', '')) - $("#" + ap.active_pgm+" .nav-tabs-sub").height() - eval($("#" + ap.active_pgm+" .nav-tabs-sub").css('margin-bottom').replace('px', '')) - eval($('#' + active_base + ' .tab-pane-main .col-md-9').css('margin-bottom').replace('px', '')));
		}

      $(document).trigger("mod_tab");
   } else if (active_base == "tab_install_wizard") {
		$('#' + active_base + ' .nav-tabs-main').css('height',$('#' + active_base + ' .nav-tabs-main li').height() - eval($('#' + active_base + ' .nav-tabs-main').css('border-bottom-width').replace('px', '')));
      $('#' + active_base + ' .tab-pane-main').css('height', $('.row-fluid .custom_span_iwpgm ').height() - $('#' + active_base + ' .nav-tabs-main').height() - eval($('#' + active_base + ' .nav-tabs-main').css('margin-top').replace('px', '')) - eval($('#' + active_base + ' .nav-tabs-main').css('margin-bottom').replace('px', '')) - eval($('#' + active_base + ' .tab-pane-main').css('padding-bottom').replace('px', '')));
   } else if (active_base == "tab_user_guide") {
      $('#' + active_base + ' .tab-pane-main').css('height', $('.row-fluid .custom_span_pgm ').height());
   }
});

$(document).bind("mod_tab", function () {
	if($('#'+active_base+' .nav-tabs-main .active').index() == 0) {
		if(!$('.tab_scrlbar_main .scrl_left').hasClass('scrl_disable')) {
			$('.tab_scrlbar_main .scrl_left').addClass('scrl_disable');
		}
	} else {
		if($('.tab_scrlbar_main .scrl_left').hasClass('scrl_disable')) {
			$('.tab_scrlbar_main .scrl_left').removeClass('scrl_disable');
		}
	}

	if($('#'+active_base+' .nav-tabs-main .active').index() == ($('#'+active_base+' .nav-tabs-main li').length - 1)) {
		if(!$('.tab_scrlbar_main .scrl_right').hasClass('scrl_disable')) {
			$('.tab_scrlbar_main .scrl_right').addClass('scrl_disable');
		}
	} else {
		if($('.tab_scrlbar_main .scrl_right').hasClass('scrl_disable')) {
			$('.tab_scrlbar_main .scrl_right').removeClass('scrl_disable');
		}
	}

	if($('#'+active_base+' .nav-tabs-main li').length > 1) {
		if($('.tab_scrlbar_main .close_tab').hasClass('scrl_disable')) {
			$('.tab_scrlbar_main .close_tab').removeClass('scrl_disable');
		}
	} else {
		if(!$('.tab_scrlbar_main .close_tab').hasClass('scrl_disable')) {
			$('.tab_scrlbar_main .close_tab').addClass('scrl_disable');
		}
	}
});

$(document).on('click', '.custom_span_menu .menu_blinker', function () {
	if ($(this).hasClass('hide_menu')) {
		$(this).children('.img_hide_menu').hide();
		$(this).children('.img_show_menu').show();
		$(this).attr('title',langs.getText("toolTip","show_menu"));
		$(this).removeClass('hide_menu').addClass('show_menu');
		$('.row-fluid .custom_span_menu').outerWidth(0);
		$('.row-fluid .custom_span_pgm').css('margin','0');
	} else if ($(this).hasClass('show_menu')) {
		$(this).children('.img_hide_menu').show();
		$(this).children('.img_show_menu').hide();
		$(this).attr('title',langs.getText("toolTip","hide_menu"));
		$(this).removeClass('show_menu').addClass('hide_menu');
		$('.row-fluid .custom_span_menu').outerWidth(299);
		$('.row-fluid .custom_span_pgm').css('margin','0 0 0 280px');
	}
	$('.row-fluid .custom_span_pgm ').css('width', $(window).width() - ($('.custom_span_menu').width() + eval($('.custom_span_menu').css('border-right-width').replace('px', ''))) + eval($('.custom_span_menu').css('margin-left').replace('px', '')));
	$(document).trigger("Resize_pane");
	if($('#' + active_base + ' .nav-tabs-main li').length > 5) {
		var new_scrollLeft = 0;

		for (var i=0; i<$('#'+active_base+' .nav-tabs-main .active').index(); i++) {
			new_scrollLeft += $('#' + active_base + ' .nav-tabs-main li:eq('+i+')').width();
		}
		$('#' + active_base + ' .nav-tabs-main').scrollLeft(new_scrollLeft);
	}
});

$('#padding_custom_span_menu').on('swiperight', function () {
	if ($('.custom_span_menu .menu_blinker').hasClass('show_menu')) {
		$('.custom_span_menu .menu_blinker').children('.img_hide_menu').show();
		$('.custom_span_menu .menu_blinker').children('.img_show_menu').hide();
		$('.custom_span_menu .menu_blinker').attr('title',langs.getText("toolTip","hide_menu"));
		$('.custom_span_menu .menu_blinker').removeClass('show_menu').addClass('hide_menu');
		$('.row-fluid .custom_span_menu').outerWidth(299);
		$('.row-fluid .custom_span_pgm').css('margin','0 0 0 280px');
		$('.row-fluid .custom_span_pgm ').css('width', $(window).width() - ($('.custom_span_menu').width() + eval($('.custom_span_menu').css('border-right-width').replace('px', ''))) + eval($('.custom_span_menu').css('margin-left').replace('px', '')));
		$(document).trigger("Resize_pane");
		if($('#' + active_base + ' .nav-tabs-main li').length > 5) {
			var new_scrollLeft = 0;

			for (var i=0; i<$('#'+active_base+' .nav-tabs-main .active').index(); i++) {
				new_scrollLeft += $('#' + active_base + ' .nav-tabs-main li:eq('+i+')').width();
			}
			$('#' + active_base + ' .nav-tabs-main').scrollLeft(new_scrollLeft);
		}
	}
});

$('.custom_span_menu').on('swipeleft', function () {
	if ($('.custom_span_menu .menu_blinker').hasClass('hide_menu')) {
		$('.custom_span_menu .menu_blinker').children('.img_hide_menu').hide();
		$('.custom_span_menu .menu_blinker').children('.img_show_menu').show();
		$('.custom_span_menu .menu_blinker').attr('title',langs.getText("toolTip","show_menu"));
		$('.custom_span_menu .menu_blinker').removeClass('hide_menu').addClass('show_menu');
		$('.row-fluid .custom_span_menu').outerWidth(0);
		$('.row-fluid .custom_span_pgm').css('margin','0');
		$('.row-fluid .custom_span_pgm ').css('width', $(window).width() - ($('.custom_span_menu').width() + eval($('.custom_span_menu').css('border-right-width').replace('px', ''))) + eval($('.custom_span_menu').css('margin-left').replace('px', '')));
		$(document).trigger("Resize_pane");
		if($('#' + active_base + ' .nav-tabs-main li').length > 5) {
			var new_scrollLeft = 0;

			for (var i=0; i<$('#'+active_base+' .nav-tabs-main .active').index(); i++) {
				new_scrollLeft += $('#' + active_base + ' .nav-tabs-main li:eq('+i+')').width();
			}
			$('#' + active_base + ' .nav-tabs-main').scrollLeft(new_scrollLeft);
		}
	}
});

$(document).on('click', '.tab_scrlbar_main .scrl_left', function () {
	if(!$(this).hasClass('scrl_disable')) {
		var prev_index = $('#' + active_base + ' .nav-tabs-main .active').index();
		$('#' + active_base + ' .nav-tabs-main li').removeClass('active');
		$('#' + active_base + ' .tab-content-main .tab-pane-main').removeClass('active');
		$('#' + active_base + ' .nav-tabs-main li:eq(' + (prev_index - 1) + ')').addClass('active');
		$('#' + active_base + ' .tab-content-main .tab-pane-main:eq(' + (prev_index - 1) + ')').addClass('active');
		moveTab();

		if($('#' + active_base + ' .nav-tabs-main li').length > 5) {
			var new_scrollLeft = 0;

			for (var i=0; i<$('#'+active_base+' .nav-tabs-main .active').index(); i++) {
				new_scrollLeft += $('#' + active_base + ' .nav-tabs-main li:eq('+i+')').width();
			}

			if (new_scrollLeft < $('#' + active_base + ' .nav-tabs-main').scrollLeft()) {
				$('#' + active_base + ' .nav-tabs-main').scrollLeft(new_scrollLeft);
			}
		}

		$(document).trigger("mod_tab");
	}
});

$(document).on('click', '.tab_scrlbar_main .scrl_right', function () {
	if(!$(this).hasClass('scrl_disable')) {
		var prev_index = $('#' + active_base + ' .nav-tabs-main .active').index();
		$('#' + active_base + ' .nav-tabs-main li').removeClass('active');
		$('#' + active_base + ' .tab-content-main .tab-pane-main').removeClass('active');
		$('#' + active_base + ' .nav-tabs-main li:eq(' + (prev_index + 1) + ')').addClass('active');
		$('#' + active_base + ' .tab-content-main .tab-pane-main:eq(' + (prev_index + 1) + ')').addClass('active');
		moveTab();

		if($('#' + active_base + ' .nav-tabs-main li').length > 5) {
			var new_scrollLeft = 0;
			var new_tabWidth = $('#'+active_base+' .nav-tabs-main .active').width();

			for (var i=0; i<$('#'+active_base+' .nav-tabs-main .active').index(); i++) {
				new_scrollLeft += $('#' + active_base + ' .nav-tabs-main li:eq('+i+')').width();
			}
			if ((new_scrollLeft + $('#' + active_base + ' .nav-tabs-main li:eq('+$('#'+active_base+' .nav-tabs-main .active').index()+')').width()) > ($('#' + active_base + ' .nav-tabs-main').scrollLeft() + $('#' + active_base + ' .nav-tabs-main').width())) {
				$('#' + active_base + ' .nav-tabs-main').scrollLeft($('#' + active_base + ' .nav-tabs-main').scrollLeft() + new_tabWidth);
			}
		}

		$(document).trigger("mod_tab");
	}
});

$(document).on('click', '.tab_scrlbar_main .close_tab', function () {
	if(!$(this).hasClass('scrl_disable')) {
		$('<div />').html(langs.getText("common","confirm_alltabclose")).dialog({
			modal: true,
			closeOnEscape: false,
			width: 400,
			title: langs.getText("common","notification"),
			open: function (event, ui) {
				$(".ui-dialog-titlebar-close").hide();
			},
			buttons: [
				{
					text: langs.getText("common","alltabclose"),
					click: function () {
						$('#' + active_base + ' .nav-tabs-main li').removeClass('active');
						$('#' + active_base + ' .tab-content-main .tab-pane-main').removeClass('active');
						$('#' + active_base + ' .nav-tabs-main li:eq(0)').addClass('active');
						$('#' + active_base + ' .tab-content-main .tab-pane-main:eq(0)').addClass('active');
						moveTab();
						$('#' + active_base + ' .nav-tabs-main').scrollLeft(0);
						$('#' + active_base + ' .nav-tabs-main li:not(:eq(0))').remove();
						$('#' + active_base + ' .tab-content-main .tab-pane-main:not(:eq(0))').remove();
						if(active_base == "tab_pgm_base") {
							$('.tab_scrlbar_util .tab_list .tab_list_pgm li:not(:eq(0))').remove();
						} else if(active_base == "tab_function_base") {
							$('.tab_scrlbar_util .tab_list .tab_list_func li:not(:eq(0))').remove();
						} else if(active_base == "tab_maintenance") {
							$('.tab_scrlbar_util .tab_list .tab_list_mnt li:not(:eq(0))').remove();
						} else if(active_base == "tab_stn_base") {
							$('.tab_scrlbar_util .tab_list .tab_list_stn li:not(:eq(0))').remove();
						}

						$(document).trigger("mod_tab");
						$(this).dialog("destroy");
					}
				},
				{
					text: langs.getText("common","withoutctabclose"),
					click: function () {
						var atv_index =	$('#' + active_base + ' .nav-tabs-main .active').index();

						$('#' + active_base + ' .nav-tabs-main').scrollLeft(0);
						$('#' + active_base + ' .nav-tabs-main li:not(:eq(0)):not(.active)').remove();
						$('#' + active_base + ' .tab-content-main .tab-pane-main:not(:eq(0)):not(.active)').remove();
						if(active_base == "tab_pgm_base") {
							$('.tab_scrlbar_util .tab_list .tab_list_pgm li:not(:eq(0)):not(:eq('+(atv_index-1)+'))').remove();
						}
						$(document).trigger("mod_tab");
						$(this).dialog("destroy");
					}
				},
				{
					text: langs.getText("common","cancel"),
					click: function () {
						$(this).dialog("destroy");
					}
				}
			]
		}).dialog("open");
	}
});

$(document).on('click', '.tab_scrlbar_main .show_tab_list', function (e) {
	if($(this).hasClass('close_list')) {
		$(this).removeClass('close_list').addClass('open_list');
		$('.tab_scrlbar_util .tab_list').show();
		if(active_base == "tab_pgm_base") {
			$('.tab_scrlbar_util .tab_list .tab_list_pgm').show();
		} else if(active_base == "tab_function_base") {
			$('.tab_scrlbar_util .tab_list .tab_list_func').show();
		} else if(active_base == "tab_maintenance") {
			$('.tab_scrlbar_util .tab_list .tab_list_mnt').show();
		} else if(active_base == "tab_stn_base") {
			$('.tab_scrlbar_util .tab_list .tab_list_stn').show();
		}
	} else if($(this).hasClass('open_list')) {
		$(this).removeClass('open_list').addClass('close_list');
		$('.tab_scrlbar_util .tab_list').hide();
		$('.tab_scrlbar_util .tab_list').children().hide();
	}
	e.stopPropagation();
});

$(document).on('click', '.tab_list .tab_name', function (e) {
	var this_name = $(this).children().text();
	$('#' + active_base + ' .nav-tabs-main li').removeClass('active');

	_.each($('#' + active_base + ' .nav-tabs-main li'), function (item, i) {
		if (this_name == $('#' + active_base + ' .nav-tabs-main li:eq(' + i + ')').children().text()) {
			$('#' + active_base + ' .nav-tabs-main li:eq(' + i + ')').addClass('active');
			return false;
		}
	});
	moveTab();

	if($('#' + active_base + ' .nav-tabs-main li').length > 5) {
		var new_scrollLeft = 0;

		for (var i=0; i<$('#'+active_base+' .nav-tabs-main .active').index(); i++) {
			new_scrollLeft += $('#' + active_base + ' .nav-tabs-main li:eq('+i+')').width();
		}

		if ((new_scrollLeft >= ($('#' + active_base + ' .nav-tabs-main').scrollLeft() + $('#' + active_base + ' .nav-tabs-main').width())) || (new_scrollLeft < $('#' + active_base + ' .nav-tabs-main').scrollLeft())) {
			$('#' + active_base + ' .nav-tabs-main').scrollLeft(new_scrollLeft);
		}
	}

	$(this).removeClass('active');
	if($('.tab_scrlbar_main .show_tab_list').hasClass('open_list')) {
		$('.tab_scrlbar_main .show_tab_list').removeClass('open_list').addClass('close_list');
		$('.tab_scrlbar_util .tab_list').hide();
		$('.tab_scrlbar_util .tab_list').children().hide();
	}
	$(document).trigger("mod_tab");
});

$(document).click(function(e) {
	if($('.tab_scrlbar_main .show_tab_list').hasClass('open_list')) {
		$('.tab_scrlbar_main .show_tab_list').removeClass('open_list').addClass('close_list');
		$('.tab_scrlbar_util .tab_list').hide();
		$('.tab_scrlbar_util .tab_list').children().hide();
	}
});

function onRefresh() {
   skipConfirm_flag = true;
}

window.onbeforeunload = onRefresh;

$(document).bind("change_active_pgm", function (e, pgm) {
   if ($('#' + active_base + ' .nav-tabs-main li:eq(0)').hasClass('active')) {
      if (active_base == "tab_stn_base") {
         make_stninfo_pgm();
      } else if ((active_base == "tab_pgm_base") || (active_base == "tab_function_base")) {
         make_favorite_pgm();
      }
   } else if (!$('#' + active_base + ' .nav-tabs-main .active').hasClass("add_func")) {
      if ($("#" + ap.render_pgm + " .preload").length) {
         $("#" + ap.render_pgm + " .preload input:eq(1)").focus();
      }
   }
   debug_mode.flag && console.log("active_pgm : " + ap.active_pgm + " render_pgm : " + ap.render_pgm);
});

$("#change_language").bind("click", function (e) {
   var send_msg = "";
   var range_type = [];
   var range = [];

	if (active_base == "tab_user_guide") {
		if (e.target.id == "change_eng") {
			lang = 0;
			localStorage.setItem("lang_flag", 0);
		} else if (e.target.id == "change_local") {
			lang = 1;
			localStorage.setItem("lang_flag", 1);
		}
	} else {
		if (e.target.id == "change_eng") {
			send_msg = "{\"CH_LANG\":\"0\"}";
			packet.setPacket(1, range_type, range, send_msg);
			sendMsg(packet.main, "pgm97", packet.type, packet.range, packet.msg);
		} else if (e.target.id == "change_local") {
			send_msg = "{\"CH_LANG\":\"1\"}";
			packet.setPacket(1, range_type, range, send_msg);
			sendMsg(packet.main, "pgm97", packet.type, packet.range, packet.msg);
		}
   }
});

$("#main_menu a").bind("click", function (e) {
   $("#main_menu a").removeClass("active");
   $("#list_for_moblie_web li").removeClass("active");

   $("#menu_select_base").hide();
   $("#menu_search_pgm").hide();
   $('#search_pgm').val("");
   $("#tab_pgm_base").hide();
   $("#tab_function_base").hide();
   $("#tab_install_wizard").hide();
   $("#tab_maintenance").hide();
   $("#accordion div").remove();

   var this_target = $(this).attr("id");
   searchText = null;
   $(this).addClass("active");

   if (this_target == "menu_admin") {
		select_list = pgm_list;
		select_menuList = left_pgm_menuList;
		
		$("#list_for_moblie_web #mob_menu_admin").parent().addClass("active");
      $("#menu_select_base").show();

	   if($("#left-menu .active").attr("id") === "menu_pgm_base") {
			$("#tab_pgm_base").show();
			$("#menu_search_pgm").show();
			active_base = "tab_pgm_base";
			$('#search_pgm').attr('placeholder',langs.getText("common","left_menu_pgmsearch"));
			pgm_dir_view.render();
			pgm_menuList_view.render();
			$('.custom_span_menu').scrollTop(0);
			tab_history = pgm_tab_history;

			ap.set_active_pgm($('#' + active_base + ' .nav-tabs-main .active a').attr("href").replace("#", ""));
	   } else if($("#left-menu .active").attr("id") === "menu_function_base") {
			$("#tab_function_base").show();
			$("#menu_search_pgm").show();
			active_base = "tab_function_base";
			$('#search_pgm').attr('placeholder',langs.getText("common","left_menu_funcsearch"));

			func_dir_view.render();
			func_menuList_view.render();
			$('.custom_span_menu').scrollTop(0);

			tab_history = func_tab_history;
			if($('#'+active_base+' .tab-content-main .active .nav-tabs-sub li').length) {
				ap.active_pgm = $('#' + active_base + ' .nav-tabs-main .active a').attr("href").replace("#", "");
				ap.render_pgm = $('#'+active_base+' .tab-content-main .active .tab-content-sub .active').attr('id');
				$(document).trigger("change_active_pgm", ap.active_pgm);
			} else {
				ap.set_active_pgm($('#' + active_base + ' .nav-tabs-main .active a').attr("href").replace("#", ""));
			}
	   }
   } else if (this_target == "menu_mnt") {
		select_list = maint_list;
		select_menuList = left_maint_menuList;
		
		$("#list_for_moblie_web #mob_menu_maint").parent().addClass("active");
      $("#tab_maintenance").show();

      active_base = "tab_maintenance";
		$("#menu_search_pgm").show();
		$('#search_pgm').attr('placeholder',langs.getText("common","left_menu_maintsearch"));
      if($("#"+active_base+" .nav-tabs-main .active").hasClass("add_func")) {
			pgm_dir_view.render();
			pgm_menuList_view.render();
			$('.custom_span_menu').scrollTop(0);
      } else {
			mnt_dir_view.render();
			mnt_menuList_view.render();
			$('.custom_span_menu').scrollTop(0);

			if(!$("#pgm98").children().length) {
				var range_type = [];
				var range = [];

				packet.setPacket(0, range_type, range, "{}");
				pgm_models.get_model("pgm98", true, packet);
			}
      }
      tab_history = mnt_tab_history;

      ap.set_active_pgm($('#' + active_base + ' .nav-tabs-main .active a').attr("href").replace("#", ""));
   }

   if($('#' + active_base + ' .nav-tabs-main .active').index() != 0) {
		var sel_id = $('#' + active_base + ' .nav-tabs-main .active a').attr('href');

		_.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');
				$('.custom_span_menu .pgm:eq(' + i + ') img').show();
				return false;
			}
		});

		$('.panel-collapse .active').parents('.panel-collapse').addClass('in');
		$('.panel-collapse .active').parents('.panel-collapse')['height']('100%');
		$('.panel-collapse .active').parents('.panel-default').children('.panel-heading').addClass('active');
		$('.panel-collapse .active').parents('.panel-default').children('.panel-heading').append("<img src='img/a.png' style='float:right; margin-top:6px;' />");
	}

   $(document).trigger("Resize_pane");
});

if (!location.origin) {
  location.origin = location.protocol + "//" + location.hostname + (location.port ? ':' + location.port: '');
}

$("#list_for_moblie_web").bind("click", function (e) {
	if ((e.target.id == "mob_menu_admin") || (e.target.id == "mob_menu_maint")) {
		$("#main_menu a").removeClass("active");
		$("#list_for_moblie_web li").removeClass("active");

		$("#menu_select_base").hide();
		$("#menu_search_pgm").hide();
		$('#search_pgm').val("");
		$("#tab_pgm_base").hide();
		$("#tab_function_base").hide();
		$("#tab_install_wizard").hide();
		$("#tab_maintenance").hide();
		$("#accordion div").remove();

		if (e.target.id == "mob_menu_admin") {
			$("#main_menu #menu_admin").addClass("active");
			$("#list_for_moblie_web #mob_menu_admin").parent().addClass("active");
			$("#menu_select_base").show();

			if($("#left-menu .active").attr("id") === "menu_pgm_base") {
				$("#tab_pgm_base").show();
				$("#menu_search_pgm").show();
				active_base = "tab_pgm_base";
				$('#search_pgm').attr('placeholder',langs.getText("common","left_menu_pgmsearch"));
				pgm_dir_view.render();
				pgm_menuList_view.render();
				$('.custom_span_menu').scrollTop(0);
				tab_history = pgm_tab_history;

				ap.set_active_pgm($('#' + active_base + ' .nav-tabs-main .active a').attr("href").replace("#", ""));
			} else if($("#left-menu .active").attr("id") === "menu_function_base") {
				$("#tab_function_base").show();
				$("#menu_search_pgm").show();
				active_base = "tab_function_base";
				$('#search_pgm').attr('placeholder',langs.getText("common","left_menu_funcsearch"));

				func_dir_view.render();
				func_menuList_view.render();
				$('.custom_span_menu').scrollTop(0);

				tab_history = func_tab_history;
				if($('#'+active_base+' .tab-content-main .active .nav-tabs-sub li').length) {
					ap.active_pgm = $('#' + active_base + ' .nav-tabs-main .active a').attr("href").replace("#", "");
					ap.render_pgm = $('#'+active_base+' .tab-content-main .active .tab-content-sub .active').attr('id');
					$(document).trigger("change_active_pgm", ap.active_pgm);
				} else {
					ap.set_active_pgm($('#' + active_base + ' .nav-tabs-main .active a').attr("href").replace("#", ""));
				}
			}
		} else if (e.target.id == "mob_menu_maint") {
			$("#main_menu #menu_mnt").addClass("active");
			$("#list_for_moblie_web #mob_menu_maint").parent().addClass("active");
			$("#tab_maintenance").show();

			active_base = "tab_maintenance";
			$("#menu_search_pgm").show();
			$('#search_pgm').attr('placeholder',langs.getText("common","left_menu_maintsearch"));

			if($("#"+active_base+" .nav-tabs-main .active").hasClass("add_func")) {
				pgm_dir_view.render();
				pgm_menuList_view.render();
				$('.custom_span_menu').scrollTop(0);
			} else {
				mnt_dir_view.render();
				mnt_menuList_view.render();
				$('.custom_span_menu').scrollTop(0);

				if(!$("#pgm98").children().length) {
					var range_type = [];
					var range = [];

					packet.setPacket(0, range_type, range, "{}");
					pgm_models.get_model("pgm98", true, packet);
				}
			}
			tab_history = mnt_tab_history;

			ap.set_active_pgm($('#' + active_base + ' .nav-tabs-main .active a').attr("href").replace("#", ""));
		}

		if($('#' + active_base + ' .nav-tabs-main .active').index() != 0) {
			var sel_id = $('#' + active_base + ' .nav-tabs-main .active a').attr('href');

			_.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');
					$('.custom_span_menu .pgm:eq(' + i + ') img').show();
					return false;
				}
			});

			$('.panel-collapse .active').parents('.panel-collapse').addClass('in');
			$('.panel-collapse .active').parents('.panel-collapse')['height']('100%');
			$('.panel-collapse .active').parents('.panel-default').children('.panel-heading').addClass('active');
			$('.panel-collapse .active').parents('.panel-default').children('.panel-heading').append("<img src='img/a.png' style='float:right; margin-top:6px;' />");
		}

		$(document).trigger("Resize_pane");
	} else if (e.target.id == "mob_user_portal") {
		location.href = location.origin + "/up_index.html";
	} else if ((e.target.id == "mob_chlang_eng") || (e.target.id == "mob_chlang_local")) {
		var send_msg = "";
		var range_type = [];
		var range = [];

		if (active_base == "tab_user_guide") {
			if (e.target.id == "mob_chlang_eng") {
				lang = 0;
				localStorage.setItem("lang_flag", 0);
				location.href = location.href.replace(/#$/, '');
			} else if (e.target.id == "mob_chlang_local") {
				lang = 1;
				localStorage.setItem("lang_flag", 1);
				location.href = location.href.replace(/#$/, '');
			}
		} else {
			if (e.target.id == "mob_chlang_eng") {
				send_msg = "{\"CH_LANG\":\"0\"}";
				packet.setPacket(1, range_type, range, send_msg);
				sendMsg(packet.main, "pgm97", packet.type, packet.range, packet.msg);
			} else if (e.target.id == "mob_chlang_local") {
				send_msg = "{\"CH_LANG\":\"1\"}";
				packet.setPacket(1, range_type, range, send_msg);
				sendMsg(packet.main, "pgm97", packet.type, packet.range, packet.msg);
			}
		}
	} else if (e.target.id == "mob_logout") {
		if (active_base == "tab_user_guide") {
			debug_mode.flag && console.log("Exit");
			location.href = location.origin;
		} else {
			var send_msg = "{\"LOGOUT\":\"\"}";
			debug_mode.flag && console.log(send_msg);
			var range_type = [];
			var range = [];

			skipConfirm_flag = true;
			logout_flag = true;

			packet.setPacket(1, range_type, range, send_msg);
			sendMsg(packet.main, "pgm50", packet.type, packet.range, packet.msg);

			$(document).unbind("Log_out");
			$(document).bind("Log_out", function () {
				debug_mode.flag && console.log("Log Out");
				location.href = location.href.replace(/#$/, '');
			});
		}
	}
});

$("#left-menu").bind("click", function (e) {
   $("#left-menu a").removeClass("active");

   $("#tab_pgm_base").hide();
   $("#tab_function_base").hide();
   $("#tab_install_wizard").hide();
   $("#menu_search_pgm").hide();
   $('#search_pgm').val("");
   $("#accordion div").remove();


   if (e.target.id == "menu_pgm_base") {
      $("#left-menu a:eq(0)").addClass("active");
      $("#tab_pgm_base").show();
      active_base = "tab_pgm_base";
      $("#menu_search_pgm").show();
      $('#search_pgm').attr('placeholder',langs.getText("common","left_menu_pgmsearch"));
      pgm_dir_view.render();
      pgm_menuList_view.render();
      $('.custom_span_menu').scrollTop(0);
      tab_history = pgm_tab_history;

      ap.set_active_pgm($('#' + active_base + ' .nav-tabs-main .active a').attr("href").replace("#", ""));
   } else if (e.target.id == "menu_function_base") {
      $("#left-menu a:eq(1)").addClass("active");
      $("#tab_function_base").show();
      active_base = "tab_function_base";
      $("#menu_search_pgm").show();
      $('#search_pgm').attr('placeholder',langs.getText("common","left_menu_funcsearch"));

      func_dir_view.render();
      func_menuList_view.render();
      $('.custom_span_menu').scrollTop(0);

      tab_history = func_tab_history;
	   if($('#'+active_base+' .tab-content-main .active .nav-tabs-sub li').length) {
			ap.active_pgm = $('#' + active_base + ' .nav-tabs-main .active a').attr("href").replace("#", "");
			ap.render_pgm = $('#'+active_base+' .tab-content-main .active .tab-content-sub .active').attr('id');
			$(document).trigger("change_active_pgm", ap.active_pgm);
		} else {
			ap.set_active_pgm($('#' + active_base + ' .nav-tabs-main .active a').attr("href").replace("#", ""));
		}
   }

   if($('#' + active_base + ' .nav-tabs-main .active').index() != 0) {
		var sel_id = $('#' + active_base + ' .nav-tabs-main .active a').attr('href');

		_.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');
				$('.custom_span_menu .pgm:eq(' + i + ') img').show();
				return false;
			}
		});

		$('.panel-collapse .active').parents('.panel-collapse').addClass('in');
		$('.panel-collapse .active').parents('.panel-collapse')['height']('100%');
		$('.panel-collapse .active').parents('.panel-default').children('.panel-heading').addClass('active');
		$('.panel-collapse .active').parents('.panel-default').children('.panel-heading').append("<img src='img/a.png' style='float:right; margin-top:6px;' />");
	}

   $(document).trigger("Resize_pane");
});

$(document).on('click', '#accordion .panel-heading', function () {
   if ($(this).hasClass('active')) {
      $("#accordion .panel-heading").removeClass('active');
      $("#accordion .panel-heading").children('img').remove();
   } else {
      $("#accordion .panel-heading").removeClass('active');
      $("#accordion .panel-heading").children('img').remove();
      $(this).append("<img src='img/a.png' style='float:right; margin-top:6px;' />");
      $(this).addClass('active');
   }
});

$(document).on('click', '.btn_add_function', function () {
	$("#accordion div").remove();
	$("#menu_search_pgm").show();
	$('#search_pgm').val("");
   $('#search_pgm').attr('placeholder',langs.getText("common","left_menu_pgmsearch"));

	pgm_dir_view.render();
	pgm_menuList_view.render();
	$('.custom_span_menu').scrollTop(0);

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

   ap.active_pgm = "add_function";
   ap.render_pgm = ap.active_pgm;
   debug_mode.flag && console.log("active_pgm : " + ap.active_pgm + " render_pgm : " + ap.render_pgm);

	if(!$('#' + active_base + ' .tab-content-main #add_function').length) {
		var source = $("#add_functionTemplate").html();
		var template = Handlebars.compile(source);
		var context = {
			add_name: langs.getText("common","tab_func_funcname"),
			add_toolTip1: langs.getText("toolTip","add_func_help1"),
			add_toolTip2: langs.getText("toolTip","add_func_help2"),
			add_toolTip3: langs.getText("toolTip","add_func_help3"),
			add_toolTip4: langs.getText("toolTip","add_func_help4"),
			add_save: langs.getText("common","tab_func_savfunc")
		};
		var html = template(context);

		$('#' + active_base + ' .nav-tabs-main').append("<li title=\"" + langs.getText("common","tab_func_addfunc") + "\" class=\"add_func active\"><a href=\"#add_function\" data-toggle=\"tab\">" + langs.getText("common","tab_func_addfunc") + "<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=\"add_function\"></div>");
		$('.tab_scrlbar_util .tab_list .tab_list_mnt ul').append("<li class='tab_name'><a href='#add_function' data-toggle='tab'>" + langs.getText("common","tab_func_addfunc") + "</a></li>");
		$('#' + active_base + ' .tab-content-main #add_function').append(html);

		for (var i = 1; i <= info.NO_OF_MAX_FUNCTION_STEP; i++) {
			if (i == 1) {
				$("#" + ap.active_pgm + "_tab ul").append("<li class=\"active\" style=\"width:19.9%; text-align:center;\"><a href=\"#" + ap.active_pgm + "_tab" + i + "\" data-toggle=\"tab\">" + langs.getText("common","title_step") + " " + i + "<input size=8 class=\"form-control\" style=\"margin-left:5px; font-weight:normal\"></a></li>");
				$("#" + ap.active_pgm + "_tab .tab-content").append("<div class=\"tab-pane tab-pane-sub active\" id=\"" + ap.active_pgm + "_tab" + i + "\"></div>");
			} else {
				$("#" + ap.active_pgm + "_tab ul").append("<li style=\"width:19.9%; text-align:center;\"><a href=\"#" + ap.active_pgm + "_tab" + i + "\" data-toggle=\"tab\">" + langs.getText("common","title_step") + " " + i + "<input size=8 class=\"form-control\" style=\"margin-left:5px; font-weight:normal\"></a></li>");
				$("#" + ap.active_pgm + "_tab .tab-content").append("<div class=\"tab-pane tab-pane-sub\" id=\"" + ap.active_pgm + "_tab" + i + "\"></div>");
			}
		}
	} else {
		$('#' + active_base + ' .nav-tabs-main .add_func').addClass('active');
		$('#' + active_base + ' .tab-content-main #add_function').addClass('active');
	}

   tab_history[0] = tab_history[1];
   tab_history[1] = $('#' + active_base + ' .nav-tabs-main .active').children().text();
   //debug_mode.flag && console.log("tab_history[0] : "+tab_history[0]+"  tab_history[1] : "+tab_history[1]);

   $(document).trigger("Resize_pane");
});

$(document).on('click', '.btn_checkall', function (event) {
   if ($('#' + ap.render_pgm + ' .btn_checkall').attr('value') == langs.getText("common","btn_chkall")) {
		_.each($('#' + ap.render_pgm + ' .chk_checkall'), function(item) {
			if(!item.disabled) {
				item.checked = true;
			}
		});
      $('#' + ap.render_pgm + ' .btn_checkall').val(langs.getText("common","btn_unchkall"));
   } else {
      $('#' + ap.render_pgm + ' .chk_checkall').removeAttr('checked');
      $('#' + ap.render_pgm + ' .btn_checkall').val(langs.getText("common","btn_chkall"));
   }
});

$(document).on('click', '.btn_selectall', function (event) {
   if ($('#' + ap.render_pgm + ' .btn_selectall').attr('value') == langs.getText("common","btn_selectall")) {
		_.each($('#' + ap.render_pgm + ' .chk_selectall'), function(item) {
			if(!item.disabled) {
				item.checked = true;
			}
		});
      $('#' + ap.render_pgm + ' .btn_selectall').val(langs.getText("common","btn_unselectall"));
   } else {
      $('#' + ap.render_pgm + ' .chk_selectall').removeAttr('checked');
      $('#' + ap.render_pgm + ' .btn_selectall').val(langs.getText("common","btn_selectall"));
   }
});

$(document).on('click', '.chk_outsideCheckall', function (event) {
	if ($('#' + ap.render_pgm + ' .chk_outsideCheckall')[0].checked) {
		_.each($('#' + ap.render_pgm + ' .chk_outsideCheck'), function(item) {
			if(!item.disabled) {
				item.checked = true;
				chkall_flag = true;
			}
		});
	} else {
		$('#' + ap.render_pgm + ' .chk_outsideCheck').removeAttr('checked');
		chkall_flag = false;
	}
});

$(document).on('change', '.rtype_select', function (evt) {
	if ($(this).attr('class').match(/target\_\d/) && $("#"+ap.render_pgm+" [name=RANGE_TYPE_"+$(this).attr('class').match(/target\_\d/)[0].replace('target_','')+"]").length) {
		$("#"+ap.render_pgm+" [name=RANGE_TYPE_"+$(this).attr('class').match(/target\_\d/)[0].replace('target_','')+"]").val(parseInt($(this).val()));
	}
});

$(document).on('click', '.btn_load', function (event) {
   var tab_str = $(this).parent().parent().attr("id");

   if (active_base == "tab_function_base") {
      ap.render_pgm = tab_str;
   }

   if (sendLoadRange()) {
      $('#' + ap.render_pgm).html("");
      pgm_models.get_model(tab_str, false, packet);
   } else {
      $('#' + ap.render_pgm).html("");
      pgm_views[ap.render_pgm].render();
   }
});

$(document).on('keypress', '.preload input', function (event) {
	if (!$('#' + active_base + ' .nav-tabs-main .active').hasClass("add_func")) {
		if (event.keyCode === 13) {
			var tab_str = $(this).parent().parent().attr("id");

			if (active_base == "tab_function_base") {
				ap.render_pgm = tab_str;
			}

			if (sendLoadRange()) {
				$('#' + ap.render_pgm).html("");
				pgm_models.get_model(tab_str, false, packet);
			} else {
				$('#' + ap.render_pgm).html("");
				pgm_views[ap.render_pgm].render();
			}
		}
   }
});

function sendLoadRange() {
   var pre_msg = [];
   var dont_load = false;
   var range_type = [];
   var range_seq = [];
   var range_error = "";
   var tmp_bind_range = "";

	if ($('#' + ap.render_pgm + ' .preload .rtype_select').length) {
		_.each($('#' + ap.render_pgm + ' .preload .rtype_select'), function (item) {
			if (item.className.match(/target\_\d/) && $("#"+ap.render_pgm+" [name=RANGE_TYPE_"+item.className.match(/target\_\d/)[0].replace('target_','')+"]").length) {
				$("#"+ap.render_pgm+" [name=RANGE_TYPE_"+item.className.match(/target\_\d/)[0].replace('target_','')+"]").val(parseInt(item.value));
			}
		});
	}

   _.each($('#' + ap.render_pgm + ' .preload').children(), function (item) {
      if (item.name) {
         if (item.name.match(/^RANGE\_TYPE/)) {
            range_type.push(item.value);
         } else if (item.name.match(/^RANGE\_/)) {
				if (!item.value && $(item).attr('default_range') && ($(item).attr('default_range') != "undefined")) {
					pre_msg.push($(item).attr('default_range'));
				} else {
					pre_msg.push(item.value);
            }
            range_seq.push(item.name.replace(/^RANGE\_\d\_/, ""));
         } else if (item.name.match(/^BIND\_RANGE\_/)) {
            if (item.name.match(/^BIND\_RANGE\_END\_/)) {
					tmp_bind_range += item.value;
					pre_msg.push(tmp_bind_range);
					range_seq.push(item.name.replace(/^BIND\_RANGE\_END\_/, ""));
            } else {
					tmp_bind_range += item.value+",";
            }
         }
      }
   });

   for (var i = 0; i < pre_msg.length; i++) {
      if (!dont_load) {
         if (pre_msg[i]) {
            if (range_seq[i] == "0") {
               if ((range_type[i] == "1") && (pre_msg[i].match(/[^0-9*#]/g))) {
                  range_error = "2";
                  dont_load = true;
               } else if ((range_type[i] == "2") && (pre_msg[i].match(/[^0-9]/g))) {
                  range_error = "3";
                  dont_load = true;
               }
            } else if (range_seq[i] == "1") {
               if ((range_type[i] == "1") && (pre_msg[i].match(/[^0-9*#,\-]/g))) {
                  range_error = "2";
                  dont_load = true;
               } else if ((range_type[i] == "2") && (pre_msg[i].match(/[^0-9,\-]/g))) {
                  range_error = "3";
                  dont_load = true;
               }
               if (pre_msg[i].match(/[,\-]$/)) {
                  range_error = "14";
                  dont_load = true;
               }

               if (!dont_load) {
                  var tmp_values = pre_msg[i].split(",");

                  for (var idx = 0; idx < tmp_values.length; idx++) {
                     if (!dont_load) {
                        if (tmp_values[idx]) {
                           if (tmp_values[idx].match("-")) {
                              if (!tmp_values[idx].split("-")[0] || !tmp_values[idx].split("-")[1]) {
                                 range_error = "4";
                                 dont_load = true;
                              }
                           }
                        } else {
                           range_error = "4";
                           dont_load = true;
                        }
                     }
                  }
               }
            }
         } else {
            range_error = "1";
            dont_load = true;
         }
      }
   }

   if (!dont_load) {
      packet.setPacket(0, range_type, pre_msg, "{}");
      return true;
   } else {
      if (active_base == "tab_install_wizard" || active_base == "tab_function_base") {
         for (var idx = 0; idx < pgm_views[ap.render_pgm].collection.models[0].attributes.elements[0].tab.length; idx++) {
            if (pgm_views[ap.render_pgm].collection.models[0].attributes.elements[0].tab[idx].key) {
               pgm_name_maps[pgm_views[ap.render_pgm].collection.models[0].attributes.elements[0].tab[idx].key.split('_')[0]]["RANGE_ERROR"].value = range_error;
               break;
            }
         }
      } else {
         pgm_name_maps[ap.render_pgm]["RANGE_ERROR"].value = range_error;
      }

      return false;
   }
}

var try_num = 0;
var reqPgmEnd = false;
var reqMntEnd = false;
var setToLocal = false;
var getFromLocal = false;

function loadPGM() {
	var pgmtmpLen=0;
	var pgmLen = 0;
	var mnttmpLen=0;
	var mntLen = 0;

	$('#search_pgm').attr('placeholder',langs.getText("common","attrsearch_alert"));
	$('#search_pgm').attr("disabled", true);
	$('#search_pgm').blur();     //for explorer/edge
	$('#search_pgm').css("cursor", "wait");
	
	for (var i in left_pgm_menuList) {
		for (var j in left_pgm_menuList[i].children) {
			pgmlistNum = left_pgm_menuList[i].children[j].num;
			if ((pgmlistNum != undefined)&&(pgm_info[pgmlistNum]!=undefined)&&(pgm_info[pgmlistNum].auth)) {
				pgmName = "pgm" + pgmlistNum;
				pgmLen++;
				require(['models/' + pgmName + "_model"], function (model) {
					if (try_num > 1) {
					pgm_models[pgmName] = model;
					var tmp_pgm_model = $.extend(true, {}, pgm_models[pgmName]);
					pgm_list[pgmName] = new pgm_ModelsView(tmp_pgm_model);
					}

					if (pgmtmpLen++ >= pgmLen-1)
					{
						reqPgmEnd = true;
						if (reqMntEnd) {
							if (active_base == "tab_pgm_base")
								$('#search_pgm').attr('placeholder',langs.getText("common","left_menu_pgmsearch"));
							else if (active_base == "tab_maintenance")
								$('#search_pgm').attr('placeholder',langs.getText("common","left_menu_maintsearch"));
							$('#search_pgm').attr("disabled", false);
							$('#search_pgm').focus(); //for explorer/edge
							$('#search_pgm').css("cursor", "text");			
						}
					}
				});
			}
		}
	}

	for (var i in left_maint_menuList) {
		for (var j in left_maint_menuList[i].children) {
			pgmlistNum = left_maint_menuList[i].children[j].num;
			if ((pgmlistNum != undefined)&&(pgm_info[pgmlistNum]!=undefined)&&(pgm_info[pgmlistNum].auth)) {
				pgmExist = 1;
				for (var k in mnt_pgm_no_model) {
					if (pgmlistNum == mnt_pgm_no_model[k]) {     //if pgm doesn't have a model file, do not require that pgm
						pgmExist = 0;
						break;
					}
				}
				
				if (pgmExist) {
					mntLen++;
					pgmName = "pgm" + pgmlistNum;
					require(['models/' + pgmName + "_model"], function (model) {
						if (try_num > 1) {
						pgm_models[pgmName] = model;
						var tmp_pgm_model = $.extend(true, {}, pgm_models[pgmName]);
						maint_list[pgmName] = new pgm_ModelsView(tmp_pgm_model);
						}
						if (mnttmpLen++ >= mntLen-1)
						{
							reqMntEnd = true;
							if (reqPgmEnd) {
								if (active_base == "tab_pgm_base")
									$('#search_pgm').attr('placeholder',langs.getText("common","left_menu_pgmsearch"));
								else if (active_base == "tab_maintenance")
									$('#search_pgm').attr('placeholder',langs.getText("common","left_menu_maintsearch"));
								$('#search_pgm').attr("disabled", false);
								$('#search_pgm').focus(); //for explorer/edge
								$('#search_pgm').css("cursor", "text");			
							}
						}
					});
				}
			}
		}
	}
	
	if (try_num > 1) {
		var pgmComp, mntComp;
		
		pgmComp = LZString.compressToUTF16(JSON.stringify(pgm_list));
		localStorage.setItem('localpgm', pgmComp);
		mntComp = LZString.compressToUTF16(JSON.stringify(maint_list));
		localStorage.setItem('localmnt', mntComp);
		setToLocal = true;
		updateList();
	}	
}

$(document).on('click', '#search_pgm', function (event) {
	requireOrlocal();
});

function requireOrlocal() {
	if (((localStorage.getItem('localpgm') == null) || (localStorage.getItem('localmnt') == null))
		|| (localStorage.getItem('app_ver') != info.APP_VERSION)) {
		if (try_num < 2) {
			try_num++ ;
			loadPGM();
		} else if (try_num == 2) {
			try_num++;
			localStorage.setItem('app_ver', info.APP_VERSION);	
		}
	} else {
		if ((getFromLocal == false) && (setToLocal == false)) {
			$('#search_pgm').attr('placeholder',langs.getText("common","attrsearch_alert"));
			$('#search_pgm').attr("disabled", true);
			$('#search_pgm').blur();     //for explorer/edge
			$('#search_pgm').css("cursor", "wait");			
			pgm_list = JSON.parse(LZString.decompressFromUTF16(localStorage.getItem('localpgm')));
			maint_list = JSON.parse(LZString.decompressFromUTF16(localStorage.getItem('localmnt')));
			getFromLocal = true;
			updateList();
		}
	}
}

function updateList() {
	if ($("#menu_mnt").hasClass("active")==true) {
		select_list = maint_list;
		select_menuList = left_maint_menuList;
	} else {
		select_list = pgm_list;
		select_menuList = left_pgm_menuList;
	}
	if (active_base == "tab_pgm_base")
		$('#search_pgm').attr('placeholder',langs.getText("common","left_menu_pgmsearch"));
	else if (active_base == "tab_maintenance")
		$('#search_pgm').attr('placeholder',langs.getText("common","left_menu_maintsearch"));
	$('#search_pgm').attr("disabled", false);
	$('#search_pgm').focus(); //for explorer/edge
	$('#search_pgm').css("cursor", "text");				
}

function showPGM (item, select_menuList) {
   var pgm_num = 0;
   var seq_num = 0;
   var seq_num_tmp = 0;

   pgm_num = item.key.replace(/_\w+/g,"").replace(/\D+/g,"");
   for (var i in select_menuList) {
      var inc = 0;
      for (var j in select_menuList[i].children) {
         if (select_menuList[i].children[j].auth) {
            seq_num = inc++ + seq_num_tmp;
            if (select_menuList[i].children[j].num == pgm_num) {
               $('.pgm:eq(' + seq_num + ')').show();
            } else if (select_menuList[i].children[j].num == undefined) {
               seq_num_tmp -= 1;
               seq_num -= 1;
            }
         }
      }
      seq_num_tmp = seq_num + 1;
   }
}
var g_last_keyup;
var searchTimerHandle;
function searchAttribute () {
	var hide_flag = false;
	var searchValue = $('#search_pgm').val();					//for PGM search

	searchText = $('#search_pgm').val().toLowerCase();		//for Attribute search

	_.each($('.pgm a'), function (item, i) {
		$('.pgm:eq(' + i + ')').hide();
	});
	
	_.each(select_list, function (pgmno) {
		_.each(pgmno.options.elements[0].tab, function (item) {
			if (item.title) {
				if (item.title.toLowerCase().indexOf(searchText)>=0){
					showPGM(item, select_menuList);
				}
			} else if (item.tr) {
				for (var k in item.tr) {
					if ((item.tr[k].label+="").toLowerCase().indexOf(searchText)>=0){
						showPGM(item, select_menuList);
					}
				}
			} else if (item.th) {
				for (var k in item.th) {
					if ((item.th[k].label+="").toLowerCase().indexOf(searchText)>=0){
						showPGM(item, select_menuList);
					}
				}
			} else if (item.struct) {
				for (var k in item.struct) {
					for(var l in item.struct[k].tr) {
						if ((item.struct[k].tr[l].label+="").toLowerCase().indexOf(searchText)>=0){
							showPGM(item, select_menuList);
						}
					}
				}
			} else if (item.contents) {
				for (var k in item.contents) {
					if (item.contents[k].text) {
						if ((item.contents[k].text+="").toLowerCase().indexOf(searchText)>=0){
							showPGM(item, select_menuList);
						}
					}
				}
			} else if (item.edit_table) {
				for (var k in item.edit_table) {
					if (item.edit_table[k].label) {
						if ((item.edit_table[k].label+="").toLowerCase().indexOf(searchText)>=0){
							showPGM(item, select_menuList);
						}
					}
				}
			} else if (item.table) {
				for (var k in item.table) {
					if (item.table[k].label) {
						if ((item.table[k].label+="").toLowerCase().indexOf(searchText)>=0){
							showPGM(item, select_menuList);
						}
					}
				}
			}
		}, this);
	}, this);

  _.each($('.pgm a'), function (item, i) {
		if ((item.textContent.indexOf(searchValue)>=0) || (item.textContent.toLowerCase().indexOf(searchValue)>=0)) {	
		$('.pgm:eq(' + i + ')').show();
	 }/* else {
		$('.pgm:eq(' + i + ')').hide();
	 }*/

	 i++;
  }, this);


	_.each($('.panel-default'), function (item, i) {
		hide_flag = true;
		_.each($('.panel-default:eq(' + i + ') .pgm'), function (p, j) {
			if ($('.panel-default:eq(' + i + ') .pgm:eq(' + j + ')').css('display') != "none") {
				$('.panel-default:eq(' + i + ')').show();
				$('.panel-collapse:eq(' + i + ')')['height']('100%');
				$('.panel-collapse:eq(' + i + ')').addClass('in');
				hide_flag = false;
				return false;
			}
		});

		if (hide_flag) {
			$('.panel-default:eq(' + i + ')').hide();
			$('.panel-collapse:eq(' + i + ')')['height'](0);
			$('.panel-collapse:eq(' + i + ')').removeClass('in');
		}
	}, this);
}

$(document).on('keyup', '#search_pgm', function (event) {
   var pgmlistNum, pgmName;

	requireOrlocal();	
	
	var _date = new Date();
	var _now = _date.getTime();
	
   if ($('#search_pgm').val() === "") {
      clearTimeout(searchTimerHandle);
      $('.panel-collapse').removeClass('in');
      $('.pgm').show();
      $('.panel-default').show();
      _.each($('.panel-default'), function (item, i) {
			if($('.panel-heading:eq(' + i + ')').hasClass('active')) {
				$('.panel-collapse:eq(' + i + ')')['height']('100%');
				$('.panel-collapse:eq(' + i + ')').addClass('in');
			} else {
				$('.panel-collapse:eq(' + i + ')')['height'](0);
			}
      });
      searchText = null;
   } else {
		var hide_flag = false;
		if(typeof g_last_keyup !== "undefined" && _now - g_last_keyup < 1000)
			clearTimeout(searchTimerHandle);
		
		g_last_keyup = _now;
		searchTimerHandle = setTimeout(searchAttribute,1000);
			
	}
});

$(document).on('click', '#clr_search_icon', function (event) {
	clear_search_pgm();
});

function clear_search_pgm () {
	$('.panel-collapse').removeClass('in');
	clearTimeout(searchTimerHandle);
	$('#search_pgm').val("");

   $('.pgm').show();
   $('.panel-default').show();
   _.each($('.panel-default'), function (item, i) {
		if($('.panel-heading:eq(' + i + ')').hasClass('active')) {
			$('.panel-collapse:eq(' + i + ')')['height']('100%');
			$('.panel-collapse:eq(' + i + ')').addClass('in');
		} else {
			$('.panel-collapse:eq(' + i + ')')['height'](0);
		}
   });
   searchText = null;
}

$(document).on('click', '.pgm', function () {
	var tab_str = $(this).children().attr("href").replace("#", "");

	if (active_base == "tab_user_guide") {
		$('.custom_span_menu .pgm').removeClass('active');
		$(this).addClass('active');

		$('#'+ap.render_pgm).html("");
		pgm_models.get_model(tab_str, true, packet);
	} else {
		if (active_base == "tab_stn_base") {
			if (tab_str == "pgms012" && !info.SWUA_EN) {
				$('<div />').html(langs.getText("ps012","alert_disable")).dialog({
					modal: true,
					closeOnEscape: false,
					title: langs.getText("common","notification"),
					open: function (event, ui) {
						$(".ui-dialog-titlebar-close").hide();
					},
					buttons: [
						{
							text: langs.getText("common","simple_okay"),
							click: function () {
								$(this).dialog("destroy");
							}
						}
					]
				});
				return false;
			} else if (tab_str == "pgms016" && !info.CB_EN) {
				$('<div />').html(langs.getText("ps016","alert_disable")).dialog({
					modal: true,
					closeOnEscape: false,
					title: langs.getText("common","notification"),
					open: function (event, ui) {
						$(".ui-dialog-titlebar-close").hide();
					},
					buttons: [
						{
							text: langs.getText("common","simple_okay"),
							click: function () {
								$(this).dialog("destroy");
							}
						}
					]
				});
				return false;
			} else if (((tab_str == "pgms002") || (tab_str == "pgms003") || (tab_str == "pgms006") || (tab_str == "pgms008") || (tab_str == "pgms009") || (tab_str == "pgms016")) && offline_mode) {
				$('<div />').html(langs.getText("error_msg","alert_owadisable")).dialog({
					modal: true,
					closeOnEscape: false,
					title: langs.getText("common","notification"),
					open: function (event, ui) {
						$(".ui-dialog-titlebar-close").hide();
					},
					buttons: [
						{
							text: langs.getText("common","simple_okay"),
							click: function () {
								$(this).dialog("destroy");
							}
						}
					]
				});
				return false;
			}
		} else {
			if (((tab_str == "pgm1291") || (tab_str == "pgm1600") || (tab_str == "pgm212") || (tab_str == "pgm214") || (tab_str == "pgm99") || (tab_str == "pgm46") || (tab_str == "pgm47") || (tab_str == "pgm48") || (tab_str == "pgm49") || (tab_str == "pgm51") || (tab_str == "pgm52") || (tab_str == "pgm78") || (tab_str == "pgm781") || (tab_str == "pgm782") || (tab_str == "pgm79") || (tab_str == "pgm87") || (tab_str == "pgm76") || (tab_str == "pgm77") || (tab_str == "pgm80") || (tab_str == "pgm81") || (tab_str == "pgm82") || (tab_str == "pgm83") || (tab_str == "pgm84") || (tab_str == "pgm85") || (tab_str == "pgm88") || (tab_str == "pgm90") || (tab_str == "pgm91") || (tab_str == "pgm93") || (tab_str == "pgm94") || (tab_str == "pgm95") || (tab_str == "pgm60") || (tab_str == "pgm61") || (tab_str == "pgm62") || (tab_str == "pgm63") || (tab_str == "pgm64") || (tab_str == "pgm65") || (tab_str == "pgm69") || (tab_str == "pgm309") || (tab_str == "pgm312") || (tab_str == "pgm3131") || (tab_str == "pgm3132") || (tab_str == "pgm315") || (tab_str == "pgm70") || (tab_str == "pgm71") || (tab_str == "pgm72") || (tab_str == "pgm73") || (tab_str == "pgm731") || (tab_str == "pgm490") || (tab_str == "pgm1292") || (tab_str == "pgm4461") || (tab_str == "pgm96") || (tab_str == "pgm1330")) && offline_mode) {
				$('<div />').html(langs.getText("error_msg","alert_owadisable")).dialog({
					modal: true,
					closeOnEscape: false,
					title: langs.getText("common","notification"),
					open: function (event, ui) {
						$(".ui-dialog-titlebar-close").hide();
					},
					buttons: [
						{
							text: langs.getText("common","simple_okay"),
							click: function () {
								$(this).dialog("destroy");
							}
						}
					]
				});
				return false;
			}
		}

		if($(this).parents('.panel-default').children('.panel-heading').length) {
			if(!$(this).parents('.panel-default').children('.panel-heading').hasClass('active')) {
				$("#accordion .panel-heading").removeClass('active');
				$("#accordion .panel-heading").children('img').remove();
				$(this).parents('.panel-default').children('.panel-heading').append("<img src='img/a.png' style='float:right; margin-top:6px;' />");
				$(this).parents('.panel-default').children('.panel-heading').addClass('active');
			}
		}
		$('.custom_span_menu .pgm').removeClass('active');
		$(this).addClass('active');

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

		if (active_base == "tab_maintenance" && $("#"+active_base+" .nav-tabs-main .active").hasClass("add_func")) {
			$("#" + ap.active_pgm + "_attrs").html("");
			$('#' + ap.active_pgm + ' .tab-content-sub .active').html("");
			pgm_models.get_model(tab_str, true);
		} else {
			$('#' + active_base + ' .nav-tabs-main li').removeClass("active");
			$('#' + active_base + ' .nav-tabs-main li .icon_refresh').remove();
			$('#' + 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_function_base") {
				if (existed === true) {
					ap.render_pgm = $("#" + tab_str + " .tab-content-sub .active").attr("id");
					if ($("#" + ap.render_pgm + " .preload").length) {
						$("#" + ap.render_pgm + " .preload input:eq(1)").focus();
					}
				} else {
					pgm_models.get_func_model(ap.render_pgm, true);
				}
			} else {
				if (existed === true) {
					//$("#"+ap.render_pgm).html("");
					if ($("#" + ap.render_pgm + " .preload").length) {
						$("#" + ap.render_pgm + " .preload input:eq(1)").focus();
					}
				} else {
					if (ap.active_pgm === "pgm51") {
						make_fileup_pgm(false);
					} else if (ap.active_pgm === "pgm55") {
						make_dbfileup_pgm();
					} else if (ap.active_pgm === "pgm56") {
						make_mlfileup_pgm();
					} else if (ap.active_pgm === "pgm76") {
						packet.setPacket(0, range_type, range, "{}");
						make_vsfprmtup_pgm(packet);
					} else if (ap.active_pgm === "pgm77") {
						make_vsfindivup_pgm();
					} else if (ap.active_pgm === "pgm782") {
						make_moh_indivup_pgm();
					} else if (ap.active_pgm === "pgm80") {
						make_vsfsgindivup_pgm();
					} else if (ap.active_pgm === "pgm82") {
						packet.setPacket(0, range_type, range, "{}");
						make_vsfsgdn_pgm(packet);
					} else if (ap.active_pgm === "pgm83") {
						packet.setPacket(0, range_type, range, "{}");
						make_vsfsgup_pgm(packet);
					} else if (ap.active_pgm === "pgm89") {
						make_licenseup_pgm(false);
					} else if (ap.active_pgm === "pgm46") {
						make_usrgrtfileup_pgm(false);
					} else if (ap.active_pgm === "pgm47") {
						packet.setPacket(0, range_type, range, "{}");
						make_usrgrtfiledn_pgm(packet);
					} else if (ap.active_pgm === "pgm48") {
						make_cdnfileup_pgm(false);
					} else if (ap.active_pgm === "pgm49") {
						packet.setPacket(0, range_type, range, "{}");
						make_cdnfiledn_pgm(packet);
					} else {
						packet.setPacket(0, range_type, range, "{}");
						pgm_models.get_model(ap.render_pgm, true, packet);
					}
				}
			}

			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");
});

$(document).on('click', '.nav-tabs-main li .icon_refresh', function () {
	save_flag = true;

	if ($('#' + active_base + ' .nav-tabs-main .active').hasClass("add_func")) {
		$('#'+ap.render_pgm).html("");

      var source = $("#add_functionTemplate").html();
      var template = Handlebars.compile(source);
      var len = 0;
      var tmp_len = 0;

      tmp_len = $(this).parent().text().replace(langs.getText("common","tab_func_addfunc"), "");
      len = eval(tmp_len);

      var context = {
         add_index: len,
         add_name: langs.getText("common","tab_func_funcname"),
         add_save: langs.getText("common","tab_func_savfunc")
      };
      var html = template(context);

      $('#'+ap.render_pgm).append(html);
      $('#' + active_base + ' .tab-pane-main .col-md-3').css('height', $('.row-fluid .custom_span_pgm ').height() - $('#' + active_base + ' .nav-tabs-main').height() - eval($('#' + active_base + ' .nav-tabs-main').css('padding-top').replace('px', '')) - eval($('#' + active_base + ' .nav-tabs-main').css('margin-bottom').replace('px', '')) - eval($('#' + active_base + ' .tab-pane-main').css('padding-bottom').replace('px', '')) - eval($('#' + active_base + ' .tab-pane-main .col-md-3').css('margin-bottom').replace('px', '')));
		$('#' + active_base + ' .tab-pane-main .col-md-9').css('height', $('.row-fluid .custom_span_pgm ').height() - $('#' + active_base + ' .nav-tabs-main').height() - eval($('#' + active_base + ' .nav-tabs-main').css('padding-top').replace('px', '')) - eval($('#' + active_base + ' .nav-tabs-main').css('margin-bottom').replace('px', '')) - eval($('#' + active_base + ' .tab-pane-main').css('padding-bottom').replace('px', '')) - eval($('#' + active_base + ' .tab-pane-main .col-md-9').css('margin-bottom').replace('px', '')));

		for (var i = 1; i <= info.NO_OF_MAX_FUNCTION_STEP; i++) {
         if (i == 1) {
            $("#" + ap.active_pgm + "_tab ul").append("<li class=\"active\" style=\"width:19.9%; text-align:center;\"><a href=\"#" + ap.active_pgm + "_tab" + i + "\" data-toggle=\"tab\">" + langs.getText("common","title_step") + " " + i + "<input size=8 style=\"margin-left:5px\"></a></li>");
            $("#" + ap.active_pgm + "_tab .tab-content").append("<div class=\"tab-pane tab-pane-sub active\" id=\"" + ap.active_pgm + "_tab" + i + "\"></div>");
         } else {
            $("#" + ap.active_pgm + "_tab ul").append("<li style=\"width:19.9%; text-align:center;\"><a href=\"#" + ap.active_pgm + "_tab" + i + "\" data-toggle=\"tab\">" + langs.getText("common","title_step") + " " + i + "<input size=8 style=\"margin-left:5px\"></a></li>");
            $("#" + ap.active_pgm + "_tab .tab-content").append("<div class=\"tab-pane tab-pane-sub\" id=\"" + ap.active_pgm + "_tab" + i + "\"></div>");
         }

         if(i == info.NO_OF_MAX_FUNCTION_STEP) {
				$("#" + ap.active_pgm + "_tab .tab-pane-sub").css('height', $("#" + ap.active_pgm).height() - eval($("#" + ap.active_pgm+"_group").css('padding-top').replace('px', '')) - eval($("#" + ap.active_pgm+"_group").css('padding-bottom').replace('px', '')) - $("#" + ap.active_pgm+" .function_name").height() - eval($("#" + ap.active_pgm+" .function_name").css('padding-bottom').replace('px', '')) - eval($("#" + ap.active_pgm+" .function_name").css('margin-bottom').replace('px', '')) - $("#" + ap.active_pgm+" .nav-tabs-sub").height() - eval($("#" + ap.active_pgm+" .nav-tabs-sub").css('margin-bottom').replace('px', '')) - eval($('#' + active_base + ' .tab-pane-main .col-md-9').css('margin-bottom').replace('px', '')));
         }
      }

      tab_history[0] = tab_history[1];
      tab_history[1] = $('#' + active_base + ' .nav-tabs-main .active').children().text();
	} else {
		var range_type = [];
		var range = [];

      if (active_base == "tab_function_base") {
         ap.render_pgm = $(this).parent().attr('href').replace("#","");
         $("#" + ap.render_pgm).html("");
         pgm_models.get_func_model(ap.render_pgm, true);
      } else {
			if (ap.render_pgm === "pgm2550") {
				$("#" + ap.render_pgm).html("");
				make_aclhelp_pgm();
			} else if (ap.render_pgm === "pgm51" || ap.render_pgm === "iw001") {
				$("#" + ap.render_pgm).html("");
				make_fileup_pgm(false);
			} else if (ap.render_pgm === "pgm55") {
				$("#" + ap.render_pgm).html("");
				make_dbfileup_pgm();
			} else if (ap.render_pgm === "pgm56") {
				$("#" + ap.render_pgm).html("");
				make_mlfileup_pgm();
			} else if (ap.render_pgm === "pgm76") {
				packet.setPacket(0, range_type, range, "{}");
				$("#" + ap.render_pgm).html("");
				make_vsfprmtup_pgm(packet);
			} else if (ap.render_pgm === "pgm77") {
				$("#" + ap.render_pgm).html("");
				make_vsfindivup_pgm();
			} else if (ap.render_pgm === "pgm782") {
				$("#" + ap.render_pgm).html("");
				make_moh_indivup_pgm();
			} else if (ap.render_pgm === "pgm80") {
				$("#" + ap.render_pgm).html("");
				make_vsfsgindivup_pgm();
			} else if (ap.render_pgm === "pgm82") {
				packet.setPacket(0, range_type, range, "{}");
				$("#" + ap.render_pgm).html("");
				make_vsfsgdn_pgm(packet);
			} else if (ap.render_pgm === "pgm83") {
				packet.setPacket(0, range_type, range, "{}");
				$("#" + ap.render_pgm).html("");
				make_vsfsgup_pgm(packet);
			} else if (ap.render_pgm === "pgm89" || ap.render_pgm === "iw007") {
				$("#" + ap.render_pgm).html("");
				make_licenseup_pgm(false);
			} else if (ap.render_pgm === "pgm46") {
				$("#" + ap.render_pgm).html("");
				make_usrgrtfileup_pgm(false);
			} else if (ap.render_pgm === "pgm47") {
				packet.setPacket(0, range_type, range, "{}");
				$("#" + ap.render_pgm).html("");
				make_usrgrtfiledn_pgm(packet);
			} else if (ap.render_pgm === "pgm48") {
				$("#" + ap.render_pgm).html("");
				make_cdnfileup_pgm(false);
			} else if (ap.render_pgm === "pgm49") {
				packet.setPacket(0, range_type, range, "{}");
				$("#" + ap.render_pgm).html("");
				make_cdnfiledn_pgm(packet);
			} else {
				if(hidden_flags[ap.render_pgm]) {
					packet.setPacket(0, range_type, range, "{}");
					$("#" + ap.render_pgm).html("");
					pgm_models.get_model(ap.render_pgm, true, packet);
				} else {
					if ($('#' + ap.render_pgm + ' .preload').length) {
						_.each($('#' + ap.render_pgm + ' .preload').children(), function (item) {
							if (item.name && item.name.match("RANGE_TYPE")) {
								range_type.push(item.value);
							} else if (item.className && item.className.match("RANGE_VIEW")) {
								range.push(item.innerHTML);
							}
						});
					} else if ((ap.render_pgm == "iw006") && info.NO_OF_COLS) {
						range_type.push("2");
						range.push("1-" + info.NO_OF_COLS);
					}
					packet.setPacket(0, range_type, range, "{}");
					$("#" + ap.render_pgm).html("");
					pgm_models.get_model(ap.render_pgm, false, packet);
				}
			}
		}
	}
});

$(document).on('click', '.nav-tabs-main li a', function () {
   if (active_base != "tab_install_wizard") {
      if (save_flag === false) {
         moveTab();
      }

      //debug_mode.flag && console.log("tab_history[0] : "+tab_history[0]+"  tab_history[1] : "+tab_history[1]);
      save_flag = false;

      $(document).trigger("Resize_pane");
   }
});

function moveTab() {
   tab_history[0] = tab_history[1];
   tab_history[1] = $('#'+active_base+' .nav-tabs-main .active a').text();

   if (active_base == "tab_function_base") {
		if($('#'+active_base+' .tab-content-main .active .nav-tabs-sub li').length) {
			ap.active_pgm = $('#'+active_base+' .nav-tabs-main .active a').attr("href").replace("#", "");
			ap.render_pgm = $('#'+active_base+' .tab-content-main .active .tab-content-sub .active').attr('id');
			$(document).trigger("change_active_pgm", ap.active_pgm);
		} else {
			ap.set_active_pgm($('#'+active_base+' .nav-tabs-main .active a').attr("href").replace("#", ""));
		}
   } else if (active_base == "tab_maintenance") {
		$("#accordion div").remove();

		if ($('#'+active_base+' .nav-tabs-main .active a').parent().hasClass("add_func")) {
         pgm_dir_view.render();
         pgm_menuList_view.render();
         $('.custom_span_menu').scrollTop(0);
		} else {
         mnt_dir_view.render();
			mnt_menuList_view.render();
			$('.custom_span_menu').scrollTop(0);
		}

		if (((tab_history[0] == "Add Function") && (tab_history[1] != "Add Function")) || ((tab_history[1] == "Add Function") && (tab_history[0] != "Add Function"))) {
			$('#search_pgm').val("");
		}

		ap.set_active_pgm($('#'+active_base+' .nav-tabs-main .active a').attr("href").replace("#", ""));
   } else {
		ap.set_active_pgm($('#'+active_base+' .nav-tabs-main .active a').attr("href").replace("#", ""));
   }

   if($('#'+active_base+' .nav-tabs-main .active').index() == 0) {
		if($("#accordion .panel-heading").length) {
			$('.panel-collapse').removeClass('in');
			$('.panel-collapse')['height'](0);
			$("#accordion .panel-heading").removeClass('active');
			$("#accordion .panel-heading").children('img').remove();
		}
		$('.custom_span_menu .pgm').removeClass('active');
   } else {
		var sel_id = $('#'+active_base+' .nav-tabs-main .active a').attr('href');
		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 .panel-heading").length) {
			$('.panel-collapse').removeClass('in');
			$('.panel-collapse')['height'](0);
			$("#accordion .panel-heading").removeClass('active');
			$("#accordion .panel-heading").children('img').remove();

			$('.panel-collapse .active').parents('.panel-collapse').addClass('in');
			$('.panel-collapse .active').parents('.panel-collapse')['height']('100%');
			$('.panel-collapse .active').parents('.panel-default').children('.panel-heading').addClass('active');
			$('.panel-collapse .active').parents('.panel-default').children('.panel-heading').append("<img src='img/a.png' style='float:right; margin-top:6px;' />");
		}
	}

   $('#' + active_base + ' .nav-tabs-main li .icon_refresh').remove();
   if ((active_base == "tab_maintenance") && ($('#' + active_base + ' .nav-tabs-main .active').index() == 0)) {
		$('#'+active_base+' .nav-tabs-main .active a').html(tab_history[1] + "<img src='img/refresh_icon.png' class='icon_refresh' title='" + langs.getText("toolTip","tip_refreshtab") + "' />");
   } else if ($('#' + active_base + ' .nav-tabs-main .active').index() != 0) {
      $('#'+active_base+' .nav-tabs-main .active a').html(tab_history[1] + "<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") + "' />");
   }
}

$(document).on('click', '.nav-tabs-main li .icon_remove', function () {
   if (active_base != "tab_install_wizard") {
      var i = 0;
      var this_index = $(this).parents('li').index();
      var this_name = $(this).parent().text();

      tab_history[0] = tab_history[1];
      tab_history[1] = $(this).parent().text();

      //debug_mode.flag && console.log("tab_history[0] : "+tab_history[0]+"  tab_history[1] : "+tab_history[1]);
      save_flag = true;

      if (tab_history[0] === tab_history[1]) {
         //debug_mode.flag && console.log("if(tab_history[0] === tab_history[1])");
         if ($(this).parent().text() === $('#' + active_base + ' .nav-tabs-main li:last a').text()) {
            //debug_mode.flag && console.log("if($(this).parent().text() === $('#'+active_base+' .nav-tabs-main li:last a').text())");
            $('#' + active_base + ' .nav-tabs-main li:eq(' + (this_index - 1) + ')').addClass("active");
            $('#' + active_base + ' .tab-content-main .tab-pane-main:eq(' + (this_index - 1) + ')').addClass("active");

            tab_history[1] = $('#' + active_base + ' .nav-tabs-main li:eq(' + (this_index - 1) + ')').children().text();
         } else {
            //debug_mode.flag && console.log("if($(this).parent().text() === $('#'+active_base+' .nav-tabs-main li:last a').text()) else");
            $('#' + active_base + ' .nav-tabs-main li:eq(' + (this_index + 1) + ')').addClass("active");
            $('#' + active_base + ' .tab-content-main .tab-pane-main:eq(' + (this_index + 1) + ')').addClass("active");

            tab_history[1] = $('#' + active_base + ' .nav-tabs-main li:eq(' + (this_index + 1) + ')').children().text();
         }
      } else {
         //debug_mode.flag && console.log("if(tab_history[0] === tab_history[1]) else");
         _.each($('#' + active_base + ' .nav-tabs-main li'), function (item) {
            if ($('#' + active_base + ' .nav-tabs-main li:eq(' + i + ')').children().text() === tab_history[0]) {
               $('#' + active_base + ' .nav-tabs-main li:eq(' + i + ')').addClass("active");
               $('#' + active_base + ' .tab-content-main .tab-pane-main:eq(' + i + ')').addClass("active");

               tab_history[1] = $('#' + active_base + ' .nav-tabs-main li:eq(' + i + ')').children().text();
            }
            i++;
         }, this);
      }

      $(this).parents('li').remove();
      $('#' + active_base + ' .tab-content-main .tab-pane-main:eq(' + this_index + ')').remove();
      if (active_base == "tab_pgm_base") {
			_.each($('.tab_scrlbar_util .tab_list .tab_list_pgm ul li'), function (item, i) {
				if (this_name == $('.tab_scrlbar_util .tab_list .tab_list_pgm ul li:eq(' + i + ')').children().text()) {
					$('.tab_scrlbar_util .tab_list .tab_list_pgm ul li:eq(' + i + ')').remove();
					return false;
				}
			});
		} else if (active_base == "tab_function_base") {
			_.each($('.tab_scrlbar_util .tab_list .tab_list_func ul li'), function (item, i) {
				if (this_name == $('.tab_scrlbar_util .tab_list .tab_list_func ul li:eq(' + i + ')').children().text()) {
					$('.tab_scrlbar_util .tab_list .tab_list_func ul li:eq(' + i + ')').remove();
					return false;
				}
			});
		} else if (active_base == "tab_maintenance") {
			_.each($('.tab_scrlbar_util .tab_list .tab_list_mnt ul li'), function (item, i) {
				if (this_name == $('.tab_scrlbar_util .tab_list .tab_list_mnt ul li:eq(' + i + ')').children().text()) {
					$('.tab_scrlbar_util .tab_list .tab_list_mnt ul li:eq(' + i + ')').remove();
					return false;
				}
			});

			if (((tab_history[0] == "Add Function") && (tab_history[1] != "Add Function")) || ((tab_history[1] == "Add Function") && (tab_history[0] != "Add Function"))) {
				$('#search_pgm').val("");
			}
		} else if (active_base == "tab_stn_base") {
			_.each($('.tab_scrlbar_util .tab_list .tab_list_stn ul li'), function (item, i) {
				if (this_name == $('.tab_scrlbar_util .tab_list .tab_list_stn ul li:eq(' + i + ')').children().text()) {
					$('.tab_scrlbar_util .tab_list .tab_list_stn ul li:eq(' + i + ')').remove();
					return false;
				}
			});
		}

      $('#' + active_base + ' .nav-tabs-main li .icon_refresh').remove();
      if ((active_base == "tab_maintenance") && ($('#' + active_base + ' .nav-tabs-main .active').index() == 0)) {
			$('#' + active_base + ' .nav-tabs-main .active a').html(tab_history[1] + "<img src='img/refresh_icon.png' class='icon_refresh' title='" + langs.getText("toolTip","tip_refreshtab") + "' />");
      } else if ($('#' + active_base + ' .nav-tabs-main .active').index() != 0) {
         $('#' + active_base + ' .nav-tabs-main .active a').html(tab_history[1] + "<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") + "' />");
      }

      //debug_mode.flag && console.log("active_base : "+active_base+" this_index : "+this_index);
      if (active_base == "tab_function_base") {
			if($('#'+active_base+' .tab-content-main .active .nav-tabs-sub li').length) {
				ap.active_pgm = $('#' + active_base + ' .nav-tabs-main .active a').attr("href").replace("#", "");
				ap.render_pgm = $('#'+active_base+' .tab-content-main .active .tab-content-sub .active').attr('id');
				$(document).trigger("change_active_pgm", ap.active_pgm);
			} else {
				ap.set_active_pgm($('#' + active_base + ' .nav-tabs-main .active a').attr("href").replace("#", ""));
			}
      } else if(active_base == "tab_maintenance") {
			$("#accordion div").remove();

			if ($('#' + active_base + ' .nav-tabs-main .active').hasClass("add_func")) {
            pgm_dir_view.render();
            pgm_menuList_view.render();
            $('.custom_span_menu').scrollTop(0);
			} else {
            mnt_dir_view.render();
				mnt_menuList_view.render();
				$('.custom_span_menu').scrollTop(0);
			}

			ap.set_active_pgm($('#' + active_base + ' .nav-tabs-main .active a').attr("href").replace("#", ""));
      } else {
			ap.set_active_pgm($('#' + active_base + ' .nav-tabs-main .active a').attr("href").replace("#", ""));
      }

      if($('#' + active_base + ' .nav-tabs-main .active').index() == 0) {
			if($("#accordion .panel-heading").length) {
				$('.panel-collapse').removeClass('in');
				$('.panel-collapse')['height'](0);
				$("#accordion .panel-heading").removeClass('active');
				$("#accordion .panel-heading").children('img').remove();
			}
			$('.custom_span_menu .pgm').removeClass('active');
      } else {
			var sel_id = $('#' + active_base + ' .nav-tabs-main .active a').attr("href");
			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 .panel-heading").length) {
				$('.panel-collapse').removeClass('in');
				$('.panel-collapse')['height'](0);
				$("#accordion .panel-heading").removeClass('active');
				$("#accordion .panel-heading").children('img').remove();

				$('.panel-collapse .active').parents('.panel-collapse').addClass('in');
				$('.panel-collapse .active').parents('.panel-collapse')['height']('100%');
				$('.panel-collapse .active').parents('.panel-default').children('.panel-heading').addClass('active');
				$('.panel-collapse .active').parents('.panel-default').children('.panel-heading').append("<img src='img/a.png' style='float:right; margin-top:6px;' />");
			}
		}

      $(document).trigger("Resize_pane");
   }
});

$(document).on('click', '.nav-tabs-sub li .icon_refresh', function () {
	var range_type = [];
	var range = [];
   var tab_str = $("#" + ap.active_pgm + " .tab-content-sub .active").attr("id");

   ap.render_pgm = tab_str;

	if(hidden_flags[ap.render_pgm]) {
		packet.setPacket(0, range_type, range, "{}");
		$("#" + ap.render_pgm).html("");
		pgm_models.get_model(ap.render_pgm, true, packet);
	} else {
		if ($('#' + ap.render_pgm + ' .preload').length) {
			_.each($('#' + ap.render_pgm + ' .preload').children(), function (item) {
				if (item.name && item.name.match("RANGE_TYPE")) {
					range_type.push(item.value);
				} else if (item.className && item.className.match("RANGE_VIEW")) {
					range.push(item.innerHTML);
				}
			});
		} else if ((ap.render_pgm == "iw006") && info.NO_OF_COLS) {
			range_type.push("2");
			range.push("1-" + info.NO_OF_COLS);
		}
		packet.setPacket(0, range_type, range, "{}");
		$("#" + ap.render_pgm).html("");
		pgm_models.get_model(ap.render_pgm, false, packet);
	}
});

$(document).on('click', '.btn_save', function () {
   var pre_msg = [];
   var tmp_name = "";
   var tmp_value = "";
   var send_msg = "";
   var restart_msg = "";
   var skip_flag = false;
   var dont_save = false;
   var range_type = [];
   var range = [];
   var real_pgm = ap.render_pgm;
   var sheet_index = 0;

   if (active_base == "tab_function_base" || active_base == "tab_install_wizard") {
      ap.render_pgm = $(this).parent().parent().attr("id");
      for (var idx = 0; idx < pgm_views[ap.render_pgm].collection.models[0].attributes.elements[0].tab.length; idx++) {
			if (pgm_views[ap.render_pgm].collection.models[0].attributes.elements[0].tab[idx].key) {
				real_pgm = pgm_views[ap.render_pgm].collection.models[0].attributes.elements[0].tab[idx].key.split('_')[0];
				break;
			}
		}
   }
   debug_mode.flag && console.log("ap.render_pgm : "+ap.render_pgm+" real_pgm : "+real_pgm);

   if ($('#' + ap.render_pgm + ' .error').length) {
      $('#' + ap.render_pgm + ' .error').siblings('input').css('outline', '').css('margin', '');
      $('#' + ap.render_pgm + ' .error').remove();
   }

   if ($('#' + ap.render_pgm + ' .htInvalid').length) {
		$('#' + ap.render_pgm + ' .htInvalid').removeClass('htInvalid');
   }

   if ($('#' + ap.render_pgm + ' .preload').length) {
      _.each($('#' + ap.render_pgm + ' .preload').children(), function (item) {
         if (item.name && item.name.match("RANGE_TYPE")) {
            range_type.push(item.value);
         } else if (item.className && item.className.match("RANGE_VIEW")) {
            range.push(item.innerHTML);
         }
      });
   } else if ((ap.render_pgm == "iw006") && info.NO_OF_COLS) {
      range_type.push("2");
      range.push("1-" + info.NO_OF_COLS);
   }

   if (real_pgm == "pgm50") {
      if (!$('[name=ADD_USERID]').val().match(/^[a-zA-Z]/)) {
			if ($('[name=ADD_USERID]').val().length) {
				$('<div />').html(langs.getText("p50","alert_invalidid")).dialog({
					modal: true,
					closeOnEscape: false,
					title: langs.getText("common","notification"),
					open: function (event, ui) {
						$(".ui-dialog-titlebar-close").hide();
					},
					buttons: [
						{
							text: langs.getText("common","simple_okay"),
							click: function () {
								$(this).dialog("destroy");
							}
						}
					]
				});
				return false;
         }
      }
   }

   if (real_pgm == "pgm100") {
		if ($('#' + ap.render_pgm + ' [name=SITEDETAIL]').length) {
			var temp;
			var msglen;
			var sendsubmit;
			var utfchar;
			var maxlen;
			var value;
			var l;

			maxlen = 100;

			value = $('#' + ap.render_pgm + ' [name=SITEDETAIL]').val();
			l = $('#' + ap.render_pgm + ' [name=SITEDETAIL]').val().length;

			msglen = maxlen;

			sendsubmit = 1;
			tmpstr = "";

			if (l == 0) {
				value = maxlen * 2;
			} else {
				for (var k = 0; k < l; k++) {
					temp = value.charAt(k);

					utfchar = escape(temp);
					if (utfchar.length > 4) {
						if (utfchar > "%u040F" && utfchar < "%u0450") msglen--;
						else msglen -= 2;
					} else msglen--;

					if (msglen < 0) {
						sendsubmit = 0;

						$('<div />').html(langs.getText("p100","alert_over_sitedetail1") + " " + maxlen + " " + langs.getText("p100","alert_over_sitedetail2")).dialog({
							modal: true,
							closeOnEscape: false,
							title: langs.getText("common","notification"),
							open: function (event, ui) {
								$(".ui-dialog-titlebar-close").hide();
							},
							buttons: [
								{
									text: langs.getText("common","simple_okay"),
									click: function () {
										$(this).dialog("destroy");
									}
								}
							]
						});

						$('#' + ap.render_pgm + ' [name=SITEDETAIL]').val(tmpstr);
						break;
					} else {
						tmpstr += temp;
					}
				}
			}

			if (1 != sendsubmit) {
				return false;
			}
      }
   }

   if ($(this).hasClass('btn_sms_send')) {
		if ($('#' + ap.render_pgm + ' [name=ADMNOTE_MSG]').length || $('#' + ap.render_pgm + ' [name=SMSMSG]').length) {
			var temp;
			var msglen;
			var sendsubmit;
			var utfchar;
			var maxlen;
			var value;
			var l;

			if(real_pgm == "pgm448") {
				maxlen = 255;

				value = $('#' + ap.render_pgm + ' [name=ADMNOTE_MSG]').val();
				l = $('#' + ap.render_pgm + ' [name=ADMNOTE_MSG]').val().length;
			} else {
				maxlen = 80;

				value = $('#' + ap.render_pgm + ' [name=SMSMSG]').val();
				l = $('#' + ap.render_pgm + ' [name=SMSMSG]').val().length;
			}

			msglen = maxlen;

			sendsubmit = 1;
			tmpstr = "";

			if (l == 0) {
				value = maxlen * 2;
			} else {
				for (var k = 0; k < l; k++) {
					temp = value.charAt(k);

					utfchar = escape(temp);
					if (utfchar.length > 4) {
						if (utfchar > "%u040F" && utfchar < "%u0450") msglen--;
						else msglen -= 2;
					} else msglen--;

					if (msglen < 0) {
						sendsubmit = 0;

						$('<div />').html(langs.getText("ps008","alert_over_msg1") + " " + maxlen + " " + langs.getText("ps008","alert_over_msg2")).dialog({
							modal: true,
							closeOnEscape: false,
							title: langs.getText("common","notification"),
							open: function (event, ui) {
								$(".ui-dialog-titlebar-close").hide();
							},
							buttons: [
								{
									text: langs.getText("common","simple_okay"),
									click: function () {
										$(this).dialog("destroy");
									}
								}
							]
						});
						if(real_pgm == "pgm448") {
							$('#' + ap.render_pgm + ' [name=ADMNOTE_MSG]').val(tmpstr);
						} else {
							$('#' + ap.render_pgm + ' [name=SMSMSG]').val(tmpstr);
						}

						break;
					} else {
						tmpstr += temp;
					}
				}
			}

			if (1 != sendsubmit) {
				return false;
			}
      }
   }

   _.each($('#' + ap.render_pgm).children(), function (items, i) {
      if ($('#' + ap.render_pgm).children().eq(i).is('div') && !$('#' + ap.render_pgm).children().eq(i).hasClass('preload') && !$('#' + ap.render_pgm).children().eq(i).hasClass('handsontable')) {
			// hansontable은 Excel 형식을 따르는 table을 생성하는 Plugin name으로 최상단에 handsontable이라는 이름을 가진 div가 생성된다.
         _.each($('#' + ap.render_pgm).children().eq(i).children(), function (item) {
            tmp_name = "";
            tmp_value = "";

            if (item.type == "radio" && item.checked == false) {
					return true;
            }

            if (item.type == "button") {
					return true;
            }

            if ((real_pgm == "pgm105") && (item.name == "SEARCHNUMBER")) {
					return true;
            }

            if (!item.disabled) {
               if (item.name && (item.name != "undefined")) {
                  tmp_name = "\"" + item.name + "\"";
                  if (item.value) {
                     if (!item.className.match('enable_mullang')) {
								if (item.value.match(/[^a-zA-Z0-9\s\{\}\[\]\/?.,;:|\)*~`!^\-_+┼<>@\#$%&\'\(\=\\]/g)) {
									dont_save = true;
									item.style.outline = "2px solid red";
									item.style.margin = "2px";
									$('#' + ap.render_pgm + ' [name=' + item.name + ']').after("<font class='error' style='font-weight: bold; color: red; margin: 0px 5px;'>" + langs.getText("error_msg","error_mullang") + "</font>");
/*
									if($('#'+ap.render_pgm+' [name='+item.name+']').next().get(0).tagName == "BR") {
										$('#'+ap.render_pgm+' [name='+item.name+']').after("<font class='error' style='font-weight: bold; color: red; margin: 0px 5px;'>"+langs.getText("error_msg","error_mullang")+"</font>");
									} else {
										if(!$('#'+ap.render_pgm+' [name='+item.name+']').nextUntil('br').get(0).className.match("error")) {
											$('#'+ap.render_pgm+' [name='+item.name+']').nextUntil('br').after("<font class='error' style='font-weight: bold; color: red; margin: 0px 5px;'>"+langs.getText("error_msg","error_mullang")+"</font>");
										}
									}
									*/
							   }
                     } else {
								if (chkKoreanLength(item.value) > item.maxLength) {
									dont_save = true;
									item.style.outline = "2px solid red";
									item.style.margin = "2px";
									$('#' + ap.render_pgm + ' [name=' + item.name + ']').after("<font class='error' style='font-weight: bold; color: red; margin: 0px 5px;'>" + langs.getText("error_msg","over_cnt") + "</font>");
								}
                     }

                     if (item.value.match(/[\f\r\n\t\v\"]/g) && !dont_save) {
								dont_save = true;
								item.style.outline = "2px solid red";
								item.style.margin = "2px";
								$('#' + ap.render_pgm + ' [name=' + item.name + ']').after("<font class='error' style='font-weight: bold; color: red; margin: 0px 5px;'>" + langs.getText("error_msg","error_mullang") + "</font>");
                     }

                     if (item.className == "chk_selectall") {
                        if (item.checked == false) {
                           item.value = 0;
                        } else {
                           item.value = 1;
                        }
                     }

                     tmp_value = "\"" + item.value + "\"";
                  } else {
                     tmp_value = "\"\"";
                  }
                  pre_msg.push({
                     name: tmp_name,
                     value: tmp_value
                  });
               }
            }
         });
      } else if ($('#' + ap.render_pgm).children().eq(i).is('table')) {
         if (real_pgm == "pgm105" || real_pgm == "pgm227" || real_pgm == "pgm2271" || real_pgm == "pgm443") {
            return true;
         }

         _.each($('#' + ap.render_pgm).children().eq(i).children().children(), function (item, j) {
            //debug_mode.flag && console.log(item);
            skip_flag = false;
            _.each($('#' + ap.render_pgm).children().eq(i).children().children().eq(j).children().children(), function (el) {
               //debug_mode.flag && console.log(el.name);
               if (el.name == "CHKFLAG") {
                  skip_flag = true;
               }

               if (el.className == "chk_checkall" && el.checked == false) {
                  skip_flag = true;
               } else if (el.className == "chk_checkall chk_p52_checkall" && el.checked == false) {
                  skip_flag = true;
               } else if (el.className == "chk_checkall chk_p78_checkall" && el.checked == false) {
                  skip_flag = true;
               } else if (el.className == "chk_checkall chk_p781_checkall" && el.checked == false) {
                  skip_flag = true;
               }

               if (el.type == "radio" && el.checked == false) {
                  skip_flag = true;
               } else if (el.type == "radio" && el.checked == true) {
                  skip_flag = false;
               }

               if (el.disabled) {
                  return true;
               }

               if (el.parentNode.style.display == "none") {
                  return true;
               }

               if (el.type == "button") {
						return true;
               }

               if (el.className == "sel_webauth_changeall") {
                  return true;
               }

               if (real_pgm == "pgm50") {
						if (el.name == "CHKSAVE_KEYSETPWD") {
							return true;
						} else if (el.name == "KEYSETPWD") {
							if ($('#' + ap.render_pgm + ' [name=CHKSAVE_KEYSETPWD]').length) {
								if (!$('#' + ap.render_pgm + ' [name=CHKSAVE_KEYSETPWD]')[0].checked) {
									return true;
								}
							}
						}
					}

               if ((real_pgm == "pgm178") && (active_base != "tab_install_wizard")) {
						if ((el.name == "TDSET_HOUR" || el.name == "TDSET_MIN" || el.name == "TDSET_MON" || el.name == "TDSET_DAY" || el.name == "TDSET_YEAR") && ($('#'+ap.render_pgm+' .chk_p178_dontsave')[0].checked)) {
							return true;
						}
               }

               if (real_pgm == "pgm448" && el.name.match("RCVADMNOTE_")) {
						return true;
               }

               if (!skip_flag) {
                  tmp_name = "";
                  tmp_value = "";
                  if (el.name && (el.name != "undefined")) {
                     tmp_name = "\"" + el.name + "\"";
                     if (el.value) {
                        if (!el.className.match('enable_mullang')) {
									if (el.value.match(/[^a-zA-Z0-9\s\{\}\[\]\/?.,;:|\)*~`!^\-_+┼<>@\#$%&\'"\(\=\\]/g)) {
										dont_save = true;
										el.style.outline = "2px solid red";
										el.style.margin = "2px";
										$('#' + ap.render_pgm + ' [name=' + el.name + ']').after("<font class='error' style='font-weight: bold; color: red;'>" + langs.getText("error_msg","error_mullang") + "</font>");
                           }
                        } else {
									if(el.type != "textarea") {
										if (chkKoreanLength(el.value) > el.maxLength) {
											dont_save = true;
											el.style.outline = "2px solid red";
											el.style.margin = "2px";
											$('#' + ap.render_pgm + ' [name=' + el.name + ']').after("<font class='error' style='font-weight: bold; color: red; margin: 0px 5px;'>" + langs.getText("error_msg","over_cnt") + "</font>");
										}
                           }
                        }

								if ((el.value.match(/[\f\r\t\v]/g) || (((el.type != "textarea") || (el.name == "SIP_DIALTONE") || (el.name == "SIP_DIGITMAP") || (el.name == "SIP_EMGCODE")) && el.value.match(/\n/g))) || (el.value.match(/[\"]/g) && ((el.name != "ADMNOTE_MSG") && (el.name != "ADMNOTE_SUBJECT") && (el.name != "SMSMSG") && (el.name != "SITEDETAIL"))) && !dont_save) {
								/* Multi Language 입력 시 제한되는 문자들을 거르는 부분                                                                                */
								/* 1. 폼피드, 캐리지리턴, Tab키(일반, 세로)                                                                                            */
								/* 2. textarea 태그일 때를 제외한 개행문자(PGM212 Digit Map 관련 Textarea는 개행문자 금지)                                             */
								/* 3. Send Internal/External SMS의 Message 부분과 Administrative Message의 Subject 및 Contents 부분일 때를 제외한 쌍따옴표 및 역슬래시 */
								/* 4. dont_save가 true일 시에는 skip                                                                                                   */
									dont_save = true;
									el.style.outline = "2px solid red";
									el.style.margin = "2px";
									$('#' + ap.render_pgm + ' [name=' + el.name + ']').after("<font class='error' style='font-weight: bold; color: red;'>" + langs.getText("error_msg","error_mullang") + "</font>");
								}

								if (el.name == "KEYSETPWD") {
									if (el.value.match(/[^0-9*#]/g)) {
										dont_save = true;
										el.style.outline = "2px solid red";
										el.style.margin = "2px";
										$('#' + ap.render_pgm + ' [name=' + el.name + ']').after("<font class='error' style='font-weight: bold; color: red;'>" + langs.getText("error_msg","opt_range_error_case2") + "</font>");
									}
								}

                        if (el.className == "chk_selectall" || el.className == "chk_selectall chk_p1010_virmac" || el.className == "chk_selectall chk_p450_select") {
                           if (el.checked == false) {
                              el.value = 0;
                           } else {
                              el.value = 1;
                           }
                        }

                        if ((el.name == "ADMNOTE_MSG") || (el.name == "ADMNOTE_SUBJECT") || (el.name == "SMSMSG") || (el.name == "SITEDETAIL")) {
                        // Send Internal/External SMS의 Message 부분과 Administrative Message의 Subject 및 Contents 부분일 때는 쌍따옴표와 역슬래시를 허용하도록
                        // 쌍따옴표는 \'로, 역슬래시는 \\로 변환 (이후 그대로 저장된 값을 웹서버로부터 받을 때 쌍따옴표는 \"로 역슬래시는 \\로 재변환)
									tmp_value = "\"" + el.value.replace(/"/g,"\\'") + "\"";
								} else if (el.name == "ADD_USERID" || el.name == "ADD_PASSWORD" || el.name == "KEYSETPWD" || el.name.match("ADM227_AUTH") || el.name.match("ADM2271_AUTH") || el.name.match("CI_AUTH") || el.name.match("PPTP_PWD")) {
									if(!offline_mode) {
										tmp_value = "\"" + RSA.encrypt(el.value, $key) + "\"";
									} else {
										tmp_value = "\"" + el.value + "\"";
									}
                        } else {
									tmp_value = "\"" + el.value + "\"";
								}
                     } else {
                        tmp_value = "\"\"";
                     }
                     pre_msg.push({
                        name: tmp_name,
                        value: tmp_value
                     });

							if ((active_base == "tab_install_wizard") && (ap.render_pgm == "iw008") && (el.name == "ADD_PASSWORD")) {
								pre_msg.push({
									name: "\"PRIVILEGE\"",
									value: "\"10\""
								});
							}
                  }
               }
            });
         });
      } else if ($('#' + ap.render_pgm).children().eq(i).is('div') && $('#' + ap.render_pgm).children().eq(i).hasClass('handsontable')) {
			sheet_index = 0;

			_.each(pgm_views[real_pgm].collection.models[0].attributes.elements[0].tab, function(item, i) {
				if (item.edit_table) {
					sheet_index = i;
				}
			});

			_.each($('#' + ap.render_pgm).children().eq(i).children('.wtHolder').find('table.htCore tr'), function (item, j) {
				if (dont_save) {
					return false;
				}
				_.each($('#' + ap.render_pgm).children().eq(i).children('.wtHolder').find('table.htCore tr').eq(j).find('td'), function (cell, k) {
					if (item.firstChild.childNodes[0].checked) {
						if (cell.className.match("htDimmed")) {
							return true;
						} else if (pgm_views[real_pgm].collection.models[0].attributes.elements[0].tab[sheet_index].variable_data && pgm_views[real_pgm].collection.models[0].attributes.elements[0].tab[sheet_index].variable_data[j] && pgm_views[real_pgm].collection.models[0].attributes.elements[0].tab[sheet_index].variable_data[j].tr[k] && pgm_views[real_pgm].collection.models[0].attributes.elements[0].tab[sheet_index].variable_data[j].tr[k].name) {
							if (!pgm_views[real_pgm].collection.models[0].attributes.elements[0].tab[sheet_index].variable_data[j].tr[k].enable_mullang || !info.MULLANG) {
								if ($('#'+ap.render_pgm+' [name=spreadsheet_table]').handsontable('getData')[j-1][k].match(/[^a-zA-Z0-9\s\{\}\[\]\/?.,;:|\)*~`!^\-_+┼<>@\#$%&\'\(\=\\]/g) || $('#'+ap.render_pgm+' [name=spreadsheet_table]').handsontable('getData')[j-1][k].match(/[\f\r\t\v\n\"]/g)) {
									if ($(cell).hasClass('htModified')) {
										$(cell).removeClass('htModified');
									}
									$(cell).addClass('htInvalid').attr('title',langs.getText("error_msg","error_mullang"));
									dont_save = true;
								}
							} else {
								if ($('#'+ap.render_pgm+' [name=spreadsheet_table]').handsontable('getData')[j-1][k].match(/[\f\r\t\v\n\"]/g)) {
									if ($(cell).hasClass('htModified')) {
										$(cell).removeClass('htModified');
									}
									$(cell).addClass('htInvalid').attr('title',langs.getText("error_msg","error_mullang"));
									dont_save = true;
								}
							}

							if (real_pgm == "pgm446" || real_pgm == "pgm4461") {
								if ((k == 1) ||  ((k == 2) && (real_pgm == "pgm446")) || (k == 3) || (k == 4) || (k == 9) || (k == 10)) {
									if ($('#'+ap.render_pgm+' [name=spreadsheet_table]').handsontable('getData')[j-1][k] == "") {
										if ($(cell).hasClass('htModified')) {
											$(cell).removeClass('htModified');
										}
										$(cell).addClass('htInvalid').attr('title',langs.getText("error_msg","novalue"));
										dont_save = true;
									}
								}

								if ((k == 11) || (k == 13)) {
									if (($('#'+ap.render_pgm+' [name=spreadsheet_table]').handsontable('getData')[j-1][k] != langs.getText("common","opt_off")) && ($('#'+ap.render_pgm+' [name=spreadsheet_table]').handsontable('getData')[j-1][k] != langs.getText("common","opt_on"))) {
										if ($(cell).hasClass('htModified')) {
											$(cell).removeClass('htModified');
										}
										$(cell).addClass('htInvalid').attr('title',langs.getText("error_msg","invalid"));
										dont_save = true;
									}
								}

								if (k == 14) {
									if (($('#'+ap.render_pgm+' [name=spreadsheet_table]').handsontable('getData')[j-1][k] != langs.getText("p446","ucs_vstd"))
									&& ($('#'+ap.render_pgm+' [name=spreadsheet_table]').handsontable('getData')[j-1][k] != langs.getText("p446","ucs_nvstd"))
									&& ($('#'+ap.render_pgm+' [name=spreadsheet_table]').handsontable('getData')[j-1][k] != langs.getText("p446","ucs_vprem"))
									&& ($('#'+ap.render_pgm+' [name=spreadsheet_table]').handsontable('getData')[j-1][k] != langs.getText("p446","ucs_nvprem"))
									&& ($('#'+ap.render_pgm+' [name=spreadsheet_table]').handsontable('getData')[j-1][k] != langs.getText("p446","ucs_mobile"))) {
										if ($(cell).hasClass('htModified')) {
											$(cell).removeClass('htModified');
										}
										$(cell).addClass('htInvalid').attr('title',langs.getText("error_msg","invalid"));
										dont_save = true;
									}
								}
							}
							if (real_pgm == "pgm443") {
								if (k == 7) {
									var correct_val = 0;
									for (var i in g_nation_list) {
										if($('#'+ap.render_pgm+' [name=spreadsheet_table]').handsontable('getData')[j-1][k] == g_nation_list[i].option)
										{
											correct_val = 1;
											break;
										}
									}
									if (correct_val != 1) {
										if ($(cell).hasClass('htModified')) {
											$(cell).removeClass('htModified');
										}
										$(cell).addClass('htInvalid').attr('title',langs.getText("error_msg","invalid"));
										dont_save = true;
									}
								}
								if (k == 8) {
									var correct_val = 0;
									for (var i in g_lang_list) {
										if($('#'+ap.render_pgm+' [name=spreadsheet_table]').handsontable('getData')[j-1][k] == g_lang_list[i].option)
										{
											correct_val = 1;
											break;
										}
									}
									if (correct_val != 1) {
										if ($(cell).hasClass('htModified')) {
											$(cell).removeClass('htModified');
										}
										$(cell).addClass('htInvalid').attr('title',langs.getText("error_msg","invalid"));
										dont_save = true;
									}
								}
							}
							if (real_pgm == "pgm206") {
								if (k == 5) {
									var correct_val = 0;
									for (var i in g_pgm206_1) {
										if($('#'+ap.render_pgm+' [name=spreadsheet_table]').handsontable('getData')[j-1][k] == g_pgm206_1[i].option)
										{
											correct_val = 1;
											break;
										}
									}
									if (correct_val != 1) {
										if ($(cell).hasClass('htModified')) {
											$(cell).removeClass('htModified');
										}
										$(cell).addClass('htInvalid').attr('title',langs.getText("error_msg","invalid"));
										dont_save = true;
									}
								} else if (k == 6) {
									var correct_val = 0;
									for (var i in g_pgm206_2) {
										if($('#'+ap.render_pgm+' [name=spreadsheet_table]').handsontable('getData')[j-1][k] == g_pgm206_2[i].option)
										{
											correct_val = 1;
											break;
										}
									}
									if (correct_val != 1) {
										if ($(cell).hasClass('htModified')) {
											$(cell).removeClass('htModified');
										}
										$(cell).addClass('htInvalid').attr('title',langs.getText("error_msg","invalid"));
										dont_save = true;
									}
								} else if (k == 8) {
									var correct_val = 0;
									for (var i in g_pgm206_3) {
										if($('#'+ap.render_pgm+' [name=spreadsheet_table]').handsontable('getData')[j-1][k] == g_pgm206_3[i].option)
										{
											correct_val = 1;
											break;
										}
									}
									if (correct_val != 1) {
										if ($(cell).hasClass('htModified')) {
											$(cell).removeClass('htModified');
										}
										$(cell).addClass('htInvalid').attr('title',langs.getText("error_msg","invalid"));
										dont_save = true;
									}
								} else if (k == 7) {
									var correct_val = 0;
									for (var i in g_onoff) {
										if($('#'+ap.render_pgm+' [name=spreadsheet_table]').handsontable('getData')[j-1][k] == g_onoff[i].option)
										{
											correct_val = 1;
											break;
										}
									}
									if (correct_val != 1) {
										if ($(cell).hasClass('htModified')) {
											$(cell).removeClass('htModified');
										}
										$(cell).addClass('htInvalid').attr('title',langs.getText("error_msg","invalid"));
										dont_save = true;
									}
								}
							}
							if ((real_pgm == "pgm115")||(real_pgm == "pgm239")) {
								if (k == 1) {
									var correct_val = 0;
									for (var i in g_pgm115) {
										if($('#'+ap.render_pgm+' [name=spreadsheet_table]').handsontable('getData')[j-1][k] == g_pgm115[i].option)
										{
											correct_val = 1;
											break;
										}
									}
									if (correct_val != 1) {
										if ($(cell).hasClass('htModified')) {
											$(cell).removeClass('htModified');
										}
										$(cell).addClass('htInvalid').attr('title',langs.getText("error_msg","invalid"));
										dont_save = true;
									}
								}
							}
							if (real_pgm == "pgm442") {
								if (k == 4) {
									var correct_val = 0;
									for (var i in g_nation_list) {
										if($('#'+ap.render_pgm+' [name=spreadsheet_table]').handsontable('getData')[j-1][k] == g_nation_list[i].option)
										{
											correct_val = 1;
											break;
										}
									}
									if (correct_val != 1) {
										if ($(cell).hasClass('htModified')) {
											$(cell).removeClass('htModified');
										}
										$(cell).addClass('htInvalid').attr('title',langs.getText("error_msg","invalid"));
										dont_save = true;
									}
								}
							}
							if (real_pgm == "pgm231") {
								if ((k==1)||(k==4)||(k==7)||(k==10)) {
									var correct_val = 0;
									for (var i in g_pgm231_1) {
										if($('#'+ap.render_pgm+' [name=spreadsheet_table]').handsontable('getData')[j-1][k] == g_pgm231_1[i].option)
										{
											correct_val = 1;
											break;
										}
									}
									if (correct_val != 1) {
										if ($(cell).hasClass('htModified')) {
											$(cell).removeClass('htModified');
										}
										$(cell).addClass('htInvalid').attr('title',langs.getText("error_msg","invalid"));
										dont_save = true;
									}
								} else if (k==15) {
									var correct_val = 0;
									for (var i in g_pgm231_2) {
										if($('#'+ap.render_pgm+' [name=spreadsheet_table]').handsontable('getData')[j-1][k] == g_pgm231_2[i].option)
										{
											correct_val = 1;
											break;
										}
									}
									if (correct_val != 1) {
										if ($(cell).hasClass('htModified')) {
											$(cell).removeClass('htModified');
										}
										$(cell).addClass('htInvalid').attr('title',langs.getText("error_msg","invalid"));
										dont_save = true;
									}
								} else if (k==13) {
									var correct_val = 0;
									for (var i in g_onoff) {
										if($('#'+ap.render_pgm+' [name=spreadsheet_table]').handsontable('getData')[j-1][k] == g_onoff[i].option)
										{
											correct_val = 1;
											break;
										}
									}
									if (correct_val != 1) {
										if ($(cell).hasClass('htModified')) {
											$(cell).removeClass('htModified');
										}
										$(cell).addClass('htInvalid').attr('title',langs.getText("error_msg","invalid"));
										dont_save = true;
									}
								}
							}
							if (real_pgm == "pgm262") {
								if (k == 1) {
									var correct_val = 0;
									for (var i in g_pgm262) {
										if($('#'+ap.render_pgm+' [name=spreadsheet_table]').handsontable('getData')[j-1][k] == g_pgm262[i].option)
										{
											correct_val = 1;
											break;
										}
									}
									if (correct_val != 1) {
										if ($(cell).hasClass('htModified')) {
											$(cell).removeClass('htModified');
										}
										$(cell).addClass('htInvalid').attr('title',langs.getText("error_msg","invalid"));
										dont_save = true;
									}
								}
							}
							if (real_pgm == "pgm324") {
								if ((k==1)||(k==15)) {
									var correct_val = 0;
									for (var i in g_pgm324_1) {
										if($('#'+ap.render_pgm+' [name=spreadsheet_table]').handsontable('getData')[j-1][k] == g_pgm324_1[i].option)
										{
											correct_val = 1;
											break;
										}
									}
									if (correct_val != 1) {
										if ($(cell).hasClass('htModified')) {
											$(cell).removeClass('htModified');
										}
										$(cell).addClass('htInvalid').attr('title',langs.getText("error_msg","invalid"));
										dont_save = true;
									}
								} else if ((k==13)||(k==14)||(k==18)||(k==19)) {
									var correct_val = 0;
									for (var i in g_noyes) {
										if($('#'+ap.render_pgm+' [name=spreadsheet_table]').handsontable('getData')[j-1][k] == g_noyes[i].option)
										{
											correct_val = 1;
											break;
										}
									}
									if (correct_val != 1) {
										if ($(cell).hasClass('htModified')) {
											$(cell).removeClass('htModified');
										}
										$(cell).addClass('htInvalid').attr('title',langs.getText("error_msg","invalid"));
										dont_save = true;
									}
								} else if ((k==16)||(k==17)||(k==22)) {
									var correct_val = 0;
									for (var i in g_onoff) {
										if($('#'+ap.render_pgm+' [name=spreadsheet_table]').handsontable('getData')[j-1][k] == g_onoff[i].option)
										{
											correct_val = 1;
											break;
										}
									}
									if (correct_val != 1) {
										if ($(cell).hasClass('htModified')) {
											$(cell).removeClass('htModified');
										}
										$(cell).addClass('htInvalid').attr('title',langs.getText("error_msg","invalid"));
										dont_save = true;
									}
								} else if (k==26) {
									var correct_val = 0;
									for (var i in g_pgm324_2) {
										if($('#'+ap.render_pgm+' [name=spreadsheet_table]').handsontable('getData')[j-1][k] == g_pgm324_2[i].option)
										{
											correct_val = 1;
											break;
										}
									}
									if (correct_val != 1) {
										if ($(cell).hasClass('htModified')) {
											$(cell).removeClass('htModified');
										}
										$(cell).addClass('htInvalid').attr('title',langs.getText("error_msg","invalid"));
										dont_save = true;
									}
								}
							}
							tmp_name = "\""+pgm_views[real_pgm].collection.models[0].attributes.elements[0].tab[sheet_index].variable_data[j].tr[k].name+"\"";
							tmp_value = "\""+$.trim(cell.firstChild.nodeValue)+"\"";
							if ((real_pgm == "pgm446" || real_pgm == "pgm4461") && ((k == 11) || (k == 13) || (k == 14))) {
								if ($.trim(cell.firstChild.data) == langs.getText("common","opt_off")) {
									tmp_value = "\"0\"";
								} else if ($.trim(cell.firstChild.data) == langs.getText("common","opt_on")) {
									tmp_value = "\"1\"";
								} else if ($.trim(cell.firstChild.data) == langs.getText("p446","ucs_vstd")) {
									tmp_value = "\"0\"";
								} else if ($.trim(cell.firstChild.data) == langs.getText("p446","ucs_nvstd")) {
									tmp_value = "\"1\"";
								} else if ($.trim(cell.firstChild.data) == langs.getText("p446","ucs_vprem")) {
									tmp_value = "\"2\"";
								} else if ($.trim(cell.firstChild.data) == langs.getText("p446","ucs_nvprem")) {
									tmp_value = "\"3\"";
								} else if ($.trim(cell.firstChild.data) == langs.getText("p446","ucs_mobile")) {
									tmp_value = "\"4\"";
								}
							} else if ((real_pgm == "pgm443") && (k == 7)) {
								for (var i in g_nation_list) {
									if($.trim(cell.firstChild.data) == g_nation_list[i].option)
									{
										tmp_value = "\""+g_nation_list[i].value+"\"";
										break;
									}
								}
							}else if ((real_pgm == "pgm443") && (k == 8)) {
								for (var i in g_lang_list) {
									if($.trim(cell.firstChild.data) == g_lang_list[i].option)
									{
										tmp_value = "\""+g_lang_list[i].value+"\"";
										break;
									}
								}
							}else if ((real_pgm == "pgm442") && (k == 4)) {
								for (var i in g_nation_list) {
									if($.trim(cell.firstChild.data) == g_nation_list[i].option)
									{
										tmp_value = "\""+g_nation_list[i].value+"\"";
										break;
									}
								}
							}else if (((real_pgm == "pgm115")||(real_pgm == "pgm239")) && (k == 1)) {
								if ($.trim(cell.firstChild.data) == langs.getText("common","not_assigned")) {
									tmp_value = "\"0\"";
								} else if ($.trim(cell.firstChild.data) == langs.getText("common","co_line")) {
									tmp_value = "\"1\"";
								} else if ($.trim(cell.firstChild.data) == langs.getText("common","cog")) {
									tmp_value = "\"2\"";
								} else if ($.trim(cell.firstChild.data) == langs.getText("common","loop")) {
									tmp_value = "\"3\"";
								} else if ($.trim(cell.firstChild.data) == langs.getText("common","sta_num")) {
									tmp_value = "\"4\"";
								} else if ($.trim(cell.firstChild.data) == langs.getText("common","prog_numplan")) {
									tmp_value = "\"5\"";
								} else if ($.trim(cell.firstChild.data) == langs.getText("common","prog_pgmcode")) {
									tmp_value = "\"6\"";
								} else if ($.trim(cell.firstChild.data) == langs.getText("common","station_speed")) {
									tmp_value = "\"7\"";
								} else if ($.trim(cell.firstChild.data) == langs.getText("common","system_speed")) {
									tmp_value = "\"8\"";
								} else if ($.trim(cell.firstChild.data) == langs.getText("common","net_sta_num")) {
									tmp_value = "\"9\"";
								} else if ($.trim(cell.firstChild.data) == langs.getText("common","uloop")) {
									tmp_value = "\"10\"";
                                                                } else if ($.trim(cell.firstChild.data) == langs.getText("common","dial_digit")) {
                                                                        tmp_value = "\"11\"";
								}
							} else if ((real_pgm == "pgm262") && (k == 1)) {
								if ($.trim(cell.firstChild.data) == langs.getText("common","not_assigned")) {
									tmp_value = "\"0\"";
								} else if ($.trim(cell.firstChild.data) == langs.getText("common","co_line")) {
									tmp_value = "\"1\"";
								} else if ($.trim(cell.firstChild.data) == langs.getText("common","cog")) {
									tmp_value = "\"2\"";
								} else if ($.trim(cell.firstChild.data) == langs.getText("common","loop")) {
									tmp_value = "\"3\"";
								} else if ($.trim(cell.firstChild.data) == langs.getText("common","transit_out")) {
									tmp_value = "\"4\"";
                                                                } else if ($.trim(cell.firstChild.data) == langs.getText("common","net_sta_num")) {
                                                                        tmp_value = "\"5\"";
								}
							} else if ((real_pgm == "pgm206") && (k == 5)) {
								if ($.trim(cell.firstChild.data) == langs.getText("common","opt_unknown")) {
									tmp_value = "\"0\"";
								} else if ($.trim(cell.firstChild.data) == langs.getText("common","international")) {
									tmp_value = "\"1\"";
								} else if ($.trim(cell.firstChild.data) == langs.getText("common","national")) {
									tmp_value = "\"2\"";
								} else if ($.trim(cell.firstChild.data) == langs.getText("p206","opt_prefix_ntype_ns")) {
									tmp_value = "\"3\"";
								} else if ($.trim(cell.firstChild.data) == langs.getText("common","subscriber")) {
									tmp_value = "\"4\"";
								} else if ($.trim(cell.firstChild.data) == langs.getText("common","opt_abbreviated")) {
									tmp_value = "\"5\"";
								} else if ($.trim(cell.firstChild.data) == langs.getText("common","reserved")) {
									tmp_value = "\"6\"";
								}
							} else if ((real_pgm == "pgm206") && (k == 6)) {
								if ($.trim(cell.firstChild.data) == langs.getText("common","opt_unknown")) {
									tmp_value = "\"0\"";
								} else if ($.trim(cell.firstChild.data) == langs.getText("common","opt_isdn_telephony")) {
									tmp_value = "\"1\"";
								} else if ($.trim(cell.firstChild.data) == langs.getText("common","data_numbering")) {
									tmp_value = "\"2\"";
								} else if ($.trim(cell.firstChild.data) == langs.getText("common","telex")) {
									tmp_value = "\"3\"";
								} else if ($.trim(cell.firstChild.data) == langs.getText("common","national_std")) {
									tmp_value = "\"4\"";
								} else if ($.trim(cell.firstChild.data) == langs.getText("common","txt_private")) {
									tmp_value = "\"5\"";
								} else if ($.trim(cell.firstChild.data) == langs.getText("common","reserved")) {
									tmp_value = "\"6\"";
								}
							} else if ((real_pgm == "pgm206") && ((k == 7)||(k == 11))) {
								if ($.trim(cell.firstChild.data) == langs.getText("common","opt_off")) {
									tmp_value = "\"0\"";
								} else if ($.trim(cell.firstChild.data) == langs.getText("common","opt_on")) {
									tmp_value = "\"1\"";
								}
							} else if ((real_pgm == "pgm206") && (k == 8)) {
								if ($.trim(cell.firstChild.data) == langs.getText("common","opt_unknown")) {
									tmp_value = "\"0\"";
								} else if ($.trim(cell.firstChild.data) == langs.getText("common","local")) {
									tmp_value = "\"1\"";
								} else if ($.trim(cell.firstChild.data) == langs.getText("common","long_distance")) {
									tmp_value = "\"2\"";
								} else if ($.trim(cell.firstChild.data) == langs.getText("common","international")) {
									tmp_value = "\"3\"";
								} else if ($.trim(cell.firstChild.data) == langs.getText("p206","opt_prefix_ctype_mobile")) {
									tmp_value = "\"4\"";
								} else if ($.trim(cell.firstChild.data) == langs.getText("common","reserved")) {
									tmp_value = "\"6\"";
								}
							} else if ((real_pgm == "pgm324") && ((k == 1)||(k == 15))) {
								if ($.trim(cell.firstChild.data) == langs.getText("common","net")) {
									tmp_value = "\"0\"";
								} else if ($.trim(cell.firstChild.data) == langs.getText("common","pstn")) {
									tmp_value = "\"1\"";
								}
							} else if ((real_pgm == "pgm324") && ((k == 13)||(k == 14)||(k == 18)||(k == 19))) {
								if ($.trim(cell.firstChild.data) == langs.getText("common","opt_no")) {
									tmp_value = "\"0\"";
								} else if ($.trim(cell.firstChild.data) == langs.getText("common","opt_yes")) {
									tmp_value = "\"1\"";
								}
							} else if ((real_pgm == "pgm324") && ((k == 16)||(k == 17)||(k == 18)||(k == 22))) {
								if ($.trim(cell.firstChild.data) == langs.getText("common","opt_off")) {
									tmp_value = "\"0\"";
								} else if ($.trim(cell.firstChild.data) == langs.getText("common","opt_on")) {
									tmp_value = "\"1\"";
								}
							} else if ((real_pgm == "pgm324") && (k == 26)) {
								if ($.trim(cell.firstChild.data) == langs.getText("common","opt_off")) {
									tmp_value = "\"0\"";
								} else if ($.trim(cell.firstChild.data) == langs.getText("p324","net_displayie")) {
									tmp_value = "\"1\"";
								}
							} else if ((real_pgm == "pgm231") && ((k == 1)||(k == 4)||(k == 7)||(k == 10))) {
								if ($.trim(cell.firstChild.data) == langs.getText("common","not_assigned")) {
									tmp_value = "\"0\"";
								} else if ($.trim(cell.firstChild.data) == langs.getText("common","info_stn")) {
									tmp_value = "\"1\"";
								} else if ($.trim(cell.firstChild.data) == langs.getText("common","station_group")) {
									tmp_value = "\"2\"";
								} else if ($.trim(cell.firstChild.data) == langs.getText("common","system_speed")) {
									tmp_value = "\"3\"";
								} else if ($.trim(cell.firstChild.data) == langs.getText("common","pabx_trans_sysspd")) {
									tmp_value = "\"4\"";
								} else if ($.trim(cell.firstChild.data) == langs.getText("common","vsf_annc")) {
									tmp_value = "\"5\"";
								} else if ($.trim(cell.firstChild.data) == langs.getText("common","vsf_annc_and_dis")) {
									tmp_value = "\"6\"";
								} else if ($.trim(cell.firstChild.data) == langs.getText("common","networking")) {
									tmp_value = "\"7\"";
								} else if ($.trim(cell.firstChild.data) == langs.getText("common","opt_confroom")) {
									tmp_value = "\"8\"";
								} else if ($.trim(cell.firstChild.data) == langs.getText("common","internal_page")) {
									tmp_value = "\"9\"";
								} else if ($.trim(cell.firstChild.data) == langs.getText("common","ext_page")) {
									tmp_value = "\"10\"";
								} else if ($.trim(cell.firstChild.data) == langs.getText("common","all_call_page")) {
									tmp_value = "\"11\"";
								} else if ($.trim(cell.firstChild.data) == langs.getText("common","vm_stagrp")) {
									tmp_value = "\"12\"";
								} else if ($.trim(cell.firstChild.data) == langs.getText("common","iclid_tbl")) {
									tmp_value = "\"13\"";
								} else if ($.trim(cell.firstChild.data) == langs.getText("common","opt_comdir")) {
									tmp_value = "\"14\"";
								} else if ($.trim(cell.firstChild.data) == langs.getText("common","record_vm_greet")) {
									tmp_value = "\"15\"";
								} else if ($.trim(cell.firstChild.data) == langs.getText("common","ucs_sys_conf_join")) {
									tmp_value = "\"16\"";
								}
 							} else if ((real_pgm == "pgm231") && (k == 13)) {
								if ($.trim(cell.firstChild.data) == langs.getText("common","opt_off")) {
									tmp_value = "\"0\"";
								} else if ($.trim(cell.firstChild.data) == langs.getText("common","opt_on")) {
									tmp_value = "\"1\"";
								}
							} else if ((real_pgm == "pgm231") && (k == 15)) {
								if ($.trim(cell.firstChild.data) == langs.getText("p231","opt_fdc_moh_cohold")) {
									tmp_value = "\"0\"";
								} else if (($.trim(cell.firstChild.data.substring(0, langs.getText("common","internal_music").length)) == langs.getText("common","internal_music")) ||
									($.trim(cell.firstChild.data.substring(0, langs.getText("common","intext_music").length)) == langs.getText("common","intext_music"))) {
									tmp_value = "\"1\"";
								} else if ($.trim(cell.firstChild.data.substring(0, langs.getText("common","extmusic").length)) == langs.getText("common","extmusic")) {
									tmp_value = "\"2\"";
								} else if ($.trim(cell.firstChild.data) == langs.getText("common","vsf_moh")) {
									tmp_value = "\"3\"";
								} else if ($.trim(cell.firstChild.data) == (langs.getText("common","slt_moh")+"1")) {
									tmp_value = "\"4\"";
								} else if ($.trim(cell.firstChild.data) == (langs.getText("common","slt_moh")+"2")) {
									tmp_value = "\"5\"";
								} else if ($.trim(cell.firstChild.data) == (langs.getText("common","slt_moh")+"3")) {
									tmp_value = "\"6\"";
								} else if ($.trim(cell.firstChild.data) == (langs.getText("common","slt_moh")+"4")) {
									tmp_value = "\"7\"";
								} else if ($.trim(cell.firstChild.data) == (langs.getText("common","slt_moh")+"5")) {
									tmp_value = "\"8\"";
								} else if ($.trim(cell.firstChild.data) == (langs.getText("common","vsf_moh")+"2")) {
									tmp_value = "\"9\"";
								} else if ($.trim(cell.firstChild.data) == (langs.getText("common","vsf_moh")+"3")) {
									tmp_value = "\"10\"";
								}
							} else if (((real_pgm == "pgm227") || (real_pgm == "pgm2271")) && (k == 1)) {
								if(!offline_mode) {
									if ($.trim(cell.firstChild.nodeValue)) {
										tmp_value = "\"" + RSA.encrypt($.trim(cell.firstChild.nodeValue), $key) + "\"";
									} else {
										tmp_value = "\"\"";
									}
								} else {
									tmp_value = "\"" + $.trim(cell.firstChild.nodeValue) + "\"";
								}
							} else if ((real_pgm == "pgm1010") && (k == 2)) {
							   var idFound = false;
							   for (var i in g_stnid) {
									if($.trim(cell.firstChild.data) == g_stnid[i].option)
									{
										tmp_value = "\""+g_stnid[i].value+"\"";
										idFound = true;
										break;
									}
								}
								if (!idFound) {
									if($.trim(cell.firstChild.data) == g_vmex.option) {
											tmp_value = "\""+g_vmex.value+"\"";
									} else if($.trim(cell.firstChild.data) == g_ucs.option) {
											tmp_value = "\""+g_ucs.value+"\"";
									}
								}
							} else if ((real_pgm == "pgm1010") && (k == 7)) {
								if ($.trim(cell.firstChild.data) == langs.getText("common","opt_no")) {
									tmp_value = "\"0\"";
								} else if ($.trim(cell.firstChild.data) == langs.getText("common","opt_yes")) {
									tmp_value = "\"1\"";
								}
							}
                     pre_msg.push({
                        name: tmp_name,
                        value: tmp_value
                     });
						}
					}
				});
			});
      }
   });

   if (real_pgm == "pgm144") {
      var remove_msg = "";

      for (var i = 0; i < $('#' + ap.render_pgm + ' .chk_checkall').length; i++) {
         if (!$('#' + ap.render_pgm + ' .chk_checkall:eq(' + i + ')').is(':checked')) {
            if (i == 0) {
               remove_msg = "COL_DAY_";
            } else if (i == 1) {
               remove_msg = "COL_NIGHT_";
            } else if (i == 2) {
               remove_msg = "COL_TR_";
            }

            for (var j = 0; j < pre_msg.length; j++) {
               if (pre_msg[j]) {
                  if (pre_msg[j].name.match(remove_msg)) {
                     pre_msg.splice(j, 1);
                     j = -1;
                  }
               }
            }
         }
      }
   }

   if (real_pgm == "pgm160") {
      if (($('#' + ap.render_pgm + ' [name=SYS_TLSWEB]').length && $('#' + ap.render_pgm + ' [name=SYS_WEBSVRPORT]').length) && (($('#' + ap.render_pgm + ' [name=SYS_TLSWEB]').val() != pgm_name_maps["pgm160"]["SYS_TLSWEB"].value) && ($('#' + ap.render_pgm + ' [name=SYS_WEBSVRPORT]').val() != pgm_name_maps["pgm160"]["SYS_WEBSVRPORT"].value))) {
         restart_msg = langs.getText("p160","alert_porttlsch");
      } else if ($('#' + ap.render_pgm + ' [name=SYS_TLSWEB]').length && ($('#' + ap.render_pgm + ' [name=SYS_TLSWEB]').val() != pgm_name_maps["pgm160"]["SYS_TLSWEB"].value)) {
         restart_msg = langs.getText("p160","alert_tlsch");
      } else if ($('#' + ap.render_pgm + ' [name=SYS_WEBSVRPORT]').length && ($('#' + ap.render_pgm + ' [name=SYS_WEBSVRPORT]').val() != pgm_name_maps["pgm160"]["SYS_WEBSVRPORT"].value)) {
         restart_msg = langs.getText("p160","alert_portch");
      }

      if (!offline_mode && restart_msg) {
         $('<div />').html(restart_msg + "<br>" + langs.getText("p160","confirm_restart")).dialog({
            modal: true,
            closeOnEscape: false,
            title: langs.getText("common","notification"),
            open: function (event, ui) {
               $(".ui-dialog-titlebar-close").hide();
            },
            buttons: [
					{
						text: langs.getText("common","simple_okay"),
						click: function () {
							send_msg = "{";
							_.each(pre_msg, function (item, i) {
								send_msg += item.name + ":" + item.value;
								if (i !== pre_msg.length - 1) {
									send_msg += ",";
								}
							});
							send_msg += "}";

							debug_mode.flag && console.log(range_type);
							debug_mode.flag && console.log(range);
							debug_mode.flag && console.log(send_msg);

							$('#' + ap.render_pgm).html("");
							packet.setPacket(1, range_type, range, send_msg);
							pgm_models.get_model(ap.render_pgm, false, packet);

							$(this).dialog("destroy");
						}
					},
					{
						text: langs.getText("common","cancel"),
						click: function () {
							$(this).dialog("destroy");
						}
					}
            ]
         });
         return false;
      }
   }

   if ($(this).hasClass('btn_p215_del')) {
      var checkFlag = true;
      tmp_name = "";
      tmp_value = "";

      if ($('#' + ap.render_pgm + ' .chk_checkall').length > 0) {
         _.each($('#' + ap.render_pgm + ' .chk_checkall'), function (item) {
            if (!item.checked) {
               checkFlag = false;
            }
         });
      } else {
         checkFlag = false;
      }

      if (checkFlag) {
         $('<div />').html(langs.getText("p215","confirm_delete")).dialog({
            modal: true,
            closeOnEscape: false,
            title: langs.getText("common","notification"),
            open: function (event, ui) {
               $(".ui-dialog-titlebar-close").hide();
            },
            buttons: [
					{
						text: langs.getText("common","simple_okay"),
						click: function () {
							tmp_name = "\"VMEXDEL\"";
							tmp_value = "\"\"";
							pre_msg.push({
								name: tmp_name,
								value: tmp_value
							});

							send_msg = "{";
							_.each(pre_msg, function (item, i) {
								send_msg += item.name + ":" + item.value;
								if (i !== pre_msg.length - 1) {
									send_msg += ",";
								}
							});
							send_msg += "}";

							debug_mode.flag && console.log(range_type);
							debug_mode.flag && console.log(range);
							debug_mode.flag && console.log(send_msg);

							$('#' + ap.render_pgm).html("");
							packet.setPacket(1, range_type, range, send_msg);
							pgm_models.get_model(ap.render_pgm, false, packet);

							$(this).dialog("destroy");
						}
					},
					{
						text: langs.getText("common","cancel"),
						click: function () {
							$(this).dialog("destroy");
						}
					}
            ]
         });
         return false;
      } else {
         tmp_name = "\"VMEXDEL\"";
         tmp_value = "\"\"";
      }

      if (tmp_name && tmp_value) {
         pre_msg.push({
            name: tmp_name,
            value: tmp_value
         });
      }
   }

   if (real_pgm == "pgm490") {
		if ($('#' + ap.render_pgm + ' [name=WTU_OPTION]').length) {
			if ($('#' + ap.render_pgm + ' [name=WTU_OPTION]:checked').val() == "0") {
				$('<div />').html(langs.getText("p490","confirm_initialize")).dialog({
					modal: true,
					closeOnEscape: false,
					title: langs.getText("common","notification"),
					open: function (event, ui) {
						$(".ui-dialog-titlebar-close").hide();
					},
					buttons: [
						{
							text: langs.getText("common","simple_okay"),
							click: function () {
								send_msg = "{";
								_.each(pre_msg, function (item, i) {
									send_msg += item.name + ":" + item.value;
									if (i !== pre_msg.length - 1) {
										send_msg += ",";
									}
								});
								send_msg += "}";

								debug_mode.flag && console.log(range_type);
								debug_mode.flag && console.log(range);
								debug_mode.flag && console.log(send_msg);

								$('#' + ap.render_pgm).html("");
								packet.setPacket(1, range_type, range, send_msg);
								pgm_models.get_model(ap.render_pgm, false, packet);

								$(this).dialog("destroy");
							}
						},
						{
							text: langs.getText("common","cancel"),
							click: function () {
								$(this).dialog("destroy");
							}
						}
					]
				});
				return false;
			}
      }
   }

   if ((real_pgm == "pgm450") && $("#"+ap.render_pgm+" [name=DBIN_ALL]").length && $("#"+ap.render_pgm+" [name=DBIN_ALL]")[0].checked) {
      $('<div />').html(langs.getText("p450","confirm_init")).dialog({
         modal: true,
         closeOnEscape: false,
         title: langs.getText("common","notification"),
         open: function (event, ui) {
            $(".ui-dialog-titlebar-close").hide();
         },
         buttons: [
				{
					text: langs.getText("common","simple_okay"),
					click: function () {
						send_msg = "{";
						_.each(pre_msg, function (item, i) {
							send_msg += item.name + ":" + item.value;
							if (i !== pre_msg.length - 1) {
								send_msg += ",";
							}
						});
						send_msg += "}";

						debug_mode.flag && console.log(range_type);
						debug_mode.flag && console.log(range);
						debug_mode.flag && console.log(send_msg);

						$('#' + ap.render_pgm).html("");
						packet.setPacket(1, range_type, range, send_msg);
						pgm_models.get_model(ap.render_pgm, false, packet);

						$(this).dialog("destroy");
					}
				},
				{
					text: langs.getText("common","cancel"),
					click: function () {
						$(this).dialog("destroy");
					}
				}
			]
      });
      return false;
   }

   if ($(this).hasClass("btn_p6800_logout")) {
      if (pre_msg.length > 0) {
         $('<div />').html(langs.getText("p6800","confirm_logout")).dialog({
            modal: true,
            closeOnEscape: false,
            title: langs.getText("common","notification"),
            open: function (event, ui) {
               $(".ui-dialog-titlebar-close").hide();
            },
            buttons: [
					{
						text: langs.getText("common","simple_okay"),
						click: function () {
							pre_msg.push({
								name: "\"LOGOUT_USER\"",
								value: "\"\""
							});
							send_msg = "{";
							_.each(pre_msg, function (item, i) {
								send_msg += item.name + ":" + item.value;
								if (i !== pre_msg.length - 1) {
									send_msg += ",";
								}
							});
							send_msg += "}";

							debug_mode.flag && console.log(range_type);
							debug_mode.flag && console.log(range);
							debug_mode.flag && console.log(send_msg);

							$('#' + ap.render_pgm).html("");
							packet.setPacket(1, range_type, range, send_msg);
							pgm_models.get_model(ap.render_pgm, false, packet);

							$(this).dialog("destroy");
						}
					},
					{
						text: langs.getText("common","cancel"),
						click: function () {
							$(this).dialog("destroy");
						}
					}
				]
         });
         return false;
      }
   }

   if (real_pgm == "pgm57") {
      $('<div />').html(langs.getText("common","confirm_delete")).dialog({
         modal: true,
         closeOnEscape: false,
         title: langs.getText("common","notification"),
         open: function (event, ui) {
            $(".ui-dialog-titlebar-close").hide();
         },
         buttons: [
				{
					text: langs.getText("common","simple_okay"),
					click: function () {
						send_msg = "{";
						_.each(pre_msg, function (item, i) {
							send_msg += item.name + ":" + item.value;
							if (i !== pre_msg.length - 1) {
								send_msg += ",";
							}
						});
						send_msg += "}";

						debug_mode.flag && console.log(range_type);
						debug_mode.flag && console.log(range);
						debug_mode.flag && console.log(send_msg);

						$('#' + ap.render_pgm).html("");
						packet.setPacket(1, range_type, range, send_msg);
						pgm_models.get_model(ap.render_pgm, false, packet);

						$(this).dialog("destroy");
					}
				},
				{
					text: langs.getText("common","cancel"),
					click: function () {
						$(this).dialog("destroy");
					}
				}
         ]
      });
      return false;
   }

   if (real_pgm == "pgm81") {
      $('<div />').html(langs.getText("common","confirm_delete")).dialog({
         modal: true,
         closeOnEscape: false,
         title: langs.getText("common","notification"),
         open: function (event, ui) {
            $(".ui-dialog-titlebar-close").hide();
         },
         buttons: [
				{
					text: langs.getText("common","simple_okay"),
					click: function () {
						send_msg = "{";
						_.each(pre_msg, function (item, i) {
							send_msg += item.name + ":" + item.value;
							if (i !== pre_msg.length - 1) {
								send_msg += ",";
							}
						});
						send_msg += "}";

						debug_mode.flag && console.log(range_type);
						debug_mode.flag && console.log(range);
						debug_mode.flag && console.log(send_msg);

						$('#' + ap.render_pgm).html("");
						packet.setPacket(1, range_type, range, send_msg);
						pgm_models.get_model(ap.render_pgm, false, packet);

						$(this).dialog("destroy");
					}
				},
				{
					text: langs.getText("common","cancel"),
					click: function () {
						$(this).dialog("destroy");
					}
				}
			]
      });
      return false;
   }

   if (dont_save) {
		if ($('#'+ap.render_pgm+' .error').length) {
			$('#'+ap.render_pgm+' .error').siblings('input:first').focus();
		} else if ($('#'+ap.render_pgm+' [name=spreadsheet_table]').children('.wtHolder').find('table.htCore .htInvalid').length) {
			for (var i=0; i<$('#'+ap.render_pgm+' [name=spreadsheet_table]').children('.wtHolder').find('table.htCore tr').length; i++) {
				for (var j=0; j<$('#'+ap.render_pgm+' [name=spreadsheet_table]').children('.wtHolder').find('table.htCore tr:eq('+i+') td').length; j++) {
					if ($('#'+ap.render_pgm+' [name=spreadsheet_table]').children('.wtHolder').find('table.htCore tr:eq('+i+') td:eq('+j+')').hasClass('htInvalid')) {
						$('#'+ap.render_pgm+' [name=spreadsheet_table]').handsontable('selectCell', i-1, j);
						return false;
					}
				}
			}
		}
		return false;
   }

   send_msg = "{";
   _.each(pre_msg, function (item, i) {
      send_msg += item.name + ":" + item.value;
      if (i !== pre_msg.length - 1) {
         send_msg += ",";
      }
   });
   send_msg += "}";

   debug_mode.flag && console.log(range_type);
   debug_mode.flag && console.log(range);
   debug_mode.flag && console.log(send_msg);

	if (real_pgm != "pgm52") {
		$('#' + ap.render_pgm).html("");
   }
   packet.setPacket(1, range_type, range, send_msg);
	pgm_models.get_model(ap.render_pgm, false, packet);
});

function chkKoreanLength(str) {
   var length = 0;

   for (var i = 0; i < str.length; i++) {
      if ((str.charCodeAt(i) > 0x3130 && str.charCodeAt(i) < 0x318F) || (str.charCodeAt(i) >= 0xAC00 && str.charCodeAt(i) <= 0xD7A3)) {
         length += 2;
      } else {
         length++;
      }
   }

   return length;
}

function chkKoreanOfLength(str, maxlen) {
   var num = 0;
   var strout = "";
   for (var i = 0; i < maxlen; i++) {
		if ((str.charCodeAt(i) > 0x3130 && str.charCodeAt(i) < 0x318F) || (str.charCodeAt(i) >= 0xAC00 && str.charCodeAt(i) <= 0xD7A3)) {
			num++;
      }
		if (i+num < maxlen)
			strout += str[i];		
   }
	return strout;
}

$(document).on('click', '.btn_save_function', function () {
   var pre_msg = [];
   var func_contents = [];
   var tmp_tab_name = null;
   var tmp_key = null;
   var tmp_func_name = null;
   var send_msg = null;
   var func_contents_value = null;
   var dont_send = false;
   var error_flag = false;
   var error_msg = null;
   var range_type = [];
   var range = [];
   var this_index = 0;

   if ($('#' + ap.active_pgm + '_group #function_name').val() === "") {
      $('<div />').html(langs.getText("common","enter_funcname")).dialog({
         modal: true,
         closeOnEscape: false,
         title: langs.getText("common","notification"),
         open: function (event, ui) {
            $(".ui-dialog-titlebar-close").hide();
         },
			buttons: [
				{
					text: langs.getText("common","simple_okay"),
					click: function () {
						$(this).dialog("destroy");
					}
				}
			]
      });
      return false;
   }

   if ($('#' + ap.active_pgm + ' .nav-tabs-sub').children().length === 0) {
      //alert("No tabs");
      return false;
   }

   tmp_func_name = $('#' + ap.active_pgm + '_group #function_name').val();

	if (tmp_func_name.match(/[^a-zA-Z0-9\s]/g)) {
      $('<div />').html(langs.getText("common","tab_func_funcname") + " " + langs.getText("error_msg","error_mullang")).dialog({
         modal: true,
         closeOnEscape: false,
         title: langs.getText("common","notification"),
         open: function (event, ui) {
            $(".ui-dialog-titlebar-close").hide();
         },
			buttons: [
				{
					text: langs.getText("common","simple_okay"),
					click: function () {
						$(this).dialog("destroy");
					}
				}
			]
      });
		return false;
	}

	pre_msg.push({
      name: "\"FUNC_NAME\"",
      value: "\"" + tmp_func_name + "\""
   });
   func_contents.push({elements: []});

   _.each($('#' + ap.active_pgm + ' .tab-pane-sub'), function (items, i) {
		if ($('#' + ap.active_pgm + ' .tab-pane-sub:eq(' + i + ')').children().length) {
			if(dont_send) {
				error_flag = true;
				error_msg = langs.getText("common","enter_funcrightorder");
				return false;
			}

			tmp_tab_name = $('#' + ap.active_pgm + ' .nav-tabs-sub li:eq(' + i + ') a input').val();

			if (tmp_tab_name.match(/[^a-zA-Z0-9\s\{\}\[\]\/?.,;:|\)*~`!^\-_+┼<>@\#$%&\'\\\(\=]/g)) {
				error_flag = true;
				error_msg = langs.getText("common","step_name") + " " + langs.getText("error_msg","error_mullang");
				return false;
			}

			if (!error_flag) {
				func_contents[0].elements.push({name: tmp_tab_name,tab: []});
				//pre_msg.push({name: "\"FUNC_STEP_"+(i+1)+"_NAME\"", value: "\"" + tmp_tab_name + "\""});

				//var step_idx = 1;
				_.each($('#' + ap.active_pgm + ' .tab-pane-sub:eq(' + i + ')').children(), function (item, j) {
					if ($('#' + ap.active_pgm + ' .tab-pane-sub:eq(' + i + ')').children().eq(j).attr('key')) {
						func_contents[0].elements[i].tab.push({key: $('#' + ap.active_pgm + ' .tab-pane-sub:eq(' + i + ')').children().eq(j).attr('key')});
						//pre_msg.push({name: "\"FUNC_STEP_"+(i+1)+"_"+step_idx+"\"", value: "\"" + $('#' + ap.active_pgm + ' .tab-pane-sub:eq(' + i + ')').children().eq(j).attr('key') + "\""});
						//step_idx++;
					} else {
						if ($('#' + ap.active_pgm + ' .tab-pane-sub:eq(' + i + ')').children().eq(j).hasClass('table')) {
							_.each($('#' + ap.active_pgm + ' .tab-pane-sub:eq(' + i + ')').children().eq(j).children().children(), function (tr, k) {
								if ($('#' + ap.active_pgm + ' .tab-pane-sub:eq(' + i + ')').children().eq(j).children().children().eq(k).attr('key')) {
									func_contents[0].elements[i].tab.push({key: $('#' + ap.active_pgm + ' .tab-pane-sub:eq(' + i + ')').children().eq(j).children().children().eq(k).attr('key')});
									//pre_msg.push({name: "\"FUNC_STEP_"+(i+1)+"_"+step_idx+"\"", value: "\"" + $('#' + ap.active_pgm + ' .tab-pane-sub:eq(' + i + ')').children().eq(j).children().children().eq(k).attr('key') + "\""});
									//step_idx++;
								}
							}, this);
						}
					}
				}, this);
			}
      } else {
			dont_send = true;
      }
   }, this);

   if(!error_flag && !func_contents[0].elements.length) {
		error_flag = true;
		error_msg = langs.getText("common","enter_stepcontent");
   }

   if (error_flag) {
      $('<div />').html(error_msg).dialog({
         modal: true,
         closeOnEscape: false,
         title: langs.getText("common","notification"),
         open: function (event, ui) {
            $(".ui-dialog-titlebar-close").hide();
         },
			buttons: [
				{
					text: langs.getText("common","simple_okay"),
					click: function () {
						$(this).dialog("destroy");
					}
				}
			]
      });
      return false;
   }

   debug_mode.flag && console.log(func_contents);

   func_contents_value = "define({elements:[";
   _.each(func_contents[0].elements, function (items, i) {
      //debug_mode.flag && console.log(pre_msg[0].elements.length);

      func_contents_value += "{name:'" + items.name + "', tab: [";
      _.each(items.tab, function (item, j) {
			if (item.key) {
				func_contents_value += "{key: '" + item.key + "'}";
			}

         //debug_mode.flag && console.log("j: " + j + ", " + pre_msg[0].elements[i].tab.length);
         if (j !== func_contents[0].elements[i].tab.length - 1) {
            func_contents_value += ",";
         }
      }, this);
      func_contents_value += "]}";

      if (i !== func_contents[0].elements.length - 1) {
         func_contents_value += ",";
      }
   }, this);
   func_contents_value += "]});";

	pre_msg.push({
      name: "\"FUNC_CONTENTS\"",
      value: "\"" + func_contents_value + "\""
   });

	send_msg = "{";
   _.each(pre_msg, function (item, i) {
      send_msg += item.name + ":" + item.value;
      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, "pgm99", packet.type, packet.range, packet.msg);
});

$(document).on('click', '.btn_checkall_attr', function () {
   if ($(this).attr('value') == langs.getText("common","btn_chkall")) {
		$('#'+ap.active_pgm+'_attrs div input:checkbox').prop('checked',true);
		$('#'+ap.active_pgm+'_attrs div input:checkbox').prop('disabled',false);
      $(this).val(langs.getText("common","btn_unchkall"));
   } else {
		$('#'+ap.active_pgm+'_attrs div input:checkbox').prop('checked',false);
		$('#'+ap.active_pgm+'_attrs div .tbl_tr').prop('disabled',true);
      $(this).val(langs.getText("common","btn_chkall"));
   }
});

$(document).on('click', '.btn_save_attr', function () {
	if($('#'+ap.active_pgm+'_attrs input:checkbox').length) {
		var save_it = false;

		_.each($('#'+ap.active_pgm+'_attrs input:checkbox'), function(item, i) {
			if(item.checked && !item.disabled) {
				save_it = true;
			}
		});

		if (save_it) {
			active_tab = $('#' + ap.active_pgm + ' .tab-content-sub .active').attr('id');
			$('#' + ap.active_pgm + ' .tab-content-sub .active').html("");

			_.each(pgm_views[$('#'+ap.active_pgm+'_attrs .btn_save_attr').attr('name')].collection.models[0].attributes.elements, function (items) {
				_.each(items.tab, function (item) {
					if (item.preload || item.button) {
						pgm_views[$('#'+ap.active_pgm+'_attrs .btn_save_attr').attr('name')].render_item(item.key);
					}
				}, this);
			}, this);

			_.each($('#'+ap.active_pgm+'_attrs input:checkbox'), function(item, i) {
				if(item.checked && !item.disabled) {
					pgm_views[$('#'+ap.active_pgm+'_attrs .btn_save_attr').attr('name')].render_item(item.value);
				}
			});
			$('#'+ap.active_pgm+'_attrs div input:checkbox').removeAttr('checked');
			$('#'+ap.active_pgm+'_attrs div .tbl_tr').attr('disabled','disabled');
		}
	} else {
		active_tab = $('#' + ap.active_pgm + ' .tab-content-sub .active').attr('id');
		$('#' + ap.active_pgm + ' .tab-content-sub .active').html("");

		_.each(pgm_views[$('#'+ap.active_pgm+'_attrs .btn_save_attr').attr('name')].collection.models[0].attributes.elements, function (items) {
			_.each(items.tab, function (item) {
				pgm_views[$('#'+ap.active_pgm+'_attrs .btn_save_attr').attr('name')].render_item(item.key);
			});
		});
	}
});

$(document).on('click', '.btn_init_attr', function () {
	active_tab = $('#' + ap.active_pgm + ' .tab-content-sub .active').attr('id');
   $("#" + ap.active_pgm + "_attrs").html("");
   $('#' + ap.active_pgm + ' .tab-content-sub .active').html("");

   pgm_models.get_model($(this)[0].name, true);
});

$(document).on('click', '#add_function_attrs div .mktbl', function () {
	var tbl_name = $(this)[0].value;

	if($(this)[0].checked) {
		$('#'+ap.active_pgm+'_attrs div input:checkbox[name='+tbl_name+']').removeAttr('disabled');
	} else {
		$('#'+ap.active_pgm+'_attrs div input:checkbox[name='+tbl_name+']').attr('disabled','disabled');
	}
});

$(document).on('click', '.btn_top', function () {
	if((active_base == "tab_function_base") && (ap.active_pgm != "favorite_func") && (pgm_models[ap.active_pgm].elements.length > 1)) {
		$('#' + ap.active_pgm+' .tab-content-sub').scrollTop(0);
	} else {
		$('#' + ap.active_pgm).scrollTop(0);
	}
});

$(document).on('click', '.btn_bottom', function () {
	if((active_base == "tab_function_base") && (ap.active_pgm != "favorite_func") && (pgm_models[ap.active_pgm].elements.length > 1)) {
		$('#' + ap.active_pgm+' .tab-content-sub').scrollTop($('#' + ap.active_pgm+' .tab-content-sub')[0].scrollHeight);
   } else {
		$('#' + ap.active_pgm).scrollTop($('#' + ap.active_pgm)[0].scrollHeight);
   }
});

$(document).on('click', '.btn_prev', function () {
	if(active_base == "tab_install_wizard") {
		var this_index = $('#' + active_base + ' .nav-tabs-main .active').index();

		$('#' + active_base + ' .nav-tabs-main .active').removeClass('active').children().children('img').remove();
		$('#' + active_base + ' .tab-content-main .active').removeClass('active');
		$('#' + active_base + ' .nav-tabs-main li:eq(' + (this_index - 1) + ')').addClass('active').children().css('color', '').append("<img src='img/refresh_icon.png' class='icon_refresh' title='" + langs.getText("toolTip","tip_refreshtab") + "' />");
		$('#' + active_base + ' .tab-content-main .tab-pane-main:eq(' + (this_index - 1) + ')').addClass('active');

		ap.render_pgm = $('#' + active_base + ' .tab-content-main .active').attr('id');
		$('#' + ap.render_pgm).html("");

      if (ap.render_pgm == "iw001") {
			make_fileup_pgm(false);
		} else if (ap.render_pgm == "iw007") {
			make_licenseup_pgm(false);
      } else {
			pgm_models.get_func_model(ap.render_pgm, true);
      }
   } else if(active_base == "tab_function_base") {
		var range_type = [];
		var range = [];
		var this_index = $('#' + ap.active_pgm + ' .nav-tabs-sub .active').index();
		var active_step_width = (60 / $('#' + ap.active_pgm + ' .nav-tabs-sub li').length) * 1.5;
		var other_step_width = (60 - active_step_width) / ($('#' + ap.active_pgm + ' .nav-tabs-sub li').length - 1);

		$('#' + ap.active_pgm + ' .nav-tabs-sub li').css('width', other_step_width+"%");
		$('#' + ap.active_pgm + ' .nav-tabs-sub .active').removeClass('active');
		$('#' + ap.active_pgm + ' .tab-content-sub .active').removeClass('active');
		$('#' + ap.active_pgm + ' .nav-tabs-sub li:eq(' + (this_index - 1) + ')').addClass('active').css('width', active_step_width+"%").children().css('color', '');
		$('#' + ap.active_pgm + ' .tab-content-sub .tab-pane-sub:eq(' + (this_index - 1) + ')').addClass('active');

		ap.render_pgm = $('#' + ap.active_pgm + ' .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);
   }
});

$(document).on('click', '.btn_next', function () {
	if(active_base == "tab_install_wizard") {
		if (ap.render_pgm == "iw008") {
			$('#' + ap.render_pgm).html("");
			packet.setPacket(0, [], [], "{\"CHECK_MAINT\":\"\"}");
			sendMsg(packet.main, "pgm50", packet.type, packet.range, packet.msg);
		} else {
			var this_index = $('#' + active_base + ' .nav-tabs-main .active').index();

			$('#' + active_base + ' .nav-tabs-main .active').removeClass('active').children().children('img').remove();
			$('#' + active_base + ' .tab-content-main .active').removeClass('active');
			$('#' + active_base + ' .nav-tabs-main li:eq(' + (this_index + 1) + ')').addClass('active').children().css('color', '').append("<img src='img/refresh_icon.png' class='icon_refresh' title='" + langs.getText("toolTip","tip_refreshtab") + "' />");
			$('#' + active_base + ' .tab-content-main .tab-pane-main:eq(' + (this_index + 1) + ')').addClass('active');

			ap.render_pgm = $('#' + active_base + ' .tab-content-main .active').attr('id');
			$('#' + ap.render_pgm).html("");

			if (ap.render_pgm == "iw001") {
				make_fileup_pgm(false);
			} else if (ap.render_pgm == "iw007") {
				make_licenseup_pgm(false);
			} else {
				pgm_models.get_func_model(ap.render_pgm, true);
			}
		}
   } else if(active_base == "tab_function_base") {
		var range_type = [];
		var range = [];
		var this_index = $('#' + ap.active_pgm + ' .nav-tabs-sub .active').index();
		var active_step_width = (60 / $('#' + ap.active_pgm + ' .nav-tabs-sub li').length) * 1.5;
		var other_step_width = (60 - active_step_width) / ($('#' + ap.active_pgm + ' .nav-tabs-sub li').length - 1);

		$('#' + ap.active_pgm + ' .nav-tabs-sub li').css('width', other_step_width+"%");
		$('#' + ap.active_pgm + ' .nav-tabs-sub .active').removeClass('active');
		$('#' + ap.active_pgm + ' .tab-content-sub .active').removeClass('active');
		$('#' + ap.active_pgm + ' .nav-tabs-sub li:eq(' + (this_index + 1) + ')').addClass('active').css('width', active_step_width+"%").children().css('color', '');
		$('#' + ap.active_pgm + ' .tab-content-sub .tab-pane-sub:eq(' + (this_index + 1) + ')').addClass('active');

		ap.render_pgm = $('#' + ap.active_pgm + ' .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);
   }
});

$(document).on('click', '.btn_iw_default', function () {
	if(active_base == "tab_install_wizard") {
		var send_msg = "{\"SET_DEFAULT\":\"\"}";
		debug_mode.flag && console.log(send_msg);

		if (ap.render_pgm == "iw006" && info.NO_OF_COLS) {
			var range_type = [];
			var range = [];
			range_type.push("2");
			range.push("1-" + info.NO_OF_COLS);

			packet.setPacket(1, range_type, range, send_msg);
		} else {
			setSpecialPacket(send_msg);
		}
		$('#' + ap.render_pgm).html("");
		pgm_models.get_model(ap.render_pgm, false, packet);
   }
});

$(document).on('click', '.chk_showpwd', function () {
   if ($(this).hasClass('on')) {
      $(this).removeClass('on');
      $(this).addClass('off');
      $(this).parent().children('input:text').get(0).type = 'password';
   } else if ($(this).hasClass('off')) {
      $(this).removeClass('off');
      $(this).addClass('on');
      $(this).parent().children('input:password').get(0).type = 'text';
   } else {
      $(this).addClass('on');
      $(this).parent().children('input:password').get(0).type = 'text';
   }
});

$(document).on('click', '.btn_addstn', function () {
   if (($(this).parent().children("input").length - $('#' + ap.render_pgm + ' .btn_addstn').length) < 10) {
      $(this).parent().append("<br>");
      $(this).parent().append($(this).parent().children().eq(0).clone().val(""));
      $(this).parent().children().last().focus();
      $(this).parent().append($(this));
   }
   if (($(this).parent().children("input").length - $('#' + ap.render_pgm + ' .btn_addstn').length) == 10) {
      $(this).remove();
   }
});

$(document).on('click', '#account_logout', function () {
	if (active_base == "tab_user_guide") {
		debug_mode.flag && console.log("Exit");
		location.href = location.origin;
	} else {
		var send_msg = "{\"LOGOUT\":\"\"}";
		debug_mode.flag && console.log(send_msg);
		var range_type = [];
		var range = [];

		skipConfirm_flag = true;
		logout_flag = true;

		packet.setPacket(1, range_type, range, send_msg);
		sendMsg(packet.main, "pgm50", packet.type, packet.range, packet.msg);

		$(document).unbind("Log_out");
		$(document).bind("Log_out", function () {
			debug_mode.flag && console.log("Log Out");
			location.href = location.href.replace(/#$/, '');
		});
	}
});

$(document).on('click', '#btn_to_user_portal', function () {
	location.href = location.origin + "/up_index.html";
});

$(document).on('click', '.btn_finish', function () {
	if(active_base == "tab_install_wizard") {
		var send_msg = "{\"LOGOUT\":\"EXIT_WIZARD\"}";
		debug_mode.flag && console.log(send_msg);
		var range_type = [];
		var range = [];

		skipConfirm_flag = true;
		logout_flag = true;

		packet.setPacket(1, range_type, range, send_msg);
		$('#' + ap.render_pgm).html("");
		sendMsg(packet.main, "pgm50", packet.type, packet.range, packet.msg);

		$(document).unbind("Log_out");
		$(document).bind("Log_out", function () {
			debug_mode.flag && console.log("Log Out");
			location.href = location.href.replace(/#$/, '')
		});
   }
});

$(document).on('click', '.btn_p50_deluser', function () {
   var del_id = $.trim($(this).parent().parent().children().eq(0).text());
   if (!offline_mode) {
		del_id = RSA.encrypt(del_id, $key);
   }
   var send_msg = "{\"DEL_USER\":\"" + del_id + "\"}";
   debug_mode.flag && console.log(send_msg);
   var range_type = [];
   var range = [];

   packet.setPacket(1, range_type, range, send_msg);
   $('#' + ap.render_pgm).html("");
   pgm_models.get_model(ap.render_pgm, true, packet);
});

$(document).on('click', '.sel_webauth_changeall', function (evt) {
   var this_block = "";
   var real_pgm = ap.render_pgm;
   var target = null;
   var target_value = evt.target.value;

   if (evt.target.tagName == "SELECT") {
		target = evt.target;
   } else {
		target = $(evt.target).parents('select')[0];
   }

   if (active_base == "tab_function_base") {
      ap.render_pgm = $(this).parents('.tab-pane-sub').attr("id");
      for (var idx = 0; idx < pgm_views[ap.render_pgm].collection.models[0].attributes.elements[0].tab.length; idx++) {
			if (pgm_views[ap.render_pgm].collection.models[0].attributes.elements[0].tab[idx].key) {
				real_pgm = pgm_views[ap.render_pgm].collection.models[0].attributes.elements[0].tab[idx].key.split('_')[0];
				break;
			}
		}
   }
   //debug_mode.flag && console.log("ap.render_pgm : "+ap.render_pgm+" real_pgm : "+real_pgm);

   _.each($('#' + ap.render_pgm + ' .sel_webauth_changeall'), function (item, i) {
      if (target == item) {
         if ((real_pgm == "pgm189") || (real_pgm == "pgm1891")) {
            this_block = item.name.replace("_CHANGEALL","");
         }
      }
   });

   _.each($('#' + ap.render_pgm + ' .sel_changeall'), function (item) {
      if (item.name.replace(/\_\d+$/, "") == this_block) {
         if (target_value == "0") {
            item.value = target_value;
         } else if (target_value == "1") {
            item.value = target_value;
         } else if (target_value == "2") {
            item.value = target_value;
         }
      }
   });
});

$(document).on('click', '.btn_smdr_alldownload', function (evt) {
   $('#hiddenFrame').attr('src', 'smdr_data.slk.gz');
});

$(document).on('click', '.btn_smdr_intdownload', function (evt) {
   $('#hiddenFrame').attr('src', 'ismdr_data.slk.gz');
});

$(document).on('click', '.btn_smdr_stnview', function (evt) {
   var range_type = [];
   var range = [];
   var send_msg = "{\"SMDR_VIEW\":\"\",\"SMDR_TYPE\":\"STN\"}";

   if ($('#' + ap.render_pgm + ' .error').length) {
      $('#' + ap.render_pgm + ' td').children().css('outline', '').css('margin', '');
      $('#' + ap.render_pgm + ' .error').remove();
   }

   if (!$('#' + ap.render_pgm + ' [name=SMDR_STN_START]').val()) {
      $('#' + ap.render_pgm + ' [name=SMDR_STN_START]').css('outline', '2px solid red').css('margin', '2px');
      $('#' + ap.render_pgm + ' [name=SMDR_STN_END]').css('outline', '2px solid red').css('margin', '2px');
      $('#' + ap.render_pgm + ' [name=SMDR_STN_START]').parent().append("<font class='error' style='font-weight: bold; color: red; margin: 0px 5px;'>" + langs.getText("error_msg","opt_range_error_case1") + "</font>");
      return false;
   } else if ($('#' + ap.render_pgm + ' [name=SMDR_STN_START]').val().match(/[^0-9*#]/g) || $('#' + ap.render_pgm + ' [name=SMDR_STN_END]').val().match(/[^0-9*#]/g)) {
      if ($('#' + ap.render_pgm + ' [name=SMDR_STN_START]').val() && $('#' + ap.render_pgm + ' [name=SMDR_STN_START]').val().match(/[^0-9*#]/g)) {
			$('#' + ap.render_pgm + ' [name=SMDR_STN_START]').css('outline', '2px solid red').css('margin', '2px');
      }
      if ($('#' + ap.render_pgm + ' [name=SMDR_STN_END]').val() && $('#' + ap.render_pgm + ' [name=SMDR_STN_END]').val().match(/[^0-9*#]/g)) {
			$('#' + ap.render_pgm + ' [name=SMDR_STN_END]').css('outline', '2px solid red').css('margin', '2px');
      }
      $('#' + ap.render_pgm + ' [name=SMDR_STN_START]').parent().append("<font class='error' style='font-weight: bold; color: red; margin: 0px 5px;'>" + langs.getText("error_msg","opt_range_error_case2") + "</font>");
      return false;
   }

   range_type.push("1");
   range[0] = $('#' + ap.render_pgm + ' [name=SMDR_STN_START]').val();
   if ($('#' + ap.render_pgm + ' [name=SMDR_STN_END]').val()) {
      range[0] += "-" + $('#' + ap.render_pgm + ' [name=SMDR_STN_END]').val();
   } else {
      range[0] += "-" + $('#' + ap.render_pgm + ' [name=SMDR_STN_START]').val();
   }

   debug_mode.flag && console.log(range_type);
   debug_mode.flag && console.log(range);
   debug_mode.flag && console.log(send_msg);

   packet.setPacket(0, range_type, range, send_msg);
   $('#' + ap.render_pgm).html("");
   pgm_models.get_model(ap.render_pgm, true, packet);
});

$(document).on('click', '.btn_smdr_intview', function (evt) {
   var send_msg = "{\"SMDR_VIEW\":\"\",\"SMDR_TYPE\":\"ISMDR\"}";
   debug_mode.flag && console.log(send_msg);
   var range_type = [];
   var range = [];

   packet.setPacket(0, range_type, range, send_msg);
   $('#' + ap.render_pgm).html("");
   pgm_models.get_model(ap.render_pgm, true, packet);
});

$(document).on('click', '.btn_smdr_stndel', function (evt) {
   var range_type = [];
   var range = [];
   var send_msg = "{\"SMDR_DEL\":\"\",\"SMDR_TYPE\":\"STN\"}";

   if ($('#' + ap.render_pgm + ' .error').length) {
      $('#' + ap.render_pgm + ' td').children().css('outline', '').css('margin', '');
      $('#' + ap.render_pgm + ' .error').remove();
   }

   if (!$('#' + ap.render_pgm + ' [name=SMDR_STN_START]').val()) {
      $('#' + ap.render_pgm + ' [name=SMDR_STN_START]').css('outline', '2px solid red').css('margin', '2px');
      $('#' + ap.render_pgm + ' [name=SMDR_STN_END]').css('outline', '2px solid red').css('margin', '2px');
      $('#' + ap.render_pgm + ' [name=SMDR_STN_START]').parent().append("<font class='error' style='font-weight: bold; color: red; margin: 0px 5px;'>" + langs.getText("error_msg","opt_range_error_case1") + "</font>");
      return false;
   } else if ($('#' + ap.render_pgm + ' [name=SMDR_STN_START]').val().match(/[^0-9*#]/g) || $('#' + ap.render_pgm + ' [name=SMDR_STN_END]').val().match(/[^0-9*#]/g)) {
      if ($('#' + ap.render_pgm + ' [name=SMDR_STN_START]').val() && $('#' + ap.render_pgm + ' [name=SMDR_STN_START]').val().match(/[^0-9*#]/g)) {
			$('#' + ap.render_pgm + ' [name=SMDR_STN_START]').css('outline', '2px solid red').css('margin', '2px');
      }
      if ($('#' + ap.render_pgm + ' [name=SMDR_STN_END]').val() && $('#' + ap.render_pgm + ' [name=SMDR_STN_END]').val().match(/[^0-9*#]/g)) {
			$('#' + ap.render_pgm + ' [name=SMDR_STN_END]').css('outline', '2px solid red').css('margin', '2px');
      }
      $('#' + ap.render_pgm + ' [name=SMDR_STN_START]').parent().append("<font class='error' style='font-weight: bold; color: red; margin: 0px 5px;'>" + langs.getText("error_msg","opt_range_error_case2") + "</font>");
      return false;
   }

   range_type.push("1");
   range[0] = $('#' + ap.render_pgm + ' [name=SMDR_STN_START]').val();
   if ($('#' + ap.render_pgm + ' [name=SMDR_STN_END]').val()) {
      range[0] += "-" + $('#' + ap.render_pgm + ' [name=SMDR_STN_END]').val();
   } else {
      range[0] += "-" + $('#' + ap.render_pgm + ' [name=SMDR_STN_START]').val();
   }

   debug_mode.flag && console.log(range_type);
   debug_mode.flag && console.log(range);
   debug_mode.flag && console.log(send_msg);

   packet.setPacket(1, range_type, range, send_msg);
   $('#' + ap.render_pgm).html("");
   pgm_models.get_model(ap.render_pgm, true, packet);
});

$(document).on('click', '.btn_smdr_intdel', function (evt) {
   var send_msg = "{\"SMDR_DEL\":\"\",\"SMDR_TYPE\":\"ISMDR\"}";
   debug_mode.flag && console.log(send_msg);
   var range_type = [];
   var range = [];

   packet.setPacket(1, range_type, range, send_msg);
   $('#' + ap.render_pgm).html("");
   pgm_models.get_model(ap.render_pgm, true, packet);
});

$(document).on('change', '.p1010_reg_idtype_sel', function (evt) {
	var ch_name_num = $(this).attr('name').split('_')[$(this).attr('name').split('_').length - 1];
	//console.log(ch_name_num);
	$('#'+ap.render_pgm+' [name=REG_ID_'+ch_name_num+']').val('');
	$('#'+ap.render_pgm+' [name=REG_PORT_'+ch_name_num+']').val('');

	$(this).parents('tr').children().eq(9).show();
	$(this).parents('tr').children().eq(10).hide();
	$(this).parents('tr').children().eq(11).hide();
	$(this).parents('tr').children().eq(12).hide();

	if ($(this).val() == "0") {
		if ($('#'+ap.render_pgm+' [name=REG_VIRMAC_'+ch_name_num+']')[0].checked == true) {
			$('#'+ap.render_pgm+' [name=REG_VIRMAC_'+ch_name_num+']')[0].checked = false;
		}
		if ($('#'+ap.render_pgm+' [name=REG_MAC_'+ch_name_num+']')[0].disabled == true) {
			$('#'+ap.render_pgm+' [name=REG_MAC_'+ch_name_num+']')[0].disabled = false;
		}

		$(this).parents('tr').children().eq(2).show();	// No Type
		$(this).parents('tr').children().eq(3).hide();	// CO Type
		$(this).parents('tr').children().eq(4).hide();	// Station Type
		$(this).parents('tr').children().eq(5).hide();	// VMIM Type
		$(this).parents('tr').children().eq(6).hide();	// MICM Type
		$(this).parents('tr').children().eq(7).hide();	// UCS Type => WTIM Type
		//$(this).parents('tr').children().eq(8).hide();
	} else if ($(this).val() == "1") {
		$(this).parents('tr').children().eq(2).hide();
		$(this).parents('tr').children().eq(3).show();
		$(this).parents('tr').children().eq(4).hide();
		$(this).parents('tr').children().eq(5).hide();
		$(this).parents('tr').children().eq(6).hide();
		$(this).parents('tr').children().eq(7).hide();
		//$(this).parents('tr').children().eq(8).hide();
	} else if ($(this).val() == "2") {
		$(this).parents('tr').children().eq(2).hide();
		$(this).parents('tr').children().eq(3).hide();
		$(this).parents('tr').children().eq(4).show();
		$(this).parents('tr').children().eq(5).hide();
		$(this).parents('tr').children().eq(6).hide();
		$(this).parents('tr').children().eq(7).hide();
		//$(this).parents('tr').children().eq(8).hide();
	} else if ($(this).val() == "3") {
		$(this).parents('tr').children().eq(2).hide();
		$(this).parents('tr').children().eq(3).hide();
		$(this).parents('tr').children().eq(4).hide();
		$(this).parents('tr').children().eq(5).show();
		$(this).parents('tr').children().eq(6).hide();
		$(this).parents('tr').children().eq(7).hide();
		//$(this).parents('tr').children().eq(8).hide();
	} else if ($(this).val() == "4") {
		$(this).parents('tr').children().eq(2).hide();
		$(this).parents('tr').children().eq(3).hide();
		$(this).parents('tr').children().eq(4).hide();
		$(this).parents('tr').children().eq(5).hide();
		$(this).parents('tr').children().eq(6).show();
		$(this).parents('tr').children().eq(7).hide();
		//$(this).parents('tr').children().eq(8).hide();
	} else if ($(this).val() == "5") {		//UCS not used
		$(this).parents('tr').children().eq(2).hide();
		$(this).parents('tr').children().eq(3).hide();
		$(this).parents('tr').children().eq(4).hide();
		$(this).parents('tr').children().eq(5).hide();
		$(this).parents('tr').children().eq(6).hide();
		$(this).parents('tr').children().eq(7).show();
		$(this).parents('tr').children().eq(8).hide();
	} else if ($(this).val() == "6") {
		$(this).parents('tr').children().eq(2).hide();
		$(this).parents('tr').children().eq(3).hide();
		$(this).parents('tr').children().eq(4).hide();
		$(this).parents('tr').children().eq(5).hide();
		$(this).parents('tr').children().eq(6).hide();
		$(this).parents('tr').children().eq(7).show();
		//$(this).parents('tr').children().eq(8).show();
	}
	$(this).parents('tr').children().eq(9).show();
	$(this).parents('tr').children().eq(10).hide();
	$(this).parents('tr').children().eq(11).hide();
	$(this).parents('tr').children().eq(12).hide();
});

$(document).on('change', '.p1010_reg_id_sel', function (evt) {
	var ch_name_num = $(this).attr('name').split('_')[$(this).attr('name').split('_').length - 1];
	//console.log(ch_name_num);
	
	if ($('#'+ap.render_pgm+' [name=REG_LOGINPWD_'+ch_name_num+']')[0].disabled == true) {
		$('#'+ap.render_pgm+' [name=REG_LOGINPWD_'+ch_name_num+']')[0].disabled = false;
	}
	if ($('#'+ap.render_pgm+' [name=REG_REPL_'+ch_name_num+']')[0].checked == true) {
		$('#'+ap.render_pgm+' [name=REG_REPL_'+ch_name_num+']')[0].checked = false;
	}
	$('#'+ap.render_pgm+' [name=REG_PORT_'+ch_name_num+']').val('');
	$('#'+ap.render_pgm+' [name=REG_VPORT_'+ch_name_num+']').val('');
	$('#'+ap.render_pgm+' [name=REG_STN_'+ch_name_num+']').val('');
	$('#'+ap.render_pgm+' [name=REG_LOGINID_'+ch_name_num+']').val('');
	$('#'+ap.render_pgm+' [name=REG_LOGINPWD_'+ch_name_num+']').val('');

	if ($(this).val() == "100" || $(this).val() == "101") {
		$(this).parents('tr').children().eq(9).hide();	// Max Port Only
		$(this).parents('tr').children().eq(10).show();	// For VOIM8, VOIM24
		$(this).parents('tr').children().eq(11).hide();	// For VMEX SIP Station
		$(this).parents('tr').children().eq(12).hide();	// For Phonetage, UCS Client

		if ($(this).val() == "100") {
			$('#'+ap.render_pgm+' [name=REG_VPORT_'+ch_name_num+']').val('8');
		} else if ($(this).val() == "101") {
			$('#'+ap.render_pgm+' [name=REG_VPORT_'+ch_name_num+']').val('24');
		}
	} else if ($(this).val() == "138") {
		$('#'+ap.render_pgm+' [name=REG_VIRMAC_'+ch_name_num+']')[0].disabled = true;
		$('#'+ap.render_pgm+' [name=REG_MAC_'+ch_name_num+']')[0].disabled = true;

		$(this).parents('tr').children().eq(9).hide();
		$(this).parents('tr').children().eq(10).hide();
		$(this).parents('tr').children().eq(11).show();
		$(this).parents('tr').children().eq(12).hide();
	} else if ($(this).val() == "1450" || $(this).val() == "1451" || $(this).val() == "1452") {
		$('#'+ap.render_pgm+' [name=REG_VIRMAC_'+ch_name_num+']')[0].disabled = true;
		$('#'+ap.render_pgm+' [name=REG_MAC_'+ch_name_num+']')[0].disabled = true;

		$(this).parents('tr').children().eq(9).hide();
		$(this).parents('tr').children().eq(10).hide();
		$(this).parents('tr').children().eq(11).hide();
		$(this).parents('tr').children().eq(12).show();

		if ($(this).val() == "1452") {
			$('#'+ap.render_pgm+' [name=REG_LOGINPWD_'+ch_name_num+']')[0].disabled = true;
		}
	} else {
		$(this).parents('tr').children().eq(9).show();
		$(this).parents('tr').children().eq(10).hide();
		$(this).parents('tr').children().eq(11).hide();
		$(this).parents('tr').children().eq(12).hide();
		if ($(this).val() == "128" || $(this).val() == "161" || $(this).val() == "162" || $(this).val() == "163" || $(this).val() == "164" || $(this).val() == "165" || $(this).val() == "193" || $(this).val() == "194" || $(this).val() == "195" || $(this).val() == "196" || $(this).val() == "197" || $(this).val() == "198" || $(this).val() == "207" || $(this).val() == "199" || $(this).val() == "205" || $(this).val() == "200" || $(this).val() == "201" || $(this).val() == "202" || $(this).val() == "204" || $(this).val() == "203" || $(this).val() == "150" || $(this).val() == "155" || $(this).val() == "137" || $(this).val() == "243" || $(this).val() == "244" || $(this).val() == "245" || $(this).val() == "246"|| $(this).val() == "247"|| $(this).val() == "248"|| $(this).val() == "249") {
			$('#'+ap.render_pgm+' [name=REG_PORT_'+ch_name_num+']').val('1');
		} else if ($(this).val() == "118" || $(this).val() == "114" || $(this).val() == "115" || $(this).val() == "119" || $(this).val() == "7") {
			$('#'+ap.render_pgm+' [name=REG_PORT_'+ch_name_num+']').val('8');
		} else if ($(this).val() == "83" || $(this).val() == "134" || $(this).val() == "1730" || $(this).val() == "10") {
			$('#'+ap.render_pgm+' [name=REG_PORT_'+ch_name_num+']').val('16');
		} else if ($(this).val() == "42" || $(this).val() == "99" || $(this).val() == "98" || $(this).val() == "104" || $(this).val() == "208") {
			$('#'+ap.render_pgm+' [name=REG_PORT_'+ch_name_num+']').val('24');
		} else if ($(this).val() == "41") {
			$('#'+ap.render_pgm+' [name=REG_PORT_'+ch_name_num+']').val('30');
		} else if ($(this).val() == "120" || $(this).val() == "116" || $(this).val() == "1731") {
			$('#'+ap.render_pgm+' [name=REG_PORT_'+ch_name_num+']').val('32');
		}
	}
});

$(document).on('click', '.chk_p1010_virmac', function (evt) {
	var ch_name_num = $(this).attr('name').split('_')[$(this).attr('name').split('_').length - 1];
	//console.log(ch_name_num);

	if ($(this)[0].checked) {
		$('#'+ap.render_pgm+' [name=REG_MAC_'+ch_name_num+']')[0].disabled = true;
	} else {
		$('#'+ap.render_pgm+' [name=REG_MAC_'+ch_name_num+']')[0].disabled = false;
	}
});

$(document).on('change', '.p1011_sel_bksutype', function (evt) {
	if (($(this).val() == "A")) {
		if($('#'+ap.render_pgm+' [name=BKSU_PHY_7_0]').find("option[value='LCOB4']")) {
			$('#'+ap.render_pgm+' [name=BKSU_PHY_7_0]').append('<option value="LCOB4">LCOB4</option>');
		}
		$('#'+ap.render_pgm+' [name=BKSU_PHY_7_0]').attr('disabled','disabled');
		$('#'+ap.render_pgm+' [name=BKSU_PHY_7_0]').val('LCOB4');
		$('#'+ap.render_pgm+' [name=BKSU_PHY_0_1]').val('HYIB8');
	}
	else if(($(this).val() == "AD")) {
		if($('#'+ap.render_pgm+' [name=BKSU_PHY_7_0]').find("option[value='LCOB4']")) {
			$('#'+ap.render_pgm+' [name=BKSU_PHY_7_0]').append('<option value="LCOB4">LCOB4</option>');
		}
		$('#'+ap.render_pgm+' [name=BKSU_PHY_7_0]').attr('disabled','disabled');
		$('#'+ap.render_pgm+' [name=BKSU_PHY_7_0]').val('LCOB4');
		$('#'+ap.render_pgm+' [name=BKSU_PHY_0_1]').val('DSIB12');
	}
	else if(($(this).val() == "I")) {
		$('#'+ap.render_pgm+' [name=BKSU_PHY_7_0]').removeAttr('disabled');
		$('#'+ap.render_pgm+' [name=BKSU_PHY_7_0]').val('NA');
		$('#'+ap.render_pgm+' [name=BKSU_PHY_0_1]').val('HYIB8');
		$('#'+ap.render_pgm+' [name=BKSU_PHY_7_0]').find("option[value='LCOB4']").remove();
	}
	else if(($(this).val() == "ID")) {
		$('#'+ap.render_pgm+' [name=BKSU_PHY_7_0]').removeAttr('disabled');
		$('#'+ap.render_pgm+' [name=BKSU_PHY_7_0]').val('NA');
		$('#'+ap.render_pgm+' [name=BKSU_PHY_0_1]').val('DSIB12');
		$('#'+ap.render_pgm+' [name=BKSU_PHY_7_0]').find("option[value='LCOB4']").remove();
	}
	else {
		$('#'+ap.render_pgm+' [name=BKSU_PHY_7_0]').removeAttr('disabled');
	}
});

$(document).on('change', '.p1011_sel_bksuoption', function (evt) {
	if (($(this).val() == "VVMU")) {
		$('#'+ap.render_pgm+' [name=BKSU_PHY_14_0]').val('VOIB');
		$('#'+ap.render_pgm+' [name=BKSU_PHY_16_0]').val('VMIB');
	} else {
		$('#'+ap.render_pgm+' [name=BKSU_PHY_14_0]').val('NA');
		$('#'+ap.render_pgm+' [name=BKSU_PHY_16_0]').val('NA');
	}
});

$(document).on('change', '.p1011_sel_eksutype', function (evt) {
	if (($(this).val() == "EKSU")) {
		$('#'+ap.render_pgm+' [name=EKSU_PHY_12_6]').removeAttr('disabled');
		$('#'+ap.render_pgm+' [name=EKSU_PHY_12_6]').val('NA');
		$('#'+ap.render_pgm+' [name=EKSU_PHY_11_5]').removeAttr('disabled');
		$('#'+ap.render_pgm+' [name=EKSU_PHY_11_5]').val('NA');
		$('#'+ap.render_pgm+' [name=EKSU_PHY_0_4]').val('HYIB8');
		$('#'+ap.render_pgm+' [name=EKSU_PHY_10_0]').val('LCOB4');

	} else {
		$('#'+ap.render_pgm+' [name=EKSU_PHY_12_6]').attr('disabled','disabled');
		$('#'+ap.render_pgm+' [name=EKSU_PHY_12_6]').val('NA');
		$('#'+ap.render_pgm+' [name=EKSU_PHY_11_5]').attr('disabled','disabled');
		$('#'+ap.render_pgm+' [name=EKSU_PHY_11_5]').val('NA');
		$('#'+ap.render_pgm+' [name=EKSU_PHY_0_4]').val('NA');
		$('#'+ap.render_pgm+' [name=EKSU_PHY_10_0]').val('NA');
	}
});

$(document).on('click', '.btn_p105_searchnumber', function (evt) {
   var send_msg = "";
   var dont_save = false;

   if ($('#' + ap.render_pgm + ' .error').length) {
      $('#' + ap.render_pgm + ' td').children().css('outline', '').css('margin', '');
      $('#' + ap.render_pgm + ' .error').remove();
   }

   if ($("#"+ap.render_pgm+" [name=SEARCHNUMBER]").val().match(/[^0-9*#]/g)) {
		$('#' + ap.render_pgm + ' [name=SEARCHNUMBER]').css("outline", "2px solid red").css("margin", "2px");
		$('#' + ap.render_pgm + ' [name=SEARCHNUMBER]').after("<font class='error' style='font-weight: bold; color: red;'>" + langs.getText("error_msg","opt_range_error_case2") + "</font>");
		dont_save = true;
   } else if ($("#"+ap.render_pgm+" [name=SEARCHNUMBER]").val().length == 0) {
		$('#' + ap.render_pgm + ' [name=SEARCHNUMBER]').css("outline", "2px solid red").css("margin", "2px");
		$('#' + ap.render_pgm + ' [name=SEARCHNUMBER]').after("<font class='error' style='font-weight: bold; color: red;'>" + langs.getText("error_msg","invalid_station_no") + "</font>");
		dont_save = true;
   } else {
		send_msg = "{\"SEARCHNUMBER\":\"" + $("#"+ap.render_pgm+" [name=SEARCHNUMBER]").val() + "\"}"
   }

   if (!dont_save) {
		setSpecialPacket(send_msg);
		debug_mode.flag && console.log(send_msg);
		$('#' + ap.render_pgm).html("");
		pgm_models.get_model(ap.render_pgm, false, packet);
   }
});

$(document).on('click', '.btn_p105_rangesave', function (evt) {
   var dont_save = false;
   var skip_flag = false;
   var cid_exist = false;

   if ($('#' + ap.render_pgm + ' .error').length) {
      $('#' + ap.render_pgm + ' td').children().css('outline', '').css('margin', '');
      $('#' + ap.render_pgm + ' .error').remove();
   }

   var send_msg = "{";
   if($('#' + ap.render_pgm + ' [name=CIDPWD]').length) {
		send_msg += "\"CIDPWD\":\"" + $('#' + ap.render_pgm + ' [name=CIDPWD]').val() + "\"";
		cid_exist = true;
   }
   _.each($(this).parents('table').children().children(), function (items, i) {
      var j = 0;
      _.each(items.childNodes, function (item) {
         _.each(item.childNodes, function (node) {
            if (node.name && (node.name != "undefined")) {
               if (node.type == "radio" && node.checked == true) {
                  skip_flag = false;
               } else if (node.type == "radio" && node.checked == false) {
                  skip_flag = true;
               }

               if (!skip_flag) {
                  if (node.name == "STN_STSEQ" || node.name == "STN_ENDSEQ") {
                     if (node.value.match(/[^0-9]/g)) {
                        $('#' + ap.render_pgm + ' [name=' + node.name + ']').css("outline", "2px solid red").css("margin", "2px");
                        if (!$('#' + ap.render_pgm + ' [name=' + node.name + ']').parent().children('.error').length) {
                           $('#' + ap.render_pgm + ' [name=' + node.name + ']').parent().append("<font class='error' style='font-weight: bold; color: red;'>" + langs.getText("error_msg","opt_range_error_case3") + "</font>");
                        }
                        dont_save = true;
                     }
                  } else if (node.name == "STN_NUMSTART" || node.name == "STN_NUMEND" || node.name == "STN_SEQSTART" || node.name == "STN_CHANGESTART") {
                     if (node.value.match(/[^0-9*#]/g)) {
                        $('#' + ap.render_pgm + ' [name=' + node.name + ']').css("outline", "2px solid red").css("margin", "2px");
                        if (!$('#' + ap.render_pgm + ' [name=' + node.name + ']').parent().children('.error').length) {
                           $('#' + ap.render_pgm + ' [name=' + node.name + ']').parent().append("<font class='error' style='font-weight: bold; color: red;'>" + langs.getText("error_msg","opt_range_error_case2") + "</font>");
                        }
                        dont_save = true;
                     }
                  }

                  if(cid_exist && (j == 0)) {
							send_msg += ","
                  } else if(j != 0) {
							send_msg += ","
                  }

                  send_msg += "\"" + node.name + "\":\"" + node.value + "\"";
                  j++;
               }
            }
         });
      });
   });
   send_msg += "}";
   if (!dont_save) {
      setSpecialPacket(send_msg);
      debug_mode.flag && console.log(send_msg);
      $('#' + ap.render_pgm).html("");
      pgm_models.get_model(ap.render_pgm, false, packet);
   }
});

function encodeToHex(str) {
   var r = "";
   var e = str.length;
   var c = 0;
   var h;
   while (c < e) {
      h = str.charCodeAt(c++).toString(16);
      if (h == "2a") //*
      h = "40";
      else if (h == "23") //#
      h = "41";
      r += h;
   }
   return r;
}

function compareValues(a, b) {
   var cnt = 0,
       tem;
   var a = a.toLowerCase();
   var b = b.toLowerCase();
   if (a == b) return 0;

   var rx = /^(\.)?\d/;
   var L = Math.min(a.length, b.length) + 1;
   while (cnt < L && a.charAt(cnt) === b.charAt(cnt) && rx.test(b.substring(cnt)) == false) cnt++;

   a = a.substring(cnt);
   b = b.substring(cnt);

   if (rx.test(a) || rx.test(b)) {
      if (rx.test(a) == false) return a ? 1 : -1;
      else if (rx.test(b) == false) return b ? -1 : 1;
      else {
         if (a.length == b.length) {
            var tem = parseFloat(a) - parseFloat(b);
            if (tem != 0) return tem;
            else tem = a.search(/[^\.\d]/);
            if (tem == -1) tem = b.search(/[^\.\d]/);
            a = a.substring(tem);
            b = b.substring(tem);
         }
      }
   }
   if (a == b) return 0;
   return a > b ? 1 : -1;

}

$(document).on('click', '.btn_p106_save', function (evt) {
   var b_FFNPvalid = true;
   var pc_FFNPnum;
   var i_rangestart = -1;
   var i_rangeend = -1;
   var hex_singlevalue;
   var hex_rangestart;
   var hex_rangeend;
   var hex_checkstart;
   var hex_checkend;

   if ($('#' + ap.render_pgm + ' .error').length) {
      $('#' + ap.render_pgm + ' td').children().css('outline', '').css('margin', '');
      $('#' + ap.render_pgm + ' .error').remove();
   }

   for (i = 0; i < $('#' + ap.render_pgm + ' input:text[name*=FFNP_]').length; i++) {
      pc_FFNPnum = eval("$('#'+ap.render_pgm+' input:text[name*=FFNP_]').eq(" + i + ").val()");
      // space check
      if (!pc_FFNPnum.match(" ")) {
         if (pc_FFNPnum.length != 0) {
            // check single value
            for (j = i + 1; j <= $('#' + ap.render_pgm + ' input:text[name*=FFNP_]').length; j++) {
               if (pc_FFNPnum == eval("$('#'+ap.render_pgm+' input:text[name*=FFNP_]').eq(" + j + ").val()")) {
                  b_FFNPvalid = false;
                  $('<div />').html(langs.getText("p106","alert_savefail") + " " + langs.getText("p106","alert_sameval") + " : " + pc_FFNPnum).dialog({
                     modal: true,
                     closeOnEscape: false,
                     title: langs.getText("common","notification"),
                     open: function (event, ui) {
                        $(".ui-dialog-titlebar-close").hide();
                     },
							buttons: [
								{
									text: langs.getText("common","simple_okay"),
									click: function () {
										$(this).dialog("destroy");
									}
								}
							]
                  });
                  break;
               }
            }
            // check range value
            if (b_FFNPvalid != false) {
               for (j = 0; j < $('#' + ap.render_pgm + ' input:text[name*=FFNPR_]').length / 2; j++) {
                  i_rangestart = eval("$('#'+ap.render_pgm+' input:text[name*=_START]').eq(" + j + ").val()");
                  i_rangeend = eval("$('#'+ap.render_pgm+' input:text[name*=_END]').eq(" + j + ").val()");
                  hex_singlevalue = encodeToHex(pc_FFNPnum);
                  hex_rangestart = encodeToHex(i_rangestart);
                  hex_rangeend = encodeToHex(i_rangeend);
                  if ((compareValues(hex_rangestart, hex_singlevalue) <= 0) && (compareValues(hex_singlevalue, hex_rangeend) <= 0)) {
                     b_FFNPvalid = false;
                     $('<div />').html(langs.getText("p106","alert_savefail") + " " + langs.getText("p106","alert_sameval") + " : " + pc_FFNPnum).dialog({
                        modal: true,
                        closeOnEscape: false,
                        title: langs.getText("common","notification"),
                        open: function (event, ui) {
                           $(".ui-dialog-titlebar-close").hide();
                        },
								buttons: [
									{
										text: langs.getText("common","simple_okay"),
										click: function () {
											$(this).dialog("destroy");
										}
									}
								]
                     });
                     break;
                  }
               }
            }
         }
      } else {
         b_FFNPvalid = false;
         $('<div />').html(langs.getText("p106","alert_savefail") + " " + langs.getText("p106","alert_spaceval") + " : " + pc_FFNPnum).dialog({
            modal: true,
            closeOnEscape: false,
            title: langs.getText("common","notification"),
            open: function (event, ui) {
               $(".ui-dialog-titlebar-close").hide();
            },
				buttons: [
					{
						text: langs.getText("common","simple_okay"),
						click: function () {
							$(this).dialog("destroy");
						}
					}
				]
         });
      }

      if (b_FFNPvalid == false) {
         return false;
      }
   }

   if (b_FFNPvalid == true) {
      var i_checkstart = -1;
      var i_checkend = -1;
      // range check
      for (i = 0; i < $('#' + ap.render_pgm + ' input:text[name*=FFNPR_]').length / 2; i++) {
         i_checkstart = eval("$('#'+ap.render_pgm+' input:text[name*=_START]').eq(" + i + ").val()");
         i_checkend = eval("$('#'+ap.render_pgm+' input:text[name*=_END]').eq(" + i + ").val()");

         if ((i_checkstart.match(" ")) || (i_checkend.match(" "))) {
            b_FFNPvalid = false;
            $('<div />').html(langs.getText("p106","alert_savefail") + " " + langs.getText("p106","alert_spaceran") + " : " + i_checkstart + " - " + i_checkend).dialog({
               modal: true,
               closeOnEscape: false,
               title: langs.getText("common","notification"),
               open: function (event, ui) {
                  $(".ui-dialog-titlebar-close").hide();
               },
					buttons: [
						{
							text: langs.getText("common","simple_okay"),
							click: function () {
								$(this).dialog("destroy");
							}
						}
					]
            });
         } else {
            if ((i_checkstart.length != 0) && (i_checkend.length != 0)) {
               for (j = i + 1; j < $('#' + ap.render_pgm + ' input:text[name*=FFNPR_]').length / 2; j++) {
                  i_rangestart = eval("$('#'+ap.render_pgm+' input:text[name*=_START]').eq(" + j + ").val()");
                  i_rangeend = eval("$('#'+ap.render_pgm+' input:text[name*=_END]').eq(" + j + ").val()");
                  hex_checkstart = encodeToHex(i_checkstart);
                  hex_checkend = encodeToHex(i_checkend);
                  hex_rangestart = encodeToHex(i_rangestart);
                  hex_rangeend = encodeToHex(i_rangeend);
                  if ((compareValues(hex_rangestart, hex_checkstart) <= 0) && (compareValues(hex_checkstart, hex_rangeend) <= 0)) {
                     b_FFNPvalid = false;
                     $('<div />').html(langs.getText("p106","alert_savefail") + " " + langs.getText("p106","alert_conflictran") + " : " + i_checkstart + " - " + i_checkend).dialog({
                        modal: true,
                        closeOnEscape: false,
                        title: langs.getText("common","notification"),
                        open: function (event, ui) {
                           $(".ui-dialog-titlebar-close").hide();
                        },
								buttons: [
									{
										text: langs.getText("common","simple_okay"),
										click: function () {
											$(this).dialog("destroy");
										}
									}
								]
                     });
                     break;
                  } else if ((compareValues(hex_rangestart, hex_checkend) <= 0) && (compareValues(hex_checkend, hex_rangeend) <= 0)) {
                     b_FFNPvalid = false;
                     $('<div />').html(langs.getText("p106","alert_savefail") + " " + langs.getText("p106","alert_conflictran") + " : " + i_checkstart + " - " + i_checkend).dialog({
                        modal: true,
                        closeOnEscape: false,
                        title: langs.getText("common","notification"),
                        open: function (event, ui) {
                           $(".ui-dialog-titlebar-close").hide();
                        },
								buttons: [
									{
										text: langs.getText("common","simple_okay"),
										click: function () {
											$(this).dialog("destroy");
										}
									}
								]
                     });
                     break;
                  } else if ((compareValues(hex_checkstart, hex_rangestart) <= 0) && (compareValues(hex_rangestart, hex_checkend) <= 0)) {
                     b_FFNPvalid = false;
                     $('<div />').html(langs.getText("p106","alert_savefail") + " " + langs.getText("p106","alert_conflictran") + " : " + i_checkstart + " - " + i_checkend).dialog({
                        modal: true,
                        closeOnEscape: false,
                        title: langs.getText("common","notification"),
                        open: function (event, ui) {
                           $(".ui-dialog-titlebar-close").hide();
                        },
								buttons: [
									{
										text: langs.getText("common","simple_okay"),
										click: function () {
											$(this).dialog("destroy");
										}
									}
								]
                     });
                     break;
                  } else if ((compareValues(hex_checkstart, hex_rangeend) <= 0) && (compareValues(hex_rangeend, hex_checkend) <= 0)) {
                     b_FFNPvalid = false;
                     $('<div />').html(langs.getText("p106","alert_savefail") + " " + langs.getText("p106","alert_conflictran") + " : " + i_checkstart + " - " + i_checkend).dialog({
                        modal: true,
                        closeOnEscape: false,
                        title: langs.getText("common","notification"),
                        open: function (event, ui) {
                           $(".ui-dialog-titlebar-close").hide();
                        },
								buttons: [
									{
										text: langs.getText("common","simple_okay"),
										click: function () {
											$(this).dialog("destroy");
										}
									}
								]
                     });
                     break;
                  }
               }
            } else if ((i_checkstart.length != 0) && (i_checkend.length == 0)) {
               b_FFNPvalid = false;
               $('<div />').html(langs.getText("p106","alert_savefail") + " " + langs.getText("p106","alert_invalran") + " : " + i_checkstart).dialog({
                  modal: true,
                  closeOnEscape: false,
                  title: langs.getText("common","notification"),
                  open: function (event, ui) {
                     $(".ui-dialog-titlebar-close").hide();
                  },
						buttons: [
							{
								text: langs.getText("common","simple_okay"),
								click: function () {
									$(this).dialog("destroy");
								}
							}
						]
               });
            } else if ((i_checkstart.length == 0) && (i_checkend.length != 0)) {
               b_FFNPvalid = false;
               $('<div />').html(langs.getText("p106","alert_savefail") + " " + langs.getText("p106","alert_invalran") + " : " + i_checkend).dialog({
                  modal: true,
                  closeOnEscape: false,
                  title: langs.getText("common","notification"),
                  open: function (event, ui) {
                     $(".ui-dialog-titlebar-close").hide();
                  },
						buttons: [
							{
								text: langs.getText("common","simple_okay"),
								click: function () {
									$(this).dialog("destroy");
								}
							}
						]
               });
            }
         }

         if (b_FFNPvalid == false) {
            return false;
         }
      }

      if (b_FFNPvalid == true) {
         var send_msg = "{";
         var dont_save = false;
         for (i = 0; i < $('#' + ap.render_pgm + ' input:text').length; i++) {
            if ($('#' + ap.render_pgm + ' input:text').eq(i).val().match(/[^0-9*#]/g)) {
               dont_save = true;
               $('#' + ap.render_pgm + ' input:text').eq(i).css("outline", "2px solid red").css("margin", "2px").after("<font class='error' style='font-weight: bold; color: red;'>" + langs.getText("error_msg","opt_range_error_case2") + "</font>");
            } else {
               if (i != 0) {
                  send_msg += ",";
               }

               send_msg += "\"" + $('#' + ap.render_pgm + ' input:text').eq(i).attr('name') + "\":\"" + $('#' + ap.render_pgm + ' input:text').eq(i).val() + "\"";
            }
         }
         send_msg += "}";

         if (!dont_save) {
            setSpecialPacket(send_msg);
            debug_mode.flag && console.log(send_msg);
            $('#' + ap.render_pgm).html("");
            pgm_models.get_model(ap.render_pgm, false, packet);
         }
      }
   }
});

$(document).on('click', '.btn_sendmail', function (evt) {
	var send_msg = "";

	if ($(this).hasClass('btn_db')) {
		send_msg = "{\"SEND_MAIL\":\"DB\"}";
	} else if ($(this).hasClass('btn_smdr')) {
		send_msg = "{\"SEND_MAIL\":\"SMDR\"}";
	} else if ($(this).hasClass('btn_acd')) {
		send_msg = "{\"SEND_MAIL\":\"ACD\"}";
	} else if ($(this).hasClass('btn_alarm')) {
		send_msg = "{\"SEND_MAIL\":\"ALARM\"}";
	} else if ($(this).hasClass('btn_emailnoti')) {
		send_msg = "{\"SEND_MAIL\":\"EMAILNOTI\"}";
	} else if ($(this).hasClass('btn_p96_send')) {
		send_msg = "{\"SEND_MAIL\":\""+$('#' + ap.render_pgm + ' .contents [name=EMAIL_FIELD]').val()+"\"}";
	}

   setSpecialPacket(send_msg);
   debug_mode.flag && console.log(send_msg);
   sendMsg(packet.main, ap.render_pgm, packet.type, packet.range, packet.msg);
});

$(document).on('click', '.btn_p195_apply', function (evt) {
   var send_msg = "{\"NTP_SVRUPDATE\":\"\"}";
   setSpecialPacket(send_msg);
   debug_mode.flag && console.log(send_msg);
   $('#' + ap.render_pgm).html("");
   pgm_models.get_model(ap.render_pgm, true, packet);
});

$(document).on('change', '.p196_sel_mibtype', function (evt) {
	if (($(this).val() == "1")) {
		$('#'+ap.render_pgm+' [name=SNMP_KT_MIB_TYPE]').removeAttr('disabled');
	} else {
		$('#'+ap.render_pgm+' [name=SNMP_KT_MIB_TYPE]').attr('disabled','disabled');;
	}
});

$(document).on('click', '.btn_p255_sort', function (evt) {
   var send_msg = "{\"ACL_SORT\":\"\"}";
   setSpecialPacket(send_msg);
   debug_mode.flag && console.log(send_msg);
   $('#' + ap.render_pgm).html("");
   pgm_models.get_model(ap.render_pgm, false, packet);
});

$(document).on('click', '.btn_p255_apply', function (evt) {
   var send_msg = "{\"ACL_APPLY\":\"\"}";
   setSpecialPacket(send_msg);
   debug_mode.flag && console.log(send_msg);
   $('#' + ap.render_pgm).html("");
   pgm_models.get_model(ap.render_pgm, false, packet);
});

$(document).on('click', '.btn_p255_pause', function (evt) {
   var send_msg = "{\"ACL_STOP\":\"\"}";
   setSpecialPacket(send_msg);
   debug_mode.flag && console.log(send_msg);
   $('#' + ap.render_pgm).html("");
   pgm_models.get_model(ap.render_pgm, false, packet);
});

$(document).on('click', '.btn_p255_clear', function (evt) {
   var send_msg = "{\"ACL_CLEAR\":\"\"}";
   setSpecialPacket(send_msg);
   debug_mode.flag && console.log(send_msg);
   $('#' + ap.render_pgm).html("");
   pgm_models.get_model(ap.render_pgm, false, packet);
});

$(document).on('click', '.btn_p190_savegrptype', function (evt) {
   var send_msg = "{\"GRP_TYPE\":\"" + $('#' + ap.render_pgm + ' .contents [name=GRP_TYPE]').val() + "\",\"GRP_ATTR\":\"" + $('#' + ap.render_pgm + ' .contents [name=GRP_ATTR]').val() + "\"}";
   setSpecialPacket(send_msg);
   debug_mode.flag && console.log(send_msg);
   $('#' + ap.render_pgm).html("");
   pgm_models.get_model(ap.render_pgm, false, packet);
});

$(document).on('click', '.btn_p260_mstnsave', function (evt) {
   if ($('#' + ap.render_pgm + ' .error').length) {
      $('#' + ap.render_pgm + ' div').children().css('outline', '').css('margin', '');
      $('#' + ap.render_pgm + ' td').children().css('outline', '').css('margin', '');
      $('#' + ap.render_pgm + ' .error').remove();
   }

   if ($('#' + ap.render_pgm + ' .contents [name=GRP_MASTERSTN]').val().match(/[^0-9*#]/g)) {
      $('#' + ap.render_pgm + ' [name=GRP_MASTERSTN]').css('outline', '2px solid red').css('margin', '2px').nextUntil('br').after("<font class='error' style='font-weight: bold; color: red; margin: 0px 5px;'>" + langs.getText("error_msg","opt_range_error_case2") + "</font>");
      return false;
   }

   var send_msg = "{\"GRP_MASTERSTN\":\"" + $('#' + ap.render_pgm + ' .contents [name=GRP_MASTERSTN]').val() + "\"}";
   setSpecialPacket(send_msg);
   debug_mode.flag && console.log(send_msg);
   $('#' + ap.render_pgm).html("");
   pgm_models.get_model(ap.render_pgm, false, packet);
});

$(document).on('click', '.btn_grp_adddel_range', function (evt) {
   if ($('#' + ap.render_pgm + ' .error').length) {
      $('#' + ap.render_pgm + ' div').children().css('outline', '').css('margin', '');
      $('#' + ap.render_pgm + ' td').children().css('outline', '').css('margin', '');
      $('#' + ap.render_pgm + ' .error').remove();
   }

   var dont_save = false;
   var send_msg = "{";
   _.each($('#' + ap.render_pgm + ' [name=GRP_RANGE_MODE]'), function (item) {
      if (item.checked) {
         if ($('#' + ap.render_pgm + ' [name=GRP_RANGE_SMEMBER]').val().match(/[^0-9*#]/g) || $('#' + ap.render_pgm + ' [name=GRP_RANGE_EMEMBER]').val().match(/[^0-9*#]/g)) {
            if ($('#' + ap.render_pgm + ' [name=GRP_RANGE_SMEMBER]').val().match(/[^0-9*#]/g)) {
               $('#' + ap.render_pgm + ' [name=GRP_RANGE_SMEMBER]').css('outline', '2px solid red').css('margin', '2px');
            }
            if ($('#' + ap.render_pgm + ' [name=GRP_RANGE_EMEMBER]').val().match(/[^0-9*#]/g)) {
               $('#' + ap.render_pgm + ' [name=GRP_RANGE_EMEMBER]').css('outline', '2px solid red').css('margin', '2px');
            }

            dont_save = true;
            $('#' + ap.render_pgm + ' [name=GRP_RANGE_MODE]').parent().append("<font class='error' style='font-weight: bold; color: red; margin: 0px 5px;'>" + langs.getText("error_msg","opt_range_error_case2") + "</font>");
         }

         send_msg += "\"GRP_RANGE_SMEMBER\":\"" + $('#' + ap.render_pgm + ' [name=GRP_RANGE_SMEMBER]').val() + "\",\"GRP_RANGE_EMEMBER\":\"" + $('#' + ap.render_pgm + ' [name=GRP_RANGE_EMEMBER]').val() + "\",";
         send_msg += "\"GRP_RANGE_MODE\":\"" + item.value + "\"";
      }
   });
   send_msg += "}";

   if (!dont_save) {
      setSpecialPacket(send_msg);
      debug_mode.flag && console.log(send_msg);
      $('#' + ap.render_pgm).html("");
      pgm_models.get_model(ap.render_pgm, false, packet);
   }
});

$(document).on('click', '.btn_grp_addstn', function (evt) {
   if ($('#' + ap.render_pgm + ' .error').length) {
      $('#' + ap.render_pgm + ' div').children().css('outline', '').css('margin', '');
      $('#' + ap.render_pgm + ' td').children().css('outline', '').css('margin', '');
      $('#' + ap.render_pgm + ' .error').remove();
   }

   var dont_save = false;
   var send_msg = "{";
   _.each($('#' + ap.render_pgm + ' [name=GRP_ADDMEMBER]'), function (item, i) {
      if ($('#' + ap.render_pgm + ' [name=GRP_ADDMEMBER]:eq(' + i + ')').val().match(/[^0-9*#]/g)) {
         dont_save = true;
         $('#' + ap.render_pgm + ' [name=GRP_ADDMEMBER]:eq(' + i + ')').css('outline', '2px solid red').css('margin', '2px').after("<font class='error' style='font-weight: bold; color: red; margin: 0px 5px;'>" + langs.getText("error_msg","opt_range_error_case2") + "</font>");
      }

      send_msg += "\"GRP_ADDMEMBER\":\"" + $('#' + ap.render_pgm + ' [name=GRP_ADDMEMBER]:eq(' + i + ')').val() + "\"";

      if (i < $('#' + ap.render_pgm + ' [name=GRP_ADDMEMBER]').length - 1) {
         send_msg += ",";
      }
   });
   send_msg += "}";

   if (!dont_save) {
      setSpecialPacket(send_msg);
      debug_mode.flag && console.log(send_msg);
      $('#' + ap.render_pgm).html("");
      pgm_models.get_model(ap.render_pgm, false, packet);
   }
});

$(document).on('click', '.btn_grp_delstn', function (evt) {
   var comma = 0;
   var dont_save = false;
   var skip_flag = false;
   var send_msg = "{";

   if ($('#' + ap.render_pgm + ' .error').length) {
      $('#' + ap.render_pgm + ' div').children().css('outline', '').css('margin', '');
      $('#' + ap.render_pgm + ' td').children().css('outline', '').css('margin', '');
      $('#' + ap.render_pgm + ' .error').remove();
   }

   _.each($('#' + ap.render_pgm + ' tr input'), function (item, i) {
      skip_flag = false;

      if (item.name) {
         if (item.name.match(/^GRP_DELMEMBER/)) {
            if (comma != 0) {
               send_msg += ",";
            }

            if (item.checked) {
               send_msg += "\"" + item.name + "\":\"1\"";
            } else {
               send_msg += "\"" + item.name + "\":\"0\"";
            }

            comma++;
         } else if (item.name.match(/^GRP_MEMBERSTN/) || item.name.match(/^GRP_DELAY/)) {
            if (item.name.match(/^GRP_MEMBERSTN/)) {
               if (item.value.match(/[^0-9*#]/g)) {
                  dont_save = true;
                  if (!$('#' + ap.render_pgm + ' tr input:eq(' + i + ')').parent().children('.error').length) {
                     $('#' + ap.render_pgm + ' tr input:eq(' + i + ')').css('outline', '2px solid red').css('margin', '2px').after("<font class='error' style='font-weight: bold; color: red; margin: 0px 5px;'>" + langs.getText("error_msg","opt_range_error_case2") + "</font>");
                  }
               }

               if (item.value) {
                  _.each($('#' + ap.render_pgm + ' tr input'), function (memstn, j) {
                     if (i != j) {
                        if (memstn.name.match(/^GRP_MEMBERSTN/)) {
                           if (item.value == memstn.value) {
                              if (!$('#' + ap.render_pgm + ' tr input:eq(' + i + ')').parent().children('.error').length) {
                                 $('#' + ap.render_pgm + ' tr input:eq(' + i + ')').css('outline', '2px solid red').css('margin', '2px').after("<font class='error' style='font-weight: bold; color: red;'>" + langs.getText("error_msg","error_grp_delstn_exist1") + " " + item.value + " " + langs.getText("error_msg","error_grp_delstn_exist2") + "</font>");
                              }
                              dont_save = true;
                              skip_flag = true;
                           }
                        }
                     }

                     if (skip_flag) {
                        return false;
                     }
                  });
               }
            } else if (item.name.match(/^GRP_DELAY/)) {
               if (item.value.match(/[^0-9]/g)) {
                  dont_save = true;
                  if (!$('#' + ap.render_pgm + ' tr input:eq(' + i + ')').parent().children('.error').length) {
                     $('#' + ap.render_pgm + ' tr input:eq(' + i + ')').css('outline', '2px solid red').css('margin', '2px').after("<font class='error' style='font-weight: bold; color: red; margin: 0px 5px;'>" + langs.getText("error_msg","opt_range_error_case3") + "</font>");
                  }
               }
            }

            if (comma != 0) {
               send_msg += ",";
            }

            send_msg += "\"" + item.name + "\":\"" + item.value + "\"";

            comma++;
         }
      }
   });

   if (!dont_save) {
      send_msg += "}";

      setSpecialPacket(send_msg);
      debug_mode.flag && console.log(send_msg);
      $('#' + ap.render_pgm).html("");
      pgm_models.get_model(ap.render_pgm, false, packet);
   } else {
      return false;
   }
});

$(document).on('click', '.btn_p133_wadreg', function (evt) {
   var send_msg = "{\"REG_START\":\"\",\"REG_END\":\"\"}";
   setSpecialPacket(send_msg);
   debug_mode.flag && console.log(send_msg);
   $('#' + ap.render_pgm).html("");
   pgm_models.get_model(ap.render_pgm, false, packet);
});

$(document).on('click', '.btn_p133_wadunreg', function (evt) {
   var send_msg = "{\"UNREG_START\":\"\",\"UNREG_END\":\"\"}";
   setSpecialPacket(send_msg);
   debug_mode.flag && console.log(send_msg);
   $('#' + ap.render_pgm).html("");
   pgm_models.get_model(ap.render_pgm, false, packet);
});

$(document).on('click', '.btn_p162_save', function (evt) {
   var dont_save = false;
   var send_msg = "{";
	var adm_chk = false;
	var mnt_chk = false;
   if ($('#' + ap.render_pgm + ' .error').length) {
      $('#' + ap.render_pgm + ' div').children().css('outline', '').css('margin', '');
      $('#' + ap.render_pgm + ' td').children().css('outline', '').css('margin', '');
      $('#' + ap.render_pgm + ' .error').remove();
   }
	if ($('#' + ap.render_pgm + ' [name=CHKSAVE_ADM]').length && $('#' + ap.render_pgm + ' [name=SYS_ADMCURPWD]').length && $('#' + ap.render_pgm + ' [name=SYS_ADMNEWPWD]').length && $('#' + ap.render_pgm + ' [name=SYS_ADMNEWPWD2]').length) {
		if ($('#' + ap.render_pgm + ' [name=CHKSAVE_ADM]')[0].checked) {
			adm_chk = true;
			if ($('#' + ap.render_pgm + ' [name=SYS_ADMCURPWD]').val().match(/[^0-9*#]/g)) {
				$('#' + ap.render_pgm + ' [name=SYS_ADMCURPWD]').css('outline', '2px solid red').css('margin', '2px').after("<font class='error' style='font-weight: bold; color: red; margin: 0px 5px;'>" + langs.getText("error_msg","opt_range_error_case2") + "</font>");
				dont_save = true;
			}

			if ($('#' + ap.render_pgm + ' [name=SYS_ADMNEWPWD]').val().match(/[^0-9*#]/g)) {
				$('#' + ap.render_pgm + ' [name=SYS_ADMNEWPWD]').css('outline', '2px solid red').css('margin', '2px').after("<font class='error' style='font-weight: bold; color: red; margin: 0px 5px;'>" + langs.getText("error_msg","opt_range_error_case2") + "</font>");
				dont_save = true;
			}

			if ($('#' + ap.render_pgm + ' [name=SYS_ADMNEWPWD2]').val().match(/[^0-9*#]/g)) {
				$('#' + ap.render_pgm + ' [name=SYS_ADMNEWPWD2]').css('outline', '2px solid red').css('margin', '2px').after("<font class='error' style='font-weight: bold; color: red; margin: 0px 5px;'>" + langs.getText("error_msg","opt_range_error_case2") + "</font>");
				dont_save = true;
			}

			if (($('#' + ap.render_pgm + ' [name=SYS_ADMNEWPWD]').val() != $('#' + ap.render_pgm + ' [name=SYS_ADMNEWPWD2]').val()) && !dont_save) {
				$('#' + ap.render_pgm + ' [name=SYS_ADMNEWPWD]').css('outline', '2px solid red').css('margin', '2px').after("<font class='error' style='font-weight: bold; color: red; margin: 0px 5px;'>" + langs.getText("p162","pwd_notequal") + "</font>");
				$('#' + ap.render_pgm + ' [name=SYS_ADMNEWPWD2]').css('outline', '2px solid red').css('margin', '2px').after("<font class='error' style='font-weight: bold; color: red; margin: 0px 5px;'>" + langs.getText("p162","pwd_notequal") + "</font>");
				$('<div />').html(langs.getText("p162","alert_admpwd_mismatch")).dialog({
					modal: true,
					closeOnEscape: false,
					title: langs.getText("common","notification"),
					open: function (event, ui) {
						$(".ui-dialog-titlebar-close").hide();
					},
					buttons: [
						{
							text: langs.getText("common","simple_okay"),
							click: function () {
								$(this).dialog("destroy");
							}
						}
					]
				});
				return false;
			} else {
				if(!offline_mode) {
					send_msg += "\"SYS_ADMCURPWD\":\"" + RSA.encrypt($('#' + ap.render_pgm + ' [name=SYS_ADMCURPWD]').val(), $key) + "\",\"SYS_ADMNEWPWD\":\"" + RSA.encrypt($('#' + ap.render_pgm + ' [name=SYS_ADMNEWPWD]').val(), $key) + "\",\"SYS_ADMNEWPWD2\":\"" + RSA.encrypt($('#' + ap.render_pgm + ' [name=SYS_ADMNEWPWD2]').val(), $key) + "\"";
				} else {
					send_msg += "\"SYS_ADMCURPWD\":\"" + $('#' + ap.render_pgm + ' [name=SYS_ADMCURPWD]').val() + "\",\"SYS_ADMNEWPWD\":\"" + $('#' + ap.render_pgm + ' [name=SYS_ADMNEWPWD]').val() + "\",\"SYS_ADMNEWPWD2\":\"" + $('#' + ap.render_pgm + ' [name=SYS_ADMNEWPWD2]').val() + "\"";
				}
			}
		}
   }
   if ($('#' + ap.render_pgm + ' [name=CHKSAVE_MNT]').length && $('#' + ap.render_pgm + ' [name=SYS_MAINTCURPWD]').length && $('#' + ap.render_pgm + ' [name=SYS_MAINTNEWPWD]').length && $('#' + ap.render_pgm + ' [name=SYS_MAINTNEWPWD2]').length) {
		if ($('#' + ap.render_pgm + ' [name=CHKSAVE_MNT]')[0].checked) {
			mnt_chk = true;
			if ($('#' + ap.render_pgm + ' [name=SYS_MAINTNEWPWD]').val() != $('#' + ap.render_pgm + ' [name=SYS_MAINTNEWPWD2]').val()) {
				$('#' + ap.render_pgm + ' [name=SYS_MAINTNEWPWD]').css('outline', '2px solid red').css('margin', '2px').after("<font class='error' style='font-weight: bold; color: red; margin: 0px 5px;'>" + langs.getText("p162","pwd_notequal") + "</font>");
				$('#' + ap.render_pgm + ' [name=SYS_MAINTNEWPWD2]').css('outline', '2px solid red').css('margin', '2px').after("<font class='error' style='font-weight: bold; color: red; margin: 0px 5px;'>" + langs.getText("p162","pwd_notequal") + "</font>");
				$('<div />').html(langs.getText("p162","alert_mntpwd_mismatch")).dialog({
					modal: true,
					closeOnEscape: false,
					title: langs.getText("common","notification"),
					open: function (event, ui) {
						$(".ui-dialog-titlebar-close").hide();
					},
					buttons: [
						{
							text: langs.getText("common","simple_okay"),
							click: function () {
								$(this).dialog("destroy");
							}
						}
					]
				});
				return false;
			} else {
				if (adm_chk) {
					send_msg += ",";
				}

				if(!offline_mode) {
					send_msg += "\"SYS_MAINTCURPWD\":\"" + RSA.encrypt($('#' + ap.render_pgm + ' [name=SYS_MAINTCURPWD]').val(), $key) + "\",\"SYS_MAINTNEWPWD\":\"" + RSA.encrypt($('#' + ap.render_pgm + ' [name=SYS_MAINTNEWPWD]').val(), $key) + "\",\"SYS_MAINTNEWPWD2\":\"" + RSA.encrypt($('#' + ap.render_pgm + ' [name=SYS_MAINTNEWPWD2]').val(), $key) + "\"";
				} else {
					send_msg += "\"SYS_MAINTCURPWD\":\"" + $('#' + ap.render_pgm + ' [name=SYS_MAINTCURPWD]').val() + "\",\"SYS_MAINTNEWPWD\":\"" + $('#' + ap.render_pgm + ' [name=SYS_MAINTNEWPWD]').val() + "\",\"SYS_MAINTNEWPWD2\":\"" + $('#' + ap.render_pgm + ' [name=SYS_MAINTNEWPWD2]').val() + "\"";
				}
			}
		}
   }
   if ($('#' + ap.render_pgm + ' [name=CHKSAVE_CID]').length && $('#' + ap.render_pgm + ' [name=SYS_CIDCURPWD]').length && $('#' + ap.render_pgm + ' [name=SYS_CIDNEWPWD]').length && $('#' + ap.render_pgm + ' [name=SYS_CIDNEWPWD2]').length) {
		if ($('#' + ap.render_pgm + ' [name=CHKSAVE_CID]')[0].checked) {
			if ($('#' + ap.render_pgm + ' [name=SYS_CIDNEWPWD]').val() != $('#' + ap.render_pgm + ' [name=SYS_CIDNEWPWD2]').val()) {
				$('#' + ap.render_pgm + ' [name=SYS_CIDNEWPWD]').css('outline', '2px solid red').css('margin', '2px').after("<font class='error' style='font-weight: bold; color: red; margin: 0px 5px;'>" + langs.getText("p162","pwd_notequal") + "</font>");
				$('#' + ap.render_pgm + ' [name=SYS_CIDNEWPWD2]').css('outline', '2px solid red').css('margin', '2px').after("<font class='error' style='font-weight: bold; color: red; margin: 0px 5px;'>" + langs.getText("p162","pwd_notequal") + "</font>");
				$('<div />').html(langs.getText("p162","alert_cidpwd_mismatch")).dialog({
					modal: true,
					closeOnEscape: false,
					title: langs.getText("common","notification"),
					open: function (event, ui) {
						$(".ui-dialog-titlebar-close").hide();
					},
					buttons: [
						{
							text: langs.getText("common","simple_okay"),
							click: function () {
								$(this).dialog("destroy");
							}
						}
					]
				});
				return false;
			} else {
				if (adm_chk || mnt_chk) {
					send_msg += ",";
				}

				if(!offline_mode) {
					send_msg += "\"SYS_CIDCURPWD\":\"" + RSA.encrypt($('#' + ap.render_pgm + ' [name=SYS_CIDCURPWD]').val(), $key) + "\",\"SYS_CIDNEWPWD\":\"" + RSA.encrypt($('#' + ap.render_pgm + ' [name=SYS_CIDNEWPWD]').val(), $key) + "\",\"SYS_CIDNEWPWD2\":\"" + RSA.encrypt($('#' + ap.render_pgm + ' [name=SYS_CIDNEWPWD2]').val(), $key) + "\"";
				} else {
					send_msg += "\"SYS_CIDCURPWD\":\"" + $('#' + ap.render_pgm + ' [name=SYS_CIDCURPWD]').val() + "\",\"SYS_CIDNEWPWD\":\"" + $('#' + ap.render_pgm + ' [name=SYS_CIDNEWPWD]').val() + "\",\"SYS_CIDNEWPWD2\":\"" + $('#' + ap.render_pgm + ' [name=SYS_CIDNEWPWD2]').val() + "\"";
				}
			}
		}
   }
   send_msg += "}";
   if (!dont_save) {
      setSpecialPacket(send_msg);
      debug_mode.flag && console.log(send_msg);
      $('#' + ap.render_pgm).html("");
      pgm_models.get_model(ap.render_pgm, false, packet);
   }
});

$(document).on('click', '.chk_p178_dontsave', function (evt) {
   if ($(this).get(0).checked == true) {
		if ($('#' + ap.render_pgm + ' table [name=TDSET_HOUR]').length) {
			$('#' + ap.render_pgm + ' table [name=TDSET_HOUR]').attr('disabled', true);
      }
      if ($('#' + ap.render_pgm + ' table [name=TDSET_MIN]').length) {
			$('#' + ap.render_pgm + ' table [name=TDSET_MIN]').attr('disabled', true);
      }
      if ($('#' + ap.render_pgm + ' table [name=TDSET_MON]').length) {
			$('#' + ap.render_pgm + ' table [name=TDSET_MON]').attr('disabled', true);
      }
      if ($('#' + ap.render_pgm + ' table [name=TDSET_DAY]').length) {
			$('#' + ap.render_pgm + ' table [name=TDSET_DAY]').attr('disabled', true);
      }
      if ($('#' + ap.render_pgm + ' table [name=TDSET_YEAR]').length) {
			$('#' + ap.render_pgm + ' table [name=TDSET_YEAR]').attr('disabled', true);
      }
   } else {
		if ($('#' + ap.render_pgm + ' table [name=TDSET_HOUR]').length) {
			$('#' + ap.render_pgm + ' table [name=TDSET_HOUR]').attr('disabled', false);
      }
      if ($('#' + ap.render_pgm + ' table [name=TDSET_MIN]').length) {
			$('#' + ap.render_pgm + ' table [name=TDSET_MIN]').attr('disabled', false);
      }
      if ($('#' + ap.render_pgm + ' table [name=TDSET_MON]').length) {
			$('#' + ap.render_pgm + ' table [name=TDSET_MON]').attr('disabled', false);
      }
      if ($('#' + ap.render_pgm + ' table [name=TDSET_DAY]').length) {
			$('#' + ap.render_pgm + ' table [name=TDSET_DAY]').attr('disabled', false);
      }
      if ($('#' + ap.render_pgm + ' table [name=TDSET_YEAR]').length) {
			$('#' + ap.render_pgm + ' table [name=TDSET_YEAR]').attr('disabled', false);
      }
   }
});

$(document).on('click', '.btn_p212_load', function (evt) {
   var send_msg = "{\"LOAD_PHONECONF\":\"\", \"SIP_CONFTYPE\":\"" + $('#' + ap.render_pgm + ' [name=SIP_CONFTYPE]').val() + "\", \"SIP_MAC\":\"" + $('#' + ap.render_pgm + ' [name=SIP_MAC]').val() + "\"}";
  setSpecialPacket(send_msg);
   debug_mode.flag && console.log(send_msg);
   $('#' + ap.render_pgm).html("");
   pgm_models.get_model(ap.render_pgm, true, packet);
});

$(document).on('click', '.btn_p212_store', function (evt) {
   var send_msg = "{\"CONF_STORE\":\"\"}";
   setSpecialPacket(send_msg);
   debug_mode.flag && console.log(send_msg);
   $('#' + ap.render_pgm).html("");
   pgm_models.get_model(ap.render_pgm, true, packet);
});

$(document).on('click', '.btn_p231_initall', function (evt) {
   $('<div />').html(langs.getText("p231","confirm_initall")).dialog({
      modal: true,
      closeOnEscape: false,
      title: langs.getText("common","notification"),
      open: function (event, ui) {
         $(".ui-dialog-titlebar-close").hide();
      },
      buttons: [
			{
				text: langs.getText("common","simple_okay"),
				click: function () {
					var send_msg = "{\"INIT\":\"EXEC_FDC\"}";
					setSpecialPacket(send_msg);
					debug_mode.flag && console.log(send_msg);
					$('#' + ap.render_pgm).html("");
					pgm_models.get_model(ap.render_pgm, false, packet);
					$(this).dialog("destroy");
				}
			},
			{
				text: langs.getText("common","cancel"),
				click: function () {
					$(this).dialog("destroy");
				}
			}
		]
   });
});

$(document).on('click', '.btn_p231_delall', function (evt) {
   $('<div />').html(langs.getText("p231","confirm_delall")).dialog({
      modal: true,
      closeOnEscape: false,
      title: langs.getText("common","notification"),
      open: function (event, ui) {
         $(".ui-dialog-titlebar-close").hide();
      },
      buttons: [
			{
				text: langs.getText("common","simple_okay"),
				click: function () {
					var send_msg = "{\"DEL\":\"EXEC_FDC\"}";
					setSpecialPacket(send_msg);
					debug_mode.flag && console.log(send_msg);
					$('#' + ap.render_pgm).html("");
					pgm_models.get_model(ap.render_pgm, false, packet);
					$(this).dialog("destroy");
				}
			},
			{
				text: langs.getText("common","cancel"),
				click: function () {
					$(this).dialog("destroy");
				}
			}
		]
   });
});

$(document).on('click', '.btn_p227_rangesave', function (evt) {
   var dont_save = false;
   var skip_flag = false;

   if ($('#' + ap.render_pgm + ' .error').length) {
      $('#' + ap.render_pgm + ' td').children().css('outline', '').css('margin', '');
      $('#' + ap.render_pgm + ' .error').remove();
   }

   var send_msg = "{";
   _.each($(this).parents('table').children().children(), function (items, i) {
      var j = 0;
      _.each(items.childNodes, function (item) {
         _.each(item.childNodes, function (node) {
            if (node.name && (node.name != "undefined")) {
               if (node.type == "radio" && node.checked == true) {
                  skip_flag = false;
               } else if (node.type == "radio" && node.checked == false) {
                  skip_flag = true;
               }

               if (!skip_flag) {
						if (node.name == "STN_AUTHSTART" || node.name == "STN_AUTHEND" || node.name == "STN_COSSTART" || node.name == "STN_COSEND" || node.name == "STN_CHAUTH") {
                     if (node.value.match(/[^0-9*#]/g)) {
                        $('#' + ap.render_pgm + ' [name=' + node.name + ']').css("outline", "2px solid red").css("margin", "2px");
                        if (!$('#' + ap.render_pgm + ' [name=' + node.name + ']').parent().children('.error').length) {
                           $('#' + ap.render_pgm + ' [name=' + node.name + ']').parent().append("<font class='error' style='font-weight: bold; color: red;'>" + langs.getText("error_msg","opt_range_error_case2") + "</font>");
                        }
                        dont_save = true;
                     }
                  }

                  if(j != 0) {
							send_msg += ","
                  }

                  if ((node.name == "STN_CHAUTH") && !offline_mode) {
							if (node.value) {
								send_msg += "\"" + node.name + "\":\"" + RSA.encrypt(node.value, $key) + "\"";
							} else {
								send_msg += "\"" + node.name + "\":\"\"";
							}
                  } else {
							send_msg += "\"" + node.name + "\":\"" + node.value + "\"";
                  }
                  j++;
               }
            }
         });
      });
   });
   send_msg += "}";
   if (!dont_save) {
      setSpecialPacket(send_msg);
      debug_mode.flag && console.log(send_msg);
      $('#' + ap.render_pgm).html("");
      pgm_models.get_model(ap.render_pgm, false, packet);
   }
});

$(document).on('click', '.btn_p2271_rangesave', function (evt) {
   var dont_save = false;
   var skip_flag = false;

   if ($('#' + ap.render_pgm + ' .error').length) {
      $('#' + ap.render_pgm + ' td').children().css('outline', '').css('margin', '');
      $('#' + ap.render_pgm + ' .error').remove();
   }

   var send_msg = "{";
   _.each($(this).parents('table').children().children(), function (items, i) {
      var j = 0;
      _.each(items.childNodes, function (item) {
         _.each(item.childNodes, function (node) {
            if (node.name && (node.name != "undefined")) {
               if (node.type == "radio" && node.checked == true) {
                  skip_flag = false;
               } else if (node.type == "radio" && node.checked == false) {
                  skip_flag = true;
               }

               if (!skip_flag) {
						if (node.name == "SYS_COSSTART" || node.name == "SYS_COSEND" || node.name == "SYS_REMARKSTART" || node.name == "SYS_REMARKEND") {
                     if (node.value.match(/[^0-9]/g)) {
                        $('#' + ap.render_pgm + ' [name=' + node.name + ']').css("outline", "2px solid red").css("margin", "2px");
                        if (!$('#' + ap.render_pgm + ' [name=' + node.name + ']').parent().children('.error').length) {
                           $('#' + ap.render_pgm + ' [name=' + node.name + ']').parent().append("<font class='error' style='font-weight: bold; color: red;'>" + langs.getText("error_msg","opt_range_error_case3") + "</font>");
                        }
                        dont_save = true;
                     }
                  } else if (node.name == "SYS_CHREMARK") {
                     if (!node.className.match('enable_mullang')) {
								if (node.value.match(/[^a-zA-Z0-9\s\{\}\[\]\/?.,;:|\)*~`!^\-_+┼<>@\#$%&\'\(\=\\]/g)) {
									dont_save = true;
									$('#' + ap.render_pgm + ' [name=' + node.name + ']').css("outline", "2px solid red").css("margin", "2px");
									$('#' + ap.render_pgm + ' [name=' + node.name + ']').parent().append("<font class='error' style='font-weight: bold; color: red;'>" + langs.getText("error_msg","error_mullang") + "</font>");
                        }
                     } else {
								if (chkKoreanLength(node.value) > node.maxLength) {
									dont_save = true;
									$('#' + ap.render_pgm + ' [name=' + node.name + ']').css("outline", "2px solid red").css("margin", "2px");
									$('#' + ap.render_pgm + ' [name=' + node.name + ']').parent().append("<font class='error' style='font-weight: bold; color: red; margin: 0px 5px;'>" + langs.getText("error_msg","over_cnt") + "</font>");
								}
                     }

                     if (node.value.match(/[\f\r\n\t\v\"]/g) && !dont_save) {
								dont_save = true;
								$('#' + ap.render_pgm + ' [name=' + node.name + ']').css("outline", "2px solid red").css("margin", "2px");
								$('#' + ap.render_pgm + ' [name=' + node.name + ']').parent().append("<font class='error' style='font-weight: bold; color: red; margin: 0px 5px;'>" + langs.getText("error_msg","error_mullang") + "</font>");
                     }
                  }

                  if(j != 0) {
							send_msg += ","
                  }

						send_msg += "\"" + node.name + "\":\"" + node.value + "\"";
                  j++;
               }
            }
         });
      });
   });
   send_msg += "}";
   if (!dont_save) {
      setSpecialPacket(send_msg);
      debug_mode.flag && console.log(send_msg);
      $('#' + ap.render_pgm).html("");
      pgm_models.get_model(ap.render_pgm, false, packet);
   }
});

$(document).on('change', '.p265_select', function (evt) {
   if ($(this).val() == "1") {
      $(this).parents('tr').children().eq(4).hide();
      $(this).parents('tr').children().eq(5).show();
   } else {
      $(this).parents('tr').children().eq(4).show();
      $(this).parents('tr').children().eq(5).hide();
   }
});

$(document).on('change', '.p270_select', function (evt) {
   if ($(this).val() == "0") {
      $(this).parents('tr').children().eq(4).show();
      $(this).parents('tr').children().eq(5).hide();
      $(this).parents('tr').children().eq(6).hide();
   } else if ($(this).val() == "1") {
      $(this).parents('tr').children().eq(4).hide();
      $(this).parents('tr').children().eq(5).show();
      $(this).parents('tr').children().eq(6).hide();
   } else if ($(this).val() == "2") {
      $(this).parents('tr').children().eq(4).hide();
      $(this).parents('tr').children().eq(5).hide();
      $(this).parents('tr').children().eq(6).show();
   }
});

$(document).on('click', '.btn_p3132_receipt', function (evt) {
   var send_msg = "{}";
   setSpecialPacket(send_msg);
   debug_mode.flag && console.log(send_msg);
   make_hotelrecipt_pgm(packet);
});

$(document).on('click', '.btn_p3132_printroomch', function (evt) {
   var send_msg = "{}";
   setSpecialPacket(send_msg);
   debug_mode.flag && console.log(send_msg);
   make_hotelroomch_pgm(packet);
});

$(document).on('click', '.btn_ps007_labelprint', function (evt) {
   make_stnlabel_pgm();
});

$(document).on('click', '.btn_p443_idsave', function (evt) {
   if ($('#' + ap.render_pgm + ' .error').length) {
      $('#' + ap.render_pgm + ' td').children().css('outline', '').css('margin', '');
      $('#' + ap.render_pgm + ' .error').remove();
   }

   var dont_save = false;
   var send_msg = "{";
   var j = 0;
   _.each($(this).parents('table').children().children(), function (items, i) {
      _.each(items.childNodes, function (item) {
         _.each(item.childNodes, function (node) {
            if (node.name && (node.name != "undefined")) {
               if (j != 0) {
                  send_msg += ","
               }

               if (node.className == "chk_selectall") {
                  if (node.checked) {
                     send_msg += "\"" + node.name + "\":\"1\"";
                  } else {
                     send_msg += "\"" + node.name + "\":\"0\"";
                  }
               } else {
                  if (node.name == "AUTO_SAVE_STSEQ" || node.name == "AUTO_SAVE_ENDSEQ") {
                     if (node.value.match(/[^0-9]/g)) {
                        $('#' + ap.render_pgm + ' [name=' + node.name + ']').css('outline', '2px solid red').css('margin', '2px');
                        if (!$('#' + ap.render_pgm + ' [name=' + node.name + ']').parent().children('.error').length) {
                           $('#' + ap.render_pgm + ' [name=' + node.name + ']').parent().append("<font class='error' style='font-weight: bold; color: red;'>" + langs.getText("error_msg","opt_range_error_case3") + "</font>");
                        }
                        dont_save = true;
                     }
                  } else if (node.name == "AUTO_SAVE_STNSTART") {
                     if (node.value.match(/[^0-9*#]/g)) {
                        $('#' + ap.render_pgm + ' [name=' + node.name + ']').css('outline', '2px solid red').css('margin', '2px');
                        if (!$('#' + ap.render_pgm + ' [name=' + node.name + ']').parent().children('.error').length) {
                           $('#' + ap.render_pgm + ' [name=' + node.name + ']').parent().append("<font class='error' style='font-weight: bold; color: red;'>" + langs.getText("error_msg","opt_range_error_case2") + "</font>");
                        }
                        dont_save = true;
                     }
                  }

                  send_msg += "\"" + node.name + "\":\"" + node.value + "\"";
               }
               j++;
            }
         });
      });
   });
   send_msg += "}";

   if (!dont_save) {
      setSpecialPacket(send_msg);
      debug_mode.flag && console.log(send_msg);
      $('#' + ap.render_pgm).html("");
      pgm_models.get_model(ap.render_pgm, false, packet);
   }
});

$(document).on('click', '.btn_p446_del', function (evt) {
   var send_msg = "";
   var delete_flag = false;

   _.each($('#'+ap.render_pgm+' .chk_outsideCheck'), function(item) {
		if (item.checked) {
			delete_flag = true;
		}
   });

   if (delete_flag) {
		$('<div />').html(langs.getText("p446","confirm_delete")).dialog({
			modal: true,
			closeOnEscape: false,
			title: langs.getText("common","notification"),
			open: function (event, ui) {
				$(".ui-dialog-titlebar-close").hide();
			},
			buttons: [
				{
					text: langs.getText("common","simple_okay"),
					click: function () {
						send_msg += "{";
						if ($('#'+ap.render_pgm+' [name=PREM_PAGE_SEL]').length) {
							send_msg += "\"PREM_PAGE_SEL\":\"" + $('#' + ap.render_pgm + ' [name=PREM_PAGE_SEL]').val() + "\"";
						}
						if ($('#'+ap.render_pgm+' input[name=UCS_DBSYNC]').length) {
							if (send_msg.length > 1) {
								send_msg += ",";
							}
							if ($('#'+ap.render_pgm+' input[name=UCS_DBSYNC]')[0].checked) {
								send_msg += "\"UCS_DBSYNC\":\"1\"";
							} else {
								send_msg += "\"UCS_DBSYNC\":\"0\"";
							}
						}
						_.each($('#'+ap.render_pgm+' .chk_outsideCheck'), function(item, i) {
							if (item.checked) {
								if (send_msg.length > 1) {
									send_msg += ",";
								}
								send_msg += "\"UCS_DEL_"+$('#'+ap.render_pgm+' .chk_outsideCheck:eq(' + i + ')').parents('tr').children().eq(1).text()+"\":\""+$('#'+ap.render_pgm+' .chk_outsideCheck:eq(' + i + ')').parents('tr').children().eq(2).text()+"\"";
							}
						});
						send_msg += "}";
						setSpecialPacket(send_msg);
						debug_mode.flag && console.log(send_msg);
						$('#' + ap.render_pgm).html("");
						pgm_models.get_model(ap.render_pgm, false, packet);
						$(this).dialog("destroy");
					}
				},
				{
					text: langs.getText("common","cancel"),
					click: function () {
						$(this).dialog("destroy");
					}
				}
			]
		});
   } else {
		send_msg += "{}";
		setSpecialPacket(send_msg);
		debug_mode.flag && console.log(send_msg);
		$('#' + ap.render_pgm).html("");
		pgm_models.get_model(ap.render_pgm, false, packet);
   }
});

$(document).on('change', '.select_p448_edit', function (evt) {
	if($(this).val() == "1") {
		$(this).parents('tr').children().eq(3).children('input')[0].disabled = true;
		$(this).parents('tr').children().eq(4).children('textarea')[0].disabled = true;
	} else {
		$(this).parents('tr').children().eq(3).children('input')[0].disabled = false;
		$(this).parents('tr').children().eq(4).children('textarea')[0].disabled = false;
	}
});

$(document).on('click', '.btn_p448_edit', function (evt) {
	var send_msg = "";

	if ($(this).parent().children('select').val() == "1") {
		send_msg = "{\""+$(this).parent().children('select').attr('name')+"\":\""+$(this).parent().children('select').val()+"\"}";
	} else if ($(this).parent().children('select').val() == "2") {
		var temp;
		var msglen;
		var sendsubmit;
		var utfchar;
		var maxlen = 255;
		var value;
		var l;

		value = $(this).parents('tr').children().eq(4).children('textarea').val();
		l = $(this).parents('tr').children().eq(4).children('textarea').val().length;

		msglen = maxlen;

		sendsubmit = 1;
		tmpstr = "";

		if (l == 0) {
			value = maxlen * 2;
		} else {
			for (var k = 0; k < l; k++) {
				temp = value.charAt(k);

				utfchar = escape(temp);
				if (utfchar.length > 4) {
					if (utfchar > "%u040F" && utfchar < "%u0450") msglen--;
					else msglen -= 2;
				} else msglen--;

				if (msglen < 0) {
					sendsubmit = 0;

					$('<div />').html(langs.getText("p448","alert_over_msg1") + " " + maxlen + " " + langs.getText("p448","alert_over_msg2")).dialog({
						modal: true,
						closeOnEscape: false,
						title: langs.getText("common","notification"),
						open: function (event, ui) {
							$(".ui-dialog-titlebar-close").hide();
						},
						buttons: [
							{
								text: langs.getText("common","simple_okay"),
								click: function () {
									$(this).dialog("destroy");
								}
							}
						]
					});
					$(this).parents('tr').children().eq(4).children('textarea').val(tmpstr);

					break;
				} else {
					tmpstr += temp;
				}
			}
		}

		if (1 != sendsubmit) {
			return false;
		}

		send_msg = "{\""+$(this).parents('tr').children().eq(3).children('input').attr('name')+"\":\""+$(this).parents('tr').children().eq(3).children('input').val().replace(/\\/g,'\\\\').replace(/"/g,"\\'")+"\",\""+$(this).parents('tr').children().eq(4).children('textarea').attr('name')+"\":\""+$(this).parents('tr').children().eq(4).children('textarea').val().replace(/\\/g,'\\\\').replace(/"/g,"\\'")+"\",\""+$(this).parent().children('select').attr('name')+"\":\""+$(this).parent().children('select').val()+"\"}";
	}

	setSpecialPacket(send_msg);
	debug_mode.flag && console.log(send_msg);
	$('#' + ap.render_pgm).html("");
	pgm_models.get_model(ap.render_pgm, true, packet);
});

$(document).on('click', '.radio_p449_audioset', function (evt) {
	if($(this).val() == "1") {
		$('#'+ap.render_pgm+' table tr input').attr('disabled','disabled');
		$('#'+ap.render_pgm+' table tr select').attr('disabled','disabled');
	} else {
		$('#'+ap.render_pgm+' table tr input').removeAttr('disabled');
		$('#'+ap.render_pgm+' table tr select').removeAttr('disabled');
	}
});

$(document).on('click', '.btn_p500_poweron', function (evt) {
   var send_msg = "{\"POWER_ON_1\":\"YES\"}";
   setSpecialPacket(send_msg);
   debug_mode.flag && console.log(send_msg);
   $('#' + ap.render_pgm).html("");
   pgm_models.get_model(ap.render_pgm, true, packet);
});

$(document).on('click', '.btn_p500_poweroff', function (evt) {
   var send_msg = "{\"POWER_OFF_1\":\"YES\"}";
   setSpecialPacket(send_msg);
   debug_mode.flag && console.log(send_msg);
   $('#' + ap.render_pgm).html("");
   pgm_models.get_model(ap.render_pgm, true, packet);
});

$(document).on('click', '.btn_p94_start', function (evt) {
   var send_msg = "{\"START\":\""+$('#' + ap.render_pgm + ' [name=OPTION]').val()+"\"}";
   setSpecialPacket(send_msg);
	debug_mode.flag && console.log(send_msg);
   $('#' + ap.render_pgm).html("");
   pgm_models.get_model(ap.render_pgm, true, packet);
});

$(document).on('click', '.btn_p94_stop', function (evt) {
   var send_msg = "{\"STOP\":\"\"}";
   setSpecialPacket(send_msg);
   debug_mode.flag && console.log(send_msg);
   $('#' + ap.render_pgm).html("");
   pgm_models.get_model(ap.render_pgm, true, packet);
});

$(document).on('click', '.btn_p94_download', function (evt) {
   $('#hiddenFrame').attr('src', 'packetdump.cap');
});

$(document).on('click', '.btn_p95_start', function (evt) {
   var send_msg = "{\"START\":\"\"}";
   setSpecialPacket(send_msg);
   debug_mode.flag && console.log(send_msg);
   $('#' + ap.render_pgm).html("");
   pgm_models.get_model(ap.render_pgm, true, packet);
});

$(document).on('click', '.btn_p95_stop', function (evt) {
   var send_msg = "{\"STOP\":\"\"}";
   setSpecialPacket(send_msg);
   debug_mode.flag && console.log(send_msg);
   $('#' + ap.render_pgm).html("");
   pgm_models.get_model(ap.render_pgm, true, packet);
});

$(document).on('click', '.btn_p95_download', function (evt) {
   $('#hiddenFrame').attr('src', 'trace_log.txt');
});
$(document).on('click', '.btn_p450_reset', function (evt) {
   $('<div />').html(langs.getText("common","reset_alertmessage")).dialog({
      modal: true,
      closeOnEscape: false,
      title: langs.getText("common","notification"),
      open: function (event, ui) {
         $(".ui-dialog-titlebar-close").hide();
      },
      buttons: [
			{
				text: langs.getText("common","simple_okay"),
				click: function () {
					var send_msg = "{\"SYSTEM_RESET\":\"YES\"}";
					debug_mode.flag && console.log(send_msg);
					var range_type = [];
					var range = [];
					packet.setPacket(1, range_type, range, send_msg);
					sendMsg(packet.main, "pgm450", packet.type, packet.range, packet.msg);
					$(this).dialog("destroy");
				}
			},
			{
				text: langs.getText("common","cancel"),
				click: function () {
					$(this).dialog("destroy");
				}
			}
      ]
   });
});

$(document).on('click', '.btn_p450_chactstb', function (evt) {
   $('<div />').html(langs.getText("common","change_alertmessage")).dialog({
      modal: true,
      closeOnEscape: false,
      title: langs.getText("common","notification"),
      open: function (event, ui) {
         $(".ui-dialog-titlebar-close").hide();
      },
      buttons: [
			{
				text: langs.getText("common","simple_okay"),
				click: function () {
					var send_msg = "{\"DBIN_CHANGE\":\"YES\"}";
					debug_mode.flag && console.log(send_msg);
					var range_type = [];
					var range = [];
					packet.setPacket(1, range_type, range, send_msg);
					sendMsg(packet.main, "pgm450", packet.type, packet.range, packet.msg);
					$(this).dialog("destroy");
				}
			},
			{
				text: langs.getText("common","cancel"),
				click: function () {
					$(this).dialog("destroy");
				}
			}
      ]
   });
});

function setSpecialPacket(send_msg) {
   var range = [];
   var range_type = [];

   if ($('#' + ap.render_pgm + ' .preload').length) {
      _.each($('#' + ap.render_pgm + ' .preload').children(), function (item) {
         if (item.name && item.name.match("RANGE_TYPE")) {
            range_type.push(item.value);
         } else if (item.className && item.className.match("RANGE_VIEW")) {
            range.push(item.innerHTML);
         }
      });
   } else if ((ap.render_pgm == "iw006") && info.NO_OF_COLS) {
      range_type.push("2");
      range.push("1-" + info.NO_OF_COLS);
   }

   debug_mode.flag && console.log(range_type);
   debug_mode.flag && console.log(range);

   packet.setPacket(1, range_type, range, send_msg);
}

$(document).on('click', '.btn_p51_reset', function (evt) {
   $('<div />').html(langs.getText("common","reset_alertmessage")).dialog({
      modal: true,
      closeOnEscape: false,
      title: langs.getText("common","notification"),
      open: function (event, ui) {
         $(".ui-dialog-titlebar-close").hide();
      },
      buttons: [
			{
				text: langs.getText("common","simple_okay"),
				click: function () {
					var send_msg = "{\"SYSTEM_RESET\":\"YES\"}";
					debug_mode.flag && console.log(send_msg);
					var range_type = [];
					var range = [];
					packet.setPacket(1, range_type, range, send_msg);
					sendMsg(packet.main, "pgm450", packet.type, packet.range, packet.msg);
					$(this).dialog("destroy");
				}
			},
			{
				text: langs.getText("common","cancel"),
				click: function () {
					$(this).dialog("destroy");
				}
			}
		]
   });
});

$(document).on('click', '.btn_p51_refresh', function (evt) {
	skipConfirm_flag = true;
	location.href = location.href.replace(/#$/, '');
});

$(document).on('click', '.btn_p51_logview', function (evt) {
	$(this).parents('tr').children('.btn_liclog').hide();
	$(this).parents('tr').children('.txt_liclog').show();
});

$(document).on('click', '.btn_p54_dbbuild', function (evt) {
	var send_msg = "";
	var dbtype = $.trim($('#'+ap.render_pgm+' [name=DB_BUILDTYPE]').val());
	var system = info.SYSTEM_ID.replace("iPECS ", "");
	var filename = "";

	if (dbtype == "DB_ALL") filename = dbtype + system + ".admgzu";
	else if (dbtype == "DB_SPD") filename = dbtype + system + ".spdgzu";
	else if (dbtype == "DB_LCR") filename = dbtype + system + ".lcrgzu";
	else if (dbtype == "DB_SIP_PROVISION") filename = dbtype + ".flegzu";
	else if (dbtype == "DB_PRE_DIAL") filename = dbtype + ".flegzu";
	else filename = dbtype + system + ".strgzu";

	send_msg = "{\"DB_BUILD\":\""+filename+"\"}";
   setSpecialPacket(send_msg);
   debug_mode.flag && console.log(send_msg);
   $('#' + ap.render_pgm).html("");
   pgm_models.get_model(ap.render_pgm, true, packet);
});

$(document).on('click', '.btn_p54_addcmt', function (evt) {
   var send_msg;
	var file_pos="";
	if($(this).parents('tr').find('input:hidden[name^=DB_FILEPOS]').val()!="")
	{
		file_pos = $(this).parents('tr').find('input:hidden[name^=DB_FILEPOS]').val()+"/";
	}
	if($(this).parents('tr').find('[name^=DB_ADDCMT]').next().hasClass("error"))
	{
		$(this).parents('tr').find('[name^=DB_ADDCMT]').css("outline","");
		$(this).parents('tr').find('[name^=DB_ADDCMT]').next().remove();
	}
	if (!$(this).parents('tr').find('[name^=DB_ADDCMT]').hasClass('enable_mullang')) {
		if ($(this).parents('tr').find('[name^=DB_ADDCMT]').val().match(/[^a-zA-Z0-9\s\#\$\%\&\'\(\)\,\-\.\@\_]/g)) {
			$(this).parents('tr').find('[name^=DB_ADDCMT]').css("outline", "2px solid red").css("margin", "2px");
			$(this).parents('tr').find('[name^=DB_ADDCMT]').after("<font class='error' style='font-weight: bold; color: red;'>" + langs.getText("error_msg","error_mullang") + "</font>");
			return 0;
		}
	}
	else {
		if ($(this).parents('tr').find('[name^=DB_ADDCMT]').val().match(/[\\\/\:\*\?\"\<\>\|\+\;\=\^\`\~\!\[\]\{\}]/g)) {
			$(this).parents('tr').find('[name^=DB_ADDCMT]').css("outline", "2px solid red").css("margin", "2px");
			$(this).parents('tr').find('[name^=DB_ADDCMT]').after("<font class='error' style='font-weight: bold; color: red;'>" + langs.getText("error_msg","error_mullang") + "</font>");
			return 0;
		}
	}
	send_msg = "{\"DB_ADDCMT\":\""+$(this).parents('tr').find('[name^=DB_ADDCMT]').val()+"\",\"DB_ORIGINALFILE\":\""+file_pos+$(this).parents('tr').find('input:hidden[name^=DB_FILENAME]').val()+"\"}";
	setSpecialPacket(send_msg);
	debug_mode.flag && console.log(send_msg);
	$('#' + ap.render_pgm).html("");
	pgm_models.get_model(ap.render_pgm, true, packet);
});

$(document).on('click', '.btn_p54_dbdelete', function (evt) {
	var pre_msg = new Array();
   var send_msg = "{";
   _.each($('#'+ap.render_pgm+' table tbody tr'), function (item, i) {
		if ($('#'+ap.render_pgm+' table tbody tr:eq('+i+')').find('.chk_checkall:checked').length && $('#'+ap.render_pgm+' table tbody tr:eq('+i+')').find('input:hidden[name^=DB_FILENAME]').length) {
			var file_pos="";
			if($('#'+ap.render_pgm+' table tbody tr:eq('+i+')').find('input:hidden[name^=DB_FILEPOS]').val()!="")
			{
				file_pos = $('#'+ap.render_pgm+' table tbody tr:eq('+i+')').find('input:hidden[name^=DB_FILEPOS]').val()+"/";
			}
			pre_msg.push("\"DB_DELETE\":\""+file_pos+$('#'+ap.render_pgm+' table tbody tr:eq('+i+')').find('input:hidden[name^=DB_FILENAME]').val()+"\"");
		}
   });
   _.each(pre_msg, function (item, i) {
		send_msg += item;
		if (i != pre_msg.length-1) {
			send_msg += ",";
		}
   });
   send_msg += "}";
   setSpecialPacket(send_msg);
   debug_mode.flag && console.log(send_msg);
   $('#' + ap.render_pgm).html("");
   pgm_models.get_model(ap.render_pgm, true, packet);
});

$(document).on('click', '.btn_p54_dbapply', function (evt) {
	var this_button = $(this);
   $('<div />').html(langs.getText("common","alert_dbapply")).dialog({
      modal: true,
      closeOnEscape: false,
      title: langs.getText("common","notification"),
      open: function (event, ui) {
         $(".ui-dialog-titlebar-close").hide();
      },
      buttons: [
			{
				text: langs.getText("common","simple_okay"),
				click: function () {
					var send_msg = "";
					if (this_button.parents('tr').find('input:hidden[name^=DB_FILENAME]').length) {
						var file_pos="";
						if(this_button.parents('tr').find('input:hidden[name^=DB_FILEPOS]').val()!="")
						{
							file_pos=this_button.parents('tr').find('input:hidden[name^=DB_FILEPOS]').val()+"/";
						}
						send_msg = "{\"DB_APPLY_"+this_button.parents('tr').find('input:hidden[name^=DB_FILENAME]').attr('name').replace('DB_FILENAME_','')+"\":\""+file_pos+this_button.parents('tr').find('input:hidden[name^=DB_FILENAME]').val()+"\"}";
					}
					setSpecialPacket(send_msg);
					debug_mode.flag && console.log(send_msg);
					$('#' + ap.render_pgm).html("");
					pgm_models.get_model(ap.render_pgm, true, packet);
					$(this).dialog("destroy");
				}
			},
			{
				text: langs.getText("common","cancel"),
				click: function () {
					$(this).dialog("destroy");
				}
			}
		]
   });
});

$(document).on('click', '.btn_p54_dbdownload', function (evt) {
   var file_name = "";
	if($.trim($(this).parents('tr').find('input:hidden[name^=DB_FILEPOS]').val())!="")
	{
		file_name = $.trim($(this).parents('tr').find('input:hidden[name^=DB_FILEPOS]').val())+"/"+$.trim($(this).parents('tr').find('input:hidden[name^=DB_FILENAME]').val());
	}
	else
	{
		file_name = $.trim($(this).parents('tr').find('input:hidden[name^=DB_FILENAME]').val());
	}
	file_name = encodeURI(file_name);
   $('#hiddenFrame').attr('src', file_name);
});

$(document).on('click', '.btn_p212_download', function (evt) {
   var file_name = "sip_conf.tar";
   $('#hiddenFrame').attr('src', file_name);
});

$(document).on('click', '.btn_p57_download', function (evt) {
   var file_name = "";

   _.each($(this).parents('tr').children(), function (items, i) {
      _.each(items.childNodes, function (item, j) {
         if (item.name) {
            if (item.name.match('MULLAN_FILE')) {
               file_name = item.value;
            }
         }
      });
   });

   $('#hiddenFrame').attr('src', file_name);
});

$(document).on('click', '.btn_p90_delete', function (evt) {
	var pre_msg = new Array();
   var send_msg = "{";
   _.each($('#'+ap.render_pgm+' table tbody tr'), function (item, i) {
		if ($('#'+ap.render_pgm+' table tbody tr:eq('+i+')').find('.chk_checkall:checked').length && $('#'+ap.render_pgm+' table tbody tr:eq('+i+')').find('input:hidden[name^=FILENAME]').length) {
			pre_msg.push("\"DELETE\":\""+$('#'+ap.render_pgm+' table tbody tr:eq('+i+')').find('input:hidden[name^=FILENAME]').val()+"\"");
		}
   });
   _.each(pre_msg, function (item, i) {
		send_msg += item;
		if (i != pre_msg.length-1) {
			send_msg += ",";
		}
   });
   send_msg += "}";
   setSpecialPacket(send_msg);
   debug_mode.flag && console.log(send_msg);
   $('#' + ap.render_pgm).html("");
   pgm_models.get_model(ap.render_pgm, true, packet);
});

$(document).on('click', '.btn_p90_transfer', function (evt) {
   $('<div />').html(langs.getText("p90","alert_transfer1")).dialog({
      modal: true,
      closeOnEscape: false,
      title: langs.getText("common","notification"),
      open: function (event, ui) {
         $(".ui-dialog-titlebar-close").hide();
      },
      buttons: [
			{
				text: langs.getText("common","simple_okay"),
				click: function () {
					$('<div />').html(langs.getText("p90","alert_transfer2")).dialog({
						modal: true,
						closeOnEscape: false,
						title: langs.getText("common","notification"),
						open: function (event, ui) {
							$(".ui-dialog-titlebar-close").hide();
						},
						buttons: [
							{
								text: langs.getText("common","simple_okay"),
								click: function () {
									var send_msg = "{\"TRANSFER\":\"\"}";
									setSpecialPacket(send_msg);
									debug_mode.flag && console.log(send_msg);
									$('#' + ap.render_pgm).html("");
									pgm_models.get_model(ap.render_pgm, true, packet);
									$(this).dialog("destroy");
								}
							},
							{
								text: langs.getText("common","cancel"),
								click: function () {
									$(this).dialog("destroy");
								}
							}
						]
					});
					$(this).dialog("destroy");
				}
			},
			{
				text: langs.getText("common","cancel"),
				click: function () {
					$(this).dialog("destroy");
				}
			}
		]
   });
});

$(document).on('click', '.btn_p90_download', function (evt) {
   var file_name = "";
	file_name = $.trim($(this).parents('tr').find('input:hidden[name^=FILENAME]').val());

   $('#hiddenFrame').attr('src', file_name);
});

$(document).on('click', '.btn_p91_apply', function (evt) {
   var send_msg = "{\"FILENAME\":\"" + $(this).parents('tr').find('input:hidden[name^=FILENAME]').val() + "\"}";
   setSpecialPacket(send_msg);
   debug_mode.flag && console.log(send_msg);
   $('#' + ap.render_pgm).html("");
   pgm_models.get_model(ap.render_pgm, true, packet);
});

$(document).on('click', '.btn_p74_default', function (evt) {
   $('<div />').html(langs.getText("p74","confirm_default")).dialog({
      modal: true,
      closeOnEscape: false,
      title: langs.getText("common","notification"),
      open: function (event, ui) {
         $(".ui-dialog-titlebar-close").hide();
      },
      buttons: [
			{
				text: langs.getText("common","simple_okay"),
				click: function () {
					var send_msg = "{\"STNPA_DFLT\":\"ON\"}";
					setSpecialPacket(send_msg);
					debug_mode.flag && console.log(send_msg);
					$('#' + ap.render_pgm).html("");
					pgm_models.get_model(ap.render_pgm, true, packet);
					$(this).dialog("destroy");
				}
			},
			{
				text: langs.getText("common","cancel"),
				click: function () {
					$(this).dialog("destroy");
				}
			}
		]
   });
});

$(document).on('click', '.btn_p75_demo', function (evt) {
	var send_name = $(this).attr("name");

	if (send_name == "LOCK_DEMO_ACT")
		var tcolor = "black";
	else
		var tcolor = "red";

    $('<div />').html("<span style='font-weight:bold;color:"+tcolor+"'>- "+langs.getText("p75","confirm_msg1")+"<br>"+"- "+langs.getText("p75","confirm_msg2")+"<br>"+"- "+langs.getText("p75","confirm_msg3")+"</span>").dialog({
      modal: true,
      closeOnEscape: false,
      title: langs.getText("common","notification"),
      open: function (event, ui) {
         $(".ui-dialog-titlebar-close").hide();
			if (send_name == "LOCK_DEMO_ACT")
				$(this).parent().find(".ui-dialog-buttonset button:contains('Ok')").focus();
			else
				$(this).parent().find(".ui-dialog-buttonset button:contains('Cancel')").focus();
      },
      buttons: [
			{
				text: langs.getText("common","simple_okay"),
				click: function () {
					var send_msg = "{\"" + send_name + "\":\"1\"}";
					setSpecialPacket(send_msg);
					debug_mode.flag && console.log(send_msg);
					$('#' + ap.render_pgm).html("");
					pgm_models.get_model(ap.render_pgm, true, packet);
					$(this).dialog("destroy");
				}
			},
			{
				text: langs.getText("common","cancel"),
				click: function () {
					$(this).dialog("destroy");
				}
			}
		]
   });
});

function SGdownload() {
   $('#hiddenFrame').attr('src', document.ONE_SGDOWN.SGNAME.value);
}

function USRGRTdownload() {
	$('#hiddenFrame').attr('src', 'UG.rom');
}

function CDNdownload() {
	$('#hiddenFrame').attr('src', 'CDN.rom');
}

$(document).on('click', '.btn_p76_del', function (evt) {
   $('<div />').html(langs.getText("p76","alert_delete_prompt")).dialog({
      modal: true,
      closeOnEscape: false,
      title: langs.getText("common","notification"),
      open: function (event, ui) {
         $(".ui-dialog-titlebar-close").hide();
      },
      buttons: [
			{
				text: langs.getText("common","simple_okay"),
				click: function () {
					var send_msg = "{";
					_.each($('#' + ap.render_pgm + ' .chk_selectall'), function (item, i) {
						if (i != 0) {
							send_msg += ",";
						}

						if (item.checked) {
							send_msg += "\"" + item.name + "\":\"1\"";
						} else {
							send_msg += "\"" + item.name + "\":\"0\"";
						}
					});
					send_msg += "}";

					debug_mode.flag && console.log(send_msg);
					var range_type = [];
					var range = [];
					packet.setPacket(1, range_type, range, send_msg);
					$("#" + ap.render_pgm).html("");
					make_vsfprmtup_pgm(packet);
					$(this).dialog("destroy");
				}
			},
			{
				text: langs.getText("common","cancel"),
				click: function () {
					$(this).dialog("destroy");
				}
			}
		]
   });
});

$(document).on('click', '.btn_p78_download', function (evt) {
   var file_name = "";
	var dir_name = "";
	dir_name = $.trim($(this).parents('tr').find('input:checkbox[name^=FILE_DIRN]').val());
	file_name = "DOWNDIR" + dir_name + "/" + $.trim($(this).parents('tr').find('input:hidden[name^=FILE_NAME]').val());

   $('#hiddenFrame').attr('src', file_name);
});

$(document).on('click', '.btn_p781_download', function (evt) {
   var file_name = "";
	var dir_name = "";
	dir_name = $.trim($(this).parents('tr').find('input:checkbox[name^=FILE_DIRN]').val());
	file_name = "DOWNDIR" + dir_name + "/" + $.trim($(this).parents('tr').find('input:hidden[name^=FILE_NAME]').val());

   $('#hiddenFrame').attr('src', file_name);
});

$(document).on('click', '.btn_p81_download', function (evt) {
   var file_name = "";

   _.each($(this).parents('tr').children(), function (items, i) {
      _.each(items.childNodes, function (item, j) {
         if (item.name) {
            if (item.name.match('INDIVSG_FILE')) {
               file_name = item.value;
            }
         }
      });
   });

   $('#hiddenFrame').attr('src', file_name);
});

$(document).on('click', '.btn_p84_stn_delete', function (evt) {
   if ($('#' + ap.render_pgm + ' .error').length) {
      $('#' + ap.render_pgm + ' td').children().css('outline', '').css('margin', '');
      $('#' + ap.render_pgm + ' .error').remove();
   }

   if (!$('#' + ap.render_pgm + ' [name=STN_ATT_NUM]').val()) {
      $('#' + ap.render_pgm + ' [name=STN_ATT_NUM]').css('outline', '2px solid red').css('margin', '2px').after("<font class='error' style='font-weight: bold; color: red; margin: 0px 5px;'>" + langs.getText("error_msg","opt_range_error_case1") + "</font>");
      return false;
   } else if ($('#' + ap.render_pgm + ' [name=STN_ATT_NUM]').val().match(/[^0-9*#]/g)) {
      $('#' + ap.render_pgm + ' [name=STN_ATT_NUM]').css('outline', '2px solid red').css('margin', '2px').after("<font class='error' style='font-weight: bold; color: red; margin: 0px 5px;'>" + langs.getText("error_msg","opt_range_error_case2") + "</font>");
      return false;
   }

   $('<div />').html(langs.getText("p84","confirm_stn_delete")).dialog({
      modal: true,
      closeOnEscape: false,
      title: langs.getText("common","notification"),
      open: function (event, ui) {
         $(".ui-dialog-titlebar-close").hide();
      },
      buttons: [
			{
				text: langs.getText("common","simple_okay"),
				click: function () {
					var range_type = [];
					var range = [];
					var inc_greeting=String($('#' + ap.render_pgm +' [name=INC_GREETING]').is(':checked')? 1 : 0);
					var send_msg = "{\"VSF_DELSTN\":\""+inc_greeting+"\"}";

					range_type.push("1");
					range[0] = $('#' + ap.render_pgm + ' [name=STN_ATT_NUM]').val();

					debug_mode.flag && console.log(range);
					debug_mode.flag && console.log(send_msg);

					packet.setPacket(1, range_type, range, send_msg);
					$('#' + ap.render_pgm).html("");
					pgm_models.get_model(ap.render_pgm, true, packet);
					$(this).dialog("destroy");
				}
			},
			{
				text: langs.getText("common","cancel"),
				click: function () {
					$(this).dialog("destroy");
				}
			}
		]
   });
});

$(document).on('click', '.btn_p84_all_delete', function (evt) {
   $('<div />').html(langs.getText("p84","confirm_all_delete")).dialog({
      modal: true,
      closeOnEscape: false,
      title: langs.getText("common","notification"),
      open: function (event, ui) {
         $(".ui-dialog-titlebar-close").hide();
      },
      buttons: [
			{
				text: langs.getText("common","simple_okay"),
				click: function () {
					var send_msg = "{\"VSF_DELALLSTN\":\"\"}";
					debug_mode.flag && console.log(send_msg);
					var range_type = [];
					var range = [];

					packet.setPacket(1, range_type, range, send_msg);
					$('#' + ap.render_pgm).html("");
					pgm_models.get_model(ap.render_pgm, true, packet);
					$(this).dialog("destroy");
				}
			},
			{
				text: langs.getText("common","cancel"),
				click: function () {
					$(this).dialog("destroy");
				}
			}
		]
   });
});

$(document).on('click', '.btn_p85_backup', function (evt) {
	var send_msg = "";
	if (info.SYSTEM_ID == "iPECS eMG80" || info.SYSTEM_ID == "iPECS eMG800") {
		if ($(this).hasClass('vmiu')) {
			send_msg = "{\"VM_BACKUP\":\"VMIU\"}";
		} else if ($(this).hasClass('vmib')) {
			send_msg = "{\"VM_BACKUP\":\"VMIB\"}";
		}
	} else {
		send_msg = "{\"VM_BACKUP\":\"\"}";
	}
   setSpecialPacket(send_msg);
   debug_mode.flag && console.log(send_msg);
   pgm_models.get_model(ap.render_pgm, true, packet);
});

$(document).on('click', '.btn_log_clear', function (evt) {
   var send_msg = "{\"CLEAR\":\"\"}";
   setSpecialPacket(send_msg);
   debug_mode.flag && console.log(send_msg);
   $('#' + ap.render_pgm).html("");
   pgm_models.get_model(ap.render_pgm, true, packet);
});

$(document).on('click', '.btn_ps010_del', function (evt) {
   var send_msg = "{\"DELCHECK\":\"" + $('#' + ap.render_pgm + ' .preload [name=RANGE_NUM]').text() + "\"}";
   setSpecialPacket(send_msg);
   debug_mode.flag && console.log(send_msg);
   $('#' + ap.render_pgm).html("");
   pgm_models.get_model(ap.render_pgm, false, packet);
});

$(document).on('click', '.btn_pre_page_sel', function (evt) {
   var send_msg = "{\"PREM_PAGE_SEL\":\"" + $('#' + ap.render_pgm + ' [name=PREM_PAGE_SEL]').val() + "\"}";
   setSpecialPacket(send_msg);
   debug_mode.flag && console.log(send_msg);
   $('#' + ap.render_pgm).html("");
   pgm_models.get_model(ap.render_pgm, false, packet);
});

$(document).on('click', '.btn_overview', function (evt) {
	if ((active_base != "tab_function_base") || (active_base != "tab_install_wizard")) {
		var tab_str = "";
		var tab_title = "";

		if ($(this).hasClass('btn_p101_reg')) {
			tab_str = "pgm1010";
			tab_title = langs.getText("adm_menu","pgm1010");
		} else if ($(this).hasClass('btn_p101_ipreg')) {
			tab_str = "pgm1010";
			tab_title = langs.getText("adm_menu","pgm1010")+" ("+langs.getText("p101","ip_dev")+")";
		} else if ($(this).hasClass('btn_p101_tdmreg')) {
			tab_str = "pgm1011";
			tab_title = langs.getText("adm_menu","pgm1010")+" ("+langs.getText("p101","tdm_dev")+")";
		} else if ($(this).hasClass('btn_p255_help')) {
			tab_str = "pgm2550";
			tab_title = langs.getText("adm_menu","pgm2550");
		} else if ($(this).hasClass('btn_p212_view')) {
			tab_str = "pgm21201";
			tab_title = langs.getText("adm_menu","pgm21201");
		} else if ($(this).hasClass('btn_p212_cert')) {
			tab_str = "pgm21202";
			tab_title = langs.getText("adm_menu","pgm21202");
		} else if ($(this).hasClass('btn_p68_logonlist')) {
			tab_str = "pgm6800";
			tab_title = langs.getText("mnt_menu","pgm6800");
		} else if ($(this).hasClass('btn_p84_status')) {
			tab_str = "pgm8400";
			tab_title = langs.getText("mnt_menu","pgm8400");
		} else if ($(this).hasClass('btn_ps010_overview')) {
			tab_str = "pgms0100";
			tab_title = langs.getText("stn_menu","pgms0100");
		} else if ($(this).hasClass('btn_ps011_overview')) {
			tab_str = "pgms0110";
			tab_title = langs.getText("stn_menu","pgms0110");
		} else if ($(this).hasClass('btn_ps018_itemlist')) {
			tab_str = "pgms0180";
			tab_title = langs.getText("stn_menu","pgms0180");
		}

		var tab_index = 0;
		var existed = false;

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

		$('#' + active_base + ' .nav-tabs-main li').removeClass("active");
		$('#' + active_base + ' .nav-tabs-main li .icon_refresh').remove();
		$('#' + 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>");
			}

			if (ap.render_pgm == "pgm2550") {
				make_aclhelp_pgm();
			} else {
				var range_type = [];
				var range = [];

				packet.setPacket(0, range_type, range, "{}");
				pgm_models.get_model(ap.render_pgm, true, packet);
			}
		}

		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");
   }
});

$(document).on('click', '.sort_str', function (evt) {
	var this_elem = $(this);

   if (this_elem.hasClass('asce')) {
      this_elem.removeClass('asce');
      this_elem.addClass('desc');
      this_elem.children('.img_asce').hide();
      this_elem.children('.img_desc').show();
   } else if (this_elem.hasClass('desc')) {
      this_elem.removeClass('desc');
      this_elem.addClass('asce');
      this_elem.children('.img_asce').show();
      this_elem.children('.img_desc').hide();
   } else {
      this_elem.addClass('asce');
   }

   var sort_arr = [];
   var th = -1;
   var column = 0;
   var sort_val_a = null;
   var sort_val_b = null;

   if (this_elem.parents('table').find('[name=CHKFLAG]').length) {
      column = this_elem.index() - 1;
   } else {
      column = this_elem.index();
   }

   _.each(this_elem.parents('tbody').children('tr'), function (item) {
      if (item.childNodes[0].tagName == "TH") {
         th++;
         sort_arr[th] = [];
      } else if (item.childNodes[0].tagName == "TD") {
         sort_arr[th].push(item);
      }
   });

   if (this_elem.hasClass('asce')) {
      for (var i = 0; i < sort_arr.length; i++) {
         sort_arr[i].sort(function (a, b) {
				if (!this_elem.hasClass('sort_elem')) {
					sort_val_a = a.childNodes[column].textContent;
					sort_val_b = b.childNodes[column].textContent;
				} else {
					sort_val_a = $(a.childNodes[column]).children().eq(0).val();
					sort_val_b = $(b.childNodes[column]).children().eq(0).val();
				}

            if (sort_val_a.toLowerCase().replace(/^\s+/, "").replace(/\s+$/, "") > sort_val_b.toLowerCase().replace(/^\s+/, "").replace(/\s+$/, "")) {
               return 1;
            } else if (sort_val_b.toLowerCase().replace(/^\s+/, "").replace(/\s+$/, "") > sort_val_a.toLowerCase().replace(/^\s+/, "").replace(/\s+$/, "")) {
               return -1;
            }
            return 0;
         });
      }
   } else if (this_elem.hasClass('desc')) {
      for (var i = 0; i < sort_arr.length; i++) {
         sort_arr[i].sort(function (a, b) {
				if (!this_elem.hasClass('sort_elem')) {
					sort_val_a = a.childNodes[column].textContent;
					sort_val_b = b.childNodes[column].textContent;
				} else {
					sort_val_a = $(a.childNodes[column]).children().eq(0).val();
					sort_val_b = $(b.childNodes[column]).children().eq(0).val();
				}

            if (sort_val_a.toLowerCase().replace(/^\s+/, "").replace(/\s+$/, "") > sort_val_b.toLowerCase().replace(/^\s+/, "").replace(/\s+$/, "")) {
               return -1;
            } else if (sort_val_b.toLowerCase().replace(/^\s+/, "").replace(/\s+$/, "") > sort_val_a.toLowerCase().replace(/^\s+/, "").replace(/\s+$/, "")) {
               return 1;
            }
            return 0;
         });
      }
   }

   th = 0;

   _.each(this_elem.parents('tbody').children('tr'), function (item, i) {
      if (item.childNodes[0].tagName == "TH") {
         sort_arr[th].reverse();
         _.each(sort_arr[th], function (td) {
            item.parentNode.insertBefore(td, item.nextSibling);
         });
         th++;
      }
   });
/*
	_.each(sort_arr, function(items) {
		_.each(items, function(item) {
			debug_mode.flag && console.log(item.childNodes[column].textContent);
		});
	});
	debug_mode.flag && console.log(sort_arr);	*/
});

$(document).on('click', '.sort_num', function (evt) {
	var this_elem = $(this);

   if (this_elem.hasClass('asce')) {
      this_elem.removeClass('asce');
      this_elem.addClass('desc');
      this_elem.children('.img_asce').hide();
      this_elem.children('.img_desc').show();
   } else if (this_elem.hasClass('desc')) {
      this_elem.removeClass('desc');
      this_elem.addClass('asce');
      this_elem.children('.img_asce').show();
      this_elem.children('.img_desc').hide();
   } else {
      this_elem.addClass('asce');
   }

   var sort_arr = [];
   var th = -1;
   var column = 0;
   var tmp_sort_num_a = "";
   var tmp_sort_num_b = "";
   var sort_val_a = null;
   var sort_val_b = null;

   if (this_elem.parents('table').find('[name=CHKFLAG]').length) {
      column = this_elem.index() - 1;
   } else {
      column = this_elem.index();
   }

   _.each(this_elem.parents('tbody').children('tr'), function (item) {
      if (item.childNodes[0].tagName == "TH") {
         th++;
         sort_arr[th] = [];
      } else if (item.childNodes[0].tagName == "TD") {
         sort_arr[th].push(item);
      }
   });

   if (this_elem.hasClass('asce')) {
      for (var i = 0; i < sort_arr.length; i++) {
         sort_arr[i].sort(function (a, b) {
            tmp_sort_num_a = 0;
            tmp_sort_num_b = 0;

				if (!this_elem.hasClass('sort_elem')) {
					sort_val_a = a.childNodes[column].textContent;
					sort_val_b = b.childNodes[column].textContent;
				} else {
					sort_val_a = $(a.childNodes[column]).children().eq(0).val();
					sort_val_b = $(b.childNodes[column]).children().eq(0).val();
				}

            if (sort_val_a.replace(/^\s+/, "").replace(/\s+$/, "").length) {
               tmp_sort_num_a = parseInt(sort_val_a.replace(/^\s+/, "").replace(/\s+$/, ""));
            }
            if (sort_val_b.replace(/^\s+/, "").replace(/\s+$/, "").length) {
               tmp_sort_num_b = parseInt(sort_val_b.replace(/^\s+/, "").replace(/\s+$/, ""));
            }

            if (tmp_sort_num_a > tmp_sort_num_b) {
               return 1;
            } else if (tmp_sort_num_b > tmp_sort_num_a) {
               return -1;
            }
            return 0;
         });
      }
   } else if (this_elem.hasClass('desc')) {
      for (var i = 0; i < sort_arr.length; i++) {
         sort_arr[i].sort(function (a, b) {
            tmp_sort_num_a = 0;
            tmp_sort_num_b = 0;

				if (!this_elem.hasClass('sort_elem')) {
					sort_val_a = a.childNodes[column].textContent;
					sort_val_b = b.childNodes[column].textContent;
				} else {
					sort_val_a = $(a.childNodes[column]).children().eq(0).val();
					sort_val_b = $(b.childNodes[column]).children().eq(0).val();
				}

            if (sort_val_a.replace(/^\s+/, "").replace(/\s+$/, "").length) {
               tmp_sort_num_a = parseInt(sort_val_a.replace(/^\s+/, "").replace(/\s+$/, ""));
            }
            if (sort_val_b.replace(/^\s+/, "").replace(/\s+$/, "").length) {
               tmp_sort_num_b = parseInt(sort_val_b.replace(/^\s+/, "").replace(/\s+$/, ""));
            }

            if (tmp_sort_num_a > tmp_sort_num_b) {
               return -1;
            } else if (tmp_sort_num_b > tmp_sort_num_a) {
               return 1;
            }
            return 0;
         });
      }
   }

   th = 0;

   _.each(this_elem.parents('tbody').children('tr'), function (item, i) {
      if (item.childNodes[0].tagName == "TH") {
         sort_arr[th].reverse();
         _.each(sort_arr[th], function (td) {
            item.parentNode.insertBefore(td, item.nextSibling);
         });
         th++;
      }
   });
});

$(document).on('click', '.sort_stanum', function (evt) {
	var this_elem = $(this);

   if (this_elem.hasClass('asce')) {
      this_elem.removeClass('asce');
      this_elem.addClass('desc');
      this_elem.children('.img_asce').hide();
      this_elem.children('.img_desc').show();
   } else if (this_elem.hasClass('desc')) {
      this_elem.removeClass('desc');
      this_elem.addClass('asce');
      this_elem.children('.img_asce').show();
      this_elem.children('.img_desc').hide();
   } else {
      this_elem.addClass('asce');
   }

   var sort_arr = [];
   var tmp_arr = [];
   var th = -1;
   var column = 0;
   var parse_tmp = "";
   var tmp_sort_num_a = "";
   var tmp_sort_num_b = "";
   var tmp_sort_str_a = "";
   var tmp_sort_str_b = "";
   var sort_val_a = null;
   var sort_val_b = null;

   if (this_elem.parents('table').find('[name=CHKFLAG]').length) {
      column = this_elem.index() - 1;
   } else {
      column = this_elem.index();
   }

   _.each(this_elem.parents('tbody').children('tr'), function (item) {
      if (item.childNodes[0].tagName == "TH") {
         th++;
         sort_arr[th] = [];
      } else if (item.childNodes[0].tagName == "TD") {
         sort_arr[th].push(item);
      }
   });

   for (var i = 0; i < sort_arr.length; i++) {
      tmp_arr[i] = [];
      tmp_arr[i][0] = [];
      tmp_arr[i][1] = [];
      for (var j = 0; j < sort_arr[i].length; j++) {
         parse_tmp = sort_arr[i][j].childNodes[column].textContent.replace(/^\s+/, "").replace(/\s+$/, "").split(" ")[0];
         //debug_mode.flag && console.log(parse_tmp);
         if (parse_tmp.match(/\*/)) {
            tmp_arr[i][1].push(sort_arr[i][j]);
         } else {
            tmp_arr[i][0].push(sort_arr[i][j]);
         }
      }
   }

   if (this_elem.hasClass('asce')) {
      for (var i = 0; i < tmp_arr.length; i++) {
         tmp_arr[i][0].sort(function (a, b) {
            tmp_sort_num_a = 0;
            tmp_sort_num_b = 0;

				if (!this_elem.hasClass('sort_elem')) {
					sort_val_a = a.childNodes[column].textContent;
					sort_val_b = b.childNodes[column].textContent;
				} else {
					sort_val_a = $(a.childNodes[column]).children().eq(0).val();
					sort_val_b = $(b.childNodes[column]).children().eq(0).val();
				}

            if (sort_val_a.replace(/^\s+/, "").replace(/\s+$/, "").length) {
               tmp_sort_num_a = parseInt(sort_val_a.replace(/^\s+/, "").replace(/\s+$/, ""));
            }
            if (sort_val_b.replace(/^\s+/, "").replace(/\s+$/, "").length) {
               tmp_sort_num_b = parseInt(sort_val_b.replace(/^\s+/, "").replace(/\s+$/, ""));
            }


            if (tmp_sort_num_a > tmp_sort_num_b) {
               return 1;
            } else if (tmp_sort_num_b > tmp_sort_num_a) {
               return -1;
            }
            return 0;
         });

         tmp_arr[i][1].sort(function (a, b) {
            tmp_sort_str_a = 0;
            tmp_sort_str_b = 0;

				if (!this_elem.hasClass('sort_elem')) {
					sort_val_a = a.childNodes[column].textContent;
					sort_val_b = b.childNodes[column].textContent;
				} else {
					sort_val_a = $(a.childNodes[column]).children().eq(0).val();
					sort_val_b = $(b.childNodes[column]).children().eq(0).val();
				}

            if (sort_val_a.replace(/^\s+/, "").replace(/\s+$/, "").split(" ")[0].replace(/\*/, "").length) {
               tmp_sort_str_a = parseInt(sort_val_a.replace(/^\s+/, "").replace(/\s+$/, "").split(" ")[0].replace(/\*/, ""));
            }
            if (sort_val_b.replace(/^\s+/, "").replace(/\s+$/, "").split(" ")[0].replace(/\*/, "").length) {
               tmp_sort_str_b = parseInt(sort_val_b.replace(/^\s+/, "").replace(/\s+$/, "").split(" ")[0].replace(/\*/, ""));
            }

            if (tmp_sort_str_a > tmp_sort_str_b) {
               return 1;
            } else if (tmp_sort_str_b > tmp_sort_str_a) {
               return -1;
            }
            return 0;
         });
      }
   } else if (this_elem.hasClass('desc')) {
      for (var i = 0; i < tmp_arr.length; i++) {
         tmp_arr[i][0].sort(function (a, b) {
            tmp_sort_num_a = 0;
            tmp_sort_num_b = 0;

				if (!this_elem.hasClass('sort_elem')) {
					sort_val_a = a.childNodes[column].textContent;
					sort_val_b = b.childNodes[column].textContent;
				} else {
					sort_val_a = $(a.childNodes[column]).children().eq(0).val();
					sort_val_b = $(b.childNodes[column]).children().eq(0).val();
				}

            if (sort_val_a.replace(/^\s+/, "").replace(/\s+$/, "").length) {
               tmp_sort_num_a = parseInt(sort_val_a.replace(/^\s+/, "").replace(/\s+$/, ""));
            }
            if (sort_val_b.replace(/^\s+/, "").replace(/\s+$/, "").length) {
               tmp_sort_num_b = parseInt(sort_val_b.replace(/^\s+/, "").replace(/\s+$/, ""));
            }

            if (tmp_sort_num_a > tmp_sort_num_b) {
               return -1;
            } else if (tmp_sort_num_b > tmp_sort_num_a) {
               return 1;
            }
            return 0;
         });

         tmp_arr[i][1].sort(function (a, b) {
            tmp_sort_str_a = 0;
            tmp_sort_str_b = 0;

				if (!this_elem.hasClass('sort_elem')) {
					sort_val_a = a.childNodes[column].textContent;
					sort_val_b = b.childNodes[column].textContent;
				} else {
					sort_val_a = $(a.childNodes[column]).children().eq(0).val();
					sort_val_b = $(b.childNodes[column]).children().eq(0).val();
				}

            if (sort_val_a.replace(/^\s+/, "").replace(/\s+$/, "").split(" ")[0].replace(/\*/, "").length) {
               tmp_sort_str_a = parseInt(sort_val_a.replace(/^\s+/, "").replace(/\s+$/, "").split(" ")[0].replace(/\*/, ""));
            }
            if (sort_val_b.replace(/^\s+/, "").replace(/\s+$/, "").split(" ")[0].replace(/\*/, "").length) {
               tmp_sort_str_b = parseInt(sort_val_b.replace(/^\s+/, "").replace(/\s+$/, "").split(" ")[0].replace(/\*/, ""));
            }

            if (tmp_sort_str_a > tmp_sort_str_b) {
               return -1;
            } else if (tmp_sort_str_b > tmp_sort_str_a) {
               return 1;
            }
            return 0;
         });
      }
   }

   for (var i = 0; i < sort_arr.length; i++) {
      sort_arr[i] = [];
      if (this_elem.hasClass('desc')) {
         tmp_arr[i].reverse();
      }
      for (var j = 0; j < tmp_arr[i].length; j++) {
         for (var k = 0; k < tmp_arr[i][j].length; k++) {
            sort_arr[i].push(tmp_arr[i][j][k]);
         }
      }
   }

   th = 0;

   _.each(this_elem.parents('tbody').children('tr'), function (item, i) {
      if (item.childNodes[0].tagName == "TH") {
         sort_arr[th].reverse();
         _.each(sort_arr[th], function (td) {
            item.parentNode.insertBefore(td, item.nextSibling);
         });
         th++;
      }
   });
});

$(document).on('click', '.sort_ip', function (evt) {
	var this_elem = $(this);

   if (this_elem.hasClass('asce')) {
      this_elem.removeClass('asce');
      this_elem.addClass('desc');
      this_elem.children('.img_asce').hide();
      this_elem.children('.img_desc').show();
   } else if (this_elem.hasClass('desc')) {
      this_elem.removeClass('desc');
      this_elem.addClass('asce');
      this_elem.children('.img_asce').show();
      this_elem.children('.img_desc').hide();
   } else {
      this_elem.addClass('asce');
   }

   var sort_arr = [];
   var tmp_arr_a = [];
   var tmp_arr_b = [];
   var tmp_ip_a = 0;
   var tmp_ip_b = 0;
   var th = -1;
   var column = 0;
   var sort_val_a = null;
   var sort_val_b = null;

   if (this_elem.parents('table').find('[name=CHKFLAG]').length) {
      column = this_elem.index() - 1;
   } else {
      column = this_elem.index();
   }

   _.each(this_elem.parents('tbody').children('tr'), function (item) {
      if (item.childNodes[0].tagName == "TH") {
         th++;
         sort_arr[th] = [];
      } else if (item.childNodes[0].tagName == "TD") {
         sort_arr[th].push(item);
      }
   });

   if (this_elem.hasClass('asce')) {
      for (var i = 0; i < sort_arr.length; i++) {
         sort_arr[i].sort(function (a, b) {
            tmp_ip_a = 0;
            tmp_ip_b = 0;

				if (!this_elem.hasClass('sort_elem')) {
					sort_val_a = a.childNodes[column].textContent;
					sort_val_b = b.childNodes[column].textContent;
				} else {
					sort_val_a = $(a.childNodes[column]).children().eq(0).val();
					sort_val_b = $(b.childNodes[column]).children().eq(0).val();
				}

            if (sort_val_a.replace(/^\s+/, "").replace(/\s+$/, "").length) {
               tmp_arr_a = sort_val_a.replace(/^\s+/, "").replace(/\s+$/, "").split(".");
               for (var j = 0; j < tmp_arr_a.length; j++) {
                  tmp_ip_a += parseInt(tmp_arr_a[j]) * Math.pow(256, tmp_arr_a.length - j);
               }
            }

            if (sort_val_b.replace(/^\s+/, "").replace(/\s+$/, "").length) {
               tmp_arr_b = sort_val_b.replace(/^\s+/, "").replace(/\s+$/, "").split(".");
               for (var k = 0; k < tmp_arr_b.length; k++) {
                  tmp_ip_b += parseInt(tmp_arr_b[k]) * Math.pow(256, tmp_arr_b.length - k);
               }
            }

            if (tmp_ip_a > tmp_ip_b) {
               return 1;
            } else if (tmp_ip_b > tmp_ip_a) {
               return -1;
            }
            return 0;
         });
      }
   } else if (this_elem.hasClass('desc')) {
      for (var i = 0; i < sort_arr.length; i++) {
         sort_arr[i].sort(function (a, b) {
            tmp_ip_a = 0;
            tmp_ip_b = 0;

				if (!this_elem.hasClass('sort_elem')) {
					sort_val_a = a.childNodes[column].textContent;
					sort_val_b = b.childNodes[column].textContent;
				} else {
					sort_val_a = $(a.childNodes[column]).children().eq(0).val();
					sort_val_b = $(b.childNodes[column]).children().eq(0).val();
				}

            if (sort_val_a.replace(/^\s+/, "").replace(/\s+$/, "").length) {
               tmp_arr_a = sort_val_a.replace(/^\s+/, "").replace(/\s+$/, "").split(".");
               for (var j = 0; j < tmp_arr_a.length; j++) {
                  tmp_ip_a += parseInt(tmp_arr_a[j]) * Math.pow(256, tmp_arr_a.length - j);
               }
            }

            if (sort_val_b.replace(/^\s+/, "").replace(/\s+$/, "").length) {
               tmp_arr_b = sort_val_b.replace(/^\s+/, "").replace(/\s+$/, "").split(".");
               for (var k = 0; k < tmp_arr_b.length; k++) {
                  tmp_ip_b += parseInt(tmp_arr_b[k]) * Math.pow(256, tmp_arr_b.length - k);
               }
            }

            if (tmp_ip_a > tmp_ip_b) {
               return -1;
            } else if (tmp_ip_b > tmp_ip_a) {
               return 1;
            }
            return 0;
         });
      }
   }

   th = 0;

   _.each(this_elem.parents('tbody').children('tr'), function (item, i) {
      if (item.childNodes[0].tagName == "TH") {
         sort_arr[th].reverse();
         _.each(sort_arr[th], function (td) {
            item.parentNode.insertBefore(td, item.nextSibling);
         });
         th++;
      }
   });
});

$(document).on('mouseenter', '.toolTip-img', function (evt) {
	$(this).siblings('.toolTip-txt').show();
});

$(document).on('mouseleave', '.toolTip-img', function (evt) {
	$(this).siblings('.toolTip-txt').hide();
});

function getObjects(obj, key, val) {
	var objects = [];
	for (var i in obj) {
		if (!obj.hasOwnProperty(i)) continue;
		if (typeof obj[i] == 'object') {
			objects = objects.concat(getObjects(obj[i], key, val));
		} else if (i == key && obj[key] == val) {
			objects.push(obj);
		}
	}
	return objects;
}

$(document).on('click', '.btn_p96_dbdownload', function (evt) {
	var file_name = "ipecs.trusted.root.cert.crt";
	file_name = encodeURI(file_name);
   $('#hiddenFrame').attr('src', file_name);
});

$(document).on('click', '.btn_p96_restart', function (evt) {
   var send_msg = "{\"SERVER_RESTART\":\"\"}";
   setSpecialPacket(send_msg);
   debug_mode.flag && console.log(send_msg);
   $('#' + ap.render_pgm).html("");
   pgm_models.get_model(ap.render_pgm, true, packet);
});

$(document).on('click', '.btn_p96_cleanup', function (evt) {
   var send_msg = "{\"CLEANUP\":\"\"}";
   setSpecialPacket(send_msg);
   debug_mode.flag && console.log(send_msg);
   $('#' + ap.render_pgm).html("");
   pgm_models.get_model(ap.render_pgm, true, packet);
});

$(document).on('click', '.btn_link_to_otherpgm', function (evt) {
	if (active_base == "tab_user_guide") {
		var tab_str = $(this).attr('class').match(/pgmug\d+/g)[0];

		$('#'+ap.render_pgm).html("");
		pgm_models.get_model(tab_str, true, packet);
	} else {
		var tab_str = $(this).attr('class').match(/pgm\d+/g)[0];
		
		if((pgm_info[eval(tab_str.replace("pgm",""))]) && (pgm_info[eval(tab_str.replace("pgm",""))].auth == 0)) {
			$('<div />').html(langs.getText("error_msg","alert_unauth")).dialog({
				modal: true,
				closeOnEscape: false,
				title: langs.getText("common","notification"),
				open: function (event, ui) {
					$(".ui-dialog-titlebar-close").hide();
				},
				buttons: [
					{
						text: langs.getText("common","simple_okay"),
						click: function () {
							$(this).dialog("destroy");
						}
					}
				]
			});
			return false;
		}

		if (getObjects(left_pgm_menuList, "num", parseInt(tab_str.match(/\d+/)))) {
			if (active_base != "tab_pgm_base") {
				if (active_base == "tab_maintenance") {
					$("#main_menu a").removeClass("active");
					$("#list_for_moblie_web li").removeClass("active");
					$("#left-menu a").removeClass("active");

					$("#menu_select_base").hide();
					$("#menu_search_pgm").hide();
					$('#search_pgm').val("");				
					$("#tab_pgm_base").hide();
					$("#tab_function_base").hide();
					$("#tab_install_wizard").hide();
					$("#tab_maintenance").hide();
					$("#accordion div").remove();

					$("#main_menu #menu_admin").addClass("active");
					$("#list_for_moblie_web #mob_menu_admin").parent().addClass("active");
					$("#left-menu #menu_pgm_base").addClass("active");

					$("#menu_select_base").show();

					$("#tab_pgm_base").show();
					$("#menu_search_pgm").show();
					active_base = "tab_pgm_base";
					$('#search_pgm').attr('placeholder',langs.getText("common","left_menu_pgmsearch"));

					pgm_dir_view.render();
					pgm_menuList_view.render();
					$('.custom_span_menu').scrollTop(0);
					tab_history = pgm_tab_history;
				} else {
					$("#left-menu a").removeClass("active");

					$("#tab_pgm_base").hide();
					$("#tab_function_base").hide();
					$("#tab_install_wizard").hide();
					$("#menu_search_pgm").hide();
					$('#search_pgm').val("");
					$("#accordion div").remove();

					$("#left-menu #menu_pgm_base").addClass("active");
					$("#tab_pgm_base").show();
					active_base = "tab_pgm_base";
					$("#menu_search_pgm").show();
					$('#search_pgm').attr('placeholder',langs.getText("common","left_menu_pgmsearch"));

					pgm_dir_view.render();
					pgm_menuList_view.render();
					$('.custom_span_menu').scrollTop(0);
					tab_history = pgm_tab_history;
				}
			}
		} else if (getObjects(left_maint_menuList, "num", parseInt(tab_str.match(/\d+/)))) {
			if (active_base != "tab_maintenance") {
				$("#main_menu a").removeClass("active");
				$("#list_for_moblie_web li").removeClass("active");

				$("#menu_select_base").hide();
				$("#menu_search_pgm").hide();
				$('#search_pgm').val("");
				$("#tab_pgm_base").hide();
				$("#tab_function_base").hide();
				$("#tab_install_wizard").hide();
				$("#tab_maintenance").hide();
				$("#accordion div").remove();

				$("#main_menu #menu_mnt").addClass("active");
				$("#list_for_moblie_web #mob_menu_maint").parent().addClass("active");

				$("#tab_maintenance").show();

				active_base = "tab_maintenance";
				$("#menu_search_pgm").show();
				$('#search_pgm').attr('placeholder',langs.getText("common","left_menu_maintsearch"));

				mnt_dir_view.render();
				mnt_menuList_view.render();
				$('.custom_span_menu').scrollTop(0);

				tab_history = mnt_tab_history;
			}
		}

		if (active_base == "tab_stn_base") {
			if (tab_str == "pgms012" && !info.SWUA_EN) {
				$('<div />').html(langs.getText("ps012","alert_disable")).dialog({
					modal: true,
					closeOnEscape: false,
					title: langs.getText("common","notification"),
					open: function (event, ui) {
						$(".ui-dialog-titlebar-close").hide();
					},
					buttons: [
						{
							text: langs.getText("common","simple_okay"),
							click: function () {
								$(this).dialog("destroy");
							}
						}
					]
				});
				return false;
			} else if (tab_str == "pgms016" && !info.CB_EN) {
				$('<div />').html(langs.getText("ps016","alert_disable")).dialog({
					modal: true,
					closeOnEscape: false,
					title: langs.getText("common","notification"),
					open: function (event, ui) {
						$(".ui-dialog-titlebar-close").hide();
					},
					buttons: [
						{
							text: langs.getText("common","simple_okay"),
							click: function () {
								$(this).dialog("destroy");
							}
						}
					]
				});
				return false;
			}
		} else {
			if (((tab_str == "pgm1291") || (tab_str == "pgm1600") || (tab_str == "pgm212") || (tab_str == "pgm214") || (tab_str == "pgm99") || (tab_str == "pgm46") || (tab_str == "pgm47") || (tab_str == "pgm48") || (tab_str == "pgm49") || (tab_str == "pgm51") || (tab_str == "pgm52") || (tab_str == "pgm78") || (tab_str == "pgm781") || (tab_str == "pgm782") || (tab_str == "pgm79") || (tab_str == "pgm87") || (tab_str == "pgm76") || (tab_str == "pgm77") || (tab_str == "pgm80") || (tab_str == "pgm81") || (tab_str == "pgm82") || (tab_str == "pgm83") || (tab_str == "pgm84") || (tab_str == "pgm85") || (tab_str == "pgm88") || (tab_str == "pgm90") || (tab_str == "pgm91") || (tab_str == "pgm93") || (tab_str == "pgm94") || (tab_str == "pgm95") || (tab_str == "pgm60") || (tab_str == "pgm61") || (tab_str == "pgm62") || (tab_str == "pgm63") || (tab_str == "pgm64") || (tab_str == "pgm65") || (tab_str == "pgm69") || (tab_str == "pgm309") || (tab_str == "pgm312") || (tab_str == "pgm3131") || (tab_str == "pgm3132") || (tab_str == "pgm315") || (tab_str == "pgm70") || (tab_str == "pgm71") || (tab_str == "pgm72") || (tab_str == "pgm73") || (tab_str == "pgm731") || (tab_str == "pgm490") || (tab_str == "pgm1292") || (tab_str == "pgm4461")) && offline_mode) {
				$('<div />').html(langs.getText("error_msg","alert_owadisable")).dialog({
					modal: true,
					closeOnEscape: false,
					title: langs.getText("common","notification"),
					open: function (event, ui) {
						$(".ui-dialog-titlebar-close").hide();
					},
					buttons: [
						{
							text: langs.getText("common","simple_okay"),
							click: function () {
								$(this).dialog("destroy");
							}
						}
					]
				});
				return false;
			}
		}

		if (active_base == "tab_maintenance") {
			var tab_title = langs.getText("mnt_menu",tab_str);
		} else if (active_base == "tab_stn_base") {
			var tab_title = langs.getText("stn_menu",tab_str);
		} else {
			var tab_title = langs.getText("adm_menu",tab_str);
		}
		var tab_index = 0;
		var existed = false;
		var range_type = [];
		var range = [];
		if (getObjects(pgm_views[ap.render_pgm].collection.models[0].attributes, "name", $(this).attr("name")).length && getObjects(pgm_views[ap.render_pgm].collection.models[0].attributes, "name", $(this).attr("name"))[0].value) {
			if (!require.defined('models/'+tab_str+'_model')) {
				require(['models/'+tab_str+'_model'], function (model) {
					if (getObjects(model.elements, "name", "RANGE_TYPE_1").length) {
						range_type.push(getObjects(model.elements, "name", "RANGE_TYPE_1")[0].range_type);
					} else {
						range_type.push("2");
					}
				});
				requirejs.undef('models/'+tab_str+'_model');
			} else {
				if (pgm_views[tab_str]==undefined){
					require(['models/'+tab_str+'_model'], function (model) {
						if (getObjects(model.elements, "name", "RANGE_TYPE_1").length) {
							range_type.push(getObjects(model.elements, "name", "RANGE_TYPE_1")[0].range_type);
						} else {
							range_type.push("2");
						}
					});
				} else {
					if (getObjects(pgm_views[tab_str].collection.models[0].attributes, "name", "RANGE_TYPE_1").length) {
						range_type.push(getObjects(pgm_views[tab_str].collection.models[0].attributes, "name", "RANGE_TYPE_1")[0].range_type);
					} else {
						range_type.push("2");
					}
				}
			}
			range.push(getObjects(pgm_views[ap.render_pgm].collection.models[0].attributes, "name", $(this).attr("name"))[0].value);
		}

		$('#' + active_base + ' .nav-tabs-main li').removeClass("active");
		$('#' + active_base + ' .nav-tabs-main li .icon_refresh').remove();
		$('#' + 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+' .nav-tabs-main .active').index() == 0) {
			if($("#accordion .panel-heading").length) {
				$('.panel-collapse').removeClass('in');
				$('.panel-collapse')['height'](0);
				$("#accordion .panel-heading").removeClass('active');
				$("#accordion .panel-heading").children('img').remove();
			}
			$('.custom_span_menu .pgm').removeClass('active');
		} else {
			var sel_id = $('#'+active_base+' .nav-tabs-main .active a').attr('href');
			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 .panel-heading").length) {
				$('.panel-collapse').removeClass('in');
				$('.panel-collapse')['height'](0);
				$("#accordion .panel-heading").removeClass('active');
				$("#accordion .panel-heading").children('img').remove();

				$('.panel-collapse .active').parents('.panel-collapse').addClass('in');
				$('.panel-collapse .active').parents('.panel-collapse')['height']('100%');
				$('.panel-collapse .active').parents('.panel-default').children('.panel-heading').addClass('active');
				$('.panel-collapse .active').parents('.panel-default').children('.panel-heading').append("<img src='img/a.png' style='float:right; margin-top:6px;' />");
			}
		}

		if (existed === true) {
			$("#" + ap.render_pgm).html("");
		}

		if (ap.active_pgm === "pgm51") {
			make_fileup_pgm(false);
		} else if (ap.active_pgm === "pgm55") {
			make_dbfileup_pgm();
		} else if (ap.active_pgm === "pgm56") {
			make_mlfileup_pgm();
		} else if (ap.active_pgm === "pgm76") {
			packet.setPacket(0, range_type, range, "{}");
			make_vsfprmtup_pgm(packet);
		} else if (ap.active_pgm === "pgm77") {
			make_vsfindivup_pgm();
		} else if (ap.active_pgm === "pgm782") {
			make_moh_indivup_pgm();
		} else if (ap.active_pgm === "pgm80") {
			make_vsfsgindivup_pgm();
		} else if (ap.active_pgm === "pgm82") {
			packet.setPacket(0, range_type, range, "{}");
			make_vsfsgdn_pgm(packet);
		} else if (ap.active_pgm === "pgm83") {
			packet.setPacket(0, range_type, range, "{}");
			make_vsfsgup_pgm(packet);
		} else if (ap.active_pgm === "pgm89") {
			make_licenseup_pgm(false);
		} else if (ap.active_pgm === "pgm46") {
			make_usrgrtfileup_pgm(false);
		} else if (ap.active_pgm === "pgm47") {
			packet.setPacket(0, range_type, range, "{}");
			make_usrgrtfiledn_pgm(packet);
		} else if (ap.active_pgm === "pgm48") {
			make_cdnfileup_pgm(false);
		} else if (ap.active_pgm === "pgm49") {
			packet.setPacket(0, range_type, range, "{}");
			make_cdnfiledn_pgm(packet);
		} else {
			packet.setPacket(0, range_type, range, "{}");
			pgm_models.get_model(ap.render_pgm, false, packet);
		}

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

		$(document).trigger("Resize_pane");
   }
});
