// ********************************************
// **        Flashmaps PinPoint! 1.0         **
// **       JavaScript API Functions         **
// ********************************************
// ** Please DO NOT make any changes here.   **
// ** You may want to chenge fmPPClient.js   **
// ********************************************
// **      (c)2004 Flashmaps Geospatial      **
// **        http://www.flashmaps.com        **
// ********************************************


// ********************************************
// **  Functions called from the map, events **
// ********************************************

// The map is ready to receive commands
function fmMapIsReady() {
	fmMapReady = true;
	fmCustomMapIsReady();
}

// A POI event was triggered
function fmPOIEvent(eventName, fmPOIID) {
	switch (eventName) {
		case 'onrollover':
			// The visitor placed the mouse over a POI
			fmCustomPOIOnRollOver(fmPOIID);
			break;
			
		case 'onrollout':
			// The visitor moved the mouse out of a POI
			fmCustomPOIOnRollOut(fmPOIID);
			break;
			
		case 'onrelease':
			// The visitor clicked on a POI
			fmCustomPOIOnRelease(fmPOIID);
			break;
						
		default:
			// Should not happen
			alert('Event ' + event + ' was triggered over POI ID ' + fmPOIID);
			break;
	}
}

// A set of POIs has been loaded
function fmPOIURLLoaded(strPOIsURL, iPOIsNumber) {
	fmCustomPOIURLLoaded(strPOIsURL, iPOIsNumber);
}



// ********************************************
// **  Functions to send commands to the map **
// ********************************************

// Highlight a POI
function fmPOIHighlight(fmPOIID, strMethod) {
	if (fmMapReady) {
		fmMapObj1.SetVariable("_root.map_mc.fromOutsidePOIID", fmPOIID); 
		fmMapObj1.SetVariable("_root.map_mc.fromOutsideAction", "highlightPOI"); 
		fmMapObj1.SetVariable("_root.map_mc.fromOutsideHighlightMethod", strMethod); 
		fmMapObj1.TCallLabel("_root.map_mc.fromOutside_mc", "doAction");
	}
}

// Unhighlight a POI
function fmPOIUnhighlight(fmPOIID) {
	if (fmMapReady) {
		fmMapObj1.SetVariable("_root.map_mc.fromOutsidePOIID", fmPOIID);
		fmMapObj1.SetVariable("_root.map_mc.fromOutsideAction", "unhighlightPOI"); 
		fmMapObj1.TCallLabel("_root.map_mc.fromOutside_mc", "doAction");
	}
}

// Highlight and focus on a POI
function fmPOIHighlightAndFocusOn(fmPOIID, strMapScale, strMethod){
	if (fmMapReady) {
		fmMapObj1.SetVariable("_root.map_mc.fromOutsidePOIID", fmPOIID); 
		fmMapObj1.SetVariable("_root.map_mc.fromOutsideScale", strMapScale); 
		fmMapObj1.SetVariable("_root.map_mc.fromOutsideAction", "highlightAndFocusOnPOI"); 
		fmMapObj1.SetVariable("_root.map_mc.fromOutsideHighlightMethod", strMethod); 
		fmMapObj1.TCallLabel("_root.map_mc.fromOutside_mc", "doAction");
	}
}

// Focus on a certain point, lat/lon.
function fmFocusOnLatLon(strLon, strLat, strMapScale) {
	if (fmMapReady) {
		fmMapObj1.SetVariable("_root.map_mc.fromOutsideLon", strLon);
		fmMapObj1.SetVariable("_root.map_mc.fromOutsideLat", strLat); 
		fmMapObj1.SetVariable("_root.map_mc.fromOutsideScale", strMapScale); 
		fmMapObj1.SetVariable("_root.map_mc.fromOutsideAction", "FocusOnLatLon"); 
		fmMapObj1.TCallLabel("_root.map_mc.fromOutside_mc", "doAction");
	}
}

// Focus on the POIs of a particular category or on all of them
function fmFocusOnAllPOIs(strCategory) {
	if (fmMapReady) {
		if (strCategory == "") {strCategory = "*";}
		fmMapObj1.SetVariable("_root.map_mc.fromOutsideCategory", strCategory);
		fmMapObj1.SetVariable("_root.map_mc.fromOutsideAction", "FocusOnAllPOIs"); 
		fmMapObj1.TCallLabel("_root.map_mc.fromOutside_mc", "doAction");
	}
}

// Show category (* for all)
function fmPOIShowCategory(strCategory) {
	if (fmMapReady) {
		fmMapObj1.SetVariable("_root.map_mc.fromOutsideCategory", strCategory); 
		fmMapObj1.SetVariable("_root.map_mc.fromOutsideAction", "showCategory"); 
		fmMapObj1.TCallLabel("_root.map_mc.fromOutside_mc", "doAction");
	}
}

// Hide category (* for all)
function fmPOIHideCategory(strCategory) {
	if (fmMapReady) {
		fmMapObj1.SetVariable("_root.map_mc.fromOutsideCategory", strCategory); 
		fmMapObj1.SetVariable("_root.map_mc.fromOutsideAction", "hideCategory"); 
		fmMapObj1.TCallLabel("_root.map_mc.fromOutside_mc", "doAction");
	}
}

// Load a set of POIs
function fmPOILoadURL(strPOIsURL) {
	if (fmMapReady) {
		fmMapObj1.SetVariable("_root.map_mc.fromOutsidePOIsURL", strPOIsURL); 
		fmMapObj1.SetVariable("_root.map_mc.fromOutsideAction", "loadPOIsURL"); 
		fmMapObj1.TCallLabel("_root.map_mc.fromOutside_mc", "doAction");
	}
}

// Remove all POIs
function fmPOIRemoveAll() {
	if (fmMapReady) {
		fmMapObj1.SetVariable("_root.map_mc.fromOutsideAction", "removeAllPOIs"); 
		fmMapObj1.TCallLabel("_root.map_mc.fromOutside_mc", "doAction");		
	}
}

// Load an set of POIs for the administration tool
function fmAdminPOILoadURL(strFile)  {
	if (fmMapReady) {
		fmMapObj1.SetVariable("_root.mcAddPlugging.fromOutsideXML", strFile); 
		fmMapObj1.TCallLabel("_root.mcAddPlugging.adminFromOutside_mc", "doAction");
	}
}

// Initial view of the map
function fmInitialView() {
	fmMapObj1.SetVariable("_root.map_mc.fromOutsideAction", "initialView");
	fmMapObj1.TCallLabel("_root.map_mc.fromOutside_mc", "doAction");
}

// Enlarge map
function fmMaximize(fmWidth, fmHeight, fmLat, fmLon, fmScale) {
	//
	// Browser detection
	if (parseInt(navigator.appVersion.charAt(0)) >= 4) {
		var isSF = (fmCheckString("Safari", navigator.appVersion)!=-1)?1:0;
		var isNN = (navigator.appName=="Netscape")?1:0;
		var isIE = (navigator.appName.indexOf("Microsoft")!=-1)?1:0;
	}
	//
	// Find out the call to the toolbar
	var strToolbarCall;
	if (isIE) {
		strToolbarCall = fmMapObj1.movie;
	} else {
		strToolbarCall = fmMapObj1.src;
	}
	//
	// Window size calculation
	factorW = (fmWidth*100)/screen.width;
	factorH = (fmHeight*100)/screen.height;
	if (factorW > factorH) {
		newW = screen.width;
		newH = (((screen.width*100)/fmWidth)/100)*fmHeight;
		posX = 0;
		posY = (screen.height - newH) / 2;
	} else {
		if (factorW < factorH) {
			newW = (((screen.height*100)/fmHeight)/100)*fmWidth;
			newH = screen.height;
			posX = (screen.width - newW) / 2;
			posY = 0;
		} else {
			newW = screen.width;
			newH = screen.height;
			posX = 0;
			posY = 0;
		}
	}
	//
	// Variables for the new window
	var optNN='scrollbars=no,menubar=no,width=' + newW + ',height=' + newH + 'left=' + posX + ',top=' + posY +'';
	var optIE='scrollbars=no,menubar=0,width=' + newW + ',height=' + newH + 'left=' + posX + ',top=' + posY+'';
  	var optSF='width=' + newW + ',height=' + newH ;
  	var newWindow = '';
	if (isIE) {
		newWindow = window.open('about:blank', '', optIE);
	} else {  
		if (isSF){
			newWindow = window.open('', '', optSF);
		} else {
			newWindow = window.open('', '', optNN);
		}
	}
	//
	// Write for the new window
	newWindow.document.writeln('<HTML>');
	newWindow.document.writeln('<HEAD>');
	newWindow.document.writeln('<title>Flashmaps PinPoint</title>');
	newWindow.document.writeln('<style>body{margin:0px;}td{font-family: Arial;font-size:10}</style>');
	newWindow.document.writeln('<sc'+'ript>');
	newWindow.document.writeln('var isNN,isIE;');
	newWindow.document.writeln('if (parseInt(navigator.appVersion.charAt(0))>=4){');
	newWindow.document.writeln(' isNN=(navigator.appName=="Netscape")?1:0;');
	newWindow.document.writeln(' isIE=(navigator.appName.indexOf("Microsoft")!=-1)?1:0;}');
	newWindow.document.writeln('function reSizeToMap(){');
	newWindow.document.writeln(' if (isIE){');
	newWindow.document.writeln('  width=' + newW + ';');
	newWindow.document.writeln('  height=' + newH + ';');
	newWindow.document.writeln('  window.moveTo(' + posX + ',' + posY + ')');
	newWindow.document.writeln('  window.resizeTo(width,height);}');
	newWindow.document.writeln(' else {');       
	newWindow.document.writeln('  window.innerWidth=' + newW + ';');
	newWindow.document.writeln('  window.innerHeight=' + newH + ';');
	newWindow.document.writeln('  window.scrollbars=false;}}');       
	newWindow.document.writeln('function fmCustomPOIRollOver(fmIDPOI) {}');
	newWindow.document.writeln('function fmCustomPOIRollOut(fmIDPOI) {}');
	newWindow.document.writeln('function fmCustomPOIOnRelease(fmIDPOI) {}');
	newWindow.document.writeln('function fmCustomPOIURLLoaded(strPOIsURL, iPOIsNumber) {}');
	newWindow.document.writeln('function fmCustomMapIsReady() {}');
	newWindow.document.writeln('</sc'+'ript>');
	newWindow.document.writeln('</HEAD>')
	newWindow.document.writeln('');
	newWindow.document.writeln('<BODY bgcolor=#FFFFFF scroll="no" onload="reSizeToMap();self.focus()">');
	newWindow.document.writeln('<TABLE width="100%" border="0">');
	newWindow.document.writeln('  <TR><TD valign="middle" align="center">');
	newWindow.document.writeln('<!-- Flash object -->');
	newWindow.document.writeln('    <OBJECT classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"');
	newWindow.document.writeln('    codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0" ');
	newWindow.document.writeln('    ID="tigris" WIDTH="' + (newW-40) + '" HEIGHT="' + (newH-40) + '" ALIGN="center">');
	newWindow.document.writeln('    <PARAM NAME=movie VALUE="'+strToolbarCall+'" /> <PARAM NAME=quality VALUE=high /> <PARAM NAME=bgcolor VALUE=#FFFFFF />  '); 
	newWindow.document.writeln('    <EMBED src="'+strToolbarCall+'" quality=high bgcolor=#FFFFFF  ');
	newWindow.document.writeln('    swLiveConnect=FALSE WIDTH="' + (newW-40) + '" HEIGHT="' + (newH-40) + '" NAME="tigris" ALIGN=""');
	newWindow.document.writeln('    TYPE="application/x-shockwave-flash" PLUGINSPAGE="http://www.macromedia.com/go/getflashplayer">');
	newWindow.document.writeln('    </EMBED>');
	newWindow.document.writeln('    </OBJECT>');
	newWindow.document.writeln('  </TD></TR>')
	newWindow.document.writeln('</TABLE>');
	newWindow.document.writeln('</BODY>')
	newWindow.document.writeln('</HTML>'); 
	newWindow.document.close();  	
}


// ********************************************
// **              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;
} 
