function loginP() {
    chkL=true
    if (document.LOGON.user.value == "") {alert('Inserire una USER'); chkL=false; return;}
    if (document.LOGON.passw.value == "") {alert('Inserire una PASSWORD'); chkL=false; return;}
    if(chkL) {
        document.LOGON.Tipo.value="P";
        document.LOGON.submit();
    }
}
function loginA() {
    chkL=true
    if (document.LOGON.user.value == "") {alert('Inserire una USER'); chkL=false; return;}
    if (document.LOGON.passw.value == "") {alert('Inserire una PASSWORD'); chkL=false; return;}
    if(chkL) {
        document.LOGON.Tipo.value="A";
        document.LOGON.submit();
    }
}
function reg() {
    chk=true;
    if (!(document.REGISTER.INFO[0].checked) && !(document.REGISTER.INFO[1].checked)) {alert('Per proseguire devi autorizzare il trattamento dei dati come riportato nell\'Informativa sulla Privacy.'); chk=false;return}
    if (document.REGISTER.nome.value == "") {alert('Inserire un Nome'); chk=false;return}
    if (document.REGISTER.Cognome.value == "") {alert('Inserire un Cognome'); chk=false;return}
    if (!(document.REGISTER.sesso[0].checked) && !(document.REGISTER.sesso[1].checked)) {alert('Selezionare il sesso'); chk=false;return}
    if (!dataNascita()){alert('Inserire una data di nascita corretta'); chk=false;return}
    if (document.REGISTER.mailT.value == "") {alert('Inserire una Mail di registrazione'); chk=false;return}    
    if (!validitaEmail(document.REGISTER.mailT)) {chk=false; return;}    
    if (!(document.REGISTER.Tipo[0].checked) && !(document.REGISTER.Tipo[1].checked)) {alert('Selezionare se Azienda o Privato'); chk=false;return}
    if (document.REGISTER.INFO[1].checked) {alert('Per proseguire devi autorizzare il trattamento dei dati come riportato nell\'Informativa sulla Privacy.'); chk=false;return}
    if (chk) {
        if (document.REGISTER.Tipo[0].checked) {
            document.REGISTER.action="reg-azienda.asp"
        }
        if (document.REGISTER.Tipo[1].checked) {
            document.REGISTER.action="reg-privato.asp"
        }
        document.REGISTER.submit();
    }
}

function dataNascita() {
    str=document.REGISTER.DataNascita.value;
    gg=str.substring(0,2)
    mm=str.substring(3,5)
    aa=str.substring(6,10)
    sng1=str.substring(2,3)
    sng2=str.substring(5,6)
    if ((isNaN(gg)) || (isNaN(mm)) || (isNaN(aa))) return false;
    if (!(sng1=="/") || !(sng2=="/")) return false;
    if (mm == "02") {
        if (gg > 29) return false;
    }
    else if ((mm=="01") || (mm=="03") || (mm=="05") || (mm=="07") || (mm=="08") || (mm=="10") || (mm=="12")) {
        if (gg > 31) return false;
    }
    else if ((mm=="04") || (mm=="06") || (mm=="09") || (mm=="11")) {
        if (gg > 30) return false;
    }
    if ((aa > 1990) || (aa < 1900)) return false;
    document.REGISTER.AA.value=aa;
    return true;
}
function chkCF() {
    str=document.REGISTERPRIV.CF.value;
    l=str.length
    if (l < 16) return false;
    else {
        document.REGISTERPRIV.CF.value.toUpperCase(); 
        return true;
    }
}
function regPR() {
    chk=true;
    if (!document.REGISTERPRIV.CF.value==""){
        if (!chkCF()) {alert('Inserire un Codice Fiscale corretto'); chk=false;return}
    }
    if (document.REGISTERPRIV.Professione.value == "") {alert('Inserire una Professione'); chk=false;return}
	if (document.REGISTERPRIV.CF.value=="") {alert('Inserire un Codice Fiscale'); chk=false;return}
	if (document.REGISTERPRIV.Via.value == "") {alert('Inserire un Domicilio Fiscale'); chk=false;return}
    if (document.REGISTERPRIV.Citta.value == "") {alert('Inserire un Comune'); chk=false;return}
    if (document.REGISTERPRIV.CAP.value == "") {alert('Inserire un CAP'); chk=false;return}
    if (isNaN(document.REGISTERPRIV.CAP.value)){alert('Inserire solo numeri nel CAP'); chk=false;return}
    if (document.REGISTERPRIV.PROV.value == "") {alert('Inserire una Provincia'); chk=false;return}
    if (!isNaN(document.REGISTERPRIV.PROV.value)){alert('Inserire solo lettere nella Provincia'); chk=false;return}
    if (!document.REGISTERPRIV.tel.value == "") {
        if (isNaN(document.REGISTERPRIV.tel.value))    {alert('Inserire solo numeri nel Telefono'); chk=false;return}      
    }
    if (!document.REGISTERPRIV.Fax.value == "") {
        if (isNaN(document.REGISTERPRIV.Fax.value))    {alert('Inserire solo numeri nel Fax'); chk=false;return}      
    }
    if (!document.REGISTERPRIV.www.value == "") {
        w=document.REGISTERPRIV.www.value;
        c=w.substring(0,7);
        if (c != 'http://')  {alert('Inserire un indirizzo web corretto.\n Esempio: http://www.alepsi.com '); chk=false; return;}   
    }  
    if (!document.REGISTERPRIV.Mail.value == "") {
        if (!validitaEmail(document.REGISTERPRIV.Mail))  {chk=false; return;}   
    }
    if (document.REGISTERPRIV.MailReg.value == "") {alert('Inserire una Mail di registrazione'); chk=false;return}    
    if (!validitaEmail(document.REGISTERPRIV.MailReg)) {chk=false; return;}
    if (document.REGISTERPRIV.mailT.value != document.REGISTERPRIV.MailReg.value) {
            if(confirm('La mail di registrazione inserita in questa pagina ('+document.REGISTERPRIV.MailReg.value+') risulta differente da quella inserita precendentemente ('+document.REGISTERPRIV.mailT.value+'). Se la mail '+document.REGISTERPRIV.MailReg.value+' è corretta cliccare su OK altrimenti cliccare su Annulla ed inserire quella corretta.')) {
                chk=true;
            }else {
                chk=false;
                return;
            }
    }
    if (chk) {
        document.REGISTERPRIV.action="reg-CONF.asp"
        document.REGISTERPRIV.submit();
    }
}

function regAZ() {
    chk=true;
    if (document.REGISTERAZIENDA.MailReg.value == "") {alert('Inserire una Mail di registrazione'); chk=false;return}    
    if (!validitaEmail(document.REGISTERAZIENDA.MailReg)) {chk=false; return;}
    if (document.REGISTERAZIENDA.Professione.value == "") {alert('Inserire il Ruolo in Azienda'); chk=false;return}
	if (document.REGISTERAZIENDA.RagSoc.value == "") {alert('Inserire una Ragione Sociale'); chk=false;return}
	if (document.REGISTERAZIENDA.IVA.value == "") {alert('Inserire Partita IVA'); chk=false;return}
    if (!document.REGISTERAZIENDA.IVA.value == "") {
        if (isNaN(document.REGISTERAZIENDA.IVA.value))    {alert('Inserire solo numeri nella Partita IVA'); chk=false;return}      
    }
    if (document.REGISTERAZIENDA.Via.value == "") {alert('Inserire l\' Indirizzo della sede legale'); chk=false;return}
    if (document.REGISTERAZIENDA.CAP.value == "") {alert('Inserire un CAP'); chk=false;return}
    if (isNaN(document.REGISTERAZIENDA.CAP.value)){alert('Inserire solo numeri nel CAP'); chk=false;return}
    if (document.REGISTERAZIENDA.Citta.value == "") {alert('Inserire un Comune'); chk=false;return}
    if (document.REGISTERAZIENDA.Prov.value == "") {alert('Inserire una Provincia'); chk=false;return}
    if (!isNaN(document.REGISTERAZIENDA.Prov.value)){alert('Inserire solo lettere nella Provincia'); chk=false;return}
    if (!document.REGISTERAZIENDA.Tel.value == "") {
        if (isNaN(document.REGISTERAZIENDA.Tel.value))    {alert('Inserire solo numeri nel Telefono'); chk=false;return}      
    }
    if (!document.REGISTERAZIENDA.Fax.value == "") {
        if (isNaN(document.REGISTERAZIENDA.Fax.value))    {alert('Inserire solo numeri nel Fax'); chk=false;return}      
    }
    if (!document.REGISTERAZIENDA.www.value == "") {
        w=document.REGISTERAZIENDA.www.value;
        c=w.substring(0,7);
        if (c != 'http://')  {alert('Inserire un indirizzo web corretto.\n Esempio: http://www.alepsi.com '); chk=false; return;}   
    }    
    if (!document.REGISTERAZIENDA.Mail.value == "") {
        if (!validitaEmail(document.REGISTERAZIENDA.Mail))  {chk=false; return;}   
    }
    if (document.REGISTERAZIENDA.mailT.value != document.REGISTERAZIENDA.MailReg.value) {
            if(confirm('La mail di registrazione inserita in questa pagina ('+document.REGISTERAZIENDA.MailReg.value+') risulta differente da quella inserita precendentemente ('+document.REGISTERAZIENDA.mailT.value+'). Se la mail '+document.REGISTERAZIENDA.MailReg.value+' è corretta cliccare su OK altrimenti cliccare su Annulla ed inserire quella corretta.')) {
                chk=true;
            }else {
                chk=false;
                return;
            }
    }    
    if (chk) {
        document.REGISTERAZIENDA.action="reg-CONF.asp"
        document.REGISTERAZIENDA.submit();
    }
}


function validitaEmail(mail)
{
  contr = true;
  var strEmail = '';
  strEmail = String(mail.value).toLowerCase();
  strEmail = stripBlanks(strEmail);
  vir=strEmail.indexOf(',')
  if (vir != -1) {
 		alert( 'Indirizzo E-MAIL non valido:\n hai inserito una virgola \n Carattere non valido' );
        contr = false;
        return contr;
  }  
  pos = strEmail.indexOf( '@' )
  if( pos != -1)
  {
    pos2 = strEmail.indexOf('.', pos)
	if (pos2 == -1) {
    		alert( 'Indirizzo E-MAIL non valido:\manca il punto dopo la chiocciola' );
    		contr = false;
    	}
  }
  else if(pos == -1){
    alert( 'Indirizzo E-MAIL non valido:\n manca @' );
    contr = false;
  }
  return contr;
}
  function stripBlanks(str)
  {
    // elimina tutti i caratteri blank dall'inizio della stringa
    while ( str.charAt(0) == ' ' )
    str = str.substr(1);
    // elimina tutti caratteri blank dalla fine della stringa
    while ( str.charAt( str.length-1 ) == ' ' )
    str = str.substr ( 0,str.length-1);
    

        p='';
        q=str.length
        for (x=0; x<q; x++) {
            z='';
            i=str.indexOf(' ');
            if (i >= 0) {
                z=z+str.substring(0,i);
                a=str.substring(i,i+1);
                    str = str.substring(str.indexOf(' ')+1, q);
                    p=p+z
            }
            else {
                p=p+str
                break;
            }
        }
      return p;
  }
