/*
// prepare the form when the DOM is ready 
$(document).ready(function() { 
		var options = { 
        target:        '#output1',   // target element(s) to be updated with server response 
        beforeSubmit:  validate,  // pre-submit callback 
        success:       showResponse  // post-submit callback 
 
        // other available options: 
        //url:       url         // override for form's 'action' attribute 
        //type:      type        // 'get' or 'post', override for form's 'method' attribute 
        //dataType:  null        // 'xml', 'script', or 'json' (expected server response type) 
        //clearForm: true        // clear all form fields after successful submit 
        //resetForm: true        // reset the form after successful submit 
 
        // $.ajax options can be used here too, for example: 
        //timeout:   3000 
    }; 

    // bind form using ajaxForm 
    //$('#myForm2').ajaxForm( { beforeSubmit: validate } ); 
		//$('#kontakt_form_footer').ajaxForm(options);
});

function validate(formData, jqForm, options) { 
    // jqForm is a jQuery object which wraps the form DOM element 
    // 
    // To validate, we can access the DOM elements directly and return true 
    // only if the values of both the username and password fields evaluate 
    // to true 
 
		var emailReg = /^([\w-\.]+@([\w-]+\.)+[\w-]{2,4})?$/;
		//var emailToVal = $("#emailTo").val();

 
    var form = jqForm[0]; 
    if (!form.username.value || !form.password.value) { 
        alert('Please enter a value for both Username and Password'); 
        return false; 
    } 
    alert('Both fields contain values.'); 
}

function showResponse(responseText, statusText)  { 
    alert('status: ' + statusText + '\n\nresponseText: \n' + responseText + 
        '\n\nThe output div should have already been updated with the responseText.'); 
}

*/
$(document).ready(function(){
			$("#kontakt_form_footer").submit(function(){
					var str = $(this).serialize();

					$.ajax({
					type: "POST",
					url: "/templates/479/formularz.php",
					data: str,
					success: function(msg){

							$("#wynik_form").ajaxComplete(function(event, request, settings){

									if(msg == 'OK') {
												result = '<div style="color: green;">Wiadomość wysłana. Dziękujemy.</div>';

												$("#kontakt_form_footer").find(':input').each(function() {
														switch(this.type) {
																case 'password':
																case 'select-multiple':
																case 'select-one':
																case 'text':
																case 'textarea':
																		$(this).val('');
																		break;
																case 'checkbox':
																case 'radio':
																		this.checked = false;
														}
												});
									}
									else 	{
												result = msg;
									}

									$(this).html(result);
							});
					}
				});

				return false;
		});
});

