
var query = '';
$(document).ready(function() {
    $('input#query').focus(function() {
      query = $(this).val();
      $(this).val('');
    });

    $('input#query').blur(function() {
      if ($(this).val() == '')
        $(this).val(query);
    });


    $('input#newsletter').click(function() {
      val = '&name=' + $('input#newsletter_name').val();
      val += '&email=' + $('input#newsletter_email').val();
      val += '&action=' + $('input#newsletter_action').val();
      val += '&captcha=' + $('input#newsletter_captcha').val();
      resp = $.ajax({
        url: "ajax.php?type=newsletter" + val,
        async: false
       }).responseText;

       if(resp == 'saved') {
         document.getElementById('confirm').style.display='none';
         document.getElementById('message_added').style.display='block';
         if($("#newsletterurl").attr("href")) {
            window.location = $("#newsletterurl").attr("href");
         }
       }else if(resp == 'removed') {
         document.getElementById('confirm').style.display='none';
         document.getElementById('message_removed').style.display='block';
       }else {
         document.getElementById('newsletter_error').innerHTML = resp
         document.getElementById('newsletter_error').style.display='block';
         document.getElementById('nameandemail').style.display='block';
         document.getElementById('confirm').style.display='none';
         img = document.getElementById('captchaimg')
         img.src = img.src + '?' + (new Date()).getTime();
         $('input#newsletter_captcha').val('');

       }


    })

    var generatstyle = $('link[href="style/index.css"]');

    $("a.print").click(function() {
      $(generatstyle).attr({href : "style/print.css"});
         setTimeout(function(){window.print()}, 100);
         $("#print_dialog").show();

         $("div#print_dialog a.back").click(function() {
           $("#print_dialog").hide();
           $(generatstyle).attr({href : "style/index.css"});
            return false;
         })

         $("div#print_dialog a.cancel").click(function() {
           $("#print_dialog").hide();
           return false;
         })

      return false;

    });

  $('div.more a.cat_view, div.more a.cat_overview').click(function(){
    if ($(this).hasClass('cat_open')) {
       $(this).removeClass('cat_open');
       $(this).addClass('cat_close');
       $(this).parent().find('ul.hidden_links').attr('class', 'hidden_links_show');

    }else {

       $(this).removeClass('cat_close');
       $(this).addClass('cat_open');
       $(this).parent().find('ul.hidden_links_show').attr('class', 'hidden_links');

    }

    return false;

  });


  $('.frm input').focus(function() {
    $(this).parent().parent().parent().children('.note').slideDown('normal');
    return false;
  });
  $('.frm input').blur(function() {
    $(this).parent().parent().parent().children('.note').slideUp('normal');
    return false;
  });
  $('.frm textarea').focus(function() {
    $(this).parent().parent().parent().children('.note').slideDown('normal');
    return false;
  });
  $('.frm textarea').blur(function() {
    $(this).parent().parent().parent().children('.note').slideUp('normal');
    return false;
  });
  
  var basehref = location.href;
  if(basehref.indexOf("#") != -1) {
    basehref = basehref.substr(0,basehref.indexOf("#"));
  }
  $("a").each(function() {
    var url = $(this).attr("href");
    if(url) {
      if(url.indexOf("#") == 0) {
        $(this).attr("href",basehref+url);
      }
    }
  });  

});




