this.tooltip = function(){
  var tt = '';
  xOffset = -15;//90;//80;
  yOffset = -80;//-95;
  $("img.tooltip").hover(function(e){
    var x = e.pageX;
    var y = e.pageY;
    $t = $(this);
    tt = $t.attr('data');//alert(tt);
    $('body').append("<div id='tooltiptop'><div id='tooltipbottom'><div id='tooltipin'><p>" + tt + "</p></div></div></div>");
    $("#tooltiptop").offset({
      top: y - 10,
      left: x + 5
    }).show();
    // $("#tooltip").get(0).style.removeAttribute('filter');
  }, function(e){
    // $("#tooltip").hide();
    $("#tooltiptop").remove();
  });
};
$(document).ready(function(){
  tooltip();
  // specializovane obchody
  $('form#hlasovaniForm h2.specTitle').click(function(){
    $(this).next('ol.specObchod').toggle();
  });
  //toggle info o hlavni cene
  $('#cenainfo').click(function(e){
    e.preventDefault();
    $('p#hideinfo').toggle();
  });
  // zmena text input / empty radio buttons
  $('input.volny').focus(function(){
    $thisEl = $(this);
    
    // alert('volny change !!');
   // if ($thisEl.val() != '') {
      var kategvolny = $thisEl.attr('name');
      var kateg = kategvolny.substring(1); //alert(kateg);
      //$('input[@name='+kateg+':checked]').attr('checked', false);
      $('fieldset#f' + kateg + ' input[@type=radio]:checked').prop('checked', false);
   // }
  });
  // click na radio - empty text box
  $(':radio').click(function(){
    $thisEl = $(this);
    
    // alert('volny change !!');
    if ($thisEl.val()) {
      var kateg = $thisEl.attr('name');//alert(kateg);
      //$('input[@name='+kateg+':checked]').attr('checked', false);
      $('fieldset#f' + kateg + ' input.volny').val('');
    }
  });
  // SPECIALNI OBCHODY zmena text input / empty radio buttons
  $('div#specObch input.volny').focusin(function(){
   // jsou checked radios ?
     $thisEl = $(this);
      var necospec1 = 0;
    var volnyspec1 = 0;
     $('div#specObch :radio').each(function(i){
    if ($(this).prop('checked') == true) {
        necospec1 = necospec1 + 1;
      }
    });

    if (necospec1 >= 1) {
      alert('V kategorii 11A-11F lze dát hlas jen jednomu obchodu - dříve přidělený hlas v této kategorii bude vymazán.');
      $('div#specObch input.[@type=radio]:checked').prop('checked', false);
     // $thisEl.prop('checked', true);
      // $('div#specObch input.volny').val('');
    }
    else {
      // zkontrolovatvolny obchod
      $('div#specObch input.volny').each(function(i){

    if ($(this).val() != '') {
          volnyspec1 = 1;
        }
      });

    if (volnyspec1 == 1) {
        alert('V kategorii 11A-11F lze dát hlas jen jednomu obchodu - dříve přidělený hlas v této kategorii bude vymazán.');
        $('div#specObch input.volny').val('');
        //$thisEl.prop('checked', true);
      }
    } // konec else kontrola volneho obchodu

  });
  // SPECIALNI OBCHODY click na radio - empty text box
  $('div#specObch :radio').click(function(){
    $thisEl = $(this);
    var necospec = 0;
    var volnyspec = 0;

    $('div#specObch :radio').each(function(i){
    if ($(this).prop('checked') == true) {
        necospec = necospec + 1;
      }
    });

    if (necospec > 1) {
      alert('V kategorii 11A-11F lze dát hlas jen jednomu obchodu - dříve přidělený hlas v této kategorii bude vymazán.');
      $('div#specObch input.[@type=radio]:checked').prop('checked', false);
      $thisEl.prop('checked', true);
      // $('div#specObch input.volny').val('');
    }
    else {
      // zkontrolovatvolny obchod
      $('div#specObch input.volny').each(function(i){

    if ($(this).val() != '') {
          volnyspec = 1;//alert(volnyspec);
        }
      });

    if (volnyspec == 1) {
        alert('V kategorii 11A-11F lze dát hlas jen jednomu obchodu - dříve přidělený hlas v této kategorii bude vymazán.');
        $thisEl.prop('checked', true);
        $('div#specObch input.volny').val('');//alert(volnyspec);
      }
    } // konec else kontrola volneho obchodu
   });
  // --- FORM SUBMIT  ---nelze odeslat formular, aniz je alespon neco vyplnene
  var neco = 0;
  $('#hlasovaniForm').submit(function(e){
    $('#klientErrorText').removeClass('klientErrorClass').html('');
    $('#captcha_error').removeClass('klientErrorClass').html('');
    $('#hlasovaniForm input.email').next('div').remove();
    // NEJPRVE  KONTROLA EMAIL
    $('#hlasovaniForm input.email').each(function(){
      //  if($(this).next('span').length < 1){
      var inputVal = $(this).val(); //alert(inputVal);
      var emailReg = /^([\w-\.]+@([\w-]+\.)+[\w-]{2,4})?$/;

if (!emailReg.test(inputVal) || inputVal == '') {
        $(this).after('<div class="klientErrorClass">Zadejte prosím správný email.</div>');
        scroll(0, 200);

        return false;
      }
    });
    neco = 0;
    //e.preventDefault();
    $('#hlasovaniForm input.volny').each(function(i){
      
if ($(this).val() != '') {
        neco = 1;
      }
    });
    $('#hlasovaniForm input[@type=radio]:checked').each(function(i){
      
if ($(this).val()) {
        neco = 1;
      }
    });
    
if (neco == 0) {
      e.preventDefault();
      // alert('Completely empty !!');
      scroll(0, 200);
      $('#klientErrorText').html('Dejte prosím hlas alespoň jednomu obchodníkovi !<br>').addClass('klientErrorClass');
    }
    else {
      
      // je vyplnena CAPTCHA ?
      if ($('#captcha_code').val() == '') {
        e.preventDefault();
        $('#captcha_error').html('Chybí kontrolní kód !').addClass('klientErrorClass');
        var htmlStr = $('#klientErrorText').html();
        
if (htmlStr != '') {
          $('#klientErrorText').html(htmlStr + '<br>Opište kontrolní kód na konci formuláře !');
        }
        else {
          $('#klientErrorText').html('Opište kontrolní kód na konci formuláře !<br>').addClass('klientErrorClass');
        }
        scroll(0, 200); //JE&nbsp;TO&nbsp;OK
      }
      else {
        // captcha OK, ostatni OK = VSE OK
        //return true;
      }
    }
  }); // konec submit hlasovani
  // ------ SUBMIT ANKETA ---------------
  $('form#anketaForm').submit(function(e){
    //e.preventDefault();
    var chyby = 0;
    $('#celkovechyby').html('');
    $('#anketaForm input').each(function(){
      $(this).next('span').remove();
    });
    $('#anketaForm input.characters').each(function(){
      
if ($(this).val().length < 3) {
        $(this).after('<span class="error">Zadejte prosím korektně povinné pole.</span>');
        chyby = 1;
      }
    });
    $('#anketaForm input.numeric').each(function(){
      
if ($(this).next('span').length < 1) {
        var inputVal = $(this).val();
        var numericReg = /^\d*[0-9](|.\d*[0-9]|,\d*[0-9])?$/;
        
if (!numericReg.test(inputVal)) {
          $(this).after('<span class="error">Zadejte prosím pouze čísla.</span>');
          chyby = 1;
        }
      }
    }); // konec numeric
    /// numeric a nepovinne
    $('#anketaForm input.numeric1').each(function(){
      
if ($(this).next('span').length < 1) {
        var inputVal = $(this).val();
        
if (inputVal != '') {
          var numericReg = /^\d*[0-9](|.\d*[0-9]|,\d*[0-9])?$/;
          
if (!numericReg.test(inputVal)) {
            $(this).after('<span class="error">Zadejte prosím pouze čísla.</span>');
            chyby = 1;
          }
          ///if inputVal !=''
        }
      }
    }); // konec numeric
    // ----------- email ------------------------
    $('#anketaForm input.email').each(function(){
      
if ($(this).next('span').length < 1) {
        var inputVal = $(this).val();
        var emailReg = /^([\w-\.]+@([\w-]+\.)+[\w-]{2,4})?$/;
        
if (!emailReg.test(inputVal)) {
          $(this).after('<span class="error">Zadejte prosím správný email.</span>');
          chyby = 1;
        }
      }
    });
    
if ($('#souhlas').prop('checked')) {
      $('#souhlas_error').text('');
      // alert('je');
      //chyby = 1;
      // $('#souhlas_error').html('<br><span class="error">Potvrďte prosím souhlas s pravidly.</span>');
    }
    else {
      //alert('nic');
      $('#souhlas_error').html('<span class="error">Potvrďte prosím souhlas s pravidly.</span>');
      chyby = 1;
    }
    
if (chyby == 1) {
      //alert(chyby);
      $('#klientErrorText').html('<span class="error">Opravte prosím chyby ve formuláři.</span>').addClass('klientErrorClass');
      scroll(0, 200);
      
      return false;
    }
    else { //alert(chyby);
      //$("#celkovechyby").html('<span class="error">Form Accepted</span>');
    return true; }
  });
  // -- end doc ready
});

