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 doLoadUpVar() {
	if (timeout) clearTimeout(timeout);
	timeout = setTimeout(doLoadVar, 100);
}


function zeroFieldsCheck(requiredFields, errorFields) {
	var valid = true;
	
	for(i in errorFields)
		if (document.getElementById(errorFields[i]) && document.getElementById(errorFields[i]).firstChild && document.getElementById(errorFields[i]).firstChild.nodeName!="#text" && document.getElementById(errorFields[i]).firstChild.innerHTML!="")
		{
			valid = false;
		}
	
	for(i in requiredFields)
		if (document.getElementById(requiredFields[i]))
		{
			var err_msg = "";
			if (document.getElementById(requiredFields[i]).value=='')
			{
				valid = false;
				err_msg = "This field is required to fill.";
			}
			
			var fld = document.getElementById(requiredFields[i]);
			if (fld.nextSibling.className.toLowerCase().indexOf("error") != -1)
			{
				//alert(" : "+fld.nextSibling.firstChild.nodeName);
				if (!fld.nextSibling.firstChild || fld.nextSibling.firstChild.nodeName=="#text" || err_msg!="")
					fld.nextSibling.innerHTML = err_msg;
			}
			else
			{
				var err = document.createElement("SPAN");
				err.className = "com error";
				err.innerText = err_msg;
				fld.parentElement.insertBefore(err, fld.nextSibling);
			}
		}
	
	return valid;
}