function ajaxboxmsg(okmsg, formval, args){
	if(okmsg)
	{
		$("body").append('<div class="ajax-box-success" id="ajax-box-success">Product Added to Your Cart</div>');
        $("#ajax-box-success")
        .css({'top':$(formval).position().top+'px', 'left':$(formval).position().left+'px'})
        .show().animate({opacity: 1.0}, 3000).fadeOut('slow',function(){ $(this).remove(); });
	}
	else
	{
	  (args)? fmsg = args : fmsg = "Could Not Add Product to Your Cart";
		$("body").append('<div class="ajax-box-error" id="ajax-box-error">'+fmsg+'</div>');
        $("#ajax-box-error")
        .css({'top':$(formval).position().top+'px', 'left':$(formval).position().left+'px'})
        .show().animate({opacity: 1.0}, 3000).fadeOut('slow',function(){ $(this).remove(); });
	}
}

function ajaxadd(slug, formval){
	// post(file, data, callback, type);
    var qty = $(formval).children("#quantity").val();
    if(qty)
    {
	    $.post("/cart/add/ajax/", //Ajax file
	    { productname: slug, quantity: qty  },  // create an object will all values
	    //function that is called when server returns a value.
	    function(data){
	      ACID = data;
	      if(data.errors === undefined){
  	    	$("#cart-count-top").text(data.cart_count);
  			  var c = data.cart_total.split('.');
  			  var amt = c[0]+'.'+c[1].slice(0,2);
  		    $("#cart-total-top").text("$"+amt);
  		    //$("#ajax-box-success").animate({opacity: 1.0}, 4000).remove();
  	    	ajaxboxmsg(true, formval);
  	    	$(formval).children("#quantity").val('');
  	    }
  	    else {
  	      $(formval).children("#quantity").val('');
  	      ajaxboxmsg(false, formval, data.errors);
  	    }
	    },
	    //How you want the data formated when it is returned from the server.
	    "json"
	    );
    } // end if
    else
    {
        ajaxboxmsg(false, formval);
    }
    return false;
}

