//$Id: event.js,v 1.38 2008/04/16 17:17:31 narendra Exp $
 
Invite = function(id, userId, response)
{
	this.id=id;
	this.userId=userId;
	this.response=response;
}
// accessors 
Invite.prototype.getId = function()	{return this.id;}
Invite.prototype.getUserId = function()	{return this.userId;}
Invite.prototype.getResponse = function()	{return this.response;}
// end accessors

/////////////////////
/////////////////////

Todo = function(id,tags,text,pos,done,createTime)
{
	this.id=id;
	this.tags=tags;
	this.text=text;
	this.pos=pos;
	this.done=done;
	createTime = new Date(createTime);
	this.createTime=createTime.valueOf();
}
// accessors 
Todo.prototype.getId = function()	{return this.id;}
Todo.prototype.getTags = function()	{return this.tags;}
Todo.prototype.getText = function()	{return this.text;}
Todo.prototype.getPos = function()	{return this.pos;}
Todo.prototype.getDone = function()	{return this.done;}
Todo.prototype.getCreateTime = function()	{return this.createTime;}
// end accessors

/////////////////////
/////////////////////

Event = function(id, userId, start, end, summary, notes, link, imgUrl, 
	privacy, tags, inviteId, inviteResponse, inviteCode, repeat, repeatWeekInMonth, 
	repeatDays, repeatInterval,otherInvitees, 
	repeatEnd, repeatSkipDates, reminder, attachments, feedId, linkId)
{
	this.id=id;
	this.userId=userId;
	dStart = new Date(start);
	this.start=dStart.valueOf();
	dEnd = new Date(end);
	this.end=dEnd.valueOf();
	this.summary=summary;
	this.notes=notes;
	this.link=link;
	this.imgUrl=imgUrl;
	this.privacy=privacy;
	this.tags=tags;
	this.inviteId=inviteId;
	this.inviteResponse=inviteResponse;
	this.inviteCode=inviteCode;
	this.repeat=repeat;
	this.repeatWeekInMonth=repeatWeekInMonth;
	this.repeatDays=repeatDays;
	this.repeatInterval=repeatInterval;
	this.otherInvitees=otherInvitees;
	this.repeatEnd = repeatEnd;
	this.repeatSkipDates = repeatSkipDates;
	this.reminder = reminder;
	this.attachmentHtml = '';
	this.feedId = feedId;
	this.linkId=linkId;
	
	// convert attachments to html
	var aAttach = attachments.split(' ');
	for (var i=0; i<aAttach.length; i++)
		if (aAttach[i].length)
			this.attachmentHtml += "<img src='/img/attach.gif' border='0'> <a target='blank' href='http://files.30boxes.com"+aAttach[i]+"'>View Attachment</a><br/>";
}

// accessors 
Event.prototype.getId = function()	{return this.id;}
Event.prototype.getRepeat = function()	{return this.repeat;}
Event.prototype.getRepeatWeekInMonth = function()	{return this.repeatWeekInMonth;}
Event.prototype.getRepeatDays = function()	{return this.repeatDays;}
Event.prototype.getRepeatInterval = function()	{return this.repeatInterval;}
Event.prototype.getUserId = function()	{return this.userId;}
Event.prototype.getStart = function()	{return this.start;}
Event.prototype.getEnd = function()	{return this.end;}
Event.prototype.getSummary = function()	{return this.summary;}
Event.prototype.getNotes = function()	{return this.notes;}
Event.prototype.setNotes = function(s)	{this.notes = s;}
Event.prototype.getLink = function()	{return this.link;}
Event.prototype.getPrivacy = function()	{return this.privacy;}
Event.prototype.getTags = function()	{return this.tags;}
Event.prototype.getInviteId = function()	{return this.inviteId;}
Event.prototype.getInviteResponse = function()	{return this.inviteResponse;}
Event.prototype.getInviteCode = function()	{return this.inviteCode;}
Event.prototype.getOtherInvitees = function()	{return this.otherInvitees;}
Event.prototype.getRepeatEnd = function()	{return this.repeatEnd;}
Event.prototype.getRepeatSkipDates = function()	{return this.repeatSkipDates;}
Event.prototype.getReminder = function()	{return this.reminder;}
Event.prototype.getAttachmentHtml = function()	{return this.attachmentHtml;}
Event.prototype.getFeedId = function()	{return this.feedId;}
Event.prototype.getLinkId = function()	{return this.linkId;}
// end accessors

// start queries
Event.prototype.getImgUrl = function(dontResize)
{
	if(!dontResize && this.imgUrl.indexOf('flickr.com') >= 0)
	{	
		myImgUrl = this.imgUrl;
		myImgUrl = myImgUrl.replace("_m.jpg","_t.jpg");
		return myImgUrl;
	}
	else
		return this.imgUrl;
}

Event.prototype.isLinked = function()
{
	return (this.getLinkId() > 0);
}

Event.prototype.hasLocation = function()
{
	return (this.getNotes().indexOf('[') >= 0);
}

Event.prototype.isHoliday = function()
{
	id = this.id+'';
	return (id.indexOf('hol_') == 0);
}
Event.prototype.isICalSub = function()
{
	id = this.id+'';
	return (id.indexOf('iCal_') == 0);
}
Event.prototype.getInvites = function() // returns array of invites, or undefined
{
	return gaInvites['e'+this.getId()];
}
Event.prototype.isEditable = function()
{
	return (this.isOwner() && !this.isFeed() && !this.isICalSub());
}
Event.prototype.isOwner = function()
{
	return (this.userId == gUserId);
}
Event.prototype.isFeed = function()
{
	return (!this.isICalSub() && this.feedId != 0);
}
Event.prototype.isInvite = function()
{
	return (this.inviteId > 0);
}
Event.prototype.isWeather = function()
{
	if (this.link.indexOf('weather.yahoo') >=0)
		return 1;
	if (this.link.indexOf('weather.com') >=0)
		return 1;
		
	return 0;	
}
Event.prototype.isStatus = function()
{
	return (this.link.indexOf('twitter.com') >=0);
}
Event.prototype.isOutsideCalendarFeed = function()
{
	if (this.link.indexOf('upcoming.org') >=0)
		return 1;
	if (this.link.indexOf('upcoming.yahoo') >=0)
		return 1;
	if (this.link.indexOf('sonicliving.com') >=0)
		return 1;
	if (this.link.indexOf('facebook.com/event') >=0)
		return 1;	

	return 0;	
}

Event.prototype.isFacebookFeed = function()
{
	if (this.link.indexOf('facebook.com/') >=0)
		return 1;	

	return 0;	
}
Event.prototype.isAllDay = function()
{
	dStart = new Date(this.start);
	dEnd = new Date(this.end);
	return (dStart.getHours()==0 && dStart.getMinutes()==0 && dEnd.getHours()==0 && dEnd.getMinutes()==0);
}
Event.prototype.isTaggedImportant = function()
{
	return (this.tags.toLowerCase().indexOf('important') >= 0);
}
Event.prototype.isTaggedStrike = function()
{
	return (this.tags.toLowerCase().indexOf('-strike-') >= 0);
}
Event.prototype.getTagColor = function()
{
	aColors = ['navy','blue','maroon','purple','green','red','teal','magenta','olive','lime','orange','aqua','yellow'];
	tags = this.tags.toLowerCase();
	for (var i=0; i<aColors.length; i++)
	{
		if (tags.indexOf(' '+aColors[i]+' ') >= 0)
			return aColors[i];
	}
	return '';
}

Event.prototype.getTagBgColor = function()
{
	tags = this.tags.toLowerCase();
	for (var sTag in gaTagColors)
	{
		if (gaTagColors[sTag])
		{
			if (sEventTags.indexOf(' '+sTag+' ') >= 0)
				return gaTagColors[sTag];
		}
	}
	
	return '';
}



// end queries