///////////////////////////////////////  Só Número //////////////////////////////////////////////////////
function soNumero(e){
	navegador = /msie/i.test(navigator.userAgent);
	if (navegador)
		var tecla = event.keyCode;
	else
		var tecla = e.which;
	//alert(tecla)
	if(tecla > 47 && tecla < 58) // numeros de 0 a 9
		return true;
	else{
	if (tecla != 8 && tecla != 0) // backspace e tab
		return false;
	else
		return true;
	}
}

///////////////////////////////////////  Calcula //////////////////////////////////////////////////////
function calcula(){
	var valor = 0;
	qtdElementos = document.formCalculo.elements.length;
	for(i=0;i<qtdElementos;i++){
		if(document.formCalculo.elements[i].type == "text"){
			if(document.formCalculo.elements[i].value != ""){
				valor += document.formCalculo.elements[i].getAttribute("medida") * document.formCalculo.elements[i].value;	
			}
		}
	}
	valor = valor.toString();
	for(x=0;x < valor.length; x++){
		if(valor.charAt(x) == "."){
			valor = valor.substring(0,x+3);
			break;
		}
	}
	
	document.getElementById("result").childNodes[0].nodeValue = valor;
}

////////////
// Select //
////////////
estiloSelect = {
	init: function(){
		var primeiro = 0;
		$("select.select").each(function(){
			var html =  '<div id="' + $(this).attr("id") + '" class="' + $(this).attr("class") + '">';
				html += '	<div class="ativo"></div>';
				html += '	<input id="' + $(this).attr("id") + '_select" name="' + $(this).attr("name") + '" type="hidden" value="" />';
				html += '	<div class="options">';
				for(i=0;i<$("option",this).length;i++){
					html += '	<a href="javascript:void(0);" title="' + $("option:eq(" + i + ")",this).text() + '" rel="' + $("option:eq(" + i + ")",this).attr("value") + '">' + $("option:eq(" + i + ")",this).text() + '</a>';
				}
				html += '	</div>';
				html += '</div>';
			
			$(this).replaceWith(html);
			$("option",this).each(function(i){
				primeiro = this.selected ? i : primeiro;
			});
		});
		$("div.select").css("visibility","visible").each(function(){
			var altura = $("a",this).length;
				altura = altura > 5 ? 5 : altura;
			$(".options",this).css({height:(altura * parseInt($("a:first",this).css("height"))) + "px", visibility:"visible", display:"none"});
			estiloSelect.change(this,primeiro);
		})
		$("div.select .ativo").unbind().click(function(){
			$(this).parent().parent().css("z-index","3");
			$(this).siblings(".options").slideDown('fast',function(){
				$("html").bind('click',estiloSelect.fecha);
			});
		});
		$("div.select").each(function(){
			$("a", this).each(function(i){
				$(this).unbind().click(function(){
					estiloSelect.change($(this).parents("div.select:eq(0)"),i);
				});
			});
		});
	},
	
	change: function(obj,option){
		$("a.optionAtivo",obj).removeClass("optionAtivo");
		$("a:eq(" + option + ")",obj).addClass("optionAtivo");
		var texto = $("a:eq(" + option + ")",obj).text();
		var valor = $("a:eq(" + option + ")",obj).attr("rel");
		$(".ativo",obj).html(texto);
		$("input",obj).val(valor);
		estiloSelect.fecha();
	},
	
	fecha: function(){
		$("div.select .options:visible").slideUp('fast',function(){$(this).parent().parent().css("z-index","2")});
		$("html").unbind('click',estiloSelect.fecha);
	}
}

imB = function(){
	jQuery.ImageBox.init({loaderSRC:'imagens/carregando.gif', overlayOpacity: 0.5});
}

//////////////////
//Fecha Banner
/////////////////
	//function fechaBanner(){
		//$(".banner, .flashEntrada").remove();
		
	//}


$(document).ready(function(){
						   
	imB();						   

	estiloSelect.init()						   
						   
//////////////////////
//ChamaBloqueio
/////////////////////

	$(".linkMapa, .mapaLink").click(function(){
		bloqueia({ speed: "slow", bgcolor: "#000" });
		$(".flutuanteMapa").absoluteCenter({animation:false}).absoluteCenter().show();
	});
	
	$(".abreVideo").click(function(){
		bloqueia({ speed: "fast", bgcolor: "#000" });
		$(".flutuanteVideo").absoluteCenter({animation:false}).absoluteCenter().show();
	});

	$(".fechaBloqueio").click(function(){
		flashVideo = $('.videoFlutuante').html();
		$('.videoFlutuante').html(flashVideo);
		$(".comoChegar").hide();
		bloqueia({ speed: "slow", evento: "fim" });
		$(window).unbind("scroll");
		$(window).unbind("resize");
		
	});
	
/////////////////////////
//Flash
////////////////////////
	
	$(".bannerHome").addFlash({src: "swf/banner_home.swf", width: 780, height: 221, title: "Promoções Rent a Box"});
	$(".flashRent").addFlash({src: "video.swf", width: 313, height: 307, title: "Video Institucional Rent a Box"});
	//$(".flashEntrada").addFlash({src: "swf/banner_entrada.swf", width: 770, height: 498, title: "Promoção Rent a Box"});
	
//////////////////////
//escurece banner
/////////////////////
	
	//$(".banner, .flashEntrada").appendTo("body");
	//$(".banner").css({opacity: 0.6, display:"block", height:$('#geral').height()});
	
//otimizacao
	$('a, form').attr('target','_parent');
	

///////////////////////
// Mudar Unidades para o Mapa de Localização
////////////////////////////////////////////////
	$('input[name="enderecoUnidade"]').click (function(){
		if ($(this).val() == 'Rua Eng. Armando de Arruda Pereira, 90, São Caetano do Sul, SP'){
			$('#paraEndereco1').val($(this).val());
		}
		if ($(this).val() == 'Av. Nossa Senhora do Ó , 141, São Paulo, SP'){
			$('#paraEndereco1').val($(this).val());
		}
	});
	


});

