﻿

$(document).ready(function() {

    //submit search on enter
    $("#SearchField").keypress(function(e) {
        alert("test");
        return false;
    });

    //Highlight product table rows
    $("#uxProductTable tr:odd").addClass("Grey");
    $("#shoppingBasket tr:odd").addClass("Grey");

    //remove or add default input text on click or blur
    $("#TopControls input").click(function() {
        if ($(this).val() == $(this).attr("title")) {
            $(this).val("");
            $(this).removeClass("Grey");
        }
    });

    $("#TopControls input").blur(function() {
        if ($(this).val() == "") {
            $(this).val($(this).attr("title"));
            $(this).addClass("Grey")
        }
    });


    //toggle product popup
    $("#ProductList .Item").mouseover(function() {
        var w = $(this).width();
        $(this).find(".ProductPopup").css("left", w + "px");
        $(this).find(".ProductPopup").show();
    });


    $("#ProductList .Item").mouseout(function() {
        $(this).find(".ProductPopup").hide();
    });


});

function jsPage(page, e) {
    if (testQuantity() == false) {
        $("#" + e).attr("value", page);
        $("#aspnetForm").submit();
    } else {
        alert("Du har lagt inn antall på et eller flere produkter! Trykk bestill før du går til ny side!");
    }
}

function testQuantity() {
    var hasValue = false;
    $("#uxProductTable").find(".quantity").each(function() {
        var quantity = $(this).val();
        if (quantity > 0) {
            hasValue = true;
        }
    });
    return hasValue;
}

