//create the namespace object for this example
YAHOO.namespace("yuibook.calendar");

var data = new Date();
var gg, mm, aaaa;
gg = data.getDate() + "/";
mm = data.getMonth() + 1 + "/";
aaaa = data.getFullYear();

//define the lauchCal function which creates the calendar
YAHOO.yuibook.calendar.launchCalArrivo = function() {
      
	//create the calendar object, specifying the container and a literal configuration object
	var myCal_arrivo = new YAHOO.widget.Calendar("mycal_arrivo", "mycal_arrivo_container", {mindate: "" + mm + gg + aaaa});
	        
	//configure the calendar to begin on Monday
	myCal_arrivo.cfg.setProperty("start_weekday", "1");

	//draw the calendar on screen
	myCal_arrivo.render();
	        
	//hide it again straight away
	myCal_arrivo.hide();
	        
	//define the showCal function which shows the calendar
	var showCal = function() {
	    //show the calendar
	    myCal_arrivo.show();
	}

	//attach listener for click event on calendar icon
	YAHOO.util.Event.addListener("cal_arrivo", "click", showCal);

	        
	//define the ripDate function which pulls the selected date from the control and places it in the form field
	var ripDate = function(type, args) {
	    //get the date components
	    var dates = args[0];
	    var date = dates[0];
	    var theYear = date[0];
	    var theMonth = date[1];
	    var theDay = date[2];

	    //create the formatted date string
	    var theDate = theDay + "/" + theMonth + "/" + theYear;

	    //get a reference to the text field
	    var field = YAHOO.util.Dom.get("arrive");

	    //insert the formatted date into the text field
	    field.value = theDate;

	    //hide the calendar once more
	    myCal_arrivo.hide();
	          
	}

	//subscribe to the select event on Calendar cells
	myCal_arrivo.selectEvent.subscribe(ripDate);
}



YAHOO.yuibook.calendar.launchCalPartenza = function() {
      
	//create the calendar object, specifying the container and a literal configuration object
	var myCal_partenza = new YAHOO.widget.Calendar("mycal_partenza","mycal_partenza_container", {mindate: "" + mm + gg + aaaa});
	        
	//configure the calendar to begin on Monday
	myCal_partenza.cfg.setProperty("start_weekday", "1");

	//draw the calendar on screen
	myCal_partenza.render();
	        
	//hide it again straight away
	myCal_partenza.hide();
	        
	//define the showCal function which shows the calendar
	var showCal = function() {
	    //show the calendar
	    myCal_partenza.show();
	}

	//attach listener for click event on calendar icon
	YAHOO.util.Event.addListener("cal_partenza", "click", showCal);

	        
	//define the ripDate function which pulls the selected date from the control and places it in the form field
	var ripDate = function(type, args) {
	    //get the date components
	    var dates = args[0];
	    var date = dates[0];
	    var theYear = date[0];
	    var theMonth = date[1];
	    var theDay = date[2];

	    //create the formatted date string
	    var theDate = theDay + "/" + theMonth + "/" + theYear;

	    //get a reference to the text field
	    var field = YAHOO.util.Dom.get("depart");

	    //insert the formatted date into the text field
	    field.value = theDate;

	    //hide the calendar once more
	    myCal_partenza.hide();
	          
	}

	//subscribe to the select event on Calendar cells
	myCal_partenza.selectEvent.subscribe(ripDate);
}

      
//create calendar on page load
YAHOO.util.Event.onDOMReady(YAHOO.yuibook.calendar.launchCalArrivo);
YAHOO.util.Event.onDOMReady(YAHOO.yuibook.calendar.launchCalPartenza);