//**Contants**
var SEARCH_PAGE_URL = "/gruppen-as/search.aspx";


//**Retreive query string parameters**
var urlParams = {};
(function () {
    var e,
        a = /\+/g,  // Regex for replacing addition symbol with a space
        r = /([^&=]+)=?([^&]*)/g,
        d = function (s) { return decodeURIComponent(s.replace(a, " ")); },
        q = window.location.search.substring(1);

    while (e = r.exec(q))
       urlParams[d(e[1])] = d(e[2]);
})();


//**Search**
var _currentSearch = urlParams["q"];
function doSearch(){
  var q = encodeURI($("#search")[0].value);
  if (q.length > 0){
    document.location.href = SEARCH_PAGE_URL + "?q=" + q;
  }
  return false;
}


$(document).ready(function(){   
  
  if (_currentSearch != null && _currentSearch.length > 0){
    $("#search")[0].value = _currentSearch;
    $("#search").focus();
  }
  
  $("#search").bind("keypress", function(e){
     var code = (e.keyCode ? e.keyCode : e.which);
     if(code == 13) { //Enter keycode
         return doSearch();
     }
  });
  
  $("#search").focus(function(){
    if (_currentSearch == null || _currentSearch.length <= 0){
      this.value = "";
    }
  });
  
  $(".elektroarbeid input:eq(1)").click(function(){
    if($(this).is(':checked')) {
      $(".antalldownlights").slideDown();
    }
    else {
      $(".antalldownlights").slideUp();
    }
  });
  
  $(".elektroarbeid input:eq(3)").click(function(){
    if($(this).is(':checked')) {
      $(".antallstikkontakter").slideDown();
    }
    else {
      $(".antallstikkontakter").slideUp();
    }
  });

});

   

