var map, curMarker;

function getIcon(opt) {
  
  var icon = new GIcon();
  
  switch (opt['icon']) {
  
    case 'city': icon.image = "/image/icon-point-place.png"; break; //icon-point-city
    case 'place': icon.image = "/image/icon-point-place.png"; break;
    
  }
  
  icon.shadow= "http://labs.google.com/ridefinder/images/mm_20_shadow.png";
  icon.iconSize = new GSize(19, 32);
  icon.shadowSize = new GSize(22, 20);
  icon.iconAnchor = new GPoint(9, 32);
  icon.infoWindowAnchor = new GPoint(9, 11);
  return icon;
}

function addCityProfile(city_id) {
  
  var req = new JsHttpRequest();
  
  req.onreadystatechange = function() {
    
    if (req.readyState == 4) {
      
      if (req.responseJS) {
        
        //var listCity = req.responseJS.list_city;
        
        if (parseInt(req.responseJS.num_city)) {
          
          //$_j('#my_city').empty();
          //
          //for (var key in listCity) {
          //  
          //  $_j('#my_city').append('<div><a href="city/' + listCity[key]['city_id'] +'/">' + listCity[key]['city_name'] +'</a> <small>(' + listCity[key]['city_country_name_code'] +')</small></div>');
          //
          //}
          
          var tmp = $_j('#was_here');
          
          if (tmp.length) tmp.empty().append(req.responseJS.was_here);
          
          $_j('#but_was_here').empty().hide();
          
          tmp = $_j('#was_city_search');
          if (tmp.length) tmp.empty().hide();
          
          alert('Город успешно добавлен в ваш профиль!');
        } else alert('Город ранее был добавлен в ваш профиль!');
      
      }
    }
  }
  
  req.caching = false; 
  req.open('POST', '/rs/add_city/', true);
  req.send({id: city_id});
  
}

function addPlaceProfile(place_id) {
  
  var req = new JsHttpRequest();
  
  req.onreadystatechange = function() {
    
    if (req.readyState == 4) {
      
      if (req.responseJS) {
        
        //var listPlace = req.responseJS.list_place;
        
        if (parseInt(req.responseJS.num_place)) {
          
        //  $_j('#my_city').empty();
          
        //  for (var key in listCity) {
        //    
        //    $_j('#my_city').append('<div><a href="city/' + listCity[key]['city_id'] +'/">' + listCity[key]['city_name'] +'</a> <small>(' + listCity[key]['city_country_name_code'] +')</small></div>');
        //  
        //  }
          //was_here
          var tmp = $_j('#was_here');
          
          if (tmp.length) tmp.empty().append(req.responseJS.was_here);
          
          $_j('#but_was_here').empty().hide();
          
          alert('Место успешно добавлено в ваш профиль!');
          
        } else alert('Это место ранее было добавлено в ваш профиль!');
      
      }
    }
  }
  
  req.caching = false; 
  req.open('POST', '/rs/add_place/', true);
  req.send({id: place_id});
  
}

function SearchControl() { }
  
SearchControl.prototype = new GControl(false, true);
  
SearchControl.prototype.initialize = function(map) {
  
  var obj = $_j('#search_form');
  
  obj.css('opacity', 0.9);
  
  obj = obj.get(0);
  
  map.getContainer().appendChild(obj);
  
  obj.style.display = 'block';
  
  return obj;
}

