Login.prototype._CheckSignInStatus_ = function()
{
	if(location.hostname.indexOf("iotstardemo.icpdas.com") != -1)
	{
		return false;
	}
	var Return;
	var Class = new Cgi();
	var LoginStatus = Class.LoginStatus("Check", false);
	if(LoginStatus == true)       {Return = true;}
	else if(LoginStatus == false) {Return = false;}
	return Return;
}

Login.prototype._GenerateSignInCredentials_ = function()
{
	var Return;
	var Class = new Cgi();
	var LoginStatus = Class.LoginStatus("Generate", true);
}

Login.prototype._GenerateLoginCredentials_ = function()
{
	var Class = new Cgi();
	var Return = Class.RestApi("GenerateLoginCredentials", new Array(), true);
};

Login.prototype._English_ = function(span, button, error)
{
	span.eq(0).text("Username：");
	span.eq(1).text("Password：");
	span.eq(2).text("Language：");
	button.eq(0).val("Login");
	error.eq(0).text("Please confirm the account password.");
	error.eq(1).text("Customer is using.");
}

Login.prototype._TraditionalChinese_ = function(span, button, error)
{
	span.eq(0).text("帳號：");
	span.eq(1).text("密碼：");
	span.eq(2).text("語系：");
	button.eq(0).val("登入");
	error.eq(0).text("請確認帳號密碼。");
	error.eq(1).text("客戶正在使用中。");
}

Login.prototype._SimplifiedChinese_ = function(span, button, error)
{
	span.eq(0).text("帐号：");
	span.eq(1).text("密码：");
	span.eq(2).text("语言：");
	button.eq(0).val("登录");
	error.eq(0).text("请确认帐号密码。");
	error.eq(1).text("客户正使用中。");
}

Login.prototype._SaveLanguage_ = function()
{
	var Language = new Array($("select").val());
	var Class = new Cgi();
	var Return = {Input:null};
	Class.RestApi("SaveLanguage", Language, true, Return);
	var SetInterval = setInterval(function()
	{
		if(Return["Input"] == true)
		{
			location.href = "./Main.html";
			clearInterval(SetInterval);
		}
	},500);
};

Login.prototype._ChangeLanguage_ = function()
{
	var span = $(".Login-Right-Div .LeftColumn");
	var button = $(".Login-Right-Div .Button");
	var error = $(".Login-Right-Div .Message");
	if($("select").val() == "English")
	{
		Login.prototype._English_(span, button, error);
	}
	else if($("select").val() == "TraditionalChinese")
	{
		Login.prototype._TraditionalChinese_(span, button, error);
	}
	else if($("select").val() == "SimplifiedChinese")
	{
		Login.prototype._SimplifiedChinese_(span, button, error);
	}
};

Login.prototype._CheckAccountPassword_ = function()
{
	var Account = $(".Login-Right-Div :text").val();
	var Password = $(".Login-Right-Div :password").val();
	var key;
	var Class = new Cgi();
	var Class_1 = new Communication();
	var Return = {Input:null};
	var key_256 = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
               16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28,
               29, 30, 31];

	Account = Class_1.PacketEncryption(Account, key_256);
	Password = Class_1.PacketEncryption(Password, key_256);

	Class.RestApi("CheckAccountPassword", new Array(Account, Password), true, Return);
	var SetInterval = setInterval(function(){
		if(Return["Input"] == true)
		{
			Login.prototype._GenerateLoginCredentials_();
			Login.prototype._GenerateSignInCredentials_();
			Login.prototype._SaveLanguage_();
			clearInterval(SetInterval);
		}
		else if(Return["Input"] == false)
		{
			$(".Login-Right-Div .Loading").hide();
			$(".Login-Right-Div .Message").eq(0).show();
			clearInterval(SetInterval);
		}
	},500);
};

Login.prototype._CheckBrowserVersion_ = function()
{
	$("body").hide();
	var userAgent = window.navigator.userAgent.toLowerCase();
	var version = $.browser.version;
	
	version=parseInt(version);
	if(version < 11)
	{
		document.write("The browser version is too old, please do the update.");
		document.write("Or use other browsers.");
		return 0;
	}
	$("body").show();
};

Login.prototype._LoadRightHtml_ = function(HtmlPath)
{
	var Class = new LoadHtml();
	var Html = {Input:null};
	Class.ReadHtml(HtmlPath, Html);
	var SetInterval = setInterval(function()
	{
		if(Html["Input"] != null)
		{
			$(".Login-Right-Div").append(Html["Input"]);
			Class = null;  delete Class;
			clearInterval(SetInterval);
		}
	},500);
};

Login.prototype._LoadLeftHtml_ = function(HtmlPath)
{
	var Class = new LoadHtml();
	var Html = {Input:null};
	Class.ReadHtml(HtmlPath, Html);
	var SetInterval = setInterval(function()
	{
		if(Html["Input"] != null)
		{
			$(".Login-Left-Div").append(Html["Input"]);
			Class = null;  delete Class;
			clearInterval(SetInterval);
		}
	},500);
};

Login.prototype._LoadLanguage_ = function(HtmlPath)
{
	var Class = new LoadHtml();
	var Text = {Input:null};
	Class.ReadHtml(HtmlPath, Text);
	var SetInterval = setInterval(function()
	{
		if(Text["Input"] != null)
		{
			$("select").val(Text["Input"]);
			Login.prototype._ChangeLanguage_();
			if($("select").val() == Text["Input"])
			{	
				Class = null;  delete Class;
				clearInterval(SetInterval);
			}
		}
	},500);
};

Login.prototype._LoginMain_ = function()
{
	$(".Login-Right-Div .Message").hide();
	$(".Login-Right-Div .Loading").show();

	var SetInterval = setInterval(function()
	{
		if(Login.prototype._CheckSignInStatus_() == true)
		{
			$(".Login-Right-Div .Loading").hide();
			$(".Login-Right-Div .Message").eq(1).show();
			clearInterval(SetInterval);
			return 0;
		}
		Login.prototype._CheckAccountPassword_();
		clearInterval(SetInterval);
	},500);
};