/****************************************************/
/****************************************************/
/****************************************************/
/****************************************************/
/****************************************************/
/****************************************************/
/****************************************************/


$('#btn_reg_struttura').click(function(){

    $('#nome_struttura').css("border", "");
    $('#referente').css("border", "");
    $('#sito_web').css("border", "");
    $('#email_struttura').css("border", "");
    $('#telefono_struttura').css("border", "");
    $('#categoria_struttura').css("border", "");
    $('#gridCheck').css("border", "");

     $('#text_msg').html('');
     $('#btn_reg_struttura').html('Attendere prego...');
     
    var nome_struttura = $('#nome_struttura').val();
    var referente = $('#referente').val();
    var email_struttura = $('#email_struttura').val();
    var sito_struttura = $('#sito_web').val();
    var telefono_struttura = $('#telefono_struttura').val();
    var categoria_struttura = $('#categoria_struttura').val();
    var check196 = $('#check_privacy').prop('checked');
  
    var errore = 0;

    if(nome_struttura==''){        var errore = 1;        $('#nome_struttura').css("border", "2px solid red");    }    
    if(referente==''){        var errore = 1;        $('#referente').css("border", "2px solid red");    }    
    if(email_struttura==''){        var errore = 1;        $('#email_struttura').css("border", "2px solid red");    }    
    if(telefono_struttura==''){        var errore = 1;        $('#telefono_struttura').css("border", "2px solid red");    }    
    if(categoria_struttura=='0'){        var errore = 1;        $('#categoria_struttura').css("border", "2px solid red");    }            
    if(check196==false){        var errore = 1;         $('#gridCheck').css("border", "2px solid red");     }        
    
    
    if(errore==0){
        var dataRichiesta = {'NomeStruttura':nome_struttura, 'ReferenteStruttura':referente, 'EmailStruttura':email_struttura, 'SitoStruttura':sito_struttura, 'TelefonoStruttura':telefono_struttura, 'CategoriaStruttura':categoria_struttura };    
        
        $.ajax({
                 url: '/wp-content/themes/crisalidelab_newage/crisalidelab/sendmailer_regstruttura.php',
                 type: "POST",
                 dataType:'json',
                 data: dataRichiesta,
                 success: function(data){                     
                     if(data.type=='error'){
                         $('#text_msg').html(data.text);      
                         $('#btn_reg_struttura').html('Proponi Struttura');
                     }else{
                        $('#nome_struttura').val('');
                        $('#referente').val('');
                        $('#sito_web').val('');
                        $('#email_struttura').val('');
                        $('#telefono_struttura').val('');
                        $('#categoria_struttura').val(0);

                        $('#gridCheck').css('outline-color', '');
                        $('#gridCheck').css('outline-style', '');
                        $('#gridCheck').css('outline-width', '');                         
                        $('#gridCheck').prop('checked', false);
                        $('#FrmRichiestaRegStruttura').hide();
                        $('#text_msg').html(data.text);          
                     }              
                 }
        });        
    }else{
        $('#btn_reg_struttura').html('Proponi Struttura');
        $('#text_msg').html('<span style="color: #FF0000;">Attenzione - Verificare i dati obbligatori.</span>');                
    }
    
});