requirejs.config({
	waitSeconds: 150
});

var save_flag = false;
var hidden_flags = new Object;
var debug_mode = new Object;
if (localStorage.getItem("d_flag") == null) {
   localStorage.setItem("d_flag", false);
}
debug_mode.flag = eval(localStorage.getItem("d_flag"));
debug_mode.on = function () {
   debug_mode.flag = true;
   localStorage.setItem("d_flag", true);
}
debug_mode.off = function () {
   debug_mode.flag = false;
   localStorage.setItem("d_flag", false);
}

var ap = new Object;
ap.active_pgm = null;
ap.render_pgm = null;
ap.set_active_pgm = function (pgm) {
   ap.active_pgm = pgm;
   ap.render_pgm = pgm;
   $(document).trigger("change_active_pgm", pgm);
}
var active_base = null;

var pgm_models = new Object;
var pgm_views = new Object;
var pgm_key_maps = new Object;
var pgm_name_maps = new Object;

var pgm_dir_view = null;
var pgm_menuList_view = null;
var searchText = null;

var column_config = new Object;

var packet = new Object;
packet.main = 0;
packet.type = [];
packet.range = [];
packet.msg = "{}";
packet.setPacket = function (main, type, ran, msg) {
   packet.main = main;
   packet.type = type;
   packet.range = ran;
   packet.msg = msg;
}

var offline_mode = 1;
if (localStorage.getItem("lang_flag") == null) {
   localStorage.setItem("lang_flag", 0);
}
var lang = eval(localStorage.getItem("lang_flag"));
active_base = "tab_user_guide";
ap.active_pgm = "user_guide_pgm";
ap.render_pgm = "user_guide_pgm";
hidden_flags["user_guide_pgm"] = false;
var lang_common_type = "common";
var lang_error_msg_type = "error_msg";

requirejs.onError = function (err) {
   debug_mode.flag && console.log("Require Error : " + err.requireModules[0]);
   //debug_mode.flag && console.log("Retry...");
   skipConfirm_flag = true;
   $('<div />').html("Problem loading a web page occurred. Please refresh the page and try again.").dialog({
      modal: true,
      closeOnEscape: false,
      title: "Notification",
      open: function (event, ui) {
         $(".ui-dialog-titlebar-close").hide();
      },
      buttons: {
         Refresh: function () {
            location.href = location.href.replace(/#$/, '')
            $(this).dialog("destroy");
         }
      }
   });
};

function main_app() {
	require(['../userguide_info'], function (a) {
		debug_mode.flag && console.log("userguide_info loaded");
		require(['user/common.lang'], function (b) {
			debug_mode.flag && console.log("user/common.lang loaded");
			require(['user/common.profile'], function (c) {
				debug_mode.flag && console.log("user/common.profile loaded");

				if (info.SYSTEM_ID == "iPECS eMG80" || info.SYSTEM_ID == "iPECS eMG800") {
					if (info.BOARD_ID == 2) {
						if (info.SYSTEM_ID == "iPECS eMG800") {
							$('.navbar-brand').css('padding','10px 85px 5px 20px');
							$('.navbar-brand img').attr('src','img/Vertical_summit_800_main.png');
						} else {
							$('.navbar-brand').css('padding','10px 85px 5px 20px');
							$('.navbar-brand img').attr('src','img/Vertical_summit_logo_main.png');
						}
					} else if (info.BOARD_ID == 3) {
						if (info.SYSTEM_ID == "iPECS eMG800") {
							$('.navbar-brand').css('padding','9px 148px 5px 20px');
							$('.navbar-brand img').attr('src','img/Aria_IP_800_logo_main.png');
						} else {
							$('.navbar-brand').css('padding','10px 148px 5px 20px');
							$('.navbar-brand img').attr('src','img/Aria_IP_100_logo_main.png');
						}
					} else {
						$('.navbar-brand img').attr('src','img/iPECS_logo_main.png');
					}
				} else {
					$('.navbar-brand img').attr('src','img/iPECS_logo_main.png');
				}
				$('.navbar-brand').append(langs.getText("common","ug_title"));
				$('title').text(langs.getText("common","ug_title"));
				
				$('#account_logout').text(langs.getText("common","top_menu_exit"));
				$('#menu_change_language a').text(langs.getText("common","top_menu_chlang"));
				$('#change_language #change_eng').text(langs.getText("common","opt_lang_eng"));
				$('#change_language #change_local').text(langs.getText("common","top_menu_chlang_loc"));
				
				$('#menu_for_moblie_web #mob_title_chlang').text(langs.getText("common","top_menu_chlang"));
				$('#menu_for_moblie_web #mob_chlang_eng').text(langs.getText("common","opt_lang_eng"));
				$('#menu_for_moblie_web #mob_chlang_local').text(langs.getText("common","top_menu_chlang_loc"));
				$('#menu_for_moblie_web #mob_logout').text(langs.getText("common","top_menu_logout"));
				require(['pgms/ug_leftmenu_view'], function (d) {
					debug_mode.flag && console.log("pgms/ug_leftmenu_view loaded");
					require(['pgms/pgm_view'], function (e) {
						debug_mode.flag && console.log("pgms/pgm_view loaded");
						require(['pgms/main_pgm'], function (f) {
							debug_mode.flag && console.log("pgms/main_pgm loaded");
							allLoadComplete = true;
							debug_mode.flag && console.log("all load complete!!");
							$('.loadingPane').removeClass('whitePane').hide();
						});
					});
				});
			});
		});
   });
}

(function ($) {
   $("#tpl").load('templates/templates.html', main_app);
}(jQuery));