
// display "Downloading Map Data...."
// start ajax download of the map JSON.
// when finished, display "Processing Map Data..."



function handleAjaxResponse( response, caller ) {
	
	var GDEBUG = 1;
	
	
	if (response.error == 0) {
		return;
	}
	if (response.error == 5) {
		location.href = 'ucp.php?mode=login';
	}
	else if (response.error == 10) {
		$.unblockUI();
		//handle SQL error.
		if ( GDEBUG == 1 ) {
			infoDialog(response.errorMsg);			
		}
		else {
			// nice way of handling this for the user.
		}
	}
	else {
		//need nicer way of handling this for user.
		$.unblockUI();
		infoDialog(response.errorMsg  + "\n Error occured in " + caller);
	}	
}


function cancelReasonDialog(title, confirmFn) {
	$('<div></div>')
	.attr('title',title)
	.html("Please give " + $('div#userlink.data a').html() + 
		  " a reason for cancelling your game:" +
		  "<br /><br />" + 
		  "<textarea id='cancelReason' style='height: 50px; width: 270px;'></textarea>")
	.dialog({ buttons: { 
			"Cancel the Game": 
			function() { 
			confirmFn();
			$(this).dialog("close"); 

			},
			"Go Back": function() { $(this).dialog("close"); }, } 
			});
}


function confirmDialog(title, confirmFn) {
	$('<div></div>')
	.attr('title',title)
	.html("Are you sure you want to perform this action?")
	.dialog({ buttons: { 
			"Continue": function() { $(this).dialog("close"); confirmFn(); },
			"Go Back": function() { $(this).dialog("close"); }, } 
			});
}

function infoDialog(msg) {
	$('<div></div>')
	.html(msg)
	.dialog({ buttons: { 
			"OK": function() { $(this).dialog("close"); }
			} 
			});
}


function my_block(msg) {
	
	$.blockUI({ message:'<div id="blockUIMessage">' + msg + '</div>', css: { 
			  border: 'none', 
			  padding: '15px', 
			  backgroundColor: '#000', 
			  '-webkit-border-radius': '10px', 
			  '-moz-border-radius': '10px', 
			  font: 'normal 30px/.5 "Trebuchet MS", Arial, Helvetica, sans-serif',
			  opacity: .5, 
			  color: '#fff' 
			  } }); 
	
	
}

function unblockAndLoad() {
	$.unblockUI();
	loadMap();
}

function showEventList() {
	//alert("trying to show event list");
	
	map.closeInfoWindow();
	
	map.setCenter(userLatLng, 14);
	
	
	
	//animate map contraction
	$('#map').css('width', '631px');
	//$('#map').effect("size", {to: {width: 631} }, 1000);
	
	
	map.checkResize();
	
	$('#eventList').css('display', '');
	//empty, so we don't end up writing over and over the same list.
	$('#eventListScroller').empty();
	$('#forumsDisplayScroller').empty();
	
	
	gradius = $('#gamesearch_radius').val();
	gshow = $('#gamesearch_show').val();
	
	////'gamesearch_radius': "10", 'gamesearch_radius': "ALL"
///	alert("yes, you actually ran showeventlist() with " + gradius + "&" + gshow);

	/* get fresh event list from ajax... */
	my_block("Loading data...");
	
	/*
	$.get('ajax_logged_in_check.php', {  }, function(data) {
		 
		  var response = $.parseJSON(data);
		  if (typeof(response) == "undefined") {
		  alert("Error while performing Login Check");
		  }		  
		  else if (response.error == 5) {
		  location.href = 'ucp.php?mode=login';
		  }		   
		  
		  });
	 
	 */
		
	
	var fnName = arguments.callee.name;
	
	$.get('games.php', { 'gamesearch_radius': gradius, 'gamesearch_show': gshow }, function(data) {
		  $.unblockUI();

		  var response = $.parseJSON(data);
		  if (typeof(response) == "undefined") {
		  alert(data);
		  }		  
		  else if (response.error == 0) {
		  // inject data into the eventlist div.
	//	  alert(response.html);
		   $('#eventListScroller').append(response.html);
		//  return;
		  }
		  else if (response.error == 5) {
		  location.href = 'ucp.php?mode=login';
		  }
		  else {
		  alert(response.errorMsg);
		  }
		  
		  
		  });
	
	
	$.get('ajax_forums_display.php', { }, function(data) {
		  $.unblockUI();
		  
		  var response = $.parseJSON(data);
		  if (typeof(response) == "undefined") {
		  alert(data);
		  }		  
		  else if (response.error == 0) {
		  // inject data into the eventlist div.
		//  alert(response.html);
		  $('#forumsDisplayScroller').append(response.html);
		  return;
		  }
		  else if (response.error == 5) {
		  location.href = 'ucp.php?mode=login';
		  }
		  else {
		  alert(response.errorMsg);
		  }
		  
		  });
	
		  
	
	
	
	return;
}

function hideEventList() {
	//$('#eventList').hide("slide", {direction: "down" }, 1000);
	$('#eventList').css('display', 'none');
	//animate map expansion
	$('#map').css('width', 'auto');
	
	map.checkResize();
	
	$('#eventListScroller').empty();
	
	
	return;
}


function preloadUser(id, preloadLatLng) {
		map.setCenter(preloadLatLng, 14);
	//	map.openInfoWindowHtml(preloadLatLng, "Loading...");
	
	var fn = userClickFn(id, preloadLatLng);
	fn();
	
}

function preloadDojo(id, preloadLatLng) {
	map.setCenter(preloadLatLng, 14);
	var fn = dojoClickFn(id, preloadLatLng);
	fn();
	
	
}

function preloadGame(id, preloadLatLng) {
	
	var fn = gameClickFn(id, preloadLatLng);
	fn();
	
	
}

function userClickFn(id, latlng){ 
	return function() {
		
		//	var avatarurl = 'http://igolocal.net/download/file.php?avatar=' + user.avatar;
		//	var infoHtml = '';
		
		hideEventList();
		
	//	map.setZoom(14);
		
	my_block("Loading Profile...");	
		
		var fnName = arguments.callee.name;
		$.get('map_data.php', { 'user_id': id, 'user_tab': "profile", 'change_lang': change_lang }, function(data) {
			  //		  $('.result').html(data);
			  //  alert(data);
			  
			  $.unblockUI();
			  
			  var response = $.parseJSON(data);
			  
			  if (typeof(response) == "undefined") {
			  alert(data);
			  }		  
			  else if (response.error == 0) {
			  map.closeInfoWindow();	
			  map.openInfoWindowHtml(latlng, response.html);
			  return;
			  }
			  else if (response.error == 5) {
			  //this shouldn't happen, don't need to login to see this.
			  location.href = 'ucp.php?mode=login';
			  }
			  else {
			  alert(response.errorMsg);
			  }
		/*	  
			  map.closeInfoWindow();
			  
			  map.openInfoWindowHtml(latlng, data);
		 */
			  
			  });
		
	};
}

function userTabProfileFn(id, latlng) {
	//var fn = userClickFn(id, latlng);
	hideEventList();
	
	my_block("Loading Profile...");
	
	var fnName = arguments.callee.name;
	$.get('map_data.php', { 'user_id': id, 'user_tab': "profile", 'change_lang': change_lang }, function(data) {
		  //		  $('.result').html(data);
		  //  alert(data);
		  
		  $.unblockUI();
		  
		  var response = $.parseJSON(data);
		  
		  if (typeof(response) == "undefined") {
		  alert(data);
		  }		  
		  else if (response.error == 0) {
		  map.closeInfoWindow();
		  map.openInfoWindowHtml(latlng, response.html);
		  return;
		  }
		  else if (response.error == 5) {
		  //this shouldn't happen, don't need to login to see this.
		  location.href = 'ucp.php?mode=login';
		  }
		  else {
		  alert(response.errorMsg);
		  }
		  
		  
	
		  /*
		  map.closeInfoWindow();
		  
		  map.openInfoWindowHtml(latlng, data);
		  */
		  
		  });
}

function userTabScheduleFn(id, latlng) {
	//	map.setCenter(latlng, 14);
	hideEventList();
	
	my_block("Loading Schedule...");

//	map.openInfoWindowHtml(latlng, "Loading...");

	var fnName = arguments.callee.name;
	
	$.get('map_data.php', { 'user_id': id,  'user_tab': "schedule", 'change_lang': change_lang}, function(data) {
		  //		  $('.result').html(data);
		  //  alert(data);
		  $.unblockUI();
		 		  
		  var response = $.parseJSON(data);
		  if (typeof(response) == "undefined") {
		  alert(data);
		  }		
		  else {
			handleAjaxResponse( response, fnName );
		  }
		  if (response.error == 0) {
		  map.closeInfoWindow();
		  map.openInfoWindowHtml(latlng, response.html);	
		  }
		 
		  });
	
}

function userTabHistoryFn(id, latlng) {
	//map.setCenter(latlng, 14);
	hideEventList();
	
	my_block("Loading...");
	
	var fnName = arguments.callee.name;
	$.get('map_data.php', { 'user_id': id,  'user_tab': "history", 'change_lang': change_lang}, function(data) {
		  $.unblockUI();
		  var response = $.parseJSON(data);
		  if (typeof(response) == "undefined") {
		  alert(data);
		  }		  
		  else {
		  handleAjaxResponse( response, fnName );
		  }
		  if (response.error == 0) {
		  map.closeInfoWindow();
		  map.openInfoWindowHtml(latlng, response.html);	
		  }
		  
		  		  
		  });
	
}

function dojoCreateFn() {
	
	$.blockUI({ message:'<div id="blockUIMessage">Please wait...</div>', css: { 
			  border: 'none', 
			  padding: '15px', 
			  backgroundColor: '#000', 
			  '-webkit-border-radius': '10px', 
			  '-moz-border-radius': '10px', 
			  opacity: .5, 
			  color: '#fff' 
			  } }); 
	
	var fnName = arguments.callee.name;
	$.get('ajax_dojo_create.php', function(data) {
			  $.unblockUI();
			  var response = $.parseJSON(data);
		  
		  if (typeof(response) == "undefined") {
		  alert(data);
		  }		  
		  else {
		  handleAjaxResponse( response, fnName );
		  }
		  if (response.error == 0) {
		  location.href = './dojo_manager_tools.php';
		  }
		  
		  
			  });
	
}



function dojoClickFn(id, latlng){ 
	return function() {
		hideEventList();
		
		//	var avatarurl = 'http://igolocal.net/download/file.php?avatar=' + user.avatar;
		//	var infoHtml = '';
		
		
	//	map.setZoom(16);
		map.closeInfoWindow();
		my_block("Loading Dojo...");
//		map.openInfoWindowHtml(latlng, "Loading...");
		
		$.get('map_data.php', { 'dojo_id': id , 'change_lang': change_lang}, function(data) {
			  //		  $('.result').html(data);
			//  map.closeInfoWindow();
			  $.unblockUI();
			  map.openInfoWindowHtml(latlng, data);
			  
			  });
		
	};
}


function dojoTabProfileFn(id, latlng) {
	map.closeInfoWindow();
	my_block("Loading Dojo...");
	
	$.get('map_data.php', { 'dojo_id': id , 'change_lang': change_lang}, function(data) {
		  //		  $('.result').html(data);
		  $.unblockUI();
		  map.openInfoWindowHtml(latlng, data);

		  
		  });
	
}

function dojoTabMeetingsEventsFn(id, latlng) {
	
	
	map.openInfoWindowHtml(latlng, "Loading...");
	
	$.get('map_data.php', { 'dojo_id': id , 'dojo_tab': 'meetingsevents', 'change_lang': change_lang}, function(data) {
		  //		  $('.result').html(data);
		  map.closeInfoWindow();
		  map.openInfoWindowHtml(latlng, data);
		  
		  });
}

function dojoTabMemberListFn(id, latlng) {
	
	map.closeInfoWindow();
	my_block("Loading...");
	
	$.get('map_data.php', { 'dojo_id': id , 'dojo_tab': 'memberlist', 'change_lang': change_lang}, function(data) {
		  //		  $('.result').html(data);
		  $.unblockUI();
		  map.openInfoWindowHtml(latlng, data);
		  
		  });
}

function dojoJoin(id) {
	
	hideEventList();
	
	// get the latlng of the current infowindow...
	var dojoLatLng = map.getInfoWindow().getPoint();
	
	map.closeInfoWindow();	 
	
	my_block("Please wait...");
	
	var fnName = arguments.callee.name;
	$.get('dojo_join.php', { 'dojo_id': id }, function(data) {
		  
		  $.unblockUI();
		  
		  var response = $.parseJSON(data);
		  if (typeof(response) == "undefined") {
		  alert(data);
		  }		 		  
		  else {
		  handleAjaxResponse( response, fnName );
		  }
		  if (response.error == 0) {
		  //reopen info window...
	//	  alert("attempting to open to dojo " + id + " at: " + dojoLatLng);
		 
		  // success msg.
		  $('<div></div>')
		  .html(response.errorMsg)
		  .dialog({ buttons: { 
				  "OK": function() { $(this).dialog("close");  dojoTabProfileFn(id, dojoLatLng); }
				  } 
				  });
		  
		  }		  
		  
		  });				  
	
}

function dojoLeaveConfirmation(id) {
	
	var dojoName = $('div#dojoNameInfo').html();
	
	confirmDialog($('a#rightLink.buttonLink').html() + " (" + dojoName + ")", function() {
				  
				  hideEventList();
				  map.closeInfoWindow();	 
				  
				  my_block("Please wait...");
				  				  
				  var fnName = arguments.callee.name;
				  $.get('dojo_leave.php', { 'dojo_id': id }, function(data) {
						
						$.unblockUI();
						
						var response = $.parseJSON(data);
						if (typeof(response) == "undefined") {
						alert(data);
						}		 		  
						else {
						handleAjaxResponse( response, fnName );
						}
						if (response.error == 0) {
						infoDialog('You are no longer a member of "' + dojoName + '".' );	
						}		  
						
						});				  
				  });		
	// ./dojo_leave.php?dojo_id=' . $dojo_id . '
}


function eventClickFn(an_event_id, a_dojo_id, latlng){ 
	
	//game_mode can be offered_game OR owned_game .. hopefully no more modes.
	// defaults to "offered game"
	//game_mode = typeof(game_mode) != 'undefined' ? game_mode : "offered_game";
	
	
	map.setZoom(16);
	
	map.closeInfoWindow();
	my_block("Loading...");
	
	
	var fnName = arguments.callee.name;
	$.get('map_data.php', { 'event_id': an_event_id, 'dojo_id': a_dojo_id, 'change_lang': change_lang}, function(data) {
		$.unblockUI();
		  var response = $.parseJSON(data);
		  if (typeof(response) == "undefined") {
		  alert(data);
		  }		
		  else {
		  handleAjaxResponse( response, fnName );
		  }
		  if (response.error == 0) {
		  map.closeInfoWindow();
		  map.openInfoWindowHtml(latlng, response.html);	
		  }
		  
				  
		  //		  $('.result').html(data);
		  	 // alert(data);
		
		  
		  });
	
}


function gameClickFn(id, latlng, game_mode){ 
	
	//game_mode can be offered_game OR owned_game .. hopefully no more modes.
	// defaults to "offered game"
	//game_mode = typeof(game_mode) != 'undefined' ? game_mode : "offered_game";
	
	
	map.setZoom(16);
	
	map.closeInfoWindow();
	my_block("Loading...");
//	map.openInfoWindowHtml(latlng, "Loading...");
	
	
	var fnName = arguments.callee.name;
	$.get('map_data.php', { 'game_id': id, 'game_mode': game_mode , 'change_lang': change_lang}, function(data) {
		  
		  $.unblockUI();
		  
		  var response = $.parseJSON(data);
		  if (typeof(response) == "undefined") {
		  alert(data);
		  }		  
		  else {
		  handleAjaxResponse( response, fnName );
		  }
		  if (response.error == 0) {
		  map.closeInfoWindow();
		  map.openInfoWindowHtml(latlng, response.html);	
		  }
		  		  
		  //		  $('.result').html(data);
		  //	  alert(data);
				  
		  });
	
}

function unblockButton() {
	$.unblockUI();
	resetBlockUIDefaults();
}

function scoreDisplay() {
	if ( $('#terms').val() == 'RESIGNATION' ) {
		$('#scoreFieldBox').css('display','none');
	}
	else if ( $('#terms').val() == 'SCORE' ) {
		$('#scoreFieldBox').css('display','inline');		
	}
}

function resetBlockUIDefaults() {

//	alert("trying to reset defaults");
	$.blockUI.defaults.css = savCSSdefaults;
	

}

function acknowledgeClaim(id) {
	confirmDialog($('a#acknowledge.buttonLink').html(), function() {
				  var fnName = arguments.callee.name;
				  $.get('./ajax_acknowledge_deny_claim.php', { 'game_id': id, 'mode': 'acknowledge' }, 
						function(data) {
						$.unblockUI();
						var response = $.parseJSON(data);
						if (typeof(response) == "undefined") {
						alert(data);
						}		  
						else {
						handleAjaxResponse( response, fnName );
						}
						if (response.error == 0) {
						unblockButton();
						}
						
						});
				  
				  }); 
	
}

function denyClaim(id) {
	confirmDialog($('a#deny.buttonLink').html(), function() {
				  var fnName = arguments.callee.name;
				  $.get('./ajax_acknowledge_deny_claim.php', { 'game_id': id, 'mode': 'deny' }, 
						function(data) {						
						$.unblockUI();						
						var response = $.parseJSON(data);
						if (typeof(response) == "undefined") {
						alert(data);
						}		  
						else {
						handleAjaxResponse( response, fnName );
						}
						if (response.error == 0) {
						unblockButton();

						}

						});

				  }); 
}



function viewClaimFn(id) {
	
//	alert("view claim");
	map.closeInfoWindow();	
	
	my_block("Loading...");
	
	
	var fnName = arguments.callee.name;
	$.get('./ajax_win_claim_html.php', { 'game_id': id, 'mode': 'acknowledge_claim' }, function(data) {
		  
		  $.unblockUI();
		  //var savCSSdefaults = $.blockUI.defaults.css;		  
		  $.blockUI.defaults.css = {}; 
		  
		  
		  var response = $.parseJSON(data);
		  if (typeof(response) == "undefined") {
		  alert(data);
		  }		  
		  else {
		  handleAjaxResponse( response, fnName );
		  }
		  if (response.error == 0) {
		  map.closeInfoWindow();
		  $.blockUI({ 
					//					theme:     true, 
					//					title:    'This is your title', 
					// message:  '<p>This is your message.</p>', 
					// timeout:   2000
					message:'<div id="blockUIMessage">' + response.html + '</div>', 
					css: {
					position: 'fixed',
					top: '0px',
					padding:  '0px', 
					margin:  '0px',
					left: '0px', 
					textAlign:      'center',
					
					border:         '3px solid #aaa', 
					//cursor:         'wait',
					border: 'none', 		 
					'-webkit-border-radius': '10px', 
					'-moz-border-radius': '10px', 
					color: '#fff',
					height: 'auto',
					width: '950px',
					opacity: 1,					
					},
					});		
		  
		  }
		  
		  
		  
		  });
	
}

function viewSettledGame(id) {

	my_block("Loading...");
	
	
	var fnName = arguments.callee.name;
	$.get('./ajax_win_claim_html.php', { 'game_id': id, 'mode': 'view_completed' }, function(data) {
		  
		  $.unblockUI();
		  //var savCSSdefaults = $.blockUI.defaults.css;		  
		  $.blockUI.defaults.css = {}; 
		  
		
		var response = $.parseJSON(data);

		  
		  if (typeof(response) == "undefined") {
		  alert(data);
		  }		  
		  else {
		  handleAjaxResponse( response, fnName );
		  }
		  if (response.error == 0) {
	
		  $.blockUI({ 
					//					theme:     true, 
					//					title:    'This is your title', 
					// message:  '<p>This is your message.</p>', 
					// timeout:   2000
					message:'<div id="blockUIMessage">' + response.html + '</div>', 
					css: {
					position: 'fixed',
					top: '0px',
					padding:  '0px', 
					margin:  '0px',
					left: '0px', 
					textAlign:      'center',
					
					border:         '3px solid #aaa', 
					//cursor:         'wait',
					border: 'none', 		 
					'-webkit-border-radius': '10px', 
					'-moz-border-radius': '10px', 
					color: '#fff',
					height: 'auto',
					width: '950px',
					opacity: 1,					
					},
					});		
		  
		  }
		  
		  
		  
		  });
	
	
}

function submitClaim(id) {
	
	var fnName = arguments.callee.name;
	
	confirmDialog($('a#location_save_button.buttonLink').html(), function() {
					
					$.get('./ajax_submit_claim.php', { 
						  'game_id': id, 
						  'challenger_color': $('#color').val(), 
						  'size': $('#size').val(),
						  'komi': $('#komi').val(),
						  'rules': $('#rules').val(),
						  'terms': $('#terms').val(),
						  'score': $('#score').val(),
						  'handicap': $('#handicap').val(),
						  }, function(data) {
						  
						  $.unblockUI();
						  
						  resetBlockUIDefaults();
						  
						  var response = $.parseJSON(data);
						  if (typeof(response) == "undefined") {
						  alert(data);
						  }		  
						  else {
						  handleAjaxResponse( response, fnName );
						  }
						  if (response.error == 0) {
						  userTabHistoryFn(global_user_id, userLatLng);
						  }		  
						  
						  });
					
					});
	
}

function claimFormFn(id) {
	map.closeInfoWindow();	

	my_block("Loading...");
	
	
	var fnName = arguments.callee.name;
	$.get('./ajax_win_claim_html.php', { 'game_id': id, 'mode': 'claim' }, function(data) {
		  
		  $.unblockUI();
	//var savCSSdefaults = $.blockUI.defaults.css;		  
		  $.blockUI.defaults.css = {}; 
		  
		  
		  var response = $.parseJSON(data);
		  if (typeof(response) == "undefined") {
		  alert(data);
		  }		  
		  else {
		  handleAjaxResponse( response, fnName );
		  }
		  if (response.error == 0) {
		  map.closeInfoWindow();
		  $.blockUI({ 
					//					theme:     true, 
					//					title:    'This is your title', 
					// message:  '<p>This is your message.</p>', 
					// timeout:   2000
					message:'<div id="blockUIMessage">' + response.html + '</div>', 
					css: {
					position: 'fixed',
					top: '0px',
					padding:  '0px', 
					margin:  '0px',
					left: '0px', 
					textAlign:      'center',
					
					border:         '3px solid #aaa', 
					cursor:         'wait',
					border: 'none', 		 
					'-webkit-border-radius': '10px', 
					'-moz-border-radius': '10px', 
					color: '#fff',
					height: 'auto',
					width: '950px',
					opacity: 1,					
					},
					});		
		  
		  }
		  
		  
		 		  
		  });
}

function cancelScheduledGameFn(id, latlng) {
	
	var fnName = arguments.callee.name;
	
	//	confirmDialog($('a#leftLink.buttonLink').html(), function() {
	
	cancelReasonDialog($('a#leftLink.buttonLink').html(), function() {
					 
					   hideEventList();
					   map.closeInfoWindow();	 
					   
					   my_block("Please wait...");
					   
					   var fnName = arguments.callee.name;
					   $.get('game_details.php', { 'game_id': id, "mode": "cancel", "cancel_confirmation": 1, "cancel_reason": $('textarea#cancelReason').val() }, function(data) {			
							 $.unblockUI();
							 var response = $.parseJSON(data);
							 if (typeof(response) == "undefined") {
							 alert(data);
							 }		 		  
							 else {
							 handleAjaxResponse( response, fnName );
							 }
							 if (response.error == 0) {
							 userTabScheduleFn(global_user_id, userLatLng);	
							 }		  
							 });
					   
					   
					   });
	
}


function cancelGameFn(id, latlng) {
	
	var fnName = arguments.callee.name;

//	confirmDialog($('a#leftLink.buttonLink').html(), function() {

	confirmDialog($('a#leftLink.buttonLink').html(), function() {
				  
				  hideEventList();
				  map.closeInfoWindow();	 
				  
				  my_block("Please wait...");
				  
				  
				  var fnName = arguments.callee.name;
				  $.get('game_details.php', { 'game_id': id, "mode": "cancel", "cancel_confirmation": 1, "cancel_reason": "Canned Response" }, function(data) {
						
						$.unblockUI();
						
						var response = $.parseJSON(data);
						if (typeof(response) == "undefined") {
						alert(data);
						}		 		  
						else {
						handleAjaxResponse( response, fnName );
						}
						if (response.error == 0) {
						userTabScheduleFn(global_user_id, userLatLng);	
						}		  
						
						
						});
				  
				  });
	 
}



function acceptGameFn(id, latlng) {
		
	var fnName = arguments.callee.name;
	
	$('<div></div>')
	.attr('title',"Terms of Service")
	.html("<b>By accepting this game offer, you agree:</b><ul style='margin-top: 5px; margin-left: 15px;'><li>To make a good faith attempt to attend the game</li><li>If you discover that you cannot attend, to cancel the game as soon as possible</li><li>To treat your opponent with courtesy and respect</li></ul>")
	.dialog({ buttons: { 
			"I Agree": function() { 
			$(this).dialog("close");
			
			hideEventList();
			map.closeInfoWindow();	
			my_block("Please wait...");
						
			$.get('game_details.php', { 'game_id': id, "mode": "accept"}, function(data) {
				  
				  $.unblockUI();		  
				  var response = $.parseJSON(data);
				  if (typeof(response) == "undefined") {
				  alert(data);
				  }		  
				  else {
				  handleAjaxResponse( response, fnName );
				  }
				  if (response.error == 0) {
				  userTabScheduleFn(global_user_id, userLatLng);	
				  }		  
				  });
			
			},
			"Cancel": function() { $(this).dialog("close"); cancel(); }, } 
			});
}

function scheduleEventFn(id, latlng) {
	hideEventList();
	
	map.openInfoWindowHtml(latlng, "Loading...");
	
	my_block("Please wait...");
	
	var fnName = arguments.callee.name;
	$.get('ajax_register_for_event.php', { 'event_id': id, 'mode': 'schedule' }, function(data) {
		  
		  $.unblockUI();
		  
		  var response = $.parseJSON(data);
		  if (typeof(response) == "undefined") {
		  alert(data);
		  }		  
		  else {
		  handleAjaxResponse( response, fnName );
		  }
		  if (response.error == 0) {
		  map.closeInfoWindow();
		  userTabScheduleFn(global_user_id, userLatLng);	
		  }		  
	
		  
		  });
}


function descheduleEventFn(id, latlng) {
	hideEventList();
	
	map.openInfoWindowHtml(latlng, "Loading...");
	
	
	$.get('ajax_register_for_event.php', { 'event_id': id, 'mode': 'deschedule' }, function(data) {
		  //		  $('.result').html(data);
		  //	alert(data);
		  map.closeInfoWindow();
		  userTabScheduleFn(global_user_id, userLatLng);
		  
		  });
}


function locationClickFn(id, latlng){ 
	return function() {
		
		//	var avatarurl = 'http://igolocal.net/download/file.php?avatar=' + user.avatar;
		//	var infoHtml = '';
		hideEventList();
		
		
		
		map.openInfoWindowHtml(latlng, "Loading...");
		
		$.get('map_data.php', { 'location_id': id, 'change_lang': change_lang }, function(data) {
			  //		  $('.result').html(data);
			  // alert(data);
			  map.closeInfoWindow();
			  map.openInfoWindowHtml(latlng, data);
			  
			  });
		
	};
}



