// Controlli vari Macromedia


function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}


function MM_findObj(n, d) { //v3.0
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document); return x;
}


function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}


function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}


// end controlli vari


// Controlla l'indirizzo di e-mail

function isEmail(email) {
			if (email.value == "")
				return false;
				
			if ((email.value.indexOf('@', 0) == -1) || (email.value.indexOf('.') == -1))
			{
				alert('Indirizzo di e-mail non valido!');
				email.focus();
				return false
			}
            else 
            {
			    if (email.value.indexOf('.',email.value.indexOf('@', 0)) == -1)
				{
				    alert('Indirizzo di e-mail non valido!');
					return(false)
                }
				else
				    return(true)
            }
}


// Controlla l'insert di valori numerici

function Tecla(e)  
		{  
			if(document.all)   
				var tecla = event.keyCode;  
			else if(document.layers)   
				var tecla = e.which;
			else if (navigator.vendor == ("Netscape6") || navigator.product == ("Gecko"))
				var tecla = e.which;
				
			if(tecla > 47 && tecla < 58)   
				return true;  
			else  
			{  
				if (tecla != 8)   
					return false;  
				else  
					return true;  
			}
} 


// Controlla il formato esatto della data (gg/mm/aaaa)

function controlla_formato_data(dt, indi)
{
    errore = false

    if (dt != '')
	{
		prima_pos = dt.indexOf('/',0)
		if (prima_pos == -1)
		   errore = true
		else
		{
			seconda_pos = dt.indexOf('/',prima_pos + 1) 

			if (seconda_pos == -1)
				errore = true
			else
			{
				giorno = dt.substring(0,prima_pos)
				mese = dt.substring(prima_pos + 1,seconda_pos)
				anno = dt.substring(seconda_pos + 1,dt.length)

				if (! (((anno.length == 2) || (anno.length == 4)) &&
				   ((mese.length == 1) || (mese.length ==2)) &&
				   ((giorno.length == 1) || (giorno.length == 2))))
					  errore = true
				else
				{
					 if (anno.length == 2)  
					     if (anno < 50)
					        {  anno_compl = '20' + anno  }
                         else
					        { anno_compl = '19' + anno  }
                     else
						 anno_compl = anno

                     if (! (isFinite(giorno) && isFinite(mese) && isFinite(anno_compl)))  
					     errore = true
                     else
					 {
						 if (! (((Number(giorno) > 0) && (Number(giorno) < 32)) &&
							    ((Number(mese) > 0) && (Number(mese) < 13)) &&
							    ((Number(anno_compl) > 1950) && (Number(anno_compl) < 2050))))  errore = true
                     }
				}
			}
		}

	}


	if (errore)  
	{
	   alert('La data relativa a ' + indi + ' non risulta in un formato accettabile.') 
	   return(true)
	} 
	else
	   return(false)
}

	
	function normalizza_anno(dt)
	{
        if ((dt.length - (dt.lastIndexOf('/') + 1)) == 2)
		{
 		     data = dt.substring(dt.length - 2,dt.length) 
		     if (Number(data) > 50)
			      data = "19" + data  
             else
			      data = "20" + data

  		     dt = dt.substring(0,dt.lastIndexOf('/') + 1) + data
        }

	    return(dt)
	}

// end script

