﻿//
// NOTE: This file must be saved in UTF-8 in Notepad, if it contains
// Chinese characters. However, if this file is edited in Visual Studio 2003,
// it is always saved in ANSI--this will cause problems!
// Therefore, use Notepad to resave this file in UTF-8 after editing it
// in Visual Studio 2003.
// 

var centerLat = 25.013068400;
var centerLong = 121.529376148;
var mapCenterCrosshair;
var mapObj;
var mapJSONObject;
var now = new Date();
var lastMoveTime = now.getTime();
var searchMod = 'MoveMap';
var noSearchZoomLevel = 16; 		// Zoom level at which search will not be performed
var defaultZoomLevel = 17; 		// Default zoom level

// Resposition map center
function repositionCenterMarker(latLng) {
	// Remove old center
	if (mapCenterCrosshair != null)
		mapObj.removeOverlay(mapCenterCrosshair);

	// Add new center crosshair mark
	var iconCenter = new GIcon();
	iconCenter.image = 'images/crosshair.gif';
	iconCenter.iconWidth = 16;
	iconCenter.iconHeight = 16;
	iconCenter.iconAnchor = new GPoint(7, 0);
	var centerPoint = new GLatLng(latLng.lat(), latLng.lng());
	var centerMarker = new GMarker(centerPoint, iconCenter);
	mapCenterCrosshair = centerMarker;
	mapObj.addOverlay(centerMarker);
}

// Recenter map
function BtnRecenterMap_OnClick() {
	mapObj.setCenter(new GLatLng(centerLat, centerLong));
}

// Center map to hotspot
function LinkHotspot_OnClick(hotspotLon, hotspotLat) {
	var latLon = new GLatLng(hotspotLat, hotspotLon);
	mapObj.setCenter(latLon);
	repositionCenterMarker(latLon);
}

// Setting the default Button for a TextBox
function clickButton(e, buttonid) {
	var bt = document.getElementById(buttonid);
	if (typeof bt == 'object') {
		if (navigator.appName.indexOf('Netscape') > -1) {
			if (e.keyCode == 13) {
				bt.click();
				return false;
			}
		}
		if (navigator.appName.indexOf('Microsoft Internet Explorer') > -1) {
			if (event.keyCode == 13) {
				bt.click();
				return false;
			}
		}
	}
}

function CopyLocationToClipboard() {
	var CopiedTxt =
		'<a href="http://www.qon.com.tw/hotsearch/hotsearch.aspx?lon=' + mapObj.getCenter().lng() +
		'&lat=' + centerLat + '&addr=' + encodeURIComponent(document.Form1.TextBoxAddrToSearch.value) +
		'">這個位置附近可無線上網的地點</a>';
	clipboardData.setData('Text', CopiedTxt);
	alert('「' + CopiedTxt + '」已經複製到剪貼簿。你可以把此超連結貼到網頁來分享給朋友。');
}

// AJAX
var xmlHttp, xmlHttp2, xmlHttp3;
var requestURL = 'GetHotspots.aspx';
//var requestURL = 'http://localhost:100/CMSNew/PriorityCompany_NewGrid.aspx'; 
var is_ie = (navigator.userAgent.indexOf('MSIE') >= 0) ? 1 : 0;
var is_ie5 = (navigator.appVersion.indexOf("MSIE 5.5") != -1) ? 1 : 0;
var is_opera = ((navigator.userAgent.indexOf("Opera6") != -1) ||
			    (navigator.userAgent.indexOf("Opera/6") != -1)) ? 1 : 0;
// netscape, safari, mozilla behave the same??? 
var is_netscape = (navigator.userAgent.indexOf('Netscape') >= 0) ? 1 : 0;

// Show the right hotspot table
function ShowHotspotsTable(center) {
	// Only show geographic objects for zoom level > noSearchZoomLevel
	if (mapObj.getZoom() < noSearchZoomLevel)
		return;

	// Get map size
	//--------------------------------------------------------------
	var bounds = mapObj.getBounds();
	var mapWidth = bounds.getNorthEast().lng() - bounds.getSouthWest().lng();
	var mapHeight = bounds.getNorthEast().lat() - bounds.getSouthWest().lat();

	if (mapWidth == 0) {
		mapWidth = 0.015838846062564471;
		mapHeight = 0.010741243142408763;
	}
	var minLong = parseFloat(center.lng()) - mapWidth / 2;
	var maxLong = parseFloat(center.lng()) + mapWidth / 2;
	var minLat = parseFloat(center.lat()) - mapHeight / 2;
	var maxLat = parseFloat(center.lat()) + mapHeight / 2;

	//--------------------------------------------------------------

	var query = document.getElementById("txtQuery").value;
	var rows = document.getElementById("txtRows").value;
	var sortExpr = document.getElementById("txtSort").value;
	var page = document.getElementById("txtPage").value;

	query = "SELECT TOP 200 ID, Name, GeoAddress, Type, IsFree, Longitude, Latitude, QonLevel " +
			"FROM PublishedHotspots " +
			"WHERE " +
			"(Longitude BETWEEN " + minLong + " AND " + maxLong + ") AND " +
			"(Latitude BETWEEN " + minLat + " AND " + maxLat + ") " +
			"AND {0} " +
			"ORDER BY QonLevel DESC, IsFree DESC, Longitude, Latitude, Name";

	//Append the name to search for to the requestURL 
	var url = "GetHotspotTable.aspx?query=" + escape(query) +
		"&rows=" + rows + "&gridpage=" + page +
		"&expression=" + sortExpr +
		"&filter=" + document.getElementById("SelectSearchFilter").value;

	// Create the xmlHttp object to use in the request 
	// stateChangeHandler will fire when the state has changed, i.e. data is received back 
	// This is non-blocking (asynchronous) 
	xmlHttp2 = GetXmlHttpObject(hotspotsTableHandler);

	// Send the xmlHttp get to the specified url 
	xmlHttp_Get(xmlHttp2, url);
}

// Process the HTTP Response when it is complete
function hotspotsTableHandler() {
	if (xmlHttp2.readyState == 4) {
		if (xmlHttp2.status == 200) {
			var retval = xmlHttp2.responseText;
			if (document.getElementById("results") != null) {
				document.getElementById("results").innerHTML = retval;
			}
			else {
				alert("Error retrieving data!");
			}
		}
	}
}

// Called when a column header is clicked
function sortGrid(sortExpr) {
	document.getElementById("txtSort").value = sortExpr;
	ShowHotspotsTable(mapObj.getCenter());
}

// Called when the grid is paged
function pageGrid(page) {
	document.getElementById("txtPage").value = page;
	ShowHotspotsTable(mapObj.getCenter());
}

// Show hotspots
// This is the main entry point for hotspot search
function ShowHotspots(center) {
	// Only show geographic objects for zoom level > noSearchZoomLevel
	if (mapObj.getZoom() < noSearchZoomLevel)
		return;

	var bounds = mapObj.getBounds();
	var width = bounds.getNorthEast().lng() - bounds.getSouthWest().lng();
	var height = bounds.getNorthEast().lat() - bounds.getSouthWest().lat();

	// Append the name to search for to the requestURL 
	var url = requestURL + '?twd97Long=' + center.lng() + '&twd97Lat=' + center.lat() +
			  '&addrText=' + encodeURIComponent(document.Form1.TextBoxAddrToSearch.value) +
			  '&mapWidth=' + width + '&mapHeight=' + height +
			  '&filter=' + document.getElementById("SelectSearchFilter").value;

	// Create the xmlHttp object to use in the request 
	// stateChangeHandler will fire when the state has changed, i.e. data is received back 
	// This is non-blocking (asynchronous) 
	xmlHttp = GetXmlHttpObject(stateChangeHandler);

	// Send the xmlHttp get to the specified url 
	xmlHttp_Get(xmlHttp, url);

	//document.body.style.cursor = 'wait';
	document.getElementById('searching').style.top = document.getElementById('map').style.top;
	document.getElementById('searching').style.display = 'block';
}

// stateChangeHandler will fire when the state has changed, i.e. data is received back 
// This is non-blocking (asynchronous) 
function stateChangeHandler() {
	// readyState of 4 or 'complete' represents that data has been returned 
	if (xmlHttp.readyState == 4 || xmlHttp.readyState == 'complete') {
		//document.body.style.cursor = 'auto';
		// Gather the results from the callback 
		var str = xmlHttp.responseText;

		// Populate the innerHTML of the div with the results 
		//document.getElementById('serverTime').innerHTML = 'The time on the server is <b>' + str; 

		//alert(str);
		//var myJSONObject = eval('(' + str + ')');
		//alert(myJSONObject.HotspotInfo[0].ID + ' ' + myJSONObject.HotspotInfo[0].Name);
		//alert(myJSONObject.HotspotInfo[10].ID + ' ' + myJSONObject.HotspotInfo[10].Name);
		//alert(myJSONObject.HotspotInfo.length);
		//document.Form1.TextDebug.value += 'Get JSON text.\n';

		mapJSONObject = eval('(' + str + ')');
		//alert(testobj.test);

		if (mapJSONObject) {
			centerLat = mapJSONObject.twd97Lat;
			centerLong = mapJSONObject.twd97Long;
		}
		else {
			centerLong = mapObj.getCenter().lng();
			centerLat = mapObj.getCenter().lat();
		}

		if (mapJSONObject.IsErrorAddr == 0) {
			mapObj.setCenter(new GLatLng(centerLat, centerLong));
			searchMod = 'FinishSearch';
			mapObj.clearOverlays();
			RedrawMap();

			// Get hotspot table
			document.getElementById("txtPage").value = 1;
			ShowHotspotsTable(mapObj.getCenter());
			document.getElementById('ErrorAddrText').style.display = 'none';
		}
		else {
			//alert('找不到您輸入的地址，請改用經緯度搜尋、或是「進階搜尋」。');
			document.getElementById('ErrorAddrText').style.display = 'block';
		}
		document.getElementById('searching').style.display = 'none';
	}
}

// Get longitude and latitude by UrMap API
function GetTWD97ByGeoAddressByUrmap() {
	// Encode address is Big5
	//Dim encodedGeoAddr As String = HttpUtility.UrlEncode(geoAddr, enc)
	var uriString = "http://www.urmap.com/asp/yesturnkey/getxy.jsp?address="
					+ document.Form1.TextBoxAddrToSearch.value + "&encode=Big5";

	xmlHttp3 = GetXmlHttpObject(GetLonLatByAddr);

	// Send the xmlHttp get to the specified url 
	xmlHttp_Get(xmlHttp3, uriString);
}

// Process the HTTP Response when it is complete
function GetLonLatByAddr() {
	if (xmlHttp3.readyState == 4) {
		if (xmlHttp3.status == 200) {
			var responseStr = xmlHttp3.responseText;
			// Parse longitude and latitude
			responseStr = responseStr.replace(/^\s+|\s+$/g, "");
			var coords = responseStr.split(",");
			var twd97long = coords[0];
			var twd97lat = coords[1];
			if (twd97long != 0 && twd97lat != 0) {
				LinkHotspot_OnClick(twd97long, twd97lat);
				//document.Form1.TextDebug.value += 'searching...\n';
				IsSearch = 0;
				ShowHotspots(mapObj.getCenter());

				// Get hotspot table
				document.getElementById("txtPage").value = 1;
				ShowHotspotsTable(mapObj.getCenter());
			}
			else {
				// Error address!
			}
		}
	}
}

// XMLHttp send GET request 
function xmlHttp_Get(xmlhttp, url) {
	xmlhttp.open('GET', url, true);
	xmlhttp.send(null);
}

function GetXmlHttpObject(handler) {
	var objXmlHttp = null;    // Holds the local xmlHTTP object instance 

	// Depending on the browser, try to create the xmlHttp object 
	if (is_ie) {
		// The object to create depends on version of IE 
		// If it isn't ie5, then default to the Msxml2.XMLHTTP object 
		var strObjName = (is_ie5) ? 'Microsoft.XMLHTTP' : 'Msxml2.XMLHTTP';

		// Attempt to create the object 
		try {
			objXmlHttp = new ActiveXObject(strObjName);
			objXmlHttp.onreadystatechange = handler;
		}
		catch (e) {
			// Object creation errored 
			alert('IE detected, but object could not be created. ' +
				  'Verify that active scripting and activeX controls are enabled');
			return;
		}
	}
	else if (is_opera) {
		// Opera has some issues with xmlHttp object functionality 
		alert('Opera detected. The page may not behave as expected.');
		return;
	}
	else {
		// Mozilla | Netscape | Safari 
		objXmlHttp = new XMLHttpRequest();
		objXmlHttp.onload = handler;
		objXmlHttp.onerror = handler;
	}

	// Return the instantiated object 
	return objXmlHttp;
}

var IsSearch = 0;
function CheckIfSearch(check) {
	//document.Form1.TextDebug.value += 'checking...\n';
	if (IsSearch == check) {
		//document.Form1.TextDebug.value += 'searching...\n';
		IsSearch = 0;
		ShowHotspots(mapObj.getCenter());
		searchMod = 'Searching';

		// Get hotspot table
		//document.getElementById("txtPage").value = 1;
		//ShowHotspotsTable(mapObj.getCenter());
	}
}

// Initialize map
function initAJAX() {
	// Hide ButtonSearchGeoPosition if necessary
	hideButtonSearchGeoPosition();

	//document.Form1.TextDebug.value += 'Initial map.\n';
	// Icon for unknown hotspot
	var iconUnknown = new GIcon();
	iconUnknown.image = 'images/UnknownHotspot.gif';
	iconUnknown.iconWidth = 20;
	iconUnknown.iconHeight = 20;
	iconUnknown.iconAnchor = new GPoint(9, 9);
	iconUnknown.infoWindowAnchor = new GPoint(16, 0);

	// Icon for free hotspot
	var iconFree = new GIcon();
	iconFree.image = 'images/FreeHotspot.gif';
	iconFree.iconWidth = 20;
	iconFree.iconHeight = 20;
	iconFree.iconAnchor = new GPoint(9, 9);
	iconFree.infoWindowAnchor = new GPoint(16, 0);

	// Icon for for-fee hotspot
	var iconForFee = new GIcon();
	iconForFee.image = 'images/ForFeeHotspot.gif';
	iconForFee.iconWidth = 20;
	iconForFee.iconHeight = 20;
	iconForFee.iconAnchor = new GPoint(9, 9);
	iconForFee.infoWindowAnchor = new GPoint(16, 0);

	// Icon for FON hotspot
	var iconFON = new GIcon();
	iconFON.image = 'images/FonHotspot.gif';
	iconFON.iconWidth = 20;
	iconFON.iconHeight = 20;
	iconFON.iconAnchor = new GPoint(9, 9);
	iconFON.infoWindowAnchor = new GPoint(16, 0);

	// Create map
	var map;
	if (!mapJSONObject) {
		map = new GMap2(document.getElementById('map'));
		map.setCenter(new GLatLng(centerLat, centerLong), defaultZoomLevel);
		map.addControl(new GLargeMapControl());
		map.addControl(new GMapTypeControl());
		map.addControl(new GScaleControl());
		//map.addControl(new GOverviewMapControl());

		mapObj = map;
	}
	else {
		map = mapObj;
	}

	// Crosshair icon for center
	var iconCenter = new GIcon();
	iconCenter.image = 'images/crosshair.gif';
	iconCenter.iconWidth = 16;
	iconCenter.iconHeight = 16;
	iconCenter.iconAnchor = new GPoint(7, 0);
	var centerPoint = new GLatLng(centerLat, centerLong);
	var centerMarker = new GMarker(centerPoint, iconCenter);
	mapCenterCrosshair = centerMarker;
	map.addOverlay(centerMarker);

	// Get center coordinates after moving map
	GEvent.addListener(map, 'moveend', function() {
		if (searchMod == 'MoveMap' || searchMod == 'FinishSearch') {
			var center = map.getCenter();
			document.Form1.TextBoxAddrToSearch.value = center.lng() + ',' + center.lat();
			repositionCenterMarker(center);
			//alert('Move map!');
			// Test for AJAX
			//document.Form1.TextDebug.value += 'Move map.\n';
			//ShowHotspots(center);
			IsSearch++;
			setTimeout('CheckIfSearch(' + IsSearch + ')', 1000);
		}
		searchMod = 'MoveMap';
	});

	// Click to recenter map
	/*
	GEvent.addListener(map, 'click', function(overlay, latLng) {
	if (latLng)
	{					
	map.setCenter(latLng);
	//repositionCenterMarker(latLng);
	//alert('Click map!');
	// Test for AJAX
	//document.Form1.TextDebug.value += 'Click map.\n';
	//ShowHotspots(map.getCenter());
	}
	});		
	*/

	// Redraw geographical objects after zoom level is changed
	GEvent.addListener(map, 'zoom', function() {
		// AJAX-call to show objects on map.
		searchMod = 'FirstSearch';
		ShowHotspots(map.getCenter());
	});

	// Add hotspot markers
	var bounds = map.getBounds();
	var width = bounds.getNorthEast().lng() - bounds.getSouthWest().lng();
	var height = bounds.getNorthEast().lat() - bounds.getSouthWest().lat();
	var hotspotName;
	var geoAddress;
	var telephone;
	var remark;

	// testing AJAX
	//alert('Getting new array values...');
	if (mapJSONObject) {
		//document.Form1.TextDebug.value += 'Drawing hotspot icons.\n';
		//alert(testobj.test);
		for (var i = 0; i < mapJSONObject.HotspotInfo.length; i++) {
			//alert(mapJSONObject.HotspotInfo[i].ID + ' ' + mapJSONObject.HotspotInfo[i].Name);
			hotspotName = '<B>' + mapJSONObject.HotspotInfo[i].Name + '</B>';
			geoAddress = mapJSONObject.HotspotInfo[i].GeoAddress;
			telephone = mapJSONObject.HotspotInfo[i].Telephone;
			remark = mapJSONObject.HotspotInfo[i].Remark;
			var point = new GLatLng(mapJSONObject.HotspotInfo[i].Latitude,
									mapJSONObject.HotspotInfo[i].Longitude);
			var marker = createMarker(point, hotspotName, geoAddress,
									  mapJSONObject.HotspotInfo[i].IsFree,
									  mapJSONObject.HotspotInfo[i].OfferAC,
									  telephone, remark, mapJSONObject.HotspotInfo[i].ID);
			map.addOverlay(marker);
		}
	}
	// Save width & height
	document.Form1.mapWidth.value = width;
	document.Form1.mapHeight.value = height;

	// Show hotspots on map and table.
	searchMod = 'FirstSearch';
	ShowHotspots(mapObj.getCenter());
}

// Redraw hotspots on the map
function RedrawMap() {
	// Icon for unknown hotspot
	var iconUnknown = new GIcon();
	iconUnknown.image = 'images/UnknownHotspot.gif';
	iconUnknown.iconWidth = 20;
	iconUnknown.iconHeight = 20;
	iconUnknown.iconAnchor = new GPoint(9, 9);
	iconUnknown.infoWindowAnchor = new GPoint(16, 0);

	// Icon for free hotspot
	var iconFree = new GIcon();
	iconFree.image = 'images/FreeHotspot.gif';
	iconFree.iconWidth = 20;
	iconFree.iconHeight = 20;
	iconFree.iconAnchor = new GPoint(9, 9);
	iconFree.infoWindowAnchor = new GPoint(16, 0);

	// Icon for for-fee hotspot
	var iconForFee = new GIcon();
	iconForFee.image = 'images/ForFeeHotspot.gif';
	iconForFee.iconWidth = 20;
	iconForFee.iconHeight = 20;
	iconForFee.iconAnchor = new GPoint(9, 9);
	iconForFee.infoWindowAnchor = new GPoint(16, 0);

	// Icon for FON hotspot
	var iconFON = new GIcon();
	iconFON.image = 'images/FonHotspot.gif';
	iconFON.iconWidth = 20;
	iconFON.iconHeight = 20;
	iconFON.iconAnchor = new GPoint(9, 9);
	iconFON.infoWindowAnchor = new GPoint(16, 0);

	// Crosshair icon for center
	var iconCenter = new GIcon();
	iconCenter.image = 'images/crosshair.gif';
	iconCenter.iconWidth = 16;
	iconCenter.iconHeight = 16;
	iconCenter.iconAnchor = new GPoint(7, 0);
	var centerPoint = new GLatLng(centerLat, centerLong);
	var centerMarker = new GMarker(centerPoint, iconCenter);
	mapCenterCrosshair = centerMarker;
	mapObj.addOverlay(centerMarker);

	// Create custom marker
	function createMarker(point, hotspotName, geoAddress, isFree, offerAcPower,
						  telephone, remark, hotspotID, wisp) {
		//document.Form1.TextDebug.value += '(' + hotspotID + ') createMarker.\n';

		var marker;
		var isFreeStr;
		var offerAcPowerStr;
		// Is free hotspot?
		if (isFree == '0') {
			marker = new GMarker(point, iconForFee);
			isFreeStr = '<FONT color="red">付費無線上網</FONT>';
		}
		else if (isFree == '1') {
			marker = new GMarker(point, iconFree);
			isFreeStr = '<FONT color="green">免費無線上網</FONT>';
		}
		else if (isFree == '2') {
			marker = new GMarker(point, iconFON);
			isFreeStr = '<FONT color="orange">FON無線上網</FONT>';
		}
		else {
			marker = new GMarker(point, iconUnknown);
			isFreeStr = '<FONT color="blue">無線上網未知是否需付費</FONT>';
		}
		// Offer AC power?
		if (offerAcPower == '0') {
			offerAcPowerStr = '<FONT color="gold">不提供電源插座</FONT>';
		}
		else if (offerAcPower == '1') {
			offerAcPowerStr = '<FONT color="gold">提供電源插座</FONT>';
		}
		else {
			offerAcPowerStr = '<FONT color="gold">未知是否提供電源插座</FONT>';
		}

		var html =
			'<B><FONT color="firebrick">' + hotspotName + '</FONT></B><BR>' +
			geoAddress + '<BR>' + isFreeStr + '<BR>' + offerAcPowerStr + '<BR>' +
			'電話：' + telephone + '<BR>' +
			'<FONT color="blue">WISP：' + wisp + '</FONT><BR><BR>' +
			'<A href="GuestBook.aspx?HotspotID=' + hotspotID + '">更多資訊...</A>';

		GEvent.addListener(marker, 'click', function() {
			mapObj.openInfoWindowHtml(point, html, { maxWidth: 250 });
		});
		return marker;
	}

	// Add hotspot markers
	var bounds = mapObj.getBounds();
	var width = bounds.getNorthEast().lng() - bounds.getSouthWest().lng();
	var height = bounds.getNorthEast().lat() - bounds.getSouthWest().lat();
	var hotspotName;
	var geoAddress;
	var telephone;
	var remark;

	// AJAX: array from JSON text
	//alert('Getting new array values...');
	if (mapJSONObject) {
		//document.Form1.TextDebug.value += 'Redrawing hotspot icons.\n';
		//alert(testobj.test);
		for (var i = 0; i < mapJSONObject.HotspotInfo.length; i++) {
			//alert(mapJSONObject.HotspotInfo[i].ID + ' ' + mapJSONObject.HotspotInfo[i].Name);
			hotspotName = '<B>' + mapJSONObject.HotspotInfo[i].Name + '</B>';
			geoAddress = mapJSONObject.HotspotInfo[i].GeoAddress;
			telephone = mapJSONObject.HotspotInfo[i].Telephone;
			remark = mapJSONObject.HotspotInfo[i].Remark;
			var point = new GLatLng(mapJSONObject.HotspotInfo[i].Latitude,
									mapJSONObject.HotspotInfo[i].Longitude);
			var marker = createMarker(point, hotspotName, geoAddress,
									  mapJSONObject.HotspotInfo[i].IsFree,
									  mapJSONObject.HotspotInfo[i].OfferAC,
									  telephone, remark, mapJSONObject.HotspotInfo[i].ID,
									  mapJSONObject.HotspotInfo[i].WISP);
			mapObj.addOverlay(marker);
		}
	}
}

// Request geo-position
function requestGeoPosition() {
	var nav = null;
	if (nav == null) {
		nav = window.navigator;
	}
	if (nav != null) {
		var geoloc = nav.geolocation;
		if (geoloc != null) {
			geoloc.getCurrentPosition(requestPositionSuccessCallback,
				requestGeoPositionFailedCallback);
			document.getElementById('searching').style.display = 'block';
		}
		else {
			//alert("geolocation not supported");
		}
	}
	else {
		//alert("Navigator not found");
	}
}

// Success call back of requestPosition
function requestPositionSuccessCallback(position) {
	centerLat = position.coords.latitude;
	centerLong = position.coords.longitude;
	document.getElementById('searching').style.display = 'none';
	
	// Recenter map
	var latLon = new GLatLng(centerLat, centerLong);
	mapObj.setCenter(latLon);
	repositionCenterMarker(latLon);
	//alert(centerLat + ',' + centerLong);
}

function requestGeoPositionFailedCallback(error) {
	var message = "";

	// Check for known errors
	switch (error.code) {
		case error.PERMISSION_DENIED:
			message = "This website does not have permission to use " +
                      "the Geolocation API";
			break;
		case error.POSITION_UNAVAILABLE:
			message = "The current position could not be determined.";
			break;
		case error.PERMISSION_DENIED_TIMEOUT:
			message = "The current position could not be determined " +
                      "within the specified timeout period.";
			break;
	}

	// If it's an unknown error, build a message that includes 
	// information that helps identify the situation so that 
	// the error handler can be updated.
	if (message == "") {
		var strErrorCode = error.code.toString();
		message = "The position could not be determined due to " +
                  "an unknown error (Code: " + strErrorCode + ").";
	}
	alert(message);
	
	document.getElementById('searching').style.display = 'none';
}

// Hide ButtonSearchGeoPosition if necessary
function hideButtonSearchGeoPosition() {
	if (!window.navigator.geolocation)
		document.getElementById('ButtonSearchGeoPosition').style.display = 'none';
}

