﻿function AbrirTour2(codigo, indice) {
	var objJanela = window.open("/pics/" + codigo.toString() + "/tour2/" + indice, "tour", "toolbar=no,location=no,status=no,menubar=no,scrollbars=no,resizable=no,top=0,left=0,width=880,height=520");
	objJanela.focus();
}

function AbrirTour(codigo) {
	var objJanela = window.open("http://www.self-imoveis.com.br/sistema/pics/" + codigo.toString() + "/tour/applet.htm", "tour", "toolbar=no,location=no,status=no,menubar=no,scrollbars=no,resizable=no,top=0,left=0,width=400,height=300");
	objJanela.focus();
}

function AbrirFoto360(foto) {
	var objJanela = window.open(foto, "foto", "toolbar=no,location=no,status=no,menubar=no,scrollbars=no,resizable=no,top=0,left=0,width=630,height=480");
	objJanela.focus();
}

function AbrirFotoComum(carregador, foto, tooltip) {
	var imgFoto = new Image();
	imgFoto.src = foto;
	
	var largura = imgFoto.width;
	var altura = imgFoto.height;

	if (largura == 0) largura = 770;
	if (altura == 0) altura = 520;
	
	var objJanela = window.open(carregador + "?foto=" + foto + "&tooltip=" + tooltip,"foto","top=0, left=0");
	objJanela.resizeTo(largura, altura);
	objJanela.focus();
}

function ampliar(alvo) {
	document.getElementById('foto').src = document.getElementById('carregando').src;

	if (document.getElementById('divFoto').style.visibility == 'hidden') {

		///////// variáveis que retornam o scrollTop e o scrollLeft da página
		var scrOfX = 0, scrOfY = 0;
		if (typeof (window.pageYOffset) == 'number') {
			//Netscape compliant
			scrOfY = window.pageYOffset;
			scrOfX = window.pageXOffset;
		} else if (document.body && (document.body.scrollLeft || document.body.scrollTop)) {
			//DOM compliant
			scrOfY = document.body.scrollTop;
			scrOfX = document.body.scrollLeft;
		} else if (document.documentElement && (document.documentElement.scrollLeft || document.documentElement.scrollTop)) {
			//IE6 standards compliant mode
			scrOfY = document.documentElement.scrollTop;
			scrOfX = document.documentElement.scrollLeft;
		}
		/////////

		document.getElementById('divFoto').style.top = scrOfY + 50 + "px";
		document.getElementById('divFoto').style.left = scrOfX + 50 + "px";

		document.getElementById('divTrasnp').style.top = scrOfY + "px";
		document.getElementById('divTrasnp').style.left = scrOfX + "px";

		document.getElementById('foto').src = document.getElementById(alvo).src;

		document.getElementById('foto').setAttribute('numFoto', alvo.replace('foto', ''));
	}

	visible('divFoto');
	visible('divTrasnp');

	if (document.getElementById('fotos360')) visible('fotos360');

	ampliarProxima(0);
}

function posicionar() {

	///////// variáveis que retornam o scrollTop e o scrollLeft da página
	var scrOfX = 0, scrOfY = 0;
	if (typeof (window.pageYOffset) == 'number') {
		//Netscape compliant
		scrOfY = window.pageYOffset;
		scrOfX = window.pageXOffset;
	} else if (document.body && (document.body.scrollLeft || document.body.scrollTop)) {
		//DOM compliant
		scrOfY = document.body.scrollTop;
		scrOfX = document.body.scrollLeft;
	} else if (document.documentElement && (document.documentElement.scrollLeft || document.documentElement.scrollTop)) {
		//IE6 standards compliant mode
		scrOfY = document.documentElement.scrollTop;
		scrOfX = document.documentElement.scrollLeft;
	}
	/////////

	document.getElementById('divFoto').style.top = scrOfY + 50 + "px";
	document.getElementById('divFoto').style.left = scrOfX + 50 + "px";

	document.getElementById('divTrasnp').style.top = scrOfY + "px";
	document.getElementById('divTrasnp').style.left = scrOfX + "px";
}

function ampliarProxima(indice) {

	if (document.getElementById('foto').getAttribute('numFoto') != '') {

		var numFoto = parseInt(document.getElementById('foto').getAttribute('numFoto'));

		numFoto += indice;

		var alvo = 'foto' + numFoto;
		var testeAlvoAnterior = 'foto' + (numFoto - 1);
		var testeAlvoProximo = 'foto' + (numFoto + 1);

		document.getElementById('foto').src = document.getElementById(alvo).src;

		document.getElementById('foto').setAttribute('numFoto', alvo.replace('foto', ''));

		if (document.getElementById(testeAlvoAnterior)) {
			document.getElementById('setaFotoAnterior').style.visibility = 'visible';
		} else {
			document.getElementById('setaFotoAnterior').style.visibility = 'hidden';
		}

		if (document.getElementById(testeAlvoProximo)) {
			document.getElementById('setaFotoProxima').style.visibility = 'visible';
		} else {
			document.getElementById('setaFotoProxima').style.visibility = 'hidden';
		}

	}

}

function ampliaFotoImovel(objeto) {
	document.getElementById('fotoImovel').style.visibility = 'hidden';

	document.getElementById('fotoImovel').width = objeto.width;
	document.getElementById('fotoImovel').height = objeto.height;
	document.getElementById('fotoImovel').src = objeto.src;

	document.getElementById('fotoLegenda').innerHTML = objeto.getAttribute('alt');

	redimImg(document.getElementById('fotoImovel'), 420, 300);
}

function redimImg(objeto, largura, altura, objetoOrigem) {
	//Redimencionando a imagem do produto
	if (objeto) {
		objeto.style.visibility = 'hidden';
		if (objetoOrigem == null) {
			objetoOrigem = objeto;
		}
		heightValue = objetoOrigem.height;
		widthValue = objetoOrigem.width;

		//Se a altura for maior que a largura
		if (heightValue > widthValue) {
			if (heightValue > altura) {
				objeto.height = altura;
				objeto.width = widthValue / (heightValue / altura);
			}
		}
		else {
			if (widthValue > largura) {
				objeto.width = largura;
				objeto.height = heightValue / (widthValue / largura);
			}
		}

		objeto.style.position = 'static';
		objeto.style.visibility = 'visible';
	}
}

function visible(visibleAlvo, estado) {
	if (estado == null || estado == 'undefined') {
		if (document.getElementById(visibleAlvo).style.visibility == 'visible' || document.getElementById(visibleAlvo).style.visibility == '') {
			estado = 'hidden';
		}
		else {
			estado = 'visible';
		}

	}

	document.getElementById(visibleAlvo).style.visibility = estado;
}

function jm_integermask(t) {
	var donepatt = /^(\d*)$/;

	if (!t.value.match(donepatt)) {
		t.value = t.value.replace(/[\D]/gi, '');
	}
}

function jm_currencymask(t) {
	var patt = /(\d*)\,{1}(\d{0,2})/;
	var donepatt = /^(\d*)\,{1}(\d{2})$/;
	var str = t.value;
	var result;
	if (!str.match(donepatt)) {
		result = str.match(patt);
		if (result != null) {
			t.value = t.value.replace(/[^\d]/gi, '');
			str = result[1] + ',' + result[2];
			t.value = str;
		}
		else {
			if (t.value.match(/[^\d]/gi)) {
				t.value = t.value.replace(/[^\d]/gi, '');
			}
		}
	}
}

function checkCR(evt) {
	var evt = (evt) ? evt : ((event) ? event : null);
	var node = (evt.target) ? evt.target : ((evt.srcElement) ? evt.srcElement : null);

	if
		(
			node.type != "submit" &&
			node.type != "textarea"
		) {
		if (evt.keyCode == 13) { return false; }
	}
	if (node.type == "select-one") {
		if (evt.keyCode == 8) { return false; }
	}

	return true;
}

document.onkeypress = checkCR;