

Calendar.setup({
            inputField  : "checkin",         // ID of the input field
            ifFormat    : "%Y-%m-%d",    // the date format
            button      : "ImgChkIn",       // ID of the button
            electric    : false,
            onUpdate    : function(){
		document.getElementById('chkInAnno').value=arguments[0].date.getFullYear();
		document.getElementById('chkInMese').selectedIndex=arguments[0].date.getMonth();
		document.getElementById('chkInGiorno').selectedIndex=arguments[0].date.getDate()-1;
                            checkDate1();
                          }
                          
});
Calendar.setup({
            inputField  : "checkout",         // ID of the input field
            ifFormat    : "%Y-%m-%d",    // the date format
            button      : "ImgChkOut",       // ID of the button
            electric    : false,
            onUpdate    : function(){
		document.getElementById('chkOutAnno').value=arguments[0].date.getFullYear();
		document.getElementById('chkOutMese').selectedIndex=arguments[0].date.getMonth();
		document.getElementById('chkOutGiorno').selectedIndex=arguments[0].date.getDate()-1;
                            checkDate();
                          }
});

function checkDate(){
   var anno = document.getElementById('chkInAnno').value;
   var mese = document.getElementById('chkInMese').selectedIndex;
   var giorno = document.getElementById('chkInGiorno').value;
   
   var annoOut = document.getElementById('chkOutAnno').value;
   var meseOut = document.getElementById('chkOutMese').selectedIndex;
   var giornoOut = document.getElementById('chkOutGiorno').value;
   var chkIn=new Date(anno,mese,giorno);
   var chkOut=new Date(annoOut,meseOut,giornoOut);
   
   var g=Math.abs(parseInt((chkOut.getTime()-chkIn.getTime())/1000/60/60/24));
  
   document.getElementById('notti').value=g;
   get('checkin').value=get('chkInAnno').value+"-"+get('chkInMese').value+"-"+get('chkInGiorno').value;
    get('checkout').value=get('chkOutAnno').value+"-"+get('chkOutMese').value+"-"+get('chkOutGiorno').value;
}

function checkDate1(){
   var anno = document.getElementById('chkInAnno').value;
   var mese = document.getElementById('chkInMese').selectedIndex;
   var giorno = document.getElementById('chkInGiorno').value;
   var g=1;
   g=g*1000*60*60*24;
   var chkIn=new Date(anno,mese,giorno);
   var chkOut=new Date(chkIn.getTime()+g);
   document.getElementById('chkOutAnno').value=chkOut.getFullYear();
   document.getElementById('chkOutMese').selectedIndex=chkOut.getMonth();
   document.getElementById('chkOutGiorno').selectedIndex=parseInt(chkOut.getDate(),10)-1;
   get('checkin').value=get('chkInAnno').value+"-"+get('chkInMese').value+"-"+get('chkInGiorno').value;
    get('checkout').value=get('chkOutAnno').value+"-"+get('chkOutMese').value+"-"+get('chkOutGiorno').value;
}

function checkDate2(){
   var anno = document.getElementById('chkInAnno').value;
   var mese = document.getElementById('chkInMese').selectedIndex;
   var giorno = document.getElementById('chkInGiorno').value;
   var g=document.getElementById('notti').value;
   g=g*1000*60*60*24;
   var chkIn=new Date(anno,mese,giorno);
   var chkOut=new Date(chkIn.getTime()+g);
   document.getElementById('chkOutAnno').value=chkOut.getFullYear();
   document.getElementById('chkOutMese').selectedIndex=chkOut.getMonth();
   document.getElementById('chkOutGiorno').selectedIndex=parseInt(chkOut.getDate(),10)-1;
   get('checkin').value=get('chkInAnno').value+"-"+get('chkInMese').value+"-"+get('chkInGiorno').value;
    get('checkout').value=get('chkOutAnno').value+"-"+get('chkOutMese').value+"-"+get('chkOutGiorno').value;
}

function submitoffer(p){
	dal=p.split("-")[0];
	al=p.split("-")[1];
	document.getElementById('chkInGiorno').value=dal.split("/")[0];
	document.getElementById('chkInMese').value=dal.split("/")[1];
	document.getElementById('chkInAnno').value=dal.split("/")[2];
	document.getElementById('chkOutGiorno').value=al.split("/")[0];
	document.getElementById('chkOutMese').value=al.split("/")[1];
	document.getElementById('chkOutAnno').value=al.split("/")[2];
	submitform();
}

function submitform(){
	get('checkin').value=get('chkInAnno').value+"-"+get('chkInMese').value+"-"+get('chkInGiorno').value;
    get('checkout').value=get('chkOutAnno').value+"-"+get('chkOutMese').value+"-"+get('chkOutGiorno').value;
	url=document.forms[0].action+"?";
	url+="checkin="+document.forms[0].checkin.value;
	url+="&checkout="+document.forms[0].checkout.value;
	url+="&id_struttura="+document.forms[0].id_struttura.value;
	if(document.forms[0].lang){url+="&lang="+document.forms[0].lang.value;}
	Shadowbox.init();
	Shadowbox.open({
		 width: 1000,
	     height: 600,
	     title: "",
         type: "iframe",
         content: url
 	});
}