﻿function onlynum(e)
{
if (e.which)
   {
   if(e.which<48 || e.which>57)
      return false;
   }
else if(e.keyCode)
   {
   if(e.keyCode<48 || e.keyCode>57)
      return false;
   }
return true;
}

function search_localita(id)
{
text = document.all("loc_search_"+id).value;
window.open("search_loc.asp?text="+text,"Localita","width=450,height=400,scrollbars=yes,resizable=no,status=no");
}

function MaxCaratteri(Object, MaxLen)
{
return (Object.value.length <= MaxLen);
}

/*Funzione di convalida dell'inidirizzo email*/
function ConvalidaEmail(input_id){
	var emailID=document.getElementById(input_id)
	
	if ((emailID.value==null)||(emailID.value=="")){
		alert("Inserire indirizzo email")
		emailID.focus()
		return false
	}
	if (echeck(emailID.value)==false){
		emailID.value=""
		emailID.focus()
		return false
	}
	return true
 }


function echeck(str) {

	var at="@"
	var dot="."
	var lat=str.indexOf(at)
	var lstr=str.length
	var ldot=str.indexOf(dot)
	if (str.indexOf(at)==-1){
	   alert("Indirizzo e-mail non valido")
	   return false
	}

	if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
	   alert("Indirizzo e-mail non valido")
	   return false
	}

	if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
	    alert("Indirizzo e-mail non valido")
	    return false
	}

	 if (str.indexOf(at,(lat+1))!=-1){
	    alert("Indirizzo e-mail non valido")
	    return false
	 }

	 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
	    alert("Indirizzo e-mail non valido")
	    return false
	 }

	 if (str.indexOf(dot,(lat+2))==-1){
	    alert("Indirizzo e-mail non valido")
	    return false
	 }
	
	 if (str.indexOf(" ")!=-1){
	    alert("Indirizzo e-mail non valido")
	    return false
	 }

	 return true					
}
/*Fine funzione di convalida dell'inidirizzo email*/

/*Funzione controllo conferma password*/
function ConfermaPassword(input_pwd,input_cpwd){
	var pass=document.getElementById(input_pwd)
	var cnf_pass=document.getElementById(input_cpwd)
	
	if (pass.value!=cnf_pass.value){
		alert("Conferma password errata");
		pass.value = "";
		cnf_pass.value = "";
		return false;
	}
	return true;
 }
 
/*Fine funzione controllo conferma password*/


/*Controllo che tutti i campi fel form siano compilati*/
function FormNotEmpty(form_name){
var mio_form = document.getElementById(form_name);

for (i=0; i < mio_form.elements.length; i++) {
    var campo = mio_form.elements[i].value;
    if (campo == ""){ 
        alert("Tutti i campi devono essere compilati");
        return false;
    }
}
return true;
}
/* Fine Controllo che tutti i campi fel form siano compilati*/

