function deslogar(){
	if(confirm('Voce possui itens na lista de compras, deseja realmente deslogar?')) {
		document.location.href="/login";
	} else {
		return;
	}
}

Carrinho = {
	keyCookie : 0,
	
	getCookie : function (name) {
		dc = document.cookie;
		if (dc.length > 0 ) {
			begin = unescape(dc.split(name + '=')[1]);
			return ((begin.indexOf(';') > -1) ? begin.substr(0, begin.indexOf(';')) : begin);
		} else return false;
	},

	setCookie : function (n, v, t){
		document.cookie = n + '=' + escape(v) + ';PATH=/' + (t ? ';EXPIRES=' + t : '');
		if (!this.getCookie(n)) {
			return false;
		} else {
			return true;
		}
	},
	
	add : function (o) {
		if(Carrinho.qtdCookie <= 20) {
			if (this.setCookie('cart' + this.keyCookie, o.id)) {
				o.name = this.keyCookie;
				document.getElementById('trProd' + o.id).className = 'item_added';
				o.onclick = function () {
					Carrinho.remove(this);
				};
				o.className = 'removeCarrinho';
				o.title = 'Remover da lista de compras';
				this.keyCookie++;
				this.qtdCookie++;
			}
		} else {
			alert('Não é possivel colocar mais de 20 itens na lista de compras.');
		}
	},
	
	remove : function (o) {
		id = this.getCookie('cart' + o.name);
		if (id) {
			this.setCookie('cart' + o.name, false, 'Thu, 01-Jan-1970 00:00:01 GMT');
			document.getElementById('trProd' + id).className = '';
			if (o) {
				o.className = 'addCarrinho';
				o.title = 'Adicionar a lista de compras';
				o.onclick  = function () {
					Carrinho.add(this);
				};
			}
			this.qtdCookie--;
		}
	},
	
	removeFromCart : function (loja, prod, o) {
		l = document.getElementById('tableProdsLoja' + loja);
		t = l.getElementsByTagName('TBODY')[0];
		for (i=0; i<t.childNodes.length; i++) {
			if (t.childNodes[i].id == 'trProd' + prod) {
				this.remove(o);
				t.removeChild( t.childNodes[i] );
				break;
			}
		}
		t = l.getElementsByTagName('TBODY')[0];
		if (t.childNodes.length == 1) {
			l.parentNode.parentNode.removeChild( l.parentNode );
		}
		
		this.totalItens--;
		if (this.totalItens == 0) {
			document.getElementById('carrinho').innerHTML = "<h2>Não há itens em sua lista de compras</h2>"
		}
	}
};

enviarEmail = function () {
	if (confirm('Deseja realmente enviar a lista de compras para o seu email cadastrado no sistema?')) {
		document.location = '/listacompras?cod=email';
	}
};

