TRestricter = function (map) {
this.map = map;
}

TRestricter.prototype.restrict = function (sw, ne) {
	this.map._allowedBounds = new GLatLngBounds(sw, ne);
	GEvent.addListener(this.map, 'move', this.checkBounds);
}

TRestricter.prototype.unrestrict = function () {
	this.map._allowedBounds = null;
}

TRestricter.prototype.checkBounds = function() {
	if (!this._allowedBounds || this._allowedBounds.contains(this.getCenter())) return;
	var x = Math.min(Math.max(this.getCenter().lng(), this._allowedBounds.getSouthWest().lng()), this._allowedBounds.getNorthEast().lng());
	var y = Math.min(Math.max(this.getCenter().lat(), this._allowedBounds.getSouthWest().lat()), this._allowedBounds.getNorthEast().lat());
	this.setCenter(new GLatLng(y,x));
}

TRestricter.prototype.zoomLevels = function (min, max) {
	var array = this.map.getMapTypes() || [];
	for (var i=0; i<array.length; i++) {
	 array[i].getMinimumResolution = function () { return min };
	 array[i].getMaximumResolution = function () { return max };
	}
}

function createMarker(point, icon, popuphtml) {
	var popuphtml = "<div id=\"popup\">" + popuphtml + "<\/div>";
	var marker = new GMarker(point, icon);
	GEvent.addListener(marker, "click", function() {
		marker.openInfoWindowHtml(popuphtml);
	});
	return marker;
}

function createMarker1(point, icon, popuphtml) {
	var popuphtml = "<div id=\"popup\">" + popuphtml + "<\/div>";
	var marker = new GMarker(point, icon);
	GEvent.addListener(marker, "mouseover", function() {
		marker.openInfoWindowHtml(popuphtml);
	});
	GEvent.addListener(marker, "mouseout", function() {
		marker.closeInfoWindow();
	});
	return marker;
}

function displayPoint(marker, index){
    $("#message").hide();
    var moveEnd = GEvent.addListener(map, "moveend", function(){
        var markerOffset = map.fromLatLngToDivPixel(marker.getLatLng());
        $("#message")
            .fadeIn()
            .css({ top:markerOffset.y, left:markerOffset.x });
        GEvent.removeListener(moveEnd);
    });
    map.panTo(marker.getLatLng());
}

//function Panner(x,y,z)
function washu()
{
	window.parent.document.getElementById('fr_left').map.zoomTo(12);
}

function include(filename)
{
	var head = document.getElementsByTagName('head')[0];
	
	script = document.createElement('script');
	script.src = filename;
	script.type = 'text/javascript';
	
	head.appendChild(script)
}
        function createMarkers()
        {
        var i;
            for(i = 0; i < newpoints.length; i++) {
                var point = new GPoint(newpoints[i][1],newpoints[i][0]);
                var popuphtml = newpoints[i][4] ;
                var marker = createMarker(point,newpoints[i][2],popuphtml);
                listMarkers[i] = marker;
                listNiveles[i] = newpoints[i][5];
                if(newpoints[i][6] >= 0)
                {
                    listAnos[i] = newpoints[i][6];
                }
//                map.addOverlay(marker);
            }
        }
		
            function showMarkersPorNivel(nivel)
            {
                var i;
                for(i = 0; i < listMarkers.length; i++) {
                    if(listNiveles[i] == nivel)
                    {
                        map.addOverlay(listMarkers[i]);
                    }
                }
                
            }
            function hideMarkersPorNivel(nivel)
            {
                var i;
                for(i = 0; i < listMarkers.length; i++) {
                    if(listNiveles[i] == nivel)
                    {
                        map.removeOverlay(listMarkers[i]);
                    }
                }
            }
            function showMarkersPorAno(ano)
            {
                var i;
                var _if = "if( listAnos[i] == ano && ( true "; 
                var _if1 = "";
                var aux;
                var auxn;
                $("[name = nivel]").each(function() {
                        if($(this).attr("checked"))
                        {
                              aux = $(this).attr("id").split("_");
                              auxn = aux[1];
                              _if1 += "&& listNiveles[i] == " + auxn + " ";
                        }
                });
                _if += _if1 + "))map.addOverlay(listMarkers[i]);";
                for(i = 0; i < listMarkers.length; i++) {
                    eval(_if);
                }
            }
            function hideMarkersPorAno(ano)
            {
                var i;
                for(i = 0; i < listMarkers.length; i++) {
                    if(listAnos[i] == ano)
                        map.removeOverlay(listMarkers[i]);
                }
            }
            function showAllMarkers(){
                var i;
                for(i = 0; i < listMarkers.length; i++) {
                        map.addOverlay(listMarkers[i]);
                }
            }
            function hideMarkers()
            {
                var i;
                for(i = 0; i < listMarkers.length; i++) {
                        map.removeOverlay(listMarkers[i]);
                }
            }
            function toggleMarkers()
            {
                var i;
                var _if;
                _if = getIF();
                for(i = 0; i < listMarkers.length; i++) {
                    eval(_if);
                }
            }
            function getIF()
            {
                var _ifn = "(false ";
                var _ifa = "(false ";
				var _ifauxi = "";
                var name = "";
                var aux;
                var auxn;
                name = "ano";
                $("input[name = "+ name +"]:checked").each(function(){
                              aux = $(this).attr("id").split("_");
							  _ifauxi = "";
							  for(var k=1; k < aux.length ; k ++)
							  {
								_ifauxi += aux[k] + "_";
							  }
							  _ifauxi = _ifauxi.slice(0, -1);                              
							  _ifn += "|| listAnos[i] == '" + _ifauxi + "' ";
                }) ;
                _ifn += " )";
                name = "nivel";
				
                $("input[name = "+ name +"]:checked").each(function(){
                              aux = $(this).attr("id").split("_");
							  _ifauxi = "";
							  for(var k=1; k < aux.length ; k ++)
							  {
								_ifauxi += aux[k] + "_";
							  }
							  _ifauxi = _ifauxi.slice(0, -1);
                              _ifa += "|| listNiveles[i] == '" + _ifauxi + "' ";
                }) ;
                _ifa += " )";
                var _if = "if(" + _ifn + " && " +  _ifa + "){map.addOverlay(listMarkers[i]);}else{map.removeOverlay(listMarkers[i]);}";
                return _if;
            }
			function jqCheckAll(name, flag )
			{
				if (flag == 0)
				{
//					$("INPUT[@name=" + name + "][type='checkbox']").attr('checked', false);
                    $("INPUT[name=" + name + "][type='checkbox']").attr('checked', false);
				}
				else
				{
					$("INPUT[name=" + name + "][type='checkbox']").attr('checked', true);
				}
			}
			function checkAll(type){
                if(type != undefined)
                {
                    type = type.toLowerCase();
                    jqCheckAll(type);
                }
                else
                {
                    jqCheckAll("ano");
                    jqCheckAll("nivel");
                    jqCheckAll("chk_allNivel");
                    jqCheckAll("chk_allAno");
                }
			}
            function unCheckAll(type){
                if(type != undefined)
                {
                    jqCheckAll(type, 0);
                }
                else
                {
                    jqCheckAll("ano", 0);
                    jqCheckAll("nivel", 0);
                    jqCheckAll("chk_allNivel", 0);
                    jqCheckAll("chk_allAno", 0);
                }
            }
            
            
            
            

