 

function showRequest(formData, jqForm, options) { 
    // formData is an array; here we use $.param to convert it to a string to display it 
    // but the form plugin does this for you automatically when it submits the data 
    var queryString = $.param(formData); 
 
    // jqForm is a jQuery object encapsulating the form element.  To access the 
    // DOM element for the form do this: 
    // var formElement = jqForm[0]; 
 
    //alert('About to submit: \n\n' + queryString); 
 
    // here we could return false to prevent the form from being submitted; 
    // returning anything other than false will allow the form submit to continue 
    return true; 
} 
 
function showerr(element, txt){
	$(element).fadeOut("slow");
	$(element).html('<span class="err">'+txt+'</span>');
	$(element).fadeIn("slow");
}

function showok(element, txt){
	$(element).fadeOut("slow");
	$(element).html('<span class="ok">'+txt+'</span>');
	$(element).fadeIn("slow");
}

// post-submit callback 
// responseText, statusText, xhr, $form
function showResponse(datajson)  { 


	 //alert( datajson.reply );
	 //$('#formout').fadeIn('slow'); 
	 if( datajson.reply == 'err' ){
	 	if( datajson.err.email == 'bad' ){
			showerr('#label_email', 'Podany email jest nieprawidłowy!');
		}
		else{
			showok('#label_email', 'Adres email [ok]');
		}
		
		if( datajson.err.subject == 'empty' ){
			showerr('#label_subject', 'Wpisz tytuł lub swój Nick/Imię');
		}
		else{
			showok('#label_subject', 'Tytuł [ok]');
		}
		
		if( datajson.err.message == 'empty' ){
			showerr('#label_message', 'Wpisz treść wiadomości');
		}
		else{
			showok('#label_message', 'Treść [ok]');
		}
		
		if( datajson.err.post_token == 'bad' ){
			showerr('#label_token', 'Wpisz prawidłowy token');
		}
		else{
			showok('#label_token', 'Token [ok]');
		}
		
	 }
	 else if( datajson.reply == 'ok' ){
	 	$('#outinfoform').html('<span class="ok">Wiadomość została wysłana<br />Dziękuję za zainteresowanie, postaram się odpowiedzieć najszybciej jak to możliwe</span>');
		$('#outinfoform').fadeIn("slow");
		$('#formcontact').fadeOut("slow");
		$('#formcontact').clearForm();
	 }
	 else{
	 
	 }
	 
}


$(document).ready(function() { 
		var options = { 
			dataType: 'json',
        	target:        '#formout',   
        	beforeSubmit:  showRequest,  // pre-submit callback 
        	success:       showResponse  // post-submit callback 
    }; 
 
    $('#formcontact').ajaxForm(options); 
	 return false;
});
