var typowanie=null;
var experci_url = '';

var podserwisy_typowanie_kursy = false;

function score_explode(score,key)
{
    if(!score)
        return "-";

    var a = explode("-",score);
    if(!a[key])
        return '-';

    return a[key];

}

function Typuj()
{
    this.typy = new Array();
    
    this.addTyp = function(t)
    {
        this.typy[this.typy.length] = t;
    }

    this.removeTyp = function(game_id)
    {
         o = this.searchType(game_id);
         if(o)
             o = null;
    }

    this.submit = function(sport_id)
    {
        window.onbeforeunload = null;

        //window.onbeforeunload = onBeforeUnloadAction;

        var input_hidden = $('input_hidden');
       
        input_hidden.innerHTML = "";

        for(i=0;i<this.typy.length;i++)
        {
            if(sport_id==1 && (!this.typy[i].game.score_0 || !this.typy[i].game.score_1))
            {
                alert("Nie wybrałeś wyniki dla jednego z typów");
                return;
            }

            if(sport_id==1 && this.typy[i].type_analiza && (!this.typy[i].game.score_0 || !this.typy[i].game.score_1))
            {
                alert("Podaj wyniki dla spotkań, dla których napisałeś analizę ");
                return;
            }

            if(this.typy[i].type_analiza && !this.typy[i].type_value_id)
            {
                alert("Podaj typy dla dla spotkań, dla których napisałeś analizę ");
                return;
            }

            input = document.createElement("input");
            input.type = "hidden";
            input.name='analiza['+this.typy[i].game.game_id+']';
            input.value = this.typy[i].type_analiza;
            input_hidden.appendChild(input);
            
            input = document.createElement("input");
            input.type = "hidden";
            input.name='wynik['+this.typy[i].game.game_id+'][0]';
            input.value = this.typy[i].game.score_0;
            input_hidden.appendChild(input);

            input = document.createElement("input");
            input.type = "hidden";
            input.name='wynik['+this.typy[i].game.game_id+'][1]';
            input.value = this.typy[i].game.score_1;
            input_hidden.appendChild(input);

            input = document.createElement("input");
            input.type = "hidden";
            input.name='typ['+this.typy[i].game.game_id+']';
            input.value = this.typy[i].type_value_id;
            input_hidden.appendChild(input);
        }

        $('typuj').submit();
    }

    this.searchType = function(game_id)
    {
        for(ind=0;ind<this.typy.length;ind++)
            if(this.typy[ind] && this.typy[ind].game.game_id==game_id)
                return this.typy[ind];

         return false;
    }

    this.typuj = function(element,game_id,value_id,sport_id)
    {

        if(game_id)
            obj = this.searchType(game_id);
        else
            return;

        if(!obj)
        {
            t = new Typy();
            g = new Game();
            g.game_id = game_id;
            t.setGame(g);
            t.type_value_id = value_id;

            this.addTyp(t);
            if(sport_id!=1 || podserwisy_typowanie_kursy)
            {
           
                input = element.parentNode.parentNode.parentNode.getElementsByTagName("input");
                    for(i=0;i<input.length;i++)
                        if(!input[i].checked)
                            input[i].disabled = true;
                    
            }


        }else{

            //sprawdzam czy typowano juz inny rodzaj
            if(element.checked && obj.type_value_id && obj.type_value_id!=value_id && obj.type_value_id < 4)
            {
              
                switch(obj.type_value_id)
                {
                    case 1:
                        if(value_id==2)
                            obj.type_value_id = 4;
                        else
                            obj.type_value_id = 6;
                    break;
                    case 2:
                        if(value_id==1)
                            obj.type_value_id = 4;
                        else
                            obj.type_value_id = 5;
                    break;
                    case 3:
                        if(value_id==1)
                            obj.type_value_id = 6;
                        else
                            obj.type_value_id = 5;
                    break;
                    default: throw "Nieoznaczony blad";
                }

                    input = element.parentNode.parentNode.parentNode.getElementsByTagName("input");
                    for(i=0;i<input.length;i++)
                        if(!input[i].checked)
                            input[i].disabled = true;
                

            }else if(!element.checked && obj.type_value_id==value_id && obj.type_value_id < 4){
                obj.type_value_id = null;
                if(sport_id!=1 || podserwisy_typowanie_kursy)
                {
                    input = element.parentNode.parentNode.parentNode.getElementsByTagName("input");
                        for(i=0;i<input.length;i++)
                            if(!input[i].checked)
                                input[i].disabled = false;
                }
                
                return false;
            //jesli klikam w typ z podporka
            }else if(obj.type_value_id > 3){
                switch(obj.type_value_id)
                {
                    case 4:
                        if(value_id==1)
                            obj.type_value_id = 2;
                        else
                            obj.type_value_id = 1;
                    break;
                    case 5:
                        if(value_id==2)
                            obj.type_value_id = 3;
                        else
                            obj.type_value_id = 2;
                    break;
                    case 6:
                        if(value_id==1)
                            obj.type_value_id = 3;
                        else
                            obj.type_value_id = 1;
                    break;
                    default: throw "Nieoznaczony blad";
                }
                
                //odblokuj typy
                input = element.parentNode.parentNode.parentNode.getElementsByTagName("input");
                for(i=0;i<input.length;i++)
                    if(!input[i].checked)
                        input[i].disabled = false;
            }else{
                obj.type_value_id = value_id;
                 if(sport_id!=1  || podserwisy_typowanie_kursy)
                {
                    input = element.parentNode.parentNode.parentNode.getElementsByTagName("input");
                        for(i=0;i<input.length;i++)
                            if(!input[i].checked)
                                input[i].disabled = true;
                }
            }

        }
    
       return true;
    }

    this.setAnaliza = function(game_id,editor_obj)
    {
        obj = this.searchType(game_id);

        if(!obj){
            t = new Typy();
            g = new Game();
            g.game_id = game_id;
            t.setGame(g);
            obj.type_analiza = editor_obj.getContent();

            this.addTyp(t);
        }else{
            obj.type_analiza = editor_obj.getContent();
        }
    }

    this.setAnalizyCounter=function(o,game_id)
    {
        obj = this.searchType(game_id);

        if(!obj)
            return false;

        o.innerHTML=obj.type_analiza.length;
    }

    this.sprawdz_wynik_typ = function(game_id,element)
    {
        obj = this.searchType(game_id);
        //sprawdz czy wynik zgadza sie z typem
        if(obj.game.score_0 > obj.game.score_1){
            type_accept = new Array(1,4,6);
        }else if(obj.game.score_0==obj.game.score_1){
            type_accept = new Array(2,4,5);
        }else{
            type_accept = new Array(3,5,6);
        }

        index=0;
        for(i=0;i<type_accept.length;i++){

            if(type_accept[i]==obj.type_value_id)
            {
                index++;
            }
        }

        if(index==0){
            select = element.parentNode.getElementsByTagName("select");
            for(k=0;k<select.length;k++)
                select[k].selectedIndex = 0;

            obj.game.score_0 = null;
            obj.game.score_1 = null;
            alert("Wynik powinien zgadzać się z typem");
        }
    }

    this.ustaw_wynik = function(type,game_id,element,value)
    {
        obj = this.searchType(game_id);
        if(!obj){
            var t = new Typy();
            var game = new Game();
            game.game_id = game_id;
            t.setGame(game);
            this.addTyp(t);

        }

        if(!obj.type_value_id){
            element.selectedIndex = 0;
            return alert("Przed wyborem wyniku zaznacz typ spotkania");
        }
        
        obj = this.searchType(game_id);
        if(type==0){
            obj.game.score_0 = value;
            if(obj.game.score_1){
                 this.sprawdz_wynik_typ(game_id,element);
            }
        }else if(!obj.game.score_0){
            alert("Ustaw najpierw wartość dla gospodarza");
            element.selectedIndex=0;
        }else{
            obj.game.score_1 = value;
            this.sprawdz_wynik_typ(game_id,element);
        }
  
        
    }

}

function Set()
{
    this.set_name = null;
    this.set_score = null;
}

function Team()
{
    this.team_name=null;
    this.team_id=null;
    this.team_url=null;
}

function Scorer()
{
    this.name=null;
    this.min=null;
}

function Game()
{
    this.teams = new Array();
    this.game_date = null;
    this.game_score = null;
    this.game_status = null;
    this.status_type = null;
    this.scorer = new Array();
    this.stadion = null;
    this.sedzia = null;
    this.sedzia_country = null;
    this.widzow = null;
    this.livegol_game_id=null;
    this.game_min = 0;
    this.sport_id = null;
    this.sets = new Array();
    this.user_typed_typ = null;
    this.user_typed_wynik = null;
    this.game_selected = false;
    this.score_0=null;
    this.score_1 = null;

    this.type_1 = null;
    this.type_x = null;
    this.type_2 = null;
    this.ilosc_typow = null;
    this.ilosc_analiz = null;
    
    this.addTeam = function(t)
    {
        this.teams[this.teams.length] = t;
    }

    this.addScorer = function(s)
    {
        if(s)
            this.scorer[this.scorer.length] = s;
    }

    this.addSet = function(s)
    {
        if(s)
            this.sets[this.sets.length] = s;
    }

    this.setGameInfo = function(obj)
    {

        if(this.scorer.length==0)
        {
            obj.innerHTML = "W bazie nie ma strzelców bramek";
            return true;
        }
        obj.innerHTML = '';
        for(i=0;i<this.scorer.length;i++)
        {
            img = document.createElement("img");
            img.alt="";
            img.src = "http://www.bukmacherzy.com/kursy/images/new_podserwisy/pilka.gif";
            obj.appendChild(img);
            obj.innerHTML+=this.scorer[i].min+"' "+this.scorer[i].name;
            obj.appendChild(document.createElement("br"));
        }
        return true;
    }

    this.tmp=true;
    this.getGameInfo = function(obj_el)
    {

        if(this.tmp && this.livegol_game_id>0)
        {
            this.tmp = false;
            thisObj = this;
            advAJAX.get({
                 url: "http://www.bukmacherzy.com/livegol_xml.php?param=pilka_nozna/match_info/"+this.livegol_game_id,
                 timeout : 4000,
                 onTimeout : function() { alert("Connection timed out."); },
                 retry: 1,
                 retryDelay: 2000,
                 onRetry : function() { alert("Retry connection..."); },
                 onRetryDelay : function() { alert("Awaiting retry..."); },
                 onSuccess : function(obj){
                    
                    //scorer
                    xml = obj.responseXML;
                    scorer = xml.getElementsByTagName("scorer");
                    
                    if(scorer.length > 0)
                    {
                        sc = scorer.item(0).getElementsByTagName("i");
                     
                        for(i=0;i<sc.length;i++)
                        {
                            var strzelec = new Scorer();
                            strzelec.name = sc[i].getElementsByTagName("n").item(0).firstChild.nodeValue;
                            strzelec.min = sc[i].getElementsByTagName("m").item(0).firstChild.nodeValue;

                            thisObj.addScorer(strzelec);
                        }
                    }
                    thisObj.setGameInfo(obj_el)

             },
                 onError : function(obj) {}
             });
        }
        
    }
}

function Typy(p_id,url)
{
    this.user_id = null;
    this.user_login = null;
    this.type_value_id = null;
    this.type_value_name = null;
    this.type_kurs = null;
    this.type_bukmacher_id  = null;
    this.type_bukmacher_name = "";
    this.type_bukmacher_link = null;
    this.type_bukmacher_website = null;
    this.type_analiza = null;
    this.type_wynik = null;

    this.site_url = url;
    this.podserwis_id = p_id;
    this.game = null;
    //ilosc typow np dla x
    this.ilosc_typow = 0;
    this.procent_typow = 0;
    this.setGame = function(g)
    {
        this.game = g;
    }
  
    this.getTypeForGameByUser = function(game_id,user_id)
    {
        thisObj = this;
        advAJAX.get({
             url: this.site_url+"/xml/getPodserwisExpertTypeForGame/?game_id="+game_id+"&user_id="+user_id,
             timeout : 4000,
             onTimeout : function() { alert("Connection timed out."); },
             retry: 1,
             retryDelay: 2000,
             onRetry : function() { alert("Retry connection..."); },
             onRetryDelay : function() { alert("Awaiting retry..."); },
             onSuccess : function(obj){
                 
                 type = obj.responseXML.getElementsByTagName("type");

                 if(type.length > 0){
                     var x = thisObj.set_type(type.item(0));
                     thisObj.setTypeBoxExpert(x);
                 }else{
                    alert("Nie znalazłem typu");
                 }

         },
             onError : function(obj) {alert("Error: " + obj.status); }
         });
    }

    this.set_type = function(xml)
    {
        teams = xml.getElementsByTagName("teams");
        if(teams.length > 0){
            teams_node = teams.item(0).getElementsByTagName("i");
            var game = new Game();

            for(i=0;i<teams_node.length;i++)
            {
                team = new Team();
                team.team_name = teams_node[i].getAttribute("team_item_name");
                team.team_id = teams_node[i].getAttribute("odds_teams_team_id");
                team.team_url = teams_node[i].getAttribute("team_item_url");

                game.addTeam(team);
            }

            game_node = teams.item(0).parentNode;
            game.game_date = game_node.getAttribute("game_date");
            game.game_id = game_node.getAttribute("game_id");
            
            var typ = new Typy(this.podserwis_id,this.site_url);
            typ.setGame(game);
            typ.type_value_name = game_node.getAttribute("odd_value_name_name");
            typ.type_analiza = game_node.getAttribute("type_opis");
            return typ;
            
        }else{
            return false;
        }
    }

    this.setTypeBoxExpert = function(typ)
    {
        expert_element = $('games_expert');
        div = expert_element.getElementsByTagName("div");
        wiersz = 0;
        for(i=0;i<div.length;i++)
        {
            if(div[i].className=="row")
            {
                wiersz++;
                
                switch(wiersz)
                {
                    case 1:
                        if(typ.game.teams.length==0)
                            throw "Nie ma drużyn";

                        if(typ.game.teams.length>2)
                            div[i].getElementsByTagName("div").item(1).innerHTML = typ.game.teams[0].team_name+", "+typ.game.teams[1].team_name+" - "+typ.game.teams[2].team_name+", "+typ.game.teams[3].team_name;
                        else
                            div[i].getElementsByTagName("div").item(1).innerHTML = typ.game.teams[0].team_name+" - "+typ.game.teams[1].team_name;
                    break;
                    case 2:
                        div[i].getElementsByTagName("div").item(1).innerHTML = new Date(parseInt(typ.game.game_date)*1000).format("d-m-Y H:i");
                    break;
                    case 3:
                        div[i].getElementsByTagName("div").item(1).innerHTML = typ.type_value_name;
                    break;
                }
            }
            if(div[i].className=="row_analiza")
                div[i].innerHTML = '<span class="analiza">Analiza:</span>'+typ.type_analiza.truncate(500);

        }
    }
}

Typy.getGamesForLeague = function(set_games,podserwis_id,round,season,date,mt,expert,check_user_typed,type_wygladu,remis)
{

  if(!date)
      date="";
  else
      date = date.replace(/-/g,"");

  if(!mt)
    mt = "";


  if(!expert)
      expert="";
  if(!check_user_typed)
     check_user_typed="";
   thisObj = this;
    advAJAX.get({
         url: "http://www.bukmacherzy.com/xml/getTypy/?p_id="+podserwis_id+"&season_id="+season+"&round="+round+"&expert="+expert+"&date="+date+"&mt="+mt+"&check_user_typed="+check_user_typed,
         timeout : 4000,
         onTimeout : function() { alert("Connection timed out."); },
         retry: 1,
         retryDelay: 2000,
         onRetry : function() { alert("Retry connection..."); },
         onRetryDelay : function() { alert("Awaiting retry..."); },
         onSuccess : function(obj){

         podzial_ligi = false;
         leagues_xml = obj.responseXML.getElementsByTagName("leagues");

         textareas = document.getElementsByTagName("textarea");
         for(k=0;k<textareas.length;k++)
         {
             tinyMCE.get(textareas[k].id).remove();
         }

         if(leagues_xml.length > 0)
            set_games.innerHTML = "";
         else
             return;
         
         var html = "";
         for(league_index=0;league_index<leagues_xml.item(0).childNodes.length;league_index++)
         {
             var league_node = leagues_xml.item(0).childNodes[league_index];
           
             if(league_node.nodeType==1)
             {
                 games_xml = league_node.getElementsByTagName("teams");
                 if(games_xml.length>0)
                 {
                     var league_html = '';
                     league_html+='<div class="league_box">';
                     league_html+='<div class="header">';
                     league_html+='<img src="http://www.bukmacherzy.com/kursy/images/new_podserwisy/league_a.gif" class="floatl" alt="" />';
                     league_html+='<div class="title">'+league_node.getAttribute("league_item_name")+'</div>';
                     league_html+='<img src="http://www.bukmacherzy.com/kursy/images/new_podserwisy/league_c.gif" alt="" class="floatr" />';
                     league_html+='</div>';
                     league_html+='<div class="text_content">';

                     if(leagues_xml.item(0).childNodes.length>1)
                     {
                        html+=league_html;
                     }
                 
                     for(i=0;i<games_xml.length;i++)
                     {
                        var game_node = games_xml[i].parentNode;
                        var game = new Game();
                        game.sport_id = game_node.getAttribute("odds_sport_type_sport_id");
                        game.game_id = game_node.getAttribute("game_id");
                        game.game_selected = game_node.getAttribute("game_selected");
                        
                        if(isdefined(typowanie))
                            saved_game = typowanie.searchType(game.game_id);
                        else
                            saved_game = false;

                        if(!saved_game || saved_game.game.teams.length == 0)
                        {
                            game.status_type = game_node.getAttribute("status_type");
                            game.game_date = game_node.getAttribute("game_date");
                            if(game.status_type==2)
                                game.game_score = ' - ';
                            else
                                game.game_score = game_node.getAttribute("game_score");
                            game.livegol_game_id = game_node.getAttribute("livegol_game_id");
                            game.game_min = game_node.getAttribute("game_min");
                            sets_p = game_node.getElementsByTagName("sets");
                            if(sets_p.length>0)
                            {
                                sets = sets_p.item(0).getElementsByTagName("i");

                                for(seti=0;seti<sets.length;seti++)
                                {
                                    var set_tmp = new Set();
                                    set_tmp.set_name = sets[seti].getAttribute("set_name");
                                    set_tmp.set_score = sets[seti].getAttribute("set_score");

                                    game.addSet(set_tmp);
                                }
                            }

                            teams_nodes = game_node.getElementsByTagName("teams");
                            if(teams_nodes.length > 0)
                            {
                                team_nodes = teams_nodes.item(0).getElementsByTagName("i");

                                for(x=0;x<team_nodes.length;x++)
                                {
                                    team = new Team();
                                    team.team_name = team_nodes.item(x).getAttribute("team_item_name");
                                    team.team_url = team_nodes.item(x).getAttribute("team_item_url");

                                    game.addTeam(team);
                                }
                            }

                            //sprawdz czy typowal
                            if(check_user_typed)
                            {
                                user_typed = game_node.getElementsByTagName("user_typed");
                                if(user_typed.length > 0)
                                {
                                    if(user_typed.item(0).getAttribute("typ"))
                                    {
                                        game.user_typed_typ = user_typed.item(0).getAttribute("typ");
                                        game.user_typed_wynik = user_typed.item(0).getAttribute("wynik")
                                    }

                                }
                            }

                            ilosc_1=0;
                            ilosc_x=0;
                            ilosc_2=0;
                            //types
                            types = game_node.getElementsByTagName("types");
                            if(types.length > 0)
                            {
                                game.ilosc_typow = types.item(0).getAttribute("sum");
                                game.ilosc_analiz = game_node.getAttribute("analizy");
                                types_items = types.item(0).getElementsByTagName("i");
                                for(z=0;z<types_items.length;z++)
                                {
                                    if(types_items[z].getAttribute("odd_value_id")==1)
                                        ilosc_1 = types_items[z].getAttribute("ilosc");
                                    else if(types_items[z].getAttribute("odd_value_id")==2)
                                        ilosc_x = types_items[z].getAttribute("ilosc");
                                    else if(types_items[z].getAttribute("odd_value_id")==3)
                                        ilosc_2 = types_items[z].getAttribute("ilosc");
                                }
                            }

                            //odds
                            odds = game_node.getElementsByTagName("odds");
                            if(odds.length > 0)
                            {
                                odds_item = odds.item(0).getElementsByTagName("i");

                                var type_1 = new Typy();
                                var type_x = new Typy();
                                var type_2 = new Typy();
                                for(a=0;a<odds_item.length;a++)
                                {

                                    if(odds_item[a].getAttribute("odd_name")==1)
                                    {
                                        type_1.type_value_name = 1;
                                        type_1.type_bukmacher_id = odds_item[a].getAttribute("bukmacher_id");
                                        type_1.type_bukmacher_name = odds_item[a].getAttribute("bukmacher_name");
                                        type_1.type_bukmacher_link = odds_item[a].getAttribute("bukmacher_link");
                                        type_1.type_kurs = odds_item[a].getAttribute("max_a");
                                        if(game.ilosc_typow==0)
                                            type_1.procent_typow = 0;
                                        else
                                             type_1.procent_typow = ilosc_1*100/game.ilosc_typow;
                                    }else if(odds_item[a].getAttribute("odd_name")=='x'){
                                        type_x.type_value_name = 1;
                                        type_x.type_bukmacher_id = odds_item[a].getAttribute("bukmacher_id");
                                        type_x.type_bukmacher_name = odds_item[a].getAttribute("bukmacher_name");
                                        type_x.type_bukmacher_link = odds_item[a].getAttribute("bukmacher_link");
                                        type_x.type_kurs = odds_item[a].getAttribute("max_a");
                                        if(game.ilosc_typow==0)
                                            type_x.procent_typow = 0;
                                        else
                                             type_x.procent_typow = ilosc_x*100/game.ilosc_typow;
                                    }else if(odds_item[a].getAttribute("odd_name")==2){
                                        type_2.type_value_name = 1;
                                        type_2.type_bukmacher_id = odds_item[a].getAttribute("bukmacher_id");
                                        type_2.type_bukmacher_name = odds_item[a].getAttribute("bukmacher_name");
                                        type_2.type_bukmacher_link = odds_item[a].getAttribute("bukmacher_link");
                                        type_2.type_kurs = odds_item[a].getAttribute("max_a");
                                        if(game.ilosc_typow==0)
                                            type_2.procent_typow = 0;
                                        else
                                            type_2.procent_typow = ilosc_2*100/game.ilosc_typow;
                                    }

                                }

                                if(!type_1.type_kurs){
                                    type_1.type_bukmacher_name = "-";
                                    type_1.type_kurs = "-";
                                }

                                if(!type_x.type_kurs){
                                    type_x.type_bukmacher_name = "-";
                                    type_x.type_kurs = "-";
                                }

                                if(!type_2.type_kurs){
                                    type_2.type_bukmacher_name = "-";
                                    type_2.type_kurs = "-";
                                }

                                game.type_1 = type_1;
                                game.type_x = type_x;
                                game.type_2 = type_2;
                            }
                              var typ = new Typy();
                              typ.type_value_id = game.user_typed_typ;
                              typ.type_wynik = game.user_typed_wynik;

                              if(saved_game){
                                    typ.type_analiza = saved_game.type_analiza;
                                    typ.type_value_id = saved_game.type_value_id


                                    if(saved_game.game){
                                        if(saved_game.game.score_0)
                                            game.score_0 = saved_game.game.score_0;

                                        if(saved_game.game.score_1)
                                            game.score_1 = saved_game.game.score_1;
                                    }
                                    typowanie.removeTyp(saved_game.game.game_id);
                              }

                              typ.setGame(game);

                           if(saved_game)
                               typowanie.addTyp(typ);
                         }else{
                             typ = saved_game;
                         }
                         
                         html += Typy.setGameHtml(typ,type_wygladu,remis);
                         
                     }
                     if(leagues_xml.item(0).childNodes.length>1)
                     {
                        html+="</div></div>";
                     }
                }
             }
         }
         
         set_games.innerHTML = html;
        
         if(type_wygladu==2)
            Typy.setWYSWIGEditor();
      
     },
         onError : function(obj) {alert("Error: " + obj.status); }
     });
}


Typy.setGameHtml = function(typ,type,remis)
{
    pokaz = 0;
    game = typ.game;
 
  
    if(type==2 && game.sport_id==2 && game.type_1.type_kurs=="-")
        return "";
  
    kursy_typowalem = 0;
    html='<div class="league"><div class="status">';
    html+='<img src="http://www.bukmacherzy.com/kursy/images/new_podserwisy/status_'+game.status_type+'.gif" alt=""  />'
    html+='</div>';
    
    html+='<div class="gamen">';
    html+='<div class="row">';

    if(game.status_type!=3)
        html+='    <div class="a">'+new Date(parseInt(game.game_date)*1000).format("d-m H:i")+'</div>';
    else
        html+='<div class="a"><img src="http://www.bukmacherzy.com/kursy/images/new_podserwisy/game_min.gif" style="float:left;margin:11px 5px 0 14px" alt=""/><span style="float:left;color:#00890e;">'+game.game_min+'min</span></div>';

    if(remis){
        html+='    <div class="b">'+game.teams[0].team_name+'</div>';
        html+='    <div class="c"><div class="z"><div class="y">remis</div></div></div>';
        html+='    <div class="d">'+game.teams[1].team_name+'</div>';
    }else{
       if(game.teams.length>2)
       {
            html+='    <div class="br">'+game.teams[0].team_name+', '+game.teams[1].team_name+'</div>';
            html+='    <div class="dr">+'+game.teams[2].team_name;

            if(game.teams.length>3)
                html+= game.teams[3].team_name;
            html+='</div>';

       }else{
            html+='    <div class="br">'+game.teams[0].team_name+'</div>';
            html+='    <div class="dr">'+game.teams[1].team_name+'</div>';
       }
    }
    html+='</div>';
    html+='<div class="row2">';

    if(type==2)
    {
        
        if(game.status_type==2 && game.game_date > Math.round(new Date().getTime() / 1000) && !typ.game.user_typed_typ ){
            pokaz = 1;
        }
   
            html+=' <div class="score_typowanie">';
            if(game.sport_id==1){
            if(game.user_typed_wynik){
                html+="Typowałem:";
                html+='       <strong>'+game.user_typed_wynik+'</strong>';
            }else if(pokaz){
                html+='   Typuję wynik:';
                html+='<select  name="wynik['+game.game_id+'][0]" onchange="typowanie.ustaw_wynik(0,'+game.game_id+',this,this.options[this.selectedIndex].value)">';
                html+='<option value="">-</option>';

                for(index_option=0;index_option<11;index_option++)
                {
                    selected = "";
                    if(game.score_0==index_option)
                        selected = "selected";

                    html+=' <option value="'+index_option+'" '+selected+'>'+index_option+'</option>';
                }

                html+='</select> : ';

                html+='<select  name="wynik['+game.game_id+'][1]" onchange="typowanie.ustaw_wynik(1,'+game.game_id+',this,this.options[this.selectedIndex].value)">';
                html+='<option value="">-</option>';

                for(index_option=0;index_option<11;index_option++)
                {
                     selected = "";
                    if(game.score_1==index_option)
                        selected = "selected";

                    html+=' <option value="'+index_option+'" '+selected+'>'+index_option+'</option>';
                }
                html+='</select>';
            }
            }
            html+="</div>";
        
        
    }else{
        html+='    <div class="a">'+game.game_score+'</div>';
    }

        if(game.sport_id==2 && !pokaz && type!=2)
        {
            html+='<div class="sety">';
            for(set_index = 0;set_index<5;set_index++)
            {
                if(game.sets[set_index])
                    html+='<span class="set">'+score_explode(game.sets[set_index].set_score,0)+'<br />'+score_explode(game.sets[set_index].set_score,1)+'</span>';
            }
            html+='</div>';
        }

        if(remis)
            html+='<div class="b">';
        else if(!pokaz && !remis && (game.sport_id==2 || game.sport_id==5) && type!=2)
            html+='    <div class="b2">';
        else if(pokaz || ( !remis && (game.sport_id==2 || game.sport_id==5)))
            html+='    <div class="b3">';

        if(type==2)
        {
    
            if(game.user_typed_typ==1 || game.user_typed_typ==4 || game.user_typed_typ==6)
            {
              html+='  <div class="h" style="color:#b1b1b1;background:url(\'http://www.bukmacherzy.com/kursy/images/new_podserwisy/typowalem.gif\');">';
              html+='  Typowałem: <strong>x</strong></div>';
              kursy_typowalem = 1;
            }else if(!pokaz){
              html+='  <div class="h"></div>';
            }else{
                checked = "";
                if(typ.type_value_id==1 || typ.type_value_id==4 || typ.type_value_id==6)
                    checked = "checked";

                if(podserwisy_typowanie_kursy && game.type_1.type_kurs=="-")
                     html+='<div class="h"><span>-</span></div>';
                else
                    html+='  <div class="h"><span>Typuję <strong>1</strong>:</span><input type="checkbox" '+checked+' onclick="typowanie.typuj(this,'+game.game_id+',1,'+game.sport_id+')" name="odd['+game.game_id+'][1]" value="1" /></div>';
            }
        }
        
      
        html+='        <div class="e"';
        if (kursy_typowalem==1)
            html+='style="color:#b1b1b1;background:url(\'http://www.bukmacherzy.com/kursy/images/new_podserwisy/typowalem.gif\')"';
         
        html+='>Kurs: <a target="_blank" href="'+game.type_1.type_bukmacher_link+'">'+game.type_1.type_kurs+'</a></div>';
        html+='        <div class="f"><a target="_blank" href="'+game.type_1.type_bukmacher_link+'">'+game.type_1.type_bukmacher_name+'</a></div>';
        html+='    </div>';
        if(remis)
        {
            html+='    <div class="c">';
            if(type==2)
            {
                if(game.user_typed_typ==2 || game.user_typed_typ==4 || game.user_typed_typ==5)
                {
                  html+='  <div class="h" style="color:#b1b1b1;background:url(\'http://www.bukmacherzy.com/kursy/images/new_podserwisy/typowalem.gif\')">';
                  html+='  Typowałem: <strong>x</strong></div>';
                  kursy_typowalem = 2;
                }else if(!pokaz){
                  html+='  <div class="h"></div>';
                }else{
                    checked = "";
                    if(typ.type_value_id==2 || typ.type_value_id==4 || typ.type_value_id==5)
                        checked = "checked";
                    if(podserwisy_typowanie_kursy && game.type_1.type_kurs=="-")
                         html+='<div class="h"><span>-</span></div>';
                    else
                        html+='  <div class="h"><span>Typuję <strong>x</strong>:</span><input '+checked+' type="checkbox" onclick="typowanie.typuj(this,'+game.game_id+',2,'+game.sport_id+')" name="odd['+game.game_id+'][2]" value="1" /></div>';
                }
            }

            html+='        <div class="e"';
            if (kursy_typowalem==2)
                html+='style="color:#b1b1b1;background:url(\'http://www.bukmacherzy.com/kursy/images/new_podserwisy/typowalem.gif\')"';

            html+='>Kurs: <a href="'+game.type_x.type_bukmacher_link+'"  target="_blank">'+game.type_x.type_kurs+'</a></div>';
            html+='        <div class="f"><a href="'+game.type_x.type_bukmacher_link+'"  target="_blank">'+game.type_x.type_bukmacher_name.truncate(10)+'</a></div>';
            html+='    </div>';
        }
        if(remis)
            html+='    <div class="d">';
        else if(!remis && !pokaz && (game.sport_id==2 || game.sport_id==5) && type!=2)
            html+='    <div class="d2">';
        else if (pokaz || (!remis && (game.sport_id==2 || game.sport_id==5)))
            html+='    <div class="d3">';

        if(type==2)
        {
            if(game.user_typed_typ==3 || game.user_typed_typ==5 || game.user_typed_typ==6)
            {
              html+='  <div class="h" style="color:#b1b1b1;background:url(\'http://www.bukmacherzy.com/kursy/images/new_podserwisy/typowalem.gif\')">';
              html+='  Typowałem: <strong>x</strong></div>';
              kursy_typowalem = 3;
            }else if(!pokaz){
              html+='  <div class="h"></div>';
            }else{
                checked = "";
                
                if(typ.type_value_id==3 || typ.type_value_id==5 || typ.type_value_id==6)
                    checked = "checked";
             
                if(podserwisy_typowanie_kursy && game.type_1.type_kurs=="-")
                    html+='<div class="h"><span>-</span></div>';
                else
                    html+='  <div class="h"><span>Typuję <strong>2</strong>:</span><input '+checked+' type="checkbox" onclick="typowanie.typuj(this,'+game.game_id+',3,'+game.sport_id+')" name="odd['+game.game_id+'][3]" value="1" /></div>';
            }
        }
        html+='        <div class="e" ';
        if (kursy_typowalem==2)
            html+='style="color:#b1b1b1;background:url(\'http://www.bukmacherzy.com/kursy/images/new_podserwisy/typowalem.gif\')"';

        html+='>Kurs: <a href="'+game.type_2.type_bukmacher_link+'" target="_blank">'+game.type_2.type_kurs+'</a></div>';
        html+='        <div class="f"><a href="'+game.type_2.type_bukmacher_link+'" target="_blank">'+game.type_2.type_bukmacher_name+'</a></div>';
        html+='    </div>';
        html+='</div>';
    
    
   //jesli typowanie
    if(type==2)
    {
         html+='    <div class="typowanie">';
         html+='       <div class="row4">';
         html+='           <div class="a">';
         if(game.user_typed_typ)
         {
             html+=' <p style="text-align:center;">';
             html+='    Oddałeś(aś) już typ dla tego spotkania.';
             html+='  </p>';
         }else if(!pokaz){
            html+='    <p style="text-align:center;">Przyjmowanie typów na spotkanie zakończone.</p>';
         }else if(podserwisy_typowanie_kursy && game.type_1.type_kurs=="-"){
             analiza = '';
             html+='Nie pobrano jeszcze kursów dla tego spotkania.';
         }else if(game.sport_id==2 && !game.game_selected){
             analiza = '';
             html+='    <p style="text-align:center;">Analizy przyjmowane są wyłącznie do meczów zaznaczonych przez moderatorów. </p>';
         }else{
            analiza = '';
            
            if(typ.type_analiza)
                analiza = typ.type_analiza;

            html+='   <textarea name="analiza['+game.game_id+']" cols="" id="'+parseInt(game.game_id).toString()+'" onkeyup="">'+analiza+'</textarea>';
         }
      
        html+='      </div>';
        html+='      </div>';
        html+='      <div class="row5">';
        html+='          <img src="http://www.bukmacherzy.com/kursy/images/new_podserwisy/game_box_g.gif" alt="" class="floatl" />';
        if(!game.user_typed_typ && pokaz)
            html+='   <div class="t"> Ilość znaków: <span id="znaki_'+game.game_id+'">'+analiza.length+'</span></div>';
        else
            html+='  <div class="t"></div>';

        html+='          <img src="http://www.bukmacherzy.com/kursy/images/new_podserwisy/game_box_i.gif" alt="" class="floatr" />';
        html+='      </div>';
        html+='  </div>';
    
    }else{
         ilosc_typow = parseInt(game.ilosc_typow);
        html+='   <div class="game_info" style="display:none">';
        html+='       <div class="row3">';
        html+='           <div class="a">';
        html+='                <div class="i"><img src="http://www.bukmacherzy.com/kursy/images/new_podserwisy/game_box_arrow.gif" alt="" /> Typów: <strong>'+parseInt(game.ilosc_typow)+'</strong></div>';
        html+='                <div class="i"><img src="http://www.bukmacherzy.com/kursy/images/new_podserwisy/game_box_arrow.gif" alt="" /> Analiz: <strong>'+parseInt(game.ilosc_analiz)+'</strong></div>';
        html+='<div class="i"><a href="http://www.bukmacherzy.com/'+podserwis_url+'/typy'+experci_url+'/'+game.game_id+'_'+game.teams[0].team_url+'_'+game.teams[1].team_url+'">';
        html+='    <img class="analiza" src="http://www.bukmacherzy.com/kursy/images/new_podserwisy/analizy.gif" alt=""/></a></div>';

        html+='            </div>';

       html+='             <div class="b">';
       html+='                <img src="http://www.bukmacherzy.com/new_lay/images/slupki/green_black_'+round_integer(game.type_1.procent_typow,5)+'.gif" alt="" /><br />';
       html+='                 '+Math.round(game.type_1.procent_typow*100)/100+'%';
       html+='                    <div class="typow">Typów: ';
       if(ilosc_typow>0)
            html+=Math.round(ilosc_typow*game.type_1.procent_typow/100);
       else
            html+='0';

       html+='                  </div>';

       html+='             </div>';
       html+='             <div class="c">';
       html+='                 <img src="http://www.bukmacherzy.com/new_lay/images/slupki/gray_black_'+round_integer(game.type_x.procent_typow,5)+'.gif" alt="" /><br />';
       html+='                 '+Math.round(game.type_x.procent_typow*100)/100+'%';
       html+='                    <div class="typow">Typów: ';
       if(ilosc_typow>0)
            html+=Math.round(ilosc_typow*game.type_x.procent_typow/100);
       else
            html+='0';

       html+='                  </div>';

       html+='             </div>';
       html+='             <div class="d">';
       html+='                 <img src="http://www.bukmacherzy.com/new_lay/images/slupki/blue_black_'+round_integer(game.type_2.procent_typow,5)+'.gif" alt="" /><br />';
       html+='                 '+Math.round(game.type_2.procent_typow*100)/100+'%';
        html+='                    <div class="typow">Typów: ';
       if(ilosc_typow>0)
            html+=Math.round(ilosc_typow*game.type_2.procent_typow/100);
       else
            html+='0';

       html+='                  </div>';

       html+='            </div>';
       html+='         </div>';

       if(game.sport_id==1)
       {
        html+='       <div class="row4">';
         html+='           <div class="a">';
         html+='               <div class="info">';

         html+='               </div>';
         html+='               <div class="sklady">';
         html+='                   <a href="http://www.livegol.pl/pilka_nozna/boisko/'+game.livegol_game_id+'/" target="_blank"><img src="http://www.bukmacherzy.com/kursy/images/new_podserwisy/sprawdz_sklady.gif" alt="" /></a>';
         html+='               </div>';
         html+='               <div class="strzelcy">';

          html+='              </div>';
          html+='          </div><span style="display:block;clear:both;"></span>';
          html+='      </div>';
          
       }
       html+='  </div>';
         html+='   <div class="row5" onclick="hide_element(searchClassElement(this,\'zwin\'),searchClassElement(this.parentNode,\'game_info\'),1);var G = new Game();G.livegol_game_id = '+game.livegol_game_id+';G.getGameInfo(searchClassElement(this.parentNode,\'strzelcy\'));">';
         html+= '      <img src="http://www.bukmacherzy.com/kursy/images/new_podserwisy/game_box_g.gif" alt="" class="floatl" />';
         html+='       <div class="t">Kliknij, aby zobaczyć szczegóły spotkania';

         html+= '      </div>';

         html+= '      <img src="http://www.bukmacherzy.com/kursy/images/new_podserwisy/game_box_i.gif" alt="" class="floatr" />';
         html+= '      <div class="zwin">';
         html+= '          <span>Rozwiń</span><img src="http://www.bukmacherzy.com/new_lay/images/plus2.gif" alt="" />';
         html+= '      </div>';
         html+= '  </div>';
         html+=' </div>';
    }
    html+= '</div><div style="clear:both;height:1px;line-height:1px;"></div>';

    return html;
   
}

function zzz(obj)
{
    alert(4);
}

Typy.setWYSWIGEditor = function()
{
    tinyMCE.init({
        theme : "advanced",
        mode : "textareas",
        plugins : "bbcode",
        theme_advanced_buttons1 : "bold,italic,underline,undo,redo",
        theme_advanced_buttons2 : "",
        theme_advanced_buttons3 : "",
        theme_advanced_toolbar_location : "top",
        theme_advanced_toolbar_align : "center",
        theme_advanced_styles : "Code=codeStyle;Quote=quoteStyle",
        content_css : "bbcode.css",
        entity_encoding : "raw",
        add_unload_trigger : false,
        remove_linebreaks : false,
        force_br_newlines : true,
        content_css: 'http://www.bukmacherzy.com/kursy/css/textarea.css',

        setup: function(ed) {
            ed.onChange.add(function(ed, e) {

                typowanie.setAnaliza(ed.id,ed);
                typowanie.setAnalizyCounter($('znaki_'+ed.id),ed.id);
            });
             
             ed.onKeyUp.add(function(ed, e) {

                typowanie.setAnaliza(ed.id,ed);
                typowanie.setAnalizyCounter($('znaki_'+ed.id),ed.id);
            });
        }
    });


    

}

