var orgMkrs;
var geocoder;

$(document).ready( function() {


  $("#Col1 .object123").each( function() {
    $(this).children("div.text,div.object222").wrapAll(  $("<div class='Wrap'/>").hide() );
  });


  $("#Col1 .object123>h3").innerWrap( $("<a href='#'/>") ).bind("click", function() {
    $(this).toggleClass("Selected").next().slideToggle();
    return false;
  });


  return false;

});


function Initialize(Id) {

  MapId = Id;

  var mapOptions = {
      zoom: 2,
      center: new google.maps.LatLng(30, 0),
      mapTypeControl: false,
      scrollwheel: false,
      mapTypeId: google.maps.MapTypeId.ROADMAP
    };
    map = new google.maps.Map(document.getElementById(Id), mapOptions);

    orgMkrs = new Array();

}


function GetLocation(s) {
  var results = GetGeoCode(s);
  if (results != null && results.length > 0) {
    return results[0].geometry.location;
  }
  return null;
}

function GetGeoCode(s) {

    geocoder = new google.maps.Geocoder();

      geocoder.geocode( { "address" : s }, function(results, status) {
        if (status == google.maps.GeocoderStatus.OK) {
          return results;
        }

      });
    return null;
    geocoder = null;  
}

function InitProfileMap() {

  isSearch = false;

  var LatLng = new google.maps.LatLng( $("#ProfileMap").find("input:eq(0)").val() , $("#ProfileMap").find("input:eq(1)").val() );

  var data = new Array();
  data[0] = new Array();
  data[0]["Latitude"] = LatLng.lat();
  data[0]["Longitude"] = LatLng.lng();
  data[0]["Org"] = $("#ProfileMap").find("input:eq(2)").val();
  data[0]["Agency"] = $("#ProfileMap").find("input:eq(3)").val();
  data[0]["AgencyId"] = "";
  data[0]["Count"] = 1;


  $("#ProfileMap").html("");

  Initialize("ProfileMap"); 

  map.setCenter( LatLng );
  map.setZoom(13);

  
  var point = new google.maps.LatLng( data[0]["Latitude"] , data[0]["Longitude"] );

  var marker = new google.maps.Marker({
      position: point, 
      map: map,
      title: data[0]["Org"] + '\n' + data[0]["Agency"]
  });

  marker.setIcon( "/img/etlas-org-blue.png" );

}


function SubmitSearchForm(oBtn) {

  $(oBtn.form['__EVENTVALIDATION']).remove(); 
  $(oBtn.form['__VIEWSTATE']).remove(); 
  oBtn.form.method='GET'; 

  SetAjax('.OrgSearchResults', '.OrgSearchResults', oBtn.form);
  return false;
}
