// CivXplorer
// loads the CX application, javascript and base variables

// user screen and window resolutions
	var reloadTimer = 0;
	var reloadInterval = 0;
	var sWidth = screen.width;
	var sHeight = screen.height;
	var winWidth = window.innerWidth; // netscape
	if (winWidth == null) winWidth = document.body.clientWidth; // ie
	var winHeight = window.innerHeight;  // netscape
	if (winHeight == null) winHeight = document.body.clientHeight; // ie
// layout
	var headerHeight = 60;
	var menubarWidth = 125;
	var toolmenuHeight = 24;
	var sidebarWidth = 200;
	var ovHeight = 175;
	var ovWidth = sidebarWidth - 5;
	var sidebarHeight = winHeight - headerHeight - toolmenuHeight*2 - ovHeight;
	var sidemenubarWidth = sidebarWidth/2;
	var CustomSidebarMenuCount = 0;
	var panbarWidth = 20;
	var borderWidth = 2;
	var iLeft = sidebarWidth + toolmenuHeight + panbarWidth;
	var iTop = headerHeight + toolmenuHeight + panbarWidth;
	iWidth = winWidth - iLeft - panbarWidth;
	iHeight = winHeight - iTop - panbarWidth;
	var iRight = iLeft + iWidth;
	var iBottom = iTop + iHeight;
	// support for resizing
	var oldWinWidth = winWidth;
	var oldWinHeight = winHeight;
	var attDisplayMaxed = false;
	
function loadCXScripts() {
	//if ((opener) && ((isIE) || (isOther) || ((isNav) && (!window.menubar.visible)))) {
		var cxScripts = document.createElement('script');
		cxScripts.setAttribute("type","text/javascript");
		cxScripts.setAttribute("src","javascript/cxCommon.js");
		document.getElementsByTagName('head')[0].appendChild(cxScripts);
	//} else {
		//document.getElementById('LoadProgram').style.visibility = "hidden";
		//alert("CivXplorer was not opened correctly!\n\nPlease email civxplorer@plansight.com for information on how to properly link and open the application.");
	//}
	return false;
}

function resizeMap() {
	// window size
	winWidth = window.innerWidth; // netscape
	if (winWidth == null) winWidth = document.body.clientWidth; // ie
	winHeight = window.innerHeight;  // netscape
	if (winHeight == null) winHeight = document.body.clientHeight; // ie
	// component sizes (map & sidebar)
	sidebarHeight = winHeight - headerHeight - toolmenuHeight*(CustomSidebarMenuCount+3) - ovHeight;
	iWidth = winWidth - iLeft - panbarWidth;
	iHeight = winHeight - iTop - panbarWidth;
	iRight = iLeft + iWidth;
	iBottom = iTop + iHeight;
	// header & menu components
	document.getElementById('cxHeader').style.width = winWidth + "px";	
	document.getElementById('menuBlankSpace').style.width = (winWidth-sidebarWidth) + "px";	
	// panbars
	panFrameWidth = winWidth - sidebarWidth - toolmenuHeight;
	panFrameHeight = winHeight - headerHeight - toolmenuHeight;
	document.getElementById('panBarBackground').style.width = panFrameWidth + "px";	
	document.getElementById('panBarBackground').style.height = panFrameHeight + "px";	
	document.getElementById('panBarN').style.left = (sidebarWidth+toolmenuHeight+iWidth/2-15) + "px";	
	document.getElementById('panBarS').style.left = (sidebarWidth+toolmenuHeight+iWidth/2-15) + "px";	
	document.getElementById('panBarS').style.top = (headerHeight+toolmenuHeight+panFrameHeight-18) + "px";	
	document.getElementById('panBarW').style.top = (headerHeight+toolmenuHeight+iHeight/2-15) + "px";	
	document.getElementById('panBarE').style.top = (headerHeight+toolmenuHeight+iHeight/2-15) + "px";	
	document.getElementById('panBarE').style.left = (sidebarWidth+toolmenuHeight+panFrameWidth-18) + "px";	
	document.getElementById('panBarNE').style.left = (sidebarWidth+toolmenuHeight+panFrameWidth-26) + "px";	
	document.getElementById('panBarSW').style.top = (headerHeight+toolmenuHeight+panFrameHeight-26) + "px";	
	document.getElementById('panBarSE').style.left = (sidebarWidth+toolmenuHeight+panFrameWidth-26) + "px";	
	document.getElementById('panBarSE').style.top = (headerHeight+toolmenuHeight+panFrameHeight-26) + "px";	
	// map components
	document.getElementById('theMapBackdrop').style.width = iWidth + "px";	
	document.getElementById('theMapBackdrop').style.height = iHeight + "px";	
	document.getElementById('theMap').style.width = iWidth + "px";	
	document.getElementById('theMap').style.height = iHeight + "px";	
	document.getElementById('theMapImage').style.width = iWidth + "px";	
	document.getElementById('theMapImage').style.height = iHeight + "px";	
	document.getElementById('theZoomBox').style.width = iWidth + "px";	
	document.getElementById('theZoomBox').style.height = iHeight + "px";	
	document.getElementById('thePolyline').style.width = iWidth + "px";	
	document.getElementById('thePolyline').style.height = iHeight + "px";	
	document.getElementById('theRubberband').style.width = iWidth + "px";	
	document.getElementById('theRubberband').style.height = iHeight + "px";	
	document.getElementById('LoadMap').style.width = iWidth + "px";	
	document.getElementById('LoadMap').style.height = iHeight + "px";	
	document.getElementById('LoadData').style.width = iWidth + "px";	
	document.getElementById('LoadData').style.height = iHeight + "px";	
	document.getElementById('cxHelp').style.width = iWidth + "px";	
	document.getElementById('cxHelp').style.height = iHeight + "px";	
	document.getElementById('mouseCapture').style.width = iWidth + "px";	
	document.getElementById('mouseCapture').style.height = iHeight + "px";	
	document.getElementById('mouseCaptureImage').style.width = iWidth + "px";	
	document.getElementById('mouseCaptureImage').style.height = iHeight + "px";	
	// sidebar components
	document.getElementById('menuQuickTools').style.height = (winHeight-headerHeight-toolmenuHeight) + "px";
	document.getElementById('ovMap').style.top = (headerHeight+toolmenuHeight*(CustomSidebarMenuCount+3)+sidebarHeight) + "px";
	document.getElementById('ovMap').style.height = ovHeight + "px";
	document.getElementById('ovZoomBox').style.top = (headerHeight+toolmenuHeight*(CustomSidebarMenuCount+3)+sidebarHeight) + "px";
	document.getElementById('ovZoomBox').style.height = ovHeight + "px";
	document.getElementById('ovHeader').style.top = (headerHeight+toolmenuHeight*(CustomSidebarMenuCount+2)+sidebarHeight) + "px";
	document.getElementById('cxTOC').style.height = sidebarHeight + "px";
	document.getElementById('cxLegend').style.height = sidebarHeight + "px";
	document.getElementById('cxDisclaimer').style.height = sidebarHeight + "px";	
	document.getElementById('cxSources').style.height = sidebarHeight + "px";
	// attribute display
	if ((document.getElementById('cxAttributeTop').style.visibility == "visible") && (document.getElementById('cxAttributeBottom').style.visibility == "visible")) { //attributes are displayed
		if (attDisplayMaxed) {
			document.getElementById('cxAttributeTop').style.width = winWidth + "px";
			document.getElementById('cxAttributeBottom').style.width = winWidth + "px";
			document.getElementById('cxAttributeBottom').style.height = (winHeight-theTopAttResize-headerHeight) + "px";
		} else {
			document.getElementById('cxAttributeTop').style.width = sidebarWidth + "px";
			document.getElementById('cxAttributeBottom').style.width = sidebarWidth + "px";
			document.getElementById('cxAttributeBottom').style.height  = (sidebarHeight-theTopAttResize) + "px";
		}
	} else if ((document.getElementById('cxAttributeTop').style.visibility == "hidden") && (document.getElementById('cxAttributeBottom').style.visibility == "visible")) { // dialog or startpage open
		if (attDisplayMaxed) {
			document.getElementById('cxAttributeBottom').style.width = winWidth + "px";
			document.getElementById('cxAttributeBottom').style.height = (winHeight-headerHeight) + "px";
		} else {
			document.getElementById('cxAttributeBottom').style.height = sidebarHeight + "px";
		}
	}
	// printable report/map display
	document.getElementById('cxInlineReports').style.width = winWidth + "px";
	document.getElementById('cxInlineReports').style.height = (winHeight-headerHeight) + "px";
	// timeout before map redraw
	window.clearTimeout(reloadTimer);
	reloadTimer = window.setTimeout("if (waitForMap) { reloadInterval=setInterval('checkOkToResize();',500) } else { sendMapRequest(); }",2000);
}			

// interval to check if previous map redraw is complete before resizing
function checkOkToResize() {
	if (!waitForMap) {
		clearInterval(reloadInterval);
		sendMapRequest();
	}
	return false;
}

