<?php use_helper('UrlFunctions'); ?>
<?php use_helper( 'IncludePartial' ); ?>
<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( 'ubigeo/deleteRow', "block=001" ) ?>", 
                        strFormSerialize,
                        function( o_json )
                        {
                            if( o_json.error )
                            {
                                ocultarCargaImg();
                                mostrarMensajeError( o_json.mensaje_error );
                                return false;
                            }
                            parent.findControl();
                            parent.$( '#dialog' ).dialog( 'close' );
                            return true;
                        } 
                   );
}
</script>
<table class="cuerpo" width="98%" border="0" cellpadding="0" cellspacing="0">
    <tr>
        <td valign="top">
            <form id="form1" name="form1" method="POST" onsubmit="return false;"  enctype="multipart/form-data">
                <input type="hidden" name="s_TipoProc" id="s_TipoProc" value="<?=$s_TipoProc?>">
                <input type="hidden" name="TypeSub" id="TypeSub" value="0">
                <table class="" width="100%">
                    <tr>
                        <td valign="top">
                            <table width="100%" border="0" cellspacing="0" cellpadding="0">
                                <tr>
                                    <td class="marco marcoTitle">
                                        <table class="" width="100%" height="100%" border="0" cellspacing="0" cellpadding="0">
                                            <tr>
                                                <td width="100%" valign="top">

                                                    <?php if( $o_MST_UbigeoBN->getIdUbigeo() ){ $s_Disabled = "disabled"; }else{ $s_Disabled = ""; } ?>
                                                    <input type="hidden" name="i_Id" id="i_Id" value="<?=$o_MST_UbigeoBN->getIdUbigeo()?>">
                                                    <div id="resultContent" style=""></div>
                                                    
                                                    <table width="100%">
                                                        <tr>
                                                            <td width="100%" valign="top" >
                                                            
                                                                <fieldset class="formGen" style="margin-top:0px">
                                                                    
                                                                    <table border="0" cellspacing="6" cellpadding="0" style="margin-left: 20px;">
                                                                       <tr>
                                                                            <td nowrap="nowrap" class="cabecera"><label class="label req" for="TipoUbigeo" >Tipo de Ubigeo</label></td>
                                                                            <td nowrap="nowrap">
                                                                                <select <?=$s_Disabled?> class="combo required" id="TipoUbigeo" name="TipoUbigeo" onchange="LoadCampos(this)">
                                                                                    <option value=""> - Seleccione - </option>
                                                                                    <option value="DEPT" <?php if($o_MST_UbigeoBN->getTipo() == "DEPT" ){ echo "SELECTED"; } ?> >Departamento </option>
                                                                                    <option value="PROV" <?php if($o_MST_UbigeoBN->getTipo() == "PROV" ){ echo "SELECTED"; } ?> >Provincia </option>
                                                                                    <option value="DIST" <?php if($o_MST_UbigeoBN->getTipo() == "DIST" ){ echo "SELECTED"; } ?> >Distrito </option>
                                                                                </select>
                                                                            </td>
                                                                            <td nowrap="nowrap" class="cabecera">&nbsp;</td>
                                                                        </tr>
                                                                        
                                                                        <tr id="rowIdDepartamento" <?php if($TipoUbigeo == "DEPT"){ ?> style="display: none; visibility: hidden;" <?php }?>>
                                                                            <td nowrap="nowrap" width="30%" class="cabecera"><label class="label req" for="IdDepartamento" >Departamento</label></td>
                                                                            <td nowrap="nowrap">
                                                                                <select <?=$s_Disabled?> class="combo required" id="IdDepartamento" name="IdDepartamento" onchange="$('#IdProvincia')[0].options.length = 1;  publicForSelectAjaxJSON('<?php echo buildUrl( 'ubigeo/request', 'block=001') ?>', $( 'form' ).serialize() + '&TipoProc=LoadProv', 'IdProvincia');">
                                                                                    <option value=""> - Seleccione - </option>
                                                                                    <?php foreach ( $a_MST_UbigeoFNDepartamentos as $i_Key => $o_MST_UbigeoBNFNDepartamento ){ ?>
                                                                                    <option value="<?=$o_MST_UbigeoBNFNDepartamento->getIdUbigeo()?>" <?php if( $o_MST_UbigeoBNFNDepartamento->getIdUbigeo()==$IdDpto ){ echo "SELECTED"; } ?> > <?=$o_MST_UbigeoBNFNDepartamento->getDescripcion()?> </option>
                                                                                    <?php } ?>
                                                                                </select>
                                                                            </td>
                                                                            <td nowrap="nowrap" width="20%" class="cabecera">&nbsp;</td>
                                                                        </tr>
                                                                        <tr id="rowIdProvincia" <?php if($TipoUbigeo == "PROV" || $TipoUbigeo == "DEPT"){ ?>style="display: none; visibility: hidden;" <?php }?>>
                                                                            <td nowrap="nowrap" class="cabecera"><label class="label req" for="IdProvincia" >Provincia</label></td>
                                                                            <td nowrap="nowrap">
                                                                                <select <?=$s_Disabled?> class="combo required" id="IdProvincia" name="IdProvincia" >
                                                                                    <option value=""> - Seleccione - </option>
                                                                                     <?php 
                                                                                     if(is_array($a_MST_UbigeoFNProvincias)){
                                                                                    	 foreach ( $a_MST_UbigeoFNProvincias as $i_Key => $o_MST_UbigeoBNFNProvincia ){ ?>
                                                                                    		<option value="<?=$o_MST_UbigeoBNFNProvincia->getIdUbigeo()?>" <?php if( $o_MST_UbigeoBNFNProvincia->getIdUbigeo()==$IdProv ){ echo "SELECTED"; } ?> > <?=$o_MST_UbigeoBNFNProvincia->getDescripcion()?> </option>
                                                                                    <?php } 
                                                                                     }?>
                                                                                </select>
                                                                            </td>
                                                                            <td nowrap="nowrap" class="cabecera">&nbsp;</td>
                                                                        </tr>
                                                                                                                                                
                                                                        <tr>
                                                                            <td nowrap="nowrap" class="cabecera"><label class="label req" for="Descripcion" >Descripción</label></td>
                                                                            <td nowrap="nowrap">
                                                                                <input class="text required" type="text" name="Descripcion" id="Descripcion" value="<?=$o_MST_UbigeoBN->getDescripcion()?>" size="40" maxlength="120"/>
                                                                            </td>
                                                                            <td nowrap="nowrap" class="cabecera">&nbsp;</td>
                                                                        </tr>
                                                                        
                                                                    	
                                                                        <?php if( $o_MST_UbigeoBN->getIdUbigeo() ){ ?>
                                                                        <tr>
                                                                            <td colspan="3">
                                                                                <input type="button" class="button" value="Auditoria" id="btnAudi" onclick="verAuditoria();">
                                                                                <script>
                                                                                $( "#btnAudi" )
                                                                                .click
                                                                                (
                                                                                    function()
                                                                                    {
                                                                                        $( '#myIframe' ).attr( 'src', '<?=buildUrl( 'ubigeo/audi', 'block=001&i_Id='.$o_MST_UbigeoBN->getIdUbigeo() )?>' );
                                                                                        $( '#dialog' ).dialog( 'open' );
                                                                                    }
                                                                                )
                                                                                </script>
                                                                            </td>
                                                                        </tr>
                                                                        <?php } ?>
                                                                    </table>
                                                                    
                                                                </fieldset>
                                                            </td>
                                                        </tr>
                                                    </table>
                                                
                                                </td>
                                            </tr>
                                        </table>
                                    </td>
                                </tr>
                                <tr>
                                    <td>
                                        <table width="100%" border="0" style="margin-top: 10px;">
                                            <tr>
                                                <td align="right" width="55%">
                                                    <input type="button" class="button" value="Cerrar" onclick="parent.$( '#dialog' ).dialog( 'close' );">
                                                    <?php if( $s_TipoProc ==  "dlt" ){ ?>
                                                    <input type="button" class="button" value="Eliminar" onclick="eliminarRegistro();">
                                                    <?php } ?>
                                                </td>
                                                <td width="45%">
                                                    <div id="s_ImagenLoad" style="display: none;"><img src="<?php echo Constantes::ROOT_DIR_APP ?>web/images/progress.gif" border="0"/>&nbsp;<label class="laber req">Grabando...</label></div>
                                                    &nbsp;
                                                </td>
                                            </tr>
                                        </table>
                                    </td>
                                </tr>
                            </table>
                        </td>
                    </tr>
                </table>
            </form>
        </td>
    </tr>
    
</table>

<div id="dialog"><iframe id="myIframe" src="" frameborder="0" height="100%" width="100%"></iframe></div>
<div id="dialog2"><iframe id="myIframe2" src="" frameborder="0" height="100%" width="100%"></iframe></div>
<script>
    objMainTab.modalUIDialog( "#dialog", { title : "Ver Plano", width : 425, height  : 350 } );
    objMainTab.modalUIDialog( "#dialog2", { title : "Auditoria", width : 425, height  : 230 } );
</script>
<script>
eliminarRegistro = function()
{
    x = confirm( "Esta seguro de eliminar el registro?" )
    if( x )
    {
        ejecutarGuardar();
    }
}
</script>