function dates_range()

				  {

				  	var $start_date = new Date(jQuery("#start_date").val());

				  	var $end_date = new Date(jQuery("#end_date").val());

				  	$start_date = jQuery("#start_date").val();	
					$end_date = jQuery("#end_date").val();	

					// workaround for IE date problems
				  	$start_date = jQuery("#start_date").val();	
					var start_year = $start_date.substr(0,4);
					var start_month = $start_date.substr(5,2);
					var start_day = $start_date.substr(8,2);
				  	$start_date = new Date(start_year,start_month,start_day);

				  	$end_date = jQuery("#end_date").val();	
					var end_year = $end_date.substr(0,4);
					var end_month = $end_date.substr(5,2);
					var end_day = $end_date.substr(8,2);
				  	$end_date = new Date(end_year,end_month,end_day);
							
				  	if($start_date > $end_date)				  	

				  	{
				  		var field = document.getElementById("start_date");

				  		return [[field, "Wybrano zły przedział dat."]];

				  	}


				  	else if($("#start_date").val() == $("#end_date").val())

				  	{
				  		//sprawdzamy poprawnosc przedzialu godzin
                         if(($("#start_notime").is(":checked")) || ($("#end_notime").is(":checked")))
                           {
                            return true;
                           } 

				  		else if($("#start_hour").val() > $("#end_hour").val())

				  		{

				  			var field = document.getElementById("start_hour");

				  			return [[field, "Wybrano zły przedział godzin."]];

				  		}

				  		else if($("#start_minute").val() > $("#end_minute").val())

				  		{

				  			var field = document.getElementById("start_minute");

				  			return [[field, "Wybrano zły przedział godzin."]];

				  		}

				  		else

				  		return true;	

				  		

				  	}				  	
				  	return true;

				  }
function start_hours(){
         if( ($("#start_hour").val() == '') || ($("#start_minute").val() == ''))

				  	{
                                    if($("#start_notime").is(":checked"))
                                    return true;
                                    else
                                    {
				  		var field = document.getElementById("start_hour");
				  		return [[field, "Wybierz godzinę przyjazdu."]];
                                    }
				  	}
				  	else
				  	return true;
				  	
				  	



}
function end_hours() {
         if( ($("#end_hour").val() == '') || ($("#end_minute").val() == ''))
         {
            if($("#end_notime").is(":checked"))
                                    return true;
                                    else
                                    {
                                    var field = document.getElementById("end_hour");
				  		return [[field, "Wybierz godzinę odjazdu."]];
				  		}
         }
         else
         return true;
         
}
		  	

			$(document).ready(function() {

				  				  

				  //przegladanie zdjec

				  $('a.lightbox').lightBox(); // Select all links with lightbox class

				  

				  //walidacja formularzy

				  $("#form_rezerwacja").RSV({

				    //onCompleteHandler: myOnComplete,

						errorFieldClass: "errorField",

						errorTextIntro:	"Wypełnij poprawnie formularz:",

				    rules: [

				      "required,start_date,Podaj datę przyjazdu.",

				      "required,end_date,Podaj datę odjazdu.",

				      "function,dates_range",
				      "function,start_hours",
				      "function,end_hours"
				

				    ]

				  });

				  

				  $("#form_kontakt").RSV({

				    //onCompleteHandler: myOnComplete,

						errorFieldClass: "errorField",

						errorTextIntro:	"Wypełnij poprawnie formularz:",

				    rules: [				      

				      "required,name,Podaj nazwisko i imię.",

				      "required,tel,Podaj telefon kontaktowy.",

				      "required,email,Podaj adres email.",

				      "required,info,Podaj treść zapytania."

				      

				    ]

				  });
  

				  //kontrola checkboxow

				  $("#start_notime").click(

					function()

					{

						if ($("#start_notime").is(":checked"))

						{

							$("#start_hour").attr("disabled","disabled");

							$("#start_minute").attr("disabled","disabled");

						}

						else

						{

							$("#start_hour").removeAttr("disabled");

							$("#start_minute").removeAttr("disabled");

						}	

					}

					);

					$("#end_notime").click(

					function()

					{

						if ($("#end_notime").is(":checked"))

						{

							$("#end_hour").attr("disabled","disabled");

							$("#end_minute").attr("disabled","disabled");

						}

						else

						{

							$("#end_hour").removeAttr("disabled");

							$("#end_minute").removeAttr("disabled");

						}	

					}

					);

			// set form submit button disabled
			$("#send_cond").attr("disabled", "disabled");				  

			$('#start_date, #end_date').change(function(){				  
				var enable_button;
				var date1 = $('#start_date').val();
				var date2 = $('#end_date').val();
				
				if(date1 !='' && date2 != '') {
					enable_button = true;
				}
				
				if(enable_button == true) {
					$("#send_cond").removeAttr("disabled");
					$("#send_cond").attr("value", "Wyślij");
				}
				
 			});
				$('input:first').trigger('change');
			});

