/*
function selectAreaData(areaValue)
function resetMap()
function loadMap(areaList)
*/

var _currZipList	= "";
var _currTextList	= "";
var _definedAreas	= new Array();

if (GBrowserIsCompatible())
{ 
	// Display the map, with some controls and set the initial location 
	var map = new GMap2(document.getElementById("map"));
	map.addControl(new GSmallZoomControl());
	map.addControl(new GMapTypeControl(true));
	map.setCenter(new GLatLng(26.294454, -81.802075),10); // US 41 & Wiggins Pass Rd
	map.hideControls();
	//'mouseover' listener shows controls
	GEvent.addListener(map, "mouseover", function(){map.showControls();});
	//'mouseout' listener hides controls
	GEvent.addListener(map, "mouseout", function(){map.hideControls();});
} else {
	alert("Sorry, the Google Maps API is not compatible with this browser");
};

function selectAreaData(areaValue, areaText)
{
	if(!_currZipList.match(areaValue))
	{
		_currZipList += "," + areaValue;
		_currTextList += ", " + areaText;
	}else{
		_currZipList = _currZipList.replace("," + areaValue,"");
		_currTextList = _currTextList.replace(", " + areaText,"");
	};
	if(_currTextList=="")
		document.getElementById('search_areas').innerHTML = "All Areas";
	else
		document.getElementById('search_areas').innerHTML = _currTextList.substring(2,_currTextList.length);

	changeFilter("zip", _currZipList);
};

function resetMap()
{
	var Runner;
	
	_currZipList = "";
	for(Runner=0;Runner<_definedAreas.length;Runner++)
		_definedAreas[Runner].setFillOpacity(0.0);
};

function loadMap(areaList)
{
	var Runner;

	_currZipList = areaList;
	for(Runner=0;Runner<_definedAreas.length;Runner++)
	{
		if(areaList.match(_definedAreas[Runner].getAreaData()))
		{
			try{
				_definedAreas[Runner].setFillOpacity(0.3);
			}catch(e){
				//BDCCPolygodId0
				alert(_definedAreas[Runner].domid + "\n\n" + document.getElementById("BDCCPolygonId0"));
				setTimeout("retryFill(" + Runner + ",1)",100);
		//		retryFill(Runner);
			};
			_currTextList += ", " + _definedAreas[Runner].tooltip;
		};
	};
	
	if(_currTextList=="")
		document.getElementById('search_areas').innerHTML = "All Areas";
	else
		document.getElementById('search_areas').innerHTML = _currTextList.substring(2,_currTextList.length);
};

function retryFill(polygonLocation, tries)
{
if(tries<2000)
{
if(tries==1000)
alert(tries);
	try{
		_definedAreas[polygonLocation].setFillOpacity(0.3);
	}catch(e){
		setTimeout("retryFill(" + polygonLocation + ", " + (tries+1) + ")",100);
//		retryFill(polygon);
	};
}else{
				alert(_definedAreas[polygonLocation].domid + "\n\n" + document.getElementById("BDCCPolygonId0"));
alert(tries);
};
};
