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

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


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

EmailFlags.meetingBits = (EmailFlags.meetingRequestBit | EmailFlags.meetingCancelBit);

EmailFlags.getReadStatus = function(flags) {
	if ((flags & EmailFlags.readBit) !== 0) {
		return "read";
	} else {
		return "unread";
	}
}

EmailFlags.getIcon = function(flags) {
	var strings = "";

	if ((flags & EmailFlags.meetingRequestBit) !== 0) {
		strings += "invite";
	} else if ((flags & EmailFlags.meetingCancelBit) !== 0) {
		strings += "meetingCancel";
	}

	if ((flags & EmailFlags.forwardedBit) !== 0) {
		strings += " forwarded";
	}

	if ((flags & EmailFlags.answeredBit) !== 0) {
		strings += " replied";
	}

	return strings;
};
	

EmailFlags.isRead = function(flags) {
	return ((flags & EmailFlags.readBit) !== 0);
};
	
	
EmailFlags.isLocked = function(flags) {
	return ((flags & EmailFlags.lockedBit) !== 0);
};


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


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

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


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

EmailFlags.isMeetingType = function(flags) {
	return ((flags & (EmailFlags.meetingRequestBit | EmailFlags.meetingCancelBit)) !== 0);
};

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

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

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

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

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

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

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

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

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

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