function login(){
	var url='files.php';
	var login = encodeURIComponent(document.getElementById('ulogin').value);
	var passwd = encodeURIComponent(document.getElementById('upasswd').value);

    if(passwd.length == 0){
        document.getElementById("loginInfo").style.backgroundColor="#ccc";
        document.getElementById("loginInfo").style.color="#ff0000";
        document.getElementById("loginInfo").innerHTML = "Brak hasla lub jest za krotkie";
    }else{
        var par = 'krkkt=check&slogin='+login+'&spassword='+passwd;
        if(xmlHttp){
            xmlHttp.open("POST",url,true);
            xmlHttp.onreadystatechange = LoginActions;
            xmlHttp.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
            xmlHttp.send(par);
        }else{
            alert('Brak obiektu XML!');
        }
    }
}

function logout(){
	var url = "panel.php";
	var par = 'url=logout';
	if(xmlHttp){
		xmlHttp.open("POST",url,true);
		xmlHttp.onreadystatechange = logoutAction;
		xmlHttp.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
		xmlHttp.send(par);
	}else{
		alert('Brak obiektu XML!');
	}
}

function logoutAction(){
	if(xmlHttp){
		if((xmlHttp.readyState==4) && (xmlHttp.status==200)){
			try{
				if(xmlHttp.responseText == 'OK'){
					window.location='?';
				}
			}catch(e){
				alert('Błą odpowiedzi: '+e.toString());
			}
		}
	}
}

function register(){
	if(xmlHttp){
		var url='panel.php';
		var login = encodeURIComponent(document.getElementById('username').value);
		var passwd = MD5(encodeURIComponent(document.getElementById('userpass').value));
		var name = encodeURIComponent(document.getElementById('name').value);
		var surname = encodeURIComponent(document.getElementById('surname').value);
		var email = encodeURIComponent(document.getElementById('email').value);
		
		var par = 'url=register&login='+login+'&passwd='+passwd+'&name='+name+'&surname='+surname+'&email='+email;
		
		try{
			xmlHttp.open("POST",url,true);
			xmlHttp.onreadystatechange = openFile;
			xmlHttp.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
			xmlHttp.send(par);
		}catch(e){
			alert('Błąd odpowiedzi: '+e.toString());
		}
	}
}

function LoginActions(){
	var info = document.getElementById('loginInfo');
	if(xmlHttp){
		if((xmlHttp.readyState==4) && (xmlHttp.status==200)){
			try{
				if(xmlHttp.responseText == 'OK'){
					window.location='?';
				}else{
					info.style.textAlign = "center";
					info.style.background = "#CCC";
					info.style.color = "#ff0000";
					info.innerHTML = "Błędna para login/hasło.";
				}
			}catch(e){
				alert('Błą odpowiedzi: '+e.toString());
			}
		}
	}
}