var ie = document.all ? true : false;

var map;

// Create a base icon for all of our markers that specifies the
// shadow, icon dimensions, etc.
var baseIcon = new GIcon();
baseIcon.shadow = "http://www.google.com/mapfiles/shadow50.png";
baseIcon.iconSize = new GSize(20, 34);
baseIcon.shadowSize = new GSize(37, 34);
baseIcon.iconAnchor = new GPoint(9, 34);
baseIcon.infoWindowAnchor = new GPoint(9, 2);
baseIcon.infoShadowAnchor = new GPoint(18, 25);

var PdMarkers;

// in use !!!
function showGoogleMap (width, LocationInputStr) {
	

	
	// delete last own location if it was set earlier
	if(SubsidName.length > Nsub) {
		SubsidName.pop();
		SubsidAddress.pop();
	}
	
	// if own location should be included, add it to Subsid-Array
	if(LocationInputStr) {
		SubsidName.push(YourLocationText);
		SubsidAddress.push(LocationInputStr);
	}
	
	
	var MapStyle = "text-align:center; height:300px; border:1px solid gray; margin-bottom:20px;"
	
	if(!ie) {
		
		var OuterBox = document.getElementById("map1");
		//
		OuterStyle = document.createAttribute("style");
		OuterStyle.nodeValue = MapStyle;
		OuterBox.setAttributeNode(OuterStyle);
	
	}
	
	else {

		document.all["jsForm"].innerHTML = "";

		document.all["jsForm"].insertAdjacentHTML('AfterBegin', '<div id="map1" style="'+MapStyle+'"><div></div></div>');
	
	}
	

	if (GBrowserIsCompatible()) {
	
		map = new GMap2(document.getElementById("map1"));
		map.addControl(new GLargeMapControl());
		map.addControl(new GMapTypeControl());
		map.clearOverlays();

 
		var geocoder = new GClientGeocoder();
		
	
		// get geocodes for 'headquarter'
		geocoder.getLatLng(SubsidAddress[0],  function(point) {
										
					if (!point) {
						alert(NotFoundText+SubsidAddress[0]);
					} 
					else {
						map.setCenter(point, 12);
					}
			}
		);
		
	
		// get geocodes for all subsidaries, set markers
		for(var i=0; i<SubsidAddress.length; i++) { 

		
			geocoder.getLatLng(SubsidAddress[i],  function(point) {
										
					if (!point) {
						alert(NotFoundText+SubsidAddress[i]);
					} 
					else {
						
						
						// set internal counter
						if(map.pdMarkers) 
						var j = map.pdMarkers.length;
						else 
						var j=0;

	
						if(SubsidAddress[j] == LocationInputStr) {
						var icon = new GIcon(baseIcon);
						icon.image = Prefix+'app/map/icons/me_green_point.png';
						marker = new PdMarker(point, icon);
						}
						else 
						{
						marker = new PdMarker(point);
						}
						marker.setTooltip(SubsidName[j]+':<br>'+SubsidAddress[j]);
						
						GEvent.addListener(map, 'click', function(marker, point) {
							map.setCenter(marker.getPoint(), 12); 
						}
						);
											
						
						map.addOverlay(marker);
							// map.pdMarkers has properties here
						if(map.pdMarkers.length > 1 &&
						   map.pdMarkers.length == SubsidAddress.length) 
						map.zoomToMarkers(5,2);
						
						
					}
				}
			);
		

		}

		
	} // eof browser compatible
	
	
}


// not in use !!!
// Creates a marker at the given point with the given number label
function createMarker(point, string) {
		
		var marker = new GMarker(point);
		GEvent.addListener(marker, 'click', function() {
    		// openInfoWindow does not work for iframe/explorer
			marker.openInfoWindowHtml(string);
			//marker.openInfoWindow(document.createTextNode("Marker #<b>" + number + "</b>"));

  		});
		return marker;
}
