// JavaScript Document

window.onload = function(){
	getLinks();
	getTRS();
	getInputs();
	ocultaDivsInstitucional();
	institucionalHeader();
	displayQuemSomos();
	
	_uacct = "UA-416988-30";
	urchinTracker(); 
}


function getLinks(){
	var el;

	el = document.getElementsByTagName("a");
	for(i=0; i < el.length; i++){
		if(el[i].rel == "linkInstitucional"){
			el[i].onclick = function ifonclick(){ showContent(this); };
		}
		if(el[i].rel == "external"){
			el[i].onclick = function ifonclick(){ externalLinks(); };
		}
		if(el[i].rel == "clickMap"){
			el[i].onclick = function ifonclick(){ expand(this.id); return false; };
		}
		if(el[i].rel == "popup"){
			el[i].onclick = function ifonclick(){ openWindow(this.href, 'width=100,height=100,top=50,left=100'); return false; };
		}
		if(el[i].id == "add_imovel"){
			el[i].onclick = function ifonclick(){ add_remove_Imovel(this); return false; };
		}
		if(el[i].id == "remove_imovel"){
			el[i].onclick = function ifonclick(){ add_remove_Imovel(this); return false; };
		}
	}
}


function getTRS(){
	var el;
	
	el = document.getElementsByTagName("tr");
	for(i=0; i < el.length; i++){
		if((el[i].className == "tr_A") || (el[i].className == "tr_B")){
			el[i].onmouseover = function ifonmouse(){ setClassTr(this); };
			el[i].onmouseout = function ifonmouse(){ setClassTr(this); };
		}
	}
}


function getInputs(){
	var el;
	
	el = document.getElementsByTagName("input");
	for(i=0; i < el.length; i++){
		if(el[i].className == "radio"){
			el[i].onclick = function ifonchange(){ disableText(this.id); };
		}
	}
}

function showContent(el){
	var ancora, divs, divMaster, showDiv;

	ancora = el.href.split("#");
	if(ancora[1] != "undefined"){
		ocultaDivsInstitucional();
		if(document.getElementById(ancora[1])){
			showDiv = document.getElementById(ancora[1]);
			showDiv.id = "_" + ancora[1];
		} else {
			showDiv = document.getElementById("_" + ancora[1]);
		}
		showDiv.style.display = "block";
		document.getElementsByTagName("body")[0].scrollTop = 0;
	}
}


function ocultaDivsInstitucional(){
	var divMaster, divs, url, splitUrl, el;
	
	if(divMaster = document.getElementById("areaInstitucional")){
		divs = divMaster.getElementsByTagName("div");
		
		for(i=0; i < divs.length; i++){
			divs[i].style.display = "none";	
		}
	}
}

/*
function ocultaDivsInstitucional_one(){
	var divMaster, divs
		
	if(divMaster = document.getElementById("areaInstitucional")){
		
		divs = divMaster.getElementsByTagName("div");
		for(i=1; i < divs.length; i++){
			divs[i].style.display = "none";	
		}
	}
}
*/

function externalLinks() {
	if (!document.getElementsByTagName) return;
	 var anchors = document.getElementsByTagName("a");
	 for (var i=0; i<anchors.length; i++) {
	   var anchor = anchors[i];
	   if (anchor.getAttribute("href") &&
		   anchor.getAttribute("rel") == "external")
		   anchor.target = "_blank";
	 }
}

function institucionalHeader(){
	var url, splitUrl, showDiv;

	url = window.location.href;
	splitUrl = url.split("#");
	
	if(splitUrl[1]){
		ocultaDivsInstitucional();
		
		if(document.getElementById(splitUrl[1])){
			showDiv = document.getElementById(splitUrl[1]);
			showDiv.id = "_" + splitUrl[1];
		} else {
			showDiv = document.getElementById("_" + splitUrl[1]);
		}

		showDiv.style.display = "block";
		setTimeout("scrolltop()", 0);
	}
	return false;
}


function scrolltop(){
	document.documentElement.scrollTop = 0;
}


function setClassTr(el){
	var classDefault;
	
	if((el.className == "tr_A") || (el.className == "tr_B")){
		classDefault = el.className
	}
	
	if(el.className == "tr_A"){
		el.className = "hover_tableA";
	} else if(el.className == "tr_B"){
		el.className = "hover_tableB";
	} else if(el.className == "hover_tableA"){
		el.className = "tr_A";
	} else if(el.className == "hover_tableB"){
		el.className = "tr_B";	
	}
}

function add_remove_Imovel(thisEl){
	var arrHref, pos, el;
	
	arrHref = thisEl.href.split("/");
	pos = arrHref.length - 1;
	
	if(thisEl.id == "add_imovel"){
		x_adicionaItemLista(arrHref[pos], retornaLista);
		el = document.getElementById("add_imovel")
		el.childNodes[0].nodeValue = "Excluir imóvel da minha lista ?";
		el.href = "./lista-de-interesses/excluir-da-lista/" + arrHref[pos];
		el.id = "remove_imovel";
	
	} else if(thisEl.id == "remove_imovel"){
		x_removeItemLista(arrHref[pos], retornaLista);
		el = document.getElementById("remove_imovel")
		el.childNodes[0].nodeValue = "Adicionar a minha lista";
		el.href = "./adicionar-a-lista/" + arrHref[pos];
		el.id = "add_imovel";
	}
}

function retornaLista(valor){
	var el, p, ps, breake;
	
	p = document.createElement("p");
	p.className = "msg_sucesso";
	p.appendChild(document.createTextNode(valor));
	el = document.getElementById("msg_return_lista");
	
	breake = false;
	ps = el.childNodes;
	if(ps[0]){
	el.removeChild(ps[0]);
	}
	
	el.appendChild(p);
}

function disableText(id){
	var el, cpf, cnpj, razao, nome;
	
	cnpj = document.getElementById("f_cnpj");
	razao = document.getElementById("f_razao");
	cpf = document.getElementById("f_cpf");
	nome = document.getElementById("f_nome");
	
	if(id == "f_pj"){ //f_pf	
		cpf.disabled = nome.disabled = "disabled";
		cnpj.disabled = razao.disabled = false;
		cpf.style.background = nome.style.background = "#FCFCFC";
		cnpj.style.background = razao.style.background = "#F3F3F3";
	
	} else if(id == "f_pf"){
		cnpj.disabled = razao.disabled = "disabled";
		cpf.disabled = nome.disabled = false;
		cnpj.style.background = razao.style.background = "#FCFCFC";
		cpf.style.background = nome.style.background = "#F3F3F3";
	}
}

function displayQuemSomos(){
	var el, url, splitUrl;
	
	url = window.location.href;
	splitUrl = url.split("#");
	
	if((splitUrl[1] == "quem-somos") || (!splitUrl[1])){
		if(el = document.getElementById("quem-somos")){
			el.style.display = "block";
		}
	}
}


Array.prototype.inArray = function (value){
var i;
for (i=0; i < this.length; i++) {
if (this[i] === value) {
return true;
}
}
return false;
}