var win
var ACTIVE_ARCIMS_LAYER_ID = 9999;


//pop-up message vars
var popup1;
	popup1 = false;
			var version = navigator.appVersion;
			var versNum = parseFloat(version);
			var browser = navigator.appName;
			var itsOK = false;
			var isNav = false;
      var isNav6 = false;
			var isNav4 = false;
			var isIE = false;
			if (browser == "Netscape") {
				if (versNum < 3) {
					itsOK = false;	
          isNav = true;
				} else if (versNum < 4) {
					itsOK = false;
          isNav = true;
				} else if (versNum >= 5) {
          isNav6 = true;
          itsOK = true;
				} else {
					if (versNum>=4 && versNum<5) 
					{
					isNav4=true;
					}
					itsOK = true;	
          isNav = true;
				}
			} else if (browser.indexOf("Microsoft") > -1) {
				isIE = true;
				if (versNum < 4.0) {
					itsOK = false;
				} else {
					itsOK = true;
	
				}
				if (navigator.platform == "MacPPC") {
					itsOK = false;
				}
       
			}
		
function switchTableColor(Input,pos)
{
var bgcolor_off = '#FFFFFF';
var bgcolor_on = '#FFFFCC';
  if (isIE || isNav6)
  {
   for (var i=1; i< document.frm.length + 1; i++)
	{
		if (i == pos)
		{
			if (isIE)
			eval("t"+i+".style.backgroundColor='" +bgcolor_on+"'");	
			else
			document.getElementById("t"+ i).style.backgroundColor=bgcolor_on;	
		}
		else
		{
			if (isIE)
			eval("t"+i+".style.backgroundColor='"+bgcolor_off+"'");
			else
			document.getElementById("t"+i).style.backgroundColor=bgcolor_off;
		}
  }
} 
}

function mWidth(frameloc)
//#########################################################
//# FUNCTION: mWeight()
//# DESCRIPTION: Gets the available frame width (NS/IE)
//# INPUT: location of frame (parent.framename) if called from current page then leave
//# blank
//# OUTPUT: Width  available in frame
//##########################################################
{
	var iw;
	if (frameloc == null)
	{
	if (window.innerWidth == null) 
			{
				iw = document.body.clientWidth;
			}
			 else 
			{
				iw = window.innerWidth;
			}
	}
	else
	{
	if (frameloc.window.innerWidth == null) 
			{
				iw = frameloc.document.body.clientWidth;
			}
			 else 
			{
				iw = frameloc.window.innerWidth;
			}
	}
		//alert(iw);
    return iw;
}


function mHeight(frameloc)
//#########################################################
//# FUNCTION: mHeight()
//# DESCRIPTION: Gets the available frame height (NS/IE)
//# INPUT: location of frame (parent.framename) if called from current page then leave
//# blank
//# OUTPUT: Height available in frame
//##########################################################
{
	var ih;
	if (frameloc == null)
	{
		if (window.innerWidth == null) 
		{
		ih=document.body.clientHeight; 
		}
		 else 
		 {
			ih = window.innerHeight;
		 }
	}
	else
	{
		if (frameloc.window.innerWidth == null) 
		{
			ih=frameloc.document.body.clientHeight; 
		}
		 else 
		{
			ih = frameloc.window.innerHeight;
		}
	 }
	 //alert(ih);
	return ih;
}

function loadPage(pagename,pagelocation)
//#########################################################
//# FUNCTION: loadpage()
//# DESCRIPTION: Loads a page in a give frame
//# INPUT: Page to be loaded, location where page is to be loaded (parent.framename)
//# OUTPUT: 
//##########################################################
{
	if (pagename == null)
	{
		alert('ERROR:\nfunction loadpage()\nNo value given for first parameter ')
	}
	 else
	{	
		if (pagelocation == null)
		{
			document.location.href = pagename
		}
		 else
		{
			pagelocation.location.href =  pagename
		}
	}
} 

function checkBrowser()
//#########################################################
//# FUNCTION: checkBrowser()
//# DESCRIPTION: checks the clients browser
//# INPUT: none
//# OUTPUT:  browser type - (Microsoft,Netscape,Error)
//##########################################################
{
			var version = navigator.appVersion;
			var versNum = parseFloat(version);
			var browser = navigator.appName;
			var btype = "Error";

			if (browser.indexOf("Microsoft") > -1) 
			{
				if (versNum < 4.0) 
				{
					btype = "Error";
				} 
				 else 
				{
					btype = "Microsoft";					
				}
			}
			else 
			{
				if (browser.indexOf("Netscape") >-1)
				{
					if (versNum < 4.0)					
					{
						btype = "Error";
					}
					 else 
					{
						btype = "Netscape";
					}
				 }
				 else
				 {
					if (navigator.platform == "MacPPC") 
					{
							 btype = "Error";
					}
				  }			

				}
							return btype;
     		}


			
function Xcoord(e) 
{
//#########################################################
//# FUNCTION: Xcoord()
//# DESCRIPTION: get the mouseclick x
//# INPUT: javascript event
//# OUTPUT:  X coordinates of mouseclick on image
//##########################################################
	if (window.event) 
	{
		return window.event.clientX
	}
    else 
	{
       return e.pageX
	}
}

function Ycoord(e) 
//#########################################################
//# FUNCTION: Ycoord()
//# DESCRIPTION: get the y
//# INPUT: javascript event
//# OUTPUT: Y coordinate of mouseclick on image
//##########################################################
{      
   	if (window.event) 
		{
			return window.event.clientY;
		}
    else 
		{
			return e.pageY
		}	
}

function selectTool(ActiveTool,Xval, Yval)
//#########################################################
//# FUNCTION: Xcoord()
//# DESCRIPTION: get the mouseclick x
//# INPUT: javascript event
//# OUTPUT:  X coordinates of mouseclick on image
//##########################################################
{


	if (ActiveTool == "zoomin")
	{
	panZoom(ActiveTool,Xval,Yval);
	}
	else 
	{
		if (ActiveTool =="zoomout")
		{
		panZoom(ActiveTool,Xval,Yval);
		}
		else
		{
			if (ActiveTool=="pan")
			{
				panZoom(ActiveTool,Xval,Yval)
			}
			else
			{
				if (ActiveTool=="identify")
				{
					identify(Xval,Yval);
				}
				else
				{
					if (ActiveTool=="zoomtofull")
					{

						panZoom(ActiveTool)
					}
					else 
					{
						if (ActiveTool =='measure')
						{
							measure(Xval,Yval)
						}

					}
				}
			}
		}
	}
}

function panZoom(ToolType,X1,Y1)
//#########################################################
//# FUNCTION: panZoom()
//# DESCRIPTION: handles zoomin,zoomout,pan
//# INPUT: tool name and coordinates
//# OUTPUT: refreshes asp page to update map
//##########################################################
{
	loadPage('PANZOOM.CFM?tooltype='+ToolType+'&x1='+X1+'&y1='+Y1,parent.ASP);
}

function identify(X1,Y1)
//#########################################################
//# FUNCTION: identify()
//# DESCRIPTION: handles identify
//# INPUT: coordinates
//# OUTPUT: refreshes asp page to update map
//##########################################################
{
		loadPage('IDENTIFY.CFM?x1='+X1+'&y1='+Y1,parent.ASP);
}

function measure(X1,Y1)
//#########################################################
//# FUNCTION: identify()
//# DESCRIPTION: handles identify
//# INPUT: coordinates
//# OUTPUT: refreshes asp page to update map
//##########################################################
{
		loadPage('measure0.asp?x1='+X1+'&y1='+Y1,parent.asp);
}

function layerLegend()
//#########################################################
//# FUNCTION: layerLegend()
//# DESCRIPTION: handles identify
//# INPUT: coordinates
//# OUTPUT: refreshes asp page to update map
//##########################################################
{
	if (parent.layerlegend.document.title == "Layer")
	{
		loadPage('legend.asp',parent.layerlegend)
	}
	else
	{
		loadPage('layer.asp', parent.layerlegend)
	}    
}

function createWindow(pagename,toolbarVis,locationVis,statusVis,resizableVis,scrollbarsVis,menuVis,xPos,yPos,valx,valy, Wname)
//#########################################################
//# FUNCTION: createWindow()
//# DESCRIPTION: handles creates a window
//# INPUT: width, height, page
//# OUTPUT: refreshes asp page to update map
//##########################################################
{
var wHelp, wPrintTable, wPrintMap, wMuniProfile

if (Wname=="printtable")
{
 Win2 = window.open(pagename,Wname,'toolbar='+toolbarVis+',location='+locationVis+',directories=no,status=no,menubar='+menuVis+',resizable='+resizableVis+',copyhistory=no,screenX='+xPos+',screenY='+yPos+',top='+yPos+',left='+xPos+',scrollbars='+scrollbarsVis+',width='+valx+',height='+valy);					
}
else
{
 Win = window.open(pagename,Wname,'toolbar='+toolbarVis+',location='+locationVis+',directories=no,status=no,menubar='+menuVis+',resizable='+resizableVis+',copyhistory=no,screenX='+xPos+',screenY='+yPos+',top='+yPos+',left='+xPos+',scrollbars='+scrollbarsVis+',width='+valx+',height='+valy);					
 }
}

function switchImage(ImageName,ImagePath,ImageLocation)
//#########################################################
//# FUNCTION: switchImage()
//# DESCRIPTION: 
//# INPUT: 
//# OUTPUT: 
//##########################################################
{
if (document.images == null)
{
alert('NULL');
}
		if (ImageLocation == null)
		{
			document.images[ImageName].src= ImagePath;
		}
		 else
		{
			ImageLocation.document.images[ImageName].src= ImagePath;
		}
}

function writeStatus(StatusMessage)
//#########################################################
//# FUNCTION: write Status()
//# DESCRIPTION: 
//# INPUT: 
//# OUTPUT: 
//##########################################################
{
	window.status=StatusMessage
}

function DisplayMuni(munilink)
//#########################################################
//# FUNCTION: write Status()
//# DESCRIPTION: 
//# INPUT: 
//# OUTPUT: 
//##########################################################
{
	document.location.href='data/' + munilink
	self.resizeTo(screen.width,screen.height);	
}

function passvar(pagetype)
{
loc = document.txtform;
if (pagetype=='land')
{
	if (loc.minval.value == "" && loc.maxval.value == "")
	{
		alert('The \'Minimun Size\'  and \'Maximum Size\' fields both cannot be blank.\n');
	}
	else
  	  {
		loadPage('calc_land.asp?minval='+loc.minval.value+'&maxval='+loc.maxval.value+'&zoning='+loc.zoning.value+'&muni='+loc.muni.options[loc.muni.options.selectedIndex].value,window.opener.parent.address);
		setTimeout('self.close()',500);  
    	}
}
else
{
if (loc.minval.value == "" && loc.maxval.value == "")
	{
		alert('The \'Minimun SQFT\'  and \'Maximum SQFT\' fields both cannot be blank.\n');
	}
	else
  	  {
		loadPage('calc_buildings.asp?minval='+loc.minval.value+'&maxval='+loc.maxval.value+'&usage='+loc.usage.options[loc.usage.options.selectedIndex].value+'&muni='+loc.muni.options[loc.muni.options.selectedIndex].value,window.opener.parent.address);
		setTimeout('self.close()',500);  
    	}
}
}

function updateLayers() {
	var theForm = document.toc;
	var j = 0;
	var args = ""
	for (var i=0;i<theForm.LayerVisible.length;i++)
	{
		j = theForm.LayerVisible[i].value;
		if (theForm.LayerVisible[i].checked) {
			args = args + "&" + j + "=Y";
		}
		else {
			args = args + "&" + j + "=N";
		}
	}
	parent.asp.location = 'readTOC.asp?action=layervis' + args;
}


function CheckMsg(msgname) 
{
	if (!top.msgname)
	{
	alert(msgname);
	top.msgname = true;
	}
}

function WinExists() 
{
if (window.opener.parent.showres.document == null) {
}
else
{
window.opener.parent.showres.document.showwindow.src='images/shim.gif';
window.opener.parent.top.focus();
}
}

function toggleVisibility(id, NNtype, IEtype, W3Ctype) {
    if (document.getElementById) {
    eval("document.getElementById(id).style.visibility = \"" + W3Ctype + "\"");
    } else {
    if (document.layers) {
    document.layers[id].visibility = NNtype;
    } else {
    if (document.all) {
    eval("document.all." + id + ".style.visibility = \"" + IEtype + "\"");
            }
        }
    }
}
