﻿var MapObjPath;
var flashvars;
var sCount = 0;
var stack = new Array();
var xmlhttp;

var legendItemsOff = "";

var doQueryCheck = 0;



function whichBrs() {
    var agt = navigator.userAgent.toLowerCase();
    if (agt.indexOf("opera") != -1) return 'Opera';
    if (agt.indexOf("staroffice") != -1) return 'Star Office';
    if (agt.indexOf("webtv") != -1) return 'WebTV';
    if (agt.indexOf("beonex") != -1) return 'Beonex';
    if (agt.indexOf("chimera") != -1) return 'Chimera';
    if (agt.indexOf("netpositive") != -1) return 'NetPositive';
    if (agt.indexOf("phoenix") != -1) return 'Phoenix';
    if (agt.indexOf("firefox") != -1) return 'Firefox';
    if (agt.indexOf("safari") != -1) return 'Safari';
    if (agt.indexOf("skipstone") != -1) return 'SkipStone';
    if (agt.indexOf("msie") != -1) return 'Internet Explorer';
    if (agt.indexOf("netscape") != -1) return 'Netscape';
    if (agt.indexOf("mozilla/5.0") != -1) return 'Mozilla';
    if (agt.indexOf('\/') != -1) {
        if (agt.substr(0, agt.indexOf('\/')) != 'mozilla') {
            return navigator.userAgent.substr(0, agt.indexOf('\/'));
        }
        else return 'Netscape';
    } else if (agt.indexOf(' ') != -1)
        return navigator.userAgent.substr(0, agt.indexOf(' '));
    else return navigator.userAgent;
}


var chldWnd;
function pleaseWait() {
    try {
        var browserName = whichBrs();
        if (browserName == "Safari") {

        } else {
            var left = (document.documentElement.clientWidth / 2) - (150 / 2);
            var top = (document.documentElement.clientHeight / 2) - (100 / 2);
            chldWnd = window.open('', 'mywindow', 'top='+top+', left='+left+',height=100,width=150, status=no');
            chldWnd.document.write("<center><img src='./images/wait.gif'><br>");
            chldWnd.document.write('Please Wait</center>');  
            chldWnd.focus();
        }
    } catch (e) { }
  }



  function closepleaseWait() {
      try {
      
              var browserName = whichBrs();
              if (browserName == "Safari") {

              } else {
	            if (chldWnd.closed){
	               //alert('child window already closed');
	               }else{
	               //alert('child window not closed, NOW CLOSED');
	               chldWnd.close();
	              }
              }
      } catch (e) {

      }

  }







function pushStack(newVal) {
    stack.push(newVal);
    sCount++;
}



function popStack() {
    var popVal = stack.pop();
    if (popVal == undefined) {
        return "EMPTY";
    } else {
        sCount--;
        return popVal;
    }
}


// The required GWM Flash Application callback
// function to handle hotspots.
function _GWMHandleAction(a) {
    try {
    var x = a.split("'");
    var link = "http://www.mobile-propertytaxal.com/php/bill.php?key=" + x[1];
    window.open(link, "mywindow", "status=1,toolbar=1, scrollbars=1,menu=1,resizable=1");
    } catch (e) { window.status="o" }
    
}


function gup(name) {
    try {
        name = name.replace(/[\[]/, "\\\[").replace(/[\]]/, "\\\]");
        var regexS = "[\\?&]" + name + "=([^&#]*)";
        var regex = new RegExp(regexS);
        var results = regex.exec(window.location.href);
        if (results == null)
            return "";
        else
            return results[1];
    } catch (e) { 
        return ""
    }
    
    

}

//-------------------------------------------------------------------------------------------------------------------
//overview geting and refreshing and window resizing

function overview(mapRange) {
    try {

        window.frames["frmDipa"].document.getElementById("txtMapRange").value = mapRange;
        //top.window.frames["frmDipa"].stateChangeOverview();
        top.window.frames["frmDipa"].mapFunc();
    } catch (e) { window.status = "-" }
}

//function refreshOverviewMap() {
//    try {
//        //var MapObjPath = "http://GTMobileCo/cache/overviewMap.xml"
//        var MapObjPath = "http://natsuki/cache/overviewMap.xml"
//        var flashvars = {
//            bridgeName: "GWMFlashMx",
//            file: MapObjPath,
//            DefaultContextMenu: "on"
//        };

//        swfobject.embedSWF("/GWMShare/GWMFlashMx.swf", "ViewControl2", "200", "200", "10.0.0", null, flashvars);
//        GWMFlashMx.mapView.zoomIn();
//        //setTimeout("updateOverview();", 1500);
//    } catch (e) {
//        alert(e.toString());
//    }
//}



function fitMap() {
    try {
        setTimeout("layoutPage(true)", 800);
    } catch (e) {
    window.status = "..";
    }
}


var doresize = true;


function resizeApplication() {
    try {
        //layoutPage();
        if (doresize == true) {
            setTimeout("layoutPage()", 1000);
            doresize = false;
        }
    } catch (e) {
    window.status = "...";
    }
}

/**
* @method
* @param {bool} fitMap Whether or not to fit map to full extent 
*/ 
function layoutPage(fitMap) {
    //------Adjust header,north, northEast, east, south, southEast, map, icons------
    if ((document.documentElement.clientWidth < 750) || (document.documentElement.clientHeight < 475)) {
        //do nothing
    } else {
        //    d = document.getElementById('divLegend');
        //    x = document.documentElement.clientWidth - 200;
        //    d.style.left = x + "px";


        divTitle.style.width = document.documentElement.clientWidth + "px";
        mainDiv.style.width = document.documentElement.clientWidth + "px";
        divNavigation.style.left = ((document.documentElement.clientWidth - 200 - 18 - 18 - 1) / 2)- 200 + "px";
        divLegend.style.left = document.documentElement.clientWidth - 200 + "px";
        divLegendEntries.style.height = document.documentElement.clientHeight - 30 - 18 - 18 - 30 - 150 + "px";
        divLegend.style.height = document.documentElement.clientHeight - 30 - 18 - 18 - 30 - 150 + "px";
        divOverviewMap.style.left = document.documentElement.clientWidth - 200 + "px";
        divOverviewMap.style.top = document.documentElement.clientHeight - 30 - 18 - 18 - 30 - 150 + "px";

        divReadout.style.width = document.documentElement.clientWidth + "px";
        divMap.style.width = document.documentElement.clientWidth - 200 - 18 - 18 - 1 + "px"; //last -1 or -2 is for visual adjustment
        divMap.style.height = document.documentElement.clientHeight - 30 - 18 - 18 - 60 - 2 + "px"; //last -1 or -2 is for visual adjustment
        map.style.height = document.documentElement.clientHeight - 30 - 18 - 18 - 60 - 2 + "px"; //last -1 or -2 is for visual adjustment
        map.style.width = document.documentElement.clientWidth - 200 - 18 - 18 - 1 + "px"; //last -1 or -2 is for visual adjustment

        north.style.width = document.documentElement.clientWidth - 200 - 18 - 18 + "px";
        northEast.style.left = document.documentElement.clientWidth - 200 - 18 + "px";
        nArrow.style.left = ((document.documentElement.clientWidth - 200 - 18 - 18) / 2) - 18 + "px";
        west.style.height = document.documentElement.clientHeight - 30 - 18 - 18 - 60 + "px";
        wArrow.style.top = (document.documentElement.clientHeight - 30 - 18 - 18 - 60) / 2 + "px";
        east.style.height = document.documentElement.clientHeight - 30 - 18 - 18 - 60 + "px";
        eArrow.style.top = (document.documentElement.clientHeight - 30 - 18 - 18 - 60) / 2 + "px";
        east.style.left = document.documentElement.clientWidth - 200 - 18 + "px";

        south.style.width = document.documentElement.clientWidth - 200 - 18 - 18 + "px";
        south.style.top = document.documentElement.clientHeight - 60 + "px";
        sArrow.style.left = ((document.documentElement.clientWidth - 200 - 18 - 18) / 2) - 18 + "px";
        southWest.style.top = document.documentElement.clientHeight - 60 + "px";
        southEast.style.top = document.documentElement.clientHeight - 60 + "px";
        southEast.style.left = document.documentElement.clientWidth - 200 - 18 + "px";
        divReadout.style.top = document.documentElement.clientHeight - 35 + "px";
        resizeMap(fitMap);
    }
    doresize = true;
}

/**
* @method
* @param {bool} fitMap Whether or not to fit map to full extent 
*/ 
function resizeMap(fitMap) {
    try {
        // var rect = GWMFlashMx.mapView.getViewRange();

        var rect = GWMFlashMx.mapView.getViewRange();

        var X1 = (rect.xMin)
        var X2 = (rect.xMax)
        var Y1 = (rect.yMin)
        var Y2 = (rect.yMax)

        var xMin = (rect.xMin);
        var xMax = (rect.xMax);
        var yMin = (rect.yMin);
        var yMax = (rect.yMax);


        var h = (document.getElementById("divMap").style.height).split("p");
        height = h[0];
        var w = (document.getElementById("divMap").style.width).split("p");
        width = w[0];
        //alert(height + ", " + width);

        viewHeight = height;
        viewWidth = width;
        document.getElementById("ViewControl").width = width
        document.getElementById("ViewControl").height = height

        var myMssFile = MapObjPath.split("/");
        var mssFile = myMssFile[myMssFile.length - 1];

        var url = "mapOperations.aspx?operation=5&mssFile=" + mssFile + "&xMin=" + xMin + "&yMin=" + yMin + "&xMax=" + xMax + "&yMax=" + yMax + "&height=" + height + "&width=" + width + "&legendItemsOff=" + legendItemsOff + "&fitMap=" + fitMap;

	pleaseWait();
        if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari
            xmlhttp = new XMLHttpRequest();
            // set the callback function
            xmlhttp.onreadystatechange = stateChangeZoom;

            xmlhttp.open("GET", url, false);
            xmlhttp.send(null);
        }
        else {// code for IE6, IE5
            xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
            // set the callback function
            xmlhttp.onreadystatechange = stateChangeZoom;
            xmlhttp.open("GET", url, false);
            xmlhttp.send();
        }
    } catch (e) { 

	//window.status = "Couldent refresh map from server. please reload the webpage." 
	setTimeout("resizeMap(" + fitMap + ")", 1000);
	
    }
}



//-------------------------------------------------------------------------------------------------------------------



function ShowBaseMap() {

    //var url = "";
    var strHref = gup('keynum');
    if (strHref == "") {
       var url = "";
         url = "mapOperations.aspx?operation=1&keynum=" + strHref
    } else {
         url = "mapOperations.aspx?operation=4&keynum=" + strHref
    }
    //alert("strHref->" + strHref);
	
 	    pleaseWait();

    if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari
        xmlhttp = new XMLHttpRequest();
        // set the callback function
        xmlhttp.onreadystatechange = stateChange;
        xmlhttp.open("GET", url + strHref, false);
        xmlhttp.send(null);
    }
    else {// code for IE6, IE5
        xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
        // set the callback function
        xmlhttp.onreadystatechange = stateChange;
        xmlhttp.open("GET", url, false);
        xmlhttp.send();
    }
}

var viewHeight = 600;
var viewWidth = 600;



function recoverFromError() {
    try {
	 alert("No Parcel Map Could be created for the parcel you searched on. Please close your browser window and try again or manually locate a parcel.");
        var h = (document.getElementById("divMap").style.height).split("p");
        height = h[0];
        var w = (document.getElementById("divMap").style.width).split("p");
        width = w[0];
        window.location.href = "index.aspx?keynum=" + "&height=" + height + "&width=" + width;
        setTimeout("layoutPage()", 1000);
        
    } catch (e) { 
	setTimeout("recoverFromError()", 1000);	
    }
}



function stateChange() {
    if (xmlhttp.readyState == 4) {
        if (xmlhttp.status == 200) {
            var retMap = "";
            retMap = xmlhttp.responseText;
            if (retMap == "" || retMap == "ERROR" || retMap == "undefined") {
               
                setTimeout("recoverFromError()", 1000);
            } else {

                var tMapPath = (xmlhttp.responseText).split(",")
                MapObjPath = tMapPath[0];
                flashvars = {
                    bridgeName: "GWMFlashMx",
                    file: MapObjPath,
                    DefaultContextMenu: "on"
                };
		     closepleaseWait();
                swfobject.embedSWF("/GWMShare/GWMFlashMx.swf", "ViewControl", viewHeight, viewWidth, "10.0.0", null, flashvars);
                try {
                    setTimeout("refreshDynamicLegend()", 1000);
                } catch (e) {
                    setTimeout("refreshDynamicLegend()", 3000);
                }
                setTimeout("layoutPage()", 1000);

            }
        }
        else {
	    
            window.status = "There was a problem in the returned Base map";
        }
    }
}



function refreshDynamicLegend() {
    try {

	    if (!GWMFlashMx.ready) {
	
        //setTimeout("refreshDynamicLegend()", 1000);
       GWMFlashMx.readyCallback = refreshDynamicLegend();
    } else {


 var dispEntries = GWMFlashMx.legend.getDisplayEntries();
        var count = dispEntries.getCount();
        rows = document.getElementById('Table1').getElementsByTagName("tr");
        var objCheckBoxes = document.forms["form1"].elements["chkLegend"];
        var countCheckBoxes = objCheckBoxes.length;

        //first switch evrything off
        for (var i = 0; i < countCheckBoxes; i++) {
                document.getElementById(objCheckBoxes[i].value).style.display = "none";
        }
        
        
        //second switch items that are only showing on the current map
        var off;
        if (!countCheckBoxes)
            objCheckBoxes.checked = "False";

        var itemsOn = ""
        for (var i = 0; i < count; i++) {
            le = dispEntries.item(i);
            //alert(le.getName());
            itemsOn = itemsOn + le.getName() + "|";
        }
        //alert(itemsOn);
        var items = itemsOn.split("|");
        for (var a = 0; a < items.length; a++) {
            for (var i = 0; i < countCheckBoxes; i++) {
                if (objCheckBoxes[i].value == items[a]) {
                    document.getElementById(objCheckBoxes[i].value).style.display = "block";
                }
            }
        }

} //else

    } catch (e) {
        //window.status = "o-o";
	 setTimeout("refreshDynamicLegend()", 1000);	
    }





       
}



function toggle(chkbox) {
	try {
	 var visSetting = (chkbox.checked) ? "visible" : "hidden";
   	 var id = chkbox.value;
  
   	 var dispEntries = GWMFlashMx.legend.getDisplayEntries();
   	 var le = dispEntries.item(id);
   	 dispEntries.release();
  //alert(visSetting + " -> " + id);
    // turn the legend entry off in the display
    // note the use of the GWMFlashMx.DisplayMode enum here
   	 if (visSetting == "visible") {
   	     le.setDisplayMode(GWMFlashMx.DisplayMode.on);
    	} else {
    	    le.setDisplayMode(GWMFlashMx.DisplayMode.off);
    	}
    	legendItemsOff = getLegendItemsChecked();   //update variable to pass not to generate legendentries on to next map. to be passed as url entry
	} catch(e) {

	}
   
}




//function to determine which legend items are switched off on client side so that next time map gets made these items wont be generated
function getLegendItemsChecked() {
    try {
        var entriesOff = "";
        var objCheckBoxes = document.forms["form1"].elements["chkLegend"];
        var off;
       var countCheckBoxes = objCheckBoxes.length;
       if (!countCheckBoxes)
           objCheckBoxes.checked = "False";
        for (var i = 0; i < countCheckBoxes; i++) {
            if (objCheckBoxes[i].checked == false) {
                entriesOff = entriesOff + objCheckBoxes[i].value + "|";
            }
        }
        return entriesOff;
    } catch (e) {return ""; }
}



function findLegendItem(rowID, items) {
    try {
        var found = 0
        for (var i = 0; i < items.length - 1; i++) {
            if (items[i] == rowID) {
                found = 1;
            }
        }
        return found;
    } catch (e) {return 0;}
}


function refreshLegend() {
   
        rows = document.getElementById('Table1').getElementsByTagName("tr");
        var objCheckBoxes = document.forms["form1"].elements["chkLegend"];
        var off;
        var countCheckBoxes = objCheckBoxes.length;
        if (!countCheckBoxes)
            objCheckBoxes.checked = "False";
        for (var i = 0; i < countCheckBoxes; i++) {
            if (objCheckBoxes[i].checked == false) {
                document.getElementById(objCheckBoxes[i].value).style.display = "none";
            }
        }
        setTimeout("refreshDynamicLegend()", 2000); 

}

//refresh from server-----------------------------------------------------------------------------------


function refreshFromServer() {
    try {
        var rect = GWMFlashMx.mapView.getViewRange();

        var X1 = (rect.xMin)
        var X2 = (rect.xMax)
        var Y1 = (rect.yMin)
        var Y2 = (rect.yMax)

        var xMin = (rect.xMin);
        var xMax = (rect.xMax);
        var yMin = (rect.yMin);
        var yMax = (rect.yMax);

        //refresh overview map
        var xMin1 = xMin//vertexArray[0];
        var yMin1 = yMin//vertexArray[1];
        var xMax1 = xMax//vertexArray[2];
        var yMax1 = yMax//vertexArray[3];
        var mapRange = xMin1 + "," + yMin1 + "," + xMax1 + "," + yMax1
        overview(mapRange);


        var h = (document.getElementById("divMap").style.height).split("p");
        height = h[0];
        var w = (document.getElementById("divMap").style.width).split("p");
        width = w[0];
        // alert(height + ", " + width);

        viewHeight = height;
        viewWidth = width;
        document.getElementById("ViewControl").width = width
        document.getElementById("ViewControl").height = height


        var myMssFile = MapObjPath.split("/");
        var mssFile = myMssFile[myMssFile.length - 1];

        var url = "mapOperations.aspx?operation=2&mssFile=" + mssFile + "&xMin=" + xMin + "&yMin=" + yMin + "&xMax=" + xMax + "&yMax=" + yMax + "&legendItemsOff=" + legendItemsOff + "&height=" + height + "&width=" + width;

        if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari
            xmlhttp = new XMLHttpRequest();
            // set the callback function
            
            xmlhttp.onreadystatechange = stateChangeZoom;

            xmlhttp.open("GET", url, false);
            xmlhttp.send(null);
        }
        else {// code for IE6, IE5
            xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
            // set the callback function
            xmlhttp.onreadystatechange = stateChangeZoom;
            xmlhttp.open("GET", url, false);
            xmlhttp.send();
        }
    } catch (e) { 
		//window.status = "Couldent refresh map from server. please reload the webpage." 
	 setTimeout("refreshFromServer()", 1000); 

    }
}

// zoom in, zoom out, pan functionality ----------------------------------------------------------------

function stateChangeZoom() {

    if (xmlhttp.readyState == 4) {

        if (xmlhttp.status == 200) {
		 closepleaseWait();
            //alert(xmlhttp.responseText);
            var tMapPath;
            //var MapObjPath;
            try {
                tMapPath = (xmlhttp.responseText).split(",");
		if (tMapPath[0] == "") {

		} else {
                	MapObjPath = tMapPath[0];
			window.status = window.status = tMapPath; 
		}  
		
            } catch (e) {
               // MapObjPath = "";
            }
           
            
            if (MapObjPath == "" || MapObjPath == "ERROR" || MapObjPath == "undefined") {
                    //show no map
            } else {
                //alert(GWMFlashMx.ready + " for " + MapObjPath);
                if (!GWMFlashMx.ready) {

                    //setTimeout("stateChangeZoom()", 1000);
                    GWMFlashMx.readyCallback = stateChangeZoom;
                    
                } else {
                    GWMFlashMx.loadFile(MapObjPath, null, null, 1);
                    var tmpMssFile = MapObjPath.split("/");
                    var mssFile = tmpMssFile[tmpMssFile.length - 1];
                    var saveMapString = mssFile + "," + tMapPath[1] + "," + tMapPath[2] + "," + tMapPath[3] + "," + tMapPath[4];
                    pushStack(saveMapString);
                    refreshLegend();
                }
            }

            
            

        }
        else {
		//setTimeout("stateChangeZoom()", 1000);
            //alert("There was a problem in the returned Base map");
        }
    } else {
    //alert("not ready");
    }
}




var xmlhttpZOOMIN;

function stateChangeZoomIN() {

    if (xmlhttpZOOMIN.readyState == 4) {

        if (xmlhttpZOOMIN.status == 200) {
	 closepleaseWait();
            //alert(xmlhttpPAN.responseText);
            var tMapPath;
            //var MapObjPath;
            try {
		tMapPath = (xmlhttpZOOMIN.responseText).split(",");
		if (tMapPath[0] == "") {

		} else {
                	MapObjPath = tMapPath[0];
			window.status = window.status = tMapPath; 
		}  

            } catch (e) {
                //MapObjPath = "";
            }
           
            
            if (MapObjPath == "" || MapObjPath == "ERROR" || MapObjPath == "undefined") {
                    //show no map
            } else {

                if (!GWMFlashMx.ready) {

                    setTimeout("stateChangeZoomIN()", 1000);

                    window.status = "not ready";
                } else {
                    GWMFlashMx.loadFile(MapObjPath, null, null, 1);
                    var tmpMssFile = MapObjPath.split("/");
                    var mssFile = tmpMssFile[tmpMssFile.length - 1];
                    var saveMapString = mssFile + "," + tMapPath[1] + "," + tMapPath[2] + "," + tMapPath[3] + "," + tMapPath[4];
                    pushStack(saveMapString);
                    refreshLegend();
                }
            }

            
            

        }
        else {
		//setTimeout("stateChangeZoom()", 1000);
		//window.status = "PAN not ready 1";	
        }
    } else {
    	//window.status = "PAN not ready 2";
    }
}






function zoomin() {
    if (!GWMFlashMx.ready) {
        //setTimeout("zoomin()", 500);
        GWMFlashMx.readyCallback = zoomin;
    }
    else {
        var rect = GWMFlashMx.mapView.getViewRange();

        var X1 = (rect.xMin)
        var X2 = (rect.xMax)
        var Y1 = (rect.yMin)
        var Y2 = (rect.yMax)

        var DeltaX = Math.abs(X2 - X1);
        var DeltaY = Math.abs(Y2 - Y1);

        var CenterX = X2 - DeltaX / 2;
        var CenterY = Y2 - DeltaY / 2;

        var xMin = parseFloat(CenterX - (DeltaX * 0.25));
        var xMax = parseFloat(CenterX + (DeltaX * 0.25));
        var yMin = parseFloat(CenterY - (DeltaY * 0.25));
        var yMax = parseFloat(CenterY + (DeltaY * 0.25));

        //refresh overview map
        var xMin1 = xMin//vertexArray[0];
        var yMin1 = yMin//vertexArray[1];
        var xMax1 = xMax//vertexArray[2];
        var yMax1 = yMax//vertexArray[3];
        var mapRange = xMin1 + "," + yMin1 + "," + xMax1 + "," + yMax1
        overview(mapRange);


        var h = (document.getElementById("divMap").style.height).split("p");
        height = h[0];
        var w = (document.getElementById("divMap").style.width).split("p");
        width = w[0];
        // alert(height + ", " + width);

        viewHeight = height;
        viewWidth = width;
        document.getElementById("ViewControl").width = width
        document.getElementById("ViewControl").height = height



        var myMssFile = MapObjPath.split("/");
        var mssFile = myMssFile[myMssFile.length - 1];

        var url = "mapOperations.aspx?operation=2&mssFile=" + mssFile + "&xMin=" + xMin + "&yMin=" + yMin + "&xMax=" + xMax + "&yMax=" + yMax + "&legendItemsOff=" + legendItemsOff + "&height=" + height + "&width=" + width;
	window.status = url;

	   pleaseWait();	
        if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari
            xmlhttpZOOMIN = new XMLHttpRequest();
            xmlhttpZOOMIN.onreadystatechange = stateChangeZoomIN;
            xmlhttpZOOMIN.open("GET", url, false);
            xmlhttpZOOMIN.send(null);
        }
        else {// code for IE6, IE5
            xmlhttpZOOMIN = new ActiveXObject("Microsoft.XMLHTTP");
            xmlhttpZOOMIN.onreadystatechange = stateChangeZoomIN;
            xmlhttpZOOMIN.open("GET", url, false);
            xmlhttpZOOMIN.send();
        }
    }
}




var xmlhttpZOOMOUT;

function stateChangeZoomOUT() {

    if (xmlhttpZOOMOUT.readyState == 4) {

        if (xmlhttpZOOMOUT.status == 200) {
		 closepleaseWait();
            //alert(xmlhttpPAN.responseText);
            var tMapPath;
            //var MapObjPath;
            try {
		tMapPath = (xmlhttpZOOMOUT.responseText).split(",");
		if (tMapPath[0] == "") {

		} else {
                	MapObjPath = tMapPath[0];
			window.status = window.status = tMapPath; 
		}  

            } catch (e) {
                //MapObjPath = "";
            }
           
            
            if (MapObjPath == "" || MapObjPath == "ERROR" || MapObjPath == "undefined") {
                    //show no map
            } else {

                if (!GWMFlashMx.ready) {

                    setTimeout("stateChangeZoomOUT()", 1000);

                    window.status = "not ready";
                } else {
                    GWMFlashMx.loadFile(MapObjPath, null, null, 1);
                    var tmpMssFile = MapObjPath.split("/");
                    var mssFile = tmpMssFile[tmpMssFile.length - 1];
                    var saveMapString = mssFile + "," + tMapPath[1] + "," + tMapPath[2] + "," + tMapPath[3] + "," + tMapPath[4];
                    pushStack(saveMapString);
                    refreshLegend();
                }
            }

            
            

        }
        else {
		//setTimeout("stateChangeZoom()", 1000);
		//window.status = "PAN not ready 1";	
        }
    } else {
    	//window.status = "PAN not ready 2";
    }
}



function zoomout() {
    // get and set the current view range
    //setTimeout("zoomout()", 1000);

    if (!GWMFlashMx.ready) {
        // if not, set the ready callback function
        //setTimeout("zoomout()", 500);
       GWMFlashMx.readyCallback = zoomout;
    }
    else {


        var rect = GWMFlashMx.mapView.getViewRange();
        var X1 = (rect.xMin);
        var X2 = (rect.xMax);
        var Y1 = (rect.yMin);
        var Y2 = (rect.yMax);

        var DeltaX = Math.abs(X2 - X1);
        var DeltaY = Math.abs(Y2 - Y1);

        var CenterX = X2 - DeltaX / 2;
        var CenterY = Y2 - DeltaY / 2;

        var xMin = parseFloat(CenterX - (DeltaX * 0.75));
        var xMax = parseFloat(CenterX + (DeltaX * 0.75));
        var yMin = parseFloat(CenterY - (DeltaY * 0.75));
        var yMax = parseFloat(CenterY + (DeltaY * 0.75));

        //refresh overview map
        var xMin1 = xMin//vertexArray[0];
        var yMin1 = yMin//vertexArray[1];
        var xMax1 = xMax//vertexArray[2];
        var yMax1 = yMax//vertexArray[3];
        var mapRange = xMin1 + "," + yMin1 + "," + xMax1 + "," + yMax1
        overview(mapRange);

        var h = (document.getElementById("divMap").style.height).split("p");
        height = h[0];
        var w = (document.getElementById("divMap").style.width).split("p");
        width = w[0];
        // alert(height + ", " + width);

        viewHeight = height;
        viewWidth = width;
        document.getElementById("ViewControl").width = width
        document.getElementById("ViewControl").height = height


        var myMssFile = MapObjPath.split("/");
        var mssFile = myMssFile[myMssFile.length - 1];
      
        var url = "mapOperations.aspx?operation=2&mssFile=" + mssFile + "&xMin=" + xMin + "&yMin=" + yMin + "&xMax=" + xMax + "&yMax=" + yMax + "&legendItemsOff=" + legendItemsOff + "&height=" + height + "&width=" + width;

   pleaseWait();

        if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari
            xmlhttpZOOMOUT = new XMLHttpRequest();
            // set the callback function
            xmlhttpZOOMOUT.onreadystatechange = stateChangeZoomOUT;
            xmlhttpZOOMOUT.open("GET", url, false);
            xmlhttpZOOMOUT.send(null);
        }
        else {// code for IE6, IE5
            xmlhttpZOOMOUT = new ActiveXObject("Microsoft.XMLHTTP");
            // set the callback function
            xmlhttpZOOMOUT.onreadystatechange = stateChangeZoomOUT;
            xmlhttpZOOMOUT.open("GET", url, false);
            xmlhttpZOOMOUT.send();
        }

    }
}


var gDIR;

var xmlhttpPAN;

function stateChangeZoomPan() {

    if (xmlhttpPAN.readyState == 4) {

        if (xmlhttpPAN.status == 200) {
		 closepleaseWait();
            //alert(xmlhttpPAN.responseText);
            var tMapPath;
            //var MapObjPath;
            try {
		tMapPath = (xmlhttpPAN.responseText).split(",");
		if (tMapPath[0] == "") {

		} else {
                	MapObjPath = tMapPath[0];
			window.status = window.status = tMapPath; 
		}  

            } catch (e) {
                //MapObjPath = "";
            }
           
            
            if (MapObjPath == "" || MapObjPath == "ERROR" || MapObjPath == "undefined") {
                    //show no map
            } else {

                if (!GWMFlashMx.ready) {

                    setTimeout("stateChangeZoomPAN()", 1000);

                    window.status = "not ready";
                } else {
                    GWMFlashMx.loadFile(MapObjPath, null, null, 1);
                    var tmpMssFile = MapObjPath.split("/");
                    var mssFile = tmpMssFile[tmpMssFile.length - 1];
                    var saveMapString = mssFile + "," + tMapPath[1] + "," + tMapPath[2] + "," + tMapPath[3] + "," + tMapPath[4];
                    pushStack(saveMapString);
                    refreshLegend();
                }
            }

            
            

        }
        else {
		//setTimeout("stateChangeZoom()", 1000);
		//window.status = "PAN not ready 1";	
        }
    } else {
    	//window.status = "PAN not ready 2";
    }
}


function panMapClient(Dir) {
    try {


            var rect = GWMFlashMx.mapView.getViewRange();
            var xMin = (rect.xMin);
            var xMax = (rect.xMax);
            var yMin = (rect.yMin);
            var yMax = (rect.yMax);

            var panScale = 0;
	    //Change the following (0.50 or 50 percent) to adjust the distance to scroll for pan.
	    panScale = (xMax - xMin) * 0.50

            switch (Dir) {

                //north
                case 1:
                    //alert(panScale);
                    GWMFlashMx.mapView.pan(0, -panScale);
                    //alert(2);
                    rect = GWMFlashMx.mapView.getViewRange();
                    break;
                //south       
                case 2:
                    GWMFlashMx.mapView.pan(0, panScale);
                    rect = GWMFlashMx.mapView.getViewRange();
                    break;
                //East   
                case 3:
                    GWMFlashMx.mapView.pan(-panScale, 0);
                    rect = GWMFlashMx.mapView.getViewRange();
                    break;
                //West       
                case 4:
                    GWMFlashMx.mapView.pan(panScale, 0);
                    rect = GWMFlashMx.mapView.getViewRange();
                    break;
                //North East        
                case 5:
                    GWMFlashMx.mapView.pan(-panScale, -panScale);
                    rect = GWMFlashMx.mapView.getViewRange();
                    break;
                //North West           
                case 6:
                    GWMFlashMx.mapView.pan(panScale, -panScale);
                    rect = GWMFlashMx.mapView.getViewRange();
                    break;
                //South East         
                case 7:
                    GWMFlashMx.mapView.pan(-panScale, panScale);
                    rect = GWMFlashMx.mapView.getViewRange();
                    break;
                //South West       
                case 8:
                    GWMFlashMx.mapView.pan(panScale, panScale);
                    rect = GWMFlashMx.mapView.getViewRange();
                    break;
            } // -- End switch


            var h = (document.getElementById("divMap").style.height).split("p");
            height = h[0];
            var w = (document.getElementById("divMap").style.width).split("p");
            width = w[0];
            // alert(height + ", " + width);

            viewHeight = height;
            viewWidth = width;
            document.getElementById("ViewControl").width = width
            document.getElementById("ViewControl").height = height


            var myMssFile = MapObjPath.split("/");
            var mssFile = myMssFile[myMssFile.length - 1];

            var url = "mapOperations.aspx?operation=2&mssFile=" + mssFile + "&xMin=" + rect.xMin + "&yMin=" + rect.yMin + "&xMax=" + rect.xMax + "&yMax=" + rect.yMax + "&legendItemsOff=" + legendItemsOff + "&height=" + height + "&width=" + width;
		window.status = url;

 		pleaseWait();

            if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari
                xmlhttpPAN = new XMLHttpRequest();
                xmlhttpPAN.onreadystatechange = stateChangeZoomPan;
                xmlhttpPAN.open("GET", url, false);
                xmlhttpPAN.send(null);
            }
            else {// code for IE6, IE5
                xmlhttpPAN = new ActiveXObject("Microsoft.XMLHTTP");
                xmlhttpPAN.onreadystatechange = stateChangeZoomPAN;
                xmlhttpPAN.open("GET", url, false);
                xmlhttpPAN.send();
            }
     


   
} catch (e) { 
	  //do nothing. leave the current map as is.
}

}



// zoom fence functionality ----------------------------------------------------------------

function GeometryCallback(gwmEvent) {
    try {
        //alert(gwmEvent.target.vertices);
        var vertexArray = ((gwmEvent.target.vertices).toString()).split(",");
        var xMin = vertexArray[0];
        var yMin = vertexArray[1];
        var xMax = vertexArray[2];
        var yMax = vertexArray[3];

        //refresh overview map
        var mapRange = vertexArray[0] + "," + vertexArray[1] + "," + vertexArray[2] + "," + vertexArray[3]
        overview(mapRange);



        var h = (document.getElementById("divMap").style.height).split("p");
        height = h[0];
        var w = (document.getElementById("divMap").style.width).split("p");
        width = w[0];
        // alert(height + ", " + width);

        viewHeight = height;
        viewWidth = width;
        document.getElementById("ViewControl").width = width
        document.getElementById("ViewControl").height = height



        var myMssFile = MapObjPath.split("/");
        var mssFile = myMssFile[myMssFile.length - 1];

        var url = "mapOperations.aspx?operation=2&mssFile=" + mssFile + "&xMin=" + xMin + "&yMin=" + yMin + "&xMax=" + xMax + "&yMax=" + yMax + "&legendItemsOff=" + legendItemsOff + "&height=" + height + "&width=" + width;
	window.status = url;
		
	 pleaseWait();
        if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari
            xmlhttp = new XMLHttpRequest();
            // set the callback function
            xmlhttp.onreadystatechange = stateChangeZoom;
            
            xmlhttp.open("GET", url, false);
            xmlhttp.send(null);
        }
        else {// code for IE6, IE5
            xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
            // set the callback function
            xmlhttp.onreadystatechange = stateChangeZoom;
            xmlhttp.open("GET", url, false);
            xmlhttp.send();
        }
    } catch (e) {
        window.status = "couldent capture";
    }
}

function zoomFence() {
    try {
        if (!GWMFlashMx.ready) {
            // if not, set the ready callback function
            GWMFlashMx.readyCallback = zoomFence;
        } else {
            GWMFlashMx.mapView.geometryCaptureService.cmdCaptureRectangle("GeometryCallback");
        }
    } catch (e) {
        window.status = "couldent draw rectangle";
    }
}

// center map functionality ----------------------------------------------------------------


function centerMap() {
    try {
 	if (!GWMFlashMx.ready) {
            GWMFlashMx.readyCallback = centerMap;
        } else {
             GWMFlashMx.mapView.cmdCenter("centerMapCallback");
        }
       
    } catch (e) {
        window.status = "couldent center on map window";
    }
}



function centerMapCallback(gwmEvent) {
    try {
        var rect = GWMFlashMx.mapView.getViewRange();
        var xMin = (rect.xMin)
        var xMax = (rect.xMax)
        var yMin = (rect.yMin)
        var yMax = (rect.yMax)

        var h = (document.getElementById("divMap").style.height).split("p");
        height = h[0];
        var w = (document.getElementById("divMap").style.width).split("p");
        width = w[0];
        // alert(height + ", " + width);

        viewHeight = height;
        viewWidth = width;
        document.getElementById("ViewControl").width = width
        document.getElementById("ViewControl").height = height
        
        

        var myMssFile = MapObjPath.split("/");
        var mssFile = myMssFile[myMssFile.length - 1];
	if (mssFile == "") {
		centerMapCallback(gwmEvent);
	} else {
        var url = "mapOperations.aspx?operation=2&mssFile=" + mssFile + "&xMin=" + xMin + "&yMin=" + yMin + "&xMax=" + xMax + "&yMax=" + yMax + "&legendItemsOff=" + legendItemsOff + "&height=" + height + "&width=" + width;
      	window.status = url;


	 pleaseWait();
        if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari
            xmlhttp = new XMLHttpRequest();
            // set the callback function
            xmlhttp.onreadystatechange = stateChangeZoom;
            xmlhttp.open("GET", url, false);
            xmlhttp.send(null);
        }
        else {// code for IE6, IE5
            xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
            // set the callback function
            xmlhttp.onreadystatechange = stateChangeZoom;
            xmlhttp.open("GET", url, false);
            xmlhttp.send();
        }


	}
	

    } catch (e) {
        window.status = "couldent capture";
    }

}



// go back functionality ----------------------------------------------------------------

function goBack() {
try{
	var mapDetails = "";
    var mapDetailsTemp = "";
    mapDetailsTemp = popStack();
    mapDetailsTemp = popStack();
    var MapFile = mapDetailsTemp.split(",");
    var mssFile = MapFile[0];
    var xMin = MapFile[1];
    var yMin = MapFile[2];
    var xMax = MapFile[3];
    var yMax = MapFile[4];


    var h = (document.getElementById("divMap").style.height).split("p");
    height = h[0];
    var w = (document.getElementById("divMap").style.width).split("p");
    width = w[0];
    // alert(height + ", " + width);

    viewHeight = height;
    viewWidth = width;
    document.getElementById("ViewControl").width = width
    document.getElementById("ViewControl").height = height

    var url = "mapOperations.aspx?operation=2&mssFile=" + mssFile + "&xMin=" + xMin + "&yMin=" + yMin + "&xMax=" + xMax + "&yMax=" + yMax + "&legendItemsOff=" + legendItemsOff + "&height=" + height + "&width=" + width; 
    //alert(url)

    if (mssFile == "EMPTY") {
        var h = (document.getElementById("divMap").style.height).split("p");
        height = h[0];
        var w = (document.getElementById("divMap").style.width).split("p");
        width = w[0];
        var mssFile = "finalDeploy.mss";

        
        var url = "mapOperations.aspx?operation=5&mssFile=" + mssFile + "&xMin=" + xMin + "&yMin=" + yMin + "&xMax=" + xMax + "&yMax=" + yMax + "&legendItemsOff=" + legendItemsOff + "&height=" + height + "&width=" + width;

 	pleaseWait();
        if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari
            xmlhttp = new XMLHttpRequest();
            // set the callback function
            xmlhttp.onreadystatechange = stateChangeZoom;
            xmlhttp.open("GET", url, false);
            xmlhttp.send(null);
        }
        else {// code for IE6, IE5
            xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
            // set the callback function
            xmlhttp.onreadystatechange = stateChangeZoom;
            xmlhttp.open("GET", url, false);
            xmlhttp.send();
        }
        
        
        
        //window.location.href = "mapOperations.aspx?operation=5&mssFile=" + mssFile + "&xMin=" + xMin + "&yMin=" + yMin + "&xMax=" + xMax + "&yMax=" + yMax + "&legendItemsOff=" + legendItemsOff + "&height=" + height + "&width=" + width; 
        //window.location.href = "index.aspx?key=" + "&height=" + height + "&width=" + width; 
         //alert("You are now looking at your first Map");
    } else {

	pleaseWait();
        if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari
            xmlhttp = new XMLHttpRequest();
            // set the callback function
            xmlhttp.onreadystatechange = stateChangeZoom;
            xmlhttp.open("GET", url, true);
            xmlhttp.send(null);
        }
        else {// code for IE6, IE5
            xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
            // set the callback function
            xmlhttp.onreadystatechange = stateChangeZoom;
            xmlhttp.open("GET", url, true);
            xmlhttp.send();
        }
    }
} catch(e) {

}
    

}



//help functionality-----------------------------------------------------------------------------------------

function help() {
    try {
        window.open('help.htm', 'help', 'menubar=no,status=yes,scrollbars=yes');
    } catch (e) {
        alert("Help File is current not available.Thank you.");
        }
}


//print -----------------------------------------------------------------------------------------------------

function print() {
    try {
        var x = stack.length
        var y = stack[stack.length - 1]

        //alert(y);
        
        var h = (document.getElementById("divMap").style.height).split("p");
        height = h[0];
        var w = (document.getElementById("divMap").style.width).split("p");
        width = w[0];

        //var myMssFile = MapObjPath.split("/");
        //var mssFile = myMssFile[myMssFile.length - 1];
        window.open('printPreview.aspx?mssFile=' + y + '&width='+ width + '&height=' + height, 'print', 'menubar=no,status=yes, scrollbars=yes');
    } catch (e) {
    alert("could not generate print preview. please use file->print on your browser instead");
    }
}

//--------------------------------------------------------------------------------------------------------

//distance and area functions


function drawPolygonPolyline(type) {
    try {
        if (type == 1) {
            GWMFlashMx.mapView.geometryCaptureService.cmdCapturePolygon("GeometryCallbackPolygon");
        } else {
            GWMFlashMx.mapView.geometryCaptureService.cmdCapturePolyline("GeometryCallbackPolyline");
        }
    } catch (e) {
        window.status = "couldent draw shape. try again or click on refresh map from server or click on go home button.";
    }
}



function GeometryCallbackPolyline(gwmEvent) {
    try {

        var vertexArray = ((gwmEvent.target.vertices).toString()).split(",")
        var coordList = (vertexArray.length / 2).toString();
        for (var i = 0; i < vertexArray.length; i++) {
            coordList = coordList + "|" + vertexArray[i];
        }

        var arrPoints;
        var distance = 0;
        arrPoints = coordList.split("|");
        numPoints = arrPoints[0];

        for (i = 1; i < numPoints; i++) {
            distance += Math.sqrt((((arrPoints[i + 2] - arrPoints[i]) * (arrPoints[i + 2] - arrPoints[i])) + ((arrPoints[i + 3] - arrPoints[i + 1]) * (arrPoints[i + 3] - arrPoints[i + 1]))));
        }

        distance = roundNumber(distance, 2);
        document.getElementById("txtReadout").value = distance + " ft";
        document.getElementById("divReadoutText").innerHTML = "Distance: ";

    } catch (e) {
        window.status = "could not calculate distance"
    }
}






function GeometryCallbackPolygon(gwmEvent) {
    try {
        var CTSvc = null;
        CTSvc = GWMFlashMx.mapView.transformationService;
        verts = CTSvc.transformVertices(gwmEvent.target.vertices, GWMFlashMx.CoordinateUnits.Storage, GWMFlashMx.CoordinateUnits.Distance);

        var coordArr = (verts.toString()).split(',');
        //coordArr = coordArr.slice(2);
        var totalArea = calcArea(coordArr);
        var cArea;
        var area;
        document.getElementById("divReadoutText").innerHTML = "Area: ";
        if (totalArea > 4046.85642) {
            //display result in acres after converting input(square meters)
            cArea = totalArea / 4046.85642;
            area = roundNumber(cArea, 2);
            document.getElementById("txtReadout").value = " " + area + " acres";
        } else {
            //display result in square feet after converting input(square meters)
            cArea = 10.7639104 * totalArea;
            area = roundNumber(cArea, 2);
            document.getElementById("txtReadout").value = " " + area + " sq ft";
        }
        cArea = 0;
        area = 0;

    } catch (e) {
        window.status = "oops so sorry"
    }
}


function calcArea(coordArr) {
    var area = 0.0;
    for (var i = 0; i < coordArr.length - 2; i += 2) {
        var pX1 = coordArr[i] * 1;
        var pY1 = coordArr[i + 1] * 1;
        var pX2 = coordArr[i + 2] * 1;
        var pY2 = coordArr[i + 3] * 1;
        area += (pX1 * pY2 - pX2 * pY1);
    }
    return Math.abs(area / 2);
}


//============================================================
function CalculateDistance(verts) {
    var dx = 0.0;
    var dy = 0.0;
    var fResult = 0.0;
    var currX = 0.0;
    var nextX = 0.0;
    var currY = 0.0;
    var nextY = 0.0;
    var i = 0;
    var len = verts.length;

    currX = verts[i++];
    currY = verts[i++];

    while (i < len) {
        nextX = verts[i++];
        nextY = verts[i++];
        dx = nextX - currX;
        dy = nextY - currY;
        fResult += Math.sqrt(((dx * dx) + (dy * dy)));
        currX = nextX;
        currY = nextY;
    }
    return fResult;

} // CalculateDistance()

//==============================================================
function ConvertFromTo(fInValue, sInUnit, sOutUnit) {
    var fResult = 0.0;
    var sBuf = "";

    sBuf = sInUnit.toLowerCase();

    fResult = fInValue;

    if (sBuf == "m") {
        if (sOutUnit == "km") {
            fResult = fInValue / 1000;
        }
        else if (sOutUnit == "mi") {
            fResult = fInValue * .00062136;  // 3.2808/5280=.00062136
        }
        else if (sOutUnit == "ft") {
            fResult = fInValue * 3.2808;
        }
        else if (sOutUnit == "yd") {
            fResult = (fInValue * 1.0936); // 3.2808/3=1.0936;
        }
    }
    else if (sBuf == "sq m") {
        if (sOutUnit == "sq km") {
            fResult = fInValue / (1000 * 1000);
        }
        else if (sOutUnit == "sq mi") {
            fResult = fInValue * (.00062136 * .00062136);
        }
        else if (sOutUnit == "sq ft") {
            fResult = fInValue * (3.2808 * 3.2808);
        }
        else if (sOutUnit == "sq yd") {
            fResult = fInValue * (1.0936 * 1.0936);
        }
    }
    else if (sBuf == "km") {
        if (sOutUnit == "m") {
            fResult = fInValue * 1000;
        }
        else if (sOutUnit == "mi") {
            fResult = fInValue * .6214;
        }
        else if (sOutUnit == "ft") {
            fResult = fInValue * 3280.8330;
        }
        else if (sOutUnit == "yd") {
            fResult = fInValue * 1093.611; //3280.8330 / 3 = 1093.611
        }
    }
    else if (sBuf == "sq km") {
        if (sOutUnit == "sq m") {
            fResult = fInValue * (1000 * 1000);
        }
        else if (sOutUnit == "sq mi") {
            fResult = fInValue * (.6214 * .6214);
        }
        else if (sOutUnit == "sq ft") {
            fResult = fInValue * (3280.8330 * 3280.8330);
        }
        else if (sOutUnit == "sq yd") {
            fResult = fInValue * (1093.611 * 1093.611);
        }
    }
    else if (sBuf == "mi") {
        if (sOutUnit == "m") {
            fResult = fInValue * 1609.3;  //1.6093 * 1000 = 1609.3
        }
        else if (sOutUnit == "km") {
            fResult = fInValue * 1.6093;
        }
        else if (sOutUnit == "ft") {
            fResult = fInValue * 5280;
        }
        else if (sOutUnit == "yd") {
            fResult = fInValue * 1760;
        }
    }
    else if (sBuf == "sq mi") {
        if (sOutUnit == "sq m") {
            fResult = fInValue * (1609.3 * 1609.3);
        }
        else if (sOutUnit == "sq km") {
            fResult = fInValue * (1.6093 * 1.6093);
        }
        else if (sOutUnit == "sq ft") {
            fResult = fInValue * (5280 * 5280);
        }
        else if (sOutUnit == "sq yd") {
            fResult = fInValue * (1760 * 1760);
        }
    }
    else if (sBuf == "ft") {
        if (sOutUnit == "m") {
            fResult = fInValue * .3048;
        }
        else if (sOutUnit == "km") {
            fResult = fInValue * 0.0003048; // 3048/1000=0.0003048
        }
        else if (sOutUnit == "mi") {
            fResult = fInValue / 5280;
        }
        else if (sOutUnit == "yd") {
            fResult = fInValue / 3;
        }
    }
    else if (sBuf == "sq ft") {
        if (sOutUnit == "sq m") {
            fResult = fInValue * (.3048 * .3048);
        }
        else if (sOutUnit == "sq km") {
            fResult = fInValue * (.0003048 * .0003048);
        }
        else if (sOutUnit == "sq mi") {
            fResult = fInValue / (5280 * 5280);
        }
        else if (sOutUnit == "sq yd") {
            fResult = fInValue / (3 * 3);
        }
    }
    else if (sBuf == "yd") {
        if (sOutUnit == "m") {
            fResult = fInValue * 0.9144111192392;
        }
        else if (sOutUnit == "km") {
            fResult = fInValue * 0.0009144111192392;
        }
        else if (sOutUnit == "mi") {
            fResult = fInValue / 1760;
        }
        else if (sOutUnit == "ft") {
            fResult = fInValue * 3;
        }
    }
    else if (sBuf == "sq yd") {
        if (sOutUnit == "sq m") {
            fResult = fInValue * (0.9144111192392 * 0.9144111192392);
        }
        else if (sOutUnit == "sq km") {
            fResult = fInValue * (0.0009144111192392 * 0.0009144111192392);
        }
        else if (sOutUnit == "sq mi") {
            fResult = fInValue / (1760 * 1760);
        }
        else if (sOutUnit == "sq ft") {
            fResult = fInValue * (3 * 3);
        }
    }
    
    return fResult;

} // ConvertFromTo()

function roundNumber(num, dec) {
    var result = Math.round(num * Math.pow(10, dec)) / Math.pow(10, dec);
    return result;
}


//------------------------------------------------------------------------------------

function goHome() {
    try {
        window.location.href = window.location.href
        var h = (document.getElementById("divMap").style.height).split("p");
        height = h[0];
        var w = (document.getElementById("divMap").style.width).split("p");
        width = w[0];
       // window.location.href = "index.aspx?key=" + "&height=" + height + "&width=" + width; 
    } catch (e) { window.status = "Could Not go back to the home page. Please refresh or close the browser window." }
}


