// CivXplorer Code to support cascading tool menus
// and control Viewer Layout
// Suzanne Fliege, Allied Information Solutions, Inc

// menu constants
var menuItemList = new Array();
var menuItemListCount = 0;
var menuSpace = "&nbsp;&nbsp;";
// layout
var borderWidth = 10;
var frameWidth = 5;
var headerHeight = 60;
var footerHeight = 30;
var menuWidth = 112;
var menuHeight = 20;
var moveOVMapCount = 0;
var moveSteps = 20;
// sidebar
var sidebarWidth = 200;
var sidebarHeight = 500;
var openSidebarHeight = 338;
var sidebarMode = 5;
var oldSidebarMode = 0;
var sidebarFloatCount = 5;
var sidebarFloatHeight = 20;
var moveSidebarCount = 0;
// tools
var toolbarTop = 0;
var toolbarLeft = 0;

// *****************
//    page
// *****************
// functions to run on CX start
function CXload() {
    // open entry page
	if (startWithEntryPage) {
        document.getElementById('cxEntryPage').style.overflow = "auto";
        document.getElementById('cxEntryPage').style.display = "inline";
    }	    
    // layout adjusted to browser size
    ResizePageControls();
    // set background properties
    document.getElementById('cxBackground').onmouseover = "JavaScript:setMenus('nothing');hideHelp();";
    // dropdown menus
	createToolMenus();
    // measurement style
    document.getElementById('mdnsMapMeasurementPalette_SegmentOrPerimeterCell').className = "CXmeasurement";
    document.getElementById('mdnsMapMeasurementPalette_DistanceOrAreaCell').className = "CXmeasurement";
    //document.getElementById('mdnsMapMeasurementPalette_SelectUnit').className = "CXmeasurement";
	// load starts with overview and scale off, toggle on if that's the starting value
	if (showOverviewMap) {
		showOverviewMap = false;
		toggleOVMap();
	}
	// make sure anno text is synched
	document.getElementById('cxTextString').value = currentTextString;
    // hide protector overlay
    ProtectorOff();
    // initialize custom TOC
    initializeOverlays();
    initializeOptionals();
    createTOC();
    // initialize map
    InitSizeMap();
    // activate starting sidebar
    showSidebar(parseInt(startingSidebar));
    // check if there is a starting selection
    if (doStartupQuery == "true"){
        StartupQueryHandler();
    }
}

// update content in a layer
function updateContent(name, content) {
	document.getElementById(name).innerHTML = content;
}

// resize page controls when map/sidebar/browser area resizes
function ResizePageControls() {
	// window size
    var mapHW = GetMapNavDimensions();
	// background
	document.getElementById('cxBackground').style.height = winHeight + "px";
	document.getElementById('cxBackground').style.width = winWidth + "px";
	// sidebar elements
	document.getElementById('cxSidebarTop').style.top = (headerHeight+menuHeight) + "px";
	document.getElementById('cxSidebarTop').style.left = borderWidth + "px";
	document.getElementById('cxSidebarBottom').style.top = (headerHeight+menuHeight+32+sidebarHeight) + "px";
	document.getElementById('cxSidebarBottom').style.left = borderWidth + "px";
	document.getElementById('cxSidebarLeft').style.height = sidebarHeight + "px";
	document.getElementById('cxSidebarLeft').style.left = borderWidth + "px";
	document.getElementById('cxSidebarRight').style.height = sidebarHeight + "px";
	document.getElementById('cxSidebarRight').style.left = (borderWidth+frameWidth+sidebarWidth) + "px";
	document.getElementById('cxSidebarBackground').style.top = (headerHeight+menuHeight+32) + "px";
	document.getElementById('cxSidebarBackground').style.left = borderWidth+frameWidth + "px";
	document.getElementById('cxSidebarBackground').style.height = sidebarHeight + "px";
    // move sidebar headers below the open one
    for (var i=sidebarMode;i<sidebarFloatCount;i++){
        divName = "cxSidebar" + (i+1) + "Header";
        document.getElementById(divName).style.top = (headerHeight+menuHeight+32+sidebarFloatHeight*i+openSidebarHeight) + "px";
    }
    // adjust height of open sidebar
    var divName = "cxSidebar" + sidebarMode;
    document.getElementById(divName).style.height = openSidebarHeight + "px";
	// dropdown menus
	document.getElementById('cxMapMenus').style.left = (sidebarWidth+borderWidth*2+frameWidth*3) + "px";
	document.getElementById('menuFind').style.left = (sidebarWidth+borderWidth*2+frameWidth*3) + "px";
	document.getElementById('menuSelect').style.left = (sidebarWidth+borderWidth*2+menuWidth+frameWidth*3) + "px";
	document.getElementById('menuAdvanced').style.left = (sidebarWidth+borderWidth*2+menuWidth*2+frameWidth*3) + "px";
	document.getElementById('menuSettings').style.left = (sidebarWidth+borderWidth*2+menuWidth*3+frameWidth*3) + "px";
	// mapbar elements
	document.getElementById('cxMapContainer').style.left = (sidebarWidth+frameWidth*2+borderWidth*2)  + "px";
	document.getElementById('cxMapContainer').style.height = mapbarHeight + "px";
	document.getElementById('cxMapContainer').style.width = mapbarWidth + "px";
	document.getElementById('cxMapCell').style.height = (mapbarHeight-footerHeight-frameWidth*3) + "px";
	document.getElementById('cxMapCell').style.width = (mapbarWidth-frameWidth*2) + "px";
	// help
	document.getElementById('cxHelp').style.height = (mapbarHeight-footerHeight) + "px";
	document.getElementById('cxHelp').style.width = mapbarWidth + "px";
	document.getElementById('cxHelp').style.left = (sidebarWidth+frameWidth*2+borderWidth*2) + "px";
	// map tools
	toolbarLeft = sidebarWidth+frameWidth*2+borderWidth*2+mapbarWidth/2-163;
	toolbarTop = headerHeight+menuHeight+mapbarHeight-footerHeight-frameWidth*2-51;
	document.getElementById('cxMapTools').style.left = toolbarLeft + "px";
	document.getElementById('cxMapTools').style.top = toolbarTop + "px";
	document.getElementById('cxMapTools').style.visibility = "visible";
	// locator
	if (showOverviewMap) {
	    document.getElementById('cxOverviewMap').style.height = (ovHeight+frameWidth*2) + "px";
	    document.getElementById('cxOverviewMap').style.width = (ovWidth+frameWidth*2) + "px";
	    document.getElementById('cxOverviewMap').style.top = (headerHeight+menuHeight+mapbarHeight-footerHeight-ovHeight-frameWidth*3) + "px";	
	    document.getElementById('cxOverviewMap').style.left = (winWidth-borderWidth-ovWidth-frameWidth*2) + "px";
	    document.getElementById('cxOverviewMapArrow').style.top = (headerHeight+menuHeight+mapbarHeight-footerHeight-ovHeight-frameWidth*3) + "px";	
	    document.getElementById('cxOverviewMapArrow').style.left = (winWidth-borderWidth-ovWidth-frameWidth*2) + "px";
	} else {
	    document.getElementById('cxOverviewMap').style.height = "16px";
        document.getElementById('cxOverviewMap').style.width = "16px";
        document.getElementById('cxOverviewMap').style.top = (headerHeight+menuHeight+mapbarHeight-footerHeight-frameWidth*2-16) + "px";	
        document.getElementById('cxOverviewMap').style.left = (winWidth-borderWidth-frameWidth-16) + "px";
        document.getElementById('cxOverviewMapArrow').style.top = (headerHeight+menuHeight+mapbarHeight-footerHeight-frameWidth*2-16) + "px";	
        document.getElementById('cxOverviewMapArrow').style.left = (winWidth-borderWidth-frameWidth-16) + "px";
    }
    document.getElementById('cxOverviewMap').style.visibility = "visible";
    document.getElementById('cxOverviewMapArrow').style.visibility = "visible";
	// tool help dialog
	document.getElementById('cxToolHelpDialog').style.top = (headerHeight+menuHeight+frameWidth) + "px";	
	document.getElementById('cxToolHelpDialog').style.left = (sidebarWidth+frameWidth*2+borderWidth*2+frameWidth) + "px";
	document.getElementById('cxToolHelpDialog').style.width = (mapbarWidth-frameWidth*2) + "px";
	// reporting
	document.getElementById('cxPopupMask').style.left = (sidebarWidth+frameWidth*2+borderWidth*2) + "px";
	document.getElementById('cxPopupMask').style.height = (winHeight-headerHeight-borderWidth) + "px";
	document.getElementById('cxPopupMask').style.width = (winWidth-(sidebarWidth+frameWidth*2)-borderWidth*3) + "px";
	document.getElementById('cxPopup').style.left = (sidebarWidth+frameWidth*2+borderWidth*2+25) + "px";
	document.getElementById('cxPopup').style.height = (winHeight-headerHeight-borderWidth-50) + "px";
	document.getElementById('cxPopup').style.width = (winWidth-(sidebarWidth+frameWidth*2)-borderWidth*3-50) + "px";
    // entry page (disclaimer)
	document.getElementById('cxEntryPage').style.height = (winHeight-headerHeight) + "px";
	document.getElementById('cxEntryPage').style.width = (winWidth) + "px";
	// spinner
	document.getElementById('cxProtectorSpinner').style.left = (sidebarWidth+frameWidth*2+borderWidth*2) + "px";
    document.getElementById('cxProtectorSpinner').style.height = (winHeight-headerHeight-borderWidth) + "px";
	document.getElementById('cxProtectorSpinner').style.width = (winWidth-(sidebarWidth+frameWidth*2)-borderWidth*3) + "px";
	return false;
}

// *****************
//    maps & tools
// *****************
// returns MapNavigator width based on current screen size
function GetMapNavDimensions() {
	// window size
	winWidth = MDNGetClientWidth();
	winHeight = MDNGetClientHeight();
	sidebarHeight = winHeight - headerHeight - menuHeight - borderWidth - 32 - 5;
	openSidebarHeight = sidebarHeight - (sidebarFloatCount*sidebarFloatHeight);
	mapbarHeight = winHeight - headerHeight - menuHeight - borderWidth;
	mapbarWidth = winWidth - (sidebarWidth+frameWidth*2) - borderWidth*3;
	mapHeight = mapbarHeight - footerHeight - frameWidth*3;
	mapWidth = mapbarWidth - frameWidth*2;
	var mapDims = new Array(mapHeight,mapWidth);
	return mapDims;
}

// turn protectors on
function ProtectorOn() {
    document.getElementById('cxProtector').style.visibility = 'visible';
    document.getElementById('cxProtectorSpinner').style.visibility = 'visible';
    return false;
}
// turn protectors off
function ProtectorOff() {
    document.getElementById('cxProtector').style.visibility = 'hidden';
    document.getElementById('cxProtectorSpinner').style.visibility = 'hidden';
    return false;
}

// turn help popup on/off
function toggleHelp() {
	// reset menus and tools
	resetAllMenus();
	resetDropdownItems();
	hideAllDropdowns();
	hideHelp();
	if (showUserHelp) {
		showUserHelp = false;
		updateContent("menuItem_Help",menuSpace+"Turn On Help Notes");
	} else {
		showUserHelp = true;
		updateContent("menuItem_Help",menuSpace+"Turn Off Help Notes");
	}
}

// launch appropriate OV map control animation
function toggleOVMap() {
    moveOVMapCount = 0;
	// reset menus and tools
	resetAllMenus();
	resetDropdownItems();
	hideAllDropdowns();
	hideHelp();
    if (showOverviewMap) {
	    updateContent("menuItem_OverviewMap",menuSpace+"Show Reference Map");
	    showOverviewMap = false;
        clearInterval(ovmapResizeTimer);
        ovmapResizeTimer = setInterval("closeOVMap()",10);
    } else {
	    updateContent("menuItem_OverviewMap",menuSpace+"Hide Reference Map");
	    showOverviewMap = true;
        clearInterval(ovmapResizeTimer);
        ovmapResizeTimer = setInterval("openOVMap()",10);
    }
}

// toggle Scalebar on/off
function toggleScalebar() {
	// reset menus and tools
	resetAllMenus();
	resetDropdownItems();
	hideAllDropdowns();
	hideHelp();
    if (showScalebar) {
	    updateContent("menuItem_Scalebar",menuSpace+"Show Scalebar");
	    showScalebar = false;
    } else {
	    updateContent("menuItem_Scalebar",menuSpace+"Hide Scalebar");
	    showScalebar = true;
    }
    UpdateScalebarHandler(showScalebar);
}

// toggle Legend on/of
function toggleLegend() {
	// reset menus and tools
	resetAllMenus();
	resetDropdownItems();
	hideAllDropdowns();
	hideHelp();
    if (showLegend) {
	    updateContent("menuItem_Legend",menuSpace+"Show Legend");
	    showLegend = false;
    } else {
	    updateContent("menuItem_Legend",menuSpace+"Hide Legend");
	    showLegend = true;
    }
    UpdateLegendHandler(showLegend);
}

// open the overview map animation
function openOVMap() {
    moveOVMapCount += 1;
    if (moveOVMapCount < moveSteps) {
	    var moveIntH = parseInt(ovHeight/moveSteps);
	    var moveIntW = parseInt(ovWidth/moveSteps);
        // new move interval
        var moveHeight = moveIntH*moveOVMapCount;
        var moveWidth = moveIntW*moveOVMapCount;
	    document.getElementById('cxOverviewMap').style.height = moveHeight + "px";
	    document.getElementById('cxOverviewMap').style.width = moveWidth + "px";
	    document.getElementById('cxOverviewMap').style.top = (headerHeight+menuHeight+mapbarHeight-footerHeight-frameWidth*3-moveHeight) + "px";	
	    document.getElementById('cxOverviewMap').style.left = (winWidth-borderWidth-frameWidth*2-moveWidth) + "px";
	    document.getElementById('cxOverviewMapArrow').style.top = (headerHeight+menuHeight+mapbarHeight-footerHeight-frameWidth*3-moveHeight) + "px";	
	    document.getElementById('cxOverviewMapArrow').style.left = (winWidth-borderWidth-frameWidth*2-moveWidth) + "px";
    } else {
	    document.getElementById('cxOverviewMap').style.height = (ovHeight+frameWidth*2) + "px";
	    document.getElementById('cxOverviewMap').style.width = (ovWidth+frameWidth*2) + "px";
	    document.getElementById('cxOverviewMap').style.top = (headerHeight+menuHeight+mapbarHeight-footerHeight-frameWidth*3-ovHeight) + "px";	
	    document.getElementById('cxOverviewMap').style.left = (winWidth-borderWidth-frameWidth*2-ovWidth) + "px";
	    document.getElementById('cxOverviewMapArrow').style.top = (headerHeight+menuHeight+mapbarHeight-footerHeight-frameWidth*3-ovHeight) + "px";	
	    document.getElementById('cxOverviewMapArrow').style.left = (winWidth-borderWidth-frameWidth*2-ovWidth) + "px";
	    document.getElementById('cxOverviewMapArrow').className = "CXovMapClose";
        clearInterval(ovmapResizeTimer);
    }
}

// close the overview map animation
function closeOVMap() {
    moveOVMapCount += 1;
    if (moveOVMapCount < moveSteps) {
	    var moveIntH = parseInt(ovHeight/moveSteps);
	    var moveIntW = parseInt(ovWidth/moveSteps);
        // new move interval
        var moveHeight = Math.abs(ovHeight - moveIntH*moveOVMapCount);
        if (moveHeight < 16) moveHeight = 16;
        var moveWidth = Math.abs(ovWidth - moveIntW*moveOVMapCount);
        if (moveWidth < 16) moveWidth = 16;
	    document.getElementById('cxOverviewMap').style.height = moveHeight + "px";
	    document.getElementById('cxOverviewMap').style.width = moveWidth + "px";
	    document.getElementById('cxOverviewMap').style.top = (headerHeight+menuHeight+mapbarHeight-footerHeight-frameWidth*2-moveHeight) + "px";	
	    document.getElementById('cxOverviewMap').style.left = (winWidth-borderWidth-frameWidth-moveWidth) + "px";
	    document.getElementById('cxOverviewMapArrow').style.top = (headerHeight+menuHeight+mapbarHeight-footerHeight-frameWidth*2-moveHeight) + "px";	
	    document.getElementById('cxOverviewMapArrow').style.left = (winWidth-borderWidth-frameWidth-moveWidth) + "px";
    } else {
	    document.getElementById('cxOverviewMap').style.height = "16px";
	    document.getElementById('cxOverviewMap').style.width = "16px";
	    document.getElementById('cxOverviewMap').style.top = (headerHeight+menuHeight+mapbarHeight-footerHeight-frameWidth*2-16) + "px";	
	    document.getElementById('cxOverviewMap').style.left = (winWidth-borderWidth-frameWidth-16) + "px";
	    document.getElementById('cxOverviewMapArrow').style.top = (headerHeight+menuHeight+mapbarHeight-footerHeight-frameWidth*2-16) + "px";	
	    document.getElementById('cxOverviewMapArrow').style.left = (winWidth-borderWidth-frameWidth-16) + "px";
	    document.getElementById('cxOverviewMapArrow').className = "CXovMapOpen";
        clearInterval(ovmapResizeTimer);
    }
}

// reset maptool highlights
function resetMapTools() {
    if (toolMode == 'zoom in') { document.getElementById("cxOnMap-ZoomIn").className='CXtoolBarButtonSelected'; } else { document.getElementById("cxOnMap-ZoomIn").className='CXtoolBarButtonNormal'; }
    if (toolMode == 'zoom out') { document.getElementById("cxOnMap-ZoomOut").className='CXtoolBarButtonSelected'; } else { document.getElementById("cxOnMap-ZoomOut").className='CXtoolBarButtonNormal'; }
    document.getElementById("cxOnMap-ZoomAll").className='CXtoolBarButtonNormal';
    if (toolMode == 'recenter') { document.getElementById("cxOnMap-Recenter").className='CXtoolBarButtonSelected'; } else { document.getElementById("cxOnMap-Recenter").className='CXtoolBarButtonNormal'; }
    if (toolMode == 'identify') { document.getElementById("cxOnMap-Identify").className='CXtoolBarButtonSelected'; } else { document.getElementById("cxOnMap-Identify").className='CXtoolBarButtonNormal'; }
    if ((toolMode.indexOf('selection') == 0) && !(measureActive)) { document.getElementById("cxOnMap-Select").className='CXtoolBarButtonSelected'; } else { document.getElementById("cxOnMap-Select").className='CXtoolBarButtonNormal'; }
    if (measureActive) { document.getElementById("cxOnMap-Measure").className='CXtoolBarButtonSelected'; } else { document.getElementById("cxOnMap-Measure").className='CXtoolBarButtonNormal'; }
	return false;
}

// highlight maptool
function highlightMapTool(maptoolName) {
	resetMapTools();
	document.getElementById(maptoolName).className = "CXtoolBarButtonHighlight";
	if (showUserHelp) showHelp(maptoolName);
	return false;
}

// *****************
//    sidebar
// *****************
function resetSidebarTitles() {
    var titleString = "";
    for (var i=0;i<=(sidebarFloatCount+1);i++) {
        titleString = "cxSidebar" + i + "Title";
	    if (document.getElementById(titleString) != null) document.getElementById(titleString).className = "CXsideBarTextNormal";
	}
	return false;
}

function showSidebar(theSidebar) {
    if (sidebarMode != theSidebar) {
        resetSidebarTitles();
	    // sidebars
	    oldSidebarMode = parseInt(sidebarMode);
	    sidebarMode = parseInt(theSidebar);
        // change sidebar visibility for move
        document.getElementById(("cxSidebar" + oldSidebarMode)).style.visibility = "hidden";
	    // move intervals
	    moveSidebarCount = 0;
        clearInterval(sidebarResizeTimer);
        sidebarResizeTimer = setInterval("moveSidebars()",10);
    } else {
        return false;
    }
}

function moveSidebars() {
    moveSidebarCount += 1;
    if (moveSidebarCount < moveSteps) {
        // new move interval
	    var moveInt = parseInt(openSidebarHeight/moveSteps);
        var moveSidebarHeight = moveInt*moveSidebarCount;
        var divName = "";
	    // move the sidebars
	    if (sidebarMode > oldSidebarMode) { // moving the sidebars up
	        // move headers
    	    for (var i=oldSidebarMode;i<sidebarMode;i++){
                divName = "cxSidebar" + (i+1) + "Header";
                document.getElementById(divName).style.top = (headerHeight+menuHeight+32+sidebarFloatHeight*i+openSidebarHeight-moveSidebarHeight) + "px";
    	    }
    	    // move & resize sidebars
            divName = "cxSidebar" + oldSidebarMode;
            document.getElementById(divName).style.height = (openSidebarHeight-moveSidebarHeight) + "px";
            divName = "cxSidebar" + sidebarMode;
            document.getElementById(divName).style.top = (headerHeight+menuHeight+32+sidebarFloatHeight*sidebarMode+openSidebarHeight-moveSidebarHeight) + "px";
            document.getElementById(divName).style.height = moveSidebarHeight + "px";
	    } else { // moving the sidebars down
	        // move headers
    	    for (var i=oldSidebarMode;i>sidebarMode;i--){
    	        if (i != 0) {
                    divName = "cxSidebar" + i + "Header";
                    document.getElementById(divName).style.top = (headerHeight+menuHeight+32+sidebarFloatHeight*(i-1)+moveSidebarHeight) + "px";
                }
    	    }
    	    // move & resize sidebars
            divName = "cxSidebar" + oldSidebarMode;
            document.getElementById(divName).style.top = (headerHeight+menuHeight+32+sidebarFloatHeight*oldSidebarMode+moveSidebarHeight) + "px";
            document.getElementById(divName).style.height = (openSidebarHeight-moveSidebarHeight) + "px";
            divName = "cxSidebar" + sidebarMode;
            document.getElementById(divName).style.top = (headerHeight+menuHeight+32+sidebarFloatHeight*sidebarMode) + "px";
            document.getElementById(divName).style.height = moveSidebarHeight + "px";
	    }
    } else {
	    // move the sidebars
	    if (sidebarMode > oldSidebarMode) { // moving the sidebars up
	        // move headers
    	    for (var i=oldSidebarMode;i<sidebarMode;i++){
                divName = "cxSidebar" + (i+1) + "Header";
                document.getElementById(divName).style.top = (headerHeight+menuHeight+32+sidebarFloatHeight*i) + "px";
    	    }
    	    // move & resize sidebars
            divName = "cxSidebar" + oldSidebarMode;
            document.getElementById(divName).style.height = "0px";
            //document.getElementById(divName).style.visibility = "hidden";
            divName = "cxSidebar" + sidebarMode;
            document.getElementById(divName).style.top = (headerHeight+menuHeight+32+sidebarFloatHeight*sidebarMode) + "px";
            document.getElementById(divName).style.height = openSidebarHeight + "px";
            document.getElementById(divName).style.visibility = "visible";
	    } else { // moving the sidebars down
	        // move headers
    	    for (var i=oldSidebarMode;i>sidebarMode;i--){
    	        if (i != 0) {
                    divName = "cxSidebar" + i + "Header";
                    document.getElementById(divName).style.top = (headerHeight+menuHeight+32+sidebarFloatHeight*(i-1)+openSidebarHeight) + "px";
                }
    	    }
    	    // move & resize sidebars
            divName = "cxSidebar" + oldSidebarMode;
            document.getElementById(divName).style.top = (headerHeight+menuHeight+32+sidebarFloatHeight*oldSidebarMode+openSidebarHeight) + "px";
            document.getElementById(divName).style.height = "0px";
            //document.getElementById(divName).style.visibility = "hidden";
            divName = "cxSidebar" + sidebarMode;
            document.getElementById(divName).style.top = (headerHeight+menuHeight+32+sidebarFloatHeight*sidebarMode) + "px";
            document.getElementById(divName).style.height = openSidebarHeight + "px";
            document.getElementById(divName).style.visibility = "visible";
	    }
        document.getElementById(("cxSidebar" + sidebarMode + "Title")).className = "CXsideBarTextSelected";
        clearInterval(sidebarResizeTimer);
    }
}

// *****************************
//    menus/dropdowns
// *****************************
// create tool menus
function createToolMenus() {
    var theString = '';
	// find/search dropdown
	for (var i=0;i<searchMenuIDs.length;i++) {
	    theString += createMenuItem(searchMenuIDs[i],searchMenuFunctions[i],menuSpace+searchMenuTexts[i]);
	}
	updateContent("menuFind",theString);
	// select dropdown
	theString = '';
	theString += createMenuItem("menuItem_Identify","setMenus('nothing');MapToolset_Identify_Click();",menuSpace+"Identify");
	theString += createMenuItem("menuItem_SelectOnMap","setMenus('nothing');OpenSelectOnMap();",menuSpace+"Select On Map");
	theString += createMenuItem("menuItem_SelectByLocation","setMenus('nothing');BufferDialogHandler();",menuSpace+"Select By Location");
	theString += createMenuItem("menuItem_ClearSelections","setMenus('nothing');clickFunction('clear selection');",menuSpace+"Clear All Selections");
	updateContent("menuSelect",theString);
    // advanced dropdown
	theString = '';
	if (VEavailable) {
	    theString += createMenuItem("menuItem_VEBirdsEye","openVEBirdsEye();",menuSpace+"Open VE Bird's Eye");
	} else {
	    theString += createMenuItem("menuItem_NoAdvanced","setMenus('nothing');",menuSpace+"No Tools Available!");
	}
	updateContent("menuAdvanced",theString);
	// settings dropdown
	theString = '';
	if (showOverviewMap) {
	    theString += createMenuItem("menuItem_OverviewMap","toggleOVMap();",menuSpace+"Hide Reference Map");
	} else {
    	theString += createMenuItem("menuItem_OverviewMap","toggleOVMap();",menuSpace+"Show Reference Map");
	}
	if (showLegend) {
	    theString += createMenuItem("menuItem_Legend","toggleLegend();",menuSpace+"Hide Legend");
	} else {
    	theString += createMenuItem("menuItem_Legend","toggleLegend();",menuSpace+"Show Legend");
	}
	if (showScalebar) {
	    theString += createMenuItem("menuItem_Scalebar","toggleScalebar();",menuSpace+"Hide Scalebar");
	} else {
    	theString += createMenuItem("menuItem_Scalebar","toggleScalebar();",menuSpace+"Show Scalebar");
	}
	if (showUserHelp) {
	    theString += createMenuItem("menuItem_Help","toggleHelp();",menuSpace+"Turn Off Help Notes");
	} else {
    	theString += createMenuItem("menuItem_Help","toggleHelp();",menuSpace+"Turn On Help Notes");
	}
	updateContent("menuSettings",theString);
    return false;
}

function createMenuItem(theID,theMouseClick,theContent) {
	var theString = '<DIV id="' + theID + '" class="CXmenuItem" oncontextmenu="JavaScript:return false;" onclick="JavaScript: ' + theMouseClick + '" onmouseover="JavaScript:highlightItem(\'' + theID + '\');if (showUserHelp) showHelp(\'' + theID + '\');" >' + theContent + '</DIV>'
	// add to list of active menu items for color control
	menuItemList[menuItemListCount] = theID;
	menuItemListCount += 1;
	return theString;
}

// set menu & dropdown visibility on mouseovers
function setMenus(theTool) {
	// reset everything
	resetAllMenus();
	resetDropdownItems();
	hideAllDropdowns();
	if (document.getElementById('cxHelp') != null) hideHelp();
	// set menu visible (if not nothing)
	if (!(theTool == "nothing")) document.getElementById(theTool).className = "CXmenuTextHighlight";
	showDropdown(theTool);
	return false;
}
// turn highlight off all menus
function resetAllMenus() {
	if (document.getElementById('menutabFind') != null) document.getElementById('menutabFind').className = "CXmenuTextNormal";
	if (document.getElementById('menutabSelect') != null) document.getElementById('menutabSelect').className = "CXmenuTextNormal";	
	if (document.getElementById('menutabAdvanced') != null) document.getElementById('menutabAdvanced').className = "CXmenuTextNormal";
	if (document.getElementById('menutabSettings') != null) document.getElementById('menutabSettings').className = "CXmenuTextNormal";
    return false;
}

// hide all dropdowns
function hideAllDropdowns() {
	if (document.getElementById('menuFind') != null) document.getElementById('menuFind').style.visibility = "hidden";
	if (document.getElementById('menuSelect') != null) document.getElementById('menuSelect').style.visibility = "hidden";	
	if (document.getElementById('menuAdvanced') != null) document.getElementById('menuAdvanced').style.visibility = "hidden";
	if (document.getElementById('menuSettings') != null) document.getElementById('menuSettings').style.visibility = "hidden";
	return false;
}

// show needed dropdown
function showDropdown(theTool) {
	if (theTool == "menutabFind" && document.getElementById('menuFind') != null) document.getElementById('menuFind').style.visibility = "visible";
	if (theTool == "menutabSelect" && document.getElementById('menuSelect') != null) document.getElementById('menuSelect').style.visibility = "visible";
	if (theTool == "menutabAdvanced" && document.getElementById('menuAdvanced') != null) document.getElementById('menuAdvanced').style.visibility = "visible";
	if (theTool == "menutabSettings" && document.getElementById('menuSettings') != null) document.getElementById('menuSettings').style.visibility = "visible";
	return false;
}

// reset menu dropdown
function resetDropdownItems() {
	for (var i=0;i<menuItemListCount;i++) {
		var tempMenuItem = document.getElementById(menuItemList[i]);
		tempMenuItem.className = "CXmenuItem";
	}
	return false;
}

// highlight menu item
function highlightItem(menuItemName) {
	resetDropdownItems();
	document.getElementById(menuItemName).className = "CXmenuItemMouseOver";
	return false;
}

// *************************************
//    printmap support
// *************************************
// set dialog visibility based on printmap type
function SetPrintMapDialog(theType) {
	document.getElementById('cxPrintMapPDF').style.display = "none";
	document.getElementById('cxPrintMapImage').style.display = "none";
	switch(theType) {
	case "nothing":
		window.status="";
		break
	case "pdf":
		document.getElementById('cxPrintMapPDF').style.display = "inline";
		break
	case "image":
	    document.getElementById('cxPrintMapImage').style.display = "inline";
		break
	default:
		//alert("Function Not Available");
	}
}

// *************************************
//    annotation support
// *************************************
// set all annotation styles
function SetAnnoStyles() {
    var annoString = '';
    annoString += document.getElementById('cxTextColor').value;
    annoString += "," + document.getElementById('cxPointColor').value;
    annoString += "," + document.getElementById('cxLineColor').value;
    annoString += "," + document.getElementById('cxFillColor').value;
    annoString += ",circle,3,solid,3,50";
    // set local variables
	currentTextColor = document.getElementById('cxTextColor').value;
	currentPointColor = document.getElementById('cxPointColor').value;
	currentLineColor = document.getElementById('cxLineColor').value;
	currentFillColor = document.getElementById('cxFillColor').value;
    // send to server
    CallbackMethods.SetAnnoStyles(annoString,EmptyCallback);
}

// save anno text
function saveAnnoText() {
    currentTextString = document.getElementById('cxTextString').value;
    CallbackMethods.SetAnnoText(currentTextString, EmptyCallback);
}

// set tool visibility based on tool type
function SetAnnotationDialog(theType) {
    ResetAnnotationDialog();
	switch(theType) {
	case "nothing":
		window.status="";
		break
	case "text":
		document.getElementById('cxTextAnno').style.display = "inline";
		document.getElementById('cxTextColor').value = currentTextColor.toLowerCase();
		MapToolset_DrawText_Click();
		break
	case "point":
	    document.getElementById('cxPointAnno').style.display = "inline";
		document.getElementById('cxPointColor').value = currentPointColor.toLowerCase();
		MapToolset_DrawPt_Click();
		break
    case "line":
	    document.getElementById('cxLineAnno').style.display = "inline";
	    document.getElementById('cxAnnoSave').style.display = "inline";
	    document.getElementById('cxLineStyles').style.display = "inline";
		document.getElementById('cxLineColor').value = currentLineColor.toLowerCase();
		MapToolset_DrawLine_Click();
		break
	case "polygon":
	    document.getElementById('cxPolyAnno').style.display = "inline";
	    document.getElementById('cxAnnoSave').style.display = "inline";
	    document.getElementById('cxLineStyles').style.display = "inline";
	    document.getElementById('cxFillStyles').style.display = "inline";
		document.getElementById('cxLineColor').value = currentLineColor.toLowerCase();
		document.getElementById('cxFillColor').value = currentFillColor.toLowerCase();
		MapToolset_DrawPolygon_Click();
		break
	case "rectangle":
	    document.getElementById('cxRectCircleAnno').style.display = "inline";
	    document.getElementById('cxLineStyles').style.display = "inline";
	    document.getElementById('cxFillStyles').style.display = "inline";
		document.getElementById('cxLineColor').value = currentLineColor.toLowerCase();
		document.getElementById('cxFillColor').value = currentFillColor.toLowerCase();
		MapToolset_DrawRect_Click();
        break
	case "circle":
	    document.getElementById('cxRectCircleAnno').style.display = "inline";
	    document.getElementById('cxLineStyles').style.display = "inline";
	    document.getElementById('cxFillStyles').style.display = "inline";
		document.getElementById('cxLineColor').value = currentLineColor.toLowerCase();
		document.getElementById('cxFillColor').value = currentFillColor.toLowerCase();
	    break
	case "clear":
	    clickFunction('clear annotation');
	    break
	default:
		//alert("Function Not Available");
	}
}

// reset the annotation dialog
function ResetAnnotationDialog() {
    swatchMode = "none";
	document.getElementById('cxTextAnno').style.display = "none";
	document.getElementById('cxPointAnno').style.display = "none";
	document.getElementById('cxLineAnno').style.display = "none";
	document.getElementById('cxPolyAnno').style.display = "none";
    document.getElementById('cxRectCircleAnno').style.display = "none";
	document.getElementById('cxAnnoSave').style.display = "none";
	document.getElementById('cxLineStyles').style.display = "none";
	document.getElementById('cxFillStyles').style.display = "none";
    return false;
}
