<html xmlns="http://www.w3.org/1999/xhtml">
<title>Test Calendar</title>
<style>
body, td, div, span {
	font-family:Verdana, Arial, Helvetica, sans-serif;
	font-size:10px;
}
</style>
<script type="text/javascript">
var djConfig = {
	isDebug: true
};
</script>
<script type="text/javascript" src="../dojo/dojo.js"></script>
<script type="text/javascript">
dojo.require("mywidgets.widget.Calendar");
dojo.require("mywidgets.widget.Timezones");
dojo.addOnLoad(init);
var oCalendar;

function init(){
	oCalendar = dojo.widget.byId("dojoCalendar");
	oCalendar.setTimeZones(mywidgets.widget.timezones);
	oCalendar.selectedtimezone = dojo.io.cookie.getObjectCookie("DCTZ");
	oCalendar.onSetTimeZone = widgetTimeZoneChanged;
	oCalendar.changeEventTimes = true;
	oCalendar.onEventChanged = widgetEventChanged;
	oCalendar.setAbleToCreateNew(true);
	oCalendar.onNewEntry = widgetNewEntry;
	oCalendar.onValueChanged = widgetValueChanged;
	widgetValueChanged(new Date());
}

function widgetValueChanged(dateObj){
	dojo.require("dojo.date.serialize");
	var d1s = new Date(dateObj);
	d1s.setDate(1);
	d1s.setHours(14,0,0,0);
	var d1e = new Date(dateObj);
	d1e.setDate(1);
	d1e.setHours(14,30,0,0);
	var d15s = new Date(dateObj);
	d15s.setDate(15);
	var d15e = new Date(dateObj);
	d15e.setDate(15);
	var d28s = new Date(dateObj);
	d28s.setDate(28);
	d28s.setHours(16,40,0,0);
	var d28e = new Date(dateObj);
	d28e.setDate(28);
	d28e.setHours(18,30,0,0);
	var entries = {
		"id1": {
			starttime: dojo.date.toRfc3339(d1s),
			endtime: dojo.date.toRfc3339(d1e),
			allday: false,
			repeated: false,
			title: "Title 1",
			url: "",
			body: "This is the body of entry with id: id1 and title: Title 1",
			attributes: {
				Location: "My Galactic Headquarters",
				Chair: "John Doe"
			},
			type: ["meeting","appointment"]
		},
		"id2": {
			starttime: dojo.date.toRfc3339(d15s),
			endtime: dojo.date.toRfc3339(d15e),
			allday: true,
			repeated: false,
			title: "Title 2",
			url: "",
			body: "This is the body of entry with id: id2 and title: Title 2",
			attributes: {
				Location: "Somewhere"
			},
			type: ["appointment","super"]
		},
		"id3": {
			starttime: dojo.date.toRfc3339(d28s),
			endtime: dojo.date.toRfc3339(d28e),
			allday: false,
			repeated: false,
			title: "Title 3",
			url: "",
			body: "This is the body of entry with id: id3 and title: Title 3",
			attributes: "",
			type: ["reminder"]
		}
	}
	oCalendar.setCalendarEntries(entries);
}

function widgetEventChanged(eventId,eventObject){
	var sReturn = "id " + eventId + "=\n";
	for(var i in eventObject){
		if(typeof(eventObject[i]) != "object"){
			sReturn += i + " = " + eventObject[i] + "\n";
		}else{
			oChildObject = eventObject[i];
			var sChildReturn = "";
			var iNum = 0;
			for(var j in oChildObject){
				if(iNum > 0){
					sChildReturn += ", ";
				}
				sChildReturn += j + ": " + oChildObject[j];
				iNum++;
			}
			sReturn += i + " = " + sChildReturn + "\n";
		}
	}
	alert(sReturn);
	//Call script to update back-end db
	oCalendar.refreshScreen();
}

function widgetNewEntry(eventObject){
	var sReturn = "";
	for(var i in eventObject){
		if(typeof(eventObject[i]) != "object"){
			sReturn += i + " = " + eventObject[i] + "\n";
		}else{
			oChildObject = eventObject[i];
			var sChildReturn = "";
			var iNum = 0;
			for(var j in oChildObject){
				if(iNum > 0){
					sChildReturn += ", ";
				}
				sChildReturn += j + ": " + oChildObject[j];
				iNum++;
			}
			sReturn += i + " = " + sChildReturn + "\n";
		}
	}
	alert(sReturn);
	//Call script to add to back-end db
	oCalendar.refreshScreen();
}

function widgetTimeZoneChanged(){
	//Setting cookie
	if(oCalendar.selectedtimezone == ""){
		dojo.io.cookie.deleteCookie("DCTZ");
	}else{
		dojo.io.cookie.setObjectCookie("DCTZ",oCalendar.selectedtimezone,3650);
	}
}

function setLocale(sLocale){
	oCalendar.lang = sLocale;
	oCalendar._preInitUI(new Date(oCalendar.value));
}
</script>
</head>
<body>
<div style="width:800px; height:400px; background-color:#cccccc; overflow:auto;">
	<div id="dojoCalendar" dojoType="mywidgets:calendar"></div>
</div>
</body>
</html>
