Page.prototype.menuOpened = true;
Page.prototype.measure = 'decimal';

Page.prototype.leftclickCount = [0, 0]; 
Page.prototype.clicksPos = [[0],[0]];
Page.prototype.lastpolyline = ['', ''];
Page.prototype.lastrulerpoint = [0, 0];
Page.prototype.rulerpoint = [[0],[0]];
Page.prototype.distance = [0];

Page.prototype.clearRuler = function(map) {
	this.leftclickCount[map] = 0;
	this.clicksPos[map] = [0];
	this.distance[map] = 0;
}

Page.prototype.showLoading = function() {
	$(this.containers.loading).style.display = 'block';
	$(this.containers.loading).style.left = (document.body.offsetWidth / 2) - 35 + 'px';
}

Page.prototype.hideLoading = function() {
	$(this.containers.loading).style.display = 'none';
}

Page.prototype.checkRuler = function() {
}

Page.prototype.setLocalsColors = function() {
	colors = ['#550000', '#990000', '#AA0000', '#CC0000', '#EE0000', '#FF0000', '#005500', '#009900', '#00AA00', '#00CC00', '#00EE00', '#00FF00', '#000055', '#000099', '#0000AA', '#0000CC', '#0000EE', '#0000FF', '#555500', '#995500', '#AA5500', '#CC5500', '#EE5500', '#FF5500', '#559900', '#55AA00', '#55CC00', '#55EE00', '#55FF00', '#995500', '#999900', '#99AA00', '#99CC00', '#99EE00', '#99FF00', '#AA5500', '#AA9900', '#AAAA00', '#AACC00', '#AAEE00', '#AAFF00', '#CC5500', '#CC9900', '#CCAA00', '#CCCC00', '#CCEE00', '#CCEE00', '#CCFF00', '#EE5500', '#EE9900', '#EEAA00', '#EECC00', '#EEEE00', '#EEFF00', '#FF5500', '#FF9900', '#FFAA00', '#FFCC00', '#FFEE00', '#FFFF00', '#005555', '#005599', '#0055AA', '#0055CC', '#0055EE', '#0055FF', '#009955', '#009999', '#0099AA', '#0099CC', '#0099EE', '#0099FF', '#00AA55', '#00AA99', '#00AAAA', '#00AACC', '#00AAEE', '#00AAFF', '#00CC55', '#00CC99', '#00CCAA', '#00CCCC', '#00CCEE', '#00CCFF', '#00EE55', '#00EE99', '#00EEAA', '#00EECC', '#00EEEE', '#00EEFF', '#00FFFF', '#55FFFF'];
	count = 0;

	for(var i = 0; i < $(this.containers.menus.locals).childNodes.length; i++) {
		if($(this.containers.menus.locals).childNodes[i].tagName == 'SPAN') {
			$(this.containers.menus.locals).childNodes[i].style.cursor = 'pointer';
			$(this.containers.menus.locals).childNodes[i].onclick = function(e) {geoMenu.fetchLocals(this)};
			$(this.containers.menus.locals).childNodes[i].onmouseover = function(e) {this.style.backgroundColor = '#f0f0f0';};
			$(this.containers.menus.locals).childNodes[i].onmouseout = function(e) {this.style.backgroundColor = 'transparent';};

			$(this.containers.menus.locals).childNodes[i].apt = {checked : false, color : colors[count].substr(1, 6), cat : geoMenu.localsCats[count]};

			var newimage = document.createElement('IMG');
			newimage.style.marginRight = '3px';
			newimage.style.paddingBottom = '3px';
			newimage.style.verticalAlign = 'middle';
			newimage.src = '../images/geo/check_unchecked.gif';
			
			var firstchild = $(this.containers.menus.locals).childNodes[i].firstChild;
			$(this.containers.menus.locals).childNodes[i].removeChild(firstchild);
			$(this.containers.menus.locals).childNodes[i].appendChild(newimage);
			$(this.containers.menus.locals).childNodes[i].appendChild(firstchild);
			count++;
		}
	}
}

Page.prototype.check = function(obj) {
	obj.apt.checked = true;

	obj.removeChild(obj.firstChild);

	var newimage = document.createElement('IMG');
	newimage.style.marginRight = '3px';
	newimage.src = URLMODULES + '/php/doImgGen.php?color=' + obj.apt.color;
	newimage.width = 11;
	newimage.height = 11;

	obj.onclick = function(e) {geoPage.clearLocal(obj.apt.cat)};

	var firstchild = obj.firstChild;
	obj.removeChild(firstchild);
	obj.appendChild(newimage);
	obj.appendChild(firstchild);
}

Page.prototype.uncheck = function(obj) {
	obj.apt.checked = false;

	obj.removeChild(obj.firstChild);

	var newimage = document.createElement('IMG');
	newimage.style.marginRight = '3px';
	newimage.src = '../images/geo/check_unchecked.gif';
	newimage.onclick = function(e) {geoMenu.fetchLocals(this.parentNode)};
	newimage.style.cursor = 'pointer';	

	var firstchild = obj.firstChild;
	obj.removeChild(firstchild);
	obj.appendChild(newimage);
	obj.appendChild(firstchild);
}

Page.prototype.openLocals = function() {
        $(this.containers.menus.locals_floater).style.display = 'block';
	$(this.containers.menus.locals_toggler).innerHTML = '';
	newimage = document.createElement('IMG');
	newimage.src = '../images/geo/arrow_locals.gif';
	newimage.onclick = function(e) {pageObj.closeLocals();};
	newimage.style.marginTop = '1px';
	newimage.style.cursor = 'pointer';	


	$(this.containers.menus.locals_toggler).appendChild(newimage);
}

Page.prototype.closeLocals = function() {
        $(this.containers.menus.locals_floater).style.display = 'none';

	$(this.containers.menus.locals_toggler).innerHTML = '';
	newimage = document.createElement('IMG');
	newimage.src = '../images/geo/arrow_locals_close.gif';
	newimage.onclick = function(e) {pageObj.openLocals();};
	newimage.style.marginTop = '1px';
	newimage.style.cursor = 'pointer';
	
        
	$(this.containers.menus.locals_toggler).appendChild(newimage);
}

Page.prototype.getMenuState = function() {
	if(this.menuOpened == true)
		return 'open';
	else
		return 'closed';
}

Page.prototype.toggleMenu = function() {
	if(this.getMenuState() == 'open') {
		$(this.containers.menu.holder).style.display = 'none';
		$(this.containers.menu.toggler).className = 'abre-dados';
		this.menuOpened = false;
		geoPage.resizingMaps();
	} else {
		$(this.containers.menu.holder).style.display = 'block';
		$(this.containers.menu.toggler).className = 'fecha-dados';
		this.menuOpened = true;
		geoPage.resizingMaps();
	}
}

Page.prototype.afterLockMove = function() {
	if(geoPage.mapIsLocked) {
		$(this.containers.tools.lock.move).onclick = function(e) {geoPage.unlockMaps();pageObj.afterLockMove();};

		newImage = document.createElement('img');
		newImage.src = '../images/geo/tool_lock_crosshair.gif';
		newImage.title = 'movimentar mapas livremente';
		newImage.width = 25;
		newImage.height = 19;
		newImage.vspace = 5;
	} else {
		$(this.containers.tools.lock.move).onclick = function(e) {geoPage.lockMaps();pageObj.afterLockMove();};

		newImage = document.createElement('img');
		newImage.src = '../images/geo/tool_unlock_crosshair.gif';
		newImage.title = 'movimentar mapas simultaneamente';
		newImage.width = 25;
		newImage.height = 19;
		newImage.vspace = 5;
	}
	$(this.containers.tools.lock.move).innerHTML = '';
	$(this.containers.tools.lock.move).appendChild(newImage);
}

Page.prototype.afterLockZoom = function() {
	if(geoPage.zoomLocked) {
		$(this.containers.tools.lock.zoom).onclick = function(e) {geoPage.unlockZoom();pageObj.afterLockZoom();};

		newImage = document.createElement('img');
		newImage.src = '../images/geo/tool_lock_zoom.gif';
		newImage.title = 'zoom independente';
		newImage.width = 20;
		newImage.height = 19;
		newImage.vspace = 5;
	} else {
		$(this.containers.tools.lock.zoom).onclick = function(e) {geoPage.lockZoom(geoPage.selectedMap);pageObj.afterLockZoom();};

		newImage = document.createElement('img');
		newImage.src = '../images/geo/tool_unlock_zoom.gif';
		newImage.title = 'zoom simultâneo (nível mapa selecionado)';
		newImage.width = 20;
		newImage.height = 19;
		newImage.vspace = 5;
	}

	$(this.containers.tools.lock.zoom).innerHTML = '';
	$(this.containers.tools.lock.zoom).appendChild(newImage);
}

Page.prototype.afterHideMap = function(whichmap) {
	container = $(this.containers.tools.close.left);
	container2 = $(this.containers.tools.close.right);
	container3 = $(this.containers.tools.close.maps)
	
	if(typeof whichmap == 'number' && whichmap == 0) {
		$(this.containers.tools.close.right).onclick = function(e) {geoPage.hideMap(1);geoPage.selectMap(0);pageObj.afterHideMap(1);};
		$(this.containers.tools.close.left).onclick = function(e) { };
		$(this.containers.tools.close.maps).onclick = function(e) {geoPage.splitMaps();geoPage.selectMap(0);pageObj.afterHideMap();};
		$(this.containers.tools.close.left).className = '';
		$(this.containers.tools.close.right).className = 'pointer_mimic';
		$(this.containers.tools.close.maps).className = 'pointer_mimic';

		newImage = document.createElement('img');
		newImage.src = '../images/geo/tool_close_left_map_on.gif';
		newImage.title = 'exibindo mapa esquerdo';
		newImage.width = 26;
		newImage.height = 19;
		newImage.vspace = 5;

		newImage2 = document.createElement('img');
		newImage2.src = '../images/geo/tool_close_right_map.gif';
		newImage2.title = 'expandir mapa direito';
		newImage2.width = 26;
		newImage2.height = 19;
		newImage2.vspace = 5;

		newImage3 = document.createElement('img');
		newImage3.src = '../images/geo/tool_open_2maps.gif';
		newImage3.title = 'exibir ambos os mapas';
		newImage3.width = 26;
		newImage3.height = 19;
		newImage3.vspace = 5;		
	} else if(typeof whichmap == 'number' && whichmap == 1) {
		$(this.containers.tools.close.right).onclick = function(e) { };
		$(this.containers.tools.close.left).onclick = function(e) {geoPage.hideMap(0);geoPage.selectMap(1);pageObj.afterHideMap(0);};
		$(this.containers.tools.close.maps).onclick = function(e) {geoPage.splitMaps();geoPage.selectMap(1);pageObj.afterHideMap();};
		$(this.containers.tools.close.right).className = '';
		$(this.containers.tools.close.left).className = 'pointer_mimic';
		$(this.containers.tools.close.maps).className = 'pointer_mimic';

		newImage = document.createElement('img');
		newImage.src = '../images/geo/tool_close_left_map.gif';
		newImage.title = 'expandir mapa esquerdo';
		newImage.width = 26;
		newImage.height = 19;
		newImage.vspace = 5;

		newImage2 = document.createElement('img');
		newImage2.src = '../images/geo/tool_close_right_map_on.gif';
		newImage2.title = 'exibindo mapa direito';
		newImage2.width = 26;
		newImage2.height = 19;
		newImage2.vspace = 5;

		newImage3 = document.createElement('img');
		newImage3.src = '../images/geo/tool_open_2maps.gif';
		newImage3.title = 'exibir ambos os mapas';
		newImage3.width = 26;
		newImage3.height = 19;
		newImage3.vspace = 5;
	} else {
		$(this.containers.tools.close.right).onclick = function(e) {geoPage.hideMap(1);geoPage.selectMap(0);pageObj.afterHideMap(1);};
		$(this.containers.tools.close.left).onclick = function(e) {geoPage.hideMap(0);geoPage.selectMap(1);pageObj.afterHideMap(0);};
		$(this.containers.tools.close.maps).onclick = function(e) { };
		$(this.containers.tools.close.right).className = 'pointer_mimic';
		$(this.containers.tools.close.left).className = 'pointer_mimic';
		$(this.containers.tools.close.maps).className = '';

		newImage = document.createElement('img');
		newImage.src = '../images/geo/tool_close_left_map.gif';
		newImage.title = 'expandir mapa direito';
		newImage.width = 26;
		newImage.height = 19;
		newImage.vspace = 5;

		newImage2 = document.createElement('img');
		newImage2.src = '../images/geo/tool_close_right_map.gif';
		newImage2.title = 'expandir mapa esquerdo';
		newImage2.width = 26;
		newImage2.height = 19;
		newImage2.vspace = 5;

		newImage3 = document.createElement('img');
		newImage3.src = '../images/geo/tool_open_2maps_on.gif';
		newImage3.title = 'exibindo ambos os mapas';
		newImage3.width = 26;
		newImage3.height = 19;
		newImage3.vspace = 5;		
	}

	container.innerHTML = '';
	container2.innerHTML = '';
	container3.innerHTML = '';

	container.appendChild(newImage);
	container2.appendChild(newImage2);
	container3.appendChild(newImage3);	
}

Page.prototype.updateMapInfo = function(whichmap, mousepoint, zoom) {
	$(this.containers.info.map).innerHTML = whichmap;
	if(this.measure == 'decimal') {
		$(this.containers.info.lat).innerHTML = mousepoint.lat().strip(10);
		$(this.containers.info.lon).innerHTML = mousepoint.lon().strip(10);
	} else {
		convertedLat = mapObj[0].math.convertToMinutesAndSeconds(mousepoint.lat(), 'lat', 'obj')
		convertedLon = mapObj[0].math.convertToMinutesAndSeconds(mousepoint.lon(), 'lon', 'obj')

		$(this.containers.info.lat).innerHTML = convertedLat.degree + '&deg;' + convertedLat.minute + '&prime;' + convertedLat.second + '&Prime;' + convertedLat.dir;
		$(this.containers.info.lon).innerHTML = convertedLon.degree + '&deg;' + convertedLon.minute + '&prime;' + convertedLon.second + '&Prime;' + convertedLon.dir;
	}
	$(this.containers.info.zoom).innerHTML = zoom;
}

Page.prototype.changeMeasure = function() {
	if(this.measure == 'degree') {
		this.measure = 'decimal';
		$(this.containers.info.measure).innerHTML = 'n.nnn';
	} else {
		this.measure = 'degree';
		$(this.containers.info.measure).innerHTML = 'n&deg; n&prime; n&Prime;';
	}
}

Page.prototype.updateStatsType = function(stat_name) {
	if(geoPage.selectedMap == 0)
		$(this.containers.titles.text.left).innerHTML = stat_name;
	else
		$(this.containers.titles.text.right).innerHTML = stat_name;
}

Page.prototype.clearMapTitle = function(whichmap) {
	if(whichmap == 0)
		$(this.containers.titles.text.left).innerHTML = 'Sem dados';
	else
		$(this.containers.titles.text.right).innerHTML = 'Sem dados';
}

Page.prototype.resizeMenu = function() {
	$(pageObj.containers.menu.toggler).style.height = (document.body.offsetHeight - 89) + 'px';
	$(pageObj.containers.menu.holder).style.height = (document.body.offsetHeight - 89) + 'px';
}

Page.prototype.beginFindCity = function() {
	pageObj.showLoading();
}

Page.prototype.endFindCity = function() {
	pageObj.hideLoading();
	if(geoObj.placeResult[0][0].city != '' && typeof geoObj.placeResult[0][0].city != 'undefined')
		mapObj[geoPage.selectedMap].centerAndZoom(new aptGeopoint(geoObj.placeResult[0][0].latitude, geoObj.placeResult[0][0].longitude), 5);
}

Page.prototype.showLegend = function(whichlegend) {
	if(whichlegend == 'left' || whichlegend == 0)
		$(this.containers.legends.left).style.display = 'block';
	else
		$(this.containers.legends.right).style.display = 'block';
}

Page.prototype.hideLegend = function(whichlegend) {
	if(whichlegend == 'left' || whichlegend == 0)
		$(this.containers.legends.left).style.display = 'none';
	else
		$(this.containers.legends.right).style.display = 'none';
}

Page.prototype.activateInfoIcon = function() {
	newImage = document.createElement('img');
	newImage.src = '../images/geo/tool_info.gif';
	newImage.title = 'ativar busca de informações';
	newImage.width = 18;
	newImage.height = 19;
	newImage.vspace = 5;

	$(pageObj.containers.tools.info).onclick = function(e) {geoPage.activateInfo();};
	$(pageObj.containers.tools.info).innerHTML = '';
	$(pageObj.containers.tools.info).className = 'pointer_mimic';
	$(pageObj.containers.tools.info).appendChild(newImage);
}

Page.prototype.activeInfoIcon = function() {
	newImage = document.createElement('img');
	newImage.src = '../images/geo/tool_info_on.gif';
	newImage.title = 'clique para desabilitar informações (ou clique com o botão direito no mapa)';
	newImage.width = 18;
	newImage.height = 19;
	newImage.vspace = 5;

	$(pageObj.containers.tools.info).onclick = function(e) {geoPage.deactivateInfo();};
	$(pageObj.containers.tools.info).innerHTML = '';
	$(pageObj.containers.tools.info).className = 'pointer_mimic';
	$(pageObj.containers.tools.info).appendChild(newImage);	
}

Page.prototype.deactivateInfoIcon = function() {
	newImage = document.createElement('img');
	newImage.src = '../images/geo/tool_info_off.gif';
	newImage.title = 'antes de utilizar esta ferramenta, selecione um tipo de dado à esquerda para exibir informações';
	newImage.width = 18;
	newImage.height = 19;
	newImage.vspace = 5;

	$(pageObj.containers.tools.info).onclick = function(e) { };
	$(pageObj.containers.tools.info).innerHTML = '';
	$(pageObj.containers.tools.info).className = '';
	$(pageObj.containers.tools.info).appendChild(newImage);
}

Page.prototype.activeRuler = function() {
	$(this.containers.tools.ruler).onclick = function(e) {geoPage.deactivateRuler();};
	$(this.containers.tools.ruler).className = 'pointer_mimic';

	$(this.containers.tools.ruler).innerHTML = '';

	newImage = document.createElement('img');
	newImage.src = '../images/geo/tool_rule_on.gif';
	newImage.title = 'desenhando régua (clique aqui ou clique com o botão direito para desabilitar)';
	$(this.containers.tools.ruler).appendChild(newImage);
}

Page.prototype.deactiveRuler = function() {
	$(this.containers.tools.ruler).onclick = function(e) {geoPage.activateRuler();};
	$(this.containers.tools.ruler).className = 'pointer_mimic';

	$(this.containers.tools.ruler).innerHTML = '';	

	newImage = document.createElement('img');
	newImage.src = '../images/geo/tool_rule.gif';
	newImage.title = 'desenhar régua';
	$(this.containers.tools.ruler).appendChild(newImage);	
}

