function generalEstaProcess( obj )
{
    if( obj.action || obj.dataId )
    {
        if( obj.dataId )
        {
            obj.data    =   $( obj.dataId );
        }
        else
        {
            obj.data    =   obj;
        }
        if( !obj.method )
        {
            obj.method = 'get';
        }
        obj.evalScripts = true;
        
        preLoader(0);
        
        new Ajax( urlEstadisticas, obj).request();
    }
}

function estaMenu( menu )
{
    var obj = {
        'update'    :   $( 'estContDiv'),
        'action'    :   'esta_menu',
        'menu'      :   menu
    };
    preLoader(1, 'estContDiv' );
    generalEstaProcess( obj );
}

function ventaUser( )
{
    var tmp = arguments[ 0 ].split("_");
    var user_id = tmp.pop(); 
    var obj = {
        'user_id'   :   user_id,
        'action'    :   'esta_venta_user_panel',
        'update'    :   $( 'userDetaDiv' )
    };
    generalEstaProcess( obj );
}
function ventaCliente( obj )
{
    var obj = { 'clie_id' : obj.clie_id }
    obj.update  =   $( 'clienteDetaDiv' );
    obj.action  =   'esta_venta_cliente_panel';
    generalEstaProcess( obj );
}

function VPCFSel( id )
{
    $( 'VPCIntervaloFech' ).setStyle('display','none');
    $( 'fechaIntervaloDiv' ).setStyle('display','none');
    $( 'VPCMonths' ).setStyle('display','none');
    $( 'VPCCmonth' ).setStyle('display','none');

    if( id != 'currMonth' && id != 'selMonth' )
    {
        $( 'VPCIntervaloFech' ).setStyle('display','block' );
    }
    if( id == 'interval' )
    {
        $( 'fechaIntervaloDiv' ).setStyle('display','block');
    }
    if( id == 'selMonth' )
    {
        $( 'VPCMonths' ).setStyle('display','block');
    }
    if( id == 'currMonth' )
    {
    $( 'VPCCmonth' ).setStyle('display','block');
    }
}

function estaFilterProd( id )
{
    var displ = 'none';
    if( id == 'selProd' )
    {
        displ = 'block';
    }
    $( 'SELPRODDIV' ).setStyle('display',displ);
}
function getEstaProdList( linea )
{
    var obj = { 'prod_linea' : linea, 'action' : 'get_esta_prod_list' , 'update' : $( 'estaProdListDiv' ) };
    generalEstaProcess( obj );
}
function addAllLine()
{
    $$( 'div.PROD_LIST' ).each(
        function(item, index)
        {
            addSelectedProd( item.id );
        }
    );
}
function addSelectedProd( id )
{
    var newId = 'selelctedProd_' + id;
    new Element( 'div', { 'id': newId } ).inject( $( 'estaSelProdListDiv' ) );
    $( newId ).innerHTML =  "<input type='hidden'  name='prod[]' id='prod[]' value='" + id.replace('PROD_','') + "'>" + 
                            $( id ).innerHTML.replace('mas.png','menos.png');
    $( newId ).setStyles( $( id ).getStyles('padding-left','background','cursor','border-bottom','width') );
    $( newId ).setStyle('background-color','#ffffff');
    $( newId ).addEvents(
        {   'click'     :   function(){ deleteSelectedProd( newId, id ); },
            'mouseover' :   function(){ $(this.id).setStyle('background-color','#cdcdcd');},
            'mouseout'  :   function(){ $(this.id).setStyle('background-color','#ffffff');}
        }
    );
    $( id ).setStyle('display','none');
    $( 'SELECTEDBTN' ).setStyle('display','block');
}
function deleteSelectedProd( newId, id )
{
    if( $(id ) ) $( id ).setStyle('display','block');
    $( newId ).remove();
}
function deleteAllSelectedProd()
{
    $( 'estaSelProdListDiv' ).setHTML('');
    $$( 'div.PROD_LIST' ).each( 
        function(item,index)
        {
            if( $( item.id ) ) $( item.id ).setStyle('display','block');
        }
    );
}
function createRepo( obj )
{
    if( obj.repoReturn == 'xls' )
    {
        //$( 'hiddenIframe' ).setStyle('display','block');
        if( $( 'repoReturn' ) ) $( 'repoReturn' ).value = obj.repoReturn;
        $(obj.formName).submit();
    }   
    else
    {
        obj.method = 'post';
        if( $( 'repoReturn' ) ) $( 'repoReturn' ).value = obj.repoReturn;
        if( obj.formName ){
            if( $('idDiv' ) ) $('idDiv' ).remove();
            new Element('input',{'id':'idDiv','name':'idDiv','value':'repoDiv','type':'hidden'}).inject( $(obj.formName) );
            obj.dataId = obj.formName;
        }
    
        new Element( 'div', {'id' : 'repoDiv' }).inject( document.body );
        $( 'repoDiv' ).setStyles(
            {   'position'  :   'absolute',
                'top'       :   $( 'estContDiv' ).getPosition().y,
                'left'      :   $( 'estContDiv' ).getPosition().x
            }
        );
        $( 'repoDiv' ).setStyles( $( 'estContDiv' ).getStyles('width','height') );
        obj.update = $( 'repoDiv' );
        generalEstaProcess( obj );
    }
}


/**
 *  CONSULTA DE COMISIONES
 */

function sendComiConsult()
{
    if( arguments[ 0 ] )
    {
        var argObj = arguments[0];
        if( argObj.objLimit )
        {
            $( 'limit' ).value = argObj.objLimit ;
        }
        if( argObj.showAll )
        {
        }
    }
    else
    {
        $( 'limit' ).value = '0';
    }
    var obj = {
        method  :   'post',
        dataId  :   'filtersForm',
        action  :   'consulta_comi',
        update  :   $( 'listaComisionesPagadas' )
    };

    generalEstaProcess( obj );
}

function selectUserComi()
{
    if( $( 'recuHumaDiv' ) ) $( 'recuHumaDiv' ).remove();
    var pos = getAvailablePosition();
    var DIV = new Element( 'div', { 'id' : 'recuHumaDiv' } ).inject( document.body );

    $( 'recuHumaDiv' ).setStyles(
        {
            'position'  :   'absolute',
            'top'       :   pos.y + 'px',
            'left'      :   pos.x + 'px'
        }
    );
    
    var axa = new Ajax( urlProcesos,
        {   'method'    :   'get',
            'data'      :   { 'action' : 'get_recu_huma_list', 'title' : 'Seleccionar usuario', 'functionName' : 'changeUserComi' },
            'update'    :   $( 'recuHumaDiv' ),
            'onComplete': function() { showOver( 'recuHumaDiv' ); }
        }
    ).request();
    
}

function changeUserComi( param )
{
    var obj = {
        'action'    :   'comi_user_info',
        'comi_user' :   param,
        'updateValue'   :   'comi_vend_id',
        'label'     :   'userNameDiv',
        'divContainer'  :   'recuHumaDiv'
    };
    generalEstaProcess( obj );
}

function comiPend( id )
{
    var obj = {
        'action'    :   'comisiones_pendientes',
        'user_id'   :   id,
        'update'    :   $('listaComisiones' )
    };
    generalEstaProcess( obj );
}



/**
 *  COBRANZA
 */
function reloadPager()
{
    var obj = {
        'dataId'      :   'pagerParamsForm',
        'update'    :   'pagerContainer',
        'method'    :   'post'
    };
    if( arguments[0] )
    {
        $( 'page' ).value = arguments[ 0 ].page;
    }
    generalEstaProcess( obj );
}

function cuentaSection( obj )
{
    $( 'page' ).value = '0';
    $( 'porCobrar' ).setHTML( '0.00');
    $( 'cobrado' ).setHTML( '0.00');
    $('pagerContainer').setHTML('');
    $('cuenta_secc').value=obj.sec;
    obj.action  =   'esta_cobranza_cuenta_secc';
    obj.update  =   $( 'secParams' );
    obj.script  =   "reloadPager();";
    generalEstaProcess( obj );

}

