
$(document).ready(function() {
	
});



function addAlert(product, email)
{
	$.ajax({
		method: "get", url: "product_alert_ajax.php", data: "id=" + product + "&email=" + email,
		beforeSend: function() {
			$("#product_alert").html("<img src='images/spinner.gif' /> Salvare date...");
		}, 
		complete: function() {}, 
		success: function(html) {
			$("#product_alert").html(html);
			
			//$("#product_alert").load("cart_ajax.php?op=info");
		}
	});
}


function openAlert(product, display)
{
	$.ajax({
		method: "get", url: "product_alert_ajax.php", data: "id=" + product + (display ? "&display=1" : ""),
		beforeSend: function() {
			$("#product_alert").html("<img src='images/spinner.gif' /> Incarcare date...");
		}, 
		complete: function() {}, 
		success: function(html) {
			$("#product_alert").html(html);
			
			//$("#product_alert").load("cart_ajax.php?op=info");
		}
	});
}


function cancelAlert(product, email)
{
	$.ajax({
		method: "get", url: "product_alert_ajax.php", data: "cancel=1&id=" + product + (email ? "&email=" + email : ""),
		beforeSend: function() {
			$("#product_alert").html("<img src='images/spinner.gif' /> Salvare date...");
		}, 
		complete: function() {}, 
		success: function(html) {
			$("#product_alert").html(html);
			
			//$("#product_alert").load("cart_ajax.php?op=info");
		}
	});
}

function openCart()
{
	$.ajax({
		method: "get", url: "cart_ajax.php", data: "",
		beforeSend: function() {
			//$("#message").show(500);
			$("#fullscreen").show(500);
			$("#shoppingcart_container").show(500);
			$("#shoppingcart").html("<img src='images/spinner.gif' /> Incarcare cos cumparaturi...");
		}, 
		complete: function() { $("#loading").hide("fast"); }, 
		success: function(html) {
			$("#shoppingcart").html(html);
		}
	});
}


function addToCart(product, qty)
{
	$.ajax({
		method: "get", url: "cart_ajax.php", data: "op=add&product=" + product + "&qty=" + qty + (product_details != 0 && product_details == product ? "&details=1" : ""),
		beforeSend: function() {
			//$("#message").show(500);
			/*$("#fullscreen").show(500);
			$("#shoppingcart_container").show(500);
			$("#shoppingcart").html("<img src='images/spinner.gif' /> Incarcare cos cumparaturi..."); */
		}, 
		complete: function() { $("#loading").hide("fast"); }, 
		success: function(html) {
			//$("#shoppingcart").html(html);
			
			$("#header_kart").load("cart_ajax.php?op=info");
			
			//if (product_details == product)
			//	$("#in_kart").load("cart_ajax.php?op=in_kart&id=" + product);
			
			$("#product_status").html(html);
		}
	});
}


function updateCart(product, qty)
{
	$.ajax({
		method: "get", url: "cart_ajax.php", data: "op=update&product=" + product + "&qty=" + qty,
		beforeSend: function() { $("#ktotal" + product).html("<img src='images/spinner.gif' />"); }, 
		success: function(html) {
			$("#ktotal" + product).html(html);
			
			$("#header_kart").load("cart_ajax.php?op=info");
			$("#kart_total").load("cart_ajax.php?op=total");
			
			//if (product_details == product)
			//	$("#in_kart").load("cart_ajax.php?op=in_kart&id=" + product);
		}
	});
}


function deleteFromCart(product)
{
	$.ajax({
		method: "get", url: "cart_ajax.php", data: "op=delete&product=" + product + "&display=none",
		success: function(html) {
			$("#kitem" + product).hide(500);
			
			$("#header_kart").load("cart_ajax.php?op=info");
			$("#kart_total").load("cart_ajax.php?op=total");
			
			//if (product_details == product)
			//	$("#in_kart").load("cart_ajax.php?op=in_kart");
		}
	});
}


function emptyCart(close)
{
	$.ajax({
		method: "get", url: "cart_ajax.php", data: "op=empty&display=none",
		success: function(html) {
			$("#kart_items").hide(500);
			$("#kart_items").after("<div class='message' id='emptykart' style='display:none'>Cosul este gol</div>");
			$("#emptykart").show(500);
			
			$("#header_kart").load("cart_ajax.php?op=info");
			//$("#in_kart").load("cart_ajax.php?op=in_kart");
			
			if (close) {
				$("#shoppingcart_container").hide(500);
				$("#fullscreen").hide(500);
			}
		}
	});
}


function openWishlist()
{
	$.ajax({
		method: "get", url: "wishlist_ajax.php", data: "",
		beforeSend: function() {
			$("#fullscreen").show(500);
			$("#popup_container").show(500);
			$("#popup_title").html('Wishlist');
			$("#popup_content").html("<img src='images/busy.gif' /> Incarcare date...");
			$("#close_popup").html("<a href='#inchide' onclick='closePopup(); return false;' class='button2'>Inchide</a>");
		}, 
		complete: function() { $("#loading").hide("fast"); }, 
		success: function(html) {
			$("#popup_content").html(html);
		}
	});
}


function addToWishlist(product, qty)
{
	$.ajax({
		method: "get", url: "wishlist_ajax.php", data: "op=add&product=" + product,
		beforeSend: function() {
			/*$("#fullscreen").show(500);
			$("#popup_container").show(500);
			$("#popup_title").html('Wishlist');
			$("#popup_content").html("<img src='images/busy.gif' /> Incarcare date...");*/
		}, 
		complete: function() { $("#loading").hide("fast"); }, 
		success: function(html) {
			//$("#popup_content").html(html);
			//$("#header_kart").load("cart_ajax.php?op=info");
			
			if (product_details == product)
				$("#in_wishlist").load("wishlist_ajax.php?op=in_wishlist&id=" + product);
			
			//$("#close_popup").html("<a href='#inchide' onclick='closePopup(\"add_to_wishlist\"); return false;' class='button2'>Inchide</a>");
		}
	});
}


function deleteFromWishlist(product)
{
	$.ajax({
		method: "get", url: "wishlist_ajax.php", data: "op=delete&product=" + product + "&display=none",
		success: function(html) {
			$("#witem" + product).hide(500);
			
			//$("#header_kart").load("cart_ajax.php?op=info");
			//$("#kart_total").load("cart_ajax.php?op=total");
			
			if (product_details == product)
				$("#in_wishlist").load("wishlist_ajax.php?op=in_wishlist&id=" + product);
		}
	});
}


function emptyWishlist(close)
{
	$.ajax({
		method: "get", url: "wishlist_ajax.php", data: "op=empty&display=none",
		success: function(html) {
			$("#wishlist_items").hide(500);
			$("#wishlist_items").after("<div class='message' id='wishlist' style='display:none'>Lista este goala</div>");
			$("#emptywishlist").show(500);
			
			//$("#header_kart").load("cart_ajax.php?op=info");
			$("#in_wishlist").load("wishlist_ajax.php?op=in_kart");
			
			if (close)
				closePopup('add_to_wishlist');
		}
	});
}


function moveToCart(product)
{
	$.ajax({
		method: "get", url: "cart_ajax.php", data: "op=add&product=" + product + "&qty=1",
		beforeSend: function() {}, 
		complete: function() {}, 
		success: function(html) {
			$("#header_kart").load("cart_ajax.php?op=info");
			deleteFromWishlist(product);
		}
	});
}