﻿/// <reference path="jquery-1.4.2.min.js" />


$(document).ready(function () {
    
    //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 .ProdSmallImage").hover(
        function () {
            // clone productpopup to show it above its inner-frame with overflow 
            var node = $(this).find(".ProductPopup").clone();
            var rootElem = $(".fwRoot");
            node.appendTo(rootElem);
            node.show();

            var popupImg = $(node).find("img");
            var h = popupImg.attr("height");
            if (h > 300 || h == 0) { h = 300; }

            var myElemOffset = $(this).offset();
            node.css("left", (myElemOffset.left + 125));
            node.css("top", (myElemOffset.top - (h / 2) + 40));

            //get the pointer and position it.
            var pointer = node.find(".Pointer");
            pointer.css("top", (h / 2));
        },
        function () {
            $(".fwRoot > .ProductPopup").remove();
        }
   );

    //toggle product popup - OLD
    /*$("#ProductList .ProdSmallImage").mouseover(function () {
    //var w = $(this).width();
    //$(this).find(".ProductPopup").css("left", w + "px");
    $(this).find(".ProductPopup").show();
    });

    $("#ProductList .ProdSmallImage").mouseout(function () {
    $(this).find(".ProductPopup").hide();
    });*/

    //Show/hide quick order box
    $("#QuickOrderBox").click(function () {
        $("#QuickOrderFrame").toggle(100);
    });
    $("#LeftMenu ul li > a").click(function () {
        var ul = $(this).next();
        if (ul.css("display") == "block") {
            ul.hide(100);
        } else {
            ul.show(100);
        }
    });
});

/*function jsPage(page, e) {
    if (testQuantity() == false) {
        $("#" + e).attr("value", page);
        //$("#aspnetForm").submit();
        __doPostBack('', '');
    } 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;
}

