var Reservado = function(){

	var lis, reservas;
	
	return {
		init: function()
		{
			reservas = window.reservas;
			
			lis = $("#lista_stands ul li");
			if(empty(lis))
			{
				return false;
			}
			
			lis.apply("magic");
			lis.apply("e", "mouseover", this.overStand);
			lis.apply("e", "mouseout", this.outStand);
			
			lis.run(function(){
				
				var ns = this.firstChild.innerHTML;
				if(reservas[ns])
				{
					this.firstChild.addClass("vermelho");
					this.top(Reservado.createReservado(reservas[ns]));
				}
				else
				{
					this.firstChild.css({"cursor": "default"});
				}
				
			});
		},
		createReservado: function(cliente)
		{
			var d = $e("DIV");
			d.addClass("reservado");
			d.innerHTML = "Reservado: <br /><strong>" + cliente + "</strong>";
			
			return d;
		}
		,
		overStand: function()
		{
			this.addClass("over");
		},
		outStand: function()
		{
			this.remClass("over");
		}
	}

}();

_c( _d(Reservado, Reservado.init) );

function fv(valor, o)
{
	if(o==undefined)
	{
		valor = valor.toString().replaceAll(".", ",").split(",");
		if(valor[1]==undefined) valor[1] = "00";
		for(var i=valor[1].length; i<2; valor[1]+="0", i++);
		valor[1] = valor[1].substr(0, 2);
		
		return "R$ " + valor.join(",");
	}
	else if(o)
	{
		return valor.toString().split("R$ ").join("").toNumber();
	}
}

_c(function(){
	
	var f = $("formReserva");
	if(!empty(f))
	{
		f.magic();
		
		/*var inv = f.investimento1;
		for(var i=0; i<inv.length; i++)
		{
			inv[i].e("click", clickInvestimento);
		}
		
		$("preco_metro").value = (/R\$ (.*)\/m²(.*)/.exec(inv[0].value))[1];
		$("metro").onblur = function()
		{
			var v = parseFloat(this.value);
			if(v > 0)
			{
				v = v * parseFloat($("preco_metro").value);
				$("v_total").value = fv(v);
			}
		}*/
	}
	
});

function clickInvestimento(n)
{
	var o = $target(n);
	var f = /R\$ (.*)\/m²(.*)/.exec(o.value);
	if(!empty(f))
	{
		$("preco_metro").value = f[1];
	}
	$("metro").onblur();
}
