function ChildAgeChooser ( child_number , mode, values ) {
	
	this.child_number 	= parseInt (child_number);
	this._is_active 	= false;
	this.node 			= null; 
	this.values 		= values;
	this.minWidth 		= '350px';
	this.selectWidth	= 60;
	this.className		= 'right';
	
	if (this.child_number < 0) {
		throw "Child number can't be less than 0.";
	}
	
	if (this.child_number > 5) {
		throw "Child number can't be more than 5.";
	}
	
	switch (mode) {
		case 'table':
			this.mode = 'table';
		break;
		case 'table2':
			this.mode = 'table2';
		break;
		default : 
			this.mode = 'div';
	}
	
	this._getSelectId = function (index) {
		return "child_age_" + index;
	};
	
	this._getSelectName = function (index) {
		return "child_age[]";
	};
	
	this.isActive = function () {
		return this._is_active;
	};
	
	this.showAfterNode = function (parent) {
		if (this.child_number == 0) {
			this.hide();
			return false;
		}
		
		if ( !this._is_active ) {
			this._is_active = true;
			this.node = this._build();
			jQuery(this.node).insertAfter (parent);
		} else {
			try {
				//console.error ("Trying to show alredy shown element.");
			} catch (e) {
				
			}
		}
	};
	
	this.hide = function () {
		if ( this._is_active ) { 
			this._is_active = false;
			this.node.parentNode.removeChild (this.node);
			this.node = null;
		} else {
			try {
				switch (this.mode) {
					case 'table2': 
					case 'table':
						jQuery('#' + this._getTableId()).remove();
						break;
					default:
						jQuery('#' + this._getDivId()).remove();
				}
				
			} catch (e) {
				
			}
		}
	};
	
	this.getValue = function (index) {
		if (this._is_active) {
			return jQuery('#'  + this._getSelectId(index)).val ();
		} else {
			return null;
		}
	};
	
	this.getValues = function () {
		if ( this._is_active ) {
			var values = [];
			for(var i=0; i< this.child_number; i++) {
				values.push(this.getValue()); 
			}
			return this.values = values;
		} else {
			var values = [];
			var index = 0;
			while (true) {
				var id = this._getSelectId(index);
				if (jQuery('#' + id).length) {
					values.push(jQuery('#' + id).val());
				} else {
					break;
				}
				index++;
			}
			return values;
		}
	};
	
	this._build = function () {
		
		switch (this.mode) {
			case 'table2':
				return this._buildTable2(); 
			break;
			case 'table':
					return this._buildTable(); 
				break;
		
			case 'div':
					return this._buildDiv();
			break;
		}
	};

	this._getDivId = function () {
		return "child_age_div";
	};
	
	this._getTableId = function () {
		return "child_age_table";
	};
	
	this._buildDiv = function () {
		var div = document.createElement("DIV");

		jQuery('#' + this._getDivId()).remove ();
		
		div.setAttribute('class', 'twoline');
		div.className = 'twoline';
		div.setAttribute('id', this._getDivId());
		
		for(var i=0; i< this.child_number; i++) {
			div.appendChild (this._buildSelect(i));
		}
		return div;
	};
	
	this._buildTable2 = function () {
		
		jQuery('#' + this._getTableId()).remove ();
		
		var table = document.createElement('table');
		
		jQuery(table).addClass(this.className);
		jQuery(table).css({'width' : this.minWidth , 'margin-bottom' : '10px'});
				
		table.style.backgroundColor= '#F3E0C4';
		table.style.borderStyle = 'dotted';
		table.style.borderColor = '#D8AE77';
		table.style.borderWidth = '1px';
		
		table.setAttribute('id' , this._getTableId());
		
		var tbody = document.createElement('tbody');
		
		tbody.appendChild (this._buildToolTipTr2());
		var trs = this._buildSelectTr2();
		for (var i=0;i<trs.length;i++) {
			tbody.appendChild(trs[i]);
		}
		
		this.node = table.appendChild (tbody);
		return table;
	};
	
	
	this._buildToolTipTr2 = function () {
		var tr = document.createElement('tr');
		var td = document.createElement('td');
		
		td.innerHTML = pe('SPECIFY_AGES_OF_CHILD');
		jQuery(td).css ({color : '#AF0303'});
		
		tr.appendChild (td);
		return tr;
	};
	
	this._buildSelectTr2 = function () {
		var trs = [];
		for (var i=0;i< this.child_number;i++) {
			
			var tr = document.createElement('tr');
			var td = document.createElement('td');
			
			td.innerHTML = 'Child ' + (i+1) + ':';
			jQuery(td).css ({color: 'black'});
			tr.appendChild (td);
			trs.push(tr);
			
			tr = document.createElement('tr');
			td = document.createElement('td');
			td.appendChild (this._buildSelect(i));
			tr.appendChild (td);
			
			if (i != this.child_number - 1) {
				td.setAttribute('width', this.selectWidth);
			} else {
				td.setAttribute('align', 'left');
			}
			trs.push(tr);
			
			
		}
		return trs;
	};
	
	
	this._buildTable = function () {
		
		
		
		jQuery('#' + this._getTableId()).remove ();
		
		var table = document.createElement('table');
		
		jQuery(table).addClass(this.className);
		jQuery(table).css({'width' : this.minWidth , 'margin-bottom' : '10px'});
		
		
		table.style.backgroundColor= '#F3E0C4';
		table.style.borderStyle = 'dotted';
		table.style.borderColor = '#D8AE77';
		table.style.borderWidth = '1px';
		
		table.setAttribute('id' , this._getTableId());
		
		var tbody = document.createElement('tbody');
		
		tbody.appendChild (this._buildToolTipTr());
		tbody.appendChild (this._buildLabelTr());
		tbody.appendChild(this._buildSelectTr());
		
		this.node = table.appendChild (tbody);
		return table;
	};
	
	this._buildToolTipTr = function () {
		var tr = document.createElement('tr');
		var td = document.createElement('td');
		
		td.colSpan = this.child_number;
		td.innerHTML = pe('SPECIFY_AGES_OF_CHILD');
		jQuery(td).css ({color : '#AF0303'});
		
		tr.appendChild (td);
		return tr;
	};
	
	this._buildLabelTr = function () {
		var tr = document.createElement('tr');
		for (var i=0;i< this.child_number;i++) {
			var td = document.createElement('td');
			td.innerHTML = 'Child ' + (i + 1) + ':';
			tr.appendChild (td);
		}
		return tr;
	};
	
	this._buildSelectTr = function () {
		var tr = document.createElement('tr');
		for (var i=0;i< this.child_number;i++) {
			var td = document.createElement('td');
			td.appendChild (this._buildSelect(i));
			tr.appendChild (td);
			
			if (i != this.child_number - 1) {
				td.setAttribute('width', this.selectWidth);
			} else {
				td.setAttribute('align', 'left');
			}
		}
		return tr;
	};
	
	this._buildSelect = function (index) {
		var select = document.createElement('SELECT');
		select.style.width = this.selectWidth + 'px';
		var selectedValue = -1;
		if (this.values) {
			selectedValue = this.values[index];
		}
		
		var selectedIndex = 0;
		var k = 0;
		
		for (var i=-1;i<=17;i++) {
			if (i >= 0) {
				var option = document.createElement("OPTION");
				option.setAttribute ('value' , i);
				option.innerHTML = '-' + i + '-';
				if (i > 0) {
					option.text = '-' + i + '-';
				} else {
					option.text = '<1';
				}
				
				option.value = i;
				select.appendChild(option);
				
				if (selectedValue == i && (new String(selectedValue)).search(/^\d+$/) >= 0) {
					option.setAttribute ('selected', 'selected');
					selectedIndex = k;
				}
			} else {
				var option = document.createElement("OPTION");
				option.setAttribute ('value' , '');
				option.innerHTML = '- ? -';
				option.text = '- ? -';
				option.value = '';
				select.appendChild(option);
			}
			k++;
		}
		
		select.selectedIndex = selectedIndex;
		select.setAttribute ("id" , this._getSelectId(index));
		select.setAttribute ("name" , this._getSelectName(index));
		
		return select;
	};
};
