var helpstatus = "0";
     
function initTool(){

	lastTool = document.Main.mapaction.value;		
	//alert(lastTool);
	if (lastTool == "zoomin") {
		setmapaction("zoomin");
		setToolPic("zoomIn");
		setZoomBoxSettings();
		setState('zoomIn');
		
	} else if (lastTool == "zoomout") {
		setmapaction("zoomout");
		setToolPic("zoomOut");
		setZoomBoxSettings();
		setState('zoomOut');
		
	} else if (lastTool == "pan") {
		setmapaction("pan");
		setToolPic("pan");
		setZoomBoxSettings();
		setState('pan');
		
	} else if (lastTool == "identify") {
		//alert("lastTool = identify");
		
		//setmapaction("identify");
		//setToolPic("identify");
		//setZoomBoxSettings();
		//setState('identify');
			
			
	
		if ( (jsBldgCount == "0") || (jsBldgCount == "99") ) {
			alert(jsNoBldgMsg);
			setmapaction("identify");
			setToolPic("identify");
			setZoomBoxSettings();
			setState('identify');
		} else {
			
			//also open new window with selected building info
			var objWin;
			var sURL;
			
			sURL = "http://primus.nss.udel.edu/buildings/displayBuilding.action?building.code=" + jsBldgCode;
			
			objWin = window.open(sURL, "Identify", "height=700,width=800,menubar=yes,toolbar=yes,location=yes,status=yes,scrollbars=yes,resizable=yes");
  			if (parseInt(navigator.appVersion) >=4) objWin.window.focus();
			
						
			//setmapaction("zoomin");
			//setToolPic("zoomIn");
			//setZoomBoxSettings();
			//setState('zoomIn');
			setmapaction("identify");
			setToolPic("identify");
			setZoomBoxSettings();
			setState('identify');
		}
			

	} else {
		setmapaction("zoomin");
		setToolPic("zoomIn");
		setZoomBoxSettings();
		setState('zoomIn');
	}	
}


function setmapaction(actiontype) {

	document.Main.mapaction.value = actiontype;
	
	if (actiontype == "zoomcampus") {
		document.Main.submit();
		showLayer("loadLayer");		
	}
	
	if (actiontype == "zoomout_old") {
		
		//modify extents for on click zoom out
		var qwidth = parseFloat(Math.abs(maxx - minx) / 2.0);
		var qheight = parseFloat(Math.abs(maxy - miny) / 2.0);
		document.Main.maxx.value = maxx + qwidth;
		document.Main.minx.value = minx - qwidth;
		document.Main.maxy.value = maxy + qheight;
		document.Main.miny.value = miny - qheight;
			
		document.Main.submit();
		showLayer("loadLayer");
	}	
}

function hideshowlegend() {
	var legstatus = "";
	legstatus = document.Main.showleg.value;
	//alert(legstatus);
	
	if (legstatus == "0") {
		document.Main.showleg.value = "1";
		showLayer("legLayer");
		document.viewlegend.src = "images/viewlegend-over.gif";
	} else if (legstatus == "1") {
		document.Main.showleg.value = "0";
		hideLayer("legLayer");
		document.viewlegend.src = "images/viewlegend.gif";
	}
	

}


function setflag(layerflag) {

	//alert("setting flag: " + layerflag + "," + document.Main.aerialflag.value);

	/*
	if (layerflag == "aerial") {
	
		//alert(document.Main.aerialflag.value);
		
		if (document.Main.dframe.value == "Layers") {
			document.Main.dframe.value = "OrthoLayers";
		} else {		
			document.Main.dframe.value = "Layers";
		}
	}
	*/
	
		
	document.Main.mapaction.value = "hold";
	
	document.Main.submit();
	showLayer("loadLayer");
}



function revertToolPic() {
	// reset tool icons to non-set mode
	document.zoomin.src="images/zoomin.gif";
	document.zoomout.src="images/zoomout.gif";
	document.pan.src="images/movemap.gif";
	document.zoomfull.src="images/zoomfull.gif";
	document.identify.src="images/buildinginfo.gif";
}
	
	
function setToolPic(functName) {

	// set clicked button icon to set mode
	revertToolPic();
	if (functName=="zoomIn") {
		document.zoomin.src="images/zoomin-over.gif";
	} else if (functName=="zoomOut") {
		document.zoomout.src="images/zoomout-over.gif";
	} else if (functName=="pan") {
		document.pan.src="images/movemap-over.gif";					
	} else if (functName=="identify") {
		document.identify.src="images/buildinginfo-over.gif";
	}
}
	

function printmap_old(){

if (isIE) {
	  var img = document.all.semigray;
	  var imgName = img.src.toUpperCase();
	  if (imgName.substring(imgName.length-3, imgName.length) == "PNG")
	     {
		 var imgID = (img.id) ? "id='" + img.id + "' " : ""
		 var imgClass = (img.className) ? "class='" + img.className + "' " : ""
		 var imgTitle = (img.title) ? "title='" + img.title + "' " : "title='" + img.alt + "' "
		 var imgStyle = "display:inline-block;" + img.style.cssText 
		 if (img.align == "left") imgStyle = "float:left;" + imgStyle
		 if (img.align == "right") imgStyle = "float:right;" + imgStyle
		 if (img.parentElement.href) imgStyle = "cursor:hand;" + imgStyle		
		 var strNewHTML = "<span " + imgID + imgClass + imgTitle
		 + " style=\"" + "width:" + img.width + "px; height:" + img.height + "px;" + imgStyle + ";"
	     + "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader"
		 + "(src=\'" + img.src + "\', sizingMethod='scale');\"></span>" 
		 img.outerHTML = strNewHTML
	     }
}


	topStatus = "notready";
	
	showLayer("lyrprintmap");
	showLayer("lyrsemigray");
	setZoomBoxSettings();

}	

var pagetitle = "My UD Map";

function printHTML(){

	var objWin;
	var sURL;
			
	sURL = "printmap.jsp?mapimage=" + sImage + "&maptitle=" + pagetitle;
		
	//objWin = window.open(sURL, "MyUDMap", "height=550,width=800,menubar=yes,toolbar=yes,location=yes,status=yes,scrollbars=yes,resizeable=yes");
	//if (parseInt(navigator.appVersion) >=4) objWin.window.focus();
	
	document.location = sURL;
			
}

function settitle(){

	pagetitle = document.Main.maptitle.value; 
}


function printCancel() {
	hideLayer("lyrprintmap");
	hideLayer("lyrsemigray");
	
	topStatus = "ready";
	
	if (document.Main.mapaction.value == "zoomout") {
			setmapaction("zoomin");
			setToolPic("zoomIn");
			setZoomBoxSettings();
			setState('zoomIn');
	} else {
			setZoomBoxSettings();
	}
	
	showLayer("loadLayer");	
	history.go(0);
	showLayer("loadLayer");	
	
	return true;
}

var maphelpstatus = "0";

function showhelp(helpLyr) {

	//alert(helpstatus);
	
	if (helpLyr == "mapHelp") {
		if (maphelpstatus == "0") {
			maphelpstatus = "1";
			document.viewhelp.src = "images/help-over.gif";
			showLayer(helpLyr);
		} else {
			maphelpstatus = "0";
			document.viewhelp.src = "images/help.gif";
			hideLayer(helpLyr);
		}
	} else {
	
		if (helpstatus == "0") {
			helpstatus = "1";
			showLayer(helpLyr);
		} else if (helpstatus == "1") {
			helpstatus = "0";
			hideLayer(helpLyr);
		}
	}
}

function zoommapfirst() {
	
	//after an identify, if a user uses the pull-down menu immediately, an error occurrs - this fixes it.
	setmapaction("zoomin");
	setToolPic("zoomIn");
	setZoomBoxSettings();
	setState('zoomIn');
			
	topStatus = "notready";
	showLayer("theTopCover");
	setZoomBoxSettings();
}

function zoommapclear() {

	topStatus = "ready";
	hideLayer("theTopCover");
	setZoomBoxSettings();
}

function zoommap(zoomlevels) {

	var newlevel = "";
	newlevel = zoomlevels[zoomlevels.selectedIndex].value;
	
	if (newlevel != "n") {
	
	
	if ((newlevel == "laird") || (newlevel == "northcentral") || (newlevel == "west") || (newlevel == "central") || (newlevel == "east") || (newlevel == "south")) {
		document.Main.mapaction.value = "zoomcampus";
		document.Main.campus.value = newlevel;
	}
	
	
	//modify extents
	var halfwidth = parseFloat(Math.abs(maxx - minx) / 2.0);
	var halfheight = parseFloat(Math.abs(maxy - miny) / 2.0);

	if (newlevel == "zoomoutby2") {	
		document.Main.maxx.value = maxx + halfwidth;
		document.Main.minx.value = minx - halfwidth;
		document.Main.maxy.value = maxy + halfheight;
		document.Main.miny.value = miny - halfheight;
	
	} else if (newlevel == "zoomoutby4") {
		document.Main.maxx.value = maxx + halfwidth * 3.0;
		document.Main.minx.value = minx - halfwidth * 3.0;
		document.Main.maxy.value = maxy + halfheight * 3.0;
		document.Main.miny.value = miny - halfheight * 3.0;
	
	} else if (newlevel == "zoominby2") {
		document.Main.maxx.value = maxx - halfwidth / 2.0;
		document.Main.minx.value = minx + halfwidth / 2.0;
		document.Main.maxy.value = maxy - halfheight / 2.0;
		document.Main.miny.value = miny + halfheight / 2.0;
	
	} else if (newlevel == "zoominby4") {
		document.Main.maxx.value = maxx - halfwidth / 1.333;
		document.Main.minx.value = minx + halfwidth / 1.333;
		document.Main.maxy.value = maxy - halfheight / 1.333;
		document.Main.miny.value = miny + halfheight / 1.333;
	
	}
	
	hideLayer('theTopCover');
	document.Main.submit();
	showLayer("loadLayer");
	
	}
	
}


function printmap() {
	
	//included here should be the map extent and any visible additional layers
	
	var sURL;
	
	var iBluelights = "off";
	var iAerial = "off";
	
	if (document.Main.bluelightsflag.checked) { iBluelights = "on"; }
	if (document.Main.aerialflag.checked) { iAerial = "on"; }
	
	//iBluelights = document.Main.bluelightsflag.checked
	//iEntrances = document.Main.entrancesflag.checked
	//iAerial = document.Main.aerialflag.checked
			
	sURL = "printmap.jsp?action=init&minx=" + minx + "&maxx=" + maxx + "&miny=" + miny + "&maxy=" + maxy + "&bluelightsflag=" + iBluelights + "&aerialflag=" + iAerial;
			
	document.location = sURL;
}

