// ==============================================================================================
// Copyright (c) 2000-2005 
// CARE Internet Services B.V. 
// All Rights Reserved
// ==============================================================================================
// $Workfile: class.input.1.js$
// $Date: 20-01-06 08:58:22 AM$
// $Revision: 1$
// $Author: bob$
// $NoKeyword$
// ----------------------------------------------------------------------------------------------

// ==============================================================================================================================
// Class Input1
// ==============================================================================================================================
Input1.prototype = new InterfaceElement1;
Input1.prototype.constructor = Input1;
Input1.superclass = InterfaceElement1.prototype;

function Input1 (sName) {
	if ( arguments.length > 0 ) this.construct(sName);
}

//-----------------------------------------------------------------
// Method Input1.construct()
//-----------------------------------------------------------------
Input1.prototype.construct = function (sName) {
	Input1.superclass.construct.call(this, sName);
	this.__is_input = true;
	this.name = sName;
	this.disabled = false;
	this.readonly = false;
	this.interfaceObject.addElement(this);
	this.initialised = false;
	this.initExecute(this, 'initialise');
}

//-----------------------------------------------------------------
// Method Input1.initialise()
//-----------------------------------------------------------------
Input1.prototype.initialise = function () {
	if ( !this.initialised ) {
		this.field = getElementById(this.id);
		this.detectField = getElementById(this.id + '_detect');
		this.initialised = true;
	}
}

//-----------------------------------------------------------------
// Method Input1.addEventHandler()
//-----------------------------------------------------------------
Input1.prototype.addEventHandler = function (sEvent, oListener, sMethod) {
	this.initialise();
	addEventHandler(this.field, sEvent, oListener, sMethod);
}

//-----------------------------------------------------------------
// Method Input1.removeEventHandler()
//-----------------------------------------------------------------
Input1.prototype.removeEventHandler = function (sEvent, oListener, sMethod) {
	this.initialise();
	removeEventHandler(this.field, sEvent, oListener, sMethod);
}

//-----------------------------------------------------------------
// Method Input1.getValue()
//-----------------------------------------------------------------
Input1.prototype.getValue = function () {
	this.initialise();
	if ( this.field )
		return this.field.value;
}

//-----------------------------------------------------------------
// Method Input1.setValue()
//-----------------------------------------------------------------
Input1.prototype.setValue = function (sValue) {
	this.initialise();
	if ( this.field )
		this.field.value = sValue;
	if ( this.readonly ) {
		if ( !this.readonlyField )
			this.readonlyField = getElementById(this.id + '_readonly');
		if ( this.readonlyField )
			this.readonlyField.innerText = sValue;
		else
			alert(this.id + '_readonly : not found');
	}
	this.sendEvent('set_value');
}

//-----------------------------------------------------------------
// Method Input1.unsetValue()
//-----------------------------------------------------------------
Input1.prototype.unsetValue = function () {
	this.initialise();
	this.setValue('');
}

//-----------------------------------------------------------------
// Method Input1.setDisabled()
//-----------------------------------------------------------------
Input1.prototype.setDisabled = function (bDisabled) {
	this.initialise();
	this.disabled = bDisabled;
	if ( this.field ) 
		this.field.disabled = this.disabled;
	if ( this.detectField ) 
		this.detectField.value = ( bDisabled ? 0 : 1 );
}

//-----------------------------------------------------------------
// Method Input1.setDisplay()
//-----------------------------------------------------------------
Input1.prototype.setDisplay = function (sDisplay) {
	this.initialise();
	if ( this.field ) 
		this.field.style.display = sDisplay;
}

//-----------------------------------------------------------------
// Method Input1.disable()
//-----------------------------------------------------------------
Input1.prototype.disable = function () {
	this.setDisabled(true);
}

//-----------------------------------------------------------------
// Method Input1.enable()
//-----------------------------------------------------------------
Input1.prototype.enable = function () {
	this.setDisabled(false);
}

//-----------------------------------------------------------------
// Method Input1.hide()
//-----------------------------------------------------------------
Input1.prototype.hide = function () {
	this.setDisplay('none');
}

//-----------------------------------------------------------------
// Method Input1.show()
//-----------------------------------------------------------------
Input1.prototype.show = function () {
	this.setDisplay('');
}

//-----------------------------------------------------------------
// Method Input1.focus()
//-----------------------------------------------------------------
Input1.prototype.focus = function () {
	if ( this.field ) {
		try {
			this.field.focus();
		} catch (e) {
		}
	}
}

//-----------------------------------------------------------------
// Method Input1.blur()
//-----------------------------------------------------------------
Input1.prototype.blur = function () {
	if ( this.field ) {
		try {
			this.field.blur();
		} catch (e) {
		}
	}
}

//-----------------------------------------------------------------
// Method Input1.setReadonly()
//-----------------------------------------------------------------
Input1.prototype.setReadonly = function (bReadonly) {
	this.readonly = bReadonly;
}

//-----------------------------------------------------------------
// Method Input1.setRequired()
//-----------------------------------------------------------------
Input1.prototype.setRequired = function (bRequired) {
	if ( !this.readonly ) {
		var oLabel = getElementById(this.id + '_label');
		if ( oLabel ) {
			if ( oLabel.className.match(/alert$/) )
				oLabel.className = ( bRequired ? 'label-required-alert' : 'label-notrequired-alert' );
			else
				oLabel.className = ( bRequired ? 'label-required' : 'label-notrequired' );
		}
	}
}

//-----------------------------------------------------------------
// Method Input1.setLabel()
//-----------------------------------------------------------------
Input1.prototype.setLabel = function (sLabel) {
	var oLabel = getElementById(this.id + '_label');
	if ( sLabel )
		sLabel += ' :';
	if ( oLabel )
		oLabel.innerText = sLabel;
}
