$(document).ready(function() {
	$('<div id="wait" style="display: none; border: solid 5px red; background: #EFEFEF; padding: 20px 40px; position: absolute; text-align: center;"><strong>Wysyłanie danych</strong><br />Proszę czekać...</div>')
		.ajaxStart(function() {
			$(this).css('top', $(window).height()/2 - $(this).height()/2)
			$(this).css('left', $(window).width()/2 - $(this).width()/2)
			$(this).show();
		})
		.ajaxStop(function() { 
			$(this).hide();
		})
		.appendTo('body');
});

function beforeSubmit(formData, jqForm, settings) {
	$(".validators").hide("slow");

	$("#" + formData.id + " input[type=submit]").disabled = true;
}

function successSubmit(response, status) {
	switch (response.result) {
		case 'ok':
		case 'error':
			if (response.functionName) {
				if (response.params) {
					window[response.functionName](response.params);
				} else {
					window[response.functionName]();
				}
			} else {
				showMessage(response.params);
			}

			break;

		case 'error_validation':
			validationError(response.params);
			break;
	}
}

function errorSubmit(request, settings) {
	alert('error');
}

function validationError(params) {
	$('div#v_msg').html('Formularz zawiera błędy').slideDown('slow');

	for (validator in params) {
		$('div#v_' + validator).html(params[validator]).slideDown('slow');

//		setTimeout('validationErrorFadeOut("' + validator + '")', 2000);
	}

}

function validationErrorFadeOut(validatror) {
	$('div#v_' + validator).slideUp('slow');
}



/* Common functions */

function redirect(params) {
	document.location.href = params.url;
}

function showMessage(params) {
	alert(params.msg);
}

function deleteServiceRow(params) {
	$("#service_" + params.id).hide();
}

function deleteNewsRow(params) {
	$("#news_" + params.id).hide();
}

function deleteUsecaseRow(params) {
	$("#usecase_" + params.id).hide();
}

function reorderSuccess(params) {
	$("#reorderSave").hide();
}
