var g_wnd_num = 0;
var wifi_exist;
var wifi_enable;
var g4_exist;
var g4_enable;

function scan_window_init() {
	$(".uri").mouseover(function (e) {
		var x = e.originalEvent.x || e.originalEvent.layerX || 0;
		var y = e.originalEvent.y || e.originalEvent.layerY || 0;
		$("#uri_scan").text($(this).next("span").text()).attr("style", "left:" + x + "px;top:" + y + "px;");
	}).mouseout(function (e) {
		$("#uri_scan").attr("style", "display:none;");
	});
}
function handle_wndnum(wnd_num) {
	if (g_wnd_num == 0) {
		for (var i = 0; i < wnd_num; ++i) {
			var temp_string = "";
			temp_string += "<hr />";
			temp_string += "<div class='subtitle'>";
			temp_string += "<span id='status_wnd_text_" + i + "' class='status_subtitle'></span>";
			temp_string += "</div>";
			temp_string += "<div>";
			temp_string += "<span id='status_decode_uri_text_" + i + "' class='small_title'></span>\n\r";
			temp_string += "<span id='status_decode_uri_" + i + "' class='dynamic_data uri'></span>";
			temp_string += "<span id='status_decode_uri_display_" + i + "' style='display:none;'></span>";
			temp_string += "</div>";
			temp_string += "<div>";
			temp_string += "<span id='status_wnd_status_text_" + i + "' class='small_title'></span>\n\r";
			temp_string += "<span id='status_wnd_status_" + i + "' class='dynamic_data'></span>";
			temp_string += "</div>";
			temp_string += "<div>";
			temp_string += "<span id='status_wnd_resolution_text_" + i + "' class='small_title'></span>\n\r";
			temp_string += "<span id='status_wnd_resolution_" + i + "' class='dynamic_data'></span>";
			temp_string += "</div>";
			temp_string += "<div>";
			temp_string += "<span id='status_wnd_type_text_" + i + "' class='small_title'></span>\n\r";
			temp_string += "<span id='status_wnd_type_" + i + "' class='dynamic_data'></span>";
			temp_string += "<span id='unable_field_" + i + "' class='dynamic_data' style='color: red'></span>";
			temp_string += "</div>";
			temp_string += "<div id='audio_type_div_" + i + "'>";
			temp_string += "<span id='status_audio_type_text_" + i + "' class='small_title'></span>\n\r";
			temp_string += "<span id='status_audio_type_" + i + "' class='dynamic_data'></span>";
			temp_string += "</div>";
			temp_string += "<div>";
			temp_string += "<span id='status_wnd_fps_text_" + i + "' class='small_title'></span>\n\r";
			temp_string += "<span id='status_wnd_fps_" + i + "' class='dynamic_data'></span>";
			temp_string += "</div>";
			temp_string += "<div>";
			temp_string += "<span id='status_wnd_bps_text_" + i + "' class='small_title'></span>\n\r";
			temp_string += "<span id='status_wnd_bps_" + i + "' class='dynamic_data'></span>";
			temp_string += "</div>";
			temp_string += "<div>";
			temp_string += "<span id='status_wnd_vdecnum_text_" + i + "' class='small_title'></span>\n\r";
			temp_string += "<span id='status_wnd_vdecnum_" + i + "' class='dynamic_data'></span>";
			temp_string += "</div>";
			temp_string += "<div>";
			temp_string += "<span id='status_wnd_adecnum_text_" + i + "' class='small_title'></span>\n\r";
			temp_string += "<span id='status_wnd_adecnum_" + i + "' class='dynamic_data'></span>";
			temp_string += "</div>";
			temp_string += "<div class='status_error_line'>";
			temp_string += "<span class='small_title status_error_spacer'></span>\n\r";
			temp_string += "<span id='status_wnd_errorstatus_text_" + i + "' class='dynamic_data span_href green errorstatus'></span>\n\r";
			temp_string += "</div>";
			temp_string += "<div id='status_wnd_errorstatus_row_" + i + "' class='status_error_panel_row display_off'>";
			temp_string += "<span class='small_title status_error_spacer'></span>\n\r";
			temp_string += "<div id='status_wnd_errorstatus_" + i + "' class='tooltip'></div>";
			temp_string += "</div>";
			$("#status").append(temp_string);
			errorstatus_content(i);
		}
		g_wnd_num = wnd_num;
		bind_errorstatus_toggle();
		language_setup(g_wnd_num);
		parentpage_adjust_height();
		scan_window_init();
	} else {
		if (g_wnd_num != wnd_num) {
			window.parent.location.reload(true);
		}
	}
}

function bind_errorstatus_toggle() {
	$("#status .errorstatus").unbind("click").click(function () {
		var index = this.id.replace("status_wnd_errorstatus_text_", "");
		var detail_row = $("#status_wnd_errorstatus_row_" + index);
		if (detail_row.hasClass("display_off")) {
			detail_row.removeClass("display_off");
			$(this).addClass("expanded");
		} else {
			detail_row.addClass("display_off");
			$(this).removeClass("expanded");
		}
		parentpage_adjust_height();
	});
}


function errorstatus_content(i){
	var errorstatus = "";
	errorstatus += "<div>";
	errorstatus += "<span id='s32FormatErr_text_" + i + "' class='small_title'></span>\n\r";
	errorstatus += "<span id='s32FormatErr_" + i + "' class='dynamic_data'></span>";
	errorstatus += "</div>";
	errorstatus += "<div>";
	errorstatus += "<span id='s32PicSizeErrSet_text_" + i + "' class='small_title'></span>\n\r";
	errorstatus += "<span id='s32PicSizeErrSet_" + i + "' class='dynamic_data'></span>";
	errorstatus += "</div>";
	errorstatus += "<div>";
	errorstatus += "<span id='s32StreamUnsprt_text_" + i + "' class='small_title'></span>\n\r";
	errorstatus += "<span id='s32StreamUnsprt_" + i + "' class='dynamic_data'></span>";
	errorstatus += "</div>";
	errorstatus += "<div>";
	errorstatus += "<span id='s32PackErr_text_" + i + "' class='small_title'></span>\n\r";
	errorstatus += "<span id='s32PackErr_" + i + "' class='dynamic_data'></span>";
	errorstatus += "</div>";
	errorstatus += "<div>";
	errorstatus += "<span id='s32PrtclNumErrSet_text_" + i + "' class='small_title'></span>\n\r";
	errorstatus += "<span id='s32PrtclNumErrSet_" + i + "' class='dynamic_data'></span>";
	errorstatus += "</div>";
	errorstatus += "<div>";
	errorstatus += "<span id='s32RefErrSet_text_" + i + "' class='small_title'></span>\n\r";
	errorstatus += "<span id='s32RefErrSet_" + i + "' class='dynamic_data'></span>";
	errorstatus += "</div>";
	errorstatus += "<div>";
	errorstatus += "<span id='s32PicBufSizeErrSet_text_" + i + "' class='small_title'></span>\n\r";
	errorstatus += "<span id='s32PicBufSizeErrSet_" + i + "' class='dynamic_data'></span>";
	errorstatus += "</div>";
	errorstatus += "<div>";
	errorstatus += "<span id='s32VdecStreamNotRelease_text_" + i + "' class='small_title'></span>\n\r";
	errorstatus += "<span id='s32VdecStreamNotRelease_" + i + "' class='dynamic_data'></span>";
	errorstatus += "</div>";
	$("#status_wnd_errorstatus_" + i).append(errorstatus);

}

function get_errorstatus(i){
	$.ajax({
		type: "GET",
		url: "http://" + xc_gethost() + "/get_status",
		dataType: "xml",
		cache: false,
		error: function () {
		},
		success: function (sxml) {
			var s32FormatErr = $(sxml).find("s" + i).find("s32FormatErr").text();
			var s32PicSizeErrSet = $(sxml).find("s" + i).find("s32PicSizeErrSet").text();
			var s32StreamUnsprt = $(sxml).find("s" + i).find("s32StreamUnsprt").text();
			var s32PackErr = $(sxml).find("s" + i).find("s32PackErr").text();
			var s32PrtclNumErrSet = $(sxml).find("s" + i).find("s32PrtclNumErrSet").text();
			var s32RefErrSet = $(sxml).find("s" + i).find("s32RefErrSet").text();
			var s32PicBufSizeErrSet = $(sxml).find("s" + i).find("s32PicBufSizeErrSet").text();
			var s32VdecStreamNotRelease = $(sxml).find("s" + i).find("s32VdecStreamNotRelease").text();

			$("#s32FormatErr_" + i).html(s32FormatErr);
			$("#s32PicSizeErrSet_" + i).html(s32PicSizeErrSet);
			$("#s32StreamUnsprt_" + i).html(s32StreamUnsprt);
			$("#s32PackErr_" + i).html(s32PackErr);
			$("#s32PrtclNumErrSet_" + i).html(s32PrtclNumErrSet);
			$("#s32RefErrSet_" + i).html(s32RefErrSet);
			$("#s32PicBufSizeErrSet_" + i).html(s32PicBufSizeErrSet);
			$("#s32VdecStreamNotRelease_" + i).html(s32VdecStreamNotRelease);
		}
	});
}

function changePage(id){
	var item = window.parent.document.getElementById(id);
	var click = window.parent.document.createEvent('MouseEvents');
	click.initEvent('click', true, true);
	item.dispatchEvent(click);
}

function init_layoutset_window(){
	$.ajax({
		type: "GET",
		url: "http://" + xc_gethost() + "/get_vopos?",
		dataType: "xml",
		cache: false,
		// async: false,
		error: function () {
		},
		success: function (data) {
			//画面布局框
			var content = "<span id='status_layout_background_text' style='color: white; position: absolute; right: 5px; bottom: 2px;'></span>";
			var bg_color = ['rgb(186, 204, 225)', 'rgb(192, 235, 210)', 'rgb(255, 198, 192)', 'rgb(218, 200, 239)']

			var vo_enable = $(data).find("enable").text();
			if(vo_enable == 0){
				$('#status_vopos_enable').html($.i18n.prop('index_common_disable'));
				$('#status_layout_div').hide();
			}else if(vo_enable == 1){
				$('#status_vopos_enable').html($.i18n.prop('index_common_enable'));
				$('#status_layout_div').show();
			}
			for(var i = 0; i < 4; i++){
				var display = $(data).find("show" + i).text();
				var priority = $(data).find("priority" + i).text();
				if(display == 1){
					var vo_pos_x = $(data).find("voposx" + i).text();
					var vo_pos_y = $(data).find("voposy" + i).text();
					var vo_pos_w = $(data).find("voposw" + i).text();
					var vo_pos_h = $(data).find("voposh" + i).text();
					vo_pos_x = (vo_pos_x/5).toFixed(2);
					vo_pos_y = (vo_pos_y/5).toFixed(2);
					vo_pos_w = (vo_pos_w/5).toFixed(2);
					vo_pos_h = (vo_pos_h/5).toFixed(2);
					content += "<div style='position: absolute; \
											left: " + vo_pos_x + "px; \
											top: " + vo_pos_y + "px; \
											width: " + vo_pos_w + "px; \
											height: " + vo_pos_h + "px; \
											z-index: " + parseInt(priority+2) + "; \
											margin: 0px; \
											overflow: hidden; \
											border-radius: 4px; \
											background-color: " + bg_color[i] + ";'>\
									<span id='sub_name_" + i +"' class='sub_name'></span>\
								</div>";
				}
			}
			$("#status_layout").append(content);
		}
	});
}

function changeSysPage(sysid, id){
	var sys = $(window.parent.document).find('#' + sysid);
	if(sys.next("ul").attr("value") == "off"){
		changePage(sysid);
	}
	changePage(id);
}

function init_wifi_option() {
	wifi_exist = window.parent.get_wifi_exist();
	if (wifi_exist == 1) {
		$("#wifi_status").removeClass("display_off");
	} else if (wifi_exist == 0) {
		$("#wifi_status").addClass("display_off");
	}

	wifi_enable = window.parent.get_wifi_enable();
	if (wifi_enable == 1) {
		$("#wifi_status_info").removeClass("display_off");
	}
	else if (wifi_enable == 0) {
		$("#wifi_status_info").addClass("display_off");
	}
}

function init_g4_option() {
	g4_exist = window.parent.get_g4_exist();
	if (g4_exist == 1) {
		$("#g4_status_div").removeClass("display_off");
	} else if (g4_exist == 0) {
		$("#g4_status_div").addClass("display_off");
	}

	g4_enable = window.parent.get_g4_enable();
	if (g4_enable == 1) {
		$("#g4_status_info").removeClass("display_off");
	}
	else if (g4_enable == 0) {
		$("#g4_status_info").addClass("display_off");
	}
}

function get_status() {
	$.ajax({
		type: "GET",
		url: "http://" + xc_gethost() + "/get_status",
		dataType: "xml",
		cache: false,
		error: function () {
		},
		success: function (sxml) {
			var devicename = $(sxml).find("devicename").text();
			$('#status_devicename').html(devicename);
			// cpu usage
			var cpu_usage = $(sxml).find("cpu_usage").text();
			$('#cpu_usage').html(cpu_usage + "%");
			// cpu_temperature
			var cpu_temperature = $(sxml).find("cpu_temperature").text();
			$('#cpu_temperature').html(cpu_temperature + "℃");
			// mem usage
			var mem_free = $(sxml).find("mem_free").text();
			var mem_total = $(sxml).find("mem_total").text();
			mem_free = mem_total - mem_free;
			mem_free = parseInt(mem_free / 1000);
			mem_total = parseInt(mem_total / 1000);
			$('#mem_free').html(mem_free + "MB/" + mem_total + "MB");
			var systime = $(sxml).find("systime").text();
			$('#status_systime').html(systime);
			var runtime = $(sxml).find("runtime").text();
			$('#status_runtime').html(runtime);
			var vo = $(sxml).find("vo").text();
			$('#status_vo').html(vo);
			var wnd_num = $(sxml).find("wndnum").text();
			$('#status_wnd_num').html(wnd_num);
			var turn = $(sxml).find("turn").text();
			if (turn == "1") {
				$('#status_turn').html($.i18n.prop('index_common_enable'));
			} else {
				$('#status_turn').html($.i18n.prop('index_common_disable'));
			}
			handle_wndnum(wnd_num);
			for (var i = 0; i < wnd_num; ++i) {
				var uri_text = $(sxml).find("s" + i).find("uri").text();
				$("#status_decode_uri_display_" + i).html(uri_text);
				if (uri_text.length > 60) {
					uri_text = uri_text.substring(0, 60);
					uri_text += "...";
				}
				$("#status_decode_uri_" + i).html(uri_text);
				var current_wnd_status = $(sxml).find("s" + i).find("alive").text();
				if (current_wnd_status == "1") {
					$("#status_wnd_status_" + i).html($.i18n.prop('status_wnd_status_text_ok'));
				} else {
					$("#status_wnd_status_" + i).html($.i18n.prop('status_wnd_status_text_error'));
				}
				$("#status_wnd_fps_" + i).html($(sxml).find("s" + i).find("fps").text());
				$("#status_wnd_bps_" + i).html($(sxml).find("s" + i).find("bps").text());
				$("#status_wnd_vdecnum_" + i).html($(sxml).find("s" + i).find("vdecnum").text());
				$("#status_wnd_adecnum_" + i).html($(sxml).find("s" + i).find("adecnum").text());

				var width = $(sxml).find("s" + i).find("w").text();
				var height = $(sxml).find("s" + i).find("h").text();
				$("#status_wnd_resolution_" + i).html(width + "x" + height);
				
				$("#unable_field_" + i).addClass("display_off");
				var codecid = $(sxml).find("s" + i).find("codecid").text();
				if(codecid == "100"){
					codecid = "H.264";
				}else if(codecid == "101"){
					codecid = "H.265";
				}else if(codecid == "36"){
					codecid = "MPEG2VIDEO";
				}else if(codecid == "1002"){
					codecid = "MJPEG";
				}
				
				var field_order = $(sxml).find("s" + i).find("source_mediainfo v field_order").text();
				if(field_order == "0"){
					$("#status_wnd_type_" + i).html(codecid + " " + $.i18n.prop('status_field_order_unknown'));
				}else if(field_order == "1"){
					$("#status_wnd_type_" + i).html(codecid + " " + $.i18n.prop('status_field_order_pro'));
				}else if(field_order == "2" || field_order == "3" || field_order == "4" || field_order == "5"){
					$("#status_wnd_type_" + i).html(codecid + " " + $.i18n.prop('status_field_order_inter'));
					$("#unable_field_" + i).removeClass("display_off");
				}else if(!field_order){
					$("#status_wnd_type_" + i).html(codecid);
				}

				var acodec = $(sxml).find("s" + i).find("source_mediainfo a codec").text();
				var sample_rate = $(sxml).find("s" + i).find("source_mediainfo a sample_rate").text();
				var channels = $(sxml).find("s" + i).find("source_mediainfo a channels").text();
				if(!acodec){
					$("#audio_type_div_" + i).addClass("display_off");
				}else{
					$("#audio_type_div_" + i).removeClass("display_off");
					sample_rate = (sample_rate / 1000).toFixed(1);
					$("#status_audio_type_" + i).html(acodec + " " + sample_rate + "kHz " + channels + "Chn");
				}


				var s32FormatErr = $(sxml).find("s" + i).find("s32FormatErr").text();
				var s32PicSizeErrSet = $(sxml).find("s" + i).find("s32PicSizeErrSet").text();
				var s32StreamUnsprt = $(sxml).find("s" + i).find("s32StreamUnsprt").text();
				var s32PackErr = $(sxml).find("s" + i).find("s32PackErr").text();
				var s32PrtclNumErrSet = $(sxml).find("s" + i).find("s32PrtclNumErrSet").text();
				var s32RefErrSet = $(sxml).find("s" + i).find("s32RefErrSet").text();
				var s32PicBufSizeErrSet = $(sxml).find("s" + i).find("s32PicBufSizeErrSet").text();
				var s32VdecStreamNotRelease = $(sxml).find("s" + i).find("s32VdecStreamNotRelease").text();
	
				$("#s32FormatErr_" + i).html(s32FormatErr);
				$("#s32PicSizeErrSet_" + i).html(s32PicSizeErrSet);
				$("#s32StreamUnsprt_" + i).html(s32StreamUnsprt);
				$("#s32PackErr_" + i).html(s32PackErr);
				$("#s32PrtclNumErrSet_" + i).html(s32PrtclNumErrSet);
				$("#s32RefErrSet_" + i).html(s32RefErrSet);
				$("#s32PicBufSizeErrSet_" + i).html(s32PicBufSizeErrSet);
				$("#s32VdecStreamNotRelease_" + i).html(s32VdecStreamNotRelease);
			}
			// net status
			var net_status = $(sxml).find("net_status").text();
			if ("1" == net_status) {
				$("#status_net").html($.i18n.prop('status_net_INTERNET'));
			}
			else if ("2" == net_status) {
				$("#status_net").html($.i18n.prop('status_net_INTERNET_IP'));
			}
			else if ("3" == net_status) {
				$("#status_net").html($.i18n.prop('status_net_INTERNET_LAN'));
			}
			else if ("4" == net_status) {
				$("#status_net").html($.i18n.prop('status_net_INTERNET_LOCAL'));
			}
			else if ("5" == net_status) {
				$("#status_net").html($.i18n.prop('status_net_NOCHECK'));
			}
			else {
				$("#status_net").html($.i18n.prop('status_net_INTERNET_LOCAL'));
			}
		}
	});
	if (true) {
		$.ajax({
			type: "GET",
			url: "http://" + xc_gethost() + "/get_g4status",
			dataType: "xml",
			cache: false,
			error: function () {
			},
			success: function (data) {
				var g4_enable = $(data).find("enable").text();
				if (g4_enable == 1) {
					$('#g4_enable').html($.i18n.prop('status_wifi_dev_enable_on_text'));
				}
				else if (wifi_enable == 0) {
					$('#g4_enable').html($.i18n.prop('status_wifi_dev_enable_off_text'));
				}

				var g4_module = $(data).find("module").text();
				$('#g4_module').html(g4_module);

				var g4_provider = $(data).find("provider").text();
				$('#g4_provider').html(g4_provider);

				var g4_imei = $(data).find("imei").text();
				$('#g4_imei').html(g4_imei);

				var g4_mode = $(data).find("mode").text();
				$('#g4_mode').html(g4_mode);

				var g4_strength = $(data).find("strength").text();
				g4_strength = "-" + (119 - parseInt(g4_strength)) + "dBm";
				$('#g4_strength').html(g4_strength);

				var g4_gps = $(data).find("gps").text();
				if(g4_gps == "unknown" || g4_gps == ";;"){
					$("#g4_gps_div").hide();
				}else {
					$("#g4_gps_time").html(Getg4gpstime(g4_gps));
					$("#g4_gps_location").html(Getg4gpslocation(g4_gps));
					$("#g4_gps_height").html(Getg4gpsheight(g4_gps));
				}

				var g4_status = $(data).find("status").text();
				var err = $(data).find("cme_err").text();
				if (g4_status == "1") {
					$('#g4_status').html($.i18n.prop('status_g4_status_COMPLETED'));
				} else if (g4_status == "2") {
					$('#g4_status').html($.i18n.prop('status_g4_status_CONNECTING'));
				} else {
					if(err != "0")
					{
					$('#g4_status').html($.i18n.prop('status_g4_status_DISCONNECTED') + "(" + err + ")" );
					}
					else
					{
						$('#g4_status').html($.i18n.prop('status_g4_status_DISCONNECTED'));
					}
				}
				

				var g4_online_time = $(data).find("online_time").text();
				g4_online_time = formatSeconds(g4_online_time);
				$('#g4_online_time').html(g4_online_time);
				var g4_in_kbyte = $(data).find("in_kbyte").text() + "kbyte";
				$('#g4_in_kbyte').html(g4_in_kbyte);
				var g4_out_kbyte = $(data).find("out_kbyte").text() + "kbyte";
				$('#g4_out_kbyte').html(g4_out_kbyte);

				var g4_gateway = $(data).find("gateway").text();
				$('#g4_gateway').html(g4_gateway);

				var g4_ip = $(data).find("ip").text();
				$('#g4_ip').html(g4_ip);

			}
		});
	}
	if (wifi_exist == 1) {
		$.ajax({
			type: "GET",
			url: "http://" + xc_gethost() + "/get_wifistatus",
			dataType: "xml",
			cache: false,
			error: function () {
			},
			success: function (sxml) {
				if (wifi_enable == 1) {
					$('#status_wifi_dev_enable').html($.i18n.prop('status_wifi_dev_enable_on_text'));
				}
				else if (wifi_enable == 0) {
					$('#status_wifi_dev_enable').html($.i18n.prop('status_wifi_dev_enable_off_text'));
				}

				var wifi_status = $(sxml).find("state").text();
				var wifi_ssid = $(sxml).find("ssid").text();
				var wifi_ip = $(sxml).find("ip").text();
				var wifi_freq = $(sxml).find("freq").text();
				var wifi_level = $(sxml).find("level").text();
				var wifi_mac = $(sxml).find("mac").text();
				if (wifi_status == "COMPLETED") {
					$('#status_link_status').html($.i18n.prop('status_connected_text'));
				} else if (wifi_status == "DISCONNECTED") {
					$('#status_link_status').html($.i18n.prop('status_disconneted_text'));
				} else {
					$('#status_link_status').html($.i18n.prop('status_connecting_text'));
				}
				$('#status_wifi_essid').html(wifi_ssid);
				$('#status_wifi_ip').html(wifi_ip);
				$('#status_freq').html(wifi_freq + "MHz");
				$('#status_singal_level').html(wifi_level + "dB");
				$('#status_wifi_mac').html(wifi_mac);
			}
		});
	}
}

function formatSeconds(value) {

	var theTime = parseInt(value); // 秒

	var theTime1 = 0; // 分

	var theTime2 = 0; // 小时

	if (theTime > 60) {

		theTime1 = parseInt(theTime / 60);

		theTime = parseInt(theTime % 60);

		if (theTime1 > 60) {

			theTime2 = parseInt(theTime1 / 60);

			theTime1 = parseInt(theTime1 % 60);

		}

	}

	var result = "" + parseInt(theTime) + "s";

	if (theTime1 > 0) {

		result = "" + parseInt(theTime1) + "m" + result;

	}

	if (theTime2 > 0) {
		result = "" + parseInt(theTime2) + "h" + result;

	}
	return result;
}

function Getg4gpstime(g4_gps) {
	var gps_time = "";
	const myArray = g4_gps.split(";");
	gps_time = myArray[2];
	return gps_time;
}

function Getg4gpslocation(g4_gps) {
	var gps_location = "";
	const myArray = g4_gps.split(";");
	gps_location = myArray[0];
	return gps_location;
}

function Getg4gpsheight(g4_gps) {
	var gps_height = "";
	const myArray = g4_gps.split(";");
	gps_height = parseInt(myArray[3]) + "M";
	return gps_height;
}

function language_setup(wnd_num) {
	jQuery.i18n.properties({
		name: 'common',
		path: '../lang/',
		mode: 'map',
		language: window.parent.get_language_setup(),
		callback: function () {
			$('#status_system_status_text').html($.i18n.prop('status_system_status_text'));
			$('#status_cpu_usage_txt').html($.i18n.prop('status_cpu_usage_txt'));
			$('#status_cpu_temperature_txt').html($.i18n.prop('status_cpu_temperature_txt'));
			$('#status_mem_free_txt').html($.i18n.prop('status_mem_free_txt'));
			$('#header_text').html($.i18n.prop('index_status'));
			$('#status_devicename_text').html($.i18n.prop('status_devicename_text'));
			$('#status_runtime_text').html($.i18n.prop('status_runtime_text'));
			$('#status_systime_text').html($.i18n.prop('status_systime_text'));
			$('#status_systime_sync_text').html($.i18n.prop('status_systime_sync_text'));
			$('#status_vo_text').html($.i18n.prop('status_vo_text'));
			$('#status_wnd_num_text').html($.i18n.prop('status_wnd_num_text'));
			$('#status_turn_text').html($.i18n.prop('status_turn_text'));
			$('#status_net_text').html($.i18n.prop('status_net_text'));
			$('#status_wifi_status_text').html($.i18n.prop('status_wifi_status_text'));
			$('#status_wifi_dev_enable_text').html($.i18n.prop('status_wifi_dev_enable_text'));
			$('#status_link_status_text').html($.i18n.prop('status_link_status_text'));
			$('#status_wifi_essid_text').html($.i18n.prop('status_wifi_essid_text'));
			$('#status_wifi_ip_text').html($.i18n.prop('status_wifi_ip_text'));
			$('#status_wifi_mac_text').html($.i18n.prop('status_wifi_mac_text'));
			$('#status_freq_text').html($.i18n.prop('status_freq_text'));
			$('#status_singal_level_text').html($.i18n.prop('status_singal_level_text'));
			$('#status_layout_text').html($.i18n.prop('status_layout_text'));
			$('#status_vopos_enable_text').html($.i18n.prop('status_vopos_enable_text'));
			$("#status_layout_background_text").html($.i18n.prop('screen_background_txt'));
			for(var i = 0; i < 4; i++){
				$("#sub_name_" + i).html(($.i18n.prop('screen_sub_txt') + (i+1)));
			}
			for (var i = 0; i <= wnd_num; ++i) {
				$("#status_wnd_text_" + i).html($.i18n.prop('status_wnd_text') + (i + 1));
				$("#status_decode_uri_text_" + i).html($.i18n.prop('status_decode_uri_text'));
				$("#status_wnd_status_text_" + i).html($.i18n.prop('status_wnd_status_text'));
				$("#status_wnd_resolution_text_" + i).html($.i18n.prop('status_wnd_resolution_text'));
				$("#status_wnd_type_text_" + i).html($.i18n.prop('status_wnd_type_text'));
				$("#status_audio_type_text_" + i).html($.i18n.prop('status_audio_type_text'));
				$("#unable_field_" + i).html($.i18n.prop('status_field_order_cant'));
				$("#status_wnd_fps_text_" + i).html($.i18n.prop('status_wnd_fps_text'));
				$("#status_wnd_bps_text_" + i).html($.i18n.prop('status_wnd_bps_text'));
				$("#status_wnd_vdecnum_text_" + i).html($.i18n.prop('status_wnd_vdecnum_text'));
				$("#status_wnd_adecnum_text_" + i).html($.i18n.prop('status_wnd_adecnum_text'));
				$("#status_wnd_errorstatus_text_" + i).html($.i18n.prop('status_wnd_errorstatus_text'));
				$("#s32FormatErr_text_" + i).html($.i18n.prop('s32FormatErr_text'));
				$("#s32PicSizeErrSet_text_" + i).html($.i18n.prop('s32PicSizeErrSet_text'));
				$("#s32StreamUnsprt_text_" + i).html($.i18n.prop('s32StreamUnsprt_text'));
				$("#s32PackErr_text_" + i).html($.i18n.prop('s32PackErr_text'));
				$("#s32PrtclNumErrSet_text_" + i).html($.i18n.prop('s32PrtclNumErrSet_text'));
				$("#s32RefErrSet_text_" + i).html($.i18n.prop('s32RefErrSet_text'));
				$("#s32PicBufSizeErrSet_text_" + i).html($.i18n.prop('s32PicBufSizeErrSet_text'));
				$("#s32VdecStreamNotRelease_text_" + i).html($.i18n.prop('s32VdecStreamNotRelease_text'));
			}
			$('#g4_status_title').html($.i18n.prop('status_g4_status_title'));
			$('#g4_enable_txt').html($.i18n.prop('status_g4_enable_txt'));
			$('#g4_module_txt').html($.i18n.prop('status_g4_module_txt'));
			$('#g4_provider_txt').html($.i18n.prop('status_g4_provider_txt'));
			$('#g4_imei_txt').html($.i18n.prop('status_g4_imei_txt'));
			$('#g4_mode_txt').html($.i18n.prop('status_g4_mode_txt'));
			$('#g4_strength_txt').html($.i18n.prop('status_g4_strength_txt'));
			$('#g4_status_txt').html($.i18n.prop('status_g4_status_txt'));
			$('#g4_online_time_txt').html($.i18n.prop('status_g4_online_time_txt'));
			$('#g4_gps_time_txt').html($.i18n.prop('status_g4_gps_time_txt'));
			$('#g4_gps_location_txt').html($.i18n.prop('status_g4_gps_location_txt'));
			$('#g4_gps_height_txt').html($.i18n.prop('status_g4_gps_height_txt'));
			$('#g4_in_kbyte_txt').html($.i18n.prop('status_g4_in_kbyte_txt'));
			$('#g4_out_kbyte_txt').html($.i18n.prop('status_g4_out_kbyte_txt'));
			$('#g4_gateway_txt').html($.i18n.prop('status_g4_gateway_txt'));
			$('#g4_ip_txt').html($.i18n.prop('status_g4_ip_txt'));
		}
	});
}

function parentpage_adjust_height() {
	window.parent.setup_iframe_height();
}

function getNowFormatDate() {
	var now = new Date();
	var currenseconds = Math.round(now.getTime() / 1000);
	return currenseconds;
}

function syncTime() {
	var nowtime = getNowFormatDate();
	$.ajax({
		type: "GET",
		url: "http://" + xc_gethost() + "/set_time?sync_time=" + nowtime,
		dataType: "xml",
		cache: false,
		error: function () {
		},
		success: function (data) {
		}
	});
}

$(function () {
	init_wifi_option();
	init_g4_option();
	language_setup(g_wnd_num);
	get_status();
	setInterval(get_status, 1000);
});
