var uri = top.location.toString().split('/')[4].split('.')[0];
var CurrentPage='porFecha';
function TRAD_nav(start){
    var param = new Array();
    param['timestamp'] = $('#TimeStamp').attr('value');
    param['userID'] = uri.split('-')[1];
    param['op'] = $("#type").attr("value");
    param['start'] = start;
    param['limit'] = 10;
    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['limit'] = 1000;
    param['type'] = $('#type').attr('value');
    param['isYear'] = $('#isYear').attr('value');
    var single = $('#single').attr('value');
    var all = $('#all').attr('value');
    if (single == 1) {
        param['single'] = single;
        param['all'] = 0;
    }
    if (all == 1) {
        param['all'] = all;
        param['single'] = 0;
    }
    //alert[param['event']];
    xajax_resumenHistorial(param);
    
}

function updateTableLinks(){
    $('table.tablesorter tr').hover(function(){
        $(this).css('cursor', 'pointer');
    });
}

function updateContent(id){
    // var uri = top.location.toString().split('/')[4].split('.')[0];
    $("." + id).tablesorter({
        widgets: ['zebra']
    });
    
}

/*new functions based on jquery*/
$(function(){
    // var uri = top.location.toString().split('/')[4].split('.')[0];
    var single = $('#single').attr('value');
    var all = $('#all').attr('value');
    var param = new Array();
    param['limit'] = 10;
    $("table").tablesorter({
        widthFixed: true,
        widgets: ['zebra']
    });
    $('table.tablesorter tr').hover(function(){
        $(this).css('cursor', 'pointer');
    });
    $('#userContainer > a').css('color', 'white');
    /**
     * Historial de pronosticos
     */
    $('#allPicks').click(function(){
        disableContent();
        if(CurrentPage=='porFecha'){
            param['op'] = 0;
            //param['limit'] = 100;
            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'] = 1;
            param['single'] = 0;
            param['fechaini'] = $('#fecha-inicio').attr('value');
            param['fechafin'] = $('#fecha-final').attr('value');
            param['isYear'] = $('#isYear').attr('value');
            param['userID'] = uri.split('-')[1];
            //alert(param['event']);
            xajax_filtersHistorial(param);
        }else{
            loadTickets();
        }
    })
    $('#picksUser').click(function(){
        disableContent();
        if(CurrentPage=='porFecha'){
            param['userID'] = uri.split('-')[1];
            param['op'] = 1;
            //  param['limit'] = 100;
            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'] = 1;
            param['all'] = 0;
            param['fechaini'] = $('#fecha-inicio').attr('value');
            param['fechafin'] = $('#fecha-final').attr('value');
            param['isYear'] = $('#isYear').attr('value');
            xajax_filtersHistorial(param);
        }else{
            loadTickets();
        }
    })
    $('#picksLeague').click(function(){
        disableContent();
        if(CurrentPage=='porFecha'){
            param['op'] = 2;
            // param['limit'] = 100;
            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['isYear'] = $('#isYear').attr('value');
            xajax_filtersHistorial(param);
        }else{
            loadTickets();
        }
    })
    $('#datePicks').click(function(){
        disableContent();
        if(CurrentPage=='porFecha'){
            param['fechaini'] = $('#fecha-inicio').attr('value');
            param['fechafin'] = $('#fecha-final').attr('value');
            //  param['limit'] = 100;
            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'] = 5;
        
            param['isYear'] = $('#isYear').attr('value');
            single = $('#single').attr('value');
            all = $('#all').attr('value');
            if (single == 1) {
                param['single'] = single;
                param['all'] = 0;
            }
            if (all == 1) {
                param['all'] = all;
                param['single'] = 0;
            }
		
		
            ///////////////////////////
            /*
		 var fecha = this.id.split('-');
        param['timestamp'] = fecha[2];
        
        if (uri.split('-')[1] != 'undefined') {
            param['userID'] = uri.split('-')[1];
        }
        else {
            param['userID'] = 0;
        }
        single = $('#single').attr('value');
        all = $('#all').attr('value');
        if (single == 1) {
            param['single'] = single;
            param['all'] = 0;
        }
        if (all == 1) {
            param['all'] = all;
            param['single'] = 0;
        }
        
        document.location.hash = 'DayInfo';
        
        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');
        //alert( param['event']);
        xajax_resumenHistorial(param);
		*/
		
            ///////////////////////
            xajax_filtersHistorial(param);
        }else{
            loadTickets();
        }
    })
    $('.datepicker').datepicker({
        dayNames: ['Domingo', 'Lunes', 'Martes', 'Miercoles', 'Jueves', 'Viernes', 'Sabado'],
        showButtonPanel: true,
        changeMonth: true,
        changeYear: true
    })/*.change(function(){alert(this.value);})*/;
    $('#ligaBox').change(function(){
        disableContent();
        if(CurrentPage=='porFecha'){
            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'] = 1000;
            param['type'] = $('#type').attr('value');
            param['isYear'] = $('#isYear').attr('value');
            single = $('#single').attr('value');
            all = $('#all').attr('value');
            if (single == 1) {
                param['single'] = single;
                param['all'] = 0;
            }
            if (all == 1) {
                param['all'] = all;
                param['single'] = 0;
            }
            xajax_filtersHistorial(param);
        }else{
            loadTickets();
        }
    });
    $('#this-week').attr('checked', 'true').click(function(){
        disableContent();
        if(CurrentPage=='porFecha'){
            param['type'] = 1;
            param['userID'] = uri.split('-')[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['isYear'] = 0;
            single = $('#single').attr('value');
            all = $('#all').attr('value');
            if (single == 1) {
                param['single'] = single;
                param['all'] = 0;
            }
            if (all == 1) {
                param['all'] = all;
                param['single'] = 0;
            }
        
            xajax_filtersHistorial(param);
        }else{
            loadTickets();
        }
    });
    $('#this-month').click(function(){
        disableContent();
        if(CurrentPage=='porFecha'){
            param['type'] = 3;
            param['userID'] = uri.split('-')[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['isYear'] = 0;
            single = $('#single').attr('value');
            all = $('#all').attr('value');
            if (single == 1) {
                param['single'] = single;
                param['all'] = 0;
            }
            if (all == 1) {
                param['all'] = all;
                param['single'] = 0;
            }
            xajax_filtersHistorial(param);
        }else{
            loadTickets();
        }
    });
    $('#this-year').click(function(){
        disableContent();
        if(CurrentPage=='porFecha'){
            param['type'] = 4;
            param['userID'] = uri.split('-')[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['isYear'] = 1;
            single = $('#single').attr('value');
            all = $('#all').attr('value');
            if (single == 1) {
                param['single'] = single;
                param['all'] = 0;
            }
            if (all == 1) {
                param['all'] = all;
                param['single'] = 0;
            }
            xajax_filtersHistorial(param);
        }else{
            loadTickets();
        }
    });
    $('#last-month').click(function(){
        disableContent();
        if(CurrentPage=='porFecha'){
            param['type'] = 2;
            param['userID'] = uri.split('-')[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['isYear'] = 0;
            single = $('#single').attr('value');
            all = $('#all').attr('value');
            if (single == 1) {
                param['single'] = single;
                param['all'] = 0;
            }
            if (all == 1) {
                param['all'] = all;
                param['single'] = 0;
            }
            xajax_filtersHistorial(param);
        }else{
            loadTickets();
        }
    });
    
    //Back Hack Ajax	
        
    $('.userHistoryInfo').live('click', (function(){
        disableContent();
        var fecha = this.id.split('-');
        param['timestamp'] = fecha[2];
        
        if (uri.split('-')[1] != 'undefined') {
            param['userID'] = uri.split('-')[1];
        }
        else {
            param['userID'] = 0;
        }
        single = $('#single').attr('value');
        all = $('#all').attr('value');
        if (single == 1) {
            param['single'] = single;
            param['all'] = 0;
        }
        if (all == 1) {
            param['all'] = all;
            param['single'] = 0;
        }
        
        document.location.hash = 'DayInfo';
        
        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');
        //alert( param['event']);
        xajax_resumenHistorial(param);
    //top.location = '/pronosticos/detallesTickets+timestamp-'+fecha[2]+'.html';
    }));
    
    $('.selectTipos').change(function(){
        disableContent();
        if(CurrentPage=='porFecha'){
            param['userID'] = uri.split('-')[1];
        
            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');
            single = $('#single').attr('value');
            all = $('#all').attr('value');
            if (single == 1) {
                param['single'] = single;
                param['all'] = 0;
            }
            if (all == 1) {
                param['all'] = all;
                param['single'] = 0;
            }
            xajax_filtersHistorial(param);
        }else{
            loadTickets();
        }
        
    });
    $('.selectEventos').live('change', function(){
        //loadResumen();
        disableContent();
        if(CurrentPage=='porFecha'){
            param['userID'] = uri.split('-')[1];
        
            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');
            single = $('#single').attr('value');
            all = $('#all').attr('value');
            if (single == 1) {
                param['single'] = single;
                param['all'] = 0;
            }
            if (all == 1) {
                param['all'] = all;
                param['single'] = 0;
            }
            xajax_filtersHistorial(param);
        }else{
            loadTickets();
        }
    });
    $('.estado-filter').change(function(){
        disableContent();
        if(CurrentPage=='porFecha'){
            param['userID'] = uri.split('-')[1];
        
            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');
            single = $('#single').attr('value');
            all = $('#all').attr('value');
            if (single == 1) {
                param['single'] = single;
                param['all'] = 0;
            }
            if (all == 1) {
                param['all'] = all;
                param['single'] = 0;
            }
            xajax_filtersHistorial(param);
        }else{
            loadTickets();
        }
    });
    /*
    $('.activbgd').click(function(){
        // window.location = '/register.php';
        xajax_joinAllLeagues();
        $(this).hide();
    });*/
    $('.acced').click(function(){
        window.location = '/user.php?xoops_redirect=/modules/pronosticos/ligas_historial.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');
        }
    });*/
});

function lookup(inputString){
    if (inputString.length == 0) {
        // Hide the suggestion box.
        $('#suggestions').hide();
    }
    else {
        $.post("/modules/pronosticos/lookup_users.php", {
            queryString: "" + inputString + ""
        }, function(data){
            if (data.length > 0) {
                $('#suggestions').show();
                $('#autoSuggestionsList').html(data);
            }
        });
    }
    setTimeout("clearSug();", 15000);
} // lookup
function clearSug(){
    $('#suggestions').hide();
    $('#inputString').val("");
}

function fill(thisValue){
    $('#inputString').val(thisValue);
    setTimeout("$('#suggestions').hide();", 200);
}

var currentAnchor = "";

function checkAnchor(){
    if (currentAnchor != document.location.hash) {
        currentAnchor = document.location.hash;
        
        //alert(document.getElementById('last-month').checked)
        if (currentAnchor != "#DayInfo") 
            loadResumen();
    }
}

$().ready(function(){
    setInterval("checkAnchor()", 300);
});

function loadResumen(){
    disableContent();
    param = new Array();
    param['isYear'] = 0;
    if (document.getElementById('last-month').checked) 
        param['type'] = 2;
    else
    if (document.getElementById('this-week').checked)
        param['type'] = 1;
    else
    if (document.getElementById('this-month').checked)
        param['type'] = 3;
    else
    if (document.getElementById('this-year').checked) {
        param['type'] = 4;
        param['isYear'] = 1;
    }
    
    
    param['userID'] = uri.split('-')[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;
    
       
    single = $('#single').attr('value');
    
    all = $('#all').attr('value');
    
    if (single == 1) {
    
        param['single'] = single;
        
        param['all'] = 0;
        
    }
    
    if (all == 1) {
    
        param['all'] = all;
        
        param['single'] = 0;
        
    }
    
    
    
    xajax_filtersHistorial(param);
    
}
function loadTickets(start){
    disableContent();
    CurrentPage='Todos';
    param = new Array();
    param['isYear'] = 0;
    if (document.getElementById('last-month').checked)
        param['type'] = 2;
    else
    if (document.getElementById('this-week').checked)
        param['type'] = 1;
    else
    if (document.getElementById('this-month').checked)
        param['type'] = 3;
    else
    if (document.getElementById('this-year').checked) {
        param['type'] = 4;
       
    }

    param['start']=start;
    param['userID'] = uri.split('-')[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;


    single = $('#single').attr('value');

    all = $('#all').attr('value');

    if (single == 1) {

        param['single'] = single;

        param['all'] = 0;

    }

    if (all == 1) {

        param['all'] = all;

        param['single'] = 0;

    }



    xajax_getAllTickets(param);
//top.location = '/pronosticos/detallesTickets+timestamp-'+fecha[2]+'.html';
}
function disableContent(){
    x=$('#pronosticos_content').offset().left;
    y=$('#pronosticos_content').offset().top;    
        
    $('#loadimg').css('left', x+$('#pronosticos_content').width()/2-15);
    $('#loadimg').css('top', y+$('#pronosticos_content').height()/2-15);
    $('#loadimg').css('display', 'block');
    //$('#pronosticos_content').attr('disabled', true);
    $('#pronosticos_content').fadeTo( 'slow',0.33);
    
}
function enableContent(){
    $('#loadimg').fadeOut();
    $('#pronosticos_content').fadeTo('slow', 1.0);
    $('#pronosticos_content').removeAttr('disabled');
    $('#loadimg').css('display', 'none');
}

