﻿
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 CurrFile = location.pathname.split('/');
	var logmsg = '';
    try
    {
	    if (document.f.modulo.value == 'modulo1')
	    {
		    // controllo primo form            
                        
            if (document.f.m1_PR.selectedIndex == 0)
		    {
			    jAlertWrapper('Selezionare la Provincia dell\'Immobile', 'Sezione A');
			    return false;
		    }
		    if (document.f.m1_CboComune.selectedIndex == -1 || document.f.m1_CboComune.options.length == 1)
		    {
			    jAlertWrapper('Selezionare il Comune dell\'Immobile', 'Sezione A');
			    return false;
		    }
		    else if (document.f.m1_CboComune.selectedIndex == 0)
		    {
			    jAlertWrapper('Selezionare il Comune dell\'Immobile', 'Sezione A');
			    return false;
		    }
		    if (document.f.m1_TxtToponimo.selectedIndex == 0)
		    {
			    jAlertWrapper('Selezionare il Toponimo dell\'Immobile', 'Sezione A');
			    return false;
		    }
		    if (document.f.m1_TxtIndirizzo.value == '')
		    {
			    jAlertWrapper('Inserire l\'Indirizzo dell\'Immobile', 'Sezione A');
			    return false;		
		    }
		    if (document.f.m1_dalcivico.value != '')
		    {
			    if (!check_num(document.f.m1_dalcivico.value))
			    {
				    jAlertWrapper('Il campo Civico deve contenere solo caratteri numerici', 'Sezione A');
				    return false;
			    }
		    }
		    
		    document.f.m1_comune.value = document.f.m1_CboComune.options[document.f.m1_CboComune.selectedIndex].text;
            
            logmsg = document.f.m1_PR.value + ', ' + document.f.m1_CboComune.value + ', ' + document.f.m1_TxtToponimo.value + ', ' + document.f.m1_TxtIndirizzo.value + ', ' + document.f.m1_dalcivico.value + ', ' + document.f.m1_comune.value + ', visura fabbricati';
	    }
	}
	catch(err)
    {
    	//*** POTENZIAMENTO LOG
    	var PR = 'null';
    	var CboComune = 'null';
    	var TxtToponimo = 'null';
    	var TxtIndirizzo = 'null';
    	var dalcivico = 'null';
    	var Comune = 'null';
    	if (document.f.m1_PR.value != '')
    	{
    		PR = document.f.m1_PR.value.replace('\'', '\'\'');
    	}
		if (document.f.m1_CboComune.value != '')
		{
			CboComune = document.f.m1_CboComune.value.replace('\'', '\'\'');
			Comune = document.f.m1_CboComune.options[document.f.m1_CboComune.selectedIndex].text;
		}
    	if (document.f.m1_TxtToponimo.value != '')
    	{
    		TxtToponimo = document.f.m1_TxtToponimo.value.replace('\'', '\'\'');
    	}
    	if (document.f.m1_TxtIndirizzo.value != '')
    	{
    		TxtIndirizzo = document.f.m1_TxtIndirizzo.value.replace('\'', '\'\'');
    	}
    	if (document.f.m1_dalcivico.value != '')
    	{
    		dalcivico = document.f.m1_dalcivico.value.replace('\'', '\'\'');
    	}
    	
        err.message = 'okdati(modulo1, ' + PR + ', ' + CboComune + ', ' + Comune + ', ' + TxtToponimo + ', ' + TxtIndirizzo + ', ' + dalcivico + ') :: ' + err.message;
        throw(err);
        
        return false;
    }
	
	try
    {
	    if (document.f.modulo.value == 'modulo2')
	    {
		    // controllo secondo form	
		    if ((document.f.m2_ChkVisFab.checked == false) && (document.f.m2_ChkVisTer.checked == false))
		    {
			    jAlertWrapper('Selezionare il Tipo di Ricerca', 'Sezione A');
			    return false;
		    }
		    if ((document.f.m2_ChkVisFab.checked == true) && (document.f.m2_ChkVisTer.checked == true))
		    {
			    jAlertWrapper('Selezionare la \'Visura Fabbricati\' o la \'Visura Terreni\'', 'Sezione A');
			    return false;
		    }		    
		    if (document.f.m2_PR.selectedIndex == 0)
		    {
			    jAlertWrapper('Selezionare la Provincia dell\'Immobile', 'Sezione A');
			    return false;
		    }
		    if (document.f.m2_CboComune.selectedIndex == -1 || document.f.m2_CboComune.options.length == 1)
		    {
			    jAlertWrapper('Selezionare il Comune dell\'Immobile', 'Sezione A');
			    return false;
		    }
		    else if (document.f.m2_CboComune.selectedIndex == 0)
		    {
			    jAlertWrapper('Selezionare il Comune dell\'Immobile', 'Sezione A');
			    return false;
		    }
		    if (document.f.m2_Foglio.value == '')
		    {
			    jAlertWrapper('Inserire il Foglio dell\'Immobile', 'Sezione A');
			    return false;
		    }
		    if (document.f.m2_Particella.value == '')
		    {
			    jAlertWrapper('Inserire la Particella dell\'Immobile', 'Sezione A');
			    return false;
		    }
		    if ((document.f.m2_Subalterno.value != '') && (document.f.m2_ChkVisTer.checked == true))
		    {
			    jAlertWrapper('Il campo Subalterno non va inserito nel caso di Visura Terreni', 'Sezione A');
			    return false;
		    }
		    if (document.f.m2_Subalterno.value != '')
	    	{
	    		if (!(check_num(document.f.m2_Subalterno.value))) {
	    			jAlertWrapper('Inserire solo caratteri numerici nel campo Subalterno', 'Sezione A');
				    return false;
	    		}
	    	}
		    
		    document.f.m2_comune.value = document.f.m2_CboComune.options[document.f.m2_CboComune.selectedIndex].text;
		    
		    logmsg = document.f.m2_PR.value + ', ' + document.f.m2_CboComune.value + ', ' + document.f.m2_Foglio.value + ', ' + document.f.m2_Particella.value + ', ' + document.f.m2_Subalterno.value + ', ' + document.f.m2_comune.value;
		    if (document.f.m2_ChkVisFab.checked == true)
				logmsg = logmsg + ', visura fabbricati';
			if (document.f.m2_ChkVisTer.checked == true)
				logmsg = logmsg + ', visura terreni';
	    }
	}
	catch(err)
    {
    	//*** POTENZIAMENTO LOG
    	var PR = 'null';
    	var CboComune = 'null';
		var Foglio = 'null';
		var Particella = 'null';
		var Subalterno= 'null';
		var Comune = 'null';
	    if (document.f.m2_PR.value != '')
    	{
    		PR = document.f.m2_PR.value.replace('\'', '\'\'');
    	}
		if (document.f.m2_CboComune.value != '')
		{
			CboComune = document.f.m2_CboComune.value.replace('\'', '\'\'');
			Comune = document.f.m2_CboComune.options[document.f.m2_CboComune.selectedIndex].text;
		}
    	if (document.f.m2_Foglio.value != '')
    	{
    		Foglio = document.f.m2_Foglio.value.replace('\'', '\'\'');
    	}
    	if (document.f.m2_Particella.value != '')
    	{
    		Particella = document.f.m2_Particella.value.replace('\'', '\'\'');
    	}
		if (document.f.m2_Subalterno.value != '')
    	{
    		Subalterno= document.f.m2_Subalterno.value.replace('\'', '\'\'');
    	}

    	err.message = 'okdati(modulo2, ' + PR + ', ' + CboComune + ', ' + Comune + ', ' + Foglio + ', ' + Particella + ', ' + Subalterno + ') :: ' + 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;
}

