// JavaScript Document FUNZIONI COMUNI
function MM_reloadPage(init) {  //reloads the window if Nav4 resized
  if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
    document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
  else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
}
MM_reloadPage(true);

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_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) { //v4.01
  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 && d.getElementById) x=d.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];}
}

function MM_jumpMenu(targ,selObj,restore){ //v3.0
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}

// codice per mostrare/nascondere livelli e immagini
function MM_showHideLayers() { //v6.0
  var i,p,v,obj,args=MM_showHideLayers.arguments;
  for (i=0; i<(args.length-2); i+=3) if ((obj=MM_findObj(args[i]))!=null) { v=args[i+2];
    if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v=='hide')?'hidden':v; }
    obj.visibility=v; }
}

function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}
		
//validazione form
function DoSubmit(obj) {
				var username     = obj.userName.value;
				var password     = obj.password.value;
				var nome		 = obj.nome.value;
				var cognome		 = obj.cognome.value;
				var indirizzo	 = obj.indirizzo.value;
				var cap		     = obj.cap.value;
				var citta		 = obj.citta.value;				
				var provincia	 = obj.provincia.value;
				var nazione		 = obj.nazione.value;
				var email        = obj.email.value;
				var telefono	 = obj.telefono.value;
				var accetto		 = obj.accetto.checked;
				var strMailFilter   = /^.+@.+\..{2,3}$/;
				var strIllegalChars = /[\(\)\<\>\,\;\:\\\/\*\-\+\=\"\[\]]/;
				var strIllegalCharsMail = /[\(\)\<\>\,\;\:\\\/\*\-\+\'\=\"\[\]]/;
				      
				var submitform = true;
				var error      = '************************* REGISTRAZIONE *************************\n\n';
				error         += ' Attenzione :   \n\n';

			if (nome.length < 3 ) {
				error     += '    + Nome è un campo richiesto  \n';
				submitform = false;
				}
				if (nome.length > 20 && isNaN(nome) ) {
				error     += '    + Nome può essere massimo 20 caratteri  \n';
				submitform = false;
				}
				if (nome.length > 1 && nome.match(strIllegalChars) ) {
				error     += '    + Nome contiene caratteri non consentiti  \n';
				submitform = false;
				
				}
				
							
				if (cognome.length < 1) {
				error     += '    + Cognome è un campo obbligatorio  \n';
				submitform = false;
				}
	
         		if (cognome.length > 20 ) {
				error     += '    + Cognome può essere massimo 20 caratteri  \n';
				submitform = false;
				}
				if (cognome.length > 1 && cognome.match(strIllegalChars)) {
				error     += '    + Cognome contiene caratteri non consentiti  \n';
				submitform = false;
				}
				
				
				if (username.length < 1) {
				error     += '    + Username è una campo richiesto  \n';
				submitform = false;
				}
				if (username.length > 20) {
				error     += '    + Username può essere massimo 20 caratteri  \n';
				submitform = false;
				}
				if (username.length > 1 && username.match(strIllegalChars)) {
				error     += '    + UserName contiene caratteri non consentiti  \n';
				submitform = false;
				}
				
				if (password.length < 5) {
				error     += '    + Password deve essere minimo 5 caratteri  \n';
				submitform = false;
				}
				if (password.length > 20) {
				error     += '    + Password può essere massimo 20 caratteri  \n';
				submitform = false;
				}
				/*if (confirmation.length < 1) {
				error     += '    + Conferma password è un campo obbligatorio  \n';
				submitform = false;
				}
				if (password != confirmation) {
				error     += '    + Password non è uguale  \n';
				submitform = false;
				}*/
				if (email.length < 1) {
				error     += '    + Email è un campo obbligatorio  \n';
				submitform = false;
				}
				
				if (email.length > 30) {
				error     += '    + Email è massimo 30 caratteri  \n';
				submitform = false;
				}
				if (email.length > 1 && email.match(strIllegalCharsMail)) {
				error     += '    + Email contiene caratteri non consentiti  \n';
				submitform = false;
				}
				if (email.length > 1 && !email.match(strIllegalCharsMail) && !(strMailFilter.test(email))) {
				error     += '    + Email non è valida  \n';
				submitform = false;
				}
				
				if (citta.length < 3 ) {
				error     += '    + Citta è un campo richiesto  \n';
				submitform = false;
				}
				if (citta.length > 15 ) {
				error     += '    + Citta può essere massimo 15 caratteri  \n';
				submitform = false;
				}
				if (citta.length > 1 && citta.match(strIllegalChars)) {
				error     += '    + Citta contiene caratteri non consentiti  \n';
				submitform = false;
				}
				
				if (provincia.length < 2 ) {
				error     += '    + Provincia è un campo richiesto  \n';
				submitform = false;
				}
				if (provincia.length > 2 && provincia.match(strIllegalChars)) {
				error     += '    + Provincia contiene caratteri non consentiti  \n';
				submitform = false;
				}
				
				if (nazione.length < 2 ) {
				error     += '    + Nazione è un campo richiesto  \n';
				submitform = false;
				}
				if (nazione.length > 2 && nazione.match(strIllegalChars)) {
				error     += '    + Nazione contiene caratteri non consentiti  \n';
				submitform = false;
				}

				if (indirizzo.length < 2 ) {
				error     += '    + Indirizzo è un campo richiesto  \n';
				submitform = false;
				}
				if (indirizzo.length > 2 && indirizzo.match(strIllegalChars)) {
				error     += '    + Indirizzo contiene caratteri non consentiti  \n';
				submitform = false;
				}

				if (cap.length < 4 ) {
				error     += '    + Cap è un campo richiesto  \n';
				submitform = false;
				}
				if (cap.length > 4 && isNaN(cap) ) {
				error     += '    + Cap contiene caratteri non consentiti  \n';
				submitform = false;
				}
				
				if (telefono.length < 6 ) {
				error     += '    + Telefono è un campo richiesto  \n';
				submitform = false;
				}
				if (telefono.length > 6 && isNaN(telefono) ) {
				error     += '    + Telefono contiene caratteri non consentiti  \n';
				submitform = false;
				}
				
				if (accetto!=true) {
				error     += '    + Accettare il trattamento dei dati personali  \n';
				submitform = false;
				}

				if (submitform) {
					obj.submit();
				}
				else {
				error += '\n************************* REGISTRAZIONE *************************\n\n';
				alert (error);
				return false;
				}
				}

//FUNZIONI PER PAGINAZIONE ARCHIVIO NEWS				
function VaiALett(lett) {
	document.FormRes.Pagina.value =1;
	document.FormRes.Lettera.value =lett;
	document.FormRes.PrimoAccesso.value='';
	document.FormRes.submit()
}

/*function Ordina(campo) {
	document.FormRes.Pagina.value =1;
	document.FormRes.Ordinamento.value=campo;
	document.FormRes.submit()
}*/
function VaiAPag(numpag) {
	if (numpag!='0') 
	{
		document.FormRes.Pagina.value =numpag;
	}
	else 
	{
		document.FormRes.PrimoAccesso.value='';
		document.FormRes.Pagina.value ='1';
	}
	document.FormRes.submit()
}

/*function Invia(cosa)
{
	document.FormRes.DataAction.value= cosa
	document.FormRes.submit();
	return true;
}*/
//FINE FUNZIONI PER PAGINAZIONE ARCHIVIO NEWS
