//bpWindow
var map;
var list;
var markers = new Array();
var iwOpener = null;
var iwOpening = false;
var load_method = (window.ie ? "load" : "domready");

function addMarker(id, lat, lng, ptName, ptType, ptDesc) {
		var latlng = new GLatLng(lat,lng);
	    var marker = new BpMarker(latlng);
		marker.setUserData({
		  'id': id,
		  'Name':	ptName,
		  'Point Type':	ptType,
		  'Description': '<div id="list" style="overflow: auto; width: 250px; height: 50px; margin-left: .45cm;">'+ptDesc+'</div>'
		});
		marker.setTooltipHtml(ptName);
		map.addOverlay(marker);
		if(tooltip) marker.showTooltip();
		list.add(marker);
		markers.push(marker);
		GEvent.addListener(marker,'click',onClick);
}

function onClick(){
	if(iwOpener === this) {
		map.closeInfoWindow();
		return;
	}
	map.closeInfoWindow();
	iwOpener  = this;
	var data = this.getUserData();
	var html = '<div><b>' + data['Name'] + '</b><br/>';
	for(prop in data)
		if(prop!='Name' && prop!='id') html += prop + ": " + data[prop] + "<br/>";
	this.openInfoWindowHtml(html);
	list.highlight(this, true);//BpBrowser.type == BpBrowser.OPERA);
}

function gotoAddress(address) {
	var geocoder = new GClientGeocoder();
	if(z==null) z=6;
    geocoder.getLocations(address, function(result) {
		if (result.Status.code == G_GEO_SUCCESS) {
			var place = result.Placemark[0];
			var zLevel = Math.min(z*place.AddressDetails.Accuracy,17);
			var center = new GLatLng(
				place.Point.coordinates[1],
				place.Point.coordinates[0]
			);
			map.setCenter(center, zLevel, G_HYBRID_MAP);
		} else {
			alert(address + " not found")
		}
	});
}

function addpoint( point ) 
{
   var str = point.toUrlValue().split(',');
   document.output_form.lat.value = str[0];
   document.output_form.lng.value = str[1];
}

//help
var help = true;
function hideHelp() {
	if(help) {
		document.getElementById('help').style.height='1px';
		document.getElementById('help').style.visibility='hidden';
		help = false;
	}
	else {
		document.getElementById('help').style.height='';
		document.getElementById('help').style.visibility='visible';
		help = true;
	}
}
