<?php use_helper('UrlFunctions'); ?>
<?php use_helper( 'IncludePartial' ); ?>
<style>
  .ui-autocomplete-loading { background: white url("<?=Constantes::ROOT_DIR_IMG?>common/progress.gif") right center no-repeat; }
</style>
<style>
.header { background-color: #E1E1E1; color: #444444; font-family: Arial,Helvetica,sans-serif; font-size: 11px; font-weight: bold; }
.pager { background-color: #F4F4F4; background-image: none; border-bottom: thin solid #999999; }
</style>
<style type="text/css">
.marcoTabActive {
  /*background:#F1F1F1 none repeat scroll 0 0;*/
  background:#A3C1E0 none repeat scroll 0 0;  font-family:Geneva, Arial, Helvetica, sans-serif;  font-size:14px;  border-top-width: 1px;
  border-right-width: 1px;  border-left-width: 1px;  border-top-style: solid;  border-right-style: solid;  border-left-style: solid;  border-top-color: #999999;
  border-right-color: #999999;  border-left-color: #999999;  font-weight: bold;  /*color:#990000;*/
}
.label { color: #444444; }
.lblSmall { color: #8D8D8D; font-size: 10px; padding-right: 8px; }
</style>
<style>
.codigoItem{ color: blue; text-decoration: underline; cursor: pointer; }
.codigoItem:hover{ text-decoration: none; cursor: pointer; }
</style>

<style>
.grid
{
    border: 1px solid #77d5f7;
    border-top-left-radius: 5px;
    border-top-right-radius: 5px;
    border-bottom-right-radius: 5px;
    border-bottom-left-radius: 5px;
}
.grid th 
{
    border-color: #77d5f7;
    background-color: #0a7db1;
    font-weight: normal;
    font-size: 11px;
    font-family: Verdana,Arial,sans-serif;
    height: 24px;
    padding: 0 2px;
}
.grid td 
{
    border-left: 0 none;
    border-right-color: #77d5f7;
    border-right-style: solid;
    border-right-width: 1px;
    border-bottom-color: #77d5f7;
    border-bottom-style: solid;
    border-bottom-width: 1px;
    padding: 0 2px;
    /*white-space: pre;*/
    height: 22px;
    /*border: 1px solid #77d5f7;*/
}
.grid td div
{
    overflow: hidden; white-space: nowrap; width: 150px; font-size: 10px;
}
.grid td label
{
    margin-right: 0;
}
</style>

<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>
blockContent = function( s_IdElement )
{
    $( '#' + s_IdElement ).block
            ( 
                { 
                    message: null,
                    css: { cursor: 'context-menu' }
                } 
            ); 
    $( ".blockUI" ).css( "cursor", "context-menu" );
};
unBlockContent = function( s_IdElement )
{
    $( '#' + s_IdElement ).unblock();
}
</script>
<script>
ejecutarGuardar = function()
{
	mostrarCargaImg();
	var strFormSerialize = $( 'form' ).serialize();
    executeAjaxJson( 
                        "<?php echo buildUrl( 'user/saveUserComp', "block=001" ) ?>", 
                        strFormSerialize,
                        function( o_json )
                        {
                            if( o_json.error )
                            {
                                ocultarCargaImg();
                                mostrarMensajeError( o_json.mensaje_error );
                                return false;
                            }
                            location.href = "<?=buildUrl( 'user/list', "block=001" )?>";
                        } 
                   );
}
</script>
<div class="titleBody descripProy">
    <ul>
        <li>
            <?=$s_Titulo?>
        </li>
    </ul>
</div>

<table class="cuerpo" width="99%" border="0" cellpadding="0" cellspacing="0">
    <tr>
        <td valign="top">
            <form id="form1" name="form1" method="POST" onsubmit=""  enctype="multipart/form-data">
                <input type="hidden" name="s_TipoProc" id="s_TipoProc" value="<?=$s_TipoProc?>">
                <input type="hidden" name="i_Id" id="i_Id" value="<?=$i_Id?>">
                <input type="hidden" name="i_IdCompania" id="i_IdCompania" value="<?=$o_UsuarioBN->getIdCompania()?>">
                <table class="" width="100%">
                    <tr>
                        <td valign="top">
                            <table width="100%" border="0" cellspacing="0" cellpadding="0">
                                <tr>
                                    <td>
                                        <table id="tabShowScan" cellpadding="0" cellspacing="0" class="mnuElement">
                                            <tr>
                                                <td class="mnuInactivoIzq"><img src="<?=Constantes::ROOT_DIR_IMG?>common/spacer.gif" width="0" /></td>
                                                <td class="mnuInactivoTxt" nowrap="nowrap" onclick="location.href='<?=buildUrl( 'user/add', "block=001&s_TipoProc=upd&i_Id=".$i_Id )?>';">General</td>
                                                <td class="mnuInactivoDer"><img src="<?=Constantes::ROOT_DIR_IMG?>common/spacer.gif" width="1" /></td>

                                                <td class="mnuActivoIzq"><img src="<?=Constantes::ROOT_DIR_IMG?>common/spacer.gif" width="0" /></td>
                                                <td class="mnuActivoTxt" nowrap="nowrap" onclick="location.href='<?=buildUrl( 'user/detail', "block=001&s_TipoProc=upd&i_Id=".$i_Id )?>';">Asociar</td>
                                                <td class="mnuActivoDer"><img src="<?=Constantes::ROOT_DIR_IMG?>common/spacer.gif" width="1" /></td>

                                                <td class="mnuInactivoIzq"><img src="<?=Constantes::ROOT_DIR_IMG?>common/spacer.gif" width="0" /></td>
                                                <td class="mnuInactivoTxt" nowrap="nowrap" onclick="location.href='<?=buildUrl( 'user/detPtoVta', "s_TipoProc=upd&i_Id=".$i_Id )?>';">Punto de Venta</td>
                                                <td class="mnuInactivoDer"><img src="<?=Constantes::ROOT_DIR_IMG?>common/spacer.gif" width="1" /></td>
                                            </tr>
                                        </table>
                                    </td>
                                </tr>
                                
                                <tr>
                                    <td class="marco">
                                        <table class="" width="100%" height="100%" border="0" cellspacing="0" cellpadding="0">
                                            <tr>
                                                <td width="100%" valign="top">
                                                        <?php include_partial( 
                                                                                "infohead", 
                                                                                array( 
                                                                                        "o_UsuarioBN" => $o_UsuarioBN,
                                                                                        "o_RolBN"     => $o_RolBN
                                                                                     )
                                                                             ); ?>
                                                </td>
                                            </tr>
                                        </table>
                                    </td>
                                </tr>
                                
                                <tr><td>&nbsp;</td> </tr>
                                
                                <tr>
                                    <td class="marco">
                                    
                                        <div id="resultContent" style=""></div>

<fieldset class="formGen" style="margin-top:0px">
    <legend class="fielsettex">Lista de Compa&ntildeias y Sucursales a Seleccionar</legend> 
    <div id="content_result_grid1">
        <table class="grid" cellspacing="0" cellpadding="0" border="0" align="center" width="60%" style="border-bottom: 1px solid #999999;">
            <tbody id="">
                <tr>
                    <th width="1%"  align="center" class="header"><input type="checkbox" id="all_checked"></th>
                    <th width="40%" align=""       class="header"><b>Descripci&oacute;n</b></th>
                </tr>
            </tbody>
            <tbody id="content_all_row">
                <?php foreach ( $a_GSS_Compania as $i_Key => $o_GSS_CompaniaBN ){ ?>
                <tr class="content_row">
                    <td align="center">
                                <input 
                                 type="checkbox"
                                 name="a_lst_companias[]" 
                                 id="" 
                                 value="<?=$o_GSS_CompaniaBN->getIdCompania()?>"
                                 <?php if( $o_GSS_CompaniaBN->getObjCompaniaUsuario( $o_UsuarioBN->getIdUsuario() ) ){ echo "CHECKED"; } ?>
                                >
                    </td>
                    <td class="row" align=""><?=$o_GSS_CompaniaBN->getDescripcionCorta()?></td>
                </tr>
                    <?php if( isset( $a_LstSucursal[$o_GSS_CompaniaBN->getIdCompania()] ) ){ ?>
                        <?php foreach ( $a_LstSucursal[$o_GSS_CompaniaBN->getIdCompania()] as $i_Key => $o_GSS_SucursalBN ){ ?>
                        <tr class="content_row">
                            <td class="row" align=""></td>
                            <td align="">
                                <input 
                                         type="checkbox"
                                         name="a_lst_sucursales[<?=$o_GSS_CompaniaBN->getIdCompania()?>][]" 
                                         id="" 
                                         value="<?=$o_GSS_SucursalBN->getIdSucursal()?>"
                                         <?php if( $o_GSS_SucursalBN->getObjSucursalUsuario( $o_UsuarioBN->getIdUsuario() ) ){ echo "CHECKED"; } ?>
                                >
                                <?=$o_GSS_SucursalBN->getDescripcion()?>
                            </td>
                            
                        </tr>
                        <?php } ?>
                    <?php } ?>
                <?php } ?>
            </tbody>
        </table>
    </div>
</fieldset>                                        
<br>
<script>
$( '#all_checked' ).change( function() 
{
    var checkboxes = $( "#content_all_row" ).find( ':checkbox' );
    checkboxes.prop( 'checked', $( this ).is( ':checked' ) );
});
</script>
                                        
                                    </td>
                                </tr>
                            </table>
                        </td>
                    </tr>
                </table>
            </form>
        </td>
    </tr>
</table>

                                        <table cellpadding="0" cellspacing="0" width="100%" border="0" style="">
                                            <tr>
                                                <td align="center" >
                                                    <input type="button" class="button" value="Salir" onclick="location.href='<?php echo buildUrl( 'user/list', 'block=001' ) ?>'">
                                                    <input type="button" class="button" value="Grabar" onclick="ejecutarGuardar()">
                                                    <div id="s_ImagenLoad" style="display: none;"><img src="<?php echo Constantes::ROOT_DIR_APP ?>/web<?=Constantes::ROOT_DIR_IMG?>progress.gif" border="0"/>&nbsp;<label class="laber req">Grabando...</label></div>
                                                </td>
                                            </tr>
                                        </table>