// JavaScript Document
//Posicao vertical utilizada para definir posição do campo de pesquisa no Internet Explorer

function subMenu(layer,botao) { 
	var ClasseLayer = document.getElementById(layer).className
	if (ClasseLayer=='listagemVertSome') { 
		document.getElementById(layer).className='listagemVert'
		document.getElementById(botao).innerHTML='&nbsp; [-]'
	} 
	if (ClasseLayer=='listagemVert') { 
		document.getElementById(layer).className='listagemVertSome'
		document.getElementById(botao).innerHTML='&nbsp; [+]'
	}
}

var posicaoV = 0
var Ncamada = ""

//Estrutura do AJAX - Get XML Http Object
function GetXmlHttpObject()	{ 
	var objXMLHttp=null
	if (window.XMLHttpRequest) {
		objXMLHttp=new XMLHttpRequest()	}
	else if (window.ActiveXObject)	{
		objXMLHttp=new ActiveXObject("Microsoft.XMLHTTP")	}
	return objXMLHttp
} 		
function findPos(obj) {
	var curleft = curtop = 0;
	if (obj.offsetParent) {
		do {
			curleft += obj.offsetLeft;
			curtop += obj.offsetTop;
			} while (obj = obj.offsetParent);
	return [curtop];
	}
}
function Detalhes(codigo,posicao,ref,camada,codimob,flagacesso) {
	posicaoV = posicao
	Ncamada = camada 
	xmlHttp=GetXmlHttpObject()
	if (xmlHttp==null) {
		alert ("Seu navegador não dá suporte a HTTP Request")
	return	} 
	var dt = new Date();
	
	var resolucao = screen.width
	var posEsq	= 0
	var altura  = 100
	if (resolucao=='800') { 
		posEsq = 100
		altura = 100
	} else { 
		posEsq = 200
		altura = 150
	} 	
	window.open("inc/detalhes.asp?codimov="+codigo+"&codimob="+codimob+"&tipo=janela&ref="+ref+"&flagacesso="+flagacesso+"&Data="+encodeURI("_" + dt.getTime()),"","width=750,height=550,left="+posEsq+",top="+altura+",scrollbars=1,resizable=0,status=0,menubar=0")
//	var url = "inc/detalhes.asp?codimov="+codigo+"&tipo=janela&ref="+ref+"&Data="+encodeURI("_" + dt.getTime())
//	xmlHttp.onreadystatechange=stateChanged
//	xmlHttp.open("GET",url,true)
//	xmlHttp.send(null)
}
function DetalhesAnuncioP(codigo,posicao,ref,camada,codimob,flagacesso) {
	posicaoV = posicao
	Ncamada = camada 
	xmlHttp=GetXmlHttpObject()
	if (xmlHttp==null) {
		alert ("Seu navegador não dá suporte a HTTP Request")
	return	} 
	var dt = new Date();
	
	var resolucao = screen.width
	var posEsq	= 0
	var altura  = 100
	if (resolucao=='800') { 
		posEsq = 170
		altura = 100
	} else { 
		posEsq = 280
		altura = 150
	} 	
	window.open("inc/detalhes_portal.asp?codimov="+codigo+"&codimob="+codimob+"&tipo=janela&ref="+ref+"&flagacesso="+flagacesso+"&Data="+encodeURI("_" + dt.getTime()),"","width=700,height=500,left="+posEsq+",top="+altura+",scrollbars=1,resizable=0,status=0,menubar=0")
//	var url = "inc/detalhes.asp?codimov="+codigo+"&tipo=janela&ref="+ref+"&Data="+encodeURI("_" + dt.getTime())
//	xmlHttp.onreadystatechange=stateChanged
//	xmlHttp.open("GET",url,true)
//	xmlHttp.send(null)
}
function TotalVisita(codigo,codref) {
	xmlHttp=GetXmlHttpObject()
	if (xmlHttp==null) {
		alert ("Seu navegador não dá suporte a HTTP Request")
	return	} 
	var dt = new Date();
	
	var resolucao = screen.width
	var posEsq	= 0
	var altura  = 100
	if (resolucao=='800') { 
		posEsq = 170
		altura = 100
	} else { 
		posEsq = 310
		altura = 160
	} 	
//	document.getElementById('frameVisitas').src="imov_visitas.asp?codimov="+codigo+"&codref="+codref+"&Data="+encodeURI("_" + dt.getTime())
//	document.getElementById("MostraVisitas").className='mostra' 
	window.open("imov_visitas.asp?codimov="+codigo+"&codref="+codref+"&Data="+encodeURI("_" + dt.getTime()),"","width=440,height=300,left="+posEsq+",top="+altura+",scrollbars=1,resizable=0,status=0,menubar=0")
//	var url = "imov_visitas.asp?codimov="+codigo+"&codref="+codref+"&Data="+encodeURI("_" + dt.getTime())
//	xmlHttp.onreadystatechange=stateChanged3
//	xmlHttp.open("GET",url,true)
//	xmlHttp.send(null)
}
function stateChanged3() { 
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete"){ 
		document.getElementById("MostraVisitas").className='mostra' 
	} 
} 
function DetalhesPRINT(codigo,ref,codimob,flagacesso) {
//	posicaoV = posicao
//	Ncamada = camada 
//	xmlHttp=GetXmlHttpObject()
//	if (xmlHttp==null) {
	//	alert ("Seu navegador não dá suporte a HTTP Request")
//	return	} 
	var dt = new Date();
	
	var resolucao = screen.width
	var posEsq	= 0
	var altura  = 100
	if (resolucao=='800') { 
		posEsq = 190
		altura = 120
	} else { 
		posEsq = 230
		altura = 200
	} 	
	window.open("detalhes_print.asp?codimov="+codigo+"&codimob="+codimob+"&tipo=janela&ref="+ref+"&flagacesso="+flagacesso+"&Data="+encodeURI("_" + dt.getTime()),"","width=700,height=500,left="+posEsq+",top="+altura+",scrollbars=1,resizable=0,status=0,menubar=0")
	//window.open("inc/detalhes_print.asp?codimov="+codigo+"&codimob="+codimob+"&tipo=janela&ref="+ref+"&flagacesso="+flagacesso+"&Data="+encodeURI("_" + dt.getTime()),"","width=600,height=500,left="+posEsq+",top="+altura+",scrollbars=1,resizable=0,status=0,menubar=0")
}
function DetalhesJanela(endereco,codigo,ref,codimob,flagacesso) {
//	posicaoV = posicao
//	Ncamada = camada 
//	xmlHttp=GetXmlHttpObject()
//	if (xmlHttp==null) {
	//	alert ("Seu navegador não dá suporte a HTTP Request")
//	return	} 
	var dt = new Date();
	
	var resolucao = screen.width
	var posEsq	= 0
	var altura  = 100
	if (resolucao=='800') { 
		posEsq = 190
		altura = 120
	} else { 
		posEsq = 230
		altura = 200
	} 	
	window.open(endereco+".asp?codimov="+codigo+"&codimob="+codimob+"&tipo=janela&ref="+ref+"&flagacesso="+flagacesso+"&Data="+encodeURI("_" + dt.getTime()),"","width=700,height=500,left="+posEsq+",top="+altura+",scrollbars=1,resizable=0,status=0,menubar=0")
	//window.open("inc/detalhes_print.asp?codimov="+codigo+"&codimob="+codimob+"&tipo=janela&ref="+ref+"&flagacesso="+flagacesso+"&Data="+encodeURI("_" + dt.getTime()),"","width=600,height=500,left="+posEsq+",top="+altura+",scrollbars=1,resizable=0,status=0,menubar=0")
}

function stateChanged() { 
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete"){ 
		document.getElementById("janela").className='mostra' 
		document.getElementById("janela").innerHTML=xmlHttp.responseText 
		var browser=navigator.appName;
		if (browser=="Microsoft Internet Explorer") { 
			 var dsoctop=document.body.scrollTop
			 if (Ncamada=='') {  
			 document.getElementById('janela').style.top = posicaoV
			 } else { 
			 document.getElementById('janela').style.top = findPos(document.getElementById(Ncamada))
			 }
		}
		//alert(document.getElementById(id).style.top)		
	} 
} 
function critPesq(codigo, posicao, ref) { 
	if (ref!='') {
		Detalhes(codigo,posicao,ref,'')
	} 
}
function trocaIMG(campo,img, local) { 
	document.getElementById(campo).innerHTML='<img src="'+img+'" height="250" border="3"><br><center><b style="text-transform:uppercase;font-size:11px;">&nbsp;'+local+'&nbsp;</b></center>'
}

function maskData(data) { 
	var valor=document.getElementById(data).value
//	if (valor.length==2 || valor.length==5) {
//		document.getElementById(data).value=valor+'/' 
//		}

	var w_tamanho=valor.length
	var w_indori1=0
	var w_destino=''
	while (w_indori1<(w_tamanho)) {
		w_indori2=w_indori1+1
		w_byte=(valor.substring(w_indori1,w_indori2))
		if (isNaN(w_byte)) 
			{
			w_indori1=w_indori1+1
		}else
		{
			w_destino=w_destino+w_byte
			w_indori1=w_indori1+1
		}
	}
	var w_tamanho=w_destino.length
	document.getElementById(data).value=w_destino

	if (w_tamanho > 4) {
		document.getElementById(data).value=((w_destino.substring(0,2))+'/'+(w_destino.substring(2,4))+'/'+(w_destino.substring(4,w_tamanho)))
 	 }
	if ((w_tamanho > 2)&&(w_tamanho < 5)) {
		document.getElementById(data).value=((w_destino.substring(0,2))+'/'+(w_destino.substring(2,w_tamanho)))
	 }
}

function carregandoTela() { 
	document.getElementById("LOADtela").className="mostra" 
	document.getElementById("LOADescurecer").className="mostra" 
	//document.getElementById("mini_loading").className="mostra" 
	//document.getElementById("LOADtela").innerHTML="<img src='img/loading.gif' height='30'><br><b style='color:#FFFFFF;font-weight:bold;font-size:11px;'>Carregando</b>"
	var browser=navigator.appName;
	if (browser=="Microsoft Internet Explorer") { 
		 var dsoctop=document.body.scrollTop
		 var window_height=document.body.scrollHeight
		 var window_width=document.body.scrollWidth
		document.getElementById("LOADescurecer").style.height 	= window_height
		document.getElementById("LOADescurecer").style.width 	= window_width
		document.getElementById("LOADtela").style.top 			= dsoctop+15
	}
}



function Selecionar(cestab, ctipo, ccidade, vtipo, vcidade, vtexto) { 

	for (var i=0; i<document.getElementById(cestab).options.length; i++){ 
		document.getElementById(cestab).options[i].selected = true}

	if (vtipo=="geral") { 
		for (var i=0; i<document.getElementById(ctipo).options.length; i++)	{ 
			document.getElementById(ctipo).options[i].selected = true}	
	} else	{ 
		if (vtipo=="apartamento") {
			for (var t=0; t<document.getElementById(ctipo).options.length; t++) {
				if ( document.getElementById(ctipo).options[t].value=='3' || document.getElementById(ctipo).options[t].value=='12' || document.getElementById(ctipo).options[t].value=='13' || document.getElementById(ctipo).options[t].value=='19' || document.getElementById(ctipo).options[t].value=='29' || document.getElementById(ctipo).options[t].value=='14' || document.getElementById(ctipo).options[t].value=='30'){ 
					document.getElementById(ctipo).options[t].selected=true	} else 	{ 
					document.getElementById(ctipo).options[t].selected=false}
			}
		} else { 
			if (vtipo=="casa") {
				for (var t=0; t<document.getElementById(ctipo).options.length; t++) {
					if ( document.getElementById(ctipo).options[t].value=='1' || document.getElementById(ctipo).options[t].value=='2' || document.getElementById(ctipo).options[t].value=='20' || document.getElementById(ctipo).options[t].value=='15'){ 
					document.getElementById(ctipo).options[t].selected=true	} else { 
					document.getElementById(ctipo).options[t].selected=false}
				}
			} else { 
				if (vtipo=="sitio") {
					for (var t=0; t<document.getElementById(ctipo).options.length; t++) {
						if ( document.getElementById(ctipo).options[t].value=='7' || document.getElementById(ctipo).options[t].value=='8' || document.getElementById(ctipo).options[t].value=='9' )	{ 
							document.getElementById(ctipo).options[t].selected=true	} else { 
							document.getElementById(ctipo).options[t].selected=false}
					}
				} else { 
					if (vtipo=="salas") {
						for (var t=0; t<document.getElementById(ctipo).options.length; t++) {
							if ( document.getElementById(ctipo).options[t].value=='4' || document.getElementById(ctipo).options[t].value=='5' || document.getElementById(ctipo).options[t].value=='22' || document.getElementById(ctipo).options[t].value=='23' || document.getElementById(ctipo).options[t].value=='25' || document.getElementById(ctipo).options[t].value=='11' || document.getElementById(ctipo).options[t].value=='31'){ 
								document.getElementById(ctipo).options[t].selected=true	} else { 
								document.getElementById(ctipo).options[t].selected=false}
						}
					} else { 
						if (vtipo=="terreno") {
							for (var t=0; t<document.getElementById(ctipo).options.length; t++) {
								if ( document.getElementById(ctipo).options[t].value=='10' || document.getElementById(ctipo).options[t].value=='21' || document.getElementById(ctipo).options[t].value=='6' ){ 
									document.getElementById(ctipo).options[t].selected=true	} else { 
									document.getElementById(ctipo).options[t].selected=false}
							}
						} else { 
							for (var t=0; t<document.getElementById(ctipo).options.length; t++) { 
									if	( document.getElementById(ctipo).options[t].value==vtipo	) { 
										document.getElementById(ctipo).options[t].selected=true	} else { 
										document.getElementById(ctipo).options[t].selected=false	}
								}
						}
					}
				}
			}
		}
	}
	for (var c=0; c<document.getElementById(ccidade).options.length; c++) { 
		if ( vcidade.match("08841") ) { 
			if ( document.getElementById(ccidade).options[c].value.match(vcidade) ) { 
					document.getElementById(ccidade).options[c].selected=true 	} else {
					document.getElementById(ccidade).options[c].selected=false	}
		} else { 
			if (vcidade=="imovelabc") { 
				if ( document.getElementById(ccidade).options[c].value=="08265" || document.getElementById(ccidade).options[c].value=="08530" || document.getElementById(ccidade).options[c].value=="08731" || document.getElementById(ccidade).options[c].value=="08740" || document.getElementById(ccidade).options[c].value=="08798" || document.getElementById(ccidade).options[c].value=="08813" || document.getElementById(ccidade).options[c].value=="08815" ) { 
						document.getElementById(ccidade).options[c].selected=true 	} else {
						document.getElementById(ccidade).options[c].selected=false	}
			} else {
				if (vcidade=="imovelat") {
					if ( document.getElementById(ccidade).options[c].value=="08099" || document.getElementById(ccidade).options[c].value=="08146" || document.getElementById(ccidade).options[c].value=="08311" || document.getElementById(ccidade).options[c].value=="08350" || document.getElementById(ccidade).options[c].value=="08424" || document.getElementById(ccidade).options[c].value=="08544" || document.getElementById(ccidade).options[c].value=="08679" || document.getElementById(ccidade).options[c].value=="08756" || document.getElementById(ccidade).options[c].value=="08780" || document.getElementById(ccidade).options[c].value=="08874" )	{			
							document.getElementById(ccidade).options[c].selected=true 	} else {
							document.getElementById(ccidade).options[c].selected=false	}
				} else {
					if ( document.getElementById(ccidade).options[c].value==vcidade ) { 
							document.getElementById(ccidade).options[c].selected=true 	} else {
							document.getElementById(ccidade).options[c].selected=false	}
				}
				
			}
		}		
	}
	
	var txtact = document.getElementById('filtro1').action
	document.getElementById('filtro1').action=txtact+'&ID='+vtexto
	document.getElementById('filtro1').submit();
	carregandoTela();
}

/*

function Selecionar(cestab, ctipo, ccidade, vtipo, vcidade, vtexto) { 
	if (vtipo=="residencial" || vtipo=="industrial" || vtipo=="comercial" || vtipo=="rural" || vtipo=="geral" ){
		if (vtipo=="geral") { 
			for (var i=0; i<document.getElementById(cestab).options.length; i++) {
				document.getElementById(cestab).options[i].selected = true
			}
			for (var i=0; i<document.getElementById(ctipo).options.length; i++) {
				document.getElementById(ctipo).options[i].selected = true
			}
		} else {
			for (var i=0; i<document.getElementById(ctipo).options.length; i++) {
				document.getElementById(ctipo).options[i].selected = true
			}
			var tempTipo 
			if (vtipo=="residencial") 	{ tempTipo=1 }
			if (vtipo=="comercial") 	{ tempTipo=2 }
			if (vtipo=="industrial") 	{ tempTipo=3 }
			if (vtipo=="rural")		 	{ tempTipo=4 }
			for (var e=0; e<document.getElementById(cestab).options.length; e++) { 
				if ( document.getElementById(cestab).options[e].value==tempTipo) { 
						document.getElementById(cestab).options[e].selected=true 
				} else {
						document.getElementById(cestab).options[e].selected=false
				}
			}
		}
	} else { 
		for (var i=0; i<document.getElementById(cestab).options.length; i++) {
			document.getElementById(cestab).options[i].selected = true
		}
		for (var t=0; t<document.getElementById(ctipo).options.length; t++) { 
			if ( document.getElementById(ctipo).options[t].value==vtipo ) { 
					document.getElementById(ctipo).options[t].selected=true 
			} else {
					document.getElementById(ctipo).options[t].selected=false
			}
		}
	}
	
	for (var c=0; c<document.getElementById(ccidade).options.length; c++) { 
		if ( vcidade=='08841' ) { 
			if ( document.getElementById(ccidade).options[c].value.match(vcidade) ) { 
					document.getElementById(ccidade).options[c].selected=true 	} else {
					document.getElementById(ccidade).options[c].selected=false	}
		} else { 
			if ( vcidade=='08841L' ) { 
				if ( document.getElementById(ccidade).options[c].value.match(vcidade) ) { 
						document.getElementById(ccidade).options[c].selected=true 	} else {
						document.getElementById(ccidade).options[c].selected=false	}
			} else { 
				if ( vcidade=='08841S' ) { 
					if ( document.getElementById(ccidade).options[c].value.match(vcidade) ) { 
							document.getElementById(ccidade).options[c].selected=true 	} else {
							document.getElementById(ccidade).options[c].selected=false	}
				} else { 
					if ( document.getElementById(ccidade).options[c].value==vcidade ) { 
							document.getElementById(ccidade).options[c].selected=true 	} else {
							document.getElementById(ccidade).options[c].selected=false	}
				}
			}		
		}
	}
	
	var txtact = document.getElementById('filtro1').action
	document.getElementById('filtro1').action=txtact+'&ID='+vtexto
	document.getElementById('filtro1').submit();
	carregandoTela();
}
*/
