// ajax call to add item to cart...
function ajaxAddToCart(sku, itemSku, sizeId, colorId, qty, price, points, discount, discountflag){
	$("#add2Cart").css("opacity", "0.4");
	var colorN = $('#color').val() ? $('#color').val() : "";
	var sizeN  = $('#size').val() ? $('#size').val() :"";
		
	var qtyN  	= qty ? qty : ($('#qty').val() ? $('#qty').val() : 1);
	$.ajax({
		url: "/shopaction.php",
		data: "action=addtocart&sku=" + sku + "&itemSku=" + itemSku + "&size=" + sizeN + "&color=" + colorN + "&qty=" + qtyN + "&price=" + price + "&points=" + points + "&discount=" + discount + "&discountflag=" + discountflag,
		success: function(msg){
			$("#dialog").attr("title", "Your cart has been updated");
			$("#dialog").html("Your product has been added to the cart <br/><br/> <input type='button' class='dia_continueshopping ui-corner-all ui-widget-header' value='Continue Shopping' onclick='$(\".ui-dialog-titlebar-close\").click();' /> <input type='button' class='dia_checkout ui-corner-all ui-widget-header' value='Checkout' onclick='window.location=\"/action/cart\"' />");
			$("#dialog").dialog();
			updateFloatingCart();
			$("#add2Cart").css("opacity", "1");
		},error: function(err){
			$("#dialog").attr("title", "Cart Error");
			$("#dialog").html("There has been an error updating your cart");
			$("#dialog").dialog();
			$("#add2Cart").css("opacity", "1");
		}
	});
}

function deleteItemFromCart(id){
	$.ajax({
		url: "/shopaction.php",
		data: "action=deletefromcart&itemId=" + id,
		success: function(msg){
			updateFloatingCart(true);
			/*$("#dialog").attr("title", "Item Removed");
			$("#dialog").html("Your cart has been updated");
			$("#dialog").dialog();*/
		}
	});	
}

function updateFloatingCart(show){
	$.ajax({
		url: "/shop/icart.php",
		data: "",
		success: function(msg){
			$("#floatcart").html(msg);
			$(".msg_head").click(function(){
				$(this).next(".msg_body").slideToggle(600);
			});
			if(show){
				$(".msg_body").show();
			}
		}
	});	
}

function addToCart(sku, itemSku, size, color, qty, price, points, discount, discountflag){
	
	var color = document.getElementById(color)?	document.getElementById(color).value : "";
	var size 	= document.getElementById(size)	?	document.getElementById(size).value	 : "";

	location.href = "/shopaction.php?action=addtocart&sku=" + sku + "&itemSku=" + itemSku + "&size=" + size + "&color=" + color + "&qty=" + qty + "&price=" + price + "&points=" + points + "&discount=" + discount + "&discountflag=" + discountflag;

}

function updateCart(orderId, qty){
	
	location.href = "/shopaction.php?action=updatecart&orderId=" + orderId + "&qty=" + qty;

}

function emptyCart(orderId){
	
	location.href = "/shopaction.php?action=emptycart&orderId=" + orderId;

}

function loadProduct(id, category, parent){
	var sku = document.getElementById(id).value;
	location.href = "/product/" + parent + "/" + category + "/" + sku;

}

function loadProduct2(size, sku, category, parent){
	var size = document.getElementById(size).value;

	location.href = "/shopredirect.php?sku=" + sku + "&size=" + size + "&category=" + category + "&parent=" + parent;

}

function loadProduct3(size, sku, category, parent){
	var color = document.getElementById("color").value;
	location.href = "/shopredirect.php?sku=" + sku + "&size=" + size + "&color=" + color + "&category=" + category + "&parent=" + parent;

}

function loadProduct4(color, sku, category, parent){
	var size = document.getElementById("size").value;
	location.href = "/shopredirect.php?sku=" + sku + "&size=" + size + "&color=" + color + "&category=" + category + "&parent=" + parent;

}

function loadProduct5(size_id, color_id, sku, category, parent){
	var size = document.getElementById(size_id).value;
	var color = document.getElementById(color_id).value;
	location.href = "/shopredirect.php?sku=" + sku + "&size=" + size + "&color=" + color + "&category=" + category + "&parent=" + parent;

}



function addToWishlist(itemSku) {
	$.ajax({
		url: "/shopaction.php",
		data: { action:'addtowishlist', itemSku:itemSku },
		success: function(msg){
				$("#dialog").attr("title", "Your Favourites has been updated");
				$("#dialog").html("Your product has been added to your Favourites <br/><br/> <input type='button' class='dia_continueshopping ui-corner-all ui-widget-header' value='Continue Shopping' onclick='$(\".ui-dialog-titlebar-close\").click();' /> <input type='button' class='dia_checkout ui-corner-all ui-widget-header' value='View Favourites' onclick='window.location=\"/action/wishlist\"' />");
				$("#dialog").dialog();
		},error: function(err){
			$("#dialog").attr("title", "Favourites Error");
			$("#dialog").html("There has been an error updating your Favourites");
			$("#dialog").dialog();
			$("#add2Cart").css("opacity", "1");
		}
	});
}

function removeFromWishlist(itemSku, sku) {
	$.ajax({
		url: "/shopaction.php",
		data: { action:'removefromwishlist', itemSku:itemSku },
		success: function(msg){
				$("#dialog").attr("title", "Your Favourites has been updated");
				$("#dialog").html("Your product has been deleted from your Favourites <br/><br/> <input type='button' class='dia_continueshopping ui-corner-all ui-widget-header' value='Continue Shopping' onclick='$(\".ui-dialog-titlebar-close\").click();' /> <input type='button' class='dia_checkout ui-corner-all ui-widget-header' value='Checkout' onclick='window.location=\"/action/cart\"' />");
				$("#dialog").dialog();
				$("#"+sku).remove();
		},error: function(err){
			$("#dialog").attr("title", "Favourites Error");
			$("#dialog").html("There has been an error updating your Favourites");
			$("#dialog").dialog();
			$("#add2Cart").css("opacity", "1");
		}
	});
}

