function update_distrito(){
var selDistrito=document.forms['frmPesquisa'].distrito
if(selDistrito.selectedIndex!=0){
document.forms['frmPesquisa'].concelho.options.length=0
document.forms['frmPesquisa'].concelho.options[0]=new Option('Concelhos','0')
var distr=(selDistrito.options[selDistrito.selectedIndex].value)*1
var total=concelhosTodos[distr].length
for(var a=0;a<total;a++){
document.forms['frmPesquisa'].concelho.options[(a+1)]=new Option(UCWords(concelhosTodos[distr][a][1]),concelhosTodos[distr][a][0])}
document.forms['frmPesquisa'].concelho.style.visibility='visible'}
else{
document.forms['frmPesquisa'].concelho.style.visibility='hidden'}
document.forms['frmPesquisa'].freguesia.style.visibility='hidden'
document.getElementById("btMostrarMapa").style.display='none'
document.getElementById("btMostrarMapaHidden").style.display='block'
document.getElementById("l_locais").style.display='none'}
function update_concelho(){
var selConcelho=document.forms['frmPesquisa'].concelho
if(selConcelho.selectedIndex!=0){
document.forms['frmPesquisa'].freguesia.options.length=0
document.forms['frmPesquisa'].freguesia.options[0]=new Option('Freguesias','0')
var selDistrito=document.forms['frmPesquisa'].distrito
var distr=(selDistrito.options[selDistrito.selectedIndex].value)*1
var concel=(selConcelho.options[selConcelho.selectedIndex].value)*1
var total=freguesiasTodas[distr][concel].length
for(var a=0;a<total;a++){
document.forms['frmPesquisa'].freguesia.options[(a+1)]=new Option(UCWords(freguesiasTodas[distr][concel][a][1]),freguesiasTodas[distr][concel][a][0])}
document.forms['frmPesquisa'].freguesia.style.visibility='visible'}
else{
document.forms['frmPesquisa'].freguesia.style.visibility='hidden'}
document.getElementById("btMostrarMapa").style.display='none'
document.getElementById("btMostrarMapaHidden").style.display='block'
document.getElementById("l_locais").style.display='none'}
function update_freguesia(){
var selDistrito=document.forms['frmPesquisa'].distrito
var selConcelho=document.forms['frmPesquisa'].concelho
var selFreg=document.forms['frmPesquisa'].freguesia
var distr=(selDistrito.options[selDistrito.selectedIndex].value)*1
var concel=(selConcelho.options[selConcelho.selectedIndex].value)*1
var freg=(selFreg.options[selFreg.selectedIndex].value)*1
if(selFreg.selectedIndex!=0){
document.getElementById("btMostrarMapa").style.display='block'
document.getElementById("btMostrarMapaHidden").style.display='none'
update_locais()
document.getElementById("l_locais").style.display=''}
else{
document.getElementById("btMostrarMapa").style.display='none'
document.getElementById("btMostrarMapaHidden").style.display='block'
document.getElementById("l_locais").style.display='none'}
setCheckedValue(document.forms['frmPesquisa'].local_rua,0)}
var frSrc=""
function updatePesquisa(){
document.getElementById("colCentralMapa").style.display=''
document.getElementById("layerInicialDiv").style.display='none'
var selDistrito=document.forms['frmPesquisa'].distrito
var selConcelho=document.forms['frmPesquisa'].concelho
var selFreg=document.forms['frmPesquisa'].freguesia
var distr=(selDistrito.options[selDistrito.selectedIndex].value)
var concel=(selConcelho.options[selConcelho.selectedIndex].value)
var freg=(selFreg.options[selFreg.selectedIndex].value)
var selLocal=document.forms['frmPesquisa'].locais
var loc=(selLocal.options[selLocal.selectedIndex].value)
var fregues=distr+concel+freg
aproximaMapa(fregues,loc)}
var tXHR=0
function XMLHTTPRequest(){
if(window.XMLHttpRequest){
a=new XMLHttpRequest();}
else{
try{
a=new ActiveXObject("Msxml2.XMLHTTP")}
catch(e){
try{
a=new ActiveXObject("Microsoft.XMLHTTP")}
catch(e){
a=false}}}
return a}
function update_locais(){
var selDistrito=document.forms['frmPesquisa'].distrito
var selConcelho=document.forms['frmPesquisa'].concelho
var selFreg=document.forms['frmPesquisa'].freguesia
var distr=(selDistrito.options[selDistrito.selectedIndex].value)
var concel=(selConcelho.options[selConcelho.selectedIndex].value)
var freg=(selFreg.options[selFreg.selectedIndex].value)
var pFreguesia=distr+concel+freg
var zona="CON"
if(distr>30&&distr<33)
zona="MAD"
else
if(distr>40&&distr<50)
zona="ACO"
tXHR=XMLHTTPRequest()
if(tXHR){
document.forms['frmPesquisa'].locais.length=0
document.forms['frmPesquisa'].locais.options[0]=new Option("Aguarde....","")
tXHR.open("GET","locais.jsp?freguesia="+pFreguesia+"&zona="+zona,true)
tXHR.onreadystatechange=resultadoLocais
tXHR.send(null)}}
function resultadoLocais(){
if(!tXHR){
return false}
else{
if(tXHR.readyState==4){
if(tXHR.status==200){
document.getElementById("l_locais").innerHTML=tXHR.responseText}
else{
alert('Erro! "'+tXHR.statusText+'" (erro '+tXHR.status+')')}}}}
function getCheckedValue(radioObj){
if(!radioObj)
return ""
var radioLength=radioObj.length
if(radioLength==undefined)
if(radioObj.checked)
return radioObj.value
else
return ""
for(var i=0;i<radioLength;i++){
if(radioObj[i].checked){
return radioObj[i].value}}
return ""}
function setCheckedValue(radioObj,newValue){
if(!radioObj)
return
var radioLength=radioObj.length
if(radioLength==undefined){
radioObj.checked=(radioObj.value==newValue.toString())
return}
for(var i=0;i<radioLength;i++){
radioObj[i].checked=false
if(radioObj[i].value==newValue.toString()){
radioObj[i].checked=true}}}
function getURLParam(strParamName){
var strReturn=""
var strHref=window.location.href
if(strHref.indexOf("?")>-1){
var strQueryString=strHref.substr(strHref.indexOf("?")).toLowerCase()
var aQueryString=strQueryString.split("&")
for(var iParam=0;iParam<aQueryString.length;iParam++){
if(
aQueryString[iParam].indexOf(strParamName.toLowerCase()+"=")>-1){
var aParam=aQueryString[iParam].split("=")
strReturn=aParam[1]
break}}}
return unescape(strReturn)}

function showCalculos(){
window.open("calculos.jsp","calculos")}

function showPortaria(){
window.open("http://info.portaldasfinancas.gov.pt/NR/rdonlyres/D5554195-D729-4500-ADB5-2B1F3339870A/0/portaria_1119_2009.pdf","portaria")}

function UCWords(str){
str=str.toLowerCase()
arrStr=str.split(" ")
var strOut=''
for(i=0;i<arrStr.length;i++){
if(arrStr[i]!='da'&&arrStr[i]!='de'&&arrStr[i]!='do'&&arrStr[i]!='das'&&arrStr[i]!='dos'){
firstChar=arrStr[i].substring(0,1)
remainChar=arrStr[i].substring(1)
if(firstChar=="("){
firstChar="("+arrStr[i].substring(1,2).toUpperCase()
remainChar=arrStr[i].substring(2)}
else{
firstChar=firstChar.toUpperCase()
remainChar=remainChar.toLowerCase()}
strOut+=firstChar+remainChar+' '}
else
strOut+=arrStr[i]+' '}
return strOut.substring(0,strOut.length-1)}
function fecharMsg(){document.getElementById('layerInicialDiv').style.display='none';}
function zoomTo(lat, lon){
centerat = new GLatLng(lat, lon)
gmap.setCenter(centerat, 17)
fecharPesquisa()
}
function fecharPesquisa(){document.getElementById("locaisHTMLTxt").innerHTML='';document.getElementById('locaisHTMLDiv').style.display='none';}  
