// JavaScript Document
function submit_cart()
{
	$("#content_form").mask("Loading...");
	$.ajax({
			type	: "POST",
			url		: site_url+"ajaxforms/cart-ajax.php?action_flg=show_content_form",
			data	: $("#form_cart").serialize(),
			success	: function(msg)
					{
						var msg_string	= msg.split('@#@#');
						var out_of_string	= msg_string[0];
						if(out_of_string == "out_of_stock")
						{
							$(".alert").show();
							$(".alert").html(msg_string[1]);
							//$("#cart_details_span").html("out of stock");
							$("#content_form").unmask("Loading...");
						$("#alert_span").highlightFade({color:'#FFB0DF',speed:1000,iterator:'exponential'});
						}
						else
							{
						$(".alert").hide();
						var substr_msg = msg.split('@#@#');
						$("#content_form").unmask("Loading...");
						$("#content_form").html(substr_msg[0]);
						$("#alert_span").highlightFade({color:'#FFB0DF',speed:1000,iterator:'exponential'});
						$("#cart_details_span").html(substr_msg[1]);
					}
					}
	});
}

function remove_from_cart(product_id,trid)
{
	var agree=confirm("Are you sure want to remove the product?");
	if (agree)
		{	
			$.ajax({
			type : "POST",
			url : "ajaxforms/cart-ajax.php",
			data : "quantity=0&product_id="+encodeURIComponent(product_id)+"&action_flg=addtocart&remove=yes",
			success : function(msg)
					{
						if(msg=='empty_cart')
						{
							$("#tocheckout_div").css("display","none");
							var string_msg	=	'<form id="tocheckout" name="tocheckout" class="left" method="post"><div  class="alert done" id="alert_span"><p>You have successfully deleted the product.</p></div><br /><br /><button  id="checkout" onclick="redirect_page(); return false;" name="checkout" class="checkoutButton">Continue Shopping</button></form>';
							$("#content_form").html(string_msg);
							$("#alert_span").highlightFade({color:'#FFB0DF',speed:1000,iterator:'exponential'});
							$("#cart_details_span").html('');
							$("#view_span").html('')
						}
						else
						{
							var msg_data	= msg.split('@#@#@');
							$('#shoptr_'+trid).fadeOut(1500).remove();
							//$("#content_form").html(msg);
							$("#tableCart").highlightFade({color:'#FFB0DF',speed:1000,iterator:'exponential'});
							$("#grand_total_div").highlightFade({color:'#FFB0DF',speed:1000,iterator:'exponential'});
							$("#cart_details_span").html(msg_data[0]);
							$("#grand_total_td").html(msg_data[1]);
							$("#grand_total_span").html("<strong>"+msg_data[1]+"</strong>");
							var is_product = 0;
							$("#tableCart").find('tr').each(function()
							{ 
								if($(this).attr("is_product") == "Y")
								{
									is_product=1;
								}
							}	
							);
							if(is_product	!= 1)	
							{
								document.location.href=site_url+"products.php?main_product=yes";
							}
						}
					}
			});
		}
}

function redirect_page()
{
	document.location.href =site_url+"products";	
}

function change_cookies(id)
{
	$.cookie("product_id_selected",null);
	$.cookie("product_id_selected",id,{path:'/'}); //,{path:'/',expires: date}
	$.fn.prettyPhoto();
	api_images = [site_url+'city_list.php?iframe=true&width=510&height=455',site_url+'products_attribute.php?form_type=edit&change_type=cart&iframe=true&width=600&height=380'];
	api_titles = ['We just want to know which city you would like us to deliver ?',''];//Delivery Location
	api_descriptions = ['','']
	$.prettyPhoto.open(api_images,api_titles,api_descriptions);
	$("div.pp_social").remove();
	$.prettyPhoto.changePage('next');
}

function add_addon(id)
{
	$("#content_form").mask("Loading...");
	$.ajax({
			type	: "POST",
			url		: site_url+"ajaxforms/cart-ajax.php?action_flg=add_addon_product&quantity=1&product_id="+id,
			data	: $("#products_addon").serialize(),
			success	: function(msg)
					{
						//alert(msg);
						$("#content_form").html(msg);
					}
	});
}
