function loadProvince( province, country ) {
  showMap( province + ',' + country, '', 4 );
}

function loadCity( city, province, country ) {
  showMap( city + ',' + province + ',' + country, '', 7 ); //'<DIV style="height: 40px;" class="popup"><CENTER><B style="text-shadow: 2px 2px 3px #DDD; font-size: 16px; font-family: Verdana; color: #2AC;">' + city + '</B><BR>' + province + '</CENTER></DIV>' );
}

function loadRecord( name, address, city, province, postalcode, country, phone ) {
  showMap( address + ',' + city + ',' + province + ',' + postalcode + ',' + country, '<DIV class="popup"><CENTER><B style="text-shadow: 2px 2px 3px #DDD; font-size: 16px; font-family: Verdana; color: #2AC;">' + name + '</B></CENTER><BR>' + address + '<BR>' + city + ', ' + postalcode + '<BR>' + province + ', ' + country + '<BR>' + phone + '</DIV>', 13 );
}

function showMap( gaddress, popup, zoomSize ) {
  var geocoder = new google.maps.Geocoder();
  geocoder.geocode( {'address': gaddress}, function( results, status ) {
    if( status == google.maps.GeocoderStatus.OK ) {
      var latlng = results[0].geometry.location;
      var myOptions = {
        zoom:      zoomSize,
        center:    latlng,
        mapTypeId: google.maps.MapTypeId.ROADMAP
      };
      var map = new google.maps.Map( document.getElementById( 'map' ), myOptions );

      var marker = new google.maps.Marker( {
          map: map,
          position: results[0].geometry.location
      } );

      if( popup != "" ) {
        var infowindow = new google.maps.InfoWindow();
        infowindow.setContent( popup );
        infowindow.open( map, marker );
      }

      var adUnitDiv = document.createElement( 'div' );
      var adUnitOptions = {
        format:   google.maps.adsense.AdFormat.SMALL_RECTANGLE,
        position: google.maps.ControlPosition.TOP_LEFT,
        map: map,
        visible: true,
        publisherId: 'pub-3337468147769261'
      }
      var adUnit = new google.maps.adsense.AdUnit( adUnitDiv, adUnitOptions );
    } else {
      document.getElementById( 'map_not_found' ).innerHTML = 'Unfortunatuly, Google wasn\'t able to find studio location';
    }
  } );
}

