var numCalls = 0;
var mapId = 'map';
var delay = 1;

function setMapId(mpId)
{
  mapId = mpId;
}

function addLatLongMarker( pointLatLng, description )
{
  numCalls++;
  timeout = delay * numCalls;
  setTimeout("addRawLatLongMarker("+pointLatLng+",'"+description+"');",  timeout);
}

function addAddressMarker( address, description )
{
  numCalls++;
  timeout = delay * numCalls;
  setTimeout("addRawAddressMarker('"+address+"','"+description+"');",  timeout);
}

function addRawAddressMarker(address, description)
{
  jQuery('#'+mapId).jmap('SearchAddress', {
      'query': address,
      'returnType': 'getLocations'
  }, function(result, options) {
      var valid = Mapifies.SearchCode(result.Status.code);
      if (valid.success) {
      jQuery.each(result.Placemark, function(i, point){
          jQuery('#'+mapId).jmap('AddMarker',{
                  'pointLatLng':[point.Point.coordinates[1], point.Point.coordinates[0]],
                  'pointHTML':description
              });
          });
      } else {
          //jQuery('#address').val(valid.message);
      }
  });
}

function addRawLatLongMarker(pointLatLng, description)
{
		jQuery('#'+mapId).jmap('AddMarker', {
  			'pointLatLng': pointLatLng,
  			'pointHTML': description,
  			'centerMap': false
  		}, function( marker, options){
		});
}
