function registerCheck( o) {
	var data = { 'id':o.id, 'value':o.value};
	$.post( '/ajax/UserRegister/check', data, registerCheckClb);
}
function registerCheckEmail( o) {
	if (o.value == '') {
		registerCheckResult( o.id, 0, 'Email nie może być pusty');
		return( false);
	}
	if (false == /^[A-Za-z0-9._%-]+@[A-Za-z0-9._%-]+\.[A-Za-z0-9._%-]{2,4}$/.test( o.value)) {
		registerCheckResult( o.id, 0, 'Email jest nieprawidłowy');
		return( false);
	}
	registerCheckResult( 'email', 1, '');
}

function registerCheckPass( o) {
	if ($('#password1').val() == '') {
		registerCheckResult( 'password1', 0, 'Hasło nie może być puste', 2);
		return( false);
	} else if (false == /^.{5,}$/.test( $('#password1').val())) {
		registerCheckResult( 'password1', 0, 'Hasło jest za krótkie', 2);
		return( false);
	} else {
		registerCheckResult( 'password1', 1, '', 2);
	}
	if (o.id != 'password2' && $('#password2').val() == '') {
		return( false);
	}
	if ($('#password1').val() != $('#password2').val()) {
		registerCheckResult( 'password2', 0, 'Potwierdzenie hasła się nie zgadza', 2);
	} else {
		registerCheckResult( 'password2', 1, '', 2);
	}
}

function registerCheckClb( msg) {
	if (!msg) {
		return( false);
	}
	var field = $('id', msg).text();
	var result = parseInt( $('result', msg).text());
	var txt = $('msg', msg).text();
	registerCheckResult( field, result, txt);
}
function registerCheckResult( field, result, txt) {
	var infoCell = (arguments.length > 3) ? arguments[3] : 1;
	if (result == 0) {
		$(document.getElementById( field).parentNode.parentNode.cells[infoCell]).html( '<img src="/img/formBad.png" class="formBad" alt="'+txt+'" /> '+txt);
		$('#'+field).addClass( 'invalid');
		$('#err_msg').text( txt);
	} else {
		$(document.getElementById( field).parentNode.parentNode.cells[infoCell]).html( '<img src="/img/formOK.png" />');
		$('#'+field).removeClass( 'invalid');
		$('#err_msg').empty();
	}
}
function registerValidate( form, step) {
//	alert( step);
//	return( false);
	var result = true;
	if (false == formValidate( form)) {
		$('#err_msg').html( 'Pola zaznaczone na czerwono zostały wypełnione błędnie');
		result = false;
	}
	if (result && $('.formBad', form).length > 0) {
		$('#err_msg').html( 'Sprawdź poprawność wszystkich pól');
		result = false;
	}
	if (result && step == 2 && $('#agree:checked', form).length == 0) {
		$('#err_msg').html( 'Musisz wyrazić zgodę na warunki regulaminu');
		result = false;
	}
	if (false == result) {
		window.location.href = '#';
	}
	return( result);
}
function registerShowAgree( o, e) {
	$('.hidden', o.parentNode).removeClass( 'hidden');
	$(o).remove();
	e.preventDefault();
}
