    var map;
    var geocoder;
    var learningCenter;
    var phone;
    var learningCenterNames = new Array(10);
    var learningCenterCount=0;
    var currentLearningCenterIndex=0;
    var markerBounds;
    var fromAddress;
    learningCenter = 'University of Phoenix';
  
  //initialize --
  //set the Default map to Main Campus -- 4615 E Elwood St, Phoenix, AZ 85040
    function initialize() {
 
      map = new GMap2(document.getElementById("map_container"));
    map.addControl(new GSmallMapControl());
    map.addControl(new GMapTypeControl());
    map.setCenter(new GLatLng(33.413025, -111.982443), 13); 
    markerBounds = new GLatLngBounds();
    //GClientGeocoder --This class is used to communicate directly with Google servers to obtain geocodes for user specified addresses
    geocoder = new GClientGeocoder();  
    }


    // addAddressToMap() is called when the geocoder returns an
    // answer.  It adds a marker to the map with an open info window
    // showing the nicely formatted version of the address.
    function addAddressToMap(response) {
    
        var selectedLearningCenterInfo;
        
        map.clearOverlays();
  

      //create UOP marker icon
    var UOPIcon = new GIcon(G_DEFAULT_ICON);
    UOPIcon.image = "../img/PNG/upxflag3.png";
    //UOPIcon.image = "http://www.google.com/intl/en_us/mapfiles/ms/micons/red-dot.png"
    UOPIcon.iconSize = new GSize(32, 32);
    //set up our GMarkerOptions object
    markerOptions = { icon:UOPIcon };
  
      if (!response || response.Status.code != 200) {
        //alert("Sorry, we were unable to geocode that address");
      } else {
        place = response.Placemark[0];
        point = new GLatLng(place.Point.coordinates[1],
                            place.Point.coordinates[0]);
                                                      
        var lngAddress = place.address;
        var aryAddress = lngAddress.split(",");
        var learningCenterAddress ='';
        
        strAddress = aryAddress[0] + ',';
        strAddress2 = aryAddress[0] + '<br>';
        lngAddress = lngAddress.replace(strAddress,strAddress2);
                                  
        //set the window message
        selectedLearningCenterInfo = '<b>' + learningCenter + '</b><p>' + lngAddress + '<br>' + phone + ' Local</p>';
        
        //add the Red Dot marker                                        
        marker = new GMarker(point,markerOptions);
        map.addOverlay(marker);
        marker.openInfoWindowHtml(selectedLearningCenterInfo);
         
        //add event listener.. when the marker is clicked, show the window.
        GEvent.addListener(marker, "click", function() {
             marker.openInfoWindowHtml(selectedLearningCenterInfo);
        });

      }
    }

    //getLearningCenterLocation(address,learningCenterName)-pass the selected learning center
    //address to getLocations() to get map location. The response from google will pass to addAddressToMap.
    function getLearningCenterLocation(address,learningCenterName, phonelocal) {
      learningCenter = learningCenter + '<br>- ' + learningCenterName.replace("%92","'"); 
      phone = phonelocal;
      geocoder.getLocations(address.replace("%92","'"), addAddressToMap);
    }
    
    function addLearningCenters(itemList) {
    	for(i = 0; i < itemList.length; i++){
    		var currentItem = itemList[i];
        	point = new GLatLng(currentItem.lat, currentItem.lng);
        	marker = new GMarker(point);
            
            //Add the campus into the map
            map.addOverlay(marker);
            marker.bindInfoWindowHtml(currentItem.popupHtml);
            markerBounds.extend(point);
    	}
    	
        //Reset the center of the map using GLatLngBounds
        map.setCenter(markerBounds.getCenter(), map.getBoundsZoomLevel(markerBounds));
    }
  
/********************************************************/
/*** Multiple Locations                             ***/

    function initializeState(CityState) 
    {
      map = new GMap2(document.getElementById("map_container"));
    map.addControl(new GSmallMapControl());
    map.addControl(new GMapTypeControl());
        geocoder = new GClientGeocoder(); 
      geocoder.getLocations(CityState.replace("%92","'"), getCenterPoint);  
          
    }
    
    
   function getLearningCenterLocationByState(LearningCenterList) {
      arLearningCenterList = LearningCenterList.split("|");
      currentLearningCenterIndex = 0;
      //Pass the learning center list one by one to get the location position      
     for (var i = 0; i < arLearningCenterList.length; i++) { 
     
        arLearningCenter = arLearningCenterList[i].split("-");
        
        learningCenterNames[i] ="<a href='" + arLearningCenter[0] + "'>University of Phoenix - " + arLearningCenter[1] + "</a>";
            var address = arLearningCenter[2];

            if(address !=""){      
                geocoder.getLocations(address, addAddressToUSMap);
                //learningCenter = learningCenter + '<br>- ' + learningCenterName.replace("%92","'"); 
             }
         }
    }
    
    //*******************************************************************************/
    // addAddressToUSMap() is called when the geocoder returns an
    // answer.  It adds a marker to the map with an open info window
    //*******************************************************************************/
        function addAddressToUSMap(response) {
    
            var selectedLearningCenterInfo; 
        
      //*** create UOP marker icon ****
            var UOPIcon = new GIcon(G_DEFAULT_ICON);
            UOPIcon.image = "../img/PNG/upxflag.png";
            UOPIcon.iconSize = new GSize(32, 32); 
    
        //set up our GMarkerOptions object
        markerOptions = { icon:UOPIcon };
          
            if (!response || response.Status.code != 200) {
                //alert("Sorry, we were unable to geocode that address");
            }
            else
            {
                place = response.Placemark[0];
                point = new GLatLng(place.Point.coordinates[1],
                                    place.Point.coordinates[0]);  
                                                                       
                var longAdddress = place.address;
                var aryAddress = longAdddress.split(",");
                longAdddress = aryAddress[0] + ', ' + aryAddress[1] + '<br>' + aryAddress[2];
                   
                //set the window message
                 selectedLearningCenterInfo = '<b>' + learningCenterNames[currentLearningCenterIndex] + '</b><p>' + longAdddress + '</p>';     
                //alert(selectedLearningCenterInfo);
                //add the Red Dot marker                                        
                var marker = new GMarker(point,markerOptions);
                map.addOverlay(marker);
                map.setZoom(9);
                 
                //add event listener.. when the marker is clicked, show the window.
                GEvent.addListener(marker, "click", function() {
                     marker.openInfoWindowHtml(selectedLearningCenterInfo);
                });
                
              }
              currentLearningCenterIndex=currentLearningCenterIndex+1;
        }    
            
    function getCenterPoint(response) {
    
     if (!response || response.Status.code != 200) {
        alert("Sorry, we were unable to geocode that address");
      } else {
            place = response.Placemark[0];
            point = new GLatLng(place.Point.coordinates[1],
                                place.Point.coordinates[0]);                                                   
            map.setCenter(new GLatLng(place.Point.coordinates[1], place.Point.coordinates[0]), 13); 

      }
    
    }
    
// This method will be called by the UI to display directions
// It will collect the from address and to address and then calls DisplayDirections to display
// the driving directions 
function GetDirections(from, to) 
{
    var toAddress;
    
    fromAddress = document.getElementById("txtFrom").value;
    toAddress= document.getElementById("txtTo").value;
    
    DisplayDirections(fromAddress, toAddress);
}
var map;
// This method will call google API methods to display directions
function DisplayDirections(FromAddress, ToAddress)
{
    var directionsPanel = document.getElementById("map_directions");
    directionsPanel.innerHTML="";
    map.addControl(new GSmallMapControl());
    map.addControl(new GMapTypeControl());
    directions = new GDirections(map, directionsPanel);
    directions.load(FromAddress + " to " + ToAddress);
}

function printDirections(printPage){
	if(fromAddress != null && fromAddress.length > 0){
		window.open(printPage + '?from=' + fromAddress, 'printDirections');
	} else {
		var fromAddrField = $('form#location_form input#txtFrom');
		fromAddrField.removeClass('initialSearch');
		fromAddrField.addClass('errorSearch');
		fromAddrField.val('Please enter the start address');
	}
}
function resizeMap()
{
  if (map)
    map.checkResize();
}

function checkEnterKey(event, link){
  var key;
  if(window.event)
    key = window.event.keyCode;     //IE
  else 
    key = event.which;    //firefox
  
  if(key == 13){
    link.onclick();
    return false;
  } else
    return true;
}