$(function() {
	ec.webi.Coveringnote = Backbone.Model.extend({
		url: function() {
			var url = 'lahetteet/';
			if (this.get('EcomId')) {
				url += this.get('EcomId');
			}
			if (this.get('Id')) {
				url += ';' + this.get('Id');
			}
			return url;
		},
		set: function(attributes, options) {
			if (attributes.Id) {
				attributes.id = attributes.Id;
			}
			Backbone.Model.prototype.set.call(this, attributes, options);
			return this;
		},
		toJSON: function() {
			var covnote = this.attributes;
			var wantedDate = ec.parseDateTime(covnote.WantedDate);
			var wantedTime = ec.parseDateTime(covnote.WantedTime);
			var covDate = ec.parseDateTime(covnote.CovDate);
			covnote.WantedDate = ec.formatDate(wantedDate);
			if (wantedTime != null) {
				covnote.WantedTime = ec.formatTime(wantedTime.getHours(), wantedTime.getMinutes());
			}
			covnote.CovDate = ec.formatDate(covDate);
			return {covnote: covnote};
		}
	});
	ec.webi.Coveringnotes = Backbone.Collection.extend({
		model: ec.webi.Coveringnote,
		url: 'lahetteet',
		parse: function(response) {
			var ret = [];
			$.each(response, function(key, value) {
				ret.push(value);
			});
			return ret;
		}
	});
});
