////////////////////////////////////////////////////////////////////////////////
//function per aprire pop-up
////////////////////////////////////////////////////////////////////////////////
function apri(path,name,feat)
{
	window.open(path,name,feat);
}

////////////////////////////////////////////////////////////////////////////////
//function per cancellare 
////////////////////////////////////////////////////////////////////////////////
function cancella(file,nome)
{
	if(confirm("Sei sicuro di voler cancellare: \n\""+nome+'\"?'))
	{
		document.location.href = file;
	}
	return;
}

////////////////////////////////////////////////////////////////////////////////	
//function per controllo campi delle form
//	parametri: nome della form, array dei campi da controllare,
//  array dei nomi dei campi da visualizzare
////////////////////////////////////////////////////////////////////////////////											
function invia(nform,campi,ncampi,numerici,nnumerici,date,ndate)
{
	try
	{
		var color = "#C1C4DC";
		//
		// controllo che siano compilatiti tutti gli input inseriti nel vettore 'campi'
		//
		for(i=0; i<campi.length; i++)
		{
			campo = eval("document." + nform + "." + campi[i]);
			valore = eval("document." + nform + "." + campi[i] + ".value");
			campo.style.backgroundColor = "#ffffff";				
			if(valore == "")
			{
				campo.style.backgroundColor = color;
				campo.focus();
				alert("Attenzione, il campo '" + ncampi[i] + "' non è stato compilato");
				return;
			}
		}
		//
		// controllo che tutti gli input inseriti nel vettore 'numerici' contengano solo numeri
		//		
		for(j=0; j<numerici.length; j++)
		{
			campo = eval("document." + nform + "." + numerici[j]);
			TheNumber = eval("document." + nform + "." + numerici[j] + ".value");			
			var valid = 1;
			var GoodChars = "0123456789";
			for (i =0; i <= TheNumber.length-1; i++) 
			{
				if (GoodChars.indexOf(TheNumber.charAt(i)) == -1) 
				{
					valid = 0;
				}
			}
			if (valid==0)
			{
				campo.style.backgroundColor = color;		
				campo.focus();				
				alert("Attenzione: Il campo '" + nnumerici[j] + "' deve contenere solo numeri.");
				return;
			}
		}	
		//
		// controllo che gli input specificati contengano delle date
		//
		for(j=0; j<date.length; j++)
		{
			campo = eval("document." + nform + "." + date[j]);
			valore = eval("document." + nform + "." + date[j] + ".value");			
			dPart = valore.split('-');
			if(dPart.length==3)
			{
				if ( (!(dPart[0]>0 && dPart[0]<=31)) || (!(dPart[1]>0 && dPart[1]<=12)) || (!(dPart[2]>1900 && dPart[2]<2010)) )
				{
					campo.style.backgroundColor = color;		
					campo.focus();				
					alert("Attenzione: Il campo '" + ndate[j] + "' deve contenere una data nel formato gg-mm-aaaa.");
					return;
				}
			}
			else 
			{
				campo.style.backgroundColor = color;		
				campo.focus();				
				alert("Attenzione: Il campo '" + ndate[j] + "' deve contenere una data nel formato gg-mm-aaaa.");
				return;
			}
		}		
/*function checkDate(theField){
 dPart = theField.value.split('/');
 if(dPart.length==3){
   theDate = new Date(theField.value);
   dPart = theField.value.split('/');
   if(theDate.getMonth()+1 != dPart[0] ||
      theDate.getDate() != dPart[1] ||
      theDate.getFullYear() != dPart[2]){
      alert('Inavield date: '+theField.value);
      theField.focus();
   }
 } else {
   alert('Not a date: '+theField.value);
   theField.focus();
 }
}*/
		
		invia = eval("document." + nform);
		invia.submit();
	}
	catch(e)
	{
		alert("Exception:" + e.Message);
	}
}	


//////////////////////////////////////////////////////////////////////////////////
/////roll over immagini per scriverci e modulo preiscrizione
//////////////////////////////////////////////////////////////////////////////////

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_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.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);
  if(!x && document.getElementById) x=document.getElementById(n); 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];}
}
