var map;
var overlay;
var infoWindow = null;
var showPleaseWait = true;
var initFlag = true;
var mapIcons = [];
var trackerData = [];
var weatherIcons = [];
var markerFlags = [true, true, true, true, true, true, true, true, false, false, false, false, false];
var dragging = false;

var plakLat;
var plakLng;
var currZoom = 5;
var currLat = -28.2399;
var currLng = 24.7288;
var mapTypeID = google.maps.MapTypeId.ROADMAP;
var wikiflag = false;
var dirflag = false;

var dirPoly = null;
var markers = [];
var weather = [];
var newMarker = null;
var ie = false;
var blinkInt;
var weatherStations;
var gettingWeather = false;
var daytime;
var vspoly = null;
var vdid = "";

if (navigator.appName == "Microsoft Internet Explorer" || navigator.appName == "Opera") {
	ie = true;
}

window.onresize = winresize;

function winresize() {
	if (ie) {
		document.getElementById("plak_map").style.height = (document.documentElement.clientHeight - 260) + "px";
		document.getElementById("sb_div").style.height = (document.documentElement.clientHeight - 260) + "px";
	}
}

var trackerIcon = new google.maps.MarkerImage ('http://bizzorg.com/img/tracker.png',
	new google.maps.Size(32, 37),
	new google.maps.Point(0, 0),
	new google.maps.Point(16, 37)
);

var xIcon = new google.maps.MarkerImage ('http://bizzorg.com/img/cross.png',
	new google.maps.Size(24, 24),
	new google.maps.Point(0, 0),
	new google.maps.Point(12, 12)
);

var xMarker = new google.maps.Marker ({
	icon: xIcon,
	zIndex: 10
});

var dirIcon = new google.maps.MarkerImage ('http://bizzorg.com/img/start.png',
	new google.maps.Size(24, 24),
	new google.maps.Point(0, 0),
	new google.maps.Point(3, 24)
);

var startMarker = new google.maps.Marker ({
	icon: dirIcon,
	zIndex: 10
});

dirIcon = new google.maps.MarkerImage ('http://bizzorg.com/img/end.png',
	new google.maps.Size(24, 24),
	new google.maps.Point(0, 0),
	new google.maps.Point(3, 24)
);

var endMarker = new google.maps.Marker ({
	icon: dirIcon,
	zIndex: 10
});

function load() {

	document.getElementById("phonenohelp").target = "_blank";
	document.getElementById("faxnohelp").target = "_blank";
	document.getElementById("imageurlhelp").target = "_blank";

		if (!ie) {
			document.getElementById("hack").style.height = "100%";
		} else {
			winresize();
		}

		var ca = document.cookie.split(';');
		for(var i=0; i < ca.length; i++) {
			var c = ca[i];
			while (c.charAt(0)==' ')
				c = c.substring(1, c.length);
			if (c.indexOf("Plak") == 0) {
				var plakcookie = c.substring(5, c.length);
				var plakarray = plakcookie.split(":");
				var plakZoom = plakarray[0];
				currZoom = parseInt(plakZoom);
				var plakCurrLat = plakarray[1];
				if (plakCurrLat != "NaN")
					currLat = parseFloat(plakCurrLat);
				var plakCurrLng = plakarray[2];
				if (plakCurrLng != "NaN")
					currLng = parseFloat(plakCurrLng);
				if (plakarray[3] == "false")
					markerFlags[1] = false;
				if (plakarray[4] == "false")
					markerFlags[2] = false;
				if (plakarray[5] == "false")
					markerFlags[3] = false;
				if (plakarray[6] == "false")
					markerFlags[4] = false;
				if (plakarray[7] == "false")
					markerFlags[5] = false;
				if (plakarray[8] == "false")
					markerFlags[6] = false;
				if (plakarray[9] == "false")
					markerFlags[7] = false;
				if (plakarray[10] == "true")
					wikiflag = true;
				if (plakarray[11]) {
					mapTypeID = getMapType(plakarray[11]);
				}
				if (plakarray[12]) {
					if (plakarray[12] == "none") {
						document.getElementById("toggle_img").src="http://bizzorg.com/img/rightbutton.gif";
						document.getElementById("toggle_img").setAttribute("title", "Maximize Sidebar");
						document.getElementById("sb_info").style.display = "none";
					}
				}
				if (plakarray[13]) {
					if (plakarray[13] == "true")
						dirflag = true;
				}
				if (plakarray[14]) {
					document.getElementById(plakarray[14]).checked = true;
				} else {
					document.getElementById("r1").checked = true;
				}
				if (plakarray[15] == "true")
					markerFlags[8] = true;
				if (plakarray[16] == "true")
					markerFlags[9] = true;
				if (plakarray[17] == "true")
					markerFlags[10] = true;
				if (plakarray[18] == "true")
					markerFlags[11] = true;
				if (plakarray[19] == "true")
					markerFlags[12] = true;
			}
		}

		var latlng = new google.maps.LatLng(currLat, currLng);
		var mapOptions = {
			zoom: currZoom,
			center: latlng,
			mapTypeId: mapTypeID
		};
		map = new google.maps.Map(document.getElementById("plak_map"), mapOptions);
		overlay = new google.maps.OverlayView();
		overlay.draw = function() {
			if (showPleaseWait) {
				showPleaseWait = false;
				var div = document.createElement("div");
				div.id = "pleasewait";
				div.style.position = "relative";
				div.style.whiteSpace = "nowrap";
				div.style.border = "1px solid silver";
				div.style.backgroundColor = "#F2F8FB";
				div.style.padding = "5px";
				div.innerHTML = "<h1>Loading. Please wait.</h1>";
				div.style.top = (overlay.getProjection().fromLatLngToDivPixel(latlng).y - 50) + 'px';
				div.style.left = (overlay.getProjection().fromLatLngToDivPixel(latlng).x - 142) + 'px';
				var panes = overlay.getPanes();
				panes.floatPane.appendChild(div);
			}
		};
		overlay.setMap(map);
		xMarker.setMap(map);

                document.getElementById("zl").innerHTML = currZoom;

		for (var n = 1; n < 15; n++) {
			document.getElementById("check" + n).checked = false;
			document.getElementById("check" + n).disabled = true;
		}

		var adUnitDiv = document.createElement('div');
		var adUnitOptions = {
			format: google.maps.adsense.AdFormat.BUTTON,
			position: google.maps.ControlPosition.RIGHT_BOTTOM,
			map: map,
			visible: true,
			publisherId: 'ca-pub-4002245024903759',
			channelNumber: '5626973176'
		};
		adUnit = new google.maps.adsense.AdUnit(adUnitDiv, adUnitOptions);
		adUnit.getContainer().style.opacity = "0.85";
		adUnit.getContainer().style.paddingRight = "10px";

		mapIcons.push(null);
		makeMapIcon("http://bizzorg.com/img/GrayPin.png");
		makeMapIcon("http://bizzorg.com/img/BluePin.png");
		makeMapIcon("http://bizzorg.com/img/RedPin.png");
		makeMapIcon("http://bizzorg.com/img/PinkPin.png");
		makeMapIcon("http://bizzorg.com/img/PurplePin.png");
		makeMapIcon("http://bizzorg.com/img/GreenPin.png");
		makeMapIcon("http://bizzorg.com/img/YellowPin.png");

		makeServiceIcon("http://bizzorg.com/img/saps.gif");
		makeServiceIcon("http://bizzorg.com/img/school.gif");
		makeServiceIcon("http://bizzorg.com/img/hospital.gif");
		makeServiceIcon("http://bizzorg.com/img/other.gif");
		makeServiceIcon("http://bizzorg.com/img/12.png");

		makeWeatherIcon("http://bizzorg.com/img/winfo.png", 16, 8);
		makeWeatherIcon("http://bizzorg.com/img/wclear.png", 24, 12);
		makeWeatherIcon("http://bizzorg.com/img/wcloudy.png", 24, 12);
		makeWeatherIcon("http://bizzorg.com/img/wpcloudy.png", 24, 12);
		makeWeatherIcon("http://bizzorg.com/img/wmcloudy.png", 24, 12);
		makeWeatherIcon("http://bizzorg.com/img/wscloudy.png", 24, 12);
		makeWeatherIcon("http://bizzorg.com/img/wfog.png", 24, 12);
		makeWeatherIcon("http://bizzorg.com/img/whaze.png", 24, 12);
		makeWeatherIcon("http://bizzorg.com/img/wdrizzle.png", 24, 12);
		makeWeatherIcon("http://bizzorg.com/img/wrain.png", 24, 12);
		makeWeatherIcon("http://bizzorg.com/img/wstorm.png", 24, 12);
		makeWeatherIcon("http://bizzorg.com/img/wsnow.png", 24, 12);
		makeWeatherIcon("http://bizzorg.com/img/wntclear.png", 24, 12);
		makeWeatherIcon("http://bizzorg.com/img/wntpcloudy.png", 24, 12);
		makeWeatherIcon("http://bizzorg.com/img/wntmcloudy.png", 24, 12);
		makeWeatherIcon("http://bizzorg.com/img/wntscloudy.png", 24, 12);
		makeWeatherIcon("http://bizzorg.com/img/wnthaze.png", 24, 12);

		google.maps.event.addListener(map, "idle", function() {
			if (!dragging) {
				document.getElementById("zl").innerHTML = map.getZoom();

				if (initFlag) {
					initFlag = false;

					var bounds = map.getBounds();
					var ne = bounds.getNorthEast();
					var sw = bounds.getSouthWest();
					var flag = getFlagBitmap();

					var rep;
					if (flag == "000000000000") {
						rep = eval("[['none']]");
						gotMarkers(rep);
					} else {
						AJAXCall("getNewMarkers", encodeURI("lat1=" + sw.lat() + "&lat2=" + ne.lat() + "&lng1=" + sw.lng() + "&lng2=" + ne.lng() + "&flag=" + flag + "&num=" + getNumMarkers()), "gotMarkers(rep)");
					}
					if (loggedin) {
						AJAXCall("getTrackerData", "uid=" + userid, "gotTrackerData(rep)");
					}
				} else {
					if (infoWindow == null) {
						displayMarkers(1);
					}
				}
			}
		});

		google.maps.event.addListener(map, "mousemove", function(event) {
			document.getElementById("latval").innerHTML = event.latLng.lat().toFixed(4);
			document.getElementById("lngval").innerHTML = event.latLng.lng().toFixed(4);
		});

		google.maps.event.addListener(map, "dblclick", function(event) {
			if (userid == 1) {
				document.location.href="http://plak.co.za/PlakLocKML.php?lat=" + event.latLng.lat() + "&lng=" + event.latLng.lng() + "&latbounds=0.1&lngbounds=0.1";
			}
		});

		google.maps.event.addListener(map, "rightclick", function(event) {
			if(infoWindow != null) {
				infoWindow.close();
				infoWindow = null;
			}
			if (document.getElementById("check9").checked) {
				var latlng = event.latLng;
 				plakLat = latlng.lat();
				plakLng = latlng.lng();
				if (plakLat < -22.1111 && plakLat > -34.8422 && plakLng > 16.4516 && plakLng < 32.8966) {
					if (startMarker.getMap() == null) {
						startMarker.setPosition(latlng);
						startMarker.setMap(map);
						if (endMarker.getMap() != null) {
							getDirections();
						}
					} else if (endMarker.getMap() == null) {
						endMarker.setPosition(latlng);
						endMarker.setMap(map);
						if (startMarker.getMap() != null) {
							getDirections();
						}
					} else {
						startMarker.setMap(null);
						endMarker.setMap(null);
						dirPoly.setMap(null);
						dirPoly = null;
					}
				}
			} else {
				if (!loggedin) {
					alert("You must be logged in before you can add a Plak.");
				} else {
					if (map.getZoom() < 14) {
						alert ("Please zoom in before trying to add a Plak.\r\nYou are currently at zoom level " + map.getZoom() + ".\r\nYou must be at zoom level 14, or greater, before adding a Plak.");
					} else {
						var latlng = event.latLng;
 						plakLat = latlng.lat();
						plakLng = latlng.lng();
						if (plakLat < -22.1111 && plakLat > -34.8422 && plakLng > 16.4516 && plakLng < 32.8966) {
							document.getElementById("plak_lat").value = plakLat;
							document.getElementById("plak_lng").value = plakLng;
							document.getElementById("plak_add").style.display = "block";
							blinkInt = setInterval("doBlink()",1000);
						}
					}
				}
			}
		});
}

function makeMapIcon(url) {
	var mapIcon = new google.maps.MarkerImage(url,
		new google.maps.Size(14, 30),
		new google.maps.Point(0, 0),
		new google.maps.Point(0, 30)
	);
	mapIcons.push(mapIcon);
}

function makeServiceIcon(url) {
	var mapIcon = new google.maps.MarkerImage(url,
		new google.maps.Size(16, 16),
		new google.maps.Point(0, 0),
		new google.maps.Point(14, 16)
	);
	mapIcons.push(mapIcon);
}

function makeWeatherIcon(url, s1, s2) {
	var mapIcon = new google.maps.MarkerImage(url,
		new google.maps.Size(s1, s1),
		new google.maps.Point(0, 0),
		new google.maps.Point(s2, s2)
	);
	weatherIcons.push(mapIcon);
}

function getDirections() {
	document.getElementById("directions").src = "http://bizzorg.com/img/throbber.gif";
	var sp = startMarker.getPosition().lng() + "," + startMarker.getPosition().lat();
	var ep = endMarker.getPosition().lng() + "," + endMarker.getPosition().lat();
	AGCall(sp, ep, "directionloadhandler(rep)", 1);
}

function getTextDirections() {
	document.getElementById("directions").src = "http://bizzorg.com/img/throbber.gif";
	var sp = startMarker.getPosition().lat() + "|" + startMarker.getPosition().lng();
	var ep = endMarker.getPosition().lat() + "|" + endMarker.getPosition().lng();
	AGCall(sp, ep, "textdirloadhandler(rep)", 2);
}

function textdirloadhandler(obj) {
	var doc = document.getElementById("dir_text").contentDocument || document.getElementById("dir_text").contentWindow.document;

	doc.open();
        doc.write("<!DOCTYPE html PUBLIC '-//W3C//DTD XHTML 1.0 Strict//EN' 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd'><html xmlns='http://www.w3.org/1999/xhtml'><head><meta http-equiv='content-type' content='text/html; charset=UTF-8'/><link rel='stylesheet' type='text/css' href='/Global.css'/></head><body style='background-color: white;'>" + obj + "</body></html>");
        doc.close();    

	document.getElementById("plak_text_directions").style.display = "block";
	document.getElementById("directions").src = "http://bizzorg.com/img/car.png";
}

function HideDir() {
	document.getElementById("plak_text_directions").style.display = "none";
}

function directionloadhandler(obj) {
	var coords = obj.RoutingPoints.split("|");
	var polyCoords = [];
	for (var n = 0; n < coords.length; n++) {
		var ll = coords[n].split(",");
		polyCoords.push(new google.maps.LatLng(parseFloat(ll[1]), parseFloat(ll[0])));
	}
	dirPoly = new google.maps.Polyline({
		path: polyCoords,
		strokeColor: "#0000ff",
		strokeOpacity: 0.5,
		strokeWeight: 5
	});
	dirPoly.setMap(map);
	document.getElementById("directions").src = "http://bizzorg.com/img/car.png";
	var ans = confirm("Would you like text directions for the displayed route?");
	if (ans) {
		getTextDirections();
	}
}

function gotNewMarkers(object) {
	clearAll();
	if (object[0][0] != "none") {
		var marker;
		for (var n = 0; n < object.length; n++) {
			var LatLng = new google.maps.LatLng(object[n][1], object[n][2]);
			marker = createMarker(LatLng, mapIcons[object[n][4]], object[n][3], object[n][0], object[n][4], object[n][5], object[n][6]);
			markers.push(marker);
		}
	}
	displayMarkers(0);
}

function displayMarkers(getFlag) {
	if (getFlag == 1) {
		var bounds = map.getBounds();
		var ne = bounds.getNorthEast();
		var sw = bounds.getSouthWest();
		if (document.getElementById("check13").checked && !gettingWeather) {
			document.getElementById("check13").disabled = true;
			gettingWeather = true;
			clearWeather();
			weatherCall(ne.lat(), sw.lat(), ne.lng(), sw.lng(), "gotWeather()", 4);
		}
		var flag = getFlagBitmap();
		if (flag != "00000000000") {
			AJAXCall("getNewMarkers", encodeURI("lat1=" + sw.lat() + "&lat2=" + ne.lat() + "&lng1=" + sw.lng() + "&lng2=" + ne.lng() + "&flag=" + flag + "&num=" + getNumMarkers()), "gotNewMarkers(rep)");
		} else {
			clearAll();
		}
	} else {

		for (var x = 0; x < markers.length; x++) {
			markers[x].setMap(map);
		}
		var max = parseInt(getNumMarkers());
		if (max == 0) {
			document.getElementById("msg").innerHTML = "<strong>Click map pins to view more information.</strong>";
		} else {
			if (markers.length == max) {
				document.getElementById("msg").innerHTML = "<strong>Zoom in to see more Plaks.</strong>";
			} else {
				document.getElementById("msg").innerHTML = "<strong>Click map pins to view more information.</strong>";
			}
		}
	}
}

function clearAll() {
	hideName();
	if (newMarker != null) {
		newMarker.setMap(null);
		newMarker = null;
	}
	if (markers.length > 0) {
		for (var n = 0; n < markers.length; n++) {
			markers[n].setMap(null);
		}
		markers = [];
	}
}

function GUnload() {
	if (!document.getElementById("check1").disabled) {
		var value = map.getZoom() + ":";
		value += map.getCenter().lat() + ":" + map.getCenter().lng() + ":";
		value += document.getElementById("check1").checked;
		value += ":" + document.getElementById("check2").checked;
		value += ":" + document.getElementById("check3").checked;
		value += ":" + document.getElementById("check4").checked;
		value += ":" + document.getElementById("check5").checked;
		value += ":" + document.getElementById("check6").checked;
		value += ":" + document.getElementById("check7").checked;
		value += ":" + document.getElementById("check8").checked;
		value += ":" + getMapTypeID(map.getMapTypeId());
		value += ":" + document.getElementById("sb_info").style.display;
		value += ":" + document.getElementById("check9").checked;
		if (document.getElementById("r1").checked) {
			value += ":r1";
		} else {
			value += ":r2";
		}
		value += ":" + document.getElementById("check10").checked;
		value += ":" + document.getElementById("check11").checked;
		value += ":" + document.getElementById("check12").checked;
		value += ":" + document.getElementById("check14").checked;
		value += ":" + document.getElementById("check15").checked;
		createCookie("Plak", value, 7);
	}
}

function getMapTypeID (type) {
	var retval = "";
	if(type == "roadmap") {
		retval = "0";
	} else if(type == "satellite") {
		retval = "1"
	} else if(type == "hybrid") {
		retval = "2"
	} else if(type == "terrain") {
		retval = "3"
	}
	return retval;
}

function getMapType (id) {
	var retval = "";
	if(id == "0") {
		retval = "roadmap";
	} else if(id == "1") {
		retval = "satellite"
	} else if(id == "2") {
		retval = "hybrid"
	} else if(id == "3") {
		retval = "terrain"
	}
	return retval;
}

function createCookie(name, value, days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function gotTrackerData(object) {
	trackerData = [];
	if (object[0][0] != "none") {
		var lastID = "";
		var tmp = [];
		for (var n = 0; n < object.length; n++) {
			if (lastID != object[n][0]) {
				if (lastID != "") {
					trackerData.push(tmp);
				}
				tmp = [];
				lastID = object[n][0];
			}
			var tdata = new Array(object[n][0], object[n][1], object[n][2], object[n][3], object[n][4]); 
			tmp.push(tdata);
		}
		trackerData.push(tmp);
		for (var n = 0; n < trackerData.length; n++) {
			if (trackerData[n].length > 1) {
				drawTrack(trackerData[n]);
			} else {
				drawTrackPoint(trackerData[n][0][1], trackerData[n][0][2], trackerData[n][0][0], trackerData[n][0][3], trackerData[n][0][4]);
			}
		}
	}
}

function drawTrack(tdata) {
	var polyCoords = [];
	for (var n = 0; n < tdata.length; n++) {
		polyCoords.push(new google.maps.LatLng(parseFloat(tdata[n][1]), parseFloat(tdata[n][2])));
	}
	var trackPoly = new google.maps.Polyline({
		path: polyCoords,
		strokeColor: "#0000ff",
		strokeOpacity: 0.5,
		strokeWeight: 5
	});
	trackPoly.setMap(map);
	for (var n = 0; n < tdata.length; n++) {
		var count = n + 1;
		drawTrackPoint(tdata[n][1], tdata[n][2], tdata[n][0] + " (" + count + ")", tdata[n][3], tdata[n][4]);
	}
}

function drawTrackPoint(tlat, tlng, name, speed, dandt) {
	var point = new google.maps.LatLng(tlat, tlng);
	var marker = new google.maps.Marker ({
		position: point,
		zIndex: 5,
		icon: trackerIcon
	});

	var kph = (speed * 60 * 60)/1000;
	var dt = dandt.split(" ");
	var d = dt[0].split("-");
	var html = "<strong>" + name + "</strong><br/><br/><table class='tracktable' cellspacing='0' cellpadding='3'><tr><td class='trackcellleft'>Latitude</td><td class='trackcellright'>" + tlat + "</td></tr><tr><td class='trackcellleft'>Longitude</td><td class='trackcellright'>" + tlng + "</td></tr><tr><td class='trackcellleft'>Speed</td><td class='trackcellright'>" + speed + " m/s</td></tr><tr><td class='trackcellleft'>Speed</td><td class='trackcellright'>" + kph + " k/h</td></tr><tr><td class='trackcellleft'>Date</td><td class='trackcellright'>" + d[2] + "/" + d[1] + "/" + d[0] + "</td></tr><tr><td>Time</td><td style='text-align: right;'>" + dt[1] + "</td></tr></table>";

	google.maps.event.addListener(marker, "click", function(event) {
		showWInfo(this, html);
	});

	google.maps.event.addListener(marker, "mouseover", function(event) {
		showName(name, event.latLng, -1, null);
	});

	google.maps.event.addListener(marker, "mouseout", function(event) {
		hideName();
	});

	marker.setMap(map);
}

function gotMarkers(object) {
	document.getElementById("check1").checked = markerFlags[1];
	document.getElementById("check2").checked = markerFlags[2];
	document.getElementById("check3").checked = markerFlags[3];
	document.getElementById("check4").checked = markerFlags[4];
	document.getElementById("check5").checked = markerFlags[5];
	document.getElementById("check6").checked = markerFlags[6];
	document.getElementById("check7").checked = markerFlags[7];
	document.getElementById("check10").checked = markerFlags[8];
	document.getElementById("check11").checked = markerFlags[9];
	document.getElementById("check12").checked = markerFlags[10];
	document.getElementById("check14").checked = markerFlags[11];
	document.getElementById("check15").checked = markerFlags[12];
	document.getElementById("check13").checked = false;

	if (object[0][0] != "none") {
		var marker;
		for (var n = 0; n < object.length; n++) {
			var LatLng = new google.maps.LatLng(object[n][1], object[n][2]);
			marker = new createMarker(LatLng, mapIcons[object[n][4]], object[n][3], object[n][0], object[n][4], object[n][5], object[n][6]);
			markers.push(marker);
		}
	}

	document.getElementById("check1").disabled = false;
	document.getElementById("check2").disabled = false;
	document.getElementById("check3").disabled = false;
	document.getElementById("check4").disabled = false;
	document.getElementById("check5").disabled = false;
	document.getElementById("check6").disabled = false;
	document.getElementById("check7").disabled = false;
	document.getElementById("check10").disabled = false;
	document.getElementById("check11").disabled = false;
	document.getElementById("check12").disabled = false;
	document.getElementById("check13").disabled = false;
	document.getElementById("check14").disabled = false;
	document.getElementById("check15").disabled = false;

	document.getElementById("check8").disabled = false;
	document.getElementById("check8").checked = wikiflag;
	document.getElementById("check9").disabled = false;
	document.getElementById("check9").checked = dirflag;
	displayMarkers(0);
	
	var pleasewait = document.getElementById("pleasewait");
	if(pleasewait) {
		var panes = overlay.getPanes();
		panes.floatPane.removeChild(pleasewait);
	}
}

function dirFromTo(lat, lng) {
	infoWindow.close();
	infoWindow = null;
	var latlng = new google.maps.LatLng(lat, lng);
	if (dirPoly != null) {
		startMarker.setMap(null);
		endMarker.setMap(null);
		dirPoly.setMap(null);
		dirPoly = null;
	}

	if (startMarker.getMap() == null) {
		startMarker.setPosition(latlng);
		startMarker.setMap(map);
		if (endMarker.getMap() != null) {
			getDirections();
		}
	} else {
		endMarker.setPosition(latlng);
		endMarker.setMap(map);
		if (startMarker.getMap() != null) {
			getDirections();
		}
	}
}

function newPos(marker, id) {
	var point = marker.getPosition();
	if (point.lat() < -22.1111 && point.lat() > -34.8422 && point.lng() > 16.4516 && point.lng() < 32.8966) {
		var ans = confirm("Are you sure that you want to move the marker?");
		if (ans) {
			AJAXCall("updateMarker", encodeURI("lat=" + point.lat() + "&lng=" + point.lng() + "&markerid=" + id), "posUpdated(rep)");
		} else {
			var latlng = new google.maps.LatLng(currLat, currLng);
			marker.setPosition(latlng);
		}
	} else {
		alert("Sorry, but you can't place your Plak there.");
		var latlng = new google.maps.LatLng(currLat, currLng);
		marker.setPosition(latlng);
	}
}

function posUpdated(object) {
	alert(object);
}

function createMarker(point, ico, name, id, type, uid, bounds) {
	var alttext = "";
	var marker;

	if (type == 12) {
		name += " - Voting Station";
	}

	if (uid == userid || userid == 1) {
		marker = new google.maps.Marker ({
			position: point,
			draggable: true,
			zIndex: 5,
			icon: ico
		});
		google.maps.event.addListener(marker, "dragstart", function(event) { dragging = true; hideName(); currLat = event.latLng.lat(); currLng = event.latLng.lng(); });
		google.maps.event.addListener(marker, "dragend", function(event) { dragging = false; newPos(marker, id); });
	} else {
		marker = new google.maps.Marker ({
			position: point,
			zIndex: 5,
			icon: ico
		});
	}

	google.maps.event.addListener(marker, "click", function(event) {
		showInfo(this, name, id, type);
	});

	google.maps.event.addListener(marker, "mouseover", function(event) {
		showName(name, event.latLng, type, bounds);
	});

	google.maps.event.addListener(marker, "mouseout", function(event) {
		hideName();
	});

	return marker;
}

function createWMarker(point, ico, label, html) {

	marker = new google.maps.Marker ({
		position: point,
		zIndex: 5,
		icon: ico
	});

	google.maps.event.addListener(marker, "click", function(event) {
		showWInfo(this, html);
	});

	google.maps.event.addListener(marker, "mouseover", function(event) {
		showName(label + " - Weather", event.latLng, 0, "");
	});

	google.maps.event.addListener(marker, "mouseout", function(event) {
		hideName();
	});

	return marker;
}

function showInfo(marker, name, id, type) {
	name = name.replace(/&amp;/g, "&");
	name = name.replace(/&/g, "&amp;");
	hideName();
	var alttext = "";
	var point = marker.getPosition();
	var ico = marker.getIcon();
	if (type > 7) {
		var istyle = "style='width: 16px; height: 16px;'";
	} else {
		var istyle = "style='width: 14px; height: 30px;'";
	}

	if (infoWindow != null) {
		infoWindow.close();
		infoWindow = null;
	}
	infoWindow = new google.maps.InfoWindow();
	google.maps.event.addListener(infoWindow, "closeclick", function() {
		infoWindow = null;
	});
	infoWindow.setContent("<div class='info_div'><img src='" + ico.url + "' class='info_icon'" + istyle + "alt='" + alttext + "'/><br/><div class='info_name'>" + name + "</div><br/><div style='text-align: center;'><input class='plak_button' type='button' value='More info...' onclick=\"document.location.href='/moreinfo.php?id=" + id + "'\"/><br/><br/><input class='plak_button' type='button' value='Street View' onclick=\"plak_sv_show(" + point.lat() + ", " + point.lng() + ");\" /><br/><br/><input class='plak_button' type='button' value='Directions' onclick=\"dirFromTo(" + point.lat() + ", " + point.lng() + ");\" /><br/><br/></div></div>");
	infoWindow.open(map, marker);
}

function showWInfo(marker, html) {
	hideName();
	if (infoWindow != null) {
		infoWindow.close();
		infoWindow = null;
	}
	infoWindow = new google.maps.InfoWindow();
	google.maps.event.addListener(infoWindow, "closeclick", function() {
		infoWindow = null;
	});
	infoWindow.setContent(html);
	infoWindow.open(map, marker);
}

function showName(name, latlng, type, bounds) {
	if (!dragging) {
		name = name.replace(/&amp;/g, "&");
		name = name.replace(/&/g, "&amp;");
		hideName();

		var div = document.createElement("div");
		div.id = "infopop";
		div.style.position = "relative";
		div.style.whiteSpace = "nowrap";
		div.innerHTML = name;
		if (type > 7) {
			div.style.top = (overlay.getProjection().fromLatLngToDivPixel(latlng).y - 41) + 'px';
			div.style.left = (overlay.getProjection().fromLatLngToDivPixel(latlng).x - 13) + 'px';
		} else if (type == 0) {
			div.style.top = (overlay.getProjection().fromLatLngToDivPixel(latlng).y - 34) + 'px';
			div.style.left = (overlay.getProjection().fromLatLngToDivPixel(latlng).x - 8) + 'px';
		} else if (type == -1) {
			div.style.top = (overlay.getProjection().fromLatLngToDivPixel(latlng).y - 56) + 'px';
			div.style.left = (overlay.getProjection().fromLatLngToDivPixel(latlng).x - 12) + 'px';
		} else {
			div.style.top = (overlay.getProjection().fromLatLngToDivPixel(latlng).y - 54) + 'px';
			div.style.left = (overlay.getProjection().fromLatLngToDivPixel(latlng).x + 8) + 'px';
		}
		var panes = overlay.getPanes();
		panes.floatPane.appendChild(div);
	}
}

function showVSBounds(bounds) {
	var bdata = bounds.split(' ');
	if (vspoly != null) {
		map.removeOverlay(vspoly);
	}
	vspoly = new GPolygon.fromEncoded({
		polylines:[ 
			{points: bdata[1],
			color: "#FF9900",
			levels: bdata[0],
			opacity: 0.5,
			weight: 3,
			numLevels: 18,
			zoomFactor: 2}],
		fill: true,
		color: "#FFFF99",
		opacity: 0.4,
		outline: true
	});
	map.addOverlay(vspoly);
}

function hideName() {
	var infopop = document.getElementById("infopop");
	if(infopop) {
		var panes = overlay.getPanes();
		panes.floatPane.removeChild(infopop);
	}
}

function plak_add_close() {
	clearInterval (blinkInt);
	document.getElementById("plak_add").style.display = "none";
}

function isUrl(s) {
	var regexp = new RegExp();
	regexp.compile("^(http|https)\://[a-zA-Z0-9\-\.]+\.[a-zA-Z]{2,3}(:[a-zA-Z0-9]*)?/?([a-zA-Z0-9\-\._\?\,\'/\\\+&amp;%\$#\=~])*$");
	return regexp.test(s);
}

function isPNum(s) {
	var regexp  = /^(0\d{2})\ \d{3}\ \d{4}$/;
	return regexp.test(s);
}

function isImage(s) {
	var regexp = /(.jpg|.jpeg|.png|.gif)/i;
	return regexp.test(s);
}

function addPlak() {
	if (document.getElementById("plak_type").value == -1) {
		alert("Please select a type.");
	} else if (document.getElementById("plak_name").value.length == 0) {
		alert("Please supply a name.");
	} else if (checkCaps(document.getElementById("plak_name").value)) {
		alert("Sorry, but the name may not be supplied using only CAPS.");
	} else if (document.getElementById("plak_name").value.length > 40) {
		alert("Sorry, but the Plak name is limited to 40 characters.");
	} else if (document.getElementById("plak_desc").value.indexOf("!!") > -1) {
		alert("Please use only single exclamation marks!!!!!!!");
	} else if (document.getElementById("plak_desc").value.length == 0) {
		alert("Please supply a description.");
	} else if (document.getElementById("plak_address").value.length > 300) {
		alert("Sorry, but the address is limited to 300 characters.");
	} else if (document.getElementById("plak_address").value.length > 0 && !checkProv(document.getElementById("plak_address").value)) {
		alert("Please include the province in the address. Valid province names are: -\r\n\r\nEastern Cape\r\nFree State\r\nGauteng\r\nKwaZulu-Natal\r\nLimpopo\r\nMpumalanga\r\nNorth West\r\nNorthern Cape\r\nWestern Cape");
	} else if (document.getElementById("plak_address").value.length > 0 && !checkCountry(document.getElementById("plak_address").value)) {
		alert("Please include the country in the address.");
	} else if (document.getElementById("plak_phone").value.length > 20) {
		alert("Sorry, but the phone number is limited to 20 characters.");
	} else if (document.getElementById("plak_phone").value.length > 0 && !isPNum(document.getElementById("plak_phone").value)) {
		alert("The correct phone number format is 099 999 9999\r\nThe phone number MUST start with a zero\r\nDO NOT include 027 or +27 for international callers\r\nPlak will automatically add the +27");
	} else if (document.getElementById("plak_fax").value.length > 20) {
		alert("Sorry, but the fax number is limited to 20 characters.");
	} else if (document.getElementById("plak_fax").value.length > 0 && !isPNum(document.getElementById("plak_fax").value)) {
		alert("The correct fax number format is 099 999 9999\r\nThe fax number MUST start with a zero\r\nDO NOT include 027 or +27 for international callers\r\nPlak will automatically add the +27");
	} else if (document.getElementById("plak_site").value.length > 0 && !isUrl(document.getElementById("plak_site").value)) {
		alert("Sorry, but the website URL seems to be invalid. It must start with http:// or https:// and may not include spaces.\r\nExample of correct website URL - http://www.mywebsite.com");
	} else if (document.getElementById("plak_image").value.length > 0 && !isUrl(document.getElementById("plak_image").value)) {
		alert("Sorry, but the image URL seems to be invalid. It must start with http:// or https:// and may not include spaces.\r\nExample of correct image URL - http://www.mywebsite.com/pic1.jpg");
	} else if (document.getElementById("plak_image").value.length > 0 && !isImage(document.getElementById("plak_image").value)) {
		alert("Sorry, but the image URL seems to be invalid. It must point at either a jpeg, a gif or a png image.\r\nExample of correct image URL - http://www.mywebsite.com/pic1.jpg");
	} else {
		var icon = mapIcons[document.getElementById("plak_type").value];
		plak_add_close();
		var LatLng = new google.maps.LatLng(document.getElementById("plak_lat").value, document.getElementById("plak_lng").value);
		if (newMarker != null) {
			newMarker.setMap(null);
		}
		newMarker = new google.maps.Marker ({
			icon: icon,
			position: LatLng,
			zIndex: 10
		});
		newMarker.setMap(map);
		infoWindow = new google.maps.InfoWindow();
		google.maps.event.addListener(infoWindow, "closeclick", function() {
			infoWindow = null;
			newMarker.setMap(null);
			newMarker = null;
		});
		infoWindow.setContent("<br/><div class='info_name'>Are you sure that want to add that Plak there?</div><br/><div style='text-align: center;'><input class='plak_button' type='button' value='Yes' onclick=\"addNewPlak();\" /> <input class='plak_button' type='button' value='No' onclick=\"removeNewPlak();\" /></div>");
		infoWindow.open(map, newMarker);
	}
}

function addNewPlak() {
	var hasWiFi;
	if (document.getElementById("plak_wifi").checked) {
		hasWiFi = 1;
	} else {
		hasWiFi = 0;
	}
	var plak_name = document.getElementById("plak_name").value;
	plak_name = plak_name.replace(/&/g, "%26");
	var plak_desc = document.getElementById("plak_desc").value;
	plak_desc = plak_desc.replace(/&/g, "%26");
	var plak_address = document.getElementById("plak_address").value;
	plak_address = plak_address.replace(/&/g, "%26");
	var plak_site = document.getElementById("plak_site").value;
	plak_site = plak_site.replace(/&/g, "%26");
	var plak_image = document.getElementById("plak_image").value;
	plak_image = plak_image.replace(/&/g, "%26");
	AJAXCall("add", encodeURI("name=" + plak_name + "&lat=" + document.getElementById("plak_lat").value + "&lng=" + document.getElementById("plak_lng").value + "&type=" + document.getElementById("plak_type").value + "&desc=" + plak_desc + "&address=" + plak_address + "&phone=" + document.getElementById("plak_phone").value + "&fax=" + document.getElementById("plak_fax").value + "&wifi=" + hasWiFi + "&wtype=" + document.getElementById("plak_wifitype").value + "&site=" + plak_site + "&image=" + plak_image), "plakAdded(rep)");
	infoWindow.close();
	infoWindow = null;
	newMarker.setMap(null);
	newMarker = null;
}

function removeNewPlak() {
	infoWindow.close();
	infoWindow = null;
	newMarker.setMap(null);
	newMarker = null;
}

function wifiClicked(value) {
	if (value) {
		document.getElementById("plak_wifitype").disabled = false;
	} else {
		document.getElementById("plak_wifitype").disabled = true;
	}
}

function plakTypeChange(value) {
	if (value == 1) {
		document.getElementById("plak_wifi").checked = true;
		document.getElementById("plak_wifi").disabled = true;
		document.getElementById("plak_wifitype").disabled = false;
	} else {
		document.getElementById("plak_wifi").disabled = false;
	}
}

function plakAdded(object) {

	document.getElementById("plak_type").selectedIndex = 0;
	document.getElementById("plak_name").value = "";
	document.getElementById("plak_desc").value = "";
	document.getElementById("plak_address").value = "";
	document.getElementById("plak_phone").value = "";
	document.getElementById("plak_fax").value = "";
	document.getElementById("plak_site").value = "";
	document.getElementById("plak_image").value = "";
	document.getElementById("plak_wifi").checked = false;
	document.getElementById("plak_wifitype").selectedIndex = 0;
	document.getElementById("plak_wifitype").disabled = true;

	var LatLng = new google.maps.LatLng(object[2], object[3]);
	var marker = createMarker(LatLng, mapIcons[object[1]], object[4], object[0], object[1], object[5], "");
	markers.push(marker);
	marker.setMap(map);
}

function toggleOverlay(flag, index) {
	markerFlags[index] = flag;
	displayMarkers(1);
}

function toggleWiki(show) {
	if (show) {
		alert("Sorry, but the Wikipedia overlay doesn't work with Google Maps API v3");
	}
}

function getWeather(flag) {
	if (flag) {
		document.getElementById("check13").disabled = true;
		var bounds = map.getBounds();
		var ne = bounds.getNorthEast();
		var sw = bounds.getSouthWest();
		weatherCall(ne.lat(), sw.lat(), ne.lng(), sw.lng(), "gotWeather()", 4);
	} else {
		clearWeather();
	}
}

function clearWeather() {
	if (weather.length > 0) {
		for (var n = 0; n < weather.length; n++) {
			weather[n].setMap(null);
		}
		weather = [];
	}
}

function checkID(id) {
	var retval = true;
	if (id.substring(0, 1) == "M") {
		var regexp  = /^M[A-Z]/;
		retval = regexp.test(id);
	}
	return retval;
}

function gotWeather() {
	clearWeather();
	for (var n = 0; n < weatherStations.length; n++) {
		var country = weatherStations[n]["country"].toLowerCase();
		if ((country == "za" || country == "south africa") && checkID(weatherStations[n]["id"])) {
			var LatLng = new google.maps.LatLng(weatherStations[n]["lat"], weatherStations[n]["lon"]);
			var wicon;
			var sweather = weatherStations[n]["weather"].toLowerCase();
			if (sweather.indexOf("light") != -1) {
				sweather = sweather.substring(6);
			}
			if (sweather.indexOf("heavy") != -1) {
				sweather = sweather.substring(6);
			}
			var whtml = "";
			if (sweather == "clear" || sweather == "clr") {
				if (daytime) {
					wicon = weatherIcons[1];
					whtml = "<img src='http://bizzorg.com/img/wlclear.png' style='float: left; width: 32px; height: 32px;' alt='Clear' />";
				} else {
					wicon = weatherIcons[12];
					whtml = "<img src='http://bizzorg.com/img/wlntclear.png' style='float: left; width: 32px; height: 32px;' alt='Clear' />";
				}
			} else if (sweather == "overcast" || sweather == "ovc") {
				wicon = weatherIcons[2];
				whtml = "<img src='http://bizzorg.com/img/wlcloudy.png' style='float: left; width: 32px; height: 32px;' alt='Cloudy' />";
			} else if (sweather == "partly cloudy") {
				if (daytime) {
					wicon = weatherIcons[3];
					whtml = "<img src='http://bizzorg.com/img/wlpcloudy.png' style='float: left; width: 32px; height: 32px;' alt='Partly Cloudy' />";
				} else {
					wicon = weatherIcons[13];
					whtml = "<img src='http://bizzorg.com/img/wlntpcloudy.png' style='float: left; width: 32px; height: 32px;' alt='Partly Cloudy' />";
				}
			} else if (sweather == "mostly cloudy") {
				if (daytime) {
					wicon = weatherIcons[4];
					whtml = "<img src='http://bizzorg.com/img/wlmcloudy.png' style='float: left; width: 32px; height: 32px;' alt='Mostly Cloudy' />";
				} else {
					wicon = weatherIcons[14];
					whtml = "<img src='http://bizzorg.com/img/wlntmcloudy.png' style='float: left; width: 32px; height: 32px;' alt='Mostly Cloudy' />";
				}
			} else if (sweather == "scattered clouds" || sweather == "few" || sweather == "sct") {
				if (daytime) {
					wicon = weatherIcons[5];
					whtml = "<img src='http://bizzorg.com/img/wlscloudy.png' style='float: left; width: 32px; height: 32px;' alt='Scattered Clouds' />";
				} else {
					wicon = weatherIcons[15];
					whtml = "<img src='http://bizzorg.com/img/wlntscloudy.png' style='float: left; width: 32px; height: 32px;' alt='Scattered Clouds' />";
				}
			} else if (sweather == "fog" || sweather == "mist" || sweather == "smoke" || sweather == "fg" || sweather == "br" || sweather == "fu") {
				wicon = weatherIcons[6];
				whtml = "<img src='http://bizzorg.com/img/wlfog.png' style='float: left; width: 32px; height: 32px;' alt='Fog/Mist/Smoke' />";
			} else if (sweather == "haze" || sweather == "hz") {
				if (daytime) {
					wicon = weatherIcons[7];
					whtml = "<img src='http://bizzorg.com/img/wlhaze.png' style='float: left; width: 32px; height: 32px;' alt='Haze' />";
				} else {
					wicon = weatherIcons[16];
					whtml = "<img src='http://bizzorg.com/img/wlnthaze.png' style='float: left; width: 32px; height: 32px;' alt='Haze' />";
				}
			} else if (sweather == "drizzle" || sweather == "dz") {
				wicon = weatherIcons[8];
				whtml = "<img src='http://bizzorg.com/img/wldrizzle.png' style='float: left; width: 32px; height: 32px;' alt='Drizzle' />";
			} else if (sweather == "rain" || sweather == "rain showers" || sweather == "ra") {
				wicon = weatherIcons[9];
				whtml = "<img src='http://bizzorg.com/img/wlrain.png' style='float: left; width: 32px; height: 32px;' alt='Rain' />";
			} else if (sweather == "thunderstorm" || sweather == "thunderstorms and rain" || sweather == "ts") {
				wicon = weatherIcons[10];
				whtml = "<img src='http://bizzorg.com/img/wlstorm.png' style='float: left; width: 32px; height: 32px;' alt='Thunderstorm' />";
			} else if (sweather == "snow" || sweather == "snow showers" || sweather == "hail" || sweather == "hail showers" || sweather == "small hail showers" || sweather == "sn" || sweather == "gr") {
				wicon = weatherIcons[11];
				whtml = "<img src='http://bizzorg.com/img/wlsnow.png' style='float: left; width: 32px; height: 32px;' alt='Snow/Hail' />";
			} else {
				wicon = weatherIcons[0];
			}
			var label;
			if (weatherStations[n]["neighborhood"]) {
				if (weatherStations[n]["neighborhood"].length == 0) {
					label = weatherStations[n]["adm1"];
				} else {
					label = weatherStations[n]["neighborhood"];
				}
			} else {
				label = weatherStations[n]["adm1"];
			}
			var temp = parseFloat(weatherStations[n]["tempf"]);
			temp = ((temp - 32)/9)*5;
			temp = temp.toFixed(2);
			var mintemp = parseFloat(weatherStations[n]["mintemp"]);
			mintemp = ((mintemp - 32)/9)*5;
			mintemp = mintemp.toFixed(2);
			var maxtemp = parseFloat(weatherStations[n]["maxtemp"]);
			maxtemp = ((maxtemp - 32)/9)*5;
			maxtemp = maxtemp.toFixed(2);
			var html = "<div style='text-align: center;'>" + whtml + "<div style='font-weight: bold; padding-bottom: 5px;'>" + label + "</div><div style='font-size: 9px;'>(" + weatherStations[n]["ageh"] + " h " + weatherStations[n]["agem"] + " m " + weatherStations[n]["ages"] + " s ago)</div>";
			if (weatherStations[n]["tempf"] != "-9999" && weatherStations[n]["tempf"] != "-999.0") {
				html += "<div style='font-size: 18px; font-weight: bold; padding: 5px;'>" + temp + "&deg; C</div>";
			}
			if (weatherStations[n]["weather"] && weatherStations[n]["weather"] != "-999" && weatherStations[n]["weather"] != "Unknown") {
				html += "<div>" + weatherStations[n]["weather"] + "</div>";
			}
			if (!isNaN(mintemp) && weatherStations[n]["maxtemp"] != "-9999") {
				html += "<div>Min = <span style='color: #0000ff; font-weight: bold;'>" + mintemp +"&deg; C</span> Max = <span style='color: #ff0000; font-weight: bold;'>" + maxtemp + "&deg C</span></div>";
			}
			var windspeed = parseFloat(weatherStations[n]["windspeedmph"]);
			if (windspeed != "-999") {
				windspeed = windspeed * 1.609344;
				windspeed = windspeed.toFixed(2);
				if (!isNaN(windspeed)) {
					html += "<div>Wind = " + windspeed + " Km/h";
					if (weatherStations[n]["winddir"] != "-999") {
						html += " @ " + weatherStations[n]["winddir"] + "&deg;</div>";
					} else {
						html += "</div>";
					}
				}
			}
			html += "</div>";
			marker = new createWMarker(LatLng, wicon, label, html);
			weather.push(marker);
			marker.setMap(map);
		}
	}
	gettingWeather = false;
	document.getElementById("check13").disabled = false;
}

function toggleDirections(show) {
	if (!show) {
		if (startMarker.getMap() != null) {
			startMarker.setMap(null);
		}
		if (endMarker.getMap() != null) {
			endMarker.setMap(null);
		}
		if (dirPoly != null) {
			dirPoly.setMap(null);
			dirPoly = null;
		}
	}
}

function togglesidebar(image) {
	if (document.getElementById("sb_info").style.display == "block") {
		image.src="http://bizzorg.com/img/rightbutton.gif";
		document.getElementById("toggle_img").setAttribute("title", "Maximize Sidebar");
		document.getElementById("sb_info").style.display = "none";
	} else {
		image.src="http://bizzorg.com/img/leftbutton.gif";
		document.getElementById("toggle_img").setAttribute("title", "Minimize Sidebar");
		document.getElementById("sb_info").style.display = "block";
	}
	google.maps.event.trigger(map, 'resize');
}

function printDirections() {
	dir_text.focus();
	dir_text.print(); 
}

function checkCaps(text) {
	var retval = false;
	var regexp = /[A-Z]/g;
	var regexp1 = /[A-Za-z]/g;
	var textList = text.match(regexp1);
	var matchList = text.match(regexp);

	if (matchList != null) {
		if (matchList.length == textList.length) {
			retval = true;
		}
	}
	return retval;
}

function checkCountry(text) {
	var retval = true;
	text = text.toLowerCase();
	if (text.indexOf("south africa") == -1) {
		retval = false;
	}
	return retval;
}

function checkProv(text) {
	text = text.toLowerCase();
	if (text.indexOf("gauteng") != -1) {
		return true;
	} else if (text.indexOf("western cape") != -1) {
		return true;
	} else if (text.indexOf("eastern cape") != -1) {
		return true;
	} else if (text.indexOf("northern cape") != -1) {
		return true;
	} else if (text.indexOf("free state") != -1) {
		return true;
	} else if (text.indexOf("mpumalanga") != -1) {
		return true;
	} else if (text.indexOf("limpopo") != -1) {
		return true;
	} else if (text.indexOf("kwazulu-natal") != -1) {
		return true;
	} else if (text.indexOf("north west") != -1) {
		return true;
	} else if (text.indexOf("gauteng") != -1) {
		return true;
	} else {
		return false;
	}
}

function doBlink() {
	var blink = document.getElementById("addrBlink");
	if (blink.style.color == "#ff0000" || blink.style.color =="rgb(255, 0, 0)") {
		blink.style.color = "#F2F8FB";
	} else {
		blink.style.color = "#FF0000";
	}
}

function plak_find_open() {
	document.getElementById("find_lat_deg").value = "";
	document.getElementById("find_lat_min").value = "";
	document.getElementById("find_lat_sec").value = "";

	document.getElementById("find_lng_deg").value = "";
	document.getElementById("find_lng_min").value = "";
	document.getElementById("find_lng_sec").value = "";

	document.getElementById("find_dec_lat").value = "";
	document.getElementById("find_dec_lng").value = "";
	document.getElementById("plak_find").style.display = "block";
}

function plak_find_close() {
	document.getElementById("plak_find").style.display = "none";
}

function findDecLoc() {
	var lat = parseFloat(document.getElementById("find_dec_lat").value);
	var lng = parseFloat(document.getElementById("find_dec_lng").value);

	if (isNaN(lat)) {
		alert("The latitude must be a negative numeric value between -34.8422 and -22.1111");
	} else if (isNaN(lng)) {
		alert("The longitude must be a positive numeric value between 16.4516 and 32.8966");
	} else if (lat > -22.1111 || lat < -35.8422) {
		alert("The latitude must be a negative numeric value between -34.8422 and -22.1111");
	} else if (lng > 32.8966 || lng < 16.4516) {
		alert("The longitude must be a positive numeric value between 16.4516 and 32.8966");
	} else {
		document.getElementById("plak_find").style.display = "none";
		map.setCenter(new google.maps.LatLng(lat, lng));
		if (map.getZoom() < 12) {
			map.setZoom(12);
		}
		showX(lat, lng);
	}
}

function findDecMinLoc() {
	var latDeg = parseInt(document.getElementById("find_lat_deg1").value);
	var latMin = parseFloat(document.getElementById("find_lat_decmin").value);

	var lngDeg = parseInt(document.getElementById("find_lng_deg1").value);
	var lngMin = parseFloat(document.getElementById("find_lng_decmin").value);

	if (isNaN(latDeg) || isNaN(latMin)) {
		alert("The latitude must be fall between S 34° 50.532' and S 22° 6.666'");
	} else if (isNaN(lngDeg) || isNaN(lngMin)) {
		alert("The longitude must be fall between E 16° 27.096' and E 32° 53.796'");
	} else {
		var lat = latDeg + (latMin / 60);
		lat = lat * -1;
		var lng = lngDeg + (lngMin / 60);
		if (lat > -22.1111 || lat < -35.8422) {
			alert("The latitude must be fall between S 34° 50.532' and S 22° 6.666'");
		} else if (lng > 32.8966 || lng < 16.4516) {
			alert("The longitude must be fall between E 16° 27.096' and E 32° 53.796'");
		} else {
			document.getElementById("plak_find").style.display = "none";
			map.setCenter(new google.maps.LatLng(lat, lng));
			if (map.getZoom() < 12) {
				map.setZoom(12);
			}
			showX(lat, lng);
		}
	}
}

function findDegLoc() {
	var latDeg = parseInt(document.getElementById("find_lat_deg").value);
	var latMin = parseInt(document.getElementById("find_lat_min").value);
	var latSec = parseFloat(document.getElementById("find_lat_sec").value);

	var lngDeg = parseInt(document.getElementById("find_lng_deg").value);
	var lngMin = parseInt(document.getElementById("find_lng_min").value);
	var lngSec = parseFloat(document.getElementById("find_lng_sec").value);

	if (isNaN(latDeg) || isNaN(latMin) || isNaN(latSec)) {
		alert("The latitude must be fall between S 34° 50' 31.9194\" and S 22° 6' 39.96\"");
	} else if (isNaN(lngDeg) || isNaN(lngMin) || isNaN(lngSec)) {
		alert("The longitude must be fall between E 16° 27' 5.7594\" and E 32° 53' 47.7594\"");
	} else {
		var lat = latDeg + (latMin / 60) + (latSec / 3600);
		lat = lat * -1;
		var lng = lngDeg + (lngMin / 60) + (lngSec / 3600);
		if (lat > -22.1111 || lat < -35.8422) {
			alert("The latitude must be fall between S 34° 50' 31.9194\" and S 22° 6' 39.96\"");
		} else if (lng > 32.8966 || lng < 16.4516) {
			alert("The longitude must be fall between E 16° 27' 5.7594\" and E 32° 53' 47.7594\"");
		} else {
			document.getElementById("plak_find").style.display = "none";
			map.setCenter(new google.maps.LatLng(lat, lng));
			if (map.getZoom() < 12) {
				map.setZoom(12);
			}
			showX(lat, lng);
		}
	}
}

function showX(xLat, xLng) {
	var point = new google.maps.LatLng(xLat, xLng);
	google.maps.event.clearListeners(xMarker, "mouseover");
	google.maps.event.clearListeners(xMarker, "mouseout");
	xMarker.setPosition(point);
}

function getFlagBitmap() {
	var retval = "";
	for (var n = 1; n < markerFlags.length; n++) {
		if (markerFlags[n] == 0) {
			retval += "0";
		} else {
			retval += "1";
		}
	}
	return retval;
}

function getNumMarkers() {
	var zoom = map.getZoom();
	var maxmarkers = "0";
	if (zoom < 15) {
		if (ie) {
			maxmarkers = "50";
		} else {
			maxmarkers = "90";
		}
	}
	return maxmarkers;
}

function plak_sv_close() {
	document.getElementById("plak_sv_container").style.display = "none";
}

function plak_sv_show(svlat, svlng) {
	var sv = new google.maps.LatLng(svlat, svlng);
	var panoramaOptions = {
		position: sv,
		enableCloseButton: true,
		pov: {
			heading: 0,
			pitch: 0,
			zoom: 1
		}
	};
	var panorama = new  google.maps.StreetViewPanorama(document.getElementById("plak_map"), panoramaOptions);
}

function cityChanged(LatLng) {
	var values = LatLng.split(",");
	var zoom = map.getZoom();
	if (zoom < 12) {
		map.setCenter(new google.maps.LatLng(values[0], values[1]));
		map.setZoom(parseInt(values[2]));
	} else {
		map.setCenter(new google.maps.LatLng(values[0], values[1]));
	}
}
