window.onload = function() {

Shadowbox.init();
window.setTimeout('startscroll()',5000);


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 get(w){
 return document.getElementById(w);
}
JQ = $;  //rename $ function

	JQ(document).ready(function(){
				JQ("#parent4").wslide({
					width: 390,
					height:94,
					autolink: false,
					fade: true,
					duration: 2000

					
				});

								});


function isIE(){
return /msie/i.test(navigator.userAgent) && !/opera/i.test(navigator.userAgent);
}

if(!isIE()){
 HTMLElement.prototype.click = function() {
 var evt = this.ownerDocument.createEvent('MouseEvents');
 evt.initMouseEvent('click', true, true, this.ownerDocument.defaultView, 1, 0, 0, 0, 0, false, false, false, false, 0, null);
 this.dispatchEvent(evt);
 }
}


var ix=1;
function startscroll(){
 document.getElementById('l'+ix).click();				
 ix++;
 if(ix>(document.getElementById('parent4').getElementsByTagName("li").length)){ix=1;}
 window.setTimeout('startscroll()',5000);
}
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("index.html")[0];
	document.getElementById('chkInMese').value=dal.split("index.html")[1];
	document.getElementById('chkInAnno').value=dal.split("index.html")[2];
	document.getElementById('chkOutGiorno').value=al.split("index.html")[0];
	document.getElementById('chkOutMese').value=al.split("index.html")[1];
	document.getElementById('chkOutAnno').value=al.split("index.html")[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;}
	window.open(url,'',''); return false;
}
