
function GoogleQualifier(mapContainer, callback)
{
	var geocoder = null;
	var map = new GMap2(mapContainer);
	var lineWidth = 10;
	var accessPoints = [
		{download:"5.0 Mbps AirMax Available", address:"96 North 500 West", city:"Bountiful", state:"Utah", zip:"84010", apName:"webwave", coverage:6, distance:''}, 
		{download:"3.0 Mbps ", address:"494 Brentwood Lane", city:"Bountiful", state:"Utah", zip:"84010", apName:"temple", coverage:6, distance:''}, 
		{download:"5.0 Mbps AirMax Available", address:"1018 S Freemont Drive", city:"Bountiful", state:"Utah", zip:"84010", apName:"temple2", coverage:6, distance:''}, 
		{download:"5.0 Mbps AirMax Available", address:"3931 South Huntington Circle", city:"Bountiful", state:"Utah", zip:"84010", apName:"northcanyon", coverage:6, distance:''}];
	var callBackFunction = callback;	
	var locations = []
	
	this.qualifyAddress = function(address, city, state, zip) 
	{
		if (GBrowserIsCompatible()) 
		{
			geocoder = new GClientGeocoder();
			map.setUIToDefault();
			var _fullAddress = buildAddress(address, city, state, zip);		
			addMarker(_fullAddress, "Customer location <br /> " + address + "<br />" + city + ", " + state);
		}
		else
		{
			alert("Your browser is not compatible");
		}	
	}
	
	function addMarker(_address, _description) 
	{

		if (geocoder) 
		{
			geocoder.getLatLng(_address, function(_customerPoint) 
			{
				if (_customerPoint) 
				{
					addPointToMap(_customerPoint, _description);
					setCenter(_customerPoint);
					for (ap in accessPoints)
					{
						_location = accessPoints[ap];
						addAPMarker(_location, _customerPoint );
					}
				} 
			});
		}
	}
	
	function addAPMarker(_location, _customerPoint) 
	{
		var _coverage = _location.coverage;
		_address = _location.address + " " + _location.city + ", " + _location.state + " " + _location.zip
		if (geocoder) 
		{
			geocoder.getLatLng(_address, function(_point) 
			{
				if (_point) 
				{
					_mapDescription = "<b>Tower: </b>" + _location.apName + "<br /><b>Download Speed: </b> " + _location.download;
					_distance = getMiles(_customerPoint, _point);
					_location.distance = _distance;
					if(_distance <= _location.coverage )
					{
						addPointToMap(_point, _mapDescription);
						drawLine(_customerPoint, _point);
						if(callBackFunction)
						{				
							callBackFunction(_location);
						}
					}
				} 
			});
		}
	  }
	
	function buildAddress(address, city, state){
	
		var fullAddress = address + " " + city + " " + state;
		return fullAddress;
	}
	
	function setCenter(_point)
	{
		map.setCenter(new GLatLng(_point.y, _point.x), 13);
	}
	
	function getMiles(_customerPoint, _point)
	{
		_accessPoint = new GLatLng(_point.y, _point.x);
		_subscriber = new GLatLng(_customerPoint.y, _customerPoint.x);
		var _distance = _accessPoint.distanceFrom(_subscriber);
		var _miles = _distance * 0.000621371192;
		_miles = _miles.toFixed(2);
		return _miles;
	}
	
	function drawLine(_customerPoint, _point)
	{
		if (_customerPoint)
		{
			var _accessPoint = new GLatLng(_point.y, _point.x);
			var _subscriber = new GLatLng(_customerPoint.y, _customerPoint.x);
			var polyline = new GPolyline([
			_accessPoint,
			_subscriber
			], "#ff0000", lineWidth);
			map.addOverlay(polyline);			
		}
	}
	
	function addPointToMap(_point, _description)
	{
			var _marker = new GMarker(_point);
			map.addOverlay(_marker);
			GEvent.addListener(_marker, "mouseover", function() {
				_marker.openInfoWindow(_description, null);
			});
	}
}
