/*
function selectAreaData(areaValue)
function resetMap()
function loadMap(areaList)
function selectTextAreas(Element)
function loadSelectList(areaList)
function resetSelectListMap()
*/

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);
	};
};

function selectTextAreas(Element)
{
	//var
	var Runner = 0;
	var fieldValue = '';
	var regEx;
	//var
	
	for(Runner = 0; Runner < Element.length; Runner++)
	{
		if(Element[Runner].selected)
		{
			if(!_currZipList.match(Element[Runner].value))
			{
				_currZipList += "," + Element[Runner].value;
				_currTextList += ", " + Element[Runner].innerHTML;
			};
		}else{
			regEx = new RegExp(', ' + Element[Runner].innerHTML + '(,|$)');
			if(_currTextList.match(regEx))
			{
//alert(Element[Runner].innerHTML + '\n' + _currTextList.replace(regEx, '$1'));
				_currZipList = _currZipList.replace("," + Element[Runner].value,"");
//			_currTextList = _currTextList.replace(", " + Element[Runner].innerHTML + ",",",");
//			_currTextList = _currTextList.replace(", " + Element[Runner].innerHTML,"");
				_currTextList = _currTextList.replace(regEx, '$1');
			};
		};	
	};

	if(_currTextList=="")
		document.getElementById('search_areas').innerHTML = "All Areas";
	else
		document.getElementById('search_areas').innerHTML = _currTextList.substring(2,_currTextList.length);

	changeFilter("zip", _currZipList);
};

function loadSelectList(areaList)
{
	var Runner;


	_currZipList = areaList;
	for(Runner = 0; Runner < document.getElementById('f_zips').length; Runner++)
	{
		if(areaList.match(document.getElementById('f_zips')[Runner].value))
		{
			document.getElementById('f_zips')[Runner].selected = true;
			_currTextList += ", " + document.getElementById('f_zips')[Runner].innerHTML;
		};
	};
	
	if(_currTextList=="")
		document.getElementById('search_areas').innerHTML = "All Areas";
	else
		document.getElementById('search_areas').innerHTML = _currTextList.substring(2,_currTextList.length);
};

function resetSelectListMap()
{
	var Runner;
	
	_currZipList = "";
	for(Runner = 0; Runner < document.getElementById('f_zips').length; Runner++)
		document.getElementById('f_zips')[Runner].selected = false;

	document.getElementById('search_areas').innerHTML = "All Areas";
};