﻿function checkChanegePasswordProfile(form) {
	var emptyData = false;
	var text = "";
	var passwordRegExp = /^[_a-zA-Z0-9-\.]{5,15}$/;

	if (passwordRegExp.test(form.password.value)==true) {
		if (!emptyData) {
			emptyData = false;
		}
	} else {
		text += " Twoje hasło,";
		emptyData = true;
	}

	if (passwordRegExp.test(form.newpassword.value)==true) {
		if (!emptyData) {
			emptyData = false;
		}
	} else {
		text += " nowe hasło,";
		emptyData = true;
	}
	
	if (passwordRegExp.test(form.renewpassword.value)==true) {
		if (!emptyData) {
			emptyData = false;
		}
	} else {
		text += " powtórzone nowe hasło,";
		emptyData = true;
	}
	
	if (form.newpassword.value==form.renewpassword.value) {
		if (!emptyData) {
			emptyData = false;
		}
	} else {
		text += " Nowe hasło i jego powtórzenie różnią się,";
		emptyData = true;
	}

	if (!emptyData) {
		return true;
	} else {
		document.getElementById('form-info').innerHTML = "<p class=\"error\">Proszę wprowadzić poprawnie pozycje: " + text.substr(0,text.length - 1) + "</p>";
		return false;
	}

}

function checkRegistrationForm(form) {
	var emptyData = false;
	var text = "";
	var emailRegExp = /^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.([a-z]){2,4})$/;
	var nameRegExp = /^[_a-zA-Z0-9-\.]{3,15}$/;

	if (emailRegExp.test(form.email.value)==true && form.email.value.length!=0) {
		if (!emptyData) {
			emptyData = false;
		}
	} else {
		text += " adres email,";
		emptyData = true;
	}

	if (nameRegExp.test(form.nickname.value)==false){
		emptyData = true;
		text += " nazwa użytkownika,";
	} else {
		if (!emptyData) {
			emptyData = false;
		}
	}

	if (form.securitycode.value==""){
		emptyData = true;
		text += " kod zabezpieczający,";
	} else {
		if (!emptyData) {
			emptyData = false;
		}
	}

	if (!form.rules[0].checked){
		emptyData = true;
		text = " Akceptacja regulaminu jest niezbędna do rejestracji na stronie.";
	} else {
		if (!emptyData) {
			emptyData = false;
		}
	}

	if (!emptyData) {
		return true
	} else {
		document.getElementById('form-info').innerHTML = "<div class=\"error\">Proszę wprowadzić poprawnie pozycje: " + text.substr(0,text.length - 1) + "</div>";
		return false;
	}
}

function checkLostPasswordForm(form) {
	var emptyData = false;
	var text = "";
	var emailRegExp = /^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.([a-z]){2,4})$/;

	if (emailRegExp.test(form.email.value)==true && form.email.value.length!=0) {
		if (!emptyData) {
			emptyData = false;
		}
	} else {
	        text += " adres email,";
		emptyData = true;
	}
	if (!emptyData) {
		return true;
	} else {
		document.getElementById('form-info').innerHTML = "<div class=\"error\">Proszę wprowadzić poprawnie pozycje: " + text.substr(0,text.length - 1) + "</div>";
		return false;
	}
}

function checkLostActivationEmailForm(form) {
	var emptyData = false;
	var text = "";
	var emailRegExp = /^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.([a-z]){2,4})$/;

	if (emailRegExp.test(form.email.value)==true && form.email.value.length!=0) {
		if (!emptyData) {
			emptyData = false;
		}
	} else {
	        text += " adres email,";
		emptyData = true;
	}
	if (!emptyData) {
		return true;
	} else {
		document.getElementById('form-info').innerHTML = "<div class=\"error\">Proszę wprowadzić poprawnie pozycje: " + text.substr(0,text.length - 1) + "</div>";
		return false;
	}
}

function checkLogin(form) {
	var emptyData = false;
	var text = "";
	var loginRegExp = /^[_a-zA-Z0-9-\.]+$/;
	var passwordRegExp = /^[_a-zA-Z0-9-\.]+$/;

	if (loginRegExp.test(form.login.value) == false){
		emptyData = true;
		text += " login,";
	} else {
		if (!emptyData) {
			emptyData = false;
		}
	}

	if (passwordRegExp.test(form.password.value) == false){
		emptyData = true;
		text += " hasło,";
	} else {
		if (!emptyData) {
			emptyData = false;
		}
	}

	if (!emptyData) {
		return true;
	} else {
		document.getElementById('form-info').innerHTML = "<div class=\"error\">Proszę wprowadzić poprawnie pozycje: " + text.substr(0,text.length - 1) + "</div>";
		return false;
	}
}

function runLogout() {
        document.logoutform.submit();
}

