
function flipStyle(id, styleName) {
	document.getElementById(id).className = styleName;
}

var dblAlignmentX = 0;
var dblAlignmentY = 0;
var dblAlignmentScale = 0;
var dblAlignmentRotation = 0;

var MapFrameMargin = 165;

var objCheckinTimer = null;

var p_oAJAXsubindex = null;


function createXMLHttpRequest() {
	if (window.ActiveXObject) {
		return new ActiveXObject("Microsoft.XMLHTTP");
	} else if (window.XMLHttpRequest) {
		return new XMLHttpRequest();
	} else {
		return null;
	}
}


function executeAJAXTypesLookup() {
	var l_pAJAX = createXMLHttpRequest();

	if (l_pAJAX != null) {
		l_pAJAX.open("GET", "ajax/ajaxGetMetadata.php?" + buildMapRequestString() + "&metadata=1&ts=" + (new Date().getTime()), true);
		l_pAJAX.onreadystatechange = function() {
			if (l_pAJAX.readyState == 4) {
				if (l_pAJAX.status == 200) {
					if (l_pAJAX.responseText.indexOf('<script') == 0) {
						executeJavascriptFunctions(l_pAJAX.responseText);
					} else {
						strTempArray = l_pAJAX.responseText.split(',');
						MapServiceExtents.X1 = parseFloat(strTempArray[1]);
						MapServiceExtents.Y1 = parseFloat(strTempArray[2]);
						MapServiceExtents.X2 = parseFloat(strTempArray[3]);
						MapServiceExtents.Y2 = parseFloat(strTempArray[4]);
						MapServiceExtents.init = true;

						MapServiceCurrent = MapServiceExtents.clone();

						switch(parseInt(intInitialMapExtent)){
							case 0: //Top Half
								MapServiceCurrent.Y2 = MapServiceExtents.Y1 - (MapServiceExtents.getWidth() * (getDIVHeight('divMapFrame' + intNextMapDiv) / getDIVWidth('divMapFrame' + intNextMapDiv)));
								break;

							case 1: //Bottom Half
								MapServiceCurrent.Y1 = MapServiceExtents.Y2 + (MapServiceExtents.getWidth() * (getDIVHeight('divMapFrame' + intNextMapDiv) / getDIVWidth('divMapFrame' + intNextMapDiv)));
								break;

							case 2: //Full Extents
								//Do nothing
								break;
						}

						pollHotSpots();
						truncateHistory();
						regenerateMainImage();
						validateHistory();
					}
				} else {
					alert("Error Polling page 'Version Info' (Error status = " + l_pAJAX.status + ")");
				}

				l_pAJAX = null;
			}
		};
		l_pAJAX.send(null);
	}
}

function executeAJAXVersionLookup() {
	var l_pAJAX = createXMLHttpRequest();

	if (l_pAJAX != null) {
		l_pAJAX.open("GET", "ajax/ajaxGetVersionMetadata.php?versionid=" + MapVersionID + "&mappage=" + MapPageName[0] + "&ts=" + (new Date().getTime()), true);
		l_pAJAX.onreadystatechange = function() {
			if (l_pAJAX.readyState == 4) {
				if (l_pAJAX.status == 200) {
					if (l_pAJAX.responseText.indexOf('<script') == 0) {
						executeJavascriptFunctions(l_pAJAX.responseText);
					} else if (l_pAJAX.responseText.indexOf('VERSIONINFO|||') == 0) {
						strTempArray = l_pAJAX.responseText.split('~~~');
						strTempArray2 = strTempArray[0].split('|||');

						MapLayerID = [];
						MapLayerType = [];
						MapLayerDisplay = [];
						MapLayerVisible = [];
						MapGotoDisplay = [];
						MapGotoLink = [];
						MapVersionID = strTempArray2[1];
						MapVersionDisplay = strTempArray2[2];
						MapVersionMapGrid = strTempArray2[3];

						var boolLayerAlreadyVis = false;
						var boolLayerMatch = false;

						for(x = 1; x < strTempArray.length; x++) {
							strTempArray2 = strTempArray[x].split('|||');

							boolLayerMatch = false;

							if (x > 1) {
								if ((MapLayerID[MapLayerID.length-1] == strTempArray2[0]) &&
									(MapLayerType[MapLayerType.length-1] == strTempArray2[1])) {

									boolLayerMatch = true;

								}
							}

							if (!boolLayerMatch) {
								MapLayerID[MapLayerID.length] = strTempArray2[0];
								MapLayerType[MapLayerType.length] = strTempArray2[1];
								MapLayerDisplay[MapLayerDisplay.length] = strTempArray2[2];

								if ((strTempArray2[1] == "PRILINEWORK") && (!boolLayerAlreadyVis)) {
									MapLayerVisible[MapLayerVisible.length] = true;
									boolLayerAlreadyVis = true;
								} else {
									MapLayerVisible[MapLayerVisible.length] = false;
								}
							}
						}

						updateContent('divProjectInfo', '<table cellspacing=2 cellpadding=0 border=0><tr align="right"><td><font size="4px" color="#FFFFFF">' + MapVersionDisplay + ' - ' + MapPageName[0] + '</td></tr></table>');

						//Refresh Frames
						if (isFrameVisibleSettings('divToolFrame')){
							loadFramePositionSettings('divToolFrame');
							showLayer('divToolFrame');
							keepFrameInBounds('divToolFrame');
							if (strToolbarType == "") setToolBar('divNavigationFrame');
						}

						if (isFrameVisibleSettings('divAlignmentFrame')){
							loadFramePositionSettings('divAlignmentFrame');
							keepFrameInBounds('divAlignmentFrame');
							refreshAlignmentLayer();
						}

						if (isFrameVisibleSettings('divHotspotFrame')){
							loadFramePositionSettings('divHotspotFrame');
							keepFrameInBounds('divHotspotFrame');
							showLayer('divHotspotFrame');
						}

						//Execute several AJAX lookups
						refreshMapLayers();
						refreshMapGrid();
						pollGotoFrame();
						executeAJAXTypesLookup();
					}
				} else {
					alert("Error Polling page 'Version Info' (Error status = " + l_pAJAX.status + ")");
				}

				l_pAJAX = null;
			}
		};
		l_pAJAX.send(null);
	}
}


var pAJAXTimer = null;
var pMapTimer = null;


/* Actions */
var intNextMapDiv = 1;
var intObjectsLoading = 0;
var mouseDownOV = false;
var initMouseX = 0;
var initMouseY = 0;
var initBoxX = 0;
var initBoxY = 0;

var bMouseDownExtentsWindow = false;
var bMouseOverExtentsWindow = false;

var OVDragMode = 0;


function fireToggleOverview() {
	if (!MapServiceStarted) return;

	if (isFrameVisibleSettings('divMapOVFrame')) {
		fireSwapMapOVLayer(false);
	} else {
		setFrameVisibleSettings('divMapOVFrame', true, false);
		if (strLastOVSignature != strLastMapSignature) {
			//Reload Overview Map
			regenerateOVImage();
		} else {
			fireSwapMapOVLayer(true);
		}
	}
}


function fireOVWindowDown(e) {
	mouseDownOV = true;
	initMouseX = getMouseX(e);
	initMouseY = getMouseY(e);
	initBoxX = getDIVLeft("MapOVViewExtents");
	initBoxY = getDIVTop("MapOVViewExtents");
}

function fireOVWindowMove(e) {
	if(mouseDownOV) {
		if(OVDragMode==0){
			OVDragMode=1;
		}
	}
	if(OVDragMode==1) {
		var newx = initBoxX + (getMouseX(e) - initMouseX);
		var newy = initBoxY + (getMouseY(e) - initMouseY);

		if (newx < 0) newx = 0;
		if (newy < 0) newy = 0;
		if (newx + getDIVWidth('MapOVViewExtents') > getDIVWidth('divMapOVFrame')) newx = (getDIVWidth('divMapOVFrame') - getDIVWidth('MapOVViewExtents'));
		if (newy + getDIVHeight('MapOVViewExtents') > getDIVHeight('divMapOVFrame')) newy = (getDIVHeight('divMapOVFrame') - getDIVHeight('MapOVViewExtents'));

		moveLayer("MapOVViewExtents", newx, newy);
	}
}

function fireOVWindowUp(e) {
	mouseDownOV = false;
	if(OVDragMode==1) {
		var extentsXRange = MapServiceExtents.X2 - MapServiceExtents.X1;
		var extentsYRange = MapServiceExtents.Y2 - MapServiceExtents.Y1;

		var tempExtents = new clsExtents();
		tempExtents.X1 = MapServiceExtents.X1 + ((getDIVLeft("MapOVViewExtents") / getDIVWidth('divMapOVFrame')) * extentsXRange);
		tempExtents.Y1 = MapServiceExtents.Y1 + ((getDIVTop("MapOVViewExtents") / getDIVHeight('divMapOVFrame')) * extentsYRange);
		tempExtents.X2 = MapServiceExtents.X1 + ((getDIVRight("MapOVViewExtents") / getDIVWidth('divMapOVFrame')) * extentsXRange);
		tempExtents.Y2 = MapServiceExtents.Y1 + ((getDIVBottom("MapOVViewExtents") / getDIVHeight('divMapOVFrame')) * extentsYRange);
		tempExtents.init = true;
		MapServiceCurrent = tempExtents.clone();

		OVDragMode = 0;
		truncateHistory();
		regenerateMainImage();
		validateHistory();
	}
}

function fireOVWindowJump(e) {
	var newx = (getMouseX(e) - getDIVLeft('divBodyFrame')) - (getDIVWidth('MapOVViewExtents') / 2);
	var newy = (getMouseY(e) - getDIVTop('divBodyFrame')) - (getDIVHeight('MapOVViewExtents') / 2);

	if (newx < 0) newx = 0;
	if (newy < 0) newy = 0;
	if (newx + getDIVWidth('MapOVViewExtents') > getDIVWidth('divMapOVFrame')) newx = (getDIVWidth('divMapOVFrame') - getDIVWidth('MapOVViewExtents'));
	if (newy + getDIVHeight('MapOVViewExtents') > getDIVHeight('divMapOVFrame')) newy = (getDIVHeight('divMapOVFrame') - getDIVHeight('MapOVViewExtents'));

	moveLayer("MapOVViewExtents", newx, newy);

	OVDragMode = 1;
	fireOVWindowUp(e);
}

function fireMapUpdate() {
	moveLayer('divMapFrame' + intNextMapDiv, MapFrameMargin, 0);
	moveLayer('divSVGFrame', MapFrameMargin, 0);

	resizeLayer('divBodyFrame', getWindowWidth(), getWindowHeight() - getDIVTop("divBodyFrame"));
	resizeLayer('divMapFrame' + intNextMapDiv, getWindowWidth() - MapFrameMargin, getWindowHeight() - (getDIVTop("divBodyFrame") - 2));
	resizeLayer('divSVGFrame', getWindowWidth() - MapFrameMargin, getWindowHeight() - (getDIVTop("divBodyFrame") - 2));

	moveLayer('divMapFramePadding', 0, 0);
	resizeLayer('divMapFramePadding', MapFrameMargin, getWindowHeight() - getDIVTop("divBodyFrame"));

	initService();

	pMapTimer = null;
}

function setMapPage(map) {
	MapPageName = [];
	MapPageName[0] = map;
	fireMapUpdate();
}

function setMapParcel(version, parcel) {
	MapPageName = [];
	MapVersionID = version;

	var l_pAJAX = createXMLHttpRequest();

	if (l_pAJAX != null) {
		l_pAJAX.open("GET", "ajax/ajaxSearchLookup_Parcel.php?version=" + version + "&parcel=" + parcel + "&ts=" + GetCurrentTime(), true);
		l_pAJAX.onreadystatechange = function() {
			if (l_pAJAX.readyState == 4) {
				if (l_pAJAX.status == 200) {
					if (l_pAJAX.responseText.indexOf("MAP=") == 0) {
						MapPageName[0] = l_pAJAX.responseText.substring(4);
						fireMapUpdate();
					} else if (l_pAJAX.responseText.indexOf("ERROR") == 0) {
						alert("Error searching for Parcel number");
					} else {
						executeJavascriptFunctions(l_pAJAX.responseText);
					}
				} else {
					alert("Error Polling page 'Parcel Search' (Error status = " + l_pAJAX.status + ")");
				}

				intObjectsLoading = 0;
				hideLoading();
				l_pAJAX = null;
			}
		};
		l_pAJAX.send(null);
	}
}

function fireMapResize() {
	if (pMapTimer != null) clearTimeout(pMapTimer);

	if ((getWindowHeight() - getDIVTop("divBodyFrame")) > 0) {
		resizeLayer('divBodyFrame', getWindowWidth(), getWindowHeight() - getDIVTop("divBodyFrame"));
		resizeLayer('divMapFrame' + intNextMapDiv, getWindowWidth() - MapFrameMargin, getWindowHeight() - (getDIVTop("divBodyFrame") - 2));
		resizeLayer('divMapFrame' + (intNextMapDiv == 1?2:1), getWindowWidth() - MapFrameMargin, getWindowHeight() - (getDIVTop("divBodyFrame") - 2));
	}

	if (strLastMapSignature == "") return;

	pMapTimer = setTimeout('fireMapUpdate()', 1000);
}

function fireSwapMapLayer(id) {
	showLayer('divMapFrame' + id);
	showLayer('divMapFramePadding');

	var otherid = (id == 1?2:1);

	hideLayer('divMapFrame' + otherid);

	setTimeout('fireSwapMapZIndex()', 300);

	intNextMapDiv = otherid;

	intObjectsLoading--;
	hideLoading();

	refreshMapHotSpots();
}

function fireSwapMapOVLayer(visible) {
	setFrameVisibleSettings('divMapOVFrame', visible, true);
	intObjectsLoading--;
	hideLoading();
}

function fireSwapMapZIndex() {
	document.getElementById("divMapFrame" + ((intNextMapDiv%2)+1)).style.zIndex = 50;
	document.getElementById("divMapFrame" + intNextMapDiv).style.zIndex = 40;
	moveLayer('divMapFrame' + intNextMapDiv, MapFrameMargin, 0);
}

function executeSearchLookup() {
	if ((document.getElementById('txtSearchMapPage').value.length > 1) && (document.getElementById('cmbSearchCounty').value.length > 0)) {

		updateContent('ajaxSearchPanel','<table><tr><td><img src="images/loading_spinner.gif" /></td><td><font size="2" face="Verdana" color="#555555"><b>Pulling List</td></tr></table>');
		moveLayer('ajaxSearchPanel', findPosX(document.getElementById('txtSearchMapPage'))+1, findPosY(document.getElementById('txtSearchMapPage')) + document.getElementById('txtSearchMapPage').offsetHeight);
		showLayer('ajaxSearchPanel');


		var l_pAJAX = createXMLHttpRequest();

		if (l_pAJAX != null) {
			l_pAJAX.open("GET", "ajax/ajaxSearchLookup.php?version=" + document.getElementById('cmbSearchCounty').value + "&map=" + document.getElementById('txtSearchMapPage').value, true);
			l_pAJAX.onreadystatechange = function() {
				if (l_pAJAX.readyState == 4) {
					if (l_pAJAX.status == 200) {
						if (l_pAJAX.responseText.indexOf('<script') == 0) {
							executeJavascriptFunctions(l_pAJAX.responseText);
						} else {
							updateContent("ajaxSearchPanel", l_pAJAX.responseText);
						}
					} else {
						updateContent("ajaxSearchPanel", "Search Failed!");
					}

					l_pAJAX = null;
				}
			};
			l_pAJAX.send(null);
		}
	} else {
		killSearchLookup();
	}
}

function executeSearchLookup2() {
	if (document.getElementById('txtHSLinkPage').value.length > 1) {

		updateContent('ajaxSearchPanel2','<table><tr><td><img src="images/loading_spinner.gif" /></td><td><font size="2" face="Verdana" color="#555555"><b>Pulling List</td></tr></table>');
		moveLayer('ajaxSearchPanel2', findPosX(document.getElementById('txtHSLinkPage'))+1, findPosY(document.getElementById('txtHSLinkPage')) + document.getElementById('txtHSLinkPage').offsetHeight);
		showLayer('ajaxSearchPanel2');


		var l_pAJAX = createXMLHttpRequest();

		if (l_pAJAX != null) {
			l_pAJAX.open("GET", "ajax/ajaxSearchLookup2.php?version=" + MapVersionID + "&map=" + document.getElementById('txtHSLinkPage').value, true);
			l_pAJAX.onreadystatechange = function() {
				if (l_pAJAX.readyState == 4) {
					if (l_pAJAX.status == 200) {
						if (l_pAJAX.responseText.indexOf('<script') == 0) {
							executeJavascriptFunctions(l_pAJAX.responseText);
						} else {
							updateContent("ajaxSearchPanel2", l_pAJAX.responseText);
						}
					} else {
						updateContent("ajaxSearchPanel2", "Search Failed!");
					}

					l_pAJAX = null;
				}
			};
			l_pAJAX.send(null);
		}
	} else {
		killSearchLookup2();
	}
}

function executeSubindexSearchLookup(){
	if (document.getElementById('txtSearchSubindex').value.length > 1) {

		if (p_oAJAXsubindex != null) {
			if (p_oAJAXsubindex.readyState != 0 && p_oAJAXsubindex.readyState != 4) {
				p_oAJAXsubindex.abort();
			}
		}

		p_oAJAXsubindex = createXMLHttpRequest();

		if (p_oAJAXsubindex != null) {
			intObjectsLoading++;
			showLoading();

			p_oAJAXsubindex.open("GET", "ajax/ajaxSearchLookup_Subindex.php?version=" + document.getElementById('cmbSearchSubdivisionCounty').value + "&subname=" + document.getElementById('txtSearchSubindex').value, true);
			p_oAJAXsubindex.onreadystatechange = function() {
				if (p_oAJAXsubindex.readyState == 4) {
					if (p_oAJAXsubindex.status == 200) {
						var strAllSubs = p_oAJAXsubindex.responseText.split("|||");
						var strHTMLOutput = "No Subdivisions Found Matching '<b>" + document.getElementById('txtSearchSubindex').value + "</b>'";

						if (p_oAJAXsubindex.responseText.length > 0) {

							strHTMLOutput = "<table width=\"360\" cellpadding=\"0\" cellspacing=\"0\" border=\"0\">";
							for(var x = 0; x < strAllSubs.length; x++) {
								var strThisSub = strAllSubs[x].split("|");
								if (strThisSub.length == 2) {
									if ((strThisSub[0] != "")&&(strThisSub[1] != "")) {
										strHTMLOutput += "<tr valign=\"top\"><td align=\"left\">" + strThisSub[0] + "</td><td align=\"right\"><a href=\"javascript:MapVersionID = " + document.getElementById('cmbSearchSubdivisionCounty').value + "; setMapPage('" + strThisSub[1] + "'); if (boolAutoCloseSearch) hideSearchFrame();\">" + strThisSub[1] + "</a></td></tr>";
									}
								}
							}
							strHTMLOutput += "</table>";

						}

						updateContent('divSearchSubdivisionResultsFrame', strHTMLOutput);
					}

					intObjectsLoading = 0;
					hideLoading();
					p_oAJAXsubindex = null;
				}
			};
			p_oAJAXsubindex.send(null);
		}
	} else {
		updateContent('divSearchSubdivisionResultsFrame', 'Start typing a subname above to begin (two or more characters)...');
	}
}

function killSearchLookup() {
	hideLayer('ajaxSearchPanel');
	updateContent('ajaxSearchPanel', '');
}

function killSearchLookup2() {
	hideLayer('ajaxSearchPanel2');
	updateContent('ajaxSearchPanel2', '');
}

function assignMapPage(strMap) {
	strSearchMappage = strMap;
	document.getElementById('txtSearchMapPage').value = strMap;
	document.getElementById('btnSearchFetchMap').disabled = false;
	document.getElementById('txtSearchMapPage').focus();
	killSearchLookup();
}

function assignMapPage2(strMap) {
	document.getElementById('txtHSLinkPage').value = strMap;
	killSearchLookup2();
}


function showLoginFrame(extra) {
	hideControlFrame();
	hideFeedbackLinks();
	hideSearchFrame();
	hideToolFrame();

	var myBodyFrame = document.getElementById("divBodyFrame");

	var myHotSpotPreview = document.getElementById("divHotSpotPreview");
	if (myHotSpotPreview != null) {
		myBodyFrame.removeChild(myHotSpotPreview);
	}

	//Kill all HotStopDIV's Here
	var myHotspot = null;
	while((myHotspot = document.getElementById("divHotSpot")) != null)
	{
		myBodyFrame.removeChild(myHotspot);
	}

	hideLayer('divPrintFrame');
	hideLayer('divOptionsFrame');
	hideLayer('divHelpFrame');
	hideLayer('divMapOVFrame');
	hideLayer('divAlignmentFrame');
	hideLayer('divHotspotFrame');
	hideLayer('divFeedbackFrame');
	hideLayer('divMapFrame' + (intNextMapDiv == 1?2:1));
	hideLayer('divMapFramePadding');
	updateContent('divLoginInfo', '');
	updateContent('divProjectInfo', '');
	strSearchCounty = "";
	strSearchMappage = "";
	strSearchParcel = "";
	strSearchSubindex = "";
	strSearchTownship = "";
	strSearchArea = "";
	strSearchType = "";
	strToolbarType = "";
	setTool('nothing');
	setMouseCursor("default");
	resetAll();
	statusBar("Sidwellmaps.com: Please Login");
	pollLoginFrame(extra);
}

function showControlFrame() {
	showLayer('divTopNavControls');
}

function hideControlFrame() {
	hideLayer('divTopNavControls');
}

function hideSearchFrame() {
	killSearchLookup();
	setSearchToolBar('');
	hideLayer('divSearchFrame');
}

function hideToolFrame() {
	setToolBar('');
	hideLayer('divToolFrame');
}

function executeJavascriptFunctions(jscode) {
	jscode = jscode.replace("<!--script", "<script");
	jscode = jscode.replace("<!--", "");
	jscode = jscode.replace("-->", "");

	intCurrentPOS = jscode.indexOf("<script", 0);

	while (intCurrentPOS > -1) {

		temp = jscode.substring(jscode.indexOf(">", intCurrentPOS)+1, jscode.indexOf("</script", intCurrentPOS));
		eval(temp);

		intCurrentPOS = jscode.indexOf("<script", jscode.indexOf("</script", intCurrentPOS)+17);
	}
}

/* Polling events for DIV content */
function pollLoginFrame(s_postdata){
	var l_pAJAX = createXMLHttpRequest();

	if (l_pAJAX != null) {
		intObjectsLoading++;
		showLoading();

		//Save Settings
		if (s_postdata.indexOf('logout=true') != -1) {
			s_postdata += "&settings=";
			s_postdata += "toolframeposition|" + getFramePositionSettings('divToolFrame') + "|||";
			s_postdata += "toolframevisible|" + isFrameVisibleSettings('divToolFrame') + "|||";
			s_postdata += "navigationmode|" + intNavMode + "|||";
			s_postdata += "initmapextent|" + intInitialMapExtent + "|||";
			s_postdata += "mapovframevisible|" + isFrameVisibleSettings('divMapOVFrame');
		}

		l_pAJAX.open("GET", "divLoginFrame.php?" + s_postdata + "&ts=" + GetCurrentTime(), true);
		l_pAJAX.onreadystatechange = function() {
			if (l_pAJAX.readyState == 4) {
				if (l_pAJAX.status == 200) {
					updateContent('divLoginFrame', l_pAJAX.responseText);
					executeJavascriptFunctions(l_pAJAX.responseText);
				} else {
					alert("Error Polling page 'Login Frame' (Error status = " + l_pAJAX.status + ")");
				}

				intObjectsLoading = 0;
				hideLoading();
				l_pAJAX = null;
			}
		};
		l_pAJAX.send(null);
	}
}

function pollPrintFrame(){
	loadFramePositionSettings('divPrintFrame');
	keepFrameInBounds('divPrintFrame');

	if (strSearchParcel != "") {
		getDIV("txtPrintTitle", false).value = "PIN #: " + strSearchParcel;
	}

	showLayer('divPrintFrame', null, null);
	setFrameFocus('divPrintFrame');
}

function pollSearchFrame(){
	loadFramePositionSettings('divSearchFrame');
	keepFrameInBounds('divSearchFrame');

	showLayer('divSearchFrame', null, null);
	setFrameFocus('divSearchFrame');
	hideLayer('divLoginFrame');

	if(strSearchType == "") {
		pollSearchGeneralFrame();
		pollSearchSubdivisionFrame();
		setSearchToolBar("divSearchGeneralFrame");
	} else {
		setSearchToolBar(strSearchType);
	}
}

function pollSearchGeneralFrame(s_postdata){
	var l_pAJAX = createXMLHttpRequest();

	if (l_pAJAX != null) {
		intObjectsLoading++;
		showLoading();

		if ((s_postdata == null) || (s_postdata == "")) {
			s_postdata = "county=" + strSearchCounty + "&" +
						  "mappage=" + strSearchMappage + "&" +
						  "parcel=" + strSearchParcel + "&" +
						  "township=" + strSearchTownship + "&" +
						  "area=" + strSearchArea;

		}

		l_pAJAX.open("GET", "divSearchGeneralFrame.php?" + s_postdata + "&ts=" + GetCurrentTime(), true);
		l_pAJAX.onreadystatechange = function() {
			if (l_pAJAX.readyState == 4) {
				if (l_pAJAX.status == 200) {
					updateContent('divSearchGeneralFrame', l_pAJAX.responseText);
					executeJavascriptFunctions(l_pAJAX.responseText);
				} else {
					alert("Error Polling page 'Search General Frame' (Error status = " + l_pAJAX.status + ")");
				}

				intObjectsLoading = 0;
				hideLoading();
				l_pAJAX = null;
			}
		};
		l_pAJAX.send(null);
	}
}

function pollSearchSubdivisionFrame(s_postdata){
	var l_pAJAX = createXMLHttpRequest();

	if (l_pAJAX != null) {
		intObjectsLoading++;
		showLoading();

		if ((s_postdata == null) || (s_postdata == "")) {
			s_postdata = "county=" + strSearchCounty + "&" +
						  "subindex=" + strSearchSubindex;

		}

		l_pAJAX.open("GET", "divSearchSubdivisionFrame.php?" + s_postdata + "&ts=" + GetCurrentTime(), true);
		l_pAJAX.onreadystatechange = function() {
			if (l_pAJAX.readyState == 4) {
				if (l_pAJAX.status == 200) {
					updateContent('divSearchSubdivisionFrame', l_pAJAX.responseText);
					executeJavascriptFunctions(l_pAJAX.responseText);
				} else {
					alert("Error Polling page 'Search Subdivision Frame' (Error status = " + l_pAJAX.status + ")");
				}

				intObjectsLoading = 0;
				hideLoading();
				l_pAJAX = null;
			}
		};
		l_pAJAX.send(null);
	}
}

function pollOptionsFrame(s_postdata){
	var l_pAJAX = createXMLHttpRequest();

	if (l_pAJAX != null) {
		intObjectsLoading++;
		showLoading();

		l_pAJAX.open("GET", "divOptionsFrame.php?" + s_postdata + "&ts=" + GetCurrentTime(), true);
		l_pAJAX.onreadystatechange = function() {
			if (l_pAJAX.readyState == 4) {
				if (l_pAJAX.status == 200) {
					updateContent('divOptionsFrame', l_pAJAX.responseText);
					executeJavascriptFunctions(l_pAJAX.responseText);
				} else {
					alert("Error Polling page 'Options Frame' (Error status = " + l_pAJAX.status + ")");
				}

				intObjectsLoading = 0;
				hideLoading();
				l_pAJAX = null;
			}
		};
		l_pAJAX.send(null);
	}
}

function pollHelpFrame(s_location, s_postdata){
	var l_pAJAX = createXMLHttpRequest();

	if (l_pAJAX != null) {
		intObjectsLoading++;
		showLoading();

		if (s_location == null) s_location = "divHelpFrame.php";

		l_pAJAX.open("GET", s_location + "?" + s_postdata + "&ts=" + GetCurrentTime(), true);
		l_pAJAX.onreadystatechange = function() {
			if (l_pAJAX.readyState == 4) {
				if (l_pAJAX.status == 200) {
					updateContent('divHelpFrame', l_pAJAX.responseText);
					executeJavascriptFunctions(l_pAJAX.responseText);
				} else {
					alert("Error Polling page 'Help Frame' (Error status = " + l_pAJAX.status + ")");
				}

				intObjectsLoading = 0;
				hideLoading();
				l_pAJAX = null;
			}
		};
		l_pAJAX.send(null);
	}
}

function getAlignmentSettings(s_postdata){
	var l_pAJAX = createXMLHttpRequest();

	if (l_pAJAX != null) {
		intObjectsLoading++;
		showLoading();

		for(x = 0; x < MapLayerDisplay.length; x++) {
			switch(MapLayerType[x]) {
				case "PRIAERIAL":
				case "AERIAL":
				case "PRISOIL":
				case "SOIL":
					if (MapLayerVisible[x]) {
						s_postdata += "&layerid=" + MapLayerID[x];
					}
					break;
			}
		}

		s_postdata += "&mappage=" + MapPageName[0];

		l_pAJAX.open("GET", "getAlignmentSettings.php?" + s_postdata + "&ts=" + GetCurrentTime(), true);
		l_pAJAX.onreadystatechange = function() {
			if (l_pAJAX.readyState == 4) {
				if (l_pAJAX.status == 200) {
					if (l_pAJAX.responseText.indexOf('ERROR') == -1) {
						var exploded = l_pAJAX.responseText.split("\n");

						dblAlignmentScale = parseFloat(exploded[0]);
						dblAlignmentRotation = parseFloat(exploded[1]);
						dblAlignmentX = parseFloat(exploded[4]);
						dblAlignmentY = parseFloat(exploded[5]);

						document.getElementById('cboScale').value = trimPrecision(dblAlignmentScale, 5);
					} else {
						intObjectsLoading = 0;
						hideLoading();
						alert("Error Apply Alignment Settings\nError status: " + l_pAJAX.status + "\nError String: " + l_pAJAX.responseText);
					}
				} else {
					intObjectsLoading = 0;
					hideLoading();
					alert("Error Apply Alignment Settings\nError status: " + l_pAJAX.status);
				}

				l_pAJAX = null;
			}
		};
		l_pAJAX.send(null);
	}
}

function applyAlignmentSettings(s_postdata){
	var l_pAJAX = createXMLHttpRequest();

	if (l_pAJAX != null) {
		intObjectsLoading++;
		showLoading();

		for(x = 0; x < MapLayerDisplay.length; x++) {
			switch(MapLayerType[x]) {
				case "PRIAERIAL":
				case "AERIAL":
				case "PRISOIL":
				case "SOIL":
					if (MapLayerVisible[x]) {
						s_postdata += "&layerid=" + MapLayerID[x];
					}
					break;
			}
		}

		s_postdata += "&mappage=" + MapPageName[0];
		s_postdata += "&scale=" + dblAlignmentScale;
		s_postdata += "&rotation=" + dblAlignmentRotation;
		s_postdata += "&x=" + dblAlignmentX;
		s_postdata += "&y=" + dblAlignmentY;

		l_pAJAX.open("GET", "applyAlignmentSettings.php?" + s_postdata + "&ts=" + GetCurrentTime(), true);
		l_pAJAX.onreadystatechange = function() {
			if (l_pAJAX.readyState == 4) {
				if (l_pAJAX.status == 200) {
					if (l_pAJAX.responseText != "OK") {
						alert("Error Apply Alignment Settings\nError status: " + l_pAJAX.status + "\nError String: " + l_pAJAX.responseText);
					}
					setTool('refresh');
				} else {
					intObjectsLoading = 0;
					hideLoading();
					alert("Error Apply Alignment Settings\nError status: " + l_pAJAX.status);
				}
				l_pAJAX = null;
			}
		};
		l_pAJAX.send(null);
	}
}

function pollFeedbackFrame(s_postdata){
	var l_pAJAX = createXMLHttpRequest();

	if (l_pAJAX != null) {
		intObjectsLoading++;
		showLoading();

		l_pAJAX.open("GET", "divFeedbackFrame.php?" + s_postdata + "&ts=" + GetCurrentTime(), true);
		l_pAJAX.onreadystatechange = function() {
			if (l_pAJAX.readyState == 4) {
				if (l_pAJAX.status == 200) {
					updateContent('divFeedbackFrame', l_pAJAX.responseText);
					executeJavascriptFunctions(l_pAJAX.responseText);
				} else {
					alert("Error Polling page 'Feedback Frame' (Error status = " + l_pAJAX.status + ")");
				}

				intObjectsLoading = 0;
				hideLoading();
				l_pAJAX = null;
			}
		};
		l_pAJAX.send(null);
	}
}

function pollGotoFrame(s_postdata){
	var l_pAJAX = createXMLHttpRequest();

	if (l_pAJAX != null) {
		intObjectsLoading++;
		showLoading();

		s_postdata = "layerid=" + MapLayerID[0];
		s_postdata += "&mappage=" + MapPageName[0];

		l_pAJAX.open("GET", "divTogoFrame.php?" + s_postdata + "&ts=" + GetCurrentTime(), true);
		l_pAJAX.onreadystatechange = function() {
			if (l_pAJAX.readyState == 4) {
				if (l_pAJAX.status == 200) {
					MapGotoDisplay = [];
					MapGotoLink = [];

					var l_temp = l_pAJAX.responseText.split('~~~');

					MapGotoDisplay = l_temp[0].split('|');
					MapGotoLink = l_temp[1].split('|');

					refreshMapGoto();
				} else {
					intObjectsLoading = 0;
					hideLoading();
					alert("Error Polling page 'Goto Frame' (Error status = " + l_pAJAX.status + ")");
				}
				l_pAJAX = null;
			}
		};
		l_pAJAX.send(null);
	}
}


function uploadHotspot(s_postdata){
	var l_pAJAX = createXMLHttpRequest();

	if (l_pAJAX != null) {

		for(x = 0; x < MapLayerDisplay.length; x++) {
			switch(MapLayerType[x]) {
				case "PRILINEWORK":
					if (MapLayerVisible[x]) {
						s_postdata += "&layerid=" + MapLayerID[x];
					}
					break;
			}
		}

		l_pAJAX.open("GET", "ajax/ajaxUploadMapHotSpot.php?" + s_postdata + "&ts=" + GetCurrentTime(), true);
		l_pAJAX.onreadystatechange = function() {
			if (l_pAJAX.readyState == 4) {
				if (l_pAJAX.status == 200) {
					pollHotSpots();
					l_pAJAX = null;
				}
			}
		};
		l_pAJAX.send(null);
	}
}

function killHotspots(s_postdata){
	var l_pAJAX = createXMLHttpRequest();

	if (l_pAJAX != null) {

		for(x = 0; x < MapLayerDisplay.length; x++) {
			switch(MapLayerType[x]) {
				case "PRILINEWORK":
					if (MapLayerVisible[x]) {
						s_postdata += "&layerid=" + MapLayerID[x];
					}
					break;
			}
		}

		l_pAJAX.open("GET", "ajax/ajaxKillMapHotSpots.php?" + s_postdata + "&ts=" + GetCurrentTime(), true);
		l_pAJAX.onreadystatechange = function() {
			if (l_pAJAX.readyState == 4) {
				if (l_pAJAX.status == 200) {
					pollHotSpots();
					l_pAJAX = null;
				}
			}
		};
		l_pAJAX.send(null);
	}
}

function pollHotSpots(s_postdata){
	var l_pAJAX = createXMLHttpRequest();

	if (l_pAJAX != null) {
		s_postdata = "layerid=" + MapLayerID[0];
		s_postdata += "&mappage=" + MapPageName[0];

		l_pAJAX.open("GET", "ajax/ajaxGetMapHotSpots.php?" + s_postdata + "&ts=" + GetCurrentTime(), true);
		l_pAJAX.onreadystatechange = function() {
			if (l_pAJAX.readyState == 4) {
				if (l_pAJAX.status == 200) {
					MapHotSpots = [];

					MapHotSpots = l_pAJAX.responseText.split('~~~');

					if (intObjectsLoading ==0) refreshMapHotSpots();
				} else {
					alert("Error Polling Map Hotspots (Error status = " + l_pAJAX.status + ")");
				}
				l_pAJAX = null;
			}
		};
		l_pAJAX.send(null);
	}
}


function pollNavFrame(s_postdata){
	var l_pAJAX = createXMLHttpRequest();

	if (l_pAJAX != null) {
		intObjectsLoading++;
		showLoading();

		l_pAJAX.open("GET", "divNavFrame.php?" + s_postdata + "&ts=" + GetCurrentTime(), true);
		l_pAJAX.onreadystatechange = function() {
			if (l_pAJAX.readyState == 4) {
				if (l_pAJAX.status == 200) {
					updateContent('divNavigationFrame', l_pAJAX.responseText);
					executeJavascriptFunctions(l_pAJAX.responseText);
				} else {
					alert("Error Polling page 'Nav Frame' (Error status = " + l_pAJAX.status + ")");
				}

				intObjectsLoading = 0;
				hideLoading();
				l_pAJAX = null;
			}
		};
		l_pAJAX.send(null);
	}
}

function pollCheckin(){
	var l_pAJAX = createXMLHttpRequest();

	if (l_pAJAX != null) {
		l_pAJAX.open("GET", "checkin.php?ts=" + GetCurrentTime(), true);
		l_pAJAX.onreadystatechange = function() {
			if (l_pAJAX.readyState == 4) {
				if (l_pAJAX.status == 200) {
					executeJavascriptFunctions(l_pAJAX.responseText);
				} else {
					//alert("Error Authenicating Check-in (Error status = " + l_pAJAX.status + ")");
				}

				l_pAJAX = null;
			}
		};
		l_pAJAX.send(null);
	}
}

function pollCheckout(){
	var l_pAJAX = createXMLHttpRequest();

	if (l_pAJAX != null) {
		l_pAJAX.open("GET", "checkout.php?ts=" + GetCurrentTime(), true);
		l_pAJAX.send(null);
	}
}

function showFeedbackLinks() {
	moveLayer('divFeedbackImage', getWindowWidth() - 80, getWindowHeight() - 60);
	showLayer('divFeedbackImage');
}

function hideFeedbackLinks() {
	hideLayer('divFeedbackImage');
}

function getCheckedValue(radioObj) {
	var radioLength = radioObj.length;
	if(radioLength == undefined)
		if(radioObj.checked)
			return radioObj.value;
		else
			return "";
	for(var i = 0; i < radioLength; i++) {
		if(radioObj[i].checked) {
			return radioObj[i].value;
		}
	}
	return "";
}


var jg_doc = null;

function initDrawing() {
	jg_doc = new jsGraphics("divSVGFrame");
	jg_doc.setPrintable(false);
}