<?php use_helper( 'UrlFunctions' ); ?>
<?php use_helper( 'IncludePartial' ); ?>
<?php use_helper( 'UtilFunctions' ); ?>
<style>
body{
    margin-right: 5px;
    font-size:60%;
}
label
{
    margin-right: 0;
}
.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;*/
}
select{ padding: 2px; }
</style>
<script type="text/javascript">
listarRutasExistentes = function()
{
    if( $( "#RutaFechaProgramada" ).val() == "" )
    {
    	alert( "Debe de seleccionar la Fecha." );
        return false;
    }
    if( $( "#IdTurno" ).val() == "" )
    {
        //alert( "Debe de seleccionar el Turno." );
        //return false;
    }
	var s_param = $( '#form1' ).serialize();
    console.log( s_param );
    
	blockContent( 'content_grid_rutas' );
	mostrarCargaImg();
    
    executeAjaxUpdater
    ( 
        "content_grid_rutas", 
        "<?=buildUrl( 'transporte/gridRutaExist' )?>", 
        s_param, 
        function()
        {
        	unBlockContent( 'content_grid_rutas' );
        	ocultarCargaImg();
        }
    );
}
seleccionarRuta = function( IdRuta )
{
    //var FechaProgramada = $( "#RutaFechaProgramada" ).val();

    //parent.$( "#RutaFechaProgramada" ).val( FechaProgramada );
    //parent.$( "#IdTurno" ).val( IdTurno );
    //parent.$( "#IdVehiculo" ).val( IdVehiculo );
    //parent.$( "#IdChofer" ).val( IdChofer );
    //parent.$( "#IdRuta" ).val( IdRuta );
    	
    parent.buscarRutaAsignada( IdRuta );
    parent.$( '#dialog2' ).dialog( 'close' );
}
eliminarRuta = function( i_Id )
{
	x = confirm( "Esta seguro de eliminar la Ruta?" );
    if( x )
    {
    	blockContent( 'content_grid_rutas' );
        var strFormSerialize = "i_Id=" + i_Id;
        executeAjaxJson
        ( 
            "<?php echo buildUrl( 'transporte/eliminarRuta' ) ?>", 
            strFormSerialize,
            function( o_json )
            {
                unBlockContent( "content_grid_rutas" );
                if( o_json.error )
                {
                	//showAlertBootStrap( 'content_alert', 'alert-danger', o_json.mensaje_error );
                	alert( o_json.mensaje_error );
                    return false;
                }
                listarRutasExistentes();
            } 
        );
    }
    
}
</script>
<div style="">
    <div>
        <form action="" method="post" name="form1" id="form1">
            <table class="marco" style="background:#E3E9E2" width="100%" border="0" cellpadding="0" cellspacing="0">
                <tr>
                    <td align="center" width="80%">
                        <table width="99%" cellspacing="0" cellpadding="0" border="0">
                            <tr>
                                <td nowrap="nowrap">
                                    <table width="100%" cellspacing="1" cellpadding="0" border="0" class="SubCabecera">
                                         <tr>
                                            <td nowrap="nowrap" width="30%" align="right"><label for="RutaFechaProgramada" class="label">Turno:</label></td>
                                            <td nowrap="nowrap">
                                            	<div>
                                                    <input type="text" class="text" name="RutaFechaDesde" id="RutaFechaDesde" size="12" style="text-align:center;" value="<?=date( "Y-m-d" )?>" onfocus="this.select()">
                                                    <script type="text/javascript">
                                                    $( "#RutaFechaDesde" ).datepicker
                                                    (
                                                        { 
                                                            dateFormat: "yy-mm-dd", changeYear:true, yearRange: "-0:+1", changeMonth: true, 
                                                            onClose: function ()
                                                            { 
                                                                this.focus();  
                                                            },
                                                            onSelect: function()
                                                            {
                                                                $( "#IdTurno" ).val( "" );
                                                                $( "#content_grid_rutas" ).html( "" );
                                                            }
                                                        }
                                                    );
                                                    </script>
                                                    <input type="text" class="text" name="RutaFechaHasta" id="RutaFechaHasta" size="12" style="text-align:center;" value="">
                                                    <script type="text/javascript">
                                                    $( "#RutaFechaHasta" ).datepicker
                                                    (
                                                        { 
                                                            dateFormat: "yy-mm-dd", changeYear:true, yearRange: "-0:+1", changeMonth: true, 
                                                            onClose: function ()
                                                            { 
                                                                this.focus();  
                                                            },
                                                            onSelect: function()
                                                            {
                                                                $( "#IdTurno" ).val( "" );
                                                                $( "#content_grid_rutas" ).html( "" );
                                                            }
                                                        }
                                                    );
                                                    </script>
                                                    <?=crearCombo( array( "name"=>"IdTurno", "ParamId"=>"getIdTurno", "ParamDesc"=>"getTurnoDescripcion", "seleccione"=>"-----", "style"=>"width:120px" ), TR_TurnoFN::selectActivos() )?>
                                                    <script type="text/javascript">
                                                    $( "#IdTurno" ).change
                                                    (
                                                        function()
                                                        {
                                                            $( "#content_grid_rutas" ).html( "" );
                                                        }
                                                    )
                                                    </script>
                                                </div>
                                            </td>
                                        </tr>
                                    </table>
                                </td>
                            </tr>
                        </table>
                    </td>
                    <td width="10%" align="center"><input type="button" value="Buscar" class="button" onclick="listarRutasExistentes();"></td>
                    <td width="3%" align="center"><div id="s_ImagenLoad" style="display: none;"><img src="<?php echo Constantes::ROOT_DIR_IMG ?>common/progress.gif" border="0"/></div></td>
                </tr>
            </table>
        </form>
    </div>
</div>
<div id="content_alert"></div>
<div style="" id="content_grid_rutas">
</div>