var CurrPage = 1;
function TRAD_nav(start){
    var param = new Array();
    
    if (start != -1) {
        param['start'] = start;
        CurrPage = start;
    }
    else {
        param['start'] = CurrPage;
    }
    
    
    maspuntos =document.getElementById('maspuntos').value;
	var ele = document.forms['filtrosform'].elements;
	var maspuntos = ele['maspuntos'].value;
    if (maspuntos != null && maspuntos != '') {
        if (isNaN(maspuntos) || maspuntos < 0) {
            alert('Numero de puntos incorrecto');
            document.getElementById('maspuntos').value = "";
            return;
        }
    }
	
	
    param['maspuntos'] = maspuntos;
    
    param['country'] = document.getElementById('countrysel').options[document.getElementById('countrysel').selectedIndex].value;
    
    param['month'] = document.getElementById('monthsel').options[document.getElementById('monthsel').selectedIndex].value;
    param['year'] = document.getElementById('yearsel').options[document.getElementById('yearsel').selectedIndex].value;
    clearSug();
    
    xajax_pagedRankings(param);
    
}

function nav_user(uid){
    var param = new Array();
    
    param['start'] = 0;
    
    param['uid'] = uid;
    param['month'] = document.getElementById('monthsel').options[document.getElementById('monthsel').selectedIndex].value;
    param['year'] = document.getElementById('yearsel').options[document.getElementById('yearsel').selectedIndex].value;
    xajax_pagedRankings(param);
}

function updateContent(classname){
    $("." + classname).tablesorter({
        widgets: ['zebra']
    
    });
    
}

/**
 *rankear ligas
 */
function rankings(value){
    xajax_rankings(value);
    return false;
}

/*new functions based on jquery*/
$(function(){
    var param = new Array();
    $("table").tablesorter({
        widthFixed: true,
        widgets: ['zebra']
    });
    $(".ligas_validate").click(function(){
        xajax_validatePronosticos();
        
    });
    /**
     * Rankings de pronosticos
     */
    $('.generic').click(function(){
        var param = new Array();
        param['ligaID'] = 0;
        param['op'] = 1;
        xajax_visualizeRankings(param);
    })
    $('#ligaBox').change(function(){
        var param = new Array();
        
        param['ligaID'] = this.value;
        var uri = top.location.toString().split('/')[4].split('.')[0];
        if (uri == 'ligas_historial') {
            param['op'] = 2;
            param['start'] = 0;
            param['limit'] = 10;
            xajax_historialPronosticos(param);
        }
        else 
            if (uri == 'ligas_rankings') {
                param['op'] = 0;
                xajax_visualizeRankings(param);
            }
    });
    $('.filled_ranking').click(function(){
        xajax_rankear();
    });
    $('li#this-month').click(function(){
        param['op'] = 2;
        param['ligaID'] = param['ligaID'] = document.getElementById('ligaBox').options[document.getElementById('ligaBox').selectedIndex].value;
        xajax_filterRankings(param);
    });
    $('li#last-month').click(function(){
        param['op'] = 3;
        param['ligaID'] = param['ligaID'] = document.getElementById('ligaBox').options[document.getElementById('ligaBox').selectedIndex].value;
        xajax_filterRankings(param);
    });
    $('li#this-week').click(function(){
    
        param['op'] = 1;
        param['ligaID'] = param['ligaID'] = document.getElementById('ligaBox').options[document.getElementById('ligaBox').selectedIndex].value;
        xajax_filterRankings(param);
    });
    $('li#this-year').click(function(){
        param['op'] = 4;
        param['ligaID'] = param['ligaID'] = document.getElementById('ligaBox').options[document.getElementById('ligaBox').selectedIndex].value;
        xajax_filterRankings(param);
    });
    /*$('.activbgd').click(function(){
        // window.location = '/register.php';
        xajax_joinAllLeagues();
        $(this).hide();
    });*/
	
    $('.acced').click(function(){
        window.location = '/user.php?xoops_redirect=/modules/pronosticos/ligas_rankings.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');
    $('#months').change(function(){
        var param = new Array();
        param['start'] = 0;
        param['mon'] = this.value;
        xajax_pagedRankings(param);
    });
});


function lookup(inputString){
    if (inputString.length == 0) {
        // Hide the suggestion box.
        $('#suggestions').hide();
    }
    else {
        $.post("/modules/pronosticos/lookup_users.php?p=Rank", {
            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);
}

