function Trim (tekst)
   {
    var p=0;
    while ((p < tekst.length) && (tekst.charAt(p)==" "))
     { p++; }
    if (p==tekst.length)
      return "";
    var k = tekst.length -1;
    while ((k>=0) && (tekst.charAt(k)==" "))
     {k--; }
    return tekst.substring (p, k+1);
   }

  function test_nazwisko (pole)
   {
    pole.value=Trim (pole.value);
    if (pole.value =="")
     {
      alert ("Podaj nazwisko !"); pole.select();pole.focus();
      return true;
     }
    else
      return false;
   }
    
  function test_imie (pole)
   {
    pole.value=Trim (pole.value);
    if (pole.value =="")
     {
      alert ("Podaj imię !"); pole.select();pole.focus(); return true;
     }
    else
      return false;
   }
    
  function test_email(pole)
   {
    pole.value=Trim(pole.value);
    if ((pole.value.indexOf("@",0)==-1) || (pole.value.indexOf(".",0)==-1))
           {
      alert ("Wprowadź właściwy adres e-mail!"); pole.select(); pole.focus(); return true;
     }
    else
      return false;
   }
    
    function test_all(form) 
    {
        if (test_imie(form.imie) || test_nazwisko(form.nazwisko) || test_email(form.email))
        {
            return;
        }
        else
        {
            form.submit();
            document.getElementById('box_send_bet').innerHTML = '<img src="/_img/loading-small.gif" /> wysyłanie typowania';          
        }
    }
    
    function test_znajdz(form) {
       if (test_email(form.email_stat))
          return;
       else
          form.submit();
    }
      

    function test_pokaz_klasyf(form) {
       if (form.email_klasyf.value!='' && test_email(form.email_klasyf))
          return;
       else
          form.submit();
    }


function showTableSport(id_dysc, id_ligi, sezon, kolejka, rodzaj, target)
{
  $.get("/_ajax/get_tabela.php?id_dysc="+id_dysc+"&id_ligi="+id_ligi+"&sezon="+sezon+"&kolejka="+kolejka+"&rodzaj="+rodzaj,function(data){
      $('#'+target).html(data)
  });  
}

function addNoteSport(id_osoby, ocena0, ocena1, ocena2, id_zaklady, target)
{
  $.ajax({
        type: 'POST',
        url: "/_ajax/add_note.php",
        data : {
            "id_osoby":id_osoby,
            "ocena0":ocena0,
            "ocena_forma":ocena1,
            "ocena_zaangazowanie":ocena2,
            "id_zaklady":id_zaklady
        },
        beforeSend : function(){
            $('#'+target).css('cursor','wait');
        },
        success : function(data, textStatus, jqXHR){
            $('#'+target).html(data);
        },
        complete : function(){
           $('#'+target).css('cursor','default'); 
        }
  });
}

function zmien_sezon(adr)
  {
    sezon = document.getElementById('SEL_SEZ').value;
    if (sezon != "")
      {
        adr = adr+"?sezon="+sezon+"#zakladki_sport_top";
      }
    window.location.href = adr;
  }

function okno_typuj_klasyfikacja() 
  {
    url = "http://sport.trojmiasto.pl/klasyfikacja.php";
    var Win = window.open(url,"displayOknoKlasyfikacja","width=712,height=600,left=40,top=30,resizable=0,scrollbars=yes,menubar=no");
  } 
    


