﻿Type.registerNamespace('Vehix.Research');
Vehix.Research.CategoryResults = function() {
	this.count = 0;
	this.maxCount = 3;
	this.registeredCheckBoxes = new Array();
}
Vehix.Research.CategoryResults.prototype =
{
	set_count: function(value) {
		this.count = value;
	},
	registerCheckBox: function(checkbox, trimID) {
		checkbox.setAttribute("trimID", trimID);
		this.registeredCheckBoxes[this.registeredCheckBoxes.length] = checkbox;
		if (checkbox.checked) {
			this.onChecked(checkbox, true);
		}
	},
	onChecked: function(checkbox, loading) {
		if (typeof loading == "undefined" || !loading) {
			this.count = checkbox.checked ? this.count + 1 : this.count - 1;
			if (checkbox.checked) {
				this.signalCompare(checkbox.getAttribute("trimID"));
			}
			else {
				this.signalNotCompare(checkbox.getAttribute("trimID"));
			}
		}
		this.updateCheckBoxes();
	},
	updateCheckBoxes: function() {
		// Enable or disable check boxes.
		for (var i = 0; i < this.registeredCheckBoxes.length; i++) {
			var cb = this.registeredCheckBoxes[i];
			cb.disabled = this.count >= this.maxCount ? !cb.checked : false;
		}
	},
	signalCompare: function(trimID) {
		Vehix.Web.Consumer.Portal.Research.category_results.AddTrimToCompare(trimID);
	},
	signalNotCompare: function(trimID) {
		Vehix.Web.Consumer.Portal.Research.category_results.RemoveTrimToCompare(trimID);
	}
}
Vehix.Research.CategoryResults.registerClass('Vehix.Research.CategoryResults');
Vehix.Research.CategoryResults.Instance = new Vehix.Research.CategoryResults();
