/**
 * constructor for NameTitle object, that uses a select box and a text box together to allow the input of titles such as 'Mr', 'Mrs', 'Prof', etc
 * @param {Object} id of select box with title options
 * @param {Object} id of text input for the 'other' title
 */
function NameTitle(titleSelectId, otherTitleId) {
	this._titleSelect = document.getElementById(titleSelectId);
	this._otherTitle = document.getElementById(otherTitleId);
	this._otValidators = new Array();

	eventSubscribe(this._titleSelect, 'change', createCallback(this, 'onTitleChange'));
}

NameTitle.prototype = {
	/**
	 * handles change event of title select box...
	 * @param {Object} event object
	 */	
	onTitleChange: function(e) {
		if (this._titleSelect.value == 'other') {
			this._otherTitle.disabled = false;
			for (var x = 0; x < this._otValidators.length; x++) {
				this._otValidators[x].showErrors();
			}
			this._otherTitle.focus();
		} else {
			this._otherTitle.disabled = true;
			for (var x = 0; x < this._otValidators.length; x++) {
				this._otValidators[x].hideErrors();
			}
		}
	},
	
	addOtherTitleValidator: function(validator) {
		this._otValidators.push(validator);
	}
}