/*!
 * Autor zwirek
 * zwirek@inetservis.com.pl
 * for jquery 2011
 */
function checkReserwationForm(autoNr)
{
	var f = document.ReserwationForm;
	
	var alert_message = "Przepraszamy wystąpił błąd.\n";
	var error = 0;	
	if (f.name.value.length < 2){
		alert_message += "Proszę podać imię i nazwisko !\n";
		error = 1;
	}
	if (f.city.value.length < 1){
		alert_message += "Proszę podać nazwę miejscowości!\n";
		error = 1;
	}
	if (f.kod.value.length < 1){
		alert_message += "Proszę podać kod pocztowy!\n";
		error = 1;
	}
	if (error == 1){
		alert(alert_message);
	}
	else{
		$.ajax({
			type:"POST",
			url:"rezerwacja.php",
			data:({"imie" : document.ReserwationForm.name.value,
				"ul" : document.ReserwationForm.ul.value,
				"city" : document.ReserwationForm.city.value,
				"kod" : document.ReserwationForm.kod.value,
				"ul" : document.ReserwationForm.ul.value,
				"nr" : document.ReserwationForm.nr.value,
				"resTime" : document.ReserwationForm.resTime.value,
				"autoNr" : autoNr}),
			async:false,
			success:function(html){				
				showFullGraph(html, autoNr);
				showCalendarSolo (html-43200, autoNr);
				alert ("Formularz został poprawnie wysłany\nProśimy o potwierdzenie rezerwacji terminu w ciągu 48 h.")
			}
		});
	}	
}
function showReservationForm (id, autoNr){
	var divfileName = 'rezerwacja.php';
	$.ajax({
		type:"POST",
		url:divfileName,
		data:({graphFullId: id, autoNr: autoNr}),
		async:false,
		success:function(html){		
		$("#RefForm").html(html);
		$("#RefForm").show('slow');	}
	});
}
function showFullGraph(id, autoNr){
	var divfileName = 'rezerwacja.php';
	$.ajax({
		type:"POST",
		url:divfileName,
		data:({graphId: id, autoNr: autoNr}),
		async:false,
		success:function(html){			
			$("#Graph").slideToggle('slow',function (){	$(this).html(html);	$(this).slideToggle('slow');});	}
	});
}
function showCalendarSolo (id, autoNr){	
	var divfileName = 'rezerwacja.php';
	$.ajax({
		type:"POST",
		url:divfileName,
		data:({i: id, autoNr: autoNr}),
		async:false,
		success:function(html){
			$("#calendarFull").animate({opacity:0.0},2000,function(){$(this).html(html); $(this).animate({opacity:1.0},2000)});
		}
	});
}
function showCalendar (id, autoNr){	
	var divfileName = 'rezerwacja.php';
	$.ajax({
		type:"POST",
		url:divfileName,
		data:({i: id, autoNr: autoNr}),
		async:false,
		success:function(html){
			$("#calendarFull").animate({opacity:0.0},2000,function(){$(this).html(html); $(this).animate({opacity:1.0},2000)});
			$("#Graph").animate({opacity:0.0},2000,function(){$(this).html(''); $(this).animate({opacity:1.0},1)});
		}
	});
}

$(document).ready(function () {
    
    $('#nav li').hover(
        function (){
        	$('ul', this).stop(true, true).slideDown('fast');
        },
        function () {
        	$('ul', this).stop(true, true).slideUp('slow'); 
        }
    ); 
    $("a#single_image").fancybox();
});

function slideNews(id){
	var divfileName = 'boxNews.php';
		$.ajax({
			type:"POST",
			url:divfileName,
			data:({i: id}),
			async:false,
			success:function(html){
				$("#slideAktualnosci").animate({opacity:0.0},2000,function(){$(this).html(html); $(this).animate({opacity:1.0},2000)});
			}
		});
}

function slideBody(_var_St, Mid, dzial ){
	var divfileName = 'note.php';
		$.ajax({
			type:"POST",
			url:divfileName,
			data:({_var_St:_var_St, MId:Mid, dzial:dzial }),
			async:false,
			success:function(html){
				$("#boxBody").animate({opacity:0.0},1000,function(){$(this).html(html); $(this).animate({opacity:1.0},1000)});
			}
		});
}
function slideBodySearch(_var_St, searchText ){
	var divfileName = 'note.php';
		$.ajax({
			type:"POST",
			url:divfileName,
			data:({_var_St:_var_St, searchText:searchText }),
			async:false,
			success:function(html){
				$("#boxBody").animate({opacity:0.0},1000,function(){$(this).html(html); $(this).animate({opacity:1.0},1000)});
			}
		});
}


function showNoteSearch(id, mid, dzial, _var_St,searchText){
	var divfileName = 'note.php';
		$.ajax({
			type:"POST",
			url:divfileName,
			data:({MId: mid, Id:id, dzial:dzial,_var_St:_var_St,searchText:searchText}),
			async:false,
			success:function(html){
				$("#boxBody").animate({opacity:0.0},1000,function(){$(this).html(html); $(this).animate({opacity:1.0},1000)});
			}
		});
}
function showNote(id, mid, dzial, _var_St){
	var divfileName = 'note.php';
		$.ajax({
			type:"POST",
			url:divfileName,
			data:({MId: mid, Id:id, dzial:dzial,_var_St:_var_St}),
			async:false,
			success:function(html){
				$("#boxBody").animate({opacity:0.0},1000,function(){$(this).html(html); $(this).animate({opacity:1.0},1000)});
			}
		});
}


function formularzKontaktowy()
{
	var f = document.startFormularz;
	
	var dobryEmail=/^[^@]+@([a-z0-9\-]+\.)+[a-z]{2,4}$/i;
	var alert_message = "Przepraszamy wystąpił błąd.\n";
	var error = 0;	
	if (f.imie.value.length < 2){
		alert_message += "Proszę podać imię i nazwisko !\n";
		error = 1;
	}
	if (!dobryEmail.test(f.email.value)){
		alert_message += "błędny adres adres email\n";
		error = 1;
	}
	if (f.email.value.length < 1){
		alert_message += "Podaj adres e-mail!\n";
		error = 1;
	}
	if (f.message.value.length < 1){
		alert_message += "Wpisz treść wiadomości!\n";
		error = 1;
	}
	if (error == 1){
		alert(alert_message);
	}
	else{
		
		$.ajax({
			type:"POST",
			url:"sendMessage.php",
			data:({"imie" : document.startFormularz.imie.value,
				"email" : document.startFormularz.email.value,
				"message" : document.startFormularz.message.value}),
			async:false,
			success:function(){
				$("#boxFormularz").hide('slow',function (){
				$(this).html('<img alt="" src="gfx/box-formularz-kontaktowy.gif" ><br /><br />Wiadomość została pomyślnie wysłana');
				$(this).show('slow');});
				
			}
		});
	}	
}
