// JScript File
var sliderStartY;
var sliderEndY;
var sliderOffsetY = 206;
var startx; //zoom box begin; also used for origin of zoom out
var starty;
var endx; //zoom box end
var endy;
var offsetX; //to be calculated with body width
var offsetY; //to be calculated with body height
var appWidth = 776; //actual width of application
var leftOfMapWidth = 205;  //the legend/layers panel width
var appHeight = 510; //actual application height
var aboveOfMapHeight = 193;  //the height of title and canvas above map
var browserIs;
var mysteryPx; //because ie adds the top boarder of 7px
var minX; //to be calculated with at event fire
var minY;
var maxX;
var maxY;
var pixheight = 436;  //actual map height
var pixwidth = 512;  //actual map width
var isdown = 0;
var oldTop;
var slide = 'n';
var arrWaitImg = new Array(10);
	arrWaitImg[0] = new Image();
	arrWaitImg[0].src="../images/wait0.bmp";
	arrWaitImg[1] = new Image();
	arrWaitImg[1].src="../images/wait1.bmp";
	arrWaitImg[2] = new Image();
	arrWaitImg[2].src="../images/wait2.bmp";
	arrWaitImg[3] = new Image();
	arrWaitImg[3].src="../images/wait3.bmp";
	arrWaitImg[4] = new Image();
	arrWaitImg[4].src="../images/wait4.bmp";
	arrWaitImg[5] = new Image();
	arrWaitImg[5].src="../images/wait5.bmp";
	arrWaitImg[6] = new Image();
	arrWaitImg[6].src="../images/wait6.bmp";
	arrWaitImg[7] = new Image();
	arrWaitImg[7].src="../images/wait7.bmp";
	arrWaitImg[8] = new Image();
	arrWaitImg[8].src="../images/wait8.bmp";
	arrWaitImg[9] = new Image();
	arrWaitImg[9].src="../images/wait9.bmp";
var waitIteration = 0;
var waitDir = "pos";
var waitTimerID = null;


function dismissMsg()
{  
    document.getElementById("nav2_wholeMap_message").style.display = 'none';
}
function hideWait()
{
    
    document.getElementById("nav2_wholeMap_wait").style.display = 'none';
    
}
function prntWin()
{
    
    window.print();
    
}
function hideMe() 
{
	//hidden form elements to hold extent between https
	document.getElementById("state_txtXMin").style.display = 'none';
	document.getElementById("state_txtXMax").style.display = 'none';
	document.getElementById("state_txtYMin").style.display = 'none';
	document.getElementById("state_txtYMax").style.display = 'none';
	
	document.getElementById("state_txtSelX").style.display = 'none';
	document.getElementById("state_txtSelY").style.display = 'none';
	
	document.getElementById("state_txtCurZoomL").style.display = 'none';
	document.getElementById("state_txtZoomToAddAPN").style.display = 'none';
	
	document.getElementById("state_txtCurrentTool").style.display = 'none';
	
	document.getElementById("state_txtAceSQL").style.display = 'none';
	document.getElementById("state_txtIconFont").style.display = 'none';
	
	document.getElementById("state_txtAirVis").style.display = 'none';
	
	document.getElementById("state_SList").style.display = 'none';
}

//MANAGE IMAGE VISIBILITY==========================================================
function whichActMapTool(){
	var act;
	//window.alert('x');
	act = getCookie('actMapToolTab');
	switch(act){
		case 'Advc':
			switchMapTools('Advc');
			break;
		case 'Bsc':
		    switchMapTools('Bsc');
			break;
	} 
}

function imageChange(name, direction, imgname){
	//window.alert(name.src);
	switch(direction){
		case 'in':
			name.src = "../images/" + imgname + "_d.bmp";
			break;
		case 'out':
			name.src = "../images/" + imgname + "_n.bmp";
			break;
		case 'roll':
			name.src = "../images/" + imgname + "_r.bmp";
	
	}
}

function switchMapTools(toolSet)
{
    
    if (document.getElementById("nav2_wholeMap").style.display == "block") 
    {
        
        switch(toolSet)
            {
                case 'Advc':
                    setCookie('actMapToolTab','Advc',1);
                    document.getElementById("nav2_wholeMap_mapTB").style.display = "none";
                    document.getElementById("nav2_wholeMap_mapTA").style.display = "block";
                    document.getElementById("nav2_wholeMap_mapTT_IBMapAdvc").src = "../images/IBMapAdvcOn.gif";
                    document.getElementById("nav2_wholeMap_mapTT_IBMapBsc").src = "../images/IBMapBscOff.gif";
                    
                    break;
                case 'Bsc': 
                    setCookie('actMapToolTab','Bsc',1);
                    document.getElementById("nav2_wholeMap_mapTA").style.display = "none";
                    document.getElementById("nav2_wholeMap_mapTB").style.display = "block";
                    document.getElementById("nav2_wholeMap_mapTT_IBMapBsc").src = "../images/IBMapBscOn.gif";
                    document.getElementById("nav2_wholeMap_mapTT_IBMapAdvc").src = "../images/IBMapAdvcOff.gif";
                    
                    break;
            }
    }
}
function setFocus(e,clientID)
{
    //window.alert(navigator.appName);
    if(navigator.appName.indexOf("Netscape")>(-1))
    { 
        if(e.keyCode==13)
        {
            //window.alert(clientID);
            document.getElementById(clientID).click();
        }
    }else 
    {
        if(event.which || event.keyCode)
            {
            if ((event.which == 13) || (event.keyCode == 13)) 
                {
                //window.alert(clientID);
                document.getElementById(clientID).focus();
                }
        } 
    }
}
function hover(name, hov)
{
    var msg = getHoverMsg(name);
   
    try{
        document.getElementById("nav2_wholeMap_hover_imgHov").src = '../images/'+msg;
        document.getElementById("nav2_wholeMap_hover").style.display = 'block';
    } catch (e) {
        
    }
    
}
function hoverOff()
{
    document.getElementById("nav2_wholeMap_hover").style.display = 'none';
}

function getHoverMsg(name){
	var msg;
	
	switch(name)
	{
		case 'IBPan':
			msg = 'InstructDPan.bmp';
			return msg;
			break;
		case 'IBZoomFull':
			msg = 'InstructWC.bmp';
			return msg;
			break;
		case 'IBZoomSel':
			msg = 'InstructZSel.bmp';
			return msg;
			break;
		case 'IBDragPan':
			msg = 'InstructDPan.bmp';
			return msg;
			break;
		case 'IBZinTool':
			msg = 'InstructZin.bmp';
			return msg;
			break;
		case 'IBZoutTool':
			msg = 'InstructZout.bmp';
			return msg;
			break;
		case 'IBSelectTool':
			msg = 'InstructSel.bmp';
			return msg;
			break;
		
		case 'IBAirPhoto':
			if (document.getElementById("state_txtAirVis").value == 'visible')
				{
					msg = 'InstructAPhoOn.bmp';
				}else{
					msg = 'InstructAPhoOff.bmp';
				}
			
			return msg;
			break;
	}
}

function stopZoom(){
	isdown = 0;
    startx = 0;
    document.getElementById("nav2_wholeMap_mainMap_rubBand").style.height = 0;
    document.getElementById("nav2_wholeMap_mainMap_rubBand").style.width = 0;
    document.getElementById("nav2_wholeMap_mainMap_rubBand").style.display = 'none';
}

//MANAGE THE SELECTED MAP TOOL====================================================
function moveSlidePlus()
{
    var zoomLev;
    //window.alert('js');
    startWait();
    zoomLev = document.getElementById("state_txtCurZoomL").value;
    zoomLev = parseInt(zoomLev);
    //window.alert(zoomLev);
    if (zoomLev < 7)
    { 
        document.getElementById("state_txtCurZoomL").value = zoomLev + 1;
    }
    //window.alert(document.getElementById("state_txtCurZoomL").value );
    zoomMapToSlider();
}

function moveSlideMinus()
{
    var zoomLev;
    startWait();
    zoomLev = document.getElementById("state_txtCurZoomL").value;
    zoomLev = parseInt(zoomLev);
    if (zoomLev > 1)
    { 
        document.getElementById("state_txtCurZoomL").value = zoomLev - 1;
    }
    zoomMapToSlider();
    
}

function moveSlider(y)
{
    slide = 'y';
    oldTop = document.getElementById("nav2_wholeMap_mapTB_slideMe").style.top;
    sliderStartY = y - sliderOffsetY + ieMarginFix();  
     
}

function sliderMoving(y)
{
    var sliderCurY = y - sliderOffsetY;
    if(slide == 'y' && sliderCurY <= 231 && sliderCurY >= 106)
     {
        document.getElementById("nav2_wholeMap_mapTB_slideMe").style.top = sliderCurY + 'px';
     }
    if(slide == 'y' && (sliderCurY == 105 || sliderCurY == 232))
    {
        document.getElementById("nav2_wholeMap_mapTB_slideMe").style.top = oldTop;
        slide = 'n';
        window.alert('You may not slide this tool past the + and - signs.');
    }
}

function sliderMoved(y)
{
    if(slide == 'y')
    {
        startWait();
        slide = 'n';
        sliderEndY = y - sliderOffsetY;
        getZoomLevelForTop(sliderEndY);
        zoomMapToSlider();
    }
}

function positionSlider()
{
    var curZoomLevel;
    curZoomLevel = document.getElementById("state_txtCurZoomL").value;
    getTopForZoomLevel(curZoomLevel);
    
}

function getZoomLevelForTop(sliderEndY)
{
    if (sliderEndY > 215)
        {
            document.getElementById("state_txtCurZoomL").value = '1';
            return;
        }
        if (sliderEndY <= 215 && sliderEndY > 197)
        {
            document.getElementById("state_txtCurZoomL").value = '2';
            return;
        }
        if (sliderEndY <= 197 && sliderEndY > 178)
        {
            document.getElementById("state_txtCurZoomL").value = '3';
            return;
        }
        if (sliderEndY <= 178 && sliderEndY > 159)
        {
            document.getElementById("state_txtCurZoomL").value = '4';
            return;
        }
        if (sliderEndY <= 159 && sliderEndY > 139)
        {
            document.getElementById("state_txtCurZoomL").value = '5';
            return;
        }
        if (sliderEndY <= 139 && sliderEndY > 121)
        {
            document.getElementById("state_txtCurZoomL").value = '6';
            return;
        }
        if (sliderEndY <= 121)
        {
            document.getElementById("state_txtCurZoomL").value = '7';
            return;
        }
       
}

function getTopForZoomLevel(zl)
{
    switch (zl)
    {
        case '1':
            document.getElementById("nav2_wholeMap_mapTB_slideMe").style.top = 231 + 'px';
            break;
        case '2':
            document.getElementById("nav2_wholeMap_mapTB_slideMe").style.top = 215 + 'px';
            break;
        case '3':
            document.getElementById("nav2_wholeMap_mapTB_slideMe").style.top = 197 + 'px';
            break;
        case '4':
            document.getElementById("nav2_wholeMap_mapTB_slideMe").style.top = 178 + 'px';
            break;
        case '5':
            document.getElementById("nav2_wholeMap_mapTB_slideMe").style.top = 159 + 'px';
            break;
        case '6':
            document.getElementById("nav2_wholeMap_mapTB_slideMe").style.top = 139 + 'px';
            break;
        case '7':
            document.getElementById("nav2_wholeMap_mapTB_slideMe").style.top = 121 + 'px';
            break;
    }  
}

function setZoomLevelForWidth(width)
{
    //window.alert('szlfw');
    if (width > 65000)
    {
        document.getElementById("state_txtCurZoomL").value = '1';
        return;
    }
    if (width <= 65000 && width > 40000)
    {
        document.getElementById("state_txtCurZoomL").value = '2';
        return;
    }
    if (width <= 40000 && width > 10000)
    {
        document.getElementById("state_txtCurZoomL").value = '3';
        return;
    }
    if (width <= 10000 && width > 5000)
    {
        document.getElementById("state_txtCurZoomL").value = '4';
        return;
    }
    if (width <= 5000 && width > 2500)
    {
        document.getElementById("state_txtCurZoomL").value = '5';
        return;
    }
    if (width <= 2500 && width > 1000)
    {
        document.getElementById("state_txtCurZoomL").value = '6';
        return;
    }
    if (width <= 1000)
    {
        document.getElementById("state_txtCurZoomL").value = '7';
        return;
    }
}

function getWidthForZoomLevel(zl)
{
    switch (zl)
	{
	    case '1':
	        newwidth = 67215;   
	        break;
	    case '2':
	        newwidth = 45000;
	        break;
	    case '3':
	        newwidth = 20000;
	        break;
	    case '4':
            newwidth = 7000;
	        break;
	    case '5':
	        newwidth = 3000;
	        break;
	    case '6':
	        newwidth = 2000;
	        break;
	    case '7':
            newwidth = 800;
	        break;
	}
	return newwidth;
}

function getHeightForWidth(width)
{
    return width * .83;
}

function zoomMapToSlider()
{
    var curZoomLevel = document.getElementById("state_txtCurZoomL").value;
	var xmin = document.getElementById("state_txtXMin").value * 1;
	var xmax = document.getElementById("state_txtXMax").value * 1;
	var ymin = document.getElementById("state_txtYMin").value * 1;
	var ymax = document.getElementById("state_txtYMax").value * 1;
	var x1;
	var x2;
	var y1; 
	var y2;
	var oldwidth = xmax - xmin;
	var oldheight = ymax - ymin;
	var newwidth;
	var newheight;
	newwidth = getWidthForZoomLevel(curZoomLevel);
	newheight = getHeightForWidth(newwidth);
    if (newwidth < oldwidth)
    {
        x1 = xmin + ((oldwidth - newwidth)/2);
        x2 = xmax - ((oldwidth - newwidth)/2);
        y1 = ymin + ((oldheight - newheight)/2);
        y2 = ymax - ((oldheight - newheight)/2);
    }
    if (oldwidth < newwidth)
    {
        x1 = xmin - ((newwidth - oldwidth)/2);
        x2 = xmax + ((newwidth - oldwidth)/2);
        y1 = ymin - ((newheight - oldheight)/2);
        y2 = ymax + ((newheight - oldheight)/2);
    }
    document.getElementById("state_txtXMin").value = x1;
    document.getElementById("state_txtXMax").value = x2;
    document.getElementById("state_txtYMin").value = y1;
    document.getElementById("state_txtYMax").value = y2;
}

function mapToolDefault()
{
	document.body.style.cursor = "default";
	if (document.getElementById("state_txtCurrentTool").value == 'zin')
	{
		mapTool("IBZinTool");
	}
	if (document.getElementById("state_txtCurrentTool").value == 'zout')
	{
		mapTool("IBZoutTool");
	}
	if (document.getElementById("state_txtCurrentTool").value == 'sel')
	{
		mapTool("IBSelectTool");
	}
	if (document.getElementById("state_txtCurrentTool").value == 'dpan')
	{
		mapTool("IBDragPan");
	}
}

function mapTool(imgname)
{
    
	switch(imgname)
	{
		case 'IBZinTool':
				document.getElementById("nav2_wholeMap_mapTA_IBZinTool").src = "../images/" + imgname + "_d.bmp";
				document.getElementById("nav2_wholeMap_mapTA_IBZoutTool").src = "../images/IBZoutTool_n.bmp";
				document.getElementById("nav2_wholeMap_mapTA_IBSelectTool").src = "../images/IBSelectTool_n.bmp";
				document.getElementById("nav2_wholeMap_mapTA_IBDragPan").src = "../images/IBDragPan_n.bmp";
				
				document.getElementById("state_txtCurrentTool").value = 'zin';
				
			break;
		case 'IBZoutTool':
				document.getElementById("nav2_wholeMap_mapTA_IBZoutTool").src = "../images/" + imgname + "_d.bmp";
				document.getElementById("nav2_wholeMap_mapTA_IBZinTool").src = "../images/IBZinTool_n.bmp";
				document.getElementById("nav2_wholeMap_mapTA_IBSelectTool").src = "../images/IBSelectTool_n.bmp";
				document.getElementById("nav2_wholeMap_mapTA_IBDragPan").src = "../images/IBDragPan_n.bmp";
				
				document.getElementById("state_txtCurrentTool").value = 'zout';
				
			break;
		case 'IBSelectTool':
				document.getElementById("nav2_wholeMap_mapTA_IBSelectTool").src = "../images/" + imgname + "_d.bmp";
				document.getElementById("nav2_wholeMap_mapTA_IBZoutTool").src = "../images/IBZoutTool_n.bmp";
				document.getElementById("nav2_wholeMap_mapTA_IBZinTool").src = "../images/IBZinTool_n.bmp";
				document.getElementById("nav2_wholeMap_mapTA_IBDragPan").src = "../images/IBDragPan_n.bmp";
				
				document.getElementById("state_txtCurrentTool").value = 'sel';
			break;
	
		
		case 'IBDragPan':
				document.getElementById("nav2_wholeMap_mapTA_IBDragPan").src = "../images/" + imgname + "_d.bmp";
				document.getElementById("nav2_wholeMap_mapTA_IBZoutTool").src = "../images/IBZoutTool_n.bmp";
				document.getElementById("nav2_wholeMap_mapTA_IBZinTool").src = "../images/IBZinTool_n.bmp";
				document.getElementById("nav2_wholeMap_mapTA_IBSelectTool").src = "../images/IBSelectTool_n.bmp";
				
				document.getElementById("state_txtCurrentTool").value = 'dpan';
				
			break;
	}
}

function ieMarginFix()
{
    switch(browserIs)
        {
            case 'ie':
                mysteryPx = -7;
                break;
            case 'ne':
                mysteryPx = 0;
                break;
        }
    return mysteryPx;
}

function fineTuneDownXAndDownY(x,y)
{
    //this changes when user streches browser window.
    var bodyWidth = document.body.clientWidth; 
    var bodyHeight = document.body.clientHeight; 
    var margin = (bodyWidth - appWidth)/2
    whatBrowser();
    mysteryPx = ieMarginFix();
    offsetX = margin + leftOfMapWidth;
    offsetY = aboveOfMapHeight - mysteryPx;
    //window.alert(offsetX + ' ' + offsetY);
    minX = offsetX;
    minY = offsetY;
    maxX = offsetX + pixwidth;
    maxY = offsetY + pixheight;
    startx = x - offsetX; 
	starty = y - offsetY;
	//window.alert(startx + ' ' + starty);
}

function md(x,y) //onMouseDown over map
{
    //window.alert("hello");
    y = y + document.documentElement.scrollTop;
    fineTuneDownXAndDownY(x,y);
	if(document.getElementById("state_txtCurrentTool").value == 'zin'||document.getElementById("state_txtCurrentTool").value == 'zout')
	{
			
		isdown = 1;
		if ((startx >= minX) && (startx <= maxX) && (starty >= minY) && (starty <= maxY))
		{
		
			document.getElementById("nav2_wholeMap_mainMap_rubBand").style.left = startx + 'px';
			document.getElementById("nav2_wholeMap_mainMap_rubBand").style.top = starty + 'px';
			document.getElementById("nav2_wholeMap_mainMap_rubBand").style.width = 1 + 'px';
			document.getElementById("nav2_wholeMap_mainMap_rubBand").style.height = 1 + 'px';
			
		}
    }
    if(document.getElementById("state_txtCurrentTool").value == 'dpan')
    {	
		isdown = 1;
	}
    if(document.getElementById("state_txtCurrentTool").value == 'sel'||document.getElementById("state_txtCurrentTool").value == 'apt')
	{   
		var xmin = document.getElementById("state_txtXMin").value * 1 ; //current map coords
		var xmax = document.getElementById("state_txtXMax").value * 1;
		var ymin = document.getElementById("state_txtYMin").value * 1;
		var ymax = document.getElementById("state_txtYMax").value * 1;
		var mxUnitPerPix = (xmax - xmin)/pixwidth;
		var myUnitPerPix = (ymax - ymin)/pixheight;
		var mapx = xmin + (startx) * mxUnitPerPix;
		var mapy = ymin + (pixheight - starty) * myUnitPerPix;
		document.getElementById("state_txtSelX").value = mapx;
		document.getElementById("state_txtSelY").value = mapy;
	}		 
}
function mm(x,y) //onMouseMove over map
{   

    y = y + document.documentElement.scrollTop;
     if(document.getElementById("state_txtCurrentTool").value == 'zin'||document.getElementById("state_txtCurrentTool").value == 'zout') 
     { 
		if ((isdown == 1)&(x > startx)&(y > starty))
		{
			document.getElementById("nav2_wholeMap_mainMap_rubBand").style.display = 'block';
			document.getElementById("nav2_wholeMap_mainMap_rubBand").style.left = startx + 'px';
			document.getElementById("nav2_wholeMap_mainMap_rubBand").style.top = starty + 'px';
			if(((x - offsetX - startx - 5) > 1) & ((y - offsetY - starty - 5) > 1))
			{
			    document.getElementById("nav2_wholeMap_mainMap_rubBand").style.width = x - offsetX - startx - 5 + 'px';
			    document.getElementById("nav2_wholeMap_mainMap_rubBand").style.height = y - offsetY - starty - 5 + 'px';
			}
		}
	 }
     if(document.getElementById("state_txtCurrentTool").value == 'dpan')
     {
        if (isdown == 1)
        {
           document.getElementById("nav2_wholeMap_mainMap").style.clip = 'rect(1px,'+pixwidth+'px,'+pixheight+'px,1px)';
		   document.getElementById("nav2_wholeMap_mainMap_inpMap").style.top = (y - offsetY)-(starty) + 'px';
		   document.getElementById("nav2_wholeMap_mainMap_inpMap").style.left = (x - offsetX)-(startx) + 'px';
		}
     }
     if(document.getElementById("state_txtCurrentTool").value == 'mulin')
	 {
	    if (isdown == 1)
        {
           //setTimeout(zornDrawFunction(startx,starty,x,y),2000); //not quite there yet
		}
	 }
     window.status = x + ',' + y;
}

function mu(x,y) //onMouseUp over map
{

    y = y + document.documentElement.scrollTop;
	 if (document.getElementById("state_txtCurrentTool").value=='zin'||document.getElementById("state_txtCurrentTool").value == 'zout')
	 {  
		endx = x - offsetX; 
		endy = y - offsetY;
		isdown = 0;
		document.getElementById("nav2_wholeMap_mainMap_rubBand").style.display = 'none';
		//window.alert(endx + '>' + startx + ',' + endy + '>' + starty)
		if (endx > startx) 
		{
			x1 = startx;
			x2 = endx;
		}else{
		    x1 = startx - 50;
		    x2 = startx + 50;
		}
		if (endy > starty) 
		{
			y1 = starty;
			y2 = endy;
		}else{
		    y1 = starty - 50;
		    y2 = starty + 50;
		}
		mapUnits(x1,y1,x2,y2);
	 }
	 if(document.getElementById("state_txtCurrentTool").value == 'dpan')
	 {	
		endx = x - offsetX; 
		endy = y - offsetY;
		isdown = 0;
		mapUnitsDragPan();
	 }
}

function mapUnitsDragPan()
{
	//current map coords
	var xmin = document.getElementById("state_txtXMin").value * 1;  
	var xmax = document.getElementById("state_txtXMax").value * 1;
	var ymin = document.getElementById("state_txtYMin").value * 1;
	var ymax = document.getElementById("state_txtYMax").value * 1;
	var mxUnitPerPix = (xmax - xmin)/pixwidth;
	var myUnitPerPix = (ymax - ymin)/pixheight;
	//drag up and left
	if ((startx > endx) & (starty > endy))
	{
		x1 = xmin + ((startx - endx) * mxUnitPerPix);
		y1 = ymin - ((starty - endy) * myUnitPerPix);
		x2 = xmax + ((startx - endx) * mxUnitPerPix);
		y2 = ymax - ((starty - endy) * myUnitPerPix);
	}
	//drag up and right
	if ((startx < endx) & (starty > endy))
	{
		x1 = xmin - ((endx - startx) * mxUnitPerPix);
		y1 = ymin - ((starty - endy) * myUnitPerPix);
		x2 = xmax - ((endx - startx) * mxUnitPerPix);
		y2 = ymax - ((starty - endy) * myUnitPerPix);
	}
	//drag down and right
	if ((startx < endx) & (starty < endy))
	{
		x1 = xmin - ((endx - startx) * mxUnitPerPix);
		y1 = ymin + ((endy - starty) * myUnitPerPix);
		x2 = xmax - ((endx - startx) * mxUnitPerPix);
		y2 = ymax + ((endy - starty) * myUnitPerPix);
	}
	//drag down and left
	if ((startx > endx) & (starty < endy))
	{
		x1 = xmin + (startx - endx) * mxUnitPerPix;
		y1 = ymin + (endy - starty) * myUnitPerPix;
		x2 = xmax + (startx - endx) * mxUnitPerPix;
		y2 = ymax + (endy - starty) * myUnitPerPix;
	}
	document.getElementById("state_txtXMin").value = x1;
	document.getElementById("state_txtYMin").value = y1;
	document.getElementById("state_txtXMax").value = x2;
	document.getElementById("state_txtYMax").value = y2;
}
function submitPass(e,clientID)
{
    if(navigator.appName.indexOf("Netscape")>(-1))
    { 
        if(e.keyCode==13)
        {
            //window.alert(clientID);
            document.getElementById(clientID).click();
        }
    }else 
    {
        if(event.which || event.keyCode)
            {
            if ((event.which == 13) || (event.keyCode == 13)) 
                {
                //window.alert(clientID);
                document.getElementById(clientID).focus();
                }
        } 
    }
}
function mapUnits(pxmin,pymin,pxmax,pymax)
{
		var x1; //final output
		var y1;
		var x2;
		var y2;
		var xmin = document.getElementById("state_txtXMin").value * 1;  //current map coords
		var xmax = document.getElementById("state_txtXMax").value * 1;
		var ymin = document.getElementById("state_txtYMin").value * 1;
		var ymax = document.getElementById("state_txtYMax").value * 1;
		var mxUnitPerPix;  //conversion screen to world
		var myUnitPerPix;  //conversion screen to world
		var zoommapXmin;  //zoom box down and up coords in feet
		var zoommapXmax;
		var zoommapYmin;
		var zoommapYmax;
		var zoompixwidth;  //zoom box pix
		var zoompixheight;
		var zoommapwidth;  //zoom box feet
		var zoommapheight;
		var curmapwidth;  //current map feet
		var curmapheight;
		var wRatio;  //bollinger vars
		var hRatio;
		var theRatio;
		var newwidth;
		var newheight;
		var newhalfwidth;
		var newhalfheight;
		var mapcentx;
		var mapcenty;
		var zoomcentx;
		var zoomcenty;
		var xdelta;
		var ydelta;
		var newcentx;
		var newcenty;
		
		//how many feet in a pixel at current scale?
		mxUnitPerPix = (xmax - xmin)/pixwidth;
		myUnitPerPix = (ymax - ymin)/pixheight;
		//zoom box width 
		zoompixwidth = pxmax - pxmin;
		zoommapwidth = zoompixwidth * mxUnitPerPix;
		//zoom box height 
		zoompixheight = pymax - pymin;
		zoommapheight = zoompixheight * myUnitPerPix;
		//current map width
		curmapwidth = (xmax - xmin);
		curmapheight = (ymax - ymin);
		if (document.getElementById("state_txtCurrentTool").value=='zin') {
			//new minx is old plus click in map units
			x1 = xmin + (pxmin * mxUnitPerPix);
			//new maxx is new minx plus new width
			x2 = x1 + zoommapwidth;
			//new map miny is old plus inversion of origin minus the new height in map units
			y1 = ymin + ((pixheight - pymin - zoompixheight) * myUnitPerPix);
			//new maxy is new miny plus new height
			y2 = y1 + zoommapheight;
		}
		if (document.getElementById("state_txtCurrentTool").value=='zout') {
			zoommapXmin = xmin + (pxmin * mxUnitPerPix);
			zoommapXmax = zoommapXmin + zoommapwidth;
			zoommapYmin = ymin + ((pixheight - pymin - zoompixheight) * myUnitPerPix);
			zoommapYmax = zoommapYmin + zoommapheight;
			//bollinger code
			wRatio = curmapwidth/zoommapwidth;
			hRatio = curmapheight/zoommapheight;
			theRatio = (wRatio > hRatio) ? wRatio : hRatio;
			newwidth = curmapwidth * theRatio;
			newheight = curmapheight * theRatio;
			newhalfwidth = newwidth / 2;
			newhalfheight = newheight / 2;
			mapcentx = (xmax + xmin) / 2;
			mapcenty = (ymax + ymin) / 2;
			zoomcentx = (zoommapXmin + zoommapXmax) / 2;
			zoomcenty = (zoommapYmin + zoommapYmax) / 2;
			xdelta = (mapcentx - zoomcentx) * theRatio;
			ydelta = (mapcenty - zoomcenty) * theRatio;
			newcentx = mapcentx + xdelta;
			newcenty = mapcenty + ydelta;
			x1 = newcentx - newhalfwidth;
			x2 = newcentx + newhalfwidth;
			y1 = newcenty - newhalfheight;
			y2 = newcenty + newhalfheight;
			//thanks bollinger
		}
		if (document.getElementById("state_txtCurrentTool").value == 'dpan')
		{
			//new minx in map units
			x1 = xmin + (pxmin * mxUnitPerPix);
			//new maxx is new minx plus new width
			x2 = x1 + zoommapwidth;
			//new map miny is old plus inversion of origin minus the new height in map units
			y1 = ymin + ((pixheight - pymin - zoompixheight) * myUnitPerPix);
			//new maxy is new miny plus new height
			y2 = y1 + zoommapheight;
		}
		document.getElementById("state_txtXMin").value = x1;
		document.getElementById("state_txtYMin").value = y1;
		document.getElementById("state_txtXMax").value = x2;
		document.getElementById("state_txtYMax").value = y2;
}

//MANAGE WAIT ANIMATION=============================================================
function startWait() {
		document.getElementById("nav2_wholeMap_wait").style.display = 'block';
		upDateWait();
}

function upDateWait(){
		if (waitIteration == 9){
			waitDir = "neg";
		}
		if (waitIteration == 0){
			waitDir = "pos";
		}
		if (waitDir == "pos"){
			waitIteration++;
		}else{
			waitIteration--;
		}
		document.getElementById("nav2_wholeMap_wait_imgWait").src=arrWaitImg[waitIteration].src;
	    waitTimerID = setTimeout("upDateWait()", 111);
}

//MANAGE OVERVIEW VISIBILITY=======================================================
function showOverview(){
    
    
    switch(document.getElementById("nav2_wholeMap_OV").style.display)
        {
            case 'block':
                document.getElementById("nav2_wholeMap_OV").style.display='none';
		        document.getElementById("nav2_wholeMap_IBOverview").src = "../images/IBOverview_n.bmp";
                break
            case 'none':
                document.getElementById("nav2_wholeMap_OV").style.display='block';
		        document.getElementById("nav2_wholeMap_IBOverview").src = "../images/IBOverview_d.bmp";
                break
            case '':
                document.getElementById("nav2_wholeMap_OV").style.display='none';
		        document.getElementById("nav2_wholeMap_IBOverview").src = "../images/IBOverview_n.bmp";
                break
        }
}

function setOverViewVis(){
	var v;
	v = getCookie('OverViewVis');
	switch(v){
		case 'v':
			document.getElementById("nav2_wholeMap_OV").style.display='block';
			document.getElementById("nav2_wholeMap_IBOverview").src = "../images/IBOverview_d.bmp";
			break;
		case 'h':
			document.getElementById("nav2_wholeMap_OV").style.display='none';
			document.getElementById("nav2_wholeMap_IBOverview").src = "../images/IBOverview_n.bmp";
			break;
	}
}

function swapOverview(x,name){
	switch(x)
		{
			case 'in':
				document.getElementById(name).src = "../images/" + name + "_y.bmp";
				break;
			case 'out':
				if (document.getElementById("panOverviewMap").style.display=='block')
				{
					document.getElementById(name).src = "../images/" + name + "_d.bmp";
				}else{
					document.getElementById(name).src = "../images/" + name + "_n.bmp";
				}
				break;
		}
}

//MANAGE AIR PHOTO VISIBILITY======================================================
function showAirPhoto(){
	startWait();
	if (document.getElementById("state_txtAirVis").value == 'visible')
	{
		document.getElementById("nav2_wholeMap_mapTA_IBAirPhoto").src = "../images/IBAirPhoto_n.bmp";
	}else{
		document.getElementById("nav2_wholeMap_mapTA_IBAirPhoto").src = "../images/IBAirPhoto_d.bmp";
	}
}

function setAirPhotoVis(){
	//window.alert(document.getElementById("state_txtAirVis").value);
	switch(document.getElementById("state_txtAirVis").value){
		case 'visible':
			document.getElementById("nav2_wholeMap_mapTA_IBAirPhoto").src = "../images/IBAirPhoto_d.bmp";
			break;
		case 'hidden':
			document.getElementById("nav2_wholeMap_mapTA_IBAirPhoto").src = "../images/IBAirPhoto_n.bmp";
			break;
	}
}

//UTILITIES===========================================================================
function getCookie(name) {
	var index = document.cookie.indexOf(name + "=");
	if (index == -1) return null;
	index = document.cookie.indexOf("=", index) + 1; // first character
	var endstr = document.cookie.indexOf(";", index);
	if (endstr == -1) endstr = document.cookie.length; // last character
	return unescape(document.cookie.substring(index, endstr));
}

function setCookie(cookieName,cookieValue,nDays) {
 var today = new Date();
 var expire = new Date();
 if (nDays==null || nDays==0) nDays=1;
 expire.setTime(today.getTime() + 3600000*24*nDays);
 document.cookie = cookieName+"="+escape(cookieValue)
                 + ";expires="+expire.toGMTString();
}

function deleteCookie ( cookie_name ){
  var cookie_date = new Date ( );  // current date &amp; time
  cookie_date.setTime ( cookie_date.getTime() - 1 );
  document.cookie = cookie_name += "=; expires=" + cookie_date.toGMTString();
}

function whatBrowser()
{
    if (navigator.appName.toUpperCase().match(/MICROSOFT INTERNET EXPLORER/) != null)
      browserIs = 'ie';
    if (navigator.appName.toUpperCase().match(/NETSCAPE/) != null)
      browserIs = 'ne';

}
