// JavaScript Document
function trimString(strTrimMe)
{
	while(strTrimMe.substr(0,1) == " ")
		strTrimMe = strTrimMe.substr(1);
	
	while (strTrimMe.substr(strTrimMe.length-1, 1) == " ")
		strTrimMe = strTrimMe.substr(0, strTrimMe.length-1);
	
	return strTrimMe;
};


function checkRegister()
{
	login = trimString(document.forms.RegisterForm.Login.value);
	document.forms.RegisterForm.Login.value = login;
	email = trimString(document.forms.RegisterForm.Email.value);
	document.forms.RegisterForm.Email.value = email;
	Password = trimString(document.forms.RegisterForm.Password.value);
	Pass2 = trimString(document.forms.RegisterForm.Pass2.value);
	document.forms.RegisterForm.Password.value = Password;
	document.forms.RegisterForm.Pass2.value = Pass2;
	
	var strErrors = "";
	
	if (login.length < 4)
		strErrors += "\n- Username must be at least 4 characters long.";

	if (email.length < 1)
		strErrors += "\n- You must insert your e-mail address in order to complete your registration.";

	if (Password.length < 4)
		strErrors += "\n- Password must be at least 4 characters long.";
	
	if (Password != Pass2)
		strErrors += "\n- Password and re-typed password doesnt match!";
	
	if (strErrors.length > 0)
	{
		alert("Fix these errors:\n" + strErrors);
		return false;
	};
	
	return true;
};