$(document).ready(function(){
	ReloadValidator(null);
});

function SerwerSelect(id,obj)
{
	PrepareWait('dformr');
	$.ajax({
		type: 'POST',
		url: 'SerwerSelect,register_make.ai',
		dataType: 'json',
		data: 'id='+id,
		success: function(msg){
			if (msg.mission) {
				//top.location=self.document.location;
				ShowContent('dformr',msg.body);
				ReloadValidator(null);
			}
			else {
				//alert(msg.error);
				//obj.attr({ src: src_old });
			}
		}
	});
}

function ReloadValidator(obj)
{
	$.validator.addMethod("V_NICK",function(value,element){
	    return this.optional(element) || /^[a-zA-Z0-9\-_]+$/i.test(value);
	    },"Nazwa może zaweierać tylko litery, cyfry i znak _ ");

	$.validator.addMethod("V_PASSWORD",function(value,element){
		return this.optional(element) || /^(?=.*\d)(?=.*[a-z])(?=.*[A-Z]).{5,16}$/i.test(value);
		},"Hasło może zawierać wielkie litey, małe litey i przynajmniej jedną cyfrę.");

	$("#f_rejestracja").validate({
		rules: {
			nick: {
				V_NICK: true,
				required: true,
				minlength: 4,
				remote: "remote.php?is="+$('#servergame').val(),
			},
			passwd: {
				V_PASSWORD: true,
				required: true,
				minlength: 5
			},
			retypepasswd: {
				V_PASSWORD: true,
				required: true,
				minlength: 5,
				equalTo: "#passwd"
			},
			email: {
				required: true,
				email: true,
				remote: "remote.php?is="+$('#servergame').val(),
			},
		},
		messages: {
			nick: {
				remote: jQuery.format("{0} jest zajęty")
			},
			email: {
				remote: jQuery.format("{0} jest zajęty")
			}
		},

	} );
}

function RegisterFormAdd(obj)
{
	PrepareWaitSmall111(obj);
	if ($("#f_rejestracja").validate().form()) {

		$.ajax({
			type: 'POST',
			url: 'RegisterFormAdd,register_make.ai',
			dataType: 'json',
			data: $("#f_rejestracja").serialize(),
			success: function(msg){
				if (msg.mission) {
					HiddeContents('#dformr');
					HiddeContents('#dservers');
					if(msg.msg)
						ShowContent('msg_div',msg.msg);
					PreppareEndWaitSmall(obj);
				}
				else {
					HiddeContents('#dformr');
					if(msg.error)
						ShowContent('msg_div',msg.error);
					PreppareEndWaitSmall(obj);
				}
			}
		});

		//
	}
	else
	{
		PreppareEndWaitSmall(obj);
	}

}


