/**
 * Site family chosing
 *
 * @author Evgueni Palchukovsky <epalchukovsky@swsoft.com>
 * @version $Id: SiteFamilies.js 22629 2007-05-16 06:34:55Z ayuzhakov $
 * @since 2005/05/02
 * @package SB
 * @subpackage Wizard
 * @copyright (c) 2004-2006, SWsoft
 */
function SiteFamilies(controlId) {
	this.collection		= new Array();
	this.imageNotActive	= '';
	this.imageDisabled	= '';
	this.imageHighLight	= '';
	this.imageActive	= '';
	this.colorHighLight	= '';
	this.colorDisabled	= '';
	this.colorActive	= '';
	this.control		= document.getElementById(controlId);
}

SiteFamilies.prototype.register = function(familiaId, familiaControlId) {
	var familiaControl = new Object();
	familiaControl.id = familiaId;
	familiaControl.image = document.getElementById(familiaControlId);
	for (	familiaControl.background = familiaControl.image.parentNode;
			familiaControl.background.tagName != 'TABLE';
			familiaControl.background = familiaControl.background.parentNode);
	this.collection.push(familiaControl);
}

SiteFamilies.prototype.activate = function(backgoundControl) {
	$('StatusMessage').update(SbGetLocaleByKey('SITE-FAMILY-CHANGED'));
	$('StatusIcon').src = sbSkinPath + '/images/icon_info.gif';
		
	this._processFamiliaActions(backgoundControl, this._processActivate, this._processHighLightOff);
}

SiteFamilies.prototype.highLightOn = function(backgoundControl) {
	this._processFamiliaActions(backgoundControl, this._processHighLightOn);
}

SiteFamilies.prototype.highLightOff = function(backgoundControl) {
	this._processFamiliaActions(backgoundControl, this._processHighLightOff);
}

SiteFamilies.prototype._processFamiliaActions = function(backgroundControl, chosenAction, notChosenAction) {
	var chosenFamilia = null;
	for (var i = 0; i < this.collection.length; ++i) {
		if (this.collection[i].background == backgroundControl) {
			chosenFamilia = this.collection[i];
		}
	}
	if (chosenFamilia.id != this.control.value) {
		if (chosenAction) {
			chosenAction(this, chosenFamilia);
		}
		if (notChosenAction) {
			for (var i = 0; i < this.collection.length; ++i) {
				if (this.collection[i] != chosenFamilia) {
					notChosenAction(this, this.collection[i]);
				}
			}
		}
	}
}

SiteFamilies.prototype._processHighLightOn = function(object, familia) {
	if (object.control.value != familia.id) {
		familia.background.style.borderColor = object.colorHighLight;
		familia.image.src = object.imageHighLight;		
		$(familia.background).setStyle({ cursor: 'pointer' });
	}
}

SiteFamilies.prototype._processHighLightOff = function(object, familia) {
	if (object.control.value != familia.id) {
		familia.background.style.borderColor = object.colorDisabled;
		familia.image.src = object.imageDisabled;
		$(familia.background).setStyle({ cursor: '' });
	}
}

SiteFamilies.prototype._processActivate = function(object, familia) {
	if (object.control.value != familia.id) {
		familia.background.style.borderColor = object.colorActive;
		familia.image.src = object.imageActive;
		$(familia.background).setStyle({ cursor: '' });
		object.control.value = familia.id;
		top.sbApplyChangesObject.registerChange();
		top.sbApplyChangesObject.registerForcedSaving();
	}
}