var calendar;
window.onload=function() {
	calendar=new DCalendar('calendar_control');
	calendar.allowPastDates=true;
	calendar.selectedDayBackgroundColor='rgb(51,102,204)';
	calendar.mouseOverDayBackgroundColor='rgb(255,255,204)';
	var locString=window.location.toString(),
		dateParamStartIndex=locString.indexOf('d=');
	if (dateParamStartIndex!==-1) {
		var dateParamEndIndex=locString.indexOf('&',dateParamStartIndex);
		if(dateParamEndIndex===-1){dateParamEndIndex=locString.length;}
		var selectedDate=locString.substring(dateParamStartIndex+2,dateParamEndIndex),
			splitDate=selectedDate.split('-');
		calendar.date.setMonth(splitDate[1]-1);
		calendar.date.setDate(splitDate[2]);
		calendar.date.setYear(splitDate[0]);
	}
	calendar.ondateclick = function() {
		var curDate=this.date,
			newDateParam='d='+curDate.getFullYear()+'-'+(curDate.getMonth()+1)+'-'+curDate.getDate();
		if (window.location.toString().indexOf('d=')>-1) {
			window.location=window.location.toString().replace(/([&?])d=[^&]*/,"$1"+newDateParam);
		} else {
			window.location=window.location.toString()+(window.location.toString().indexOf('?')!==-1?'&':'?')+newDateParam;
		}
	};
	calendar.draw();
};
function cancelBubbleUp(event) {
	if (!event) { event=window.event; }
        if(event.stopPropagation){
       		event.stopPropagation();
        }
	event.cancelBubble=true;
}
