//==========================================================================================================
//=== TRIM
//==========================================================================================================
//---  LeftTrim: elimina tutti gli spazi a sinistra della stringa ------------------------------------------
function LeftTrim(theString)
{
	var RE;
	RE = /^\s+/gi; // tutti gli spazi, a partire dall'inizio della stringa
	return (theString.replace(RE, ""));
}
//---  RightTrim: elimina tutti gli spazi a destra della stringa -------------------------------------------
function RightTrim(theString)
{	var RE;

	RE = /\s+$/gi; // tutti gli spazi, a partire dalla fine della stringa
	return (theString.replace(RE, ""));
}
//---  Trim: elimina tutti gli spazi a sinistra e a destra della stringa -----------------------------------
function Trim(theString)
{
	theString = LeftTrim(theString);
	theString = RightTrim(theString);

	return (theString);
}

//==========================================================================================================
//=== Le funzioni di controllo hanno parametri di ingresso dati di tipo stringa; restituiscono:
//=== 	 true: se il controllo ha avuto esito positivo
//===    false: se il controllo ha avuto esito negativo
//==========================================================================================================
//---  IsStringUndefined: stringa non valorizzata ----------------------------------------------------------
function IsStringUndefined(theString)
{
	//alert("IsStringUndefined")
	return false;
}
//---  IsStringBlank: stringa contenente solo spazi --------------------------------------------------------
function IsStringBlank(theString)
{
	//alert("IsStringBlank")
	//... Blank ............................................
	if ((Trim(theString)) == "") return true;
	// ... Else ............................................
	return false;
}
//---  IsStringEmpty: stringa "vuota" ----------------------------------------------------------------------
function IsStringEmpty(theString)
{
	//alert("IsStringEmpty")
	//... Undefined ........................................
	if (IsStringUndefined(theString)) return true;
	//... Blank ............................................
	if (IsStringBlank(theString)) return true;
	// ... Else ............................................
	return false;
}

//==========================================================================================================
//---  IsNumberInteger: numero intero ----------------------------------------------------------------------
function IsNumberInteger(theNumber)
{
	var RE;
	var matchArray;

	theNumber += ""; // cast a stringa
	RE = /-?\d+/; // sequenza di un numero qualsiasi di cifre, eventualmente precedute da "-"
	matchArray = theNumber.match(RE);
	//--- Se il numero è diverso dalla sequenza estratta
	if ((matchArray == null) || (theNumber != matchArray[0])) return false;
	//--- Else
	return true;
}

//==========================================================================================================
//---  ValidatorNumerico(object): input solo determinati caratteri -----------------------------------------
function ValidatorNumber(object) {
 // Se window.event.returnValue è non definito oppure è false non si applica il validator
 // per non sovrascrivere l'azione di un eventuale validator scatenato prima di quello attuale
 if (window.event.returnValue == "undefined" || window.event.returnValue == false) return;
 
 // Il tasto Enter in caso di textbox multiline deve essere sempre consentito
 if (window.event.keyCode == 13) return;
 
 var values = "0123456789";
 if (values.indexOf(String.fromCharCode(window.event.keyCode)) == -1)
  window.event.returnValue = false;
}

//==========================================================================================================
//--- LenMax(Value, Len): Funzione interna per la lunghezza massima [AF, SS, 16 June 2003]
function LenMax(Value, Len)
{
	if ((!(Value == "")) && (!(Value.length <= Len)))
	{
		return (0);
	}
	return (1);
}

//==========================================================================================================
//---  checkMail(TextBox): controlla campo e-mail ----------------------------------------------------------
function checkMail(TextBox)
{
	return(controllaMail(TextBox, true));
}

//--- ControllaMail(TextBox,avviso): Funzione e-mail [AF, SS, 16 June 2003]
function controllaMail(TextBox,avviso)
{
	apos=TextBox.indexOf("@");
	dotpos=TextBox.lastIndexOf(".");
	lastpos=TextBox.length-1;

	if (TextBox.value == "")
		return(1);
		if (!(LenMax(TextBox, 50))) {
		if (avviso=true) alert("Inserire al più 50 caratteri nel campo.");
		//TextBox.focus();
		return 0;
	}
	if (apos<1 || dotpos-apos<2 || lastpos-dotpos>4 || lastpos-dotpos<2) {
		if (avviso=true) alert('Inserire un indirizzo e-mail valido');
		//TextBox.focus();
		return(0);
	}
	return 1;
}


//--- PopUpStatistiche (documento): Apertura Pop Up statistiche [UG, MG, 21 July 2005]
function PopUpStatistiche(documento) {
	var customWindow
	customWindow = window.open(documento, "popUpStatistiche", "toolbar=no, scrollbars= yes, location=no, directories=no, status=no, menubar=no, resizable=no, width=800, height=400");
	customWindow.moveTo(100,150);
	customWindow.focus();
}

//--- checkNumAccessi(theForm): Controllo per form ultimi accessi statistiche [UG, MG, 21 July 2005]
function checkNumAccessi(theForm) {
	if (theForm.numAccessi.value== "") {
		alert("Compilare il campo.");
		theForm.numAccessi.focus();
		return;
	}
	
	if ( !(IsNumberInteger(theForm.numAccessi.value)) ) {
		alert ("E' necessario inserire un valore numerico.");
		theForm.numAccessi.value = '';
		theForm.numAccessi.focus();
		return;
	}
		
	theForm.action = "statistiche.asp?Idstep=1";
	theForm.submit();
}
 