﻿function check_login(id)
{
	check_login_validation(id);
	var login = document.getElementById(id).value;
	check_login_exist(login);
}

function check_login_validation(id)
{
	var login = document.getElementById(id).value;
	if (login.length <3)
	{
		document.getElementById('error_login').innerHTML='Podany login jest za krótki';
	}else{
		document.getElementById('error_login').innerHTML='';
	}
}

function check_password()
{
	var pass = document.getElementById('pass').value;
	var pass2 = document.getElementById('pass2').value;
	
	if (pass!=pass2)
	{
		document.getElementById('error_password').innerHTML='Hasła różnią się';
	}else{
		document.getElementById('error_password').innerHTML='';
	}

}

function check_email()
{
	mail = document.getElementById('email').value;
	if(mail.length!=0)
	{
		if(isEmail(mail)){
			document.getElementById('error_email').innerHTML='';
		}else{
			document.getElementById('error_email').innerHTML='Podany adres e-mail jest niepoprawny.';
		}
		
	}
}

function isEmail(string) {
if (string.search(/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/) != -1)
	return true;
else
	return false;
}

function check_login_exist(login)
{
	url='http://www.fontshome.com/user/check_login_exists/'+login
	if(url){
	  // kontynuuje, jeśli obiekt xmlHttp nie jest pusty
		  if (xmlHttp)
		  {
			// próbuje połączyć się z serwerem
			try
			{
			  // początkuje odczyt pliku z serwera
			  xmlHttp.open("GET", url, true);
			  xmlHttp.onreadystatechange = handleRequestStateChange;
			  xmlHttp.send(null);
			}
				// w razie niepowodzenia wyświetla komunikat o błędzie
				catch (e)
				{
				  alert("Nie mogę połączyć się z serwerem:\n" + e.toString());
				}
		  }
	  }

}

function check_rules()
{
	rul = document.getElementById('rules').checked;
	if(rul){
		document.getElementById('rules').style.border='';
	}else{
		document.getElementById('rules').style.border='1px red solid';
	}
}
function readResponse()
{
	var xmlRoot = xmlHttp.responseXML;

	if(xmlRoot!=null){
		le = xmlRoot.getElementsByTagName("user_exists")[0].firstChild.nodeValue
		if(le==1){
			document.getElementById('error_login').innerHTML+='Podany login istnieje w naszej bazie<br>';
		}
	}
}
