//Set Global Variables
var ACTION = 'NULL';
var zoomObject = false;
var KEY = 'NULL';
var winStart = true;


function getMap()
{
  if (navigator.appName == "Netscape")
  	return document.form1.map;
  else
    return form1.map;
}

function InsertControl(url)
{
    document.writeln('<OBJECT ID="map" WIDTH=100% HEIGHT=80% ALIGN="TEXTOP"');
	
    document.writeln(' CLASSID="CLSID:62789780-B744-11D0-986B-00609731A21D"');
	
    document.writeln(' CODEBASE="http://gis.pinellascounty.org/ActiveX/ver6.5/mgaxctrl.cab#Version=6,5,6,12">');
	
    document.writeln('  <PARAM NAME="URL" VALUE="' + url + '">');
	
    document.writeln('  <EMBED SRC="' + url + '"');
	
    document.writeln('  ALIGN="LEFT" BORDER="0" WIDTH=95% HEIGHT=80%');
	
    document.writeln('  NAME="map" TYPE="application/x-mwf">');
	
    document.writeln('</OBJECT>');
}


function initObs1()
{
    ver = parseFloat(getMap().getApiVersion());
    if (navigator.appName == "Netscape")
    {

        if (ver >= 1.2)
        {
                getMap().setViewChangedObserver(document.obs);
                //getMap().setDoubleClickObserver(document.obs);
            	//getMap().setSelectionChangedObserver(document.obs);
        }

        if (ver > 1.2)
        {
                //getMap().setBusyStateChangedObserver(document.obs);

            	//getMap().setMapLoadedObserver(document.obs);
                getMap().setViewChangingObserver(document.obs);
                //getMap().setViewDistanceObserver(document.obs);
        }
    }
}




function initObs2()
{
        if (navigator.appName == "Netscape")
        {
            var ver = parseFloat(getMap().getApiVersion());
            if (ver >= 1.3)
        {
                document.write("<APPLET CODE=\"MapGuideObserver6.class\" WIDTH=1 HEIGHT=1 NAME=\"obs\" MAYSCRIPT>");
                document.write("</APPLET>");
        }
            else if (ver == 1.2)
        {
                document.write("<APPLET CODE=\"MapGuideObserver3.class\" WIDTH=1 HEIGHT=1 NAME=\"obs\" MAYSCRIPT>");
                document.write("</APPLET>");
        }
        }
}




function initVB()
{
    ver = parseFloat(getMap().getApiVersion());
    if (navigator.appName == "Microsoft Internet Explorer")
    {
        if (ver >= 1.2)
        {
                document.write('<SCRIPT LANGUAGE="VBScript">\n');

                //document.write('Sub map_onSelectionChanged(map)\n');
            	//document.write('    onSelectionChanged map\n');
                //document.write('End Sub\n\n');
                
                //document.write('Sub map_onDoubleClickObject(mapObj)\n');
            	//document.write('    mapObj.DoubleClickHandled = onDoubleClickObject(mapObj)\n');
                //document.write('End Sub\n\n');

                document.write('Sub map_onDigitizedPoint(map, point)\n');
            	document.write('    onDigitizedPoint map, point\n');
                document.write('End Sub\n\n');

                //document.write('Sub map_onDigitizedPolygon(map, numPoints, points)\n');
            	//document.write('    onDigitizedPolygon map, numPoints, points\n');
                //document.write('End Sub\n\n');

                //document.write('Sub map_onDigitizedPolyline(map, numPoints, points)\n');
            	//document.write('    onDigitizedPolyline map, numPoints, points\n');
                //document.write('End Sub\n\n');

                //document.write('Sub map_onDigitizedCircle(map, units, center, radius)\n');
            	//document.write('    onDigitizedCircle map, units, center, radius\n');
                //document.write('End Sub\n\n');

                //document.write('Sub map_onAddMapLayer(url, mapLayer)\n');
            	//document.write('    onAddMapLayer url, mapLayer\n');
                //document.write('End Sub\n\n');

                document.write('Sub map_onViewChanged(map)\n');
            	document.write('    onViewChanged map\n');
                document.write('End Sub\n\n');
        }   
        
        if (ver > 1.2)
        {
            //document.write('Sub map_onBusyStateChanged(map, isBusy)\n');
            //document.write('    onBusyStateChanged map, isBusy\n');
            //document.write('End Sub\n\n');

            //document.write('Sub map_onDigitizedRectangle(map, anchorPt, endPt)\n');
            //document.write('    onDigitizedRectangle map, anchorPt, endPt\n');
            //document.write('End Sub\n\n');

            //document.write('Sub map_onViewChanging(map)\n');
            //document.write('    onViewChanging map\n');
            //document.write('End Sub\n\n');

            document.write('Sub map_onMapLoaded(map)\n');
            document.write('    onMapLoaded map\n');
            document.write('End Sub\n\n');

            //document.write('Sub map_onViewedDistance(map, totalDistance, distances, units)\n');
            //document.write('    onViewedDistance map, totalDistance, distances, units\n');
            //document.write('End Sub\n\n');
        }

        if (ver >= 1.2)
        {
                document.write('<\/SCRIPT>\n');
        }
    }
}


function init()
{
// For Netscape Browsers, checks for plug-in
if (navigator.appName == "Netscape")
{
  for(j=0;j<navigator.plugins.length;j++)
  {
    if (navigator.plugins[j].name == "Autodesk MapGuide")
	  return;
  }
  // If the plug-in is not found, display message ... 
  displayDownloadMsg();
  return;
}
// If the plug-in is installed, check to see if latest version is installed

    ver = parseFloat(getMap().getApiVersion());
    
	if (ver < 5.0)
    {
        displayDownloadMsg();
    }
    else 
    {
        initObs1();
    }    
}     


function displayDownloadMsg()
{
    msg =  "You do not have the latest version of the Autodesk Mapguide Viewer.\n" +
         "Do you want to download the latest Autodesk MapGuide viewer now? " +
         "Click OK to download the latest viewer. Otherwise, click Cancel to " +
         " proceed with your current viewer. If you click Cancel, some features " + 
         "of the example may not work properly)."

   if (confirm(msg))
       parent.window.location = "http://pubgis.co.pinellas.fl.us/plugins.cfm";
}

// The following JavaScript functions process events from both the ActiveX
// Control and the Netscape Plug-in. The ActiveX events are forwarded to these
// functions via VBScript, and the Plug-in events are forwarded to these
// functions via the MapGuideObserver Java applet.

//function onSelectionChanged(map)
//{
//    if (parent.toggleframe.displaySelEvents)
//    {
//        var mapSel = map.getSelection();
//        var numObjs = mapSel.getNumObjects();

//        alert(numObjs + " Object(s) selected");
//    }
//}




//function onDoubleClickObject(mapObj)
//{
//    if (parent.toggleframe.displayDblClickEvents)
//    {
//        alert("\nYou just double clicked on: " + mapObj.getName() + "\n\nLayer: "
//              + mapObj.getMapLayer().getName());

//        return true;
//    }
//    return false;
//}




function onDigitizedPoint(map, point)
{
    
    alert("You just really digitized a point. The coordinates are:\n\nLAT = " + point.getY()
          + " , " + "LON = " + point.getX());
}


//function onDigitizedPolygon(map, numPoints, points)
//{
//    alert("You just digitized a polygon with: " + numPoints + " Points");
//    for (i = 0; i < numPoints; i++)
//        alert("Point[" + i + "] = " + points.item(i).getY() + " , " + points.item(i).getX());
//}




//function onDigitizedCircle(map, units, point, r)
//{
//    alert("You just digitized a circle \n"
//          + "centre: LAT=" + point.getY() + " LON=" + point.getX() + "\n"
//          + "radius " + r + " " + units);
//}




//function onDigitizedPolyline(map, numPoints, points)
//{
//    alert("You just digitized a polyline with: " + numPoints + " Points");
//    for (i = 0; i < numPoints; i++)
//        alert("Point[" + i + "] = " + points.item(i).getY() + " , " + points.item(i).getX());
//}




//function onAddMapLayer(url, mapLayer)
//{
//   alert("You just added " + mapLayer.getName() + " from " + url);
//}





//function onDigitizedRectangle(map, anchorPt, endPt)
//{
//    alert("You just digitized a rectangle. The coordinates are:\n\n" 
//          +     "Anchor: LAT = " + anchorPt.getY() + " , " + "LON = " + anchorPt.getX() + "\n" 
//          +     "End: LAT = " + endPt.getY() + " , " + "LON = " + endPt.getX());
//}




//function onBusyStateChanged(map, bIsBusy)
//{
//    if (parent.toggleframe.displayBusyEvents)
//    {
//        alert('map.isBusy: ' + bIsBusy);
//    }
//}




//Function fired when Map View changes
function onViewChanged(map)
{
	//if (ACTION == 'zin')
		//getMap().zoomInMode();
	//else
		//if (ACTION == 'zout')
			//getMap().zoomOutMode();
		//else
			//if (ACTION == 'pan')
				//getMap().panMode();
if (winStart){
  openSearch();
  winStart = false;
}
  
if (zoomObject == false)
	return;
else
	top.rightFrame.select_Object(KEY);
}






function onMapLoaded(map)
{
   //if (parent.mainFrame.displayMapLoadedEvents)
    // {
	//if (getMap().isBusy() == false)
    //{
//        alert('Map Loaded\nisBusy: ' + map.isBusy());
         //openSearch();
	//}	 
   //}
}




//function onViewChanging(map)
//{
//    if (parent.toggleframe.displayViewChangingEvents)
//    {
//        alert('View is changing\nisBusy: ' + map.isBusy() 
//            + '\nautoRefresh: ' + map.getAutoRefresh());
//    }
//}




//function onViewedDistance(map, totalDistance, distances, units)
//{
//    alert('view distance completed.\n total distance: ' + totalDistance 
//        + '\n units: ' + units
//        + '\n number of segments: ' + distances.size()
//        + '\n 2nd last seg: ' + distances.item(distances.size()-2)
//        + '\n last seg: ' + distances.item(distances.size()-1)); 
//}}}}}}