var	ativo = ""

function resetcor(){
	if(ativo != ""){
		document.getElementById(ativo).background = "img/botao1.gif";
		ativo = ""
	}
}

function mudacor(nome,id,trans){
	if(ativo != ""){
		document.getElementById(ativo).background = "img/botao1.gif";
	}
	ativo=nome
	document.getElementById(nome).background = "img/botao2.gif";
	frame.location = "produtos.asp?categoria=" + id + "&transacao=" + trans;
	window.scrollTo(0,0)
}

function tiramouse(nome){
	if (ativo == nome){
		document.getElementById(nome).background='img/botao2.gif';
	}else{
		document.getElementById(nome).background="img/botao1.gif";
	}
}

function colocacor(nome){
	document.getElementById(nome).background="img/botao2.gif";
}

function mudapagina(vaipra){
	if(ativo != ""){
		document.getElementById(ativo).background = "img/botao1.gif";
		ativo = ""
	}
	frame.location = vaipra + ".htm";
}
function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.0
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && document.getElementById) x=document.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function calcHeight(){
	//calcular altura
	var altura=document.getElementById('frame').contentWindow.document.body.scrollHeight;

	if (altura - 300 < 0){altura = 300;}

	//alterar altura do iframe
	document.getElementById('frame').style.height=altura;	
}





/*cadastre*/
function isNumeric2(valor,campo,nome){
	if (isNaN(valor)){
			eval("document.form." + campo + ".value  = ''");
			alert("O Campo " + nome + " deve conter apenas números");
			eval("document.form." + campo + ".focus()");
		}
}

function limpa(){
   for(i=0;i<document.forms.length;i++){
      document.forms[i].reset()
   }
}

function validarEmail(valor) {
	if (document.form.nome.value == ""){
			alert("Insira seu Nome");
			document.form.nome.focus();
			return false
	}
	if (document.form.endereco.value == ""){
			alert("Insira seu Endereço");
			document.form.endereco.focus();
			return false
	}
	if (document.form.bairro.value == ""){
			alert("Insira seu Bairro");
			document.form.bairro.focus();
			return false
	}
	if (document.form.cidade.value == ""){
			alert("Insira sua Cidade");
			document.form.cidade.focus();
			return false
	}
	if (document.form.estado.value == ""){
			alert("Escolha seu Estado");
			document.form.estado.focus();
			return false
	}
	if (document.form.cep.value == ""){
			alert("Insira seu CEP");
			document.form.cep.focus();
			return false
	}
	if (document.form.email.value == ""){
			alert("Insira seu E-mail");
			document.form.email.focus();
			return false
	}
	if (document.form.telcom.value == "" && document.form.telres.value == "" && document.form.telcel.value == ""){
			alert("Insira pelo menos um Telefone");
			document.form.dddcom.focus();
			return false
	}
	if (document.form.dddcom.value == "" && document.form.telcom.value != ""){
			alert("Insira o Telefone Comercial completo");
			document.form.dddcom.focus();
			return false
	}
	if (document.form.telcom.value == "" && document.form.dddcom.value != ""){
			alert("Insira o Telefone Comercial completo");
			document.form.telcom.focus();
			return false
	}
	if (document.form.dddres.value == "" && document.form.telres.value != ""){
			alert("Insira o Telefone Residencial completo");
			document.form.dddres.focus();
			return false
	}
	if (document.form.telres.value == "" && document.form.dddres.value != ""){
			alert("Insira o Telefone Residencial completo");
			document.form.telres.focus();
			return false
	}
	if (document.form.dddcel.value == "" && document.form.telcel.value != ""){
			alert("Insira o Telefone Celular completo");
			document.form.dddcel.focus();
			return false
	}
	if (document.form.telcel.value == "" && document.form.dddcel.value != ""){
			alert("Insira o Telefone Celular completo");
			document.form.telcel.focus();
			return false
	}
	if (document.form.dddcel.value == "" && document.form.telcel.value != ""){
			alert("Insira o Telefone Celular completo");
			document.form.dddcel.focus();
			return false
	}
	if (document.form.telfax.value == "" && document.form.dddfax.value != ""){
			alert("Insira o Fax completo");
			document.form.telfax.focus();
			return false
	}
	if (document.form.dddfax.value == "" && document.form.telfax.value != ""){
			alert("Insira o Fax completo");
			document.form.dddfax.focus();
			return false
	}
	if (document.form.gaby.value == ""){
			alert("Informe-nos como conheceu a Gaby Imóveis");
			document.form.gaby.focus();
			return false
	}
	if (document.form.transacao.value == ""){
			alert("Escolha o tipo de Transaçăo");
			document.form.transacao.focus();
			return false
	}
	if (document.form.tipo.value == ""){
			alert("Escolha o tipo de Imóvel");
			document.form.tipo.focus();
			return false
	}
	if (document.form.dddimo.value == "" && document.form.telimo.value != ""){
			alert("Insira o Telefone do Imóvel completo");
			document.form.dddimo.focus();
			return false
	}
	if (document.form.telimo.value == "" && document.form.dddimo.value != ""){
			alert("Insira o Telefone do Imóvel completo");
			document.form.telimo.focus();
			return false
	}
	if (document.form.dddcaseiro.value == "" && document.form.telcaseiro.value != ""){
			alert("Insira o Telefone do Caseiro / Zelador completo");
			document.form.dddcaseiro.focus();
			return false
	}
	if (document.form.telcaseiro.value == "" && document.form.dddcaseiro.value != ""){
			alert("Insira o Telefone do Caseiro / Zelador completo");
			document.form.telcaseiro.focus();
			return false
	}
	if (document.form.areau.value == ""){
			alert("Insira a Área Útil do Imóvel");
			document.form.areau.focus();
			return false
	}
	if (document.form.areat.value == ""){
			alert("Insira a Área Total do Imóvel");
			document.form.areat.focus();
			return false
	}
	if (document.form.dorm.value == ""){
			alert("Escolha a Quantidade de Domitórios");
			document.form.dorm.focus();
			return false
	}
	if (document.form.gara.value == ""){
			alert("Escolha a Quantidade de Garagens");
			document.form.gara.focus();
			return false
	}
	if (document.form.valor.value == ""){
			alert("Insira o Valor do Imóvel");
			document.form.valor.focus();
			return false
	}
	if (document.form.endimo.value == ""){
			alert("Insira o Endereço do Imóvel");
			document.form.endimo.focus();
			return false
	}
	if (document.form.bairroimo.value == ""){
			alert("Insira o Bairro do Imóvel");
			document.form.bairroimo.focus();
			return false
	}
	if (document.form.cidadeimo.value == ""){
			alert("Insira a Cidade do Imóvel");
			document.form.cidadeimo.focus();
			return false
	}
	if (document.form.estadoimo.value == ""){
			alert("Escolha o Estado do Imóvel");
			document.form.estadoimo.focus();
			return false
	}
	if (document.form.concordo.checked == false){
			alert("É necessário sua autorizaçăo para que seu formulário seja enviado");
			document.form.concordo.focus();
			return false
	}
	if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(valor)){
            return (true)
    }
	        else {
            alert("E-mail inválido");
	        form.email.value="";
	        document.form.email.focus();
            return (false);
	        }
}


function valida(){
	if (document.form.nome.value == ""){
		alert(mensagem1);
		document.form.nome.focus();
		return false
	}
	if (!checarEmail(document.form.email.value)){
		alert(mensagem12);
		document.form.email.value="";
		document.form.email.focus();
		return false
	}
	return true
}

function checarEmail(email){
	if (email.length < 6){
		return false;
	}
	i = email.indexOf("@");
	if (i < 1){
		return false;
	}
  	i = email.indexOf(".", i+3);
	if (i < 1){
		return false;
	}
	i = email.lastIndexOf(".", email.length)
	if (email.length - i < 3){
		return false;
	}
   	var valid = '0123456789._@%#abcdefghijklmnopqrstuvwxyz';
	email = email.toLowerCase(); 
	if  (!isValid(email,valid)){ 
		return false;
	}
	return true;	
}

function isValid(string,allowed) { for (var i=0; i< string.length; i++) { if (allowed.indexOf(string.charAt(i)) == -1) return false; } return true; }

mensagem1 = "Preencher o Campo Nome";
mensagem12 = "E-mail inválido!";

function validar(){
  if (document.form.locacao.value.length == 0){
	alert("Favor selecionar o campo Transaçao");
	document.form.locacao.focus();
	return false;
  }	
 if (document.form.comercial.value.length == 0){
	alert("Favor selecionar o campo Comercial ou Residencial");
	document.form.comercial.focus();
	return false;
  }	
  if (document.form.categoria.value.length == 0){
	alert("Favor selecionar o campo Tipo de Imóvel");
	document.form.categoria.focus();
	return false;
  }	
 if (document.form.area.value.length == 0){
	alert("Favor selecionar o campo Regiao");
	document.form.area.focus();
	return false;
  }	
  return true
}

function habilita(){
	if(document.form.locacao.value == ""){
		document.form.preco.disabled = true;
	}
	else{
		document.form.preco.disabled = false;
	}
}

/*imprimir*/
function imprimir(){
	window.print()
}

function getUrl(url){
	var http = new XMLHttpRequest();
	http.open("GET",url,false);
	http.send(null);
	return http.responseText;
}
function imagem(dir){
	if((pos+dir)<0){
		pos=total-1
	}else if((pos+dir-total)==0){
		pos=0
	}else{
		pos=(pos+dir)
	}
	display_imagem(vetor[pos]);
	contador();
	display_texto(vetor[pos]);
	return pos;
}
function contador(){
	document.getElementById('posicao').childNodes[0].nodeValue=pos+1+" de "+total
}
function display_imagem(id){
	document.getElementById('placeholder').src="showPic.asp?id="+id
}
function display_texto(id){
	document.getElementById('desc').childNodes[0].nodeValue=getUrl("HTTP://www.nlk.com.br/africa/imoveis/showTitle.asp?id="+id)
}

// Calcula data de Hoje

var now = new Date();
var mName = now.getMonth() + 1;
var dName = now.getDay() + 1;
var dayNr = now.getDate();
var yearNr=now.getYear();
if(dName==1) Day = "Domingo";
if(dName==2) Day = "Segunda-feira";
if(dName==3) Day = "Ter&ccedil;a-feira";
if(dName==4) Day = "Quarta-feira";
if(dName==5) Day = "Quinta-feira";
if(dName==6) Day = "Sexta-feira";
if(dName==7) Day = "S&aacute;bado";
if(mName==1) Month = "Janeiro"
if(mName==2) Month = "Fevereiro"
if(mName==3) Month = "Mar&ccedil;o"
if(mName==4) Month = "Abril"
if(mName==5) Month = "Maio"
if(mName==6) Month = "Junho"
if(mName==7) Month = "Julho"
if(mName==8) Month = "Agosto"
if(mName==9) Month = "Setembro"
if(mName==10) Month = "Outubro"
if(mName==11) Month = "Novembro"
if(mName==12) Month = "Dezembro"

if(yearNr < 2000) Year = 1900 + yearNr;
else Year = yearNr;

// String to display current date.
var todaysDate =(" " + Day + ", " + dayNr + " de " + Month + " de " + Year);

