// ==============================================================================================
// Copyright (c) 2000-2005 
// CARE Internet Services B.V. 
// All Rights Reserved
// ==============================================================================================
// $Workfile: class.input.text.1.js$
// $Date: 11-01-06 03:04:07 PM$
// $Revision: 1$
// $Author: bob$
// $NoKeyword$
// ----------------------------------------------------------------------------------------------

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

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

//-----------------------------------------------------------------
// Method InputText1.initialise()
//-----------------------------------------------------------------
InputText1.prototype.initialise = function () {
	if ( !this.initialised ) {
		InputText1.superclass.initialise.call(this);
		if ( this.field )
			addEventHandler(this.field, 'keypress',		this, 'checkKeypress');
	}
}

//-----------------------------------------------------------------
// Method InputText1.restrictInput()
//-----------------------------------------------------------------
InputText1.prototype.restrictInput = function (sType) {
	// defines, for faster event handling
	this.NUMERICAL = 1;

	if ( !this.inputType ) {
		// this.addEventHandler('keypress',		this, 'checkKeypress');
		this.addEventHandler('paste',			this, 'checkPaste');
		this.addEventHandler('contextmenu',	this, 'disableEvent');
	}
	switch ( sType ) {
		case 'numerical':
			this.inputType = this.NUMERICAL;
			this.charCodeZero = '0'.charCodeAt(0);
			this.charCodeNine = '9'.charCodeAt(0);
			break;
		default:
			alert('unknown input type: ' + sType);
			this.inputType = '';
			break;
	}
}

//-----------------------------------------------------------------
// Method InputText1.checkKeypress()
//-----------------------------------------------------------------
InputText1.prototype.checkKeypress = function (oEvent) {
	var iKey = oEvent.which ? oEvent.which : oEvent.keyCode;
	
	// block enter
	if ( iKey == 13 ) {
		oEvent.returnValue = false;
	}
	
	switch ( this.inputType ) {
		case this.NUMERICAL:
			if ( oEvent.ctrlKey && !oEvent.shiftKey && !oEvent.altKey) {
				if ( iKey == 118 ) {
					// to do.. (mozilla clipboard is not trivial)
					oEvent.returnValue = false;
				}
	      } else {
				if ( (iKey < this.charCodeZero) || (this.charCodeNine < iKey) ) 
					oEvent.returnValue = false;
	      }
			break;
	}
}

//-----------------------------------------------------------------
// Method InputText1.checkPaste()
//-----------------------------------------------------------------
InputText1.prototype.checkPaste = function (oEvent) {
	if ( clipboardData ) {
		var sInput = clipboardData.getData('Text');
		switch ( this.inputType ) {
			case this.NUMERICAL:
				if ( !sInput.match(/^\d*$/) ) 
					oEvent.returnValue = false;
				break;
		}
	}
}

//-----------------------------------------------------------------
// Method InputText1.disableEvent()
//-----------------------------------------------------------------
InputText1.prototype.disableEvent = function (oEvent) {
	oEvent.returnValue = false;
}
