function authBottom() {
	scroll(0,0);
	document.getElementById("loginBox").style.display = "block";
	document.getElementById("login_div").firstChild.focus();
}


	/*
	*		Admin post init
	*/
	var adminMessageRequest = new XMLHttpRequest();
	adminMessageRequest.sendTry = function () {
		this.open("POST","/ajax/PostAdmin.php",true);
		this.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
		this.send(this.data);
	}
	adminMessageRequest.onreadystatechange = function () {
		if(this.readyState == 4 && this.status == 200) {
			
			if(this.responseText == "OK") {
				this.help.innerHTML = "Ваше сообщение успешно доставлено";
				this.help.style.color = "lime";
				this.help.style.fontWeight = "bold";
				setTimeout("messageOk()", 1500);
				document.getElementById("post_admin_roll").innerHTML = "";
			}
			else {
				this.help.innerHTML = this.responseText;
				this.help.style.color = "red";
			}
		}
	}

	function messageOk() {
		document.getElementById("post_admin").style.display = "none";
		document.getElementById("post_admin_roll").style.display = "none";
	}

	function backMessageInput() {
		if(this.value == "") {
			if(this.id == "") {
				this.value = "Ваши контакты...";
			}
			else {
				this.innerHTML = "Ваше сообщение...";
			}
		}
	}

	function rollClick() {
		this.style.display = "none";
		document.getElementById("post_admin").style.display = "block";
	}
	function closeClick() {
		this.parentNode.style.display = "none";
		document.getElementById("post_admin_roll").style.display = "block";
	}
	function sendClick() {
		contacts = document.getElementById("message_contacts").firstChild.value;
		if(contacts == "Ваши контакты...") {
			contacts = "";
		}
		author = document.getElementById("message_author").firstChild.value;
		content = document.getElementById("message_content").value;
		
		adminMessageRequest.data = "contacts=" + contacts + "&author=" + author + "&content=" + content;
		adminMessageRequest.sendTry();
	}
	onload = function () {
		adminMessageRequest.help = document.getElementById("post_admin_help");
		document.getElementById("message_contacts").firstChild.onblur = backMessageInput;
		document.getElementById("message_content").onblur = backMessageInput;
		document.getElementById("post_admin_roll").onclick = rollClick;
		document.getElementById("post_admin_close").onclick = closeClick;
		document.getElementById("send_message").onclick = sendClick;
		
		//		GamesBlock
		gamesBlock.construct();
		
		//crear last hr's
		if(document.getElementsByClassName("site_news_hr") !== undefined) {
			document.getElementsByClassName("site_news_hr")[document.getElementsByClassName("site_news_hr").length - 1].style.display = "none";
		}
		if(document.getElementsByClassName("news_hr") !== undefined) {
			document.getElementsByClassName("news_hr")[document.getElementsByClassName("news_hr").length - 1].style.display = "none";
		}
	}
	
	/*
	*		GamesBlock init
	*/
	gamesBlock= {};
	gamesBlock.construct = function () {
		this.popularGames = document.getElementsByClassName("popular_game");
		this.newGames = document.getElementsByClassName("game_new");
		this.relizes = document.getElementsByClassName("last_relize");
		for(var i = 0; i < 9; i++) {
			this.popularGames[i].info = document.getElementsByClassName("popular_game_info")[i];
			this.popularGames[i].onmouseover = this.actionOver;
			this.popularGames[i].onmouseout = this.actionOut;
			
			this.newGames[i].info = document.getElementsByClassName("game_new_info")[i];
			this.newGames[i].onmouseover = this.actionOver;
			this.newGames[i].onmouseout = this.actionOut;
		}
		for(var i = 0; i < this.relizes.length; i++) {
			this.relizes[i].info = document.getElementsByClassName("relize_info")[i];
			this.relizes[i].onmouseover = this.actionOver;
			this.relizes[i].onmouseout = this.actionOut;
		}
	}
	gamesBlock.actionOver = function () {
		this.info.style.display = "block";
	}
	gamesBlock.actionOut = function () {
		this.info.style.display = "none";
	}

/*
*		Auth
*/
	
var exitRequest = new XMLHttpRequest();
var authRequest = new XMLHttpRequest();
	
	
exitRequest.onreadystatechange = function () {
	if(this.readyState == 4 && this.status == 200) {
		document.location.href = document.location.href;
	}
}
function doExit() {
	exitRequest.exit();
}
exitRequest.onreadystatechange = function () {
	if(this.readyState == 4 && this.status == 200) {
		document.location.href = document.location.href;
	}
}

authRequest.onreadystatechange = function () {
	if(this.readyState == 4 && this.status == 200) {
	//		body parsing
		bodyBegin = '<div id="body">';
		bodyEnd = '</body>';
		bodyBeginPosition = this.responseText.search(bodyBegin);
		regBody = this.responseText.slice(bodyBeginPosition);
		bodyEndPosition = regBody.search(bodyEnd);
		regBody = regBody.slice(0, bodyEndPosition);
		
		var hidden = document.getElementById('hidden');
		hidden.innerHTML = regBody;
		if(document.getElementsByClassName('gensmall')[1] !== undefined) {
			var error = document.getElementsByClassName('gensmall')[1];
			var result = document.getElementById('result');
			result.innerHTML = error.innerHTML;
			if(result.childNodes[1] !== undefined) {
				if(result.childNodes[1].innerHTML == 'Администраторский раздел') {
					document.location.href = document.location.href;
				}
				else {
					alert(result.childNodes[1].innerHTML);
				}
			}
		}
		else {
			document.location.href = document.location.href;
		}
	}
}

authRequest.auth = function (data) {
	//		If not empty result - clean it
	if(document.getElementById('result').innerHTML != '') {
		document.getElementById('result').innerHTML = '';
	}
	this.open('POST','/forum/ucp.php?mode=login',true);
	this.setRequestHeader('Content-type','application/x-www-form-urlencoded');
	this.send(data);
}
