function addtocart(c){
	var d=jqnc(),
	a=d(c).find("select.options"),
	b;
	if(a && ShoppSettings.opdef){
		b=true;
		a.each(function(e,f){
			if(d(f).val()==""){
				b=false
			}
		});
		
		if(!b){
			if(!ShoppSettings.opreq){
				ShoppSettings.opreq="You must select the options for this item before you can add it to your shopping cart.";
			}
			
			alert(ShoppSettings.opreq);
			return false;
		}
	}
	if(d(c).find("input.addtocart").hasClass("ajax-html")){
		ShoppCartAjaxRequest(c.action,d(c).serialize(),"html")
	}else{
		if(d(c).find("input.addtocart").hasClass("ajax")){
			ShoppCartAjaxRequest(c.action,d(c).serialize())
		}else{
		c.submit()
		}
	}
	return false
}
function ShoppCartAjaxRequest(b,e,a){
	if(!a){
		a="json"
	}
	var d=jqnc(),
	c=((a=="json")?"json":"string");
	d.ajax({
		type:"POST",
		url:b,
		data:e+"&response="+a,
		timeout:10000,
		dataType:c,
		success:function(f){
			ShoppCartAjaxHandler(f,a)
		},
		error:function(){}
	})
}
function ShoppCartAjaxHandler( g, a )
{
	var d = jqnc();
	var c = d(".widget_shoppcartwidget div.widget-all");
	var patt = /,\d\d/g;
	var total = asMoney(g.Totals.total).replace(patt, "");	
		
	d("#shoppcart").html('<span id="shopp-sidecart-items">'+g.Totals.quantity+'</span> <strong>artiklar</strong> <span id="shopp-sidecart-total">'+total+'</span> <strong>totalt</strong>');
	
	d("#cart-links").show();	
	jQuery.jGrowl(g.Item.name + " har blivit lagd i varukorgen.",{ life: 4000 });
}

jQuery(document).ready(function(){
	var a=jqnc();
	a("#cart #shipping-country").change(function(){
		this.form.submit()
	});
	
	a("input.addtocart").each(function(){
		var b=a(this),
		c=b.parents("form.product");
		
		if(!c){
			return false
		}
		c.submit(function(d){
			d.preventDefault();
			addtocart(this)
		});
		
		if(b.attr("type")=="button"){
			b.click(function(){
				c.submit()
			})
		}
	})
});


/*
function ShoppCartAjaxHandler(g,a){
	var d=jqnc(),
	c=d(".widget_shoppcartwidget div.widget-all"),
	f=c.find("ul"),
	e=d("#shopp-cart-ajax"),
	b=d('<div class="added"></div>');
	
	alert( "Alert!" );
	if(a=="html"){
		return e.html(g)
	}
	
	added=e.find("div.added").empty().hide();
	
	if(added.length==1){
		b=added
	}else{
		b.prependTo(e).hide()
	}
	
	if(g.Item.image){
		d('<p><img src="'+g.imguri+g.Item.image.id+'" alt="" width="96"  height="96" /></p>').appendTo(b)
	}
	
	d("<p />").html("<strong>"+g.Item.name+"</strong>").appendTo(b);
	d("<p />").html(asMoney(g.Item.unitprice)).appendTo(b);
	c.find("p.status").html('<a href="'+g.url+'"><span id="shopp-sidecart-items">'+g.Totals.quantity+'</span> <strong>Items</strong> &mdash; <strong>Total</strong> <span id="shopp-sidecart-total">'+asMoney(g.Totals.total)+"</span></a>");
	
	if(f.length!=1){
		f=d("<ul />").appendTo(c)
	}
	
	f.html('<li><a href="'+g.url+'">'+g.label+'</a></li><li><a href="'+g.checkouturl+'">'+g.checkoutLabel+"</a></li>");
	b.slideDown()
}
*/


