var msgExistEmail = 'Email ƒë√£ t·ªìn t·∫°i';
var msgExistUsername = 'Username ƒë√£ t·ªìn t·∫°i';
var request;
var queryString;
var strResponse;
function httpRequestPost(frm, url, isAsynch, contentType) {
	setQueryString(frm);
	httpRequest("POST", url, true, contentType);
}
function setQueryString(frm) {
	queryString = "";
	var numberElements = frm.elements.length;
	for ( var i = 0; i < numberElements; i++) {
		if ((frm.elements[i].name == "chkItem[]") && !frm.elements[i].checked) {
			continue;
		}
		queryString += frm.elements[i].name + "="
				+ encodeURIComponent(frm.elements[i].value) + "&";
	}
	queryString = queryString.substr(0, queryString.length - 1);
}
function httpRequest(requestType, url, isAsynch, contentType) {
	if (window.XMLHttpRequest) {
		request = new XMLHttpRequest();
	} else if (window.ActiveXObject) {
		request = new ActiveXObject("Msxml2.XMLHTTP");
		if (!request) {
			request = new ActiveXObject("Microsoft.XMLHTTP");
		}
	}
	if (request.overrideMimeType) {
	}
	if (request) {
		initRequest(requestType, url, isAsynch, contentType);
		return false;
	} else {
		return true;
	}
}
var p_ = "modules/map/e_map/";
var ext = '.jpg';
function initRequest(requestType, url, isAsynch, contentType) {
	request.open(requestType, url, isAsynch);
	request.onreadystatechange = function() {
		if (request.readyState == 4) {
			if (request.status == 200) {
				if (contentType.length != 0) {
					document.getElementById(contentType).innerHTML = request.responseText;
				} else {
					strResponse = request.responseText;
				}
				document.getElementById("loading").style.display = "none";
			} else {
				alert("loi");
			}
		} else {
			document.getElementById("loading").style.display = "";
		}
	};
	if (requestType == "GET") {
		request.send(null);
	} else {
		request.setRequestHeader("Content-Type",
				"application/x-www-form-urlencoded; charset=UTF-8");
		request.send(queryString);
	}
}
function showResult(blockId, content) {
	if (document.getElementById(blockId)) {
		document.getElementById(blockId).innerHTML = content;
	}
}

function showHidePanel(panel_id) {
	var panel = document.getElementById(panel_id);
	if (panel.style.display == '') {
		panel.style.display = 'none';
	} else {
		panel.style.display = '';
	}
}

function replaceString(str, needle, replace_by) {
	if (str.length > 0) {
		while (str.search(needle) != -1) {
			str = str.replace(needle, replace_by);
		}
	}
	return str;
}
function init_dimensions() {
	$(document).ready(function() {
		var containerWidth = $('#container').innerWidth();
		var columnLeftWidth = $('#column_left').innerWidth();
		if ($.browser.msie) {
			mapWidth = containerWidth - columnLeftWidth - 5;
		} else {
			mapWidth = containerWidth - columnLeftWidth - 20;
			$('#side_bar').width($('#side_bar').width() + 8);
		}
		var window_height = $(window).height();
		var headerHeight = $('#categories').height();
		if ($.browser.msie) {
			mapHeight = window_height - headerHeight - 15;
		} else {
			mapHeight = window_height - headerHeight - 10;
		}
		$('#map').width(mapWidth);
		$('#map').height(mapHeight);
		$("#loading").css("top", window_height / 2 + "px");
		$("#loading").css("left" + containerWidth / 2 + "px");
		var contentLeftHeight = mapHeight;
		$('#personal').height(contentLeftHeight - $('.tab').height() - 10);
		$('#side_bar').height(contentLeftHeight - $('.tab').height() - 10);
		rsRowsPerPage = Math.floor((mapHeight - 20) / rsItemHeight - 3);
		$('#tab_search').click(function() {
			$('#personal').hide();
			$('#side_bar').show();
			inPublicMap = true;
			//loadMarkers(0);
		});
		$('#tab_personal').click(function() {
			onPersonalTabClick(currentMapUserId);
		});
	});
	$("#loading").ajaxStart(function() {
		$(this).show();
	});
	$("#loading").ajaxComplete(function() {
		$(this).hide();
	});
}
function onPersonalTabClick(user_id) {
	inPublicMap = false;
	$('#side_bar').hide();
	$('#personal').show();
	var responseContent = $.ajax( {
		type : "GET",
		async : false,
		url : "modules/map/action.php?param=get_user_panel&user_id=" + user_id,
		dataType : "html"
	}).responseText;
	var loginForm = document.getElementById("form_login");
	if (currentMapUserId != 0
			|| (responseContent.search("%emicesoft-separate%") != -1)) {
		if (responseContent.search("%emicesoft-separate%") != -1) {
			var aryResponseContent = responseContent
					.split("%emicesoft-separate%");
			loginForm.innerHTML = aryResponseContent[0];
			userLoginedId = parseInt(aryResponseContent[1], 10);
			//loadMarkers(user_id);
			personalBlockEvent();
		} else {
			loginForm.innerHTML = responseContent;
			//loadMarkers(user_id);
			personalBlockEvent();
		}
	} else {
		loginForm.innerHTML = responseContent;
	}
}
var mapHeight;
var mapWidth;
var rsRowsPerPage;
var rsItemHeight = 23;
var centreLat = 21.030513401775398;
var centreLon = 105.81726551055908;
var initialZoom = 15;
var map;
var gmarkers = [];
var side_bar_html = "<ul>";
var contextmenu;
var myPoint;
var addSucces = false;
var newMarker;
var loadedFlag = false;
var userLoginedId = 0;
var inPublicMap = true;
var currentMapUserId = 0;
var currentSharePlace;
var isRated = 0;
var clickedPixel;
var drawingPolyLine = false;
var aryPolyLinePoint = [];
var aryPolyLinePointCount = 0;
function c(a, b) {
	var d = a.x;
	var e = a.y;
	var f = "t";
	var c = Math.pow(2, b);
	for (g = 0; g < b; g++) {
		c = c / 2;
		if (e < c) {
			if (d < c) {
				f += "q";
			} else {
				f += "r";
				d -= c;
			}
		} else {
			if (d < c) {
				f += "t";
				e -= c;
			} else {
				f += "s";
				d -= c;
				e -= c;
			}
		}
	}
	return p_ + f + ext;
}
function getWindowHeight() {
	if (window.self && self.innerHeight) {
		return self.innerHeight;
	}
	if (document.documentElement && document.documentElement.clientHeight) {
		return document.documentElement.clientHeight;
	}
	return 0;
}
function resizeMapDiv() {
	var d = document.getElementById("map");
	var offsetTop = 0;
	for ( var elem = d; elem != null; elem = elem.offsetParent) {
		offsetTop += elem.offsetTop;
	}
	var height = getWindowHeight() - offsetTop - 16;
	if (height >= 0) {
		d.style.height = height + "px";
		$("#side_bar").height(height - $('.tab').height() - 10);
		$("#personal").height(height - $('.tab').height() - 10);
	}
}
function load() {
	buildSideBar();
	if (GBrowserIsCompatible()) {
		var copyright = new GCopyright(1, new GLatLngBounds(new GLatLng(-90,
				-180), new GLatLng(90, 180)), 0,
				"<a href=\"http://www.bandoso.com\">E.Map</a>");
		/*var pic_tileLayers = [ new GTileLayer(new GCopyrightCollection(
				"Emice Software Solutions"), 0, 3) ];
		pic_tileLayers[0].getTileUrl = c;
		pic_tileLayers[0].isPng = function() {
			return false;
		};
		pic_tileLayers[0].getOpacity = function() {
			return 1.0;
		};
		var pic_customMap = new GMapType(pic_tileLayers,
				new GMercatorProjection(7), "Pic", {
					maxResolution : 6,
					minResolution : 2,
					errorMessage : "Ko co du lieu"
				});
		
		map = new GMap2(document.getElementById("map"), {
			mapTypes : [ pic_customMap ]
		});*/
		map = new google.maps.Map2(document.getElementById("map"));
		map.addControl(new GLargeMapControl());
		map.addControl(new GMapTypeControl());
		
		map.enableDoubleClickZoom();
		map.enableContinuousZoom();
		map.enableScrollWheelZoom();
		/*map.setCenter(new GLatLng(centreLat, centreLon), initialZoom,
				pic_customMap);*/
		map.setCenter(new GLatLng(centreLat, centreLon), initialZoom);
        map.setUIToDefault();
		contextmenu = document.createElement("div");
		contextmenu.style.visibility = "hidden";
		contextmenu.style.background = "#ffffff";
		contextmenu.style.border = "1px solid #999999";
		contextmenu.className = "contextMenu";
		map.getContainer().appendChild(contextmenu);
		GEvent.addListener(map, "singlerightclick",function(pixel, tile) {
							clickedPixel = pixel;
							var x = pixel.x;
							var y = pixel.y;
							var add_item = '';
							//alert('Current Map User ID' + currentMapUserId);
							
							//if (currentMapUserId == userLoginedId && userLoginedId != 0 && !inPublicMap) {
								add_item = '<a href="javascript:showAddForm()"><div class="context">&nbsp;&nbsp;Add marker&nbsp;&nbsp;</div></a>';
								add_item += '<a href="javascript:drawPolyLine()"><div class="context">&nbsp;&nbsp;Add Poly line&nbsp;&nbsp;</div></a>';
								if (drawingPolyLine) {
									add_item += '<a href="javascript:savePolyLine()"><div class="context">&nbsp;&nbsp;Save Poly line&nbsp;&nbsp;</div></a>';
								}
							//}
							contextmenu.innerHTML = add_item
									+ '<a href="javascript:zoomIn()"><div class="context">&nbsp;&nbsp;Zoom in&nbsp;&nbsp;</div></a>'
									+ '<a href="javascript:zoomOut()"><div class="context">&nbsp;&nbsp;Zoom out&nbsp;&nbsp;</div></a>'
									+ '<a href="javascript:zoomInHere()"><div class="context">&nbsp;&nbsp;Zoom in here&nbsp;&nbsp;</div></a>'
									+ '<a href="javascript:zoomOutHere()"><div class="context">&nbsp;&nbsp;Zoom out here&nbsp;&nbsp;</div></a>'
									+ '<a href="javascript:centreMapHere()"><div class="context">&nbsp;&nbsp;Centre map here&nbsp;&nbsp;</div></a>';
							if (x > map.getSize().width - 120) {
								x = map.getSize().width - 120
							}
							if (y > map.getSize().height - 100) {
								y = map.getSize().height - 100
							}
							var pos = new GControlPosition(G_ANCHOR_TOP_LEFT,
									new GSize(x, y));
							pos.apply(contextmenu);
							contextmenu.style.visibility = "visible";
						});
		GEvent.addListener(map, "click", function(overlay, point) {
			contextmenu.style.visibility = "hidden";
			closeFriendsListContextMenu();
		});
	}
loadMarkers(18);	
}
function loadMarkers(user_id) {
	map.clearOverlays();
			var xml = $.ajax( {
				type : "GET",
				async : false,
				url : "modules/map/xml_marker.php?uid=" + user_id,
				dataType : "xml"
			}).responseXML;
			xmlToPlace(xml);
}
function clickMarker(id) {
	if (!gmarkers[id]) {
		var xml = $.ajax( {
			type : "GET",
			async : false,
			url : "modules/map/xml_marker.php?id=" + id,
			dataType : "xml"
		}).responseXML;
		xmlToPlace(xml);
	}
	gmarkers[id].openInfoWindowHtml(getInfoWindowHTML(id));
}
function buildSideBar() {
	var sideBarHtml = $.ajax( {
		type : "GET",
		async : false,
		url : "modules/map/action.php?param=sidebar",
		dataType : "html"
	}).responseText;
	$("#side_bar").html(sideBarHtml);
}
function xmlToPlace(xml) {
	var markers = xml.documentElement.getElementsByTagName("marker");
	for ( var i = 0; i < markers.length; i++) {
		var id = markers[i].getAttribute("id");
		var name = markers[i].getAttribute("name");
		var address = markers[i].getAttribute("description");
		var isPublic = markers[i].getAttribute("public");
		var image = markers[i].getAttribute("image");
		var isRated = markers[i].getAttribute("rated");
		var point = new GLatLng(parseFloat(markers[i].getAttribute("lat")),
				parseFloat(markers[i].getAttribute("lng")));
		var icon;
		var marker = createMarker(point, icon, id);
		map.addOverlay(marker);
		gmarkers[id] = marker;
	}
}
function drawPolyLine() {
	contextmenu.style.visibility = "hidden";
	aryPolyLinePointCount++;
}
function savePolyLine() {
	aryPolyLinePointCount = 0;
	showPolyLine();
}
function showPolyLine() {
}
function zoomIn() {
	//alert('123');
	map.zoomIn();
	contextmenu.style.visibility = "hidden";
}
function zoomOut() {
	map.zoomOut();
	contextmenu.style.visibility = "hidden";
}
function zoomInHere() {
	var point = map.fromContainerPixelToLatLng(clickedPixel);
	map.zoomIn(point, true);
	contextmenu.style.visibility = "hidden";
}
function zoomOutHere() {
	var point = map.fromContainerPixelToLatLng(clickedPixel);
	map.setCenter(point, map.getZoom() - 1);
	contextmenu.style.visibility = "hidden";
}
function centreMapHere() {
	var point = map.fromContainerPixelToLatLng(clickedPixel);
	map.setCenter(point);
	contextmenu.style.visibility = "hidden";
}
function createMarker(point, myIcon, id) {
	var marker = new GMarker(point, {
		icon : myIcon,
		draggable : true
	});
	GEvent.addListener(marker, 'click', function() {
		map.setCenter(point, initialZoom);
		marker.openInfoWindowHtml(getInfoWindowHTML(id));
		if (parseInt(isRated, 10) == 0) {
			$('#star1').rating('modules/map/action.php?param=rate&id=' + id, {
				maxvalue : 5,
				curvalue : 0,
				id : id
			});
		}
	});
	GEvent.addListener(marker, 'dragend', function() {
		var new_point = marker.getPoint();
		httpRequest('GET', 'modules/map/action.php?param=update_point&id=' + id
				+ '&lng=' + new_point.x + '&lat=' + new_point.y, true, '')
	});
	return marker;
}
function getInfoWindowHTML(id) {
	var infoWindow = $.ajax( {
		type : "GET",
		async : false,
		url : "modules/map/action.php?param=get_info_window&id=" + id,
		dataType : "html"
	}).responseText;
	var aryInfo = new Array();
	aryInfo = infoWindow.split('%emicesoft-separate%');
	var name = aryInfo[0];
	var avg_stars = (aryInfo[1] > 0) ? aryInfo[1] : 0;
	var total_rates = (aryInfo[2] > 0) ? aryInfo[2] : 0;
	isRated = (aryInfo[5] > 0) ? aryInfo[5] : 0;
	var str_stars = '<div id="rated_star_container">';
	for (i = 0; i < parseInt(avg_stars, 10); i++) {
		str_stars += '<div class="rated_star"></div>';
	}
	for (i = 0; i < 5 - parseInt(avg_stars, 10); i++) {
		str_stars += '<div class="unrated_star"></div>';
	}
	str_stars += '(' + total_rates + ' rates)</div>';
	var description = replaceString(aryInfo[3], '&lt;br /&gt;', '<br />');
	description = replaceString(description, '&lt;', '<');
	description = replaceString(description, '&gt;', '>');
	var isPublic = aryInfo[4];
	var html = '<div id="my_info_window"><div id="my_info_window_title">'
			+ name
			+ "</div><div>"
			+ str_stars
			+ '</div><div id="info_window_description">'
			+ description
			+ '</div><div id="star1" class="rating">&nbsp;</div><div id="action_link_container">';
	if ((userLoginedId == currentMapUserId) && userLoginedId != 0
			&& !inPublicMap) {
		html += '<span class="markerActionLink" onclick="return editMarker('
				+ id
				+ ')">Edit</span>'
				+ ' &nbsp;<span class="markerActionLink" onclick="return deleteMarker('
				+ id + ')">Delete</span>&nbsp;&nbsp;';
	}
	if (userLoginedId != 0) {
		html += '<span class="markerActionLink" onclick="return onShareLinkClick(' + id + ')">Share</span>&nbsp;&nbsp;'
	}
	if ((userLoginedId != 0) && (currentMapUserId == userLoginedId)
			&& (isPublic == 0)) {
		html += '<span class="markerActionLink" onclick="return publicThisPlace(' + id + ')">Public</span>&nbsp;&nbsp;'
	}
	return html + '</div></div>'
}
function myclick(i) {
	GEvent.trigger(gmarkers[i], "click");
}
function insertMarker(frm, url) {
	httpRequestPost(frm, url, false, '');
	var htmlPlaces = $.ajax( {
		type : "GET",
		async : false,
		url : "modules/map/action.php?param=refresh_places_list&user_id="
				+ userLoginedId,
		dataType : "html",
		data : queryString
	}).responseText;
	var friendsListContainer = document.getElementById("my_place");
	friendsListContainer.innerHTML = htmlPlaces;
	map.closeInfoWindow();
	//loadMarkers(currentMapUserId);
}
function showAddForm() {
	//alert('123');
	var responseContent = $.ajax( {
		type : "GET",
		async : false,
		url : "modules/map/action.php?param=check_login",
		dataType : "html"
	}).responseText;
	if (responseContent == 'please_login') {
		var point = map.fromContainerPixelToLatLng(clickedPixel);
		newMarker = new GMarker(point);
		map.addOverlay(newMarker);
		var html = '<div>Please login</div>';
		newMarker.openInfoWindowHtml(html);
		contextmenu.style.visibility = "hidden";
		GEvent.addListener(newMarker, 'infowindowclose', function() {
			newMarker.remove();
		});
	} else {
		var point = map.fromContainerPixelToLatLng(clickedPixel);
		newMarker = new GMarker(point);
		map.addOverlay(newMarker);
		var html = '<div id="my_info_window"><div id="my_info_window_title">Add Place</div><div id="my_info_window_title"><form name="markers" id="markers" action="javascript:void%200" method="post" onsubmit="' + " return insertMarker(this,'modules/map/action.php?param=insert_marker') " + ';"><input name="lat" type="hidden" id="lat" value="' + point.y + '"/><input name="lng" id="lng"  type="hidden"  value="' + point.x + '"/><label for="lng">Name</label><input name="name" id="name" size="35"/><label>Description</label><textarea name="description" id="description" style="width:100%" rows="10"></textarea><div id="cat_marker"></div><div><input id="public" type="checkbox" name="public" />Public</div><input type="submit" value="Add" style="width:80px; height:22px;"/></form></div></div>';
		newMarker.openInfoWindowHtml(html);
		contextmenu.style.visibility = "hidden";
		httpRequest('GET', 'modules/map/action.php?param=get_cat_tree', true,'cat_marker');
		GEvent.addListener(newMarker, 'infowindowclose', function() {
			newMarker.remove();
		});
	}
	//alert('456');
}
function editMarker(id) {
	var myMarker = gmarkers[id];
	var responseContent = $.ajax( {
		type : "GET",
		async : false,
		url : 'modules/map/action.php?param=get_edit_form&id=' + id,
		dataType : "html"
	}).responseText;
	myMarker
			.openInfoWindowHtml('<div id="my_info_window">' + responseContent + '</div>');
}
function deleteMarker(id) {
	if (confirm('Are you sure?')) {
		httpRequest('GET',
				'modules/map/action.php?param=delete_marker&id=' + id, true, '');
		myMarker = gmarkers[id];
		map.closeInfoWindow();
		myMarker.remove();
	}
}
function openEditor() {
	tinyMCE.init( {
		theme : "simple",
		mode : "exact",
		elements : "description"
	});
}
function markerSuggest(myTextbox, mySelect) {
	var keyword = myTextbox.value;
	var cat_id = mySelect.options[mySelect.selectedIndex].value;
	var url = 'modules/map/action.php?param=marker_suggest&keyword=' + keyword
			+ '&cat_id=' + cat_id;
	document.getElementById('marker_suggest_container').style.display = '';
	httpRequest('GET', url, true, 'marker_suggest_container');
}
function suggestSelect(element) {
	var keyword = element.innerHTML;
	document.getElementById('txtSearch').value = keyword;
	closeSuggest();
	return false;
}
function searchLocation(frm) {
	var url = 'modules/map/action.php?param=search_location';
	httpRequestPost(frm, url, true, 'map_search_result');
	$('#map_search_result').height($('#map').height() - 40);
	$('#map_search_result_header').show();
	$("#map_search_result").slideDown("slow");
	$('#search_result_control').html('[-]');
}
function searchPersonalLocation(frm, uid) {
	var url = 'modules/map/action.php?param=search_location&uid=' + uid;
	httpRequestPost(frm, url, true, 'my_place');
}
function closeSuggest() {
	var suggestContainer = document.getElementById('marker_suggest_container');
	suggestContainer.innerHTML = '';
	suggestContainer.style.display = 'none';
}
function addMarkerChangeCat(mySelect, newMarker) {
}
function showRegistrationForm() {
	var htmlRegForm = $.ajax( {
		type : "GET",
		async : false,
		url : "modules/map/action.php?param=get_register_form",
		dataType : "html"
	}).responseText;
	$("#form_login").html(htmlRegForm);
	var validator = $("#form_register").validate( {
		submitHandler : function(form) {
			userRegister(form);
		}
	});
}
function userRegister(frm) {
	setQueryString(frm);
	var successfulMsg = 'Ch√∫c m·ª´ng! B·∫°n ƒë√£ l√† th√†nh vi√™n c·ªßa B·∫£n ƒê·ªì S·ªë';
	var unsuccessfulMsg = 'B·∫°n vui l√≤ng ki·ªÉm tra l·∫°i th√¥ng tin ƒëƒÉng k√≠!';
	var responseContent = $.ajax( {
		type : "POST",
		async : false,
		url : "modules/map/action.php?param=user_register",
		dataType : "html",
		data : queryString
	}).responseText;
	var personalMessage = document.getElementById("personal_message");
	if (responseContent == 'register_ok') {
		personalMessage.innerHTML = successfulMsg;
		setTimeout('$("#personal_message").hide("slow");getUserPanel();', 5000);
	}
}
function getUserPanel() {
	var responseContent = $.ajax( {
		type : "POST",
		async : false,
		url : "modules/map/action.php?param=get_user_panel",
		dataType : "html",
		data : queryString
	}).responseText;
	var userPanel = document.getElementById("form_login");
	var aryResponseContent = responseContent.split("%emicesoft-separate%");
	userPanel.innerHTML = aryResponseContent[0];
	userId = parseInt(aryResponseContent[1]);
}
function userLogin(frm) {
	setQueryString(frm);
	var successfulMsg = 'Ch√∫c m·ª´ng! B·∫°n ƒë√£ ƒëƒÉng nh·∫≠p th√†nh c√¥ng !';
	var unsuccessfulMsg = 'B·∫°n vui l√≤ng ki·ªÉm tra l·∫°i th√¥ng tin ƒëƒÉng nh·∫≠p !';
	var responseContent = '';
	responseContent = $.ajax( {
		type : "POST",
		async : false,
		url : "modules/map/action.php?param=user_login",
		dataType : "html",
		data : queryString
	}).responseText;
	var personalMessage = document.getElementById("personal_message");
	if (responseContent != 'login_fail') {
		personalMessage.innerHTML = successfulMsg;
		$("#personal_message").show("slow");
		setTimeout('$("#personal_message").hide("slow");', 5000);
		var userPanel = document.getElementById("form_login");
		var aryResponseContent = responseContent.split("%emicesoft-separate%");
		userPanel.innerHTML = aryResponseContent[0];
		userLoginedId = parseInt(aryResponseContent[1], 10);
		currentMapUserId = userLoginedId;
		//alert(currentMapUserId);
		//loadMarkers(userLoginedId);
		personalBlockEvent();
	} else {
		personalMessage.innerHTML = unsuccessfulMsg;
		$("#personal_message").show("slow");
		setTimeout('$("#personal_message").hide("slow");', 5000);
	}
}
function personalBlockEvent() {
	$("#my_marker_block_header")
			.click(
					function() {
						if ($("#my_marker_block_content").css("display") == "none") {
							$("#my_marker_block_header").css(
									"background-image",
									"url(images/opentriangle.gif)");
							$("#my_place")
									.height($("#side_bar").height() - 200);
							$("#my_marker_block_content").show();
							$("#friends_list_block_content").hide();
						} else {
							$("#my_marker_block_header").css(
									"background-image",
									"url(images/triangle.gif)");
							$("#my_marker_block_content").hide();
							$("#my_friends_list").height(
									$("#side_bar").height() - 170);
							$("#friends_list_block_content").show();
						}
					});
	$("#friends_list_block_header")
			.click(
					function() {
						if ($("#friends_list_block_content").css("display") == "none") {
							$("#my_marker_block_header").css(
									"background-image",
									"url(images/opentriangle.gif)");
							$("#my_friends_list").height(
									$("#side_bar").height() - 170);
							$("#friends_list_block_content").show();
							if ((userLoginedId = currentMapUserId) != 0) {
								$(".add_new_friends").show();
							}
							$("#my_marker_block_content").hide();
						} else {
							$("#my_marker_block_header").css(
									"background-image",
									"url(images/triangle.gif)");
							$("#friends_list_block_content").hide();
							$("#my_place")
									.height($("#side_bar").height() - 200);
							$("#my_marker_block_content").show();
						}
					});
}
function changeToFriendMap(friend_id) {
	currentMapUserId = friend_id;
	onPersonalTabClick(friend_id);
}
function gotoPlace(friend_id, id) {
	currentMapUserId = friend_id;
	onPersonalTabClick(friend_id);
	clickMarker(id);
}
function showAddFriendsForm() {
	var html = '<div style="width: 100%; margin-bottom:5px; height: 22px; background-color:#D5EBFF; border-bottom: 1px solid #6D90B0;"><span class="actionLink">Close <img src="images/map/close_small.gif" align="absmiddle" /></span></div><form name="search_to_add" action="javascript:void%200" style="padding-left: 5px;" onsubmit="return searchFriendsToAdd(this);"><input type="text" name="keyword" style="width:220px;" /><input type="submit" value="Search" /></form><form name="add_to_friend_list" action="javascript:void%200" onsubmit="return addToFriendsList(this);"><div id="friends_list_search_result"><div style="margin-top: 30px;">H√£y nh·∫≠p t√™n c·ªßa ng∆∞·ªùi mu·ªën add v√† t√¨m ki·∫øm. <br/> N·∫øu kh√¥ng nh·ªõ ch√≠nh x√°c, b·∫°n c√≥ th·ªÉ nh·∫≠p m·ªôt ph·∫ßn c·ªßa t√™n.</div></div></form>';
	var div = document.getElementById("block_add_to_friends_list");
	div.innerHTML = html;
	$("#block_add_to_friends_list").show();
	$(".actionLink").click(function() {
		hideAddFriendsForm();
	});
}
function hideAddFriendsForm() {
	$("#block_add_to_friends_list").hide();
}
function searchFriendsToAdd(frm) {
	setQueryString(frm);
	var responseContent = $.ajax( {
		type : "POST",
		async : false,
		url : "modules/map/action.php?param=search_friends_to_add&user_id="
				+ userLoginedId,
		dataType : "html",
		data : queryString
	}).responseText;
	var searchResultContainer = document
			.getElementById('friends_list_search_result');
	searchResultContainer.innerHTML = responseContent;
}
function addToFriendsList(frm) {
	setQueryString(frm);
	var responseContent = $.ajax( {
		type : "POST",
		async : false,
		url : "modules/map/action.php?param=add_to_friends_list",
		dataType : "html",
		data : queryString
	}).responseText;
	$('#block_add_to_friends_list').hide();
	var htmlFriendsList = $.ajax( {
		type : "GET",
		async : false,
		url : "modules/map/action.php?param=refresh_friend_list&user_id="
				+ userLoginedId,
		dataType : "html"
	}).responseText;
	var friendsListContainer = document.getElementById("my_friends_list");
	friendsListContainer.innerHTML = htmlFriendsList;
}
function friendsListContextMenu(evt, user_id) {
	evt = (evt) ? evt : ((event) ? event : null);
	var html = '<a class="context_menu_link" href="javascript:changeToFriendMap('
			+ user_id
			+ ')"><div class="context">&nbsp;&nbsp;Go to  map</div></a>'
			+ '<a class="context_menu_link" href="javascript:openChatWindow('
			+ user_id
			+ ')"><div class="context">&nbsp;&nbsp;Chat&nbsp;&nbsp;(Coming soon !)</div></a>'
			+ '<a class="context_menu_link" href="javascript:deleteFromFriendsList('
			+ user_id + ')"><div class="context">&nbsp;&nbsp;Delete</div></a>';
	var div = document.getElementById("friends_list_context_menu_content");
	div.innerHTML = html;
	$("#friends_list_context_menu").css("top", evt.clientY + "px");
	$("#friends_list_context_menu").css("left", evt.clientX + "px");
	$("#friends_list_context_menu").show();
	$(".context_menu_link").click(function() {
		closeFriendsListContextMenu();
	});
}
function closeFriendsListContextMenu() {
	$("#friends_list_context_menu").hide();
}
function onShareLinkClick(place_id) {
	var title = document.getElementById("my_info_window_title");
	var responseContent = $.ajax( {
		type : "GET",
		async : false,
		url : "modules/map/action.php?param=search_friends_to_share&user_id="
				+ userLoginedId + "&id=" + place_id,
		dataType : "html"
	}).responseText;
	gmarkers[place_id]
			.openInfoWindowHtml('<div id="my_info_window"><div id="my_info_window_title">'
					+ title.innerHTML + '</div>' + responseContent + '</div>');
	currentSharePlace = place_id;
}
function shareThisPlace(frm) {
	setQueryString(frm);
	$.ajax( {
		type : "POST",
		async : false,
		url : "modules/map/action.php?param=share_this_place",
		dataType : "html",
		data : queryString
	});
	clickMarker(currentSharePlace);
}
function onNewMessageLinkClick(message_id) {
	var str = '';
	if (parseInt(message_id, 10) != 0) {
		str = '&message_id=' + message_id;
	}
	var responseContent = $.ajax( {
		type : "GET",
		async : false,
		url : "modules/map/action.php?param=get_share_message" + str,
		dataType : "html"
	}).responseText;
	var point = new GPoint(parseInt(mapWidth / 2), parseInt(mapHeight / 4) * 3);
	point = map.fromContainerPixelToLatLng(point);
	newMarker = new GMarker(point);
	map.addOverlay(newMarker);
	var html = '<div id="my_info_window">' + responseContent + '</div>';
	newMarker.openInfoWindowHtml(html);
	GEvent.addListener(newMarker, 'infowindowclose', function() {
		newMarker.remove();
	});
}
function publicThisPlace(id) {
	var responseContent = $.ajax( {
		type : "GET",
		async : false,
		url : "modules/map/action.php?param=public_this_place&id=" + id,
		dataType : "html"
	}).responseText;
	clickMarker(id);
}
function showPlacesByCat(cat_id, page) {
	var responseContent = $.ajax( {
		type : "GET",
		async : false,
		url : "modules/map/action.php?param=get_by_cat&cid=" + cat_id + '&rpp='
				+ rsRowsPerPage + '&p=' + page,
		dataType : "html"
	}).responseText;
	$('#map_search_result_header').show();
	$('#map_search_result').height($('#map').height() - 40);
	$("#map_search_result").slideDown("slow");
	$("#map_search_result").html(responseContent);
}
function collapseSearchResult() {
	if ($("#map_search_result").is(":hidden")) {
		$("#map_search_result").slideDown("slow");
		$('#search_result_control').html('[-]');
	} else {
		$("#map_search_result").hide();
		$('#search_result_control').html('[+]');
	}
}
function changeUserType(userTypeSelect) {
	var optionValue = userTypeSelect.options[userTypeSelect.selectedIndex].value;
	if (optionValue == 'personal') {
		$('#birdthday').show();
		$('#company_info').hide();
	} else {
		$('#birdthday').hide();
		$('#company_info').show();
	}
}
function fastURL(url, isAsync, block_to_update) {
	url = url.substring(url.indexOf('module'));
	var pattern = /module=(\w+)&action=(\w+)[&\s]/;
	var fastURL = url.replace(pattern, "modules/$1/$2.php?");
	if (fastURL.indexOf('aj=false') != -1) {
		fastURL = fastURL.replace('aj=false', "aj=true");
	} else {
		fastURL += '&aj=true';
	}
	httpRequest('GET', fastURL, true, block_to_update);
	return false;
}
