var body_overflow;
var cookie_ordinace;

$(function(){
  body_overflow = $('body').css('overflow');

  //-- vyhledat-hlavicka
  vyhledat_hlavicka_bg();
  $('#vyhledat-hlavicka').focus(function(){$('#vyhledat-hlavicka').attr('class','text-vyhledat-aktivni');});
  $('#vyhledat-hlavicka').blur(function(){vyhledat_hlavicka_bg();});
  $('#vyhledat-hlavicka').change(function(){vyhledat_hlavicka_bg();});
  
  //-- registrace adresy
  registrace_synchronizace_adres();
  $('#fakulice').change(function(){registrace_synchronizace_adres();});
  $('#fakobec').change(function(){registrace_synchronizace_adres();}); 
  $('#fakpsc').change(function(){registrace_synchronizace_adres();}); 
  $('#fakzeme').change(function(){registrace_synchronizace_adres();});  
  $('#dodstejna').change(function(){registrace_synchronizace_adres();}).click(function(){registrace_synchronizace_adres();});
  
  $('a.lightbox').lightBox({containerResizeSpeed: 10,
                            txtImage: 'Obrázek',
                            txtOf: 'z',
                            imageBlank: 'img/lightbox/blank.gif',
                            imageBtnPrev: 'img/lightbox/prev.gif',
                            imageBtnNext: 'img/lightbox/next.gif',
                            imageBtnClose: 'img/lightbox/close.gif',
                            imageLoading: 'img/lightbox/loading.gif'});
  
  
  get_box_ordinace();
  $('#ordinace_ano').click(function(){akce_box_ordinace('ano');});
  $('#ordinace_ne').click(function(){akce_box_ordinace('ne');});
  
});

$(window).load(function(){
  if(!cookie_ordinace){
    $(window).scrollTop(0);
  }
});

function vyhledat_hlavicka_bg(){
  var q_text = $('#vyhledat-hlavicka').val();
  if(q_text){
    $('#vyhledat-hlavicka').attr('class','text-vyhledat-aktivni');
  } else {
    $('#vyhledat-hlavicka').attr('class','text-vyhledat');
  }
}

function registrace_synchronizace_adres(){
  if($('#dodstejna').attr('checked')){
    $('#dodulice').val($('#fakulice').val());
    $('#dodobec').val($('#fakobec').val());
    $('#dodpsc').val($('#fakpsc').val());
    $('#dodzeme').val($('#fakzeme').val());
    
    $('#dodulice').attr('disabled',true).attr('class','text povinne readonly');
    $('#dodobec').attr('disabled',true).attr('class','text povinne readonly');
    $('#dodpsc').attr('disabled',true).attr('class','text povinne readonly');
    $('#dodzeme').attr('disabled',true).attr('class','text povinne readonly');
  } else {
    $('#dodulice').attr('disabled',false).attr('class','text povinne');
    $('#dodobec').attr('disabled',false).attr('class','text povinne');
    $('#dodpsc').attr('disabled',false).attr('class','text povinne');
    $('#dodzeme').attr('disabled',false).attr('class','text povinne');
  }
}

function get_box_ordinace(){
  if(!cookie_ordinace){
    return;
  }
  var html;
  
  box_shutter(true);
  
  html = ''+
    '<div id="form_ordinace">'+
    '<p class="text">Dobrý den, vítejte na stránkách e-shopu pro praktické lékaře a jejich ordinace. Pokud jste lékař či z ordinace lékaře, pokračujte tlačítkem <b>ANO</b>. V opačném případě zvolte <b>NE</b> a budete přesměrováni na web <a href="http://www.martekmedical.cz/">www.martekmedical.cz</a>, kde se můžete zaregistrovat.</p>'+
    '<p class="button"><input type="button" id="ordinace_ano" class="button" value="ANO" /><input type="button" id="ordinace_ne" class="button" value="NE" /></p>'+
    '</div>';
  $('body').append(html);
  $('form_ordinace').css('display','block');
  return;   
}

function akce_box_ordinace(akce){
  if(akce == 'ano'){
    //$.get("/_test/index.php", {'ordinace': 1});
    
  $.ajax({
    type: "GET",
    url: window.location.href,
    data : ({ordinace : '1' }),
    async: false,
    cache: false,
    success: function(html){
      box_shutter(false);
      $('#form_ordinace').css('display','none');
    }
  });
    

  } else {
    location.href = 'https://www.martekmedical.cz/registrace.php';
  }
  return;   
} 

function box_shutter(active){
  if(!$('#shutter').length){
    $('body').append('<div id="shutter"></div>');
  } 
  
  if(active){
    $('#shutter').css('display','block');
    $('body').css('overflow','hidden'); 
  } else {
    $('#shutter').css('display','none');
    $('body').css('overflow',body_overflow);
  }
  return;   
}
