IoTstar.prototype._CheckIP_ = function(that)
{
	$(that).closest(".Row").find(".Message").hide();
	if($(that).val() == "")
	{
		$(that).closest(".Row").find(".Message").show();
		return 0;
	}
};

IoTstar.prototype._CheckPort_ = function(that)
{
	var Port = $(that).val();
	Port = parseInt(Port);
	if(!(Port > 0))
	{
		Port = 80;
	}
	$(that).val(Port);
};

IoTstar.prototype._CheckAccount_ = function(that)
{
	$(that).closest(".Row").find(".Message").hide();
	var Account = $(that).val();
	if(Account == "")
	{
		$(that).closest(".Row").find(".Message").eq(0).show();
	}
	else if(Account.length > 16)
	{
		$(that).closest(".Row").find(".Message").eq(1).show();
	}
};

IoTstar.prototype._CheckPassword_ = function(that)
{
	$(that).closest(".Row").find(".Message").hide();
	var Password = $(that).val();
	if(Password == "")
	{
		$(that).closest(".Row").find(".Message").eq(0).show();
	}
	else if(Password.length > 16)
	{
		$(that).closest(".Row").find(".Message").eq(1).show();
	}
};

IoTstar.prototype._CheckNickname_ = function(that)
{
	$(that).closest(".Row").find(".Message").hide();
	if($(that).val() == "")
	{
		$(that).closest(".Row").find(".Message").show();
		return 0;
	}
};

IoTstar.prototype._CheckDeviceName_ = function(that)
{
	var Class = new Type();
	$(that).closest(".Row").find(".Message").hide();
	var DeviceName = $(that).val();
	if(Class.CheckChineseLanguage(DeviceName) == true)
	{
		$(that).closest(".Row").find(".Message").eq(0).show();
		return 0;
	}
	else if(DeviceName.length > 16)
	{
		$(that).closest(".Row").find(".Message").eq(1).show();
		return 0;
	}
};

IoTstar.prototype._AllDataIsCorrect_ = function()
{
	var Return = true;
	var Form = $("#Main_Center-Content").find(".Form").eq(0);
	var length = Form.find(".Row").length;
	for(var i=0; i<length; i++)
	{
		var Message = Form.find(".Row").eq(i).find(".Message");
		for(var j=0; j<Message.length; j++)
		{
			var ShowMessage = Form.find(".Row").eq(i).find(".Message").eq(j).is(":visible");
			if(ShowMessage == true)
			{
				Return = false;
			}
		}
	}
	return Return;
}

IoTstar.prototype._Collect_IoTstar_Data_ = function()
{
	var Form = $("#Main_Center-Content").find(".Form").eq(0);

	var IP = Form.find(".Row").eq(0).find(".Text").val();
	var Port = Form.find(".Row").eq(1).find(".Text").val();
	var Account = Form.find(".Row").eq(2).find(".Text").val();
	var Password = Form.find(".Row").eq(3).find(".Text").val();
	var Nickname = Form.find(".Row").eq(4).find(".Text").val();
	var DeviceName = Form.find(".Row").eq(5).find(".Text").val();
	var Return = new Array(IP, Port, Account, Password, Nickname, DeviceName);
	return Return;
}

IoTstar.prototype._Transmission_IoTstar_Data_ = function(that, array)
{
	setTimeout(function()
	{
		var Form = $("#Main_Center-Content").find(".Form").eq(1);
		var Class = new Cgi();
		var Return = Class.RestApi("SaveIoTstarSetting", array, false);
		if(Return == true)
		{
			Form.find(".Loading").hide();
			Form.find(".Message").eq(0).show();
		}
		else if(Return == false)
		{
			Form.find(".Loading").hide();
			Form.find(".Message").eq(1).show();
		}
	},500);
}

IoTstar.prototype._SaveData_ = function(that)
{
	$(that).closest('.Row').find(".Message").hide();
	$(that).closest('.Row').find(".Loading").show();
	if(IoTstar.prototype._AllDataIsCorrect_() == false)
	{
		$(that).closest('.Row').find(".Loading").hide();
		$(that).closest('.Row').find(".Message").eq(2).show();
		return 0;
	}
	var array = IoTstar.prototype._Collect_IoTstar_Data_();
	IoTstar.prototype._Transmission_IoTstar_Data_(that, array);
};

IoTstar.prototype._GetUiData_ = function(FilePath)
{
	var Class = new LoadFile();
	var Return = Class.ReadFile(FilePath);
	var Value = Return.replace("<ServerIP>", "").replace("</ServerIP>", "")
	                  .replace("<Port>", "").replace("</Port>", "")
	                  .replace("<Account>", "").replace("</Account>", "")
	                  .replace("<Password>", "").replace("</Password>", "")
	                  .replace("<Nickname>", "").replace("</Nickname>", "")
	                  .replace("<DeviceName>", "").replace("</DeviceName>", "")
	                  .replace("\r", "").split("\n");
	return Value;
};

IoTstar.prototype._ShowUi_ = function()
{
	var array = IoTstar.prototype._GetUiData_("./File/IoT_Platform/IoTstarConfigure");
	$("#Main_Center-Content").find(".Form").eq(0).find(".Row").eq(0).find(".Text").val(array[0]);
	$("#Main_Center-Content").find(".Form").eq(0).find(".Row").eq(1).find(".Text").val(array[1]);
	$("#Main_Center-Content").find(".Form").eq(0).find(".Row").eq(2).find(".Text").val(array[2]);
	$("#Main_Center-Content").find(".Form").eq(0).find(".Row").eq(3).find(".Text").val(array[3]);
	$("#Main_Center-Content").find(".Form").eq(0).find(".Row").eq(4).find(".Text").val(array[4]);
	$("#Main_Center-Content").find(".Form").eq(0).find(".Row").eq(5).find(".Text").val(array[5]);
	IoTstar.prototype._GetIoTstarStatus_();
};

IoTstar.prototype._StartIoTstar_ = function(that)
{
	var Message = $(that).closest(".Row").find(".Message");
	Message.show();
	var Radio = $(that).closest(".Row").find(":radio");
	Radio.attr("checked", false);
	setTimeout(function()
	{
		var Class = new Cgi();
		var Return = Class.RestApi("StartIoTstar", new Array(), false);
		if(Return == true)
		{
			Radio.get(0).checked=true;
			Message.hide();
		}
	},500);
};

IoTstar.prototype._StopIoTstar_ = function(that)
{
	var Message = $(that).closest(".Row").find(".Message");
	Message.show();
	var Radio = $(that).closest(".Row").find(":radio");
	Radio.attr("checked", false);
	setTimeout(function()
	{
		var Class = new Cgi();
		var Return = Class.RestApi("StopIoTstar", new Array(), false);
		if(Return == true)
		{
			Radio.get(1).checked=true;
			Message.hide();
		}
	},500);
};

IoTstar.prototype._GetIoTstarStatus_ = function()
{
	var Radio = $("#Main_Center-Content").find(".Form").eq(2).find(".Row").find(":radio");
	var Class = new Cgi();
	var Return = Class.RestApi("GetIoTstarStatus", new Array(), false);
	if(Return == true)
	{
		Radio.get(0).checked=true;
	}
	else if(Return == false)
	{
		Radio.get(1).checked=true;
	}
};