tms=new Array()

//Mostra o submenu no mouseover
function over(n){
	if(typeof(tms[n])!="undefined")clearTimeout(tms[n])
	document.getElementById(n).style.visibility="visible"
}
//Esconde o submenu no mouseout
function out(n){
	tms[n]=setTimeout('document.getElementById("'+n+'").style.visibility="hidden"',500)
}

// ENDEREÇOS
function muda_agencia(cidade){
	switch(cidade){
		case "Blumenau":
			txt = "<b>Matriz - Blumenau e Região</b><br>Rua Paulo Zimmermann, 55 - Centro - Fone/Fax (47) 3326-7595 - <a href='mailto:blumenau@blusol.org.br'>blumenau@blusol.org.br</a><br>Municípios de Abrangência: Blumenau e região.";
			foto = "<img src=../img/local_blumenau.jpg width=130 height=193 border=0>";
			break;
		case "Gaspar":
			txt = "<b>Filial de Gaspar e Região</b><br>Rua Vereador Augusto Beduschi, 99-A - Fone/Fax (47) 3332-6238 - <a href='mailto:gaspar@blusol.org.br'>gaspar@blusol.org.br</a><br>Municípios de Abrangência: Gaspar, Ilhota.";
			foto = "<img src=../img/local_gaspar.jpg width=130 height=193 border=0>";
			break;
		case "Brusque":
			txt = "<b>Filial de Brusque</b><br>Rua Hercílio Luz, 79 - Fone/Fax (47) 3351-3928 - <a href='mailto:brusque@blusol.org.br'>brusque@blusol.org.br</a><br>Municípios de Abrangência: Brusque, Guabiruba, Botuverá, Nova Trento, Canelinha, São João Batista e Tijucas.";
			foto = "<img src=../img/local_brusque.jpg width=130 height=193 border=0>";
			break;
		case "Indaial":
			txt = "<b>Filial de Indaial</b><br>Rua Prefeito Frederico Hardt, 145 - Fone/Fax (47) 3333-6495 - <a href='mailto:indaial@blusol.org.br'>indaial@blusol.org.br</a><br>Municípios de Abrangência: Indaial, Timbó, Benedito Novo, Rodeio, Rio dos Cedros, Pomerode,<br>Apiúna e Ascurra.";
			foto = "<img src=../img/local_indaial.jpg width=130 height=193 border=0>";
			break;
		case "Riodosul":
			txt = "<b>Filial de Rio do Sul</b><br>Rua Coelho Neto, 170 - Fone/Fax (47) 3521-2579 - <a href='mailto:riodosul@blusol.org.br'>riodosul@blusol.org.br</a><br>Municípios de Abrangência: Rio do Sul, Rio do Campo, Salete, Taió, Pouso Redondo, Laurentino,<br>Presidente Getúlio, Dona Emma, Witmarsun, Vitor Meireles, Trombudo Central, Agronômica,<br>Aurora, Ituporanga, Agrolândia, Atalanta, Lontras, José Boiteux, Ibirama, Imbuia,<br>Presidente Nereu, Mirim Doce e Petrolândia.";
			foto = "<img src=../img/local_rdosul.jpg width=130 height=193 border=0>";
			break;
	}
	endereco.innerHTML = txt;
	agencia.innerHTML = foto;
}

// JANELA RESULTADOS
function abre_resultado(end){
	w = 571;
	h = 500;
	largura = screen.width;
	altura = screen.height;
	XX =(largura-w)/2;
	YY = (altura-h)/2;
	janela = window.open(end,'POP_RESULTADOS','width='+w+',height='+h+',left='+XX+',top='+YY+',scrollbars=yes,status=no,resizable=no, toolbar=no,directories=no,menubar=no');
	janela.focus();
}

// CASES
function choose_case(){
	x = parseInt(Math.random()*3)
	
	switch(x){
		case 0:
			txt1 = "<a href='../instituicao/cases.asp'><img src='../img/cechetti.jpg' width='130' height='104' border='0'></a>";
			txt2 = "<a href='../instituicao/cases.asp' class='case'><b>Com. Irmãos Cechetti</b><br>Cliente desde 1999</a>";
			break;
		case 1:
			txt1 = "<a href='../instituicao/cases_03.asp'><img src='../img/franz.jpg' width='130' height='104' border='0'></a>";
			txt2 = "<a href='../instituicao/cases_03.asp' class='case'><b>Rolando Franz</b></a>";
			break;
		case 2:
			txt1 = "<a href='../instituicao/cases_04.asp'><img src='../img/heinicke.jpg' width='130' height='104' border='0'></a>";
			txt2 = "<a href='../instituicao/cases_04.asp' class='case'><b>Rosana H. dos Santos</b><br>Cliente desde 2001</a>";
			break;
	}
	case_foto.innerHTML = txt1;
	case_nome.innerHTML = txt2;
}

// SIMULACAO DE CREDITO
function limpa(campo) {
	campo.value = "";
}
function valida_numero(campo) {
	if(isNaN(campo.value)) {
		alert("Por favor, digite apenas números.\nExemplo: 3000");
		campo.focus();
		campo.value = "";
	}
}

function milhares(numero) {
	// quebra a milhar em números individuais
	var partes = new Array(numero.length);
	for(var i=0; i<numero.length; i++) {
		partes[i] = numero.substr(i, 1);
	}
	casa = 1;
	for(i=partes.length-1; i>=0; i--) {
		if(casa > 2) {
			partes[i] = "." + partes[i];
			casa = 0;
		}
		casa++;
	}
	var valor_retorno = "";
	for(var i=0; i<partes.length; i++) {
		valor_retorno = valor_retorno + partes[i];
	}
	// tira o ponto se ele ficar só na frente
	
	if(valor_retorno.substr(0,1) == ".") {
		tamanho = valor_retorno.length;
		valor_retorno = valor_retorno.slice(1,tamanho);
	}
	return(valor_retorno);
}

function formata_moeda(numero) {
	valor = numero;
	valor = valor.toString();
	var array_valor = new Array();
	
	// +++++ centavos +++++
	array_valor = valor.split(".");
	if(centavos = array_valor[1].substr(0, 2)) {
		terceiro_numero = array_valor[1].substr(2, 1); //usado pra arrendondar os centavos
		if(terceiro_numero >= 5 ) 
			centavos++;
	} else
		centavos = "00";
	// +++++ fim dos centavos +++++
	return("R$ " + milhares(array_valor[0]) + "," + centavos);
}

//retira a formatacao de moeda
function retira_formatacao(valor) {
	if(isNaN(valor)) {
		array_valor = valor.split(',');
		valor = array_valor[0];
		valor = valor.replace('R$ ', '');
		valor = valor.replace('.', '');
	}
	return(valor);
}

function calcula() {
	var valor = document.form.valor.value;
	var percentual = document.form.parcelas[document.form.parcelas.selectedIndex].value;
	var parcelas = document.form.parcelas[document.form.parcelas.selectedIndex].text;

	valor = retira_formatacao(valor);

	if(valor !="") {
		valor_prestacao = valor*percentual;
		valor_total = valor_prestacao * parcelas;
		document.form.prestacao.value = formata_moeda(valor_prestacao);
		document.form.total.value = formata_moeda(valor_total);
		document.form.valor.value = "R$ " + milhares(valor) + ",00";
	}
	else
		alert("Por favor, informe o valor desejado");
}

function abre_creditos(){
	w = 400;
	h = 120;
	largura = screen.width;
	altura = screen.height;
	XX =(largura-w)/2;
	YY = (altura-h)/2;
	janela = window.open('../home/creditos.asp','POP_CREDITOS','width='+w+',height='+h+',left='+XX+',top='+YY+',scrollbars=no,status=no,resizable=no, toolbar=no,directories=no,menubar=no');
	janela.focus();
}
