


function Login()
{
	this.loginFields = document.getElementById("login_fields");

	this.button = document.getElementById("login_button");
	this.registerButton = document.getElementById("register_button");

	this.usernameField = document.getElementById("username_field");
	this.passwordField = document.getElementById("password_field");
	
	YAHOO.util.Event.addListener(this.button, "mouseover", this.mouseOverButton, this, true);
	YAHOO.util.Event.addListener(this.button, "mouseout", this.mouseOutButton, this, true);
	YAHOO.util.Event.addListener(this.button, "mousedown", this.pressButton, this, true);
	YAHOO.util.Event.addListener(this.button, "keydown", this.pressButton, this, true);
	YAHOO.util.Event.addListener(this.button, "mouseup", this.depressButton, this, true);
	YAHOO.util.Event.addListener(this.button, "keyup", this.depressButton, this, true);
	YAHOO.util.Event.addListener(this.button, "click", this.clickButton, this, true);
	
	YAHOO.util.Event.addListener(this.registerButton, "mouseover", this.mouseOverRegister, this, true);
	YAHOO.util.Event.addListener(this.registerButton, "mouseout", this.mouseOutRegister, this, true);
	YAHOO.util.Event.addListener(this.registerButton, "mousedown", this.pressRegister, this, true);
	YAHOO.util.Event.addListener(this.registerButton, "keydown", this.pressRegister, this, true);
	YAHOO.util.Event.addListener(this.registerButton, "mouseup", this.depressRegister, this, true);
	YAHOO.util.Event.addListener(this.registerButton, "keyup", this.depressRegister, this, true);
	YAHOO.util.Event.addListener(this.registerButton, "click", this.clickRegister, this, true);
	
	YAHOO.util.Event.addListener(this.usernameField, "focus", this.focusUsername, this, true);
	YAHOO.util.Event.addListener(this.usernameField, "blur", this.blurUsername, this, true);
	YAHOO.util.Event.addListener(this.passwordField, "focus", this.focusPassword, this, true);
	YAHOO.util.Event.addListener(this.passwordField, "blur", this.blurPassword, this, true);
	
	if (this.usernameField.value.length <= 0 || this.usernameField.value == "username")
	{
		this.usernameField.value = "username";
		this.usernameField.style.color = "rgb(100, 100, 100)";
	}
	
	var newPasswordField = document.createElement("input");
	newPasswordField.id="password_field";
	YAHOO.util.Dom.addClass(newPasswordField, "login_field");
	
	newPasswordField.value = "password";
	newPasswordField.style.color = "rgb(100, 100, 100)";
	newPasswordField.type = "text";
	newPasswordField.tabIndex = 2;
	newPasswordField.name = "password";
	
	YAHOO.util.Event.removeListener(this.passwordField);
	this.loginFields.replaceChild(newPasswordField, this.passwordField);
	this.passwordField = newPasswordField;
	YAHOO.util.Event.addListener(this.passwordField, "focus", this.focusPassword, this, true);
	YAHOO.util.Event.addListener(this.passwordField, "blur", this.blurPassword, this, true);
}

Login.prototype.mouseOverButton = function()
{
	this.button.style.backgroundPosition = "-302px 0px";
}

Login.prototype.mouseOutButton = function()
{
	this.button.style.backgroundPosition = "0px 0px";
}

Login.prototype.pressButton = function(event)
{
	if (event.keyCode)
	{
		if (event.keyCode != 13 && event.keyCode != 32)
		{
			return;
		}
	}
	
	this.button.style.backgroundPosition = "-604px 0px";
}

Login.prototype.depressButton = function(event)
{
	if (event.keyCode)
	{
		if (event.keyCode != 13 && event.keyCode != 32)
		{
			return;
		}
		
		this.clickButton();
	}
	
	this.button.style.backgroundPosition = "-302px 0px";
}

Login.prototype.clickButton = function()
{
	document.login.submit();
}


Login.prototype.mouseOverRegister = function()
{
	this.registerButton.style.backgroundPosition = "-257px 0px";
}

Login.prototype.mouseOutRegister = function()
{
	this.registerButton.style.backgroundPosition = "0px 0px";
}

Login.prototype.pressRegister = function(event)
{
	if (event.keyCode)
	{
		if (event.keyCode != 13 && event.keyCode != 32)
		{
			return;
		}
	}
	
	this.registerButton.style.backgroundPosition = "-514px 0px";
}

Login.prototype.depressRegister = function(event)
{
	if (event.keyCode)
	{
		if (event.keyCode != 13 && event.keyCode != 32)
		{
			return;
		}
		
		this.clickRegister();
	}
	this.registerButton.style.backgroundPosition = "-257px 0px";
}

Login.prototype.clickRegister = function()
{
	window.location = "https://account.legacyofwarriors.com/account/register.php";
}


Login.prototype.focusUsername = function()
{
	if (this.usernameField.value == "username")
	{
		this.usernameField.value = "";
		this.usernameField.style.color = "";
	}
}

Login.prototype.blurUsername = function()
{
	if (this.usernameField.value == "")
	{
		this.usernameField.value = "username";
		this.usernameField.style.color = "rgb(100, 100, 100)";
	}
}

Login.prototype.focusPassword = function()
{
	if (this.passwordField.value == "password")
	{
		var newPasswordField = document.createElement("input");
		newPasswordField.id="password_field";
		YAHOO.util.Dom.addClass(newPasswordField, "login_field");
		
		newPasswordField.value = "";
		newPasswordField.style.color = "";
		newPasswordField.type = "password";
		newPasswordField.tabIndex = 2;
		newPasswordField.name = "password";
		
		YAHOO.util.Event.removeListener(this.passwordField);
		this.loginFields.replaceChild(newPasswordField, this.passwordField);
		this.passwordField = newPasswordField;
		YAHOO.util.Event.addListener(this.passwordField, "focus", this.focusPassword, this, true);
		YAHOO.util.Event.addListener(this.passwordField, "blur", this.blurPassword, this, true);

		setTimeout(focusPasswordField, 0);
	}
}

Login.prototype.blurPassword = function()
{
	if (this.passwordField.value == "")
	{
		var newPasswordField = document.createElement("input");
		newPasswordField.id="password_field";
		YAHOO.util.Dom.addClass(newPasswordField, "login_field");
		
		newPasswordField.value = "password";
		newPasswordField.style.color = "rgb(100, 100, 100)";
		newPasswordField.type = "text";
		newPasswordField.tabIndex = 2;
		
		YAHOO.util.Event.removeListener(this.passwordField);
		this.loginFields.replaceChild(newPasswordField, this.passwordField);
		this.passwordField = newPasswordField;
		YAHOO.util.Event.addListener(this.passwordField, "focus", this.focusPassword, this, true);
		YAHOO.util.Event.addListener(this.passwordField, "blur", this.blurPassword, this, true);
	}
}

function focusPasswordField()
{
	login.passwordField.focus();
}

function initializeHome()
{
	login = new Login();
}

login = null;

YAHOO.util.Event.onDOMReady(initializeHome);