var Login = Class.create({
	/**
	 * @construct
	 */
	initialize: function()
	{
		if (!Prototype.Browser.IE) {
			$("popup").up().remove();
		}

		$("login").getInputs().each(function(input) {
			if (input.type == "text" || input.type == "password") {
				input.observe("keyup", function(ev) {
					ev = !ev ? window.event : ev;

					if (ev.keyCode == Event.KEY_RETURN) {
						this.checkEnterEvent();
					}
				}.bind(this));
			}
		}.bind(this));
	},

	/**
	 *
	 */
	checkEnterEvent: function()
	{
		var first_focus = false;
		var all_fields_filled = true;

		$("login").getInputs().each(function(input) {
			if ((input.type == "text" || input.type == "password") && input.value == "") {
				all_fields_filled = false;
			}

			if (input.value == "" && !first_focus) {
				input.focus();
				first_focus = true;
			}
		}.bind(this));

		if (all_fields_filled) {
			this.load();
		}
	},

	/**
	 *
	 */
	load: function()
	{
		var form = $("login");

		if ($("popup").checked) {
			var width  = screen.width - 12;
			var height = screen.height - 70;
			var props = "top=0,left=0,width=" + width + ",height=" + height + ",toolbar=no,"
				+ "menubar=no,scrollbars=yes,resizable=yes,location=no,directories=no,personalbar=no";

			window.open("", "App", props);
			form.target = "App";
			form.submit();
			setTimeout("$('login').reset()", 500);
		}
		else {
			form.target = "";
			form.submit();
		}
	}
});