  var HOME_URL;
  
  function set_HOME_URL(url){
    HOME_URL=url;
  }
  
  /*** membox ***/
    
  function remove_from_membox(id) {
      $.get(HOME_URL+"rq/membox.php",
            {id: id, action: "toggle",time:new Date().getTime()},
            function(data){
              fill_membox();
            }
      );
  }
  function fill_membox() {
    $("#membox").addClass('loading');
    $.get(HOME_URL+"rq/membox.php",
          {action: "get_list",time:new Date().getTime()},
          function(data) {
            $("#membox").html(data);
            $("#membox").removeClass('loading');
          }
    );
  }
  
  function clear_membox() {
      $("#control_box").addClass('loading');      
      $.get(HOME_URL+"rq/membox.php",
            {action: "clear",time:new Date().getTime()},
            function(data){
              fill_membox();
            }
      );
  }
  
  function show_membox() {
    $("#membox").toggle(500);
    fill_membox();
  }
  
  function toggle_membox(id) {
      //$("#control_box").fadeOut(100);
      $("#control_box").addClass('loading');      
      $.get(HOME_URL+"rq/membox.php",
            {id: id, action: "toggle",time:new Date().getTime()},
            function(data){
              set_box_control(id);
            }
      );
  }
  
  function set_box_control(id) {
      $.get(HOME_URL+"rq/membox.php",
            {id: id, action: "is_in",time:new Date().getTime()},
            function(data){
              if (data==1) {
                $("#control_box").text('Odebrat z oblíbených');
                $("#control_box").addClass('membox_remove');
                $("#control_box").removeClass('membox_add');
              }
              else {
                $("#control_box").text('Přidat do oblíbených');
                $("#control_box").addClass('membox_add');
                $("#control_box").removeClass('membox_remove');
              }
              $("#control_box").removeClass('loading');
            }
      );
  }  
  
  /**** source ****/
  function update_source_select() {
      var sources_txt="";
      $("#sources .item input").each(function() {          
        if(this.checked) sources_txt+= this.title+'; ';
      });
      if (!sources_txt) sources_txt = 'Všechny portály';
      $("#select_source").val(sources_txt);
  }

  function init_source() {  
    $("#select_source").click(function(){
        if($("#sources").css('display')=='none') $("#sources").fadeIn(200);
        else $("#sources").fadeOut(200);
      }
    );
    $("#sources .item input").change(function(){
      update_source_select();
    });
  }  
  
  /*** mailbox ***/
  var buff_mailbox;
  
  function show_mailbox() {
    $("#mailbox").fadeIn(200);
    buff_mailbox = $("#mailbox").html();
  }
  
  function hide_mailbox() {
    $("#mailbox").fadeOut(200, function(){
      $("#mailbox").html(buff_mailbox);
    });
     
  }
  
  function send_mailbox(id) {    
    $("#mailbox #status").addClass('loading');
    $.get(HOME_URL+"rq/mailbox.php",
      {id: id, action: "send", to_email:$("#param_to_email").val(),from_email:$("#param_from_email").val(),time:new Date().getTime()},
      function(data){
        $("#mailbox #status").html(data);
        if (!data) {
          $("#mailbox").html('Úspěšně odesláno <a href="#" class="button blue" onclick="hide_mailbox()">Zavřít</a>');
        }
        $("#mailbox #status").removeClass('loading');            
      }
    );
  }  
    




function submitenter(myfield,e)
{
var keycode;
if (window.event) keycode = window.event.keyCode;
else if (e) keycode = e.which;
else return true;
if (keycode == 13)
   {
   myfield.form.submit();
   return false;
   }
else
   return true;
}


$(document).keydown(function(event){
        if (event.keyCode == '37') {
          if($('a.nav_left').size()>0)
             window.location = $('a.nav_left').attr("href");
         }
        if (event.keyCode == '39') {
          if($('a.nav_right').size()>0)
           window.location = $('a.nav_right').attr("href");
         }
});


function activate_search(what) {
  $('#menu_i').removeClass('active');
  $('#menu_b').removeClass('active');
  
  $('#menu_'+what).addClass('active');

  $('#searchform_i').removeClass('active');
  $('#searchform_b').removeClass('active');  
  $('#searchform_'+what).addClass('active');
  
  
  

}
