﻿// Routine di utilità per la gestione dell'input
// Creato da Luigi Gaeta il 23-10-2007
// Ultima modifica il 7-11-2007
// Versione 1.0.1
// Librerie richieste: eventutil.js

var InputUtil = new Object();

InputUtil.AllowChars = function(oTextBox, oEvent)
{   //Richiede la presenza degli attributi "validChars" e/o "invalidChars" all'interno del controllo che la utilizza
	var oEvent = EventUtil.formatEvent(oEvent);
	var sCharAllowed = oTextBox.getAttribute("validChars");
	var sCharNotAllowed = oTextBox.getAttribute("invalidChars");
	var sChar = String.fromCharCode(oEvent.charCode);
	var isValidChar = ((sCharAllowed==null || sCharAllowed.indexOf(sChar)!=-1) &&    
	        (sCharNotAllowed==null || sCharNotAllowed.indexOf(sChar)==-1));
	return(isValidChar || oEvent.ctrlKey || 
		oEvent.keyCode==37 || oEvent.keyCode==39 || //Left e Right Arrow
		oEvent.keyCode==8 || oEvent.keyCode==46 || //Backspace e Cancel Key
		oEvent.keyCode==36 || oEvent.keyCode==35 || //Home e End key
		oEvent.keyCode==9);	//Tab key
};	//Fine di "AllowChars()"

InputUtil.CheckNumber = function(oTextBox)
{	//CONTROLLO NUMERICO
	if (oTextBox.value!="")
	{
		var mynum = Number(oTextBox.value);
		if (!isNaN(mynum))
	    {   //Lo riconosce in qualità di numero
			return(true);
	    }
	}
	return(false);
};	//Fine di "Checknumber()"

