﻿
function okDatiModulo()
{
    try
    {
	    var IdModulo=document.f.modulo.value;
	    var ris;
    	
	    if (IdModulo=='')
	    {
            jAlertWrapper('Completare la Sezione A', 'Sezione A');
		    
		    ris= false;
	    }
	    else
	    {
		    ris = okdati();		
	    }
	    return ris;
    }
    catch(err)
    {
        err.message = 'okDatiModulo() :: ' + err.message;
        throw(err);
    }
}

function okdati()
{
	var logmsg = '';
	var CurrFile = location.pathname.split('/');
	
	var dal = new Date();
	var al = new Date();
    try
    {
	    if (document.f.modulo.value == 'modulo1')
	    {
		    // controllo primo form
		    if (document.f.m1_t_Denominazione.value=='')
		    {
			    jAlertWrapper('Inserire la Denominazione dell\'Impresa', 'Sezione A');

			    return false;	
		    }
		    if (document.f.m1_t_ProvCcia.selectedIndex == 0)
		    {
				jAlertWrapper('Selezionare la Provincia dell\'Impresa', 'Sezione A');
				
				return false;	
			}
			if ( (document.f.m_1dal_g.value!='') || (document.f.m_1dal_m.value!='') || (document.f.m_1dal_a.value!=''))
            {
            	if (!check_data2(document.f.m_1dal_g.value, document.f.m_1dal_m.value, document.f.m_1dal_a.value))
            	{
	                jAlertWrapper('Data di inizio storico formalmente errata', 'Sezione A');
	                
	                return false;
                }
            }
			if ( (document.f.m_1al_g.value!='') || (document.f.m_1al_m.value!='') || (document.f.m_1al_a.value!=''))
            {
            	if (!check_data2(document.f.m_1al_g.value, document.f.m_1al_m.value, document.f.m_1al_a.value))
            	{
	                jAlertWrapper('Data di fine storico formalmente errata', 'Sezione A');
	                
	                return false;
                }
            }
            if ( document.f.m_1dal_g.value!='' && document.f.m_1dal_m.value!='' && document.f.m_1dal_a.value!='' && (document.f.m_1al_g.value=='' || document.f.m_1al_m.value=='' || document.f.m_1al_a.value=='') )
            {
            	jAlertWrapper('Inserire la Data di fine storico', 'Sezione A');
	                
	            return false;
            }
            if ( (document.f.m_1dal_g.value!='') && (document.f.m_1dal_m.value!='') && (document.f.m_1dal_a.value!='') && (document.f.m_1al_g.value!='') && (document.f.m_1al_m.value!='') && (document.f.m_1al_a.value!='') )
            {
	            dal.setFullYear(document.f.m_1dal_a.value, document.f.m_1dal_m.value - 1, document.f.m_1dal_g.value);
				al.setFullYear(document.f.m_1al_a.value, document.f.m_1al_m.value - 1, document.f.m_1al_g.value);
	            if (dal >= al)
	            {
	            	jAlertWrapper('La Data di inizio storico non può essere maggiore o uguale della Data di fine storico', 'Sezione A');
					
					return false;
	            }
            }
            if ((document.f.ChkChiusura1[0].checked == false)&&(document.f.ChkChiusura1[1].checked == false))
			{
				jAlertWrapper('Selezionare se in bollo o esente bollo', 'Sezione A');
				
				return false;
			}
			if ((document.f.m5_TxtChiusura.value == '')&&(document.f.ChkChiusura1[1].checked == true))
			{
				jAlertWrapper('Selezionare la motivazione per l\'esenzione', 'Sezione A');
				
				return false;
			}
			
			var tmpDenominazione = Replace4Log(document.f.m1_t_Denominazione.value);

			ReplaceAcc(document.f.m1_t_Denominazione);
		    document.f.m1_t_Denominazione.value = document.f.m1_t_Denominazione.value.toUpperCase();
		    
		    document.f.m5_TxtGg.value = document.f.m_1dal_g.value;
		    document.f.m5_TxtMm.value = document.f.m_1dal_m.value;
		    document.f.m5_TxtAaaa.value = document.f.m_1dal_a.value;
		    
		    document.f.m5_TxtGgAL.value = document.f.m_1al_g.value;
		    document.f.m5_TxtGgAL.value = document.f.m_1al_m.value;
		    document.f.m5_TxtMmAL.value = document.f.m_1al_a.value;

			logmsg = tmpDenominazione + ', ' + document.f.m1_t_ProvCcia.value + ', ' + document.f.m_1dal_g.value + document.f.m_1dal_m.value + document.f.m_1dal_a.value + ', ' + document.f.m_1al_g.value + document.f.m_1al_m.value + document.f.m_1al_a.value;
			if (document.f.ChkChiusura1[0].checked == true)
				logmsg = logmsg + ', bollo';
			else if (document.f.ChkChiusura1[1].checked == true)
				logmsg = logmsg + ', nobollo';
			else
				logmsg = logmsg + ', null';
	    }
	}
	catch(err)
    {
        err.message = 'okdati(modulo1) :: ' + err.message;
        throw(err);
        
        return false;
    }
    
    try
    {
	    if (document.f.modulo.value == 'modulo2')
	    {
		    // controllo secondo form
		    if (document.f.m2_t_CodFisc.value == '')
		    {
                jAlertWrapper('Inserire Il Codice Fiscale o la Partita Iva dell\'Impresa', 'Sezione A');
			    return false;		
		    }
			else
		    {   
		        if (document.f.m2_t_CodFisc.value.length < 11)
		        {
		            document.f.m2_t_CodFisc.focus();
			        jAlertWrapper('Il campo Codice Fiscale o Partita Iva deve contenere o 11 caratteri numerici o 16 caratteri alfanumerici in caso di Ditta Individuale', 'Sezione A');
				    return false;
		        }
		        if (!isanum(document.f.m2_t_CodFisc.value) && document.f.m2_t_CodFisc.value.length == 11)
		        {
		            document.f.m2_t_CodFisc.focus();
			        jAlertWrapper('Il campo Codice Fiscale o Partita Iva deve contenere o 11 caratteri numerici o 16 caratteri alfanumerici in caso di Ditta Individuale', 'Sezione A');
				    return false;
		        }
		        if (isanum(document.f.m2_t_CodFisc.value) && document.f.m2_t_CodFisc.value.length == 11)
		        {
		            //Ha inserito nel m2_t_CodFisc una piva
		            if (!partitaIVA(document.f.m2_t_CodFisc.value))
			        {  	
			            document.f.m2_t_CodFisc.focus();
			            jAlertWrapper('Campo Codice Fiscale o Partita Iva formalmente errato', 'Sezione A');
				        return false;
			        }
		        }
		        if (document.f.m2_t_CodFisc.value.length > 11 && document.f.m2_t_CodFisc.value.length < 16)
		        {
		            document.f.m2_t_CodFisc.focus();
			        jAlertWrapper('Il campo Codice Fiscale o Partita Iva deve contenere o 11 caratteri numerici o 16 caratteri alfanumerici in caso di Ditta Individuale', 'Sezione A');
				    return false;
		        }
		        if (document.f.m2_t_CodFisc.value.length == 16)
		        {
		            //Ha inserito nel m2_t_CodFisc un codfisc
		            if (!codiceFISCALE(document.f.m2_t_CodFisc.value))
		            {
		                document.f.m2_t_CodFisc.focus();
			            jAlertWrapper('Campo Codice Fiscale o Partita Iva formalmente errato', 'Sezione A');
				        return false;
		            }
		        }
		    }
			if ( (document.f.m_2dal_g.value!='') || (document.f.m_2dal_m.value!='') || (document.f.m_2dal_a.value!=''))
            {
            	if (!check_data2(document.f.m_2dal_g.value, document.f.m_2dal_m.value, document.f.m_2dal_a.value))
            	{
	                jAlertWrapper('Data di inizio storico formalmente errata', 'Sezione A');
	                
	                return false;
                }
            }
			if ( (document.f.m_2al_g.value!='') || (document.f.m_2al_m.value!='') || (document.f.m_2al_a.value!=''))
            {
            	if (!check_data2(document.f.m_2al_g.value, document.f.m_2al_m.value, document.f.m_2al_a.value))
            	{
	                jAlertWrapper('Data di fine storico formalmente errata', 'Sezione A');
	                
	                return false;
                }
            }
            if ( document.f.m_2dal_g.value!='' && document.f.m_2dal_m.value!='' && document.f.m_2dal_a.value!='' && (document.f.m_2al_g.value=='' || document.f.m_2al_m.value=='' || document.f.m_2al_a.value=='') )
            {
            	jAlertWrapper('Inserire la Data di fine storico', 'Sezione A');
	                
	            return false;
            }
            if ( (document.f.m_2dal_g.value!='') && (document.f.m_2dal_m.value!='') && (document.f.m_2dal_a.value!='') && (document.f.m_2al_g.value!='') && (document.f.m_2al_m.value!='') && (document.f.m_2al_a.value!='') )
            {
	            dal.setFullYear(document.f.m_2dal_a.value, document.f.m_2dal_m.value - 1, document.f.m_2dal_g.value);
				al.setFullYear(document.f.m_2al_a.value, document.f.m_2al_m.value - 1, document.f.m_2al_g.value);
	            if (dal >= al)
	            {
	            	jAlertWrapper('La Data di inizio storico non può essere maggiore o uguale della Data di fine storico', 'Sezione A');
					
					return false;
	            }
            }
            if ((document.f.ChkChiusura2[0].checked == false)&&(document.f.ChkChiusura2[1].checked == false))
			{
				jAlertWrapper('Selezionare se in bollo o esente bollo', 'Sezione A');
				
				return false;
			}
			if ((document.f.m5_TxtChiusura.value == '')&&(document.f.ChkChiusura2[1].checked == true))
			{
				jAlertWrapper('Selezionare la motivazione per l\'esenzione', 'Sezione A');
				
				return false;
			}
            
            document.f.m5_TxtGg.value = document.f.m_2dal_g.value;
		    document.f.m5_TxtMm.value = document.f.m_2dal_m.value;
		    document.f.m5_TxtAaaa.value = document.f.m_2dal_a.value;
		    
		    document.f.m5_TxtGgAL.value = document.f.m_2al_g.value;
		    document.f.m5_TxtGgAL.value = document.f.m_2al_m.value;
		    document.f.m5_TxtMmAL.value = document.f.m_2al_a.value;
		    
			logmsg = document.f.m2_t_CodFisc.value + ', ' + document.f.m_2dal_g.value + document.f.m_2dal_m.value + document.f.m_2dal_a.value + ', ' + document.f.m_2al_g.value + document.f.m_2al_m.value + document.f.m_2al_a.value;
			if (document.f.ChkChiusura2[0].checked == true)
				logmsg = logmsg + ', bollo';
			else if (document.f.ChkChiusura2[1].checked == true)
				logmsg = logmsg + ', nobollo';
			else
				logmsg = logmsg + ', null';
				
	    }
	}
	catch(err)
    {
        err.message = 'okdati(modulo2) :: ' + err.message;
        throw(err);
        
        return false;
    }
	
	try
	{
	    if (document.f.modulo.value == 'modulo3')
	    {
		    // controllo terzo form
            if ( (document.f.m3_t_Denominazione.value == '') && (document.f.m3_t_CodFisc.value == '') )
		    {
		        jAlertWrapper('Inserire i dati nel campo Cognome o nel campo Codice Fiscale', 'Sezione A');
	         	return false;
	        }
	        
	        //INSERITO CODICE FISCALE
		    if (document.f.m3_t_CodFisc.value != '')
		    {
			    if (( document.f.m3_t_Denominazione.value != '') || (document.f.m3_t_Nome.value != '') || (document.f.m3_n_g.value != '') || (document.f.m3_n_m.value != '') || (document.f.m3_n_a.value != '') )
			    {
			        document.f.m3_t_Denominazione.value = '';
			        document.f.m3_t_Nome.value = '';
			        document.f.m3_n_g.value = '';
			        document.f.m3_n_m.value = '';
			        document.f.m3_n_a.value = '';
				    jAlertWrapper('La ricerca per Codice Fiscale non prevede l\'inserimento di ulteriori dati', 'Sezione A');
				    return false;
			    }
			    
			    if (document.f.m3_t_CodFisc.value.length < 16)
                {
                    document.f.m3_t_CodFisc.focus();
                    jAlertWrapper('Il campo Codice Fiscale deve contenere 16 caratteri alfanumerici', 'Sezione A');
                    return false;
                }
                if (document.f.m3_t_CodFisc.value.length == 16)
                {
                    if (!codiceFISCALE(document.f.m3_t_CodFisc.value))
	                {
	                    document.f.m3_t_CodFisc.focus();
		                jAlertWrapper('Codice Fiscale formalmente errato', 'Sezione A');
			            return false;
	                }
                }
                
                if (document.f.m3_t_ProvCcia.selectedIndex == 0)
			    {
				    jAlertWrapper('Inserire la Provincia sede impresa', 'Sezione A');
				    return false;
			    }

			}
	        else
	        {
	            if (document.f.m3_t_Denominazione.value != '')
	            {
	                if (!check_letter(document.f.m3_t_Denominazione.value))
	                {
			            jAlertWrapper('Il campo Cognome deve contenere solo caratteri alfabetici', 'Sezione A');
				        return false;
	                }
	                
	                if (WordCount(document.f.m3_t_Denominazione, '') > 1)
                    {
			            jConfirmWrapper(
                                        'Sono state inserite due o più parole nel campo COGNOME. Confermare se trattasi di cognome doppio (tasto Conferma), oppure inserire il nome nell\'apposito campo (tasto Annulla)',
                                        'Sezione A',
                                        function(r) {
                                                      if (r == false)
                                                      {
	                                                    document.f.m3_t_Denominazione.focus();
	                                                    return false;
	                                                  } 
                                                      
                                                    }
                                        );
			        }
	            }
	            
	            if (document.f.m3_t_Nome.value == '')
	            {
	            	jAlertWrapper('Inserire il campo Nome', 'Sezione A');
				    return false;
	            }
	            else
	            {
	            	if (!check_letter(document.f.m3_t_Nome.value))
                    {
	                    jAlertWrapper('Il campo Nome deve contenere solo caratteri alfabetici', 'Sezione A');
		                return false;
                    }
	            }
	            
	            if (document.f.m3_n_g.value == '' && document.f.m3_n_m.value == '' && document.f.m3_n_a.value == '')
	            {
	            	jAlertWrapper('Inserire il campo Data di nascita', 'Sezione A');
				    return false;
	            }
	            else
	            {
	            	if (!check_data2(document.f.m3_n_g.value, document.f.m3_n_m.value, document.f.m3_n_a.value))
	                {
	                    jAlertWrapper('Data di nascita formalmente errata', 'Sezione A');
	                    return false;
	                }
	            }
	            
	            if (document.f.m3_t_ProvCcia.selectedIndex == 0)
			    {
				    jAlertWrapper('Inserire la Provincia sede impresa', 'Sezione A');
				    return false;
			    }	
	            
            }
            
			if ( (document.f.m_3dal_g.value!='') || (document.f.m_3dal_m.value!='') || (document.f.m_3dal_a.value!=''))
            {
            	if (!check_data2(document.f.m_3dal_g.value, document.f.m_3dal_m.value, document.f.m_3dal_a.value))
            	{
	                jAlertWrapper('Data di inizio storico formalmente errata', 'Sezione A');
	                
	                return false;
                }
            }
			if ( (document.f.m_3al_g.value!='') || (document.f.m_3al_m.value!='') || (document.f.m_3al_a.value!=''))
            {
            	if (!check_data2(document.f.m_3al_g.value, document.f.m_3al_m.value, document.f.m_3al_a.value))
            	{
	                jAlertWrapper('Data di fine storico formalmente errata', 'Sezione A');
	                
	                return false;
                }
            }
            if ( document.f.m_3dal_g.value!='' && document.f.m_3dal_m.value!='' && document.f.m_3dal_a.value!='' && (document.f.m_3al_g.value=='' || document.f.m_3al_m.value=='' || document.f.m_3al_a.value=='') )
            {
            	jAlertWrapper('Inserire la Data di fine storico', 'Sezione A');
	                
	            return false;
            }
            if ( (document.f.m_3dal_g.value!='') && (document.f.m_3dal_m.value!='') && (document.f.m_3dal_a.value!='') && (document.f.m_3al_g.value!='') && (document.f.m_3al_m.value!='') && (document.f.m_3al_a.value!='') )
            {
	            dal.setFullYear(document.f.m_3dal_a.value, document.f.m_3dal_m.value - 1, document.f.m_3dal_g.value);
				al.setFullYear(document.f.m_3al_a.value, document.f.m_3al_m.value - 1, document.f.m_3al_g.value);
	            if (dal >= al)
	            {
	            	jAlertWrapper('La Data di inizio storico non può essere maggiore o uguale della Data di fine storico', 'Sezione A');
					
					return false;
	            }
            }
            if ((document.f.ChkChiusura3[0].checked == false)&&(document.f.ChkChiusura3[1].checked == false))
			{
				jAlertWrapper('Selezionare se in bollo o esente bollo', 'Sezione A');
				
				return false;
			}
			if ((document.f.m5_TxtChiusura.value == '')&&(document.f.ChkChiusura3[1].checked == true))
			{
				jAlertWrapper('Selezionare la motivazione per l\'esenzione', 'Sezione A');
				
				return false;
			}
            
            document.f.m5_TxtGg.value = document.f.m_3dal_g.value;
		    document.f.m5_TxtMm.value = document.f.m_3dal_m.value;
		    document.f.m5_TxtAaaa.value = document.f.m_3dal_a.value;
		    
		    document.f.m5_TxtGgAL.value = document.f.m_3al_g.value;
		    document.f.m5_TxtGgAL.value = document.f.m_3al_m.value;
		    document.f.m5_TxtMmAL.value = document.f.m_3al_a.value;
            
			logmsg = document.f.m3_t_Denominazione.value + ', ' + document.f.m3_t_Nome.value + ', ' + document.f.m3_t_CodFisc.value + ', ' + document.f.m3_n_g.value + document.f.m3_n_m.value + document.f.m3_n_a.value + ', ' + document.f.m3_t_ProvCcia.value + ', ' + document.f.m_3dal_g.value + document.f.m_3dal_m.value + document.f.m_3dal_a.value + ', ' + document.f.m_3al_g.value + document.f.m_3al_m.value + document.f.m_3al_a.value;
			if (document.f.ChkChiusura3[0].checked == true)
				logmsg = logmsg + ', bollo';
			else if (document.f.ChkChiusura3[1].checked == true)
				logmsg = logmsg + ', nobollo';
			else
				logmsg = logmsg + ', null';
	    }
	}
	catch(err)
    {
        err.message = 'okdati(modulo3) :: ' + err.message;
        throw(err);
        
        return false;
    }
    
    try
    {
        if (document.f.modulo.value == 'modulo4')
	    {
            if (document.f.m4_t_Nccia.value == '')
            {
			    jAlertWrapper('Inserire il Numero R.E.A.', 'Sezione A');
			    return false;
		    }
		    if (!isanum(document.f.m4_t_Nccia.value)) 
            {
                 document.f.m4_t_Nccia.focus();
                 jAlertWrapper('Il campo Numero R.E.A deve contenere soltanto caratteri numerici', 'Sezione A');
                 return (false);
            }
		    if (document.f.m4_t_ProvCcia.selectedIndex == 0)
		    {
			    jAlertWrapper('Inserire la Provincia sede impresa', 'Sezione A');
			    return false;
		    }
			if ( (document.f.m_4dal_g.value!='') || (document.f.m_4dal_m.value!='') || (document.f.m_4dal_a.value!=''))
            {
            	if (!check_data2(document.f.m_4dal_g.value, document.f.m_4dal_m.value, document.f.m_4dal_a.value))
            	{
	                jAlertWrapper('Data di inizio storico formalmente errata', 'Sezione A');
	                
	                return false;
                }
            }
			if ( (document.f.m_4al_g.value!='') || (document.f.m_4al_m.value!='') || (document.f.m_4al_a.value!=''))
            {
            	if (!check_data2(document.f.m_4al_g.value, document.f.m_4al_m.value, document.f.m_4al_a.value))
            	{
	                jAlertWrapper('Data di fine storico formalmente errata', 'Sezione A');
	                
	                return false;
                }
            }
            if ( document.f.m_4dal_g.value!='' && document.f.m_4dal_m.value!='' && document.f.m_4dal_a.value!='' && (document.f.m_4al_g.value=='' || document.f.m_4al_m.value=='' || document.f.m_4al_a.value=='') )
            {
            	jAlertWrapper('Inserire la Data di fine storico', 'Sezione A');
	                
	            return false;
            }
            if ( (document.f.m_4dal_g.value!='') && (document.f.m_4dal_m.value!='') && (document.f.m_4dal_a.value!='') && (document.f.m_4al_g.value!='') && (document.f.m_4al_m.value!='') && (document.f.m_4al_a.value!='') )
            {
	            dal.setFullYear(document.f.m_4dal_a.value, document.f.m_4dal_m.value - 1, document.f.m_4dal_g.value);
				al.setFullYear(document.f.m_4al_a.value, document.f.m_4al_m.value - 1, document.f.m_4al_g.value);
	            if (dal >= al)
	            {
	            	jAlertWrapper('La Data di inizio storico non può essere maggiore o uguale della Data di fine storico', 'Sezione A');
					
					return false;
	            }
            }
            if ((document.f.ChkChiusura4[0].checked == false)&&(document.f.ChkChiusura4[1].checked == false))
			{
				jAlertWrapper('Selezionare se in bollo o esente bollo', 'Sezione A');
				
				return false;
			}
			if ((document.f.m5_TxtChiusura.value == '')&&(document.f.ChkChiusura4[1].checked == true))
			{
				jAlertWrapper('Selezionare la motivazione per l\'esenzione', 'Sezione A');
				
				return false;
			}
			
            document.f.m5_TxtGg.value = document.f.m_4dal_g.value;
		    document.f.m5_TxtMm.value = document.f.m_4dal_m.value;
		    document.f.m5_TxtAaaa.value = document.f.m_4dal_a.value;
		    
		    document.f.m5_TxtGgAL.value = document.f.m_4al_g.value;
		    document.f.m5_TxtGgAL.value = document.f.m_4al_m.value;
		    document.f.m5_TxtMmAL.value = document.f.m_4al_a.value;
		    
			logmsg = document.f.m4_t_Nccia.value + ', ' + document.f.m4_t_ProvCcia.value + ', ' + document.f.m_4dal_g.value + document.f.m_4dal_m.value + document.f.m_4dal_a.value + ', ' + document.f.m_4al_g.value + document.f.m_4al_m.value + document.f.m_4al_a.value;
			
			if (document.f.ChkChiusura4[0].checked == true)
				logmsg = logmsg + ', bollo';
			else if (document.f.ChkChiusura4[1].checked == true)
				logmsg = logmsg + ', nobollo';
			else
				logmsg = logmsg + ', null';

		}
    }
    catch(err)
    {
        err.message = 'okdati(modulo4) :: ' + err.message;
        throw(err);
        
        return false;
    }
	
	//Tutto ok, scrivo log
	var paramErr = new Array('javascript', '0', '['+ sessId + '] :: ' + 'okdati (' + logmsg + ')', 'true', CurrFile[CurrFile.length - 1]);		
	Log(paramErr);

    return true;
}

function ApriTabella()
{
	window.open('http://www.visureinrete.it/01_informazioni_sui_servizi/certificato_camerale/tabella_chiusure_cliccabile.asp','tabes','width=1,height=1,scrollbars=yes,resizable=no');
}

function Chiusura(Es)
{
	document.f.m5_TxtChiusura.value = '';
	document.getElementById('contentChius1').innerHTML = '&nbsp;';
	document.getElementById('contentChius2').innerHTML = '&nbsp;';
	document.getElementById('contentChius3').innerHTML = '&nbsp;';
	document.getElementById('contentChius4').innerHTML = '&nbsp;';
	
	var add = '';
	if (document.f.modulo.value == 'modulo1')
	{
		add = '1';
	}
	if (document.f.modulo.value == 'modulo2')
	{
		add = '2';
	}
	if (document.f.modulo.value == 'modulo3')
	{
		add = '3';
	}
	if (document.f.modulo.value == 'modulo4')
	{
		add = '4';
	}
	
	if (Es == 'si')
	{		
		document.getElementById('contentChius' + add).innerHTML = 'Specificare la motivazione per cui si chiede l\'esenzione. <a href="#" onclick="ApriTabella();"><u>Seleziona</u></a>';
	}
	if (Es == 'no')
	{
		document.getElementById('contentChius' + add).innerHTML = 'Nella parte finale del Certificato Camerale viene riportato il numero di marche da bollo da applicarsi a carico del cliente.';
	}
}

