Navy/Marine Corps Medal Ribbon, Presented to US Navy and Marine Corps.
curInventory) {
// Whoops! Not enough inventory!
var s = (curInventory==1)? '':'s';
alert('Sorry, but we only have '+curInventory+' item'+s+' in stock. You may only choose up to that many items.');
$('#qty').val(curInventory).focus();
return false;
}
// Just a small "are you sure"
if(quantity >= 99) {
if(!confirm('Are you sure you want this quantity?')) {
$('#qty').val(1);
return false;
}
}
// Submit form if everything is good
return true;
} else { // Invalid!
alert('Please select a value for each product option.');
invalidField.focus();
return false;
}
});
// Image swap
function updateProduct() {
$.post('https://www.armynavywisconsin.com/products/compute_price', $('#options-form').serialize(), function(data) {
curInventory = Number(data.inventory);
// Defaults
$('.add-cart-btn').show();
$('.stock-amount').show();
$('.quantity-field').show();
// No Tracking
if (data.inventory === '') {
curInventory = false;
$('.stock-amount').hide();
// Out of Stock
} else if (data.inventory == 0) {
$('.stock-amount span').text('Out Of Stock');
$('.add-cart-btn').hide();
$('.quantity-field').hide();
// Stock Available
} else {
$('.stock-amount span').text(data.inventory);
}
if(data.image_url) {
$('.main-img img').attr('src', data.image_url);
$('.main-img a').attr('href', data.image_url).css('background-image', 'url('+data.image_url+')');
}
if (data.price) {
// Pad with zeros
var cents = data.price.toString().split('.'); // Note: toString() needed for IE
if (cents[1]==null) data.price += '.00'; // No cents at all
else if (cents[1].length == 1) data.price += '0'; // Divisible by ten
var formatter = new Intl.NumberFormat('en-US', {
style: 'currency',
currency: 'USD',
});
$('span.price').html(formatter.format(data.price));
}
// If any option hasn't yet been set, we should NOT show the "out of stock" message
var notSelected = false;
var options = $('#options-form select');
if (options.length>1) for (var i=0; iRemove from Wish List');
$('#wishStatus').val(data.inWishlist);
} else {
$('#wishlist').html('Add to Wish List');
$('#wishStatus').val('no');
}
} else {
$('#wishlist').hide();
$('#wishlistStatus').val('no');
}
}, 'json');
}
$('#options-form select').change(function() {
updateProduct();
});
/*
$('#options-form select').change(function() {
options = [];
$('#options-form select').each(function() {
//options = $(this).attr('id');
console.log($(this).attr('id'));
//selectedOption = $(this).children('option:selected').attr('value');
console.log($(this).children('option:selected').attr('value'));
options[$(this).attr('id')] = $(this).children('option:selected').attr('value');
});
console.log(options)
console.log('^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^');
});
*/
//$('#options-form select').change(function() {
/*
$.post('https://www.armynavywisconsin.com/Ajax/check_quantity', $('#options-form').serialize(), function(data) {
if(data.inventory_count) {
console.log(data.inventory_count);
}
});
*/
// });
updateProduct();
$('#wishlist').click(function() {
// See if there is an index id (or "No" for not in wishlist yet)
var inWishlist = $('#wishStatus').val();
// If item is not in wishlist yet.
if (inWishlist == 'no') {
$.post('https://www.armynavywisconsin.com/wishlists/add_item', $('#options-form').serialize(), function(data) {
if (data.success) {
$('#wishMsg').fadeIn();
$('#wishMsg').html('✓ Added to Wish List')
$('#wishStatus').val(data.indexId);
$('#wishlist').html('Remove from Wish List');
setTimeout("hideWishMsg()", 3000);
} else {
alert('Could not add item to Wish List.');
}
}, 'json');
} else {
// Remove Item based off Index ID (inWishlist)
$.post('https://www.armynavywisconsin.com/wishlists/remove_item/'+inWishlist+'/true', function(data) {
$('#wishMsg').fadeIn();
$('#wishMsg').html('X Removed from Wish List');
$('#wishStatus').val('no');
$('#wishlist').html('Add to Wish List');
setTimeout("hideWishMsg()", 3000);
}, 'json');
}
});
// Hide the wishlist msg
function hideWishMsg() {
$('#wishMsg').fadeOut();
}
// check currInventory vs quantity wanted
/*
$('#options-form').submit(function() {
$currInventory = $('#inventoryAvailable').val();
$quantityWanted = $('#qty').val();
// Still have to check if the value of currInventory is an empty string or not.
if($quantityWanted > $currInventory) {
alert('We are sorry, there are only '+$currInventory+' left in stock.');
}
});
*/