/* Copyright 2009 Palm, Inc.  All rights reserved. */

var CalendarEvent = Class.create({
	initialize: function(crudJson) {
		this.startTimestamp		= undefined;
		this.endTimestamp		= undefined;
		this.allDay				= false;
		this.subject			= "";	// Do not default this to anything but null or an empty string
		this.location			= "";
		this.note				= "";
		this.timeZoneId			= "";
		this.rrule				= "";
		this.endValidity		= 0;
		this.alarm				= "none";	// Do NOT Localize
		
		this.fromCrudJson(crudJson);
	},
	
	// Parses the json and sets the values of the CalendarEvent based on the json
	fromCrudJson: function(json) {
		if (json) {
			Mojo.Log.info("CalendarEvent: fromCrudJson " + Object.toJSON(json));
			
			// Subject has to be null or empty string (can't be undefined)
			if (json.subject)
				this.subject = json.subject;
			this.startTimestamp = json.startTimestamp;
			this.endTimestamp = json.endTimestamp;
			this.allDay = json.allDay;
			if (json.note)
				this.note = json.note;
			if (json.location)
				this.location = json.location;
			if (json.alarm) {
				this.alarm  = json.alarm;
			}
			if (json.rrule && json.rruleTZ) {
				// rruleTZ MUST be specified if rrule is specified so if either one is missing we leave rrule
				// alone
				this.rrule = json.rrule;
				this.rruleTZ = json.rruleTZ;
				if (json.endValidity == undefined || json.endValidity == 0)
					this.isRecurringForever = true;
			} 
			if (json.endValidity) {
				this.endValidity = json.endValidity;
			}
		}
	}
});

var recurrence_model ={
	count: 1, 
	interval: 1, 
	bymonthday: [], 
	frequency: "", 
	bymonth: [], 
	until: "", 
	byhour: [], 
	byweekno: [], 
	bysetpos: [], 
	byyearday: [], 
	byday: [], 
	byminute: [], 
	bysecond: []
};

