_c(function(){

	$("#lista_orcamento tbody tr[-class!=odd]").apply("addClass", "odd");
	$("#lista_orcamento tbody td.qtd input").run(function(){
		this.e("focus", function(){
			this.oldValue = this.value;
		});
		this.e("blur", changeQtd);
	});
	$("#lista_orcamento tbody td.excluir a").apply("e", "click", clickExcluir);

});

function changeTotal()
{
	var trs = $("#lista_orcamento tbody tr");
	var td_foot = $("#lista_orcamento tfoot tr td")[0];
	var qtd = $t("SPAN", td_foot);
		
	var msg_empty = {
		pt: "Sua lista está vazia",
		es: "Su lista está vacía",
		en: "Your list is empty" 
	}

	if(trs.length > 0)
	{
		qtd[0].innerHTML = trs.length;
	}
	else
	{
		td_foot.innerHTML = msg_empty[window.lang];
	}
	
	resizeContent();	
}

function clickExcluir(e)
{
	if(confirm("Deseja remover este produto?"))
	{
		Ajax(this.href.toString(), {
			onLoad: function()
			{
				this.tr.parentNode.removeChild(this.tr);
				changeTotal();
			},
			async: false,
			tr: this.parentNode.parentNode
		});
	}
	this.cancelEvent(e);
	return false;
}

function changeQtd()
{
	if(this.oldValue == this.value) return true;
	
	var id = this.id.toString().split("_")[1];
	
	this.parentNode.appendChild((a=$e("SPAN", "Aguarde")));

	Ajax(window.defaultUrl + "/orcamento/changeQtd/" + id + "/" + this.value, {
		onLoad: function()
		{
			this.input.parentNode.lastChild.remove();
			this.input.toggle();
		},
		input: this
	});
	
	this.toggle();
}