Validator={};
Validator.passwordMinLength = 6;
Validator.passwordMaxLength = 16;

/**
* Validate an email, and eventually shows - hides  the corresponding error field (display: none <-> block)*/
Validator.validateEmail = function(email, errorField){
	regex = /^([a-zA-Z0-9_\-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([a-zA-Z0-9\-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$/;
	test = document.getElementById(errorField)!=null;
	if (email=="" || regex.exec(email) == null){
		if (test) document.getElementById(errorField).style.display = 'block';
		return false;
	}else{
		if (test) document.getElementById(errorField).style.display='none';
		return true;
	}
}

Validator.validatePassword = function(password1, password2, errorField1, errorField2){
	test1 = getTestFromPassword(password1);
	test2 = getTestFromPassword(password2);
	var result;
	if (test2==1 || (password1==password2 && test1==test2 && test1==3)) result = 3;
	else if (test1==test2 && test2==2) result = 2;
	else result=1;
	
	error1Exists = document.getElementById(errorField1)!=null;
	error2Exists = document.getElementById(errorField2)!=null;
	
	if (result==2 && error2Exists) document.getElementById(errorField2).style.display = 'block';
	else document.getElementById(errorField2).style.display = 'none';
	
	if (result==1 && error1Exists) document.getElementById(errorField1).style.display = 'block';
	else document.getElementById(errorField1).style.display = 'none';
	return result == 3;
}

function getTestFromPassword(password){
	if (password==null || password=='') return 1;
	else if (password.length>Validator.passwordMaxLength || password.length<Validator.passwordMinLength) return 2;
	else return 3;
}
