// JavaScript Document
//*******************************************************
function tmt_confirm(msg){
	document.MM_returnValue=(confirm(unescape(msg)));
}
//*******************************************************
function nascondi(){
	var nava = (document.layers);
	var dom = (document.getElementById);
	var iex = (document.all);
	if (nava) { oggetto = document.aggiornas}
	else if (dom) {oggetto = document.getElementById("aggiornas").style}
	else if (iex) {oggetto = aggiornas.style}
	oggetto.visibility = "hidden";
}
function mostra(){
	oggetto.visibility = "visible";
}
//*******************************************************
function conta_testoA(nome,nume,nome1,nome2) {
	
	myForm = nome;
	numb = parseInt(nume);
	this.selname1 = nome1;
	this.selname2 = nome2;
	numa = document.forms[myForm][this.selname1].value.length; 
	a = numb - numa;
	if ((a==0) || (a<0)){ 
		alert("Attenzione \nAvete esaurito i caratteri a disposizione !");
	}
	document.forms[myForm][this.selname2].value = a;	//document.forms[0][this.selname2].value = a;
}
//***********************************************************************
function ControllaMail(nome1,nome2){
	myForm = nome1;
	this.selname1 = nome2;
	EmailAddr = document.forms[myForm][this.selname1].value;
	Filtro = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-]{2,})+\.)+([a-zA-Z0-9]{2,})+$/;
	if (Filtro.test(EmailAddr)) {
		flag=1;
		return true
	} else {
		alert("Attenzione ! \nControllare l'indirizzo di mail inserito");
		flag=0;
		return false
	}
}
/***********************************************************************/
//controlla la data
function controlla_Data(nome,campo){
	myForm = nome;
	this.camponome = campo;
	myobj = document.forms[myForm][this.camponome].value;
	
	if (myobj.substring(2,3) != "/" ||
	   myobj.substring(5,6) != "/" ||
	   isNaN(myobj.substring(0,2)) ||
	   isNaN(myobj.substring(3,5)) ||
	   isNaN(myobj.substring(6,10))) {
		  alert("Inserire nascita in formato gg/mm/aaaa");
		  myobj = "";
		  document.forms[myForm][this.camponome].focus();
		  return false;
	} else if (myobj.substring(0,2) > 31) {
	   alert("Impossibile utilizzare un valore superiore a 31 per i giorni");
	   myobj = "";
	   document.forms[myForm][this.camponome].focus();
	   return false;
	} else if (myobj.substring(3,5) > 12) {
	   alert("Impossibile utilizzare un valore superiore a 12 per i mesi");
	   myobj = "";
	   document.forms[myForm][this.camponome].focus();
	   return false;
	} else if (myobj.substring(6,10) < 1900) {
	   alert("Impossibile utilizzare un valore inferiore a 1900 per l'anno");
	   myobj = "";
	   document.forms[myForm][this.camponome].focus();
	   return false;
	} 
}
//***********************************************************************
function numerico(stringain){

	pattern = /^([0-9\.\-])+$/;
	if(!checkPatternChars(stringain,pattern)){
		return false;
	} 
   return true;
}
//***********************************************************************
function checkPatternChars(nm,pattern){

  if (!pattern.test(nm)){
    //alert("Il campo "+nm+" non e\' valido!");
    return false;
  }else{ 
    return true; 
  }
}

//*******************************************************
function controllo_scheda() {
	Radioarray=document.FormNewDato.scheda;
	flag=false;
	for (var i=0;i<Radioarray.length; i++) {
		if (Radioarray[i].checked==true) { 
			flag=true;
		}
	}
	if (flag==false) {
  		alert("Selezionare una scheda !");
		return false
  	} else {
	  	document.FormNewDato.submit();
	}
}
//*******************************************************
function con_link() {
	var dato_nome=document.forms[0].dato_nome.value;
	var dato_URL=document.forms[0].dato_URL.value;

	if (dato_nome==""){ 
		alert ("Attenzione, inserire il testo !");
		return false
		}
	if (dato_URL==""){ 
		alert ("Attenzione, inserire il link !");
		return false
		}
}
//*******************************************************
function con_allegato() {
	var dato_testo=document.forms[0].dato_testo.value;

	if (dato_testo==""){ 
		alert ("Attenzione, inserire il testo !");
		return false
		}
}
//*******************************************************
function con_foto() {
	var dato_testo=document.forms[0].dato_testo.value;

	if (dato_testo==""){ 
		alert ("Attenzione, inserire il testo !");
		return false
		}
}
//*******************************************************
function con_utenti() {
	var IdLivello=document.forms[0].IdLivello.value;
	var nome=document.forms[0].nome.value;
	var cognome=document.forms[0].cognome.value;
	var mail=document.forms[0].mail.value;
	var user=document.forms[0].user.value;
	var password=document.forms[0].password.value;
	
	if (IdLivello==-1){ 
		alert ("Attenzione, selezionare un livello !");
		return false
		}
		
	if (nome==""){ 
		alert ("Attenzione, inserire il nome !");
		return false
		}
		
	if (cognome==""){ 
		alert ("Attenzione, inserire il cognome !");
		return false
		}

	if (mail!=""){ 
		ControllaMail('composeForm','mail');
			if (flag!=1) {
				return false
			}
		}

	if (user==""){ 
		alert ("Attenzione ! \nInserire un user valido !");
		return false
	}else{
			if (user.length < 5) {
				alert ("Attenzione ! \nInserire un user valido con almeno 5 caratteri!");
				return false
			}
		}
		
	if (password==""){ 
		alert ("Attenzione ! \nInserire una password valida !");
		return false
	}else{
			if (password.length < 5) {
				alert ("Attenzione ! \nInserire una password valida con almeno 5 caratteri!");
				return false
			}
		}
	
}


//*******************************************************
function con_associato() {
	var IdAssociato_tipo=document.forms[0].IdAssociato_tipo.value;
	var associato_nome=document.forms[0].associato_nome.value;
	var associato_descrizione=document.forms[0].associato_descrizione.value;
	var comune=document.forms[0].comune.value;
	var associato_indirizzo=document.forms[0].associato_indirizzo.value;
	var associato_tel=document.forms[0].associato_tel.value;
	var associato_fax=document.forms[0].associato_fax.value;
	var associato_mail=document.forms[0].associato_mail.value;
	var associato_user=document.forms[0].associato_user.value;
	var associato_password=document.forms[0].associato_password.value;
	
	if (IdAssociato_tipo==0){ 
		alert ("Attenzione, selezionare la categoria !");
		return false
	}
	if (associato_nome==""){ 
		alert ("Attenzione, inserire il testo !");
		return false
	}
	if (associato_descrizione==""){ 
		alert ("Attenzione, inserire la descrizione !");
		return false
	}
	if (comune==0){ 
		alert ("Attenzione, selezionare il comune !");
		return false
	}
	if (associato_indirizzo==""){ 
		alert ("Attenzione, inserire l'indirizzo !");
		return false
	}

	if (associato_tel!=""){ 
		//if(!(numerico(associato_tel))){
		//alert ('Attenzione ! \nIl numero inserito non è in formato numerico !');
		//return false
		//}
	}

	if (associato_fax!=""){ 
		//if(!(numerico(associato_fax))){
		//alert ('Attenzione ! \nIl numero inserito non è in formato numerico !');
		//return false
		//}
	}


	if (associato_mail!=""){ 
		ControllaMail('composeForm','associato_mail');
			if (flag!=1) {
				return false
			}
		}

	if (associato_user==""){ 
		alert ("Attenzione ! \nInserire un user valido !");
		return false
	}else{
			if (associato_user.length < 5) {
				alert ("Attenzione ! \nInserire un user valido con almeno 5 caratteri!");
				return false
			}
		}
		
	if (associato_password==""){ 
		alert ("Attenzione ! \nInserire una password valida !");
		return false
	}else{
			if (associato_password.length < 5) {
				alert ("Attenzione ! \nInserire una password valida con almeno 5 caratteri!");
				return false
			}
		}	


}

//*******************************************************
function con_news() {
	var IdNews_Tipo=document.forms[0].IdNews_Tipo.value;
	var news_data=document.forms[0].news_data.value;
	var news_titolo=document.forms[0].news_titolo.value;
	var news_testo=document.forms[0].news_testo.value;
	var news_link_testo=document.forms[0].news_link_testo.value;
	var news_link=document.forms[0].news_link.value;
	
	if (IdNews_Tipo==0){ 
		alert ("Attenzione, seleziona la categoria !");
		return false
		}
		
	if (news_data==""){ 
		alert ("Attenzione, inserire la data !");
		return false
	}
	if (news_titolo==""){ 
		alert ("Attenzione, inserire il titolo !");
		return false
	}
	if (news_testo==0){ 
		alert ("Attenzione, inserire il testo !");
		return false
	}

}
//*******************************************************
function con_doc() {
	var IdDoc_Tipo=document.forms[0].IdDoc_Tipo.value;
	var doc_data=document.forms[0].doc_data.value;
	var doc_titolo=document.forms[0].doc_titolo.value;
	var doc_testo=document.forms[0].doc_testo.value;
	var doc_link_testo=document.forms[0].doc_link_testo.value;
	var doc_link=document.forms[0].doc_link.value;
	
	if (IdDoc_Tipo==0){ 
		alert ("Attenzione, seleziona la categoria !");
		return false
		}
		
	if (doc_data==""){ 
		alert ("Attenzione, inserire la data !");
		return false
	}
	if (doc_titolo==""){ 
		alert ("Attenzione, inserire il titolo !");
		return false
	}
	if (doc_testo==0){ 
		alert ("Attenzione, inserire il testo !");
		return false
	}

}

//*******************************************************
function con_allegato_news() {
	var news_allegato_testo=document.forms[0].news_allegato_testo.value;

	if (news_allegato_testo==""){ 
		alert ("Attenzione, inserire il testo !");
		return false
		}
}

//*******************************************************
function con_allegato_doc() {
	var doc_allegato_testo=document.forms[0].doc_allegato_testo.value;

	if (doc_allegato_testo==""){ 
		alert ("Attenzione, inserire il testo !");
		return false
		}
}
//*******************************************************
function finestra_circolari(str) {
	var width="460", height="180";
	var left = (screen.width/2) - width/2;
	var top = (screen.height/2) - height/2;
	var styleStr = 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbar=no,resizable=yes,copyhistory=no,width='+width+',height='+height+',left='+left+',top='+top+',screenX='+left+',screenY='+top;
	var finestra = window.open(str,'nuova',styleStr); 
}









