//  -----------------------------------------------------------------
//    Notes:	The purpose of this Javascript File provide an api interface for mapAsheville
//    Global Variables Delcared:         
//           NONE
//
//    Arguments:   
//    Returns:	N/A
//  	
//   -----------------------------------------------------------------
//    Orginization:	City of Asheville IT Services
//    Original Code: 	Dave Michelson 9/11/2006
//    Last Update:	Dave Michelson 11/16/2006
//

  var mshuplocstr = 'SOURCE';
  var isNav = (navigator.appName.indexOf("Netscape")>=0);
  var isIE = (navigator.appName.indexOf("Internet Explorer")>=0);

    //get date
    var d=new Date()
    var month=new Array(12)

    month[0]="January"
    month[1]="February"
    month[2]="March"
    month[3]="April"
    month[4]="May"
    month[5]="June"
    month[6]="July"
    month[7]="August"
    month[8]="September"
    month[9]="October"
    month[10]="November"
    month[11]="December"

    var weekday=new Array(7)
    weekday[0]="Sunday"
    weekday[1]="Monday"
    weekday[2]="Tuesday"
    weekday[3]="Wednesday"
    weekday[4]="Thursday"
    weekday[5]="Friday"
    weekday[6]="Saturday"

    DateStr = weekday[d.getDay()] + ', ' + month[d.getMonth()] + ' ' + d.getDate() + ', ' +  d.getFullYear();

  function mapAVL(){
    this.ResponseXML = '';
    this.RequestXML = '';
    this.RequestURL = '';
    //this.AppName = 'mapAsheville';
    this.mapAVLURL = '';
    this.mapDiv = '';
    this.mapService='';
    this.InitXML = InitXML();
    this.InitURL = InitURL();
    this.Tool = '';
    this.UI = new Array();
    this.UList = new Array();
    this.USecDevList = new Array();
    this.PreXML='';
    this.MapClicks;
    this.maxX=0;
    this.maxY=0;
    this.minX=0;
    this.minY=0;
    this.mapHeight=0;
    this.mapWidth=0;
    this.xDistance=0;
    this.yDistance=0;
    this.xHalf=0;
    this.yHalf=0;
    this.mouseX=0;
    this.mouseY=0;
    this.pixelX=0;
    this.pixelY=0;
    this.ShowToc=true;
    this.Name='mAVL';
    this.UN='';
    this.PD='';
    this.PassSec=false;
    this.LoginDiv='Login';
    this.HelpLoc='help/';
    this.HelpDoc='index.html';
    this.PopUpWidth=200;
    
    //layer tip
    this.UseLayerTip=false;
    this.LayerTipFields='';
    this.LayerTipLayer='';
    this.LayerTipCSSClass='DevMap';
    this.LayerTipWidth=0;
    this.LayerTipHeight=0;
    this.LayerTipWaitTime=0;
    this.LayerTipEnableDrag=false;

    //overviewmap information
    this.mapOverview=false;
    this.mapOverviewMapCALLOUT=false;
    this.mapOverviewMapService='mapAsheville_CoaLocator';
    this.mapOverviewScale=10000;
    this.mapOverviewMapDiv='mapOV';
    this.mapOverviewMapWidth=150;
    this.mapOverviewMapHeight=150;

    //this menus
    this.showCursorLoc=true;
    this.showToolBar=true;
    this.showStatusBar=true;
    this.MapOnly=false;

    ResZ=0;
    topname='';
    menuName='';
    follower='';
    highZ=100000;

    //messageing settings
    this.TitleText='';
    this.WorkingImg='../../IMAGES/ArcIMSFrameWork/ArcIMSFrameWork_Working.gif';
    this.WorkingSplash='../../IMAGES/ArcIMSFrameWork/ArcIMSFrameWork_Workking_Splash.gif';
    this.WorkingCompleteImg='../../IMAGES/ArcIMSFrameWork/ArcIMSFrameWork_WorkingStop.gif';
    this.WorkingTxt='&nbsp;&nbsp;Map Loading...';
    this.WorkingCompleteTxt='&nbsp;&nbsp;Map Loaded!';
    
    //get properties
    this.GetRequestXML = function() { return this.RequestXML; }
    this.GetRequestURL = function() { return this.RequestURL; }
    this.GetResponseXML = function() { return this.ResponseXML; }
    this.GetMapDiv = function() { return this.mapDiv; }
    this.GetMapOverViewURL = function() { return this.OVMapURL; } 
    this.GetMapURL = function() { return this.mapURL; }   
    this.GetInitXML = function() { return this.InitXML; }
    this.GetInitURL = function() { return this.InitURL; }
    this.GetTool = function() { return this.Tool; }
    this.GetUI =  function() { return this.UI; }
    this.GetUList =  function() { return this.UList; }
    this.GetPreXML =  function() { return this.PreXML; }
    this.GetMapService =  function() { return this.mapService; }
    this.GetPopUpWidth=function() { return this.PopUpWidth; }


    this.GetCursorLoc = function() {  return this.showCursorLoc; }
    this.GetToolBar = function() {  return this.showToolBar; }
    this.GetStatusBar = function() {  return this.showStatusBar; }
    this.GetMapOnly = function() {  return this.MapOnly; }

    //this.GetAppName  =  function() { return this.AppName; }

    //set properties
    this.SetRequestXML = function(newVal) { this.RequestXML = newVal; }
    this.SetRequestURL = function(newVal) { this.RequestURL = newVal; }
    this.SetResponseXML = function(newVal) { this.ResponseXML = newVal; }
    this.SetMapService =  function(newVal,obj) { fSetMapService(newVal,obj); }
    this.SetName = function(newVal) { this.Name = newVal; }
    this.SetMapDiv = function(newVal) { this.mapDiv = newVal; }
    this.SetMapURL = function(xml,tag) { this.mapURL = returnInfo(xml,tag); }
    this.SetMapOverViewURL = function(xml,tag) { this.OVMapURL= returnInfo(xml,tag); } 
    this.SetInitXML = function(newVal) { this.InitXML  = newVal; }
    this.SetInitURL = function(newVal) {  this.InitURL = newVal; }

    this.SetCursorLoc = function(newVal) {  this.showCursorLoc = newVal; }
    this.SetToolBar = function(newVal) {  this.showToolBar = newVal; }
    this.SetStatusBar = function(newVal) {  this.showStatusBar = newVal; }
    this.SetMapOnly = function(newVal) {  this.MapOnly = newVal; }

    
    this.SetMapDimension = fSetMapDim;
    this.SetToolVal = function(newVal) { this.Tool = newVal; }
    this.ToolSet=fToolSet;
    this.SetPreXML = fSetPreXML;
    this.SetEnvelopeOBJ = fSetEnvO;
    this.SetEnvelopeXML = function(RspXM,ReqXML){ xml=fSetEnvX(RspXM,ReqXML);this.RequestXML=xml; }
    this.SetNewResponseXML = function(newVal) { this.ResponseXML = newVal;}
    this.SetBtnScript = fSetBtnScript();
    this.AddUI = function(newVal) {var idx=(Number(this.UI.length));this.UI[idx] = newVal;}
    this.AddUListener = function(newVal) {var idx=(Number(this.UList.length));this.UList[idx] = newVal;}
    this.AddSecDevList = function(newVal) {var idx=(Number(this.USecDevList.length));this.USecDevList[idx] = newVal;} 
    this.SetCanvas=fSetCanvas;
    this.SetInfo=fSetInfo;
    this.TempDraw=TempDraw;
    this.PopUp=new fPopUp();
    this.LayerTip=new fLayerTip();
    this.InfoDiv=fInfoDiv;
    this.SetPopUpWidth=function(newVal) { this.PopUpWidth=newVal; }
    //this.SetAppName =function(newVal) { this.AppName = newVal; }

    //set events
    this.AddListener = function(name,type,funct,obj)
                       {                        
                         fAddEventListener( name , type , funct , false , obj);
                         if(name.indexOf('Pos',1)>0){fMoveXY(name,type,obj)}
                         if(name.indexOf('mapEvent',1)>0){fMoveXY(name,type,obj)}
                       } 
    this.RemoveListener = function(name,type,funct){ fRemoveEventListener( name , type , funct , false );}

    //Send XML method
    this.SendRequest = fSendRequest;

    //mapAshevile mashup methods
    this.InitDrawMap = fInitDrawMap;
    this.InitializeMap = fInitializeMap;
    this.InitializeOverViewMap = fInitOverViewMap;
    this.RefreshMap = fRefreshMap;
    this.SendTool = fSendTool;
    this.SendMapAction = fSendMapAction;
    this.ShowTools = fShowTools;
    this.AddUserEvent = fAddUserEvent;
    this.MoveIt=fMoveIt;

    //generic xml methods
    this.GetTag = returnInfo;
    this.GetXML = returnXML;
    this.ReplaceTag = replaceValue;
  }


  function getCookie(c_name)
  {
  if (document.cookie.length>0)
    {
    c_start=document.cookie.indexOf(c_name + "=")
    if (c_start!=-1)
      { 
      c_start=c_start + c_name.length+1 
      c_end=document.cookie.indexOf(";",c_start)
      if (c_end==-1) c_end=document.cookie.length
      return unescape(document.cookie.substring(c_start,c_end))
      } 
    }
    return ""
  }

  function setCookie(c_name,value,expiredays)
  {
    var exdate=new Date()
    exdate.setDate(exdate.getDate()+expiredays)
    document.cookie=c_name+ "=" +escape(value)+
    ((expiredays==null) ? "" : ";expires="+exdate.toGMTString())
  }


  //function for getting query String variables
  function getQueryVariable(variable) {
    var query = window.location.search.substring(1);
    var vars = query.split("&");
    for (var i=0;i<vars.length;i++) {
      var pair = vars[i].split("=");
      if (pair[0] == variable) {
        return pair[1];
      }
    }
  }

  //function to set map Service
  function fSetMapService(newMapService,obj)
  {
    InitXML=obj.GetInitXML();
    xml=replaceValue(InitXML,'SERVICENAME',newMapService);
    obj.SetInitXML(xml);
    InitXML=obj.GetInitXML();
    return InitXML;
  }

  //new object for recording and rendering user click actions in browser
  function fMapClicks(mapCan1,mapCan2)
  {
    this.ClickCount=-1;
    this.ClickMin=0;
    this.ContinueSelect=true;
    this.KeepGrahpics=false;
    this.aShapeType=4;
    this.ButtonDown=false;
    this.StartX;
    this.StartY;
    this.EndX;
    this.EndY;
    this.WidthX;
    this.HeightY;
    this.DrawOne = new jsGraphics(mapCan1);
    this.DrawTwo = new jsGraphics(mapCan2);
    this.DrawOne.Color='#ff0000';  //red
    this.DrawTwo.Color='#0000ff';  //blue
    this.DrawOne.Stroke=2;
    this.DrawTwo.Stroke=2;
    this.DrawOne.Opacity=0.5;
    this.DrawTwo.Opacity=0.5;
    this.ImageX = new Array();
    this.ImageY = new Array();
    this.allX = new Array();
    this.allY = new Array();
    this.MapX = Array();
    this.MapY = Array();
    this.curImageX;
    this.curImageY;
    this.curHOLDX;
    this.curMapX;
    this.curMapY;

    this.ClearClicks=fClear;
    this.AddClick=fAddClick
    this.ConvertClicks=fConvertClicks;
    this.ConvertMousePosition=fConvertMousePosition;
    this.SetClickMin=fSetClickMin;
    this.DrawShape=fDrawShape;
    this.MoveXY=fMoveXY;
    this.Dragging=fDragging;
    this.ForceNewXY=fForceNewXY;
    this.AfterSendStartXY=fAfterSendStartXY;
  }

  function jsHTMLEncode (str)
  { 
    str = str.replace(/&/g, "&amp;");
    str = str.replace(/</g, "&lt;");
    str = str.replace(/>/g, "&gt;");
    str = str.replace(/"/g, "&quot;");
    str = str.replace(/'/g, "&apos;");
    return str;
  }; 

  function jsHTMLDecode (str)
  { 
    str = str.replace(/&amp;/g, "&");
    str = str.replace(/&lt;/g, "<");
    str = str.replace(/&gt;/g, ">");
    str = str.replace(/&quot;/g, '"');
    str = str.replace(/&apos;/g, "'");
    return str;
  }; 


  //function or resets clicks to defaults
  function fClear(obj)
  {
    obj.MapClicks.ClickCount = -1;
    obj.clickMin = 0
    obj.MapClicks.ContinueSelect = true;
    obj.MapClicks.mDistance = 0;
    obj.MapClicks.ImageX = Array();
    obj.MapClicks.ImageY = Array();
    obj.MapClicks.allX = Array();
    obj.MapClicks.allY = Array();
    obj.MapClicks.MapX = new Array();
    obj.MapClicks.MapY = new Array();
    obj.MapClicks.StartX = 0;
    obj.MapClicks.StartY = 0;
    obj.MapClicks.EndX = 0;
    obj.MapClicks.EndY = 0;
    obj.MapClicks.WidthX = 0;
    obj.MapClicks.HeightY = 0;
    obj.MapClicks.DrawTwo.clear();
    obj.MapClicks.DrawOne.clear(); 
    obj.MapClicks.DrawTwo.clear(); 
    obj.MapClicks.DrawOne.paint();
    obj.MapClicks.DrawTwo.paint();
  }

  //function sets basic info for object
  function fSetInfo(obj)
  {
    RspXML=obj.GetResponseXML();
    obj.maxX=returnInfo(RspXML,'MAPMAXX');
    obj.maxY=returnInfo(RspXML,'MAPMAXY');
    obj.minX=returnInfo(RspXML,'MAPMINX');
    obj.minY=returnInfo(RspXML,'MAPMINY');
    obj.mapHeight=returnInfo(RspXML,'MAPHEIGHT');
    obj.mapWidth=returnInfo(RspXML,'MAPWIDTH');;
    obj.xDistance=Math.abs(obj.maxX-obj.minX);
    obj.yDistance=Math.abs(obj.maxY-obj.minY);
    obj.xHalf=obj.xDistance/2;
    obj.yHalf=obj.yDistance/2;
    obj.pixelX=obj.xDistance/obj.mapHeight;
    obj.pixelY=obj.yDistance/obj.mapWidth;
  }


  //funciont sets overview
  function fInitOverViewMap(obj)
  {
      //set ov map
      fSetIntitXMLTAG(obj,obj.mapOverviewMapService,'OVERVIEWMAPSERVICENAME');
      fSetIntitXMLTAG(obj,obj.mapOverviewScale,'OVERVIEWMAPSCALE');
      fSetIntitXMLTAG(obj,obj.mapOverviewMapWidth,'OVERVIEWMAPWIDTH');
      fSetIntitXMLTAG(obj,obj.mapOverviewMapHeight,'OVERVIEWMAPHEIGHT');
      fSetIntitXMLTAG(obj,obj.mapOverview,'OVERVIEWMAPINCLUDE');
      fSetIntitXMLTAG(obj,obj.mapOverviewMapCALLOUT,'OVERVIEWMAPCALLOUT');
  }

  //function to set INIT XML tag
  function fSetIntitXMLTAG(obj,val,tag)
  {
    
    if(typeof(obj)=='object')
    {
      //set xml from object
      InitXML=obj.GetInitXML();
      //prompt('object',InitXML);
      newXML=replaceValue(InitXML,tag,val);
      //prompt('object',newXML);

      //set new initial xml
      obj.SetInitXML(newXML);
      return obj.GetInitXML();
    }else{
      //set xml for get from XML string
      InitXML=obj;
      newXML=replaceValue(InitXML,tag,val);

      //set new initial xml
      obj.SetInitXML(newXML);
      return obj.GetInitXML();

      //set new initial xml
      return newXML;     
    }
  }

  //function to set mapWidth
  function fSetMapDim(obj,val,tag)
  {
    if(typeof(obj)=='object')
    {
      //set xml for map dimensions get from object
      InitXML=obj.GetInitXML();
      newXML=replaceValue(InitXML,tag,val);

      //set new initial xml
      obj.SetInitXML(newXML);
      return obj.GetInitXML();
    }else{
      //set xml for map dimensions get from XML string
      InitXML=obj;
      newXML=replaceValue(InitXML,tag,val);

      //set new initial xml
      obj.SetInitXML(newXML);
      return obj.GetInitXML();

      //set new initial xml     
      return newXML;     
    }
  }
 
  //function to display tool button
  function fAddXML(obj)
  {
    //get the last request
    var ReqXML=obj.GetRequestXML();
    //get the last response
    var RspXML=obj.GetResponseXML();

    //replace new envelope history with old one
    var xmlOLD=returnXML(ReqXML,'ENVELOPEHISTORY')
    var xmlNEW=returnXML(RspXML,'ENVELOPEHISTORY')
    if(xmlOLD==''){xmlOLD='xmlreplaceholder';ReqXML=ReqXML.replace(xmlOLD,xmlNEW+xmlOLD);}else{ReqXML=ReqXML.replace(xmlOLD,xmlNEW);}

    //replace new layer list with old one
    var xmlOLD=returnXML(ReqXML,'LAYERLIST')
    var xmlNEW=returnXML(RspXML,'LAYERLIST')
    if(xmlOLD==''){xmlOLD='xmlreplaceholder';ReqXML=ReqXML.replace(xmlOLD,xmlNEW+xmlOLD);}else{ReqXML=ReqXML.replace(xmlOLD,xmlNEW);}

    //replace new map services list with old one
    var xmlOLD=returnXML(ReqXML,'MAPSERVICES')
    var xmlNEW=returnXML(RspXML,'MAPSERVICES')
    if(xmlOLD==''){xmlOLD='xmlreplaceholder';ReqXML=ReqXML.replace(xmlOLD,xmlNEW+xmlOLD);}else{ReqXML=ReqXML.replace(xmlOLD,xmlNEW);}

    //return new XML
    return ReqXML;
  }

  //function to set the current envelope dimentsions with xml
  function fSetEnvX(RspXM,ReqXML)
  {
    //replace old env with new env
    var newVal=returnInfo(RspXML,'MAPMAXX');
    var newXML=replaceValue(ReqXML,'MAXX',newVal);

    newVal=returnInfo(RspXML,'MAPMAXY');
    newXML=replaceValue(newXML,'MAXY',newVal);

    newVal=returnInfo(RspXML,'MAPMINX');
    newXML=replaceValue(newXML,'MINX',newVal);

    newVal=returnInfo(RspXML,'MAPMINY');
    newXML=replaceValue(newXML,'MINY',newVal);
   
    //set the request xml with new envelope
    return newXML;
  }

  //functon adds user xml to the intial XML
  function fSetPreXML(xml,obj)
  {
    mapactions=returnInfo(xml,'ACTION')
    mapsets=returnInfo(xml,'SET')
    if(typeof(obj)=='object')
    {
      //set xml for mapactions
      InitXML=obj.GetInitXML();
      imapactions=returnInfo(InitXML,'ACTION');
      newXML=imapactions+mapactions;
      newInitXML=replaceValue(InitXML,'ACTION',newXML);

      //set xml for settings
      InitXML=obj.GetInitXML();
      imapsets=returnInfo(InitXML,'SET');
      newXML=imapsets+mapsets;
      newXML=replaceValue(newInitXML,'SET',newXML);

      //set new initial xml
      obj.SetInitXML(newXML);
      return obj.GetInitXML();
    }else{
      //set xml for mapactions
      InitXML=obj;
      imapactions=returnInfo(InitXML,'ACTION');
      newXML=imapactions+mapactions;
      newInitXML=replaceValue(InitXML,'ACTION',newXML);

      //set xml for settings
      InitXML=obj;
      imapsets=returnInfo(InitXML,'SET');
      newXML=imapsets+mapsets;
      newXML=replaceValue(newInitXML,'SET',newXML);

      //set new initial xml     
      return newXML;     
    }
  }

  //function to set the current envelope dimentsions with mapavl object
  function fSetEnvO(obj)
  {
    //get the last request
    var ReqXML=obj.GetRequestXML();
    //get the last response
    var RspXML=obj.GetResponseXML();

    //replace old env with new env
    var newVal=returnInfo(RspXML,'MAPMAXX');
    var newXML=replaceValue(ReqXML,'MAXX',newVal);

    newVal=returnInfo(RspXML,'MAPMAXY');
    newXML=replaceValue(newXML,'MAXY',newVal);

    newVal=returnInfo(RspXML,'MAPMINX');
    newXML=replaceValue(newXML,'MINX',newVal);

    newVal=returnInfo(RspXML,'MAPMINY');
    newXML=replaceValue(newXML,'MINY',newVal);
   
    //set the request xml with new envelope
    obj.SetRequestXML(newXML);
  }

  var dot='.';
  var dotcnt=1;
  //initalizes map
  function fInitializeMap(obj,objName)
  {
      if(dotcnt>40){dot='.';dotcnt=1;}
      dot=dot+'.';
      dotcnt=dotcnt+1;
      loadtxt=obj.WorkingTxt;
      load='<div style="position:absolute;overflow:hidden;" >'+loadtxt+dot+'</div>';

    if ( obj.SetResponseXML()+'' == 'undefined'  )
    {
      fInitializeMap.thread = window.setTimeout(function(){fInitializeMap(obj,objName);},100);
      mMapDIV=obj.GetMapDiv();
      fAddDivHTML(mMapDIV,load);
      fResizeDiv(mMapDIV,300,16);
      fEleClass(mMapDIV,'tabnameheader')
      fBorderSizeDiv(mMapDIV,1);
      fDivVis(mMapDIV,'visible');
      
    }else{
      //clear time out
      clearTimeout(fInitializeMap.thread);

       window.status='';

      obj.PassSec=true;
      if ( obj.mapURL.length > 0 ){
      fDivVis(obj.LoginDiv,'hidden')
      obj.InitDrawMap(obj);
      obj.SetEnvelopeOBJ(obj);
      //listenters for map clicks
      if(isIE){obj.AddListener( 'mapIMG' , 'load' , fStartXY , obj );}
      obj.AddListener( 'mapHolder' , 'mouseover' , fMousePosition , obj );
      obj.AddListener( 'mapHolder' , 'mousemove' , fMousePosition , obj );
      obj.AddListener( 'mapHolder' , 'mousedown' , fMouseDown, obj );
      obj.AddListener( 'mapHolder' , 'dblclick' , fDoubleClick, obj );
      obj.AddListener( 'mapHolder' , 'mouseup' , fMouseUp, obj );
      obj.AddListener( 'mapDraw' , 'mouseover' , fMousePosition , obj );
      obj.AddListener( 'mapDraw' , 'mousemove' , fMousePosition , obj );
      obj.AddListener( 'mapDraw' , 'mousedown' , fMouseDown, obj );
      obj.AddListener( 'mapDraw' , 'dblclick' , fDoubleClick, obj );
      obj.AddListener( 'mapDraw' , 'mouseup' , fMouseUp, obj );
      //listenters for capturing clicks pts when changed
      obj.AddListener( 'mapClickX' , 'change' , fChange , obj );
      obj.AddListener( 'mapClickY' , 'change' , fChange , obj );
      obj.AddListener( 'xPos' , 'change' , fChange , obj );
      obj.AddListener( 'yPos' , 'change' , fChange , obj );
      //add ui tools to interface
      obj.ShowTools('mapToolbar', objName , obj );
      //add user events to interface
      obj.AddUserEvent( obj );
      //set up click object
      var oMapClicks = new fMapClicks('mapDraw','mapDraw2');
      obj.MapClicks=oMapClicks;
      //setintial info
      obj.SetInfo(obj);
      //postion canvas with map div will ensure clicks are collected properly
      obj.SetCanvas(obj.GetMapDiv());
      //add text to app
      fAddDivHTML('mapStatus',obj.WorkingCompleteTxt);
      document.getElementById('mapLoading').src=obj.WorkingCompleteImg;
      fAddDivHTML('mapTitleTxt',obj.TitleText);

      //fill toc box when data returned and show toc is true
      if(obj.ShowToc)
      {
        tag='LAYERLIST';
        res=obj.GetTag(obj.GetResponseXML(),tag);
        if(res.length>0)
        {      
          xml=obj.GetXML(obj.GetResponseXML(),tag);
          var TOC = obj.PopUp;
          TOC.SetPopUpWidth(obj.GetPopUpWidth());
          var txt = fGetLegend(obj,xml)    
          var name=txt.Name;
          TOC.Set('Legend',txt,obj);
        }
      }

        ray=obj.USecDevList;
        //loop through User event array and add change event
        for (i=0;i<ray.length;i++)
        {
          var val=obj.USecDevList[i];
          fDivVis(val,'visible');         
        }
        mMapDIV=obj.GetMapDiv();
        fDivVis(mMapDIV,'visible');

        if(obj.mapOverview){fDivVis('mapOV','visible');}

       // Set up the sliders and the displays.
       // ActivateSliders();
       }else{
        alert('Invalid user name, password, or invalid request!');
        obj.PassSec=false;
        ray=obj.USecDevList;
        //loop through User event array and add change event
        for (i=0;i<ray.length;i++)
        {
          var val=obj.USecDevList[i];
          fDivVis(val,'hidden');         
        }
        mMapDIV=obj.GetMapDiv();
        fDivVis(mMapDIV,'hidden');
     }
      
    }
  }
  function test(evt){alert(evt.type)}
  function fMousePos(){document.getElementById('mapPosition').innerHTML='test'}
  function fMousePos2(){document.getElementById('mapPosition').innerHTML=document.getElementById('mapPosition').innerHTML+'--test2'}

  //function to display tool button
  function fSendMapAction(val,type,obj,goval,divName)
  {
    //alert(val);
    if (val=='Clear'){return null;};//do nothing for custom event
    if ( obj.SetResponseXML()+'' == 'undefined'  )
    {
      document.getElementById('LayerTipData').innerHTML="Working...";
      fSendMapAction.thread = window.setTimeout(function(){fSendMapAction(val,type,obj,goval,divName);},100);
    }else{
      //clear time out
      clearTimeout(fSendMapAction.thread);

       window.status='';

    var xml=fClearActions(obj);
    var xml=obj.GetRequestXML();  
    var tag=type.toUpperCase()+'NAME';
    xml=replaceValue(xml,tag,val);
    var tag=type.toUpperCase()+'ACTION';
    xml=replaceValue(xml,tag,'GO');
    if(type.toUpperCase()=='USERSETTING')
    {
      var tag=type.toUpperCase()+'VALUE';
      if(goval!='undefined'){xml=replaceValue(xml,tag,goval);}
    }else{
      var tag='USERSETTINGVALUE';
      if(goval!='undefined'){xml=replaceValue(xml,tag,goval);}
    }
    obj.SetRequestXML(xml);
    var addXML=fAddXML(obj);
    obj.SetRequestXML(addXML);
    obj.SendRequest(obj.GetRequestURL(),obj.GetRequestXML(),obj);
    fFireSimpleRequest(obj,divName);
    }
  }

  //function to display tool button
  function fSendTool(val,type,obj,goval)
  {
    if (val=='Clear'){return null;};//do nothing for custom event
    fClearUserShapes(obj,val)
    if ( obj.SetResponseXML()+'' == 'undefined'  )
    {
      fSendTool.thread = window.setTimeout(function(){fSendTool(val,type,obj,goval);},100);
    }else{
    //clear time out
    clearTimeout(fSendTool.thread);

    window.status='';

    var xml=fClearActions(obj);
    var xml=obj.GetRequestXML();  
    var tag=type.toUpperCase()+'NAME';
    xml=replaceValue(xml,tag,val);
    var tag=type.toUpperCase()+'ACTION';
    xml=replaceValue(xml,tag,'GO');
    
    if(type.toUpperCase()=='USERSETTING')
    {
      var tag=type.toUpperCase()+'VALUE';
      if(goval!='undefined'){xml=replaceValue(xml,tag,goval);}
    }else{
      var tag='USERSETTINGVALUE';
      if(goval!='undefined'){xml=replaceValue(xml,tag,goval);}
      
    }
    obj.SetRequestXML(xml);
    var addXML=fAddXML(obj);
    obj.SetRequestXML(addXML);
    obj.SendRequest(obj.GetRequestURL(),obj.GetRequestXML(),obj);   
    if(document.getElementById('mapLoading'))
    {
      document.getElementById('mapLoading').src=obj.WorkingImg;
      fToggleWorking(obj,'ON');
    }
    fFireRequest(obj);
    }
  }

  //togggles working image
  function fToggleWorking(obj,togglestr)
  {
    switch(togglestr)
    {
      case 'ON':
        document.getElementById('workingSplsh').src=obj.WorkingSplash;
        var loc = new fAdjDiv(obj.GetMapDiv);
        var locTop = (obj.mapWidth/2) + loc.Y;
        var locLeft = (obj.mapHeight/2) + loc.X;
        obj.MoveIt('workingSplsh',locTop,locLeft);
        document.getElementById('workingSplsh').style.visibility='visible';
        document.getElementById('workingSplsh').style.zIndex='9999';
        break;
      case 'OFF':
        document.getElementById('workingSplsh').src=obj.WorkingCompleteImg;
        document.getElementById('workingSplsh').style.visibility='hidden';
        break;
    }
  }

  //fires an ajax request sets simple request
  function fFireSimpleRequest(obj,divName)
  {
    if ( obj.SetResponseXML()+'' == 'undefined'  )
    {
      fSendTool.thread = window.setTimeout(function(){fFireSimpleRequest(obj,divName);},100);
    }else{
      //clear time out
      clearTimeout(fSendTool.thread);

      window.status='';

      document.getElementById('LayerTipDataIMG').style.visibility='hidden';

      xml=obj.GetXML(obj.GetResponseXML(),tag);
      if( obj.GetTag(obj.GetResponseXML(),'FEATURECOUNT')  > 0)
      {

        var myExcelbtn = obj.GetTag(obj.GetResponseXML(),'FEATURECONVERT') 

        var fldvalues = obj.GetTag(obj.GetResponseXML(),'FIELDROW') 
        fldvalues = fReplace(fldvalues,'-STARTFLD--ENDFLD--STARTFLD-','')
        fldvalues = fReplace(fldvalues,'-ENDFLD--STARTFLD-','<br />')
        fldvalues = fReplace(fldvalues,'-STARTFLD-','')
        fldvalues = fReplace(fldvalues,'-ENDFLD-','')
        fldvalues = fldvalues.replace(/\+/g, " ");
        fldvalues = unescape(fldvalues);

       document.getElementById('LayerTipData').innerHTML=fldvalues+myExcelbtn;
       fDivVis('LayerTipH','visible');
       fDivVis('LayerTip','visible');
       fDivVis('LayerTipBlocker','visible');
       fDivVis(this.DataDiv,'visible');
       fDivVis(LayerTip.LayerName,'visible');

      }else{
       document.getElementById('LayerTipData').innerHTML='';
       fDivVis('LayerTipH','hidden');
       fDivVis('LayerTip','hidden');
       fDivVis('LayerTipBlocker','hidden');
       fDivVis(this.DataDiv,'hidden');
      }
    }
  }

  //fires an AJAX request to framework
  function fFireRequest(obj)
  {   
    var eleName='mapStatus';
    if ( obj.SetResponseXML()+'' == 'undefined'  )
    {
      loadtxt=obj.WorkingTxt;
      fAddDivHTML(eleName,loadtxt); //+dot
      fFireRequest.thread =  window.setTimeout(function(){fFireRequest(obj);},100);
    }else{
      //clear time out
      clearTimeout(fFireRequest.thread);

      window.status='';

      fAddDivHTML(eleName,obj.WorkingCompleteTxt);      
      XML=fAddCount(obj);

      if(!obj.MapClicks){return null;}

      obj.MapClicks.ForceNewXY(obj);

      obj.OVMapURL='test';
      obj.RefreshMap(obj.GetMapURL(),obj.GetResponseXML(),obj.GetMapDiv(),obj.OVMapURL,'mapOV');

      obj.SetEnvelopeOBJ(obj);
      obj.SetInfo(obj);
      obj.MapClicks.ClearClicks(obj);

      document.getElementById('mapLoading').src=obj.WorkingCompleteImg;
      fToggleWorking(obj,'OFF');
      //reset last tool interaction for contiued usage - zoom in , pan , identify , etc
      t=obj.GetTag(obj.GetRequestXML(),'TOOLNAME')
      if(typeof(t)=='string'){obj.ToolSet(obj,t);} //obj.SetTool(t);

      //fill identify box when data returned
      tag='IDENTIFYRESULTS';
      res=obj.GetTag(obj.GetResponseXML(),tag);
      if(res.length>0)
      {      
        xml=obj.GetXML(obj.GetResponseXML(),tag);
        var Identify =  obj.PopUp;
        Identify.SetPopUpWidth(obj.GetPopUpWidth());
        var txt = new obj.InfoDiv(xml,tag,'IDENTIFY');    
        var name=txt.Name;
        Identify.Set('Identify',txt.Div,obj);
      }

      //fill identify box when data returned
      tag='TABLERESULTS';
      res=obj.GetTag(obj.GetResponseXML(),tag);
      if(res.length>0)
      {      
        xml=obj.GetXML(obj.GetResponseXML(),tag);
        var Table =  obj.PopUp;
        Table.SetPopUpWidth(obj.GetPopUpWidth());
        var txt = new obj.InfoDiv(xml,tag,'Table');    
        var name=txt.Name;
        Table.Set('Table',txt.Div,obj);
      }

      if(obj.UseLayerTip)
      {
        var LayerTip =  obj.LayerTip;
        LayerTip.InDiv='mapLayerTipH';
        LayerTip.MapDiv=obj.GetMapDiv();
        LayerTip.SetXY(obj.MapClicks.curImageX,obj.MapClicks.curImageY);
        LayerTip.SetFields(obj.LayerTipFields);
        LayerTip.SetLayerName(obj.LayerTipLayer);
        LayerTip.SetWidth(obj.LayerTipWidth);
        LayerTip.SetHeight(obj.LayerTipHeight);
        LayerTip.SetCSS(obj.LayerTipCSSClass);
        LayerTip.SetWaitTime(obj.LayerTipWaitTime);
        LayerTip.EnableLTDrag(obj.LayerTipEnableDrag);
        LayerTip.SetDIV();

        LayerTip.ShowTip(LayerTip.X,LayerTip.Y,obj,LayerTip.Fields,LayerTip.LayerName);
      }

      //fill identify box when data returned
      tag='GEOCODERESULTS';
      res=obj.GetTag(obj.GetResponseXML(),tag);
      if(res.length>0)
      {      
        xml=obj.GetXML(obj.GetResponseXML(),tag);
        var GEOCODE =  obj.PopUp;
        GEOCODE.SetPopUpWidth(obj.GetPopUpWidth());
        var txt = new obj.InfoDiv(xml,tag,'GEOCODE');    
        var name=txt.Name;
        GEOCODE.Set('Geocode',txt.Div,obj);
      }

      //fill toc box when data returned and show toc is true
      if(obj.ShowToc)
      {
        tag='LAYERLIST';
        res=obj.GetTag(obj.GetResponseXML(),tag);
        if(res.length>0)
        {      
          xml=obj.GetXML(obj.GetResponseXML(),tag);
          var TOC =  obj.PopUp;
          TOC.SetPopUpWidth(obj.GetPopUpWidth());
          var txt = fGetLegend(obj,xml)    
          var name=txt.Name;
          TOC.Set('Legend',txt,obj);
        }
      }

      //delay for pan flickering
      window.setTimeout(function(){obj.MoveIt('mapIMG',0,0);},100);
    }
  }

  //fore new x y to update on change
  function fForceNewXY(obj)
  {
    switch(obj.MapClicks.aShapeType)
    {
      case 1:  //line
        break;
      case 2:  //poly
        break;
      case 3:  //rectangle
        break;
      case 4:  //Point
        break;
      case 5:  //Point - pan
        if(document.getElementById('xPos'))
        {
          eleX=document.getElementById('xPos');
          eleX.value=obj.MapClicks.StartX;
          fireChange(eleX);
        }
        if(document.getElementById('yPos'))
        {
          eleY=document.getElementById('yPos');
          eleY.value=obj.MapClicks.StartY;
          fireChange(eleY);
        }
        break;
      default:break;
    }
  }

  //adds one the count
  function fAddCount(obj)
  {
    xml=obj.GetRequestXML();
    count=Number(returnInfo(xml,'COUNT'));
    count+=1; 
    xml=replaceValue(xml,'COUNT',count);
    count=Number(returnInfo(xml,'COUNT'));
    obj.SetRequestXML(xml);
    return xml;
  }


  //function object for creating a layer tip
  function fLayerTip()
  {
     //replacename...
     //           


     var div = '<iframe id="LayerTipBlocker" style="position:absolute;height:'+this.height+'px;width:'+this.width+'px;background-color:transparent;color:white;font-size:1em;"  src="javascript:false;" frameBorder="0" scrolling="no" ></iframe>' +
               '<div id="LayerTip" class="'+this.CSSClass+'" style="position:absolute;top:0px;left:0px;border:1px solid dodgerblue;background:white;padding:2px 2px 2px 2px;height:'+this.height+'px;width:'+this.width+'px;" >' +
                 '<div id="LayerTipDrag" class="mapTitleTxtDevMap" style="position:relative;top:0px;left:0px;border:1px solid dodgerblue;padding:2px 2px 2px 2px;width:'+(this.width-5)+'px;" >' +
                   '<span id="LayerTipTitle" style="padding:5px 5px 5px 5px;" >' +
                     '<div class="textwhitesm" style="float:right;width:45px;padding:1px 1px 1px 1px;border:1px solid white;background-color:#D2691E;cursor:pointer;"  onclick="xHide(\'LayerTip\');xHide(\'LayerTipBlocker\');" >' +
                       'Close x' +
                     '</div>' +
                     'Layer Tip' +
                   '</span>' +
                 '</div>' +
                   '<div id="LayerTipDataH" class="'+this.CSSClass+'" style="position:relative;top:0px;left:0px;padding:5px 5px 5px 5px;height:'+(this.height-30)+'px;width:'+(this.width-10)+'px;overflow:scroll;"  >' +
                    '<img id="LayerTipDataIMG" name="LayerTipDataIMG" src="../../IMAGES/ArcIMSFrameWork/ArcIMSFrameWork_Working.gif" alt="working..." style="visibility:hidden;" />' +
                     '<div id="LayerTipData" class="dmText" style=""position:relative;top:-175px;left:0px;padding:10px 10px 10px 10px;" >' +
                         '' +
                         '<br />' +
                         '<span id="LayerTipDataHolder" style="'+this.CSSClass+'" ></span>' +
                     '</div>' +
                   '</div>' +
               '</div>'

    this.InDiv;
    this.MapDiv;
    this.Name='Layer Tip';
    this.Caption='Data:';
    this.Title='Layer Information';
    this.Fields='';
    this.LayerName='';
    this.CSSClass='DevMap';
    this.width=240;
    this.height=165;
    this.WaitTime=1000;
    this.Div=div;
    this.LTDrag=false;

    this.X=0;
    this.Y=0;
    this.DataXML='';   
    this.DataDiv='LayerTipDataHolder';
    this.lastX;
    this.lastY;

    var MapObj;
    var mFields;
    var mLayerName;
    var mLTCSSClass;
    var mLTwidth;
    var mLTHeight;
    var mLTWaitTime;
    var mStop;
    var mWtime=this.WaitTime;
    var mEnalbleLTDrag;

    this.EnableLTDrag=function(newVal){if(newVal.length>0){this.LTDrag=newVal;mEnalbleLTDrag=newVal;}}

    this.SetFields=function(newval){this.Fields=newval;mFields=newval}
    this.SetLayerName=function(newval){this.LayerName=newval;mLayerName=newval}
    this.SetXY=function(xInt,yInt){this.X=xInt;this.Y=yInt;}
    this.SetWidth=function(newVal){ if(newVal>0){this.width = newVal;mLTwidth=newVal;}}
    this.SetHeight=function(newVal){ if(newVal>0){this.height = newVal;mLTHeight=newVal}}
    this.SetCSS=function(newVal){ if(newVal.length>0){this.CSSClass = newVal;mLTCSSClas=newVal;}}
    this.SetWaitTime=function(newVal){ if(newVal>0){this.WaitTime= newVal;mWtime= newVal;}}
    this.SetDIV=function(){ 
  
      this.Div = '<iframe id="LayerTipBlocker" style="position:absolute;height:'+this.height+'px;width:'+this.width+'px;background-color:transparent;color:white;font-size:1em;"  src="javascript:false;" frameBorder="0" scrolling="no" ></iframe>' +
                 '<div id="LayerTip" class="'+this.CSSClass+'" style="position:absolute;top:0px;left:0px;border:1px solid dodgerblue;background:white;padding:2px 2px 2px 2px;height:'+this.height+'px;width:'+this.width+'px;" >' +
                   '<div id="LayerTipDrag" class="mapTitleTxtDevMap" style="position:relative;top:0px;left:0px;border:1px solid dodgerblue;padding:2px 2px 2px 2px;width:'+(this.width-5)+'px;" >' +
                     '<span id="LayerTipTitle" style="padding:5px 5px 5px 5px;" >' +
                       '<div class="textwhitesm" style="float:right;width:45px;padding:1px 1px 1px 1px;border:1px solid white;background-color:#D2691E;cursor:pointer;"  onclick="xHide(\'LayerTip\');xHide(\'LayerTipBlocker\');" >' +
                         'Close x' +
                       '</div>' +
                       'Layer Tip' +
                     '</span>' +
                   '</div>' +
                     '<div id="LayerTipDataH" class="'+this.CSSClass+'" style="position:relative;top:0px;left:0px;padding:5px 5px 5px 5px;height:'+(this.height-30)+'px;width:'+(this.width-10)+'px;overflow:scroll;"  >' +
                      '<img id="LayerTipDataIMG" name="LayerTipDataIMG" src="../../IMAGES/ArcIMSFrameWork/ArcIMSFrameWork_Working.gif" alt="working..." style="visibility:hidden;" />' +
                       '<div id="LayerTipData" class="'+this.CSSClass+'" style=""position:relative;top:-175px;left:0px;padding:10px 10px 10px 10px;" >' +
                           '' +
                           '<span id="LayerTipDataHolder" style="'+this.CSSClass+'" ></span>' +
                       '</div>' +
                     '</div>' +
                 '</div>';
    }
   
    this.ShowTip=function(xInt,yInt,obj,aFlds,mLyr)
    {
      MapObj=obj;
      mFields=aFlds;
      mLayerName=mLyr;
      idTxt='LayerTipH';
      myDiv=document.getElementById('mapResults');

      //if cloned div exists then remove the div to restablish the scale dependicies
      //if(document.getElementById(idTxt)){document.body.removeChild(document.getElementById(idTxt));}

      //if cloned div does not exist then make it
      if(!document.getElementById(idTxt))
      {
        var cloneDiv=myDiv.cloneNode(false); 
        cloneDiv.id=idTxt;
        //Set up clone div
        cloneDiv.innerHTML=this.Div;
        document.body.appendChild(cloneDiv);  
        fDivClr(cloneDiv,'DodgerBlue');
        fDivZ(cloneDiv.id,'100000');

        //Set inital position of legend div just offset of map div 
        var loc = new fAdjDiv(this.MapDiv);
        var mTop = loc.Y+yInt;    //+yInt
        var mLeft = loc.X+xInt;   //+xInt

        //set level of transparency for layer tip
        setOpacity(document.getElementById('LayerTip'), 85 );
        setOpacity(document.getElementById('LayerTipBlocker'), 1);
      }

      //add mousemove - mousestop event for sending map tip
      fAddUserEventFull('mapIMG','mousemove',fCheckMouse,obj);fAddUserEventFull('mapDraw','mousemove',fCheckMouse,obj);

      //add mouseout event for stoping the sending of the map tip
      fAddUserEventFull('mapIMG','mouseout',fCheckMouse,obj);fAddUserEventFull('mapDraw','mouseout',fCheckMouse,obj);
    }

    //function for getting mouse stop moving
    function fCheckMouse(evt)
    { 
      Obj=MapObj;
      flds=mFields;
      mLyr=mLayerName;

      //mosue moving reinstate the map tip
      if(evt.type == 'mousemove'){mStop=false;}
      
      if (evt.type == 'mouseout'){clearTimeout(fCheckMouse.thread);mStop=false;return null;}
      clearTimeout(fCheckMouse.thread);

      //when mouse stops moving send request for getting map tip
      var e=evt? evt : window.event, x=evt.clientX,
      mymousestop=function()
      { 
        if ( Obj.SetResponseXML()+'' != 'undefined'  ){ fGetLayerTip(Obj,flds,mLyr);clearTimeout(fCheckMouse.thread);return null;}
      };

      fCheckMouse.thread=setTimeout(mymousestop, mWtime);
    } 

    //function for getting map tip information
    function fGetLayerTip(Obj,flds,mLyr)
    {

      if(!Obj.UseLayerTip ){return '';}
      if(mStop){return '';}

      if(this.lastX==Obj.MapClicks.curImageX && this.lastY == Obj.MapClicks.curImageY)
      {
        mStop=true;
        clearTimeout(fCheckMouse.thread);
        return '';
      }else{
        fDivVis('LayerTipH','hidden');
        fDivVis('LayerTip','hidden');
        fDivVis('LayerTipBlocker','hidden');
        fDivVis('LayerTipDat','hidden')
      }
      
      this.lastX = Obj.MapClicks.curImageX;
      this.lastY = Obj.MapClicks.curImageY;

      mShapeTypeLT='POINTONLY'
      var xPointLT = Obj.MapClicks.curMapX;
      var yPointLT = Obj.MapClicks.curMapY;
      var mDistanceLT = (Obj.xDistance/Obj.mapHeight) * 4

      fPositionDiv('LayerTip',Obj.MapClicks.curImageY+110,Obj.MapClicks.curImageX+290);
      fPositionDiv('LayerTipBlocker',Obj.MapClicks.curImageY+110,Obj.MapClicks.curImageX+290);
      document.getElementById('LayerTipData').innerHTML='';

      theQuery = '[XPOINTS]='+xPointLT+';[YPOINTS]='+yPointLT+';[DISTANCE]='+mDistanceLT+';[UNIT]=FEET;[OVERLAYLAYER]='+mLyr+';[SHAPETYPE]='+mShapeTypeLT+';[LAYER]='+mLyr+';[FIELDS]='+flds+';';
      Obj.SendMapAction('Map Tip','USERSETTING',Obj,theQuery,this.DataDiv);
      
      if(Obj.LayerTipEnableDrag)
      {
        //enable draging with the ie blocker only after mousestop event so other functions do not open the layer tip box
        DragSetup( 'LayerTip' , 'LayerTipBlocker' );
        DragSetup( 'LayerTip' , 'LayerTipBlocker' );
      }

      mStop=true;

    }

  }
  
  //function object for creating a new or mapResults Holder
  function fPopUp()
  {
     //replacename...
     var div='<div id="menureplacename" name="menureplacename" class="resultsBox" >' +
              '<div id="menureplacenameDrag" class="tabnameheader" >' +
                '<div id="menureplacenamePopUps" class="tabbackground" >' +
                  'replacepopups'+
                '</div>' +              
              '<span class="resultsnametxt" >'+'<input type="hidden" value="10" id="replacenamelastscrollval" name="replacenamelastscrollval" />'+'</span>'+
                '<div id="menureplacenameIn" class="resultsInfo" >' +
                  'replacein'+
                '</div>' +
              '</div>' +
            '</div>';

    this.width=200;
    this.InDiv;
    this.Name;
    this.Div=div;
    this.XAdj=0;
    this.YAdj=0;
    this.HeightAdj=30;
    this.WidthAdj=-15;
    this.Popups=new Array();
    this.SetPopUpWidth=function(newVal){ this.width = newVal }
    this.AddPopup = function(newVal)
      {
        list=this.Popups.join(",").toUpperCase();
        if(list.indexOf(newVal.toUpperCase(),0)<0)
        {
          var idx=(Number(this.Popups.length));
          this.Popups[idx] = newVal;
        }
      }

    this.Set=function(name,indiv,obj)
    {
      newDiv=fReplace(div,'replacename',name)
      newDiv=fReplace(newDiv,'replacein',indiv)

      this.AddPopup(name);
      img='<img src="../../IMAGES/ArcIMSFrameWork/ArcIMSFrameWork_blank.gif" class="tabImgSpc" >';

      clickstr='fMoveNameFront(this.innerHTML);';
      list=this.Popups.join('</span>'+
           img+img+
           '<span id="mapResultsList" class="tabunselect" name="mapResultsList" onclick="'+clickstr+';" >');
      if(list.length==0){list='N/A';} 
      list='<span id="mapResultsListHolder" class="tabHolder"  >'+
           img+
           '<span id="mapResultsList" name="mapResultsList" class="tabunselect" onclick="'+clickstr+'" >'+
           list+
           '</span>'+
           img+
           '</span>';

      newDiv=fReplace(newDiv,'replacepopups',list)

      this.InDiv=indiv;
      this.Name=name;
      this.Div=newDiv;
      var mapdiv=obj.GetMapDiv();
      var width=Number(fGetDivDim(mapdiv,'width'));
      var height=Number(fGetDivDim(mapdiv,'height'));
      var nHeight=Number(fGetDivDim('mapDrag','height'));
      HoldScrollTop=0;     
      if(document.getElementById('mapResults_'+name))
      {
        HoldScrollTop=document.getElementById('menu'+name+'In').scrollTop;
        cloneDiv=document.getElementById('mapResults_'+name);
        cloneDiv.innerHTML=this.Div;
        document.getElementById('menu'+name+'In').scrollTop=HoldScrollTop;
      }else{
        if(document.getElementById('mapResults')){myDiv=document.getElementById('mapResults')}
        var cloneDiv=myDiv.cloneNode(false);
        topname=name; 
        cloneDiv.id=myDiv.id+'_'+name;
        cloneDiv.innerHTML=this.Div;
        document.getElementById('mapResults').appendChild(cloneDiv);
      }
      if(isNav){scrollAdj=15;}else{scrollAdj=0;}
      fMoveIt(cloneDiv.id,width+nHeight+2+this.XAdj,0+this.YAdj);
      fResizeDiv(cloneDiv.id,this.width,height);
      var width=Number(fGetDivDim(cloneDiv.id,'width'));
      fResizeDiv('menu'+name,(width+scrollAdj)+this.WidthAdj,(height)+this.HeightAdj);
      fResizeDiv('menu'+name+'Drag',(width)+this.WidthAdj,(nHeight*2)+this.HeightAdj);
      fResizeDiv('menu'+name+'In',(width)+this.WidthAdj,((height)-(nHeight*3.5))+this.HeightAdj ); 
      document.getElementById('menu'+name+'In').onscroll=function()
          { 
            document.getElementById(name+'lastscrollval').value=this.scrollTop;
          }
      fMoveNameFront(topname);
      fDivVis(cloneDiv.id,'visible');

      //ie doesnot play nice so must set scroll top twice.
      document.getElementById('menu'+name+'In').scrollTop=HoldScrollTop;
      document.getElementById('menu'+name+'In').scrollTop=HoldScrollTop;
    }
  }

  //replaces all instances of string
  function fReplace(string,curstr,newstr)
  {
      var reg = new RegExp(curstr, 'gi');
      string=string.replace(reg,newstr);
      return string;
  }

  //toggles a tab menu
  //tab ids must be [name]_tab[n]
  //the information tab or data part id must be [name]_[TabInfo][n]
  function fToggleTab(eleName,tabName,ele,TabCnt)
  {
    
    //loop the count of tabs turn all of invisible
    for (i=1;i<TabCnt+1;i++)
    {
      if(document.getElementById(tabName+'_TabInfo'+i)  ){
        //make all tabs hidden
        document.getElementById(tabName+'_TabInfo'+i).style.visibility='hidden';
        xBackground(document.getElementById(tabName+'_TabInfo'+i),'white');

        //make all tabs display none
        document.getElementById(tabName+'_TabInfo'+i).style.display='none';

        //change css class of each tab to unselected
        fEleClass(tabName+'_tab'+i,'mapTitleTxtTabUnSel')
      }
    }

    //make the current tab vis
    fEleClass(ele.id,'mapTitleTxtTabSel')

    if (document.getElementById(tabName+'_'+eleName))
    {
        //change css class of select tab to vis
      document.getElementById(tabName+'_'+eleName).style.visibility=(document.getElementById(tabName+'_'+eleName).style.visibility=='hidden')?'visible':'hidden';

        //change css class of select tab to display
      document.getElementById(tabName+'_'+eleName).style.display=(document.getElementById(tabName+'_'+eleName).style.display=='none')?'block':'none';
 
      //xBackground(document.getElementById(tabName+'_'+eleName),'royalblue');
    }
  }



  //moves name element to front
  function fMoveNameFront(ele_name)
  {
    topname=ele_name;
    holdpos=new Array();
    var list=document.getElementsByName('mapResultsList');
    //loop through map Results List and set css syles make all not selected
    for (i=0;i<list.length;i++)
    {
      tmpEleName=list[i].innerHTML;
      //alert(tmpEleName)
      holdpos[i]=document.getElementById('menu'+tmpEleName+'In').scrollTop;
      if(tmpEleName==topname)
      {
        fEleClass(list[i],'tabselect');
        //adjust for ie tab 
        if(isIE){list[i].style.top='1px';}
      }else{
        fEleClass(list[i],'tabunselect');
        //adjust for ie tab 
        if(isIE){list[i].style.top='0px';}
      }
      tmpEleName=tmpEleName.replace(/^\s*|\s*$/g,"");
      tmpEleNameone='mapResults_'+tmpEleName;
      fDivVis(tmpEleNameone,'hidden');
      fDivZ(tmpEleNameone,0);
      tmpEleNametwo='menu'+tmpEleName;
      fEleClass(tmpEleNametwo,'hidebox');
      if(ele_name.length==0){ele_name=list[0].innerHTML}
    }

    //make user click results visible - selected
    ele_name=ele_name.replace(/^\s*|\s*$/g,"");
    ele_nameone='mapResults_'+ele_name;
    fDivVis(ele_nameone,'visible');
    fDivZ(ele_nameone,2)
    ele_nametwo='menu'+ele_name;
    fEleClass(ele_nametwo,'resultsBoxMenuFront')
    for (i=0;i<list.length;i++)
    {
      tmpEleName=list[i].innerHTML;
      if(holdpos[i]!=0){       
        if(isIE){document.getElementById('menu'+tmpEleName+'In').scrollTop=document.getElementById(tmpEleName+'lastscrollval').value}else{document.getElementById('menu'+tmpEleName+'In').scrollTop=holdpos[i];}
      }
    }
  }

  function DragSetup( name , followname )
  {   
    menuName = name;
    //check if exists
    if(document.getElementById(followname))
    {
      fdiv = document.getElementById(followname);
      follower = fdiv.cloneNode(false);
      //follower.id = followname+menuName;
      //alert( follower.id );
      xShow( follower.id );
      Paint( follower.id );
    }
    var dBtn = xGetElementById(name+'Drag');
    xEnableDrag( dBtn , DragStart(name+'Drag') , OnDrag , null);
    xShow( name );
    Paint( name );
  }

  function oldDragSetup( name )
  {   
    menuName = 'menu'+name;

    //var rBtn = xGetElementById( 'menu'+name+'Resize');
    var dBtn = xGetElementById( 'menu'+name+'Drag');
    xEnableDrag( dBtn , DragStart('menu'+name+'Drag') , OnDrag , null);
    //if(!isNav){
    //  xEnableDrag( rBtn , ResizeStart( 'menu'+name+'Resize'  ) , OnResize , null);
    //}
    xShow( name );
    Paint( name );
    var obj = document.getElementById( 'menu'+name ); 
    //setOpacity(obj, 85 );
    //var obj = document.getElementById( 'menu'+name+'HW' ); 
    //setOpacity(obj, 0 );
  }

  function setOpacity(obj, opacity)
  {
    opacity = (opacity == 100)?99.999:opacity;
    // IE/Win
    obj.style.filter = "alpha(opacity="+opacity+")";
    //obj.style.filter = '"alpha(Opacity:75)"';
    // Safari<1.2, Konqueror
    obj.style.KHTMLOpacity = opacity/100;
    // Older Mozilla and Firefox
    obj.style.MozOpacity = opacity/100;
    // Safari 1.2, newer Firefox and Mozilla, CSS3
    obj.style.opacity = opacity/100;
  }

  function DragStart( ele , mx, my){xZIndex( ele , highZ++ );xZIndex( follower , highZ++ );}
  function OnDrag( ele , mdx, mdy)
  {
     xMoveTo( menuName , xLeft( menuName ) + mdx, xTop( menuName  ) + mdy);
     xMoveTo( follower.id, xLeft( follower.id) + mdx, xTop( follower.id) + mdy)
     parEle = xParent(ele);
     wd=xWidth(parEle.id);
     ht=xHeight(parEle.id);
     xResizeTo(follower.id,wd,ht)
  }

  function ResizeStart( ele , mx, my){xZIndex( ele , highZ++ );xZIndex( follower , highZ++ );}

  function OnResize(ele, mdx, mdy)
  {
    xResizeTo( menuName , xWidth( menuName ) + mdx, xHeight( menuName ) + mdy);    
    Paint( menuName );
  }

  function Paint( mName )
  {
    var mEle = xGetElementById( mName );
    var rBtn = xGetElementById( mName + 'Resize' );
    xMoveTo(rBtn, xWidth(mEle) - xWidth(rBtn), xHeight(mEle) - xHeight(rBtn));
  }

  //build a div for data info for identify view table from framework xml
  function fInfoDiv(xml,STARTTAG,type)
  {
    var STg='<';
    var ETg='>';
    var CTg='/';
    var retTxt='<div class="mapAddress" >No data!</div>';

    this.Name=returnInfo(xml,'FEATURENAME');
    this.Desc=returnInfo(xml,'FEATUREDESCRIPTION');
    this.Count=returnInfo(xml,'FEATURECOUNT');
   
    featuresXML=returnInfo(xml,'FEATURES');
    nameXML=returnXML(xml,'FEATURENAME');
    descXML=returnXML(xml,'FEATUREDESCRIPTION');
    countXML=returnXML(xml,'FEATURECOUNT');
    deleteXML=countXML+nameXML+descXML;

    featuresXML=fReplace(featuresXML,nameXML,'')
    featuresXML=fReplace(featuresXML,descXML,'')
    featuresXML=fReplace(featuresXML,countXML,'')
    featuresXML=fReplace(featuresXML,deleteXML,'')

    buid=returnInfo(xml,'FIELDNAME');
    buid=getBUID(buid);
    featuresXML=fReplace(featuresXML,buid,'')
    
    //cases for different info boxes
    switch (type.toUpperCase())
    {
      case 'IDENTIFY':
        featuresXML=fEscapeValues(featuresXML,0);
        featuresXML=featuresXML.replace(/\<FEATURE\>/g,'<TR class="datalistheader" ><TD colspan="2" >');
        featuresXML=featuresXML.replace(/\<\/FEATURE\>/g,'</TD></TR>' );
        featuresXML=featuresXML.replace(/\<FIELDS\>/g,'');
        featuresXML=featuresXML.replace(/\<\/FIELDS\>/g,'');
        featuresXML=featuresXML.replace(/\<FIELD\>/g,'<TR class="datalistfields" >');
        featuresXML=featuresXML.replace(/\<\/FIELD\>/g,'</TR>');
        featuresXML=featuresXML.replace(/\<FEATUREINDEX\>/g,'<TR><TD colspan="2" class="datalistfieldcount" >Index:');
        featuresXML=featuresXML.replace(/\<\/FEATUREINDEX\>/g,'</TD></TR>');
        featuresXML=featuresXML.replace(/\<FIELDNAME\>/g,'<TD class="datalistfieldname" >');
        featuresXML=featuresXML.replace(/\<FIELDVALUE\>/g,'<TD class="datalistfieldvalue" >');
        featuresXML=featuresXML.replace(/\<\/FIELDNAME\>/g,'</TD>');
        featuresXML=featuresXML.replace(/\<\/FIELDVALUE\>/g,'</TD>');
        info='<TABLE class="datalisttable" >'+
             '<TR><TD colspan="2" >'+this.Desc+': '+this.Count+'</TD></TR>'+
             featuresXML+'</TABLE>';
        break;
      case 'TABLE':
        featuresXML=fEscapeValuesCustom(featuresXML,'FIELDROW',0);

        featuresXML=featuresXML.replace(/\<FEATURECONVERT\>/g,'<TR><TD colspan="200" class="datalistfieldvalue" >');
        featuresXML=featuresXML.replace(/\<\/FEATURECONVERT\>/g,'</TD></TR>' );

        featuresXML=featuresXML.replace(/\<FEATURE\>/g,'<TR style="padding:1px 1px 1px 1px;" >');
        featuresXML=featuresXML.replace(/\<\/FEATURE\>/g,'</TR>' );
        featuresXML=featuresXML.replace(/\<FIELDNAMES\>/g,'<TR><TD >&nbsp;&nbsp;&nbsp;&nbsp;</TD>');
        featuresXML=featuresXML.replace(/\<\/FIELDNAMES\>/g,'</TR>' );
        featuresXML=featuresXML.replace(/\<FIELDROW\>/g,'');
        featuresXML=featuresXML.replace(/\<\/FIELDROW\>/g,'' );
        featuresXML=featuresXML.replace(/-STARTFLD--ENDFLD-/g,'' );
        featuresXML=featuresXML.replace(/-STARTNAME--ENDNAME-/g,'' );
        featuresXML=featuresXML.replace(/-STARTFLD-/g,'<TD class="datalistfieldvalue" style="white-space:nowrap;border-bottom:1px solid #D3D3D3;padding:2px 2px 2px 2px;background-color:white;" >&nbsp;&nbsp;');
        featuresXML=featuresXML.replace(/-STARTNAME-/g,'<TD class="datalistfieldname" style="background-color=#808080;">&nbsp;&nbsp;');
        featuresXML=featuresXML.replace(/-ENDFLD-/g,'&nbsp;&nbsp;</TD>');
        featuresXML=featuresXML.replace(/-ENDNAME-/g,'&nbsp;&nbsp;</TD>');
        featuresXML=featuresXML.replace(/\<FEATUREINDEX\>/g,'<TD class="datalistfieldvalue" style="white-space:nowrap;background-color=#D3D3D3;border-bottom:1px solid #D3D3D3;background-color:white;" >&nbsp;&nbsp;');
        featuresXML=featuresXML.replace(/\<\/FEATUREINDEX\>/g,'&nbsp;&nbsp;</TD>');
        info='<TABLE class="DataViewTable" style="background-color:#D3D3D3;padding:1px 1px 1px 1px;border-collapse:collapse;"  >'+
             '<TR><TD colspan="100" style="background-color:white;" >'+this.Desc+': '+this.Count+'</TD></TR>'+featuresXML+'</TABLE>';
        break;
      case 'GEOCODE':
        featuresXML=fEscapeValues(featuresXML,0);
        featuresXML=featuresXML.replace(/\<FEATURE\>/g,'<TR class="datalistheader" ><TD colspan="2" >');
        featuresXML=featuresXML.replace(/\<\/FEATURE\>/g,'</TD></TR>' );
        featuresXML=featuresXML.replace(/\<FIELDS\>/g,'');
        featuresXML=featuresXML.replace(/\<\/FIELDS\>/g,'');
        featuresXML=featuresXML.replace(/\<FIELD\>/g,'<TR class="datalistfields" >');
        featuresXML=featuresXML.replace(/\<\/FIELD\>/g,'</TR>');
        featuresXML=featuresXML.replace(/\<FEATUREINDEX\>/g,'<TR><TD colspan="2" class="datalistfieldcount" >Index:');
        featuresXML=featuresXML.replace(/\<\/FEATUREINDEX\>/g,'</TD></TR>');
        featuresXML=featuresXML.replace(/\<FIELDNAME\>/g,'<TD class="datalistfieldname" >');
        featuresXML=featuresXML.replace(/\<FIELDVALUE\>/g,'<TD class="datalistfieldvalue" >');
        featuresXML=featuresXML.replace(/\<\/FIELDNAME\>/g,'</TD>');
        featuresXML=featuresXML.replace(/\<\/FIELDVALUE\>/g,'</TD>');
        info='<TABLE class="datalisttable" >'+
             '<TR><TD colspan="2" >'+this.Desc+': '+this.Count+'</TD></TR>'+
             featuresXML+'</TABLE>';
        break;
      default:
        featuresXML=fEscapeValues(featuresXML,0);
        featuresXML=featuresXML.replace(/\<FEATURE\>/g,'<TR class="datalistheader" ><TD colspan="2" >');
        featuresXML=featuresXML.replace(/\<\/FEATURE\>/g,'</TD></TR>' );
        featuresXML=featuresXML.replace(/\<FIELDS\>/g,'');
        featuresXML=featuresXML.replace(/\<\/FIELDS\>/g,'');
        featuresXML=featuresXML.replace(/\<FIELD\>/g,'<TR class="datalistfields" >');
        featuresXML=featuresXML.replace(/\<\/FIELD\>/g,'</TR>');
        featuresXML=featuresXML.replace(/\<FEATUREINDEX\>/g,'<TR><TD colspan="2" class="datalistfieldcount" >Index:');
        featuresXML=featuresXML.replace(/\<\/FEATUREINDEX\>/g,'</TD></TR>');
        featuresXML=featuresXML.replace(/\<FIELDNAME\>/g,'<TD class="datalistfieldname" >');
        featuresXML=featuresXML.replace(/\<FIELDVALUE\>/g,'<TD class="datalistfieldvalue" >');
        featuresXML=featuresXML.replace(/\<\/FIELDNAME\>/g,'</TD>');
        featuresXML=featuresXML.replace(/\<\/FIELDVALUE\>/g,'</TD>');
        info='<TABLE class="datalisttable" >'+
             '<TR><TD colspan="2" >'+this.Desc+': '+this.Count+'</TD></TR>'+
             featuresXML+'</TABLE>';
        break;
    }
    this.Div = info; 
  }
  
  function fChangeLayerXML(obj,layer,xmlChangeTag,xmlNewVal)
  {
    
    xml=fChangeLayerONEXML(obj,obj.GetRequestXML(),layer,xmlChangeTag,xmlNewVal)
    obj.SetRequestXML(xml);

    xml=fChangeLayerONEXML(obj,obj.GetResponseXML(),layer,xmlChangeTag,xmlNewVal)
    obj.SetNewResponseXML(xml);
  }

  function fGetLayerXML(xml,layer,xmlTag)
  {
    var START='<LAYER>';
    var END='</LAYER>';
    pos=0
    while(xml.indexOf(START,pos)>0)
    {     
      aStartPos=xml.indexOf(START,pos);
      if (xml.indexOf(END,aStartPos+1)>0)
      {
        aEndPos=xml.indexOf(END,aStartPos+1);         
        val=xml.substr(aStartPos,(aEndPos-aStartPos)+END.length);
        layerID=returnInfo(val,'LAYERAXLID')
        if (layerID.toUpperCase() == layer.toUpperCase() )
        {
          theXML=returnXML(val,xmlTag);
          aEndPos=aEndPos;
        }
        pos=aEndPos;
      }
    }
    return theXML
  }

  function fChangeLayerONEXML(obj,xml,layer,xmlChangeTag,xmlNewVal)
  {
    var START='<LAYER>';
    var END='</LAYER>';
    pos=0
    while(xml.indexOf(START,pos)>0)
    {     
      aStartPos=xml.indexOf(START,pos);
      if (xml.indexOf(END,aStartPos+1)>0)
      {
        aEndPos=xml.indexOf(END,aStartPos+1);         
        val=xml.substr(aStartPos,(aEndPos-aStartPos)+END.length);
        layerID=returnInfo(val,'LAYERAXLID')
        if (layerID.toUpperCase() == layer.toUpperCase() )
        {
          theOrigXML=returnXML(val,xmlChangeTag);
          theNewXML='<'+xmlChangeTag+'>'+xmlNewVal+'</'+xmlChangeTag+'>'
          var reg = new RegExp(theOrigXML,'gi');
          xml=xml.replace(reg,theNewXML);
          aEndPos=aEndPos;
        }
        pos=aEndPos;
      }
    }
    return xml
  }

  //get legend TOC
  function fGetLegend(obj,xml)
  {
    startDiv = '<div class="tocbox" >';
    endDiv = '</div>';

    startSpan = '<span>';
    endSpan = '</span>';
    mapscale=Number(obj.GetTag(obj.GetResponseXML(),'MAPSCALE'));
    xml=fRemoveTags(xml,'FIELDS',0);
    xml=fRemoveTags(xml,'LAYERSELECTIONS',0);
    xml=fRemoveTags(xml,'LAYEREXTENT',0);
    xml=fRemoveTags(xml,'SELECTIONMETHOD',0);
    xml=fRemoveTags(xml,'LAYERCOUNT',0);
    xml=fRemoveTags(xml,'LAYERINDEX',0);
    xml=fRemoveTags(xml,'LAYERTYPE',0);
    xml=fRemoveTags(xml,'LAYERFCTYPE',0);
    xml=fRemoveTags(xml,'LAYEREXTENSION',0);
    xml=fRemoveTags(xml,'LAYEREXTENSIONTYPE',0);
    
    var START='<LAYER>';
    var END='</LAYER>';
    pos=0
    while(xml.indexOf(START,pos)>0)
    {     
      aStartPos=xml.indexOf(START,pos);
      if (xml.indexOf(END,aStartPos+1)>0)
      {       
        aEndPos=xml.indexOf(END,aStartPos+1);
        val=xml.substr(aStartPos,(aEndPos-aStartPos)+END.length);

        legxml=returnXML(val,'LAYERLEGENDS');
        var STARTin='<LAYER_LEGEND>';
        var ENDin='</LAYER_LEGEND>';
        posin=0
        replegxml='';
        while(legxml.indexOf(STARTin,posin)>0)
        {     
          aStartPosin=legxml.indexOf(STARTin,posin);
          if (legxml.indexOf(ENDin,aStartPosin+1)>0)
          {       
            aEndPosin=legxml.indexOf(ENDin,aStartPosin+1);
            aval=legxml.substr(aStartPosin,(aEndPosin-aStartPosin)+ENDin.length);
            minscale=Number(returnInfo(aval,'LAYER_LEGEND_MINSCALE'));
            maxscale=Number(returnInfo(aval,'LAYER_LEGEND_MAXSCALE'));             
            //get legend swatch for current scale
            if( mapscale < maxscale && mapscale > minscale )
            {
              replegxml=returnXML(aval,'LAYER_LEGEND_URL')
              break;
            }
            else
            {
              posin=aStartPosin+1;
            }
          }
        }
        //prompt('',val);
        layerXML=returnXML(val,'LAYERAXLID')
        layerID=returnInfo(val,'LAYERAXLID')
        vistxt=returnInfo(val,'LAYERVISIBLE')
        activeTxt=returnInfo(val,'LAYERACTIVE')

        if(vistxt.toUpperCase() == 'true'.toUpperCase())
        {
          clckval='false';
          vistxt='CHECKED';
          laystr='LAYEROFF';
        }else{
          clckval='true';
          vistxt='';
          laystr='LAYERON';
        }

        if(activeTxt.toUpperCase() == 'true'.toUpperCase())
        {
          color='rgb(135,206,250)';
          imgtxt='AC_';
        }else{
          color='white';
          imgtxt='NA_';
        }

        clickstr=obj.Name+'.SendTool(\''+laystr+'\',\'USERSETTING\','+obj.Name+',\''+layerID+'\');'+
                 obj.Name+'.ToolSet('+obj.Name+',\''+laystr+'\');';

        clickstrTwo=obj.Name+'.SendTool(\'LAYERACTIVE\',\'USERSETTING\','+obj.Name+',\''+layerID+'\');'+
                 obj.Name+'.ToolSet('+obj.Name+',\'LAYERACTIVE\');';

        if (mapscale>maxscale || mapscale<minscale){disTxt='disabled';classTxt='textgraysm';}else{disTxt='';classTxt='textblackvsmbold';}

        layervisHTML='<div style="background-color:'+color+';"  >'+
                     '<INPUT ID="'+layerID+'" '+vistxt+
                         ' '+disTxt+' NAME="'+layerID+'" '+
                         'TYPE="checkbox" REPLACE_VISIBLITY '+
                         'onclick="'+clickstr+'" style="vertical-align:top;cursor:default;"  />'+
                      '<span class="'+ classTxt +'" id="'+layerID+'" style="background-color:'+color+';"  onclick="'+clickstrTwo+'" >'

        repval=layervisHTML;
        var reg = new RegExp(layerXML,'i');
        xml=xml.replace(reg,repval);
        if(replegxml.length==0){replegxml='<LAYER_LEGEND_URL>BLANK.jpg</LAYER_LEGEND_URL>';}

        var reg = new RegExp('<LAYER_LEGEND_URL>','i');
        replegxml=replegxml.replace(reg,'<br /><IMG id="img_'+layerID+'" SRC="../../IMAGES/legends/'+imgtxt);  //<LAYER_LEGEND_URL>

        var reg = new RegExp('</LAYER_LEGEND_URL>','i');
        replegxml=replegxml.replace(reg,'" ALT="LEGEND" onclick="this.style.display=\'none\';" />');

        //toggle  legend by id function gets id display=none xml = false start with false
        repval=replegxml;
        var reg = new RegExp(legxml,'i');
        xml=xml.replace(reg,repval);

        aEndPos=aEndPos-legxml.length
        pos=aEndPos;
      }
    }

    xml=fReplace(xml,'<LAYERLIST>',startDiv)
    xml=fReplace(xml,'</LAYERLIST>',endDiv)

    xml=fRemoveTags(xml,'LAYERVISIBLE',0);
    xml=fRemoveTags(xml,'LAYERACTIVE',0);

    xml=fReplace(xml,'<LAYER>',startDiv )
    xml=fReplace(xml,'</LAYER>',endSpan+endDiv+endDiv)

    xml=fReplace(xml,'<LAYERNAME>','')
    xml=fReplace(xml,'</LAYERNAME>','')

    //xml=fReplace(xml,'<LAYER_LEGEND_URL>','<br /><IMG SRC="../../IMAGES/legends/')
    //xml=fReplace(xml,'</LAYER_LEGEND_URL>','" ALT="LEGEND" onclick="this.style.display=\'none\';" />')

    return xml;
  }

  //get legend - simple
  function fGetSimpleLegend(obj,xml)
  {
    startDiv = '<div class="tocboxsimple" >';
    endDiv = '</div>';

    startImg = '<img src="../../IMAGES/legends/NA_';
    endDImg = '" alt="legend" />';

    mLeg = '';
    mapscale=Number(obj.GetTag(obj.GetResponseXML(),'MAPSCALE'));
    
    var START='<LAYER>';
    var END='</LAYER>';
    pos=0
    while(xml.indexOf(START,pos)>0)
    {     
      aStartPos=xml.indexOf(START,pos);
      if (xml.indexOf(END,aStartPos+1)>0)
      {       
        aEndPos=xml.indexOf(END,aStartPos+1);
        val=xml.substr(aStartPos,(aEndPos-aStartPos)+END.length);

        legxml=returnXML(val,'LAYERLEGENDS');
        var STARTin='<LAYER_LEGEND>';
        var ENDin='</LAYER_LEGEND>';
        posin=0
        replegxml='';
        while(legxml.indexOf(STARTin,posin)>0)
        {     
          aStartPosin=legxml.indexOf(STARTin,posin);
          if (legxml.indexOf(ENDin,aStartPosin+1)>0)
          {       
            aEndPosin=legxml.indexOf(ENDin,aStartPosin+1);
            aval=legxml.substr(aStartPosin,(aEndPosin-aStartPosin)+ENDin.length);
            minscale=Number(returnInfo(aval,'LAYER_LEGEND_MINSCALE'));
            maxscale=Number(returnInfo(aval,'LAYER_LEGEND_MAXSCALE'));             
            //get legend swatch for current scale
            if( mapscale < maxscale && mapscale > minscale )
            {
              LegTag=obj.GetTag(aval,'LAYER_LEGEND_URL')
              LegName=obj.GetTag(val,'LAYERNAME')
              mLeg = mLeg + startDiv + LegName + '<br />' + startImg  + LegTag + endDImg + endDiv 
              break;
            }
            else
            {
              posin=aStartPosin+1;
            }
          }
        }
        aEndPos=aEndPos
        pos=aEndPos;
      }
    }
    return startDiv + mLeg + endDiv ;
  }


  //remove tags and their vales in text verions of xml.
  function fRemoveAllTagValues(xml,tag,pos)
  {
    var value;
    var repvalue;
    var aStartPos;
    var aEndPos;
    var START='<'+tag+'>';
    var END='</'+tag+'>';
    RetVal = "";
    while(xml.indexOf(START,pos)>0)
    {     
      aStartPos=xml.indexOf(START,pos);
      if (xml.indexOf(END,aStartPos)>0)
      {
        aStartPos=xml.indexOf(START,pos);
        aStartPos=xml.indexOf('>',aStartPos);
        aEndPos=xml.indexOf(END,aStartPos)
        val = xml.substring(aStartPos+1,aEndPos);
        if (val.length>0){xml=fReplace(xml,val,'');}
        pos=aEndPos;
      }
    }
    return xml;
  }

  //remove tags and their vales in text verions of xml.
  function fRemoveTags(xml,tag,pos)
  {
    var value;
    var repvalue;
    var aStartPos;
    var aEndPos;
    var START='<'+tag+'>';
    var END='</'+tag+'>';
    RetVal = "";
    while(xml.indexOf(START,pos)>0)
    {     
      aStartPos=xml.indexOf(START,pos);
      if (xml.indexOf(END,aStartPos)>0)
      {
        val=returnXML(xml,tag);
        xml=replaceValue(xml,tag,''); 
        xml=fReplace(xml,START+END,'')
        pos=aEndPos;
      }
    }
    return xml;
  }

  //escape values for http links
  function fEscapeValuesCustom(xml,mTag,pos)
  {
    var value;
    var repvalue;
    var aStartPos;
    var aEndPos;
    var START='<'+mTag+'>';
    var END='</'+mTag+'>';
    RetVal = "";
    
    while(xml.indexOf(START,pos)>0)
    {
      aStartPos=xml.indexOf(START,pos);
      aStartPos=aStartPos+START.length;
      if (xml.indexOf(END,aStartPos)>0)
      {
        aEndPos=xml.indexOf(END,aStartPos);
        value=xml.substr(aStartPos,aEndPos-aStartPos);
        repvalue=unescape(value);
        repvalue=repvalue.replace(/\+/g, " ");
        xml=xml.replace(START+value+END,START+repvalue+END);
        pos=aEndPos;
      }else{pos=START.length;}
    }
    return xml;
  }

  //escape values for http links
  function fEscapeValues(xml,pos)
  {
    var value;
    var repvalue;
    var aStartPos;
    var aEndPos;
    var START='<FIELDVALUE>';
    var END='</FIELDVALUE>';
    RetVal = "";
    while(xml.indexOf(START,pos)>0)
    {
      aStartPos=xml.indexOf(START,pos);
      aStartPos=aStartPos+START.length;
      if (xml.indexOf(END,aStartPos)>0)
      {
        aEndPos=xml.indexOf(END,aStartPos);
        value=xml.substr(aStartPos,aEndPos-aStartPos);
        repvalue=unescape(value);
        repvalue=repvalue.replace(/\+/g, " ");
        xml=xml.replace(START+value+END,START+repvalue+END);
        pos=aEndPos;
      }else{pos=START.length;}
    }
    return xml;
  }

  //get the buisness table id ie gis. sde. pds.
  function getBUID( mFName )
  {
    var TempVal;
    var RetVal;
    var BUID;
    var aPos
    RetVal = "";

    if (mFName.indexOf(".") > 0){
      aPos = mFName.indexOf(".");
      TempVal = mFName.substr( 0 , aPos+1);
      RetVal = mFName.replace( TempVal , "" );
      BUID=TempVal
      //recursive call to remove any additional qualifers
      if (RetVal.indexOf(".") > 0){
        BUID = BUID + getBUID( RetVal );
      }
    }else{
      BUID = '';
    }
    return BUID;
  }

  //function to do nothing at all
  function fDoNothing(){return '';};

  //function clear all actions - buttons,tools,usersettings
  function fClearActions(obj)
  {
    var val='SET';
    var xml=obj.GetRequestXML()
    var tag='TOOLACTION';
    xml=replaceValue(xml,tag,val);
    var tag='BUTTONACTION';
    xml=replaceValue(xml,tag,val);
    var tag='USERSETTINGACTION';
    xml=replaceValue(xml,tag,val);
    obj.SetRequestXML(xml);
    return xml;
  } 
 
  //function iterates through all tools and displays them
  function fShowTools(bar,name,obj)
  {
    var txt='';
    ray=obj.UI;
    var ele=fAddDivHTML(bar,txt);   //clear tool bar
    //loop through ui array and display each tool
    for (i=0;i<ray.length;i++)
    {
      var val=obj.UI[i];
      fShowTool(val,bar,name); //add user interface tool 
    }
    fAddToolClicks(bar,name,'ui',obj)
  }

  //adds user defined event to a user defined HTMLDOM element with a user defined function
  function fAddUserEventFull(eleName,type,func,obj)
  {
        obj.AddListener(eleName,type,func,obj);
  }

  //Removes user defined event to a user defined HTMLDOM element with a user defined function
  function fRemoveUserEventFull(eleName,type,func,obj)
  {
        obj.RemoveListener(eleName,type,func);   
  }

  //adds tool user defined event for map when interaction takes place
  function fAddUserEvent( obj )
  {
      eleName='mapLoading';
      ray=obj.UList;
      //loop through User event array and add change event
      for (i=0;i<ray.length;i++)
      {
        var val=obj.UList[i];
        obj.AddListener( eleName, 'load' , val , obj );
      }
  }

  //function prepares print url to send to print engine - so we can post the form to the print engine
  function fOpenPrint(string)
  {

    string=fReplace(string,'','')
    string=unescape(string)
    string=fReplace(string,'../PDF/SendPDF.php','')

    srchStart = '&';
    srchSep = '=';
    srchEnd = '&';

    inputstr='';
    pos = 0;
    formstringST='<form name="ML" method="post" action="../../'+mshuplocstr+'/pdf/MapPDF.php" target="_Blank" >'
    fPos = string.indexOf('?',pos)

    //parse each get variable & and = are delimeters
    while (fPos>-1)
    {
      
      ePos=string.indexOf(srchEnd,fPos+1);
      varStr=string.substring(fPos+1,ePos);
      fPos = string.indexOf(srchEnd,fPos+1);
      if(fPos>-1)
      {
        var ary=varStr.split('=')
        name=ary[0];
        value=ary[1];
        value=fReplace(value,'"','\'');
        inputstr = inputstr + '<input type="hidden" name="'+name+'" value="'+value+'" />';
      }
    }

    //write form so can post large amount of data
    formstringEnd = '</form>';
    formstring = formstringST + inputstr + formstringEnd;
    document.getElementById('mapPrintForm').innerHTML = formstring;
    document.ML.submit();

  }

  //function to check for processing and then print
  function fGetPrint(obj)
  {
    //AJAX retreval in process
    if(obj.SetResponseXML()+'' == 'undefined' )
    { window.setTimeout(function(){fGetPrint(obj);},5);}
    else{window.setTimeout(function(){fOpenPrint(obj.GetTag(obj.GetResponseXML(),'PRINTRESULTS'))},5);} //AJAX complete open print
  }

  //adds click for type of script
  function fSetBtnScript(action,obj,btn)
  {
    if(action)
    {
    switch(action.toUpperCase())
    {
      //create a letter size map portraits
      case 'QUICK PRINT (HIGH QUALITY)':
        //make usersetting string and send it to the framework
        newAction='Print Map';
        newActionName='USERSETTING';
        newActionValue='[ORIENTATION]=Portrait;'+
                    '[PRINTSIZE]=Letter;'+
                    '[MAPSCALE]='+obj.GetTag(obj.GetResponseXML(),'MAPSCALE')+';'+
                    '[MAPTITLE]=mapAsheville - Printed Map;'+
                    '[MAPSOURCE]=mapAsheville - Simple Viewer;'+
                    '[DATASOURCE]=City of Asheville GIS;'+
                    '[PRINTDATE]='+fGetDate()+';'+
                    '[QUALITY]=HIGH;'+
                    '[REPORTTYPE]=QUICKMAP;'+
                    '[DISCLAIMER]=;'+
                    '[REPORTTEXT]=TEST;[REPORTNAME]=TEST;[REPORTMAPHEIGHT]=380;[REPORTMAPWIDTH]=400;'

        obj.ToolSet(obj,newAction);
        obj.SendTool(newAction,newActionName,obj,newActionValue);
        fGetPrint(obj);
        break;
      case 'QUICK PRINT':
        //make usersetting string and send it to the framework
        newAction='Print Map';
        newActionName='USERSETTING';
        newActionValue='[ORIENTATION]=Portrait;'+
                    '[PRINTSIZE]=Letter;'+
                    '[MAPSCALE]='+obj.GetTag(obj.GetResponseXML(),'MAPSCALE')+';'+
                    '[MAPTITLE]=mapAsheville - Printed Map;'+
                    '[MAPSOURCE]=mapAsheville - Simple Viewer;'+
                    '[DATASOURCE]=City of Asheville GIS;'+
                    '[PRINTDATE]='+fGetDate()+';'+
                    '[QUALITY]=LOW;'+
                    '[REPORTTYPE]=QUICKMAP;'+
                    '[DISCLAIMER]=;'+
                    '[REPORTTEXT]=TEST;[REPORTNAME]=TEST;[REPORTMAPHEIGHT]=380;[REPORTMAPWIDTH]=400;'

        obj.ToolSet(obj,newAction);
        obj.SendTool(newAction,newActionName,obj,newActionValue);
        fGetPrint(obj);
        break;
      //Get att table for selected features limited by specified field if none activelayers objectid
      case 'VIEW FIELD TABLE LAYER':
        //make usersetting string and send it to the framework
        newAction='View Field Table Layer';
        newActionName='USERSETTING';
        newActionValue='[LAYER]=;'+
                    '[FIELDS]=;'
        obj.ToolSet(obj,newAction);
        obj.SendTool(newAction,newActionName,obj,newActionValue);
        break;
      //Get att table for selected features
      case 'VIEW TABLE (SELECTED)':
        //make usersetting string and send it to the framework
        newAction='View Table Layer';
        newActionName='USERSETTING';
        newActionValue='[LAYER]=;';
        obj.ToolSet(obj,newAction);
        obj.SendTool(newAction,newActionName,obj,newActionValue);
        break;
      //create a non-ineractive legend box
      case 'GET LEGEND':
        tag='LAYERLIST';
        xml=obj.GetXML(obj.GetResponseXML(),tag);
        var mLeg = fGetSimpleLegend(obj,xml);
        //ensure results div exists use this as a clone
        if(document.getElementById('mapResults'))
        {
          idTxt='SimpleLegend';
          myDiv=document.getElementById('mapResults')
          //if cloned div exists then remove the div to restablish the scale dependicies
          if(document.getElementById('SimpleLegend')){document.body.removeChild(document.getElementById('SimpleLegend'));}
          //if cloned div does not exist then make it
          if(!document.getElementById('SimpleLegend'))
          {
            var cloneDiv=myDiv.cloneNode(false); 
            cloneDiv.id=idTxt;
            //Simple legend div width 
            mLeg='<iframe id="frmLegBlocker"style="position:absolute;top:0px;left:0px;background-color:white;width:150px;height:150px;visibility:hidden;"  src="javascript:false;" frameBorder="0" scrolling="no " >' +
                 '</iframe>'+
                 '<div id="legendBox" style="position:absolute;width:200px;border:1px solid dodgerblue;background:white;padding:2px 2px 2px 2px;z-index:4;" onclick="xZIndex( this.id ,highZ++ );" >' +
                 '  <div id="legendBoxDrag" class="mapTitleTxt" style="border:1px solid dodgerblue;padding:2px 2px 2px 2px;z-index:4;" >' +
                 '    Legend' +
                 '  </div>' +
                 '  <div class="textwhitesm" style="position:relative;top:-17px;width:45px;left:145;padding:1px 1px 1px 1px;border:1px solid white;background-color:#D2691E;cursor:pointer;"  onclick="xHide(\'legendBox\');xHide(\'frmLegBlocker\');" >' +
                 '    Close x' +
                 '  </div>' +
                 '  <div id="legends" style="width:192px;height:400px;padding:2px 2px 2px 2px;overflow:scroll;z-index:4;" >' +
                 mLeg +
                 '  </div>' +
                 '</div>'
            //Set up clone div
            cloneDiv.innerHTML=mLeg;
            document.body.appendChild(cloneDiv);  
            fDivClr(cloneDiv,'DodgerBlue');
            fDivZ(cloneDiv.id,'100000');
            //Set inital position of legend div just offset of map div 
            var loc = new fAdjDiv(obj.GetMapDiv());
            var mTop = loc.Y+5;
            var mLeft = loc.X+5;   
            fPositionDiv('legendBox',mTop,mLeft)
            fPositionDiv('frmLegBlocker',mTop,mLeft);
            //make the leg div visible and 
            fDivVis(idTxt,'visible');
            //enable draging with the ie blocker may make this active at a later time
            //DragSetup( 'legendBox' , 'frmLegBlocker' )
          }
        }
        break;
      }
    }
  }

  //function to get Current Date String
  function fGetDate()
  {
    //get date
    var d=new Date()
    var month=new Array(12)

    month[0]="January"
    month[1]="February"
    month[2]="March"
    month[3]="April"
    month[4]="May"
    month[5]="June"
    month[6]="July"
    month[7]="August"
    month[8]="September"
    month[9]="October"
    month[10]="November"
    month[11]="December"

    var weekday=new Array(7)
    weekday[0]="Sunday"
    weekday[1]="Monday"
    weekday[2]="Tuesday"
    weekday[3]="Wednesday"
    weekday[4]="Thursday"
    weekday[5]="Friday"
    weekday[6]="Saturday"

    DateStr = weekday[d.getDay()] + ', ' + month[d.getMonth()] + ' ' + d.getDate() + ', ' +  d.getFullYear();
    return DateStr;
  }

  //adds tool onclick event to the user interface
  function fAddToolClicks(bar,name,uiname,obj)
  {
    if(document.getElementById(bar))
    {
      var imgs=document.getElementsByName(uiname);
      //loop through img array and add click for each tool in the UI
      for (i=0;i<imgs.length;i++)
      {
        document.getElementById(imgs[i].id).onclick=function()
        {
          action=returnInfo(this.id,'ACTION');
          actionName=returnInfo(this.id,'NAME');
          actionValue=returnInfo(this.id,'VALUE');
          if(actionName=='SCRIPT'){fSetBtnScript(action,obj);}
          if(actionName=='BUTTON'){obj.ToolSet(obj,action);obj.SendTool(action,actionName,obj);}
          if(actionName=='USERSETTING'){obj.ToolSet(obj,action);obj.SendTool(action,actionName,obj,actionValue);}
          if(action != 'Clear')
          {
            if(actionName=='TOOL'){obj.ToolSet(obj,action);obj.MapClicks.ContinueSelect = true;fToolClick(bar,this,uiname);}
          }else{
            if(actionName=='TOOL'){fToolClear(bar);}
          }
        }       
      }
    }
  }

  function fToolSet(obj,name)
  {
    obj.SetToolVal(name);
    var type=4;
    obj.MapClicks.KeepGrahpics=false;
    switch(name.toUpperCase())
    {
      case 'ZOOM IN':type=3;break;
      case 'ZOOM OUT':type=3;break;
      case 'PAN':type=5;break;
      case 'IDENTIFY':type=4;break;
      case 'MEASURE':type=4;break;
      case 'SELECT BY POINT':type=4;break;
      case 'SELECT BY LINE':type=1;break;
      case 'DRAW POINT':type=4;obj.MapClicks.KeepGrahpics=true;break;
      case 'DRAW LINE':type=1;obj.MapClicks.KeepGrahpics=true;break;
      case 'DRAW RECTANGLE':type=3;obj.MapClicks.KeepGrahpics=true;break;
      case 'DRAW POLYGON':type=2;obj.MapClicks.KeepGrahpics=true;break;
      case 'DRAW POINT CS':type=4;obj.MapClicks.KeepGrahpics=true;break;
      case 'DRAW LINE CS':type=1;obj.MapClicks.KeepGrahpics=true;break;
      case 'DRAW RECTANGLE CS':type=3;obj.MapClicks.KeepGrahpics=true;break;
      case 'DRAW POLYGON CS':type=2;obj.MapClicks.KeepGrahpics=true;break;
      case 'SELECT BY RECTANGLE':type=3;break;
      case 'SELECT BY POLYGON':type=2;break;
      case '':type=4;break;
    }
    //set click values
    obj.MapClicks.ContinueSelect=true;
    obj.MapClicks.ClearClicks(obj);
    obj.MapClicks.aShapeType=type;
    obj.MapClicks.SetClickMin(type);
  }

  //function to setup and display tool button
  function fShowTool(val,bar,name)
  {
    //Default set up new user interface
    var toolW=16;
    var toolH=16;
    var imgDir='../../IMAGES/ArcIMSFrameWork/';
    var mID;

    //var uiNameID='ui_'+val;
    var type='BUTTON';
    mID='<ONCLICK><ACTION>Zoom to Full Extent</ACTION><NAME>'+type+'</NAME></ONCLICK>'
    var imgSrc=imgDir+'ArcIMSFrameWork_blank.gif';

    //get existing toolbar html-text
    var mHtml=fGetDivHTML(bar);
    switch(val)
    {

      case 'Clear All Selected Features':
        type='BUTTON';
        imgSrc=imgDir+'ArcIMSFrameWork_ClearAllSelected.gif';
        break;
      case 'Clear All Selected':
        type='BUTTON';
        imgSrc=imgDir+'ArcIMSFrameWork_ClearAllSelected.gif';
        break;
      case 'Clear Selected in Layer':
        type='BUTTON';
        imgSrc=imgDir+'ArcIMSFrameWork_ClearSelected.gif';
        break;
      case 'Clear':  //tool does nothing for adding custom functionality
        type='TOOL';
        imgSrc=imgDir+'ArcIMSFrameWork_blank.gif';
        break;
      case 'Clear Selection':  
        type='TOOL';
        imgSrc=imgDir+'ArcIMSFrameWork_blank.gif';
        break;
      case 'Identify':
        type='TOOL';
        imgSrc=imgDir+'ArcIMSFrameWork_Identify_Color.gif';
        break;
      case 'Refresh':
        type='BUTTON';
        imgSrc=imgDir+'ArcIMSFrameWork_Refresh_BW.gif';
        break;
      case 'Pan':
        type='TOOL';
        imgSrc=imgDir+'ArcIMSFrameWork_Pan_Color.gif';
        break;
      case 'Zoom In':
        type='TOOL';
        imgSrc=imgDir+'ArcIMSFrameWork_ZoomIn_Color.gif';
        break;
      case 'Zoom In One':
        type='BUTTON';
        imgSrc=imgDir+'ArcIMSFrameWork_ZoomIn_One.gif';
        break;
      case 'Zoom Out':
        type='TOOL';
        imgSrc=imgDir+'ArcIMSFrameWork_ZoomOut_Color.gif';
        break;
      case 'Zoom Out One':
        type='BUTTON';
        imgSrc=imgDir+'ArcIMSFrameWork_ZoomOut_One.gif';
        break;
      case 'Zoom to Full Extent':
        type='BUTTON';
        imgSrc=imgDir+'ArcIMSFrameWork_ZoomFull_Color.gif';
        break;
      case 'Zoom to Extent of Layer':
        type='BUTTON';
        imgSrc=imgDir+'ArcIMSFrameWork_ZoomLayerExtent_Color.gif';
        break;
      case 'Zoom to Selected Extent':
        type='BUTTON';
        imgSrc=imgDir+'ArcIMSFrameWork_ZoomSelected_Color.gif';
        break;
      case 'Get Legend':
        type='SCRIPT';
        imgSrc=imgDir+'ArcIMSFrameWork_Legend.gif';
        break;
      case 'View Table (Selected)':
        type='SCRIPT';
        imgSrc=imgDir+'ArcIMSFrameWork_ViewTable_Color.gif';
        break;
      case 'View Field Table Layer':
        type='SCRIPT';
        imgSrc=imgDir+'ArcIMSFrameWork_ViewTable_Color.gif';
        break;
      case 'Quick Print':
        type='SCRIPT';
        imgSrc=imgDir+'ArcIMSFrameWork_Print_Color.gif';
        break;
      case 'Quick Print (High Quality)':
        type='SCRIPT';
        imgSrc=imgDir+'ArcIMSFrameWork_Print_Color.gif';
        break;
      case 'Zoom to Previous Extent':
        type='BUTTON';
        imgSrc=imgDir+'ArcIMSFrameWork_ZoomPrevExtent_BW.gif';
        break;
      case 'Zoom to Next Extent':
        type='BUTTON';
        imgSrc=imgDir+'ArcIMSFrameWork_ZoomNextExtent_BW.gif';
        break;
      case 'Select by Point':
        type='TOOL';
        imgSrc=imgDir+'ArcIMSFrameWork_SelectPoint_Color.gif';
        break;
      case 'Select by Polygon':
        type='TOOL';
        imgSrc=imgDir+'ArcIMSFrameWork_SelectPoly_Color.gif';
        break;
      case 'Select by Line':
        type='TOOL';
        imgSrc=imgDir+'ArcIMSFrameWork_SelectLine_Color.gif';
        break;
      case 'Select by Rectangle':
        type='TOOL';
        imgSrc=imgDir+'ArcIMSFrameWork_SelectRect_Color.gif';
        break;

      default:break;
    }
    //add to user interface
    mID='<ONCLICK><ACTION>'+val+'</ACTION><NAME>'+type+'</NAME></ONCLICK>'; 
    //mouse over and out styles
    msover='fEleClass(this,\'mashuptoolon\')'
    msout='fEleClass(this,\'mashuptooloff\')'
    var starter='<a title="'+val+'" name="'+val+'" id="uitool" class="mashuptooloff" style="width:'+toolW+'px;height:'+toolH+'px;" onmouseover="'+msover+'" onmouseout="'+msout+'" >';
    var ender='</a>';
    var mImg=starter+'<img id="'+mID+'" name="ui" src="'+imgSrc+'" alt="'+val+'" class="mashuptoolimgnotclicked" style="width:'+toolW+'px;height:'+toolH+'px;" />'+ender;
    fAddDivHTML(bar,mHtml+mImg);
  }

  //makes all tools appear "unclicked" 
  function fToolClear(bar)
  { 
    if(document.getElementById(bar))
    {
      var imgs=document.getElementsByName("ui");
      //loop through img array and add click for each tool in the UI
      for (i=0;i<imgs.length;i++)
      {
        fEleClass(imgs[i],'mashuptoolimgnotclicked')
      }
    }
  }

  //makes tool appear "clicked"
  function fToolClick(bar,tool,uiname,cType)
  {

    if(uiname=='ui'){cType='';}
    if(document.getElementById(bar))
    {
      var imgs=document.getElementsByName(uiname);
      //loop through img array and add click for each tool in the UI
      for (i=0;i<imgs.length;i++)
      {
        fEleClass(imgs[i],'mashuptool'+cType+'imgnotclicked')
      }
    }
    //Set clicked tool to appear clicked
    fEleClass(tool,'mashuptool'+cType+'imgclicked')
  }

  //forces x y to change when map refreshes.
  function fStartXY()
  {
    //force x,y change
    var ele=document.getElementById('mapHolder');
    fFireMouseEvent(ele,'mouseover');
    var ele=document.getElementById('mapDraw');
    fFireMouseEvent(ele,'mouseover');
  }

  function testch(){alert('here');}
  function TempDraw(obj)
  {
    x=Number(obj.MapClicks.ImageX[obj.MapClicks.ClickCount]);
    y=Number(obj.MapClicks.ImageY[obj.MapClicks.ClickCount]);
    o=.0001;
    obj.MapClicks.DrawTwo.clear();
    obj.MapClicks.DrawTwo.setColor("#ff0000"); // red
    obj.MapClicks.DrawTwo.setOpacity(100);
    obj.MapClicks.DrawTwo.setStroke(2);
    o=.0001;
    obj.MapClicks.DrawTwo.drawLine(x-o,y-o,x+o,y+o);
    obj.MapClicks.DrawTwo.drawLine(x+o,y+o,x-o,y-o);
    obj.MapClicks.DrawTwo.paint();
  }

  //do nothing change function used in change listener but really does nothing
  function fChange(){}

  //sets up the x,y position in map units
  function fMoveXY(name,type,obj)
  {
    var eleX=document.getElementById('xPos');
    var eleY=document.getElementById('yPos');
    var eleMV=document.getElementById('mapEvent');       
    //y changed second so only change once otherwse converts converted value
    eleY.onchange=function()
                    {
                     obj.MapClicks.ConvertMousePosition(obj,eleX.value,eleY.value);
                     obj.MapClicks.Dragging(obj);
                     //fAfterSendStartXY(obj);
                    }
    eleMV.onchange=function()
                   {
                     var evt=eleMV.value;
                     imgX=obj.MapClicks.curImageX;
                     imgY=obj.MapClicks.curImageY;
                     mapX=obj.MapClicks.curMapX;
                     mapY=obj.MapClicks.curMapY;
                     shapetype=obj.MapClicks.aShapeType;
                     if(evt=='dblclick')
                     {
                         switch(shapetype)
                         {
                           case 1:  //line
                           fAddClick(obj);
                           if(obj.MapClicks.ClickCount>1){obj.MapClicks.ContinueSelect=false;}   
                           fSetCanvasDraw( obj.MapClicks.DrawOne);
                           var Shape = new fGetShape(obj,imgX,imgY);
                           fDrawShape(obj,obj.MapClicks.DrawOne,Shape);
                           obj.MapClicks.DrawOne.paint();
                           fAddClickXML(obj);
                           if(obj.GetTool().toUpperCase() != 'DRAW LINE'){obj.SendTool(obj.GetTool(),'TOOL',obj);}
                           break;
                         case 2:  //poly
                           fAddClick(obj);
                           if(obj.MapClicks.ClickCount>1){obj.MapClicks.ContinueSelect=false;}   
                           fSetCanvasDraw( obj.MapClicks.DrawOne );
                           var Shape = new fGetShape(obj,imgX,imgY);
                           fDrawShape(obj,obj.MapClicks.DrawOne,Shape);
                           fFillShape(obj,obj.MapClicks.DrawOne,Shape);
                           obj.MapClicks.DrawOne.paint();
                           fAddClickXML(obj);
                           if(obj.GetTool().toUpperCase() != 'DRAW POLYGON'){obj.SendTool(obj.GetTool(),'TOOL',obj);}
                           break;
                         default:break;
                       }
                     }
                     if(evt=='mousedown')
                     {
                         switch(shapetype)
                         {
                           case 1:  //line
                             if(obj.MapClicks.ContinueSelect==false){obj.MapClicks.ClearClicks(obj);obj.MapClicks.ContinueSelect=true;}
                             fAddClick(obj);
                             fSetCanvasDraw( obj.MapClicks.DrawOne);
                             var Shape = new fGetShape(obj,imgX,imgY);
                             fDrawShape(obj,obj.MapClicks.DrawOne,Shape);
                             obj.MapClicks.DrawOne.paint();
                             break;
                           case 2:  //poly
                             if(obj.MapClicks.ContinueSelect==false){obj.MapClicks.ClearClicks(obj);obj.MapClicks.ContinueSelect=true;}
                             fAddClick(obj);
                             fSetCanvasDraw( obj.MapClicks.DrawOne);
                             var Shape = new fGetShape(obj,imgX,imgY);
                             fDrawShape(obj,obj.MapClicks.DrawOne,Shape);
                             obj.MapClicks.DrawOne.paint();
                             break;
                           case 3:  //rectangle
                             fAddClick(obj);
                             break;
                           case 4:  //Point
                             fAddClick(obj);
                             fAddClickXML(obj);
                             if(obj.GetTool().toUpperCase() != 'DRAW POINT'){obj.SendTool(obj.GetTool(),'TOOL',obj);}
                             break;
                           case 5:  //Point - pan
                             if (obj.MapClicks.StartX == 0){fAddClick(obj);}
                             break;
                           default:break;
                         }
                     }
                     if(evt=='mouseup')
                     {
                       if (obj.MapClicks.ContinueSelect)
                       {
                         switch(shapetype)
                         {
                           case 1:  //line
                             obj.MapClicks.ButtonDown=false;
                             fAddClick(obj);
                             break;
                           case 2:  //poly
                             obj.MapClicks.ButtonDown=false;
                             fAddClick(obj);
                             break;
                           case 3:  //rectangle
                             obj.MapClicks.ButtonDown=false;
                             fAddClick(obj);
                             if(obj.MapClicks.ClickCount==1){obj.MapClicks.ContinueSelect=false;}                            
                             obj.MapClicks.DrawOne.clear();
                             fSetCanvasDraw( obj.MapClicks.DrawOne);
                             var Shape = new fGetShape(obj,imgX,imgY);
                             fDrawShape(obj,obj.MapClicks.DrawOne,Shape);
                             fFillShape(obj,obj.MapClicks.DrawOne,Shape);
                             obj.MapClicks.DrawOne.paint();
                             fAddClickXML(obj);
                             if(obj.GetTool().toUpperCase() != 'DRAW RECTANGLE'){obj.SendTool(obj.GetTool(),'TOOL',obj);}
                             break;
                           case 4:  //Point
                             obj.MapClicks.ButtonDown=false;
                             if(obj.MapClicks.ClickCount==0){obj.MapClicks.ContinueSelect=false;}                            
                             obj.MapClicks.DrawOne.clear();
                             fSetCanvasDraw(obj.MapClicks.DrawOne);
                             var Shape = new fGetShape(obj,imgX,imgY);
                             fDrawShape(obj,obj.MapClicks.DrawOne,Shape);
                             obj.MapClicks.DrawOne.paint();
                             fAddClickXML(obj);                            
                             mapScale=obj.GetTag(obj.GetResponseXML(),'MAPSCALE');
                             theTool=obj.GetTool();
                             if(obj.GetTool().toUpperCase() != 'DRAW POINT'){if( (theTool=='Identify')   && (Number(mapScale) < 250000) ){obj.SendTool(theTool,'TOOL',obj);}}
                             break;
                           case 5:  //Point - pan
                             obj.MapClicks.ButtonDown=false;
                             fAddClick(obj);
                             if(obj.MapClicks.ClickCount==1){obj.MapClicks.ContinueSelect=false;}
                             fAddClickXML(obj);
                             obj.SendTool(obj.GetTool(),'TOOL',obj);
                             break;
                           default:break;
                         }
	               }
                     }
                   }
  }

  //function to parse address and zip code
  function fParseAddress(txt)
  {
    zip = txt.replace(/[A-Za-z]/g,'');
    pos=zip.indexOf(' ',0);
    zip=zip.substr(pos,zip.length);
    zip = zip.replace(/\W/g,'');
    address = fReplace(txt,zip,'');
    pos=address.indexOf(',',0);
    if(pos>1){address= address.substr(0,pos);}
    return '[ADDRESS]='+address+';[ZIPCODE]='+zip+';'
  }

  // function moves element to new x y
  function fMoveIt(name, x, y)
  {
    if(document.getElementById(name))
    {
      var layer = document.getElementById(name).style;
      if( layer.position=='' ){layer.position = 'relative';}
      layer.left = x + "px";
      layer.top = y + "px";
      layer.overflow='hidden';
    }
  }

  //adds click mouse down events to app
  function fAddClick(obj)
  {
    //increment clickcount
    obj.MapClicks.ClickCount+=1;

    //image unties
    imgX=obj.MapClicks.curImageX;
    imgY=obj.MapClicks.curImageY;
    var idx=(Number(obj.MapClicks.ImageX.length));
    obj.MapClicks.ImageX[idx]=imgX;
    var idx=(Number(obj.MapClicks.ImageY.length));
    obj.MapClicks.ImageY[idx]=imgY;

    //map units
    mapX=obj.MapClicks.curMapX;
    mapY=obj.MapClicks.curMapY;
    var idx=(Number(obj.MapClicks.MapX.length));
    obj.MapClicks.MapX[idx]=mapX;
    var idx=(Number(obj.MapClicks.MapY.length));
    obj.MapClicks.MapY[idx]=mapY;
  }

  //clears user shape xml 
  function fClearUserShapes(obj,val)
  {
   
    if ((val.toUpperCase() == "CLEAR USER SHAPE") || (val.toUpperCase() == "CLEAR ALL SELECTED"))
    {
      var tag='USERSHAPEX';
      xml=replaceValue(obj.GetRequestXML(),tag,'');
      obj.SetRequestXML(xml);

      var tag='USERSHAPEY';
      xml=replaceValue(obj.GetRequestXML(),tag,'');
      obj.SetRequestXML(xml);

      var tag='USERSHAPETYPE';
      xml=replaceValue(obj.GetRequestXML(),tag,'');
      obj.SetRequestXML(xml);

      var tag='CLICKX';
      xml=replaceValue(obj.GetRequestXML(),tag,'');
      obj.SetRequestXML(xml);

      var tag='CLICKY';
      xml=replaceValue(obj.GetRequestXML(),tag,'');
      obj.SetRequestXML(xml);
    }  
  }
  function fAddClickXML(obj)
  {
     var mapX=obj.MapClicks.MapX.join(',');
     var mapY=obj.MapClicks.MapY.join(',');
     shapetype=obj.MapClicks.aShapeType;
     switch(shapetype)
     {
       case 1:  //line
         break;
       case 2:  //poly
         break;
       case 3:  //rectangle
         //fix drag for good box
         mapX=obj.MapClicks.MapX.sort().join(',');
         mapY=obj.MapClicks.MapY.sort().join(',');
         break;
       case 4:  //Point
         break;
       case 5:  //Point - pan
         //fix drag for good box
         mapX=obj.MapClicks.MapX.join(',');
         mapY=obj.MapClicks.MapY.join(',');
         break;
       default:break;
     }
   
    var tag='CLICKX';
    xml=replaceValue(obj.GetRequestXML(),tag,mapX);
    obj.SetRequestXML(xml);
    var tag='CLICKY';
    xml=replaceValue(obj.GetRequestXML(),tag,mapY);
    obj.SetRequestXML(xml);

     aTooltype=obj.GetTool().toUpperCase();
     //add userx usery and usershape
     switch(aTooltype)
     {
       case 'DRAW POINT':
         var tag='USERSHAPEX';
         xml=replaceValue(obj.GetRequestXML(),tag,mapX);
         obj.SetRequestXML(xml);

         var tag='USERSHAPEY';
         xml=replaceValue(obj.GetRequestXML(),tag,mapY);
         obj.SetRequestXML(xml);

         var tag='USERSHAPETYPE';
         xml=replaceValue(obj.GetRequestXML(),tag,shapetype);
         obj.SetRequestXML(xml);
         break;
       case 'DRAW LINE':
         var tag='USERSHAPEX';
         xml=replaceValue(obj.GetRequestXML(),tag,mapX);
         obj.SetRequestXML(xml);

         var tag='USERSHAPEY';
         xml=replaceValue(obj.GetRequestXML(),tag,mapY);
         obj.SetRequestXML(xml);

         var tag='USERSHAPETYPE';
         xml=replaceValue(obj.GetRequestXML(),tag,shapetype);
         obj.SetRequestXML(xml);
         break;
       case 'DRAW RECTANGLE':
         var tag='USERSHAPEX';
         xml=replaceValue(obj.GetRequestXML(),tag,mapX);
         obj.SetRequestXML(xml);

         var tag='USERSHAPEY';
         xml=replaceValue(obj.GetRequestXML(),tag,mapY);
         obj.SetRequestXML(xml);

         var tag='USERSHAPETYPE';
         xml=replaceValue(obj.GetRequestXML(),tag,shapetype);
         obj.SetRequestXML(xml);
         break;
       case 'DRAW POLYGON':
         var tag='USERSHAPEX';
         xml=replaceValue(obj.GetRequestXML(),tag,mapX);
         obj.SetRequestXML(xml);

         var tag='USERSHAPEY';
         xml=replaceValue(obj.GetRequestXML(),tag,mapY);
         obj.SetRequestXML(xml);

         var tag='USERSHAPETYPE';
         xml=replaceValue(obj.GetRequestXML(),tag,shapetype);
         obj.SetRequestXML(xml);        
         break;
     }

  }

  function fGetShape(obj,x,y)
  {
    this.StartX=0;
    this.StartY=0;
    this.LastX=0;
    this.LastY=0;
    this.WidthX=0;
    this.HeightY=0;
    clickCount=obj.MapClicks.ClickCount;
    if(clickCount>-1){this.LastX=obj.MapClicks.ImageX[clickCount];}
    if(clickCount>-1){this.LastY=obj.MapClicks.ImageY[clickCount];}
    if(!obj.MapClicks.ButtonDown){this.LastX=obj.MapClicks.ImageX[clickCount-1];}
    if(!obj.MapClicks.ButtonDown){this.LastY=obj.MapClicks.ImageY[clickCount-1];}
    shapetype=obj.MapClicks.aShapeType;
    switch(shapetype)
    {
      case 1:  //line
        this.StartX = x;
        this.StartY = y;
        break;
      case 2:  //poly
        this.StartX = x;
        this.StartY = y;
        break;
      case 3:                                                          //rectangle
        if ( (x-this.LastX) > 0 && (y-this.LastY) > 0)                 //LOWER RIGHT QUADRANT
        {
          this.StartX = this.LastX;
          this.StartY = this.LastY;
          this.WidthX = x-this.LastX;
          this.HeightY = y-this.LastY;
        }
        if ( (x-this.LastX) > 0 &&  (y-this.LastY) < 0)                //UPPER RIGHT QUADRANT
        {
          this.StartX = this.LastX;
          this.StartY = y;
          this.WidthX = x-this.LastX;
          this.HeightY = this.LastY-y;
        }
        if ( (x-this.LastX) < 0 &&  (y-this.LastY) < 0)                //UPPER LEFT QUADRANT
        {
          this.StartX = x;
          this.StartY = y;
          this.WidthX = this.LastX-x;
          this.HeightY = this.LastY-y;			
        }
        if ( (x-this.LastX) < 0 &&  (y-this.LastY) > 0)                //LOWER LEFT QUADRANT
        {
          this.StartX = x;
          this.StartY = this.LastY;
          this.WidthX = this.LastX-x;
          this.HeightY = y-this.LastY;
        }
        //lastX should on last mouse down
        if(!obj.MapClicks.ButtonDown){this.LastX=obj.MapClicks.ImageX[clickCount-1];}
        if(!obj.MapClicks.ButtonDown){this.LastY=obj.MapClicks.ImageY[clickCount-1];}         
        break;
      case 4:  //Point
        this.StartX=this.LastX
        this.StartY=this.LastY
        break;
      case 5:  //Point - pan
        if (obj.MapClicks.StartX == 0)
        {
          obj.MapClicks.StartX=x;
          obj.MapClicks.StartY=y;
          this.StartX=x;
          this.StartY=y;
        }
        break;
      default:break;
    }   
  }

  //sets the click values for user interaction 
  function fSetClickMin(aType){
    var value=0;
    switch(aType){
      case 1:value=0;break;   //line
      case 2:value=1;break;   //poly
      case 3:value=1;break;   //rectangle
      case 4:value=0;break;   //Point
      case 5:value=1;break;   //Point - pan
    }
    this.clickMin=value;
  }

  function fDrawShape(obj,DrawObj,Shape)
  {
    var StartX=Shape.StartX;
    var StartY=Shape.StartY;
    var LastX=Shape.LastX;
    var LastY=Shape.LastY;
    var WidthX=Shape.WidthX;
    var HeightY=Shape.HeightY;
    switch(shapetype)
    {
      case 1:  //line
        if(DrawObj.drawLine){DrawObj.drawLine(Shape.StartX,Shape.StartY,Shape.LastX,Shape.LastY)}
        break;
      case 2:  //poly
        if(obj.MapClicks.ContinueSelect)
        {
          if(DrawObj.drawLine){DrawObj.drawLine(Shape.StartX,Shape.StartY,Shape.LastX,Shape.LastY)}
        }else{
          if(DrawObj.drawPolygon){DrawObj.drawPolygon(obj.MapClicks.ImageX,obj.MapClicks.ImageY)}
        }
        break;
      case 3:  //rectangle
        if(DrawObj.drawRect){DrawObj.drawRect(Shape.StartX,Shape.StartY,Shape.WidthX,Shape.HeightY)}
        break;
      case 4:  //Point
        x=obj.MapClicks.ImageX[0];
        y=obj.MapClicks.ImageY[0];
        a=.0001;
        if(DrawObj.drawRect){DrawObj.drawLine(x-a,y-a,x+a,y+a);}
        if(DrawObj.drawRect){DrawObj.drawLine(x+a,y+a,x-a,y-a);}
        break;
      case 5:  //Point - pan no draw just move image to nex
        //set up move distance
        imgX=obj.MapClicks.curImageX;
        imgY=obj.MapClicks.curImageY;
        //move the map image with cursor drag limit to width and height of image
        if (imgX>0 && imgX<obj.mapWidth)
        {
          if (imgY>0 && imgY<obj.mapHeight)
          {
            var xMove = imgX-obj.MapClicks.StartX;
            var yMove = imgY-obj.MapClicks.StartY;
            fMoveIt('mapIMG',xMove,yMove);
          }
        }
        break;
      default:break;
    }
  }

  function fFillShape(obj,DrawObj,Shape)
  {
    var StartX=Shape.StartX;
    var StartY=Shape.StartY;
    var LastX=Shape.LastX;
    var LastY=Shape.LastY;
    var WidthX=Shape.WidthX;
    var HeightY=Shape.HeightY;
    switch(shapetype)
    {
      case 2:  //poly
        if(DrawObj.drawPolygon){DrawObj.fillPolygon(obj.MapClicks.ImageX,obj.MapClicks.ImageY)}
        break;
      case 3:  //rectangle
        if(DrawObj.drawRect){DrawObj.fillRect(Shape.StartX,Shape.StartY,Shape.WidthX,Shape.HeightY)}
        break;
      default:break;
    }
  }

  function fSetCanvasDraw(DrawObj)
  {
    DrawObj.setColor(DrawObj.Color);
    DrawObj.setOpacity(DrawObj.Opacity);
    DrawObj.setStroke(DrawObj.Stroke);
  }

  function fAfterSendStartXY(obj)
  {
    if(!obj.MapClicks.ButtonDown)
    {
      if(!obj.MapClicks.ContinueSelect)
      {
        if(obj.MapClicks.aShapeType==5)
        {
          imgX=obj.MapClicks.curImageX;
          imgY=obj.MapClicks.curImageY;
          obj.MapClicks.StartX=imgX;
          obj.MapClicks.StartY=imgY;
        }
      }
    }
  }

  //when user dragging with button 1 - left mouse btn down
  function fDragging(obj)
  {
    if(document.getElementById('mapEvent').value=='mousedown')
    {obj.MapClicks.ButtonDown=true;}else{obj.MapClicks.ButtonDown=false;}
    if(obj.MapClicks.ButtonDown && obj.MapClicks.ContinueSelect)
    {
      x=obj.MapClicks.curImageX;
      y=obj.MapClicks.curImageY;
      obj.MapClicks.DrawTwo.clear();
      fSetCanvasDraw(obj.MapClicks.DrawTwo);
      var Shape = new fGetShape(obj,x,y);
      fDrawShape(obj,obj.MapClicks.DrawTwo,Shape);
      obj.MapClicks.DrawTwo.paint();
    }
    if(!obj.MapClicks.ButtonDown && obj.MapClicks.ContinueSelect)
    {
      if(obj.GetTool().toUpperCase() != 'PAN')
      {
        x=obj.MapClicks.curImageX;
        y=obj.MapClicks.curImageY;
        obj.MapClicks.DrawTwo.clear();
        fSetCanvasDraw(obj.MapClicks.DrawTwo);
        var Shape = new fGetShape(obj,x,y);
        fDrawShape(obj,obj.MapClicks.DrawTwo,Shape);
        obj.MapClicks.DrawTwo.paint();
      }
    }
  }

  //gets mouse position in image units
  function fConvertMousePosition(obj,x,y)
  {
    //get x y clickholders
    var eleX=document.getElementById('xPos');
    var eleY=document.getElementById('yPos');

    yOffset=0;
    var w = window;
    if(w.document.documentElement && w.document.documentElement.scrollTop) yOffset=w.document.documentElement.scrollTop;
    else if(w.document.body && xDef(w.document.body.scrollTop)) yOffset=w.document.body.scrollTop;

    xOffset=0;
    var w = window;
    if(w.document.documentElement && w.document.documentElement.scrollLeft) xOffset=w.document.documentElement.scrollLeft;
    else if(w.document.body && xDef(w.document.body.scrollLeft)) xOffset=w.document.body.scrollLeft;
 
    if(isIE){eleY.value=Number(eleY.value)+Number(yOffset)}
    if(isIE){eleX.value=Number(eleX.value)+Number(xOffset)}

    if(x){x=Number(eleX.value)}else{x=0;}
    if(y){y=Number(eleY.value)}else{y=0;}
    obj.MapClicks.curImageX=x;
    obj.MapClicks.curImageY=y;
    var converter = new fConvertClicks(obj,x,y);
    x=Math.round(Number(converter.mapX)*10)/10;
    y=Math.round(Number(converter.mapY)*10)/10;
    //change click holders and fire chnage so app can do what it needs to with user clicks.
    obj.MapClicks.curHOLDX=eleX.value.substring(0,1)
    if(document.getElementById('xPos')){eleX.value=x;obj.MapClicks.curMapX=x}
    if(document.getElementById('yPos')){eleY.value=y;obj.MapClicks.curMapY=y}
  }

  //converts click from image to map units
  function fConvertClicks(obj,x,y)
  {
    this.mapX=0;
    this.mapY=0;
    mouseX=x;
    pixelX=obj.xDistance/obj.mapWidth;
    this.mapX=pixelX*mouseX+Number(obj.minX);
    mouseY=obj.mapHeight-y;
    pixelY=obj.yDistance/obj.mapHeight;
    this.mapY=pixelY*mouseY+Number(obj.minY);   
  }
  
  //gets position of click in image units
  function fGetImagePosition(evt,ele)
  {
    this.xEvent=0;
    this.yEvent=0;
    var BrowserAdj=0;

    //ie needs to get the actual div element for some crazy reason
    if(isIE){obj=document.getElementById('mapHolder');BrowserAdj=-3;}
    else{obj=ele;BrowserAdj=-1;}

    //get adjustment from offset
    var adj = new fAdjDiv(obj);
    var xAdj = adj.X;
    var yAdj = adj.Y;
    if(!xAdj){xAdj=0;}
    if(!yAdj){yAdj=0;}
    if(isNav){this.xEvent = evt.pageX;this.yEvent = evt.pageY;}
    else{this.xEvent = evt.clientX;this.yEvent = evt.clientY;}
    //record machine coords with adjustment
    this.xEvent=(this.xEvent-xAdj)+BrowserAdj;
    this.yEvent=(this.yEvent-yAdj)+BrowserAdj;
  }

  function fGetEvent(evt){return evt;}

  //record event to event mapavl event recorder
  function fRecordMapEvent(evt)
  {
    ele=document.getElementById('mapEvent')
    if(document.getElementById('mapEvent')){ele.value=evt.type}
    return ele;
  }

  //mouse up function
  function fMouseUp(evt)
  {
    // get the button pushed... if right, ignore... let browser do the popup... it will anyway
    if (isNav){theButton = evt.which;}
    else{theButton=window.event.button;}
    if(theButton == 1){ele=fRecordMapEvent(evt);if(ele){fireChange(ele);}}
  }

  //mouse double click function
  function fDoubleClick(evt)
  {
    // get and record double click
    ele=fRecordMapEvent(evt);if(ele){fireChange(ele);}
  }

  //mouse up function
  function fMouseDown(evt)
  {
    // get the button pushed... if right, ignore... let browser do the popup... it will anyway
    if (isNav){theButton = evt.which;}
    else{theButton=window.event.button;}
    if(theButton == 1){ele=fRecordMapEvent(evt);if(ele){fireChange(ele);}}
  }

  //sets up mouse movement - position
  function fMousePosition(evt)
  { 
    var xEvent=0;
    var yEvent=0;   
    var pos = new fGetImagePosition(evt,this);
    xEvent = pos.xEvent;
    yEvent = pos.yEvent;
    //get x y clickholders
    var eleX=document.getElementById('xPos');
    var eleY=document.getElementById('yPos');

    //change click holders and fire chnage so app can do what it needs to with user clicks.
    if(document.getElementById('xPos'))
    {
      eleX.value=xEvent;
      fireChange(eleX);
    } 
    if(document.getElementById('yPos'))
    {
      eleY.value=yEvent;
      fireChange(eleY);
    }
  }

  //fire the event regardaless of focus
  function fFireMouseEvent(ele,evt_name)
  {
    if (isNav)
    {
      var evt = document.createEvent('MouseEvents');
      evt.initEvent(evt_name, true, false);
      ele.dispatchEvent(evt);
    }else{ele.fireEvent('on'+evt_name);}
  }

  //fire the change event regardaless of focus
  function fireChange(ele)
  {
    if (isNav){var evt = document.createEvent('HTMLEvents');evt.initEvent('change', true, true);ele.dispatchEvent(evt);}
    else{ele.fireEvent('onchange');}
  }

  //adds a listener to an element
  function fAddEventListener( element_name , event_name , observer , capturing ) {   
    var element = document.getElementById(element_name);    
    if ( element.addEventListener )  // the DOM2, W3C way      
      element.addEventListener( event_name, observer, capturing );
    else if ( element.attachEvent )  // the IE way
      element.attachEvent( "on" + event_name, observer );
  }
  
  //removes a listener to an element
  function fRemoveEventListener( element_name , event_name , observer , capturing ) {
    var element = document.getElementById(element_name);
    if ( element.removeEventListener )  // the DOM2, W3C way
      element.removeEventListener( event_name, observer, capturing );
    else if ( element.detachEvent )  // the IE way
      element.detachEvent( "on" + event_name, observer );
  }

  //function postions canvas over map holder
  function fSetCanvas(ele_name)
  {
    //get the top & left for the mapHolder
    var loc = new fAdjDiv('mapHolder');
    var locTop = loc.Y;
    var locLeft = loc.X;
    // the top & left for the mapHolder
    var loc = new fAdjDiv(ele_name);
    var mTop = loc.Y;
    var mLeft = loc.X;   
    //do not adjust canvas if no postion relative-aboslute postioning is set
    if(fGetPositionAttDiv(ele_name)!='')
    {
      locTop = (locTop-mTop);locLeft = (locLeft-mLeft);
    }else{
      if(isIE){locTop = (locTop+1);locLeft = (locLeft+1);}
    }
    //repostion canvas to top * left of  the mapHolder
    fPositionDiv('mapDraw',locTop,locLeft);
    fPositionDiv('mapDraw2',locTop,locLeft);
  }

  //Draws the initial map at start up
  function fInitDrawMap( obj ){    
    mXML=obj.GetResponseXML();
    mMap=obj.GetMapURL();
    mMapDIV=obj.GetMapDiv();
    if ( mXML == '' ){mXML = this.InitXML }
    if (mMap ==''){mMap='../../IMAGES/ArcIMSFrameWork/ArcIMSFrameWork_blank.gif';}
    ele=null;
    if(document.getElementById(mMapDIV))
    {
      var ele=document.getElementById(mMapDIV);
      if(document.getElementById('mapIMG')){document.getElementById('mapIMG').src=mMap;}
    }
    var padVal=5;
    var IEnudge=0;
    var BarHgt=18;
    var barWidthAdj=0;
    var BrowserAdj=(padVal*2)+2;
    var mWidth=Number(returnInfo( mXML , 'MAPWIDTH' ));
    var mHeight=Number(returnInfo( mXML , 'MAPHEIGHT' ));
    //if(isIE){barWidthAdj=BrowserAdj;BrowserAdj=0;IEnudge=0;}
    var allWidth=(Number(mWidth)-(padVal*2));

    
    var CurLoc = '';
    var Tbar = '';
    var StatBar = '';
    var disp = '';

    if(!obj.GetCursorLoc()){ CurLoc = 'display:none;';  }
    if(!obj.GetToolBar()){ Tbar = 'display:none;'; }
    if(!obj.GetStatusBar()){ StatBar = 'display:none;'; }
    if(obj.GetMapOnly()){ disp = 'display:none;'; }
    
    var mapHeader =  '<div id="mapDrag" name="mapDrag" class="mapDrag"  style="'+disp+'border-width:0px;vertical-align:middle;" >'+
                       '<a href="'+obj.HelpLoc+obj.HelpDoc+'" target="_blank" title="Help" style="float:right;border-width:0px;vertical-align:top;height:18px;" >'+
                         '<img src="../../IMAGES/ArcIMSFrameWork/mashupIcon_Help.gif" alt="Help" title="Help" style="border-width:0px;vertical-align:top;height:16px;" />'+
                       '</a>'+
                       '<span style="border-width:0px;vertical-align:middle;" >mapAsheville&nbsp;'+
                       '</span>'+
                       '<span id="mapTitleTxt" name="mapTitleTxt" class="mapTitleTxtMAVL" style="vertical-align:middle;" >'+
                       '</span>'+
                     '</div>';
    var mapToolBar = '<div id="mapToolbar" name="mapToolbar" class="mapToolbar"  style="'+disp+' '+Tbar+'" >'+
                     '</div>';
    var mapEle =     '<div id="mapHolder" name="mapHolder" class="mapHolder" style="position:absolute;"  >'+
                     '<img id="mapIMG" name="mapIMG" src="'+mMap+'" alt="mapAsheville Map" ondragstart="return false" style=""  />'+
                     '</div>';
    var mapCanvas =  '<div id="mapDraw2" name="mapDraw2" class="mapDrawTwo" ></div>'+
                     '<div id="mapDraw" name="mapDraw" class="mapDrawOne"  ></div>';
    var mapStatus =  '';

    if(!obj.GetMapOnly())
    {
        mapStatus =  '<div id="mapStatusBar" name="mapStatusBar" class"mapStatusBar" style="position:absolute;'+disp+' '+StatBar+'"   >'+
                     '<img id="mapLoading" class="mapLoadingimg" name="mapLoading" src="../../IMAGES/ArcIMSFrameWork/ArcIMSFrameWork_WorkingStop.gif" alt="mapAsheville Map" />'+
                     '<span id="mapStatus" name="mapStatus" class="mapStatus" >'+
                     '</span>'+
                     '</div>';
    }

    var mapPos =     '<div id="mapPosition" name="mapPosition" class="mapPosition" style="position:absolute;'+disp+' '+CurLoc+'"  >'+
                     'X:<input type="text" id="xPos" name="xPos" class="xypos" value="0" />'+ 
                     'Y:<input type="text" id="yPos" name="yPos" class="xypos" value="0" />'+ 
                     '</div>';
    var mapResults = '<div id="mapResults" name="mapResults" style="'+disp+' position:absolute;top:0px;left:0px;visibility:hidden;z-index:4;" >'+
                     '</div>';
    var mapLayerTip = '<div id="mapLayerTipH" name="mapLayerTipH" style="'+disp+' position:absolute;top:0px;left:0px;visibility:hidden;z-index:9999;"   >'+
                     '</div>';
    var mapClicks =  '<div id="mapClicks" name="mapClicks" class="mapClicks" style="'+disp+' '+CurLoc+'"  >'+
                     '<input type="text" id="mapClickX" name="mapClickX" class="mapClickXY" value="" />'+
                     '<input type="text" id="mapClickY" name="mapClickY" class="mapClickXY" >'+
                     '<input type="text" id="mapEvent" name="mapEvent" class="mapEvent" >'+
                     '</div>';
    var mapPrintForm = '<div id="mapPrintForm" style="display:none;visibility:hidden;" ></div>';
    var loadingSplsh = '<img id="workingSplsh" name="workingSplsh" src="../../IMAGES/ArcIMSFrameWork/ArcIMSFrameWork_blank.gif" alt="working..." style="'+disp+' position:absolute;visibility:hidden;" />';

    fAddDivHTML(mMapDIV,mapHeader+mapToolBar+mapEle+mapStatus+mapPos+mapCanvas+mapClicks+mapResults+mapLayerTip+loadingSplsh+mapPrintForm); //+zoomtool
    if(Number(mWidth)>0)
    {
      fResizeDiv('mapDrag',allWidth+barWidthAdj,BarHgt);
      fResizeDiv('mapToolbar',allWidth+barWidthAdj,BarHgt);
      fResizeDiv('mapHolder',mWidth,mHeight);
      fResizeDiv('mapIMG',mWidth,mHeight);
      fResizeDiv('mapDraw',mWidth+IEnudge,mHeight+IEnudge);
      fResizeDiv('mapDraw2',mWidth+IEnudge,mHeight+IEnudge);
      fResizeDiv('mapLayerTipH',mWidth+IEnudge,mHeight+IEnudge);
      fResizeDiv('mapPosition',allWidth+barWidthAdj,BarHgt);
      fResizeDiv('xPos',(allWidth+barWidthAdj)/2.5,BarHgt);
      fResizeDiv('yPos',(allWidth+barWidthAdj)/2.5,BarHgt);
      if(!obj.GetMapOnly())
      {
        fResizeDiv('mapLoading',BarHgt,BarHgt);
      }
      fResizeDiv('mapStatus',(allWidth+barWidthAdj)-(BarHgt*2),BarHgt);
      fResizeDiv('mapStatusBar',allWidth+barWidthAdj,BarHgt);
      fResizeDiv('mapClicks',allWidth+barWidthAdj,BarHgt);
      fResizeDiv('mapinfo',allWidth+barWidthAdj,BarHgt);
      fResizeDiv(mMapDIV,allWidth+BrowserAdj,Number(mHeight)+(BarHgt*4)+(padVal*8));
      fMoveIt('mapStatus',0,mHeight+padVal);
      if(!obj.GetMapOnly())
      {
        fMoveIt('mapLoading',0,mHeight+padVal);
      }
      fMoveIt('mapPosition',padVal,mHeight+(BarHgt*4)+(padVal*4));
      fBorderSizeDiv(mMapDIV,1);
    }
    fDivVis(mMapDIV,'visible');
  }

  //Refreshes map and map div
  function fRefreshMap( mMap , mXML , mMapDIV , mOVMapURL , mOVMapDiv){    
    if ( mXML == '' ){mXML = this.InitXML }
    if (mMap ==''){mMap='../../IMAGES/ArcIMSFrameWork/ArcIMSFrameWork_blank.gif';}
    ele=null;
    if(document.getElementById(mMapDIV))
    {
      var ele=document.getElementById(mMapDIV);
      if(document.getElementById('mapIMG'))
      {
        document.getElementById('mapIMG').src=mMap;
      }
    }
    var padVal = 5;
    var BarHgt = 18;
    var mWidth=Number(returnInfo( mXML , 'MAPWIDTH' ));
    var mHeight=Number(returnInfo( mXML , 'MAPHEIGHT' ));
    var BrowserAdj=(padVal*2)+2;
    var barWidthAdj=0;
    var IEnudge=0;
    //if(isIE){barWidthAdj=BrowserAdj;BrowserAdj=0;IEnudge=0;} //IEnudge=2
    var allWidth=(Number(mWidth)-(padVal*2));
    if(Number(mWidth)>0)
    {
      fResizeDiv('mapDrag',allWidth+barWidthAdj,BarHgt);
      fResizeDiv('mapToolbar',allWidth+barWidthAdj,BarHgt);
      fResizeDiv('mapHolder',mWidth,mHeight);
      fResizeDiv('mapIMG',mWidth,mHeight);
      fResizeDiv('mapDraw',mWidth+IEnudge,mHeight+IEnudge);
      fResizeDiv('mapDraw2',mWidth+IEnudge,mHeight+IEnudge);
      fResizeDiv('mapLayerTipH',mWidth+IEnudge,mHeight+IEnudge);
      fResizeDiv('mapPosition',allWidth+barWidthAdj,BarHgt);
      fResizeDiv('xPos',(allWidth+barWidthAdj)/2.5,BarHgt);
      fResizeDiv('yPos',(allWidth+barWidthAdj)/2.5,BarHgt);
      fResizeDiv('mapLoading',BarHgt,BarHgt);
      fResizeDiv('mapStatus',(allWidth+barWidthAdj)-(BarHgt*2),BarHgt);
      fResizeDiv('mapStatusBar',allWidth+barWidthAdj,BarHgt);
      fResizeDiv('mapClicks',allWidth+barWidthAdj,BarHgt);
      fResizeDiv(mMapDIV,allWidth+BrowserAdj,Number(mHeight)+(BarHgt*4)+(padVal*8));
      fSetCanvas(mMapDIV);
      fBorderSizeDiv(mMapDIV,1);
    }
    return ele;
  }

  //gets offset adjustment for x and y
  function fAdjDiv(obj)
  {
    if(typeof(obj)!='object')
    {if( document.getElementById(obj)){obj=document.getElementById(obj);}else{this.X=0;this.Y=0;}}
    this.X = 0;
    this.Y = 0;
    if (obj.offsetParent)
    {
      this.X=obj.offsetLeft;this.Y=obj.offsetTop;
      while (obj=obj.offsetParent){this.X+=obj.offsetLeft;this.Y+=obj.offsetTop;}
    }
  }

  //adds text or HTML to a div
  function fAddDivHTML(name,txt)
  {
   if(typeof(name=='object')){name.innerHTML=txt;}
   if(document.getElementById(name))
   {
     ele=document.getElementById(name);
     ele.innerHTML=txt;
   }else{ele=null;}
   return ele;
  }

  //gets text or HTML to a div
  function fGetDivHTML(name)
  {
   if(document.getElementById(name))
   {
     ele=document.getElementById(name);
     txt=ele.innerHTML;
   }else{txt='';}
   return txt;
  }

  //gets dimension of doc
  function fGetDivDim(name,dim)
  {
   if(document.getElementById(name))
   {
     ele=document.getElementById(name);
     switch(dim)
     {
       case 'width':
         val=ele.style.width;
         break;
       case 'height':
         val=ele.style.height;
         break;
       case 'top':
         val=ele.style.top;
         break;
       case 'left':
         val=ele.style.left;
         break;
     }
   }else{val=0;}
   val=val.replace(/[ABCDEFGHIJLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz%]/g,'')
   return val;
  }

  //changes class css for element
  function fEleClass(name,mClass)
  {
   if(typeof(name=='object')){name.className=mClass;}
   if(document.getElementById(name))
   {
     ele=document.getElementById(name);
     ele.className=mClass;
   }else{ele=null;}
   return ele;
  }

  //changes font color of div
  function fDivClr(name,color)
  {
   if(typeof(name=='object')){name.style.color=color;}
   if(document.getElementById(name))
   {
     ele=document.getElementById(name).style;
     ele.color=color;
   }else{ele=null;}
   return ele;
  }

  //changes background of div
  function fDivBG(name,color)
  {
   if(typeof(name=='object')){name.style.backgroundColor=color;}
   if(document.getElementById(name))
   {
     ele=document.getElementById(name).style;
     ele.backgroundColor=color;
   }else{ele=null;}
   return ele;
  }

  //changes z index of div
  function fDivZ(name,z)
  {
   if(document.getElementById(name))
   {
     ele=document.getElementById(name).style;
     ele.zIndex=z;
   }else{ele=null;}
   return ele;
  }

  //makes a div visible or not
  function fDivVis(name,vis)
  {
   if(document.getElementById(name))
   {
     ele=document.getElementById(name).style;
     ele.visibility=vis;
   }else{ele=null;}
   return ele;
  }

  //postions top left of a div
  function fGetPositionAttDiv(name)
  {
   if(document.getElementById(name))
   {
     ele=document.getElementById(name).style;
     pos=ele.position;
   }else{pos='';}
   return pos;
  }

  //postions top left of a div
  function fPositionDiv(name,top,left)
  {
   if(document.getElementById(name))
   {
     ele=document.getElementById(name).style;
     if(top>0){ele.postion='absolute';ele.top=top+'px';}
     if(left>0){ele.left=left+'px';}
   }else{ele=null;}
   return ele;
  }

  //Resizes a div
  function fResizeDiv(name,width,height)
  {
   if(document.getElementById(name))
   {
     ele=document.getElementById(name).style;
     if(width>0){ele.width=width+'px';}
     if(height>0){ele.height=height+'px';}
   }else{ele=null;}
   return ele;
  }

  //intiall for main map div to allowable border 
  //must do this to get relable click locations
  function fBorderSizeDiv(name,size)
  {
   if(document.getElementById(name))
   {
     ele=document.getElementById(name).style;
     ele.borderWidth=size+'px';
   }else{ele=null;}
   return ele;
  }

  //send AJAX post
  function fSendRequest(URL,XML,obj,async){
    if(XML==''){XML=this.InitXML;}
    if(URL==''){URL=this.InitURL}
    if(async=''){async=true;}
    if(async='undefined'){async=true;}
    this.file=URL;
    this.xml=XML;
    this.xmlobj=null;
    this.ResponseXML='';
    this.MapURL='';
    this.OVMapURL='';

    // instantiate object for Mozilla, Nestcape, FireFox etc.
    try{this.xmlobj=new XMLHttpRequest();}
    catch(e)
    {
       try{this.xmlobj=new ActiveXObject('Microsoft.XMLHTTP');}  // instantiate object for Internet Explorer
       catch(e){this.xmlobj=null;}                               // Ajax is not supported by the browser
    }    
    // define response method
    this.SetResponseXML=function()
    {
      if(this.xmlobj.readyState==4)
      {
        // if status == 200 return file data         
        if(this.xmlobj.status==200)
        {
          // get data set response xml
          this.ResponseXML = this.xmlobj.responseText;
          //alert(this.xmlobj.getAllResponseHeaderd());

          // set response map url
          this.mapURL = returnInfo( this.ResponseXML , 'MAPURL' );
          if(typeof(obj)=='object')
          {
            obj.mapURL=this.mapURL;
            obj.ResponseXML=this.ResponseXML;
            obj.OVMapURL=this.OVmapURL;
            obj.RefreshMap(obj.GetMapURL(),this.ResponseXML,obj.GetMapDiv(),'','');
            mOVMap=this.GetMapOverViewURL();
            if(document.getElementById('mapOV')){} //insert ovmap

          }                                                                         //end object
          return this.xmlobj.responseText;
        }
        else
        {
          // set xml error for error response
          errorXML = '<?xml version="1.0"?><COAARCIMSFRAMEWORK>'+
                     '<ERROR>'+this.xmlobj.statusText+'</ERROR>'+
                     '</COAARCIMSFRAMEWORK>';
          this.ResponseXML=errorXML;
          //alert('Error retrieving data from GIS Server: ' + this.xmlobj.statusText + ' - ' + this.xmlobj.status)
          this.mapURL='';
          return errorXML ;
        }                                                                           //end status 200
      }                                                                             //end status 4
    }                                                                               //end response function
    // assign state handler    
    this.xmlobj.onreadystatechange=function(){this.SetResponseXML;}
    // open socket connection
    //if(typeof(obj)=='object'){x=obj.PreXML;prompt('',this.file+'?PREXML='+x);}else{x='';}
    this.xmlobj.open('POST',this.file,async);
    if(typeof(obj)=='object'){if(obj.UN.length > 0){this.xmlobj.setRequestHeader('valueu',obj.UN);}}
    if(typeof(obj)=='object'){if(obj.UN.length > 0){this.xmlobj.setRequestHeader('valuep',obj.PD);}}
    // send request
    this.xmlobj.send(this.xml);
  }

  //function to return first occurance of tag set
  function returnInfo(theString,theTag){
    var startPos;
    var endPos;
    var AstartPos;
    var AendPos;
    var pos = 1;
    var newString = '';
    var countString;
    var StartTag = '<'+theTag+'>';
    var EndTag= '</'+theTag+'>';
    var startSearchString = StartTag;
    var endSearchString = EndTag;
    var startAttString;
    var endAttString;
    var attString ='';
    //check if xml tag is in string
    if ( theString.indexOf( startSearchString , pos ) > 0 ) {
      startPos = theString.indexOf(startSearchString ,pos);
      //check for end tag
      if( theString.indexOf(endSearchString ,startPos) > 0 )
      {
        endPos = theString.indexOf(endSearchString ,startPos);
        newString += theString.substring(startPos,endPos);      
        pos = endPos+(startSearchString.length+1);            
        attString = newString.substring(startSearchString.length,newString.length);
        return attString;
       }else{
         attString = ''; 
         return attString;
       }
    }else{
      //nothing found return empty string
      attString = ''; 
      return attString;
    }  
  }

  //return first occurance of tag set
  function returnXML(theString,theTag){
    var startPos;
    var endPos;
    var AstartPos;
    var AendPos;
    var pos = 1;
    var newString = '';
    var countString;
    var StartTag = '<'+theTag+'>';
    var EndTag= '</'+theTag+'>';
    var startSearchString = StartTag;
    var endSearchString = EndTag;
    var startAttString;
    var endAttString;
    var attString = '';
    //check if xml tag is in string
    if ( Number(theString.indexOf( startSearchString , pos )) > 0 ) {
      startPos = theString.indexOf(startSearchString ,pos);
      //check for end tag
      if( theString.indexOf(endSearchString ,startPos) > 0 )
      {
        endPos = theString.indexOf(endSearchString ,startPos);
        newString += theString.substring(startPos,endPos);      
        pos = endPos+(startSearchString.length+1);            
        attString = newString.substring(startSearchString.length,newString.length);
        attString = startSearchString + attString + endSearchString ;
        return attString;
      }else{
        attString = ''; 
        return attString;
      }
    }else{
      //nothing found return empty string
      attString = ''; 
      return attString;
    }
  }  

  function replaceValue(theString,theTag,TheValue)
  {   
    var StartTag = '<'+theTag+'>';
    var EndTag = '</'+theTag+'>';
    var retVal = '';
    //get tag value
    var ReplaceVal = returnInfo( theString , theTag ) ;
    //replace tag tag value with TheValue
    var retVal = theString.replace(StartTag+ReplaceVal+EndTag,StartTag+TheValue+EndTag);
    return retVal;
  }
  //gis.ashevillenc.gov  192.168.0.16
  function InitURL(){var theInitURL = '../../'+mshuplocstr+'/asp/ArcIMSFrameWork.asp';return theInitURL}
  function InitXML()
  {

    var theInitXML =  '<?xml version="1.0"?>'+
                      '<COAARCIMSFRAMEWORK>'+  
                        '<OVERVIEWMAPSETTINGS>' +
                          '<OVERVIEWMAPINCLUDE>false' +
                          '</OVERVIEWMAPINCLUDE>' +
                          '<OVERVIEWMAPCALLOUT>false' +
                          '</OVERVIEWMAPCALLOUT>' +
                          '<OVERVIEWMAPWIDTH>150' +
                          '</OVERVIEWMAPWIDTH>' +
                          '<OVERVIEWMAPHEIGHT>150' +
                          '</OVERVIEWMAPHEIGHT>' +
                          '<OVERVIEWMAPSERVICENAME>mapAsheville_CoaLocator' +
                          '</OVERVIEWMAPSERVICENAME>' +
                          '<OVERVIEWMAPSCALE>10000' +
                          '</OVERVIEWMAPSCALE>' +
                        '</OVERVIEWMAPSETTINGS>' +
                        '<SESSIONS>' +
                          '<SESSIONID></SESSIONID>' +
                          '<USERIP></USERIP>' +
                          '<SERVER>tomcatgis.ashevillenc.gov</SERVER>' +
                          '<PORT>5300</PORT>' +
                          '<SERVICENAME>mapAsheville_Standard</SERVICENAME>' +
                          '<APPNAME>mapAsheville_mashup</APPNAME>' +
                        '</SESSIONS>' +
                        '<MAPSETTINGS>' +
                          '<MAPWIDTH>200</MAPWIDTH>' +
                          '<MAPHEIGHT>200</MAPHEIGHT>' +
                          '<ENVELOPE>' +
                            '<MINX></MINX>' +
                            '<MINY></MINY>' +
                            '<MAXX></MAXX>' +
                            '<MAXY></MAXY>' +
                          '</ENVELOPE>'+
                          'xmlreplaceholder' +
                        '</MAPSETTINGS>' +
                        '<ACTIONS>' +
                          '<TOOL>' +
                            '<TOOLNAME></TOOLNAME>' +
                            '<TOOLACTION>SET</TOOLACTION>' +
                          '</TOOL>' +
                          '<BUTTON>' +
                            '<BUTTONNAME></BUTTONNAME>' +
                            '<BUTTONACTION></BUTTONACTION>' +
                          '</BUTTON>' +
                          '<USERSETTING>' +
                            '<USERSETTINGNAME>MAPSTART</USERSETTINGNAME>' +
                            '<USERSETTINGVALUE>100</USERSETTINGVALUE>' +
                            '<USERSETTINGACTION>GO</USERSETTINGACTION>' +
                          '</USERSETTING>' +
                          '<PRESETS>' +
                            '<USERSETS>' +
                              '<ACTION>' +
                                '<MAPACTION>' +
                                  '<MAPACTIONNAME>LAYERACTIVE</MAPACTIONNAME>' + 
                                  '<MAPACTIONVALUE>GIS.GIS.BC_PROPERTY</MAPACTIONVALUE>' +
                                '</MAPACTION>' +
                                '<MAPACTION>' +
                                  '<MAPACTIONNAME>ZOOM TO EXTENT OF LAYER</MAPACTIONNAME>' +
                                  '<MAPACTIONVALUE>PDS.PDS.ACTIVEJURISDICTIONS</MAPACTIONVALUE>' +
                                '</MAPACTION>' +
                              '</ACTION>' +
                              '<SET>' +
                                '<SETACTION>' +
                                  '<SETACTIONNAME>SETZOOMSELECTFACTORTWO</SETACTIONNAME>' +
                                  '<SETACTIONVALUE>0.5</SETACTIONVALUE>' +
                                '</SETACTION>' +
                              '</SET>' +
                            '</USERSETS>' +
                          '</PRESETS>' +
                        '</ACTIONS>' +
                        '<USERCLICKS>' +
                          '<CLICK>' +
                            '<CLICKX></CLICKX>' +
                            '<CLICKY></CLICKY>' +
                          '</CLICK>' +
                        '</USERCLICKS>' +
                        '<COUNT>1</COUNT>' +
                        '<USERSHAPE>'+
                          '<AUSHAPE>' +
                            '<USERSHAPETYPE></USERSHAPETYPE>' +
                            '<USERSHAPEX></USERSHAPEX>' +
                            '<USERSHAPEY></USERSHAPEY>' +
                          '</AUSHAPE>' +
                        '</USERSHAPE>'+
                      '</COAARCIMSFRAMEWORK>';
    return theInitXML;
  }


//********************************************************
//********************************************************
//*js graphics - for cross browser drawing of user shapes 
//********************************************************
//********************************************************

/* This notice must be untouched at all times.

wz_jsgraphics.js    v. 2.3
The latest version is available at

http://www.walterzorn.com
or http://www.devira.com
or http://www.walterzorn.de

Copyright (c) 2002-2004 Walter Zorn. All rights reserved.
Created 3. 11. 2002 by Walter Zorn (Web: http://www.walterzorn.com )
Last modified: 13. 2. 2006

added transparency

Performance optimizations for Internet Explorer
by Thomas Frank and John Holdsworth.
fillPolygon method implemented by Matthieu Haller.

High Performance JavaScript Graphics Library.
Provides methods
- to draw lines, rectangles, ellipses, polygons
  with specifiable line thickness,
- to fill rectangles and ellipses
- to draw text.
NOTE: Operations, functions and branching have rather been optimized
to efficiency and speed than to shortness of source code.

LICENSE: LGPL

This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License (LGPL) as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.

This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA,
or see http://www.gnu.org/copyleft/lesser.html 
*/
var jg_ihtm, jg_ie, jg_fast, jg_dom, jg_moz,
jg_n4 = (document.layers && typeof document.classes != "undefined");
this.Opacity=1;

function chkDHTM(x, i)
{
  x = document.body || null;
  jg_ie = x && typeof x.insertAdjacentHTML != "undefined";
  jg_dom = (x && !jg_ie &&
    typeof x.appendChild != "undefined" &&
    typeof document.createRange != "undefined" &&
    typeof (i = document.createRange()).setStartBefore != "undefined" &&
    typeof i.createContextualFragment != "undefined");
  jg_ihtm = !jg_ie && !jg_dom && x && typeof x.innerHTML != "undefined";
  jg_fast = jg_ie && document.all && !window.opera;
  jg_moz = jg_dom && typeof x.style.MozOpacity != "undefined";

}

function pntDoc()
{
  this.wnd.document.write(jg_fast? this.htmRpc() : this.htm);
  this.htm = '';
}

function pntCnvDom()
{
  var x = document.createRange();
  x.setStartBefore(this.cnv);
  x = x.createContextualFragment(jg_fast? this.htmRpc() : this.htm);
  this.cnv.appendChild(x);
  this.htm = '';
}

function pntCnvIe()
{
  this.cnv.insertAdjacentHTML("BeforeEnd", jg_fast? this.htmRpc() : this.htm);
  this.htm = '';
}

function pntCnvIhtm()
{
  this.cnv.innerHTML += this.htm;
  this.htm = '';
}

function pntCnv()
{
  this.htm = '';
}

function mkDiv(x, y, w, h)
{
  if(h==''){h=1;}
  if(h=='undefined'){h=1;}
  this.htm += '<div style="position:absolute;'+
    'left:' + x + 'px;'+
    'top:' + y + 'px;'+
    'width:' + w + 'px;'+
    'height:' + h + 'px;'+
    '-moz-opacity:'+this.Opacity+';' +
    'opacity: '+this.Opacity+';' +
    'clip:rect(0,'+w+'px,'+h+'px,0);'+
    'background-color:' + this.color +
    (!jg_moz? ';overflow:hidden' : '')+
    ';"><\/div>';
}

function mkDivIe(x, y, w, h)
{
  if(h==''){h=1;}
  if(h=='undefined'){h=1;}
  this.htm += '%%'+this.color+';'+x+';'+y+';'+w+';'+h+';';

}

function mkDivPrt(x, y, w, h)
{
  if(h==''){h=1;}
  if(h=='undefined'){h=1;}
  this.htm += '<div style="position:absolute;'+
    'border-left:' + w + 'px solid ' + this.color + ';'+
    'left:' + x + 'px;'+
    'top:' + y + 'px;'+
    'width:' + w + 'px;'+
    'height:' + h + 'px;'+
    '-moz-opacity:'+this.Opacity+';' +
    'opacity: '+this.Opacity+';' +
    'clip:rect(0,'+w+'px,'+h+'px,0);'+
    'background-color:' + this.color +
    (!jg_moz? ';overflow:hidden' : '')+
    ';"><\/div>';
}

function mkLyr(x, y, w, h)
{
  if(h==''){h=1;}
  if(h=='undefined'){h=1;}
  this.htm += '<layer '+
    'left:' + x + 'px;'+
    'top:' + y + 'px;'+
    'width:' + w + 'px;'+
    'height:' + h + 'px;'+
    '-moz-opacity:'+this.Opacity+';' +
    'opacity: '+this.Opacity+';' +
    'bgcolor:"' + this.color + '"><\/layer>\n';
}

var regex =  /%%([^;]+);([^;]+);([^;]+);([^;]+);([^;]+);/g;
function htmRpc()
{
  return this.htm.replace(
    regex,
    '<div style="overflow:hidden;position:absolute;filter:alpha(opacity='+this.Opacity*100+');background-color:'+
    '$1;left:$2;top:$3;width:$4;height:$5;"></div>\n');
  return this.htm.replace(/height\:\s\;/g,'')  
}


function htmPrtRpc()
{
  return this.htm.replace(
    regex,
    '<div style="overflow:hidden;position:absolute;background-color:'+
    '$1;left:$2;top:$3;width:$4;height:$5;border-left:$4px solid $1;"></div>\n');

  return this.htm.replace(/height\:\s\;/g,'')
}


function mkLin(x1, y1, x2, y2)
{
  if (x1 > x2)
  {
    var _x2 = x2;
    var _y2 = y2;
    x2 = x1;
    y2 = y1;
    x1 = _x2;
    y1 = _y2;
  }
  var dx = x2-x1, dy = Math.abs(y2-y1),
  x = x1, y = y1,
  yIncr = (y1 > y2)? -1 : 1;
  if (dx >= dy)
  {
    var pr = dy<<1,
    pru = pr - (dx<<1),
    p = pr-dx,
    ox = x;
    while ((dx--) > 0)
    {
      ++x;
      if (p > 0)
      {
        this.mkDiv(ox, y, x-ox, 1);
        y += yIncr;
        p += pru;
        ox = x;
      }
      else p += pr;
    }
    this.mkDiv(ox, y, x2-ox+1, 1);
  }
  else
  {
    var pr = dx<<1,
    pru = pr - (dy<<1),
    p = pr-dy,
    oy = y;
    if (y2 <= y1)
    {
      while ((dy--) > 0)
      {
        if (p > 0)
        {
          this.mkDiv(x++, y, 1, oy-y+1);
          y += yIncr;
          p += pru;
          oy = y;
        }
        else
        {
          y += yIncr;
          p += pr;
        }
      }
      this.mkDiv(x2, y2, 1, oy-y2+1);
    }
    else
    {
      while ((dy--) > 0)
      {
        y += yIncr;
        if (p > 0)
        {
          this.mkDiv(x++, oy, 1, y-oy);
          p += pru;
          oy = y;
        }
        else p += pr;
      }
      this.mkDiv(x2, oy, 1, y2-oy+1);
    }
  }
}

function mkLin2D(x1, y1, x2, y2)
{
  if (x1 > x2)
  {
    var _x2 = x2;
    var _y2 = y2;
    x2 = x1;
    y2 = y1;
    x1 = _x2;
    y1 = _y2;
  }
  var dx = x2-x1, dy = Math.abs(y2-y1),
  x = x1, y = y1,
  yIncr = (y1 > y2)? -1 : 1;
  var s = this.stroke;
  if (dx >= dy)
  {
    if (s-3 > 0)
    {
      var _s = (s*dx*Math.sqrt(1+dy*dy/(dx*dx))-dx-(s>>1)*dy) / dx;
      _s = (!(s-4)? Math.ceil(_s) : Math.round(_s)) + 1;
    }
    else var _s = s;
    var ad = Math.ceil(s/2);

    var pr = dy<<1,
    pru = pr - (dx<<1),
    p = pr-dx,
    ox = x;
    while ((dx--) > 0)
    {
      ++x;
      if (p > 0)
      {
        this.mkDiv(ox, y, x-ox+ad, _s);
        y += yIncr;
        p += pru;
        ox = x;
      }
      else p += pr;
    }
    this.mkDiv(ox, y, x2-ox+ad+1, _s);
  }
  else
  {
    if (s-3 > 0)
    {
      var _s = (s*dy*Math.sqrt(1+dx*dx/(dy*dy))-(s>>1)*dx-dy) / dy;
      _s = (!(s-4)? Math.ceil(_s) : Math.round(_s)) + 1;
    }
    else var _s = s;
    var ad = Math.round(s/2);
    var pr = dx<<1,
    pru = pr - (dy<<1),
    p = pr-dy,
    oy = y;
    if (y2 <= y1)
    {
      ++ad;
      while ((dy--) > 0)
      {
        if (p > 0)
        {
          this.mkDiv(x++, y, _s, oy-y+ad);
          y += yIncr;
          p += pru;
          oy = y;
        }
        else
        {
          y += yIncr;
          p += pr;
        }
      }
      this.mkDiv(x2, y2, _s, oy-y2+ad);
    }
    else
    {
      while ((dy--) > 0)
      {
        y += yIncr;
        if (p > 0)
        {
          this.mkDiv(x++, oy, _s, y-oy+ad);
          p += pru;
          oy = y;
        }
        else p += pr;
      }
      this.mkDiv(x2, oy, _s, y2-oy+ad+1);
    }
  }
}

function mkLinDott(x1, y1, x2, y2)
{
  if (x1 > x2)
  {
    var _x2 = x2;
    var _y2 = y2;
    x2 = x1;
    y2 = y1;
    x1 = _x2;
    y1 = _y2;
  }
  var dx = x2-x1, dy = Math.abs(y2-y1),
  x = x1, y = y1,
  yIncr = (y1 > y2)? -1 : 1,
  drw = true;
  if (dx >= dy)
  {
    var pr = dy<<1,
    pru = pr - (dx<<1),
    p = pr-dx;
    while ((dx--) > 0)
    {
      if (drw) this.mkDiv(x, y, 1, 1);
      drw = !drw;
      if (p > 0)
      {
        y += yIncr;
        p += pru;
      }
      else p += pr;
      ++x;
    }
    if (drw) this.mkDiv(x, y, 1, 1);
  }
  else
  {
    var pr = dx<<1,
    pru = pr - (dy<<1),
    p = pr-dy;
    while ((dy--) > 0)
    {
      if (drw) this.mkDiv(x, y, 1, 1);
      drw = !drw;
      y += yIncr;
      if (p > 0)
      {
        ++x;
        p += pru;
      }
      else p += pr;
    }
    if (drw) this.mkDiv(x, y, 1, 1);
  }
}

function mkOv(left, top, width, height)
{
  if(height==''){height=1;}
  if(height=='undefined'){height=1;}
  var a = width>>1, b = height>>1,
  wod = width&1, hod = (height&1)+1,
  cx = left+a, cy = top+b,
  x = 0, y = b,
  ox = 0, oy = b,
  aa = (a*a)<<1, bb = (b*b)<<1,
  st = (aa>>1)*(1-(b<<1)) + bb,
  tt = (bb>>1) - aa*((b<<1)-1),
  w, h;
  while (y > 0)
  {
    if (st < 0)
    {
      st += bb*((x<<1)+3);
      tt += (bb<<1)*(++x);
    }
    else if (tt < 0)
    {
      st += bb*((x<<1)+3) - (aa<<1)*(y-1);
      tt += (bb<<1)*(++x) - aa*(((y--)<<1)-3);
      w = x-ox;
      h = oy-y;
      if (w&2 && h&2)
      {
        this.mkOvQds(cx, cy, -x+2, ox+wod, -oy, oy-1+hod, 1, 1);
        this.mkOvQds(cx, cy, -x+1, x-1+wod, -y-1, y+hod, 1, 1);
      }
      else this.mkOvQds(cx, cy, -x+1, ox+wod, -oy, oy-h+hod, w, h);
      ox = x;
      oy = y;
    }
    else
    {
      tt -= aa*((y<<1)-3);
      st -= (aa<<1)*(--y);
    }
  }
  this.mkDiv(cx-a, cy-oy, a-ox+1, (oy<<1)+hod);
  this.mkDiv(cx+ox+wod, cy-oy, a-ox+1, (oy<<1)+hod);
}

function mkOv2D(left, top, width, height)
{
  if(height==''){height=1;}
  if(height=='undefined'){height=1;}
  var s = this.stroke;
  width += s-1;
  height += s-1;
  var a = width>>1, b = height>>1,
  wod = width&1, hod = (height&1)+1,
  cx = left+a, cy = top+b,
  x = 0, y = b,
  aa = (a*a)<<1, bb = (b*b)<<1,
  st = (aa>>1)*(1-(b<<1)) + bb,
  tt = (bb>>1) - aa*((b<<1)-1);
  if (s-4 < 0 && (!(s-2) || width-51 > 0 && height-51 > 0))
  {
    var ox = 0, oy = b,
    w, h,
    pxl, pxr, pxt, pxb, pxw;
    while (y > 0)
    {
      if (st < 0)
      {
        st += bb*((x<<1)+3);
        tt += (bb<<1)*(++x);
      }
      else if (tt < 0)
      {
        st += bb*((x<<1)+3) - (aa<<1)*(y-1);
        tt += (bb<<1)*(++x) - aa*(((y--)<<1)-3);
        w = x-ox;
        h = oy-y;

        if (w-1)
        {
          pxw = w+1+(s&1);
          h = s;
        }
        else if (h-1)
        {
          pxw = s;
          h += 1+(s&1);
        }
        else pxw = h = s;
        this.mkOvQds(cx, cy, -x+1, ox-pxw+w+wod, -oy, -h+oy+hod, pxw, h);
        ox = x;
        oy = y;
      }
      else
      {
        tt -= aa*((y<<1)-3);
        st -= (aa<<1)*(--y);
      }
    }
    this.mkDiv(cx-a, cy-oy, s, (oy<<1)+hod);
    this.mkDiv(cx+a+wod-s+1, cy-oy, s, (oy<<1)+hod);
  }
  else
  {
    var _a = (width-((s-1)<<1))>>1,
    _b = (height-((s-1)<<1))>>1,
    _x = 0, _y = _b,
    _aa = (_a*_a)<<1, _bb = (_b*_b)<<1,
    _st = (_aa>>1)*(1-(_b<<1)) + _bb,
    _tt = (_bb>>1) - _aa*((_b<<1)-1),
    pxl = new Array(),
    pxt = new Array(),
    _pxb = new Array();
    pxl[0] = 0;
    pxt[0] = b;
    _pxb[0] = _b-1;
    while (y > 0)
    {
      if (st < 0)
      {
        st += bb*((x<<1)+3);
        tt += (bb<<1)*(++x);
        pxl[pxl.length] = x;
        pxt[pxt.length] = y;
      }
      else if (tt < 0)
      {
        st += bb*((x<<1)+3) - (aa<<1)*(y-1);
        tt += (bb<<1)*(++x) - aa*(((y--)<<1)-3);
        pxl[pxl.length] = x;
        pxt[pxt.length] = y;
      }
      else
      {
        tt -= aa*((y<<1)-3);
        st -= (aa<<1)*(--y);
      }
      if (_y > 0)
      {
        if (_st < 0)
        {
          _st += _bb*((_x<<1)+3);
          _tt += (_bb<<1)*(++_x);
          _pxb[_pxb.length] = _y-1;
        }
        else if (_tt < 0)
        {
          _st += _bb*((_x<<1)+3) - (_aa<<1)*(_y-1);
          _tt += (_bb<<1)*(++_x) - _aa*(((_y--)<<1)-3);
          _pxb[_pxb.length] = _y-1;
        }
        else
        {
          _tt -= _aa*((_y<<1)-3);
          _st -= (_aa<<1)*(--_y);
          _pxb[_pxb.length-1]--;
        }
      }
    }
    var ox = 0, oy = b,
    _oy = _pxb[0],
    l = pxl.length,
    w, h;
    for (var i = 0; i < l; i++)
    {
      if (typeof _pxb[i] != "undefined")
      {
        if (_pxb[i] < _oy || pxt[i] < oy)
        {
          x = pxl[i];
          this.mkOvQds(cx, cy, -x+1, ox+wod, -oy, _oy+hod, x-ox, oy-_oy);
          ox = x;
          oy = pxt[i];
          _oy = _pxb[i];
        }
      }
      else
      {
        x = pxl[i];
        this.mkDiv(cx-x+1, cy-oy, 1, (oy<<1)+hod);
        this.mkDiv(cx+ox+wod, cy-oy, 1, (oy<<1)+hod);
        ox = x;
        oy = pxt[i];
      }
    }
    this.mkDiv(cx-a, cy-oy, 1, (oy<<1)+hod);
    this.mkDiv(cx+ox+wod, cy-oy, 1, (oy<<1)+hod);
  }
}

function mkOvDott(left, top, width, height)
{
  if(height==''){height=1;}
  if(height=='undefined'){height=1;}
  var a = width>>1, b = height>>1,
  wod = width&1, hod = height&1,
  cx = left+a, cy = top+b,
  x = 0, y = b,
  aa2 = (a*a)<<1, aa4 = aa2<<1, bb = (b*b)<<1,
  st = (aa2>>1)*(1-(b<<1)) + bb,
  tt = (bb>>1) - aa2*((b<<1)-1),
  drw = true;
  while (y > 0)
  {
    if (st < 0)
    {
      st += bb*((x<<1)+3);
      tt += (bb<<1)*(++x);
    }
    else if (tt < 0)
    {
      st += bb*((x<<1)+3) - aa4*(y-1);
      tt += (bb<<1)*(++x) - aa2*(((y--)<<1)-3);
    }
    else
    {
      tt -= aa2*((y<<1)-3);
      st -= aa4*(--y);
    }
    if (drw) this.mkOvQds(cx, cy, -x, x+wod, -y, y+hod, 1, 1);
    drw = !drw;
  }
}
function mkRect(x, y, w, h)
{
  if(h==''){h=1;}
  if(h=='undefined'){h=1;}
  var s = this.stroke;
  this.mkDiv(x, y, w, s);
  this.mkDiv(x+w, y, s, h);
  this.mkDiv(x, y+h, w+s, s);
  this.mkDiv(x, y+s, s, h-s);
}
function mkRectDott(x, y, w, h)
{
  if(h==''){h=1;}
  if(h=='undefined'){h=1;}
  this.drawLine(x, y, x+w, y);
  this.drawLine(x+w, y, x+w, y+h);
  this.drawLine(x, y+h, x+w, y+h);
  this.drawLine(x, y, x, y+h);
}
function jsgFont()
{
  this.PLAIN = 'font-weight:normal;';
  this.BOLD = 'font-weight:bold;';
  this.ITALIC = 'font-style:italic;';
  this.ITALIC_BOLD = this.ITALIC + this.BOLD;
  this.BOLD_ITALIC = this.ITALIC_BOLD;
}
var Font = new jsgFont();
function jsgStroke()
{
  this.DOTTED = -1;
}
var Stroke = new jsgStroke();
function jsGraphics(id, wnd)
{
  this.setColor = new Function('arg', 'this.color = arg.toLowerCase();');
        this.Opacity = 1;
  //this.setOpacity = new Function('arg', 'this.Opacity = arg.toLowerCase();');
  this.setOpacity = function(arg)
  {
    this.Opacity = arg;
  }
  this.setStroke = function(x)
  {
    this.stroke = x;
    if (!(x+1))
    {
      this.drawLine = mkLinDott;
      this.mkOv = mkOvDott;
      this.drawRect = mkRectDott;
    }
    else if (x-1 > 0)
    {
      this.drawLine = mkLin2D;
      this.mkOv = mkOv2D;
      this.drawRect = mkRect;
    }
    else
    {
      this.drawLine = mkLin;
      this.mkOv = mkOv;
      this.drawRect = mkRect;
    }
  };
  this.setPrintable = function(arg)
  {
    this.printable = arg;
    if (jg_fast)
    {
      this.mkDiv = mkDivIe;
      this.htmRpc = arg? htmPrtRpc : htmRpc;
    }
    else this.mkDiv = jg_n4? mkLyr : arg? mkDivPrt : mkDiv;
  };
  this.setFont = function(fam, sz, sty)
  {
    this.ftFam = fam;
    this.ftSz = sz;
    this.ftSty = sty || Font.PLAIN;
  };
  this.drawPolyline = this.drawPolyLine = function(x, y, s)
  {
    for (var i=0 ; i<x.length-1 ; i++ )
      this.drawLine(x[i], y[i], x[i+1], y[i+1]);
  };
  this.fillRect = function(x, y, w, h)
  {
    if(h==''){h=1;}
    if(h=='undefined'){h=1;}
    this.mkDiv(x, y, w, h);
  };
  this.drawPolygon = function(x, y)
  {
    this.drawPolyline(x, y);
    this.drawLine(x[x.length-1], y[x.length-1], x[0], y[0]);
  };
  this.drawEllipse = this.drawOval = function(x, y, w, h)
  {
    if(h==''){h=1;}
    if(h=='undefined'){h=1;}
    this.mkOv(x, y, w, h);
  };
  this.fillEllipse = this.fillOval = function(left, top, w, h)
  {
    var a = (w -= 1)>>1, b = (h -= 1)>>1,
    wod = (w&1)+1, hod = (h&1)+1,
    cx = left+a, cy = top+b,
    x = 0, y = b,
    ox = 0, oy = b,
    aa2 = (a*a)<<1, aa4 = aa2<<1, bb = (b*b)<<1,
    st = (aa2>>1)*(1-(b<<1)) + bb,
    tt = (bb>>1) - aa2*((b<<1)-1),
    pxl, dw, dh;
    if (w+1) while (y > 0)
    {
      if (st < 0)
      {
        st += bb*((x<<1)+3);
        tt += (bb<<1)*(++x);
      }
      else if (tt < 0)
      {
        st += bb*((x<<1)+3) - aa4*(y-1);
        pxl = cx-x;
        dw = (x<<1)+wod;
        tt += (bb<<1)*(++x) - aa2*(((y--)<<1)-3);
        dh = oy-y;
        if(dh==''){dh=1;}
        if(dh=='undefined'){dh=1;}
        this.mkDiv(pxl, cy-oy, dw, dh);
        this.mkDiv(pxl, cy+oy-dh+hod, dw, dh);
        ox = x;
        oy = y;
      }
      else
      {
        tt -= aa2*((y<<1)-3);
        st -= aa4*(--y);
      }
    }
    this.mkDiv(cx-a, cy-oy, w+1, (oy<<1)+hod);
  };
/* fillPolygon method, implemented by Matthieu Haller.
This javascript function is an adaptation of the gdImageFilledPolygon for Walter Zorn lib.
C source of GD 1.8.4 found at http://www.boutell.com/gd/
THANKS to Kirsten Schulz for the polygon fixes!
The intersection finding technique of this code could be improved
by remembering the previous intertersection, and by using the slope.
That could help to adjust intersections to produce a nice
interior_extrema. */
  this.fillPolygon = function(array_x, array_y)
  {
    var i;
    var y;
    var miny, maxy;
    var x1, y1;
    var x2, y2;
    var ind1, ind2;
    var ints;
    var n = array_x.length;
    if (!n) return;
    miny = array_y[0];
    maxy = array_y[0];
    for (i = 1; i < n; i++)
    {
      if (array_y[i] < miny)
        miny = array_y[i];

      if (array_y[i] > maxy)
        maxy = array_y[i];
    }
    for (y = miny; y <= maxy; y++)
    {
      var polyInts = new Array();
      ints = 0;
      for (i = 0; i < n; i++)
      {
        if (!i)
        {
          ind1 = n-1;
          ind2 = 0;
        }
        else
        {
          ind1 = i-1;
          ind2 = i;
        }
        y1 = array_y[ind1];
        y2 = array_y[ind2];
        if (y1 < y2)
        {
          x1 = array_x[ind1];
          x2 = array_x[ind2];
        }
        else if (y1 > y2)
        {
          y2 = array_y[ind1];
          y1 = array_y[ind2];
          x2 = array_x[ind1];
          x1 = array_x[ind2];
        }
        else continue;

         // modified 11. 2. 2004 Walter Zorn
        if ((y >= y1) && (y < y2))
          polyInts[ints++] = Math.round((y-y1) * (x2-x1) / (y2-y1) + x1);

        else if ((y == maxy) && (y > y1) && (y <= y2))
          polyInts[ints++] = Math.round((y-y1) * (x2-x1) / (y2-y1) + x1);
      }
      polyInts.sort(integer_compare);
      for (i = 0; i < ints; i+=2)
        this.mkDiv(polyInts[i], y, polyInts[i+1]-polyInts[i]+1, 1);
    }
  };
  this.drawString = function(txt, x, y)
  {
    this.htm += '<div style="position:absolute;white-space:nowrap;'+
      'left:' + x + 'px;'+
      'top:' + y + 'px;'+
      'font-family:' +  this.ftFam + ';'+
      'font-size:' + this.ftSz + ';'+
      'color:' + this.color + ';' + this.ftSty + '">'+
      txt +
      '<\/div>';
  }
  this.drawImage = function(imgSrc, x, y, w, h)
  {
    if(h==''){h=1;}
    if(h=='undefined'){h=1;}
    this.htm += '<div style="position:absolute;'+
      'left:' + x + 'px;'+
      'top:' + y + 'px;'+
      'width:' +  w + ';'+
      'height:' + h + ';">'+
      '<img src="' + imgSrc + '" width:"' + w + '" height:"' + h + '">'+
      '<\/div>';
  }
  this.clear = function()
  {
    this.htm = "";
    if (this.cnv) this.cnv.innerHTML = this.defhtm;
  };
  this.mkOvQds = function(cx, cy, xl, xr, yt, yb, w, h)
  {
    if(h==''){h=1;}
    if(h=='undefined'){h=1;}
    this.mkDiv(xr+cx, yt+cy, w, h);
    this.mkDiv(xr+cx, yb+cy, w, h);
    this.mkDiv(xl+cx, yb+cy, w, h);
    this.mkDiv(xl+cx, yt+cy, w, h);
  };
  this.setStroke(1);
  this.setFont('verdana,geneva,helvetica,sans-serif', String.fromCharCode(0x31, 0x32, 0x70, 0x78), Font.PLAIN);
  this.color = '#000000';
  this.Opacity = 1;
  this.htm = '';
  this.wnd = wnd || window;
  if (!(jg_ie || jg_dom || jg_ihtm)) chkDHTM();
  if (typeof id != 'string' || !id) this.paint = pntDoc;
  else
  {
    this.cnv = document.all? (this.wnd.document.all[id] || null)
      : document.getElementById? (this.wnd.document.getElementById(id) || null)
      : null;
    this.defhtm = (this.cnv && this.cnv.innerHTML)? this.cnv.innerHTML : '';
    this.paint = jg_dom? pntCnvDom : jg_ie? pntCnvIe : jg_ihtm? pntCnvIhtm : pntCnv;
  }
  this.setPrintable(false);
}

function integer_compare(x,y)
{
  return (x < y) ? -1 : ((x > y)*1);
}


//********************************************************
//********************************************************
//*js graphics - for cross browser drawing of user shapes 
//********************************************************
//********************************************************


//********************************************************
//********************************************************
//*for click-n-drag divs
//********************************************************
//********************************************************
/* x_core.js compiled from X 4.0 with XC 0.27b. Distributed by GNU LGPL. For ;*/
/* copyrights, license, documentation and more visit Cross-Browser.com */

  var xOp7Up;
  var xOp6Dn;
  var xIE4Up;
  var xIE4;
  var xIE5;
  var xNN4;
  var xUA=navigator.userAgent.toLowerCase();

  if(window.opera)
  {
    var i=xUA.indexOf('opera');
    if(i!=-1)
    {
      var v=parseInt(xUA.charAt(i+6));
      xOp7Up=v>=7;
      xOp6Dn=v<7;
    }
  }
  else if(navigator.vendor!='KDE' && document.all && xUA.indexOf('msie')!=-1)
  {
    xIE4Up=parseFloat(navigator.appVersion)>=4;
    xIE4=xUA.indexOf('msie 4')!=-1;
    xIE5=xUA.indexOf('msie 5')!=-1;
  }
  else if(document.layers)
  {
  xNN4=true;  
  }

  xMac=xUA.indexOf('mac')!=-1;
  
  function xBackground(e,c,i)
  {
    if(!(e=xGetElementById(e))) return '';
    var bg='';
    if(e.style) 
    {
      if(xStr(c)) 
      {
        if(!xOp6Dn)
        {
          e.style.backgroundColor=c;
        }
        else
        {
          e.style.background=c;
        }
      }
      if(xStr(i)) e.style.backgroundImage=(i!='')? 'url('+i+')' : null;
      if(!xOp6Dn)
      {
        bg=e.style.backgroundColor;
      }
      else
      {
        bg=e.style.background;
      } 
    }
    return bg;
  }
  
  function xClientHeight()
  {
    var h=0;
    if(xOp6Dn) h=window.innerHeight;
    else if(document.compatMode == 'CSS1Compat' && !window.opera && document.documentElement && document.documentElement.clientHeight)h=document.documentElement.clientHeight;
    else if(document.body && document.body.clientHeight)h=document.body.clientHeight;
    else if(xDef(window.innerWidth,window.innerHeight,document.width)) 
    {
      h=window.innerHeight;
      if(document.width>window.innerWidth) h-=16;  
    }
    return h;
  }
  
  function xClientWidth()
  {
    var w=0;
    if(xOp6Dn) w=window.innerWidth;
    else if(document.compatMode == 'CSS1Compat' && !window.opera && document.documentElement && document.documentElement.clientWidth)w=document.documentElement.clientWidth;
    else if(document.body && document.body.clientWidth)w=document.body.clientWidth;
    else if(xDef(window.innerWidth,window.innerHeight,document.height)) 
    {
      w=window.innerWidth;
      if(document.height>window.innerHeight) w-=16;
    }
    return w;
  }
  
  function xClip(e,t,r,b,l)
  {
    if(!(e=xGetElementById(e))) return;
    if(e.style) 
    {
      if (xNum(l)) e.style.clip='rect('+t+'px '+r+'px '+b+'px '+l+'px)';
      else e.style.clip='rect(0 '+parseInt(e.style.width)+'px '+parseInt(e.style.height)+'px 0)';
    }
  }
  
  function xColor(e,s)
  {
    if(!(e=xGetElementById(e))) return '';
    var c='';
    if(e.style && xDef(e.style.color)) 
    {
      if(xStr(s)) e.style.color=s;
      c=e.style.color;
    }
    return c;  
  }
  
  function xDef()
  {
    for(var i=0;i<arguments.length;++i)
    {
      if(typeof(arguments[i])=='undefined') return false;
    }
    return true;
  }
  
  function xDisplay(e,s)
  {
    if(!(e=xGetElementById(e))) return null;
    if(e.style && xDef(e.style.display)) 
    {
      if (xStr(s)) e.style.display = s;
      return e.style.display;
    }
    return null;  
  }
  
  function xGetComputedStyle(oEle, sProp, bInt)
  {
    var s, p = 'undefined';
    var dv = document.defaultView;
    if(dv && dv.getComputedStyle)
    {
      s = dv.getComputedStyle(oEle,'');
      if (s) p = s.getPropertyValue(sProp);
    }
    else if(oEle.currentStyle) 
    {
      var a = sProp.split('-');
      sProp = a[0];
      for (var i=1;i<a.length;++i) 
      {
        c = a[i].charAt(0);
        sProp += a[i].replace(c, c.toUpperCase());
      }
      p = oEle.currentStyle[sProp];
    }
    else return null;
    return bInt ? (parseInt(p) || 0) : p;
  }
  
  function xGetElementById(e)
  {
    if(typeof(e)!='string') return e;
    if(document.getElementById) e=document.getElementById(e);
    else if(document.all) e=document.all[e];
    else e=null;
    return e;
  }
  
  function xHasPoint(e,x,y,t,r,b,l)
  {
    if (!xNum(t))
    {
      t=r=b=l=0;
    }
    else if (!xNum(r))
    {
      r=b=l=t;
    }
    else if (!xNum(b))
    {
      l=r;
      b=t;
    }
    var eX = xPageX(e), eY = xPageY(e);
    return (x >= eX + l && x <= eX + xWidth(e) - r &&y >= eY + t && y <= eY + xHeight(e) - b );
  }
  
  function xHeight(e,h)
  {
    if(!(e=xGetElementById(e))) return 0;
    if (xNum(h)) 
    {
      if (h<0) h = 0;
      else h=Math.round(h);
    }
    else h=-1;
    var css=xDef(e.style);
    if (e == document || e.tagName.toLowerCase() == 'html' || e.tagName.toLowerCase() == 'body') 
    {
      h = xClientHeight();  
    }
    else if(css && xDef(e.offsetHeight) && xStr(e.style.height)) 
    {
      if(h>=0) 
    {
      var pt=0,pb=0,bt=0,bb=0;
      if (document.compatMode=='CSS1Compat') 
      {
        var gcs = xGetComputedStyle;
        pt=gcs(e,'padding-top',1);
        if (pt !== null) 
        {
          pb=gcs(e,'padding-bottom',1);
          bt=gcs(e,'border-top-width',1);
          bb=gcs(e,'border-bottom-width',1);
        }
        else if(xDef(e.offsetHeight,e.style.height))
        {
           e.style.height=h+'px';
          pt=e.offsetHeight-h;
        }
      }
      h-=(pt+pb+bt+bb);
      if(isNaN(h)||h<0) return;
      else e.style.height=h+'px';
    }
    h=e.offsetHeight;
    }
    else if(css && xDef(e.style.pixelHeight)) 
    {
      if(h>=0) e.style.pixelHeight=h;
      h=e.style.pixelHeight;
    }
    return h;
  }
  
  function xHide(e)
  {
    return xVisibility(e,0);
  }
  
  function xLeft(e, iX)
  {
    if(!(e=xGetElementById(e))) return 0;
    var css=xDef(e.style);
    if (css && xStr(e.style.left)) 
    {
      if(xNum(iX)) e.style.left=iX+'px';
      else 
      {
        iX=parseInt(e.style.left);
        if(isNaN(iX)) iX=0;
      }
    }
    else if(css && xDef(e.style.pixelLeft)) 
    {
      if(xNum(iX)) e.style.pixelLeft=iX;
      else iX=e.style.pixelLeft;  
    }
    return iX;
  }
  
  function xMoveTo(e,x,y)
  {
    if(x<0)x=0;
    xLeft(e,x);
    if(y<0)y=0;
    xTop(e,y);
  }
  
  function xNum()
  {
    for(var i=0;i<arguments.length;++i)
    {
      if(isNaN(arguments[i]) || typeof(arguments[i])!='number') return false;
    }
    return true;  
  }
  
  function xOffsetLeft(e)
  {
    if (!(e=xGetElementById(e))) return 0;
    if (xDef(e.offsetLeft)) return e.offsetLeft;
    else return 0;  
  }
  
  function xOffsetTop(e)
  {
    if (!(e=xGetElementById(e))) return 0;
    if (xDef(e.offsetTop)) return e.offsetTop;
    else return 0;  
  }
  
  function xPageX(e)
  {
    if (!(e=xGetElementById(e))) return 0;
    var x = 0;
    while (e) 
    {
      if (xDef(e.offsetLeft)) x += e.offsetLeft;
      e = xDef(e.offsetParent) ? e.offsetParent : null;
    }
    return x;    
  }
  
  function xPageY(e)
  {
    if (!(e=xGetElementById(e))) return 0;
    var y = 0;
    while (e) 
    {
      if (xDef(e.offsetTop)) y += e.offsetTop;
      e = xDef(e.offsetParent) ? e.offsetParent : null;
    }
    return y;
  }
  
  function xParent(e, bNode)
  {
    if (!(e=xGetElementById(e))) return null;
    var p=null;
    if (!bNode && xDef(e.offsetParent)) p=e.offsetParent;
    else if (xDef(e.parentNode)) p=e.parentNode;
    else if (xDef(e.parentElement)) p=e.parentElement;
    return p;
  }
  
  function xResizeTo(e,w,h)
  {
    xWidth(e,w);
    xHeight(e,h);
  }
  
  function xScrollLeft(e, bWin)
  {
    var offset=0;
    if (!xDef(e) || bWin || e == document || e.tagName.toLowerCase() == 'html' || e.tagName.toLowerCase() == 'body') 
    {
      var w = window;
      if (bWin && e) w = e;
      if(w.document.documentElement && w.document.documentElement.scrollLeft) offset=w.document.documentElement.scrollLeft;
      else if(w.document.body && xDef(w.document.body.scrollLeft)) offset=w.document.body.scrollLeft;
    }
    else 
    {
      e = xGetElementById(e);
      if (e && xNum(e.scrollLeft)) offset = e.scrollLeft;
  
    }
    return offset;
  }
  
  function xScrollTop(e, bWin)
  {
    var offset=0;
    if (!xDef(e) || bWin || e == document || e.tagName.toLowerCase() == 'html' || e.tagName.toLowerCase() == 'body') 
    {
      var w = window;
      if (bWin && e) w = e;
      if(w.document.documentElement && w.document.documentElement.scrollTop) offset=w.document.documentElement.scrollTop;
      else if(w.document.body && xDef(w.document.body.scrollTop)) offset=w.document.body.scrollTop;
    }
    else 
    {
      e = xGetElementById(e);
      if (e && xNum(e.scrollTop)) offset = e.scrollTop;
    }
    return offset;
  }
  
  function xShow(e) 
  {
    return xVisibility(e,1);
  }
  
  function xStr(s)
  {
    for(var i=0;i<arguments.length;++i)
    {
      if(typeof(arguments[i])!='string') return false;
    }
    return true;
  }
  
  function xTop(e, iY)
  {
    if(!(e=xGetElementById(e))) return 0;
    var css=xDef(e.style);
    if(css && xStr(e.style.top)) 
    {
      if(xNum(iY))
      {
        e.style.top=iY+'px';
      }
      else 
      {
        iY=parseInt(e.style.top);
        if(isNaN(iY)) iY=0;
      }
    }
    else if(css && xDef(e.style.pixelTop)) 
    {
      if(xNum(iY)) e.style.pixelTop=iY;
      else iY=e.style.pixelTop;
    }
    return iY;
  }
  
  function xVisibility(e, bShow)
  {
    if(!(e=xGetElementById(e))) return null;
    if(e.style && xDef(e.style.visibility)) 
    {
      if (xDef(bShow)) e.style.visibility = bShow ? 'visible' : 'hidden';
      return e.style.visibility;
    }
    return null;
  }
  
  function xWidth(e,w)
  {
    if(!(e=xGetElementById(e))) return 0;
    if (xNum(w)) 
    {
      if (w<0) w = 0;
      else w=Math.round(w);
    }
    else w=-1;
    var css=xDef(e.style);
    if (e == document || e.tagName.toLowerCase() == 'html' || e.tagName.toLowerCase() == 'body') 
    {
      w = xClientWidth();
    }
    else if(css && xDef(e.offsetWidth) && xStr(e.style.width)) 
    {
      if(w>=0) 
      {
        var pl=0,pr=0,bl=0,br=0;
        if (document.compatMode=='CSS1Compat') 
        {
          var gcs = xGetComputedStyle;
          pl=gcs(e,'padding-left',1);
          if (pl !== null) 
          {
            pr=gcs(e,'padding-right',1);
            bl=gcs(e,'border-left-width',1);
            br=gcs(e,'border-right-width',1);
          }
          else if(xDef(e.offsetWidth,e.style.width))
          {
            e.style.width=w+'px';
            pl=e.offsetWidth-w;
          }
        }
        w-=(pl+pr+bl+br);
        if(isNaN(w)||w<0) return;
        else e.style.width=w+'px';
      }
      w=e.offsetWidth;
      }
      else if(css && xDef(e.style.pixelWidth)) 
      {
      if(w>=0) e.style.pixelWidth=w;
      w=e.style.pixelWidth;
    }
    return w;
  }
  
  function xZIndex(e,uZ)
  {
    if(!(e=xGetElementById(e))) return 0;
    if(e.style && xDef(e.style.zIndex)) 
    {
      if(xNum(uZ)) e.style.zIndex=uZ;
      uZ=parseInt(e.style.zIndex);
    }
    return uZ;
  }

/* x_drag.js compiled from X 4.0 with XC 0.27b. */
/* Distributed by GNU LGPL. For copyrights, license, documentation and more visit Cross-Browser.com */

  function xDisableDrag(id, last)
  {
    if (!window._xDrgMgr)
    {
      return;
    }

    var ele = xGetElementById(id);
    ele.xDraggable = false;
    ele.xODS = null;
    ele.xOD = null;ele.
    xODE = null;
    xRemoveEventListener(ele, 'mousedown', _xOMD, false);

    if (_xDrgMgr.mm && last)
    {
      _xDrgMgr.mm = false;
      xRemoveEventListener(document, 'mousemove', _xOMM, false);
    }
  }

  var _xDrgMgr = {ele:null, mm:false};

  function xEnableDrag(id,fS,fD,fE)
  {
    var ele = xGetElementById(id);
    ele.xDraggable = true;
    ele.xODS = fS;
    ele.xOD = fD;
    ele.xODE = fE;
    xAddEventListener(ele, 'mousedown', _xOMD, false);

    if (!_xDrgMgr.mm)
    {
      _xDrgMgr.mm = true;
      xAddEventListener(document, 'mousemove', _xOMM, false);
    }
  }

  function _xOMD(e) 
  {
    var evt = new xEvent(e);
    var ele = evt.target;
    while(ele && !ele.xDraggable)
    {
      ele = xParent(ele);
    }

    if (ele)
    {
      xPreventDefault(e);
      ele.xDPX = evt.pageX;
      ele.xDPY = evt.pageY;
      _xDrgMgr.ele = ele;
      xAddEventListener(document, 'mouseup', _xOMU, false);

      if (ele.xODS)
      {
        ele.xODS(ele, evt.pageX, evt.pageY);
      }
    }
  }

  function _xOMM(e)
  {
    var evt = new xEvent(e);
    if (_xDrgMgr.ele)
    {
      xPreventDefault(e);
      var ele = _xDrgMgr.ele;
      var dx = evt.pageX - ele.xDPX;
      var dy = evt.pageY - ele.xDPY;
      ele.xDPX = evt.pageX;
      ele.xDPY = evt.pageY;

      if (ele.xOD)
      {
        ele.xOD(ele, dx, dy);
      }else{
        xMoveTo(ele, xLeft(ele) + dx, xTop(ele) + dy);
      }
    }
  }

  function _xOMU(e)
  {
    if (_xDrgMgr.ele)
    {
      xPreventDefault(e);
      xRemoveEventListener(document, 'mouseup', _xOMU, false);
      if (_xDrgMgr.ele.xODE)
      {
        var evt = new xEvent(e);
        _xDrgMgr.ele.xODE(_xDrgMgr.ele, evt.pageX, evt.pageY);
      }_xDrgMgr.ele = null;
    }
  }

/* x_event.js compiled from X 4.0 with XC 0.27b. Distributed by GNU LGPL. For copyrights, license, documentation and more visit Cross-Browser.com */


  function xAddEventListener(e,eT,eL,cap)
  {
  if(!(e=xGetElementById(e))) return;
  eT=eT.toLowerCase();
  if((!xIE4Up && !xOp7Up) && e==window) 
  {
  if(eT=='resize') 
  {
   window.xPCW=xClientWidth();
   window.xPCH=xClientHeight();
   window.xREL=eL;
   xResizeEvent();
   return;
  }
  if(eT=='scroll') 
  {
   window.xPSL=xScrollLeft();
   window.xPST=xScrollTop();
   window.xSEL=eL;
   xScrollEvent();
   return;
  }
  }
  var eh='e.on'+eT+'=eL';
  if(e.addEventListener) e.addEventListener(eT,eL,cap);
  else if(e.attachEvent) e.attachEvent('on'+eT,eL);
  else eval(eh);
  }
  
  function xResizeEvent()
  {
  if (window.xREL) setTimeout('xResizeEvent()', 250);
  var cw = xClientWidth(), ch = xClientHeight();
  if (window.xPCW != cw || window.xPCH != ch) 
  {
   window.xPCW = cw;
   window.xPCH = ch;
   if (window.xREL) window.xREL();
  }
  }
  
  function xScrollEvent()
  {
  if (window.xSEL) setTimeout('xScrollEvent()', 250);
  var sl = xScrollLeft(), st = xScrollTop();
  if (window.xPSL != sl || window.xPST != st) 
  {
   window.xPSL = sl;
   window.xPST = st;
   if (window.xSEL) window.xSEL();
  }
  }
  
  function xEvent(evt) 
  {
  var e = evt || window.event;
  if(!e) return;
  if(e.type) this.type = e.type;
  if(e.target) this.target = e.target;
  else if(e.srcElement) this.target = e.srcElement;
  if (e.relatedTarget) this.relatedTarget = e.relatedTarget;
  else if (e.type == 'mouseover' && e.fromElement) this.relatedTarget = e.fromElement;
  else if (e.type == 'mouseout') this.relatedTarget = e.toElement;
  if(xOp6Dn) 
  {
   this.pageX = e.clientX;
   this.pageY = e.clientY;
  }
  else if(xDef(e.pageX,e.pageY)) 
  {
   this.pageX = e.pageX;
   this.pageY = e.pageY;
  }
  else if(xDef(e.clientX,e.clientY)) 
  {
   this.pageX = e.clientX + xScrollLeft();
   this.pageY = e.clientY + xScrollTop();
  }
  if (xDef(e.offsetX,e.offsetY)) 
  {
  this.offsetX = e.offsetX;
  this.offsetY = e.offsetY;
  }
  else if (xDef(e.layerX,e.layerY)) 
  {
  this.offsetX = e.layerX;
  this.offsetY = e.layerY;
  }
  else 
  {
  this.offsetX = this.pageX - xPageX(this.target);
  this.offsetY = this.pageY - xPageY(this.target);
  }
  if (e.keyCode) 
  {
   this.keyCode = e.keyCode;
  }
   else if (xDef(e.which) && e.type.indexOf('key')!=-1) 
  {
   this.keyCode = e.which;
  }
  this.shiftKey = e.shiftKey;
  this.ctrlKey = e.ctrlKey;
  this.altKey = e.altKey;
  }
  
  function xPreventDefault(e)
  {
  if (e && e.preventDefault) e.preventDefault();
  else if (window.event) window.event.returnValue = false;
  }
  
  function xRemoveEventListener(e,eT,eL,cap)
  {
  if(!(e=xGetElementById(e))) return;
  eT=eT.toLowerCase();
  if((!xIE4Up && !xOp7Up) && e==window) 
  {
  if(eT=='resize') 
  {
   window.xREL=null;
   return;
  }
  if(eT=='scroll') 
  {
   window.xSEL=null;
   return;
  }
  }
  var eh='e.on'+eT+'=null';
  if(e.removeEventListener) e.removeEventListener(eT,eL,cap);
  else if(e.detachEvent) e.detachEvent('on'+eT,eL);
  else eval(eh);
  }
  
  function xStopPropagation(evt)
  {
  if (evt && evt.stopPropagation) evt.stopPropagation();
  else if (window.event) window.event.cancelBubble = true;
  }
  
//********************************************************
//********************************************************
//*ajax form submital using get.
//********************************************************
//********************************************************

   var http_request = false;
   var http_results = '';
   function makeRequest(url, parameters , output,un,up) {
      http_request = false;
      http_results = output;
      if (window.XMLHttpRequest) { // Mozilla, Safari,...
         http_request = new XMLHttpRequest();
         if (http_request.overrideMimeType) {
            // set type accordingly to anticipated content type
            //http_request.overrideMimeType('text/xml');
            //http_request.overrideMimeType('text/html');
         }
      } else if (window.ActiveXObject) { // IE
         try {
            http_request = new ActiveXObject("Msxml2.XMLHTTP");
         } catch (e) {
            try {
               http_request = new ActiveXObject("Microsoft.XMLHTTP");
            } catch (e) {}
         }
      }
      if (!http_request) {
         alert('Cannot create XMLHTTP instance');
         return false;
      }
      http_request.onreadystatechange = alertContents;
      //prompt("",url + parameters)
      http_request.open('GET', url + parameters, true);
      http_request.setRequestHeader('valueu',un);
      http_request.setRequestHeader('valuep',up);
      http_request.send(null);
   }

   function alertContents() {
      if (http_request.readyState == 4) {
         if (http_request.status == 200) {
            //alert(http_request.responseText);
            result = http_request.responseText;         
            if(document.getElementById(http_results)){document.getElementById(http_results).innerHTML = result;}
            //prompt('',result); //document.getElementById('myspan').innerHTML = result;            
         } else {
            alert('There was a problem with the request. - ' + req.statusText);
         }
      }
   }
   
   function get(sendURL,objname,output,un,up) {
     if(un=='undefined'){un='';};
     if(up=='undefined'){up='';};
     obj = document.getElementById(objname)
     var getstr = "?";
      for (i=0; i<obj.childNodes.length; i++) {

         if (typeof(obj.childNodes[i].tagName) != 'undefined'){
           tagname = obj.childNodes[i].tagName.toUpperCase();
         }else{
           tagname = 'none';
         }
        
         if (tagname  == "INPUT") {

            if (typeof(obj.childNodes[i]) != 'undefined'){
              type = obj.childNodes[i].type.toUpperCase();
              //alert(type );
            }else{
              type = '';
            }

            if (type == "TEXT") {
                 getstr += obj.childNodes[i].name + "=" + obj.childNodes[i].value + "&";
            }
            if (type == "HIDDEN") {
               getstr += obj.childNodes[i].name + "=" + obj.childNodes[i].value + "&";
            }
            if (type == "CHECKBOX") {
               if (obj.childNodes[i].checked) {
                  getstr += obj.childNodes[i].name + "=" + obj.childNodes[i].value + "&";
               } else {
                  getstr += obj.childNodes[i].name + "=&";
               }
            }
            if (type == "RADIO") {
               if (obj.childNodes[i].checked) {
                  getstr += obj.childNodes[i].name + "=" + obj.childNodes[i].value + "&";
               }
            }

         }

         if (tagname == "SELECT") {
            var sel = obj.childNodes[i];
            getstr += sel.name + "=" + sel.options[sel.selectedIndex].value + "&";
         }

      }
      makeRequest(sendURL,getstr,output,un,up);
   }