<!-- //
var iMinLenUsername = 8;
var iMaxLenUsername = 20;
var iMinLenPassword = 8;
var iMaxLenPassword = 12;
var iPasswordMaxCharsUguali= 3;
var iPasswordNumericChar = 2;
var iPasswordSpecChars= 1;
var sUsernamePattern = new RegExp("^[a-zA-Z0-9_]+$");	
var sPasswordSpecChars = "!?#@$%&*+-/.,:;=_()[]{}";	
var sStrPasswordPattern= "abcdefghijklmnopqrstuvwxyz0123456789!?#@$%&*+-/.,:;=_()[]{}" 
var sMobilePattern = new RegExp("^[\+](39){1}[0-9]+$");	
var SMS_maxchar = 130;

function bCheckValidPassword(sPassword, sErrors) {
	var sTemp= "";
	var iNumInteger= 0;
	var iNumSpecChars= 0;
	var iCt;
	var vChars= new MakeArray(sStrPasswordPattern.length+1);
		
	sErrors= "";	

	// Controllo della linghezza minima
	if (sPassword.length < iMinLenPassword) {
		sErrors= sErrors + "La password ha una lunghezza troppo piccola.\nLunghezza minima richiesta " + iMinLenPassword + " caratteri.\n";		
	}

	// Controllo della linghezza massima
	if (sPassword.length > iMaxLenPassword) {
		sErrors= sErrors + "La password ha una lunghezza troppo grande.\nLunghezza massima consentita " + iMaxLenPassword + " caratteri.\n";		
	}

	// Controllare che non ci sia lo stesso carattere per più di tre volte
	// Controllare che ci siano almeno 2 numeri
	// Controllare che ci sia almeno 1 carattere speciale
	iNumInteger= 0;
	iNumSpecChars= 0;
	iInvalidChars= 0;
	// alert(vChars.length);	
	for(iCt= 0; iCt <= sPassword.length -1; iCt++) {		
		sTemp= sPassword.charAt(iCt);			
		iPos = sStrPasswordPattern.indexOf(sTemp);
		
		if (iPos>=0) {						
			vChars[iPos]= vChars[iPos] +1;		
						
			if(isNaN(sTemp)==false) {
				iNumInteger= iNumInteger +1;
			}
			/*
			iPos = sPasswordSpecChars.indexOf(sTemp);			
			alert ("SC iPos =" + iPos);
			if (iPos>=0)  {
			*/
			if(sPasswordSpecChars.indexOf(sTemp)>=0) {
				
				iNumSpecChars= iNumSpecChars +1;
			}
		}
		else {	
			iInvalidChars= iInvalidChars +1;
		}				 
	}
	
	if(iInvalidChars>0) {
		sErrors = sErrors + "La password contiene " + iInvalidChars + " caratteri non ammessi!\n"		
	}
	else {
		for(iCt=1; iCt <= vChars.length; iCt++) {			
			if(vChars[iCt]>iPasswordMaxCharsUguali) {
				sErrors = sErrors + "La password contiene caratteri uguali ripertuti per più di " + iPasswordMaxCharsUguali + " volte!\n"		
			}
		}
	}

	if (iNumInteger < iPasswordNumericChar) {
		sErrors = sErrors + "La password deve contenere almeno " + iPasswordNumericChar + " caratteri numerici.\n";
	}
	 
	if (iNumSpecChars < iPasswordSpecChars) {
		sErrors = sErrors + "La password deve contenere almeno " + iPasswordSpecChars + " carattere speciale.\n";
	}

	if (sErrors=="") {		
		return true;
	}
	else { 
		alert(sErrors);	
		return false;
	}
}

function CheckChangePassword(theForm) {
	var OldPwd;
	var NewPwd;
	var ConPwd;
	var sErrors="";
		
	OldPwd= CutSpace(theForm.OldPassword.value);
	if (OldPwd.length==0) {
		alert("inserire la password attuale!");
		theForm.OldPassword.focus();
		return false;
	}
				
	NewPwd= CutSpace(theForm.NewPassword.value);
	if (NewPwd.length==0) {
		alert("Inserire la nuova password!");
		theForm.NewPassword.focus();
		return false;
	}
	
	ConPwd= CutSpace(theForm.ConPassword.value);
	if (ConPwd.length==0) {
		alert("Inserire la conferma della nuova password!");
		theForm.ConPassword.focus();
		return false;
	}
	
	if (NewPwd != ConPwd) {
		alert("La nuova password e quella di conferma non sono uguali!");
		theForm.NewPassword.focus();
		return false;				
	}

	if (NewPwd == OldPwd) {
		alert("La nuova password nopn può essere uguale a quella vecchia!");
		theForm.NewPassword.focus();
		return false;				
	}

	if (NewPwd.length < iMinLenPassword) {
		alert("La nuova password ha una lunghezza troppo piccola.\nLunghezza minima richiesta " + iMinLenPassword +" caratteri");
		theForm.NewPassword.focus();
		return false;
	}	

	if (NewPwd.length > iMaxLenPassword) {
		alert("La nuova password ha una lunghezza troppo grande.\nLunghezza massima consentita " + iMaxLenPassword + " caratteri");
		theForm.NewPassword.focus();
		return false;
	}

	if (bCheckValidPassword(theForm.NewPassword.value, sErrors)==false) {
		// alert(sErrors);
		theForm.NewPassword.focus();
		return false;
	}
	
	theForm.ACT.value= "SAVEPWD";
	
	return true;
}

function CheckLostPassword(theForm) {			
	if (isEmail(theForm.EMail.value) == false) {			
		alert("L'indirizzo Email inserito non è valido!\nRimuovere gli eventuali spazi!");
		theForm.EMail.focus();
		return false;	 
	}	

	return true;
}

function CheckOkUserPwd(frmLogin)
{
    var ris;
    ris= CutSpace(frmLogin.username.value);
    if (ris.length == 0) {
        alert ("Lo Username non può essere nullo");
        frmLogin.username.focus();
        return false;
    } 
     
    ris= CutSpace(frmLogin.password.value);
    if (ris.length == 0) {
        alert ("La Password non può essere nulla");
        frmLogin.password.focus();
        return false;
    }   
    return true;
}

function SMS_calcCharLeft(Target) {
	StrLen = Target.value.length;
	if (StrLen > SMS_maxchar ) {
		Target.value = Target.value.substring(0,SMS_maxchar);
		CharsLeft = 0;
		window.alert("Lunghezza stringa eccessiva di: " + (StrLen - SMS_maxchar) + " carattere/i");
	} else {
		CharsLeft = SMS_maxchar - StrLen;
	}
	Target.form.charsleft.value = SMS_maxchar - Target.value.length;
}

function SMS_checkForm(form) {
	var sTemp;
	SMS_calcCharLeft(form.charsleft);
	if (form.Message.value.length==0) {
		alert("Inserire un testo per il messaggio.");
		form.Message.focus();
		return false;
	}	
	sTemp = form.Receiver.value;
	if ((sTemp== "") || (sTemp.substr(0,4)!= "+393")) {
    		alert("Inserire il Numero di Cellulare nel formato +393...\nSolo numeri Vodafone.");
    		form.Receiver.focus();
		return false;	    
	}
	return true;
}

function SMS_CheckBroadCast(form) {
	var sTemp;
	SMS_calcCharLeft(form.charsleft);
	if (form.Message.value.length==0) {
		alert("Inserire un testo per il messaggio.");
		form.Message.focus();
		return false;
	}	
	return true;
}

function SMS_Rubrica_OnChange(object)
{
	if(object.value.length==0) {
		alert(object.value);
	}	
	else {		
		document.smsform.Receiver.value= object.value.substring(object.value.indexOf("/")+1,object.value.length)		
	}
}

//-->