function bodyload() {
	collapse_all();
	request = false;
	try {
		request = new XMLHttpRequest();
	} catch (trymicrosoft) {
		try {
			request = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (othermicrosoft) {
			try {
				request = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (failed) {
				request = false;
			}
		}
	}
	if (!request) {
		alert("Ошибка инициализации XMLHttpRequest!");
	}
}

function smooth(sv) {
	sv += 15;
	var shadow = document.getElementById('overlap');
	shadow.style.opacity = sv / 100;
	shadow.style.filter = "alpha(opacity=" + sv + ")";
	if (sv < 70) {
		setTimeout("smooth(" + (sv) + ")",10)
	} else {
		document.getElementById('ajaxwindow').style.display = 'inline';
	}
}

function loginclick() {
	document.getElementById('overlap').style.display = 'inline';
	smooth(10);
	return false;
}

function closeclick() {
	document.getElementById('overlap').style.display = 'none';
	document.getElementById('ajaxwindow').style.display = 'none';
}

function ajaxlogin() {
	showErrorMsg('Пожалуйста, подождите...');
	var c = 0;
	if (document.getElementById('remember_me').checked > '') c = 1; else c = 0;
	var url = "lcheck.php?l=" + encodeURIComponent(document.getElementById('username').value) + "&p=" + encodeURIComponent(document.getElementById('password').value) + "&c=" + c;
	//if (document.getElementById('username').value == 'pelewin') alert(url);
	request.open("GET", url, true);
	request.onreadystatechange = updatePage;
	request.send(null);
	return false;
}

function showErrorMsg(str) {
	var msg = document.getElementById('msg');
	msg.className = 'errormsg';
	msg.innerHTML = str;
}

function updatePage() {
	if (request.readyState == 4) {
		if (request.status == 200) {
			var xmlRoot=request.responseXML.documentElement;
			var answer = xmlRoot.firstChild.nodeValue;
			answer = parseInt(answer, 10);
			if (answer > 0) {
				//проверить кукисы
				document.cookie = "cookietest=1";
				var ck = document.cookie;
				if (ck.length == 0) {
					showErrorMsg('Внимание!<br/>Включите cookies в браузере!');
				} else {
					location="index.php";
				}
			} else if (answer == 0) {
				showErrorMsg('Ошибка!<br/>Неверный логин или пароль!');
				document.getElementById('password').value = '';
			} else {
				showErrorMsg('Ваш аккаунт заблокирован!<br/>Причина: ' + xmlRoot.getAttribute('blres'));
				document.getElementById('password').value = '';
			}
		} else
			alert("status is " + request.status);
	}
}

function wcheck() {
	var str = document.getElementById("wallet").value;
	var url = "xmlwch.php?w=" + encodeURIComponent(str);
	request.open("GET", url, true);
	request.onreadystatechange = wCheckUpdatePage;
	request.send(null);
}

function wCheckUpdatePage() {
	if (request.readyState == 4) {
		if (request.status == 200) {
			var xmlRoot=request.responseXML.documentElement;
			var cWals = xmlRoot.getElementsByTagName('wallet');
			var cWal = cWals[0].firstChild.nodeValue;
			if (cWal == '0') cWal = '';
			document.getElementById("wallet").value = cWal;
			var incWals = xmlRoot.getElementsByTagName('incw');
			var incWal = incWals[0].firstChild.nodeValue;
			if (incWal != '0')
				incWal = 'Данные номера не являются верными номерами кошельков ни WebMoney, ни Yandex-денег: ' + incWal;
			else
				incWal = '&nbsp;';
			document.getElementById("incwallets").innerHTML = incWal;
		} else
			alert("status is " + request.status);
	}
}

function collapse_all(){
	if (document.getElementById('showhide') != null) {
		var divs = document.getElementsByTagName('div');
		var x;
		for(x=0; x<divs.length; ++x){
			if (divs[x].className == 'ruls_one') {
				divs[x].style.display = "none";
			}
			if (divs[x].className == 'ruls_zag2') {
				divs[x].style.cursor = "pointer";
			}
		}
	}
}

function showhide(no){
	var was = document.getElementById('ro' + no).style.display;
	collapse_all();
	if(was == 'none')
		was = 'block';
	else
		was = 'none';
	document.getElementById('ro' + no).style.display = was;
}
