/*
 * jrgp - 7/31/2010
 */

/*
 * Deal with fake sexy popup in the middle of the screen
 */
login_prompt = {

	/*
	 * Id that login page assumes
	 */
	id : 'unified_air_login',

	/*
	 * Go here if posted after successful login
	 */
	loc: false,

	set_loc: function(to_go) {
		this.loc = to_go;
	},

	/*
	 * Dim page and show login prompt in the middle
	 * of screen. 
	 */
	show_prompt : function	() {

		// Kill existing
		this.kill_prompt();

		// Dim page back a bit
		gray_in();

		// Deal with main holder div
		var login = document.createElement('div');
		login.setAttribute('id', this.id);
		login.innerHTML = '<form action="/'+unified_current_lang+'/login'+(this.loc ? ',dest=' + this.loc : '')+'" method="post"><input type="hidden" name="do_login" value="yes"><div id="login_form" class="col_box"><h2 class="alt">Login</h2><div class="col_box_inner"><div class="col_box_row alt"><label for="username_air">Username</label><input type="text" id="username_air" name="username"></div><div class="col_box_row"><label for="password_air">Password</label><input type="password" id="password_air" name="password"></div><div class="col_box_row alt"><input type="checkbox" id="rem_air" name="rem" value="yes"><label for="rem_air">Keep me logged in</label></div><div class="col_box_msg">(This is the same account as your one on the Soldat Forums)</div><div class="col_box_row alt button_bar"><input type="submit" value="login"><button onclick="login_prompt.kill_prompt();">Cancel</button></div></div></div></form>';
		document.body.appendChild(login);
		
		// Handle pressing escape murders form
		document.onkeyup = function(e) {
			switch(window.event ? event.keyCode : e.keyCode) {
				case 27:
					login_prompt.kill_prompt();
				break;
			}
		}

		// Focus it
		document.getElementById('username_air').focus();

	},

	/*
	 * Remove login prompt from middle of screen. 
	 */
	kill_prompt : function () {
		
		// Kill grayness
		gray_out();

		// Remove form
		if (document.getElementById(this.id))
			document.body.removeChild(document.getElementById(this.id));

	}
}

