// ********************************************
// **        Flashmaps DB Mapper 4.0.1       **
// **       JavaScript API Functions         **
// ********************************************
// ** Please DO NOT make any changes here.   **
// ** You may want to chenge fmDBMCustom.js  **
// ********************************************
// **      (c)2008 Flashmaps Geospatial      **
// **        http://www.flashmaps.com        **
// ********************************************

// ********************************************
// **  Functions called from the map, events **
// ********************************************

	var fmMcPath = "dbm_mc.map_mc.";
	var fmPOIsLoaded = false;
	var fmPOIsURL = "";

// The map is ready to receive commands
function fmMapIsReady() {
	return document.getElementById("fmASEngine").GetVariable("_root." + fmMcPath + "map_mc.outMapIsReady");
}

// A POI event was triggered
function fmPOIEvent(eventName, fmPOIID) {
	switch (eventName) {
		case 'onrollover':
			break;
		case 'onrollout':
			break;
		case 'onrelease':
			break;
		default:
			break;
	}
}

// A set of POIs has been loaded
function fmPOIURLLoaded(strPOIsURL, iPOIsNumber) {
	fmPOIsLoaded = true;
	fmPOIsURL = strPOIsURL;
}

function fmGeometryEvent(eventName, geometryID) {
	switch(eventName) {
		case 'onrollover':
			break;
		case 'onrollout':
			break;
		case 'onrelease':
			break;
	}
}

// ********************************************
// **             Map properties             **
// ********************************************

// Get map latitude / longitude / scale
function fmGetMapLat()   { return document.getElementById("fmASEngine").GetVariable("_root." + fmMcPath + "map_mc.outLat"); }
function fmGetMapLon()   { return document.getElementById("fmASEngine").GetVariable("_root." + fmMcPath + "map_mc.outLon"); }
function fmGetMapScale() { return document.getElementById("fmASEngine").GetVariable("_root." + fmMcPath + "map_mc.outScale"); }

// Get current view's minimum latitude, longitude, maximum latitude and longitude
function fmGetMapViewMinLat() { return document.getElementById("fmASEngine").GetVariable("_root." + fmMcPath + "map_mc.outViewMinLat"); }
function fmGetMapViewMaxLat() { return document.getElementById("fmASEngine").GetVariable("_root." + fmMcPath + "map_mc.outViewMaxLat"); }
function fmGetMapViewMaxLon() {	return document.getElementById("fmASEngine").GetVariable("_root." + fmMcPath + "map_mc.outViewMaxLon"); }
function fmGetMapViewMinLon() {	return document.getElementById("fmASEngine").GetVariable("_root." + fmMcPath + "map_mc.outViewMinLon"); }

//GET current view the latitude/longitude of the corners
function fmGetMapViewSWLat() { return document.getElementById("fmASEngine").GetVariable("_root." + fmMcPath + "map_mc.outViewSWLat"); }
function fmGetMapViewNWLat() { return document.getElementById("fmASEngine").GetVariable("_root." + fmMcPath + "map_mc.outViewNWLat"); }
function fmGetMapViewSELat() { return document.getElementById("fmASEngine").GetVariable("_root." + fmMcPath + "map_mc.outViewSELat"); }
function fmGetMapViewNELat() { return document.getElementById("fmASEngine").GetVariable("_root." + fmMcPath + "map_mc.outViewNELat"); }
function fmGetMapViewSWLon() { return document.getElementById("fmASEngine").GetVariable("_root." + fmMcPath + "map_mc.outViewSWLon"); }
function fmGetMapViewNWLon() { return document.getElementById("fmASEngine").GetVariable("_root." + fmMcPath + "map_mc.outViewNWLon"); }
function fmGetMapViewSELon() { return document.getElementById("fmASEngine").GetVariable("_root." + fmMcPath + "map_mc.outViewSELon"); }
function fmGetMapViewNELon() { return document.getElementById("fmASEngine").GetVariable("_root." + fmMcPath + "map_mc.outViewNELon"); }

// ********************************************
// **  Functions to send commands to the map **
// ********************************************

//Execute a POI event
function fmPOIEventTrigger(strEvent, strTarget, strUrl, fmPOIID) {
	if (fmPOIsLoaded) {
		document.getElementById("fmASEngine").SetVariable("_root." + fmMcPath + "map_mc.fromOutsideEvent", strEvent); 
		document.getElementById("fmASEngine").SetVariable("_root." + fmMcPath + "map_mc.fromOutsideTarget", strTarget); 
		document.getElementById("fmASEngine").SetVariable("_root." + fmMcPath + "map_mc.fromOutsideUrl", strUrl); 
		document.getElementById("fmASEngine").SetVariable("_root." + fmMcPath + "map_mc.fromOutsidePOIID", fmPOIID); 
		document.getElementById("fmASEngine").SetVariable("_root." + fmMcPath + "map_mc.fromOutsideAction", "POIEventTrigger"); 
		document.getElementById("fmASEngine").TCallLabel("_root." + fmMcPath + "map_mc.fromOutside_mc", "doAction");
	}
}

// Highlight a POI
function fmPOIHighlight(fmPOIID, strMethod) {
	if (fmPOIsLoaded) {
		document.getElementById("fmASEngine").SetVariable("_root." + fmMcPath + "map_mc.fromOutsidePOIID", fmPOIID); 
		document.getElementById("fmASEngine").SetVariable("_root." + fmMcPath + "map_mc.fromOutsideAction", "highlightPOI"); 
		document.getElementById("fmASEngine").SetVariable("_root." + fmMcPath + "map_mc.fromOutsideHighlightMethod", strMethod); 
		document.getElementById("fmASEngine").TCallLabel("_root." + fmMcPath + "map_mc.fromOutside_mc", "doAction");
	}
}

// Unhighlight a POI
function fmPOIUnhighlight(fmPOIID) {
	if (fmPOIsLoaded) {
		document.getElementById("fmASEngine").SetVariable("_root." + fmMcPath + "map_mc.fromOutsidePOIID", fmPOIID);
		document.getElementById("fmASEngine").SetVariable("_root." + fmMcPath + "map_mc.fromOutsideAction", "unhighlightPOI"); 
		document.getElementById("fmASEngine").TCallLabel("_root." + fmMcPath + "map_mc.fromOutside_mc", "doAction");
	}
}

// Unhighlight all
function fmPOIUnhighlightAll() {
	document.getElementById("fmASEngine").SetVariable("_root." + fmMcPath + "map_mc.fromOutsideAction", "unhighlightAll"); 
	document.getElementById("fmASEngine").TCallLabel("_root." + fmMcPath + "map_mc.fromOutside_mc", "doAction");
}

// Highlight and focus on a POI
function fmPOIHighlightAndFocusOn(fmPOIID, strMapScale, strMethod){
	if (fmPOIsLoaded) {
		document.getElementById("fmASEngine").SetVariable("_root." + fmMcPath + "map_mc.fromOutsidePOIID", fmPOIID); 
		document.getElementById("fmASEngine").SetVariable("_root." + fmMcPath + "map_mc.fromOutsideScale", strMapScale); 
		document.getElementById("fmASEngine").SetVariable("_root." + fmMcPath + "map_mc.fromOutsideAction", "highlightAndFocusOnPOI"); 
		document.getElementById("fmASEngine").SetVariable("_root." + fmMcPath + "map_mc.fromOutsideHighlightMethod", strMethod); 
		document.getElementById("fmASEngine").TCallLabel("_root." + fmMcPath + "map_mc.fromOutside_mc", "doAction");
	}
}

// Focus on a certain point, lat/lon.
function fmFocusOnLatLon(strLat, strLon, strMapScale) {
	if (fmMapIsReady()) {
		document.getElementById("fmASEngine").SetVariable("_root." + fmMcPath + "map_mc.fromOutsideLat", strLat); 
		document.getElementById("fmASEngine").SetVariable("_root." + fmMcPath + "map_mc.fromOutsideLon", strLon);
		document.getElementById("fmASEngine").SetVariable("_root." + fmMcPath + "map_mc.fromOutsideScale", strMapScale); 
		document.getElementById("fmASEngine").SetVariable("_root." + fmMcPath + "map_mc.fromOutsideAction", "FocusOnLatLon"); 
		document.getElementById("fmASEngine").TCallLabel("_root." + fmMcPath + "map_mc.fromOutside_mc", "doAction");
	}
}

//Focus on a Scale
function fmFocusOnScale(strMapScale) {
	if (fmMapIsReady()) {
		document.getElementById("fmASEngine").SetVariable("_root." + fmMcPath + "map_mc.fromOutsideScale", strMapScale); 
		document.getElementById("fmASEngine").SetVariable("_root." + fmMcPath + "map_mc.fromOutsideAction", "FocusOnScale"); 
		document.getElementById("fmASEngine").TCallLabel("_root." + fmMcPath + "map_mc.fromOutside_mc", "doAction");
	}
}

// Focus on a min/max lat/lon.
function fmFocusOnMinMax(strMinLat, strMinLon, strMaxLat, strMaxLon) {
	if (fmMapIsReady()) {
		document.getElementById("fmASEngine").SetVariable("_root." + fmMcPath + "map_mc.fromOutsideMinLat", strMinLat); 
		document.getElementById("fmASEngine").SetVariable("_root." + fmMcPath + "map_mc.fromOutsideMinLon", strMinLon);
		document.getElementById("fmASEngine").SetVariable("_root." + fmMcPath + "map_mc.fromOutsideMaxLat", strMaxLat); 
		document.getElementById("fmASEngine").SetVariable("_root." + fmMcPath + "map_mc.fromOutsideMaxLon", strMaxLon);
		document.getElementById("fmASEngine").SetVariable("_root." + fmMcPath + "map_mc.fromOutsideAction", "FocusOnMinMax"); 
		document.getElementById("fmASEngine").TCallLabel("_root." + fmMcPath + "map_mc.fromOutside_mc", "doAction");
	}
}

function fmFocusOnAllPOIs(strCategory) {
//do: Focus on the POIs of a particular category or on all of them

	if (fmPOIsLoaded) {
		if (strCategory == "") {strCategory = "*";}
		document.getElementById("fmASEngine").SetVariable("_root." + fmMcPath + "map_mc.fromOutsideCategory", strCategory);
		document.getElementById("fmASEngine").SetVariable("_root." + fmMcPath + "map_mc.fromOutsideAction", "FocusOnAllPOIs"); 
		document.getElementById("fmASEngine").TCallLabel("_root." + fmMcPath + "map_mc.fromOutside_mc", "doAction");
	}
}

//Focus on an address
function fmFocusOnAddress(strAddress, strCity, strState, strZipCode, strCountry) {
	if (fmMapIsReady()) {
		document.getElementById("fmASEngine").SetVariable("_root." + fmMcPath + "map_mc.fromOutsideAddress", strAddress);
		document.getElementById("fmASEngine").SetVariable("_root." + fmMcPath + "map_mc.fromOutsideCity", strCity);
		document.getElementById("fmASEngine").SetVariable("_root." + fmMcPath + "map_mc.fromOutsideState", strState);
		document.getElementById("fmASEngine").SetVariable("_root." + fmMcPath + "map_mc.fromOutsideZipCode", strZipCode);
		document.getElementById("fmASEngine").SetVariable("_root." + fmMcPath + "map_mc.fromOutsideCountry", strCountry);
		document.getElementById("fmASEngine").SetVariable("_root." + fmMcPath + "map_mc.fromOutsideAction", "FocusOnAddress"); 
		document.getElementById("fmASEngine").TCallLabel("_root." + fmMcPath + "map_mc.fromOutside_mc", "doAction");
	}
}

// Highlight on a certain lat/lon.
function fmHighlightLatLon(strLat, strLon) {
	if (fmMapIsReady()) {
		document.getElementById("fmASEngine").SetVariable("_root." + fmMcPath + "map_mc.fromOutsideLat", strLat); 
		document.getElementById("fmASEngine").SetVariable("_root." + fmMcPath + "map_mc.fromOutsideLon", strLon);
		document.getElementById("fmASEngine").SetVariable("_root." + fmMcPath + "map_mc.fromOutsideAction", "highlightLatLon"); 
		document.getElementById("fmASEngine").TCallLabel("_root." + fmMcPath + "map_mc.fromOutside_mc", "doAction");
	}
}

// Show category (* for all)
function fmPOIShowCategory(strCategory) {
	if (fmPOIsLoaded) {
		document.getElementById("fmASEngine").SetVariable("_root." + fmMcPath + "map_mc.fromOutsideCategory", strCategory); 
		document.getElementById("fmASEngine").SetVariable("_root." + fmMcPath + "map_mc.fromOutsideAction", "showCategory"); 
		document.getElementById("fmASEngine").TCallLabel("_root." + fmMcPath + "map_mc.fromOutside_mc", "doAction");
	}
}

// Hide category (* for all)
function fmPOIHideCategory(strCategory) {
	if (fmPOIsLoaded) {
		document.getElementById("fmASEngine").SetVariable("_root." + fmMcPath + "map_mc.fromOutsideCategory", strCategory); 
		document.getElementById("fmASEngine").SetVariable("_root." + fmMcPath + "map_mc.fromOutsideAction", "hideCategory"); 
		document.getElementById("fmASEngine").TCallLabel("_root." + fmMcPath + "map_mc.fromOutside_mc", "doAction");
	}
}

// Show a POI
function fmPOIShow(id_str) {
	if (fmPOIsLoaded) {
		document.getElementById("fmASEngine").SetVariable("_root." + fmMcPath + "map_mc.fromOutsidePOIID", id_str); 
		document.getElementById("fmASEngine").SetVariable("_root." + fmMcPath + "map_mc.fromOutsideAction", "showPOI"); 
		document.getElementById("fmASEngine").TCallLabel("_root." + fmMcPath + "map_mc.fromOutside_mc", "doAction");
	}
}

// Hide a POI
function fmPOIHide(id_str) {
	if (fmPOIsLoaded) {
		document.getElementById("fmASEngine").SetVariable("_root." + fmMcPath + "map_mc.fromOutsidePOIID", id_str); 
		document.getElementById("fmASEngine").SetVariable("_root." + fmMcPath + "map_mc.fromOutsideAction", "hidePOI"); 
		document.getElementById("fmASEngine").TCallLabel("_root." + fmMcPath + "map_mc.fromOutside_mc", "doAction");
	}
}

// Show cross hair
function fmShowCrossHair() {
	if (fmMapIsReady()) {
		document.getElementById("fmASEngine").SetVariable("_root." + fmMcPath + "map_mc.fromOutsideAction", "showCrossHair");
		document.getElementById("fmASEngine").TCallLabel("_root." + fmMcPath + "map_mc.fromOutside_mc", "doAction");
	}
}

// Hide cross hair
function fmHideCrossHair() {
	if (fmMapIsReady()) {
		document.getElementById("fmASEngine").SetVariable("_root." + fmMcPath + "map_mc.fromOutsideAction", "hideCrossHair"); 
		document.getElementById("fmASEngine").TCallLabel("_root." + fmMcPath + "map_mc.fromOutside_mc", "doAction");
	}
}

// Load a set of POIs
function fmPOILoadURL(strPOIsURL) {
	if (fmMapIsReady()) {
		fmPOIsURL = strPOIsURL;
		document.getElementById("fmASEngine").SetVariable("_root." + fmMcPath + "map_mc.fromOutsidePOIsURL", strPOIsURL); 
		document.getElementById("fmASEngine").SetVariable("_root." + fmMcPath + "map_mc.fromOutsideAction", "loadPOIsURL"); 
		document.getElementById("fmASEngine").TCallLabel("_root." + fmMcPath + "map_mc.fromOutside_mc", "doAction");
	}
}

// Load a set of POIs
function fmPOILoadURLAndFocus(strPOIsURL) {
	if (fmMapIsReady()) {
		fmPOIsURL = strPOIsURL;
		document.getElementById("fmASEngine").SetVariable("_root." + fmMcPath + "map_mc.fromOutsidePOIsURL", strPOIsURL); 
		document.getElementById("fmASEngine").SetVariable("_root." + fmMcPath + "map_mc.fromOutsideAction", "loadPOIsURLAndFocus"); 
		document.getElementById("fmASEngine").TCallLabel("_root." + fmMcPath + "map_mc.fromOutside_mc", "doAction");
	}
}

// Remove all POIs
function fmPOIRemoveAll() {
	if (fmPOIsLoaded) {
		document.getElementById("fmASEngine").SetVariable("_root." + fmMcPath + "map_mc.fromOutsideAction", "removeAllPOIs"); 
		document.getElementById("fmASEngine").TCallLabel("_root." + fmMcPath + "map_mc.fromOutside_mc", "doAction");		
		fmPOIsLoaded = false;
	}
}

// Remove all POIs of a category
function fmPOIRemoveCategory(strCategory) {
	if (fmPOIsLoaded) {
		document.getElementById("fmASEngine").SetVariable("_root." + fmMcPath + "map_mc.fromOutsideCategory", strCategory); 
		document.getElementById("fmASEngine").SetVariable("_root." + fmMcPath + "map_mc.fromOutsideAction", "removeCategory"); 
		document.getElementById("fmASEngine").TCallLabel("_root." + fmMcPath + "map_mc.fromOutside_mc", "doAction");		
	}
}

// Load an set of POIs for the administration tool
function fmAdminPOILoadURL(strFile)  {
	if (fmMapIsReady()) {
		document.getElementById("fmASEngine").SetVariable("_root." + fmMcPath + "mcAddPlugging.fromOutsideXML", strFile); 
		document.getElementById("fmASEngine").TCallLabel("_root." + fmMcPath + "mcAddPlugging.adminFromOutside_mc", "doAction");
	}
}

// Initial view of the map
function fmInitialView() {
	document.getElementById("fmASEngine").SetVariable("_root." + fmMcPath + "map_mc.fromOutsideAction", "initialView");
	document.getElementById("fmASEngine").TCallLabel("_root." + fmMcPath + "map_mc.fromOutside_mc", "doAction");
}

// ********************************************
// **              Miscellaneous             **
// ********************************************

// Check string, for navigator version
function fmCheckString(str_find, str) {
	var result=-1;
	var re = new RegExp(str_find) ;

	if (str.search(re) != -1)
		result = 0;
	else
		result = -1;
	return result;
} 


// ********************************************
// **             Layer functions            **
// ********************************************

function fmLayerLoad(strLayer) {
//do: load and show a layer

	if (fmMapIsReady()) {
		document.getElementById("fmASEngine").SetVariable("_root." + fmMcPath + "map_mc.fromOutsideLayer", strLayer); 
		document.getElementById("fmASEngine").SetVariable("_root." + fmMcPath + "map_mc.fromOutsideAction", "customLayerLoad"); 
		document.getElementById("fmASEngine").TCallLabel("_root." + fmMcPath + "map_mc.fromOutside_mc", "doAction");
	}
}

function fmLayerRemove(strLayerID) {
//do: remove a layer

	if (fmMapIsReady()) {
		document.getElementById("fmASEngine").SetVariable("_root." + fmMcPath + "map_mc.fromOutsideLayer", strLayerID); 
		document.getElementById("fmASEngine").SetVariable("_root." + fmMcPath + "map_mc.fromOutsideAction", "customLayerRemove"); 
		document.getElementById("fmASEngine").TCallLabel("_root." + fmMcPath + "map_mc.fromOutside_mc", "doAction");
	}
}

function fmLayerShow(strLayerID) {
//do: show a layer or all '*'

	if (fmMapIsReady()) {
		document.getElementById("fmASEngine").SetVariable("_root." + fmMcPath + "map_mc.fromOutsideLayer", strLayerID); 
		document.getElementById("fmASEngine").SetVariable("_root." + fmMcPath + "map_mc.fromOutsideAction", "customLayerShow"); 
		document.getElementById("fmASEngine").TCallLabel("_root." + fmMcPath + "map_mc.fromOutside_mc", "doAction");
	}
}

function fmLayerHide(strLayerID) {
//do: hide a layer or all '*'
	
	if (fmMapIsReady()) {
		document.getElementById("fmASEngine").SetVariable("_root." + fmMcPath + "map_mc.fromOutsideLayer", strLayerID); 
		document.getElementById("fmASEngine").SetVariable("_root." + fmMcPath + "map_mc.fromOutsideAction", "customLayerHide"); 
		document.getElementById("fmASEngine").TCallLabel("_root." + fmMcPath + "map_mc.fromOutside_mc", "doAction");
	}
}

// ********************************************
// **          Geometry functions            **
// ********************************************

function fmGeometryLoad(strGeometryURL) {
//do: load a geometry url in XML format

	if (fmMapIsReady()) {
		document.getElementById("fmASEngine").SetVariable("_root." + fmMcPath + "map_mc.fromOutsideGeometry", strGeometryURL); 
		document.getElementById("fmASEngine").SetVariable("_root." + fmMcPath + "map_mc.fromOutsideAction", "geometryLoad"); 
		document.getElementById("fmASEngine").TCallLabel("_root." + fmMcPath + "map_mc.fromOutside_mc", "doAction");
	}
}

function fmGeometryLoadAndFocus(strGeometryURL) {
//do: load a geometry url in XML format, and focus

	if (fmMapIsReady()) {
		document.getElementById("fmASEngine").SetVariable("_root." + fmMcPath + "map_mc.fromOutsideGeometry", strGeometryURL); 
		document.getElementById("fmASEngine").SetVariable("_root." + fmMcPath + "map_mc.fromOutsideAction", "geometryLoadAndFocus"); 
		document.getElementById("fmASEngine").TCallLabel("_root." + fmMcPath + "map_mc.fromOutside_mc", "doAction");
	}
}

function fmGeometryUnload() {
//do: unload all geometry elements into the dbmapper

	if (fmMapIsReady()) {
		document.getElementById("fmASEngine").SetVariable("_root." + fmMcPath + "map_mc.fromOutsideAction", "geometryUnload"); 
		document.getElementById("fmASEngine").TCallLabel("_root." + fmMcPath + "map_mc.fromOutside_mc", "doAction");
	}
}

function fmGeometryElementShow(strId) {
//do: show a geometry element (use "*" for all elements)

	if (fmMapIsReady()) {
		if (strId == "") { strId = "*" }
		document.getElementById("fmASEngine").SetVariable("_root." + fmMcPath + "map_mc.fromOutsideElement", strId); 
		document.getElementById("fmASEngine").SetVariable("_root." + fmMcPath + "map_mc.fromOutsideAction", "geometryElementShow"); 
		document.getElementById("fmASEngine").TCallLabel("_root." + fmMcPath + "map_mc.fromOutside_mc", "doAction");
	}
}

function fmGeometryElementHide(strId) {
//do: hide a geometry element (use "*" for all elements)

	if (fmMapIsReady()) {
		if (strId == "") { strId = "*" }
		document.getElementById("fmASEngine").SetVariable("_root." + fmMcPath + "map_mc.fromOutsideElement", strId); 
		document.getElementById("fmASEngine").SetVariable("_root." + fmMcPath + "map_mc.fromOutsideAction", "geometryElementHide"); 
		document.getElementById("fmASEngine").TCallLabel("_root." + fmMcPath + "map_mc.fromOutside_mc", "doAction");
	}
}

function fmGeometryElementRemove(strId) {
//do: remove a geometry element

	if (fmMapIsReady()) {
		document.getElementById("fmASEngine").SetVariable("_root." + fmMcPath + "map_mc.fromOutsideElement", strId); 
		document.getElementById("fmASEngine").SetVariable("_root." + fmMcPath + "map_mc.fromOutsideAction", "geometryElementRemove"); 
		document.getElementById("fmASEngine").TCallLabel("_root." + fmMcPath + "map_mc.fromOutside_mc", "doAction");
	}
}
