//Edited by Mfenoglio ( overlay fijo , en refresh no funcionaba )

function GoogleCreateMarker(point, title,pointicon) {

  // Create our "tiny" marker icon
  var blueIcon = new GIcon(G_DEFAULT_ICON);
  blueIcon.image = pointicon;
  switch(pointicon)
        {   
            case "Blue":
		    blueIcon.image = "http://gmaps-samples.googlecode.com/svn/trunk/markers/blue/blank.png";
                    break;
            case "Green":
 		    blueIcon.image = "http://gmaps-samples.googlecode.com/svn/trunk/markers/green/blank.png";
                    break;
            case "Orange":
                    blueIcon.image = "http://gmaps-samples.googlecode.com/svn/trunk/markers/orange/blank.png";
		    break;
            case "Red":
		    blueIcon.image = "http://gmaps-samples.googlecode.com/svn/trunk/markers/red/blank.png";
                    break;
            case "Pink":
		    blueIcon.image = "http://gmaps-samples.googlecode.com/svn/trunk/markers/pink/blank.png";
                    break;
            case "BlueC":
		    blueIcon.image = "http://gmaps-samples.googlecode.com/svn/trunk/markers/circular/bluecirclemarker.png";
                    break;
            case "GreenC":
		    blueIcon.image = "http://gmaps-samples.googlecode.com/svn/trunk/markers/circular/greencirclemarker.png";
                    break;
            case "YellowC":
		    blueIcon.image = "http://gmaps-samples.googlecode.com/svn/trunk/markers/circular/yellowcirclemarker.png";
                    break;
            default:
		    blueIcon.image = pointicon;
                    break;

        }
    blueIcon.iconSize = new GSize(15, 20);
    blueIcon.shadowSize = new GSize(15, 20);
    blueIcon.iconAnchor = new GPoint(15, 20);
    blueIcon.infoWindowAnchor = new GPoint(15, 2);
    blueIcon.infoShadowAnchor = new GPoint(15, 20);
	
    
    // Set up our GMarkerOptions object
       markerOptions = { icon:blueIcon  };
    var marker = new GMarker(point, markerOptions);
    GEvent.addListener(marker, "click", function() {marker.openInfoWindowHtml(title);});
  return marker;
}

function GoogleMapSetCenter( GoogleMapControl)
{
	
	//alert('Centrar');
    var mapControl = GoogleMapControl;
    var map = mapControl.map;
    Coord = mapControl.City;
    Coord = Coord.split(',');
    if (Coord!="0,0") 
        map.setCenter(new GLatLng(Coord[0],Coord[1]), parseInt(mapControl.Precision));
    else 
        map.setCenter(new GLatLng(mapControl.Latitude,mapControl.Longitude), parseInt(mapControl.Precision));
}
function GoogleShow(GoogleMapControl){
	//alert('Show');
    var mapControl=GoogleMapControl;
    var points = new Array();
        google.load("maps", "2", {callback: function()
        {
          {

	
	if (mapControl.Width=='100'){

			var myHeight = 0;

			if( typeof( window.innerWidth ) == 'number' ) {
				myHeight = window.innerHeight;
			} else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
				myHeight = document.documentElement.clientHeight;
			} else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
				myHeight = document.body.clientHeight;
			}

			myHeight = myHeight - 126;

			document.getElementById(mapControl.ContainerName).innerHTML = '<div id="' + mapControl.ContainerName + '_MAP" style="width: 100%; height: ' + myHeight + 'px"></div>';

	}else{
		document.getElementById(mapControl.ContainerName).innerHTML = '<div id="' + mapControl.ContainerName + '_MAP" style="width: ' + mapControl.Width + 'px; height: ' + mapControl.Height + 'px"></div>';
	}
    if (GBrowserIsCompatible()) {
                  var map = new google.maps.Map2(document.getElementById(mapControl.ContainerName + '_MAP'));

                  GoogleMapControl.map = map;
       
                  GoogleMapSetCenter( GoogleMapControl);

        // Controls
		if (mapControl.Small_Control==CONTROL_SMALL_VISIBLE) map.addControl(new google.maps.SmallMapControl());
		if (mapControl.Type_Control==CONTROL_TYPE_VISIBLE) map.addControl(new google.maps.MapTypeControl());
		if (mapControl.OverView_Control==CONTROL_OVERVIEW_VISIBLE) map.addControl(new google.maps.OverviewMapControl());
		if (mapControl.Large_Control==CONTROL_LARGE_VISIBLE) map.addControl(new google.maps.LargeMapControl());
		if (mapControl.Small_Zoom_Control==CONTROL_SMALL_ZOOM_VISIBLE) map.addControl(new google.maps.SmallZoomControl()); 
		if (mapControl.Scale_Control==CONTROL_SCALE_VISIBLE)  map.addControl(new google.maps.ScaleControl());

		map.enableScrollWheelZoom(); 

        // Map Type
        var x= map.getMapTypes(); 

        switch (mapControl.Type)
        {
            case TYPE_NORMAL:
                map.setMapType(x[0]);        
                break;
            case TYPE_SATELLITE:
                map.setMapType(x[1]);
                break;
            case TYPE_HYBRID:             
                map.setMapType(x[2]);
                break;
        }
	if ((GoogleMapControl.IsPostBack) && ((mapControl.Onclick == 'getvalue') || (mapControl.Onclick == 'getvalue_center')))
	  {
	    GEvent.addListener(map, "click", function(overlay, point) {
		//alert('overlay')
		
	    if (! overlay)
		 {
			map.clearOverlays()
            if (mapControl.Clear_Overlay==true) map.clearOverlays();

		    infowin2 = "<B>Latitude: </B>" + point.lat() + "<Br>";
                    infowin2 += "<B>Longitude: </B>" + point.lng() + "<Br>";
	     	    mapControl.getlatitude= point.lat();
	            mapControl.getlongitude=  point.lng();
		    pointicon2 = mapControl.getIcon;
		    //pointicon2 = "Orange"; 
		    map.addOverlay( GoogleCreateMarker(point,infowin2,pointicon2) );
	   if (mapControl.Onclick == 'getvalue_center')
		 map.setCenter(new GLatLng(mapControl.getlatitude,mapControl.getlongitude), parseInt(map.getZoom()));
	         }
	    });
	  }
       // Points
        var point;
        var infowin;
        for(var i=0;mapControl.GoogleMap.Points[i]!=undefined;i++){
            point = new GLatLng(mapControl.GoogleMap.Points[i].PointLat, mapControl.GoogleMap.Points[i].PointLong);
            infowin = "<B>" + mapControl.GoogleMap.Points[i].PointInfowinTit + "</B><Br>";
            infowin += mapControl.GoogleMap.Points[i].PointInfowinDesc + "<Br>";
			
            if(mapControl.GoogleMap.Points[i].PointInfowinLink != "") 
               {
			   var re=/^http:\/\/\w+(\.\w+)*\.\w{2,3}$/; 
			if (re.test(mapControl.GoogleMap.Points[i].PointInfowinLink))
			{
				
				infowin += "<A HREF=" + mapControl.GoogleMap.Points[i].PointInfowinLink 
				if (mapControl.OpenLinksInNewWindow == "OpenNew_True")
					{
						//infowin += ' target="_blank"'vm comenta						
					}
				infowin += ">" + mapControl.GoogleMap.Points[i].PointInfowinLinkDsc + "</A>" + "<Br><Br>";
			}
			  
			  else
			  {
				
				infowin += "<A HREF=" + mapControl.GoogleMap.Points[i].PointInfowinLink 
				if (mapControl.OpenLinksInNewWindow == "OpenNew_True")
					{
// 						//infowin += ' target="_blank"'  //vmcomenta
							
					}
				infowin += ">" + mapControl.GoogleMap.Points[i].PointInfowinLinkDsc + "</A>" + "<Br><Br>";
				   }
			  
			  }
			   
			   
            var varUrl = mapControl.GoogleMap.Points[i].PointInfowinImg;
            if(varUrl != "") infowin += "<img src=" + '"' + varUrl + '"' + "/>" + "<Br>";
            pointicon = mapControl.GoogleMap.Points[i].PointIcon;
            if (pointicon== "") pointicon=mapControl.Icon;
            map.addOverlay(GoogleCreateMarker(point,infowin,pointicon));       
			}
    }
}
   }});

}

