App.Collections.Email = Backbone.Collection.extend({
	model : App.Models.Email,
	currentAcct:0,
	currentFolder:'INBOX',
	searchTerm: '',
	search: 'false',
	fromSearch: '',  
	toSearch: '', 
	subjectSearch: '', 
	bodySearch: '',
	date: '0',
	currentPage:1,
	listRequiresPager:false,

	url: function(folder,searchterm, fromsearch, tosearch, subjectsearch, bodySearch, date){
		if (this.search == 'true'){
			return App.baseUrl + '/api/mail/search'
				+'?searchQuery='+this.searchTerm
				+'&from='+this.fromSearch
				+'&to='+this.toSearch
				+'&subject='+this.subjectSearch
				+'&body='+this.bodySearch
				+'&date='+this.date;
		}
		else if (this.search == 'false'){
			return App.baseUrl + '/api/mail/list?acct='+this.currentAcct+'&folder='+this.currentFolder+'&range='+this.currentPage;
		}
		
	},
//	url:  App.baseUrl + '/api/mail/list?folder='+this.currentFolder,
	initialize:function(){
		// this.deferred = this.fetch();
	}
	
});

App.Collections.Email.prototype.setCurrentPage = function(page){
	this.currentPage = parseInt(page,10);
};

App.Collections.Email.prototype.incrementPage = function(){
	this.currentPage += 1;
};

App.Collections.Email.prototype.decrementPage = function(){
	
	if(this.currentPage > 1 ){
		this.currentPage -= 1;
	}
};

App.Collections.Email.prototype.setCurrentAcct = function(acct){
	this.currentAcct = acct;
}

App.Collections.Email.prototype.getCurrentAcct = function(){
	return this.currentAcct;
}

App.Collections.Email.prototype.setCurrentFolder = function(folder){
	this.currentFolder = folder;
};

App.Collections.Email.prototype.getCurrentFolder = function(){
	return this.currentFolder;
}

App.Collections.Email.prototype.setSearch = function(searching){
	this.search = searching;
};

App.Collections.Email.prototype.setSearchTerm = function(searchterm){
	this.searchTerm = searchterm;
};

App.Collections.Email.prototype.setFrom = function(fromsearch){
	this.fromSearch = fromsearch;
};
App.Collections.Email.prototype.setTo = function(tosearch){
	this.toSearch = tosearch;
};
App.Collections.Email.prototype.setSubject= function(subjectsearch){
	this.subjectSearch = subjectsearch;
};
App.Collections.Email.prototype.setBody = function(bodysearch){
	this.bodySearch = bodysearch;
};
App.Collections.Email.prototype.setDate = function(date){
	this.date = date;
};



