function OddsBetType(BetTypeChg,BetTypeDet,EventoIdU){

    SetOddsBetType(BetTypeChg);

	document.location.hash=BetTypeChg+'-'+BetTypeDet+'-'+EventoIdU;
	currentAnchor=document.location.hash;
    if(page=='evento'){
        xajax_OddsBetTypeMax(BetTypeChg,EventoIdU);
    }
    else if(page=='compare'){
        xajax_OddsBetTypeCompare(BetTypeChg,MatchupId);
        xajax_OddsBetInfoLimp();

    }
    else if(page=='tendencia'){
        casasel=document.getElementById("selcasa");
        sel=casasel.options[casasel.selectedIndex];
        if(sel.value!='-1'){
            casasel=sel.value;
        }else{
            casasel='';
        }
        xajax_OddsBetTypeCompare(BetTypeChg,MatchupId);
        xajax_OddsTendencia(MatchupId, BetType,Periado,casasel,EventoId);

    }else if(page=='info'){
        xajax_OddsBetTypeCompare(BetTypeChg,MatchupId);
    }
}



function OddsmatchupType(varBetType,varMatchup,varEventoID){
	
	SetOddsBetType(varBetType);
	SetEventId(varEventoID);
	alphaOff('matchsdiv-'+varEventoID)
	xajax_OddsmatchupType(BetType,varMatchup,EventoId)
}



function OddsFormat(Format){
	
	//alert(Format + ' ' + BetType + ' ' + EventoId);
    if(page=='evento'){
        xajax_OddsFormat(Format,BetType,EventoId);
    }
    else if(page=='compare'){
        xajax_OddsOddsFormatCompare(Format,BetType,EventoId);
    }
 }

function refrescar(){
    if(page=='evento'){
        alphaOff("matchsdiv");
        xajax_RefrescarMaxOdds(EventoId,BetType);
    }
    else if(page=='compare'){
        alphaOff("MainCompare");
        xajax_RefrescarCompareOdds(MatchupId,BetType);
    }
    else if(page=='tendencia'){
        alphaOff("MainCompare");
        casasel=document.getElementById("selcasa");
        sel=casasel.options[casasel.selectedIndex];

        if(sel.value!='-1'){
            casasel=sel.value;
        }else{
            casasel='';

        }
        xajax_OddsTendencia(MatchupId, BetType,Periado,casasel,EventoId);
    }
}
function showTip(btpid,idev)
{
    ele=document.getElementById('bet_'+btpid+'_tip'+idev);
    ele.style.top=(document.getElementById('bet_type_'+btpid+'_ev'+idev).offsetTop-25)+'px';

    ele.style.visibility='visible';
}
function SetOddsBetType(VarBetType){
    BetType=VarBetType;
}
function SetEventId(VarEventId){
    EventoId=VarEventId;
}
function SetPage(VarPage){
    page=VarPage;
}
/**
 *Control bet borrowed functions
 */
function AddTicket(IdEnc, Select,Price)
{
    //alert(IdEnc+ " " + Select + " " + Price);
    xajax_AddTicket(IdEnc,Select,Price);
}
function DelTicket(IdEnc)
{
    xajax_DelTicket(IdEnc);
}
function calculate(win, i, old)
{
    var Import ;
    var Price ;
    var Winner;
    var result;
    var WinnerNeto;
    if(win=='IN'){
        Import = document.getElementById('importe'+i);
        Price = document.getElementById('price'+i);
        Winner = document.getElementById('win'+i);
        WinnerNeto = document.getElementById('winNeto'+i);
        

        Total=Import.value*Price.value;
        result=calRound(Total) ;
        TotalNeto= Total-Import.value;
        resultNeto=calRound(TotalNeto);
    }

    if(win=='ALL'){

        Import = document.getElementById('importe'+i);
        Price = document.getElementById('pricetotal'+i);
        Winner = document.getElementById('win'+i);
        WinnerNeto = document.getElementById('winNeto'+i);   

        Total=Import.value*Price.value;
        result=calRound(Total) ;
        TotalNeto= Total-Import.value;
        resultNeto=calRound(TotalNeto);

    }
    if(win=='CALL'){
        var PriceTotal=1;
        for (j=1;j<=i;j++)
        {
            var price = document.getElementById('price'+j);
            PriceTotal=PriceTotal*price.value;
        }


        Import = document.getElementById('importe'+i);
        Winner = document.getElementById('win'+i);
        WinnerNeto = document.getElementById('winNeto'+i);   
        var ptotal = document.getElementById('ptotal'+i);


        Total=Import.value*calRound(PriceTotal);
        result=calRound(Total);  
        TotalNeto= Total-Import.value;
        resultNeto=calRound(TotalNeto);

        ptotal.innerHTML='<input type="hidden" name="pricetotal'+i+'" id="pricetotal'+i+'" size="8" value="'+calRound(PriceTotal)+'" style="font-size: 10px">Cuota Total:</font> <b>'+calRound(PriceTotal)+'</b>';

    }

    Winner.innerHTML='<font color="#808000" size="1" face="Verdana">Retorno:</font> <b>'+result+'</b>';
    WinnerNeto.innerHTML='<font color="#808000" size="1" face="Verdana">Ganancia Neta:</font> <b>'+resultNeto+'</b>'; 
    
}
function calRound(number){

    var original=parseFloat(number);
    var result=Math.round(original*100)/100;
    return result;

}
function simple_values(_name){
    var _total = _name.slice(7);
    var spread = null;
    var over_under = null;

    if(document.getElementById('price'+_total) != null)
        var _cuotas = parseFloat(document.getElementById('price'+_total).value);
    if(document.getElementById('importe'+_total) != null)
        var _importe = parseFloat(document.getElementById('importe'+_total).value);
    if(document.getElementById('comentario'+_total) != null)
        var _coment = document.getElementById('comentario'+_total).value;
    if(document.getElementById('spread'+_total) != null)
        spread =parseFloat(document.getElementById('spread'+_total).value);
    if(document.getElementById('over_under'+_total)!=null)
        over_under = parseFloat(document.getElementById('over_under'+_total).value);

 

    if(isNaN(_cuotas) || isNaN(_importe))
    {
        alert("Estos valores deben ser numericos");
        return false;
    }

    if(spread != null)
        if(isNaN(spread)){
            alert("La ventaja debe ser numerica");
            return false;
        }

    if(over_under != null)
        if(isNaN(over_under)){
            alert("El total debe ser numerico");
            return false;
        }

    if ( _importe <= 0 || _importe == false ) {
        alert("El importe debe ser un numero mayor que cero");
        return false;
    }
    else
    if (_cuotas <= 0) {
        alert("La cuota debe ser un numero mayor que cero");
        return false;
    }
    else {
       // alert(_cuotas + " "+ _importe+ " "+ _coment+ " "+ _total+ " "+ spread+ " "+ over_under);
        xajax_insertPronostico(_cuotas, _importe, _coment, _total, spread, over_under);

    }
    return false;

}
function sendform(url){

    if(document.getElementById('deporte').options[document.getElementById('deporte').selectedIndex].value)
        var deporte = document.getElementById('deporte').options[document.getElementById('deporte').selectedIndex].value;
	
    if(document.getElementById('pais').options[document.getElementById('pais').selectedIndex].value)
        var paises = document.getElementById('pais').options[document.getElementById('pais').selectedIndex].value;

    if(document.getElementById('evento').options[document.getElementById('evento').selectedIndex].value && document.getElementById('evento').options[document.getElementById('evento').selectedIndex].value != "0"  && document.getElementById('evento').options[document.getElementById('evento').selectedIndex].value != "-1")
        var evt = document.getElementById('evento').options[document.getElementById('evento').selectedIndex].value;

    if (deporte && deporte != "" && deporte!=0) {
        url = url + 'ligas_pronosticos+deport-' + deporte;

        if (paises && paises !="" && paises !=0) {
            url = url + '-pais-' + paises.toLowerCase();

            if (evt && evt !="" && evt!=0) {
                url = "ligas_pronosticos+" + 'id_eventos\n\
-' + evt;
            //
            }
        }
        url = url +'.html';
        window.location=url;
    }
}

function alphaOff(IdElement){
	
      document.getElementById(IdElement).style.opacity='.5';
	document.getElementById(IdElement).style.filter='alpha(opacity=50)';
	
}

function alphaOn(IdElement){
     
      document.getElementById(IdElement).style.opacity='1';
	document.getElementById(IdElement).style.filter='alpha(opacity=100)';
	
}


function imprimirTicket(){
     
     xajax_imprimirTicket();
	
}

// ************** End of odds Javascripts *********************

$(function(){
    $('#SelectLiga').change(function(){
        var ligaID = this.value;
        //xajax_setSessionID(ligaID);
        top.location = '/pronosticos/ligas_pronosticos+ligaID-'+ligaID+'.html';

    });
/*
    $('.activbgd').click(function(){
        // window.location = '/register.php';
        xajax_joinAllLeagues();
        $(this).hide();
    });
	*/
    $('.acced').click(function(){
        window.location = '/user.php?xoops_redirect=/modules/pronosticos/ligas_pronosticos.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');
});

