window.onload = (function() {
  if ($("#SearchField") != null) {
      swapValue = [];
      $("#SearchField").each(function(i) {
          swapValue[i] = $(this).val();
          $(this).focus(function() {
              if ($(this).val() == swapValue[i]) {
                  $(this).val("");
              }
              $(this).addClass("focus");
          }).blur(function() {
              if ($.trim($(this).val()) == "") {
                  $(this).val(swapValue[i]);
                  $(this).removeClass("focus");
              }
          });
      });
  }
  
if($("#prismedloeb") != null) {
  prisloebUpdate();
  }
});

function prisloebUpdate() {
  var da = new Date().getTime();
  $.ajax({
    url: '/prices?da='+da,
      dataType: 'json',
      complete: function(data) {
        jsonelm = eval("("+data.responseText+")");
        tbody = $("#prismedloeb table > tbody");
        tbody.empty();
        $(jsonelm).each(function(a, b) {
          dollar = b.Lys*1;
          if(a % 2 == 0) trClass = ' class = "odd"';
          else trClass = '';
          html = '<tr'+trClass+'><td>'+roundNumber(b.Lys, 2)+'</td><td>'+b.Price+'</td><td>'+b.Number+'</td><td>'+b.Type+'</td><td>'+b.Str+'</td></tr>';
          tbody.append(html);
        });
        setTimeout('prisloebUpdate()', 9000);
      }
    });
}

function roundNumber(number,decimal_points) {
  if(!decimal_points) return Math.round(number);
  if(number == 0) {
    var decimals = "";
    for(var i=0;i<decimal_points;i++) decimals += "0";
    return "0."+decimals;
  }

  var exponent = Math.pow(10,decimal_points);
  var num = Math.round((number * exponent)).toString();
  return num.slice(0,-1*decimal_points) + "." + num.slice(-1*decimal_points)
}

$(window).load(function() {
    $('#searchbutton').click(function() {
var formen = $('.rte form');
        formen.attr('method', 'get');
        formen.submit();
    });
});
function foderforbrugChangePage(page) {
var formen = $('.rte form');
  $('#page').val(page);
  formen.attr('method', 'get');
  formen.submit();
}

