<?php use_helper( 'UtilFunctions' ); ?>
<script>
mostrarCargaImg = function(){ $('#s_ImagenLoad')[0].style.display = 'inline'; }
ocultarCargaImg = function(){ $('#s_ImagenLoad')[0].style.display = 'none'; }

mostrarMensajeError = function( s_MensajeError )
{
    $( "#resultContent" ).html( '<div id="mensaje_error_content" class="error">' + s_MensajeError + '</div>' );
    setTimeout( function(){ $( "#mensaje_error_content" ).fadeOut( 800 ).fadeIn( 800 ).fadeOut( 500 ).fadeIn( 500 ).fadeOut( 300 ); }, 4000 );
}
</script>
<script>
ejecutarGuardar = function()
{
	mostrarCargaImg();
	var strFormSerialize = $( 'form' ).serialize();
    executeAjaxJson( 
                        "<?php echo buildUrl( 'listprecios/saveAddEdit', "block=001" ) ?>", 
                        strFormSerialize,
                        function( o_json )
                        {
                            //console.log( o_json );
                            ocultarCargaImg();
                            if( o_json.error )
                            {
                                mostrarMensajeError( o_json.mensaje_error );
                                return false;
                            }
                            //return false;
                            switch ( o_json.type_sub )
                            {
                                case "0":
                                    location.href = "<?=buildUrl( 'listprecios/addedit', "block=001&s_TipoProc=upd&i_Id=")?>" + o_json.id;
                                break;
                                case "1":
                                    location.href = "<?=buildUrl( 'listprecios/list', "block=001")?>";
                                break;
                            }
                        } 
                   );
}
</script>

<?php if( $o_DefaultBN->getIdConcat() ){ $s_Disabled = "disabled"; }else{ $s_Disabled = ""; } ?>
<input type="hidden" name="i_Id" id="i_Id" value="<?=$o_DefaultBN->getIdConcat()?>">
<div id="resultContent" style=""></div>


<div class="card">
    <div class="container">

        <div class="form-row mx-0">
            <div class="col-md-6 mb-1">
                <label class="col-form-label" for="IdTipoLista">Tipo Lista</label>
                <select class="form-control form-control-sm custom-select my-0 mr-sm-2" name="IdTipoLista" id="IdTipoLista" required>
                    <option value=""> - SELECCIONE - </option>
                    <option value="1" <?php if( $o_DefaultBN->getIdTipoLista() == 1 ){ echo "selected"; } ?> > RANGO POR VENTA </option>
                    <option value="2" <?php if( $o_DefaultBN->getIdTipoLista() == 2 ){ echo "selected"; } ?>> RANGO POR ALQUILER </option>
                    <option value="3" <?php if( $o_DefaultBN->getIdTipoLista() == 3 ){ echo "selected"; } ?>> POR TIPO DE PRECIOS </option>
                </select>
            </div>
            <div class="col-md-6 mb-1">
                &nbsp;
            </div>
        </div>
        <div class="form-row mx-0">
            <div class="col-md-6 mb-1">
                <label class="col-form-label" for="Estado">Estado</label>
                    <?=crearSelect( array( "Estado", "Llave", "Valor" ), array( array( "Llave" => "A", "Valor" => "ACTIVO" ), array( "Llave" => "I", "Valor" => "INACTIVO" ) ), $o_DefaultBN->getEstado() )?>
            	</div>
            <div class="col-md-6 mb-1">
                <label class="col-form-label" for="Estado">Moneda</label>
                <select
                    class="form-control form-control-sm custom-select my-0 mr-sm-2"
                    name="IdMoneda" id="IdMoneda" required>
                    	<?php foreach ( $a_GSS_MonedaMast as $i_Key => $o_GSS_MonedaMastBN ){ ?>
                        <option
                        value="<?=$o_GSS_MonedaMastBN->getIdMoneda()?>"
                        <?php if( $o_DefaultBN->getIdMoneda()==$o_GSS_MonedaMastBN->getIdMoneda() ){ echo "selected"; } ?>> <?=$o_GSS_MonedaMastBN->getDescripcion()?> </option>
                        <?php } ?>
                	</select>
            </div>

        </div>
           
            
        <?php if( $o_DefaultBN->getIdConcat() ){ ?>
            <!-- <br>
            <button type="submit" class="btn btn-primary btn-lg btn-block" id="btnAudi">Auditoria</button>
            <script>
                    $( "#btnAudi" )
                    .click
                    (
                        function()
                        {
                            $( '#myIframe' ).attr( 'src', '<?=buildUrl( 'listprecios/audi', 'block=001&i_Id='.$o_DefaultBN->getIdConcat() )?>' );
                            $( '#dialog' ).dialog( 'open' );
                        }
                    )
            </script>
            <br> -->
        <?php } ?>
        
        <div class="form-group col-14">
            <div class="dropdown-divider"></div>
            
            
        </div>
    </div>
</div>

<div id="dialog" style="display:none;"><iframe id="myIframe" src="" frameborder="0" height="100%" width="100%"></iframe></div>
<script>
    objMainTab.modalUIDialog( "#dialog", { title : "Auditoria", width : 425, height  : 230 } );
</script>
                                                    
<script>
$.validator.setDefaults
(
    {
        submitHandler: function( form ) 
        {
            ejecutarGuardar();
        }
    }
);
$( "#form1" ).validate();
</script>