var Loaded = false;
var SessionId = Math.floor(Math.random()*100000000);
var MapScript, MapPath;
var MapWidth, MapHeight;
var State="Zoom";
var Hint;
var timeId = 0;
var InfoWindow, LocateWindow, GotoWindow, OrientationWindow, EnlargeWindow, PrintWindow;

/*if(document.all) {
    var bg='IEloadingbg';
  }else {
    var bg='loadingbg';
  }*/

function LocateFeature(View, Display, Key, Scale, Tag)
{
  Query="";
  if (View) Query+="&view="+View;
  Query+="&display="+Display;
  Query+="&Key="+Key;
  if (Scale>0) Query+="&scale="+Scale;
  if (Tag) Query="Action=tag"+Query
  else Query="Action=locate"+Query;
  //if (KeepTags) Query+="&keeptags=yes";
  SetQuery(Query);
}

function GetFeatureAt(x, y)
{
  var request = window.XMLHttpRequest ? new XMLHttpRequest() : new ActiveXObject("MSXML2.XMLHTTP.3.0");
  request.open("GET", MapScript+MapPath+"?xml&clickX="+x+"&clickY="+y+"&width="+MapWidth+"&height="+MapHeight+"&sessionid="+SessionId+"&time="+d.getTime(), false);
  request.send(null);
  str = new String(request.responseText);
  lines=request.responseText.split('\r\n');
  vals=lines[0].split('\t');
  this.Key=vals[0];
  this.FeatureClass=vals[1];
}

function SetSrc(id, url)
{
  if (Loaded)
  {
    elem=document.getElementById(id+"img");
    if (elem) elem.src = url;
  }
}

function MapLoading()
{
  document.getElementById('LoadingDiv').style.visibility='visible';
}

function MapLoaded()
{
  document.getElementById('LoadingDiv').style.visibility='hidden';
}

function SetQuery(Query)
{
  MapLoading();
  d=new Date();
  SetSrc("MapArea", MapScript+MapPath+"?"+Query+"&width="+MapWidth+"&height="+MapHeight+"&sessionid="+SessionId+"&time="+d.getTime());
}

function SetAlt(id, alt)
{
  if (Loaded)
    document.getElementById(id + "img").title = alt;
}

function SetState(S)
{
  if (Loaded)
  {
    State=S;
    SetSrc("Info", (State=="Info")?"/mapicons/info_2.gif":"/mapicons/info_0.gif");
    SetSrc("Zoom", (State=="Zoom")?"/mapicons/zoom_2.gif":"/mapicons/zoom_0.gif");
    SetSrc("Pan", (State=="Pan")?"/mapicons/pan_2.gif":"/mapicons/pan_0.gif");
    if (State=="Info") SetHint('Click on the map to get information about an object', true)
    else if ((State=="Zoom") || (State=="Zoom")) SetHint('Click on the map to zoom in; drag to zoom to area; right-click to zoom out', true)
    else if ((State=="Capture")) SetHint('Click on the map to capture a point.', true)
    else if (State=="Pan") SetHint('Click on the map to center that position', true);
  }
}

function SetHint(Text, Permanent)
{
  if (Loaded)
  {
    if (timeId>0) clearTimeout(timeId);
    timeId=0;
    document.getElementById('hint').innerHTML=Text;
    if (Permanent)
    {
      Hint=Text;
      //SetAlt("MapArea", Text);
    }
    window.status=Text;
  }
}

function RestoreHint()
{
  if (Loaded)
  {
    if (timeId==0) timeId=setTimeout("SetHint('"+Hint+"')", 50);
  }
}

function PreloadImg(URL)
{
  img = new Image();
  img.src = URL;
}

function CreateButton(ID, NormalURL, HighlightURL, ClickedURL, Width, Height, Alt, X, Y, onClick)
{
  PreloadImg(NormalURL);
  PreloadImg(HighlightURL);
  PreloadImg(ClickedURL);
  return '<STYLE TYPE="text/css">'+
    '#'+ID+' {'+
      'position:absolute;'+
      'left:'+X+'px;'+
      'top:'+Y+'px;'+
      'width:'+Width+'px;'+
      'height:'+Height+'px;'+
      'z-index:3'+
    '}'+
    '</STYLE>'+
    '<DIV ID="'+ID+'">'+
    '<A HREF="javascript:'+
    ((ClickedURL)?"SetSrc('"+ID+"','"+ClickedURL+"');":"")+
    onClick+'"'+
    ((HighlightURL)?
      ' onMouseOver="SetHint('+"'"+Alt+"', false); "+'if (State!='+"'"+ID+"') "+"SetSrc('"+ID+"','"+HighlightURL+"')"+'"'+
      ' onMouseOut="RestoreHint(); if (State!='+"'"+ID+"') "+"SetSrc('"+ID+"','"+NormalURL+"')"+'"':'')+
    '>'+
    '<IMG NAME="'+ID+'img" ID="'+ID+'img" SRC="'+((State==ID)?ClickedURL:NormalURL)+'" TITLE="'+Alt+
    '" BORDER="0" HEIGHT="'+Height+'" WIDTH="'+Width+'">'+
    '</A></DIV>';
}

function CreateMapImage(ID, X, Y, Width, Height, URL)
{
  return '<STYLE TYPE="text/css">'+
    '#'+ID+' {'+
      'position:absolute;'+
      'left:'+(X-1)+'px;'+
      'top:'+(Y-1)+'px;'+
      'width:'+(Width+2)+'px;'+
      'height:'+(Height+2)+'px;'+
      'cursor:pointer;'+
      'z-index:1'+
    '}'+
    '</STYLE>'+
    '<DIV ID="'+ID+'">'+
    '<IMG NAME="'+ID+'img" ID="'+ID+'img" SRC="'+URL+
    '" BORDER="1" HEIGHT="'+Height+'" WIDTH="'+Width+'" STYLE="z-index:1;cursor:pointer;" oncontextmenu="return false;" onload="MapLoaded();">'+
    '</DIV>'+
    '<DIV style="position:absolute;'+
      'left:'+(X+(Width-32)/2)+'px;'+
      'top:'+(Y+(Height-32)/2)+'px;'+
      'width:32px;'+
      'height:32px;'+
      'cursor:pointer;'+
      'z-index:2;" ID="LoadingDiv" oncontextmenu="return false;">'+
      '<IMG NAME="Loadingimg" ID="Loadingimg" SRC="/mapicons/ajax-loader.gif" BORDER="0" STYLE="z-index:2;cursor:pointer;" oncontextmenu="return false;">'+
    '</DIV>'+
    '<DIV style="position:absolute;'+
      'left:'+(X)+'px;'+
      'top:'+(Y)+'px;'+
      'width:'+Width+'px;'+
      'height:'+Height+'px;'+
      'cursor:pointer;'+
      'z-index:3;" ID="MarqueeDiv" oncontextmenu="return false;">'+
    '</DIV>';
}

function CreateMapSWF(ID, X, Y, Width, Height, URL)
{
  return '<STYLE TYPE="text/css">'+
    '#'+ID+' {'+
      'position:absolute;'+
      'left:'+X+';'+
      'top:'+Y+';'+
      'width:'+Width+';'+
      'height:'+Height+';'+
      'cursor:pointer;'+
      'z-index:1'+
    '}'+
    '</STYLE>'+
    '<DIV ID="'+ID+'">'+
    '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0" width="'+Width+'" height="'+Height+'">'+
    '  <param name="movie" value="'+URL+'" />'+
    '  <param name="quality" value="high" />'+
    '  <embed src="'+URL+'" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="'+Width+'" height="'+Height+'"></embed>'+
    '</object>'+
    '</DIV>';
}

function CreateHint(ID, X, Y, Width, Height, Text)
{
  Hint=Text;
  return '<STYLE TYPE="text/css">'+
    '#'+ID+' {'+
      'position:absolute;'+
      'left:'+X+'px;'+
      'top:'+Y+'px;'+
      'width:'+Width+'px;'+
      'height:'+Height+'px;'+
      'z-index:1;'+
      'font:9pt Arial'+
    '}'+
    '</STYLE>'+
    '<DIV ID="'+ID+'">'+
    Text+
    '</DIV>';
}

function DoInfo(x, y)
{
  d=new Date();
  if (!(InfoWindow) || (InfoWindow.closed)) InfoWindow=window.open(MapScript+MapPath+"?info&clickX="+x+"&clickY="+y+"&sessionid="+SessionId+"&time="+d.getTime(), "InfoWindow", "width=600,height=400,resizable=yes,scrollbars=yes")
  else
  {
    InfoWindow.location=MapScript+MapPath+"?info&clickX="+x+"&clickY="+y+"&sessionid="+SessionId+"&time="+d.getTime();
    InfoWindow.focus();
  }
}

/*function MapClick(e)
{
  if (document.all)
  {
    x=window.event.offsetX;
    y=window.event.offsetY;
  }
  else
  {
    x=e.layerX;
    y=e.layerY;
  }
  if (State=="Info") DoInfo(x, y)
  else if (State=="Capture") DoCapture(x, y)
  else SetQuery("Action="+State+"&clickX="+x+"&clickY="+y);
}*/

function ZoomScale(Scale)
{
  SetQuery("Action=Zoom&scale="+Scale);
}

function Redraw()
{
  SetQuery("Action=Redraw");
}

function DoLocate()
{
  if (!(LocateWindow) || (LocateWindow.closed)) LocateWindow=window.open(MapScript+MapPath+"?findstreet", "LocateWindow", "width=400,height=300,resizable=yes,scrollbars=yes")
  else
  {
    LocateWindow.location=MapScript+MapPath+"?findstreet";
    LocateWindow.focus();
  }
}

function DoGoto()
{
  if (!(GotoWindow) || (GotoWindow.closed)) GotoWindow=window.open(MapScript+MapPath+"?goto", "GotoWindow", "width=400,height=300,resizable=yes,scrollbars=yes")
  else
  {
    GotoWindow.location=MapScript+MapPath+"?goto";
    GotoWindow.focus();
  }
}

function DoOrientate()
{
  d=new Date();
  if (!(OrientationWindow) || (OrientationWindow.closed)) OrientationWindow=window.open(MapScript+MapPath+"?noupdate&Action=orientate&factor=5&width=400&height=300&sessionid="+SessionId+"&time="+d.getTime(), "OrientationWindow", "width=440,height=340,resizable=yes,scrollbars=yes")
  else
  {
    OrientationWindow.location=MapScript+MapPath+"?noupdate&Action=orientate&factor=5&width=400&height=300&sessionid="+SessionId+"&time="+d.getTime();
    OrientationWindow.focus();
  }
}

function DoEnlarge()
{
  d=new Date();
  if (!(EnlargeWindow) || (EnlargeWindow.closed)) EnlargeWindow=window.open(MapScript+MapPath+"?noupdate&Action=Redraw&width=800&height=600&sessionid="+SessionId+"&time="+d.getTime(), "EnlargeWindow", "width=830,height=620,resizable=yes,scrollbars=yes")
  else
  {
    EnlargeWindow.location=MapScript+MapPath+"?noupdate&Action=Redraw&width=800&height=600&sessionid="+SessionId+"&time="+d.getTime();
    EnlargeWindow.focus();
  }
}

function DoPrint()
{
  d=new Date();
  if (!(PrintWindow) || (PrintWindow.closed)) PrintWindow=window.open(MapScript+MapPath+"?noupdate&Action=Redraw&width="+(MapWidth*2)+"&height="+(MapHeight*2)+"&sessionid="+SessionId+"&time="+d.getTime(), "EnlargeWindow", "width=830,height=620,resizable=yes,scrollbars=yes")
  else
  {
    PrintWindow.location=MapScript+MapPath+"?noupdate&Action=Redraw&width="+(MapWidth*2)+"&height="+(MapHeight*2)+"&sessionid="+SessionId+"&time="+d.getTime();
    PrintWindow.focus();
  }
  PrintWindow.print();
}

function Pan(X,Y)
{
  SetQuery("Action=Pan&X="+X+"&Y="+Y);
}

function CreateMap(Script, Path, Query, Style, Width, Height, Buttons, Session)
{
  MapScript=Script;
  MapPath=Path;
  MapWidth=Width;
  MapHeight=Height;
  d=new Date();
  if (Session) SessionId=Session;
  MapQuery=Script+Path+"?width="+Width+"&height="+Height+((Query!="")?"&"+Query:"")+"&sessionid="+SessionId+"&time="+d.getTime();
  TopButtons="";
  T=0;
  L=32;
  Buttons=Buttons.toLowerCase();
//  if (Buttons.indexOf("locate")>=0) { TopButtons+=CreateButton("Locate", "/mapicons/locate0.gif", "/mapicons/locate1.gif", "/mapicons/locate2.gif", 64, 32, "Locate", L, 0, "DoLocate()"); L+=64; }
//  if (Buttons.indexOf("goto")>=0) { TopButtons+=CreateButton("Goto", "/mapicons/goto0.gif", "/mapicons/goto1.gif", "/mapicons/goto2.gif", 58, 32, "Goto", L, 0, "DoGoto()"); L+=58; }
  if (Buttons.indexOf("orientation")>=0) { TopButtons+=CreateButton("Orientation", "/mapicons/orient0.gif", "/mapicons/orient1.gif", "/mapicons/orient2.gif", 84, 32, "Orientation", L, 0, "DoOrientate()"); L+=84; }
  if (Buttons.indexOf("enlarge")>=0) { TopButtons+=CreateButton("Enlarge", "/mapicons/enlarge0.gif", "/mapicons/enlarge1.gif", "/mapicons/enlarge2.gif", 75, 32, "Enlarge", L, 0, "DoEnlarge()"); L+=75; }
  if (Buttons.indexOf("help")>=0) { TopButtons+=CreateButton("Help", "/mapicons/help0.gif", "/mapicons/help1.gif", "/mapicons/help2.gif", 48, 32, "Help", L, 0, "DoHelp()"); }
  LeftButtons="";
  if (L>32)
    T=32;
  MapTop=T;
  //LeftButtons+=CreateButton("Info", "/mapicons/info_0.gif", "/mapicons/info_1.gif", "/mapicons/info_2.gif", 32, 32, "Info", 0, T, "SetState('Info')"); T+=32;
  LeftButtons+=CreateButton("Zoom", "/mapicons/zoom_0.gif", "/mapicons/zoom_1.gif", "/mapicons/zoom_2.gif", 32, 32, "Zoom", 0, T, "SetState('Zoom')"); T+=32;
  //LeftButtons+=CreateButton("ZoomOut", "/mapicons/zoomo_0.gif", "/mapicons/zoomo_1.gif", "", 32, 32, "Zoom out", 0, T, "SetQuery('Action=ZoomOutx2&ClickX="+(Width/2)+"&ClickY="+(Height/2)+"')"); T+=32;
  LeftButtons+=CreateButton("Pan", "/mapicons/pan_0.gif", "/mapicons/pan_1.gif", "/mapicons/pan_2.gif", 32, 32, "Pan", 0, T, "SetState('Pan')"); T+=32;
  LeftButtons+=CreateButton("ZoomAll", "/mapicons/zoomall_0.gif", "/mapicons/zoomall_1.gif", "", 32, 32, "Zoom all", 0, T, "SetQuery('Action=ZoomAll')"); T+=32;
  LeftButtons+=CreateButton("ZoomPrev", "/mapicons/zoomp_0.gif", "/mapicons/zoomp_1.gif", "", 32, 32, "Zoom previous", 0, T, "SetQuery('Action=ZoomPrev')"); T+=32;
  LeftButtons+=CreateButton("Print", "/mapicons/print_0.gif", "/mapicons/print_1.gif", "", 32, 32, "Print", 0, T, "DoPrint()"); T+=32;
  document.write(
    '<STYLE TYPE="text/css">',
    '#map {', Style,
      'width:', Width+34, 'px;',
      'height:', Height+(TopButtons!=""?32:0)+22, 'px;',
    '}',
    '</STYLE>',
    '<DIV ID="map">',
  TopButtons,
  LeftButtons,
  CreateMapImage("MapArea", 33, MapTop+1, Width, Height, MapQuery),
  CreateHint("hint", 32, Height+MapTop+2, Width, 32, "Click on the map to get information about an object"),
  CreateButton("PanLeft", "/mapicons/left.gif", "/mapicons/left_h.gif", "", 17, 15, "Pan left", 33, MapTop+Height/2-8, "Pan(-90,0)"),
  CreateButton("PanLeftUp", "/mapicons/nw.gif", "/mapicons/nw_h.gif", "", 16, 16, "Pan left and up", 32, MapTop, "Pan(-90,90)"),
  CreateButton("PanUp", "/mapicons/up.gif", "/mapicons/up_h.gif", "", 15, 17, "Pan up", 32+Width/2-8, MapTop+1, "Pan(0,90)"),
  CreateButton("PanRightUp", "/mapicons/ne.gif", "/mapicons/ne_h.gif", "", 16, 16, "Pan right and up", Width+18, MapTop, "Pan(90,90)"),
  CreateButton("PanRight", "/mapicons/right.gif", "/mapicons/right_h.gif", "", 17, 15, "Pan right", 32+Width-16, MapTop+Height/2-8, "Pan(90,0)"),
  CreateButton("PanRightDown", "/mapicons/se.gif", "/mapicons/se_h.gif", "", 16, 16, "Pan right and down", Width+18, MapTop+Height-14, "Pan(90,-90)"),
  CreateButton("PanDown", "/mapicons/down.gif", "/mapicons/down_h.gif", "", 15, 17, "Pan down", 32+Width/2-8, MapTop+Height-16, "Pan(0,-90)"),
  CreateButton("PanLeftDown", "/mapicons/sw.gif", "/mapicons/sw_h.gif", "", 16, 16, "Pan left and down", 32, MapTop+Height-14, "Pan(-90,-90)"),
  '</DIV>');
}

function CreateSWFMap(Script, Path, Query, Style, Width, Height, Buttons)
{
  State = "Info";
  MapScript=Script;
  MapPath=Path;
  MapWidth=Width;
  MapHeight=Height;
  d=new Date();
  MapQuery=Script+Path+"?width="+Width+"&height="+Height+((Query!="")?"&"+Query:"")+"&time="+d.getTime();
  TopButtons="";
  L=32;
  Buttons=Buttons.toLowerCase();
//  if (Buttons.indexOf("locate")>=0) { TopButtons+=CreateButton("Locate", "/mapicons/locate0.gif", "/mapicons/locate1.gif", "/mapicons/locate2.gif", 64, 32, "Locate", L, 0, "DoLocate()"); L+=64; }
//  if (Buttons.indexOf("goto")>=0) { TopButtons+=CreateButton("Goto", "/mapicons/goto0.gif", "/mapicons/goto1.gif", "/mapicons/goto2.gif", 58, 32, "Goto", L, 0, "DoGoto()"); L+=58; }
  if (Buttons.indexOf("orientation")>=0) { TopButtons+=CreateButton("Orientation", "/mapicons/orient0.gif", "/mapicons/orient1.gif", "/mapicons/orient2.gif", 84, 32, "Orientation", L, 0, "DoOrientate()"); L+=84; }
  TopButtons+=CreateButton("Enlarge", "/mapicons/enlarge0.gif", "/mapicons/enlarge1.gif", "/mapicons/enlarge2.gif", 75, 32, "Enlarge", L, 0, "DoEnlarge()");
  L+=75;
  document.write(
    '<STYLE TYPE="text/css">',
    '#map {', Style,
      'width:', Width+64, ';',
      'height:', Height+64, ';',
    '}',
    '</STYLE>',
    '<DIV ID="map">',
  TopButtons,
  CreateButton("Info", "/mapicons/info_0.gif", "/mapicons/info_1.gif", "/mapicons/info_2.gif", 32, 32, "Info", 0, 32, "SetState('Info')"),
  CreateButton("Zoom", "/mapicons/zoom_0.gif", "/mapicons/zoom_1.gif", "/mapicons/zoom_2.gif", 32, 32, "Zoom In", 0, 64, "SetState('Zoom')"),
  CreateButton("Pan", "/mapicons/pan_0.gif", "/mapicons/pan_1.gif", "/mapicons/pan_2.gif", 32, 32, "Pan", 0, 192-64, "SetState('Pan')"),
  CreateButton("ZoomAll", "/mapicons/zoomall_0.gif", "/mapicons/zoomall_1.gif", "", 32, 32, "Zoom all", 0, 224-64, "SetQuery('Action=ZoomAll')"),
  CreateButton("ZoomPrev", "/mapicons/zoomp_0.gif", "/mapicons/zoomp_1.gif", "", 32, 32, "Zoom previous", 0, 256-64, "SetQuery('Action=ZoomPrev')"),
  CreateMapSWF("MapArea", 33, 33, Width, Height, MapQuery),
  CreateHint("hint", 32, Height+32, Width, 32, "Click on the map to get information about an object"),
  CreateButton("PanLeft", "/mapicons/left.gif", "/mapicons/left_h.gif", "", 17, 15, "Pan left", 32, 32+Height/2-8, "Pan(-90,0)"),
  CreateButton("PanLeftUp", "/mapicons/nw.gif", "/mapicons/nw_h.gif", "", 16, 16, "Pan left and up", 32, 32, "Pan(-90,90)"),
  CreateButton("PanUp", "/mapicons/up.gif", "/mapicons/up_h.gif", "", 15, 17, "Pan up", 32+Width/2-8, 32, "Pan(0,90)"),
  CreateButton("PanRightUp", "/mapicons/ne.gif", "/mapicons/ne_h.gif", "", 16, 16, "Pan right and up", Width+16, 32, "Pan(90,90)"),
  CreateButton("PanRight", "/mapicons/right.gif", "/mapicons/right_h.gif", "", 17, 15, "Pan right", 32+Width-17, 32+Height/2-8, "Pan(90,0)"),
  CreateButton("PanRightDown", "/mapicons/se.gif", "/mapicons/se_h.gif", "", 16, 16, "Pan right and down", Width+16, Height+16, "Pan(90,-90)"),
  CreateButton("PanDown", "/mapicons/down.gif", "/mapicons/down_h.gif", "", 15, 17, "Pan down", 32+Width/2-8, 32+Height-17, "Pan(0,-90)"),
  CreateButton("PanLeftDown", "/mapicons/sw.gif", "/mapicons/sw_h.gif", "", 16, 16, "Pan left and down", 32, Height+16, "Pan(-90,-90)"),
  '</DIV>');
}

var x, y, x0, y0, x1, y1;
var MouseDown = false;
var Marquee = null;

function onMouseDown(e)
{
  if(document.all)
  {
    x=event.offsetX;
    y=event.offsetY;
  }
  else
  {
    x=e.layerX;
    y=e.layerY;
  }
  x0=x1=x;
  y0=y1=y;
  if (State=="Zoom")
  {
    MouseDown = true;
    if (!Marquee)
    {
      Marquee=document.createElement('DIV');
      Marquee.style.border="1px dashed black";
      Marquee.style.position="absolute";
      Marquee.style.visibility="hidden";
      Marquee.id="Marquee";
      document.getElementById("MarqueeDiv").appendChild(Marquee);
    }
    Marquee.style.left=x+'px';
    Marquee.style.top=y+'px';
    Marquee.style.width=0;
    Marquee.style.height=0;
/*    if(document.all)
      mydiv.className='IEloadingbg';
    else
      mydiv.className='loadingbg';*/
  }
}

function onMouseMove(e)
{
  if (MouseDown)
  {
    if(document.all)
    {
      x=event.offsetX;
      y=event.offsetY;
      event.cancelBubble = true;
      event.returnValue = false;
    }
    else
    {
      x=e.layerX;
      y=e.layerY;
    }
    if(document.all)
      elm=window.event.srcElement.id
    else
      elm=e.target.id;
    if (elm=="Marquee")
    {
      if (document.all)
        return;
      x=Math.min(x0,x1)+x;
      y=Math.min(y0,y1)+y;
    }
    else if (elm!="MapAreaimg" && elm!="MarqueeDiv")
      return;
    if (x>MapWidth-1) x=MapWidth-1;
    if (y>MapHeight-1) y=MapHeight-1;
    //SetHint(x0+"; "+y0+"; "+x1+"; "+y1+"; "+elm, false);
    x1=x;
    y1=y;
    Marquee.style.left=Math.min(x0,x1)+'px';
    Marquee.style.top=Math.min(y0,y1)+'px';
    Marquee.style.width=Math.abs(x1-x0)+'px';
    Marquee.style.height=Math.abs(y1-y0)+'px';
    Marquee.style.visibility="visible";
  }
}

function onMouseUp(e)
{
  if (Marquee)
    Marquee.style.visibility="hidden";
  right=false;
  if (document.all)
  {
    if (event.button==2) right=true;
  }
  else if (e.which==3)
    right=true;
  if (right)
  {
    //if (State=="ZoomInX2" || State=="ZoomInX5")
      SetQuery("Action=zoomoutx2&ClickX="+x0+"&ClickY="+y0);
  }
  else
  {
    if (State=="Info")
    {
      DoInfo(x0, y0);
      // or write your own handler eg.:
      // F = new GetFeatureAt(x0, y0);
      // alert(F.Key);
    }
    else if (State=="Capture") DoCapture(x0, y0)
    else if ((x1>x0+2) && (y1>y0+2) && (State=="Zoom"))
      SetQuery("Action=zoomrect&x0="+x0+"&y0="+y0+"&x1="+x1+"&y1="+y1)
    else if (State=="Zoom")
      SetQuery("Action=ZoomInX2&ClickX="+x0+"&ClickY="+y0)
    else
      SetQuery("Action="+State+"&ClickX="+x0+"&ClickY="+y0);
  }
  MouseDown = false;
}

function onLoad()
{
  if (document.all) {
    //document.all.MapAreaimg.onclick=MapClick;
    document.getElementById('MapAreaimg').attachEvent('onmousedown', onMouseDown);
    document.getElementById('MapAreaimg').attachEvent('onmousemove', onMouseMove);
    document.getElementById('MapAreaimg').attachEvent('onmouseup', onMouseUp);
  } else {
    //document.getElementById('markers').addEventListener('click', MapClick, false);
    document.getElementById('MarqueeDiv').addEventListener('mousemove', onMouseMove, false);
    document.getElementById('MarqueeDiv').addEventListener('mousedown', onMouseDown, false);
    document.getElementById('MarqueeDiv').addEventListener('mouseup', onMouseUp, false);
  }
  Loaded=true;
  SetState(State);
}

window.onload=onLoad;



