function addToCart() {
	if ($('#qty').val() > 0) {
		$.ajax({
			url: "/inc/ajax/cart_add.php",
			global: false,
			type: "POST",
			dataType: "html",
			data: "pid=" + $('#pid').val() + "&vid=" + $('#vid').val() + "&vid2=" + $('#vid2').val() + "&type=" + $('#type').val() + "&qty=" + $('#qty').val(),
			success: function(msg){
				$.ajax({
					url: "/inc/ajax/cart_update_mini.php",
					global: false,
					type: "POST",
					dataType: "html",
					success: function(msg){
						$('#cartmini').html(msg);	
						$('#cartbutton').css('display', 'block');
						$('#cartmini').html(msg);	
						$('#myaccountbutton a').removeClass('first');						
					}
				});
				cartAdded('Cart updated',msg); // Show Dialog box
			}
		});
	}
}



function proceedBookingPayment() {
	$.ajax({
		url: "/inc/ajax/online_booking.php",
		global: false,
		type: "POST",
		dataType: "html",
		success: function(msg){
			$('#paymentform').html(msg);
			//if (confirm("Proceeed?")) {		
				$('#paymentform form').submit();
			//}
		}
	});	
}


function proceedPayment() {
	$.ajax({
		url: "/inc/ajax/cart_proceed_payment.php",
		global: false,
		type: "POST",
		dataType: "html",
		success: function(msg){
			$('#paymentform').html(msg);
			//if (confirm("Proceeed?")) {		
				$('#securetradform').submit();
			//}
		}
	});	
}


function qtyChange(option,cartid,cart) {
	var currentqty = cleanNum($('#qty'+cartid).val());
	var newqty = currentqty;	
	if (option == "add") {
		newqty = newqty + 1;
	} else if (newqty > 1) {
		newqty -= 1;
	}
	if (newqty == 1) {
		$('#qty'+cartid+'minus').addClass('disabled');
	} else {
		$('#qty'+cartid+'minus').removeClass('disabled');
	}
	$('#qty'+cartid).val(newqty);
	if (cart && newqty != currentqty) updateCartTotals(cartid);
}

function qtyEnter(qty,cartid,cart) {
	cleanqty = cleanNum(qty,1);
	$('#qty'+cartid).val(cleanqty);
	if (cleanqty == 1) {
		$('#qty'+cartid+'minus').addClass('disabled');
	} else {
		$('#qty'+cartid+'minus').removeClass('disabled');
	}
	if (cart) updateCartTotals(cartid);
}

function updateCartTotals(cartid) {
	// Update actual QTY first
	$.ajax({
		url: "/inc/ajax/cart_update.php",
		global: false,
		type: "POST",
		dataType: "html",
		data: "cid=" + cartid + "&qty=" + $('#qty'+cartid).val(),
		success: function(msg) {
			cartRender();
		}
	});
}

function cartRender() {
	//!TODO Update item total/sub total
	cartheight = $('#cartholder').height();
	$('#cartholder').addClass('loading');
	$('#cartholder').html('');
	$('#cartholder').css('height',cartheight);
	$.ajax({
		url: "/inc/ajax/cart_render.php",
		global: false,
		type: "POST",
		dataType: "html",
		success: function(msg) {
			$('#cartholder').css("height", 'auto');
			$('#cartholder').removeClass('loading');
			$('#cartholder').html(msg);
			tooltips();
		}
	});
}

function cartDelete(cid) {
	$('#cart'+cid).hide();
	$.ajax({
		url: "/inc/ajax/cart_delete.php",
		global: false,
		type: "POST",
		dataType: "html",
		data: "cid=" + cid,
		success: function(msg) {
			cartRender();
		}
	});
}

function cartAdded(title,subtitle) {
	$.ui.dialog.defaults.bgiframe = true;
	$("#dialog").html(subtitle);
	$("#dialog").dialog({
		bgiframe: true,
		resizable: false,
		width: 350,
		height: 160,
		modal: true,
		title: title,
		buttons: {
			Ok: function() {
				$(this).dialog('close');
			},
			'View Your Cart': function() {
				document.location = '/cart';
			}
		}
	});
	$("#dialog").dialog('open');
}