// Legacy startup code from ArcIMSparam.js

// setup test for Nav 4.0
var isIE   = false;
var isNav  = (navigator.appName.indexOf("Netscape")>=0);
var isNav4 = false;
var isIE4  = false;
var is5up  = false;

if (isNav) {
	if (parseFloat(navigator.appVersion)<5) {
		isNav4=true;
	} else {
		is5up = true;
	}
} else {
	isIE4=true;
	isIE=true;
	if ((navigator.appVersion.indexOf("MSIE 5")>0) || (navigator.appVersion.indexOf("MSIE 6")>0)) {
		isIE4 = false;
		is5up = true;
	}
}	

var webParams = "";
if (parent.MapFrame!=null) {
	webParams = parent.document.location.search;
} else {
	webParams = document.location.search;
}

// sets extents and event handling context. Called after checking for skin
// var in url param
function setExtentsAndEventHandling() {

	// startExt are both set when aimsMap.js loads, and may be reset when url
	// params are processed in USGS_NATMAP_utilities.js

	// if starting extents zero'd then flag to get start from mapservice
	if ((startExt.minX !=0) && (startExt.maxX !=0)) getStartingExtent=false;
	// if limit extents zero'd then flag to get max from mapservice
	if ((limitMinX != 0) && (limitMaxX != 0)) {
		getLimitExtent=false;
		enforceLimitExtent=true;
	}

	if (hasOVMap) {
		ovBbMinX = startOVLeft;
		ovBbMaxX = startOVRight;
		ovBbMaxY = startOVTop;
		ovBbMinY = startOVBottom;
	}

	if (aimsNavigationPresent) {
		// Set up event capture for mouse movement
		if (isNav) {
			document.captureEvents(Event.MOUSEMOVE);
			document.captureEvents(Event.MOUSEDOWN);
			document.captureEvents(Event.MOUSEUP);
			document.captureEvents(Event.MOUSEOUT);
		}
		document.onmousemove = getMouse;
		document.onmousedown = mapTool;
		document.onmouseup = chkMouseUp;
		document.onmouseout = clearCoords;
	}
}

function simpleSetup() {
	appDir = getPath(document.location.pathname);

	// set default crosshair threshold
	ovSymbolSwitchThreshold = defaultSkin.ovSymbolSwitchThreshold;

	// global for overview map. . . change if not on same frame as Map
	debugOn = globalDebugFlag;
	if (document.ovImage==null) hasOVMap = false;
	
	if (isIE)	{
		if (hasLayer("theTop")) document.all.theTop.style.cursor = "crosshair";
		if (hasOVMap) document.ovImage.style.cursor = "hand";
	}
}

function checkJsLibsAndStart() {
	// check for Javascript modules
	if (!(aimsXMLPresent) || !(aimsMapPresent)) {
		alert(msgList[0]);
	}
	else if (!nmUtilitiesPresent) {
		alert(msgList[16]);
	}
	else if (!nmXmlPresent) {
		alert(msgList[17]);
	}
	else if (!nmRegionsPresent) {
		alert(msgList[18]);
	}
	else if (!nmPrintPresent) {
		alert(msgList[19]);
	}
	else if (!nmOgcParamsPresent) {
		alert(msgList[20]);
	}
	else if (!nmMapToolsPresent) {
		alert(msgList[21]);
	}
	else if (!nmIdentifyPresent) {
		alert(msgList[22]);
	}
	else if (!nmConstantsPresent) {
		alert(msgList[23]);
	}
	else if (!nmClassPresent) {
		alert(msgList[24]);
	}
	else if (!ngFunctionsPresent) {
		alert(msgList[25]);
	}
	else {
		clickFunction("zoomin");
		if (!useInstantRefresh) {
			parent.RefreshFrame.document.location.replace(appDir + 'refresh.htm');
		}
		parent.ToolFrame.document.location = appDir + "toolbar.htm";
		//parent.USGSfooterFrame.document.location= appDir + 'USGSfooter.htm';

		startMap();
	}
}

function parseParams() {
	if (webParams!="") {
		processUrlParams(webParams);
	}
}
