<inp2:m_Set skip_last_template="1"/>
<inp2:adm_HTTPAuth result_to_var="http_auth"/>
<inp2:m_include t="incs/header" nobody="yes"/>

<body topmargin="0" leftmargin="0" marginheight="0" marginwidth="0" bgcolor="#FFFFFF">
	<style type="text/css">
	<!--
		html, body {
			margin: 0;
			padding: 0;
			width: 100%;
			height: 100%;
			overflow: hidden;
		}

		#header-div {
			position: absolute;
			top: 0px;
			height: 160px;
			left: 0px;
			right: 0px;
			background: url('img/login/login-top.png') no-repeat right top #007bf4;
			z-index: 2;
		}

		#body-div {
			position: absolute;
			top: 160px;
			bottom: 160px;
			width: 100%;
			text-align: center;
			z-index: 5;
		}

		#footer-div {
			position: absolute;
			bottom: 0px;
			height: 160px;
			left: 0px;
			right: 0px;
			background: url('img/login/login-bottom.png') no-repeat left bottom #007bf4;
			z-index: 2;
		}

		#outer {
			position: absolute;
			top: 50%;
			left: 0px;
			width: 100%;
			height: 1px;
			overflow: visible;
			z-index: 10;
		}

		#inner {
			text-align: left;
			width: 100%;
			height: 300px;
			margin-left: -50%;  /***  width / 2   ***/
			position: absolute;
			top: -150px;          /***  height / 2   ***/
			left: 50%;
			z-index: 5;
			/* border: 1px solid #000000; */
		}

		#form table {
			-moz-border-radius: 20px;
			-webkit-border-radius: 20px;
			border: 1px solid #CCCCCC;
			font-weight: normal;
			background-color: #ECECEC;
			z-index: 5;
		}

		#form table td {
			padding: 2px 15px 2px 15px;
		}

		.login-table {
			background: #ECECEC;
		}

		.roundbutton {
			-moz-border-radius: 11px;
			-webkit-border-radius: 11px;
			cursor: pointer;
			padding: 2px 5px;
			text-decoration: none;
		}
	-->
	</style>

	<div id="header-div"></div>

	<div id="body-div">

		<div id="outer">

		  	<div id="inner" align="center">

			  	<div id="logo" align="center" style="margin-bottom: 20px;">
			  		<table class="head-table" style="background: none;">
			  		<tr>
			  			<inp2:m_if check="adm_AdminSkin" type="LogoLogin">
			  				<td align="center"><img src="<inp2:adm_AdminSkin type='LogoLogin'/>" alt="<inp2:m_GetConfig var='Site_Name'/>"></td>
			  			<inp2:m_else/>
			  				<inp2:m_if check="adm_AdminSkin" type="Logo">
				  				<td>
				  					<img src="<inp2:adm_AdminSkin type='Logo'/>" alt="<inp2:m_GetConfig var='Site_Name'/>"><br/>
				  					<inp2:m_if check="adm_AdminSkin" type="LogoBottom">
				  						<img src="<inp2:adm_AdminSkin type='LogoBottom'/>" alt="<inp2:m_GetConfig var='Site_Name'/>">
				  					</inp2:m_if>
				  				</td>
			  				</inp2:m_if>

			  				<td align="left" valign="middle">
				  				<span style="font-size: 48px; color: black;"><inp2:m_GetConfig var="Site_Name"/></span>
				  			</td>
			  			</inp2:m_if>
			  		</tr>
			  		</table>
			  	</div>

			  	<div id="form" align="center">
			  		<inp2:m_if check="m_Param" name="http_auth">
				    	<table class="login-table">
			      			<tr>
			      				<td colspan="2" style="text-align: center">
			      				<inp2:m_if check="u.current_HasError" field="any">
									<span class="error-cell"><inp2:u.current_Error field="ValidateLogin"/></span>
								</inp2:m_if><br/>
			      				</td>
			      			</tr>
			      			<tr>
		          				<td class="text"><inp2:m_phrase name="la_Text_Login"/>:</td>
		          				<td><input type="text" name="login" class="text" value="<inp2:u_CookieUsername submit_field="login"/>" style="width: 150px;"></td>
		          			</tr>
		          			<tr>
		          				<td class="text"><inp2:m_phrase name="la_prompt_Password"/>:</td>
		          				<td><input type="password" name="password" class="text" style="width: 150px;"></td>
		          			</tr>
		          			<tr>
			          			<td colspan="2">
			          				<input type="checkbox" id="save_username" name="cb_save_username"<inp2:m_if check="m_GetEquals" name="save_username" value="" inverse="inverse"> checked="checked"</inp2:m_if>/>&nbsp;
			          				<label for="save_username"><inp2:m_Phrase label="la_SaveLogin"/></label>
			          			</td>
		          			</tr>
		          			<tr>
		          				<td colspan="2" align="center" style="padding: 5px 15px 10px 15px;">
		              				<input type="submit" name="login_button" value="<inp2:m_phrase name='la_Login' no_editing='1'/>" class="kx-login-button roundbutton"></td>
		          			</tr>
						</table>
					<inp2:m_else/>
						<h1 style="color: red;">401 Authentication Required</h1>
					</inp2:m_if>
			    </div>

			</div>

		</div>

	</div>

	<div id="footer-div"></div>

	<inp2:m_if check="m_Param" name="http_auth">
		<input type="hidden" name="events[u]" value="OnLogin"/>
		<input type="hidden" name="next_template" value="<inp2:m_if check="m_GetEquals" name="next_template" value="">index<inp2:m_else/><inp2:m_get var="next_template"/></inp2:m_if>"/>
		<input type="hidden" name="skip_last_template" value="1"/>

		<script type="text/javascript">

			$(document).ready(
				function() {
					$("input[name='login']").focus();
				}
			);

			var a_parent = window.parent;
			var to_close = new Array();

			function redirect() {
	//			alert('running redirect in "' + window.name + '"');
	//			window.name = 'redirect';
				var $main_frame = getFrame('main');
				a_parent = window;

				try {
					var i = 0;
					while (i < 10) {
						i++;
						var $opener = $main_frame.getWindowOpener(a_parent);
	//					console.log('window: ', a_parent.name, '; opener: ', $opener ? $opener.name : null);

						if ($opener) {
							to_close.push(a_parent);
							a_parent = $opener;
							continue;
						}

						if (a_parent.name == 'main_frame') {
							break;
						}

						if (a_parent.parent && a_parent.parent.name != a_parent.name) {
							a_parent = a_parent.parent;
							continue;
						}
					}
				}
				catch (err) {
					// another website is opened in parent window
					alert('Error while trying to access window opener: [' + err.message + ']');
					i = 10;
				}

				if (i < 10) {
	//				console.log('to close: ', to_close);
					setTimeout(close_windows, 100);
				}
			}

			function close_windows() {
				page = '<inp2:m_t t="index" expired="1" escape="1" no_amp="1" m_wid=""/>'; // a_parent.location.href + '?expired=1';
	//			alert('redirecting ' + a_parent.name + ' to ' + page);
				a_parent.location.href = page;

	//			alert('closing ' + to_close.length + ' windows');
				for (var c = (to_close.length - 1); c >= 0; c--) {
	//				alert('closing ' + to_close[c].name);
					window_close(to_close[c]);
				}
			}

			if (window.top.frames.length > 0) {
				redirect();
			}
		</script>
	</inp2:m_if>

<inp2:m_include t="incs/footer"/>