Date.format = 'yyyy/mm/dd';

$(function()
{
	$('.date-pick').datePicker()
	$('#start_date1').bind(
		'dpClosed',
		function(e, selectedDates)
		{
			var d = selectedDates[0];
			if (d) {
				d = new Date(d);
				$('#end_date1').dpSetStartDate(d.addDays(1).asString());
			}
		}
	);
	$('#end_date1').bind(
		'dpClosed',
		function(e, selectedDates)
		{
			var d = selectedDates[0];
			if (d) {
				d = new Date(d);
				$('#start_date1').dpSetEndDate(d.addDays(-1).asString());
			}
		}
	);
});

$(document).ready(function(){
	$.validator.setDefaults({
		submitHandler: function() {
			  $.post("http://peklo.gartproject.com/send_form.php", {
					 name: $('#name').val(),
					 street: $('#street').val(),
					 city: $('#city').val(),
					 country: $('#country').val(),
					 plusbed: $('#plusbed').val(),
					 breakfast: $('#breakfast').val(),
					 zip: $('#zip').val(),
					 phone: $('#phone').val(),
					 mail: $('#mail').val(),
					 adult: $('#adult').val(),
					 children: $('#children').val(),
					 
					 start_date1: $('#start_date1').val(),
					 end_date1: $('#end_date1').val(),
					 
					 basicroom1: $('#basicroom1').val(),
					 basicroom2: $('#basicroom2').val(),
 					 basicroom2for1: $('#basicroom2for1').val(),
					 apartmanbasic: $('#apartmanbasic').val(),
					 apartmantower: $('#apartmantower').val(),
					 comment: $('#comment').val()
				},
			  function(data){
				if(data != 'error'){ 
				  $.blockUI({ 
					css: {border: 'none',padding: '15px',backgroundColor: '#000','-webkit-border-radius': '10px','-moz-border-radius': '10px',opacity: '.5',color: '#fff'},
					message:'<h3>'+data+'<\/h3>',
					timeout: 3000 
				});
				window.setTimeout("window.location.reload(true)",3000);
				}
				else {
					//document.getElementById('regform').reset();
					/*
					document.getElementById('name').value = '';
					document.getElementById('street').value = '';
					document.getElementById('city').value = '';
					document.getElementById('zip').value = '';
					document.getElementById('phone').value = '';
					document.getElementById('mail').value = '';
					document.getElementById('start_date1').value = '';
					document.getElementById('end_date1').value = '';
					*/
					//
					$.blockUI({ 
					css: {border: 'none',padding: '15px',backgroundColor: '#000','-webkit-border-radius': '10px','-moz-border-radius': '10px',opacity: '.5',color: '#fff'},
					message:'<h3>'+data+'<\/h3>',
					timeout: 3000 
				});
					}
			  });
		}
	});
	
	var validator = $("#regform").validate({
		rules: {
			start_date1: {required: true,date:true},
			end_date1: {required: true,date:true},

			name: {required: true,minlength: 5},
			phone: {required: true,minlength: 8},
			country: {required: true},
			mail: {required: true,email: true}
		},
		errorPlacement: function(error, element) {
			 if ( element.is(":checkbox") )error.appendTo ( element.parent() ); 
			 else error.appendTo( element.parent() );			
		  },
		success: function(label) {
			label.html("&nbsp;").addClass("checked");
		}
	});
});


/***  Simple jQuery Slideshow Script -  Released by Jon Raasch (jonraasch.com) under FreeBSD license ***/
function slideSwitch() {
    var $active = $('#slideshow IMG.active');

    if ( $active.length == 0 ) $active = $('#slideshow IMG:last');

    // use this to pull the images in the order they appear in the markup
    var $next =  $active.next().length ? $active.next()
        : $('#slideshow IMG:first');
    // uncomment the 3 lines below to pull the images in random order
    // var $sibs  = $active.siblings();
    // var rndNum = Math.floor(Math.random() * $sibs.length );
    // var $next  = $( $sibs[ rndNum ] );
    $active.addClass('last-active');

    $next.css({opacity: 0.0})
        .addClass('active')
        .animate({opacity: 1.0}, 1000, function() {
            $active.removeClass('active last-active');
        });
}

$(function() {
    setInterval( "slideSwitch()", 5000 );
});

