//------------------------------------------------------------------------------
// *** Intialize

var allmarkers = [];
var geocoder = new GClientGeocoder();
var icons = {};
var map;
var mapClickLatLng;
var mgr;
var scrnheight = 0;
var scrnwidth  = 0;
var userMarker;

// height 
var bufferHeight = 9;
if ( devicename == 'PC' ) bufferHeight = 1;
	
//------------------------------------------------------------------------------
// *** resize window

window.onresize = function (){
 
	setHeightWidth();
	
	if ( document.getElementById('choicesbar') )	
		document.getElementById('choicesbar').style.width = scrnwidth + "px";

	if ( document.getElementById('menubar') )	
		document.getElementById('menubar').style.width = scrnwidth + "px";
	
	document.getElementById('map_canvas').style.width  = scrnwidth + "px";
	document.getElementById('map_canvas').style.height = scrnheight + "px";
}

//------------------------------------------------------------------------------
// *** clear ajax area
function clearAjax()
{
	var x = document.getElementById('ajaxresponses').innerHTML;
	document.getElementById('ajaxresponses').innerHTML = '';
	return x;
}


//------------------------------------------------------------------------------
// *** screen width setup

function setHeightWidth()
{
	if ( devicename == 'PC' ) 
	{
		if (navigator.appName=="Netscape") 
		{
			scrnwidth = window.innerWidth - 20;
			scrnheight = window.innerHeight - 120;
		} 
		else if ( navigator.appName.indexOf("Microsoft") != -1 ) 
		{
			scrnwidth = document.body.offsetWidth - 20;
			scrnheight = document.body.offsetHeight - 120;
		} 
		else 
		{
			scrnwidth = 320;
			scrnheight = 356;
		}
	} 
	else if ( devicename == 'iPhone' 
	       || devicename == 'Palm Pre' 
	       || devicename == 'Android' 
		   || devicename == 'G1' ) 
	{
			scrnwidth = window.innerWidth;
			if ( window.innerHeight < 300 )
				scrnheight = 228;
			else
				scrnheight = 326; //window.innerHeight;
	}
	else if ( devicename == 'Blackberry' ) 
	{
			scrnheight = 240;
			scrnheight = 320; 
	}
	
	document.getElementById('content-wrapper').style.width = scrnwidth + "px";

	setTimeout('window.scrollTo(0, 1)', 250);
}

//------------------------------------------------------------------------------
// *** Intialize historical markers

function load() {
  
  setHeightWidth();
  
  if (GBrowserIsCompatible()) {
    
	var map_canvas = document.getElementById("map_canvas");
    
    if (map_canvas)
    {
		map_canvas.style.width = scrnwidth + "px";
	    map_canvas.style.height = scrnheight + "px";
	    
		map = new GMap2( map_canvas );
	    
	    map.addControl(new GLargeMapControl3D());
	    map.setCenter(new GLatLng(latitude, longitude), zoomlevel);
	    map.enableDoubleClickZoom();
	    mgr = new MarkerManager(map, {trackMarkers:true});
	    window.setTimeout(setupPinMarkers, 0);

	    GEvent.addListener(map, 'click', function(overlay, latlng) { removeCurrentMarker(); mapClick( latlng ); });
	}
  }

}

function getIcon(images) {
  var icon = null;
  
  if (images) {
	// 
	icon = new GIcon();
	icon.image = "images/icons/" + images[0] + ".png";
	
	size = IconData[images[0]];
	icon.iconSize = new GSize(size.width, size.height);
	icon.iconAnchor = new GPoint(size.width >> 1, size.height >> 1);
	icon.shadow = "images/" + images[1] + ".png";
	
	size = IconData[images[1]];
	icon.shadowSize = new GSize(size.width, size.height);
	icons[images[0]] = icon;
  }
  return icon;
}

function setupPinMarkers() {
  
  allmarkers.length = 0;
  for (var i in pinLayer) 
  {
    
	var layer = pinLayer[i];
    var markers = [];
    
	for (var j in layer["places"]) 
	{
      var place = layer["places"][j];
      var icon = getIcon(place["icon"]); // use for state flags
      var title = place["name"] + ", " + place["count"];
      var posn = new GLatLng( place["posn"][0], place["posn"][1] );
      var marker = createMarker( posn, title, icon ); 

      markers.push( marker );
      allmarkers.push( marker );
    }
    mgr.addMarkers(markers, layer["zoom"][0], layer["zoom"][1]);
  }
  mgr.refresh();
}

function createMarker( posn, title, icon ) {
  var marker = new GMarker(posn, {title: title, icon: icon, draggable:false });
  GEvent.addListener(marker, 'click', function() { 
    map.setCenter( posn, getZoom( marker ) ); 
    var parts = title.split(', ');
    
    var htmlTitle;
    var newLocation;
	if ( parts.length == 5 )
    {
		htmlTitle = parts[0] + "<br />" + parts[1] + ", " + parts[2] + ", " + parts[3] + "<br />" + parts[4];
		newLocation = parts[0] + ", " + parts[1] + ", " + parts[2] + ", " + parts[3];
	}
	else if ( parts.length == 4 )
    {
		htmlTitle = parts[0] + "<br />" + parts[1] + ", " + parts[2] + "<br />" + parts[3];
		newLocation = parts[0] + ", " + parts[1] + ", " + parts[2];
	}
	else if ( parts.length == 3 )
    {
		htmlTitle = parts[0] + ", " + parts[1] + "<br />" + parts[2];
		newLocation = parts[0] + ", " + parts[1];
	}

    document.getElementById("SelectedPoint").value = newLocation;
    showComments();
	//marker.openInfoWindowHtml( htmlTitle + ' fapping <p> click <a href="javascript:;" onclick="showComments()">HERE</a> for comments' );

  } ); 
  return marker;
}

function getZoom( obj ) {
 
 	var newZoom = map.getZoom();
	return newZoom;
}

function deleteMarker() {
  var markerNum = parseInt(document.getElementById("markerNum").value);
  mgr.removeMarker(allmarkers[markerNum]);
}

function clearMarkers() {
  mgr.clearMarkers();
}

function reloadMarkers() {
  setupPinMarkers();
}

//------------------------------------------------------------------------------
// *** map click
function mapClick( latlng ) {
	
	if (!logonstatus) return;
	
    mapClickLatLng = latlng;
    geocoder.getLocations(latlng, getLocation);
}

function getLocation( response ) {

     // erase previous marker, if it exists
  if ( userMarker ) mgr.removeMarker(userMarker);

  if ( !response || response.Status.code != 200 ) 
  {
    fmAlert( "Sorry, we were unable to geocode that address." );
    return false;
  } 

  // just in case
  fmCloseAll();

  // store for my usage later
  var place = response.Placemark[0];
  //alert(place.toSource());

	//alert(place.toSource());

  var locality = '';
  var streetAddress = '';
  var adminarea = '';
  
  if ( place.AddressDetails.Country.SubAdministrativeArea ) 
  {
//alert(place.toSource());
      // uses the GB/Asia short codes
      adminarea = place.AddressDetails.Country.SubAdministrativeArea.SubAdministrativeAreaName
      locality = place.AddressDetails.Country.SubAdministrativeArea.Locality.LocalityName;
      streetAddress = place.AddressDetails.Country.SubAdministrativeArea.Locality.Thoroughfare.ThoroughfareName;

  } else if ( place.AddressDetails.Country.AdministrativeArea.SubAdministrativeArea ) {

//alert(place.toSource());
      adminarea = place.AddressDetails.Country.AdministrativeArea.AdministrativeAreaName;
      
      // city
	  if ( place.AddressDetails.Country.AdministrativeArea.SubAdministrativeArea.Locality )
      	locality = place.AddressDetails.Country.AdministrativeArea.SubAdministrativeArea.Locality.LocalityName;
      else
	    locality = place.AddressDetails.Country.AdministrativeArea.SubAdministrativeArea.SubAdministrativeAreaName;
      
	  if ( place.AddressDetails.Country.AdministrativeArea.SubAdministrativeArea.Thoroughfare )
        streetAddress = place.AddressDetails.Country.AdministrativeArea.SubAdministrativeArea.Thoroughfare.ThoroughfareName;
      else
        streetAddress = place.AddressDetails.Country.AdministrativeArea.SubAdministrativeArea.Locality.Thoroughfare.ThoroughfareName;
	    
  } else if ( place.AddressDetails.Country.AdministrativeArea ) {

//alert(place.toSource());
      adminarea = place.AddressDetails.Country.AdministrativeArea.AdministrativeAreaName;
      locality = place.AddressDetails.Country.AdministrativeArea.Locality.LocalityName;
	  if ( place.AddressDetails.Country.AdministrativeArea.Locality.Thoroughfare )
	  {
	    // uses the short codes
        streetAddress = place.AddressDetails.Country.AdministrativeArea.Locality.Thoroughfare.ThoroughfareName;
	  }
  }

  if ( streetAddress == '' ) streetAddress = "Rural Area = " + place.Point.coordinates[1] + "  " + place.Point.coordinates[0];
  
  var windowHTML = 'Leave a Fap Comment:<p>';
  
  if ( place.AddressDetails.Accuracy < 8 )
  {
	windowHTML += '<p>Latitude = ' + place.Point.coordinates[1] +
                  '<br />Longitude = ' + place.Point.coordinates[0] + "<br />";
  }

  if ( streetAddress ) windowHTML += streetAddress + '<br />' 
  
  if ( locality ) windowHTML += locality;

  windowHTML += '<br />' + adminarea +
                ', ' + place.AddressDetails.Country.CountryNameCode +
				'<div style="float:left;"><textarea id="Comment" cols="17" rows="2" wrap="OFF"></textarea></div>' +
				'<div style="float:left;"><input type="button" value="save" onclick="saveFapInput()" /></div>' +
				'<input type="hidden" id="Latitude" value="'+place.Point.coordinates[1]+'" />' +
				'<input type="hidden" id="Longitude" value="'+place.Point.coordinates[0]+'" />' +
				'<input type="hidden" id="North" value="'+place.ExtendedData.LatLonBox.north+'" />' +
				'<input type="hidden" id="South" value="'+place.ExtendedData.LatLonBox.south+'" />' +
				'<input type="hidden" id="East" value="'+place.ExtendedData.LatLonBox.east+'" />' +
				'<input type="hidden" id="West" value="'+place.ExtendedData.LatLonBox.west+'" />' +
				'<input type="hidden" id="CountryName" value="'+place.AddressDetails.Country.CountryName+'" />' +
				'<input type="hidden" id="CountryNameCode" value="'+place.AddressDetails.Country.CountryNameCode+'" />' +
				'<input type="hidden" id="AdministrativeAreaName" value="'+adminarea+'" />' +
				'<input type="hidden" id="LocalityName" value="'+locality+'" />' +
				'<input type="hidden" id="ThoroughfareName" value="'+streetAddress+'" />' +
				'</form>';
                   
  map.openInfoWindowHtml(mapClickLatLng, windowHTML);
  
  userMarker = new GMarker( mapClickLatLng );
  var myMarkerListener = GEvent.addListener(map, 'click', function() { 
	    map.closeInfoWindow();
	    mgr.removeMarker( userMarker );
    	GEvent.removeListener(myMarkerListener);  
  	} ); 
  map.addOverlay(userMarker);

}

function removeCurrentMarker()
{
	if ( userMarker ) 
	{
	  //map.closeInfoWindow();
	  mgr.removeMarker( userMarker );
	}
}

//------------------------------------------------------------------------------
// *** saving a password change

function savePassword()
{
	var params = '?old=' + document.getElementById('oldpwd').value +
			     '&new=' + document.getElementById('newpwd').value;

	ahah( 'update.php'+params, 'ajaxresponses' );
	setTimeout( 'fmSaveCompleted()', 500 );
}

//------------------------------------------------------------------------------
// *** saving a new fap

function saveFapInput()
{
	if ( document.getElementById('Comment').value == "" ) 
	{
		document.getElementById('ajaxresponses').innerHTML = "Please enter a comment first";
		setTimeout( 'fmSaveCompleted()', 100 );
		return false;
	}

	params = 'Comment=' + document.getElementById('Comment').value +
			 '&Latitude=' + document.getElementById('Latitude').value +
	         '&Longitude=' + document.getElementById('Longitude').value +
	         '&North=' + document.getElementById('North').value +
	         '&South=' + document.getElementById('South').value +
	         '&East=' + document.getElementById('East').value +
	         '&West=' + document.getElementById('West').value +
	         '&CountryNameCode=' + document.getElementById('CountryNameCode').value +
	         '&CountryName=' + document.getElementById('CountryName').value +
	         '&AdministrativeAreaName=' + document.getElementById('AdministrativeAreaName').value +
	         '&LocalityName=' + document.getElementById('LocalityName').value +
	         '&ThoroughfareName=' +  document.getElementById('ThoroughfareName').value;

	removeCurrentMarker();
	ahah( 'newfap.php?'+params, 'ajaxresponses' );
	setTimeout( 'fmSaveCompleted()', 500 );
}

//------------------------------------------------------------------------------
// *** location goto was selected
function fmGoto() {
	
	// doofus check
	if ( document.getElementById('gotoText') )
	{
		closeMakeDiv();	
		return false;
	} 
	
	// just in case
	fmCloseAll();
	
	// form html
	var formHTML = ' By City<br />Example:San Jose, Ca, US or Paris, France' +
				   '<div style="clear:both;"></div>' +
				   '<div style="float:left;"><textarea id="gotoText" cols="20" rows="2" wrap="OFF">' +
				   '</textarea></div><div style="float:left;">' +
				   '<input type="button" value="go" style="width:55px;" ' +
				   'onclick="gotoGoto()" /></div>' + 
				   '<div style="clear:both;">&nbsp;<p>by Username: <br />' +
				   '<div style="clear:both;"></div>' +
				   '<div style="float:left;"><input type="text" name="gotoName" id="gotoName" />' +
				   '</div>' +
				   '<div style="float:left;">' +
				   '<input type="button" value="go" style="width:55px;" ' +
				   'onclick="gotoName()" /><br />' +
				   '<div style="clear:both;"></div><p>';
	
	fmMakeDiv( formHTML );	
}

function gotoGoto()
{
	if ( document.getElementById('gotoText') && document.getElementById('gotoText').value != '' )
	{
		geocoder.getLocations( document.getElementById('gotoText').value, gotoMap );
		closeGoto();
	}
}

function gotoName()
{
	if ( document.getElementById('gotoName') && document.getElementById('gotoName').value != '' )
	{
		showSoloComments( document.getElementById('gotoName').value );
	}
}

function gotoMap( response )
{
	if ( !response || response.Status.code != 200 ) 
	{
		fmAlert( "Sorry, we were unable to geocode that address." );
		return false;
	} 

	// goto location
  	place = response.Placemark[0];
    map.setCenter( new GLatLng(place.Point.coordinates[1], place.Point.coordinates[0]) );
}

function gpsGotoMap( latitude, longitude )
{
	// goto location
    map.setCenter( new GLatLng( latitude, longitude ), 12 );
}

//------------------------------------------------------------------------------
// *** location statistics
function fmStats() {

	// doofus check
	if ( document.getElementById('statsDataDiv') )
	{
		closeMakeDiv();	
		return false;
	} 
	
	// just in case these are open
	fmCloseAll();
	
	// form html
	var formHTML = '<h2>TOP TEN</h2>' +
				   '<input type="button" value="Fapper" onclick="statsShow(\'fapper\')" />' + 
				   '<input type="button" value="City" onclick="statsShow(\'city\')" />' +
				   '<input type="button" value="State" onclick="statsShow(\'state\')" />' + 
				   '<input type="button" value="Country" onclick="statsShow(\'country\')" />' + 
				   '<input type="button" value="Month" onclick="statsShow(\'month\')" />' +
				   '<div style="clear:both"></div>' +
				   '<div id="statsDataDiv"></div> ';
	
	fmMakeDiv( formHTML );	

	statsShow();
}

function statsShow( selection )
{
	// make ajax call for default data
	ahah( "topten.php?type="+selection, 'statsDataDiv' );
}

//------------------------------------------------------------------------------
// *** display and edit options
function fmOptions()
{
	// doofus check
	if ( document.getElementById('optionsDiv') )
	{
		closeMakeDiv();	
		return false;
	} 
	
	// just in case these are open
	fmCloseAll();
	
	// form html
	var formHTML = '<h2>OPTIONS</h2>' +
				   '<input type="button" value="Info" onclick="optionsShow(\'accountinfo\')" />' + 
				   '<input type="button" value="Avatar" onclick="optionsShow(\'avatar\')" />' +
				   '<input type="button" value="Password" onclick="optionsShow(\'password\')" />' +
				   '<div style="clear:both"></div>' +
				   '<div id="optionsDiv"></div> ';
	
	fmMakeDiv( formHTML );	


	optionsShow();
}

function optionsShow( selection )
{
	// make ajax call for default data
	ahah( "options.php?usrid="+selection+"&selection="+selection, 'optionsDiv' );
}

//------------------------------------------------------------------------------
// *** help
function fmHelp() {

	// doofus check
	if ( document.getElementById('helpDiv') )
	{
		closeMakeDiv();	
		return false;
	} 
	
	// just in case these are open
	fmCloseAll();
	
	// form html
	var formHTML = '<h2>FAPMAP HELP</h2>' +
				   '<div style="clear:both"></div>' +
				   '<div id="helpDiv"></div> ';
	
	fmMakeDiv( formHTML );	

	ahah( 'include/help.inc.php', 'helpDiv' );
}

//------------------------------------------------------------------------------
// *** about
function fmAbout() {

	// doofus check
	if ( document.getElementById('aboutDiv') )
	{
		closeMakeDiv();	
		return false;
	} 
	
	// just in case these are open
	fmCloseAll();
	
	// form html
	var formHTML = '<h2>ABOUT FAPMAP</h2>' +
				   '<div style="clear:both"></div>' +
				   '<div id="aboutDiv"></div> ';
	
	fmMakeDiv( formHTML );	

	ahah( 'include/about.inc.php', 'aboutDiv' );
}

//------------------------------------------------------------------------------
// *** members
function fmLogon() {

	// doofus check
	if ( document.getElementById('membersDiv') )
	{
		closeMakeDiv();	
		return false;
	} 
	
	// just in case these are open
	fmCloseAll();
	
	// form html
	var formHTML = '<div id="membersDiv"></div>';
	
	fmMakeDiv( formHTML );	

	ahah( 'include/logon.inc.php', 'membersDiv' );
}

//------------------------------------------------------------------------------
// *** join
function fmJoin() {

	// doofus check
	if ( document.getElementById('joinDiv') )
	{
		closeMakeDiv();	
		return false;
	} 
	
	// just in case these are open
	fmCloseAll();
	
	// form html
	var formHTML = '<script type="text/javascript" src="js/joinpage.js"></script>' +
				   '<div id="joinDiv"></div> ';
	
	fmMakeDiv( formHTML );	

	ahah( 'include/join.inc.php', 'joinDiv' );
}

//------------------------------------------------------------------------------
// *** confirm and alert box

function fmConfirm( text ) {

	var question;

	// default
	question = confirm( text );
	
	// return true or false
	return question;
}

function fmAlert( text ) {

	var question;

	// default
	alert( text );
}

//------------------------------------------------------------------------------
// *** look at comments
function showComments() {

	// just in case these are open
	fmCloseAll();
	
	// form html
	var formHTML = '<div id="commentDiv"></div> ';
	
	fmMakeDiv( formHTML );	

	var params = "?SelectedPoint=" + document.getElementById("SelectedPoint").value;
	
	ahah( 'include/comment.inc.php'+params, 'commentDiv' );
}

function showSoloComments( username ) {

	// doofus check
	if ( document.getElementById('commentDiv') )
	{
		closeMakeDiv();	
		return false;
	} 
	
	// just in case these are open
	fmCloseAll();
	
	// form html
	var formHTML = '<div id="commentDiv"></div> ';
	
	fmMakeDiv( formHTML );	
	
	document.getElementById("SoloUserName").value = username;

	var params = "?SoloUserName=" + username;
	
	ahah( 'include/solocomment.inc.php'+params, 'commentDiv' );
}

//------------------------------------------------------------------------------
// *** change page
function fmCommentPage( page ) {
	var params = "?SelectedPoint=" + document.getElementById("SelectedPoint").value +
				 "&Page=" + page;
	
	ahah( 'include/comment.inc.php'+params, 'commentDiv' );
}

function fmSoloCommentPage( page ) {
	var params = "?SoloUserName=" + document.getElementById("SoloUserName").value +
				 "&Page=" + page;
	
	ahah( 'include/solocomment.inc.php'+params, 'commentDiv' );
}

//------------------------------------------------------------------------------
// *** edit comment
function fmCommentEdit( fapid ) {
	// just in case
	fmCloseAll();
	
	// form html
	var formHTML = 'Edit your comment:' +
				   '<div style="clear:both;"></div>' +
				   '<div style="float:left;"><textarea id="commentText" ' +
				   'cols="20" rows="2" wrap="ON">' +
				   '</textarea></div><div style="float:left;">' +
				   '<input id="commentId" type="hidden" value="'+fapid+'" />' +
				   '<input type="button" value="Save" style="width:55px;" ' +
				   'onclick="fmCommentSave()" /><br />' +
				   '<input type="button" value="Delete" style="width:55px;" ' +
				   'onclick="fmCommentDelete()" /><br />';
	
	fmMakeDiv( formHTML );	

	ahah( 'getcomment.php?fapid='+fapid, 'ajaxresponses' );
	
	setTimeout( 'fmCommentMove()', 500 );
}

function fmCommentMove() {

  var commentText = clearAjax();
    
  if ( commentText > '' )
  {
	document.getElementById('commentText').value = commentText;
  }
  else
  {
	setTimeout( 'fmCommentMove()', 250 );
  }		
}

function fmCommentSave() {
	var t = document.getElementById('commentText').value;
	var i = document.getElementById('commentId').value;

	if ( t == "" ) 
	{
		document.getElementById('ajaxresponses').innerHTML = "Please enter a comment first";
		setTimeout( 'fmSaveCompleted()', 100 );
		return;
	}

	ahah( 'savecomment.php?fapid='+i+'&comment='+t, 'ajaxresponses' );
	
	setTimeout( 'fmSaveCompleted()', 500 );
}

function fmCommentDelete() {
	var i = document.getElementById('commentId').value;

	ahah( 'deletecomment.php?fapid='+i, 'ajaxresponses' );
	
	fmCloseAll();
	
	fmAlert("Comment Deleted");
}

//------------------------------------------------------------------------------
// *** generic html box

function fmMakeDiv( passedText )
{
	// form html
	var formHTML = '<table border="0" cellpadding="0" cellspacing="0" width="100%">' +
	               '<tr><td colspan="3" style="height: ' + bufferHeight +
				   'px; background-color: #000;"></td></tr>' +
	               '<tr><td style="background: url( images/box/box-4.png ) repeat-y;"></td>' +
				   '<td style="background-color: #FFF; color:#999;" align="center">' +
				   passedText +
				   '<div style="clear:both;"></div>' +
				   '<input type="button" value="Close" ' +
				   'onclick="closeMakeDiv()" ' +
				   'style="width:55px;" /></div></td>' +
				   '<td style="background: url( images/box/box-6.png ) repeat-y;"></td>' +
				   '</tr><tr>' +
				   '<td style="height: 15px; width:15px; background: ' +
				   'url( images/box/box-7.png ) no-repeat;"></td>' +
				   '<td style="background: url( images/box/box-8.png ) repeat-x;"></td>' +
				   '<td style="height: 15px; width:15px; background: ' +
				   'url( images/box/box-9.png ) no-repeat;"></td></tr></table>';
	
	// new div in center top of map_canvas (use desi box)
	var makeDiv = document.createElement('div');
    makeDiv.setAttribute('id', 'holdingBox');
    makeDiv.style.position = "absolute";
    makeDiv.innerHTML = formHTML;
    makeDiv.style.width = "300px";
    makeDiv.style.height = "100px";
    makeDiv.style.left = "50%";
    makeDiv.style.margin = "0 0 0 -150px";
    makeDiv.style.top = "35px";
    //makeDiv.style.background = "#00C";
    //makeDiv.style.border = "4px solid #000";
    makeDiv.style.zindex = 1000;
 	document.body.appendChild(makeDiv);	
}

function closeMakeDiv()
{
	if ( document.getElementById('holdingBox') )
		document.body.removeChild( document.getElementById('holdingBox') );	

	setTimeout('window.scrollTo(0, 1)', 250);
}

function fmCloseAll()
{
  // just in case
  closeMakeDiv();
  map.closeInfoWindow();
  //removeCurrentMarker();
}

function fmSaveCompleted()
{
  var validate = clearAjax();
    
  if ( validate == 'OK' )
  {
	fmAlert("your selection was saved");
	fmCloseAll();
  }
  else if ( validate != '' )
  {
	fmAlert( validate );	
  }
  else
  {
	setTimeout( 'fmSaveCompleted()', 250 );
  }
}
