﻿$(document).ready(function() {

    $('.image-thumb-item').click(function() {
        var img = $(this).attr("href");

        $('#image-loader').html("");
        $('#image-loader').addClass('image-loading');
        $('#image-loader').html("");
        LoadImage(img);
        return false;

    });

    function LoadImage(imageLocation) {
        var img = new Image();

        $(img).load(function() {
        $('#image-loader').removeClass('image-loading').append(img);
        }).attr('src', imageLocation);

    }

    $("#diffAddressChk").click(function() {
        $("#diffAddress").toggle("fast");
    });


    $('.wishlist-quantity').blur(function() {
        var Quantity = $(this).val();

        if (IsNumeric(Quantity)) {
            var wlItemid = $(this).parent().find('.itemId').val();
            var wlid = $('.wlid').val();

            $.get('/UpdateQuantity.aspx?q=' + Quantity + '&wliId=' + wlItemid + '&wlId=' + wlid, doSomethingWithData);
        }
        else {
            alert("You must only input Numbers in this field");
            $(this).val('1');
        }
    });

    function doSomethingWithData(data) {
        if (data == "false") {
            alert("Somthing has gone wrong, please try again");
        }
    };



    function IsNumeric(sText) {
        var ValidChars = "0123456789";
        var IsNumber = true;
        var Char;


        for (i = 0; i < sText.length && IsNumber == true; i++) {
            Char = sText.charAt(i);
            if (ValidChars.indexOf(Char) == -1) {
                IsNumber = false;
            }
        }
        return IsNumber;
    }



});
