
function updateCart(action,pId,pq){
	$(".addToCartMessage").hide();
	$.ajax({

	type:"POST",
	url: "/CTRL/Ajax",
	data: {call: action , productId: pId, quantity:pq},
	success: function(res){

		$(".cartRight").html(res);
		$.ajax({
			type:"POST",
			url: "/CTRL/Ajax",
			data: {call: "UPDATESMALLCART"},
			success: function(res){
				$(".totamountheader").html(res+'<span style="font-size:10px; color:#10afe3;">&euro;</span>');
				if (action == "ADD")	$("#summary"+pId).load('/addedToCartMessage/productId/'+pId).show();
				}

			});
		}

	});




}

function addToCartOnSubmit(pId){

	var pq;
	pq = $('#quantity').val();

	addToCart(pId,pq);

}

function addToCart(pId,pq){
	$(".addToCartMessage2").hide();
	$(".addToCartMessage3").hide();
	$.ajax({

	type:"POST",
	url: "/CTRL/Ajax",
	data: {call: "ADD2" , productId: pId, quantity:pq},
	success: function(res){
		$.ajax({
			type:"POST",
			url: "/CTRL/Ajax",
			data: {call: "UPDATESMALLCART"},
			success: function(res){
					$(".totamountheader").html(res+'<span style="font-size:10px; color:#10afe3;">&euro;</span>');
					$("#summary"+pId).load('/addedToCartMessage/productId/'+pId).show();
				}

			});
		}
	});

}



function updateQuantity(pId,pq){

	var productId = pId;
	var quantity = pq;

	var newQuantity = parseInt($("#"+pId).attr("value"))+ quantity;
	$("#" + pId).attr("value",newQuantity);

	if(newQuantity	<=0)
		quantity=0;

	updateCart("UPDATEQUANTITY",pId,quantity);

}

function deleteItem(pId){
	updateCart("DEL",pId);
}


this.productPreview = function(){
	/* CONFIG */

		xOffset = 10;
		yOffset = 20;

		// these 2 variable determine popup's distance from the cursor
		// you might want to adjust to get the right result

	/* END CONFIG */
	$(".border").hover(function(e){
		this.t = this.title;
		this.title = "";
		var c = (this.t != "") ? "<br/>" + this.t : "";
		$(".border").append("");

		$(".border")
			.css("top",(e.pageY - xOffset) + "px")
			.css("left",(e.pageX + yOffset) + "px")
			.fadeIn("fast");
    },
	function(){
		this.title = this.t;
		$("#border").remove();
    });
	$("a.border").mousemove(function(e){
		$("#border")
			.css("top",(e.pageY - xOffset) + "px")
			.css("left",(e.pageX + yOffset) + "px");
	});
};

