//walidacja e-maila
$(document).ready(function(){

$("#email").change(function() { 

var email = $("#email").val();

if(email.length >= 3)
{
	$("#status1").html('<img align="absmiddle" src="gfx/layout/indicator.gif" /> <span style="font-size:10px;">Sprawdzam dostepność...</span>');
	
	$.ajax({ 
	type: "POST", 
	url: "modules/helpers/check_emailnick.php", 
	data: "email="+ email, 
	success: function(msg){ 

	$("#status1").ajaxComplete(function(event, request, settings){ 
	
		if(msg == 'OK')
		{ 
			$("#email").removeClass('object_error'); // if necessary
			$("#email").addClass("object_ok")
			$("#email").val(email);
			$("#nick").focus();
			$(this).html('<span style="font-size:10px; color:#81EB54;">Adres e-mail nie jest zarejestrowany.</span>');
		} 
		else
		{ 
			$("#email").addClass("object_error");
			$("#email").val("");
			$("#email").focus();
			$(this).html(msg);
		}
	});
	}});
}
else
{
	$("#status1").html('<span style="font-size:10px; color:#f35a5c;">E-mail jest nieprawidlowy.</span>');
	$("#email").addClass("object_error");
	$("#email").focus();
}
});
});
//walidacja nick'u
$(document).ready(function(){

$("#nick").change(function() { 

var nick = $("#nick").val();

if(nick.length >= 3)
{
	$("#status2").html('<img align="absmiddle" src="gfx/indicator.gif" /> <span style="font-size:10px;">Sprawdzam dostepność...</span>');
	
	$.ajax({ 
	type: "POST", 
	url: "modules/helpers/check_emailnick.php", 
	data: "nick="+ nick, 
	success: function(msg){ 

	$("#status2").ajaxComplete(function(event, request, settings){ 
	
		if(msg == 'OK')
		{ 
			$("#nick").removeClass('object_error'); // if necessary
			$("#nick").addClass("object_ok")
			$("#nick").val(nick);
			$("#haslo1").focus();
			$(this).html('<span style="font-size:10px; color:#81EB54;">Nick jest wolny.</span>');
		} 
		else
		{ 
			$("#nick").addClass("object_error");
			$("#nick").val("");
			$("#nick").focus();
			$(this).html(msg);
		}
	});
	}});
}
else
{
	$("#status2").html('<span style="font-size:10px; color:#f35a5c;">Nick jest nieprawidłowy [min 3 znaki, max 20].</span>');
	$("#nick").addClass("object_error");
	$("#nick").focus();
}
});
});
//walidacja e-maila ze zmiany e-maila
$(document).ready(function(){

$("#email1").change(function() { 

var email = $("#email1").val();

if(email.length >= 3)
{
	$("#status1").html('<img align="absmiddle" src="gfx/layout/indicator.gif" /> <span style="font-size:10px;">Sprawdzam dostepność...</span>');
	
	$.ajax({ 
	type: "POST", 
	url: "modules/helpers/check_emailnick.php", 
	data: "email="+ email, 
	success: function(msg){ 

	$("#status1").ajaxComplete(function(event, request, settings){ 
	
		if(msg == 'OK')
		{ 
			$("#email1").removeClass('object_error'); // if necessary
			$("#email1").addClass("object_ok")
			$("#email1").val(email);
			$("#email2").focus();
			$(this).html('<span style="font-size:10px; color:#81EB54;">Adres e-mail nie jest zarejestrowany.</span>');
		} 
		else
		{ 
			$("#email1").addClass("object_error");
			$("#email1").val("");
			$("#email1").focus();
			$(this).html(msg);
		}
	});
	}});
}
else
{
	$("#status1").html('<span style="font-size:10px; color:#f35a5c;">E-mail jest nieprawidlowy.</span>');
	$("#email").addClass("object_error");
	$("#email").focus();
}
});
});

//walidacja hasła promocyjnego
$(document).ready(function(){

$("#temporary_haslo_promocyjne").change(function() { 

var haslo_promocyjne = $("#temporary_haslo_promocyjne").val();

if(haslo_promocyjne.length >= 3)
{
	$("#status_haslo").html('<img align="absmiddle" src="gfx/indicator.gif" /> <span style="font-size:10px;">Sprawdzam czy istnieje takie hasło...</span>');
	
	$.ajax({ 
	type: "POST", 
	url: "modules/helpers/check_promocjahaslo.php", 
	data: "promocjahaslo="+ haslo_promocyjne, 
	success: function(msg){ 

	$("#status_haslo").ajaxComplete(function(event, request, settings){ 
	
		if(msg == 'OK')
		{ 
			$("#temporary_haslo_promocyjne").val(haslo_promocyjne);
			$("#haslo_promocyjne").val(haslo_promocyjne);
			$("#email_zamowienie").focus();
			$(this).html('<span style="font-size:10px; color:#81EB54;">Hasło jest poprawne. Przyznamy Ci rabat w następnym kroku.</span>');
		} 
		else
		{ 
			$("#temporary_haslo_promocyjne").val("");
			$("#haslo_promocyjne").val("");
			$("#temporary_haslo_promocyjne").focus();
			$(this).html(msg);
		}
	});
	}});
}
else
{
	$("#status_haslo").html('<span style="font-size:10px; color:#f35a5c;">Hasło jest nieprawidłowy [min 3 znaki, max 20].</span>');
	$("#temporary_haslo_promocyjne").focus();
}
});
});

