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

var ChatFlags = Class.create( {
	initialize: function() {
		
	}	
});


// is the message read or unread
ChatFlags.readBit = 1<<0;
// set if the message cannot be deleted by the user
ChatFlags.lockedBit = 1<<1;
// set if the message can be put into a chat thread - CURRENTLY SET BY DEFAULT
ChatFlags.threadableBit = 1<<2;
// set if the message has been answered (Chat)
ChatFlags.answeredBit = 1<<3;
// set if the message has been forwarded (Chat)
ChatFlags.forwardedBit = 1<<4;
// set if the message has been "flagged" (Chat)
ChatFlags.flaggedBit = 1<<5;
// does the message have an attachment?
ChatFlags.attachmentBit = 1<<6;
// is the message outgoing (vs. incoming)
ChatFlags.outgoingBit = 1<<7;
// is the message marked for deletions (Chat)
ChatFlags.deletedBit = 1<<8;
// did the message generate an error when processed
ChatFlags.errorBit = 1<<9;
// set if the message canNOT be replied to
ChatFlags.noReplyAllowedBit = 1<<10;
// set if the message is to be moved (IMAP/EAS)
ChatFlags.toBeMovedBit = 1<<11;
// set if the message is not to be displayed 
ChatFlags.invisibleBit = 1<<12;
// set if the message is a meeting request notification
ChatFlags.meetingRequestBit = 1<<13;
// set if the message is a meeting cancelled notification
ChatFlags.meetingCancelBit = 1<<14;
// set if the message is newly added 
ChatFlags.newBit = 1<<15;
// set if the message has been moved
ChatFlags.movedBit = 1<<16;
// set if the message has multiple recipients
ChatFlags.multipleRecipientsBit = 1<<17;
// set if the message has multiple recipients
ChatFlags.incompleteBit = 1<<18;
// set if the message is an invitation message
ChatFlags.invitationBit = 1<<19;	

ChatFlags.transientAvailableBit = 1<<23;
// set if this message is an busy status change
ChatFlags.transientBusyBit = 1<<24;
// set if this message is an offline status change
ChatFlags.transientOfflineBit = 1<<25;
  
ChatFlags.isRead = function(flags) {
	return ((flags & ChatFlags.readBit) != 0);
};
	
	
ChatFlags.isLocked = function(flags) {
	return ((flags & ChatFlags.lockedBit) != 0);
};


ChatFlags.isThreadable = function(flags) {
	return ((flags & ChatFlags.threadableBit) != 0);
};


ChatFlags.hasAttachment = function(flags) {
	return ((flags & ChatFlags.attachmentBit) != 0);
};

	
ChatFlags.canReply = function(flags) {
	return ((flags & ChatFlags.noReplyAllowedBit) == 0);
};


ChatFlags.isDeleted = function(flags) {
	return ((flags & ChatFlags.deletedBit) != 0);
};

ChatFlags.isMeetingRequest = function(flags) {
	return ((flags & ChatFlags.meetingRequestBit) != 0);
};

ChatFlags.isMeetingCancel = function(flags) {
	return ((flags & ChatFlags.meetingCancelBit) != 0);
};

ChatFlags.isAnswered = function(flags) {
	return ((flags & ChatFlags.answeredBit) != 0);
};

ChatFlags.isIncomplete = function(flags) {
	return ((flags & ChatFlags.incompleteBit) != 0);
};

ChatFlags.isRead = function(flags) {
	return ((flags & ChatFlags.readBit) != 0);
};

ChatFlags.isToBeMoved = function(flags) {
	return ((flags & ChatFlags.toBeMovedBit) != 0);
};

ChatFlags.isNew = function(flags) {
	return ((flags & ChatFlags.newBit) != 0);
};

ChatFlags.isMoved = function(flags) {
	return ((flags & ChatFlags.movedBit) != 0);
};

ChatFlags.isOutgoing = function(flags) {
	return ((flags & ChatFlags.outgoingBit) != 0);
};	

ChatFlags.hasAttachment = function(flags) {
	return ((flags & ChatFlags.attachmentBit) != 0);
};

ChatFlags.isInvitation = function(flags) {
	return ((flags & ChatFlags.invitationBit) != 0);  
};

ChatFlags.isTransientAvailable = function(flags) {
	return ((flags & ChatFlags.transientAvailableBit) != 0);  
};

ChatFlags.isTransientBusy = function(flags) {
	return ((flags & ChatFlags.transientBusyBit) != 0);  
};

ChatFlags.isTransientOffline = function(flags) {
	return ((flags & ChatFlags.transientOfflineBit) != 0);  
};	

ChatFlags.isTransient = function(flags) {
	return (ChatFlags.isTransientAvailable(flags) || ChatFlags.isTransientBusy(flags) || ChatFlags.isTransientOffline(flags));
};

ChatFlags.getAvailability = function(availabilityObj,flags) {
	if(ChatFlags.isTransientAvailable(flags))
		return availabilityObj.AVAILABLE;
	else if(ChatFlags.isTransientBusy(flags))
		return availabilityObj.BUSY;
	else if(ChatFlags.isTransientOffline(flags))
		return availabilityObj.OFFLINE;
};