<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( 'tipocambio/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( 'tipocambio/addedit', "block=001&s_TipoProc=upd&i_Id=")?>" + o_json.id;
                                break;
                                case "1":
                                    location.href = "<?=buildUrl( 'tipocambio/list', "block=001")?>";
                                break;
                            }
                        } 
                   );
}
</script>

<?php if( $o_GSS_TipoCambioBN->getIdTipoCambio() ){ $s_Disabled = "disabled"; }else{ $s_Disabled = ""; } ?>
<input type="hidden" name="i_Id" id="i_Id" value="<?=$o_GSS_TipoCambioBN->getIdTipoCambio()?>">

<div id="resultContent" style=""></div>
<input type="hidden" name="IdMoneda" id="IdMoneda" value="EX">
<input type="hidden" name="IdMonedaCambio" id="IdMonedaCambio" value="LO">
<table border="0" cellpadding="0" cellspacing="0" width="100%">
    <tr>
        <td width="" valign="top" >
            <fieldset class="formGen" style="margin-top:0px">
                <table border="0" cellpadding="0" cellspacing="0" width="100%">
                    <tr>
                        <td width="50%">
                            <table border="0" cellspacing="6" cellpadding="0" style="margin-left: 20px;">
                                <input type="hidden" name="IdCompania" id="IdCompania" value="<?=myUser::getUser()->getIdBusiness()?>" />
                                <tr>
                                    <td nowrap="nowrap" class="cabecera"><label class="label req" for="FechaCambio" >Fecha Registro</label></td>
                                                                                             <td nowrap="nowrap" width="80%">
                                            <input type="text" class="text" name="FechaCambio" id="FechaCambio" size="10px" value="<?=substr( $o_GSS_TipoCambioBN->getIdFechaCambio(),0 ,10 )?>" />
                                            <script type="text/javascript">
                                            $( "#FechaCambio" ).datepicker( { dateFormat: "yy-mm-dd", changeYear:true, yearRange: "-100:+0", changeMonth: true, onClose: function (){ this.focus(); } } );
                                            </script>
                                        </td>
                                        <td nowrap="nowrap" class="cabecera">&nbsp;</td>
                                    </tr>
                                    
                                    <!--<tr>
                                        <td nowrap="nowrap" class="cabecera" colspan="2">

                                            <label class="label">De </label>
                                            <label class="label">a </label>
                                     </td>
                                    <td nowrap="nowrap" class="cabecera">&nbsp;</td>
                                </tr>-->

                                <tr>
                                    <td nowrap="nowrap" class="cabecera"><label class="label req" for="Descripcion" >T/C - Sunat - Compra</label></td>
                                    <td nowrap="nowrap">
                                        <input class="text required" type="text" name="SunatCompra" id="SunatCompra" size="10" maxlength="45" value="<?=$o_GSS_TipoCambioBN->getSunatCompra();?>"  onblur="this.value=this.value.toUpperCase();"/>
                                    </td>
                                    <td nowrap="nowrap" class="cabecera">&nbsp;</td>
                                </tr>
                                 <tr>
                                    <td nowrap="nowrap" class="cabecera"><label class="label req" for="Descripcion" >T/C - Sunat - Venta</label></td>
                                    <td nowrap="nowrap">
                                        <input class="text required" type="text" name="SunatVenta" id="SunatVenta" size="10" maxlength="45" value="<?=$o_GSS_TipoCambioBN->getSunatVenta();?>"  onblur="this.value=this.value.toUpperCase();"/>
                                    </td>
                                    <td nowrap="nowrap" class="cabecera">&nbsp;</td>
                                </tr>
                                  <tr>
                                    <td nowrap="nowrap" class="cabecera"><label class="label req" for="Descripcion" >T/C Comercial</label></td>
                                    <td nowrap="nowrap">
                                        <input class="text" type="text" name="TipoCambioCobranza" id="TipoCambioCobranza" size="10" maxlength="45" value="<?=$o_GSS_TipoCambioBN->getTipoCambioCobranza();?>"  onblur="this.value=this.value.toUpperCase();"/>
                                    </td>
                                    <td nowrap="nowrap" class="cabecera">&nbsp;</td>
                                </tr>
                                <tr>
                                    <td nowrap="nowrap" class="cabecera"><label class="label req" for="Estado" >Estado</label></td>
                                    <td nowrap="nowrap">
                                        <select class="combo required" id="Estado" name="Estado" >
                                            <option value=""> - Seleccione - </option>
                                            <option value="A" <?php if( $o_GSS_TipoCambioBN->getEstado()=="A" ){ echo "SELECTED"; } ?>> ACTIVO </option>
                                            <option value="I" <?php if( $o_GSS_TipoCambioBN->getEstado()=="I" ){ echo "SELECTED"; } ?>> INACTIVO </option>
                                        </select>
                                    </td>
                                    <td nowrap="nowrap" class="cabecera">&nbsp;</td>
                                </tr>
                                <?php if( $o_GSS_TipoCambioBN->getIdMonedaCambio() ){ ?>
                                <tr>
                                    <td colspan="3">
                                        <input type="button" class="button" value="Auditoria" id="btnAudi">
                                        <script>
                                        $( "#btnAudi" )
                                        .click
                                        (
                                            function()
                                            {
                                                $( '#myIframe' ).attr( 'src', '<?=buildUrl( 'tipocambio/audi', 'block=001&i_Id='.$o_GSS_TipoCambioBN->getIdTipoCambio() )?>' );
                                                $( '#dialog' ).dialog( 'open' );
                                            }
                                        )
                                        </script>
                                    </td>
                                </tr>
                                <?php } ?>
                            </table>
                        </td>
                    </tr>
                </table>

            </fieldset>
        </td>
        
                                <td>
                            <iframe id="myIframe" src="https://e-consulta.sunat.gob.pe/cl-at-ittipcam/tcS01Alias" frameborder="0" height="600" width="100%"></iframe>
                        </td>
        
    </tr>
</table>
                                                    
<div id="dialog"><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>