var ecal;  
var baseurl = getBaseURL();

function getBaseURL () {
	
	url = document.location.href.split("#");
	return url[0];
	
}
	
	

function init() { 

	YAHOO.namespace("example.calendar");
	
	YAHOO.example.calendar.cal1 = new YAHOO.widget.Calendar2up("YAHOO.example.calendar.cal1","cal1Container");
	
	/* Override the doCellMouseOver function (used for IE) to add row highlighting) */
	YAHOO.example.calendar.cal1.doCellMouseOver = function(e, cal) {
		var cell = this;
		var row = cell.parentNode;

		YAHOO.util.Dom.addClass(this, cal.Style.CSS_CELL_HOVER);
		YAHOO.util.Dom.addClass(row, "hilite-row");
	}

	/* Override the doCellMouseOut function (used for IE) to remove row highlighting) */
	YAHOO.example.calendar.cal1.doCellMouseOut = function(e, cal) {
		var cell = this;
		var row = cell.parentNode;

		YAHOO.util.Dom.removeClass(this, cal.Style.CSS_CELL_HOVER);
		YAHOO.util.Dom.removeClass(row, "hilite-row");
	}

	YAHOO.example.calendar.cal1.render();

	YAHOO.example.calendar.cal1.title = "Select your desired return date:";
	YAHOO.example.calendar.cal1.setChildFunction("onSelect", selectTheDate);

	ecal = YAHOO.example.calendar.cal1;
	
}

function selectTheDate () {
	
	sunday = new Date(ecal.getSelectedDates()[0].getYear(), 
		ecal.getSelectedDates()[0].getMonth(), 
		ecal.getSelectedDates()[0].getDate() -
		ecal.getSelectedDates()[0].getDay()
		);
	
	newhref = baseurl + "#" + (sunday.getMonth() + 1) + "-" +sunday.getDate();
	document.location.href = newhref;
	
}

YAHOO.util.Event.addListener(window, "load", init);