$(function() {
  
            date = $( "#arrivo" );
                date2 = $("#ritorno");
            var opt2 = {altField: "#alternate2",
			altFormat: "DD, d MM, yy",
                    dateFormat: "dd-mm-yy",
                    dayNames: ['Domenica','Lunedi', 'Martedi', 'Mercoledi', 'Giovedi', 'Venerdi', 'Sabato',],
                    dayNamesMin: ['Do','Lu', 'Ma', 'Me', 'Gi', 'Ve', 'Sa' ],
                    dayNamesShort: ['Dom','Lun', 'Mar', 'Mer', 'Gio', 'Ven', 'Sab' ],
                    firstDay: 1,
                    monthNames: ['Gennaio','Febbraio','Marzo','Aprile','Maggio','Giugno','Luglio','Agosto','Settembre','Ottobre','Novembre','Dicembre'],
                    monthNamesShort: ['Gen','Feb','Mar','Apr','Mag','Giu','Lug','Ago','Set','Ott','Nov','Dic']};
            var opt = {
                        altField: "#alternate",
			altFormat: "DD, d MM, yy",
                    dateFormat: "dd-mm-yy",
                    dayNames: ['Domenica','Lunedi', 'Martedi', 'Mercoledi', 'Giovedi', 'Venerdi', 'Sabato',],
                    dayNamesMin: ['Do','Lu', 'Ma', 'Me', 'Gi', 'Ve', 'Sa' ],
                    dayNamesShort: ['Dom','Lun', 'Mar', 'Mer', 'Gio', 'Ven', 'Sab' ],
                    firstDay: 1,
                    minDate: '09-06-2012',
                    maxDate: '08-09-2012',
                    monthNames: ['Gennaio','Febbraio','Marzo','Aprile','Maggio','Giugno','Luglio','Agosto','Settembre','Ottobre','Novembre','Dicembre'],
                    monthNamesShort: ['Gen','Feb','Mar','Apr','Mag','Giu','Lug','Ago','Set','Ott','Nov','Dic'],
                    showAnim: 'blind',
                    yearRange: '2011:2012',
                    beforeShowDay: function(d) {
    return [(d.getDay() == 6), ''];
 },
 onSelect: function (){$("#testoStart").addClass("tit").attr("style" , "").html("Data di Partenza ?");if($("#week").val()>0){ calcDateReturn(); }if($("#alternate").is(":hidden")){ $("#data").animate({"width" : "+=188"},1000,function(){$("#sett").show();$("#alternate").show("slow");});}}
                };
		
                date2.datepicker(opt2);
                date.datepicker(opt);
               // date(opt);
             //  date.datepicker( "option", "numberOfMonths", [1,3] );
             $("#arrivo").bind("change",calcDateReturn);
            
            $(".n").bind("click",function(){
             $("#week").val(parseInt($(this).html()));
             $("#rit").show();
             $(".n").removeClass("nH");
             $(this).addClass("nH");
             calcDateReturn();
             $("#adu,#ba").show();
           
            });
            
            $(".b").bind("click",function(){
             $("#bambini").val(parseInt($(this).html()));
            
             $(".b").removeClass("bH");
             $(this).addClass("bH");
             calcDateReturn();
           
            });
            
            $(".d").bind("click",function(){
             $("#adulti").val(parseInt($(this).html()));
            // $("#rit").show();
             $(".d").removeClass("dH");
             $(this).addClass("dH");
             calcDateReturn();
           
            });
            
	});
       
         function calcDateReturn(){
              
             var arr = parseInt($("#week").val())*7;

             if(date.val() == "" || date.val() == null || !arr ){
              
                 
             }else{
               
                  var c = $("#arrivo").datepicker("getDate",'+'+arr+'d');
                  c.setDate(c.getDate()+arr);
                  $("#ritorno").datepicker("setDate",c);
                    var end = $("#ritorno").val();
                    var start = $("#arrivo").val();
                    var ad = $("#adulti").val();
                    var bm = $("#bambini").val();
                    
                    $("#Jtb-loader").load("MoDprenota.php",{andata: start , ritorno: end, adulti : ad , bambini : bm});
                   
             }

                }
                       
             
     
