jQuery(document).ready(function(){ 
jQuery('#frm').ajaxForm({
dataType: 'json', 
success:  processJson,
beforeSubmit: function(){
	jQuery("#frm table tr").removeClass("error_tr_rejestracja_table"); 
	jQuery("#frm table tr td span").empty(); 
	jQuery("#frm input[type=submit]").attr('disabled', 'disabled');
	jQuery("#mess").fadeOut("slow");
	jQuery("#aloader").fadeIn("slow");
}
});
jQuery('#plan').ajaxForm({
dataType: 'json',
success: planJson,
beforeSubmit: function() {
	jQuery("#plan table tr").removeClass("error_tr_rejestracja_table"); 
	jQuery("#plan table tr td span").empty(); 
	jQuery("#plan input[type=submit]").attr('disabled', 'disabled');
	jQuery("#aloader").fadeIn("slow");
}
});
jQuery('#frm_order').ajaxForm({
dataType: 'html',
success: orderJson,
clearForm: true,
beforeSubmit: function() {
	jQuery("#frm_order input[type=submit]").attr('disabled', 'disabled');
	jQuery("#aloader").fadeIn("slow");
}
});

});

function processJson(data)
{
	if (data.success=='ok')
	{
		jQuery("#frm").fadeOut("fast");
		jQuery("#frm").after(data.html);
		var timer = setTimeout(function(){window.location.href=jQuery("#aredir").attr('href');}, 5000);
		return false;
	}
	jQuery("#frm input[type=submit]").attr('disabled', '');
	jQuery("#mess").fadeIn("slow");
	jQuery("#aloader").fadeOut("slow");
	if (data.ef)
	{
		jQuery.each(data.ef,function(f,m){
				jQuery("#"+f).addClass("error_tr_rejestracja_table");
				jQuery("#"+f+" span").html(m);
				});
		if (data.token==1)
		{
			jQuery('#captcha').attr('src','/token/show.php?' + Math.random());
			jQuery('#frm input[name=token]').val('');
		}
	}
	else
		alert("Przeciążenie systemu. Proszę spróbować później.");
}
function planJson(data)
{
	if (data.success=='ok')
	{
		window.location.href='/uzytkownik/';
		return false;
	}
	if (data.redir)
	{
		window.location.href=data.redir;
		return false;
	}
	jQuery("#plan input[type=submit]").attr('disabled', '');
	jQuery("#aloader").fadeOut("slow");
	if (data.ef)
	{
		jQuery.each(data.ef,function(f,m){
			jQuery("#"+f).addClass("error_tr_rejestracja_table");
			jQuery("#"+f+" span").html(m);
		});
	}
	else
		alert("Przeciążenie systemu. Proszę spróbować później.");
}
function orderJson(responseText, statusText)
{
	jQuery("#frm_order input[type=submit]").attr('disabled', '');
	jQuery("#aloader").fadeOut("slow");
	jQuery("#mess").fadeIn("slow");
}
