var timeout = null;

function doLoad(force) {
	var req = new Subsys_JsHttpRequest_Js();

	req.onreadystatechange = function() {
		if (req.readyState == 4) {
			document.getElementById('log').innerHTML = (req.responseJS.htm);
			document.getElementById('debug').innerHTML = '';
		}
	}

	req.caching = false;
	req.open('POST', 'includes/ajax/loader.php', true);

	req.send({ qer: document.getElementById('loggin').value });
	//doLoadUp();
}

function doLoadUp() {
	if (timeout) clearTimeout(timeout);
	timeout = setTimeout(doLoad, 1000);
}

function doLoadpass(force) {
	var req = new Subsys_JsHttpRequest_Js();
	
	req.onreadystatechange = function() {
		if (req.readyState == 4) {
			document.getElementById('pass').innerHTML = (req.responseJS.htm);
			document.getElementById('debug').innerHTML = '';
		}
	}

	req.caching = false;
	req.open('POST', 'includes/ajax/loader.php', true);

	req.send({ p1: document.getElementById('password_f').value, p2: document.getElementById('password_s').value });
// 	doLoadUppass();
}

function doLoadUppass() {
	if (timeout) clearTimeout(timeout);
	timeout = setTimeout(doLoadpass, 1000);
}
  
  
function doLoadmail(force) {

	var req = new Subsys_JsHttpRequest_Js();

	req.onreadystatechange = function() {
		if (req.readyState == 4) {
			document.getElementById('mail').innerHTML = (req.responseJS.htm);
			document.getElementById('debug').innerHTML = '';
		}
	}

	req.caching = false;
	req.open('POST', 'includes/ajax/loader.php', true);

	req.send({ email: document.getElementById('email').value });
//	doLoadUpmail();
}

function doLoadUpmail() {
	if (timeout) clearTimeout(timeout);
	timeout = setTimeout(doLoadmail, 1000);
}



function doLoadVar(AVar, AOUT) {
	var req = new Subsys_JsHttpRequest_Js();
	var AValue;

	if (document.getElementById(AVar)) AValue = document.getElementById(AVar).value;
	
	req.onreadystatechange = function() {
		if (req.readyState == 4) {
			document.getElementById(AOUT).innerHTML = (req.responseJS.htm);
		}
	}

	req.caching = false;
	req.open('POST', 'includes/ajax/loader.php', true);

	eval('req.send({ '+AVar+': AValue })');
//	doLoadUpVar();
}


function doLoadAuth() {
	var req = new Subsys_JsHttpRequest_Js();

	document.getElementById('auth_error').style.color='#9d0000';
	if (!document.getElementById('log').value || !document.getElementById('pass').value) {
		document.getElementById('auth_error').innerHTML = 'Введите логин и пароль для авторизации!';
		return false;
	}

	req.onreadystatechange = function() {
		if (req.readyState == 4) {
			document.getElementById('auth_error').innerHTML = (req.responseJS.htm);
		}
	}
	
	if (document.getElementById('auth_error').innerHTML == '' || document.getElementById('auth_error').innerHTML == 'Авторизация') {
		document.getElementById('auth_error').style.color='#008000';
		document.getElementById('auth_error').innerHTML = 'Успешная авторизация!';
		document.getElementById('auth_form').submit();
	}

	req.caching = false;
	req.open('POST', 'includes/ajax/loader.php', true);
	req.send({ login: document.getElementById('log').value, password: document.getElementById('pass').value});
//	doLoadUpVar();
}



function doLoadUpVar() {
	if (timeout) clearTimeout(timeout);
	timeout = setTimeout(doLoadVar, 100);
}
