/****************************************************************************************
ui.js
Created by ESRI 10/14/2002
User Interface Functions - all non-DHTML javascript that is needed to "glue" the site
together.
****************************************************************************************/
/****************************************************************************************
Function called after the layers on the map.asp page have loaded (the DHTMLlayers.js page
calls this function)
****************************************************************************************/
function mapPageLoad(){
	var windowheight = 0;
	var windowwidth = 0;
	if (document.mapparams.initialized.value == ""){
		showRetrieveMap();
		document.mapparams.initialized.value = "true";
		if (window.innerWidth){   
			windowwidth = window.innerWidth;
			windowheight = window.innerHeight;
		}else{
			windowwidth = document.body.clientWidth;
			windowheight = document.body.clientHeight;
		}
		document.mapparams.imageWidth.value = windowwidth - 20;
		document.mapparams.imageHeight.value = windowheight - 60;
		iHeight = parseFloat(document.mapparams.imageHeight.value);
		iWidth = parseFloat(document.mapparams.imageWidth.value);
		document.mapparams.submit();

	} else {
		//capture the user's mouse movements.  This enables the DHTML functions (zoombox, pan, etc...)
		tool = document.mapparams.tool.value;
		if (isNav) {
			document.captureEvents(Event.MOUSEDOWN | Event.MOUSEMOVE | Event.MOUSEUP);
		} 
		document.onmousedown = mapTool;
		document.onmouseup = chkMouseUp;
		document.onmousemove = getMouse;
		changeCursor();
		//setUpScales();
		//populateLayers();
	}
	
}
/****************************************************************************************

****************************************************************************************/
function resizeMap(){
	if (window.innerWidth){   
		windowwidth = window.innerWidth;
		windowheight = window.innerHeight;
	}else{
		windowwidth = document.body.clientWidth;
		windowheight = document.body.clientHeight;
	}
	document.mapparams.imageWidth.value= windowwidth - 20;
	document.mapparams.imageHeight.value= windowheight - 60;
	showRetrieveMap();
	document.mapparams.submit();
}
/****************************************************************************************

****************************************************************************************/
function populateLayers(){
	if (top.tabWindow.document.tabparams){
		if (top.tabWindow.document.tabparams.currentView.value == "layers" || top.tabWindow.document.tabparams.currentView.value == ""){
			top.tabWindow.document.tabparams.VisList.value = top.map.document.mapparams.VisList.value;
			top.tabWindow.document.tabparams.InVisList.value = top.map.document.mapparams.InVisList.value;
			top.tabWindow.document.tabparams.CurList.value = top.map.document.mapparams.CurList.value;
			top.tabWindow.document.tabparams.VisCatList.value = top.map.document.mapparams.VisCatList.value;
			top.tabWindow.document.tabparams.currentView.value = "layers";
			top.tabWindow.document.tabparams.submit();
		}else{
			top.tabWindow.document.tabparams.submit();
			top.tabWindow.document.tabparams.maxy.value = top.map.document.mapparams.MaxY.value;
			top.tabWindow.document.tabparams.maxx.value = top.map.document.mapparams.MaxX.value;
			top.tabWindow.document.tabparams.miny.value = top.map.document.mapparams.MinY.value;
			top.tabWindow.document.tabparams.minx.value = top.map.document.mapparams.MinX.value;
			top.tabWindow.document.tabparams.submit();
		}
	}
	return;
}
/****************************************************************************************

****************************************************************************************/
function setUpScales(){
	top.leftTools.document.toolparams.tool.value = document.mapparams.tool.value;
	top.leftTools.document.toolparams.mapScaleLevel.value = document.mapparams.mapScaleLevel.value;
	top.leftTools.document.toolparams.mapScale.value = document.mapparams.MapScale.value;
	top.leftTools.document.scaleForm.ZoomScale.value = document.mapparams.MapScale.value;
	top.leftTools.document.toolparams.submit();
	return;
}
/****************************************************************************************

****************************************************************************************/
function switchTool(basename){
	//var oldTool = top.map.document.mapparams.tool.value;
	//if (oldTool) document.images[oldTool].src = "/images/images_standard/tool_"+oldTool+"_off.gif";
	top.map.document.mapparams.tool.value = basename;
	//document.images[basename].src = "/images/images_standard/tool_"+basename+"_on.gif";
	top.map.changeCursor();
	return;
}
/****************************************************************************************
****************************************************************************************/
function download(){
	var featureStr="height=225,width=420,scrollbars=yes,resizable=yes,menubar=yes";
	var DownloadWin = window.open("download.asp","downloadPage",featureStr);
	DownloadWin.focus();
return;
}
/****************************************************************************************
****************************************************************************************/
function switchAction(action){
	top.map.document.mapparams.action.value = action;
	top.map.showRetrieveMap();
	top.map.document.mapparams.submit();
	return;
}
/****************************************************************************************
****************************************************************************************/
function zoomScale(){
	var newScale = parseFloat(document.scaleForm.ZoomScale.value);
	var maxScale = parseFloat(top.map.document.mapparams.maxScale.value);
	var fullScale = top.map.document.mapparams.fullScale.value;
	if (newScale == "" || isNaN(newScale)){
		alert("Please enter a numeric scale in the scale box and try again!");
	}else{
		if (parseFloat(newScale) < maxScale || parseFloat(newScale) > fullScale){
			alert("Please enter a scale between " + fullScale + " and " + maxScale + " and try again!");
		}else{
			top.map.document.mapparams.action.value = "ZoomScale"
			top.map.document.mapparams.MapScale.value = newScale;
			top.map.showRetrieveMap();
			top.map.document.mapparams.submit();
		}
	}
	return;
}
/****************************************************************************************
****************************************************************************************/
function openHelp(){
	var featureStr="height=580,width=797,scrollbars=yes,resizable=yes,menubar=yes,location=yes,toolbar=yes";
	var MapHelpWin = window.open("maphelp_contents.asp", "MapHelpPage", featureStr);
	MapHelpWin.focus();
return;
}
/****************************************************************************************
****************************************************************************************/
function openThemes(){
	var featureStr="height=450,width=750,scrollbars=yes,resizable=yes,menubar=yes,location=yes,toolbar=yes";
	var MapThemeWin = window.open("mapthemes.asp", "MapThemes", featureStr);
	top.name = "opener";
	MapThemeWin.focus();
return;
}
/****************************************************************************************
****************************************************************************************/
function zoomFeature(){
	var searchStr = document.searchparams.searchText.value;
	if (document.searchparams.searchType.value == "address"){
		var featureStr="height=40,width=420,scrollbars=yes,resizable=yes,menubar=yes";
		var addWin = window.open("address.asp?qryStr="+escape(searchStr),"addPage",featureStr);
		addWin.focus();
	}else{
		var featureStr="height=40,width=420,scrollbars=yes,resizable=yes,menubar=yes";
		var waterWin = window.open("watersearch.asp?watertext="+escape(searchStr),"waterPage",featureStr);
		waterWin.focus();
	}
	return
}
/****************************************************************************************
****************************************************************************************/
function printPage(){
		var VisList = top.map.document.mapparams.VisList.value;
		var InVisList = top.map.document.mapparams.InVisList.value;
		var maxy = top.map.document.mapparams.MaxY.value;
		var maxx = top.map.document.mapparams.MaxX.value;
		var miny = top.map.document.mapparams.MinY.value;
		var minx = top.map.document.mapparams.MinX.value;
		var valStr = "VisList="+VisList+"&InVisList="+InVisList
		valStr = valStr + "&maxy="+maxy+"&maxx="+maxx+"&miny="+miny+"&minx="+minx
		var featureStr="height=200,width=500,scrollbars=yes,resizable=yes,menubar=no";
		var printWin = window.open("printForm.asp?"+valStr,"printPage",featureStr);
		printWin.focus();
		return;
}
/****************************************************************************************
****************************************************************************************/
function changeSearchText(inText, type){
	document.searchparams.searchText.value = inText;
	document.searchparams.searchType.value = type;
	return;
}
/****************************************************************************************
****************************************************************************************/
function switchTab(base){
	if (top.tabWindow.document.tabparams){
		var oldTab = top.tabWindow.document.tabparams.currentView.value;
		document.images[oldTab].src = "/images/images_standard/tab"+oldTab+"_off.gif";
		top.tabWindow.document.tabparams.currentView.value = base;
		document.images[base].src = "/images/images_standard/tab"+base+"_on.gif";
		
		if(base == "locator"){
			//Netscape 4.7 section
			if(top.bottomTools.document.layers) {
				top.bottomTools.document.layers['divResetLayers'].style.visibility = 'hidden';
				top.bottomTools.document.layers['divRefreshMap'].style.visibility = 'hidden';
			} else if (top.bottomTools.document.all){
				top.bottomTools.document.all('divResetLayers').style.visibility = 'hidden';
				top.bottomTools.document.all('divRefreshMap').style.visibility = 'hidden';
			} else if (top.bottomTools.document.getElementsByTagName && top.bottomTools.document.getElementById){
				top.bottomTools.document.getElementById('divResetLayers').style.visibility = 'hidden';
				top.bottomTools.document.getElementById('divRefreshMap').style.visibility = 'hidden';
			}
			top.tabWindow.document.tabparams.maxy.value = top.map.document.mapparams.MaxY.value;
			top.tabWindow.document.tabparams.maxx.value = top.map.document.mapparams.MaxX.value;
			top.tabWindow.document.tabparams.miny.value = top.map.document.mapparams.MinY.value;
			top.tabWindow.document.tabparams.minx.value = top.map.document.mapparams.MinX.value;
		}
		top.tabWindow.document.tabparams.submit();
		return;
	}
}
