// Restituisce il numero di caratteri specificato di una 
// stringa a partire da sinistra.
function left(stringa, lunghezza)
{
	var stringa = new String(stringa)
	
	if (lunghezza > stringa.length)
	{
		lunghezza = stringa.length;
	}
	
	if (lunghezza == 0)
	{
		return stringa;
	}
	else
	{
		return stringa.substring(0, lunghezza);
	}
}


// Restituisce il numero di caratteri specificato di una 
// stringa a partire da sinistra.
function right(stringa, lunghezza) 
{
	var stringa = new String(stringa)
	var r = "";
	var i;
	for (i=0; i < stringa.length; i++)
	{
		var ch = stringa.charAt(i);
		r = ch + r;
	}
	

	var rev = left(r, lunghezza)
	r = "";

	for (i=0; i < rev.length; i++)
	{
		var ch = rev.charAt(i);
		r = ch + r;
	}
	
	
	return r;
}


// Restituisce il numero di caratteri specificato di una stringa.
function mid(stringa, inizio, lunghezza)	
{
	var stringa = new String(stringa)
		
	if (lunghezza > stringa.length)
	{
		lunghezza = stringa.length;
	}

	if (lunghezza == 0)
	{
		return stringa;
	}
	else
	{
		return stringa.substring(inizio - 1, (lunghezza + inizio) - 1);    
	}
}


// Restituisce la copia di una stringa senza spazi iniziali.
function lTrim(str)
{
	return (new String(str)).replace(/^\s*/, "")
}


// Restituisce la copia di una stringa senza spazi finali.
function rTrim(str)
{
	return (new String(str)).replace(/\s*$/, "")
}


// Restituisce la copia di una stringa senza spazi iniziali e finali.
function trim(str)
{
	return lTrim(rTrim(new String(str)))
}


// Apre l'url desiderata.
function apriFinestra(url,target,options)
{
	window.open(url,target,options);
}


// Controlla che la data inserita sia corretta.
function checkDate(giorno, mese, anno)
{	
	var insertDate = new Date(anno, (mese-1) , giorno);
	
	var bDate = ( (insertDate.getDate() == giorno) && (insertDate.getMonth() == (mese-1) ) && (insertDate.getFullYear() == anno) );
		
	return bDate;
}



function isNumeric(valore, minimo, massimo)
{
	var bNumeric = false;
	
	if (valore.length > 0)
	{
		var re = /,/gi;
		valore = valore.replace(re, ".");
		
		var numberValue = new Number(valore);
		
		if (!isNaN(numberValue.valueOf()) )
		{
			bNumeric = true;
			
			if ( !(minimo == '') )
			{
				bNumeric = (numberValue.valueOf() >= minimo);
			}
			
			if (bNumeric && ( !(massimo == '')) )
			{
				bNumeric = (bNumeric && (numberValue.valueOf() <= massimo) );
			}
		}
	}
	
	return bNumeric;
}



// Controlla se il valore inserito è un numerico positivo.
function isNumericPositive(valore)
{
	var s = valore;
	re = /[.,]/g;
	r = s.search(re);
	
	
	if (r >= 0)
	{
		return false;
	}		
	
	if (isNaN(valore) || (valore < 0) || (valore.length <= 0))
	{
		return false;
	}
	else
	{
		return true;
	}
} 

// cerca il prossimo tag HTML di nome tagName (es. "A"), a partire dall'indice startIndex (indice rispetto al numero di tags all'interno del documento)
function getNextTag(startIndex, tagName)
{
	// prendo il primo elemento
	var element = document.all[startIndex];
	if (element == null)
		return null;
		
	tagName = tagName.toUpperCase();
	// ciclo fino a quando non trovo il tipo di tag cercato
	while (element.tagName.toUpperCase() != tagName)
	{
		element = document.all[element.sourceIndex + 1];
		if (element == null)
			return null;
	}
	return element;
}

// cerca il precedente tag HTML di nome tagName (es. "A"), a partire dall'indice startIndex (indice rispetto al numero di tags all'interno del documento)
function getPrevTag(startIndex, tagName)
{
	// prendo il primo elemento
	var element = document.all[startIndex];
	if (element == null)
		return null;
		
	tagName = tagName.toUpperCase();
	// ciclo fino a quando non trovo il tipo di tag cercato
	while (element.tagName.toUpperCase() != tagName)
	{
		element = document.all[element.sourceIndex - 1];
		if (element == null)
			return null;
	}
	return element;
}

		



// defaultStatus.
defaultStatus = "";
