
$(document).ready(function() {
           
	$('#new-boxprenotazione').cornerz({
		radius: 8
	});

	if (lang == 'en') lang = 'en-GB';
	$.datepicker.setDefaults($.datepicker.regional[lang]);
            
            
	$( "#data1" ).datepicker({
		showOn: "button",
		dateFormat: 'dd/mm/yy',
		minDate: 1,
		constrainInput: true,
		buttonImage: "/engines/jadranka/images/datapiker.jpg",
		buttonImageOnly: true,
		onSelect: function () {
			var d = $(this).datepicker('getDate');
			var d1 = $("#data2").datepicker('getDate');
			if (d >= d1)
			{
				d1.setTime(d.getTime() + 24*3600000);   //aggiungo un giorno, in millisecondi...
				$("#data2").datepicker('setDate', d1);
			}
		}
	});
	$( "#data2" ).datepicker({
		showOn: "button",
		dateFormat: 'dd/mm/yy',
		minDate: 1,
		constrainInput: true,
		buttonImage: "/engines/jadranka/images/datapiker.jpg",
		buttonImageOnly: true,
		onSelect: function (dateText, inst) {
			var d = $('#data1').datepicker('getDate');
			var d1 = $(this).datepicker('getDate');
			if (d >= d1)
			{
				d1.setTime(d.getTime() + 24*3600000);   //aggiungo un giorno, in millisecondi...
				$(this).datepicker('setDate', d1);
			}
		}
	});
	$( "#data3" ).datepicker({
		showOn: "button",
		dateFormat: 'dd/mm/yy',
		minDate: 1,
		constrainInput: true,
		buttonImage: "/engines/jadranka/images/datapiker.jpg",
		buttonImageOnly: true,
		onSelect: function () {
			var d = $(this).datepicker('getDate');
			var d1 = $("#data4").datepicker('getDate');
			if (d >= d1)
			{
				d1.setTime(d.getTime() + 24*3600000);   //aggiungo un giorno, in millisecondi...
				$("#data4").datepicker('setDate', d1);
			}
		}
	});
	$( "#data4" ).datepicker({
		showOn: "button",
		dateFormat: 'dd/mm/yy',
		minDate: 1,
		constrainInput: true,
		buttonImage: "/engines/jadranka/images/datapiker.jpg",
		buttonImageOnly: true,
		onSelect: function (dateText, inst) {
			var d = $('#data3').datepicker('getDate');
			var d1 = $(this).datepicker('getDate');
			if (d >= d1)
			{
				d1.setTime(d.getTime() + 24*3600000);   //aggiungo un giorno, in millisecondi...
				$(this).datepicker('setDate', d1);
			}
		}
	});
            
            
	$("#kid-switch1").change(function(){
                    
		updateRoomData(this, '1');

	});
	$("#kid-switch2").change(function(){
                    
		updateRoomData(this, '2');

	});
            
	$("#kid-switch3").change(function(){
                    
		updateRoomData(this, '3');

	});
            
            
            
	$("#new-room").change(function(){
                
		updateRooms(this);
                
	});

	$("#kid-switch2_1").change(function(){

		updateRoomData2(this, '1');

	});
	$("#kid-switch2_2").change(function(){

		updateRoomData2(this, '2');

	});

	$("#kid-switch2_3").change(function(){

		updateRoomData2(this, '3');

	});



	$("#new-room2").change(function(){

		updateRooms2(this);

	});
            
            
            
            
	$(".new-tabs-booking .new-icon2-active a").live("click",function(){
		$(".new-tabs-booking .new-icon1 a").attr("href","#");
		$(".new-tabs-booking .new-icon1").addClass("new-icon1-active").removeClass("new-icon1");
		$(".new-tabs-booking .new-icon2-active").addClass("new-icon2").removeClass("new-icon2-active");
		$(".new-tabs-booking .new-icon2 a").removeAttr("href");
		$('#new-inner-boxprenotazione .scelta-rapida').hide();
        $('#new-inner-boxprenotazione .scelta-guidata').show();

	});
            
            
	$(".new-tabs-booking .new-icon1-active a").live("click",function(){
		$(".new-tabs-booking .new-icon2 a").attr("href","#");
		$(".new-tabs-booking .new-icon2").addClass("new-icon2-active").removeClass("new-icon2");
		$(".new-tabs-booking .new-icon1-active").addClass("new-icon1").removeClass("new-icon1-active");
		$(".new-tabs-booking .new-icon1 a").removeAttr("href");
		$('#new-inner-boxprenotazione .scelta-guidata').hide();
        $('#new-inner-boxprenotazione .scelta-rapida').show();
                   
	});


	$('a.wait').live('click', function(){
		showWait();
	});
});

function showWait()
{
	//$('#dialog-wait').empty();
	//$('#dialog-wait').load('/nodes/bol/wait.jsp?lang='+lang, function() {
		$('#dialog-wait').modal({
			containerCss:{
				height:480,
				padding:0,
				width:725
			},
			opacity: 80,
			//overlayClose: true,
			closeClass: "modalClose",
			onShow: function() {	
				startPuntini();
			},
			onClose: function() {
				$.modal.close();   //va chiamata per forza!
				$('#dialog-wait').hide();
				stopPuntini();
			}
		});
	//});
}

var WAIT_TIMING = 1000;
var counter = 0;
var activePuntini = false;
function startPuntini()
{
	if (!activePuntini)
	{
		clearPuntini();
		activePuntini = true;
		setTimeout('updatePuntini()', WAIT_TIMING);
	}
}

function stopPuntini()
{
	if (activePuntini)
	{
		activePuntini = false;
		clearPuntini();
	}
}

function updatePuntini() {
	if (activePuntini)
	{
		if (counter >= 10)
		{
			clearPuntini();
		}
		else    
		{
			$('#puntini').text($('#puntini').text()+'.');
			counter++;
		}
			
		setTimeout('updatePuntini()', WAIT_TIMING);
	}
}

function clearPuntini() {
	$('#puntini').empty();
	counter = 0;
}


function updateRooms(sel)
{
		nroom =  $(sel).val();

	$(".new-box-camera").each(function(k){

		if(k>nroom-1){
			$("#room"+k).hide();
		}else{
			$("#room"+k).show();
		}
	});
}

function updateRooms2(sel)
{
		nroom =  $(sel).val();

	$(".new-box-camera").each(function(k){

		if(k>nroom-1){
			$("#room2_"+k).hide();
		}else{
			$("#room2_"+k).show();
		}
	});
}

function updateRoomData(sel, num)
{
	valore =  $(sel).val();
	$("#kid-age"+num+" div").each(function(i){

		if(i>valore-1){
			$(this).hide();
		}else{
			$(this).show();
		}
	});
}

function updateRoomData2(sel, num)
{
	valore =  $(sel).val();
	$("#kid-age2_"+num+" div").each(function(i){

		if(i>valore-1){
			$(this).hide();
		}else{
			$(this).show();
		}
	});
}

function updateSelectsOnload()
{
	/** chiamate all'onload della pagina, per preimpostare la form! **/
	updateRoomData(document.getElementById('kid-switch1'), '1');
	updateRoomData(document.getElementById('kid-switch2'), '2');
	updateRoomData(document.getElementById('kid-switch3'), '3');

	updateRooms(document.getElementById('new-room'));
}
