$(document).ready(function() {
var maxchars = 200;
$('.cartMessageText').on('keyup paste', function () {
var ID = $(this).attr('id');
$(this).val($(this).val().substring(0, maxchars));
var tlength = $(this).val().length;
remain = maxchars - parseInt(tlength);
$('#'+ID).text(remain);
});
$('#addToCart').click(function() {
AddToCart();
})
$('.cartProductRemove').click(function() {
if (confirm('Are you sure?')) {
RemoveFromCart($(this));
}
})
$('#Checkout').click(function() {
AddMessage();
})
});
function AddMessage() {
var vals = $('#cartProducts').find('textarea').serialize();
$.ajax({
type: 'POST',
url: 'https://www.cobblestoneflorist.com/Components/Product/Assets/AJAX/AddMessage.php',
dataType : 'text', // data type
data : vals,
success: function(msg){
var ret = msg.split(';;');
if (ret[0] == 1) {
setTimeout( function(){
window.location.href = 'https://www.cobblestoneflorist.com/checkout';
}, 1000);
} else {
$('.addtocart-message').html('
'+ret[1]+'
');
}
}
});
}
function RemoveFromCart(x) {
$.ajax({
type: 'POST',
url: 'https://www.cobblestoneflorist.com/Components/Product/Assets/AJAX/RemoveFromCart.php',
dataType : 'text', // data type
data : 'id='+x.attr('rel'),
success: function(msg){
var ret = msg.split(';;');
if (ret[0] == 1) {
$(x).parent().parent().hide();
if (ret[1] == 0) {
$('.notification-number').addClass('number0');
} else {
$('.notification-number').removeClass('number0');
}
$('#currentTotal').html(ret[2]);
$('.notification-number').html(ret[1]);
setTimeout( function(){
window.location.href = 'https://www.cobblestoneflorist.com/cart';
}, 500);
} else {
//console.log(ret[1])
//$('.addtocart-message').html(''+ret[1]+'
');
}
}
});
}
function AddToCart() {
$.ajax({
type: 'POST',
url: 'https://www.cobblestoneflorist.com/Components/Product/Assets/AJAX/AddToCart.php',
dataType : 'text', // data type
data : 'quantity='+$('#Quantity').val()+'&id='+$('#addToCart').val(),
success: function(msg){
var ret = msg.split(':');
if (ret[0] == 1) {
$('.notification-number').removeClass('number0');
$('.notification-number').html(ret[1]);
$('.addtocart-message').html('');
} else {
console.log(ret[1])
$('.addtocart-message').html(''+ret[1]+'
');
}
}
});
}