function get_g4() {
	$.ajax({
		type: "GET",
		url: "http://" + xc_gethost() + "/get_g4",
		dataType: "xml",
		cache: false,
		async: false,
		error: function () {
		},
		success: function (data) {
			var g4_switch = $(data).find("g4_enable").text();
			if (g4_switch == 1) {
				$("#g4_switch_on_txt").attr("selected", "selected");
			} else {
				$("#g4_switch_off_txt").attr("selected", "selected");
			}

			var g4_dns_order = $(data).find("g4_dns_order").text();
			if (g4_dns_order == 0) {
				$("#g4_gwasdns_enable_0").attr("selected", "selected");
			} else if (g4_dns_order == 1) {
				$("#g4_gwasdns_enable_1").attr("selected", "selected");
			} else if (g4_dns_order == 2) {
				$("#g4_gwasdns_enable_2").attr("selected", "selected");
			} else if (g4_dns_order == 3) {
				$("#g4_gwasdns_enable_3").attr("selected", "selected");
			} else {
				$("#g4_gwasdns_enable_0").attr("selected", "selected");
			}

			var g4_apn = $(data).find("g4_apn").text();
			$("#g4_apnTxt").attr("value", g4_apn);

			var g4_username = $(data).find("g4_username").text();
			$("#g4_usernameTxt").attr("value", g4_username);

			var g4_password = $(data).find("g4_password").text();
			$("#g4_passwordTxt").attr("value", g4_password);

			var g4_auth_type = $(data).find("g4_auth_type").text();
			if (g4_auth_type == 0) {
				$("#g4_auth_type_enable_0").attr("selected", "selected");
			} else if (g4_auth_type == 1) {
				$("#g4_auth_type_enable_1").attr("selected", "selected");
			} else if (g4_auth_type == 2) {
				$("#g4_auth_type_enable_2").attr("selected", "selected");
			} else if (g4_auth_type == 3) {
				$("#g4_auth_type_enable_3").attr("selected", "selected");
			} else {
				$("#g4_auth_type_enable_0").attr("selected", "selected");
			}

			var g4_simcard_id = $(data).find("g4_simcard_id").text();
			$("#g4_simcard_id").attr("value", g4_simcard_id);
		}
	});
}

function language_setup() {
	jQuery.i18n.properties({
		name: 'common',
		path: '../lang/',
		mode: 'map',
		language: window.parent.get_language_setup(),
		callback: function () {
			$('#header_text').html($.i18n.prop('g4_header_txt'));
			$('#g4_switch_txt').html($.i18n.prop('g4_switch_txt'));
			$('#g4_apn').html($.i18n.prop('g4_apn'));
			$('#g4_user').html($.i18n.prop('g4_user'));
			$('#g4_pwd').html($.i18n.prop('g4_pwd'));
			$('#g4_auth_type').html($.i18n.prop('g4_auth_type'));
			$('#g4_dns_order').html($.i18n.prop('g4_dns_order'));
			$('#g4_sim_choost').html($.i18n.prop('g4_sim_choost'));
			$('#g4_switch_on_txt').html($.i18n.prop('g4_switch_on_txt'));
			$('#g4_switch_off_txt').html($.i18n.prop('g4_switch_off_txt'));
			$('#g4_setting').val($.i18n.prop('g4_setting'));
			
		}
	});
}

function g4_set() {
	var ptmp = "";
	//
	var g4_enable = $("#g4_switch").val();
	ptmp = "g4_enable=" + g4_enable;

	var g4_apn = $("#g4_apnTxt").val();
	if (g4_apn == "") g4_apn = 0;
	ptmp += "&g4_apn=" + g4_apn;

	var g4_username = $("#g4_usernameTxt").val();
	if (g4_username == "") g4_username = 0;
	ptmp += "&g4_username=" + g4_username

	var g4_password = $("#g4_passwordTxt").val();
	if (g4_password == "") g4_password = 0;
	ptmp += "&g4_password=" + g4_password

	var g4_auth_type = $("#g4_auth_type_enable").val();
	ptmp += "&g4_auth_type=" + g4_auth_type

	var g4_dns_order = $("#g4_gwasdns_enable").val();
	ptmp += "&g4_dns_order=" + g4_dns_order;

	var g4_simcard_id = $("#g4_simcard_id").val();
	ptmp += "&g4_simcard_id=" + g4_simcard_id;

	$.ajax({
		type: "GET",
		url: "http://" + xc_gethost() + "/set_g4" + "?" + ptmp,
		cache: false,
		success: function (data) {
			var ret = $(data).find("return").text();
			if ("ok" == ret) {
				alert($.i18n.prop('g4_setting_success'));
			}
			else {
				alert($.i18n.prop('g4_setting_failed'));
			}
		},
		error: function () {
			alert($.i18n.prop('g4_setting_failed'));
		}
	});
}

$(function () {
	language_setup();
	get_g4();
})