/**
 * *************** GLOBALES ***************
 */
var urlTop  = " " + window.location;
var SID = "SID=1";
if( urlTop.indexOf( "?" ) > 0 )
{
    SID = urlTop.split( "?" ).pop();
}
var urlProcesos     =   "procesos.php?" + SID;
var urlFunciones    =   "funciones.php?" + SID;
var urlElementos    =   "elementos.php?" + SID;
var urlEstadisticas =   "estadisticas.php?" + SID;
var urlEquipos      =   "equipos_gestion.php?" + SID;
var urlProductos    =   "productos_gestion.php?" + SID;
var urlFactura      =   "facturacion.php?" + SID;
var urlInfoVend     =   "InfoVend.php?"+SID;

var recuHumaArr = [];
var switchIniFin = 'ini';
var componentes = [];
var rm_equipos_id = [];
initArrayValues( 'Component_' );
var currentZIndex = 1;
var activeCtrl = false;

/**
 *  Rango de ventanas y ventanas abiertas
 */
var rango = 20;
var ventanas = 0;
var ventanasEmergentes = [
    'newInvitaAlertDiv',
    'newCommentsAlertDiv',
    'recuHumaDiv',
    'acti_deta_div',
    'acti_comment_div',
    'acti_comment_deta_div',
    'detalle_mensaje',
    'captura_mensaje_alerta',
    'nuevaTareaDiv',
    'attachFiles',
    'chkHorariosDiv',
    'alertaNuevaTarea',
    'userParentDiv',
    'recuMateDiv',
    'recuMateParams',
    'prodSelDiv',
    'pagoFormDiv',
    'prodImportDiv',
    'soliAlertDiv',
    'userClientDiv',
    'clieFormSelect'
];
var selectHour = {
    'stat':0,
    'h1':0,
    'h2':0
};
var selectHourE = {
    'stat':false,
    'col1':false,
    'row1':false,
    'col2':false,
    'row2':false,
    'date1':false,
    'date2':false,
    'hour1':false,
    'hour2':false
};
/**
 *  *************** FUNCIONES ***************
 */
 
//Prueba AJAX 
function objetoAjax(){
    var xmlhttp=false;
    try {
        xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
        } catch (e) {
        try {
            xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
            } catch (E) {
            xmlhttp = false;
            }
        }
        if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
            xmlhttp = new XMLHttpRequest();
        }
        return xmlhttp;
    }  
 
 

/**
 * Coordenadas iniciales de ventanas emergentes
 */
function initPosition()
{
    var x = ( $( 'mainContainer' ) ? $( 'mainContainer' ).getPosition().x.toInt() : 100 );
    var y = ( $( 'mainContainer' ) ? $( 'mainContainer' ).getPosition().y.toInt() : 100 );
    var obj = { 'x' : x, 'y' : y };
    return obj
}
/**
 *  checar vigencia
 */
function getSelectionStart(o) {
	if (o.createTextRange) {
		var r = document.selection.createRange().duplicate()
		r.moveEnd('character', o.value.length)
		if (r.text == '') return o.value.length
		return o.value.lastIndexOf(r.text)
	} else return o.selectionStart
}
/**
 *  checar vigencia
 */
function getSelectionEnd(o) {
	if (o.createTextRange) {
		var r = document.selection.createRange().duplicate()
		r.moveStart('character', -o.value.length)
		return r.text.length
	} else return o.selectionEnd
}

/**
 *  cambia el foco a otro input
 */
function changeCell( evnt, el, maxCols, maxRows )
{
    code = ( window.ie ? evnt.keyCode : evnt.which );
    var pos = getSelectionStart( el );
    var id = el.id.split( '-' );
    var pre = id[0];
    var col = parseInt( id[ 1 ] );
    var row = parseInt( id[ 2 ] );

    if( code == 37 )
    {
        if( pos  == 0 )
        {
            if( col == 0 && row == 0 )
            {
                return false;
            }
            else
            {
                if( col == 0 )
                {
                    $( pre + '-' + maxCols + '-' + ( row - 1 ) ).focus();
                }
                else
                {
                    $( pre + '-' + ( col - 1 ) + '-' + row ).focus();
                }
            }
        }
    }
    else if ( code == 39 || code == 13 )
    {
        if( pos == el.value.length )
        {
            if( col == maxCols && row == maxRows )
            {
                return false;
            }
            else
            {
                if( col == maxCols )
                {
                    $( pre + '-0-' + ( row + 1 ) ).focus();
                }
                else
                {
                    $( pre + '-' + ( col + 1 ) + '-' + row ).focus();
                }
            }
        }
    }
    else if( code == 38 )
    {
        if( row > 0 )
        {
            $( pre + '-' + col + '-' + ( row - 1 ) ).focus();
        }
    }
    else if( code == 40 )
    {
        if( row < maxRows )
        {
            $( pre + '-' + col + '-' + ( row + 1 ) ).focus();
        }
    }
    else if( code == 36 )
    {
        if( activeCtrl )
        {
            $( pre + '-0-0' ).focus();
            activeCtrl = false;
        }
        else
        {
            $( pre + '-0-' + row).focus();
        }
    }
    else if( code == 35 )
    {
        if( activeCtrl )
        {
            $( pre + '-' + maxCols + '-' + maxRows ).focus();
            activeCtrl = false;
        }
        else
        {
            $( pre + '-' + maxCols + '-' + row ).focus();
        }
    }
    else if( code == 17 )
    {
        activeCtrl = true;
    }
    else
    {
        activeCtrl = false;
        //alert( code );
    }
}
/**
 *  hace un scroll al elemento
 */
function scrollTable( el )
{
    X = el.scrollLeft;
    Y = el.scrollTop;
    $( 'headerDiv' ).scrollTo( X, 0 );
    $( 'leftDiv' ).scrollTo(0, Y );
}
/**
 *  checar vigencia
 */
function combo( obj )
{
    var url =   urlElementos + "&elemento=combo";

    for( var o in obj )
    {
       url += "&" + o + "=" + obj[ o ];
    }
    var myAjax = new Ajax( url,
        {
            method  :   'get',
            update  :   $( obj.div ),
            onComplete : function()
            {
                //preLoader(0);
            }
        }
    ).request();
}
/**
 *  PRINT_R  como el de php pero para los arreglos esta haciendo algo raro por el momento
 *  solo esta funcionnando bien con los objetos
*/
function print_r( Obj )
{
    var string = "";
    var nivel = arguments[1] ? parseInt( arguments[1] ) : 0;
    var tabs = "";
    for( var i = 0; i < parseInt( nivel ); i++ )
    {
        tabs += "\t";
    }
    if( Obj.constructor == Array ||
        Obj.constructor == Object)
    {
        string += typeof( Obj ) + "\n" + tabs +"(\n";
        for( var p in Obj)
        {
            if( Obj[p].constructor == Array ||
                Obj[p].constructor == Object )
            {
                string +=   tabs + "\t[" + p + "] => " +
                            print_r( Obj[ p ], ( nivel + 1 ) ) ;
            } else {
                string += tabs + "\t[" + p + "] => " + Obj[ p ] + "\n";
            }
        }
        string += tabs + ")\n";
    }
    return string;
      
}
/**
 *  envia el foco al siguiente input
 */
function nextInput( ev, id )
{
    code = ( window.ie ? ev.keyCode : ev.which );

    if( code == 13 )
    {
        $( id ).focus();
        return true;
    }
}
/**
 *  Muestra u oculta el preloader
 */
function preLoader( showHide )
{
    var cId = "tdContainer";
    var pId = "preloader";

    if( showHide == 'show' || showHide == 1 )
    {
        var display = 'inline';
        if( arguments[1] )
        {
            cId = arguments[1]
        }
        $( pId ).style.top      = $( cId ).getPosition().y ;
        $( pId ).style.left     = $( cId ).getPosition().x ;
        $( "preloaderTable" ).style.width    = $( cId ).getStyle('width').toInt();//$( cId ).style.width;
        $( "preloaderTable" ).style.height   = $( cId ).getStyle('height').toInt();//$( cId ).style.height;
        $( pId ).style.display = display;
        showOver( pId );
    }
    else
    {
        var display = 'none';
       // $( pId ).style.display = display;
        return fadeOut( $( pId ) );
    }
    
}
/**
 *  desaparece gradualment un eleento
 */
function fadeOut( box )
{
    var duracion = ( arguments[1] ? arguments[1] : 700 );
    var fx = box.effects({duration: duracion, transition: Fx.Transitions.Quart.easeOut});
    /* AJAX Request here... */
    
    fx.start(
        {
        }).chain(function()
            {
                this.start.delay(100, this,
                    {'opacity' : 0
                    });
            }).chain(function()
            {
                box.style.display="none";
                this.start.delay(50, this, {'opacity' : 1});
            });
    return true;
            // $( 'loader' ).style.display = 'none';
}
/**
 *  checar vigencia
 */
function cargaTab( idTab, idContainer, idContent )
{
    preLoader(1, ( $('tabContainer') ? 'tabContainer' : idContainer ));
    var url =   urlFunciones + "&action=getTabs" + 
                "&idTab=" + idTab +
                "&idContent=" + idContent +
                "&idContainer=" + idContainer;
    var myAjax = new Ajax( url,
        {
            method  :   'get',
            update  :   $( idContainer ),
            onComplete : function()
            {
                preLoader(0);
            }
        }
    ).request();

}
/**
 *  carga la imagen de la seccion cargada
 */
function imgSection( seccion )
{
    var url = urlProcesos + "&action=imgSection&seccion=" + seccion;
    var request = new Json.Remote(url, 
        {
            onComplete : function( obj )
            {
                if( obj.complete == 'ok' )
                {
                    $( 'seccionTitulo' ).innerHTML = obj.pathImg;
                    correctPNG();
                }
            }
        }
    ).send();
}
/**
 *  carga la interface seleccionada del menu
 */
function goTo( action )
{
    closeAllWindows();
    if( action == 'monitor' )
    {
        userMonitor();
        return;
    }
    if( action == 'logout' )
    {
        logout();
    }
    else
    {
        if( action == 'equipos_pannel' )
        {
            //include( 'js/equipos.gestion.js',{'cache':false,'dom':true,'charset':'iso-8859-1'});
        }
        if( action == 'users_pannel' )
        {   
            include( 'js/user.gestion.js',{'cache':false,'dom':true,'charset':'iso-8859-1'} );
        }
        if( action == 'conceptos_setup' )
        {
            include( 'js/conceptos.gestion.js',{'cache':false,'dom':true,'charset':'iso-8859-1'} );
        }
        if( action == 'clients_pannel' )
        {var pre_div = parent.document.getElementById('preloader');
            include( 'js/client.gestion.js',{'cache':false,'dom':true,'charset':'iso-8859-1'} );
        }
        if( action == 'check' )
        {
            include( 'js/check.js',{'cache':false,'dom':true,'charset':'iso-8859-1'} );               
        }

        preLoader(1 ,( arguments[1] ? arguments[1] : 'mainContainer' ) );
        imgSection( action );
        var obj = {};
        if( arguments[2] )
        {   
            var obj = arguments[2];
        }
        obj.action = action;
        var myAjax = new Ajax( urlProcesos,
            {
                'method'  :   'get',
                'data'    :   obj,
                'update'  :   $(( arguments[1] ? arguments[1] : 'mainContainer' )),
                'evalScripts' : true,
                'onComplete'  :   function()
                {
                    preLoader(0);
                    if( action == 'interface_setup' )
                    {
                        goTo( 'menu_interface_setup', 'mainMenu' );
                    }
                    if( action == 'index' )
                    {
                        goTo( 'index_menu', 'mainMenu' );
                    }
                    if( action == 'menu_interface_setup' )
                    {
                        makeDraggableComponents();
                    }
                    if( action == 'clients_pannel' )
                    {
                        setTimeout( "startSlider( 50,'area')" , 1000 );
                        setTimeout( "startSliderTabla({'id':'area2','idTabla':'segDiv','idContent':'sliderContent'} )" , 1000 );
                        setTimeout( "startSliderTabla({'id':'area3','idTabla':'segDiv','idContent':'sliderContent','mode':'vertical'} )" , 1000 );
                        setTimeout( "clienteAccordion()" , 1000 );
                    }
                    if( action == 'act_hoy' && arguments[2] )
                    {
                        obj = arguments[2];
                        show_activities( obj.date, obj.act_id );
                    }
                }
            }
        ).request();
    }
}
/**
 *  Inicializa el slider de la tabla de segmentos de cliente
 */
function startSliderTabla( obj ) // startIn, id, idTabla, idContent )
{
    if( $( obj.idContent ) )
    {
    var mySlide = new Slider(
        $( obj.id ),
        $( obj.id + 'knob'),
        {
            steps:  (   obj.mode == 'vertical'
                    ?   $( obj.idContent ).getStyle('height').toInt() - $( obj.idTabla ).getStyle('height').toInt()  
                    :   $( obj.idContent ).getStyle('width').toInt() - $( obj.idTabla ).getStyle('width').toInt()
                    ),
            mode : ( obj.mode ? obj.mode : 'horizontal' ),
            onChange: function( step )
            {
                if( obj.mode == 'vertical' )
                {
                    $( obj.idTabla ).scrollTo( $( obj.idTabla).scrollLeft, step);
                }
                else
                {
                    $( obj.idTabla ).scrollTo(step,$( obj.idTabla ).scrollTop);
                }
            }
        }
    ).set( ( obj.startIn ? obj.startIn : 0 ) );
    }
}
/**
 *  checar vigencia
 */
function getCombo( id, obj_table, obj_value, obj_text, obj_selected, obj_where )
{
    var url =   urlFunciones + "&action=getCombo" + 
                "&id_container=" + id +
                "&obj_table=" + obj_table +
                "&obj_value=" + obj_value +
                "&obj_text=" + obj_text +
                "&obj_selected=" + obj_selected + 
                "&obj_where=" + obj_where;

    $( id ).length = 0;
    add_option( id, 'Seleccione una opcion', '' );
    var request = new Json.Remote(
        url,
        {
            onComplete : function( obj )
            {
                if( obj.complete == 'ok' )
                {
                    for( var i = 0; i < obj.rs.length; i++ )
                    {
                       add_option( obj.id_container, obj.rs[i].optionText, obj.rs[i].optionValue );
                    }
                }
            }
        }
    ).send();
}
/**
 * checar vigencia
 *  agrega option a un select
 */
function add_option(id,txt,val)
{
    var newOption = new Element('option',{});
    if( window.ie )
    {
        newOption.innerText = txt;
    }
    else
    {
        newOption.text = txt;
    }
    newOption.value = val;
    newOption.selected = arguments[3];
    newOption.inject( id );
}
/**
 *  checar vigencia
 *  mueve un  elemento al centro de la pantalla
 */
function moveToCenter( id )
{
    var winW =  (   window.ie 
                ?   (   document.documentElement.offsetWidth
                    ?   document.documentElement.offsetWidth
                    :   document.body.offsetWidth
                    )
                :   window.innerWidth
                );
    var winH =  (   window.ie
                ?   (   document.documentElement.offsetHeight
                    ?   document.documentElement.offsetHeight 
                    :   document.body.offsetHeight
                    )
                :   window.innerHeight
                );

    var sizeW   =   $( id ).getStyle('width').toInt() / 2 ;//( $( id ).style.width  ? ( parseFloat( $( id ).style.width.replace('px','') ) / 2 ) : 1 );
    var sizeH   =   ( $( id ).style.height ? ( parseFloat( $( id ).style.height.replace('px','')) / 2 ) : 1 );
    var elLeft  =   ( ( winW / 2 ) - sizeW ) + 'px';
    var elTop   =   ( ( winH / 2 ) - sizeH ) + 'px';

    $( id ).setStyles(
        {
         position   :   'absolute',
         left       :   elLeft,
         top        :   elTop   
        }
       );
    
}
/**
 *  cambia el z-index de un elemento para que se vea encima de los demas
 */
function showOver(id )
{
    if( $( id ) )
    {
        currentZIndex++;
        $( id ).style.zIndex = currentZIndex;
    }
}
/**
 *  checar vigencia
 */
function changePosition( obj )
{
    var TopPos  =   $( obj ).getPosition().y;
    var LeftPos =   $( obj ).getPosition().x;
}
/**
 *  checar vigencia
 */
function draggableElement( id )
{
    showOver(id);
    $( id ).makeDraggable(
        {
            'container' : $('mainContainer'),
            onComplete : function()
            {
                
                changePosition(id);
                updateInterface();
            },
            onDrag : function()
            {
                var pos = {
                    "x": this.element.getStyle('left').toInt() + 1, 
                    "y": this.element.getStyle('top').toInt() + 1
                };
                $( 'divId' ).value = this.element.id;
                $( 'coordX' ).value = pos.x;
                $( 'coordY' ).value = pos.y;
            }
        }
    );
}
/**
 *  checar vigencia
 */
function ajustaInterface()
{
    var winW =  (   window.ie 
                ?   (   document.documentElement.offsetWidth
                    ?   document.documentElement.offsetWidth
                    :   ( document.body.offsetWidth - 25 )
                    )
                :   ( window.innerWidth - 25 )
                );
    var winH =  (   window.ie
                ?   (   document.documentElement.offsetHeight
                    ?   document.documentElement.offsetHeight 
                    :   document.body.offsetHeight
                    )
                :   ( window.innerHeight - 10 )
                );
    var newWidth = winW- $( 'mainMenu' ).getStyle('width').toInt();
    var newHeight= winH;
    $( 'principalTable' ).setStyle( 'height' , newHeight + 'px' );
}
/**
 *  checar vigencia
 */
function initArrayValues( prefix )
{
/*
    var url =   urlProcesos + "&action=initArray&prefix=" + prefix +
                "&user_components=1";
    var request = new Json.Remote( url,
        {
            onComplete : function( obj )
            {
                if( obj.complete == 'ok' )
                {
                    componentes = obj.componentes;
                }
                else
                {
                   // alert( obj.complete );
                }
            }
        }
    ).send();
    */
}
/**
 *  verifica que exista un elemento en un arreglo (arreglos simples)
 */
function inArray( el, arr )
{
    var rs = false;
    for( var i = 0; i < arr.length; i++ )
    {
        rs = ( el == arr[ i ] ? true : rs );
    }
    return rs;
}
function arrayDel( el, arr )
{
    var tmp = [];
    for( var i = 0; i < arr.length; i++ )
    {
        if( el != arr[ i ] )
        {
            tmp.push( arr[ i ] );
        }
    }
    return tmp;
}
/**
 *  checar vigencia
 */
function getComponent( comp, divId )
{
    var url =   urlProcesos + "&action=getComponent&editable=1&componentName=" + comp +
                "&interface_id=1" +
                "&divContainer=" + divId ;
    var myAjax  =   new Ajax( url,
        {
            method  :   'get',
            update  :   $( divId ),
            onComplete : function()
            {
                $( divId ).setStyles(
                    { 
                        'border' : 'none',
                        'cursor' : 'move'
                    }
                );
                $( divId ).addEvent( 'mousedown', function(){ draggableElement(this.id) });
            }
        }
    ).request();
}
/**
 *  checar vigencia
 */
function makeDraggableComponents()
{
    var drop = $('mainContainer');
    var dropFx = drop.effect('background-color', {wait: false}); 
    
    $$('.menuImgComponent').each( 
        function( item )
        {  
            item.addEvent('mousedown',
            function(e) 
            {
                e = new Event(e).stop();    
                var clone = this.clone()
                .setStyles(this.getCoordinates()) // this returns an object with left/top/bottom/right, so its perfect
                .setStyles({'opacity': 0.7, 'position': 'absolute'})
                .addEvent('emptydrop',
                function()
                {
                    this.remove();
                    drop.removeEvents();
                }
                ).inject( document.body );    
                
                drop.addEvents(
                    {
                        'drop': function() 
                        {
                            drop.removeEvents();
                            clone.remove();
                            //dropFx.start('7389AE').chain(dropFx.start.pass('ffffff', dropFx));
                            var tmpId = item.id.split( '_' );
                            tmpId.reverse();
                            tmpId.pop();
                            tmpId.reverse();
                            var newId = tmpId.join('_');
                            if( !inArray( newId, componentes ) )
                            {
                                //alert( newId );

                                componentes.push( newId );
                                //$( 'debug' ).innerHTML += newId + ' ' ;
                                $( 'preloaderTable' ).setStyles({'width':'50px','height':'50px'});
                                var newClone = $( 'preloader' ).clone();
                                newClone.setStyles(
                                    {   
                                        'position'  :   'static',
                                        'float'     :   'left',
                                        'display'   :   'inline',
                                        'border'    :   'solid 1px #cdcdcd'
                                    }
                                );
                                newClone.id = newId; 
                                newClone.inject(drop);
                                getComponent( newId, newClone.id );
                            }
                            else
                            {
                                alert( 'El componente ya esta en el escritorio' );
                            }
                        },
                        'over': function() 
                        {
                            //dropFx.start('98B5C1');
                        },
                        'leave': function() 
                        {
                            //dropFx.start('ffffff');
                        }
                    }
                );    
                var drag = clone.makeDraggable(
                    {
                        droppables: [drop]
                    }
                ); // this returns the dragged element
    
                drag.start(e); // start the event manual
            }
            );
    
        }
    );
}
/**
 *  arregla el canal alpha de los archivos PNG para internet explorer
 */
function correctPNG() // correctly handle PNG transparency in Win IE 5.5 & 6.
{
    var arVersion = navigator.appVersion.split("MSIE")
    var version = parseFloat(arVersion[1])
    if( window.ie && (version >= 5.5) && (document.body.filters)) 
    {
        //alert( "Explorer : " + version );
        for(var i=0; i<document.images.length; i++)
        {
            var img = document.images[i]
            var imgName = img.src.toUpperCase()
            if (imgName.substring(imgName.length-3, imgName.length) == "PNG")
            {
                var imgID = (img.id) ? "id='" + img.id + "' " : ""
                var imgClass = (img.className) ? "class='" + img.className + "' " : ""
                var imgTitle = (img.title) ? "title='" + img.title + "' " : "title='" + img.alt + "' "
                var imgStyle = "display:inline-block;" + img.style.cssText 
                if (img.align == "left") imgStyle = "float:left;" + imgStyle
                if (img.align == "right") imgStyle = "float:right;" + imgStyle
                if (img.parentElement.href) imgStyle = "cursor:hand;" + imgStyle
                var strNewHTML = "<span " + imgID + imgClass + imgTitle
                + " style=\"" + "width:" + img.width + "px; height:" + img.height + "px;" + imgStyle + ";"
                + "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader"
                + "(src=\'" + img.src + "\', sizingMethod='scale');\"></span>" 
                img.outerHTML = strNewHTML
                i = i-1
            }
        }
    }    
}
/**
 *  FORMATOS
 */
/**
 * Campo numerico 
 * Solo permite la captura de numeros
 */
function numerico( evnt, id )
{
    var code = ( window.ie ? evnt.keyCode : evnt.which );
    if( 
        (   code >= 48 && code <= 57 ) ||
        code == 8 || code == 0 || code == 13
    )
    {
        return true;
    }
    return false;
}
function decimal( evnt, value, dec )
{
    var code = ( window.ie ? evnt.keyCode : evnt.which );
    //alert(code);
    if( (   code >= 48 && code <= 57 ) ||
        code == 8 || code == 0 || code == 13 || code == 45 ||
        ( code == 46 && value.indexOf('.') < 0 )
    )
    {
        if( value.indexOf('.') > 0 && code != 8 && code != 0 )
        {
            var tmp = value.split('.');
            if( tmp[1].length <= dec )
            {
                return true;
            }
            return false;
        }
        return true;
    }
    return false;
}

function decimal_desc( evnt, value, dec )
{
    var code = ( window.ie ? evnt.keyCode : evnt.which );
    //alert(code);
    if( (   code >= 48 && code <= 57 ) ||
        code == 8 || code == 0 || code == 13 || code == 45 ||
        ( code == 46 && value.indexOf('.') < 0 )
    )
    {
        if( value.indexOf('.') > 0 && code != 8 && code != 0 )
        {
            var tmp = value.split('.');
            if( tmp[1].length <= dec )
            {
                return true;
            }
            return false;
        }
        return true;
    }
    return false;
}
/**
 *  verifica el formato de la hora capturada
 */
function formatoHora( id )
{
    var error = false;
    if( $( id ).value.indexOf( ':' ) > 0)
    {
        var dat = $( id ).value.split( ':' );
        var hora = dat[0].toInt();
        var minutos = dat[1].toInt();
        if( isNaN( hora ) || isNaN( minutos ) )
        {
            alert( "La hora y los minutos deben ser numeros" );
            error = true;
        }
        if( hora > 24 || hora < 0 )
        {   
            alert( "La hora debe ser de 0 a 24 " );
            error = true;
        }
        if( minutos < 0 || minutos > 59 )
        {
            alert( "Los minutos deben ser de 0 a 59 " );
            error = true;
        }
    }
    else
    {
        alert( "Formato incorrecto\nUtilice 'HH:MM' " );
        error = true;
    }

    if( error == true )
    {
        $( id ).value = '';
    }
}
/**
 *  rellena el input con la hora segun la mascara
 */
function completaHora( el )
{
    if( el.value.indexOf( ":" ) == 0 )
    {
        el.value = "00" + el.value;
    }
    if( el.value.length == 1 )
    {
        el.value = "0" + el.value + ":00";
    }
    if( el.value.length == 3 )
    {
        el.value += "00";
    }
    if( el.value.length == 4 )
    {
        el.value += "0";
    }
    if( el.value.indexOf( ":" ) > 0 )
    {
        var tmp = el.value.split( ":" );
        var v1 = tmp[0];
        var v2 = tmp[1];
        if( tmp[0].length == 1 )
        {
            v1 = "0" + parseInt( tmp[0] );
        }
        if( tmp[1].length == 1 )
        {
            v2 = "0" + parseInt( tmp[1] );
        }
        el.value = v1 + ":" + v2;
    }
    if( el.value.indexOf(":") < 0 )
    {
        var tmp = el.value;
        el.value = tmp.substr(0,2) + ":" + tmp.substr(2,4);
    }
    if( el.value.length > 5 )
    {
        el.value = el.value.substr(0,5);
    }
}
/**
 *  crea marcara de captura con formato HH:MM
 */
function mascaraHora( el, evnt )
{
    var code = ( window.ie ? evnt.keyCode : evnt.which );
    if( 
        ( code >= 48 && code <= 57 ) ||
        ( code >= 96 && code <= 105 ) ||
        code == 8 || code == 0 || code == 13
    )
    {
        if( el.value.length == 1 )
        {
            if( parseInt( el.value ) > 2 )
            {
                el.value = "0" + el.value;
            }
        }
        if( el.value.length == 2 )
        {
            if( parseInt( el.value ) > 23 )
            {
                 el.value = "0" + el.value.substr(0,1) + ":" + el.value.substr(1,1);
            }
            else  if( code != 8 )
            {
                el.value += ":";
            }
        }
        if( el.value.length == 4 )
        {
            var tmp = el.value.split(":");
            if( parseInt( tmp[1] ) > 5 )
            {
                el.value = tmp[0] + ":0" + tmp[1].substr(0,1);   
            }
        }
        return true;
    }
    else
    {
        if( code == 9 )
        {
            return true;
        }
        return false;
    }
}
/**
 *  checar vigencia
 */
function switchColor( id, col1, col2 )
{
    var currColor = $( id ).getStyle( 'background-color' );
    var color = ( currColor == "#" + col1 ? "#" + col2 : "#" + col1 );
    $( id ).setStyle('background-color' , color );
}
/**
 *  Cambia la vista de un elemento
 */
function switchDisplay( id )
{
    var displ = $( id ).getStyle('display' );
    $( id ).setStyle('display', ( displ == 'none' ? 'block' : 'none' ) );
}
/*  Actividades y tareas */
/**
 *  checar vigencia
 */
function detaHist( id )
{
    var url = urlProcesos + '&action=detaHist&id=' + id;
    var aja = new Ajax( url,
        {
            'method' : 'get',
            'update' : $( 'emptyDiv' ),
            'onComplete' : function()
            {
                $( 'emptyDiv' ).setStyles(
                    {
                        'position'  :   'absolute',
                        'top'       :   '150',
                        'left'      :   '150'
                    }
                );
                showOver( 'emptyDiv' );
            }
        }
    ).request();
}
/**
 * checar vigencia
 */
function ajustaTareas()
{
    for( var i = 0 ; i < 24; i++ )
    {
    }
}
/**
 *  cambia la imagen
 */
function switchImage( el )
{
    var url = $( el ).innerHTML;
    if( url.indexOf( 'Mas' ) > 1 )
    {
        var sr = url.replace( 'Mas','Menos' );
    }
    else
    {
        var sr = url.replace('Menos','Mas');
    }
    $( el ).innerHTML = sr;
}
/**
 *  carga el formulario de captura de las tareas
 */
function nuevaTarea()
{
    var obj = arguments[1] ? arguments[1] : {'horainicial':false,'horafinal':false};
    rm_equipos_id = [];
    recuHumaArr = [];
    if( $( 'nuevaTareaDiv' ) ) $( 'nuevaTareaDiv' ).remove();
    var pos = getAvailablePosition();
    var newDiv = new Element( 'div', { 'id':'nuevaTareaDiv' }).inject( document.body );
    $( 'nuevaTareaDiv' ).setStyles(
        {   'position'      :   'absolute',
            'top'           :   pos.y + 'px',
            'left'          :   pos.x + 'px'
        }
    );
    var aja = new Ajax( urlProcesos,
        {   'method'    :   'get',
            'data'      :   {   'action'    :   'nuevaTareaForm',
                                'date'      :   $( 'acti_fech_hidden' ).value,
                                'parent'    :   ( arguments[0] ? arguments[0] : 0 )
                            },
            'update'    :   $( 'nuevaTareaDiv' ),
            'onComplete' : function()
            {
                showOver('nuevaTareaDiv');
                $( 'acti_tipo' ).focus();
                if( obj.horainicial )
                {
                    $( 'acti_hora_ini' ).value = obj.horainicial;
                }
                if( obj.horafinal )
                {
                    $( 'acti_hora_fin' ).value = obj.horafinal;
                }
            }
        }
    ).request();
}
/**
 * Valida el tipo de ubicacion
 */
function validaTipoUbicacion( valor )
{
    var displ = 'none';
    if( valor > 1 )
    {   
        displ = 'inline';
    }
    $( 'acti_ubicacion' ).setStyle('display',displ);
}
/**
 * Edicion de tareas
 */
function editaTarea( acti_id )
{
    rm_equipos_id = [];
    recuHumaArr = [];
    if( $( 'nuevaTareaDiv' ) ) $( 'nuevaTareaDiv' ).remove();
    var pos = getAvailablePosition();
    var newDiv = new Element( 'div', { 'id':'nuevaTareaDiv' }).inject( document.body );
    $( 'nuevaTareaDiv' ).setStyles(
        {   'position'      :   'absolute',
            'top'           :   pos.y + 'px',
            'left'          :   pos.x + 'px'
        }
    );
    var aja = new Ajax( urlProcesos,
        {   'method'    :   'get',
            'data'      :   {   'action'    :   'editarTareaForm',
                                'acti_id'      :   acti_id
                            },
            'update'    :   $( 'nuevaTareaDiv' ),
            'onComplete' : function()
            {
                showOver('nuevaTareaDiv');
                $( 'acti_tipo' ).focus();
                chkRecuHuma( acti_id );
                chkRecuMate( acti_id );
            }
        }
    ).request();
        
}
/**
 *  Eliminacion de tareas
 */
function eliminaTarea( acti_id )
{
    $( 'deleteActi' ).disabled = 'disabled';
    if( confirm( 'Desea eliminar la actividad? ' ) == true )
    {
        var jsn = new Json.Remote(
            urlProcesos + '&action=delete_acti&acti_id=' + acti_id,
            {
                'onComplete' : function( obj )
                {
                    if( obj.complete == 'ok' )
                    {
                        $( 'acti_deta_div' ).remove();
                        var d = new Date();
                        var Y = d.getFullYear();
                        var M = d.getMonth() + 1;
                        var D = d.getDate();
                        showCalendar( ( M < 10 ? '0' + M : M ), Y, D );
                        actualizaTareasAtrazadas();
                        show_activities(obj.fech);
                        //confirmAttachFiles(obj.acti_id);
                    }
                }
            }
        ).send();
    }
    else
    {
        $( 'deleteActi' ).disabled = false;
    }
}
/**
 *  Cancela la finalizacion de la tarea
 */
function cancelaTareaFin()
{
    var el = $$( 'input.statTarea' );
    for( var  i = 0; i < el.length; i++ )
    {
        el[i].checked = false;
    }
    $( 'alertaNuevaTarea' ).setStyle('display','none');
    $('finalizarBtn').setStyle('display','none');
    $( 'tareaId' ).value = '';
    $( 'tareaDivId' ).value = '';
    $( 'acti_fin_desc' ).value = '';
}
/**
 * checar vigencia
 */
function validaTareaStatus()
{
    var el = $$( 'input.statTarea' );
    var fin_desc = escape( $( 'acti_fin_desc' ).value );
    var op = false;
    for( i = 0; i < el.length; i++)
    {
        op = ( el[i].checked == true ? el[i].value : op );
    }
    if( op == false )
    {
        alert( 'Seleccione una de las opciones o de click en cancelar' );
        return;
    }
    if( op == 1 )
    {
        nuevaTarea( $('tareaId').value );
    }
    if( window.ie )
    {
        window.parent.tareasIframe.saveStatus($('tareaId' ).value,$('tareaDivId').value,fin_desc);
    }
    else
    {
        parent.tareasIframe.saveStatus($('tareaId').value,$('tareaDivId').value,fin_desc);
    }
    cancelaTareaFin();
}
/**
 *  actualiza vista de tareas pendientes
 */
function actualizaTareasAtrazadas()
{
    
    if( $( 'componente_content_4' ) )
    {
        var tipo = $( 'tareasAMP' ) ? $( 'tareasAMP' ).value : 0;
        var url = urlProcesos + "&action=getTareasAtrazadas&tipo=" + tipo;
        var aja =   new Ajax( url,
            {
                'method' : 'get',
                'update' : $( 'componente_content_4' ),
                'onComplete' : function()
                {
                    var d = new Date();
                    var Y = d.getFullYear();
                    var M = d.getMonth() + 1;
                    var D = d.getDate();
                    showCalendar( ( M < 10 ? '0' + M : M ), Y, D );
                }
            }
        ).request();
    }
}
/**
 *  checar vigencia
 */
function getHistory(id)
{
    var url = urlProcesos + "&action=getTareasHistorial&id=" + id;
    var aja = new Ajax( url,
        {
            'method' : 'get',
            'update' : $( 'history' )
        }
    ).request();
}
/**
*
*/
function cargaClieSelect( obj )
{
    if( obj.like.length >= 3 )
    {
        if( !$( 'clieFormSelect' ) ) 
        {
            new Element( 'div', { 'id' : 'clieFormSelect' } ).inject( document.body );
        }
        $( 'clieFormSelect' ).setStyles(
            {   'position'   :   'absolute',
                'top'       :   ( $( obj.idEl ).getPosition().y.toInt() + 18 ) + 'px',
                'left'      :   ( $( obj.idEl ).getPosition().x.toInt() )  + 'px',
                'display'   :   'block',
                'border'    :   'solid 1px #cdcdcd',
                'background-color'  :   '#ffffff'
            }
        );
        obj.action = 'carga_clie_select';
        new Ajax( urlProcesos ,
        {   'update'    :   'clieFormSelect',
                'method'    :   'get',
                'data'      :   obj,
                'evalScripts' : true
        }
        ).request();
        showOver( 'clieFormSelect' );
    }
}
function selectActiCliente( obj )
{
    $( 'clieFormSelect' ).remove();
    $( 'actiCliente' ).value = unescape( obj.clie_razo_come );
    $( 'acti_clie_id' ).value = obj.clie_id;
    cargaContForm( obj.clie_id );
}
/**
 *  carga formulario de contactos
 */
function cargaContForm( clie_id )
{
    var url = urlProcesos + "&action=cargaContForm&clie_id=" + clie_id;
    var ajs = new Ajax( url,
        {
            'method' : 'get',
            'update' : $( 'contDivForm' )
        }
    ).request();
}
/**
 *  checar vigencia
 */
function switchTareasAMP( tipo )
{
    $( 'tareasAMP' ).value = 0; //tipo;
    /*
    $( 'title_component_4' ).innerHTML =    (   tipo == 0
                                            ?   'Tareas atrazadas'
                                            :   (   tipo == 1
                                                ?   'Tareas de ma&ntilde;a'
                                                :   'Tareas de pasado ma&ntilde;a'
                                                )
                                            );
                                            */
    actualizaTareasAtrazadas();
}




function atend_ped( id,acti )
{

var aja = new Ajax( urlProcesos,
        {   'method'    :   'get',
        'data'      :   {   'action'     : 'atend_ped',
                            'id'         :   id,
                            'acti'       :  acti
                            },
            'update'        :   $( 'mainContainer' ),
            
            'onComplete' : function()
            {   
             
             alert("Pedido atendido.")
             if($('atend_ped')){
             $('atend_ped').remove();
             }
             if($('detalle_mensaje')){
             $('detalle_mensaje').remove();
             }
             if($('acti_deta_div')){
             $('acti_deta_div').remove();
             }
             
            }
        }
    ).request();   

}



function atend_ped_l( id,acti )
{

var aja = new Ajax( urlProcesos,
        {   'method'    :   'get',
        'data'      :   {   'action'     : 'atend_ped_l',
                            'id'         :   id,
                            'acti'       :  acti
                            },
            'update'        :   $( 'mainContainer' ),
            
            'onComplete' : function()
            {   
             
             alert("Pedido atendido.")
             if($('atend_ped')){
             $('atend_ped').remove();
             }
             
            }
        }
    ).request();   

}


function req_ped(id,acti)
{


 if( $( 'req_ped' ) )
    {
        $( 'req_ped' ).remove();
    }
    var pos = getAvailablePosition();
    
    var nx=pos.x+20;
    var ny=pos.y+70;
    
    var Div = new Element( "div",{"id" : "req_ped"} ).inject( document.body );
    $( 'req_ped' ).setStyles(
        {   'position'  :   'absolute',
            'left'      :   nx + 'px',
            'top'       :   ny + 'px'
        }
    );
    var aja = new Ajax( urlProcesos,
        {
            'method'        :   'get',
            'data'          :   {   'action'    : 'req_ped',
                                    'id'        :  id,
                                    'acti'      :  acti
                                },
            'update'        :   $( 'req_ped' ),
            'onComplete'    :   function()
            {
                showOver( 'req_ped' );
            }
        }
    ).request();


}


function req_ped_but(id)
{


 if( $( 'req_ped' ) )
    {
        $( 'req_ped' ).remove();
    }
    var pos = getAvailablePosition();
    
    var nx=pos.x;
    var ny=pos.y+90;
    
    var Div = new Element( "div",{"id" : "req_ped"} ).inject( document.body );
    $( 'req_ped' ).setStyles(
        {   'position'  :   'absolute',
            'left'      :   nx + 'px',
            'top'       :   ny + 'px'
        }
    );
    var aja = new Ajax( urlProcesos,
        {
            'method'        :   'get',
            'data'          :   {   'action'    : 'req_ped_but',
                                    'id'        :  id
                                },
            'update'        :   $( 'req_ped' ),
            'onComplete'    :   function()
            {
                showOver( 'req_ped' );
            }
        }
    ).request();


}





function req_ped_list(id)
{


 if( $( 'req_ped' ) )
    {
        $( 'req_ped' ).remove();
    }
    var pos = getAvailablePosition();
    
    var nx=pos.x+500;
    var ny=pos.y+345;
    
    var Div = new Element( "div",{"id" : "req_ped"} ).inject( document.body );
    $( 'req_ped' ).setStyles(
        {   'position'  :   'absolute',
            'left'      :   nx + 'px',
            'top'       :   ny + 'px'
        }
    );
    var aja = new Ajax( urlProcesos,
        {
            'method'        :   'get',
            'data'          :   {   'action'    : 'req_ped_list',
                                    'id'        :  id
                                },
            'update'        :   $( 'req_ped' ),
            'onComplete'    :   function()
            {
                showOver( 'req_ped' );
            }
        }
    ).request();


}

 
function req_par()
{

pPed=$( 'ped' ).value;
pActi=$( 'act' ).value;

 if( $( 'req_par' ) )
    {
        $( 'req_par' ).remove();
    }
    var pos = getAvailablePosition();
    
    var nx=pos.x+20;
    var ny=pos.y+70;
    
    var Div = new Element( "div",{"id" : "req_par"} ).inject( document.body );
    $( 'req_par' ).setStyles(
        {   'position'  :   'absolute',
            'left'      :   nx + 'px',
            'top'       :   ny + 'px'
        }
    );
    var aja = new Ajax( urlProcesos,
        {
            'method'        :   'get',
            'data'          :   {   'action'    : 'req_par',
                                    'ped'        :  pPed,
                                    'acti'      :  pActi
                                },
            'update'        :   $( 'req_par' ),
            'onComplete'    :   function()
            {
                showOver( 'req_par' );
            }
        }
    ).request();


}


function req_par_list()
{

pPed=$( 'ped' ).value;

 if( $( 'req_par' ) )
    {
        $( 'req_par' ).remove();
    }
    var pos = getAvailablePosition();
    
    var nx=pos.x+500;
    var ny=pos.y+345;
    
    var Div = new Element( "div",{"id" : "req_par"} ).inject( document.body );
    $( 'req_par' ).setStyles(
        {   'position'  :   'absolute',
            'left'      :   nx + 'px',
            'top'       :   ny + 'px'
        }
    );
    var aja = new Ajax( urlProcesos,
        {
            'method'        :   'get',
            'data'          :   {   'action'    : 'req_par_list',
                                    'ped'        :  pPed
                                },
            'update'        :   $( 'req_par' ),
            'onComplete'    :   function()
            {
                showOver( 'req_par' );
            }
        }
    ).request();


}


function send_req_par_list()
{

pCant=$( 'canti' ).value;
pPed=$( 'ped' ).value;

if($( 'msj' )){
pMsj=$( 'msj' ).value;
}
else{
pMsj=0;
}

var aja = new Ajax( urlProcesos,
        {   'method'    :   'get',
        'data'      :   {   'action'     : 'send_req_par_list',
                            'cant'       :  pCant,
                            'ped'        :  pPed,
                            'msj'        :  pMsj
                            },
        'update'        :   $( 'mainContainer' ),
        'onComplete'    :   function()
            {
                alert('Pedido requerido.');
                $('req_par').remove();
				$('req_ped').remove();
				if($('atend_ped')){
				$('atend_ped').remove();
                }
                if($('detalle_mensaje')){
				$('detalle_mensaje').remove();
                }
                if($('acti_deta_div')){
				$('acti_deta_div').remove();
                }
                
            }
        }
    ).request();  


}




function send_req_par()
{

pCant=$( 'canti' ).value;
pPed=$( 'ped' ).value;
pActi=$( 'act' ).value;

if($( 'msj' )){
pMsj=$( 'msj' ).value;
}
else{
pMsj=0;
}

var aja = new Ajax( urlProcesos,
        {   'method'    :   'get',
        'data'      :   {   'action'     : 'send_req_par',
                            'cant'       :  pCant,
                            'ped'        :  pPed,
                            'acti'       :  pActi,
                            'msj'        :  pMsj
                            },
        'update'        :   $( 'mainContainer' ),
        'onComplete'    :   function()
            {
                alert('Pedido requerido.');
                $('req_par').remove();
				$('req_ped').remove();
				if($('atend_ped')){
				$('atend_ped').remove();
                }
                if($('detalle_mensaje')){
				$('detalle_mensaje').remove();
                }
                if($('acti_deta_div')){
				$('acti_deta_div').remove();
                }
                
            }
        }
    ).request();  


}



function req_com()
{

pPed=$( 'ped' ).value;
pActi=$( 'act' ).value;

if($( 'msj' )){
pMsj=$( 'msj' ).value;
}
pMsj=0;

var aja = new Ajax( urlProcesos,
        {   'method'    :   'get',
        'data'      :   {   'action'     : 'req_com',
                            'acti'       :  pActi,
                            'ped'        :  pPed,
                            'msj'        :  pMsj
                            },
        
        'update'        :   $( 'mainContainer' ),
        'onComplete'    :   function()
            {
                alert('Pedido requerido.');
                $('req_ped').remove();
                if($('detalle_mensaje')){
				$('detalle_mensaje').remove();
                }
                if($('atend_ped')){
				$('atend_ped').remove();
                }
                if($('acti_deta_div')){
				$('acti_deta_div').remove();
                }
                
            }
        }
    ).request();  


}


function req_com_list()
{

pPed=$( 'ped' ).value;
pActi=$( 'act' ).value;

if($( 'msj' )){
pMsj=$( 'msj' ).value;
}
pMsj=0;

var aja = new Ajax( urlProcesos,
        {   'method'    :   'get',
        'data'      :   {   'action'     : 'req_com_list',
                            'acti'       :  pActi,
                            'ped'        :  pPed,
                            'msj'        :  pMsj
                            },
        
        'update'        :   $( 'mainContainer' ),
        'onComplete'    :   function()
            {
                alert('Pedido requerido.');
                $('req_ped').remove();
                if($('detalle_mensaje')){
				$('detalle_mensaje').remove();
                }
                if($('atend_ped')){
				$('atend_ped').remove();
                }
                if($('acti_deta_div')){
				$('acti_deta_div').remove();
                }
                
            }
        }
    ).request();  


}




function conf_ent( id,act )
{

pMsj=$( 'msj' ).value;

var aja = new Ajax( urlProcesos,
        {   'method'    :   'get',
        'data'      :   {   'action'     : 'conf_ent',
                            'id'         :   id,
                            'msj'        : pMsj
                            },
            'update'        :   $( 'mainContainer' ),
            'onComplete' : function()
            {   
             alert("Entrega confirmada.")
             $('detalle_mensaje').remove();
            }
        }
    ).request();   

}


function rech_ent(id){


 if( $( 'form_rech_ent' ) )
    {
        $( 'form_rech_ent' ).remove();
    }
    var pos = getAvailablePosition();
    
    var nx=pos.x;
    
    var Div = new Element( "div",{"id" : "form_rech_ent"} ).inject( document.body );
    $( 'form_rech_ent' ).setStyles(
        {   'position'  :   'absolute',
            'left'      :   nx + 'px',
            'top'       :   pos.y + 'px'
        }
    );
    var aja = new Ajax( urlProcesos,
        {
            'method'        :   'get',
            'data'          :   {   'action'    : 'form_rech_ent',
                                    'id'        :  id
                                },
            'update'        :   $( 'form_rech_ent' ),
            'onComplete'    :   function()
            {
                showOver( 'form_rech_ent' );
            }
        }
    ).request();


}


function resp_rech(id){


 if( $( 'form_resp_rech' ) )
    {
        $( 'form_resp_rech' ).remove();
    }
    var pos = getAvailablePosition();
    
    var nx=pos.x;
    
    var Div = new Element( "div",{"id" : "form_resp_rech"} ).inject( document.body );
    $( 'form_resp_rech' ).setStyles(
        {   'position'  :   'absolute',
            'left'      :   nx + 'px',
            'top'       :   pos.y + 'px'
        }
    );
    var aja = new Ajax( urlProcesos,
        {
            'method'        :   'get',
            'data'          :   {   'action'    : 'form_resp_rech',
                                    'id'        :  id
                                },
            'update'        :   $( 'form_resp_rech' ),
            'onComplete'    :   function()
            {
                showOver( 'form_resp_rech' );
            }
        }
    ).request();


}

function rech_doc_ven(venta,acti){


 if( $( 'rech_doc_ven' ) )
    {
        $( 'rech_doc_ven' ).remove();
    }
    var pos = getAvailablePosition();
    
    var nx=pos.x+58;
    var ny=pos.y+127;
    
    var Div = new Element( "div",{"id" : "rech_doc_ven"} ).inject( document.body );
    $( 'rech_doc_ven' ).setStyles(
        {   'position'  :   'absolute',
            'left'      :   nx + 'px',
            'top'       :   ny + 'px'
        }
    );
    var aja = new Ajax( urlProcesos,
        {
            'method'        :   'get',
            'data'          :   {   'action'    : 'rech_doc_ven',
                                    'venta'     :  venta,
                                    'acti'      :  acti
                                },
            'update'        :   $( 'rech_doc_ven' ),
            'onComplete'    :   function()
            {
                showOver( 'rech_doc_ven' );
            }
        }
    ).request();


}



function rech_tel(venta_deta,acti){


 if( $( 'rech_tel' ) )
    {
        $( 'rech_tel' ).remove();
    }
    var pos = getAvailablePosition();
    
    var nx=pos.x+58;
    var ny=pos.y+127;
    
    var Div = new Element( "div",{"id" : "rech_tel"} ).inject( document.body );
    $( 'rech_tel' ).setStyles(
        {   'position'  :   'absolute',
            'left'      :   nx + 'px',
            'top'       :   ny + 'px'
        }
    );
    var aja = new Ajax( urlProcesos,
        {
            'method'        :   'get',
            'data'          :   {   'action'    : 'rech_tel',
                                    'venta_deta':  venta_deta,
                                    'acti'      :  acti
                                },
            'update'        :   $( 'rech_tel' ),
            'onComplete'    :   function()
            {
                showOver( 'rech_tel' );
            }
        }
    ).request();


}


function rech_exp(venta,acti){


 if( $( 'rech_exp' ) )
    {
        $( 'rech_exp' ).remove();
    }
    var pos = getAvailablePosition();
    
    var nx=pos.x+58;
    var ny=pos.y+127;
    
    var Div = new Element( "div",{"id" : "rech_exp"} ).inject( document.body );
    $( 'rech_exp' ).setStyles(
        {   'position'  :   'absolute',
            'left'      :   nx + 'px',
            'top'       :   ny + 'px'
        }
    );
    var aja = new Ajax( urlProcesos,
        {
            'method'        :   'get',
            'data'          :   {   'action'    : 'rech_exp',
                                    'venta'     :  venta,
                                    'acti'      :  acti
                                },
            'update'        :   $( 'rech_exp' ),
            'onComplete'    :   function()
            {
                showOver( 'rech_exp' );
            }
        }
    ).request();


}

function rech_sct(venta,acti,venta_deta){

    var aja = new Ajax( urlProcesos,
        {
            'method'        :   'get',
            'data'          :   {   'action'    : 'rech_sct',
                                    'venta'     :  venta,
                                    'acti'      :  acti,
                                    'venta_deta':  venta_deta
                                },
            'onComplete'    :   function()
            {
                $('acti_deta_div').remove();
                alert('Venta rechazada');
            },
            'update'    :   $( 'mainContainer' )
        }
    ).request();


}


function rech_rec_doc(fact,acti,acti_rest){


 if( $( 'rech_rec_doc' ) )
    {
        $( 'rech_rec_doc' ).remove();
    }
    var pos = getAvailablePosition();
    
    var nx=pos.x+58;
    var ny=pos.y+127;
    
    var Div = new Element( "div",{"id" : "rech_rec_doc"} ).inject( document.body );
    $( 'rech_rec_doc' ).setStyles(
        {   'position'  :   'absolute',
            'left'      :   nx + 'px',
            'top'       :   ny + 'px'
        }
    );
    var aja = new Ajax( urlProcesos,
        {
            'method'        :   'get',
            'data'          :   {   'action'    : 'rech_rec_doc',
                                    'fact'      :  fact,
                                    'acti'      :  acti,
                                    'acti_rest' :  acti_rest
                                },
            'update'        :   $( 'rech_rec_doc' ),
            'onComplete'    :   function()
            {
                showOver( 'rech_rec_doc' );
            }
        }
    ).request();


}


function send_rech_rec_doc(fact,acti,acti_rest){

    var aja = new Ajax( urlProcesos,
        {
            'method'        :   'get',
            'data'          :   $( 'rech_rec_doc_form' ),
            'onComplete'    :   function()
            {
                $('acti_deta_div').remove();
                $('rech_rec_doc').remove();
                alert('Recepcion de documentos rechazada');
            },
            'update'    :   $( 'mainContainer' )
        }
    ).request();


}

function send_rech_exp(){

    var aja = new Ajax( urlProcesos,
        {
            'method'        :   'get',
            'data'          :   $( 'rech_exp' ),
            'onComplete'    :   function()
            {
                $('acti_deta_div').remove();
                $('rech_exp').remove();
                alert('Expediente rechazado');
            },
            'update'    :   $( 'mainContainer' )
        }
    ).request();


}


function send_rech_tel(){

	if($( 'mot_rech' ).value=='0')
	{
		alert('Favor de seleccionar un motivo');
	}
	else{

		var aja = new Ajax( urlProcesos,
			{
				'method'        :   'get',
				'data'          :   $( 'rech_tel' ),
				'onComplete'    :   function()
				{
					$('acti_deta_div').remove();
					$('rech_tel').remove();
					alert('Rechazo enviado');
				},
				'update'    :   $( 'mainContainer' )
			}
		).request();
	}

}


function rech_pago_dif(fact,acti,acti_rest){


 if( $( 'rech_pago_dif' ) )
    {
        $( 'rech_pago_dif' ).remove();
    }
    var pos = getAvailablePosition();
    
    var nx=pos.x+58;
    var ny=pos.y+127;
    
    var Div = new Element( "div",{"id" : "rech_pago_dif"} ).inject( document.body );
    $( 'rech_pago_dif' ).setStyles(
        {   'position'  :   'absolute',
            'left'      :   nx + 'px',
            'top'       :   ny + 'px'
        }
    );
    var aja = new Ajax( urlProcesos,
        {
            'method'        :   'get',
            'data'          :   {   'action'    : 'rech_pago_dif',
                                    'fact'      :  fact,
                                    'acti'      :  acti,
                                    'acti_rest' :  acti_rest
                                },
            'update'        :   $( 'rech_pago_dif' ),
            'onComplete'    :   function()
            {
                showOver( 'rech_pago_dif' );
            }
        }
    ).request();


}


function rech_pago_dif_suc(fact,acti){


 if( $( 'rech_pago_dif' ) )
    {
        $( 'rech_pago_dif' ).remove();
    }
    var pos = getAvailablePosition();
    
    var nx=pos.x+58;
    var ny=pos.y+127;
    
    var Div = new Element( "div",{"id" : "rech_pago_dif"} ).inject( document.body );
    $( 'rech_pago_dif' ).setStyles(
        {   'position'  :   'absolute',
            'left'      :   nx + 'px',
            'top'       :   ny + 'px'
        }
    );
    var aja = new Ajax( urlProcesos,
        {
            'method'        :   'get',
            'data'          :   {   'action'    : 'rech_pago_dif_suc',
                                    'fact'      :  fact,
                                    'acti'      :  acti
                                },
            'update'        :   $( 'rech_pago_dif' ),
            'onComplete'    :   function()
            {
                showOver( 'rech_pago_dif' );
            }
        }
    ).request();


}


function send_rech_pago_dif(fact,acti,acti_rest){

    var aja = new Ajax( urlProcesos,
        {
            'method'        :   'get',
            'data'          :   $( 'rech_pago_dif_form' ),
            'onComplete'    :   function()
            {
                $('acti_deta_div').remove();
                $('rech_pago_dif').remove();
                alert('Comprobante de pago diferencias rechazado');
            },
            'update'    :   $( 'mainContainer' )
        }
    ).request();


}

function send_rech_pago_dif_suc(){

    var aja = new Ajax( urlProcesos,
        {
            'method'        :   'get',
            'data'          :   $( 'rech_pago_dif_form' ),
            'onComplete'    :   function()
            {
                $('acti_deta_div').remove();
                $('rech_pago_dif').remove();
                alert('Comprobante de pago diferencias rechazado');
            },
            'update'    :   $( 'mainContainer' )
        }
    ).request();


}


function reimp_con(venta_deta,acti,motivo){

    var aja = new Ajax( urlProcesos,
        {
            'method'        :   'get',
            'data'          :   {   'action'    : 'reimp_con',
                                    'venta_deta':  venta_deta,
                                    'acti'      :  acti,
									'motivo'	:  motivo
                                },
            'onComplete'    :   function()
            {
                $('acti_deta_div').remove();
            },
            'update'    :   $( 'mainContainer' )
        }
    ).request();


}


function reimp_con_exp(venta_deta,acti,motivo){

    var aja = new Ajax( urlProcesos,
        {
            'method'        :   'get',
            'data'          :   {   'action'    : 'reimp_con_exp',
                                    'venta_deta':  venta_deta,
                                    'acti'      :  acti,
									'motivo'	:  motivo
                                },
            'onComplete'    :   function()
            {
                $('acti_deta_div').remove();
            },
            'update'    :   $( 'mainContainer' )
        }
    ).request();


}


function ok_err_pen(venta_deta,fact,acti){

    var aja = new Ajax( urlProcesos,
        {
            'method'        :   'get',
            'data'          :   {   'action'    : 'ok_err_pen',
                                    'venta_deta':  venta_deta,
									'fact'      :  fact,
                                    'acti'      :  acti
                                },
            'onComplete'    :   function()
            {
                $('acti_deta_div').remove();
            },
            'update'    :   $( 'mainContainer' )
        }
    ).request();


}


function ok_err_pen_lib(venta_deta,acti){

    var aja = new Ajax( urlProcesos,
        {
            'method'        :   'get',
            'data'          :   {   'action'    : 'ok_err_pen',
                                    'venta_deta':  venta_deta,
                                    'acti'      :  acti
                                },
            'onComplete'    :   function()
            {
                $('acti_deta_div').remove();
            },
            'update'    :   $( 'mainContainer' )
        }
    ).request();


}


function recab_firm(venta_deta,fact,acti){

    var aja = new Ajax( urlProcesos,
        {
            'method'        :   'get',
            'data'          :   {   'action'    : 'recab_firm',
                                    'venta_deta':  venta_deta,
									'fact'      :  fact,
                                    'acti'      :  acti
                                },
            'onComplete'    :   function()
            {
                $('acti_deta_div').remove();
            },
            'update'    :   $( 'mainContainer' )
        }
    ).request();


}


function recab_firm_lib(venta_deta,acti){

    var aja = new Ajax( urlProcesos,
        {
            'method'        :   'get',
            'data'          :   {   'action'    : 'recab_firm',
                                    'venta_deta':  venta_deta,
                                    'acti'      :  acti
                                },
            'onComplete'    :   function()
            {
                $('acti_deta_div').remove();
            },
            'update'    :   $( 'mainContainer' )
        }
    ).request();


}


function recab_ife(venta_deta,fact,acti){

    var aja = new Ajax( urlProcesos,
        {
            'method'        :   'get',
            'data'          :   {   'action'    : 'recab_ife',
                                    'venta_deta':  venta_deta,
									'fact'      :  fact,
                                    'acti'      :  acti
                                },
            'onComplete'    :   function()
            {
                $('acti_deta_div').remove();
            },
            'update'    :   $( 'mainContainer' )
        }
    ).request();


}


function recab_ife_lib(venta_deta,acti){

    var aja = new Ajax( urlProcesos,
        {
            'method'        :   'get',
            'data'          :   {   'action'    : 'recab_ife',
                                    'venta_deta':  venta_deta,
                                    'acti'      :  acti
                                },
            'onComplete'    :   function()
            {
                $('acti_deta_div').remove();
            },
            'update'    :   $( 'mainContainer' )
        }
    ).request();


}


function ok_env_exp(fact,acti){

    var aja = new Ajax( urlProcesos,
        {
            'method'        :   'get',
            'data'          :   {   'action'    : 'ok_env_exp',
                                    'fact'      :  fact,
                                    'acti'      :  acti
                                },
            'onComplete'    :   function()
            {
                $('acti_deta_div').remove();
            },
            'update'    :   $( 'mainContainer' )
        }
    ).request();


}


function ok_env_exp_lib(venta,acti){

    var aja = new Ajax( urlProcesos,
        {
            'method'        :   'get',
            'data'          :   {   'action'    : 'ok_env_exp_lib',
                                    'venta'     :  venta,
                                    'acti'      :  acti
                                },
            'onComplete'    :   function()
            {
                $('acti_deta_div').remove();
            },
            'update'    :   $( 'mainContainer' )
        }
    ).request();


}


function no_pago_tel(venta_deta,acti){

    var aja = new Ajax( urlProcesos,
        {
            'method'        :   'get',
            'data'          :   {   'action'    : 'no_pago_tel',
                                    'venta_deta':  venta_deta,
                                    'acti'      :  acti
                                },
            'onComplete'    :   function()
            {
                $('acti_deta_div').remove();
				alert('Se envio aviso de reclamacion');
            },
            'update'    :   $( 'mainContainer' )
        }
    ).request();


}


function si_pago_tel(venta_deta,fact,partida,acti){

    var aja = new Ajax( urlProcesos,
        {
            'method'        :   'get',
            'data'          :   {   'action'    : 'si_pago_tel',
                                    'venta_deta':  venta_deta,
                                    'fact'      :  fact,
                                    'partida'   :  partida,
                                    'acti'      :  acti
                                },
            'onComplete'    :   function()
            {
                $('acti_deta_div').remove();
				alert('Telcel ha pagado la venta');
            },
            'update'    :   $( 'mainContainer' )
        }
    ).request();


}


function si_pago_tel_lib(venta_deta,acti){

    var aja = new Ajax( urlProcesos,
        {
            'method'        :   'get',
            'data'          :   {   'action'    : 'si_pago_tel',
                                    'venta_deta':  venta_deta,
                                    'acti'      :  acti
                                },
            'onComplete'    :   function()
            {
                $('acti_deta_div').remove();
				alert('Telcel ha pagado la venta');
            },
            'update'    :   $( 'mainContainer' )
        }
    ).request();


}


function acep_sct(venta,acti,venta_deta){

    var aja = new Ajax( urlProcesos,
        {
            'method'        :   'get',
            'data'          :   {   'action'    : 'acep_sct',
                                    'venta'     :  venta,
                                    'acti'      :  acti,
                                    'venta_deta':  venta_deta
                                },
            'onComplete'    :   function()
            {
                $('acti_deta_div').remove();
            },
            'update'    :   $( 'mainContainer' )
        }
    ).request();


}

function ap_doc_ven(venta,acti){


    var aja = new Ajax( urlProcesos,
        {   'method'    :   'get',
            'data'      :   {   
                            'action'    : 'ap_doc_ven',
                            'venta'     : venta,
                            'acti'      : acti
                            },
            'onComplete' : function()
            {  
               $('acti_deta_div').remove();
               alert("Se aprobaron los documentos.");
                
            },
            'update'    :   $( 'mainContainer' )
        }
    ).request();


}

function rec_eq(venta_deta,acti){


    var aja = new Ajax( urlProcesos,
        {   'method'    :   'get',
            'data'      :   {   
                            'action'    : 'rec_eq',
                            'venta_deta': venta_deta,
                            'acti'      : acti
                            },
            'onComplete' : function()
            {  
               $('acti_deta_div').remove();
                
            },
            'update'    :   $( 'mainContainer' )
        }
    ).request();


}

function comp_imp_con(venta,acti,contrato){


    if( $( 'dif_vent' ) )
    {
        $( 'dif_vent' ).remove();
    }
    var pos = getAvailablePosition();
    
    var nx=pos.x+58;
    var ny=pos.y+97;
    
    var Div = new Element( "div",{"id" : "dif_vent"} ).inject( document.body );
    $( 'dif_vent' ).setStyles(
        {   'position'  :   'absolute',
            'left'      :   nx + 'px',
            'top'       :   ny + 'px'
        }
    );
    var aja = new Ajax( urlProcesos,
        {
            'method'        :   'get',
            'data'          :   {   'action'    : 'dif_vent',
                                    'venta'     :  venta,
                                    'acti'      :  acti,
                                    'contrato'  :  contrato
                                },
            'update'        :   $( 'dif_vent' ),
            'onComplete'    :   function()
            {
                showOver( 'dif_vent' );
            }
        }
    ).request();


}

function nvas_dif_fact(venta){


    if( $( 'nvas_dif_fact' ) )
    {
        $( 'nvas_dif_fact' ).remove();
    }
    var pos = getAvailablePosition();
    
    var nx=pos.x-20;
    var ny=pos.y+54;
    
    var Div = new Element( "div",{"id" : "nvas_dif_fact"} ).inject( document.body );
    $( 'nvas_dif_fact' ).setStyles(
        {   'position'  :   'absolute',
            'left'      :   nx + 'px',
            'top'       :   ny + 'px'
        }
    );
    var aja = new Ajax( urlProcesos,
        {
            'method'        :   'get',
            'data'          :   {   'action'    : 'nvas_dif_fact',
                                    'venta'     :  venta
                                },
            'update'        :   $( 'nvas_dif_fact' ),
            'onComplete'    :   function()
            {
                showOver( 'nvas_dif_fact' );
            }
        }
    ).request();


}


function dif_add_fact(){


    if( $( 'dif_add_fact' ) )
    {
        $( 'dif_add_fact' ).remove();
    }
    var pos = getAvailablePosition();
    
    var nx=pos.x+58;
    var ny=pos.y+97;
    
    var Div = new Element( "div",{"id" : "dif_add_fact"} ).inject( document.body );
    $( 'dif_add_fact' ).setStyles(
        {   'position'  :   'absolute',
            'left'      :   nx + 'px',
            'top'       :   ny + 'px'
        }
    );
    var aja = new Ajax( urlProcesos,
        {
            'method'        :   'get',
            'data'          :   $( 'comp_dif' ),
            'update'        :   $( 'dif_add_fact' ),
            'onComplete'    :   function()
            {
                showOver( 'dif_add_fact' );
            }
        }
    ).request();


}


function send_add_fact()
{    

    var aja = new Ajax( urlProcesos,
        {   'method' : 'get',
            'data' : $( 'facts_dif' ),
			'evalScripts'   :   true,
            'onComplete' : function()
            {
                alert('Facturas agregadas, favor de verificar el nuevo monto.');
				$( 'dif_add_fact' ).remove();
            }
        }
    ).request();    
}


function no_exist(venta_deta,acti,activ){


    var aja = new Ajax( urlProcesos,
        {   'method'    :   'get',
            'data'      :   {   
                            'action'    : 'no_exist',
                            'venta_deta': venta_deta,
                            'acti'      : acti,
                            'activ'     : activ
                            },
            'evalScripts'   :   true,
            'onComplete' : function()
            {  
               $('acti_deta_div').remove();
            },
            'update'    :   $( 'mainContainer' )
        }
    ).request();


}

function detaPedido(p){


    if( $( 'deta_pedido' ) )
    {
        $( 'deta_pedido' ).remove();
    }
    var pos = getAvailablePosition();
    
    var nx=pos.x+215;
    var ny=pos.y+102;
    
    var Div = new Element( "div",{"id" : "deta_pedido"} ).inject( document.body );
    $( 'deta_pedido' ).setStyles(
        {   'position'  :   'absolute',
            'left'      :   nx + 'px',
            'top'       :   ny + 'px'
        }
    );
    var aja = new Ajax( urlProcesos,
        {
            'method'        :   'get',
            'data'          :   {   'action'    : 'deta_pedido',
                                    'p'      :  p
                                },
            'update'        :   $( 'deta_pedido' ),
            'onComplete'    :   function()
            {
                showOver( 'deta_pedido' );
            }
        }
    ).request();


}


function no_exist_telcel(venta_deta,acti){


    var aja = new Ajax( urlProcesos,
        {   'method'    :   'get',
            'data'      :   {   
                            'action'    : 'no_exist_telcel',
                            'venta_deta': venta_deta,
                            'acti'      : acti
                            },
            'onComplete' : function()
            {  
               $('acti_deta_div').remove();
               alert("Aviso de no exitencia enviado");
                
            },
            'update'    :   $( 'mainContainer' )
        }
    ).request();


}



function exist_otro_color(venta_deta,acti){


    var aja = new Ajax( urlProcesos,
        {   'method'    :   'get',
            'data'      :   {   
                            'action'    : 'exist_otro_color',
                            'venta_deta': venta_deta,
                            'acti'      : acti
                            },
            'onComplete' : function()
            {  
               $('acti_deta_div').remove();
               alert("Se ha enviado la solicitud de otro color");
                
            },
            'update'    :   $( 'mainContainer' )
        }
    ).request();


}


function validaOtCol( venta_deta,acti )
{
    
    new Ajax( urlProcesos,
        {   'method'        :   'get',
            'data'          :   { 'action' : 'valida_ot_col','venta_deta':venta_deta,'acti':acti},
            'evalScripts'   :   true
        }
    ).request();
}


function acep_ot_col(){

    

    
    ok=0;
    
    if(document.colores.color.length > 0)
    {
        for(i=0; i<document.colores.color.length;i++)
        {
            if(document.colores.color[i].checked)
            {
                ok=1;
            }
        }
    }
    else
    {
        if(document.colores.color.checked)
        {
            ok=1;
        }
    }
    
    
    


    if(ok==1)
    {
        var aja = new Ajax( urlProcesos,
                {   'method'    :   'get',
                    'data'      :   $( 'colores' ),
                    'onComplete' : function()
                    {   
                      $('acti_deta_div').remove();
                      alert( 'Color cambiado' );     
                    },
                    'update'    :   $( 'mainContainer' )
                }
            ).request();      
    }
    else{
        alert('Favor de seleccionar un color');
    }

}


function asig_eq(venta,acti,venta_deta){


 if( $( 'asig_eq' ) )
    {
        $( 'asig_eq' ).remove();
    }
    var pos = getAvailablePosition();
    
    var nx=pos.x+58;
    var ny=pos.y+127;
    
    var Div = new Element( "div",{"id" : "asig_eq"} ).inject( document.body );
    $( 'asig_eq' ).setStyles(
        {   'position'  :   'absolute',
            'left'      :   nx + 'px',
            'top'       :   ny + 'px'
        }
    );
    var aja = new Ajax( urlProcesos,
        {
            'method'        :   'get',
            'data'          :   {   'action'    : 'asig_eq',
                                    'venta'     :  venta,
                                    'acti'      :  acti,
                                    'venta_deta':  venta_deta
                                },
            'update'        :   $( 'asig_eq' ),
            'onComplete'    :   function()
            {
                showOver( 'asig_eq' );
                $( 'imei' ).focus();
            }
        }
    ).request();


}


function close_msj(){

    
    
    var aja = new Ajax( urlProcesos,
        {
            'method'        :   'get',
            'data'          :   {   'action'    : 'act_hoy'
                                },
            'update'        :   $( 'mainContainer' ),
            'onComplete'    :   function()
            {
                 $('detalle_mensaje').remove();
            }
        }
    ).request();


}

function close_noti_prom(){

    
    
    var aja = new Ajax( urlProcesos,
        {
            'method'        :   'get',
            'data'          :   {   'action'    : 'show_notificaciones'
                                },
            'update'        :   $( 'notificaciones' ),
            'onComplete'    :   function()
            {
                 $('deta_noti_prom').remove();
            }
        }
    ).request();


}


function close_acti_deta(){

    
    
    var aja = new Ajax( urlProcesos,
        {
            'method'        :   'get',
            'data'          :   {   'action'    : 'act_hoy'
                                },
            'update'        :   $( 'mainContainer' ),
            'onComplete'    :   function()
            {
                 $('acti_deta_div').remove();
            }
        }
    ).request();


}



function change_pass(user){

    
    if( $( 'change_pass' ) )
    {
        $( 'change_pass' ).remove();
    }
    var pos = getAvailablePosition();
    
    var nx=pos.x+300;
    var ny=pos.y+210;
    
    var Div = new Element( "div",{"id" : "change_pass"} ).inject( document.body );
    $( 'change_pass' ).setStyles(
        {   'position'  :   'absolute',
            'left'      :   nx + 'px',
            'top'       :   ny + 'px'
        }
    );
    var aja = new Ajax( urlProcesos,
        {
            'method'        :   'get',
            'data'          :   {   'action'    : 'change_pass',
                                    'user'      :  user
                                },
            'update'        :   $( 'change_pass' ),
            'onComplete'    :   function()
            {
                showOver( 'change_pass' );
            }
        }
    ).request();

}


function send_change_pass()
{
    
    var aja = new Ajax( urlProcesos,
        {   'method'    :   'get',
            'data'      :   $( 'change_pass' ),
            'evalScripts'   :   true
        }
    ).request();
}


/**
 * Menu existencias
*/
function existMenu( menu )
{
    preLoader(1, 'ExistContDiv' );
    
    var aja = new Ajax( urlProcesos,
        {
            'method'        :   'get',
            'data'          :   {   'action'  : 'exist_menu',
                                    'menu'    : menu
                                },
            'update'        :   $( 'ExistContDiv' ),
            'onComplete'    :   function()
            {
                preLoader(0);
            }
        }
    ).request();
}


/************GUARDAR EXISTENCIAS******************/

function save_exist(){

    
    if( $( 'exist_fact' ).value == '' )
    {
        alert( 'Se necesita capturar la factura' );
        return false;
    }
    
    if( $( 'exist_eq' ).value == '' )
    {
        alert( 'Se necesita capturar el producto' );
        return false;
    }
    
    if( $( 'exist_costo' ).value == '' )
    {
        alert( 'Se necesita capturar el costo' );
        return false;
    }
    
    if( $( 'exist_num_eq' ).value == '' )
    {
        alert( 'Se necesita capturar el numero de equipos recibidos' );
        return false;
    }



    preLoader(1, 'form_exist' );

    var aja = new Ajax( urlProcesos,
            {   'method'    :   'get',
                'data'      :   $( 'form_exist' ),
                'onComplete' : function()
                {   
                   
                   preLoader(0);
                    
                },
                'update'    :   $( 'form_exist' )
            }
        ).request();  


}

/************GUARDAR IMEI TRASLADOS******************/
function save_tras(){

    
    if( $( 'tras_suc' ).value == '0' )
    {
        alert( 'Se necesita elegir una sucursal' );
        return false;
    }
    
    if( $( 'tras_num_eq' ).value == '' )
    {
        alert( 'Necesita ingresar un numero de equipos a trasladar' );
        return false;
    }

    preLoader(1, 'ExistContDiv' );

    var aja = new Ajax( urlProcesos,
            {   'method'    :   'get',
                'data'      :   $( 'form_tras' ),
                'onComplete' : function()
                {   
                   
                   preLoader(0);
                    
                },
                'update'    :   $( 'ExistContDiv' )
            }
        ).request();  


}

/************GUARDAR IMEI TRASLADOS******************/



function chk_vol(val){

    
    if(val=="0"){
        
        $('but_vol').style.display='inline';
        $( 'chk_vol' ).value = '1';
    }  
    else{
        $('but_vol').style.display='none';
        $( 'chk_vol' ).value = '0';
    }

}


function save_imei_exist(num){

    
    
    for(i=1; i<=num; i++){
        
        if( $( 'imei['+i+']' ).value == '' )
        {
            alert( 'Favor de capturar el IMEI '+i );
            return false;
        }
    
    }
  

    preLoader(1, 'ExistContDiv' );

    var aja = new Ajax( urlProcesos,
            {   'method'    :   'get',
                'data'      :   $( 'form_exist' ),
                'onComplete' : function()
                {   
                   alert('Existencias guardadas');
                   preLoader(0);
                    
                },
                
                'update'    :   $( 'ExistContDiv' )
            }
        ).request();  


}


function back_exist(num){


  

    preLoader(1, 'ExistContDiv' );

    var aja = new Ajax( urlProcesos,
            {   'method'    :   'get',
                'data'      :   {
                                 'action'   :   'back_exist',
                                 'id'       :   num
                                 },
                'onComplete' : function()
                {   
                   
                   preLoader(0);
                    
                },
                
                'update'    :   $( 'ExistContDiv' )
            }
        ).request();  


}

function validaTras( el,i,num )
{
    var imei="";
	
	if(el.value==""){
		imei='0';
	}
	else{
		imei=el.value;
	}
    
	new Ajax( urlProcesos,
        {   'method'        :   'get',
            'data'          :   { 'action' : 'valida_imei_tras', 'imei' : imei,'idInp':el.id,'i':i,'num':num },
            'evalScripts'   :   true
        }
    ).request();
}


function validaImei( el,i,num )
{
    var imei="";
	
	if(el.value==""){
		imei='0';
	}
	else{
		imei=el.value;
	}
    
	new Ajax( urlProcesos,
        {   'method'        :   'get',
            'data'          :   { 'action' : 'valida_imei', 'imei' : imei,'idInp':el.id,'i':i,'num':num },
            'evalScripts'   :   true
        }
    ).request();
}

function validaImeiAsig( el,venta,venta_deta )
{
    
    new Ajax( urlProcesos,
        {   'method'        :   'get',
            'data'          :   { 'action' : 'valida_imei_asig', 'imei' : el.value,'idInp':el.id,'venta':venta,'venta_deta':venta_deta},
            'evalScripts'   :   true
        }
    ).request();
}

function send_asig_eq()
{
    
    var aja = new Ajax( urlProcesos,
        {   'method'    :   'get',
            'data'      :   $( 'asig_eq' ),
            'onComplete' : function()
            {   
               $( 'asig_eq' ).remove();
               $('acti_deta_div').remove();
               alert("Se asigno el equipo.");
                
            },
            'update'    :   $( 'mainContainer' )
        }
    ).request();
}

function send_dif_vent()
{
    
    var aja = new Ajax( urlProcesos,
        {   'method'    :   'get',
            'data'      :   $( 'dif_vent' ),
            'onComplete' : function()
            {   
               $( 'dif_vent' ).remove();
               $('acti_deta_div').remove();
               alert("Se enviaron los datos del equipo.");
                
            },
            'update'    :   $( 'mainContainer' )
        }
    ).request();
}

function send_nvas_dif()
{
    
    var aja = new Ajax( urlProcesos,
        {   'method'    :   'get',
            'data'      :   $( 'nvas_dif_fact' ),
            'onComplete' : function()
            {   
               $( 'nvas_dif_fact' ).remove();
               $('detalle_mensaje').remove();
               alert("Se enviaron las diferencias.");
                
            },
            'update'    :   $( 'mainContainer' )
        }
    ).request();
}

function comp_fact( venta,acti )
{

    $('acti_deta_div').remove();
    
    partidas = 0;
    var obj = {   
        'action'    :   'get_fact_capt',
        'venta'     :   venta,
        'acti'      :   acti,
        'update'    :   $( 'mainContainer' )
    };

    generalFactProcess( obj );
}


function comp_dif(venta,acti,fact)
{
    //Check de diferencias cobradas seleccionado
    if( $( 'dif_cob' ).checked == true )
    {
    
            if( $( 'preg_dif_pago' ) )
                {
                    $( 'preg_dif_pago' ).remove();
                }
                var pos = getAvailablePosition();
                
                var nx=pos.x+58;
                var ny=pos.y+127;
                
                var Div = new Element( "div",{"id" : "preg_dif_pago"} ).inject( document.body );
                $( 'preg_dif_pago' ).setStyles(
                    {   'position'  :   'absolute',
                        'left'      :   nx + 'px',
                        'top'       :   ny + 'px'
                    }
                );
                var aja = new Ajax( urlProcesos,
                    {
                        'method'        :   'get',
                        'data'          :   {   'action'    : 'preg_dif_pago',
                                                'venta'     :  venta,
                                                'acti'      :  acti,
                                                'fact'      :fact
                                            },
                        'update'        :   $( 'preg_dif_pago' ),
                        'onComplete'    :   function()
                        {
                            showOver( 'preg_dif_pago' );
                        }
                    }
                ).request();
            
                   /*
                    
                    */
           
    }
    //Check de diferencias cobradas no seleccionado
    else{
            if( confirm( 'Usted no ha cobrado las diferencias, por lo tanto se le cargara a su cuenta, y tendra que pagarlo al recoger su comision ' ) == true )
            {
            
                var aja = new Ajax( urlProcesos,
                    {
                        'method'        :   'get',
                        'data'          :   {   'action'    : 'pago_dif_ok',
                                                'cargo'     :  '1',
                                                'acti'      :  acti,
                                                'fact'      :fact
                                            },
                        'update'        :   $( 'mainContainer' ),
                        'onComplete'    :   function()
                        {
                            $('acti_deta_div').remove();
                        }
                    }
                ).request();
                
            }
    }
    
}


function dif_dep(venta,acti,fact)
{
    
    if( $( 'adj_comp_dif' ) )
    {
        $( 'adj_comp_dif' ).remove();
    }
    var pos = getAvailablePosition();
    
    var nx=pos.x+58;
    var ny=pos.y+127;
    
    var Div = new Element( "div",{"id" : "adj_comp_dif"} ).inject( document.body );
    $( 'adj_comp_dif' ).setStyles(
        {   'position'  :   'absolute',
            'left'      :   nx + 'px',
            'top'       :   ny + 'px'
        }
    );
    var aja = new Ajax( urlProcesos,
        {
            'method'        :   'get',
            'data'          :   {   'action'    : 'adj_comp_dif',
                                    'venta'     :  venta,
                                    'acti'      :  acti,
                                    'fact'      :fact
                                },
            'update'        :   $( 'adj_comp_dif' ),
            'onComplete'    :   function()
            {
                showOver( 'adj_comp_dif' );
            }
        }
    ).request();
}



function dif_efe(venta,acti,fact)
{
    
    var aja = new Ajax( urlProcesos,
        {   'method'    :   'get',
            'data'      :   {
                                 'action'    : 'dif_efe',
                                 'venta'     :  venta,
                                 'acti'      :  acti,
                                 'fact'      :fact
                            },
            'onComplete' : function()
            {   
               $('acti_deta_div').remove();
               $('preg_dif_pago').remove();
               alert('Diferencias comprobadas, favor de pasar a la administracion a pagar');
                
            },
            'update'    :   $( 'mainContainer' )
        }
    ).request();
}


function pago_dif_ok(fact,acti)
{
    
    var aja = new Ajax( urlProcesos,
        {   'method'    :   'get',
            'data'      :   {
                                 'action'    : 'pago_dif_ok',
                                 'acti'      :  acti,
                                 'fact'      :fact
                            },
            'onComplete' : function()
            {   
               $('acti_deta_div').remove();
               alert('Pago completado');
                
            },
            'update'    :   $( 'mainContainer' )
        }
    ).request();
}


function pago_dif_ok_suc(fact,acti)
{
    
    var aja = new Ajax( urlProcesos,
        {   'method'    :   'get',
            'data'      :   {
                                 'action'    : 'pago_dif_ok_suc',
                                 'acti'      :  acti,
                                 'fact'      :fact
                            },
            'onComplete' : function()
            {   
               $('acti_deta_div').remove();
               alert('Pago completado');
                
            },
            'update'    :   $( 'mainContainer' )
        }
    ).request();
}


function ok_pago_sae(fact,acti)
{
    
    var aja = new Ajax( urlProcesos,
        {   'method'    :   'get',
            'data'      :   {
                                 'action'    : 'ok_pago_sae',
                                 'acti'      :  acti,
                                 'fact'      :fact
                            },
            'onComplete' : function()
            {   
               $('acti_deta_div').remove();
               alert('Pago aplicado');
                
            },
            'update'    :   $( 'mainContainer' )
        }
    ).request();
}



function ing_vnt(venta_deta,acti)
{
    
    var aja = new Ajax( urlProcesos,
        {   'method'    :   'get',
            'data'      :   {
                                 'action'    :   'ing_vnt',
                                 'venta_deta':    venta_deta,
                                 'acti'      :    acti
                            },
            'onComplete' : function()
            {   
               $('acti_deta_div').remove();
                
            },
            'update'    :   $( 'mainContainer' )
        }
    ).request();
}



function rec_doc_ok(fact,acti)
{
    
    var aja = new Ajax( urlProcesos,
        {   'method'    :   'get',
            'data'      :   {
                                 'action'    : 'rec_doc_ok',
                                 'acti'      :  acti,
                                 'fact'      :fact
                            },
            'onComplete' : function()
            {   
               $('acti_deta_div').remove();
               alert('Recepcion documentos correcta');
                
            },
            'update'    :   $( 'mainContainer' )
        }
    ).request();
}


function rec_sim(acti)
{
    
    var aja = new Ajax( urlProcesos,
        {   'method'    :   'get',
            'data'      :   {
                                 'action'    : 'rec_sim',
                                 'acti'      :  acti,
                            },
            'onComplete' : function()
            {   
               $('acti_deta_div').remove();
               alert('Contrato y sim recibidos');
                
            },
            'update'    :   $( 'mainContainer' )
        }
    ).request();
}


function comp_recl(acti)
{
    
    var aja = new Ajax( urlProcesos,
        {   'method'    :   'get',
            'data'      :   {
                                 'action'    : 'comp_recl',
                                 'acti'      :  acti,
                            },
            'onComplete' : function()
            {   
               $('acti_deta_div').remove();
                
            },
            'update'    :   $( 'mainContainer' )
        }
    ).request();
}


function ent_eq(fact,acti_alm,acti_ven)
{


    if( $( 'ver_im' ).checked == false )
    {
        alert( 'Se requiere revisar que los equipos sean los correctos' )
        return false;
    }
    
    var aja = new Ajax( urlProcesos,
        {   'method'    :   'get',
            'data'      :   {
                                 'action'    :   'ent_eq',
                                 'fact'      :    fact,
                                 'acti_alm'  :    acti_alm,
                                 'acti_ven'  :    acti_ven
                            },
            'onComplete' : function()
            {   
               $('acti_deta_div').remove();
               alert('Equipo entregado');
                
            },
            'update'    :   $( 'mainContainer' )
        }
    ).request();
    
}


function img_rec_doc(fact,acti)
{
    
    if( $( 'adj_rec_doc' ) )
    {
        $( 'adj_rec_doc' ).remove();
    }
    var pos = getAvailablePosition();
    
    var nx=pos.x+58;
    var ny=pos.y+127;
    
    var Div = new Element( "div",{"id" : "adj_rec_doc"} ).inject( document.body );
    $( 'adj_rec_doc' ).setStyles(
        {   'position'  :   'absolute',
            'left'      :   nx + 'px',
            'top'       :   ny + 'px'
        }
    );
    var aja = new Ajax( urlProcesos,
        {
            'method'        :   'get',
            'data'          :   {   'action'    : 'adj_rec_doc',
                                    'acti'      :  acti,
                                    'fact'      :fact
                                },
            'update'        :   $( 'adj_rec_doc' ),
            'onComplete'    :   function()
            {
                showOver( 'adj_rec_doc' );
            }
        }
    ).request();
}


function si_exist_telcel()
{
    

        var chk = $$( 'input.checkComp');
        var ped = false;
        
        for( var i = 0; i < chk.length; i++ )
        {
            ped = chk[i].checked == true ? true : ped;
        }
        if( ped == false )
        {
            alert( 'Necesita seleccionar un equipo para realizar la compra' );
            return false;
        }
   
   
   
        if( $( 'adj_fact_eq' ) )
        {
            $( 'adj_fact_eq' ).remove();
        }
        var pos = getAvailablePosition();
        
        var nx=pos.x+90;
        var ny=pos.y+170;
        
        var Div = new Element( "div",{"id" : "adj_fact_eq"} ).inject( document.body );
        $( 'adj_fact_eq' ).setStyles(
            {   'position'  :   'absolute',
                'left'      :   nx + 'px',
                'top'       :   ny + 'px'
            }
        );
        
        preLoader(1, 'pedidosCompContainer' );
        
        var aja = new Ajax( urlProcesos,
            {
                'method'        :   'get',
                'data' : $( 'pedidosForm' ),
                'update'        :   $( 'adj_fact_eq' ),
                'onComplete'    :   function()
                {
                    showOver( 'adj_fact_eq' );
                    
                }
            }
        ).request();
    
    
}



function close_adj_fact()
{
   
    var aja = new Ajax( urlProcesos,
    {
        'method'        :   'get',
        'data'          :   {   'action'    : 'pedidos_list'
                            },
        'update'        :   $( 'pedidosCompContainer' ),
        'onComplete'    :   function()
        {
             preLoader(0);
            $('adj_fact_eq').remove();
        }
    }
    ).request();

}



/***************Actividades/Tareas*********************/
function save_acti_rel(){

preLoader(1, 'form_acti_tarea' );

pActi=$( 'acti' ).value; 

if($('sub_acti')){
pSubacti=$( 'sub_acti' ).value; 
}
else{
pSubacti='';
}

if($('acti_des_cont')){
pActi_des_cont=$( 'acti_des_cont' ).value; 
}
else{
pActi_des_cont='';
}


pTipo_act=$( 'tipo_acti' ).value;
pActi_des=$( 'acti_des' ).value;
pUser_prim=$( 'user_prim' ).value; 
pUser_sec=$( 'user_sec' ).value; 
pTa=$( 'ta' ).value;
pR_ta=$( 'r_ta' ).value; 
pTr=$( 'tr' ).value;
pR_tr=$( 'r_tr' ).value; 
pTipo=$( 'tipo' ).value; 

var aja = new Ajax( urlProcesos,
        {   'method'    :   'get',
        'data'      :   {   'action'     : 'save_acti_rel',
                            'acti'       :   pActi,
                            'acti_des'   :   pActi_des,
                            'user_prim'  :   pUser_prim,
                            'user_sec'   :   pUser_sec,
                            'ta'         :   pTa,
                            'r_ta'       :   pR_ta,
                            'tr'         :   pTr,
                            'r_tr'       :   pR_tr,
                            'tipo'       :   pTipo,
                            'sub_acti'   :   pSubacti,
                            'acti_des_cont': pActi_des_cont,
                            'tipo_acti'     : pTipo_act
                            },
            'onComplete' : function()
            {   
               
               preLoader(0);
                
            },
            'update'    :   $( 'actiRelContDiv' )
        }
    ).request();  


}

function send_acti_rel(){


pActi=$( 'acti' ).value;

var aja = new Ajax( urlProcesos,
        {   'method'    :   'get',
        'data'      :   {   'action'     : 'send_acti_rel',
                            'acti'       :   pActi
                            },
            'update'    :   $( 'actiRelContDiv' )
        }
    ).request();  


}

function send_subacti_rel(){


pActi=$( 'acti' ).value;
pSacti=$( 'sub_acti' ).value;

var aja = new Ajax( urlProcesos,
        {   'method'    :   'get',
        'data'      :   {   'action'     : 'send_subacti_rel',
                            'acti'       :   pActi,
                            'subacti'    :   pSacti
                            },
            'update'    :   $( 'actiRelContDiv' )
        }
    ).request();  


}


function send_tipo_acti(){



pActi=$( 'acti' ).value;

if($('sub_acti')){
pSubacti=$( 'sub_acti' ).value; 
}
else{
pSubacti='';
}

pTipo=$( 'tipo_acti' ).value;
var aja = new Ajax( urlProcesos,
        {   'method'    :   'get',
        'data'      :   {   'action'     : 'send_tipo_acti',
                            'acti'       :   pActi,
                            'subacti'    :   pSubacti,
                            'tipo'       :   pTipo
                            },
            'update'    :   $( 'actiRelContDiv' )
        }
    ).request();  


}


/***************Fin Actividades/Tareas*********************/




/***************Casos Tipicos*********************/



//Guardar caso sugerido
function save_sug_caso(){
    
pNom=$( 'nom_caso' ).value; 
pProb=$( 'prob_caso' ).value;

    var aja = new Ajax( urlProcesos,
        {   'method'    :   'get',
            'data'      :   {   'action' : 'save_sug_caso',
                                'nom_caso'   :   pNom,
                                'prob_caso'  :   pProb
                            },
            'onComplete' : function()
            {   
               alert("Sugerencia enviada");
               $( 'form_sug_caso' ).remove();
                
            }
        }
    ).request();


}
//



//Guardar caso agregado
function save_add_caso(){

preLoader(1, 'infoContDiv' );
    
pNom=$( 'nom_caso' ).value; 
pProb=$( 'prob_caso' ).value;
pSol=$( 'sol_caso' ).value;

    var aja = new Ajax( urlProcesos,
        {   'method'    :   'get',
            'data'      :   {   'action' : 'save_add_caso',
                                'nom_caso'   :   pNom,
                                'prob_caso'  :   pProb,
                                'sol_caso'   :   pSol
                            },
            'onComplete' : function()
            {   
               $( 'form_add_caso' ).remove();
               alert("Caso agregado");
               preLoader(0);
                
            },
            'update'    :   $( 'infoContDiv' )
        }
    ).request();


}
//



//Guardar cambios detalle sugerencia
function save_deta_sug(){


pCaso =$( 'id_caso' ).value;   
pNom=$( 'nom_caso' ).value; 
pProb=$( 'prob_caso' ).value;
pSol=$( 'sol_caso' ).value;

    var aja = new Ajax( urlProcesos,
        {   'method'    :   'get',
            'data'      :   {   'action'     : 'save_deta_sug',
                                'id_caso'    :   pCaso,
                                'nom_caso'   :   pNom,
                                'prob_caso'  :   pProb,
                                'sol_caso'   :   pSol
                            },
            'onComplete' : function()
            {   
               alert("Cambios Guardados");
               $( 'casos_sug_deta' ).remove();
               
            },
            'update'    :   $( 'casos_sug_list' )
        }
    ).request();


}
//





//Guardar comentario de caso

function save_com_caso(){
    
pCaso=$( 'caso' ).value; 
pComent=$( 'coment' ).value;


   var aja = new Ajax( urlProcesos,
        {   'method'    :   'get',
            'data'      :   {   'action' : 'save_com_caso',
                                'caso'   :   pCaso,
                                'coment'  :   pComent
                            },
            'onComplete' : function()
            {   
               alert("Comentario enviado. Espere su validacion");
               $( 'coment' ).value='';
                
            }/*,
            'update'    :   $( 'casosList' )*/
        }
    ).request();


}/**/
//



//Guardar comentario de caso de admin

function save_com_caso_admin(){

preLoader(1, 'com_caso' );
    
pCaso=$( 'caso' ).value; 
pComent=$( 'coment' ).value;


   var aja = new Ajax( urlProcesos,
        {   'method'    :   'get',
            'data'      :   {   'action' : 'save_com_caso_admin',
                                'caso'   :   pCaso,
                                'coment'  :   pComent
                            },
            'onComplete' : function()
            {   
               alert("Comentario agregado.");
               preLoader(0);
                
            },
            'update'    :   $( 'casoShow' )
        }
    ).request();


}/**/
//




//Aprobar Comentario

function aprob_com(id){

preLoader(1, 'com_caso' );

pCaso=$( 'caso' ).value; 

   var aja = new Ajax( urlProcesos,
        {   'method'    :   'get',
            'data'      :   {   'action' : 'aprob_com',
                                'id_com' :   id,
                                'id_caso': pCaso
                            },
            'onComplete' : function()
            {   
               alert("Se aprobo el comentario.");
               preLoader(0);
                
            },
            'update'    :   $( 'casoShow' )
        }
    ).request();


}/**/
//



//Aprobar Caso

function aprob_caso(id){

//preLoader(1, 'sug_list' );



   var aja = new Ajax( urlProcesos,
        {   'method'    :   'get',
            'data'      :   {   'action' : 'aprob_caso',
                                'id_caso': id
                            },
            'onComplete' : function()
            {   
               alert("Se aprobo el caso.");
               //preLoader(0);
                
            },
            'update'    :   $( 'casos_sug_list' )
        }
    ).request();


}/**/
//


//Formulario Rechazar Caso

function rech_caso(id){


 if( $( 'form_rech_caso' ) )
    {
        $( 'form_rech_caso' ).remove();
    }
    var pos = getAvailablePosition();
    
    var nx=pos.x+203;
    
    var Div = new Element( "div",{"id" : "form_rech_caso"} ).inject( document.body );
    $( 'form_rech_caso' ).setStyles(
        {   'position'  :   'absolute',
            'left'      :   nx + 'px',
            'top'       :   pos.y + 'px'
        }
    );
    var aja = new Ajax( urlProcesos,
        {
            'method'        :   'get',
            'data'          :   {   'action'    : 'form_rech_caso',
                                    'id_caso'        :  id
                                },
            'update'        :   $( 'form_rech_caso' ),
            'onComplete'    :   function()
            {
                showOver( 'form_rech_caso' );
            }
        }
    ).request();


}/**/
//

//Rechazar Docs Ventas

function send_rech_doc_vent(){


   var aja = new Ajax( urlProcesos,
        {   'method'    :   'get',
            'data'      :   $( 'rech_doc_ven' ),
            'onComplete' : function()
            {   
               $( 'rech_doc_ven' ).remove();
               $('acti_deta_div').remove();
               alert("Se rechazaron los documentos.");
                
            },
            'update'    :   $( 'mainContainer' )
        }
    ).request();/**/


}


//Rechazar Caso

function send_rech_caso(){


//preLoader(1, 'sug_list' );

pCaso=$( 'id_caso' ).value; 

//alert(pCaso)
pMotivo=$( 'motivo' ).value; 



   var aja = new Ajax( urlProcesos,
        {   'method'    :   'get',
            'data'      :   {   'action' : 'send_rech_caso',
                                'id_caso': pCaso,
                                'motivo' : pMotivo
                            },
            'onComplete' : function()
            {   
               $( 'form_rech_caso' ).remove();
               alert("Se rechazo el caso.");
              // preLoader(0);
                
            },
            'update'    :   $( 'casos_sug_list' )
        }
    ).request();/**/


}


function send_rech_ent(){




pId=$( 'id' ).value; 
pAct=$( 'act' ).value;

pCom=$( 'com' ).value; 



   var aja = new Ajax( urlProcesos,
        {   'method'    :   'get',
            'data'      :   {   'action' : 'send_rech_ent',
                                'id'     : pId,
                                'com'    : pCom,
                                'acti'    : pAct
                            },
             'update'        :   $( 'mainContainer' ),
             'onComplete' : function()
             {   
               alert("Se envio su comentario de rechazo.");
               $( 'form_rech_ent' ).remove();
               if($('detalle_mensaje')){
				$('detalle_mensaje').remove();
                }
               
             },
        }
    ).request();/**/


}



function send_resp_rech(){




pId=$( 'id' ).value; 

pCom=$( 'com' ).value; 



   var aja = new Ajax( urlProcesos,
        {   'method'    :   'get',
            'data'      :   {   'action' : 'send_resp_rech',
                                'id'     : pId,
                                'com'    : pCom
                            },
            'update'        :   $( 'mainContainer' ),
            'onComplete' : function()
            {   
               alert("Se envio su comentario de respuesta.");
               $( 'form_resp_rech' ).remove();
               if($('detalle_mensaje')){
				$('detalle_mensaje').remove();
                }
               
            },
        }
    ).request();/**/


}


function atend_ped_but(id){

if( $( 'atend_ped' ) )
    {
        $( 'atend_ped' ).remove();
    }
    var pos = getAvailablePosition();
    
    var nx=pos.x;
    var ny=pos.y+90;
    
    var Div = new Element( "div",{"id" : "atend_ped"} ).inject( document.body );
    $( 'atend_ped' ).setStyles(
        {   'position'  :   'absolute',
            'left'      :   nx + 'px',
            'top'       :   ny + 'px'
        }
    );
    var aja = new Ajax( urlProcesos,
        {
            'method'        :   'get',
            'data'          :   {   'action'    : 'atend_ped_but',
                                    'id'        :  id
                                },
            'update'        :   $( 'atend_ped' ),
            'onComplete'    :   function()
            {
                showOver( 'atend_ped' );
            }
        }
    ).request();


}


function atend_ped_list(id){

if( $( 'atend_ped' ) )
    {
        $( 'atend_ped' ).remove();
    }
    var pos = getAvailablePosition();
    
    var nx=pos.x+500;
    var ny=pos.y+345;
    
    var Div = new Element( "div",{"id" : "atend_ped"} ).inject( document.body );
    $( 'atend_ped' ).setStyles(
        {   'position'  :   'absolute',
            'left'      :   nx + 'px',
            'top'       :   ny + 'px'
        }
    );
    var aja = new Ajax( urlProcesos,
        {
            'method'        :   'get',
            'data'          :   {   'action'    : 'atend_ped_but_list',
                                    'id'        :  id
                                },
            'update'        :   $( 'atend_ped' ),
            'onComplete'    :   function()
            {
                showOver( 'atend_ped' );
            }
        }
    ).request();


}





//Cerrar lista de sugerencias de casos

function close_sug_list(){

$('casos_sug_list').remove()

preLoader(1, 'infoContDiv' );



   var aja = new Ajax( urlProcesos,
        {   'method'    :   'get',
            'data'      :   {   'action' : 'close_sug_list'
                            },
            'onComplete' : function()
            {  
               
               preLoader(0);
                
            },
            'update'    :   $( 'infoContDiv' )
        }
    ).request();


}/**/
//



//Rechazar Comentario

function rech_com(id){

preLoader(1, 'com_caso' );

pCaso=$( 'caso' ).value; 

   var aja = new Ajax( urlProcesos,
        {   'method'    :   'get',
            'data'      :   {   'action' : 'rech_com',
                                'id_com' :   id,
                                'id_caso': pCaso
                            },
            'onComplete' : function()
            {   
               alert("Se rechazo el comentario.");
               preLoader(0);
                
            },
            'update'    :   $( 'casoShow' )
        }
    ).request();


}/**/
//




//Muestra de caso

function Muesta_caso( id ){
    
    preLoader(1, 'casoShow' );

 var aja = new Ajax( urlProcesos,
        {   'method'    :   'get',
            'data'      :   {   'action' : 'muestra_caso',
                                'id_caso'   :   id
                            },
            
            'update'    :   $( 'casoShow' ),
            'onComplete' : function()
            {   
              preLoader(0); 
                
            }
        }
    ).request();


}/**/
//



//Muestra de caso admin

function Muesta_caso_admin( id ){
    
    preLoader(1, 'casoShow' );

 var aja = new Ajax( urlProcesos,
        {   'method'    :   'get',
            'data'      :   {   'action' : 'muestra_caso_admin',
                                'id_caso'   :   id
                            },
            
            'update'    :   $( 'casoShow' ),
            'onComplete' : function()
            {   
              preLoader(0); 
                
            }
        }
    ).request();


}/**/
//

/********************Fin Casos Tipicos*******************************/



/**
 * Guardando la actividad
 */
function saveActividad()
{
    if( $( 'recuHumaDiv' ) ) $( 'recuHumaDiv' ).remove();
    if( $( 'recuMateDiv' ) ) $( 'recuMateDiv' ).remove();
    var el = $$( 'input.acti', 'textarea.acti', 'select.acti' );
    var url = urlProcesos + "&action=saveActivities&alerta=" + $( 'alerta' ).value;
    for(  var i = 0; i < el.length; i++ )
    {
        if( el[i].value != '' )
        {
            url += "&" + el[i].id + '=' + escape( el[i].value );
        }
    }
    if( $( 'acti_tipo' ).value == '' )
    {
        alert( 'seleccione un tipo de actividad' );
        $( 'acti_tipo' ).focus();
        return;
    }
    if( $( 'acti_objetivo' ).value == '' )
    {
        alert( 'Se requiere de un objetivo' );
        $( 'acti_objetivo' ).focus();
        return;
    }

    $( 'saveActiBtn' ).disabled='disbled';
    if( arguments[0] != '' && arguments[0] != undefined )
    {
        url += "&acti_id=" + arguments[0];
    }
    if( recuHumaArr.length > 0 )
    {
        url += "&recuHuma=" + recuHumaArr;
    }
    if( $( 'rm' ).value != '' )
    {
        url += "&r_m=" + $( 'rm' ).value;
    }
    var jsn = new Json.Remote( url,
        {
            onComplete : function( obj )
            {
                if( obj.complete == 'ok' )
                {
                    var d = new Date();
                    var Y = d.getFullYear();
                    var M = d.getMonth() + 1;
                    var D = d.getDate();
                    showCalendar( ( M < 10 ? '0' + M : M ), Y, D );
                    actualizaTareasAtrazadas();
                    show_activities(obj.fech);
                    confirmAttachFiles(obj.acti_id);
                }
                else
                {
                    alert(obj.complete);
                }
            }
        }
    ).send();
}
/**
 *  checar vigencia
 */
function reload_acti()
{
    show_activities( $('acti_fech_hidden').value );
}



/*Abrir adjunto*/


function openFile(href) {

    window.open(href);

}


/**
 *  Descarga el archivo seleccionado
 */
function downloadFile( path )
{
    if( $( 'downLoadFiles' ) )
    {
        $( 'downLoadFiles' ).remove();
    }
    var iFrame = new Element( 'iframe',{'id':'downLoadFiles'} ).inject( document.body );
    $( 'downLoadFiles' ).setStyles(
        {   'width' : '1px',
            'height' : '1px',
            'position' : 'absolute',
            'top' : '0px',
            'left' : '0px'
        }
    );
    $( 'downLoadFiles' ).src = 'downloadFiles.php?path=' + path + ( arguments[1] ? '&name=' + arguments[1] : '' );
}
/**
 *  Descarga el archivo seleccionado de la venta
 */
function downloadFileVent( path )
{
    if( $( 'downLoadFiles' ) )
    {
        $( 'downLoadFiles' ).remove();
    }
    var iFrame = new Element( 'iframe',{'id':'downLoadFiles'} ).inject( document.body );
    $( 'downLoadFiles' ).setStyles(
        {   'width' : '1px',
            'height' : '1px',
            'position' : 'absolute',
            'top' : '0px',
            'left' : '0px'
        }
    );
    $( 'downLoadFiles' ).src = 'downloadFilesVent.php?path=' + path + ( arguments[1] ? '&name=' + arguments[1] : '' );
}
/**
 *  Descarga el archivo seleccionado de comprobante de pago
 */
function downloadFileComp( path )
{
    if( $( 'downLoadFiles' ) )
    {
        $( 'downLoadFiles' ).remove();
    }
    var iFrame = new Element( 'iframe',{'id':'downLoadFiles'} ).inject( document.body );
    $( 'downLoadFiles' ).setStyles(
        {   'width' : '1px',
            'height' : '1px',
            'position' : 'absolute',
            'top' : '0px',
            'left' : '0px'
        }
    );
    $( 'downLoadFiles' ).src = 'downloadFilesComp.php?path=' + path + ( arguments[1] ? '&name=' + arguments[1] : '' );
}
/**
 *  Descarga el archivo seleccionado de recepcion de documentos
 */
function downloadFileRec( path )
{
    if( $( 'downLoadFiles' ) )
    {
        $( 'downLoadFiles' ).remove();
    }
    var iFrame = new Element( 'iframe',{'id':'downLoadFiles'} ).inject( document.body );
    $( 'downLoadFiles' ).setStyles(
        {   'width' : '1px',
            'height' : '1px',
            'position' : 'absolute',
            'top' : '0px',
            'left' : '0px'
        }
    );
    $( 'downLoadFiles' ).src = 'downloadFilesRec.php?path=' + path + ( arguments[1] ? '&name=' + arguments[1] : '' );
}

/**
 *  Descarga el archivo seleccionado de factura de equipo
 */
function downloadFileFactEq( path )
{
    if( $( 'downLoadFiles' ) )
    {
        $( 'downLoadFiles' ).remove();
    }
    var iFrame = new Element( 'iframe',{'id':'downLoadFiles'} ).inject( document.body );
    $( 'downLoadFiles' ).setStyles(
        {   'width' : '1px',
            'height' : '1px',
            'position' : 'absolute',
            'top' : '0px',
            'left' : '0px'
        }
    );
    $( 'downLoadFiles' ).src = 'downloadFilesFactEq.php?path=' + path + ( arguments[1] ? '&name=' + arguments[1] : '' );
}
/**
 *  elimina archivo de la lista de archivos adjuntos en la tarea
 */
function deleteFile( obj )
{
    var jsn = new Json.Remote(
        urlProcesos + '&action=delete_file&tableName=' + obj.tableName +
        '&columnId=' + obj.columnId +
        '&id=' + obj.id +
        '&archivo_id=' + obj.archivo_id,
        {
            'onComplete' : function( jobj )
            {
                if( jobj.complete == 'ok' )
                {
                    updateFileList( obj.id );
                }
            }
        }
    ).send();
}
/**
 *  carga la lista de archivos adjuntos en la tarea
 */
function updateFileList(acti_id)
{
    var aja = new Ajax( urlProcesos,
        {   'method' : 'get',
            'data' : {'action':'update_file_list','acti_id':acti_id},
            'update' : $('fileList'),
            'onComplete' : function()
            {
                preLoader(0);
            }
        }
    ).request();
}
/**
 *  checar vigencia
 */
function setUploadFile( el )
{
    $( 'fileName' ).value = el.value;
}
/**
 *  Ventana de confirmacion para agregar archivos a la tarea
 */
function confirmAttachFiles( acti_id )
{
    if( $( 'attachFiles' ) ) $( 'attachFiles' ).remove();
    var pos = getAvailablePosition();
    var DIV = new Element( "div", { "id" : "attachFiles"} ).inject( document.body );
    $( 'attachFiles' ).setStyles(
        {   'position'  :   'absolute',
            'top'       :   pos.y + 'px',
            'left'      :   pos.x + 'px'
        }
    );
    var aja = new Ajax( urlProcesos,
        {   'method'    :   'get',
            'data'      :   {   'action' : 'attachFiles',
                                'acti_id'   :   acti_id
                            },
            'update'    :   $( 'attachFiles' ),
            'onComplete' : function()
            {
               $( 'nuevaTareaDiv' ).remove(); 
            }
        }
    ).request();
    showOver( 'attachFiles' );
}
/**
 * Finalizador de tareas
 */
function endActi( idTarea, idDiv )
{
    if( $( 'alertaNuevaTarea' ) ) $( 'alertaNuevaTarea' ).remove();
    var pos = getAvailablePosition();
    var DIV = new Element( 'div', { 'id': 'alertaNuevaTarea' }).inject( document.body );
    $( 'alertaNuevaTarea' ).setStyles(
        {   'position'  :   'absolute',
            'top'       :   pos.y + 'px',
            'left'      :   pos.x + 'px'
        }
    );
    var ax = new Ajax( urlProcesos,
        {   'method'    :   'get',
            'data'      :   {'action':'endActi'},
            'update'    :   $( 'alertaNuevaTarea' ),
            'onComplete'    :   function()
            {
                $( 'tareaId' ).value = idTarea;
                $( 'tareaDivId' ).value = idDiv;
            }
        }
    ).request();
}
/**
 *  Comentario de cierre de tarea forzoso!!
 */
function valida_finalizar_comentario()
{
    if( $( 'acti_fin_desc' ).value != '' && $( 'acti_fin_desc' ).value.length > 3 )
    {
        $('finalizarBtn').setStyle('display','inline');
    }
    else
    {
        $('finalizarBtn').setStyle('display','none');
    }
}
/**
 *  checar vigencia
 */
function allDay( el )
{
    if( el.checked == true )
    {
        display = 'none';
    }
    else
    {
        display = 'inline';
    }
        $( 'acti_hora_ini' ).setStyle('display',display);
        $( 'acti_hora_fin' ).setStyle('display',display);
}
/**
 *  checar vigencia
 */
function showClock( el )
{
    var id = 'tmpDiv';
    var div = new Element( 'div', {
        'id' : id
    });
    div.inject( $( 'emptyDiv' ),'after' );
    $( id ).setStyles(
        {
            'position'  :   'absolute',
            'width'     :   '100px',
            'height'    :   '150px',
            'overflow'  :   'auto',
            'background' : '#ffffff',
            'border-style'  :   'solid',
            'border-width'  :   '1px',
            'border-color'  :   '#cdcdcd',
            'top'   :   ( $(el.id).getPosition().y + 20 ) + 'px',
            'left'  :   $(el.id).getPosition().x + 'px'
        }
    );
    
    var cad = '';
    var h1 = $( 'acti_hora_ini' ).value.split( ':' );
    var curr_hour = h1[0] + '' + parseInt( h1[1] );
    var H = ( el.id == 'acti_hora_fin' ? curr_hour : 0 );

    for( var i = H; i < 24; i++ )
    {
        var hora =  (   i == 0
                    ?   12
                    :   (   i > 12
                        ?   i  - 12
                        :   i
                        )
                    );
        hora = ( hora < 10 ? '0' + hora : hora );
        var meridiano = ( i < 12 ? 'am' : 'pm' );
        for( var min = 0; min < 60; min += 30 )
        {
            var tmpH = parseFloat( i + '.' + min );
            if( el.id == 'acti_hora_fin' && tmpH < curr_hour )
            {
            }
            else
            {
                var txtMin = ( min < 10 ? '0' + min : min )
                cad +=  "<div id='D" + hora + txtMin +"' style='cursor:pointer' " + 
                        "onmouseover=\"$(this.id).setStyle('background','#7782a2')\" " + 
                        "onmouseout=\"$(this.id).setStyle('background','#ffffff')\" " + 
                        "onclick=\"$('" + el.id + "').value='" + ( i < 10 ? '0' + i : i ) + ":" + txtMin +  "';$('" + id + "').remove();\" " +
                        ">" + hora + ":" + txtMin + " " + meridiano + " " + tmpH + "</div>";
            }
        }
    }

    $( id ).setHTML(cad);
    setTimeout( "showOver('" + id + "');", 100 );
}
/**
 *  regresa el codigo de la tecla presionada por el usuario
 */
function kPress( evnt, id )
{
    code = ( window.ie ? evnt.keyCode : evnt.which );
}
/**
 *  remueve elemento
 *  checar vigencia
 */
function hideClock()
{
    if( $( 'tmpDiv' ) )
    {
        $( 'tmpDiv' ).remove();
    }
}
/**
 *  Muestra el calendario para seleccionar fecha  asignar a input
 */
function showInputCalendar( id, date )
{
    if( arguments[ 2 ] )
    {
        evn = arguments[ 2 ];
        var Xpos = evn.clientX;
        var Ypos = evn.clientY;
    }
    var CAL = new Element( "div", { "id" : "selectCalandar" } ).inject( document.body );
    var aja = new Ajax( urlProcesos,
        {   'method'    :   'get',
            'data'      :   {'action':'showInputCalendar','date':date,'inputId' : id},
            'update'    :   $( 'selectCalandar' ),
            'onComplete':   function()
            {
                $( 'selectCalandar' ).setStyles(
                    {   'position'  :   'absolute',
                        'top'       :   ( Ypos ? Ypos - 20 : $( id ).getPosition().y.toInt() ) - 100 + 'px',
                        'left'      :   ( Xpos ? Xpos - 100 : $( id ).getPosition().x.toInt() ) - 100 + 'px'
                    }
                );
                showOver( 'selectCalandar' );
            }
        }
    ).request();
}
/**
 * 
 */
function elementRemove( id, time )
{
}
/*****************************************************************************************
 * MENSAJES Y ALERTAS
 * ***************************************************************************************/
/**
 *  marcha los checkbox para los destinatarios de mensajes
 */
function switchAll( el, tipo )
{
    var chk = $$( 'input.user_tipo_' + tipo );
    for( var i = 0; i < chk.length; i++ )
    {
        chk[i].checked = el.checked;
    }
}

function switchAllclient( el, id )
{ 
    var chk = $$( 'input.clie_user_' + id );
    for( var i = 0; i < chk.length; i++ )
    {
        chk[i].checked = el.checked;
    }
}
    
function switchAllprod( el, fam )
{
    
    var chk = $$( 'input.prod_fam_' + fam );
    for( var i = 0; i < chk.length; i++ )
    {
        chk[i].checked = el.checked;
    }
    
}
/**
 *  Marca la alerta como revisada
 */
function alertaOK( alerta_id )
{
	if( confirm( "Marcar alerta como atendida?" ) == true )
	{
		var J = new Json.Remote( urlProcesos + "&action=alertOK&alerta_id=" + alerta_id,
			{	'onComplete' : function( obj )
				{
					if( obj.complete == 'ok' )
					{
						updateAlertList();
					}
					else
					{
						alert('error');
					}
				}
			}
		).send();
	}
}
/**
 *  Actualiza la lista de aleras
 */
function updateAlertList()
{
    if( $( 'alertasContenedor' ) )
    {
	    var aja = new Ajax( urlProcesos,
		    {	'method' : 'get',
    			'data'	: {'action' : 'updateAlertList'},
	    		'update' : $( 'alertasContenedor' )
		    }
    	).request();
    }
}
/**
 *  Actualiza el mensaje
 */
function updateMsjList()
{
    if( $( 'mensajesContenedor') )
    {
	    var aja = new Ajax( urlProcesos,
            {   'method' : 'get',
                'data' : {'action':'updateMsjList'},
                'update' : $( 'mensajesContenedor')
            }
        ).request();
    }
}
/**
 *  Guarda el mensaje capturado
 */
function saveMsj()
{
    if( $( 'paraTodos' ).checked == false && $( 'paraVarios' ).checked == false )
    {
        alert( 'Seleccione si el mensaje es para todos o para uno o varios usuarios' );
        return false;
    }
    if( $( 'paraVarios' ).checked == true )
    {
        var usr = false;
        var chk = $$( 'input.user_tipo_1','input.user_tipo_2','input.user_tipo_3','input.user_tipo_4','input.user_tipo_5','input.user_tipo_6');
        for( var i = 0; i < chk.length; i++ )
        {
            usr = chk[i].checked == true ? true : usr;
        }
        if( usr == false )
        {
            alert( 'necesita seleccionar por lo menos un usuario' );
            return false;
        }
    }
    if( $( 'mensaje_asunto' ).value == '' )
    {
        alert( 'se requiere de un asunto para registrar el mensaje' );
        return false;
    }
    var aja = new Ajax( urlProcesos,
        {   'method' : 'get',
            'data' : $( 'mensajesForm' ),
            'update' : $( 'mensajesContenedor'),
            'onComplete' : function()
            {
                $( 'captura_mensaje_alerta' ).remove();
            }
        }
    ).request();
}

/**
 *  Guarda noticia o promocion caputarada
 */
function save_noti_promo()
{
    if( $( 'noti' ).checked == false && $( 'promo' ).checked == false )
    {
        alert( 'Seleccione el tipo de informacion que esta capturando.' );
        return false;
    }
    
    if( $( 'paraTodos' ).checked == false && $( 'paraVarios' ).checked == false )
    {
        alert( 'Seleccione si el mensaje es para todos o para uno o varios usuarios' );
        return false;
    }
    
    if( $( 'paraVarios' ).checked == true )
    {
        var usr = false;
        var chk = $$( 'input.user_tipo_1','input.user_tipo_2','input.user_tipo_3','input.user_tipo_4');
        for( var i = 0; i < chk.length; i++ )
        {
            usr = chk[i].checked == true ? true : usr;
        }
        if( usr == false )
        {
            alert( 'necesita seleccionar por lo menos un usuario' );
            return false;
        }
    }
    if( $( 'mensaje_asunto' ).value == '' )
    {
        alert( 'se requiere de un titulo para registrar la informacion' );
        return false;
    }
    var aja = new Ajax( urlProcesos,
        {   'method' : 'get',
            'data' : $( 'noti_promo_form' ),
            'onComplete' : function()
            {
                $( 'nueva_not_prom' ).remove();
            }
        }
    ).request();
}

//MAndar las variables del filtro de vendedores
function Vend_send()
{   

divRef = document.getElementById('estContDiv');

preLoader(1, 'grafica' );

    var aja = new Ajax( 'resumen_ventas.php',
        {   'method' : 'get',
            'data' : $( 'filtro_vend' ),
            'update' : divRef,
            'onComplete' : function()
            {
                preLoader(0);
                $( 'vendedores_alerta' ).remove();
            }
        }
    ).request();    
}

function Vend_send_sld()
{ 

divRef = document.getElementById('estContDiv');

preLoader(1, 'grafica' );
  
    var aja = new Ajax( 'resumen_saldos.php',
        {   'method' : 'get',
            'data' : $( 'filtro_vend' ),
            'update' : divRef,
            'onComplete' : function()
            {
                preLoader(0);
                $( 'vendedores_alerta' ).remove();
            }
        }
    ).request();    
}


//MAndar las variables del filtro de comparacion_grafica
function Comp_send( id,graf_tipo,fe_se,fs,ven_part,cuenta_ven,sel_fvend,clie_part,cuenta_clie,sel_fclie,fam_part,cuenta_fam,
                   sel_ffam,prod_part,cuenta_prod,sel_fprod,sid,fecha_ini,fecha_fin,user_tipo )
{  

divRef = document.getElementById('estContDiv');

preLoader(1, 'grafica' );

graf_comp=id;
    var aja = new Ajax( 'resumen_ventas.php',
        {   'method' : 'get',
            'data'          :   {  
                                    'graf_comp'      :   graf_comp,
                                    'graf_tipo'      :   graf_tipo,
                                    'fe_se'      :   fe_se,
                                    'fs'      :   fs,
                                    'ven_part' : ven_part,
                                    'cuenta_ven'      :   cuenta_ven,
                                    'sel_fvend'      :   sel_fvend,
                                    'clie_part'      :   clie_part,
                                    'cuenta_clie'      :   cuenta_clie,
                                    'sel_fclie'      :   sel_fclie,
                                    'fam_part'      :   fam_part,
                                    'cuenta_fam'      :   cuenta_fam,
                                    'sel_ffam'      :   sel_ffam,
                                    'prod_part'      :   prod_part,
                                    'cuenta_prod'      :   cuenta_prod,
                                    'sel_fprod'      :   sel_fprod,
                                    'sid'            :   sid,
                                    'fecha_ini'      :   fecha_ini,
                                    'fecha_fin'      :   fecha_fin,
                                    'user_tipo'      :   user_tipo
                                            
                                },
            'update' : divRef,
            'onComplete' : function()
            {
                preLoader(0);
                $( 'comp_alerta' ).remove();
            }
        }
    ).request();     
}

//MAndar las variables del filtro de clientes
function Clie_send()
{  

divRef = document.getElementById('estContDiv');

preLoader(1, 'grafica' );
 
    var aja = new Ajax( 'resumen_ventas.php',
        {   'method' : 'get',
            'data' : $( 'filtro_clie' ),
            'update' : divRef,
            'onComplete' : function()
            {
                preLoader(0);
                $( 'clie_alerta' ).remove();
            }
        }
    ).request();    
}

function Clie_send_sld()
{ 

divRef = document.getElementById('estContDiv');

preLoader(1, 'grafica' );

    var aja = new Ajax( 'resumen_saldos.php',
        {   'method' : 'get',
            'data' : $( 'filtro_clie' ),
            'update' : divRef,
            'onComplete' : function()
            {
                preLoader(0);
                $( 'clie_alerta' ).remove();
            }
        }
    ).request();    
}

//MAndar las variables del filtro de familias
function Fam_send()
{   

divRef = document.getElementById('estContDiv');

preLoader(1, 'grafica' );

    var aja = new Ajax( 'resumen_ventas.php',
        {   'method' : 'get',
            'data' : $( 'filtro_fam' ),
            'update' : divRef,
            'onComplete' : function()
            {
                preLoader(0);
                $( 'fam_alerta' ).remove();
            }
        }
    ).request();    
}

//MAndar las variables del filtro de familias
function Prod_send()
{  

divRef = document.getElementById('estContDiv');

preLoader(1, 'grafica' );
 
    var aja = new Ajax( 'resumen_ventas.php',
        {   'method' : 'get',
            'data' : $( 'filtro_prod' ),
            'update' : divRef,
            'onComplete' : function()
            {
                preLoader(0);
                $( 'prod_alerta' ).remove();
            }
        }
    ).request();    
}


/**
 *  Detalle del mensaje seleccionado
 */
function mensaje_detalle( mensaje_id )
{
    if( $(' detalle_mensaje' ) )
    {
        $( 'detalle_mensaje' ).remove();
    }
    var pos = getAvailablePosition();
    var Div = new Element( "div", { "id" : "detalle_mensaje" }).inject( document.body );
    $( 'detalle_mensaje' ).setStyles(
        {   'position'  :   'absolute',
            'top'       :   pos.y + 'px',
            'left'      :   pos.x + 'px'
        }
    );
    var aja = new Ajax( urlProcesos,
        {
            'method'    :   'get',
            'data'      :   {   'action' : 'mensaje_deta',
                                'mensaje_id' : mensaje_id
                            },
            'update'    :   $( "detalle_mensaje" ),
            'onComplete'    : function()
            {
                showOver( "detalle_mensaje" );
            }
        }
    ).request();
}

/**
 *  Detalle de noticia o promocion
 */
function noti_prom_detalle( noti_prom_id )
{
    if( $(' deta_noti_prom' ) )
    {
        $( 'deta_noti_prom' ).remove();
    }
    var pos = getAvailablePosition();
    var Div = new Element( "div", { "id" : "deta_noti_prom" }).inject( document.body );
    $( 'deta_noti_prom' ).setStyles(
        {   'position'  :   'absolute',
            'top'       :   pos.y + 'px',
            'left'      :   pos.x + 'px'
        }
    );
    var aja = new Ajax( urlProcesos,
        {
            'method'    :   'get',
            'data'      :   {   'action' : 'noti_prom_deta',
                                'noti_prom_id' : noti_prom_id
                            },
            'update'    :   $( "deta_noti_prom" ),
            'onComplete'    : function()
            {
                showOver( "deta_noti_prom" );
            }
        }
    ).request();
}

/**
 *  Nuevo mensaje
 */
function nuevo_mensaje()
{
    captura_ma_form( 'mensaje' );
}




//Empiezan pruebas

function filtro_vend()
{

pGraf_comp=document.filtro.graf_comp.value;
pGraf_tipo=document.filtro.graf_tipo.value;
pFe_se=document.filtro.fe_se.value;
pFs=document.filtro.fs.value;
pVen_part=document.filtro.ven_part.value;
pCuenta_ven=document.filtro.cuenta_ven.value;
pSel_fvend=document.filtro.sel_fvend.value;
pClie_part=document.filtro.clie_part.value;
pCuenta_clie=document.filtro.cuenta_clie.value;
pSel_fclie=document.filtro.sel_fclie.value;
pFam_part=document.filtro.fam_part.value;
pCuenta_fam=document.filtro.cuenta_fam.value;
pSel_ffam=document.filtro.sel_ffam.value;
pProd_part=document.filtro.prod_part.value;
pCuenta_prod=document.filtro.cuenta_prod.value;
pSel_fprod=document.filtro.sel_fprod.value;

if(pFe_se=="rango"){
pFecha_ini=document.filtro.fechaIni.value;
pFecha_fin=document.filtro.fechaFin.value;
}
else{
pFecha_ini="";
pFecha_fin="";
}

    form_filtro('vendedor',pGraf_comp,pGraf_tipo,pFe_se,pFs,pVen_part,pCuenta_ven,pSel_fvend,pClie_part,pCuenta_clie,pSel_fclie,
    pFam_part,pCuenta_fam,pSel_ffam,pProd_part,pCuenta_prod,pSel_fprod,pFecha_ini,pFecha_fin);
}


function filtro_vend_sld()
{

pGraf_tipo=document.filtro.graf_tipo.value;
pFe_se=document.filtro.fe_se.value;
pFs=document.filtro.fs.value;
pVen_part=document.filtro.ven_part.value;
pCuenta_ven=document.filtro.cuenta_ven.value;
pSel_fvend=document.filtro.sel_fvend.value;
pClie_part=document.filtro.clie_part.value;
pCuenta_clie=document.filtro.cuenta_clie.value;
pSel_fclie=document.filtro.sel_fclie.value;

if(pFe_se=="rango"){
pFecha_ini=document.filtro.fechaIni.value;
pFecha_fin=document.filtro.fechaFin.value;
}
else{
pFecha_ini="";
pFecha_fin="";
}

    form_filtro_sld('vendedor',pGraf_tipo,pFe_se,pFs,pVen_part,pCuenta_ven,pSel_fvend,pClie_part,pCuenta_clie,pSel_fclie,pFecha_ini,pFecha_fin);
}


function muestra_info_mult(id)
{
    if( $( 'info_alerta' ) )
    {
        $( 'info_alerta' ).remove();
    }
    var pos = getAvailablePosition();
    var Div = new Element( "div",{"id" : "info_alerta"} ).inject( document.body );
    $( 'info_alerta' ).setStyles(
        {   'position'  :   'absolute',
            'left'      :   pos.x + 'px',
            'top'       :   pos.y + 'px'
        }
    );
    var aja = new Ajax( urlProcesos,
        {
            'method'        :   'get',
            'data'          :   {   'action'    : 'muestra_info_mult',
                                    'id_info'      :   id,
                                },
            'update'        :   $( 'info_alerta' ),
            'onComplete'    :   function()
            {
                showOver( 'info_alerta' );
            }
        }
    ).request();

}

function muestra_info_pdf(id)
{
    if( $( 'info_alerta' ) )
    {
        $( 'info_alerta' ).remove();
    }
    var pos = getAvailablePosition();
    var Div = new Element( "div",{"id" : "info_alerta"} ).inject( document.body );
    $( 'info_alerta' ).setStyles(
        {   'position'  :   'absolute',
            'width'     :   '700px',
            'height'    :   '700px',
            'left'      :   pos.x + 'px',
            'top'       :   pos.y + 'px'
        }
    );
    var aja = new Ajax( urlProcesos,
        {
            'method'        :   'get',
            'data'          :   {   'action'    : 'muestra_info_pdf',
                                    'id_info'      :   id,
                                },
            'update'        :   $( 'info_alerta' ),
            'onComplete'    :   function()
            {
                showOver( 'info_alerta' );
            }
        }
    ).request();

}

function Borrar_info_vend(id)
{
    preLoader(1, 'listaInfo' );
    
      
	  var d = document.getElementById(id);
	  //var a = document.getElementsByName(id);
	  
	  d.remove();
	  //a[1].remove();
	  /**/
	  
	  
  
    var aja = new Ajax( urlProcesos,
        {
            'method'        :   'get',
            'data'          :   {   'action'    : 'borrar_info_vend',
                                    'id_info'   :   id
                                },                   
            'onComplete'    :   function()
            {    
                preLoader(0);
            }
        }
    ).request();
	

}



function Borrar_caso(id)
{
    preLoader(1, 'casoShow' );
    

    
    if( confirm( 'Esta seguro que desea eliminar este caso? ' ) == true )
    {
      
	  var d = document.getElementById(id);
	  
	  d.remove();
	  
  
    var aja = new Ajax( urlProcesos,
        {
            'method'        :   'get',
            'data'          :   {   'action'    : 'borrar_caso',
                                    'id_caso'   :   id
                                },                   
            'onComplete'    :   function()
            {    
                preLoader(0);
            },
            'update'    :   $( 'casoShow' )
        }
    ).request();
	}else
	{}

}


function form_filtro( tipo,graf_comp,graf_tipo,fe_se,fs,ven_part,cuenta_ven,sel_fvend,clie_part,cuenta_clie,sel_fclie,
fam_part,cuenta_fam,sel_ffam,prod_part,cuenta_prod,sel_fprod,fecha_ini,fecha_fin )
{
    if( $( 'vendedores_alerta' ) )
    {
        $( 'vendedores_alerta' ).remove();
    }
    var pos = getAvailablePosition();
    var Div = new Element( "div",{"id" : "vendedores_alerta"} ).inject( document.body );
    $( 'vendedores_alerta' ).setStyles(
        {   'position'  :   'absolute',
            'left'      :   pos.x + 'px',
            'top'       :   pos.y + 'px'
        }
    );
    var aja = new Ajax( urlProcesos,
        {
            'method'        :   'get',
            'data'          :   {   'action'    : 'form_vendedor',
                                    'tipo'      :   tipo,
                                    'graf_comp'      :   graf_comp,
                                    'graf_tipo'      :   graf_tipo,
                                    'fe_se'      :   fe_se,
                                    'fs'      :   fs,
                                    'ven_part'      :   ven_part,
                                    'cuenta_ven'      :   cuenta_ven,
                                    'sel_fvend'      :   sel_fvend,
                                    'clie_part'      :   clie_part,
                                    'cuenta_clie'      :   cuenta_clie,
                                    'sel_fclie'      :   sel_fclie,
                                    'fam_part'      :   fam_part,
                                    'cuenta_fam'      :   cuenta_fam,
                                    'sel_ffam'      :   sel_ffam,
                                    'prod_part'      :   prod_part,
                                    'cuenta_prod'      :   cuenta_prod,
                                    'sel_fprod'      :   sel_fprod,
                                    'fecha_ini'      :   fecha_ini,
                                    'fecha_fin'      :   fecha_fin
                                },
            'update'        :   $( 'vendedores_alerta' ),
            'onComplete'    :   function()
            {
                showOver( 'vendedores_alerta' );
            }
        }
    ).request();
}


//Formulario para sugerir caso
function form_sug_caso()
{
    if( $( 'form_sug_caso' ) )
    {
        $( 'form_sug_caso' ).remove();
    }
    var pos = getAvailablePosition();
    var Div = new Element( "div",{"id" : "form_sug_caso"} ).inject( document.body );
    $( 'form_sug_caso' ).setStyles(
        {   'position'  :   'absolute',
            'left'      :   pos.x + 'px',
            'top'       :   pos.y + 'px'
        }
    );
    var aja = new Ajax( urlProcesos,
        {
            'method'        :   'get',
            'data'          :   {   'action'    : 'form_sug_caso'
                                },
            'update'        :   $( 'form_sug_caso' ),
            'onComplete'    :   function()
            {
                showOver( 'form_sug_caso' );
            }
        }
    ).request();
}
//


//Formulario para agregar caso
function form_add_caso()
{
    if( $( 'form_add_caso' ) )
    {
        $( 'form_add_caso' ).remove();
    }
    var pos = getAvailablePosition();
    var Div = new Element( "div",{"id" : "form_add_caso"} ).inject( document.body );
    $( 'form_add_caso' ).setStyles(
        {   'position'  :   'absolute',
            'left'      :   pos.x + 'px',
            'top'       :   pos.y + 'px'
        }
    );
    var aja = new Ajax( urlProcesos,
        {
            'method'        :   'get',
            'data'          :   {   'action'    : 'form_add_caso'
                                },
            'update'        :   $( 'form_add_caso' ),
            'onComplete'    :   function()
            {
                showOver( 'form_add_caso' );
            }
        }
    ).request();
}
//



//Lista de casos sugeridos
function casos_sug_list()
{
    if( $( 'casos_sug_list' ) )
    {
        $( 'casos_sug_list' ).remove();
    }
    var pos = getAvailablePosition();
    var Div = new Element( "div",{"id" : "casos_sug_list"} ).inject( document.body );
    $( 'casos_sug_list' ).setStyles(
        {   'position'  :   'absolute',
            'left'      :   pos.x + 'px',
            'top'       :   pos.y + 'px'
        }
    );
    var aja = new Ajax( urlProcesos,
        {
            'method'        :   'get',
            'data'          :   {   'action'    : 'casos_sug_list'
                                },
            'update'        :   $( 'casos_sug_list' ),
            'onComplete'    :   function()
            {
                showOver( 'casos_sug_list' );
            }
        }
    ).request();
}
//


//Detalle de caso sugerido
function caso_sug_deta(id)
{
   if( $( 'casos_sug_deta' ) )
    {
        $( 'casos_sug_deta' ).remove();
    }
    var pos = getAvailablePosition();
    
    var nx=pos.x+203;
    
    var Div = new Element( "div",{"id" : "casos_sug_deta"} ).inject( document.body );
    $( 'casos_sug_deta' ).setStyles(
        {   'position'  :   'absolute',
            'left'      :   nx + 'px',
            'top'       :   pos.y + 'px'
        }
    );
    var aja = new Ajax( urlProcesos,
        {
            'method'        :   'get',
            'data'          :   {   'action'    : 'casos_sug_deta',
                                    'id'        :  id
                                },
            'update'        :   $( 'casos_sug_deta' ),
            'onComplete'    :   function()
            {
                showOver( 'casos_sug_deta' );
            }
        }
    ).request();
}
//




function form_filtro_sld( tipo,graf_tipo,fe_se,fs,ven_part,cuenta_ven,sel_fvend,clie_part,cuenta_clie,sel_fclie,fecha_ini,fecha_fin )
{
    if( $( 'vendedores_alerta' ) )
    {
        $( 'vendedores_alerta' ).remove();
    }
    var pos = getAvailablePosition();
    var Div = new Element( "div",{"id" : "vendedores_alerta"} ).inject( document.body );
    $( 'vendedores_alerta' ).setStyles(
        {   'position'  :   'absolute',
            'left'      :   pos.x + 'px',
            'top'       :   pos.y + 'px'
        }
    );
    var aja = new Ajax( urlProcesos,
        {
            'method'        :   'get',
            'data'          :   {   'action'    : 'form_vendedor_sld',
                                    'tipo'      :   tipo,
                                    'graf_tipo'      :   graf_tipo,
                                    'fe_se'      :   fe_se,
                                    'fs'      :   fs,
                                    'ven_part'      :   ven_part,
                                    'cuenta_ven'      :   cuenta_ven,
                                    'sel_fvend'      :   sel_fvend,
                                    'clie_part'      :   clie_part,
                                    'cuenta_clie'      :   cuenta_clie,
                                    'sel_fclie'      :   sel_fclie,
                                    'fecha_ini'      :   fecha_ini,
                                    'fecha_fin'      :   fecha_fin
                                },
            'update'        :   $( 'vendedores_alerta' ),
            'onComplete'    :   function()
            {
                showOver( 'vendedores_alerta' );
            }
        }
    ).request();
}


function filtro_comp()
{

pGraf_comp=document.filtro.graf_comp.value;
pGraf_tipo=document.filtro.graf_tipo.value;
pFe_se=document.filtro.fe_se.value;
pFs=document.filtro.fs.value;
pVen_part=document.filtro.ven_part.value;
pCuenta_ven=document.filtro.cuenta_ven.value;
pSel_fvend=document.filtro.sel_fvend.value;
pClie_part=document.filtro.clie_part.value;
pCuenta_clie=document.filtro.cuenta_clie.value;
pSel_fclie=document.filtro.sel_fclie.value;
pFam_part=document.filtro.fam_part.value;
pCuenta_fam=document.filtro.cuenta_fam.value;
pSel_ffam=document.filtro.sel_ffam.value;
pProd_part=document.filtro.prod_part.value;
pCuenta_prod=document.filtro.cuenta_prod.value;
pSel_fprod=document.filtro.sel_fprod.value;

if(pFe_se=="rango"){
pFecha_ini=document.filtro.fechaIni.value;
pFecha_fin=document.filtro.fechaFin.value;
}
else{
pFecha_ini="";
pFecha_fin="";
}


    form_comp('comp',pGraf_comp,pGraf_tipo,pFe_se,pFs,pVen_part,pCuenta_ven,pSel_fvend,pClie_part,pCuenta_clie,pSel_fclie,
    pFam_part,pCuenta_fam,pSel_ffam,pProd_part,pCuenta_prod,pSel_fprod,pFecha_ini,pFecha_fin);
}


function form_comp( tipo,graf_comp,graf_tipo,fe_se,fs,ven_part,cuenta_ven,sel_fvend,clie_part,cuenta_clie,sel_fclie,
fam_part,cuenta_fam,sel_ffam,prod_part,cuenta_prod,sel_fprod,fecha_ini,fecha_fin )
{
    
    if( $( 'comp_alerta' ) )
    {
        $( 'comp_alerta' ).remove();
    }
    var pos = getAvailablePosition();
    var Div = new Element( "div",{"id" : "comp_alerta"} ).inject( document.body );
    $( 'comp_alerta' ).setStyles(
        {   'position'  :   'absolute',
            'left'      :   pos.x + 'px',
            'top'       :   pos.y + 'px'
        }
    );
    var aja = new Ajax( urlProcesos,
        {
            'method'        :   'get',
            'data'          :   {   'action'    : 'form_comp',
                                    'tipo'      :   tipo,
                                    'graf_comp'      :   graf_comp,
                                    'graf_tipo'      :   graf_tipo,
                                    'fe_se'      :   fe_se,
                                    'fs'      :   fs,
                                    'ven_part'      :   ven_part,
                                    'cuenta_ven'      :   cuenta_ven,
                                    'sel_fvend'      :   sel_fvend,
                                    'clie_part'      :   clie_part,
                                    'cuenta_clie'      :   cuenta_clie,
                                    'sel_fclie'      :   sel_fclie,
                                    'fam_part'      :   fam_part,
                                    'cuenta_fam'      :   cuenta_fam,
                                    'sel_ffam'      :   sel_ffam,
                                    'prod_part'      :   prod_part,
                                    'cuenta_prod'      :   cuenta_prod,
                                    'sel_fprod'      :   sel_fprod,
                                    'fecha_ini'      :  fecha_ini,
                                    'fecha_fin'      :  fecha_fin
                                      
                                },
            'update'        :   $( 'comp_alerta' ),
            'onComplete'    :   function()
            {
                showOver( 'comp_alerta' );
            }
        }
    ).request();
}


function filtro_clie()
{
pGraf_comp=document.filtro.graf_comp.value;
pGraf_tipo=document.filtro.graf_tipo.value;
pFe_se=document.filtro.fe_se.value;
pFs=document.filtro.fs.value;
pVen_part=document.filtro.ven_part.value;
pCuenta_ven=document.filtro.cuenta_ven.value;
pSel_fvend=document.filtro.sel_fvend.value;
pClie_part=document.filtro.clie_part.value;
pCuenta_clie=document.filtro.cuenta_clie.value;
pSel_fclie=document.filtro.sel_fclie.value;
pFam_part=document.filtro.fam_part.value;
pCuenta_fam=document.filtro.cuenta_fam.value;
pSel_ffam=document.filtro.sel_ffam.value;
pProd_part=document.filtro.prod_part.value;
pCuenta_prod=document.filtro.cuenta_prod.value;
pSel_fprod=document.filtro.sel_fprod.value;

if(pFe_se=="rango"){
pFecha_ini=document.filtro.fechaIni.value;
pFecha_fin=document.filtro.fechaFin.value;
}
else{
pFecha_ini="";
pFecha_fin="";
}

    form_clie('clie',pGraf_comp,pGraf_tipo,pFe_se,pFs,pVen_part,pCuenta_ven,pSel_fvend,pClie_part,pCuenta_clie,pSel_fclie,
    pFam_part,pCuenta_fam,pSel_ffam,pProd_part,pCuenta_prod,pSel_fprod,pFecha_ini,pFecha_fin);
}


function filtro_clie_sld()
{

pGraf_tipo=document.filtro.graf_tipo.value;
pFe_se=document.filtro.fe_se.value;
pFs=document.filtro.fs.value;
pVen_part=document.filtro.ven_part.value;
pCuenta_ven=document.filtro.cuenta_ven.value;
pSel_fvend=document.filtro.sel_fvend.value;
pClie_part=document.filtro.clie_part.value;
pCuenta_clie=document.filtro.cuenta_clie.value;
pSel_fclie=document.filtro.sel_fclie.value;

if(pFe_se=="rango"){
pFecha_ini=document.filtro.fechaIni.value;
pFecha_fin=document.filtro.fechaFin.value;
}
else{
pFecha_ini="";
pFecha_fin="";
}

    form_clie_sld('clie',pGraf_tipo,pFe_se,pFs,pVen_part,pCuenta_ven,pSel_fvend,pClie_part,pCuenta_clie,pSel_fclie,pFecha_ini,pFecha_fin );
}



function form_clie( tipo,graf_comp,graf_tipo,fe_se,fs,ven_part,cuenta_ven,sel_fvend,clie_part,cuenta_clie,sel_fclie,
fam_part,cuenta_fam,sel_ffam,prod_part,cuenta_prod,sel_fprod,fecha_ini,fecha_fin )
{
    if( $( 'clie_alerta' ) )
    {
        $( 'clie_alerta' ).remove();
    }
    var pos = getAvailablePosition();
    var Div = new Element( "div",{"id" : "clie_alerta"} ).inject( document.body );
    $( 'clie_alerta' ).setStyles(
        {   'position'  :   'absolute',
            'left'      :   pos.x + 'px',
            'top'       :   pos.y + 'px'
        }
    );
    var aja = new Ajax( urlProcesos,
        {
            'method'        :   'get',
            'data'          :   {   'action'    : 'form_clie',
                                    'tipo'      :   tipo,
                                    'graf_comp'      :   graf_comp,
                                    'graf_tipo'      :   graf_tipo,
                                    'fe_se'      :   fe_se,
                                    'fs'      :   fs,
                                    'ven_part'      :   ven_part,
                                    'cuenta_ven'      :   cuenta_ven,
                                    'sel_fvend'      :   sel_fvend,
                                    'clie_part'      :   clie_part,
                                    'cuenta_clie'      :   cuenta_clie,
                                    'sel_fclie'      :   sel_fclie,
                                    'fam_part'      :   fam_part,
                                    'cuenta_fam'      :   cuenta_fam,
                                    'sel_ffam'      :   sel_ffam,
                                    'prod_part'      :   prod_part,
                                    'cuenta_prod'      :   cuenta_prod,
                                    'sel_fprod'      :   sel_fprod,
                                    'fecha_ini'      :   fecha_ini,
                                    'fecha_fin'      :   fecha_fin
                                },
            'update'        :   $( 'clie_alerta' ),
            'onComplete'    :   function()
            {
                showOver( 'clie_alerta' );
            }
        }
    ).request();
}

function form_clie_sld( tipo,graf_tipo,fe_se,fs,ven_part,cuenta_ven,sel_fvend,clie_part,cuenta_clie,sel_fclie,fecha_ini,fecha_fin )
{
    if( $( 'clie_alerta' ) )
    {
        $( 'clie_alerta' ).remove();
    }
    var pos = getAvailablePosition();
    var Div = new Element( "div",{"id" : "clie_alerta"} ).inject( document.body );
    $( 'clie_alerta' ).setStyles(
        {   'position'  :   'absolute',
            'left'      :   pos.x + 'px',
            'top'       :   pos.y + 'px'
        }
    );
    var aja = new Ajax( urlProcesos,
        {
            'method'        :   'get',
            'data'          :   {   'action'    : 'form_clie_sld',
                                    'tipo'      :   tipo,
                                    'graf_tipo'      :   graf_tipo,
                                    'fe_se'      :   fe_se,
                                    'fs'      :   fs,
                                    'ven_part'      :   ven_part,
                                    'cuenta_ven'      :   cuenta_ven,
                                    'sel_fvend'      :   sel_fvend,
                                    'clie_part'      :   clie_part,
                                    'cuenta_clie'      :   cuenta_clie,
                                    'sel_fclie'      :   sel_fclie,
                                    'fecha_ini'      :   fecha_ini,
                                    'fecha_fin'      :   fecha_fin
                                },
            'update'        :   $( 'clie_alerta' ),
            'onComplete'    :   function()
            {
                showOver( 'clie_alerta' );
            }
        }
    ).request();
}


function filtro_fam()
{
pGraf_comp=document.filtro.graf_comp.value;
pGraf_tipo=document.filtro.graf_tipo.value;
pFe_se=document.filtro.fe_se.value;
pFs=document.filtro.fs.value;
pVen_part=document.filtro.ven_part.value;
pCuenta_ven=document.filtro.cuenta_ven.value;
pSel_fvend=document.filtro.sel_fvend.value;
pClie_part=document.filtro.clie_part.value;
pCuenta_clie=document.filtro.cuenta_clie.value;
pSel_fclie=document.filtro.sel_fclie.value;
pFam_part=document.filtro.fam_part.value;
pCuenta_fam=document.filtro.cuenta_fam.value;
pSel_ffam=document.filtro.sel_ffam.value;
pProd_part=document.filtro.prod_part.value;
pCuenta_prod=document.filtro.cuenta_prod.value;
pSel_fprod=document.filtro.sel_fprod.value;

if(pFe_se=="rango"){
pFecha_ini=document.filtro.fechaIni.value;
pFecha_fin=document.filtro.fechaFin.value;
}
else{
pFecha_ini="";
pFecha_fin="";
}

    form_fam('fam',pGraf_comp,pGraf_tipo,pFe_se,pFs,pVen_part,pCuenta_ven,pSel_fvend,pClie_part,pCuenta_clie,pSel_fclie,
    pFam_part,pCuenta_fam,pSel_ffam,pProd_part,pCuenta_prod,pSel_fprod,pFecha_ini,pFecha_fin);
}

function form_fam( tipo,graf_comp,graf_tipo,fe_se,fs,ven_part,cuenta_ven,sel_fvend,clie_part,cuenta_clie,sel_fclie,
fam_part,cuenta_fam,sel_ffam,prod_part,cuenta_prod,sel_fprod,fecha_ini,fecha_fin )
{
    if( $( 'fam_alerta' ) )
    {
        $( 'fam_alerta' ).remove();
    }
    var pos = getAvailablePosition();
    var Div = new Element( "div",{"id" : "fam_alerta"} ).inject( document.body );
    $( 'fam_alerta' ).setStyles(
        {   'position'  :   'absolute',
            'left'      :   pos.x + 'px',
            'top'       :   pos.y + 'px'
        }
    );
    var aja = new Ajax( urlProcesos,
        {
            'method'        :   'get',
            'data'          :   {   'action'    : 'form_fam',
                                    'tipo'      :   tipo,
                                    'graf_comp'      :   graf_comp,
                                    'graf_tipo'      :   graf_tipo,
                                    'fe_se'      :   fe_se,
                                    'fs'      :   fs,
                                    'ven_part'      :   ven_part,
                                    'cuenta_ven'      :   cuenta_ven,
                                    'sel_fvend'      :   sel_fvend,
                                    'clie_part'      :   clie_part,
                                    'cuenta_clie'      :   cuenta_clie,
                                    'sel_fclie'      :   sel_fclie,
                                    'fam_part'      :   fam_part,
                                    'cuenta_fam'      :   cuenta_fam,
                                    'sel_ffam'      :   sel_ffam,
                                    'prod_part'      :   prod_part,
                                    'cuenta_prod'      :   cuenta_prod,
                                    'sel_fprod'      :   sel_fprod,
                                    'fecha_ini'      :   fecha_ini,
                                    'fecha_fin'      :   fecha_fin
                                },
            'update'        :   $( 'fam_alerta' ),
            'onComplete'    :   function()
            {
                showOver( 'fam_alerta' );
            }
        }
    ).request();
}

function filtro_prod()
{
pGraf_comp=document.filtro.graf_comp.value;
pGraf_tipo=document.filtro.graf_tipo.value;
pFe_se=document.filtro.fe_se.value;
pFs=document.filtro.fs.value;
pVen_part=document.filtro.ven_part.value;
pCuenta_ven=document.filtro.cuenta_ven.value;
pSel_fvend=document.filtro.sel_fvend.value;
pClie_part=document.filtro.clie_part.value;
pCuenta_clie=document.filtro.cuenta_clie.value;
pSel_fclie=document.filtro.sel_fclie.value;
pFam_part=document.filtro.fam_part.value;
pCuenta_fam=document.filtro.cuenta_fam.value;
pSel_ffam=document.filtro.sel_ffam.value;
pProd_part=document.filtro.prod_part.value;
pCuenta_prod=document.filtro.cuenta_prod.value;
pSel_fprod=document.filtro.sel_fprod.value;

if(pFe_se=="rango"){
pFecha_ini=document.filtro.fechaIni.value;
pFecha_fin=document.filtro.fechaFin.value;
}
else{
pFecha_ini="";
pFecha_fin="";
}

    form_prod('prod',pGraf_comp,pGraf_tipo,pFe_se,pFs,pVen_part,pCuenta_ven,pSel_fvend,pClie_part,pCuenta_clie,pSel_fclie,
    pFam_part,pCuenta_fam,pSel_ffam,pProd_part,pCuenta_prod,pSel_fprod,pFecha_ini,pFecha_fin);
}

function form_prod( tipo,graf_comp,graf_tipo,fe_se,fs,ven_part,cuenta_ven,sel_fvend,clie_part,cuenta_clie,sel_fclie,
fam_part,cuenta_fam,sel_ffam,prod_part,cuenta_prod,sel_fprod,fecha_ini,fecha_fin )
{
    if( $( 'prod_alerta' ) )
    {
        $( 'prod_alerta' ).remove();
    }
    var pos = getAvailablePosition();
    var Div = new Element( "div",{"id" : "prod_alerta"} ).inject( document.body );
    $( 'prod_alerta' ).setStyles(
        {   'position'  :   'absolute',
            'left'      :   pos.x + 'px',
            'top'       :   pos.y + 'px'
        }
    );
    var aja = new Ajax( urlProcesos,
        {
            'method'        :   'get',
            'data'          :   {   'action'    : 'form_prod',
                                    'tipo'      :   tipo,
                                    'graf_comp'      :   graf_comp,
                                    'graf_tipo'      :   graf_tipo,
                                    'fe_se'      :   fe_se,
                                    'fs'      :   fs,
                                    'ven_part'      :   ven_part,
                                    'cuenta_ven'      :   cuenta_ven,
                                    'sel_fvend'      :   sel_fvend,
                                    'clie_part'      :   clie_part,
                                    'cuenta_clie'      :   cuenta_clie,
                                    'sel_fclie'      :   sel_fclie,
                                    'fam_part'      :   fam_part,
                                    'cuenta_fam'      :   cuenta_fam,
                                    'sel_ffam'      :   sel_ffam,
                                    'prod_part'      :   prod_part,
                                    'cuenta_prod'      :   cuenta_prod,
                                    'sel_fprod'      :   sel_fprod,
                                    'fecha_ini'      :   fecha_ini,
                                    'fecha_fin'      :   fecha_fin
                                },
            'update'        :   $( 'prod_alerta' ),
            'onComplete'    :   function()
            {
                showOver( 'prod_alerta' );
            }
        }
    ).request();
}

//Terminan pruebas






/**
 *  formulario para la captura de mensajes
 */
function captura_ma_form( tipo )
{
    if( $( 'captura_mensaje_alerta' ) )
    {
        $( 'captura_mensaje_alerta' ).remove();
    }
    var pos = getAvailablePosition();
    var Div = new Element( "div",{"id" : "captura_mensaje_alerta"} ).inject( document.body );
    $( 'captura_mensaje_alerta' ).setStyles(
        {   'position'  :   'absolute',
            'left'      :   pos.x + 'px',
            'top'       :   pos.y + 'px'
        }
    );
    var aja = new Ajax( urlProcesos,
        {
            'method'        :   'get',
            'data'          :   {   'action'    : 'form_cap_mensaje_alerta',
                                    'tipo'      :   tipo
                                },
            'update'        :   $( 'captura_mensaje_alerta' ),
            'onComplete'    :   function()
            {
                showOver( 'captura_mensaje_alerta' );
            }
        }
    ).request();
}

/**
 *  formulario para la captura de noticias y promociones
 */
function nueva_not_prom()
{
    if( $( 'nueva_not_prom' ) )
    {
        $( 'nueva_not_prom' ).remove();
    }
    var pos = getAvailablePosition();
    var Div = new Element( "div",{"id" : "nueva_not_prom"} ).inject( document.body );
    $( 'nueva_not_prom' ).setStyles(
        {   'position'  :   'absolute',
            'left'      :   pos.x + 'px',
            'top'       :   pos.y + 'px'
        }
    );
    var aja = new Ajax( urlProcesos,
        {
            'method'        :   'get',
            'data'          :   {   'action'    : 'form_cap_noti_promo'
                                },
            'update'        :   $( 'nueva_not_prom' ),
            'onComplete'    :   function()
            {
                showOver( 'nueva_not_prom' );
            }
        }
    ).request();
}
/**
 *  Ventana de notificaciones
 */
function show_notificaciones()
{
    if( $( 'notificaciones' ) )
    {
        $( 'notificaciones' ).remove();
    }
    var pos = getAvailablePosition();
    var Div = new Element( "div",{"id" : "notificaciones"} ).inject( document.body );
    $( 'notificaciones' ).setStyles(
        {   'position'  :   'absolute',
            'left'      :   pos.x + 'px',
            'top'       :   pos.y + 'px'
        }
    );
    var aja = new Ajax( urlProcesos,
        {
            'method'        :   'get',
            'data'          :   {   'action'    : 'show_notificaciones'
                                },
            'update'        :   $( 'notificaciones' ),
            'onComplete'    :   function()
            {
                showOver( 'notificaciones' );
            }
        }
    ).request();
}

/**
 * Menu notificaciones
*/
function notiMenu( menu )
{
    preLoader(1, 'notiCont' );
    
    var aja = new Ajax( urlProcesos,
        {
            'method'        :   'get',
            'data'          :   {   'action'  : 'noti_menu',
                                    'menu'    : menu
                                },
            'update'        :   $( 'notiCont' ),
            'onComplete'    :   function()
            {
                preLoader(0);
            }
        }
    ).request();
}


/**
 * LOOP de funciones
*/
function loopFunctions()
{
    chkComments();
	updateAlertList();
	updateMsjList();
    chkInvita();
    if( $( 'session_user_tipo' ).value == 1 )
    {
        chkSoli();
    }
	//setTimeout( "loopFunctions()", 60000 );
    if( arguments[ 0 ] )
    {
        setCascade();
    }
	setTimeout( "loopFunctions()", 60000 );
}
/**
 *  Solicitudes
 */
function chkSoli()
{
    if( $( 'soliAlertDiv' ) ) $( 'soliAlertDiv' ).remove();
    var pos = getAvailablePosition();
    new Element( 'div', { 'id' : 'soliAlertDiv' } ).inject( document.body );
    $( 'soliAlertDiv' ).setStyles(
        {   'position'  :   'absolute',
            'top'       :   pos.y + 'px',
            'left'      :   pos.x + 'px'
        }
    );
    new Ajax( urlProcesos,
        {   'method'    :   'get',
            'data'      :   { 'action'  :   'chk_soli' },
            'evalScripts'   :   true,
            'update'    :   $( 'soliAlertDiv' )
        }
    ).request();
}
/**
 * Buscador de tareas
 */ 
function buscador()
{
    
    el=document.getElementById("searchInput");
    
    if( !$( 'searchRS' ) )
    {
        var srs = new Element( "div", { "id" : "searchRS" } ).inject( document.body );
    }
    if( el.value.length >= 3 )
    {
        var aja = new Ajax( urlProcesos,
            {   'method' : 'get',
                'data'   : {'action':'seachData','valor' : el.value },
                'update' : $( 'searchRS' ),
                'onComplete' : function()
                {
                    $( 'searchRS' ).setStyles( 
                        {
                            'position'  : 'absolute',
                            'top'       :   $( el.id ).getPosition().y + 20,
                            'left'      :   $( el.id ).getPosition().x - 48
                        }
                    );
                    showOver( 'searchRS');
                }
            }
        ).request();
    }
    else
    {
        $( 'searchRS' ).remove();
    }
}

function closeSearch()
{
    if( $('searchRS') )
    {
        $('searchRS').remove()
    }
    
    if( $('searchInput') )
    {
        $('searchInput').value="";
    }
    
    
}
/**
 *  Asigna el status de la solicitud recibida
 *  0   pendiente de confirmacion
 *  1   Aceptada
 *  2   Resolucion mas tarde
 *  3   No acptada
 */
function setSolicitudStatus( acti_id, status )
{
    var jsn = new Json.Remote( 
        urlProcesos + '&action=set_solicitud_status' + 
        '&acti_id=' + acti_id + '&status=' + status,
        {   'onComplete'    :   function( obj )
            {
                if( obj.complete == 'ok' )
                {
                    if( $( 'acti_fech_hidden' ) )
                    {
                        show_activities( $( 'actiFechHidden' ).value );
                        $('acti_deta_div').remove();
                    }
                    else
                    {
                        activitie_deta( obj.acti_id );
                    }
                    chkInvita();
                }
            }
        }
    ).send();
}
/**
 *  Filtra listado de recursos humanos
 */
function filtraRecursosHumanos( val )
{
    var func = ( arguments[1] ? arguments[1] : 'add_recu_huma' );
    filtraUserList( val, 'listaRecursosHumanos', func, 'ALL' );
}
/**
 *  Filtra listado de usuarios
 */
function filtraUserList( val, idUpdate, functionName, filterType )
{
    var obj=   {
            'val'           :   val,
            'idUpdate'      :   idUpdate,
            'functionName'  :   functionName,
            'filterType'    :   filterType,
            'action'        :   'filter_user_list'
        }
    if( arguments[4] )
    {
        obj.tipo = arguments[ 4 ];
    }
    filterList( obj );
}

/**
 *  Filtra listado de vendedores comi
 */
function filtraVendComiList( val, idUpdate, functionName, filterType )
{
    var obj=   {
            'val'           :   val,
            'idUpdate'      :   idUpdate,
            'functionName'  :   functionName,
            'filterType'    :   filterType,
            'action'        :   'filter_vend_comi_list'
        }
    if( arguments[4] )
    {
        obj.tipo = arguments[ 4 ];
    }
    filterList( obj );
}

//Filtra lista casos tipicos
function filtraCasosList( like, chk, idUpdate )
{

    var obj=   {
            'like'          :   like,
            'chk'           :   chk,
            'idUpdate'      :   idUpdate,
            'action'        :   'filter_casos_list'
        }
        
   if( like.length >= 2 ){
    
         new Ajax( urlProcesos,
                {   'method'    :   'get',
                    'data'      :   obj,
                    'update'    :   $( obj.idUpdate )
                }
            ).request();
    }
    
    if(like==''){
    
        new Ajax( urlProcesos,
                {   'method'    :   'get',
                    'data'      :   obj,
                    'update'    :   $( obj.idUpdate )
                }
            ).request();
    }
}

//Admin

function filtraCasosListAdmin( like, chk, idUpdate )
{

    var obj=   {
            'like'          :   like,
            'chk'           :   chk,
            'idUpdate'      :   idUpdate,
            'action'        :   'filter_casos_list_admin'
        }
        
   if( like.length >= 2 ){
    
         new Ajax( urlProcesos,
                {   'method'    :   'get',
                    'data'      :   obj,
                    'update'    :   $( obj.idUpdate )
                }
            ).request();
    }
    
    if(like==''){
    
        new Ajax( urlProcesos,
                {   'method'    :   'get',
                    'data'      :   obj,
                    'update'    :   $( obj.idUpdate )
                }
            ).request();
    }
}

//

/**
 *  Filtra listado de vendedores
 */
function filtraVendList( val, idUpdate, functionName, filterType )
{
    
    pVen_part=document.filtro.ven_part.value;
    
    
    var obj=   {
            'val'           :   val,
            'idUpdate'      :   idUpdate,
            'functionName'  :   functionName,
            'filterType'    :   filterType,
            'action'        :   'filter_vend_list'
        }
    if( arguments[4] )
    {
        obj.tipo = arguments[ 4 ];
    }
    filterList( obj,pVen_part );
}

/**
 * Filtra listado de clientes del filtro
 */
function filtraClieList( val, idUpdate, functionName )
{

    pClie_part=document.filtro.clie_part.value;
    
    var obj = { 'val' : val, 'idUpdate' : idUpdate, 'functionName' : functionName, 'action' : 'filter_clie_list' };
    if( arguments[3] == 'obj' )
    {
        obj.funcReturn = 'obj';
    }
    filterList( obj,'',pClie_part );
}

/**
 * Filtra listado de familias del filtro
 */
function filtraFamList( val, idUpdate, functionName, filterType )
{
    pFam_part=document.filtro.fam_part.value;
    
    var obj=   {
            'val'           :   val,
            'idUpdate'      :   idUpdate,
            'functionName'  :   functionName,
            'filterType'    :   filterType,
            'action'        :   'filter_fam_list'
        }
    if( arguments[4] )
    {
        obj.tipo = arguments[ 4 ];
    }
    filterList( obj,'','',pFam_part );
}

/**
 * Lista product input
 */
function InputProdList( val,id,evnt,form )
{


    code = ( window.ie ? evnt.keyCode : evnt.which );
    if( val.length >= 3 && 
        (   (   code >= 65 && code <= 92 ) ||
            (   code >= 96 && code <= 105 ) ||
            (   code >= 48 && code <= 57 )
        )
    )
    {
        
        selectInpProd( val,id,form );
    }
    if( code == 27 || code == 9 )
    {
        if( $( 'InputProdList' ) ) $( 'InputProdList' ).remove();
    }

}


/**
 * Lista product input
 */
function InputProdListExist( val,id,evnt,form )
{


    code = ( window.ie ? evnt.keyCode : evnt.which );
    if( val.length >= 3 && 
        (   (   code >= 65 && code <= 92 ) ||
            (   code >= 96 && code <= 105 ) ||
            (   code >= 48 && code <= 57 )
        )
    )
    {
        
        selectInpProd( val,id,form,'exist' );
    }
    if( code == 27 || code == 9 )
    {
        if( $( 'InputProdList' ) ) $( 'InputProdList' ).remove();
    }

}

function selectInpProd( val,id,form,exist )
{
    if( $( 'InputProdList' ) ) $( 'InputProdList' ).remove();
    var Div =new Element( 'div', { 'id' : 'InputProdList' } ).inject( document.body );
    $( 'InputProdList' ).setStyles(
        {   'position'      :   'absolute',
            'left'          :   ( $( id ) ? $( id ).getPosition().x : $( form ).getPosition().x ),
            'top'           :   ( $( id ) ? $( id ).getPosition().y : $( form ).getPosition().y )+15,
            'border'        :   'solid 2px #cdcdcd',
            'background-color'  :   '#ffffff'
        }
    );
    
    if(exist){
        
        exist=1;
    
    }else{
    
        exist=0;
    }
    
    var like = false;
    var noFind = false;
    
    if( val )
    {
        like   =  val;
        noFind =   1;
    }

    new Ajax( urlProductos,
        {   'method'    :   'get',
            'data'      :   {   'input'         :   id,
                                'form'          :   form,
                                'action'        :   'input_prod',
                                'like'          :   like,
                                'exist'         :   exist,
                                'noFind'        :   noFind
                            },
            'update'    :   $( 'InputProdList' ),
            'evalScripts'   :   true,
            'onComplete'    :   function()
            {
                showOver( 'InputProdList' );
            }
            
        }
    ).request();
}

function FillInputProd( obj )
{

        $( obj.input ) .value =   unescape( obj.prod_desc );
        
        if($( 'prod_clave' )){
            $( 'prod_clave' ) .value =   unescape( obj.prod_clave );
        }
       
        if($( obj.input ) .id=="mod_ant"){
            $( 'prod_clave_ant' ) .value =   unescape( obj.prod_clave );
        }
        
        if($( obj.input ) .id=="mod_nue"){
            $( 'prod_clave_nue' ) .value =   unescape( obj.prod_clave );
        }
        

        if( $( 'InputProdList' ) ) $( 'InputProdList' ).remove();


}


function numTras( num )
{
	
	if( $( 'tras_num_eq' ).value == '0' )
    {
        alert( 'Debe introducir un numero mayor a cero' );
		$( 'tras_num_eq' ).value = "";
		num="";
    }
	
	preLoader(1, 'imei_tras' );
	
	new Ajax( urlProcesos,
		{   'method'    :   'get',
			'data'      :   {   'num'         :   num,
								'action'     :   "numTras"
							},
			'update'    :   $( 'imei_tras' ),
			'onComplete'    :   function()
			{
				preLoader(0);
			}
			 
		}
	).request();
}



/**
 * Lista plan input
 */
function InputPlanList( val,id,evnt,form )
{


    code = ( window.ie ? evnt.keyCode : evnt.which );
    if( val.length >= 1 && 
        (   (   code >= 65 && code <= 92 ) ||
            (   code >= 96 && code <= 105 ) ||
            (   code >= 48 && code <= 57 )
        )
    )
    {
        
        selectInpPlan( val,id,form );
    }
    if( code == 27 || code == 9 )
    {
        if( $( 'InputPlanList' ) ) $( 'InputPlanList' ).remove();
    }

}

function selectInpPlan( val,id,form )
{
    if( $( 'InputPlanList' ) ) $( 'InputPlanList' ).remove();
    var Div =new Element( 'div', { 'id' : 'InputPlanList' } ).inject( document.body );
    $( 'InputPlanList' ).setStyles(
        {   'position'      :   'absolute',
            'left'          :   ( $( id ) ? $( id ).getPosition().x : $( form ).getPosition().x ),
            'top'           :   ( $( id ) ? $( id ).getPosition().y : $( form ).getPosition().y )+15,
            'border'        :   'solid 2px #cdcdcd',
            'background-color'  :   '#ffffff'
        }
    );

    
    
    var like = false;
    var noFind = false;
    
    if( val )
    {
        like   =  val;
        noFind =   1;
    }

    new Ajax( urlProductos,
        {   'method'    :   'get',
            'data'      :   {   'input'         :   id,
                                'form'          :   form,
                                'action'        :   'input_plan',
                                'like'          :   like,
                                'noFind'        :   noFind
                            },
            'update'    :   $( 'InputPlanList' ),
            'evalScripts'   :   true,
            'onComplete'    :   function()
            {
                showOver( 'InputPlanList' );
            }
            
        }
    ).request();
}

function FillInputPlan( obj )
{

        $( obj.input ) .value =   unescape( obj.plan_nom );
        
        if($( 'plan_id' )){
            $( 'plan_id' ) .value =   unescape( obj.plan_id );
        }
       
        if($( obj.input ) .id=="plan_ant_text"){
            $( 'plan_ant' ) .value =   unescape( obj.plan_id );
        }
        
        if($( obj.input ) .id=="plan_nue_text"){
            $( 'plan_nue' ) .value =   unescape( obj.plan_id );
        }
        

        if( $( 'InputPlanList' ) ) $( 'InputPlanList' ).remove();


}



/**
 * Filtra listado de productos del filtro
 */
function FiltraProdList( val, idUpdate, functionName )
{


    pProd_part=document.filtro.prod_part.value;
    
    var obj = { 'val' : val, 'idUpdate' : idUpdate, 'functionName' : functionName, 'action' : 'filter_prod_list' };
    if( arguments[3] == 'obj' )
    {
        obj.funcReturn = 'obj';
    }
    filterList( obj,'','','',pProd_part );
}

/**
 * Filtra listado de clientes
 */
function filtraClientList( val, idUpdate, functionName )
{
    var obj = { 'val' : val, 'idUpdate' : idUpdate, 'functionName' : functionName, 'action' : 'filter_client_list' };
    if( arguments[3] == 'obj' )
    {
        obj.funcReturn = 'obj';
    }
    filterList( obj );
}

/**
 * Filtra listado de clientes
 */
function filtraClientListVent( val, idUpdate, functionName )
{
    var obj = { 'val' : val, 'idUpdate' : idUpdate, 'functionName' : functionName, 'action' : 'filter_client_list_vent' };
    if( arguments[3] == 'obj' )
    {
        obj.funcReturn = 'obj';
    }
    filterList( obj );
}

/**
 *  Filtra listado
 */

function filterList( obj,ven_part,clie_part,fam_part,prod_part )
{
    var filter  =   false;
    var tipo    =   ( obj.tipo ? obj.tipo : '' );
    var filter  =   ( obj.val.length >= 2 ? obj.val : '' );
    var sendObj =   {   'action'        :   obj.action,
                        'functionName'  :   obj.functionName,
                        'filterType'    :   obj.filterType ? obj.filterType : 'USER',
                        'filter'        :   filter,
                        'tipo'          :   tipo,
                        'ven_part'      :   ven_part,
                        'clie_part'     :   clie_part,
                        'fam_part'      :   fam_part,
                        'prod_part'     :   prod_part
                    };
    if( obj.funcReturn )
    {
        sendObj.funcReturn = obj.funcReturn;
    }
    new Ajax( urlProcesos,
        {   'method'    :   'get',
            'data'      :   sendObj,
            'update'    :   $( obj.idUpdate )
        }
    ).request();
}

/**
 *  Llena campos cliente venta
 */

function VentaCliente( id )
{
    
    preLoader(1, 'formulario' );
    
    new Ajax( urlProcesos,
        {   'method'    :   'get',
            'data'      :   {   'id'         :   id,
                                'action'     :   "cliente_venta"
                            },
            'update'    :   $( 'formulario' ),
            'onComplete'    :   function()
            {
               preLoader(0); 
            }
            
        }
    ).request();

}

/**
 *  Formulario venta renovacion
 */
function val_renov(val){

    
    if(val=="0"){
        
        $('renov').style.display='inline';
        $( 'chk_renov' ).value = '1';
        $( 'cont_tipo' ).setHTML( 'A-' );
    }  
    else{
        $('renov').style.display='none';
        $( 'chk_renov' ).value = '0';
        $( 'cont_tipo' ).setHTML( 'B-' );
    }

}

/**
 *  Validar contrato
 */
function validaContNo( el )
{
    $( 'valida_cont' ).setHTML( 'Verificando....' );
	
	var renov= $( 'chk_renov' ).value;
	
    new Ajax( urlProcesos,
        {   'method'        :   'get',
            'data'          :   { 'action' : 'validate_cont_no','renov':renov, 'cont' : el.value, 'idMns' : 'valida_cont','idInp':el.id },
            'evalScripts'   :   true
        }
    ).request();
}


/**
 *  Cambio de numero libre
 */
function camb_num(val,vd,n){

    
    if(val=="0"){
        
        $('tel_'+vd).removeProperty('disabled');
        $( 'cam_num' ).value = '1';
    }  
    else{
        
        $('tel_'+vd).disabled = true;
        $('tel_'+vd).value= n;
        $( 'cam_num' ).value = '0';
    }

}


/**
 *  Habilitar compra pedido
 */
function compPed(val,pi,pc){
    
    if(val=="0"){
        $( "cantComp_"+pi ).removeProperty('disabled');
        $( "checkComp["+pi+"]" ).value = pc;
    }  
    else{
        
        $("cantComp_"+pi).disabled = true;
        $("cantComp_"+pi).value= "";
        $( "checkComp["+pi+"]" ).value = '0';
    }

}

/**
 *  Registrar compra
 */
function regisComp()
{
    preLoader(1,'pedidosContDiv');
    
    var aja = new Ajax( urlProcesos,
        {   'method' : 'get',
            'data' : $( 'pedidosForm' ),
            'update' : $( 'pedidosContDiv'),
            'onComplete' : function()
            {
                preLoader(0);
            }
        }
    ).request();
}

/**
 *  Principal activacion
 */
function principal_check(val,tipo,user){

	new Ajax( urlProcesos,
			{   'method'        :   'get',
				'data'          :   { 'action' : 'principal_check',
									  'val' : val,
									  'tipo':tipo,
									  'user':user
									},
				'evalScripts'   :   true
			}
		).request();

}



/**
 *  Tipo plan
 */
function val_tp(val){

    
    if(val=="Forzoso"){
        $('plazo1').style.display='inline';
        $('plazo2').style.display='inline';
        
        $('mod1').style.display='inline';
        $('mod2').style.display='inline'; 
        
        $('renovacion_check').style.display='inline'; 
        
        $('plan1').style.position='relative';
        $('plan2').style.position='relative';
        
        $('plan1').style.top='0px';
        $('plan2').style.top='0px';
        
        $('plan1').style.left='0px';
        $('plan2').style.left='0px';
        
        $('docs_form').style.position='relative';
        $('docs_form').style.top='0px'; 
        
        if($('chk_renov').value=="1"){
            $('renov').style.display='inline'; 
            $( 'cont_tipo' ).setHTML( 'A-' );  
        } 
        
        $('carta_resp1').style.display='none';
        $('carta_resp2').style.display='none'; 
        
        $('lin_tel').style.display='none';
        $('lin_tel2' ).setHTML( '' ); 
        $('lin_tel2').style.display='none';    
    }  
    else{
        $('plazo1').style.display='none';
        $('plazo2').style.display='none';
        
        $('mod1').style.display='none';
        $('mod2').style.display='none';
        
        $('renovacion_check').style.display='none';

        $('docs_form').style.position='relative';
        $('docs_form').style.top='-20px';
        
        $('renov').style.display='none';
        
        $( 'cont_tipo' ).setHTML( 'B-' );
        
        $('carta_resp1').style.display='inline';
        $('carta_resp2').style.display='inline';
        
        $('lin_tel').style.display='inline';
        $('lin_tel2').style.display='inline';
        
        $('lin_tel').style.position='relative';
        $('lin_tel2').style.position='relative';
       
        $('lin_tel').style.top='-22px';
        $('lin_tel2' ).setHTML( "<input name='num_tel' id='num_tel' autocomplete='off'>" ); 
        $('lin_tel2').style.top='-22px';
        
    }

}

/**
 *  Nuevo cliente venta
 */
function nvo_clie_vent(val){

    nom = document.getElementById("clie_nombre");
    tel = document.getElementById("clie_tel");
    rfc = document.getElementById("clie_rfc");
    
    
    if(val=="0"){
                
        nom.value = "";
        tel.value = "";
        rfc.value = "";
        
        nom.removeProperty('readonly');
        tel.removeProperty('readonly');
        rfc.removeProperty('readonly');
        
        $( 'chk_nvo_clie' ).value = '1';
    }  
    else{
        
        nom.readOnly = true;
        tel.readOnly = true;
        rfc.readOnly = true;
        
        $( 'chk_nvo_clie' ).value = '0';
    }

    

}

/**
 *  Guardar datos venta
 */

function save_venta()
{
    
    preLoader(1,'formulario');
    
    $('info_venta_form').submit();

}

//Adjuntar comprobante de pago diferencias vendedor
function send_adj_comp_dif()
{
    
    preLoader(1,'formulario');
    
    $('comp_dif').submit();

}


//Adjuntar recepcion de documentos firmada
function send_rec_doc()
{
    
    preLoader(1,'formulario');
    
    $('rec_doc_form').submit();

}

//Adjuntar factura de equipo
function send_fact_eq()
{
    
    preLoader(1,'formulario');
    preLoader(1, 'contPedidos' );
    
    $('fact_eq_form').submit();

}

//Adjuntar comprobante de pago diferencias sucursal
function send_comp_dif_suc()
{
    
    preLoader(1,'acti_deta_div');
    
    $('comp_dif').submit();

}

/**
*  Tipo pago sucursal
*/
function tip_pag_suc(val){

    
    if(val=="E"){
        $('add_fact').style.display='inline';   
    }  
    else{
        $('add_fact').style.display='none';
    }

}


/**
 *  Abre listado de usuarios
 */
function openUserList()
{
    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' },
            'update'    :   $( 'recuHumaDiv' ),
            'onComplete': function() { showOver( 'recuHumaDiv' ); }
        }
    ).request();
}
/**
 *  
 */
function chkRecuHuma( acti_id )
{
    recuHumaArr = [];
    var json = new Json.Remote( urlProcesos + '&action=chkRecuHuma&acti_id=' +acti_id,
        {   'onComplete'    :   function( jsonObj )
                                {
                                    for( var i = 0; i < jsonObj.recuHumaArr.length; i++ )
                                    {
                                        add_recu_huma( 'user_' + jsonObj.recuHumaArr[i] );
                                    }
                                }
        }
    ).send();
}
/**
 *  Elimina el recurso humano seleccionado de la lista
 */
function removeRecuHuma( id )
{
    $( 'acti_recu_huma' + id ).remove();
    var tmpArr = [];
    for( var i=0; i < recuHumaArr.length; i++ )
    {
        if( id != recuHumaArr[ i ] )
        {
            tmpArr.include( recuHumaArr[ i ] );
        }
    }
    recuHumaArr = tmpArr;
}
/** 
 *  Abre el listado de recursos humanos
 */
function add_recu_huma( user_id )
{
    if( $( 'listaRecuHumaDiv' ) )
    {
        var url = urlProcesos + "&action=get_user_obj&user_id=" + user_id.split("_").pop();
        var json = new Json.Remote( url,
        {   'onComplete' : function( obj )
            {
                if( obj.complete == 'ok' )
                {
                    recuHumaArr.include( obj.user_id );
                    if( $( 'acti_recu_huma' + obj.user_id ) )
                    {
                        $( 'acti_recu_huma' + obj.user_id ).remove();
                    }

                    var div1 = new Element( 'div',
                        {
                            'id'        :   'acti_recu_huma' + obj.user_id,
                            'styles'    :   {   'border-bottom' :   'solid 1px #cdcdcd',
                                                'height'        :   '15px',
                                                'white-space'   :   'nowrap',
                                                'cursor'        :   'pointer'
                            },
                            'events'    :   {
                                'click' :   function()
                                { 
                                    removeRecuHuma( obj.user_id )
                                }
                            }
                        }
                    ).inject( $('listaRecuHumaDiv') );

                    var html =  "<img src='img/themes/" + obj.theme + "/iconos/menos.png' align='top'/>" +
                                obj.user_nombre;
                    $( 'acti_recu_huma' + obj.user_id ).setHTML( html );
                }
                else
                {
                    alert( 'error' );
                }
            }
        }
        ).send();
    }
    else
    {
        $( 'recuHumaDiv' ).remove();
    }
}
/**
 *  Abre el panel de disponibilidad de horarios de los recursos humanos
 */
function chkHorarios()
{
    selectHour = {'stat':0,'h1':0,'h2':0};
    if( $( 'chkHorariosDiv' ) ) $( 'chkHorariosDiv' ).remove();
    var pos = getAvailablePosition();
    if( recuHumaArr.length > 0 )
    {
        var DIV = new Element( 'div',
            {   'id'    :   'chkHorariosDiv',
                'styles'    :   {
                    'position'  : 'absolute',
                    'top'       :   pos.y + 'px',
                    'left'      :   pos.x + 'px'
                }
            }
        ).inject( document.body );
        var aja = new Ajax( urlProcesos,
            {   'method'    :   'get',
                'data'      :   {   'action'    :   'chk_horarios',
                                    'fecha'     :   arguments[0] ? arguments[0] : $( 'acti_fech_fin' ).value,
                                    'usuarios'  :   recuHumaArr 
                                },
                'update'    :   $( 'chkHorariosDiv' ),
                'onComplete'    :   function()
                {
                    showOver( 'chkHorariosDiv' );
                }
            }
        ).request();
    }
    else
    {
        alert( 'Necesita agreagr recursos humanos para checar la disponibilidad de horarios');
    }
}
/**
 * selecciona los horarios en el panel de disponibilidad de recursos humanos
 */
function selectHorarios(obj)
{
    if( obj.freeRow == 'NO' )
    {
        var continua = confirm( 'Algun usuario tiene registrada una tarea en esta hora\ndesea continuar?' );
    }
    else
    {   
        var continua = true;
    }
    if( continua == true )
    {
        selectHour.stat++;
        /**
         *  Primer click asigna hora inicial
         */
        if( selectHour.stat == 1 )
        {
            /**
             *  Regresando color de fondo original
             */
            for( var i = obj.hini.toInt(); i <= obj.hfin.toInt(); i++ )
            {
                var currBG = $( 'trH_' + i ).getStyle( 'background-color' );
                if( currBG != '#f4eaea' )
                {   
                    $( 'trH_' + i ).setStyle( 'background-color' , '#ffffff' );
                }
            }
            selectHour.h1 = obj.hora;
            if( $( 'trH_' + obj.hora ).getStyle( 'background-color' ) != '#f4eaea' )
            {
                $( 'trH_' + obj.hora ).setStyle('background-color' , '#b1bda2');
            }
            $( 'acti_hora_ini_sel' ).value = ( selectHour.h1.toInt() < 10 ? '0' : '' ) + selectHour.h1 + ':00';
            $( 'acti_hora_fin_sel' ).value = ( selectHour.h1.toInt() < 10 ? '0' : '' ) + selectHour.h1 + ':59';
        }
        /**
         *  Segundo click pinta filas de la hora inicial a la hora final
         */
        if( selectHour.stat == 2 )
        {
            if( $( 'trH_' + obj.hora ).getStyle( 'background-color' ) != '#f4eaea' )
            {
                $( 'trH_' + obj.hora ).setStyle('background-color' , '#b1bda2');
            }
            /**
             *  Ordenando las horas seleccionadas de menor a mayor
             */
            if( obj.hora.toInt() < selectHour.h1.toInt() )
            {
                var horaIni =  obj.hora;
                var horaFin =  selectHour.h1;
                selectHour.h1 = horaIni;
                selectHour.h2 = horaFin;
            }
            else
            {
                selectHour.h2 = obj.hora;
            }
            /**
             *  Pintando filas seleccionadas
             */
            var free = true;
            for( var i = selectHour.h1.toInt(); i <= selectHour.h2.toInt(); i++ )
            {
                var currBG = $( 'trH_' + i ).getStyle( 'background-color' );
                if( currBG != '#f4eaea' )
                {   
                    $( 'trH_' + i ).setStyle( 'background-color' , '#d4e5d0' );
                }
                free = ( $('trH_' + i ).hasClass( 'ocupada' ) ? false : free );
            }
            if( free == false )
            {
                alert( 'Selecciono un horario con algunas horas ocupadas por otros usuarios' );
            }
            $( 'acti_hora_ini_sel' ).value = ( selectHour.h1.toInt() < 10 ? '0' : '' ) + selectHour.h1 + ':00';
            $( 'acti_hora_fin_sel' ).value = ( selectHour.h2.toInt() < 10 ? '0' : '' ) + selectHour.h2 + ':59';
            selectHour = {'stat':0,'h1':0,'h2':0};
        }
    }
}
/**
 *  asigna el horario y la fecha desde el panel de disponibilidad de recursos humanos
 */
function setHorario()
{
    if( $('acti_fech_fin') && $('acti_fech_fin_sel').value != '' ) $('acti_fech_fin').value=$('acti_fech_fin_sel').value;
    if( $('acti_hora_ini') && $('acti_hora_ini_sel').value != '' ) $('acti_hora_ini').value=$('acti_hora_ini_sel').value;
    if( $('acti_hora_fin') && $('acti_hora_fin_sel').value != '' ) $('acti_hora_fin').value=$('acti_hora_fin_sel').value;
    /**
     *  Si no se selecciona hora final toma hora inicial + ':59' para la hora final
     */
    if( $('acti_hora_fin_sel').value == '' )
    {
        if( selectHour.h1 )
        {
            $('acti_hora_ini').value = ( selectHour.h1.toInt() < 10 ? '0' : '' ) + selectHour.h1 + ':00';
            if( selectHour.h2.toInt() <= 0 )
            {
                $('acti_hora_fin').value = ( selectHour.h1.toInt() < 10 ? '0' : '' ) + selectHour.h1 + ':59';
            }
            else
            {
                $('acti_hora_fin').value = ( selectHour.h2.toInt() < 10 ? '0' : '' ) + selectHour.h2 + ':59';
            }
        }
    }
    $('chkHorariosDiv').remove(); 
}
/**
 *  Monitor de usuarios
 */
function userMonitor()
{
    $( 'userMonitorDiv' ).setStyles(
        {
            'display'   :   'block',
            'width'     :   '250px',
            'height'    :   '610px',
            'overflow'  :   'hidden'
        }
    );
    var ajx = new Ajax( urlProcesos,
        {   'method'    :   'get',
            'data'      :   { 'action' : 'get_user_monitor'},
            'update'    :   $('userMonitorDiv')
        }
    ).request();
}
/**
 * abre una nueva ventana con la vista del usuario seleccionado del monitor
 */
function openUserMonitor( sid )
{
    window.open( "index.php?SID=" + sid , "", "width=1150, height=620" );
}
/**
 *  Buscando posiciones disponibles
 */
function getAvailablePosition()
{
    var ini = initPosition();
    var available = ini;
    var cant = ventanasEmergentes.length;
    var margen = rango * cant;
    var margenY =   ini.y + margen;
    var margenX =   ini.x + margen;
    for( var i = 0; i < cant; i++ )
    {   
        if( $( ventanasEmergentes[ i ] ) )
        {
            var elPos   =   $( ventanasEmergentes[ i ] ).getPosition();
            var elX     =   elPos.x.toInt();
            var elY     =   elPos.y.toInt();
            //if( elX > ( ini.x - rango ) && elX < margenX )
            //{
                available.x += rango;
            //}
            //if( elY > ( ini.y - rango ) && elY < margenY  )
            //{
                available.y += rango;
            //}
        }
        
    }
    return available;
}
/**
 *  Ordena ventanas emergentes abiertas en carcada
 */
function setCascade()
{
    var ini = initPosition();
    var win = ventanasEmergentes;
    var cant = 1;
    for( var i = 0; i < win.length; i++ )
    {
        if( $( win[ i ] ) )
        {
            $( win[ i ] ).setStyles(
                {   'position'  :   'absolute',
                    'top'       :   ( ini.y + ( rango * cant ) ) + 'px',
                    'left'      :   ( ini.x + ( rango * cant ) ) + 'px'
                }
            );
            cant++;
        }
    }
}
/**
 *  cierra todas las ventanas emergentes
 */
function closeAllWindows()
{
    for( var i = 0; i < ventanasEmergentes.length; i++ )
    {
        if( $( ventanasEmergentes[ i ] ) )
        {
            $( ventanasEmergentes[ i ] ).remove();
        }
    }
}

/**
 *
 */
function closeFinder()
{
    if( $('findClieLstDiv') )
    {
        $('findClieLstDiv').remove()
    }
}
function cancelFind()
{  
    if( $( 'findClieLstDiv') )
    {
        setTimeout( "closeFinder()",1000);
    }
}
/***
 *  Buscar client por...
 */
function findClie( obj )
{
    
    if( $( 'findClieLstDiv' ) ) $( 'findClieLstDiv' ).remove();
    if( obj.value.length > 2 )
    {
        new Element( 'div', { 'id' : 'findClieLstDiv' } ).inject( document.body );
        $( 'findClieLstDiv' ).setStyles(
            {   'position'  :   'absolute',
                'top'       :   ( $( obj.id ).getPosition().y.toInt() + 15 ) + 'px',
                'left'      :   $( obj.id ).getPosition().x,
                'background-color'  :   '#ffffff',
                'border'    :   'solid 2px #cdcdcd'
            }
        );
        if( !obj.functionName ) obj.functionName = 'alert';
        obj.action = 'find_clie_by';
        new Ajax( urlProcesos,
            {   'method'    :   'get',
                'data'      :   obj,
                'update'    :   $( 'findClieLstDiv' ),
                'evalScripts'   :   true
            }
        ).request();
    }
}


/*
Property: numberFormat
Format a number with grouped thousands.

Arguments:
decimals, optional - integer, number of decimal percision; default, 2
dec_point, optional - string, decimal point notation; default, '.'
thousands_sep, optional - string, grouped thousands notation; default, ','
                            
Returns:
a formatted version of number.

Example:
>(36432.556).numberFormat()  // returns 36,432.56
>(36432.556).numberFormat(2, '.', ',')  // returns 36,432.56
*/
Number.extend(
{     
    numberFormat : function(decimals, dec_point, thousands_sep) 
    {
        var decimals = Math.abs(decimals) + 1 ? decimals : 2;
        var dec_point = dec_point || '.';
        var thousands_sep = thousands_sep || ',';
        var matches = /(-)?(\d+)(\.\d+)?/.exec(this + ''); // returns matches[1] as sign, matches[2] as numbers and matches[2] as decimals
        var remainder = matches[2].length > 3 ? matches[2].length % 3 : 0;
        return (matches[1] ? matches[1] : '') + 
        (remainder ? matches[2].substr(0, remainder) + thousands_sep : '') +
        matches[2].substr(remainder).replace(/(\d{3})(?=\d)/g, "$1" + thousands_sep) + 
        (decimals ? dec_point + (+matches[3] || 0).toFixed(decimals).substr(2) : '');
    }
});

