// JavaScript Document

// komunikat błędu
function blad($error) {
	switch($error) {  
	case 1:
	$tekstbledu = "Uzupełnij wymagane pola!";
	break;
	}
	wyswietlStatus($tekstbledu,1);
}
 
function status($status) {
	switch($status) {
	case 1:
	$tekstkomunikatu = "Dziękujemy za wiadomość!";
	break;
	}
	wyswietlStatus($tekstkomunikatu,0);
}


// wyświetla box ze statusem bądź błędem
function wyswietlStatus($statusid, $czyblad) {
	$("#status").html($statusid);
	if ($czyblad == 1) $("#status_box").css({  'color': '#c93030' }); else $("#status_box").css({  'color': '#1bb8ff' });
	$("#status_box").animate( {
	top: 0, height: "18px", opacity: 1
	}, 500);
}

// wyświetla błąd (koloruje na czerwień)
function indicateError($pola) {
	$($pola).css ( { 'border-color': 'red', 'border-style': 'dotted'} );
}

/* POCZĄTEK WALIDACJI FORMULARZA */

// sprawdza wszystkie pole w obrębie podanego w argumencie formularza - jeżeli któreś ma pustą wartość, koloruje na czerwień i zwraca błąd
function validateForm($form) {
$error = false;
$($form+' .input-box').each(function() {
if ($(this).val () == "") { indicateError($(this)); $error = true; };
} ); 
if ($error) { blad(1); return true; } else return false;
}


/* KONIEC FUNKCJI WALIDACJI FORMULARZA */

// animacja zamykania status boxu
function animateStatusBox() {
	$('#status_box').animate({ top:"-=15px",opacity:0 }, "slow");
}

$(document).ready ( function() {

//$('#status_box').animate({ top:"-=15px",opacity:0 }, "slow");

$(".input-box").focus( 
		function () {
		$(this).css( { 'border-color': '#ffc100' , 'border-style': 'solid'} );
		});
$(".input-box").blur( 
		function () {
		$(this).css( { 'border-color': '#bb9d40' , 'border-style': 'solid'} );
		}
	); 

$('#formularz').submit( function(){												 
	if (validateForm('#formularz')) return false;
});


$('#status_box, #status, #status_zamknij').click(function() {
	animateStatusBox();
});	

});