// JavaScript Document
//Funzione per validare campo email
function domainvalidation(entered, alertbox) {
	with (entered) {
		inizio = value.substring (0,4)
		pospunto = value.indexOf(".",0)
		if (pospunto > -1) {
			value = value.substr (0,pospunto)
		}
		for (i=0; i < value.length; i++) {
			carattere = value.charCodeAt(i)
			if  ( (carattere < 48) && (carattere != 45) || (carattere > 57) && (carattere < 65) || (carattere > 90) && (carattere < 97) || (carattere > 122) ) {
				if (carattere == 32) {
					alert(alertbox);
				} else {
					alert("il carattere " + value.charAt(i) + " non è ammesso per un nome di dominio")
				}
				return false 
			}
		}
		if (value.charAt(0) == "-") {
			alert("Il carattere - non può essere all'inizio del nome")
			return false
		}
		ultimo = value.length -1
		if (value.charAt(ultimo) == "-") {
			alert("Il carattere - non può essere alla fine del nome")
			return false
		}
		return true
	}
} 
//Funzione per validare campo email
function emailvalidation(entered, alertbox) {
	with (entered) {
		apos=value.indexOf("@"); 
		dotpos=value.lastIndexOf(".");
		lastpos=value.length-1;
		if (apos<1 || dotpos-apos<2 || lastpos-dotpos>3 || lastpos-dotpos<2) {
			if (alertbox) {
			alert(alertbox);
			} 
			return false;
		}
		else {
		return true;
		}
	}
} 
//Funzione per validare casella numerica
function valuevalidation(entered, min, max, alertbox, datatype) {
	with (entered) {
		checkvalue=parseFloat(value);
			if (datatype) {
				smalldatatype=datatype.toLowerCase();
					if (smalldatatype.charAt(0)=="i") {
					checkvalue=parseInt(value)
					};
			}
			if ((parseFloat(min)==min && checkvalue<min) || (parseFloat(max)==max && checkvalue>max) || value!=checkvalue) {
				if (alertbox!="") {alert(alertbox);
				} 
				return false;
			}
			else {
				return true;
			}
	}
} 
//Funzione per validare quantità caratteri
function digitvalidation(entered, min, max, alertbox) {
	with (entered) {
		checkvalue=parseFloat(value);
		if ((value.length<min) || (value.length>max)) {
				if (alertbox!="") {alert(alertbox);
			}
			return false;
		}
		else {
			return true;
		}
	}
} 
//Funzione per convalida se campo vuoto
function emptyvalidation(entered, alertbox) {
	with (entered) {
		if (value==null || value=="") {
			if (alertbox!="") {alert(alertbox);
		} 
			return false;
		}
		else {
			return true;
		}
	}
} 
//Funzione per convalida se checked selezionato
function emptyvalidationchecked(entered, alertbox) {
		if (entered == "") {
			if (alertbox!="") {alert(alertbox);
		} 
			return false;
		}
		else {
			return true;
		}
} 
//Funzione per convalida se checked selezionato
function emptyvalidationpassword(entered, entered2, alertbox) {
	if (entered != entered2) {
			if (alertbox!="") {
				alert(alertbox);
			} 
			return false;
	} else {
			return true;
	}
} 
