var onloading = 0;

function LoginCheck(){
	
	if(onloading == 0)
	{
		onloading = 1;

		var un = document.getElementById('username').value;
		var pw = document.getElementById('password').value;
		
		if(un == '' || pw == '')
		{
			document.getElementById('error_caption').innerHTML = 'Ошибка';
			document.getElementById('error_text').innerHTML = 'Логин/Пароль не могут быть пустыми.';	
			ShowPanel();
			onloading = 0;	
			}else{
		
		ShowPanel();
		document.getElementById('username').disabled = "true";
		document.getElementById('password').disabled = "true";
		
		req = 'checklogin=1&username='+un+'&password='+pw;
		
		document.getElementById('error_caption').innerHTML = 'Загрузка';
		document.getElementById('error_text').innerHTML = 'Подождите...';
		
		
		var ajaxreq = null;
		
		if(window.XMLHttpRequest)
		{
			ajaxreq = new XMLHttpRequest();
			}else if(window.ActiveXObject)
			{
				ajaxreq = new ActiveXObject('Microsoft.XMLHTTP');
				}else{
					alert('AJAX Error');
					return;
					}
					//document.getElementById('event_div').innerHTML = 'Загрузка данных...';
					
					ajaxreq.open('POST','index.php', true);
					ajaxreq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
					ajaxreq.send(req);
					
					ajaxreq.onreadystatechange = function(){
						
						if(ajaxreq.readyState==4)
						{
							if(ajaxreq.status==200){

								if(ajaxreq.responseText == 'logingood')
								{
									window.location = 'frames.php';
								}
								else if(ajaxreq.responseText != ''){
									
										document.getElementById('error_caption').innerHTML = 'Ошибка';
										document.getElementById('error_text').innerHTML = ajaxreq.responseText;
										
										}else{
											document.getElementById('error_text').innerHTML = 'Неизвестная ошибка.<br/>Пожалуйста, сообщите о ней Администрации проекта.';
											}
										if(ajaxreq.responseText != 'logingood'){
											document.getElementById('username').disabled = false;
											document.getElementById('password').disabled = false;
											}
										delete req;
										onloading = 0;
									
								}
			}
		}
	}
  }
}

var slide_on = 0;//флаг движения панели
var pan_top = -60;//положение панели от верха окна

function ShowPanel()
{
	if(slide_on == 0){
		if(pan_top <= -60)
		{
			slidetimer = setInterval('slidePan_down()',10);	
			}
	}
}

function slidePan_down()
{
	document.getElementById('error_div').style.display = 'block';
	if(pan_top < 5 )
	{
		slide_on = 1;
		pan_top = pan_top+5;
		document.getElementById('error_div').style.top = pan_top+'px';
		}
		else
		{
			clearInterval(slidetimer);
			//slide_on = 0;
			pan_top = 5;
			slidetimer2 = setInterval('run_sp_up()',2000);
			} 
}
function run_sp_up(){
	clearInterval(slidetimer2);
	slidetimer = setInterval('slidePan_up()',25);
}

var flash_cnt = 8;
function slidePan_up()
{
 if (flash_cnt <= 0) {
 	clearInterval(slidetimer);
 	document.getElementById('error_div').style.display = 'none';
 	flash_cnt = 8;
 	pan_top = -60;
 	slide_on = 0;
 }
 else {
 	slide_on = 1;
 	--flash_cnt;
 	if (document.getElementById('error_div').style.display == 'none') {
 		document.getElementById('error_div').style.display = 'block';
 	}
 	else {
 		document.getElementById('error_div').style.display = 'none'
 	}
 }
}
//Панель слева
var slide_on1 = 0;//флаг движения панели
var pan_left = -300;//положение панели от верха окна

function ShowOnline()
{if(slide_on1 == 0){if(pan_left <= -300){slideonl = setInterval('slidePan_left()',15);}}}
function slidePan_left()
{if(pan_left < 15){slide_on1 = 1; pan_left = pan_left+15; document.getElementById('reg_onl').style.left = pan_left+'px';}else{clearInterval(slideonl);slide_on1 = 0;slideonl2 = setInterval('slidePan_back()',10);}}
function slidePan_back()
{if(pan_left > 1){slide_on1 = 1; pan_left = pan_left-1;	document.getElementById('reg_onl').style.left = pan_left+'px';}else{clearInterval(slideonl2);}}














