/* data podczas zakladania firmy */
$(
  function()
    {
    $("#data").datepicker(
                          {
                            changeMonth: true,
                            changeYear: true,
                            dateFormat : 'yy-mm-dd',
                            dayNamesMin: ['Po', 'Wt', 'Śr', 'Cz', 'Pt', 'So', 'Nd'],
                            monthNamesShort: ['Styczeń','Luty','Marzec','Kwiecień','Maj',
                                              'Czerwiec','Lipiec','Sierpień','Wrzesień','Październik',
                                              'Listopad','Grudzień']
                          });
    setInterval(animacja, 4000,'#status_naprawy')
    }
  );

animacja = function(pole)
{
    $(pole).animate({"opacity":0.4},'slow');
    $(pole).animate({"opacity":1},'slow');
}

$(
 function()
 {
   $("#firma").click(
          function(){
                    if( $('input:checked').length > 0)
                      {
                         $("#firma_nazwa").removeAttr("disabled");
                      }
                    else
                      {
                         $("#firma_nazwa").attr("disabled",true);
                      }
                    }
                    ); $("textarea").css("resize","none")
 }
 );

pokaz = function(obiekt)
  {
      $(obiekt).next().toggle(0);
  }

schowaj = function(obiekt)
  {
      $(obiekt).hide(0);
  }

walidacja = function()
{
  var i = 0;

  if($("#regulamin_form:checked").val() == null)
    {
      alert('Brak akceptacji regulaminu');
      i++;
    }
    
  if($("#usterka #imie").val().length < 4)
    {
      $("#usterka #imie").css({"background":"#f8b8b8"})
      i++;
    }
  else
    {
      $("#usterka #imie").css({"background":""})
    }

  if($("#usterka #nazwisko").val().length < 6)
    {
      $("#usterka #nazwisko").css({"background":"#f8b8b8"})
      i++;
    }
   else
    {
      $("#usterka #nazwisko").css({"background":""})
    }
    
  if($("#usterka #tel").val().length < 9)
    {
      $("#usterka #tel").css({"background":"#f8b8b8"})
      i++;
    }
   else
    {
      $("#usterka #tel").css({"background":""})
    }
  
  if($("#usterka #imei").val().length < 9)
    {
      $("#usterka #imei").css({"background":"#f8b8b8"})
      i++;
    }
   else
    {
      $("#usterka #imei").css({"background":""})
    }

  if($("#usterka #model").val().length < 2)
    {
      $("#usterka #model").css({"background":"#f8b8b8"})
      i++;
    }
   else
    {
      $("#usterka #model").css({"background":""})
    }

  if($("#usterka #data").val().length < 7)
    {
      $("#usterka #data").css({"background":"#f8b8b8"})
      i++;
    }
   else
    {
      $("#usterka #data").css({"background":""})
    }

  if(i > 0)
    {
      alert('Formularz posiada błędy');
      return false;
    }

}

datka = function(pole)
{
  $(pole).datepicker(
                          {
                            changeMonth: true,
                            changeYear: true,
                            dateFormat : 'yy-mm-dd',
                            dayNamesMin: ['Po', 'Wt', 'Śr', 'Cz', 'Pt', 'So', 'Nd'],
                            monthNamesShort: ['Styczeń','Luty','Marzec','Kwiecień','Maj',
                                              'Czerwiec','Lipiec','Sierpień','Wrzesień','Październik',
                                              'Listopad','Grudzień']
                          });
}


function ajax_post(adres,typ_zwracany,argumenty,pole_wyswietlania)
{
    $.ajax(
      {
      type: "POST",
      url: adres,
      data: argumenty,
      success: function(msg)
              {
                //$(pole_wyswietlania).hide(400).show(400);
                $(pole_wyswietlania).effect('highlight');
                $(pole_wyswietlania).html(msg);
                $(pole_wyswietlania).show("slow");
                //console.log('Operacja zakonczona sukcesem');
              },
      complete: function(msg)
              {
                //console.log('zakonczono pobieranie: '+msg);
              },
      error: function(msg)
              {
                //console.log('blad podczas operacji: '+msg);
                alert( " blad podczas wykonywania operacji");
              },
      beforeSend: function(msg)
              {
                $(pole_wyswietlania).html('<img alt="Ładowanie treści..." src="/grafika/loading.gif" align="center" />');
                //console.log('Wyslano operacje na serwer: ' + msg );
              },
      start: function(msg)
              {
                //console.log('Zainicjowano ajax: ' + msg );
              },
      stop: function(msg)
              {
                //console.log('Zatrzymano ajax: ' + msg );
              },
      dataType: typ_zwracany,
      async: true
      }
    );
}
