function search(page) {
    var input = $("#searchfield").val();
    var search = "?q=" + encodeURIComponent(input);
    var url = 'http://' + page + search;
    window.location.href = url;
    return false;
}
function tab(id) {
    $(".tabTitle").removeClass("selected");
    $(".tab").hide();
    $("#" + id).show();
    $("#t" + id).addClass("selected");
}

function closePopup() {
  $('#readMoreContainer').hide();
  $("#bgContainer").hide();
  $('#BigMapContainer').hide()
}
function showPopupBg() {
  var width = document.documentElement.clientWidth;
  $("#bgContainer").css("width", width);
  $("#bgContainer").css("height", $(document).height());
  $("#bgContainer").css("opacity", 0.7);
  $("#bgContainer").show();
}
function openInformation(id) {
  $('#BigMapContainer').hide();
  showPopupBg();

  var width = document.documentElement.clientWidth;
  $("#readMoreContainer").show();
  $("#readMoreContainer").css("left", ((width - 632) / 2));
  $("#readMoreContainer").css("top", $(window).scrollTop() + 30);

  $("#readMoreContainer .content").html($("#" + id).html());

  return false;
}

function addBasket(urlHdl, urlBasket, code, qty) {
    if (qty==undefined) qty = $("#qty_" + code).val();
    if (!(qty.toString().search(/^[0-9]+$/) == 0)) {
        alert("Vous devez saisir une quantité valide.");
        return;
    }

    if (qty > 10) {
			if (!confirm("Attention vous avez saisi une quantité supérieure à 10, êtes-vous sûr de vouloir continuer ?"))
				return;
    }

    $.post(
        urlHdl + "/Basket.ashx",
        { "cmd":"add","code":code,"qty":qty },
        function(rsp) {
            if (rsp) {
                if (rsp.err) {
                    alert(rsp.err);
                } else {
                    if (rsp.msg) {
                        var mmsg=rsp.msg;
                        if (rsp.qty > 0) mmsg += '<br/><br/><a href="' + urlBasket + '/">Valider mon panier</a>';
                        ShowMascot(mmsg);
                    }
                }
            }
        }, "json");
}

$(document).ready(function () {
  $(window).resize(function () {
    var width = document.documentElement.clientWidth;
    $("#bgContainer").css("width", width);
    $("#bgContainer").css("height", $(document).height());
  });

  $("#bgContainer").click(function () {
    closePopup();
  });
});

