var lastOldper=0;
function showOldPer(per,def){
    if(lastOldper!=0)
        document.getElementById(lastOldper).style.display='none';
    else
        document.getElementById(def).style.display='none';
        
    document.getElementById(per).style.display='block';
    //document.getElementById('oldpersel').style.visibility='none';
    lastOldper=per;
}
function TRAD_nav(start){
    var param = new Array();
    param['op'] = $("#op").attr("value");
    param['start'] = start;
    param['limit'] = 10;
    xajax_historialPronosticos(param);

}
function updateContent(id){
    // var uri = top.location.toString().split('/')[4].split('.')[0];
    $("."+id)
    .tablesorter({
        widgets: ['zebra']
    })
    .tablesorterPager({
        container: $("#pager")
    });
  
}
/*new functions based on jquery*/
$(function() {
    var uri = top.location.toString().split('/')[4].split('.')[0];
    $("table")
    .tablesorter({
        widthFixed: true,
        widgets: ['zebra']
    })    ;
  
    /**
     * Historial de pronosticos
     */

    /* $('#allPicks').click(function(){
        var param = new Array();
        param['op'] = 0;
        param['limit'] = 10;
        param['own'] = false;
        param['event'] = document.getElementById('selectEventos').
        options[document.getElementById('selectEventos').selectedIndex].value;
        param['betype'] = document.getElementById('selectTipos').
        options[document.getElementById('selectTipos').selectedIndex].value;
        param['estado'] = document.getElementById('estado-filter').
        options[document.getElementById('estado-filter').selectedIndex].value;
        param['type'] = $('#type').attr('value');
        param['all'] = true;
        xajax_filtersHistorial(param);
       
    })
    $('#picksUser').click(function(){
        var param = new Array();
        param['op'] = 1;
        param['limit'] = 10;
        param['own'] = 1;
        param['event'] = document.getElementById('selectEventos').
        options[document.getElementById('selectEventos').selectedIndex].value;
        param['betype'] = document.getElementById('selectTipos').
        options[document.getElementById('selectTipos').selectedIndex].value;
        param['estado'] = document.getElementById('estado-filter').
        options[document.getElementById('estado-filter').selectedIndex].value;
        param['type'] = $('#type').attr('value');
        param['single'] = true;
        //xajax_historialPronosticos(param);
        xajax_filtersHistorial(param);
    })
    $('#picksLeague').click(function(){
        var param = new Array();
        param['op'] = 2;
        param['limit'] = 10;
        param['own'] = false;
        param['event'] = document.getElementById('selectEventos').
        options[document.getElementById('selectEventos').selectedIndex].value;
        param['betype'] = document.getElementById('selectTipos').
        options[document.getElementById('selectTipos').selectedIndex].value;
        param['estado'] = document.getElementById('estado-filter').
        options[document.getElementById('estado-filter').selectedIndex].value;
        param['type'] = $('#type').attr('value');

        //xajax_historialPronosticos(param);
        xajax_filtersHistorial(param);
    })
    $('#datePicks').click(function(){
        var param = new Array();
        param['fechaini'] = $('#fecha-inicio').attr('value');
        param['fechafin'] = $('#fecha-final').attr('value');
        param['limit'] = 10;
        param['op'] = 3;
        param['own'] = false;
        param['event'] = document.getElementById('selectEventos').
        options[document.getElementById('selectEventos').selectedIndex].value;
        param['betype'] = document.getElementById('selectTipos').
        options[document.getElementById('selectTipos').selectedIndex].value;
        param['estado'] = document.getElementById('estado-filter').
        options[document.getElementById('estado-filter').selectedIndex].value;
        param['type'] = $('#type').attr('value');
        param['ligaID'] = document.getElementById('ligaBox').
        options[document.getElementById('ligaBox').selectedIndex].value;
        //xajax_historialPronosticos(param);
        xajax_filtersHistorial(param);
    })
    $('.datepicker').datepicker({
        dayNames: ['Domingo', 'Lunes', 'Martes', 'Miercoles', 'Jueves', 'Viernes', 'Sabado'],
        showButtonPanel: true,
        changeMonth: true,
        changeYear: true
    })/*.change(function(){alert(this.value);})*/;

    /*$('#ligaBox').change(
        function(){
            var param = new Array();
            param['ligaID'] = this.value;
            param['event'] = document.getElementById('selectEventos').
            options[document.getElementById('selectEventos').selectedIndex].value;
            param['betype'] = document.getElementById('selectTipos').
            options[document.getElementById('selectTipos').selectedIndex].value;
            param['estado'] = document.getElementById('estado-filter').
            options[document.getElementById('estado-filter').selectedIndex].value;
            param['op'] = 2;
            param['start'] = 0;
            param['limit'] = 10;
            param['type'] = $('#type').attr('value');
            param['isYear'] = 0;
            //xajax_historialPronosticos(param);
            xajax_filtersHistorial(param);
        }
        );

    $('#this-week').click(function(){
        var param = new Array();
        param['type'] = 1;
        param['userID'] = uri.split('-')[1];
        param['ligaID'] = document.getElementById('ligaBox').
        options[document.getElementById('ligaBox').selectedIndex].value;
        param['event'] = document.getElementById('selectEventos').
        options[document.getElementById('selectEventos').selectedIndex].value;
        param['betype'] = document.getElementById('selectTipos').
        options[document.getElementById('selectTipos').selectedIndex].value;
        param['estado'] = document.getElementById('estado-filter').
        options[document.getElementById('estado-filter').selectedIndex].value;
        param['isYear'] = 0;
        xajax_filtersHistorial(param);
    });
    $('#this-month').click(function(){
        var param = new Array();
        param['type'] = 3;
        param['userID'] = uri.split('-')[1];
        param['ligaID'] = document.getElementById('ligaBox').
        options[document.getElementById('ligaBox').selectedIndex].value;
        param['event'] = document.getElementById('selectEventos').
        options[document.getElementById('selectEventos').selectedIndex].value;
        param['betype'] = document.getElementById('selectTipos').
        options[document.getElementById('selectTipos').selectedIndex].value;
        param['estado'] = document.getElementById('estado-filter').
        options[document.getElementById('estado-filter').selectedIndex].value;
        param['isYear'] = 0;
        xajax_filtersHistorial(param);
    });
    $('#this-year').click(function(){
        var param = new Array();
        param['type'] = 4;
        param['userID'] = uri.split('-')[1];
        param['ligaID'] = document.getElementById('ligaBox').
        options[document.getElementById('ligaBox').selectedIndex].value;
        param['event'] = document.getElementById('selectEventos').
        options[document.getElementById('selectEventos').selectedIndex].value;
        param['betype'] = document.getElementById('selectTipos').
        options[document.getElementById('selectTipos').selectedIndex].value;
        param['estado'] = document.getElementById('estado-filter').
        options[document.getElementById('estado-filter').selectedIndex].value;
        param['isYear'] = 1;
        xajax_filtersHistorial(param);
    });
    $('#last-month').click(function(){
        var param = new Array();
        param['type'] = 2;
        param['userID'] = uri.split('-')[1];
        param['ligaID'] = document.getElementById('ligaBox').
        options[document.getElementById('ligaBox').selectedIndex].value;
        param['event'] = document.getElementById('selectEventos').
        options[document.getElementById('selectEventos').selectedIndex].value;
        param['betype'] = document.getElementById('selectTipos').
        options[document.getElementById('selectTipos').selectedIndex].value;
        param['estado'] = document.getElementById('estado-filter').
        options[document.getElementById('estado-filter').selectedIndex].value;
        param['isYear'] = 0;
        xajax_filtersHistorial(param);
    });
    $('.userHistoryInfo').live('click',(function(){
        
        var fecha = this.id.split('-');
        var param = new Array();
        if (uri.split('-')[1] != 'undefined'){
            param['userID'] = uri.split('-')[1];
        }
        else{
            param['userID'] = 0;
        }
        var single = $('#single').attr('value');
        var all = $('#all').attr('value');
        if (single == 1){
            param['single'] = 1;
        }
        if (all == 1){
            param['all'] = 1;
        }
        param['timestamp'] = fecha[2];
        param['ligaID'] = document.getElementById('ligaBox').
        options[document.getElementById('ligaBox').selectedIndex].value;
        param['event'] = document.getElementById('selectEventos').
        options[document.getElementById('selectEventos').selectedIndex].value;
        param['betype'] = document.getElementById('selectTipos').
        options[document.getElementById('selectTipos').selectedIndex].value;
        param['estado'] = document.getElementById('estado-filter').
        options[document.getElementById('estado-filter').selectedIndex].value;
        param['type'] = $('#type').attr('value');
        param['isYear'] = $('#isYear').attr('value');
        
        xajax_resumenHistorial (param);
    //top.location = '/pronosticos/detallesTickets+timestamp-'+fecha[2]+'.html';
    }));
    $('.selectTipos').change(function(){
        var param = new Array();
        param['userID'] = uri.split('-')[1];
        param['ligaID'] = document.getElementById('ligaBox').
        options[document.getElementById('ligaBox').selectedIndex].value;
        param['type'] = $('#type').attr('value');
        param['betype'] = this.value;
        param['event'] = document.getElementById('selectEventos').
        options[document.getElementById('selectEventos').selectedIndex].value;
        param['estado'] = document.getElementById('estado-filter').
        options[document.getElementById('estado-filter').selectedIndex].value;
        param['type'] = $('#type').attr('value');
        param['isYear'] = $('#isYear').attr('value');

        xajax_filtersHistorial(param);

    });
    $('.selectEventos').live('change',function(){
        var param = new Array();
        param['userID'] = uri.split('-')[1];
        param['ligaID'] = document.getElementById('ligaBox').
        options[document.getElementById('ligaBox').selectedIndex].value;
        param['type'] = $('#type').attr('value');
        param['event'] = this.value;
        param['betype'] = document.getElementById('selectTipos').
        options[document.getElementById('selectTipos').selectedIndex].value;
        param['estado'] = document.getElementById('estado-filter').
        options[document.getElementById('estado-filter').selectedIndex].value;
        param['isYear'] = $('#isYear').attr('value');
        xajax_filtersHistorial(param);
    });
    $('.estado-filter').change(function(){
        var param = new Array();
        param['userID'] = uri.split('-')[1];
        param['ligaID'] = document.getElementById('ligaBox').
        options[document.getElementById('ligaBox').selectedIndex].value;
        param['type'] = $('#type').attr('value');
        param['estado'] = this.value;
        param['betype'] = document.getElementById('selectTipos').
        options[document.getElementById('selectTipos').selectedIndex].value;
        param['event'] = document.getElementById('selectEventos').
        options[document.getElementById('selectEventos').selectedIndex].value;
        param['isYear'] = $('#isYear').attr('value');
        xajax_filtersHistorial(param);
    });*/
	
    /*
    $('.activbgd').click(function(){
        // window.location = '/register.php';
        xajax_joinAllLeagues();
        $(this).hide();
    });*/
	
    $('.acced').click(function(){
        window.location = '/user.php?xoops_redirect=/modules/pronosticos/ligas_premios.php';
    });
    
    /*$('.joinAll').click(function(){
        xajax_joinAllLeagues();
        $(this).hide();
        var log = $('#logging').attr('value');
        if (log == 1){
            $('div.LigaCont ul li > img').
            attr('src', '/modules/pronosticos/images/img1B.gif').
            attr('class', 'disableAccount');
        }
    });*/
    $('strong#userContainer > a').css('color','white');
});

var loaded=false;
$(document).ready(function(){
    /*$('#tabs div').hide(); // Hide all divs
    $('#tabs div:first').show(); // Show the first div
    $('#tabs ul li:first').addClass('active'); // Set the class of the first link to active
    $('#tabs ul li a').click(function(){ //When any link is clicked
        $('#tabs ul li').removeClass('active'); // Remove active class from all links
        $(this).parent().addClass('active'); //Set clicked link class to active
        var currentTab = $(this).attr('href'); // Set variable currentTab to value of href attribute of clicked link
        $('#tabs div').hide(); // Hide all divs
        $(currentTab).show(); // Show div with id equal to variable currentTab
        return false;
    });
     *
      ,
         function (){
             //alert(ui.panel.id)
               $('#picktabs').tabs( "enable" , '#'+ui.panel.id )
         }
     */
    $('#picktabs').tabs({     
        select:function(event,ui){
            ancla=ui.tab;
            arr=ancla.toString().split('#')
            tabid=arr[1];
            arr=tabid.split('-');
            per=arr[1];
            //alert(per)
            if(!loaded){
                disableContent('picktabs')
                $('#'+tabid).load('/modules/pronosticos/include/get_777.php?per='+per,
                    function (){                        
                        loaded=true;                        
                        $('#picktabs').tabs( "select" ,  '#'+ui.panel.id )

                        enableContent('picktabs')
                    });
            }else{
                loaded=false;
                return true;
            }
            return false;
        // return false;
        // $('#'+tabid).html("holaaaa");
        //alert(ui.toString());
        }
    });
    $('#mes_select').change(function() {
        /* $.get('/modules/pronosticos/include/get_777.php?mes='+$(this).val(),function(data){
            alert( data );
        });*/
        persarr=$(this).val().split('-');
        i=0;
        $('#picktabs').children("ul").each(function() {
            $(this).children("li").each(function() {
                $(this).children("a").each(function() {
                    //     alert('x')
                    $(this).attr("href",'#tabs-'+persarr[i]);
                    i++;
                })
            })
        });
        i=0;
        $('#picktabs').children("div").each(function() {
            $(this).attr("id",'tabs-'+persarr[i]);
            i++;
        })
        if($('#picktabs').tabs('option', 'selected')==0){
            disableContent('picktabs')
            $('#'+'tabs-'+persarr[0]).load('/modules/pronosticos/include/get_777.php?per='+persarr[0],
                function (){
                    //loaded=true;
                    enableContent('picktabs')
                });
        }else{
            $('#picktabs').tabs( "select" , 0 )
        }
    //alert($('#mes_select').val());
    });
});
var openpick=null;
function show_pick(pid){
    if(openpick!=null){
        $('#pick'+openpick).hide('slow');
        $('#pimg'+openpick).attr('src','/general_css_file/images/minusd_sign2.gif');
    }
    if(openpick!=pid){
        $('#pick'+pid).show('slow');
        $('#pimg'+pid).attr('src','/general_css_file/images/masd_sign2.gif');
        openpick=pid;
    }else
        openpick=null;
}

function disableContent(contentid){
    x=$('#'+contentid).offset().left;    
    y=$('#'+contentid).offset().top;

    $('#loadimg').css('left', x+$('#'+contentid).width()/2-15);
    $('#loadimg').css('top', y+$('#'+contentid).height()/2-15);
    $('#loadimg').css('display', 'block');
    //alert(x+','+$('#'+contentid).width()/2-15)
    $('#'+contentid).fadeTo( 'slow',0.33);

}
function enableContent(contentid){
    //$('#loadimg').fadeOut();
    $('#'+contentid).fadeTo('slow', 1);
    $('#'+contentid).removeAttr('disabled');
    $('#loadimg').css('display', 'none');
}
