var inputElement;
var mapaRow="";


function janelaPDF (url, title) { 
	try {
		janela(url, title, 750, 500, 'yes', 'yes');
	} catch (e) {
		alert('Por favor, feche a janela de impressão que se encontra aberta.');
		return false;
	}
	return false;
}

function janela (url, title, width, height, scrollbars, resize) {
	if (scrollbars == null) scrollbars='no';
	if (resize == null) resize='no';
	var opened = window.open(url, title, 'width='+width+',height='+height+',menubar=no,location=no,resizable='+resize+',scrollbars='+scrollbars+',status=yes,toolbar=no,titlebar=no');
	if (opened != null) opened.focus();
}

function janelaInput (input, url, title, width, height, scrollbars, resizable) {
    inputElement = input;
    if (scrollbars == null) scrollbars='no';
	if (resizable == null) resizable='no';
	var opened = window.open(url, title, 'width='+width+',height='+height+',menubar=no,location=no,resizable='+resizable+',scrollbars='+scrollbars+',status=no,toolbar=no,titlebar=no');
	opened.focus();
}

function setDistrito(value) {
	var dist = document.getElementsByName('distrito'+mapaRow)[0];
    dist.value = value;
    
    if (isIE()) {
		dist.fireEvent("onchange");
	} else {
		var evt = document.createEvent("HTMLEvents");
		evt.initEvent("change",true,true);
		dist.dispatchEvent( evt );
	}
}

function setConcelho(value) {
	var conc = document.getElementsByName('concelho'+mapaRow)[0];
    conc.value = value;
    
    if (isIE()) {
		conc.fireEvent("onchange");
	} else {
		var evt = document.createEvent("HTMLEvents");
		evt.initEvent("change",true,true);
		conc.dispatchEvent( evt );
	}
}

function setFreguesia(value) {
	var freg = document.getElementsByName('freguesia'+mapaRow)[0];
    
    if (freg==null) return;
    
    freg.value = value;
    
    if (isIE()) {
		freg.fireEvent("onchange");
	} else {
		var evt = document.createEvent("HTMLEvents");
		evt.initEvent("change",true,true);
		freg.dispatchEvent( evt );
	}
}
/*
function janelaZonamentoLocalizacao(baseUrl, localizacao, coordX, coordY) {
    janelaZonamentoTipo(baseUrl, '', localizacao, coordX, coordY);
}

function janelaZonamentoTipo(baseUrl, tipoCoefLoc, localizacao, coordX, coordY) {
    janelaZonamento(baseUrl, tipoCoefLoc, localizacao, coordX, coordY, null);
}

function janelaZonamento(baseUrl, tipoCoefLoc, localizacao, coordX, coordY, urlResposta) {
    var url = baseUrl;
    url += '?codFreguesia=' + localizacao;
    if (tipoCoefLoc != "") url += '&afectacao=' + tipoCoefLoc;
    if (coordX != "") url += '&coordX=' + coordX;
    if (coordY != "") url += '&coordY=' + coordY;
    if (urlResposta!=null && urlResposta!='') url += '&url=' + escape(urlResposta);

//    alert(url);

	var opened = window.open(url, 'Zonamento', "width=800, height=600, scrollbar=no,menubar=no,toolbar=no,status=yes")
	opened.focus();
}

function janelaZonamentoPublico (url) {
	//getHttpUrl(url)
	var opened = window.open('http://www.e-financas.gov.pt'+url, 'Zonamento', 'width=760,height=560,menubar=yes,location=yes,resizable=yes,scrollbars=yes,status=yes,toolbar=yes,titlebar=yes');
	if (opened != null) opened.focus();
}
*/
