﻿/// <reference path="http://wwwdev.4imprint.com/_JS/jquery/jquery-vsdoc.js" />
$(function() {
    $.ajaxSetup( { timeout: 15000 } ); 
    $('#addCpnPnl').hide().removeClass('hide');
    
    $('.deleteBtn').click(function() {
        return confirm("Are you sure you want to remove this item from your shopping cart?");
    });
    
    $('.detailsBtn').click(function() {
        var clickPos = $(this).position();
        var LineID = $(this).siblings('input.CartLineID').val();
        $('form').append('<div id="cartDetailsPop"></div>');
        $('#cartDetailsPop')
            .html('<div id="loadingImg" class="cartDetailsLoading"><img src="/CONTENT/Common%20to%20All/IMAGES/Product/loadingprogressbar.gif" /></div>')
            .css({ position: 'absolute', left: clickPos.left, top: clickPos.top})
            .fadeIn()
            .load('/cart/ajaxcartitemdetails.aspx', { ID : LineID }, function() {
                $('#loadingImg').addClass('hide');
                $('.cartDetailsLine:first').css('padding-bottom', '20px');
            });
        return false;
    });
    
    $('.updateBtn').click(function() {
        var TextQty = $(this).parent().siblings('.cartItemDetailsCol').children('.txtQty');
        var MinQty = $(this).siblings('.hdnMinQty');
        if(IsNumeric(TextQty.val())) {
            if(parseInt(TextQty.val()) >= parseInt(MinQty.val())) {
                return true;
            } else {
                alert("Unable to update the order - minimum order quantity is : " + MinQty.val());
                TextQty.focus();
                return false;
            }
        } else {
            alert("Invalid Quantity - Please enter a numeric value.");
            TextQty.focus();
            return false;
        }
    });
    
    $('.clearCart').click(function() {
        return confirm("This will remove all the products currently stored in your cart.\n\nClick Ok to delete, otherwise click Cancel.");
    });
    
    $('.cpnCodeBtn').click(function() {
        $(this).fadeOut(function() { 
            $('#addCpnPnl').fadeIn();
        });
        return false;
    });
});

function IsNumeric(strString) {
    var strValidChars = "0123456789";
    var strChar;
    var blnResult = true;

    for (i = 0; i < strString.length && blnResult == true; i++) {
        strChar = strString.charAt(i);
        if (strValidChars.indexOf(strChar) == -1) {
            blnResult = false;
        }
    }
    return blnResult;
}



