
function WindowResizeEvent() {

    var bSubmitResize = true;
    
    if (top.scriptVersion.indexOf('Amanda') > -1) {
        if (!top.bMapSubmitted) {
            bSubmitResize = false;
        }
    }     
    
    if (bSubmitResize) {
        if (top.frames[4].document.body) {
	        var dWinWidth = top.frames[4].document.body.clientWidth;
            var dWinHeight = top.frames[4].document.body.clientHeight;
    	    
            var d = new Date();
            var curr_hour = d.getHours();
            var curr_min = d.getMinutes();
            var curr_seconds = d.getSeconds();
            
            var minutesSinceMidnight = (curr_hour * 60) + curr_min;
            var secondsSinceMidnight = (minutesSinceMidnight * 60) + curr_seconds;
            
            if ((dWinWidth != top.mapFrameBodyWidth) || (dWinHeight != top.mapFrameBodyHeight)) {
    	    
                if ((Math.abs(dWinWidth - top.mapFrameBodyWidth) > 100) || (Math.abs(dWinHeight - top.mapFrameBodyHeight) > 100)) {
                    
                    if (dWinWidth > 1920) {
                        dWinWidth = 1920;
                    }
                    
                    if (dWinHeight > 1200) {
                        dWinHeight = 1200;
                    }
                    
                    top.mapFrameBodyWidth = dWinWidth;
                    top.mapFrameBodyHeight = dWinHeight;
                    
                    top.mapWidth = dWinWidth * 15;
                    top.mapHeight = dWinHeight * 15;
                    
                    if ((secondsSinceMidnight - top.resizeSubmitSeconds) > 10) {      
                        RedrawMap();
                        top.bWindowResized = true;
                    }                   
                }
            }
        }
    }
}

function ShowCityMapLink() {
	try {
		objLink = top.frames[3].document.getElementById('SHOW_ALT_MAP');
	
		if (objLink) {	
			objLink.style.visibility = 'visible';
		}
	
	} catch (ex) {
		alert('ShowCityMapLink: ' + ex.message);
	}
}

function HideCityMapLink() {
	try {
		objLink = top.frames[3].document.getElementById('SHOW_ALT_MAP');
	
		if (objLink) {	
			objLink.style.visibility = 'hidden';
		}
	
	} catch (ex) {
		alert('HideCityMapLink: ' + ex.message);
	}
}


function ShowAltMap(iVersion) {

	try {
	
		var strLocation1 = '';
		var strLocation3 = '';
		
		if (iVersion == 1) {
			scriptVersion = "CityCounty";
			
			if (Z1 == 9) {
				Z2 = 1;
			}
			
		} else {
			scriptVersion = "County_Public_Init";
		}
		
		if (L1 != '') {
		
			if ((L1.indexOf('29-') > -1) || (L1.indexOf('30-') > -1) || (L1.indexOf('31-') > -1) || (L1.indexOf('29*') > -1) || (L1.indexOf('30*') > -1) || (L1.indexOf('31*') > -1)) {
				strLocation1 = L1;
			}

		} else if (L3 != '') {
		
			if ((L3.indexOf('29-') > -1) || (L3.indexOf('30-') > -1) || (L3.indexOf('31-') > -1)) {
				strLocation3 = L3;
			}
		}
		
		var sWidth = screen.width;
		var mapURL = "main.asp?Script=" + scriptVersion + "&Browser=W3C&Width=" + sWidth + "&L1=" + strLocation1 + 
					"&L3=" + strLocation3 + "&X=" + X + "&Y=" + Y + "&Z1=" + Z1 + "&Z2="+Z2 + "&Provider=" + top.strProvider + "&Server=" + strServiceLocation;
					
		window.location.href = mapURL;
		
	} catch (ex) {
		alert('ShowAltMap: ' + ex.message);
	}
}

function SetScope() {

	try {
		objScope = top.frames[3].document.getElementById('SCOPE');
	
		if (objScope) {	
			iMapScope = objScope.selectedIndex;
		}
	
	} catch (ex) {
		alert('SetScope: ' + ex.message);
	}
}

function SO(bitpos, i, intVal, extDisp) {
	top.selectOptions[bitpos].text[i] = extDisp;
	top.selectOptions[bitpos].value[i] = intVal;
}

function CheckLocBoxes() {

	if (locationBox[1].open) {

		if (locationBox[2].open) {
			return 0;
		} else {
			locationBox[2].open = 1;
			return 2;
		}
	} else {
		locationBox[1].open = 1;
		
		top.L3 = '';
		top.LABEL3 = '';
		top.L4 = '';
		top.LABEL4 = '';
		
		return 1;
	}
}

function SetMode(ckMode) {

	var oldMode = clickMode;
	if ((submitPending == 0) && (loadComplete == 1) && (errorCode == 0)) {

	  	clickMode = parseInt(ckMode);

		if (clickMode == 3) {
			queryData = 0;
		}

		if ((clickMode != oldMode) || (NS_Reset)) {

			HideQueryResults();
			HideErrorPanel();

			HidePanel(oldMode);
			ShowPanel(clickMode);

			ActiveTab(clickMode);
			PassiveTab(oldMode);
			
		}
		
		if (clickMode == IDENTIFY_MODE) {	
		    if (top.bWindowResized) {
		        top.bWindowResized = false;
		        RedrawMap();
		    }
		}
	}
}

function GenMapWindow() {
	HideMessage();
	HideErrorPanel();
	HideQueryResults();
	UpdateMap();
	QUERYFILE = '';
	
	var zStr = new String();
	zStr = "" + Z1;
	var pos = zStr.indexOf('C');
	if (pos == 0) {
		if (zRadio) {		
			if (zRadio[9]) {
				zRadio[9].checked = true;
			} else {
				zRadio[8].checked = true;			
			}
		}
	} else {
	
		if (Z1 < 9) {
			x = 8 - Z1;
			if (zRadio) {
				zRadio[x].checked = true;
			}
		}
		
		if (Z1 == 9) {
			if (zRadio[8]) {
				zRadio[8].checked = true;
			}
		}
	}
	HideRedraw();
	if (top.bProxyMap) {
		if (navigator.appName == 'Netscape') {
			HideMessageProxy();
		}
	}
}

function ShowMessage(msgStr) {

	HidePanel(clickMode);
	ShowMessagePanel(msgStr);
}

function HideMessage() {

	if (!bProxyMap) {
		HideMessagePanel();
		ShowPanel(clickMode);
	}
}

function HideMessageProxy() {

	HideMessagePanel();
	ShowPanel(clickMode);

}

function RedrawMap() {
	var oldMode = clickMode;
	redrawRequested = 1;
	QUERYFILE = '';
	SubmitMap(clickMode);
	redrawRequested = 0;
	clickMode = oldMode;
}

function FindLocations() {

	HideErrorPanel();

	Z2 = defaultFindZoom;

	bFindSubmit = true;
	
	if (bSitePlanFind) {
		SubmitMap(17);
	} else {
		SubmitMap(1);
	}
	bFindSubmit = false;
}

function GenQueryResult(qType, layers) {

	if (top.bProxyMap) {	
		HideMessageProxy();
	} else {
		HideMessage();
	}
	
	HideErrorPanel();	
	HideQueryResults();	
	ShowQueryResults(qType);
}

function GenQueryWindow() {

	var URLstr = 'Temp/' + QUERYFILE;
	
	if (top.bProxyMap) {	
		URLstr = QUERYFILE;
	}

	if ((top.queryWindow) && (!top.queryWindow.closed)) {
		top.queryWindow.close();
		top.queryWindow = window.open(URLstr, "QueryWindowName", "left=0,top=20,toolbar=no,menubar=yes,status=no,location=no,scrollbars=yes,resizable=yes,width="+qWinWidth+",height="+qWinHeight);	
	} else {
		top.queryWindow = window.open(URLstr, "QueryWindowName", "left=0,top=20,toolbar=no,menubar=yes,status=no,location=no,scrollbars=yes,resizable=yes,width="+qWinWidth+",height="+qWinHeight);
	}

	if (top.queryWindow) {
		top.queryWindow.focus();
	} else {
		top.queryWindow = window.open(URLstr, "QueryWindowName", "left=0,top=20,toolbar=no,menubar=yes,status=no,location=no,scrollbars=yes,resizable=yes,width="+qWinWidth+",height="+qWinHeight);
	}
	queryWindowOpen = 1;
}

function GenLinkWindow(URLnumStr) {

	var URLnumber = 0;
	URLnumber = parseInt(URLnumStr);

	if (URLlist[URLnumber] != "") {
		extLinkWindow = window.open(URLlist[URLnumber], "ExtLinkWindowName", "toolbar,menubar,status,location,scrollbars,resizable,width=640,height=400");
		linkWindowOpen = 1;
	}
}

function OpenLinkWindow(width,height,URLStr) {

   	var oWidth = parseInt(width);
   	var oHeight = parseInt(height);

	try {
		if (top.linkWindow) {
			top.linkWindow.close();
		}
	} catch (ex) {
	
	}
	
	try {
		top.linkWindow = window.open(URLStr, "LinkWindowName", "toolbar,menubar,status,location,scrollbars,resizable,width="+oWidth+",height="+oHeight);
		top.linkWindow.focus();
	} catch (ex) {
		alert('OpenLinkWindow: ' + ex.message);
	}
	linkWindowOpen = 1;
}

function ErrorMessage(eType) {

	HideMessagePanel();
	HidePanel(clickMode);
	ShowErrorPanel(eType);
}

function ErrorOK() {

	HideErrorPanel();
	ShowPanel(clickMode);
	FindLocations();

}

function ErrorCancel() {
	HideErrorPanel();
	ShowPanel(clickMode);
	replCount = 0;
}



function SetMenuSelect(selectObj, bitpos) {
	if (selectObj) {
		var selectVal = selectObj.options[selectObj.selectedIndex].value;
		selectMenuValues[bitpos] = selectVal;
	}
	
	ShowRedraw(bitpos);
}



function CloseWindow() {
	window.close();
}

function GenFullMenu(menuVersion) {
	top.frames[2].location = 'menu.asp?Menu=' + menuVersion + '&Regen=1';
}

function ClearL3L4() {

	L3 = '';
	L4 = '';

	bListSubmit = true;
	RedrawMap();
	bListSubmit = false;

}

function SetL3(strLocValue) {
	L3 = strLocValue;
}

function SetL4(strLocValue) {
	L4 = strLocValue;
}

function Initialize() {

	if (top.bHideMenu) {
		top.HideMenu();
	}
	
	top.bInitSubmit = true;
	var thinSubmit = false;
	var bShowDisclaimer = false;
	var strDisclaimerPage = '';

	for (var i = 0; i <= maxBitPos; i++) {
		if (top.checked[i]) {
		
			strDisclaimerPage = disClaimerMenuItems[i];
			if ((strDisclaimerPage != '') && (strDisclaimerPage)) {
				top.currentDisclaimerItem = i;
				if ((publicScript) && (top.scriptVersion != 'PublicZoningNoDisclaimer')) {
					bShowDisclaimer = true;
				}
				break;
			}
		}
	}

	if ((L3) || (L1)) {
		if (thinZoomVal) {
			defaultFindZoom = thinZoomVal;
		}
		
		if (L1) {

			OpenTextBox(L1Prompt, L1BitPos);
		
			if (top.B == 'NS') {
				tObj = eval('top.frames[0].document.layers.T1.document.INPUT1.TEXT1');			
				if (tObj) {
					tObj.value = L1;
				}
			} else {
				top.frames[0].document.LOCFORM.T1.value = L1;
			}
		}

		if (bShowDisclaimer) {
			ShowDisclaimer(strDisclaimerPage);
		} else {
		
			if (top.scriptVersion == 'CityCounty') {
				RedrawMap();
			} else {
				FindLocations();
			}
		}
		
	} else {
	
		if (bShowDisclaimer) {
			ShowDisclaimer(strDisclaimerPage);
		} else {
			RedrawMap();
		}
	}
}

function OpenHelpWindow(helpURLStr) {

	if (helpURLStr == 'default_help.htm') {
		helpWindow = window.open(helpURLStr, "LinkWindowName", "toolbar=no,menubar=no,status=no,location=no,scrollbars=no,resizable,width=400,height=200,top=200,left=300");
	} else if (helpURLStr == 'F_default_help.htm') {
		helpWindow = window.open(helpURLStr, "LinkWindowName", "toolbar=no,menubar=no,status=no,location=no,scrollbars=no,resizable,width=400,height=300,top=200,left=300");	
	} else {
		helpWindow = window.open(helpURLStr, "LinkWindowName", "toolbar=no,menubar=yes,status=no,location=no,scrollbars=yes,resizable,width=700,height=500,top=0,left=0");
	}
	
	helpWindow.focus();
}

function sleep(waitMilliSeconds) {

	var nowTime = new Date();
	var startMilliSeconds = 0;
	var endMilliSeconds = 0;
	var nowMilliSeconds = 0;

	startMilliSeconds = nowTime.getTime();
	endMilliSeconds = startMilliSeconds + waitMilliSeconds;

	nowMilliSeconds = nowTime.getTime();

	while (nowMilliSeconds < endMilliSeconds) {
		nowTime = new Date();
		nowMilliSeconds = nowTime.getTime();
	}
}

function Shutdown() {
	window.close();
}

function AcceptDisclaimer() {

	if (top.currentDisclaimerItem) {
		if (top.currentDisclaimerItem > 0) {
		
			var bitpos = top.currentDisclaimerItem;
			top.disClaimerMenuItems[top.currentDisclaimerItem] = '';
			top.currentDisclaimerItem = 0;
			top.HideDisclaimer(bitpos, true);
		}
	}
	
	top.bDisclaimerAccepted = true;
}

function StringReplace(findText, replaceText) {
	
	var originalString = new String(this);
		
	var pos = 0;
	var i = 0;
		
	pos = originalString.indexOf(findText);
			
	while (pos != -1) {
		
		preString = originalString.substring(0,pos);
		postString = originalString.substring(pos+1, originalString.length);
		originalString = preString + replaceText + postString;
		pos = originalString.indexOf(findText);
			
		i++;
			
	}
		
	return originalString;
}

//String.prototype.Replace = StringReplace;
