	
// ********************************************************
// tools.js  Javascript functions used by IMS frames
// Programmer: Michael Shen
// Original Date: May 15 2002
// Last revised date: August 4, 2004
// Application: City iMap
// ********************************************************


var panning=false;
var zooming=false;

var toolMode  // zoomin

function GetExtent() 
{
   top.control.document.theme.LEFT.value=top.map.document.forms[0].LEFT.value
   top.control.document.theme.RIGHT.value=top.map.document.forms[0].RIGHT.value
   top.control.document.theme.BOTTOM.value=top.map.document.forms[0].BOTTOM.value
   top.control.document.theme.TOP.value=top.map.document.forms[0].TOP.value
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v3.0
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function GetScreenSetting() {
  var sh = screen.height;
  var sw = screen.width;
  if ((sh !=600) | (sw!=800)) {
 //    alert('This application is best viewed at 800x600 resolution. All data in this map subject to be changed without notification. The City of Medicine Hat is providing the data without liability to the City of Medicine Hat, its officers, employees, agents or elected officals. The City of Medicine Hat air photo, provided in this application, was taken on April 23 1999.');
  }
  else {
 //    alert('All data in this map subject to be changed without notification. The City of Medicine Hat is providing the data without liability to the City of Medicine Hat, its officers, employees, agents or elected officals. The City of Medicine Hat air photo, provided in this application, was taken on April 23 1999.');
  }
}

function TurnLotOn() {
   top.layers.document.theme.lots.checked=true ;
}

function TurnThemeOn(atheme) {
   var elelen
   elelen = top.layers.document.theme.elements.length
   for (var i = 0; i < elelen ; i++) {
       if (top.layers.document.theme.elements[i].name == atheme)
          top.layers.document.theme.elements[i].checked = true;  }
}

function GetOnOff() {
 if (top.layers.document.theme.river.checked) {  // get river on/off value in map
     top.map.document.forms[0].river.value="on";
     }
 else {
     top.map.document.forms[0].river.value="";
     }
 if (top.layers.document.theme.park.checked) {   // get park on/off value in map
       top.map.document.forms[0].park.value="on";
       }
 else {
       top.map.document.forms[0].park.value="";
       }
 if (top.layers.document.theme.building.checked) {  // get building on/off value in map
       top.map.document.forms[0].building.value="on";
       }
 else {
       top.map.document.forms[0].building.value="";
       }
 if (top.layers.document.theme.golf.checked) {   // get golf on/off value in map
       top.map.document.forms[0].golf.value="on";
       }
 else {
       top.map.document.forms[0].golf.value="";
       }
 if (top.layers.document.theme.slsn.checked) {  // get slsn on/off value in map
       top.map.document.forms[0].slsn.value="on";
       }
 else {
       top.map.document.forms[0].slsn.value="";
       }
 if (top.layers.document.theme.dbln.checked) {   // get dbln on/off value in map
       top.map.document.forms[0].dbln.value="on";
       }
 else {
       top.map.document.forms[0].dbln.value="";
       }
 if (top.layers.document.theme.airport.checked) {  // get airport on/off value in map
       top.map.document.forms[0].airport.value="on";
       }
 else {
       top.map.document.forms[0].airport.value="";
       }
 if (top.layers.document.theme.lots.checked) {   // get lots on/off value in map
       top.map.document.forms[0].lots.value="on";
       }
 else {
       top.map.document.forms[0].lots.value="";
       }
 if (top.layers.document.theme.trail.checked) {  // get trail on/off value in map
       top.map.document.forms[0].trail.value="on";
       }
 else {
       top.map.document.forms[0].trail.value="";
       }
 if (top.layers.document.theme.landuse.checked) {   // get landuse on/off value in map
       top.map.document.forms[0].landuse.value="on";
       }
 else {
       top.map.document.forms[0].landuse.value="";
       }
 if (top.layers.document.theme.airphoto.checked) {   // get airphoto image on/off value in map
       top.map.document.forms[0].airphoto.value="on";
       }
 else {
       top.map.document.forms[0].airphoto.value="";
       }
}

function SetSearchOnOff() {
 if (window.opener.parent.frames["layers"].document.theme.river.checked) {  // get river on/off value in map
     window.document.forms[0].river.value="on";
     }
 else {
     window.document.forms[0].river.value="";
     }
 if (window.opener.parent.frames["layers"].document.theme.park.checked) {   // get park on/off value in map
       window.document.forms[0].park.value="on";
       }
 else {
       window.document.forms[0].park.value="";
       }
 if (window.opener.parent.frames["layers"].document.theme.building.checked) {  // get building on/off value in map
       window.document.forms[0].building.value="on";
       }
 else {
       window.document.forms[0].building.value="";
       }
 if (window.opener.parent.frames["layers"].document.theme.golf.checked) {   // get golf on/off value in map
       window.document.forms[0].golf.value="on";
       }
 else {
       window.document.forms[0].golf.value="";
       }
 if (window.opener.parent.frames["layers"].document.theme.slsn.checked) {  // get slsn on/off value in map
       window.document.forms[0].slsn.value="on";
       }
 else {
       window.document.forms[0].slsn.value="";
       }
 if (window.opener.parent.frames["layers"].document.theme.dbln.checked) {   // get dbln on/off value in map
       window.document.forms[0].dbln.value="on";
       }
 else {
       window.document.forms[0].dbln.value="";
       }
 if (window.opener.parent.frames["layers"].document.theme.airport.checked) {  // get airport on/off value in map
       window.document.forms[0].airport.value="on";
       }
 else {
       window.document.forms[0].airport.value="";
       }
 if (window.opener.parent.frames["layers"].document.theme.lots.checked) {   // get lots on/off value in map
       window.document.forms[0].lots.value="on";
       }
 else {
       window.document.forms[0].lots.value="";
       }
 if (window.opener.parent.frames["layers"].document.theme.trail.checked) {  // get trail on/off value in map
       window.document.forms[0].trail.value="on";
       }
 else {
       window.document.forms[0].trail.value="";
       }
 if (window.opener.parent.frames["layers"].document.theme.landuse.checked) {   // get landuse on/off value in map
       window.document.forms[0].landuse.value="on";
       }
 else {
       window.document.forms[0].landuse.value="";
       }
 if (window.opener.parent.frames["layers"].document.theme.airphoto.checked) {   // get airphoto image on/off value in map
       window.document.forms[0].airphoto.value="on";
       }
 else {
       window.document.forms[0].airphoto.value="";
       }
 // Get the framewidht and frameheight value from map frame 
 window.document.forms[0].framewidth.value = window.opener.parent.frames["map"].document.forms[0].framewidth.value
 window.document.forms[0].frameheight.value = window.opener.parent.frames["map"].document.forms[0].frameheight.value

}

function resetSearch() {
if (top.path != null) {
  top.path.document.forms[0].houseno1.value = ""
  top.path.document.forms[0].suffix1.value=""
  top.path.document.forms[0].unit1.value=""
  top.path.document.forms[0].houseno2.value = ""
  top.path.document.forms[0].suffix2.value=""
  top.path.document.forms[0].unit2.value=""
  }
if (top.address != null) {
  top.address.document.forms[0].houseno.value = ""
  top.address.document.forms[0].suffix.value=""
  top.address.document.forms[0].unit.value=""
//  top.address.document.forms[0].streetname.value=""
//  top.address.document.forms[0].streetinfo.options[0].selected = true
//  top.address.document.forms[0].type.options[0].selected = true
//  top.address.document.forms[0].dir.options[0].selected = true
  }
}

function setAddress() {
// Code for From address or site 
  if (this.document.forms[0].R1[0].checked) {  //   from by name
     document.forms[0].houseno1.value = ""
     document.forms[0].suffix1.value = ""
     document.forms[0].unit1.value = ""
     document.forms[0].streetname1.value = ""
     document.forms[0].type1.value = ""
     document.forms[0].dir1.value = ""
     var siteIndex = document.forms[0].sitename1.selectedIndex
     document.forms[0].site1.value=document.forms[0].sitename1.options[siteIndex].text
     }
  else {  // from by address
     var houseno = document.forms[0].houseno1.value
     var suffix = document.forms[0].suffix1.value
     var unit = document.forms[0].unit1.value
     var stnameInteger, streetinfo
     stnameInteger=document.forms[0].streetinfo1.selectedIndex
     streetinfo=document.forms[0].streetinfo1.options[stnameInteger].text
     var arrayOfStrings = streetinfo.split(" ")
     if (arrayOfStrings.length < 4) {
        streetname = arrayOfStrings[0]
        type = arrayOfStrings[1]
        dir = arrayOfStrings[2]
       }
     else {
        var stnam
        var init = 0
        for (var i=0; i < arrayOfStrings.length - 2; i++) {
            if (init == 0) {
               stnam = arrayOfStrings[i]
               init = init + 1
               }
            else {
                stnam = stnam + " " + arrayOfStrings[i] 
               }
            }
        var l = arrayOfStrings.length
        streetname = stnam.replace(/&/gi,"_")
        var type = arrayOfStrings[l - 2]
        var dir = arrayOfStrings[l - 1]
        }
     document.forms[0].streetname1.value = streetname
     document.forms[0].type1.value = type
     document.forms[0].dir1.value = dir
     document.forms[0].site1.value = ""
   }
// Code for To address or To site
  if (this.document.forms[0].R2[0].checked) {  //   to by name
     document.forms[0].houseno2.value = ""
     document.forms[0].suffix2.value = ""
     document.forms[0].unit2.value = ""
     document.forms[0].streetname2.value = ""
     document.forms[0].type2.value = ""
     document.forms[0].dir2.value = ""
     var siteIndex = document.forms[0].sitename2.selectedIndex
     document.forms[0].site2.value=document.forms[0].sitename2.options[siteIndex].text
     }
   else {  // to by address
     var houseno = document.forms[0].houseno2.value
     var suffix = document.forms[0].suffix2.value
     var unit = document.forms[0].unit2.value
     var stnameInteger, streetinfo
     stnameInteger=document.forms[0].streetinfo2.selectedIndex
     streetinfo=document.forms[0].streetinfo2.options[stnameInteger].text
     var arrayOfStrings = streetinfo.split(" ")
     if (arrayOfStrings.length < 4) {
        streetname = arrayOfStrings[0]
        type = arrayOfStrings[1]
        dir = arrayOfStrings[2]
        }
     else {
        var stnam
        var init = 0
        for (var i=0; i < arrayOfStrings.length - 2; i++) {
            if (init == 0) {
               stnam = arrayOfStrings[i]
               init = init + 1
               }
            else {
                stnam = stnam + " " + arrayOfStrings[i] 
               }
            }
        var l = arrayOfStrings.length
        streetname = stnam.replace(/&/gi,"_")
        var type = arrayOfStrings[l - 2]
        var dir = arrayOfStrings[l - 1]
        }
     document.forms[0].streetname2.value = streetname
     document.forms[0].type2.value = type
     document.forms[0].dir2.value = dir
     document.forms[0].site2.value = ""
   }
  var houseno1 = document.forms[0].houseno1.value
  var suffix1 = document.forms[0].suffix1.value
  var unit1 = document.forms[0].unit1.value
  var streetname1 = document.forms[0].streetname1.value
  var type1 = document.forms[0].type1.value
  var dir1 = document.forms[0].dir1.value
  var fromaddress = unit1.toUpperCase() + " " + houseno1 + " " +  suffix1.toUpperCase() + " " + streetname1.toUpperCase() + " " + type1 + " " + dir1
  var houseno2 = document.forms[0].houseno2.value
  var suffix2 = document.forms[0].suffix2.value
  var unit2 = document.forms[0].unit2.value
  var streetname2 = document.forms[0].streetname2.value
  var type2 = document.forms[0].type2.value
  var dir2 = document.forms[0].dir2.value
  var toaddress = unit2.toUpperCase() + " " + houseno2 + " " +  suffix2.toUpperCase() + " " + streetname2.toUpperCase() + " " + type2 + " " + dir2
  var siteInteger, fromsite, tosite

  if (this.document.forms[0].R1[0].checked) {  // from is by name
     fromsite=document.forms[0].site1.value
     if (this.document.forms[0].R2[0].checked) { // To is by name 
        tosite=document.forms[0].site2.value
        showmessage('Searching Path From ' + fromsite + ', To ' + tosite + ', please wait...') }
     else
        showmessage('Searching Path From ' + fromsite + ', To ' + toaddress + ', please wait...')
     }
  else {  // from is by address
     if (this.document.forms[0].R2[0].checked)  { // To is by name
        tosite=document.forms[0].site2.value
        showmessage('Searching Path From ' + fromaddress + ', To ' + tosite + ', please wait...') }
     else
        showmessage('Searching Path From ' + fromaddress + ', To ' + toaddress + ', please wait...')
     }
}


function PanMap(action){
  var newURL;
  var leftval = top.map.document.forms[0].LEFT.value;
  var rightval = top.map.document.forms[0].RIGHT.value;
  var topval = top.map.document.forms[0].TOP.value;
  var bottomval = top.map.document.forms[0].BOTTOM.value;
  var riverval = top.map.document.forms[0].river.value;
  var parkval = top.map.document.forms[0].park.value;
  var buildingval = top.map.document.forms[0].building.value;
  var golfval = top.map.document.forms[0].golf.value;
  var slsnval = top.map.document.forms[0].slsn.value;
  var dblnval = top.map.document.forms[0].dbln.value;
  var airportval = top.map.document.forms[0].airport.value;
  var lotsval = top.map.document.forms[0].lots.value;
  var trailval = top.map.document.forms[0].trail.value;
  var landuseval = top.map.document.forms[0].landuse.value;
  var lightval = top.map.document.forms[0].streetlight.value;
  var airphotoval = top.map.document.forms[0].airphoto.value;
  var optiontool = top.map.document.forms[0].mapoption.value;
  var foundx = top.map.document.forms[0].foundaddX.value;
  var foundy = top.map.document.forms[0].foundaddY.value;
  var fromx = top.map.document.forms[0].fromX.value;
  var fromy = top.map.document.forms[0].fromY.value;
  var tox = top.map.document.forms[0].toX.value;
  var toy = top.map.document.forms[0].toY.value;
  var legalinfo = top.map.document.forms[0].legalinfo.value;
  var screenwidth = top.map.document.forms[0].screenwidth.value;
  var framewidth = top.map.document.forms[0].framewidth.value;
  var frameheight = top.map.document.forms[0].frameheight.value;

  var onepage = "";
  if (self.document.forms[0] != null) {
     if (self.document.forms[0].onepage != null) var onepage = self.document.forms[0].onepage.value;
     }
  else {
    if (top.map != null) {
       if (top.map.document.forms[0].onepage != null) var onepage = top.map.document.forms[0].onepage.value;
       }
    }
 
  if (action=="map") {
     newURL = "/servlet/com.esri.esrimap.Esrimap?name=cityims&Cmd=" + action + "&mapoption=" + optiontool + "&streetlight=" + lightval + "&river=" + riverval + "&park=" + parkval + "&building=" + buildingval  + "&golf=" + golfval  + "&slsn=" + slsnval  + "&dbln=" + dblnval  + "&airport=" + airportval  + "&lots=" + lotsval  + "&trail=" + trailval  + "&landuse=" + landuseval  + "&airphoto=" + airphotoval + "&foundaddX=" + foundx + "&foundaddY=" + foundy + "&fromX=" + fromx + "&fromY=" + fromy + "&toX=" + tox + "&toY=" + toy + "&legalinfo=" + legalinfo + "&screenwidth=" + screenwidth + "&framewidth=" + framewidth + "&frameheight=" + frameheight + "&onepage=" + onepage;
  }
  else {
     newURL = "/servlet/com.esri.esrimap.Esrimap?name=cityims&Cmd=" + action + "&mapoption=" + optiontool + "&left=" + leftval + "&right=" + rightval + "&top=" + topval + "&bottom=" + bottomval + "&streetlight=" + lightval + "&river=" + riverval + "&park=" + parkval + "&building=" + buildingval  + "&golf=" + golfval  + "&slsn=" + slsnval  + "&dbln=" + dblnval  + "&airport=" + airportval  + "&lots=" + lotsval  + "&trail=" + trailval  + "&landuse=" + landuseval  + "&airphoto=" + airphotoval  + "&foundaddX=" + foundx + "&foundaddY=" + foundy + "&fromX=" + fromx + "&fromY=" + fromy + "&toX=" + tox + "&toY=" + toy + "&legalinfo=" + legalinfo + "&screenwidth=" + screenwidth + "&framewidth=" + framewidth + "&frameheight=" + frameheight + "&onepage=" + onepage;
    }
  showRetrieveMap();
  top.map.document.location=newURL;
}

function writeoverview(imgsrc) {
top.overview.document.open("text/html")
top.overview.document.writeln ("<html>")
top.overview.document.writeln ("<head>")
top.overview.document.writeln ("<meta http-equiv=Content-Type content=text/html; charset=windows-1252>")
top.overview.document.writeln ("<title>City OverView Map</title>")
top.overview.document.writeln ("</head>")
top.overview.document.writeln ("<body background=/cityimap/background.jpg>")
top.overview.document.writeln ("<table border=0 width=16%>")
top.overview.document.writeln ("<tr><td width=100%>")
top.overview.document.writeln ("<p align=center>")
top.overview.document.writeln ("<font face=Arial size=2 color=#000080>")
top.overview.document.writeln ("OverView Map</b></font></p>")
top.overview.document.writeln ("</td></tr>")
top.overview.document.writeln ("<tr>")
top.overview.document.writeln ("<td width=100%>")
top.overview.document.writeln ("<img src=" + imgsrc + " border=1>")
top.overview.document.writeln ("</td></tr>")
top.overview.document.writeln ("</table>")
top.overview.document.writeln ("</body>")
top.overview.document.writeln ("</html>")
top.overview.document.close()
showmessage('')
}

function showmessage(msg) {
var msg = msg.replace(/_/gi," ")
if (self.name == "search") {
   var mframe = window.opener.parent.frames["mapstatus"];
   }
else { 
   var mframe = top.mapstatus;
     }
if (mframe != null) {
   mframe.document.open();
   mframe.document.writeln ("<html>")
   mframe.document.writeln ("<head>")
   mframe.document.writeln ("<meta http-equiv=Content-Type content=text/html; charset=windows-1252>")
   mframe.document.writeln ("<title>Status</title>")
   mframe.document.writeln ("</head>")
   mframe.document.writeln ("<body background=/cityimap/background.jpg>")
   mframe.document.writeln ("<font color=#000080 size=1 face=Arial>Status: " + msg + "</font>")
   mframe.document.writeln ("</body>")
   mframe.document.writeln ("</html>")
   mframe.document.close();}
}

function writeaddress(address,landuse) {
var newaddress = address.replace(/_/gi," ")
top.query.document.open()
top.query.document.writeln ("<html>")
top.query.document.writeln ("<head>")
top.query.document.writeln ("<meta http-equiv=Content-Type content=text/html; charset=windows-1252>")
top.query.document.writeln ("<title>Query</title>")
top.query.document.writeln ("</head>")
top.query.document.writeln ("<body background=/cityimap/background.jpg>")
top.query.document.writeln ("<font color=#000080 size=1 face=Arial><b>Lot address: </font><br><font size=1>" + newaddress + "</font><br>")
top.query.document.writeln ("<font color=#000080 size=1 face=Arial><b>Landuse zoning: </font><br><font size=1>" + landuse + "</font><br>")
top.query.document.writeln ("</body>")
top.query.document.writeln ("</html>")
top.query.document.close()
}

function writequery(legal,landuse) {
var arrayOfStrings = legal.split(";")
var l = arrayOfStrings.length
if (arrayOfStrings.length == 3) {
    var newlegal = arrayOfStrings[2] + ";" + arrayOfStrings[1] + ";" + arrayOfStrings[0] }
else { newlegal = " " }
top.query.document.open()
top.query.document.writeln ("<html>")
top.query.document.writeln ("<head>")
top.query.document.writeln ("<meta http-equiv=Content-Type content=text/html; charset=windows-1252>")
top.query.document.writeln ("<title>Query</title>")
top.query.document.writeln ("</head>")
top.query.document.writeln ("<body background=/cityimap/background.jpg>")
//top.query.document.writeln ("<font color=#000080 size=1 face=Arial><b>Legal description: Lot;Block;Plan<br></font><font size=1>" + newlegal + "</font><br>")
top.query.document.writeln ("<font color=#000080 size=1 face=Arial>Please contact the City at 529-8111 or <a href=mailto:customer_accounts@medicinehat.ca>Email us</a> for legal information for this address.</font><br>")
top.query.document.writeln ("<font color=#000080 size=1 face=Arial><b>Land Use District: </font><font size=1>" + landuse + "</font>")
top.query.document.writeln ("</body>")
top.query.document.writeln ("</html>")
top.query.document.close()
}

function writelotinfo(price,size) {
var plen = price.length
if (plen > 3) {
   var kstart = price.substr(plen-3,3)
   var kpos = price.substr(0, plen-3)
   var price = kpos + "," + kstart
   }
var slen = size.length - 7
if (slen > 3) {
   var kpart = size.substr(0, slen - 2)
   var part2 = size.substr(slen-2)
   var size = kpart + "," + part2
   }   

top.query.document.open()
top.query.document.writeln ("<html>")
top.query.document.writeln ("<head>")
top.query.document.writeln ("<meta http-equiv=Content-Type content=text/html; charset=windows-1252>")
top.query.document.writeln ("<title>Query</title>")
top.query.document.writeln ("</head>")
top.query.document.writeln ("<body background=/cityimap/background.jpg>")
top.query.document.writeln ("<font color=#000080 size=1 face=Arial><b>Lot Price: <br></font><font size=2 color=#FF0000>" + "$" + price + "</font><br>")
top.query.document.writeln ("<font color=#000080 size=1 face=Arial><b>Lot Size: </font><font size=2 color=#FF0000>" + size + "</font>")
top.query.document.writeln ("</body>")
top.query.document.writeln ("</html>")
top.query.document.close()
}

function clearquery() {
top.query.document.open()
top.query.document.writeln ("<html>")
top.query.document.writeln ("<head>")
top.query.document.writeln ("<meta http-equiv=Content-Type content=text/html; charset=windows-1252>")
top.query.document.writeln ("<title>Query</title>")
top.query.document.writeln ("</head>")
top.query.document.writeln ("<body background=/cityimap/background.jpg>")
top.query.document.writeln ("</body>")
top.query.document.writeln ("</html>")
top.query.document.close()
}

function getmapoption() {
  document.forms[0].mapoption.value=window.opener.parent.frames["map"].document.forms[0].mapoption.value
}

function validate(obj, lowval, hival) {
if (obj.value == '') {
   return false;
   }
else if ((obj.value < lowval) || (obj.value > hival)) {
   alert("Invalid Value!")
   obj.value=""
   return false;
   }
else {
   if (isNaN(obj.value)) {
      alert('Please input number.');
      obj.value="";
      return false; 
   }
   else
      return true;
   }
}

function validateform() {
  var stnameInteger,houseno, streetname
  stnameInteger=document.forms[0].streetname.selectedIndex   
  streetname=document.forms[0].streetname.options[stnameInteger].text
  var houseno = document.forms[0].houseno.value
//  var streetname = document.forms[0].streetname.value
  if ((houseno < 1) || (houseno > 99999)) {
     alert('Please input house number');
     showmessage('');
     }
  else {
     if (streetname == "") {
        alert('Please input street name.');
        showmessage('');
        }
     else {
        if (streetname.length < 1) {
           alert('Please input street name.');
           showmessage('');
           }
        else
           top.address.document.forms[0].submit();
          }
       }
}

function printmap() {
   var imgsrc=top.map.document.forms[0].mapimgsrc.value
   var mapwin = window.open("", "printwin", "width=550,height=460,center=yes,scrollbars=yes,menubar=yes,resizable=yes,toolbar=yes,statusbar=yes");
   var mapwindoc = mapwin.document ;
   mapwindoc.open()   
   mapwindoc.writeln ("<html>")
   mapwindoc.writeln ("<head>")
   mapwindoc.writeln ("<meta http-equiv=Content-Type content=text/html; charset=windows-1252>")
   mapwindoc.writeln ("<title>City of Medicine Hat i-Map</title>")
   mapwindoc.writeln ("</head>")
   mapwindoc.writeln ("<body background=/cityimap/background.jpg>")
 
   mapwindoc.writeln ("<table border=0 width=477 height=255>")
   mapwindoc.writeln ("<tr>")
   mapwindoc.writeln ("<td width=313 height=29><font face=Arial size=2 color=#000080><b>City of Medicine Hat i-Map</b></font></td>")
   mapwindoc.writeln ("<td width=306 height=29 colspan=2>")
   mapwindoc.writeln ("<p align=center>")
   mapwindoc.writeln ("<img border=0 src=/cityimap/gislogo.jpg width=106 height=67></p></td>")
   mapwindoc.writeln ("</tr>")

   mapwindoc.writeln ("<tr>")
   mapwindoc.writeln ("<td width=478 height=41 rowspan=3>")
   mapwindoc.writeln ("<p align=center><img src=" + imgsrc + " border=1></p></td>")
   mapwindoc.writeln ("<td width=212 height=14><img src=/cityimap/foundaddress.jpg width=53 height=38 border=1></td>")
   mapwindoc.writeln ("<td width=226 height=14><font size=1 color=#000080>Found Address</font></td>")
   mapwindoc.writeln ("</tr>")

   mapwindoc.writeln ("<tr>")
   mapwindoc.writeln ("<td width=212 height=14><img src=/cityimap/fromaddress.jpg width=53 height=38 border=1></td>")
   mapwindoc.writeln ("<td width=226 height=14><font size=1 color=#000080>From Address</font></td>")
   mapwindoc.writeln ("</tr>")

   mapwindoc.writeln ("<tr>")
   mapwindoc.writeln ("<td width=212 height=13><img src=/cityimap/toaddress.jpg width=53 height=38 border=1></td>")
   mapwindoc.writeln ("<td width=226 height=13><font size=1 color=#000080>To Address</font></td>")
   mapwindoc.writeln ("</tr>")

   mapwindoc.writeln ("<tr>")
   mapwindoc.writeln ("<td width=302 height=49>")
   mapwindoc.writeln ("<font size=1>Disclaimer: Map content subject to change without notification. Please contact the City for further information.</font><br>")
   mapwindoc.writeln ("<font size=1>Please <a href=mailto:gis@medicinehat.ca>send e-mail</a>, or</font>")
   mapwindoc.writeln ("<font size=1>phone GIS data coordinator: (403) 529-8101</font><br>")
   mapwindoc.writeln ("</td>")
   mapwindoc.writeln ("<td width=210 height=49 colspan=2>")
   mapwindoc.writeln ("<form>")
   mapwindoc.writeln ("<p align=right>")
   mapwindoc.writeln ("<input type=button value='Print Map' name=print onclick=window.print()></p>")  
   mapwindoc.writeln ("</form>")
   mapwindoc.writeln ("</td>")
   mapwindoc.writeln ("</tr>")

   mapwindoc.writeln ("</table>")
   mapwindoc.writeln ("</body>")
   mapwindoc.writeln ("</html>")
   mapwindoc.close()
}

function LocateStreet() {  
   var separator
   var arrayvalue 
   separator = " "
   var stnameInteger, streetinfo
   if (document.forms[0].streetinfo.length > 0) {
      stnameInteger=document.forms[0].streetinfo.selectedIndex   
      streetinfo=document.forms[0].streetinfo.options[stnameInteger].text
      }
   else streetinfo = "";
   
   if (streetinfo == "") {
      alert('Please select street name');
      showmessage(''); }
   else { 
         var arrayOfStrings = streetinfo.split(separator)
         if (arrayOfStrings.length < 4) {
           self.document.forms[0].streetname.value = arrayOfStrings[0]
           self.document.forms[0].type.value = arrayOfStrings[1]
           self.document.forms[0].dir.value = arrayOfStrings[2]
           }
         else {
           var stnam
           var init = 0
           for (var i=0; i < arrayOfStrings.length - 2; i++) {
               if (init == 0) {
                  stnam = arrayOfStrings[i]
                  init = init + 1
                  }
               else {
                  stnam = stnam + " " + arrayOfStrings[i] }
           }
           var l = arrayOfStrings.length
           self.document.forms[0].streetname.value = stnam.replace(/&/gi,"_")
           self.document.forms[0].type.value = arrayOfStrings[l - 2]
           self.document.forms[0].dir.value = arrayOfStrings[l - 1]
         }

         self.document.forms[0].action="/servlet/com.esri.esrimap.Esrimap"
         self.document.forms[0].target="map"
         self.document.forms[0].submit();
	 var wo 
	 wo = window.opener
	 if (wo != null)  {
            tmpwin = window.open()
            tmpwin.close()
            close(); }
  }
}

function GetStreetArray() {  
   var separator
   var arrayvalue 
   separator = " "
   var stnameInteger,houseno, streetinfo
   if (document.forms[0].streetinfo.length > 0) {
      stnameInteger=document.forms[0].streetinfo.selectedIndex   
      streetinfo=document.forms[0].streetinfo.options[stnameInteger].text
      }
   else {
      streetinfo = ""
      }
   var houseno = document.forms[0].houseno.value
   if ((houseno < 1) || (houseno > 99999)) {
      alert('Please input house number');
      showmessage('');
      }
   else { 
         var arrayOfStrings = streetinfo.split(separator)
         if (arrayOfStrings.length < 4) {
           self.document.forms[0].streetname.value = arrayOfStrings[0]
           self.document.forms[0].type.value = arrayOfStrings[1]
           self.document.forms[0].dir.value = arrayOfStrings[2]
           }
         else {
           var stnam
           var init = 0
           for (var i=0; i < arrayOfStrings.length - 2; i++) {
               if (init == 0) {
                  stnam = arrayOfStrings[i]
                  init = init + 1
                  }
               else {
                  stnam = stnam + " " + arrayOfStrings[i] }
               }
           var l = arrayOfStrings.length
 //           top.address.document.forms[0].streetname.value = stnam
            self.document.forms[0].streetname.value = stnam.replace(/&/gi,"_")
            self.document.forms[0].type.value = arrayOfStrings[l - 2]
            self.document.forms[0].dir.value = arrayOfStrings[l - 1]
            }
            self.document.forms[0].action="/servlet/com.esri.esrimap.Esrimap"
            self.document.forms[0].target="map"
            self.document.forms[0].submit();
	    var wo 
	    wo = window.opener
	    if (wo != null)  {
               tmpwin = window.open()
               tmpwin.close()
               close(); 
               }
      }
}

function GetNoMapStreetArray() {
   var separator
   var arrayvalue 
   separator = " "
   var stnameInteger,houseno, streetinfo
   if (document.forms[0].streetinfo.length > 0) {
      stnameInteger=document.forms[0].streetinfo.selectedIndex   
      streetinfo=document.forms[0].streetinfo.options[stnameInteger].text
      }
   else {
      streetinfo = ""
      }
   var houseno = document.forms[0].houseno.value
   if ((houseno < 1) || (houseno > 99999)) {
      alert('Please input house number');
      showmessage('');
      }
   else {
       var arrayOfStrings = streetinfo.split(separator)
       if (arrayOfStrings.length < 4) {
          self.document.forms[0].streetname.value = arrayOfStrings[0]
          self.document.forms[0].type.value = arrayOfStrings[1]
          self.document.forms[0].dir.value = arrayOfStrings[2]
          }
       else {
          var stnam
          var init = 0
              for (var i=0; i < arrayOfStrings.length - 2; i++) {
                  if (init == 0) {
                     stnam = arrayOfStrings[i];
                     init = init + 1;
                     }
                  else stnam = stnam + " " + arrayOfStrings[i];
              }
          var l = arrayOfStrings.length;
       self.document.forms[0].streetname.value = stnam.replace(/&/gi,"_")
       self.document.forms[0].type.value = arrayOfStrings[l - 2]
       self.document.forms[0].dir.value = arrayOfStrings[l - 1]
       }
       self.document.forms[0].action="/servlet/com.esri.esrimap.Esrimap"
       self.document.forms[0].submit();
       }
}


// *************** Scripts for zoombox zooming in ******************************* //
		var zoomBoxColor = "#FF0000";	// color of zoombox
	//	var iWidth = 402; 	// image width
	//	var iHeight = 294;	// image height
	
       var initMapLeft = 13449 // 14535
       var initMapRight = 31060 // 29974
       var initMapTop = 5550964
       var initMapBottom = 5536616
       var initMapWidth = initMapRight - initMapLeft
       var initMapHeight = initMapTop - initMapBottom
       
		var hspc = 0; 		// horizontal image offset
		var vspc = 0; 		// vertical image offset
		var ovBoxSize = 2; 	// Zoombox line width;
				
		
		// Global vars to save mouse position
		var mouseX=0;
		var mouseY=0;
		var x1=0;
		var y1=0;
		var x2=0;
		var y2=0;
		var zleft=0;
		var zright=0;
		var ztop=0;
		var zbottom=0;

		var MapX1=0;
		var MapY1=0;
		var MapX2=0;
		var MapY2=0;
		var iWidth     // map frame width
		var iHeight    // map frame height
		var ImageMapXUnit
		var ImageMapYUnit

		
		// Global vars for browser type and version
		var isNav = (navigator.appName.indexOf("Netscape")>=0);
		var isNav4 = false;
		var isIE4 = false;
		var is5up = false;
		//alert(navigator.appVersion);
		if (isNav) {
			if (parseFloat(navigator.appVersion)<5) {
				isNav4=true;
				//alert("Netscape 4.x or older");
			} else {
				is5up = true;
			}
		} else {
			isIE4=true;
			if (navigator.appVersion.indexOf("MSIE 5")>0) {
				isIE4 = false;
				is5up = true;
			}
		}
		
		
		function startUp() {
			if (isNav) {
				document.captureEvents(Event.MOUSEDOWN | Event.MOUSEMOVE | Event.MOUSEUP);
			}
			document.onmousedown = mapTool;
			document.onmouseup = chkMouseUp;
			document.onmousemove = getMouse;

                        var onepage = "";
                        if (self.document.forms[0] != null) {
                           if (self.document.forms[0].onepage != null) var onepage = self.document.forms[0].onepage.value;
                           }
                        else {
                           if (top.map != null) {
                              if (top.map.document.forms[0].onepage != null) var onepage = top.map.document.forms[0].onepage.value;
                           }
                        }

                        if (onepage=='TRUE') {
                           iWidth = 600
                           iHeight = 465
                           }
                        else {
                           iWidth = getMapWidth();
                           iHeight = getMapHeight();
                           }

		 	ImageMapXUnit = (initMapWidth / iWidth)
			ImageMapYUnit = (initMapHeight / iHeight)
		}

			
		/*
		***************************************************************************************
		

		DHTML layer functions - used to create and manipulate style sheets
			These functions are used by the ArcIMS HTML Viewer - found in aimsDHTML.js
		
		***************************************************************************************
		*/

		// get the Map Image width
		function getMapWidth () {
		var mapFrameWidth = thePageWin.innerWidth;
		if (mapFrameWidth == null) {
			mapFrameWidth = thePageDoc.body.clientWidth;
		}
		return mapFrameWidth;
		}

		// get the Map Image height
		function getMapHeight () {
		var mapFrameHeight = thePageWin.innerHeight;
		
		if (mapFrameHeight == null) {
			mapFrameHeight = thePageDoc.body.clientHeight;
		}
		return mapFrameHeight;
		}
	
		// Create a DHTML layer
		function createLayer(name, inleft, intop, width, height, visible, content) {
			  var layer;
			  if (isNav4) {
			    document.writeln('<layer name="' + name + '" left=' + inleft + ' top=' + intop + ' width=' + width + ' height=' + height +  ' visibility=' + (visible ? '"show"' : '"hide"') +  '>');
			    document.writeln(content);
			    document.writeln('</layer>');
			  } else {
			    document.writeln('<div id="' + name + '" style="position:absolute; overflow:hidden; left:' + inleft + 'px; top:' + intop + 'px; width:' + width + 'px; height:' + height + 'px;' + '; z-index:1; visibility:' + (visible ? 'visible;' : 'hidden;') +  '">');
			    document.writeln(content);
			    document.writeln('</div>');
			  }
		}
		
		// get the layer object called "name"
		function getLayer(name) {
			  if (isNav4) {
				 if (document.layers[name] == null) {
				    if (top.map !=null) {
                                       if (top.map.document.layers[name]!=null) return(top.map.document.layers[name]); }
                                    else if (window.opener !=null) {
                                       if (window.opener.parent.frames["map"].document.layers[name]!=null) return(window.opener.parent.frames["map"].document.layers[name]); }
                                    }
				 else {
                                    return(document.layers[name]);}
                             }
			  else if (isIE4) {
  			        if (eval('document.all.' + name) == null)
				   { if (top.map != null) {
				        if (eval('top.map.document.all.'+name !=null)) {
				           layer = eval('top.map.document.all.'+name+'.style');
				           }
				        }
				     else if (window.opener != null) {
                                       if (eval('window.opener.parent.frames["map"].document.all.' + name) != null) {
                                          layer = eval('window.opener.parent.frames["map"].document.all.' + name + '.style')
                                           }
                                     }
                                   }
                                else layer = eval('document.all.' + name + '.style');
                                
			        return(layer);
			  } else if (is5up) {
				var theObj = document.getElementById(name);
				return theObj.style
			  }
			  else
			    return(null);
		}
				
		function isVisible(name) {
			  var layer = getLayer(name);
			  if (isNav && layer.visibility == "show")
			    return(true);
			  if (isIE && layer.visibility == "visible")
			    return(true);
			  return(false);
		}
		
		
		// move layer to x,y
		function moveLayer(name, x, y) {		
		  	var layer = getLayer(name);		
		  	if (isNav4)
		    	layer.moveTo(x, y);
		  	//if (document.all) {
			 else {
		    	layer.left = x + "px";
		   		 layer.top  = y + "px";
		  	}
		}
		
		// set layer background color
		function setLayerBackgroundColor(name, color) {		
		  	var layer = getLayer(name);		
		 	 if (isNav4)
		    	layer.bgColor = color;
		  	//else if (document.all)
			else
		    	layer.backgroundColor = color;
		}
		
		// toggle layer to invisible
		function hideLayer(name) {		
		  	var layer = getLayer(name);		
		  	if (isNav4)
		    	layer.visibility = "hide";
		  	//if (document.all)
			else
		   		 layer.visibility = "hidden";
				 //layer.display="none";
		}
		
		// toggle layer to visible
		function showLayer(name) {		
		  	var layer = getLayer(name);
		  	if (isNav4) {
		    	   layer.visibility = "show"; }
		  	 //if (document.all)
			else
		   	   layer.visibility = "visible";
			 //layer.display="block";
		}
		
		// clip layer display to clipleft, cliptip, clipright, clipbottom
			// Not working with Mozilla Milestone 12 (Nav5)
		function clipLayer2(name, clipleft, cliptop, clipright, clipbottom) {		
			  var layer = getLayer(name);		
			  if (isNav4) {
				    layer.clip.left   = clipleft;
				    layer.clip.top    = cliptop;
				    layer.clip.right  = clipright;
				    layer.clip.bottom = clipbottom;
			  }
			  //if (document.all)
			  else if (isIE4) {
				    layer.clip = 'rect(' + cliptop + ' ' +  clipright + ' ' + clipbottom + ' ' + clipleft +')';
			  }
		}
		
		function clipLayer(name, clipleft, cliptop, clipright, clipbottom) {		
			  var layer = getLayer(name);		
			  if (isNav4) {
				    layer.clip.left   = clipleft;
				    layer.clip.top    = cliptop;
				    layer.clip.right  = clipright;
				    layer.clip.bottom = clipbottom;
			  }	  else {
					var newWidth = clipright - clipleft;
					var newHeight = clipbottom - cliptop;
					layer.height = newHeight;
					layer.width	= newWidth;
					layer.top	= cliptop + "px";
					layer.left	= clipleft + "px";
				}
		
		}

		function boxIt(theLeft,theTop,theRight,theBottom) {

                        var onepage = "";
                        if (self.document.forms[0] != null) {
                           if (self.document.forms[0].onepage != null) var onepage = self.document.forms[0].onepage.value;
                           }
                        else {
                           if (top.map != null) {
                              if (top.map.document.forms[0].onepage != null) var onepage = top.map.document.forms[0].onepage.value;
                           }
                        }


                        if (onepage=="TRUE") {
                           theLeft = theLeft + 15;
                           theRight = theRight + 15;
                           theTop = theTop + 60;
                           theBottom = theBottom + 60; }

			clipLayer("zoomBoxTop",theLeft,theTop,theRight,theTop+ovBoxSize);
			clipLayer("zoomBoxLeft",theLeft,theTop,theLeft+ovBoxSize,theBottom);
			clipLayer("zoomBoxRight",theRight-ovBoxSize,theTop,theRight,theBottom);
			clipLayer("zoomBoxBottom",theLeft,theBottom-ovBoxSize,theRight,theBottom);	
			showLayer("zoomBoxTop");
			showLayer("zoomBoxLeft");
			showLayer("zoomBoxRight");
			showLayer("zoomBoxBottom");
		}
		
	
		/*
		***************************************************************************************
		
		Navigation functions - used to resize zoom box
			Extended versions of these functions are used by the ArcIMS HTML Viewer - found in aimsNavigation.js
		
		***************************************************************************************
		*/
		
		// get cursor location
		function getImageXY(e) {
			if (isNav) {
				mouseX=e.pageX;
				mouseY=e.pageY;
			} else {
				mouseX=event.clientX + document.body.scrollLeft;
				mouseY=event.clientY + document.body.scrollTop;
			}

                        var onepage = "";
                        if (self.document.forms[0] != null) {
                           if (self.document.forms[0].onepage != null) var onepage = self.document.forms[0].onepage.value;
                           }
                        else {
                           if (top.map != null) {
                              if (top.map.document.forms[0].onepage != null) var onepage = top.map.document.forms[0].onepage.value;
                           }
                        }

 			// subtract offsets from page left and top
                       if (onepage=="TRUE") {
                            hspc = 15;
                            vspc = 60; } 
                        else {
                            hspc = 0;
                            vspc = 0; }
			mouseX = mouseX-hspc;
			mouseY = mouseY-vspc;		
		}	


		// start zoom in.... box displayed
		function startZoomBox(e) {
//			moveLayer("theMap",hspc,vspc);
			getImageXY(e);
			// keep it within the MapImage
                        if ((mouseX<iWidth) && (mouseY<iHeight)) {
				if (zooming) {
					stopZoomBox(e);
				} else {
					x1=mouseX;
					y1=mouseY;
					x2=x1+1;
					y2=y1+1;
					zleft=x1;
					ztop=y1;
					zbottom=y1;
					zright=x1
					
					boxIt(x1,y1,x2,y2);
					
					MapX1 = Math.round(initMapLeft + (x1 * ImageMapXUnit ))
					MapY1 = Math.round(initMapTop - (y1 * ImageMapYUnit ))
               
					zooming=true;
				}
			}
			return false;
			
		}

		
		// stop zoom box display... 
		function stopZoomBox(e) {
			zooming=false;
			if ((zright <zleft+2) && (zbottom < ztop+2)) {
				zoomin(e);
			}
			else {
			hideLayer("zoomBoxTop");
			hideLayer("zoomBoxLeft");
			hideLayer("zoomBoxRight");
			hideLayer("zoomBoxBottom");
			window.scrollTo(0,0);
			}			
			return true;		
		}

		// zoom in from mouse single click
		function zoomin(e) {
			var mapWidth = (initMapRight - initMapLeft) /2
			var mapHeight = (initMapTop - initMapBottom) /2
			initMapLeft = MapX1 - ( mapWidth * 0.8)
			initMapBottom = MapY1 - (mapHeight * 0.8)
			initMapRight = MapX1 + (mapWidth * 0.8)
			initMapTop = MapY1 + (mapHeight * 0.8)
			MapX1 = initMapLeft
			MapY1 = initMapBottom
			MapX2 = initMapRight
			MapY2 = initMapTop
		}	

// start zoom out... box displayed
function startZoomOutBox(e) {
//	moveLayer("theMap",hspc,vspc);
	getImageXY(e);
	// keep it within the MapImage
	if ((mouseX<iWidth) && (mouseY<iHeight)) {
		
		if (zooming) {
			stopZoomOutBox(e);
		} else {
			x1=mouseX;
			y1=mouseY;
			x2=x1+1;
			y2=y1+1;
			zleft=x1;
			ztop=y1;
			zbottom=y1;
			zright=x1
			boxIt(x1,y1,x2,y2);

			// ***** Add to specify start map coordinate for zoomoutbox ***** //
			MapX1 = Math.round(initMapLeft + (x1 * ImageMapXUnit ))
			MapY1 = Math.round(initMapTop - (y1 * ImageMapYUnit ))
 
			zooming=true;
			/*
			if (isNav4) {
				showLayer("zoomBoxTop");
				showLayer("zoomBoxLeft");
				showLayer("zoomBoxRight");
				showLayer("zoomBoxBottom");
			} else {
				showLayer("zoomBox");
			}
			*/
		}
	//} else {
	//	if (zooming) stopZoomOutBox(e);
	}
	return false;
	
}

// stop zoom out box. . . zoom out
function stopZoomOutBox(e) {
	zooming=false;
		hideLayer("zoomBoxTop");
		hideLayer("zoomBoxLeft");
		hideLayer("zoomBoxRight");
		hideLayer("zoomBoxBottom");
	if ((zright <zleft+2) && (zbottom < ztop+2)) {
		zoomout(e);
	} else {
		var origMapWidth = (initMapRight - initMapLeft)
		var origMapHeight = (initMapTop - initMapBottom)
		var xRatio = origMapWidth / (Math.abs(MapX1 - MapX2)) * 0.5
		var yRatio = origMapHeight / (Math.abs(MapY1 - MapY2)) * 0.5
	
		var oldCenterX = (initMapLeft + initMapRight) /2
		var oldCenterY = (initMapBottom + initMapTop) /2
		var NewCenterX = (MapX1 + MapX2) /2
		var NewCenterY = (MapY1 + MapY2) /2
		var CenterShiftX = NewCenterX - oldCenterX
		var CenterShiftY = NewCenterY - oldCenterY

		initMapLeft = CenterShiftX + initMapLeft - (xRatio * origMapWidth / 2) ;
		initMapRight = CenterShiftX + initMapRight + (xRatio * origMapWidth / 2);
		initMapTop = CenterShiftY + initMapTop + (yRatio * origMapHeight / 2);
		initMapBottom = CenterShiftY + initMapBottom - (yRatio * origMapHeight / 2);
		
		window.scrollTo(0,0);
	}
	return true;
}

// zoom out from mouse single click
function zoomout(e) {
	var mapWidth = (initMapRight - initMapLeft) /2
	var mapHeight = (initMapTop - initMapBottom) /2
			
	initMapLeft = MapX1 - ( mapWidth * 1.2)
	initMapBottom = MapY1 - (mapHeight * 1.2)
	initMapRight = MapX1 + (mapWidth * 1.2)
	initMapTop = MapY1 + (mapHeight * 1.2)

}	

// ****************************************************************************************************** //

		// perform appropriate action with mapTool
		function mapTool (e) {
			toolMode = 0
			var mt 
			mt = top.maptool
			if (mt == null) {
			     if (self.document.forms[0].CMD[0].checked) toolMode = 1;
			     else if (self.document.forms[0].CMD[1].checked) toolMode = 2;
			     else if (self.document.forms[0].CMD[2].checked) toolMode = 3;
			     else if (self.document.forms[0].CMD[3].checked) toolMode = 4;
                           }
			else {
			     if (top.maptool.document.forms[0].CMD[0].checked) toolMode = 1;
			     else if (top.maptool.document.forms[0].CMD[1].checked) toolMode = 2;
			     else if (top.maptool.document.forms[0].CMD[2].checked) toolMode = 3;
			     else if (top.maptool.document.forms[0].CMD[3].checked) toolMode = 4;
                             //if (!zooming) startZoomBox(e);
			     }
                        if (toolMode < 1) toolMode = 1

                        var onepage = "";
                        if (self.document.forms[0] != null) {
                           if (self.document.forms[0].onepage != null) var onepage = self.document.forms[0].onepage.value;
                           }
                        else {
                           if (top.map != null) {
                              if (top.map.document.forms[0].onepage != null) var onepage = top.map.document.forms[0].onepage.value;
                           }
                        }

			getImageXY(e)

                        if (onepage=='TRUE') { 
                           if ((mouseX < 12) || (mouseY < 62) || (mouseX > 610) || (mouseY > 525)) {
                              return;
                           }
                        }
                        
                        switch(toolMode) {
				case 1:
  	        	              if (!zooming) {
	 				  startZoomBox(e);
					  return false;
					  breaK }
				case 2:
		                      if (!zooming) {
 					startZoomOutBox(e);
					return false;
					breaK	}
				case 3:
       	                              if (!panning) {
					startPan(e);
					return false;
					break	}
				}
			   return false;
		}
		


		// get the coords at mouse position
		function getMouse(e) {

                        var onepage = "";
                        if (self.document.forms[0] != null) {
                           if (self.document.forms[0].onepage != null) var onepage = self.document.forms[0].onepage.value;
                           }
                        else {
                           if (top.map != null) {
                              if (top.map.document.forms[0].onepage != null) var onepage = top.map.document.forms[0].onepage.value;
                           }
                        }

			window.status="";
 			getImageXY(e);
			
			if ((mouseX>iWidth) || (mouseY>iHeight) || (mouseX<=0) ||(mouseY<=0)) {
                           if (zooming || panning) chkMouseUp(e);
                           }
                        else {
				if (zooming) {
					x2=mouseX;
					y2=mouseY;
					setClip();}
				else if (panning) {
					x2=mouseX;
					y2=mouseY;
					panMouse();}

        	                var MapX = Math.round(initMapLeft + (mouseX * ImageMapXUnit ));
	    			var MapY = Math.round(initMapTop - (mouseY * ImageMapYUnit ));
                        	MapX2 = Math.round(initMapLeft + (x2 * ImageMapXUnit ));
	                        MapY2 = Math.round(initMapTop - (y2 * ImageMapYUnit )); }

                                if (onepage=='TRUE') { 
                                   if ((mouseX <= 0) || (mouseY <= 0) || (mouseX >= 600) || (mouseY >= 465)) {
                                      return;
                                      }
                                }

       	                var mouseString = "";
                        if (zooming) mouseString += " ZoomBox: [" + MapX1 + "," + MapY1 + " x " + MapX2 + "," + MapY2 + "] ";
                        mouseString += "Map Coords: " + MapX + " , " + MapY;                           
                        window.status = mouseString;

//                      if (zooming) mouseString += " ZoomBox: [" + x1 + "," + y1 + " x " + x2 + "," + y2 + "]";
//			mouseString += "Coords: " + mouseX + " , " + mouseY;			  
			// next line needed for Mac
			return false;

		}
		
		// clip zoom box layer to mouse coords
		function setClip() {	
			var tempX=x1;
			var tempY=y1;
			if (x1>x2) {
				zright=x1;
				zleft=x2;
			} else {
				zleft=x1;
				zright=x2;
			}
			if (y1>y2) {
				zbottom=y1;
				ztop=y2;
			} else {
				ztop=y1;
				zbottom=y2;
			}
			
			if ((x1 != x2) && (y1 != y2)) {
				boxIt(zleft,ztop,zright,zbottom);
			}
			return false;
		}

		/*
		***************************************************************************************
		
		Click/Mouse functions - used to catch mouse button events
			Extended versions of these functions are used by the ArcIMS HTML Viewer - found in aimsClick.js
		
		***************************************************************************************
		*/

		// check for mouseup
		function chkMouseUp(e) { 
//			if ((mouseX>iWidth) || (mouseY>iHeight) || (mouseX<=0) ||(mouseY<=0)) {
//			   return false }
			// 
			if ((toolMode == 1) && (zooming)) {
				stopZoomBox(e);
				var LeftX
				var RightX
				if (MapX1 > MapX2) {
					LeftX = MapX2;
					RightX = MapX1; }
				else {
					LeftX = MapX1;
					RightX = MapX2; }
				var TopY
				var BottomY
				if (MapY1 > MapY2) {
					TopY= MapY1;
					BottomY = MapY2; }
				else {
					TopY = MapY2;
					BottomY = MapY1; }
				window.document.map.LEFT.value = LeftX;
				window.document.map.RIGHT.value = RightX;
				window.document.map.BOTTOM.value = BottomY;
				window.document.map.TOP.value = TopY;
				window.document.map.submit();
                                showRetrieveMap();}
			if ((toolMode == 2) && (zooming)) {
				stopZoomOutBox(e);
				if (initMapLeft != null) window.document.map.LEFT.value = initMapLeft;
				if (initMapRight != null) window.document.map.RIGHT.value = initMapRight;
				if (initMapBottom != null) window.document.map.BOTTOM.value = initMapBottom;
				if (initMapTop != null) window.document.map.TOP.value = initMapTop;
				window.document.map.submit();
                                showRetrieveMap();}
			if ((toolMode == 3) && (panning)) {
			     stopPan(e);
                             if (initMapLeft != null) window.document.map.LEFT.value = initMapLeft;
		             if (initMapRight != null) window.document.map.RIGHT.value = initMapRight;
		             if (initMapBottom != null) window.document.map.BOTTOM.value = initMapBottom;
		             if (initMapTop != null) window.document.map.TOP.value = initMapTop;
				window.document.map.submit();
                                showRetrieveMap();}
			if (toolMode == 4) {
 				getImageXY(e);
				if ((mouseX>iWidth) || (mouseY>iHeight) || (mouseX<=0) ||(mouseY<=0)) {
 					return false;		
				} else {
	     			var MapX = Math.round(initMapLeft + (mouseX * ImageMapXUnit ))
	    			var MapY = Math.round(initMapTop - (mouseY * ImageMapYUnit ))
				window.document.map.selectx.value = MapX
				window.document.map.selecty.value = MapY
				window.document.map.submit();
                                showRetrieveMap();}
			}


                        showmessage('Refreshing map, please wait...');
			// next line needed for Mac
			return false;
			
		}

		function setmaptool(settool) {
		  var mt 
		  mt = top.map
		  if (mt == null) {
                      self.document.forms[0].CMD.value=settool;
                      self.document.forms[0].mapoption.value = settool;                  
                     }
                  else {
		      top.map.document.forms[0].CMD.value=settool;
                      top.map.document.forms[0].mapoption.value = settool;
                     }
		  var i;
		  if (settool=='zoomin') {
		     toolMode = 1;
		     i = 0; 
		     if (!isNav4) top.map.document.forms[0].theImage.alt="Single click or drag a box to zoom in" 
                     else top.map.document.layers[0].document.images.alt="Single click or drag a box to zoom in"}
		  if (settool=='zoomout') {
		     toolMode = 2;
		     i = 1;
		     if (!isNav4) top.map.document.forms[0].theImage.alt="Single click or drag a box to zoom out"
                     else top.map.document.layers[0].document.images.alt="Single click or drag a box to zoom out"}

		  if (settool=='pan') {
		     toolMode = 3;
		     i = 2;
		     if (!isNav4) top.map.document.forms[0].theImage.alt="Drag the map to pan around"
                     else top.map.document.layers[0].document.images.alt="Drag the map to pan around"}
		  if (settool=='select') {
		     toolMode = 4;
		     i = 3;
		     if (!isNav4) top.map.document.forms[0].theImage.alt="Single click on the map to select"
                     else top.map.document.layers[0].document.images.alt="Single click on the map to select"}
		  if (settool=='identify') {
		     toolMode = 4;
		     i = 3;
		     if (!isNav4) top.map.document.forms[0].theImage.alt="Single click on the map to select"
                     else top.map.document.layers[0].document.images.alt="Single click on the map to select"}
		  document.forms[0].CMD[i].checked=true;
 		}

// start pan.... image will move
function startPan(e) {
//	moveLayer("theMap",hspc,vspc);

	getImageXY(e);
	// keep it within the MapImage
	if ((mouseX<iWidth) && (mouseY<iHeight)) {
  		if (panning) {
			stopPan(e);
		} else {
			x1=mouseX;
			y1=mouseY;
			x2=x1+1;
			y2=y1+1;
			panning=true;
		}
	}
	return false;

}

// move map image with mouse
function panMouse() {
	var xMove = x2-x1;
	var yMove = y2-y1;
	var cLeft = -xMove;
	var cTop = -yMove;
	var cRight = iWidth;
	var cBottom = iHeight;
	if (xMove>0) {
		cLeft = 0;
		cRight = iWidth - xMove;
	}
	if (yMove>0) {
		cTop = 0;
		cBottom = iHeight - yMove;
	}
	clipLayer2("theMap",cLeft,cTop,cRight,cBottom);
	moveLayer("theMap",xMove+hspc,yMove+vspc);
	if (hasLayer("theMapClicks")) {
		clipLayer2("theMapClicks",cLeft,cTop,cRight,cBottom);
		moveLayer("theMapClicks",xMove+hspc,yMove+vspc);

	}
	//return false;
}

// stop moving image.... pan 
function stopPan(e) {
	window.scrollTo(0,0);
	panning=false;
        var tempLeft = initMapLeft
        var tempRight =  initMapRight
        var tempTop = initMapTop
        var tempBottom = initMapBottom

	//saveLastExtent();
	var ixOffset = x1 - x2 ;
	var iyOffset = y2 - y1 ;
//	pixelX = xDistance / iWidth;
//	var theY = iHeight - ztop;
//	pixelY = yDistance / iHeight;
//	var xOffset = pixelX * ixOffset;
//	var yOffset = pixelY * iyOffset;
        var xoffset = ImageMapXUnit * ixOffset;
        var yoffset = ImageMapYUnit * iyOffset;
	initMapRight = tempRight + xoffset;
	initMapBottom = tempBottom + yoffset;
	initMapLeft = tempLeft + xoffset;
	initMapTop = tempTop + yoffset;
	hideLayer("theMap");
	if (hasLayer("theMapClicks")) {
		document.theClickImage.src = blankImage;
	}
	return true;
	
}

// check for existance of layer
function hasLayer(name) {
	var result = false;
	if (isNav4) {
	   if (document.layers[name]!=null) result=true;
           if (result != true) {
              if (top.map != null) {
                 if (top.map.document.layers[name] != null) result=true; }
              else if (window.opener != null) {
                 if (window.opener.parent.frames["map"].document.layers[name] != null) result=true; }
           }
	} else if (isIE4) {
           if (eval('document.all.' + name)!=null) result=true;
		   if (result != true)
		   { if (top.map != null)
		     { if (eval('top.map.document.all.' + name) !=null) result=true; }
	             else {
                          var wo
                          wo = window.opener
                          if (wo !=null ) {
                             if (eval('wo.parent.frames["map"].document.all.'+name) != null) result = true;
                             }
                          }
		   }
    } else if (isNav) {
		var theElements = document.getElementsByTagName("DIV");
		var theObj;
		var j = -1;
		for (i=0;i<theElements.length;i++) {
			if (theElements[i].id==name) result=true;
		}
    }
	return result;
}

function SetMapBorder(left,bottom,right,top) {
   if (left == null) left = 13449
   if (bottom == null) bottom = 5536616
   if (right == null) right = 31060
   if (top == null) top = 5550964

   initMapLeft = left
   initMapRight =  right
   initMapTop = top
   initMapBottom = bottom

   initMapWidth = initMapRight - initMapLeft
   initMapHeight = initMapTop - initMapBottom

   ImageMapXUnit = (initMapWidth / iWidth)
   ImageMapYUnit = (initMapHeight / iHeight)
}


function FillMapContent(imgsrc) {
	var content
	// "glass" top layer
	content = '<img name="pixel" src="pixel.gif" width=1 height=1>';
	createLayer("theTop",-1,-1,(iWidth+1),(iHeight+1),true,content);

	// map image
	content = '<img name="theImage" src=' + imgsrc + ' hspace=0 vspace=0 border=1 style="cursor:crosshair">';
 	createLayer("theMap",0,0,(iWidth+2),(iHeight+2),true,content);

	this.document.forms[0].LEFT.value = initMapLeft
        this.document.forms[0].BOTTOM.value = initMapBottom
        this.document.forms[0].RIGHT.value = initMapRight
        this.document.forms[0].TOP.value = initMapTop
	var mWidth = getMapWidth();
	var mHeight = getMapHeight();
        this.document.forms[0].framewidth.value = mWidth
        this.document.forms[0].frameheight.value = mHeight

	// zoom/selection box
	content = '<img name="zoomImageTop" src="images/pixel.gif" width=1 height=1>';
	createLayer("zoomBoxTop",0,0,iWidth,iHeight,false,content);
	content = '<img name="zoomImageLeft" src="images/pixel.gif" width=1 height=1>';
	createLayer("zoomBoxLeft",0,0,iWidth,iHeight,false,content);
	content = '<img name="zoomImageRight" src="images/pixel.gif" width=1 height=1>';
	createLayer("zoomBoxRight",0,0,iWidth,iHeight,false,content);
	content = '<img name="zoomImageBottom" src="images/pixel.gif" width=1 height=1>';
	createLayer("zoomBoxBottom",0,0,iWidth,iHeight,false,content);

	// set zoom box color
	setLayerBackgroundColor("zoomBoxTop", zoomBoxColor);
	setLayerBackgroundColor("zoomBoxLeft", zoomBoxColor);
	setLayerBackgroundColor("zoomBoxRight", zoomBoxColor);
	setLayerBackgroundColor("zoomBoxBottom", zoomBoxColor);

 	content = '<img name="loading" border="1" src="/cityimap/webimages/loading.gif">';
        var tmpWidth = mWidth/2 - 60;
        var tmpHeight = mHeight/2 - 12;
	createLayer("Loading",tmpWidth,tmpHeight,mWidth,mHeight,false,content);

}


function InsertMap(imgsrc) {
	this.document.forms[0].LEFT.value = initMapLeft
        this.document.forms[0].BOTTOM.value = initMapBottom
        this.document.forms[0].RIGHT.value = initMapRight
        this.document.forms[0].TOP.value = initMapTop
	
	iWidth = 600;
	iHeight = 465;
        this.document.forms[0].framewidth.value = iWidth;
        this.document.forms[0].frameheight.value = iHeight;

	var content
	// "glass" top layer
	content = '<img name="pixel" src="pixel.gif" width=1 height=1>';
	createLayer("theTop",12,60,(iWidth),(iHeight),true,content);

	// map image
	content = '<img name="theImage" src=' + imgsrc + ' hspace=0 vspace=0 border=1 style="cursor:crosshair">';
 	createLayer("theMap",12,60,(iWidth),(iHeight),true,content);

	// zoom/selection box
	content = '<img name="zoomImageTop" src="images/pixel.gif" width=1 height=1>';
	createLayer("zoomBoxTop",12,60,iWidth,iHeight,false,content);
	content = '<img name="zoomImageLeft" src="images/pixel.gif" width=1 height=1>';
	createLayer("zoomBoxLeft",12,60,iWidth,iHeight,false,content);
	content = '<img name="zoomImageRight" src="images/pixel.gif" width=1 height=1>';
	createLayer("zoomBoxRight",12,60,iWidth,iHeight,false,content);
	content = '<img name="zoomImageBottom" src="images/pixel.gif" width=1 height=1>';
	createLayer("zoomBoxBottom",12,60,iWidth,iHeight,false,content);

	// loading splashs
 	content = '<img name="loading" border="1" src="/cityimap/webimages/loadmap.gif">';
   	createLayer("Loading",iWidth/2-60,iHeight/2-12,iWidth,iHeight,false,content);

	// set zoom box color
	setLayerBackgroundColor("zoomBoxTop", zoomBoxColor);
	setLayerBackgroundColor("zoomBoxLeft", zoomBoxColor);
	setLayerBackgroundColor("zoomBoxRight", zoomBoxColor);
	setLayerBackgroundColor("zoomBoxBottom", zoomBoxColor);
}


// put up the "RetriveMap" image
function showRetrieveMap() {
	if (hasLayer("Loading")) {
		showLayer("Loading");
	}
}

// hide the "RetriveMap" image
function hideRetrieveMap() {
	if (hasLayer("Loading")) {
		hideLayer("Loading");
	}
}