function DSRange(low,high){this.low=low;this.high=high;}
DSRange.prototype.contains=function(n){return n>=this.low&&n<=this.high;};DSRange.prototype.limitNumber=function(number){number=Math.max(parseFloat(number),this.low);return Math.min(number,this.high);};function DSCircle(low,high){this.low=low;this.high=high;}
DSCircle.prototype.limitNumber=function(number){number=parseFloat(number);while(number>this.high){number-=this.high-this.low;}
while(number<this.low){number+=this.high-this.low;}
return number;};function DSCircleSegment(circle,low,high){this.circle=circle;this.low=low;this.high=high;}
DSCircleSegment.prototype.contains=function(point){var p=this.circle.limitNumber(point);if(this.low>this.high){return(p>=this.low&&p<=this.circle.high)||(p>=this.circle.low&&p<=this.high);}else{return p>=this.low&&p<=this.high;}};var DSLatitude=new DSRange(-90,90);var DSLongitude=new DSCircle(-180,180);function DSBoundingBox(lower,upper){this.lower=lower;this.upper=upper;this.width=new DSCircleSegment(DSLongitude,lower.lng,upper.lng);this.height=new DSRange(lower.lat,upper.lat);}
DSBoundingBox.prototype.contains=function(point){return this.width.contains(point.lng)&&this.height.contains(point.lat);};function DSMapTileUrlFactory(base,tileSet,extension,map,suffix){this.base=base||'';this.tileSet=tileSet||'';this.extension=extension||'';this.map=map;this.locale=map.locale||'';this.suffix=suffix||'';this.post=this.extension+'?';this.setPre();}
DSMapTileUrlFactory.prototype.setPre=function(){this.pre=this.base+(this.locale.length?this.locale+'/':'');};DSMapTileUrlFactory.prototype.getPost=function(){return this.post+'w='+this.map.width+'&h='+this.map.height+this.suffix;};DSMapTileUrlFactory.prototype.getUrl=function(x,y,z){return this.pre+z+'/'+x+'/'+y+this.getPost();};DSMapTileUrlFactory.prototype.setLocale=function(locale){this.locale=locale;this.setPre();};function DSCopyright(text,boxes,minzoom,maxzoom,tileset){this.text=text;this.boxes=(typeof boxes.length=='undefined'?[boxes]:boxes);this.minzoom=minzoom;this.maxzoom=maxzoom;this.tileset=tileset;}
DSCopyright.prototype.contains=function(point,zoom,tileset){var t=(!tileset||!this.tileset||(tileset==this.tileset));var z=(!this.minzoom||zoom>=this.minzoom)&&(!this.maxzoom||zoom<=this.maxzoom);var p=false;for(var i=0;i<this.boxes.length;++i){if(this.boxes[i].contains(point)){p=true;break;}}
return p&&z&&t;};function DSCopyrightSet(){this.copyrights=[];}
DSCopyrightSet.prototype.getCopyright=function(point,zoom,tileset){var t=[];if(point&&zoom){for(var i=0;i<this.copyrights.length;++i){if(this.copyrights[i].contains(point,zoom,tileset)){t.push(this.copyrights[i].text);}}}
return t.join(' - ');};DSCopyrightSet.prototype.addCopyright=function(c){this.copyrights.push(c);};function DSMapDecoratorCollection(){this.init();}
LMI.Lang.extend(DSMapDecoratorCollection,DSCollection);DSMapDecoratorCollection.prototype.getByType=function(type){var it=new DSIterator(this),ret=[],d;while((d=it.next())){if(d.type==type){ret.push(d);}}
return ret;};DSMapDecoratorCollection.prototype.getByName=function(name){var it=new DSIterator(this),d;while((d=it.next())){if(d.name==name){return d;}}
return ret;};function DSMapDecorator(map,el,pos,type,name){this.init(map,el,pos,type,name);}
DSMapDecorator.prototype.init=function(map,el,pos,type,name){this.map=map;this.element=el;this.position=pos;this.type=type;this.name=name;this.updatePosition();};DSMapDecorator.prototype.getElement=function(){return this.element;};DSMapDecorator.prototype.getFirstElement=function(){for(i=0,iLen=this.element.childNodes.length;i<iLen;++i){var o=this.element.childNodes[i];if(!LMI.StyleSheet.isClass(o,'skip')){return o;}}};DSMapDecorator.prototype.updatePosition=function(){this.element.style.position='absolute';if(typeof this.position.left!='undefined'){this.element.style.left=parseInt(this.position.left,10)+'px';}
if(typeof this.position.right!='undefined'){this.element.style.right=parseInt(this.position.right,10)+'px';}
if(typeof this.position.top!='undefined'){this.element.style.top=parseInt(this.position.top,10)+'px';}
if(typeof this.position.bottom!='undefined'){this.element.style.bottom=parseInt(this.position.bottom,10)+'px';}
for(var i in{width:'',height:''}){if(typeof this.position[i]!='undefined'){this.element.style[i]=parseInt(this.position[i],10)+'px';}}
if(typeof this.position.zIndex!='undefined'){this.element.style.zIndex=parseInt(this.position.zIndex,10);}};DSMapDecorator.prototype.setPosition=function(pos){for(var i in pos){this.position[i]=pos[i];}
this.updatePosition();};DSMapDecorator.prototype.getPosition=function(){return this.position;};(function(){function InvalidLatException(){this.name='InvalidLatException';}
LMI.Lang.extend(InvalidLatException,TypeError);function InvalidLngException(){this.name='InvalidLngException';}
LMI.Lang.extend(InvalidLngException,TypeError);function degrees(rad){return rad*(180.0/Math.PI);}
var M=LMI.Lang.getObject('LMI.Mapping',true);M.Point=function(lat,lng){this.init(lat,lng);};M.Point.prototype={init:function(lat,lng){this.setLat(lat);this.setLng(lng);},latAsRad:function(){return radians(this.lat);},lngAsRad:function(){return radians(this.lng);},equals:function(p){return p&&this.lat===p.lat&&this.lng===p.lng;},limitLat:function(lat){return DSLatitude.limitNumber(lat);},limitLng:function(lng){return DSLongitude.limitNumber(lng);},toString:function(){return'LMI.Mapping.Point('+this.lat+','+this.lng+')';},setLat:function(lat){var latn=parseFloat(lat);if(latn!=lat||isNaN(latn)){throw new InvalidLatException();}
this.lat=Math.round(this.limitLat(latn)*100000)/100000;},setLng:function(lng){var lngn=parseFloat(lng);if(lngn!=lng||isNaN(lngn)){throw new InvalidLngException();}
this.lng=Math.round(this.limitLng(lngn)*100000)/100000;},setLatFromRad:function(latRad){this.setLat(degrees(latRad));},setLngFromRad:function(lngRad){this.setLng(degrees(lngRad));}};M.Point.fromRadians=function(lat,lng){return new M.Point(degrees(lat),degrees(lng));};})();function DSMapObject(point,element,xOffset,yOffset,zOffset){this.init(point,element,xOffset,yOffset,zOffset);}
DSMapObject.prototype={init:function(point,element,xOffset,yOffset,zOffset){this.setPoint(point);this.element=element;this.xOffset=(xOffset?xOffset:0);this.yOffset=(yOffset?yOffset:0);this.zOffset=(zOffset?zOffset:0);this.properties={};this.initEvents('click','mouseout','mouseover');},setPoint:function(point){this.point=point;},setProperty:function(name,val){return this.properties[name]=val;},setProperties:function(){for(var i=0;i<arguments.length;i++){this.properties[arguments[i]]=arguments[++i];}
return this;},getProperty:function(name){return(name&&name in this.properties?this.properties[name]:"");},getXOffset:function(){return this.xOffset;},getYoffset:function(){return this.yOffset;},getZOffset:function(){return this.zOffset;},getWidth:function(){return this.element.offsetWidth;},getHeight:function(){return this.element.offsetHeight;},isIncludedInBestFit:function(){return!this.getProperty('excludeFromBestFit');},update:function(){},remove:function(){}};LMI.Lang.importFunctions(DSMapObject,LMI.Event);DSMapObject.prototype._addEventListener=DSMapObject.prototype.addEventListener;DSMapObject.prototype.addEventListener=function(type,func){switch(type){case'click':LMI.StyleSheet.setCursor(this.element,'pointer');case'mouseout':case'mouseover':if(this.getListeners(type).length==0){var o=this;LMI.BrowserEvent.addListener(this.element,type,function(evt){var e=new LMI.BrowserEventObject(evt,window.event,this);o.triggerEvent(type,e,o);});}
break;}
this._addEventListener(type,func);};DSMapObject.prototype.bindEvent=function(type,obj,func,arg){var f=function(e,o){func.call(obj,e,o,arg);};return this.addEventListener(type,f);};function DSMapObject_Iterator(coll,offset){this.coll=coll;this.pos=(offset?offset:0);}
function DSMapObject_HasNext(){if(this.coll&&(this.pos+1)<=this.coll.order.length){return true;}
this.pos=0;return false;}
function DSMapObject_Next(){return(this.coll.objects[this.coll.order[this.pos++]]);}
function DSMapObject_GetId(){return this.coll.order[this.pos-1];}
function DSMapObject_SetIteratorOffset(offset){this.pos=offset;}
function DSMapObject_GetIteratorOffset(){return this.pos;}
function DSMapObject_Add(obj){this.objects[this.currIdx]=obj;this.order.push(this.currIdx);return this.currIdx++;}
function DSMapObject_Remove(key){if(this.objects[key]){delete this.objects[key]
for(var i=0;i<this.order.length;++i){if(this.order[i]==key){this.order.splice(i,1);}}
return true;}
return false;}
function DSMapObject_RemoveAll(){this.objects={};this.order=[];this.currPos=this.currIdx=0;}
function DSMapObject_GetByIndex(i){return this.objects[this.order[i]];}
function DSMapObject_GetById(id){return this.objects[id]?this.objects[id]:null;}
function DSMapObject_Size(){return this.order.length;}
function DSMapObject_GetByProperty(name,val){for(var i=0;i<this.order.length;++i){if(this.objects[this.order[i]].getProperty(name)==val){return this.objects[this.order[i]];}}
return null;}
function DSMapObject_GetIdsByProperty(name,val){var ids=[];for(var i=0;i<this.order.length;++i){if(this.objects[this.order[i]].getProperty(name)==val){ids.push(this.order[i]);}}
return ids;}
function DSMapObject_Collection(){this.objects={};this.order=[];this.currPos=this.currIdx=0;}
DSMapObject_Collection.prototype.add=DSMapObject_Add;DSMapObject_Collection.prototype.remove=DSMapObject_Remove;DSMapObject_Collection.prototype.getById=DSMapObject_GetById;DSMapObject_Collection.prototype.getByIndex=DSMapObject_GetByIndex;DSMapObject_Collection.prototype.size=DSMapObject_Size;DSMapObject_Collection.prototype.getByProperty=DSMapObject_GetByProperty;DSMapObject_Collection.prototype.getIdsByProperty=DSMapObject_GetIdsByProperty;DSMapObject_Collection.prototype.removeAll=DSMapObject_RemoveAll;DSMapObject_Iterator.prototype.next=DSMapObject_Next;DSMapObject_Iterator.prototype.getId=DSMapObject_GetId;DSMapObject_Iterator.prototype.hasNext=DSMapObject_HasNext;DSMapObject_Iterator.prototype.setOffset=DSMapObject_SetIteratorOffset;DSMapObject_Iterator.prototype.getOffset=DSMapObject_GetIteratorOffset;function DSIcon(point,iconSrc,xOffset,yOffset,zOffset){this.init(point,iconSrc,xOffset,yOffset,zOffset);}
LMI.Lang.extend(DSIcon,DSMapObject);DSIcon.prototype.init=function(point,iconSrc,xOffset,yOffset,zOffset){var icon=LMI.Element.createImage(iconSrc);LMI.BrowserEvent.addListener(icon,'error',DSIcon.ImageError);DSIcon.superclass.init.call(this,point,icon,xOffset,yOffset,zOffset);};DSIcon.prototype.getIcon=function(){return this.icon;};DSIcon.ImageError=function(evt){var e=new LMI.BrowserEventObject(evt,window.event,this),i=e.getCurrentTarget(),defaultIcon=LMI.Urls.getImg('map_icon_blank.png');if(!LMI.Element.getImageSrc(i).match(defaultIcon)){LMI.Element.setImageSrc(i,defaultIcon);}}
function DSOutline(point,width,height){this.init(point,width,height);}
LMI.Lang.extend(DSOutline,DSMapObject);DSOutline.prototype.init=function(point,width,height){var o=LMI.Element.create('div',null);var e=LMI.Element.create('div',o);LMI.StyleSheet.addClass(o,'outline');LMI.StyleSheet.addClass(e,'fill');LMI.StyleSheet.setOpacity(o,60);LMI.StyleSheet.setOpacity(e,25);DSOutline.superclass.init.call(this,point,o);this.setWidth(width);this.setHeight(height);};DSOutline.prototype.setWidth=function(w){this.element.style.width=w+'px';};DSOutline.prototype.setHeight=function(h){this.element.style.height=h+'px';};function DSPolyLine(shapePoints,url,routeArea,visibleArea){this.init(shapePoints,url,routeArea,visibleArea);}
LMI.Lang.extend(DSPolyLine,DSMapObject);DSPolyLine.prototype.init=function(shapePoints,url,routeArea,visibleArea){this.eventsInited=false;this.shapePoints=shapePoints;this.routeArea=routeArea;this.routeRect=null;this.setVisibleArea(visibleArea);this.timeout=null;var el;if(url){el=document.createElement('img');LMI.BrowserEvent.addListener(el,'load',DSPolyLine.ImageLoad);DSPolyLine.superclass.init.call(this,this.point,el,0,0,-1);this.setLineUrl(url);this.url=url;}else{alert('TODO: create poly line element');el=LMI.Element.create('div',null);DSPolyLine.superclass.init.call(this,this.point,el,0,0,-1);}};DSPolyLine.prototype.updateCallback=function(data){if(data.routeUrl){this.setLineUrl(data.routeUrl);this.setVisibleArea(data.visibleRouteArea);this.map.positionObject(this);}};DSPolyLine.prototype.doUpdateLine=function(m){if(this.timeout){window.clearTimeout(this.timeout);}
var that=this;this.timeout=window.setTimeout(function(){that.timeout=null;that.element.style.display='none';var ur=m.getMapLayerURPoint();var ll=m.getMapLayerLLPoint();var bound=[ll.lng,ll.lat,ur.lng,ur.lat];this.center=m.getCenterPoint();LMI.AjaxController.getRouteImageUrl(function(data){that.updateCallback(data)},that.shapePoints,that.routeArea,bound,m.zoomLevel);},250);};DSPolyLine.prototype.updateLine=function(e,m){if(!this.center&&e.previousCenter){this.center=e.previousCenter;}
if(e.eventType=='zoom'&&e.previousZoomLevel!=m.zoomLevel){this.routeRect=null;this.doUpdateLine(m);}else if(e.eventType=='recenter'){var center=this.center;var newCenter=m.getCenterPoint();var tl=m.gridSystem.getUpperLeftPoint(newCenter.lng,newCenter.lat,this.map.width,this.map.height);var br=m.gridSystem.getLowerRightPoint(newCenter.lng,newCenter.lat,this.map.width,this.map.height);var mapRect=new Rectangle(tl.y,tl.x,br.y,br.x);if(!this.routeRect){this.routeRect=this.calculateRect(this.routeArea,m);}
if(!this.visibleRect){this.visibleRect=this.calculateRect(this.visibleArea,m);}
var routeIntersect=mapRect.intersection(this.routeRect);var visibleIntersect=mapRect.intersection(this.visibleRect);var finalIntersect=routeIntersect.intersection(visibleIntersect);if(!routeIntersect.equals(finalIntersect)){this.doUpdateLine(m);}}};DSPolyLine.prototype.calculateRect=function(area,_map){var tl=_map.gridSystem.toXY(area[0],area[3]);var br=_map.gridSystem.toXY(area[2],area[1]);return new Rectangle(tl.y,tl.x,br.y,br.x);}
DSPolyLine.prototype.update=function(_map){if(!this.eventsInited){this.eventsInited=true;this.map=_map;var o=this;this.updateFunc=function(e,m){o.updateLine(e,m)};_map.addEventListener('zoom',this.updateFunc);_map.addEventListener('recenter',this.updateFunc);}};DSPolyLine.prototype.remove=function(){if(this.eventsInited){this.eventsInited=false;this.map.removeEventListener('zoom',this.updateFunc);this.map.removeEventListener('recenter',this.updateFunc);}};DSPolyLine.prototype.setVisibleArea=function(a){this.visibleArea=a;this.point=new LMI.Mapping.Point(a[3],a[0]);this.visibleRect=null;};DSPolyLine.prototype.setLineUrl=function(url){this.url=url;if(LMI.Browser.browser==='Explorer'&&LMI.Browser.version<7){var el=this.element;var u=url.split('?',2);LMI.Element.setAlphaImageLoader(el,u[0]+'?'+u[1].replace(/%/g,'%25'));}else{this.element.src=url;}};DSPolyLine.ImageLoad=function(evt){var e=new LMI.BrowserEventObject(evt,window.event,this);var i=e.getCurrentTarget();i.style.display='block';i.style.height='auto';i.style.width='auto';};function Rectangle(top,left,bottom,right){this.top=top;this.left=left;this.bottom=bottom;this.right=right;}
Rectangle.prototype.intersection=function(r,dest){var x1=Math.max(this.left,r.left);var y1=Math.max(this.top,r.top);var x2=Math.min(this.right,r.right);var y2=Math.min(this.bottom,r.bottom);if(!dest){dest=new Rectangle();}
dest.top=y1;dest.left=x1;dest.bottom=y2;dest.right=x2;return dest;}
Rectangle.prototype.equals=function(r){return this.left==r.left&&this.top==r.top&&this.right==r.right&&this.bottom==r.bottom;}
var EQUITORIAL_EARTH_RADIUS_MEAN_METERS=6.378245e6;var HALF_PI=Math.PI/2.0;(function(){var L=LMI.Lang.getObject('LMI.Mapping'),radiusMiles=EQUITORIAL_EARTH_RADIUS_MEAN_METERS*0.000621371192;L.getDistance=function(p1,p2){if(p1.equals(p2)){return 0;}
var lat1=p1.latAsRad(),lat2=p2.latAsRad(),lng1=p1.lngAsRad(),lng2=p2.lngAsRad(),c=Math.cos,s=Math.sin;return Math.acos(c(lat1)*c(lng1)*c(lat2)*c(lng2)+
c(lat1)*s(lng1)*c(lat2)*s(lng2)+
s(lat1)*s(lat2))*radiusMiles;};})();function Coord(x,y){this.x=x;this.y=y;}
Coord.prototype.toString=function(){return'Coord('+this.x+','+this.y+')';};function radians(deg){return deg*(Math.PI/180.0);}
LMI.Mapping.Grid=function(p,x_size,y_size,x_units,y_units,invert_y,origin_lon,origin_lat){this._P=p;this._x_grid_size=x_size;this._y_grid_size=y_size;this._x_upg=x_units;this._y_upg=y_units;this._invert_y=invert_y;this._origin_lon=radians(origin_lon);this._origin_lat=radians(origin_lat);this.reset();};LMI.Mapping.Grid.prototype=(function(){return{reset:function(){var pt=this._P.forward(this._origin_lon,this._origin_lat);this._x_translation=-pt.x;this._y_translation=-pt.y;this._x_scale=(this._x_upg/this._x_grid_size);this._y_scale=(this._y_upg/this._y_grid_size)*(this._invert_y?-1.0:1.0);},getXScale:function(){return this._x_scale;},getYScale:function(){return this._y_scale;},gridX:function(x){return Math.floor(x/this._x_upg);},gridY:function(y){return Math.floor(y/this._y_upg);},grid:function(x,y){if(arguments.length===1){var pt=x;return new Coord(this.gridX(pt.x),this.gridY(pt.y));}else{return new Coord(this.gridX(x),this.gridY(y));}},offsetX:function(x){return x%this._x_upg;},offsetY:function(y){return y%this._y_upg;},offset:function(x,y){if(arguments.length===1){var pt=x;return new Coord(this.offsetX(pt.x),this.offsetY(pt.y));}else{return new Coord(this.offsetX(x),this.offsetY(y));}},toX:function(grid){var offset=(arguments.length==2?arguments[1]:0);return(grid*this._x_upg)+offset;},toY:function(grid){var offset=(arguments.length==2?arguments[1]:0);return(grid*this._y_upg)+offset;},toXY:function(gridX,offsetX,gridY,offsetY){if(arguments.length==2){var lon=gridX;var lat=offsetX;var xy=this._P.forward(radians(lon),radians(lat));return new Coord((xy.x+this._x_translation)*this._x_scale,(xy.y+this._y_translation)*this._y_scale);}else{return new Coord(this.toX(gridX,offsetX),this.toY(gridY,offsetY));}},toLL:function(x,y){if(arguments.length==1){y=arguments[0].y;x=arguments[0].x;}
return this._P.inverse((x/this._x_scale)-this._x_translation,(y/this._y_scale)-this._y_translation);},getUpperLeftPoint:function(center_lon,center_lat,width,height){var xy=this.toXY(center_lon,center_lat);if(this._invert_y){return new Coord(xy.x-(width/2.0),xy.y-(height/2.0));}else{return new Coord(xy.x-(width/2.0),xy.y+(height/2.0));}},getLowerRightPoint:function(center_lon,center_lat,width,height){var xy=this.toXY(center_lon,center_lat);if(this._invert_y){return new Coord(xy.x+(width/2.0),xy.y+(height/2.0));}else{return new Coord(xy.x+(width/2.0),xy.y-(height/2.0));}},getLowerLeftPoint:function(center_lon,center_lat,width,height){var xy=this.toXY(center_lon,center_lat);if(this._invert_y){return new Coord(xy.x-(width/2.0),xy.y+(height/2.0));}else{return new Coord(xy.x-(width/2.0),xy.y-(height/2.0));}},getUpperRightPoint:function(center_lon,center_lat,width,height){var xy=this.toXY(center_lon,center_lat);if(this._invert_y){return new Coord(xy.x+(width/2.0),xy.y-(height/2.0));}else{return new Coord(xy.x+(width/2.0),xy.y+(height/2.0));}}};})();LMI.Mapping.Grid.newInstance=function(size_x,size_y,tile_width,tile_height,standard_parallel){return new LMI.Mapping.Grid(new EquiRectangularMapProjection(radians(0.0),radians(standard_parallel)),size_x,size_y,tile_width,tile_height,true,-180.0,90.0);};function EquiRectangularMapProjection(lon,lat){this._center_lon=lon;this._center_lat=lat;this._cos_center_lat=Math.cos(lat);this._R=EQUITORIAL_EARTH_RADIUS_MEAN_METERS;}
function adjust_lon(lon){if(lon<-Math.PI){return lon-(Math.floor(lon/Math.PI)*Math.PI);}else if(lon>Math.PI){return-(Math.PI-lon+(Math.floor(lon/Math.PI)*Math.PI));}
return lon;}
EquiRectangularMapProjection.prototype.forward=function(lon,lat){return new Coord(this._R*adjust_lon(lon-this._center_lon)*this._cos_center_lat,this._R*lat);};EquiRectangularMapProjection.prototype.inverse=function(x,y){return LMI.Mapping.Point.fromRadians(Math.min(y/this._R,HALF_PI),adjust_lon(this._center_lon+x/(this._R*this._cos_center_lat)));};(function(){var M=LMI.Lang.getObject('LMI.Mapping',true),scales=[1.7021276,3.4042553,6.80851064,13.61702128,27.23404256,54.46808512,108.93617024,217.87234048,435.74468096,871.48936192,1742.97872384,3485.95744768,6971.9148953,13943.82979072],grid=[],scalesInited=false;M.Map=function(container,options){this.init(container,options);};M.Map.prototype={setZoomLevel:function(z,p){this.prepareEventObject();if(z<1){z=1;}else if(z>scales.length){z=scales.length;}
if(this.zoomSlider&&this.zoomSlider.shown){this.zoomSlider.setPosition(((z-1)/(scales.length-1)));}
if(p&&!p.equals(this.getCenterPoint())){this.setCenterPoint(p);}
this.zoomLevel=z;this.setScale();this.loadTiles();this.triggerEvent('zoom',this.getEventObject(),this);},bestFit:function(factor,collection){if(typeof factor==='number'){this.factor=factor;}else if(typeof this.factor==='number'){factor=this.factor;}else{this.factor=factor=0.9;}
collection=collection||this.objects;var i,p,pt,maxpt=null,minpt=null,it=new DSMapObject_Iterator(collection);P=this.gridSystem._P;while(it.hasNext()){p=it.next();if(!p.isIncludedInBestFit()){continue;}
if(maxpt===null){maxpt=P.forward(p.point.lngAsRad(),p.point.latAsRad());}
if(minpt===null){minpt=new Coord(maxpt.x,maxpt.y);}
pt=P.forward(p.point.lngAsRad(),p.point.latAsRad());if(pt.x<minpt.x){minpt.x=pt.x;}
if(pt.x>maxpt.x){maxpt.x=pt.x;}
if(pt.y<minpt.y){minpt.y=pt.y;}
if(pt.y>maxpt.y){maxpt.y=pt.y;}}
if(maxpt===null){if(this.getOption('defaultLat')&&this.getOption('defaultLng')&&this.getOption('emptyZoom')){this.centerAndZoom(new M.Point(this.getOption('defaultLat'),this.getOption('defaultLng')),this.getOption('emptyZoom'));}}else if(minpt.x===maxpt.x&&minpt.y===maxpt.y){var ll=P.inverse(minpt.x,minpt.y);this.centerAndZoom(ll,this.getOption('singleZoom'));}else{var midll=P.inverse((minpt.x+maxpt.x)/2.0,(minpt.y+maxpt.y)/2.0);var width=this.width*factor;var height=this.height*factor;var dist_x=maxpt.x-minpt.x;var dist_y=maxpt.y-minpt.y;dist_x*=width/height;for(i=0;i<scales.length;++i){if(dist_x<=(width/grid[i].getXScale())&&dist_y<=Math.abs(height/grid[i].getYScale())){break;}}
var zoom=Math.min(i,scales.length-1);this.centerAndZoom(midll,zoom+1);}},centerOnPoint:function(p){if(!p.equals(this.getCenterPoint())){this.prepareEventObject();this.setCenterPoint(new M.Point(p.lat,p.lng));this.loadTiles();var o=this.getEventObject();this.triggerEvent('recenter',o,this);}},centerAndZoom:function(p,z){this.prepareEventObject();this.setZoomLevel(z,p);var o=this.getEventObject();this.triggerEvent('recenter',o,this);},init:function(cont,options){var container=(typeof cont==='string')?container=LMI.Element.getOne(cont):cont;if(!container){throw('Map: unable to find container: "'+cont+'"');}
this.container=container;LMI.StyleSheet.addClass(container,'dsMap');this.initOptions(options);this.decorators=new DSMapDecoratorCollection();this.centerPoint=null;this.zoomLevel=scales.length;this.locale=this.getOption('defaultLocale');if(!scalesInited){for(var i=0;i<scales.length;++i){grid[i]=LMI.Mapping.Grid.newInstance(scales[i]*this.getOption('tileWidth'),scales[i]*this.getOption('tileHeight'),this.getOption('tileWidth'),this.getOption('tileHeight'),this.getOption('standardParallel'));}
scalesInited=true;}
var year=new Date().getYear();if(year<1000){year+=1900;}
this.copyrightTxt='\xa9'+year+' Local Matters, Inc.';this.copyrightSet=DSMapCopyrightSet;this.setScale();this.setGridLeft(null);this.setGridTop(null);this.columns=this.rows=0;this.initContainer();this.tileUrlFactory=new DSMapTileUrlFactory(this.getOption('tileBase'),'',this.getOption('tileExtension'),this,this.getOption('tileSuffix'));this.objects=new DSMapObject_Collection();this.initEvents('zoom','recenter','resize');},initOptions:function(options){this.options=LMI.Mapping.Map.Defaults;if(typeof options!='undefined'){for(var i in options){this.options[i]=options[i];}}},setLocale:function(locale){this.locale=locale;this.tileUrlFactory.setLocale(locale);},setOption:function(key,value){this.options[key]=value;},getOption:function(key){return this.options[key]||'';},addDecorator:function(d){this.decorators.push(d);this.decoratorLayer.appendChild(d.getElement());},removeDecorator:function(d){var l=this.decorators.getLength();for(var i=0;i<l;++i){if(this.decorators.getByIndex(i)===d){this.decorators.remove(i);this.decoratorLayer.removeChild(d.getElement());return;}}},positionTile:function(i){var t=this.tiles[i];t.setLeft(((i%this.columns)*t.getWidth()+this.mlOffsetLeft)+'px');t.setTop((Math.floor(i/this.columns)*t.getHeight()+this.mlOffsetTop)+'px');},prepareEventObject:function(){this.beforeEvent={previousZoomLevel:this.zoomLevel,previousCenter:this.getCenterPoint()};},getEventObject:function(){var o=this.beforeEvent;this.beforeEvent={};o.zoomLevel=this.zoomLevel;o.center=this.getCenterPoint();return o;},setCopyright:function(copyrightStr){this.copyright.getElement().firstChild.nodeValue=this.copyrightTxt=copyrightStr;},setGridLeft:function(n){return(this.gridLeft=n);},getGridLeft:function(){return this.gridLeft;},setGridTop:function(n){return(this.gridTop=n);},getGridTop:function(){return this.gridTop;},getScale:function(l){if(typeof l=='number'){return scales[l-1];}
return this.scale;},setScale:function(){this.scale=scales[this.zoomLevel-1];this.gridSystem=grid[this.zoomLevel-1];},positionMap:function(){var xy=this.getMapLayerXYByPoint(this.getCenterPoint());this.mapLayer.style.left=Math.round((this.width/2)-xy.x)+'px';this.mapLayer.style.top=Math.round((this.height/2)-xy.y)+'px';},updateTiles:function(){for(var i=0;i<this.tiles.length;++i){this.tiles[i].setSize(this.getOption('tileWidth'),this.getOption('tileHeight'));this.positionTile(i);}
this.updateDataCopyright();},updateMap:function(){this.updateTiles();},calculateGridPosition:function(){var p=this.getCenterPoint();var tl=this.gridSystem.getUpperLeftPoint(p.lng,p.lat,this.mapLayerWidth,this.mapLayerHeight);var tlTile=this.gridSystem.grid(tl);this.setGridLeft(tlTile.x);this.setGridTop(tlTile.y);},loadTiles:function(){this.mlOffsetTop=this.mlOffsetLeft=0;var o=0;this.calculateGridPosition();for(var i=this.getGridTop();i<this.getGridTop()+this.rows;++i){for(var j=this.getGridLeft();j<this.getGridLeft()+this.columns;++j){this.tiles[o++].setUrl(this.tileUrlFactory.getUrl(j,i,this.zoomLevel));}}
this.updateMap();this.positionMap();this.updateObjects();},updateObjects:function(){for(var it=new DSMapObject_Iterator(this.objects);it.hasNext();){this.positionObject(it.next());}},getMapLayerULXY:function(){var s=this.mapLayer.style;return new Coord(parseInt(s.left,10),parseInt(s.top,10));},getMapLayerXYByPoint:function(p){if(this.getGridLeft()!==null&&this.getGridTop()!==null){var x=this.gridSystem.toX(this.getGridLeft());var y=this.gridSystem.toY(this.getGridTop());var xy=this.gridSystem.toXY(p.lng,p.lat);return new Coord(Math.round(xy.x-x),Math.round(xy.y-y));}
return null;},getXYByPoint:function(p){var xy=this.getMapLayerXYByPoint(p);if(xy){xy.x+=this.getMapLeft();xy.y+=this.getMapTop();}
return xy;},getPointByMapLayerXY:function(x,y){if(this.getGridLeft()!==null&&this.getGridTop()!==null){return this.gridSystem.toLL(this.gridSystem.toXY(this.getGridLeft(),x-this.mlOffsetLeft,this.getGridTop(),y-this.mlOffsetTop));}
return null;},getPointByXY:function(x,y){return this.getPointByMapLayerXY(x-this.getMapLeft(true),y-this.getMapTop(true));},setCenterPoint:function(p){this.centerPoint=p;},getCenterPoint:function(){return this.centerPoint;},getMapLayerCenterXY:function(){return new Coord((this.width/2)-this.getMapLeft(),(this.height/2)-this.getMapTop());},getULPoint:function(){return this.getPointByXY(0,0);},getBRPoint:function(){return this.getPointByXY(this.width,this.height);},calculateCenterPoint:function(){return this.getPointByXY(Math.floor(this.width/2),Math.floor(this.height/2));},recalculateCenterPoint:function(){this.setCenterPoint(this.calculateCenterPoint());},getMapLayerCenterPoint:function(){var p=this.getCenterPoint();var center=this.gridSystem.toXY(p.lng,p.lat);var xy=this.getMapLayerCenterXY();xy.x-=this.mapLayerWidth/2;xy.y-=this.mapLayerHeight/2;return this.getPointByXY(this.width/2-xy.x,this.height/2-xy.y);},getMapLayerLLPoint:function(){var p=this.getMapLayerCenterPoint();var xy=this.gridSystem.getLowerLeftPoint(p.lng,p.lat,this.mapLayerWidth,this.mapLayerHeight);return this.gridSystem.toLL(xy.x,xy.y);},getMapLayerURPoint:function(){var p=this.getMapLayerCenterPoint();var xy=this.gridSystem.getUpperRightPoint(p.lng,p.lat,this.mapLayerWidth,this.mapLayerHeight);return this.gridSystem.toLL(xy.x,xy.y);},positionObject:function(obj,point){if(typeof point!='undefined'){obj.setPoint(point);}
var xy=this.getMapLayerXYByPoint(obj.point);if(xy){obj.element.style.left=(xy.x-obj.xOffset+this.mlOffsetLeft)+'px';obj.element.style.top=(xy.y-obj.yOffset+this.mlOffsetTop)+'px';}
obj.update(this);},addObject:function(obj){var id=this.objects.add(obj);this.mapLayer.appendChild(obj.element);obj.element.style.position='absolute';obj.z=5+obj.zOffset;obj.element.style.zIndex=obj.z;this.positionObject(obj);return id;},removeObject:function(o){var id=-1;if(typeof o==='object'){for(var it=new DSMapObject_Iterator(this.objects);it.hasNext();){var i=it.next();if(i===o){id=it.getId();break;}}}else{id=o;}
var obj=this.objects.getById(id);if(obj){obj.remove(this);this.mapLayer.removeChild(obj.element);this.objects.remove(id);}},removeAll:function(){var o;for(var it=new DSMapObject_Iterator(this.objects);it.hasNext();){o=it.next();o.remove(this);o.element.parentNode.removeChild(o.element);}
this.objects.removeAll();},updateDataCopyright:function(){if(!this.dataCopyright){var c=LMI.Element.create('div',null,{textValue:' ',className:'dataCopyright'});var pos={zIndex:100,bottom:0};if(this.width>=250){pos.right=0;}else{pos.left=0;}
this.dataCopyright=new DSMapDecorator(this,c,pos,'copyright','data copyright');this.addDecorator(this.dataCopyright);}
this.dataCopyright.getElement().firstChild.nodeValue=this.copyrightSet.getCopyright(this.getCenterPoint(),this.zoomLevel);},addCopyright:function(){var t=LMI.Element.create('div',null,{textValue:this.copyrightTxt});LMI.StyleSheet.addClass(t,'copyright');this.copyright=new DSMapDecorator(this,t,{bottom:this.width>=250?0:10},'copyright','main copyright');this.addDecorator(this.copyright);this.updateDataCopyright();},sizeLayers:function(){this.width=parseInt(this.container.clientWidth,10);this.height=parseInt(this.container.clientHeight,10);this.desiredRows=Math.ceil(this.height/this.getOption('tileHeight'))+2;this.desiredColumns=Math.ceil(this.width/this.getOption('tileWidth'))+2;this.mapLayerWidth=this.desiredColumns*this.getOption('tileWidth');this.mapLayerHeight=this.desiredRows*this.getOption('tileHeight');this.mapLayer.style.height=this.mapLayerHeight+'px';this.mapLayer.style.width=this.mapLayerWidth+'px';this.viewport.style.height=this.height+'px';this.viewport.style.width=this.width+'px';this.decoratorLayer.style.height=this.height+'px';this.decoratorLayer.style.width=this.width+'px';},initContainer:function(){this.decoratorLayer=LMI.Element.create('div',this.container,{'class':'decLayer'});this.viewport=LMI.Element.create('div',this.decoratorLayer,{'class':'viewport'});this.mapLayer=LMI.Element.create('div',this.viewport,{'class':'mapLayer'});this.tileLayer=LMI.Element.create('div',this.mapLayer,{'class':'tileLayer'});if(!this.getOption('controlBuffer')){this.setOption('controlBuffer',0);}
this.sizeLayers();this.tiles=[];for(var i=0;i<this.desiredRows;++i){for(var j=0;j<this.desiredColumns;++j){this.tiles.push(new M.Tile(this,this.tileLayer));}}
this.rows=this.desiredRows;this.columns=this.desiredColumns;this.mlOffsetTop=this.mlOffsetLeft=0;this.addCopyright();},getMapLeft:function(unadjusted){var l=parseInt(LMI.StyleSheet.getStyle(this.mapLayer,'left'),10);if(!unadjusted){l+=this.mlOffsetLeft;}
return l;},getMapTop:function(unadjusted){var t=parseInt(LMI.StyleSheet.getStyle(this.mapLayer,'top'),10);if(!unadjusted){t+=this.mlOffsetTop;}
return t;}};LMI.Lang.importFunctions(M.Map,LMI.Event);M.Map.setScales=function(s){scales=s;};M.Map.getScales=function(){return scales;};})();LMI.Mapping.Map.Defaults={'singleZoom':3,'emptyZoom':14,'defaultLat':39.73926,'defaultLng':-104.98478,'defaultLocale':'','imageBase':'img/','pixelUrl':'img/pixel_trans.gif','brokenUrl':'img/map_unavailable.gif','tileBase':'http://localhost/tiles/','tileExtension':'.png','tileSuffix':'','tileWidth':256,'tileHeight':256,'tileAttempts':1,'standardParallel':40};(function(){var errors={};LMI.Mapping.Tile=function(map,parent){this.map=map;this.img=LMI.Element.create('img',parent,{src:map.getOption('pixelUrl'),style:'position: absolute;',galleryImg:'no'});LMI.StyleSheet.setOpacity(this.img,0);LMI.BrowserEvent.bind(this.img,'load',this,this.load);LMI.BrowserEvent.bind(this.img,'error',this,this.error);};LMI.Mapping.Tile.prototype={error:function(){var i=this.img,attempts=this.map.getOption('tileAttempts'),broken=this.map.getOption('brokenUrl'),pixel=this.map.getOption('pixelUrl');if(!errors[i.src]){errors[i.src]=1;}
if(errors[i.src]++<attempts){var s=i.src;i.src=pixel;i.src=s;}else if(!i.src.match(broken)){i.src=broken;}},load:function(evt){var a;if('Animation'in LMI){a=new LMI.Animation.Fade(this.img,0,100);a.setDuration(.75);a.start();}else{LMI.StyleSheet.setOpacity(this.img,100);}},removeFromDom:function(){LMI.Element.destroy(this.img);},setSize:function(width,height){this.width=this.img.width=width;this.height=this.img.height=height;},getWidth:function(){return this.width;},getHeight:function(){return this.height;},setLeft:function(left){this.img.style.left=left;},setTop:function(top){this.img.style.top=top;},setUrl:function(url){if(typeof this.img.complete!='undefined'&&!this.img.complete){var o=this;window.setTimeout(function(){o.setUrl(url);},1000);return;}
if(url){if(this.img.src!=url){LMI.StyleSheet.setOpacity(this.img,1);this.img.src=url;}}else{this.img.src=this.map.getOption('brokenUrl');}}};})();var DSMapCopyrightSet=new DSCopyrightSet();(function(){var year=new Date().getYear(),P=LMI.Mapping.Point;if(year<1000){year+=1900;}
var nt=new DSCopyright('\xa9'+year+' NAVTEQ',[new DSBoundingBox(new P(10.0,-135.0),new P(70.0,-60.0)),new DSBoundingBox(new P(48.0,-180.0),new P(75.0,-124.0)),new DSBoundingBox(new P(16.860777,-161.283172),new P(24.219651,-153.424705)),new DSBoundingBox(new P(12.5,-78.6),new P(33.0,-50.0))]);var ta=new DSCopyright('\xa9'+year+' TeleAtlas',[new DSBoundingBox(new P(48.478825,1.322422),new P(52.521175,7.677558)),new DSBoundingBox(new P(31.0,-10),new P(44.0,5.0)),new DSBoundingBox(new P(48.0,-0.6),new P(56.0,11.5)),new DSBoundingBox(new P(46.0,-20.0),new P(61.0,4.7))]);var tl='\xa9'+year+' Terralink Intl Ltd';DSMapCopyrightSet.addCopyright(nt);DSMapCopyrightSet.addCopyright(ta);DSMapCopyrightSet.addCopyright(new DSCopyright(tl,new DSBoundingBox(new P(-70.0,133.0),new P(-11.0,180.0))));})();if(DWREngine==null)var DWREngine={};DWREngine.setErrorHandler=function(handler){DWREngine._errorHandler=handler;};DWREngine.setWarningHandler=function(handler){DWREngine._warningHandler=handler;};DWREngine.setTimeout=function(timeout){DWREngine._timeout=timeout;};DWREngine.setPreHook=function(handler){DWREngine._preHook=handler;};DWREngine.setPostHook=function(handler){DWREngine._postHook=handler;};DWREngine.XMLHttpRequest=1;DWREngine.IFrame=2;DWREngine.setMethod=function(newMethod){if(newMethod!=DWREngine.XMLHttpRequest&&newMethod!=DWREngine.IFrame){DWREngine._handleError("Remoting method must be one of DWREngine.XMLHttpRequest or DWREngine.IFrame");return;}
DWREngine._method=newMethod;};DWREngine.setVerb=function(verb){if(verb!="GET"&&verb!="POST"){DWREngine._handleError("Remoting verb must be one of GET or POST");return;}
DWREngine._verb=verb;};DWREngine.setOrdered=function(ordered){DWREngine._ordered=ordered;};DWREngine.setAsync=function(async){DWREngine._async=async;};DWREngine.setTextHtmlHandler=function(handler){DWREngine._textHtmlHandler=handler;}
DWREngine.defaultMessageHandler=function(message){if(typeof message=="object"&&message.name=="Error"&&message.description){alert("Error: "+message.description);}
else{if(message.toString().indexOf("0x80040111")==-1){alert(message);}}};DWREngine.beginBatch=function(){if(DWREngine._batch){DWREngine._handleError("Batch already started.");return;}
DWREngine._batch={map:{callCount:0},paramCount:0,ids:[],preHooks:[],postHooks:[]};};DWREngine.endBatch=function(options){var batch=DWREngine._batch;if(batch==null){DWREngine._handleError("No batch in progress.");return;}
if(options&&options.preHook)batch.preHooks.unshift(options.preHook);if(options&&options.postHook)batch.postHooks.push(options.postHook);if(DWREngine._preHook)batch.preHooks.unshift(DWREngine._preHook);if(DWREngine._postHook)batch.postHooks.push(DWREngine._postHook);if(batch.method==null)batch.method=DWREngine._method;if(batch.verb==null)batch.verb=DWREngine._verb;if(batch.async==null)batch.async=DWREngine._async;if(batch.timeout==null)batch.timeout=DWREngine._timeout;batch.completed=false;DWREngine._batch=null;if(!DWREngine._ordered){DWREngine._sendData(batch);DWREngine._batches[DWREngine._batches.length]=batch;}
else{if(DWREngine._batches.length==0){DWREngine._sendData(batch);DWREngine._batches[DWREngine._batches.length]=batch;}
else{DWREngine._batchQueue[DWREngine._batchQueue.length]=batch;}}};DWREngine._errorHandler=DWREngine.defaultMessageHandler;DWREngine._warningHandler=null;DWREngine._preHook=null;DWREngine._postHook=null;DWREngine._batches=[];DWREngine._batchQueue=[];DWREngine._handlersMap={};DWREngine._method=DWREngine.XMLHttpRequest;DWREngine._verb="POST";DWREngine._ordered=false;DWREngine._async=true;DWREngine._batch=null;DWREngine._timeout=0;DWREngine._DOMDocument=["Msxml2.DOMDocument.6.0","Msxml2.DOMDocument.5.0","Msxml2.DOMDocument.4.0","Msxml2.DOMDocument.3.0","MSXML2.DOMDocument","MSXML.DOMDocument","Microsoft.XMLDOM"];DWREngine._XMLHTTP=["Msxml2.XMLHTTP.6.0","Msxml2.XMLHTTP.5.0","Msxml2.XMLHTTP.4.0","MSXML2.XMLHTTP.3.0","MSXML2.XMLHTTP","Microsoft.XMLHTTP"];DWREngine._execute=function(path,scriptName,methodName,vararg_params){var singleShot=false;if(DWREngine._batch==null){DWREngine.beginBatch();singleShot=true;}
var args=[];for(var i=0;i<arguments.length-3;i++){args[i]=arguments[i+3];}
if(DWREngine._batch.path==null){DWREngine._batch.path=path;}
else{if(DWREngine._batch.path!=path){DWREngine._handleError("Can't batch requests to multiple DWR Servlets.");return;}}
var params;var callData;var firstArg=args[0];var lastArg=args[args.length-1];if(typeof firstArg=="function"){callData={callback:args.shift()};params=args;}
else if(typeof lastArg=="function"){callData={callback:args.pop()};params=args;}
else if(lastArg!=null&&typeof lastArg=="object"&&lastArg.callback!=null&&typeof lastArg.callback=="function"){callData=args.pop();params=args;}
else if(firstArg==null){if(lastArg==null&&args.length>2){DWREngine._handleError("Ambiguous nulls at start and end of parameter list. Which is the callback function?");}
callData={callback:args.shift()};params=args;}
else if(lastArg==null){callData={callback:args.pop()};params=args;}
else{DWREngine._handleError("Missing callback function or metadata object.");return;}
var random=Math.floor(Math.random()*10001);var id=(random+"_"+new Date().getTime()).toString();var prefix="c"+DWREngine._batch.map.callCount+"-";DWREngine._batch.ids.push(id);if(callData.method!=null){DWREngine._batch.method=callData.method;delete callData.method;}
if(callData.verb!=null){DWREngine._batch.verb=callData.verb;delete callData.verb;}
if(callData.async!=null){DWREngine._batch.async=callData.async;delete callData.async;}
if(callData.timeout!=null){DWREngine._batch.timeout=callData.timeout;delete callData.timeout;}
if(callData.preHook!=null){DWREngine._batch.preHooks.unshift(callData.preHook);delete callData.preHook;}
if(callData.postHook!=null){DWREngine._batch.postHooks.push(callData.postHook);delete callData.postHook;}
if(callData.errorHandler==null)callData.errorHandler=DWREngine._errorHandler;if(callData.warningHandler==null)callData.warningHandler=DWREngine._warningHandler;DWREngine._handlersMap[id]=callData;DWREngine._batch.map[prefix+"scriptName"]=scriptName;DWREngine._batch.map[prefix+"methodName"]=methodName;DWREngine._batch.map[prefix+"id"]=id;for(i=0;i<params.length;i++){DWREngine._serializeAll(DWREngine._batch,[],params[i],prefix+"param"+i);}
DWREngine._batch.map.callCount++;if(singleShot){DWREngine.endBatch();}};DWREngine._sendData=function(batch){if(batch.map.callCount==0)return;for(var i=0;i<batch.preHooks.length;i++){batch.preHooks[i]();}
batch.preHooks=null;if(batch.timeout&&batch.timeout!=0){batch.interval=setInterval(function(){DWREngine._abortRequest(batch);},batch.timeout);}
var urlPostfix;if(batch.map.callCount==1){urlPostfix=batch.map["c0-scriptName"]+"."+batch.map["c0-methodName"]+".dwr";}
else{urlPostfix="Multiple."+batch.map.callCount+".dwr";}
if(batch.method==DWREngine.XMLHttpRequest){if(window.XMLHttpRequest){batch.req=new XMLHttpRequest();}
else if(window.ActiveXObject&&!(navigator.userAgent.indexOf("Mac")>=0&&navigator.userAgent.indexOf("MSIE")>=0)){batch.req=DWREngine._newActiveXObject(DWREngine._XMLHTTP);}}
var query="";var prop;if(batch.req){batch.map.xml="true";if(batch.async){batch.req.onreadystatechange=function(){DWREngine._stateChange(batch);};}
var indexSafari=navigator.userAgent.indexOf("Safari/");if(indexSafari>=0){var version=navigator.userAgent.substring(indexSafari+7);if(parseInt(version,10)<400)batch.verb=="GET";}
if(batch.verb=="GET"){batch.map.callCount=""+batch.map.callCount;for(prop in batch.map){var qkey=encodeURIComponent(prop);var qval=encodeURIComponent(batch.map[prop]);if(qval=="")DWREngine._handleError("Found empty qval for qkey="+qkey);query+=qkey+"="+qval+"&";}
try{var _url=batch.path;if(_url.indexOf(';')>=0){_url=_url.replace(/(;.*)/,"/exec/"+urlPostfix+"?"+query+"$1");}else{_url+="/exec/"+urlPostfix+"?"+query;}
batch.req.open("GET",_url,batch.async);batch.req.send(null);if(!batch.async)DWREngine._stateChange(batch);}
catch(ex){DWREngine._handleMetaDataError(null,ex);}}
else{for(prop in batch.map){if(typeof batch.map[prop]!="function"){query+=prop+"="+batch.map[prop]+"\n";}}
var _url=batch.path;if(_url.indexOf(';')>=0){_url=_url.replace(/(;.*)/,"/exec/"+urlPostfix+"$1");}else{_url+="/exec/"+urlPostfix;}
try{batch.req.open("POST",_url,batch.async);batch.req.setRequestHeader('Content-Type','text/plain');batch.req.send(query);if(!batch.async)DWREngine._stateChange(batch);}
catch(ex){DWREngine._handleMetaDataError(null,ex);}}}
else{batch.map.xml="false";var idname="dwr-if-"+batch.map["c0-id"];batch.div=document.createElement("div");batch.div.innerHTML="<iframe src='javascript:void(0)' frameborder='0' width='0' height='0' id='"+idname+"' name='"+idname+"'></iframe>";document.body.appendChild(batch.div);batch.iframe=document.getElementById(idname);batch.iframe.setAttribute("style","width:0px; height:0px; border:0px;");if(batch.verb=="GET"){for(prop in batch.map){if(typeof batch.map[prop]!="function"){query+=encodeURIComponent(prop)+"="+encodeURIComponent(batch.map[prop])+"&";}}
query=query.substring(0,query.length-1);batch.iframe.setAttribute("src",batch.path+"/exec/"+urlPostfix+"?"+query);document.body.appendChild(batch.iframe);}
else{batch.form=document.createElement("form");batch.form.setAttribute("id","dwr-form");batch.form.setAttribute("action",batch.path+"/exec"+urlPostfix);batch.form.setAttribute("target",idname);batch.form.target=idname;batch.form.setAttribute("method","POST");for(prop in batch.map){var formInput=document.createElement("input");formInput.setAttribute("type","hidden");formInput.setAttribute("name",prop);formInput.setAttribute("value",batch.map[prop]);batch.form.appendChild(formInput);}
document.body.appendChild(batch.form);batch.form.submit();}}};DWREngine._stateChange=function(batch){if(!batch.completed&&batch.req.readyState==4){try{var reply=batch.req.responseText;if(reply==null||reply==""){DWREngine._handleMetaDataWarning(null,"No data received from server");}
else{var contentType=batch.req.getResponseHeader("Content-Type");if(!contentType.match(/^text\/plain/)&&!contentType.match(/^text\/javascript/)){if(DWREngine._textHtmlHandler&&contentType.match(/^text\/html/)){DWREngine._textHtmlHandler();}
else{DWREngine._handleMetaDataWarning(null,"Invalid content type from server: '"+contentType+"'");}}
else{if(reply.search("DWREngine._handle")==-1){DWREngine._handleMetaDataWarning(null,"Invalid reply from server");}
else{eval(reply);}}}
DWREngine._clearUp(batch);}
catch(ex){if(ex==null)ex="Unknown error occured";DWREngine._handleMetaDataWarning(null,ex);}
finally{if(DWREngine._batchQueue.length!=0){var sendbatch=DWREngine._batchQueue.shift();DWREngine._sendData(sendbatch);DWREngine._batches[DWREngine._batches.length]=sendbatch;}}}};DWREngine._handleResponse=function(id,reply){var handlers=DWREngine._handlersMap[id];DWREngine._handlersMap[id]=null;if(handlers){try{if(handlers.callback)handlers.callback(reply);}
catch(ex){DWREngine._handleMetaDataError(handlers,ex);}}
if(DWREngine._method==DWREngine.IFrame){var responseBatch=DWREngine._batches[DWREngine._batches.length-1];if(responseBatch.map["c"+(responseBatch.map.callCount-1)+"-id"]==id){DWREngine._clearUp(responseBatch);}}};DWREngine._handleServerError=function(id,error){var handlers=DWREngine._handlersMap[id];DWREngine._handlersMap[id]=null;if(error.message)DWREngine._handleMetaDataError(handlers,error.message,error);else DWREngine._handleMetaDataError(handlers,error);};DWREngine._eval=function(script){return eval(script);}
DWREngine._abortRequest=function(batch){if(batch&&!batch.completed){clearInterval(batch.interval);DWREngine._clearUp(batch);if(batch.req)batch.req.abort();var handlers;for(var i=0;i<batch.ids.length;i++){handlers=DWREngine._handlersMap[batch.ids[i]];DWREngine._handleMetaDataError(handlers,"Timeout");}}};DWREngine._clearUp=function(batch){if(batch.completed){DWREngine._handleError("Double complete");return;}
if(batch.div)batch.div.parentNode.removeChild(batch.div);if(batch.iframe)batch.iframe.parentNode.removeChild(batch.iframe);if(batch.form)batch.form.parentNode.removeChild(batch.form);if(batch.req)delete batch.req;for(var i=0;i<batch.postHooks.length;i++){batch.postHooks[i]();}
batch.postHooks=null;for(var i=0;i<DWREngine._batches.length;i++){if(DWREngine._batches[i]==batch){DWREngine._batches.splice(i,1);break;}}
batch.completed=true;};DWREngine._handleError=function(reason,ex){if(DWREngine._errorHandler)DWREngine._errorHandler(reason,ex);};DWREngine._handleWarning=function(reason,ex){if(DWREngine._warningHandler)DWREngine._warningHandler(reason,ex);};DWREngine._handleMetaDataError=function(handlers,reason,ex){if(handlers&&typeof handlers.errorHandler=="function")handlers.errorHandler(reason,ex);else DWREngine._handleError(reason,ex);};DWREngine._handleMetaDataWarning=function(handlers,reason,ex){if(handlers&&typeof handlers.warningHandler=="function")handlers.warningHandler(reason,ex);else DWREngine._handleWarning(reason,ex);};DWREngine._serializeAll=function(batch,referto,data,name){if(data==null){batch.map[name]="null:null";return;}
switch(typeof data){case"boolean":batch.map[name]="boolean:"+data;break;case"number":batch.map[name]="number:"+data;break;case"string":batch.map[name]="string:"+encodeURIComponent(data);break;case"object":if(data instanceof String)batch.map[name]="String:"+encodeURIComponent(data);else if(data instanceof Boolean)batch.map[name]="Boolean:"+data;else if(data instanceof Number)batch.map[name]="Number:"+data;else if(data instanceof Date)batch.map[name]="Date:"+data.getTime();else if(data instanceof Array)batch.map[name]=DWREngine._serializeArray(batch,referto,data,name);else batch.map[name]=DWREngine._serializeObject(batch,referto,data,name);break;case"function":break;default:DWREngine._handleWarning("Unexpected type: "+typeof data+", attempting default converter.");batch.map[name]="default:"+data;break;}};DWREngine._lookup=function(referto,data,name){var lookup;for(var i=0;i<referto.length;i++){if(referto[i].data==data){lookup=referto[i];break;}}
if(lookup)return"reference:"+lookup.name;referto.push({data:data,name:name});return null;};DWREngine._serializeObject=function(batch,referto,data,name){var ref=DWREngine._lookup(referto,data,name);if(ref)return ref;if(data.nodeName&&data.nodeType){return DWREngine._serializeXml(batch,referto,data,name);}
var reply="Object:{";var element;for(element in data){batch.paramCount++;var childName="c"+DWREngine._batch.map.callCount+"-e"+batch.paramCount;DWREngine._serializeAll(batch,referto,data[element],childName);reply+=encodeURIComponent(element)+":reference:"+childName+", ";}
if(reply.substring(reply.length-2)==", "){reply=reply.substring(0,reply.length-2);}
reply+="}";return reply;};DWREngine._serializeXml=function(batch,referto,data,name){var ref=DWREngine._lookup(referto,data,name);if(ref)return ref;var output;if(window.XMLSerializer)output=new XMLSerializer().serializeToString(data);else output=data.toXml;return"XML:"+encodeURIComponent(output);};DWREngine._serializeArray=function(batch,referto,data,name){var ref=DWREngine._lookup(referto,data,name);if(ref)return ref;var reply="Array:[";for(var i=0;i<data.length;i++){if(i!=0)reply+=",";batch.paramCount++;var childName="c"+DWREngine._batch.map.callCount+"-e"+batch.paramCount;DWREngine._serializeAll(batch,referto,data[i],childName);reply+="reference:";reply+=childName;}
reply+="]";return reply;};DWREngine._unserializeDocument=function(xml){var dom;if(window.DOMParser){var parser=new DOMParser();dom=parser.parseFromString(xml,"text/xml");if(!dom.documentElement||dom.documentElement.tagName=="parsererror"){var message=dom.documentElement.firstChild.data;message+="\n"+dom.documentElement.firstChild.nextSibling.firstChild.data;throw message;}
return dom;}
else if(window.ActiveXObject){dom=DWREngine._newActiveXObject(DWREngine._DOMDocument);dom.loadXML(xml);return dom;}
else{var div=document.createElement("div");div.innerHTML=xml;return div;}};DWREngine._newActiveXObject=function(axarray){var returnValue;for(var i=0;i<axarray.length;i++){try{returnValue=new ActiveXObject(axarray[i]);break;}
catch(ex){}}
return returnValue;};if(typeof window.encodeURIComponent==='undefined'){DWREngine._utf8=function(wide){wide=""+wide;var c;var s;var enc="";var i=0;while(i<wide.length){c=wide.charCodeAt(i++);if(c>=0xDC00&&c<0xE000)continue;if(c>=0xD800&&c<0xDC00){if(i>=wide.length)continue;s=wide.charCodeAt(i++);if(s<0xDC00||c>=0xDE00)continue;c=((c-0xD800)<<10)+(s-0xDC00)+0x10000;}
if(c<0x80){enc+=String.fromCharCode(c);}
else if(c<0x800){enc+=String.fromCharCode(0xC0+(c>>6),0x80+(c&0x3F));}
else if(c<0x10000){enc+=String.fromCharCode(0xE0+(c>>12),0x80+(c>>6&0x3F),0x80+(c&0x3F));}
else{enc+=String.fromCharCode(0xF0+(c>>18),0x80+(c>>12&0x3F),0x80+(c>>6&0x3F),0x80+(c&0x3F));}}
return enc;}
DWREngine._hexchars="0123456789ABCDEF";DWREngine._toHex=function(n){return DWREngine._hexchars.charAt(n>>4)+DWREngine._hexchars.charAt(n&0xF);}
DWREngine._okURIchars="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789_-";window.encodeURIComponent=function(s){s=DWREngine._utf8(s);var c;var enc="";for(var i=0;i<s.length;i++){if(DWREngine._okURIchars.indexOf(s.charAt(i))==-1){enc+="%"+DWREngine._toHex(s.charCodeAt(i));}
else{enc+=s.charAt(i);}}
return enc;}}
if(typeof Array.prototype.splice==='undefined'){Array.prototype.splice=function(ind,cnt)
{if(arguments.length==0)return ind;if(typeof ind!="number")ind=0;if(ind<0)ind=Math.max(0,this.length+ind);if(ind>this.length){if(arguments.length>2)ind=this.length;else return[];}
if(arguments.length<2)cnt=this.length-ind;cnt=(typeof cnt=="number")?Math.max(0,cnt):0;removeArray=this.slice(ind,ind+cnt);endArray=this.slice(ind+cnt);this.length=ind;for(var i=2;i<arguments.length;i++)this[this.length]=arguments[i];for(i=0;i<endArray.length;i++)this[this.length]=endArray[i];return removeArray;}}
if(typeof Array.prototype.shift==='undefined'){Array.prototype.shift=function(str){var val=this[0];for(var i=1;i<this.length;++i)this[i-1]=this[i];this.length--;return val;}}
if(typeof Array.prototype.unshift==='undefined'){Array.prototype.unshift=function(){var i=unshift.arguments.length;for(var j=this.length-1;j>=0;--j)this[j+i]=this[j];for(j=0;j<i;++j)this[j]=unshift.arguments[j];}}
if(typeof Array.prototype.push==='undefined'){Array.prototype.push=function(){var sub=this.length;for(var i=0;i<push.arguments.length;++i){this[sub]=push.arguments[i];sub++;}}}
if(typeof Array.prototype.pop==='undefined'){Array.prototype.pop=function(){var lastElement=this[this.length-1];this.length--;return lastElement;}}
LMI.AjaxController=(function(){function handleMessage(errorStr,ex){if(typeof messageHandler==='function'){messageHandler.apply(this,arguments);}
if(typeof LMI.Lang.getObject("LMI.RoadTrip.removeWorkingCursor")==='function'){LMI.RoadTrip.removeWorkingCursor();}}
var path,uid,ptkn,messageHandler,className='mapping',L={getNearestRouteSegment:function(callback,point,shapeData){DWREngine._execute(path,className,'getNearestRouteSegment',callback,point.lat,point.lng,shapeData,uid,ptkn);},editListingNote:function(callback,id,note){DWREngine._execute(path,className,'editListingNote',callback,id,note,uid,ptkn);},saveSavedLocation:function(callback,id,name,address,note){DWREngine._execute(path,className,'saveSavedLocation',callback,id,name,address,note,uid,ptkn);},saveSavedLocationLatLng:function(callback,id,name,address,lat,lng,note){DWREngine._execute(path,className,'saveSavedLocation',callback,id,name,address,lat,lng,note,uid,ptkn);},saveItinerary:function(callback,id,name,locations,locationTypes,properties){DWREngine._execute(path,className,'saveItinerary',callback,id,name,locations,locationTypes,properties,uid,ptkn);},deleteItinerary:function(callback,ids){DWREngine._execute(path,className,'deleteItinerary',callback,ids,uid,ptkn);},getSearchCount:function(callback,what,latitude,longitude,distance,businessName){DWREngine._execute(path,className,'getSearchCount',callback,what,latitude,longitude,distance,businessName,uid,ptkn);},addToMyList:function(callback,listingIds,savedLoc){DWREngine._execute(path,className,'addToMyList',callback,listingIds,savedLoc,uid,ptkn);},getLocations:function(type,callback,cat,lat,lng,radius){if(type==='poi'){L.getPois(callback,cat,lat,lng,radius);}else if(type==='myplaces'){L.getNearbySavedLocations(callback,lat,lng,radius);}},getPois:function(callback,cat,lat,lng,radius){DWREngine._execute(path,className,'getPois',callback,cat,lat,lng,radius,uid,ptkn);},getRoutePois:function(callback,cat,shapePoints,radius){DWREngine._execute(path,className,'getPois',callback,cat,shapePoints,radius,uid,ptkn);},getNearbySavedLocations:function(callback,lat,lng,radius){DWREngine._execute(path,className,'getNearbySavedLocations',callback,lat,lng,radius,uid,ptkn);},getRouteImageUrl:function(callback,shapeData,routeArea,boundingArea,zoomLevel){DWREngine._execute(path,className,'getRouteImageUrl',callback,shapeData,routeArea,boundingArea,zoomLevel,uid,ptkn,'png');},getItineraryImageUrl:function(callback,itinId,boundingArea,zoomLevel,output){output=output||'png';DWREngine._execute(path,className,'getItineraryImageUrl',callback,itinId,boundingArea,zoomLevel,uid,ptkn,output);},getPrintRouteImageUrl:function(callback,shapeData,routeArea,boundingArea,zoomLevel){DWREngine._execute(path,className,'getRouteImageUrl',callback,shapeData,routeArea,boundingArea,zoomLevel,uid,ptkn,'gif');},removeSavedLocations:function(callback,ids){DWREngine._execute(path,className,'removeSavedLocations',callback,ids,uid,ptkn);},findNearby:function(callback,location,locationType,searchType,maxResults,distance){DWREngine._execute(path,className,'findNearby',callback,location,locationType,searchType,maxResults,distance,uid,ptkn);},submitLivingChoicesLead:function(callback,parameters){DWREngine._execute(path,className,'submitLivingChoicesLead',callback,parameters,uid,ptkn);},setSessionValue:function(callback,key,value){DWREngine._execute(path,className,'setVisitorPreference',callback,uid,ptkn,key,value,'SESSION');},getPath:function(){return path;},getClassName:function(){return className;},setMessageHandler:function(handler){messageHandler=handler;}};LMI.Init.addFunction(function(){path=LMI.Urls.get("dwr");uid=LMI.Lang.getObject("LMI.Data.Visitor.uid");ptkn=LMI.Lang.getObject("LMI.Data.Visitor.passwordToken");DWREngine.setErrorHandler(handleMessage);DWREngine.setWarningHandler(handleMessage);});return L;})();