
/* Permette la verifica della correttezza della mail */

function isEmail(email){
	invalidChars = " /:,;"
	for(i=0;i<invalidChars.length;i++)
	{
		badChar = invalidChars.charAt(i)
		if(email.indexOf(badChar,0)>-1)
			return false
	}
	atPos = email.indexOf("@",1)
	if (atPos == -1)
		return false
	if (email.indexOf("@",atPos +1)>-1)
		return false
	periodPos = email.indexOf(".",atPos)
	if (periodPos ==-1)
		return false
	if (periodPos+3 > email.length)
		return false
	return true
}

/* Permette la verifica della correttezza della data in formato dd/mm/aaaa */

function isDateS(data){
	
if (data.indexOf("/") == data.lastIndexOf("/") || data.indexOf("/") == -1 ||    data.lastIndexOf("/")==-1)
		return false
		
	gg		= data.split("/")[0]
	mm		= data.split("/")[1]
	aaaa	= data.split("/")[2]
	
	if(isDate(gg,mm,aaaa))
		return true
	else
		return false
}

/* Permette la verifica della correttezza della data divisa in piu campi al momento dell'ins. */

function isDate(gg,mm,aaaa){

		gg = Number(gg)
		mm = Number(mm)

	if(aaaa.length<4){
		return false
	}else{
		data = new Date(aaaa,mm-1,gg)
		gg1 = data.getDate()
		mm1 = data.getMonth()+1
		aaaa1 = data.getFullYear()
		
		datainput = gg+"/"+mm+"/"+aaaa
		dataresult = gg1+"/"+mm1+"/"+aaaa1
		if (dataresult!=datainput)
			return false
		else
			return true
	}	 	
}

// controlla il testo dell'MMS
function verificaTesto(testo){

	validChars = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'()+,-.;_{} :"
	for(i=0; i<testo.length; i++){
		if(validChars.indexOf(testo.charAt(i),0) < 0){
			return false
		}
	}
	return true
}


function apriFinestra(sUrl, iWidth, iHeight, sNome){

	if(iWidth > screen.width - 100) iWidth = screen.width - 100
	if(iHeight > screen.height - 100) iHeight = screen.height - 100
		
	if(sNome == "") sNome = "SELEZ"

	var FX	=	iWidth
	var FY	=	iHeight
	var X	=	(Math.round(screen.width/2))-(Math.round(FX/2))
	var Y	=	(Math.round(screen.height/2))-(Math.round(FY/2)) - 30

	win=window.open(sUrl, sNome, "width="+FX+",height="+FY+",status=no,toolbar=no,menubar=no,scrollbars=yes,resizable=yes,top="+Y+",left="+X );
	win.focus()
}

//	ritorna il valore del radio button selezionato
//	o null se non è checkato nessuno

function radioVal(objRadio){

	try{
		if(isNaN(objRadio.length)){
			if(objRadio.checked){
				return objRadio.value
			}else{
				return null;
			}
		}else{
			iOut = null;
			for (i = 0; i < objRadio.length; ++ i){
				if (objRadio[i].checked){
					iOut = objRadio[i].value
				}
			}
			return iOut;
		}
	}catch(e){
		return null;
	}
}



//	ritorna il valore del checkbox
//	o null se non è checkato nessuno

function checkVal(objCheck){

	try{
		if(isNaN(objCheck.length)){
			if(objCheck.checked){
				return objCheck.value
			}else{
				return null;
			}
		}else{
			iOut = null;
			for (i = 0; i < objCheck.length; ++ i){
				if (objCheck[i].checked){
					if(iOut == null)
						iOut = objCheck[i].value
					else
						iOut += ', ' + objCheck[i].value
				}
			}
			return iOut;
		}
	}catch(e){
		return null;
	}
}


// verifica se una stringa è un numero di telefono corretto

function isTel(testo){

//	validChars = "0123456789/-+ "
	validChars = "0123456789/-+ "
	for(i=0; i<testo.length; i++){
		if(validChars.indexOf(testo.charAt(i),0) < 0)
			return false
	}
	return true
}


// verifica se una stringa è un alfanumerico

function isAlfanumerico(testo){

	validChars = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
	for(i=0; i<testo.length; i++){
		if(validChars.indexOf(testo.charAt(i),0) < 0)
			return false
	}
	return true
}


// verifica se una stringa è un nome cartella corretto

function isFolderName(testo){

	invalidChars = "\\\/:*?\"<>|.' "
	for(i=0; i<testo.length; i++){
		if(invalidChars.indexOf(testo.charAt(i),0) >= 0)
			return false
	}
	return true
}



// sposta le option selezionate da una select-multiple(objFrom) all'altra(objTo)

function spostaKey(objFrom, objTo){

	for( i=objFrom.length -1 ; i >= 0 ; i--){

		if(objFrom.options[i].selected){
			testo = objFrom.options[i].text
			value = objFrom.options[i].value
			objTo.options[objTo.length] = new Option()
			objTo.options[objTo.length - 1].text = testo
			objTo.options[objTo.length - 1].value = value
			objTo.selected = true;
			objFrom.options[i] = null
		}
	}
}



//	seleziona tutti i valori di tutte le select multiple della pagina

function selectAllMultiple(){

	for (i=0; i<document.FRM01.length; i++){
		if(document.FRM01[i].type == "select-multiple"){
			for (k=0; k<document.FRM01[i].length; k++){
				document.FRM01[i].options[k].selected = true;
			}
		}
	}
}





//	Sposta le option su e giu nelle select (es. ordinamento)
//	se iDirezione > 0 -> SU
//	se iDirezione < 0 -> GIU

function spostaOption(objSelect, iDirezione){

	if (objSelect.selectedIndex > -1){

		sTextSelezionato = objSelect.options[objSelect.selectedIndex].text
		iValueSelezionato = objSelect.options[objSelect.selectedIndex].value
		iIndexSelezionato = objSelect.selectedIndex

		if (iDirezione > 0){	// SU
			if (iIndexSelezionato > 0){

				sTextPrecedente = objSelect.options[objSelect.selectedIndex - 1].text
				iValueprecedente = objSelect.options[objSelect.selectedIndex - 1].value
				iIndexPrecedente = objSelect.selectedIndex - 1

				iIndexTemp = iIndexSelezionato
				iIndexSelezionato = iIndexPrecedente
				iIndexPrecedente = iIndexTemp

				objSelect.options[iIndexSelezionato].text = sTextSelezionato
				objSelect.options[iIndexSelezionato].value = iValueSelezionato
				objSelect.options[iIndexPrecedente].text = sTextPrecedente
				objSelect.options[iIndexPrecedente].value = iValueprecedente

				objSelect.selectedIndex = iIndexSelezionato
			}

		}else{	// GIU

			if (objSelect.selectedIndex + 1 < objSelect.length){

				sTextPrecedente = objSelect.options[objSelect.selectedIndex + 1].text
				iValueprecedente = objSelect.options[objSelect.selectedIndex + 1].value
				iIndexPrecedente = objSelect.selectedIndex + 1

				iIndexTemp = iIndexSelezionato
				iIndexSelezionato = iIndexPrecedente
				iIndexPrecedente = iIndexTemp

				objSelect.options[iIndexSelezionato].text = sTextSelezionato
				objSelect.options[iIndexSelezionato].value = iValueSelezionato
				objSelect.options[iIndexPrecedente].text = sTextPrecedente
				objSelect.options[iIndexPrecedente].value = iValueprecedente

				objSelect.selectedIndex = iIndexSelezionato
			}

		}
		
	}
}


function nomeFile(sPercorso){
	return sPercorso.substring(sPercorso.lastIndexOf("\\") + 1, sPercorso.length)
}




function isNum(s){

	var codes="0123456789";
	var l=s.length;
	for(i=0; i<l; i++) {
		if (codes.indexOf(s.charAt(i))==-1) return false;
	}
	return true;	

}