Wireless.prototype._IsExistWirelessDevice_ = function()
{
	var ssocket = io.connect();
	ssocket.emit('IsExistWirelessDevice');
	ssocket.on('IsExistWirelessDevice', function (Return) {
		if(Return==true)
		{
			Wireless.prototype._LoadWirelessWebUi_();
			ssocket.emit('GetWirelessInformation');
			ssocket.on('GetWirelessInformation', function (Return)
			{
				if(Return.length >0)
				{
					Wireless.prototype._UpdateWirelessInformation_(Return);
				}
			});
			Wireless.prototype._ShowWirelessWebUi_();
			Wireless.prototype._MonitorWirelessInformation_();
		}
		$("#Main_Center-Content").find(".Body").show();
		$("#Main_Center-Content").find(".Body").eq(0).hide();
		Wireless.prototype._SimCardKillCount_();
		ssocket.emit("SocketClose");
	});
};

Wireless.prototype._IsUsedNetworkSetting_ = function()
{
	var Return=true;
	if(!($("#Top-Menu-SystemSetting").css("border-bottom-color") == "rgb(57, 93, 139)" &&
		 $("#Left-List-NetworkSetting").css("border-left-color") == "rgb(57, 93, 139)"))
	{
		Return=false;
	}
	return Return;
}

Wireless.prototype._LoadWirelessWebUi_ = function()
{
	var Class = new LoadHtml();
	var Html = Class.ReadTranslateAfterOfHtml("./Plugin/NetworkSetting/html/Wireless.html");	
	$("#Main_Center-Content").append(Html);
};

Wireless.prototype._GetWirelessWebUiData_ = function()
{
	var AutomaticConnection=$("#Wireless").find(".Row").eq(3).find(":checkbox").prop("checked");
	var DialUpNumber       =$("#Wireless").find(".Row").eq(4).find(".Text").val();
	var APN                =$("#Wireless").find(".Row").eq(5).find(".Text").val();
	var Username           =$("#Wireless").find(".Row").eq(6).find(".Text").eq(0).val();
	var Password           =$("#Wireless").find(".Row").eq(6).find(".Text").eq(1).val();
	var MobileCodeEnable   =$("#Wireless").find(".Row").eq(7).find(":checkbox").prop("checked");
	var MCC                =$("#Wireless").find(".Row").eq(7).find(".Text").eq(0).val();
	var MNC                =$("#Wireless").find(".Row").eq(7).find(".Text").eq(1).val();
	return new Array(AutomaticConnection, DialUpNumber, APN, Username, Password, MobileCodeEnable, MCC, MNC);
};

Wireless.prototype._ShowWirelessWebUi_ = function()
{
	var ssocket = io.connect();
	ssocket.emit('GetWirelessData');
	ssocket.on('GetWirelessData', function (Return) {
		if(Return.length > 0){
			var Data=new Object();
			Data["AutomaticConnection"]=Return[0];
			Data["DialUpNumber"]       =Return[1];
			Data["APN"]                =Return[2];
			Data["Username"]           =Return[3];
			Data["Password"]           =Return[4];
			Data["MobileCodeEnable"]   =Return[5];
			Data["MCC"]                =Return[6];
			Data["MNC"]                =Return[7];
			Wireless.prototype._SetWirelessWebUiData_(Data);
		}
		ssocket.emit("SocketClose");
	});
};

Wireless.prototype._ShowSignalStrength_ = function(SignalStrength)
{
	if(SignalStrength == null)	{return 0;}
	
	$("#Wireless").find(".Row").eq(0).find(".SignalGrid").css("background-color", "#F8F8F8");
	if(SignalStrength == 99 || SignalStrength == 199)	{return 0;}

	var SignalGridQuantity=0, dBm=0;
	if(SignalStrength < 100)
	{
		SignalGridQuantity=parseInt((SignalStrength*5)/32);
		dBm=(-113+SignalStrength*2);
	}
	else
	{
		SignalGridQuantity=parseInt(((SignalStrength-100)*5)/92);
		dBm=(-216+SignalStrength);
	}
	
	for(var i=0; i<=SignalGridQuantity; i++)
	{
		$("#Wireless").find(".Row").eq(0).find(".SignalGrid").eq(i).css("background-color", "#395D8B");
	}
	$("#Wireless").find(".Row").eq(0).find(".Text").eq(0).text(dBm);
}

Wireless.prototype._SetWirelessWebUiData_ = function(Data)
{
	$("#Wireless").find(".Row").eq(3).find(":checkbox").prop("checked", Data["AutomaticConnection"]);
	$("#Wireless").find(".Row").eq(4).find(".Text").val(Data["DialUpNumber"]);
	$("#Wireless").find(".Row").eq(5).find(".Text").val(Data["APN"]);
	$("#Wireless").find(".Row").eq(6).find(".Text").eq(0).val(Data["Username"]);
	$("#Wireless").find(".Row").eq(6).find(".Text").eq(1).val(Data["Password"]);
	$("#Wireless").find(".Row").eq(7).find(":checkbox").prop("checked", Data["MobileCodeEnable"]);
	
	$("#Wireless").find(".Row").eq(7).find(".Text").eq(0).val(Data["MCC"]);
	$("#Wireless").find(".Row").eq(7).find(".Text").eq(1).val(Data["MNC"]);
	Wireless.prototype._ChangeMobileCodeEnable_($("#MobileCode"));
};

Wireless.prototype._Disconnect_ = function(that)
{
	$(that).closest('.Row').find(".Message").hide();
	$(that).closest(".LeftColumn").find(".Loading").show();
	var ssocket = io.connect();
	ssocket.emit('WirelessDisconnect');
	ssocket.on('WirelessDisconnect', function (Return) {
		if(Return==true)
		{
			$(that).closest(".LeftColumn").find(".Message").eq(0).show();
		}
		else
		{
			$(that).closest(".LeftColumn").find(".Message").eq(1).show();
		}
		$(that).closest(".LeftColumn").find(".Loading").hide();
		ssocket.emit("SocketClose");
	});
};

Wireless.prototype._Connection_ = function(that)
{
	var ssocket = io.connect();
	ssocket.emit('WirelessConnection');
	ssocket.on('WirelessConnection', function (Return) {
		if(Return==true)
		{
			$(that).closest(".LeftColumn").find(".Message").eq(0).show();
		}
		else
		{
			$(that).closest(".LeftColumn").find(".Message").eq(2).show();
		}
		$(that).closest(".LeftColumn").find(".Loading").hide();
		ssocket.emit("SocketClose");
	});
};

Wireless.prototype._SaveWirelessData_ = function(that)
{
	$(that).closest('.Row').find(".Message").hide();
	var MessageError = $("#Wireless").find(".Message").is(":visible");
	if(MessageError == true){
		$(that).closest(".LeftColumn").find(".Message").eq(1).show();
		return 0;
	}
	$(that).closest(".LeftColumn").find(".Loading").show();
	var ssocket = io.connect();
	var array=Wireless.prototype._GetWirelessWebUiData_();
	ssocket.emit('SaveWirelessData', array);
	ssocket.on('SaveWirelessData', function (Return) {
		if(Return==true)
		{
			Wireless.prototype._Connection_(that);
		}
		else{
			$(that).closest(".LeftColumn").find(".Message").eq(2).show();
			$(that).closest(".LeftColumn").find(".Loading").hide();
		}
		ssocket.emit("SocketClose");
	});
};

Wireless.prototype._MonitorWirelessInformation_ = function()
{
	var ssocket = io.connect();
	var TimeSetInterval = setInterval(function()
	{
		if(Wireless.prototype._IsUsedNetworkSetting_() == false)
		{
			ssocket.emit("SocketClose");
			clearInterval(TimeSetInterval);
			return 0;
		}
		else if($("#WirelessButtonForm").find(".LeftColumn").eq(1).find(".Loading").is(":visible") == true)
		{
			Wireless.prototype._UpdateWirelessInformation_(new Array(null, "Disconnected", ""));
			return 0;
		}
		ssocket.emit('GetWirelessInformation');
		ssocket.on('GetWirelessInformation', function (Return)
		{
			if(Return.length >0)
			{
				Wireless.prototype._UpdateWirelessInformation_(Return);
			}
		});
	}, 2000);
}

Wireless.prototype._UpdateWirelessInformation_ = function(Data)
{
	$("#Wireless").find(".Row").eq(1).find(".ConnectionStatus").hide();
	$("#Wireless").find(".Row").eq(1).find(".Loading").hide();
	Wireless.prototype._ShowSignalStrength_(Data[0]);
	$("#PinFrom").find(".PinRow").eq(0).find(".SimConnectionStatus").hide();
	if(Data[3] == "PIN"){
		Wireless.prototype._OpenPinCloseSetting_();
		$("#PinFrom").find(".PinRow").eq(0).find(".SimConnectionStatus").eq(2).show();
	}
	else if(Data[3] == "Kill"){
		Wireless.prototype._ClosePinCloseSetting_();
		$("#PinFrom").find(".PinRow").eq(0).find(".SimConnectionStatus").eq(1).show();
	}
	else if(Data[1] == "Connected"){
		Wireless.prototype._OpenSettingClosePin_();
		$("#PinFrom").find(".PinRow").eq(0).find(".SimConnectionStatus").eq(2).show();
		$("#Wireless").find(".Row").eq(1).find(".ConnectionStatus").eq(0).show();
	}
	else if(Data[1] == "Disconnected"){
		Wireless.prototype._OpenSettingClosePin_();
		$("#PinFrom").find(".PinRow").eq(0).find(".SimConnectionStatus").eq(2).show();
		$("#Wireless").find(".Row").eq(1).find(".ConnectionStatus").eq(1).show();
	}
	else if(Data[1] == "SimDisconnected"){
		Wireless.prototype._ClosePinCloseSetting_();
		$("#PinFrom").find(".PinRow").eq(0).find(".SimConnectionStatus").eq(0).show();
	}
	$("#Wireless").find(".Row").eq(2).find(".RightColumn").text(Data[2]);
}

Wireless.prototype._CheckDialUpNumber_ = function(that)
{
	$(that).closest(".Row").find(".Message").hide();
	var DialUpNumber=$(that).val();
	if(DialUpNumber == "")
	{
		$(that).closest(".Row").find(".Message").eq(0).show();
	}
};

Wireless.prototype._CheckAPN_ = function(that)
{
	$(that).closest(".Row").find(".Message").hide();
	var APN=$(that).val();
	if(APN == "")
	{
		$(that).closest(".Row").find(".Message").eq(0).show();
	}
};

Wireless.prototype._CheckUsername_ = function(that)
{
	$(that).closest("tr").find(".Message").hide();
	var Username=$(that).val();
	if(Username == "")
	{
		$(that).closest("tr").find(".Message").eq(0).show();
	}
};

Wireless.prototype._CheckPassword_ = function(that)
{
	$(that).closest("tr").find(".Message").hide();
	var Password=$(that).val();
	if(Password == "")
	{
		$(that).closest("tr").find(".Message").eq(0).show();
	}
};

Wireless.prototype._CheckMCC_ = function(that)
{
	$(that).closest("tr").find(".Message").hide();
	var MCC=$(that).val();
	if(MCC == "" || MCC.length > 3)
	{
		$(that).closest("tr").find(".Message").eq(0).show();
	}
};

Wireless.prototype._CheckMNC_ = function(that)
{
	$(that).closest("tr").find(".Message").hide();
	var MNC=$(that).val();
	if(MNC == "" || MNC.length > 3)
	{
		$(that).closest("tr").find(".Message").eq(0).show();
	}
};

Wireless.prototype._ChangeMobileCodeEnable_ = function(that)
{
	var MobileCodeEnable = $(that).prop("checked");
	if(MobileCodeEnable == true)
	{
		$(that).closest(".Row").find("table").show();
		$(that).closest(".Row").find(".Link").show();
	}
	else
	{
		$(that).closest(".Row").find("table").hide();
		$(that).closest(".Row").find(".Link").hide();
	}
};
Wireless.prototype._SimCardConnect_ = function(that)
{
	Wireless.prototype._CheckPIN_();
	var MessageError = $("#PinFrom").find(".PinRow").eq(1).find(".Message").eq(0).is(":visible");
	if(MessageError == true){
		return 0;
	}
	else{
		$("#PinFrom").find(".PinRow").eq(1).find(".Message").eq(0).hide();
	}
	var PinPassword = $("#PinFrom").find(".PinRow").eq(1).find(".Text").val();
	var KillCount = $(".PinMessage").eq(1).text();
	if(KillCount != 0){
		KillCount = KillCount - 1;
		$(".PinMessage").eq(1).text(KillCount);
		var Result = {"Input":null};
		var array = new Array(PinPassword, KillCount);
		var Class = new Transmission();
		Class.TransmissionArray("InputSimCardPassword", array, Result);
		var SetInterval = setInterval(function()
		{
			if(Result["Input"]!=null){
				if(Result["Input"][0]=="Pass"){
					Wireless.prototype._OpenSettingClosePin_();
				}
				if(KillCount==0 && Result["Input"][0]=="Fail"){
					Wireless.prototype._ClosePinCloseSetting_();
					$("#PinFrom").find(".PinRow").eq(0).find(".SimConnectionStatus").hide();
					$("#PinFrom").find(".PinRow").eq(0).find(".SimConnectionStatus").eq(1).show();
				}
				Class = null; delete Class;
				clearInterval(SetInterval);
			}
			$("#PinFrom").find(".PinRow").eq(1).find(".Button").css('pointer-events', "visible");
		}, 500);
	}
}

Wireless.prototype._SimCardKillCount_ = function(that)
{
	var Result = {"Input":null};
	var array = new Array("3");
	var Class = new Transmission();
	Class.TransmissionArray("KillCount", array, Result);
	var SetInterval = setInterval(function()
	{
		if(Result["Input"]!=null)
		{
			var KillCount = Result["Input"].split(",")[1]
			$(".PinMessage").eq(1).text(KillCount);
			Class = null; delete Class;
			clearInterval(SetInterval);
		}
	},500);
}


Wireless.prototype._CheckPIN_ = function(that)
{
	$("#PinFrom").find(".PinRow").eq(1).find(".Message").hide();
	var MNC = $("#PinFrom").find(".PinRow").eq(1).find(".Text").val();
	if(MNC == "" || MNC.length < 4 || MNC.length > 8)
	{
		$("#PinFrom").find(".PinRow").eq(1).find(".Message").show();
	}
	for(var i=0;i<MNC.length;i++)
	{
		if(MNC[i] < '0' || MNC[i] > '9')
		{
			$("#PinFrom").find(".PinRow").eq(1).find(".Message").show();
		}
	}
};
Wireless.prototype._OpenPinCloseSetting_ = function(that)
{
	$("#PinFrom").css('pointer-events', "visible");
	$("#PinFrom").css('opacity', 1);
	
	$("#Wireless").css('pointer-events', "none");
	$("#Wireless").css('opacity', 0.5);
	$("#WirelessButtonForm").css('pointer-events', "none");
	$("#WirelessButtonForm").css('opacity', 0.5);
}
Wireless.prototype._OpenSettingClosePin_ = function(that)
{
	$("#PinFrom").css('pointer-events', "none");
	$("#PinFrom").css('opacity', 0.5);
	
	$("#Wireless").css('pointer-events', "visible");
	$("#Wireless").css('opacity', 1);
	$("#WirelessButtonForm").css('pointer-events', "visible");
	$("#WirelessButtonForm").css('opacity', 1);
}
Wireless.prototype._ClosePinCloseSetting_ = function(that)
{
	$("#PinFrom").css('pointer-events', "none");
	$("#PinFrom").css('opacity', 0.5);
	
	$("#Wireless").css('pointer-events', "none");
	$("#Wireless").css('opacity', 0.5);
	$("#WirelessButtonForm").css('pointer-events', "none");
	$("#WirelessButtonForm").css('opacity', 0.5);
}