//SABA - Controlli sul tipo di browser
browsername=navigator.appName;
if (browsername.indexOf("Netscape")!=-1) {ns4=true;
 ie4=false;}
else
{ns4=false; 
 ie4=true;}
//------ Controlli sul tipo di browser
function trim(stringa)
{
    // Utilizza un'espressione regolare per sostituire gli spazi 
    // iniziali e finali con la stringa vuota
    return stringa.replace(/(^\s*)|(\s*$)/g, "");
}


function ControlloNumerico(nomecampo,nome)
{
	if (ie4)
		var valore = document.all[nomecampo].value;
	if (ns4)
		var valore =document.getElementById(nomecampo).value;
	if (valore == "")	
	{
		return true;
	}
	else
	{
		if (isNaN(valore))
		{	alert("Inserire un valore numerico nel campo " + nome);
			if (ie4)
				document.all[nomecampo].value="";
			if (ns4)
				document.getElementById(nomecampo).value="";

			
			return false;
		}
	}
	return true;
}
/********** funzione di validazione dei campi contenenti i numeri di telefono e fax ***************/
/********** controlla che siano stati inseriti solo numeri, spazi e "/" ***********/ 
function validate_telx(valore,nome,nelcampo,ammessi) 
{
	var i;
	if (valore=="") {return true;}

	for(i=0;i<valore.length;i++) 
	{ 
		if ((isNaN(valore.toString().charAt(i))))
		{
			if (( valore.toString().charAt(i) != " " ) && ( valore.toString().charAt(i) != "/" ) && ( valore.toString().charAt(i) != "." ))
				{alert(nelcampo + " " + nome+ " " + ammessi );
				return false;}
		}
	}

	return true;
}

function validate_emailx(txtEmail,aler) 
{
	Email=txtEmail.value;
	if (Email=="") {return true;}
	counter_chiocciola=0;
	counter_punto=0;
	for(i=0;i<Email.length;i++) { 
		if ( Email.toString().charAt(i) == "@" ) {counter_chiocciola++};
		if ( Email.toString().charAt(i) == "." ) {counter_punto++};
		}
		if ((counter_chiocciola == 0) || ( counter_chiocciola > 1 ) || (counter_punto == 0)) {
		alert(aler); 
		return false;
		}
	return true;
}

function ISdata(stringa) 
	{
	var data = stringa; 
	if (data.length > 0) 
		{
		var ok = true; 
		var first = false; 
		var second = false; 
		var g = 0; 
		var m = 0; 
		var giorno; 
		var mese; 
		var anno; 
		for(i=0;i<data.length;i++) { 
		if (data.charAt(i) != '/' && (data.charAt(i) < '0') || (data.charAt(i) > '9')) ok = false; 
		} 
    
    if (!ok)
		{
		return false;
		}
    for(i=0;i<data.length;i++)
		{ 
		if (data.charAt(i) == '/' && !first)
			{
			first = true;
			g = i;
			}else if (data.charAt(i) == '/' && first)
				{ 
				second = true;
				m = i;
				} 
			} 
		if (!first || !second) ok = false; 
		
		if (!ok)
			{
			return false;
			}
		giorno = data.substring(0,g); 
		mese   = data.substring(g+1,m); 
		anno   = data.substring(m+1,data.length); 
		if (anno < 1000) ok = false;     
		if (mese < 1 || mese > 12) ok = false;     
		if (giorno < 1 || giorno > 31) ok = false; 
		if (giorno > 30 && (mese == '4' || mese == '04')) ok = false; 
		if (giorno > 30 && (mese == '6' || mese == '06')) ok = false; 
		if (giorno > 30 && (mese == '9' || mese == '09')) ok = false; 
		if (giorno > 30 &&  mese == '11') ok = false; 
		if (giorno >29 && (mese == '2' || mese == '02')) ok=false;
		if (giorno == '29' && (mese == '2' || mese == '02'))
			{
			if (anno % 4 == 0)
				{
				if (anno % 100 == 0)
					{
					if (anno % 400 != 0) ok = false; 
					}
				}else ok = false;
			} 
    
		if (!ok)
			{
			return false;
			}
		}
		return true;
		}
