var jq = jQuery.noConflict(), emailAlertSubReq, immediateReq, backendReq, imagesReq, descriptionReq, miscReq, favReq, hideReq, gotoReq, quickMailReq, overlayReq, yelpReq, map, markerArray = [], newMarkerArray = [], myPano, maxMarkers = 150, workplaceLat = 0, workplaceLong = 0, showPOI = false, showCityClusters = true, picDialogUnopened = true, favDialogUnopened = true, aboutDialogUnopened = true, saveFavsDialogUnopened = true, numTimesBounced = 0, userId = -1, searchTerms = "", showMarkerPoint, isIE = false, listingLimitAlertDisabled = false, yelpType = "bars", currImage = 0, currNumImages = 0, currListing = 0, inactivePoints = [], activePoints = [], tempPoints = [], currentPoint, workIcon, currentWorkIcon, bizMarkers = Array(), directionsObj = new GDirections, geocoder = new GClientGeocoder();
GEvent.addListener(directionsObj, "load", directionsLoadedCallback);
GEvent.addListener(directionsObj, "error", directionsErrorCallback);
var commuteBoundsTime, interval = 14, boundsPolyPoints = Array(), boundsPoly, circlePolyPoints = Array(), circleSearchPoints = Array(), circleSearchPointsTemp = Array(), circlePoly, directionsPolyLines = Array(), drivingCircleCenter = null, commuteMode = "drive", walkscoreLayer = null, quickMailFrom, quickMailSignature, quickMailEmail, quickMailSetup = false, quickMailId = -1, seenMarkers = {}, favMarkers = {}, type0icon = new GIcon(
		G_DEFAULT_ICON);
type0icon.image = base + "img/green.png";
var type2icon = new GIcon(G_DEFAULT_ICON);
type2icon.image = base + "img/yellow-dot2.png";
var shoppingTypeIcon = new GIcon(G_DEFAULT_ICON);
shoppingTypeIcon.image = base + "img/shopping-rounded.png";
var foodTypeIcon = new GIcon(G_DEFAULT_ICON);
foodTypeIcon.image = base + "img/food-rounded.png";
var barTypeIcon = new GIcon(G_DEFAULT_ICON);
barTypeIcon.image = base + "img/bar-rounded.png";
var nightlifeTypeIcon = new GIcon(G_DEFAULT_ICON);
nightlifeTypeIcon.image = base + "img/nightlife-rounded.png";
var activeTypeIcon = new GIcon(G_DEFAULT_ICON);
activeTypeIcon.image = base + "img/active-rounded2.png";
var artTypeIcon = new GIcon(G_DEFAULT_ICON);
artTypeIcon.image = base + "img/art-rounded.png";
var beautyTypeIcon = new GIcon(G_DEFAULT_ICON);
beautyTypeIcon.image = base + "img/beautysvc-rounded.png";
var seenIcon = new GIcon(G_DEFAULT_ICON);
seenIcon.image = base + "img/gray-dot.png";
var favIcon = new GIcon(G_DEFAULT_ICON);
favIcon.image = base + "img/green.png";
function setupInput(a, b) {
	var c = document.getElementById(a);
	if (isIE) {
		c.attachEvent("onfocus", clearDefaultText);
		c.attachEvent("onblur", replaceDefaultText);
		maxMarkers = 120
	} else {
		c.addEventListener("focus", clearDefaultText, false);
		c.addEventListener("blur", replaceDefaultText, false)
	}
	if (c.value != "")
		c.defaultText = b
}
function makeInputSelectall(a) {
	jq(a).focus(function() {
		this.select()
	});
	jq(a).mouseup(function(b) {
		b.preventDefault()
	})
}
function subscribeToAlerts(a, b) {
	toggleDiv("#alerttSignupSpinnerContainer");
	var c = getWindowLimits();
	c = makeGetVars(c, 100);
	c = c + "&email=" + URLEncode(a) + "&frequency=" + URLEncode(b);
	emailAlertSubReq = GXmlHttp.create();
	emailAlertSubReq.onreadystatechange = emailAlertSubStateChanged;
	emailAlertSubReq.open("GET", "/emailSub.php" + c, true);
	emailAlertSubReq.send(null)
}
function saveAndEmailFavs(a, b) {
	toggleDiv("#divSpinnerContainer");
	var c = "?name=" + b + "&emailAddress=" + a;
	miscReq = GXmlHttp.create();
	miscReq.onreadystatechange = storeAndEmailStateChanged;
	miscReq.open("GET", "/storeList.php" + c, true);
	miscReq.send(null)
}
function emailAlertSubStateChanged() {
	if (emailAlertSubReq.readyState == 4)
		if (emailAlertSubReq.status == 200)
			if (emailAlertSubReq.responseText == "1") {
				toggleDiv("#alerttSignupSpinnerContainer");
				showDiv("#alerttSignupCompletedMessage");
				setTimeout("hideDiv('#alerttSignupCompletedMessage');", 2E3)
			} else
				alert("Failed")
}
function storeAndEmailStateChanged() {
	if (miscReq.readyState == 4)
		if (miscReq.status == 200)
			if (miscReq.responseText == "1") {
				toggleDiv("#divSpinnerContainer");
				showDiv("#favEmailCompletedMessage");
				setTimeout("hideDiv('#favEmailCompletedMessage');", 2E3)
			} else
				alert("Failed")
}
function clearDefaultText(a) {
	if (a = window.event ? window.event.srcElement : a ? a.target : null)
		if (a.value == a.defaultText)
			a.value = ""
}
function replaceDefaultText(a) {
	if (a = window.event ? window.event.srcElement : a ? a.target : null)
		if (a.value == "" && a.defaultText)
			a.value = a.defaultText
}
function badListing(a) {
	a = "?id=" + a;
	if (descriptionReq)
		descriptionReq.readyState != 0 && descriptionReq.abort();
	else
		descriptionReq = GXmlHttp.create();
	descriptionReq.onreadystatechange = descriptionLoadStateChanged;
	descriptionReq.open("GET", "/flagAsBad.php" + a, true);
	descriptionReq.send(null)
}
function doubleSlider(a, b, c, d, e, f, g, h, i, j) {
	jq(a).slider( {
		range : true,
		min : b,
		max : c,
		values : [ e, f ],
		step : d,
		slide : function(k, m) {
			doubleChangeEvent(k, m, g, h, i, j, c)
		},
		change : function(k, m) {
			doubleChangeEvent(k, m, g, h, i, j, c)
		},
		stop : function() {
			reloadAll()
		}
	});
	b = jq(a).slider("values", 1);
	if (b == c)
		b += "+";
	jq(g).text(jq(a).slider("values", 0));
	jq(h).text(b);
	jq(i).text(jq(a).slider("values", 0));
	jq(j).text(b)
}
function doubleChangeEvent(a, b, c, d, e, f, g) {
	a = b.values[1];
	if (b.values[1] == g)
		a += "+";
	jq(c).text(b.values[0]);
	jq(d).text(a);
	jq(e).text(b.values[0]);
	jq(f).text(a)
}
function singleChangeEvent(a, b, c, d, e) {
	a = b.values[0];
	if (b.values[0] == e)
		a += "+";
	jq(c).text(a);
	jq(d).text(a)
}
function singleSlider(a, b, c, d, e, f, g) {
	jq(a).slider( {
		min : b,
		max : c,
		values : [ d ],
		step : e,
		slide : function(h, i) {
			singleChangeEvent(h, i, f, g, c)
		},
		change : function(h, i) {
			singleChangeEvent(h, i, f, g, c)
		},
		stop : function() {
			reloadAll()
		}
	});
	a = jq(a).slider("values", 0);
	if (a == c)
		a += "+";
	jq(f).text(a);
	jq(g).text(a)
}
function createMarker(a, b, c, d) {
	return c == 0 ? createCityMarker(a, b, d)
			: c == 1 || c == 2 ? createApartmentMarker(a, b, d, c)
					: createPOIMarker(a, b, d, c)
}
function createCityMarker(a, b, c) {
	markerOptions = {
		icon : type0icon
	};
	var d = new GMarker(a, markerOptions);
	d.value = b;
	GEvent
			.addListener(
					d,
					"click",
					function() {
						currentPoint = a;
						c
								.openInfoWindowHtml(a,
										'<div id = "infoBoxHTML"><img src="/images/throbber.gif"/></div>');
						loadCityDescription(d.value)
					});
	return d
}
function createPOIMarker(a, b, c, d) {
	if (d == 3)
		markerOptions = {
			icon : shoppingTypeIcon
		};
	else if (d == 4)
		markerOptions = {
			icon : foodTypeIcon
		};
	else if (d == 5)
		markerOptions = {
			icon : barTypeIcon
		};
	else if (d == 6)
		markerOptions = {
			icon : nightlifeTypeIcon
		};
	else if (d == 7)
		markerOptions = {
			icon : activeTypeIcon
		};
	else if (d == 8)
		markerOptions = {
			icon : artTypeIcon
		};
	else if (d == 9)
		markerOptions = {
			icon : beautyTypeIcon
		};
	var e = new GMarker(a, markerOptions);
	e.value = b;
	GEvent
			.addListener(
					e,
					"click",
					function() {
						currentPoint = a;
						c
								.openInfoWindowHtml(a,
										'<div id = "infoBoxHTML"><img src="/images/throbber.gif"/></div>');
						loadPOIDescription(e.value)
					});
	return e
}
function createPOIMarkerHtml(a, b, c) {
	markerOptions = yelpType == "groceries" ? {
		icon : shoppingTypeIcon
	} : yelpType == "restaurants" ? {
		icon : foodTypeIcon
	} : yelpType == "bars" ? {
		icon : barTypeIcon
	} : yelpType == "nightlife" ? {
		icon : nightlifeTypeIcon
	} : yelpType == "gyms" ? {
		icon : activeTypeIcon
	} : yelpType == 8 ? {
		icon : artTypeIcon
	} : {
		icon : beautyTypeIcon
	};
	var d = new GMarker(a, markerOptions);
	GEvent.addListener(d, "click", function() {
		currentPoint = a;
		b.openInfoWindowHtml(a, c)
	});
	return d
}
function createApartmentMarker(a, b, c, d) {
	if (favMarkers[b] != null) {
		markerOptions = {
			icon : favIcon
		};
		var e = new GMarker(a, markerOptions)
	} else if (seenMarkers[b] != null) {
		markerOptions = {
			icon : seenIcon
		};
		e = new GMarker(a, markerOptions)
	} else if (d == 1 || userId > -1)
		e = new GMarker(a);
	else if (d == 2) {
		markerOptions = {
			icon : type2icon
		};
		e = new GMarker(a, markerOptions)
	}
	e.value = b;
	GEvent
			.addListener(
					e,
					"click",
					function() {
						currentPoint = a;
						seenMarkers[e.value] == null
								&& replacePointWithSeenOrFavMarker(e, true);
						c
								.openInfoWindowHtml(a,
										'<div id = "infoBoxHTML"><img src="/images/throbber.gif"/></div>');
						loadHotelDescription(e.value)
					});
	return e
}
function createAndAddWorkMarker(a, b, c) {
	if (!workIcon) {
		workIcon = new GIcon(G_DEFAULT_ICON);
		workIcon.image = base + "img/marker_34_green.png"
	}
	if (currentWorkIcon) {
		b.removeOverlay(currentWorkIcon);
		currentWorkIcon = null
	}
	var d = new GMarker(a, {
		icon : workIcon
	});
	GEvent.addListener(d, "click", function() {
		b.openInfoWindowHtml(a, '<div id = "infoBoxHTML">' + c + "</div>")
	});
	b.addOverlay(d);
	currentWorkIcon = d
}
function removeWorkMarker(a) {
	if (currentWorkIcon) {
		a.removeOverlay(currentWorkIcon);
		currentWorkIcon = null
	}
}
function hideOrShowListingNumWarning() {
	markerArray.length >= maxMarkers && !listingLimitAlertDisabled ? jq(
			"#tooManyAlertOverlay").show() : jq("#tooManyAlertOverlay").hide()
}
function closeListingNumWarning() {
	listingLimitAlertDisabled = true;
	miscReq = GXmlHttp.create();
	miscReq.onreadystatechange = null;
	miscReq.open("GET", "/disableListingAlertBox.php", true);
	miscReq.send(null);
	jq("#tooManyAlertOverlay").hide()
}
function getYelpPOIs(a) {
	yelpReq = GXmlHttp.create();
	yelpReq.onreadystatechange = yelpLoadStateChanged;
	yelpType = a;
	var b = getWindowLimits();
	getVars = "?eastLong=" + b.eastLong + "&northLat=" + b.northLat
			+ "&westLong=" + b.westLong + "&southLat=" + b.southLat + "&term="
			+ a;
	yelpReq.open("GET", "/yelpRequest.php" + getVars, true);
	yelpReq.send(null)
}
function yelpLoadStateChanged() {
	if (yelpReq.readyState == 4)
		if (yelpReq.status == 200) {
			var a = JSON.parse(yelpReq.responseText);
			a.message.text == "OK" ? showBusinesses(a.businesses)
					: alert("Could not find any nearby matches.")
		}
}
function changeToLoggedIn(a) {
	jq("#loginWindow").html(
			"Logged in - " + a
					+ ' <a href="#" onclick = "logout();">Logout</a>')
}
function changeToLoggedOut() {
	jq("#loginWindow")
			.html(
					"Not logged in. <a href=\"javascript:showDiv('#overlay'); showDiv('#loginRegisterDiv');\">Login/Register</a>")
}
function logout() {
	changeIframeToLogout();
	miscReq = GXmlHttp.create();
	miscReq.onreadystatechange = function() {
		miscReq.readyState == 4 && miscReq.status == 200 && changeToLoggedOut()
	};
	miscReq.open("GET", "/logout.php", true);
	miscReq.send(null)
}
function isTrue(a) {
	return a === "true"
}
function setMapAndFilters() {
	miscReq = GXmlHttp.create();
	miscReq.onreadystatechange = function() {
		if (miscReq.readyState == 4)
			if (miscReq.status == 200) {
				var a = JSON.parse(miscReq.responseText);
				if (a.isLoggedIn === true && a.currentSettings != null) {
					a = a.currentSettings;
					jq("#rent_slider").slider("values", 0, a.minRent);
					jq("#rent_slider").slider("values", 1, a.maxRent);
					jq("#br_slider").slider("values", 0, a.minBR);
					jq("#br_slider").slider("values", 1, a.maxBR);
					jq("#ba_slider").slider("values", 0, a.minBA);
					jq("#ppbr_slider")
							.slider("values", 0, a.maxPricePerBedroom);
					jq("#age_slider").slider("values", 0, a.maxAge);
					jq("#imagesOnlyCheck")
							.attr("checked", isTrue(a.imagesOnly));
					jq("#catsCheck").attr("checked", isTrue(a.cats));
					jq("#dogsCheck").attr("checked", isTrue(a.dogs));
					jq("#noFeeCheck").attr("checked", isTrue(a.noFee));
					jq("#subs").attr("checked", isTrue(a.showSubs));
					jq("#nonsubs").attr("checked", isTrue(a.showNonSubs));
					jq("#cl").attr("checked", isTrue(a.cl));
					jq("#apts").attr("checked", isTrue(a.apts));
					jq("#ood").attr("checked", isTrue(a.ood));
					jq("#forrent").attr("checked", isTrue(a.forrent));
					var b = a.searchTerms;
					b != null && b != "" && jq("#listingSearch").val(b);
					setSearchTermsNoReload();
					map.setCenter(new GLatLng(a.centerLat, a.centerLong),
							a.zoom);
					reloadAll()
				}
			}
	};
	miscReq.open("GET", "/loadAccountSettings.php", true);
	miscReq.send(null)
}
function checkIfLoggedIn() {
	miscReq = GXmlHttp.create();
	miscReq.onreadystatechange = function() {
		if (miscReq.readyState == 4)
			if (miscReq.status == 200) {
				var a = JSON.parse(miscReq.responseText);
				if (a.isLoggedIn == true) {
					changeToLoggedIn(a.login);
					seenMarkers = a.seenIds;
					favMarkers = a.favIds;
					jq("#favsListTextArea").html(a.favListHtml);
					if (a.hasLastSettings) {
						showDiv("#overlay");
						showDiv("#restoreOriginalDialog")
					} else
						reloadAll()
				}
			}
	};
	miscReq.open("GET", "/checkIfLoggedIn.php", true);
	miscReq.send(null)
}
function clearYelpMarkers() {
	for ( var a = 0; a < bizMarkers.length; a++) {
		bizMarker = bizMarkers[a];
		map.removeOverlay(bizMarker)
	}
	bizMarkers = Array()
}
function showBusinesses(a) {
	for ( var b = 0; b < a.length; b++) {
		var c = a[b], d = "Unknown";
		if (c.categories[0])
			d = c.categories[0].name;
		d = "<div class='infoDescriptionDiv' style='font-size:10pt;'> <a target='_blank' href='"
				+ c.url
				+ "'>"
				+ c.name
				+ "</a><br/>Category: "
				+ d
				+ "<br/> <img src='"
				+ c.rating_img_url
				+ "'/> ("
				+ c.review_count
				+ " ratings) <br/><br/><div style='float:left; font-size:10px; padding-top:6px;'>Powered by</div> <div style='float:left;'><img src='/images/miniMapLogo.png'/></div><div style='clear:both;'></div></div>";
		c = new GLatLng(c.latitude, c.longitude);
		c = createPOIMarkerHtml(c, map, d);
		bizMarkers.push(c);
		map.addOverlay(c)
	}
}
function reShowBusinesses() {
	for ( var a = 0; a < bizMarkers.length; a++)
		map.addOverlay(bizMarkers[a])
}
function replacePointWithSeenOrFavMarker(a, b) {
	var c = a.getLatLng(), d = a.value;
	if (b)
		seenMarkers[d] = 1;
	else
		favMarkers[d] = 1;
	c = createApartmentMarker(c, d, map, 1);
	swapMarkers(a, c)
}
function swapMarkers(a, b) {
	map.addOverlay(b);
	map.removeOverlay(a);
	for ( var c = 0; c < markerArray.length; c++)
		if (markerArray[c] == a)
			markerArray[c] = b
}
function dragUpdateMarkers() {
	for ( var a = map.getBounds(), b = [], c = [], d = 0, e = 0; e < markerArray.length; e++) {
		var f = new GLatLng(activePoints[e].lat, activePoints[e].lng);
		if (a.contains(f)) {
			b[d] = markerArray[e];
			c[d] = activePoints[e];
			d++
		} else {
			map.removeOverlay(markerArray[e]);
			inactivePoints[inactivePoints.length] = activePoints[e]
		}
	}
	activePoints = c;
	markerArray = b;
	trimAndPromoteInactivePoints();
	updateBackend()
}
function trimAndPromoteInactivePoints() {
	for ( var a = map.getBounds(), b = getOuterLimits(), c = [], d = 0, e = markerArray.length, f = 0; f < inactivePoints.length; f++) {
		var g = inactivePoints[f].lat, h = inactivePoints[f].lng;
		if (!(b.eastLong > b.westLong && (g > b.northLat || g < b.southLat
				|| h > b.eastLong || h < b.westLong))) {
			h = new GLatLng(inactivePoints[f].lat, inactivePoints[f].lng);
			if (e < maxMarkers && a.contains(h)) {
				g = activePoints.length;
				activePoints[g] = inactivePoints[f];
				var i = activePoints[g];
				h = createMarker(h, i.id, i.type, map);
				map.addOverlay(h);
				markerArray[g] = h;
				e++
			} else {
				c[d] = inactivePoints[f];
				d++
			}
		}
	}
	inactivePoints = c;
	hideOrShowListingNumWarning()
}
function createMarkers() {
	map.clearOverlays();
	redrawAllPolys();
	walkscoreOverlayEnabled() && enableWalkscoreOverlay();
	map.getZoom();
	bizMarkers.length > 0 && reShowBusinesses();
	currentWorkIcon && map.addOverlay(currentWorkIcon);
	markerArray = [];
	for ( var a = 0, b = map.getBounds(), c = 0; c < activePoints.length; c++) {
		var d = activePoints[c], e = new GLatLng(d.lat, d.lng);
		if (!(!b.contains(e) || a > maxMarkers)) {
			d = createMarker(e, d.id, d.type, map);
			map.addOverlay(d);
			markerArray[c] = d;
			a++
		}
	}
	if (showMarkerPoint) {
		goToMarker(showMarkerPoint.id);
		showMarkerPoint = null
	}
}
function loadCityDescription(a) {
	if (descriptionReq)
		descriptionReq.readyState != 0 && descriptionReq.abort();
	else
		descriptionReq = GXmlHttp.create();
	descriptionReq.onreadystatechange = descriptionLoadStateChanged;
	descriptionReq.open("GET", base + "hotels/city/" + a, true);
	descriptionReq.send(null)
}
function loadPOIDescription(a) {
	a = "?poiID=" + a;
	if (descriptionReq)
		descriptionReq.readyState != 0 && descriptionReq.abort();
	else
		descriptionReq = GXmlHttp.create();
	descriptionReq.onreadystatechange = descriptionLoadStateChanged;
	descriptionReq.open("GET", "/loadPOIDescription.php" + a, true);
	descriptionReq.send(null)
}
function loadApartmentMarkerPoint(a) {
	if (gotoReq)
		gotoReq.readyState != 0 && gotoReq.abort();
	else
		gotoReq = GXmlHttp.create();
	gotoReq.onreadystatechange = apartMarkerLoadStateChanged;
	gotoReq.open("GET", base + "hotels/load_point/" + a, true);
	gotoReq.send(null)
}
function apartMarkerLoadStateChanged() {
	if (gotoReq.readyState == 4)
		if (gotoReq.status == 200) {
			var a;
			if (gotoReq.responseText != "" && gotoReq.responseText != "0") {
				a = eval("(" + gotoReq.responseText + ")");
				// a = a[0];
				goToAndSelectMarker(a, null)
			} else
				alert("I'm sorry, it looks like that this hotel does not exist on our database anymore. If you think this is in error, please contact jim@surfnetwebdesign.com. Thank you.")
		}
}
function loadHotelDescription(a) {
	currListing = a;
	a = "/" + a + "/workLat:" + workplaceLat + "/workLong:" + workplaceLong;
	if (descriptionReq)
		descriptionReq.readyState != 0 && descriptionReq.abort();
	else
		descriptionReq = GXmlHttp.create();
	descriptionReq.onreadystatechange = descriptionLoadStateChanged;
	descriptionReq.open("GET", base + "hotels/details/" + a, true);
	descriptionReq.send(null)
}
function descriptionLoadStateChanged() {
	descriptionReq.readyState == 4
			&& descriptionReq.status == 200
			&& map
					.openInfoWindowHtml(currentPoint,
							descriptionReq.responseText)
}
function loadOverlayPolys() {
	var a = getOuterLimits();
	a = "?eastLong=" + a.eastLong + "&northLat=" + a.northLat + "&westLong="
			+ a.westLong + "&southLat=" + a.southLat + "&type=crime";
	if (overlayReq)
		overlayReq.readyState != 0 && overlayReq.abort();
	else
		overlayReq = GXmlHttp.create();
	overlayReq.onreadystatechange = overlayPolyLoadStateChanged;
	overlayReq.open("GET", "/loadOverlayPolys.php" + a, true);
	overlayReq.send(null)
}
function overlayPolyLoadStateChanged() {
	overlayReq.readyState == 4 && overlayReq.status == 200
			&& updateOverlayPolys(overlayReq.responseText)
}
function updateOverlayPolys(a) {
	a = eval(a);
	for ( var b = 0; b < a.length; b++) {
		for ( var c = a[b], d = [], e = 1; e < c.length; e++) {
			var f = c[e];
			f = new GLatLng(f[0], f[1]);
			d.push(f)
		}
		c = new GPolygon(d, "#f33f00", 1, 1, "#ff0000", 0.1);
		map.addOverlay(c)
	}
}
function enableOverlayClick() {
	makeCursorCrosshair();
	hideInitAndShowCancelButton();
	var a = GEvent.addListener(map, "click", function(b, c) {
		createTransitBoundPoly(c);
		resetCursor();
		GEvent.removeListener(a)
	})
}
function makeCursorCrosshair() {
	jq("#map img").addClass("crossHaired")
}
function resetCursor() {
	jq("#map img").removeClass("crossHaired")
}
function clearMap() {
	makeBackgroundWhite("#driveCommuteAddress");
	showInitAndHideCancelButton();
	resetCursor();
	removeAllPolys();
	resetCommuteTime()
}
function haltCommuteTime() {
	showInitAndHideCancelButton();
	resetCursor();
	circleSearchPointsTemp = Array()
}
function resetCommuteTime() {
	boundsPolyPoints = Array();
	boundsPoly = null;
	circlePolyPoints = Array();
	circleSearchPoints = Array();
	circleSearchPointsTemp = Array();
	circlePoly = null;
	directionsPolyLines = Array();
	drivingCircleCenter = null
}
function hideInitAndShowCancelButton() {
	hideDiv("#drivingBoundsInitButton");
	showDiv("#drivingBoundsCancelButton")
}
function showInitAndHideCancelButton() {
	showDiv("#drivingBoundsInitButton");
	hideDiv("#drivingBoundsCancelButton")
}
function driveCommuteCallback(a) {
	var b = a.address;
	commuteMode = jq("#commuteType").val();
	if (a) {
		var c = 12;
		if (commuteMode == "walk")
			c = 14;
		map.setCenter(a, c);
		makeBackgroundGreen("#driveCommuteAddress");
		workplaceLat = a.lat();
		workplaceLong = a.lng();
		createAndAddWorkMarker(a, map, b);
		createTransitBoundPoly(a)
	} else {
		makeBackgroundRed("#driveCommuteAddress");
		workplaceLong = workplaceLat = 0;
		removeWorkMarker(map)
	}
}
function setupDirectionsObjCommuteMode() {
	directionsObj = new GDirections;
	if (commuteMode == "walk") {
		directionsObj = new GDirections(null, document
				.getElementById("directionStepsOverlay"));
		assumedMaxSpeedLimit = 6
	} else if (commuteMode == "bike")
		assumedMaxSpeedLimit = 25;
	GEvent.addListener(directionsObj, "load", directionsLoadedCallback);
	GEvent.addListener(directionsObj, "error", directionsErrorCallback)
}
function getAssumedSpeedLimits() {
	var a = 40;
	if (commuteMode == "walk")
		a = 6;
	else if (commuteMode == "bike")
		a = 25;
	return a
}
function createTransitBoundPoly(a) {
	if (a) {
		removeAllPolys();
		resetCommuteTime();
		setupDirectionsObjCommuteMode();
		commuteBoundsTime = jq("#commuteTime").val();
		var b = getAssumedSpeedLimits() * (commuteBoundsTime / 60);
		circlePolyPoints = getPolyPoints(a, b, false);
		circleSearchPointsTemp = circleSearchPoints = getPolyPoints(a, b, true);
		redrawRoadDistCircle();
		getDirections(a)
	}
}
function getPolyPoints(a, b, c) {
	drivingCircleCenter = a;
	var d = Array();
	Array();
	var e = 1;
	if (c)
		e = interval;
	b = b * 0.014457;
	c = b / Math.cos(a.lat() * 0.017453);
	for ( var f = 0; f < 361; f += e) {
		var g = f * (Math.PI / 180), h = a.lng() + c * Math.cos(g);
		g = a.lat() + b * Math.sin(g);
		h = new GLatLng(parseFloat(g), parseFloat(h), true);
		d.push(h)
	}
	return d
}
function getDirections() {
	if (!circleSearchPointsTemp || circleSearchPointsTemp.length == 0)
		showInitAndHideCancelButton();
	else {
		var a = "from: " + drivingCircleCenter.lat() + ","
				+ drivingCircleCenter.lng() + " to: "
				+ circleSearchPointsTemp[0].lat() + ", "
				+ circleSearchPointsTemp[0].lng();
		circleSearchPointsTemp.shift();
		var b = {
			getPolyline : true,
			getSteps : true
		};
		if (commuteMode == "walk")
			b = {
				getPolyline : true,
				getSteps : true,
				travelMode : G_TRAVEL_MODE_WALKING
			};
		else if (commuteMode == "bike")
			b = {
				getPolyline : true,
				getSteps : true,
				avoidHighways : true
			};
		directionsObj.load(a, b)
	}
}
function directionsErrorCallback() {
	setTimeout("getDirections()", 400)
}
function directionsLoadedCallback() {
	var a = shortenPolyLineByDuration(directionsObj.getRoute(0), directionsObj
			.getPolyline());
	if (a && a.getVertexCount() > 0) {
		directionsPolyLines.push(a);
		var b = a.getVertex(a.getVertexCount() - 1);
		boundsPolyPoints.push(b);
		boundsPolyPoints.sort(angleComparator);
		setupShapeListeners(a);
		map.addOverlay(a);
		redrawBoundsPoly()
	}
	setTimeout("getDirections()", 700)
}
function shortenPolyLineByDuration(a, b) {
	for ( var c = commuteBoundsTime * 60, d = 0, e = Array(), f = a
			.getNumSteps(), g = 0; g < f; g++) {
		var h = a.getStep(g), i = h.getDuration().seconds, j = h
				.getPolylineIndex(), k = 0;
		k = g + 1 < f ? a.getStep(g + 1).getPolylineIndex() : b
				.getVertexCount();
		if (d + i < c)
			for (j = j; j < k; j++)
				e.push(b.getVertex(j));
		else {
			f = 0;
			c = h.getDistance().meters * ((c - d) / i);
			for (j = j; j < k - 1; j++) {
				d = b.getVertex(j);
				i = b.getVertex(j + 1);
				g = d.distanceFrom(i);
				e.push(d);
				if (f + g > c) {
					e.push(getPartialVertex((c - f) / g, d, i));
					break
				}
				f += g
			}
			break
		}
		d += i
	}
	return new GPolyline(e, "#bb4444", 2, 0.7)
}
function shortenPolyLineByDistance(a) {
	for ( var b = drivingDistance * 1609, c = 0, d = Array(), e = 0; e < a
			.getVertexCount() - 1; e++) {
		var f = a.getVertex(e), g = a.getVertex(e + 1), h = f.distanceFrom(g);
		d.push(f);
		if (c + h > b) {
			d.push(getPartialVertex((b - c) / h, f, g));
			break
		}
		c += h
	}
	return new GPolyline(d, "#bb4444", 2, 0.7)
}
function getPartialVertex(a, b, c) {
	var d = b.lat() + a * (c.lat() - b.lat());
	a = b.lng() + a * (c.lng() - b.lng());
	return new GLatLng(d, a)
}
function redrawRoadDistCircle() {
}
function redrawBoundsPoly() {
	boundsPoly && map.removeOverlay(boundsPoly);
	if (boundsPolyPoints.length >= 3) {
		boundsPoly = new GPolygon(boundsPolyPoints, "#00ff00", 1, 1, "#00ff00",
				0.2);
		GEvent.clearInstanceListeners(boundsPoly);
		setupShapeListeners(boundsPoly);
		map.addOverlay(boundsPoly)
	}
}
function setupShapeListeners(a) {
	GEvent.addListener(a, "click", function() {
		map.closeInfoWindow()
	})
}
function redrawDrivingPathLines() {
	for ( var a = 0; a < directionsPolyLines.length; a++) {
		var b = directionsPolyLines[a];
		setupShapeListeners(b);
		map.addOverlay(b)
	}
}
function removeAllPolys() {
	boundsPoly && map.removeOverlay(boundsPoly);
	circlePoly && map.removeOverlay(circlePoly);
	for ( var a = 0; a < directionsPolyLines.length; a++)
		map.removeOverlay(directionsPolyLines[a])
}
function redrawAllPolys() {
	redrawRoadDistCircle();
	redrawBoundsPoly();
	redrawDrivingPathLines()
}
function angleComparator(a, b) {
	return getAngleToVert(drivingCircleCenter, a)
			- getAngleToVert(drivingCircleCenter, b)
}
function squared(a) {
	return Math.pow(a, 2)
}
function getAngleToVert(a, b) {
	var c = b.lat(), d = b.lng(), e = a.lat(), f = a.lng(), g = 69.172 * Math
			.abs(Math.cos(e * Math.PI / 180));
	g = Math.sqrt(squared((c - e) * 69.172) + squared((d - f) * g));
	var h = 1, i = 0;
	if (f > d) {
		h = -1;
		i = Math.PI
	}
	return i + Math.acos(h * (c - e) * 69.172 / g)
}
function redrawPolyLines() {
}
function toggleWalkscoreOverlay() {
	walkscoreOverlayEnabled() ? enableWalkscoreOverlay() : map
			.removeOverlay(walkscoreLayer)
}
function enableWalkscoreOverlay() {
	if (!walkscoreLayer) {
		var a = new GCopyrightCollection(" ");
		a.addCopyright(new GCopyright("Demo", new GLatLngBounds(new GLatLng(
				-90, -180), new GLatLng(90, 180)), 0,
				"Walk Score &copy; 2010 Front Seat"));
		a = new GTileLayer(a);
		a.getTileUrl = CustomGetTileUrl;
		a.isPng = function() {
			return true
		};
		a.getOpacity = function() {
			return 0.35
		};
		walkscoreLayer = new GTileLayerOverlay(a)
	}
	map.addOverlay(walkscoreLayer)
}
function CustomGetTileUrl(a, b) {
	return "http://tilecache.walkscore.com.s3.amazonaws.com/1.0.0/ws/" + b
			+ "/" + a.x + "/" + a.y + ".png"
}
function showStreetView(a, b) {
	myPano = new GStreetviewPanorama(document.getElementById("pano"));
	hideDiv("#infoDescriptionDiv");
	showDiv("#panoPane");
	myPano.setLocationAndPOV(new GLatLng(a, b))
}
function showWalkScore(a) {
	jq("#walkPane")
			.html(
					"<div style = 'height:300px; overflow:hidden;'><script type='text/javascript'> var ws_wsid = 'de3c2ed1a164722c4391a9f63f73d514'; var ws_address = '"
							+ a
							+ "';var ws_width = '370';var ws_height = '340';var ws_layout = 'vertical';<\/script><style type='text/css'>#ws-walkscore-tile{position:relative;text-align:left}#ws-walkscore-tile *{float:none;}#ws-footer a,#ws-footer a:link{font:11px Verdana,Arial,Helvetica,sans-serif;margin-right:6px;white-space:nowrap;padding:0;color:#000;font-weight:bold;text-decoration:none}#ws-footer a:hover{color:#777;text-decoration:none}#ws-footer a:active{color:#b14900}</style><div id='ws-walkscore-tile'></div><script type='text/javascript' src='http://www.walkscore.com/tile/show-walkscore-tile.php'><\/script></div> <div style = 'margin-top:5px; font-size:10px;'><a href='javascript:showInfo()'>Go Back to the Description</a></div>");
	hideDiv("#infoDescriptionDiv");
	showDiv("#walkPane")
}
function showInfo() {
	hideDiv("#panoPane");
	hideDiv("#walkPane");
	showDiv("#infoDescriptionDiv")
}
function addAsHidden(a) {
	var b = "?apartmentID=" + a;
	map.closeInfoWindow();
	for ( var c = 0; c < markerArray.length; c++)
		markerArray[c].value == a && map.removeOverlay(markerArray[c]);
	hideReq = GXmlHttp.create();
	hideReq.onreadystatechange = apartmentAsHiddenLoadStateChanged;
	hideReq.open("GET", "/addAsHidden.php" + b, true);
	hideReq.send(null)
}
function apartmentAsHiddenLoadStateChanged() {
}
function addAsFavorite(a) {
	hideDiv("#saveLinkDiv");
	showDiv("#savingMessage");
	for ( var b = 0; b < markerArray.length; b++) {

		if (markerArray[b] != null && markerArray[b] != 'undefined') {

			if (markerArray[b].value == a) {
				replacePointWithSeenOrFavMarker(markerArray[b], false)
			}

		}
	}

	favReq = GXmlHttp.create();
	favReq.onreadystatechange = apartmentAsFavoriteLoadStateChanged;
	favReq.open("GET", base + "/hotels/fav/add/" + a, true);
	favReq.send(null);
}

function apartmentAsFavoriteLoadStateChanged() {
	favReq.readyState == 4 && favReq.status == 200
			&& addHTMLToFavList(favReq.responseText)
}
function bounceFavoritesDiv() {
	jq("#viewFavoritesDiv").animate( {
		top : "-15px"
	}, 300).animate( {
		top : "0px"
	}, 300).animate( {
		top : "-7px"
	}, 200).animate( {
		top : "0px"
	}, 200).animate( {
		top : "-3px"
	}, 100).animate( {
		top : "0px"
	}, 100)
}
function addHTMLToFavList(a) {
	a = jq("#favoritesInnerInner").html() + a;
	jq("#favoritesInnerInner").html(a);
	hideDiv("#savingMessage");
	showDiv("#savedMessage");
	favDialogUnopened && numTimesBounced < 3 && bounceFavoritesDiv()
}
function getImage(a, b, c) {
	a %= b;
	if (a < 0)
		a = b + a;
	currImage = a;
	currNumImages = b;
	currListing = c;
	a = "?id=" + c + "&image=" + a;
	if (imagesReq)
		imagesReq.readyState != 0 && imagesReq.abort();
	else
		imagesReq = GXmlHttp.create();
	imagesReq.onreadystatechange = imageLoadStateChanged;
	imagesReq.open("GET", "/getImageUrl.php" + a, true);
	imagesReq.send(null)
}
function imageLoadStateChanged() {
	imagesReq.readyState == 4 && imagesReq.status == 200
			&& showImage(imagesReq.responseText)
}
function showSaveFavoritesDialog() {
	if (jq("#savefavoverlaydiv").hasClass("hidden")) {
		showDiv("#overlay");
		showDiv("#savefavoverlaydiv")
	}
}
function toggleFavorites() {
	favDialogUnopened = false;
	if (jq("#favoritesInner").hasClass("hidden")) {
		showDivHorizSizeChange("#favoritesInner", "#favoritesContainer");
		hideDiv("#toggleFavoritesLinkOpen");
		showDiv("#toggleFavoritesLinkClose")
	} else {
		hideDivHorizSizeChange("#favoritesInner", "#favoritesContainer");
		hideDiv("#toggleFavoritesLinkClose");
		showDiv("#toggleFavoritesLinkOpen")
	}
}
function showImage(a) {
	var b = currListing, c = currImage, d = currNumImages;
	if (jq("#overlaydiv").hasClass("hidden")) {
		showDiv("#overlay");
		showDiv("#overlaydiv")
	}
	jq("#overlaycontents")
			.html(
					'<div style = "padding: 20px;">  <div style="text-align: center; padding-bottom:15px;"><a style= "border=0px;" href = "javascript:getImage('
							+ (c - 1)
							+ ","
							+ d
							+ ","
							+ b
							+ ')"> <img class="controlArrow" title = "Previous Image" src=base + "img/leftArrow.png"/></a> <b>('
							+ (c + 1)
							+ "/"
							+ d
							+ ')</b> <a href = "javascript:getImage('
							+ (c + 1)
							+ ","
							+ d
							+ ","
							+ b
							+ ')"> <img class="controlArrow" title = "Next Image" src=base + "img/rightArrow.png"/> </a></div> <div style = "text-align: center;"><img id = "enlargedImage" class = "enlargedImg" src="'
							+ a + '"/></div></div>')
}
function openDialog(a) {
	if (aboutDialogUnopened) {
		jq("#dialog").dialog( {
			height : 600,
			width : 800,
			modal : true,
			overlay : {
				opacity : 0.5,
				background : "black"
			}
		});
		aboutDialogUnopened = false
	} else
		jq("#dialog").dialog("open");
	a = jq(a).html();
	jq("#dialog").html('<div style = "padding:20px; ">' + a + "</div>")
}
function getOuterLimits() {
	var a = getWindowLimits(), b = a.westLong - a.eastLong, c = a.northLat
			- a.southLat;
	a.northLat += 1 * c;
	a.southLat -= 1 * c;
	a.westLong += 1 * b;
	a.eastLong -= 1 * b;
	return a
}
function getWindowLimits() {
	var a = map.getBounds(), b = a.getSouthWest();
	a = a.getNorthEast();
	var c = {};
	c.northLat = a.lat();
	c.eastLong = a.lng();
	c.southLat = b.lat();
	c.westLong = b.lng();
	return c
}
function walkscoreOverlayEnabled() {
	// return document.f4.walkscoreOverlay.checked
	return false;
}
function isImagesOnly() {
	// return document.f1.imagesOnly.checked
	return false;
}
function areCatsAllowed() {
	// return document.f1.catsAllowed.checked
	return false;
}
function areDogsAllowed() {
	// return document.f1.dogsAllowed.checked
	return false;
}
function noFeeOnly() {
	return document.f1.noFee.checked
}
function subletsShown() {
	// return document.f2.subs.checked
	return false;
}
function clShown() {
	// return document.f2.cl.checked
	return false;
}
function aptsComShown() {
	// return document.f2.apts.checked
	return false;
}
function oodShown() {
	// return document.f2.ood.checked
	return false;
}
function forrentShown() {
	// return document.f2.forrent.checked
	return false;
}
function nonSubletsShown() {
	// return document.f2.nonsubs.checked
	return false;
}
function generateLink() {
	var a = "http://www.padmapper.com/" + makeGetVarsLink(), b = '<iframe width="900" height="700" frameborder="0" scrolling="no" marginheight="0" marginwidth="0" src="'
			+ a
			+ '&ver=1"></iframe><br /><small><a href="'
			+ a
			+ '" style="color:#0000FF;text-align:left">View Larger Map</a>, Powered by PadMapper <a href="http://www.padmapper.com" style="color:#0000FF;text-align:left">Apartment Search</a></small>';
	jq("#directLink").val(a);
	jq("#embedOutput").val(b);
	toggleDiv("#linkEmbedDiv");
	showDiv("#overlay")
}
function linkToListing(a) {
	jq("#listingDirectLink").val(base + 'hotels/index/' + a + "/src:link");
	toggleDiv("#listingLinkDiv");
	showDiv("#overlay")
}
function makeGetVars(a, b) {
	return makeGetVarsBase(a, b, "")
}
function makeGetVarsLink() {
	var a = getWindowLimits();
	return makeGetVarsBase(a, 0, "link")
}
function makeGetVarsBase(a, b, c) {
	var
	// d = jq("#rent_slider").slider("values", 0),
	// e = jq("#rent_slider").slider("values", 1),
	// f = jq("#ppbr_slider").slider("values", 0),
	g = jq("input[@name='rating']:checked").val();
			// h = jq("#br_slider").slider("values", 0),
			// i = jq("#br_slider").slider("values", 1),
			// j = isImagesOnly(),
			// k = areCatsAllowed(),
			// m = areDogsAllowed(),
			// o = subletsShown(),
			// p = nonSubletsShown(),
			// q = clShown(),
			r = aptsComShown(), s = oodShown(), t = forrentShown(),
			u = document.f3.favsOnly.checked,
			// v = noFeeOnly(), l = 0,
			// w = jq("#age_slider").slider("values", 0),
			x = URLEncode(searchTerms), y = map.getZoom();

	if (g == null || isNaN(g) || g < 1 || g > 10)
		g = 1;
	// if (h == null || isNaN(h) || h < 0 || h > 10)
	// h = 0;
	// if (i == null || isNaN(i) || i < 0 || i > 10)
	// i = 10;
	// if (f == null || isNaN(f) || f > 1E4 || f < 0)
	// f = 1E4;
	// if (e == null || isNaN(e) || e < 0 || e > 1E4)
	// e = 1E4;
	// if (d == null || isNaN(d) || d < 0 || d > 1E4)
	// d = 0;
	// if (l == null || isNaN(l) || l < 0 || l > 60)
	// l = 60;
	var n = "";
	n = c == "link" ? "?lat=" + (a.northLat + a.southLat) / 2 + "&lng="
			+ (a.eastLong + a.westLong) / 2 : "?eastLong=" + a.eastLong
			+ "&northLat=" + a.northLat + "&westLong=" + a.westLong
			+ "&southLat=" + a.southLat + "&cities=" + showCityClusters
			+ "&showPOI=" + showPOI + "&limit=" + b;
	n = n +
	// "&minRent=" + d +
			// "&maxRent=" + e +
			"&searchTerms=" + x +
			// "&maxPricePerBedroom=" + f +
			// "&minBR=" + h +
			// "&maxBR=" + i +
			"&minBA=" + g +
			// "&maxAge=" + w +
			// "&imagesOnly=" + j +
			// "&cats=" + k +
			// "&dogs=" + m +
			// "&noFee=" + v +
			// "&showSubs=" + o +
			// "&showNonSubs=" + p +
			// "&userId=" + userId +
			// "&cl=" + q +
			// "&apts=" + r +
			// "&ood=" + s +
			// "&forrent=" + t +
			"&zoom=" + y + "&favsOnly=" + u;

	// return n + "&workplaceLat=0&workplaceLong=0&maxTime=" + l

	return n + "&workplaceLat=0&workplaceLong=0";
}
function reloadAll() {
	showDiv("#mapUpdatingMessage");
	var a = getWindowLimits();
	a = makeGetVars(a, maxMarkers);
	immediateReq = GXmlHttp.create();
	immediateReq.onreadystatechange = reloadAllReadystateChange;
	immediateReq.open("GET", base + "hotels/reload_markers/" + a, true);
	immediateReq.send(null)
}
function updateBackend() {
	var a = getOuterLimits();
	a = makeGetVars(a, maxMarkers * 5);
	backendReq = GXmlHttp.create();
	backendReq.onreadystatechange = dragReadystateChange;
	backendReq.open("GET", base + "hotels/reload_markers/" + a, true);
	backendReq.send(null)
}
function setSearchTermsNoReload() {
	searchTerms = jq("#listingSearch").val()
}
function setSearchTerms() {
	setSearchTermsNoReload();
	reloadAll()
}
function clearSearchTerms() {
	searchTerms = "";
	jq("#listingSearch").val("Words Required In Listing");
	reloadAll()
}
function handleEnter(a) {
	if (a == "#commuteAddress" || a == "#driveCommuteAddress"
			|| a == "#goToAddress") {
		var b;
		b = a == "#commuteAddress" ? commuteCallback
				: a == "#driveCommuteAddress" ? driveCommuteCallback
						: gotoCallback;
		var c = jq(a).val();
		geocodeAdd(c, a, b)
	} else if (a == "#favlistEmailAddress")
		getEmailFromInputBoxAndSend();
	else if (a == "#alertEmailAddress")
		getEmailFromInputBoxAndSubscribeToAlerts();
	else
		a == "#listingSearch" ? setSearchTerms()
				: alert("No Recognizable input box...")
}
function getEmailFromInputBoxAndSend() {
	var a = jq("#favlistEmailAddress").val();
	saveAndEmailFavs(a, "default")
}
function getEmailFromInputBoxAndSubscribeToAlerts() {
	var a = jq("#alertEmailAddress").val(), b = jq(
			"input[name='emailFreq']:checked").val();
	subscribeToAlerts(a, b)
}

function showAllHotels(a, b, c) {
	map.setCenter(new GLatLng(a, b), 11);
	//setGeoLocation(new GLatLng(a, b));
	reloadAll()
}

function goToLatLong(a, b, c) {
	a = new GLatLng(a, b);
	map.setCenter(a, c)
}
function checkAddress(a) {
	var b;
	b = a == "#commuteAddress" ? commuteCallback
			: a == "#driveCommuteAddress" ? driveCommuteCallback : gotoCallback;
	var c = jq(a).val();
	geocodeAdd(c, a, b)
}
function goToMarker(a) {
	for ( var b, c = false, d = null, e = 0; e < activePoints.length; e++) {
		var f = activePoints[e];
		if (f.type == 1 && f.id == a) {
			c = true;
			b = activePoints[e];
			d = markerArray[e]
		}
	}
	if (!c)
		for (e = 0; e < inactivePoints.length; e++) {
			f = inactivePoints[e];
			if (f.type == 1 && f.id == a) {
				c = true;
				b = inactivePoints[e]
			}
		}
	c ? goToAndSelectMarker(b, d) : loadApartmentMarkerPoint(a)
}
function goToAndSelectMarker(a, b) {
	if (b == null) {
		var c = new GLatLng(a.lat, a.lng), d = map.getZoom();
		if (d < 14) {
			showMarkerPoint = a;
			map.setCenter(c, 14);
			return

			

		}
		map.setCenter(c, d);
		b = createMarker(c, a.id, a.type, map);
		map.addOverlay(b);
		markerArray[markerArray.length] = b;
		activePoints[activePoints.length] = a;
		c = [];
		for ( var e = d = 0; e < inactivePoints.length; e++)
			if (inactivePoints[e].id != a.id
					|| inactivePoints[e].type != a.type) {
				c[d] = inactivePoints[e];
				d++
			}
		inactivePoints = c
	}
	GEvent.trigger(b, "click");
	showMarkerPoint = null
}
function geocodeAdd(a, b, c) {
	(new GClientGeocoder).getLocations(a, function(d) {
		if (d.Status.code == 200) {
			place = d.Placemark[0];
			accuracy = place.AddressDetails.Accuracy;
			d = new GLatLng(place.Point.coordinates[1],
					place.Point.coordinates[0]);
			d.address = a
		} else
			d = null;
		c(d, accuracy)
	})
}
function commuteCallback(a) {
	var b = a.address;
	if (a) {
		map.setCenter(a, 13);
		makeBackgroundGreen("#commuteAddress");
		workplaceLat = a.lat();
		workplaceLong = a.lng();
		createAndAddWorkMarker(a, map, b);
		showDiv("#commuteSliderDiv")
	} else {
		makeBackgroundRed("#commuteAddress");
		workplaceLong = workplaceLat = 0;
		hideDiv("#commuteSliderDiv");
		removeWorkMarker(map)
	}
}
function gotoCallback(a, b) {
	var c = new Array(2, 4, 6, 10, 12, 13, 16, 16, 16);
	if (a) {
		makeBackgroundGreen("#goToAddress");
		map.setCenter(a, c[b])
	} else
		makeBackgroundRed("#goToAddress")
}
function removeCommuteFilter() {
	makeBackgroundWhite("#commuteAddress");
	hideDiv("#commuteSliderDiv");
	workplaceLong = workplaceLat = 0;
	removeWorkMarker(map);
	reloadAll()
}
function reloadAllReadystateChange() {
	if (immediateReq.readyState == 4)
		if (immediateReq.status == 200) {
			activePoints = tempPoints = eval(immediateReq.responseText);
			inactivePoints = [];
			createMarkers();
			hideDiv("#mapUpdatingMessage");
			dragUpdateMarkers();

		}
}
function removeFavorite(a) {
	jq("#fav" + a).remove();
	favMarkers[a] = null;
	for ( var b = 0; b < markerArray.length; b++)
		markerArray[b].value == a
				&& replacePointWithSeenOrFavMarker(markerArray[b], true);

	b = GXmlHttp.create();
	b.open("GET", base + "hotels/remove_favourites/" + a, true);
	b.send(null)
}
function dragReadystateChange() {
	if (backendReq.readyState == 4)
		if (backendReq.status == 200) {
			tempPoints = eval(backendReq.responseText);
			for ( var a = 0, b = 0, c = [], d = 0; d < tempPoints.length; d++) {
				for (; a < activePoints.length
						&& tempPoints[d].id < activePoints[a].id;)
					a++;
				if (a >= activePoints.length
						|| tempPoints[d].id > activePoints[a].id) {
					c[b] = tempPoints[d];
					b++
				}
			}
			inactivePoints = c;
			trimAndPromoteInactivePoints()
		}
}
function arrowToggleDiv(a, b) {
	var c;
	c = jq(a).hasClass("hidden") ? '<img class="toggleArrow" title = "Minimize" src = "' + base + 'img/minimize.png"/>'
			: '<img class="toggleArrow" title = "Unminimize" src = "' + base + 'img/maximize.png"/>';
	toggleDiv(a);
	jq(b).html(c)
}
function toggleDiv(a) {
	jq(a).hasClass("hidden") ? showDiv(a) : hideDiv(a)
}
function hideDiv(a) {
	jq(a).removeClass("shown");
	jq(a).addClass("hidden")
}
function showDiv(a) {
	jq(a).removeClass("hidden")
}
function showDivHorizSizeChange(a, b) {
	if (jq(a).hasClass("hidden")) {
		var c = jq(b).width(), d = jq(a).outerWidth();
		showDiv(a);
		jq(b).width(c + d)
	}
}
function hideDivHorizSizeChange(a, b) {
	if (!jq(a).hasClass("hidden")) {
		var c = jq(b).width(), d = jq(a).outerWidth();
		hideDiv(a);
		jq(b).width(c - d)
	}
}
function makeBackgroundGreen(a) {
	jq(a).removeClass("redBackground");
	jq(a).removeClass("whiteBackground");
	jq(a).addClass("greenBackground")
}
function makeBackgroundWhite(a) {
	jq(a).removeClass("redBackground");
	jq(a).removeClass("greenBackground");
	jq(a).addClass("whiteBackground")
}
function makeBackgroundRed(a) {
	jq(a).removeClass("whiteBackground");
	jq(a).removeClass("greenBackground");
	jq(a).addClass("redBackground")
}
function handleKeyPress(a, b) {
	makeBackgroundWhite(b);
	(a.keyCode || a.which) == 13 && handleEnter(b)
}
function showQM(a) {
	quickMailId = a;
	if (quickMailSetup)
		showQuickMail();
	else {
		showDiv("#overlay");
		showDiv("#quickMailSetup")
	}
}
function goBackToQMSetup() {
	quickMailSetup = false;
	hideDiv("#quickMail");
	showQM(quickMailId)
}
function doQuickMailSetup() {
	quickMailFrom = jq("#quickMailFrom").val();
	quickMailSignature = jq("#quickMailSignature").val();
	quickMailEmail = jq("#quickMailEmail").val();
	jq("#quickMailSetupError").html("");
	hideDiv("#quickMailSetup");
	var a = "?quickMailFrom=" + URLEncode(quickMailFrom)
			+ "&quickMailSignature=" + URLEncode(quickMailSignature)
			+ "&quickMailEmail=" + URLEncode(quickMailEmail);
	if (quickMailReq)
		quickMailReq.readyState != 0 && quickMailReq.abort();
	else
		quickMailReq = GXmlHttp.create();
	quickMailReq.onreadystatechange = quickMailSetupStateChanged;
	quickMailReq.open("GET", "/quickMailSetup.php" + a, true);
	quickMailReq.send(null)
}
function quickMailSetupStateChanged() {
	if (quickMailReq.readyState == 4)
		if (quickMailReq.status == 200) {
			var a = quickMailReq.responseText;
			if (a == "OK") {
				quickMailSetup = true;
				showQuickMail()
			} else {
				quickMailSetup = false;
				showDiv("#overlay");
				showDiv("#quickMailSetup");
				jq("#quickMailSetupError").html(a);
				showDiv("#quickMailSetupError")
			}
		}
}
function showQuickMail() {
	var a = "?quickMailFrom=" + URLEncode(quickMailFrom)
			+ "&quickMailSignature=" + URLEncode(quickMailSignature)
			+ "&quickMailEmail=" + URLEncode(quickMailEmail) + "&id="
			+ quickMailId;
	quickMailReq = GXmlHttp.create();
	quickMailReq.onreadystatechange = quickMailStateChanged;
	quickMailReq.open("GET", "/quickMail.php" + a, true);
	quickMailReq.send(null);
	showDiv("#overlay");
	jq("#quickMailContents").html('<img src="/images/throbber.gif"/>');
	showDiv("#quickMail")
}
function quickMailStateChanged() {
	if (quickMailReq.readyState == 4)
		if (quickMailReq.status == 200) {
			var a = quickMailReq.responseText;
			jq("#quickMailContents").html(a)
		}
}
function sendQuickMail() {
	var a = jq("#quickMailSubject").val(), b = jq("#quickMailBody").val();
	jq("#quickMailContents").html('<img src="/images/throbber.gif"/>');
	a = "?quickMailFrom=" + URLEncode(quickMailFrom) + "&quickMailSignature="
			+ URLEncode(quickMailSignature) + "&quickMailEmail="
			+ URLEncode(quickMailEmail) + "&quickMailSubject=" + URLEncode(a)
			+ "&quickMailBody=" + URLEncode(b) + "&id=" + quickMailId;
	quickMailReq = GXmlHttp.create();
	quickMailReq.onreadystatechange = quickMailStateChanged;
	quickMailReq.open("GET", "/quickMailSend.php" + a, true);
	quickMailReq.send(null)
}
function URLEncode(a) {
	var b = "", c = 0;
	a = a.toString();
	for ( var d = /(^[a-zA-Z0-9_.]*)/; c < a.length;) {
		var e = d.exec(a.substr(c));
		if (e != null && e.length > 1 && e[1] != "") {
			b += e[1];
			c += e[1].length
		} else {
			if (a[c] == " ")
				b += "+";
			else {
				e = a.charCodeAt(c).toString(16);
				b += "%" + (e.length < 2 ? "0" : "") + e.toUpperCase()
			}
			c++
		}
	}
	return b
}
function getInternetExplorerVersion() {
	var a = -1;
	if (navigator.appName == "Microsoft Internet Explorer")
		if (/MSIE ([0-9]{1,}[.0-9]{0,})/.exec(navigator.userAgent) != null)
			a = parseFloat(RegExp.$1);
	return a
}
function checkIEVersion() {
	if (getInternetExplorerVersion() > -1)
		isIE = true
};

function setGeoLocation(latlng) {

		geocoder.getLocations(latlng, showAddress);

}

function showAddress(response) {

	var locationString;
	var loc;

	if (!response || response.Status.code != 200) {

		alert("Status Code:" + response.Status.code);

	} else {
		
		
		
		loc = response.Placemark[0].address.split(',');
		
		var locationString = '<strong>Current Location</strong> :';
		
		var tmp = Array();
		
		for(var i =0; i<loc.length; i++){
			tmp.push('<span><a href="javascript:gotoA(\''+loc[i]+'\', '+ i +')">' +  loc[i] + '</a></span>'); 
		}
		
		tmp.reverse();
		locationString += tmp.join(' >> ');
		
		jq("#geolocation").html(locationString);
			
	}

}

function gotoA(a, z){
	
	var d;
	
	(new GClientGeocoder).getLocations(a, function(d) {
		if (d.Status.code == 200) {
			place = d.Placemark[0];
			accuracy = place.AddressDetails.Accuracy;
			d = new GLatLng(place.Point.coordinates[1],
					place.Point.coordinates[0]);
			d.address = a
		} else
			d = null;
			accuracy = 2;
		
	})
	
	var c = new Array(11, 4, 2, 1);
	
	map.setCenter(d, c[z]);
	
	setGeoLocation(d);
	
	reloadAll();
	
}
