function checkEMail(field){

	Campo = new Object  
	Campo = eval("document.form1." + field.name) 
	
	if(field.value != ''){ 
		mailaddr = field.value
		if (mailaddr.search(/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/) == -1){ 
			alert('E-mail non valido')
			Campo.select();
		}
	}
}

function replaceComma(entry)
{
	out = ",";				// fai il replace di ...
	add = ".";				// con ....
	temp = "" + entry;		// temporary holder

	while (temp.indexOf(out)>-1)
	{
		pos= temp.indexOf(out);
		temp = "" + (temp.substring(0, pos) + add + 
		temp.substring((pos + out.length), temp.length));
	}
	return temp;
}

function validate(field)
{
	field.value = replaceComma(field.value)
	var Numero = isFinite(field.value) 
	var Campo = field.name

	ClasseCampo = new Object  
	ClasseCampo = eval("document.form1." + Campo) 

	if(Numero==false)
	{
		alert('ATTENZIONE! il valore inserito nel campo "' + field.name + '" non é un valore numerico valido.\n\nInserire numeri interi (Esempio: 2) oppure decimali(Esempio: 2.55)');
		ClasseCampo.select();
	}
	return Numero;
}

function replaceChars(entry, i, o)
{
	out = i;				// fai il replace di ...
	add = o;				// con ....

//	out = "'";				// fai il replace di ...
//	add = "/'";				// con ....

	temp = "" + entry;		// temporary holder

	while (temp.indexOf(out)>-1)
	{
		pos= temp.indexOf(out);
		temp = "" + (temp.substring(0, pos) + add + 
		temp.substring((pos + out.length), temp.length));
	}
	return temp;
}

function JsTrim(strText) { 
	while (strText.substring(0,1) == ' ') 
		strText = strText.substring(1, strText.length);
	while (strText.substring(strText.length-1,strText.length) == ' ')
	strText = strText.substring(0, strText.length-1);
	return strText;
} 

function CheckFields(){
	var err=0
	for (i=0;i<window.document.form1.elements.length;i++){
		if ((window.document.form1.elements[i].name.charAt(0)=="O") && (window.document.form1.elements[i].name.charAt(1)=="_")){
			if (window.document.form1.elements[i].value==""){
				err=1;
				alert("I campi contrassegnati con asterisco * sono obbligatori");
				window.document.form1.elements[i].focus();
				break;
			}
		}
	}
	if (err==0)
		window.document.form1.submit()
}

function validateFileName(field)
{
	var charsNotValid = '\\/:*?"<>|\''
	var valid = true;
	var temp;
		
	for (var i=0; i<field.value.length; i++)
	{
		temp = "" + field.value.substring(i, i+1);
		if (charsNotValid.indexOf(temp) != "-1") valid = false;
	}
	
	if (!valid)
	{
		alert('Attenzione!!! questo campo non puo contenere i seguenti caratteri: \n\n \\   /   :   *   ?   "   <   >    |   \'');

		field.focus();
		field.select();
	}
}

// Funzione che vede č stato selezionato un radiobutton di 1 gruppo.//////
// Ritorna true se č stato selezionato, false in caso contrario///////////
// In Formname va passata una stringa con il nome del Form////////////////
// In Radioname va passato una stringa il nome del gruppo di radiobutton//
// Esempio RadioButtonCheck('form1', 'Provincia') ////////////////////////

function RadioButtonCheck(FormName,RadioName) {

	var selezionato = false;
	var myradio = eval("window.document." + FormName + "." + RadioName);
	// Loop da 0 a 1 meno il numero dei radio button
	for (counter = 0; counter < myradio.length; counter++){
		// Se un radio č stato selezionato, allora selezioanto=true
		if (myradio[counter].checked){
			selezionato = true; 
		}
			
	}
	
	if (!selezionato){
		// Se non č stato selezionato nulla
		return (false);
	}
	else
		return (true);
}

/*
//Funzione che controlla i campi - 12/10/05
//questa funzione va copiata e incollata nella pagina che contiene il form, non scommentarla qui!
//USO: č sufficiente modificare le voci in required[X] per aggiungere/rimuovere campi obbligatori
//il primo valore detro gli apici indica il nome del campo input, il secondo il nome che apparirā nel msg dell'alert.

function CheckFields(FORMNAME){
	
	required = new Array();
	//modifica l'array seguente in base ad i campi che vuoi rendere obbligatori
	required[0] = new Array("NOME","Nome");
	required[1] = new Array("COGNOME","Cognome");
	required[2] = new Array("SOCIETA","Societā");
	required[3] = new Array("INDIRIZZO","Indirizzo");
	required[4] = new Array("CAP","C.a.p.");	
	required[5] = new Array("CITTA","Cittā");
	required[6] = new Array("PROV","Provincia");
	required[7] = new Array("TEL","Telefono");	
	required[8] = new Array("EMAIL","E-mail");

	for (i=0; i<=required.length-1; i++) {
		obj = eval("window.document." + FORMNAME + "." + required[i][0]);
		if (obj.value == ""){
			alert("Attenzione: il campo " + required[i][1] + " č obbligatorio")
			obj.focus();
			return;			
		}
		
		///// INIZIO VALIDATOR EMAIL AUTOMATICO commenta sotto per rimuoverlo
		//il seguente script valida automaticamente un indirizzo email 
		//se esiste nel form un campo chiamato EMAIL, E_MAIL oppure E-MAIL
		if (((obj.name.toUpperCase())=="EMAIL") || ((obj.name.toUpperCase())=="E_MAIL") || ((obj.name.toUpperCase())=="E-MAIL")){
			mailaddr = obj.value
			if (mailaddr.search(/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/) == -1){ 
				alert('E-mail inserita non valida')
				obj.focus();
				return;
			}
		}
		//// FINE VALIDATOR EMAIL
	}
	//invia il form
	OkSubmit = eval("window.document." + FORMNAME);
	OkSubmit.submit();
}
*/


