/*
 * Copyright (c) 2005-2006, Image Matters LLC. All Rights Reserved.
 * 
 * This software is distributed under the terms of the LICENSE file
 * included with the program and available here:
 * 
 * http://www.imagemattersllc.com/legal-notice/LICENSE-userSmartsGX.html
 */
namespace("userSmarts.geo");namespace("userSmarts.geo");namespace("userSmarts.geo");function Point(x,y){this.x=x;this.y=y;}
Geometry=Class.create(Bean);$prototype.initialize=function(superClass,type){superClass.call(this,{type:(type||'Geometry'),points:[]});};Geometry.DELETED='deleted';Geometry.UPDATED='updated';Geometry.prototype.remove=function(){this.setProperty(Geometry.DELETED,this);};Geometry.prototype.update=function(){this.setProperty(Geometry.UPDATED,this);};Geometry.prototype.getType=function(){return this.type;};Geometry.prototype.addPoint=function(p){p.x*=1.0;p.y*=1.0;this.points.push(p);};Geometry.prototype.getPoint=function(i){if(i<this.points.length&&i>=0){return this.points[i];}else{return null;}};Geometry.prototype.getPoints=function(){return this.points;};Geometry.prototype.getEnvelope=function(){var env=new Geometry("Box");var minx=null,maxx=null,miny=null,maxy=null;if(this.points.length==1){minx=this.points[0].x;miny=this.points[0].y;env.addPoint(new Point(minx-0.001,miny-0.001));env.addPoint(new Point(minx+0.001,miny+0.001));}else{for(var i=0;i<this.points.length;i++){if(minx===null||this.points[i].x<minx){minx=this.points[i].x;}
if(miny===null||this.points[i].y<miny){miny=this.points[i].y;}
if(maxx===null||this.points[i].x>maxx){maxx=this.points[i].x;}
if(maxy===null||this.points[i].y>maxy){maxy=this.points[i].y;}}
if(minx==maxx){minx-=0.001;maxx+=0.001;}
if(miny==maxy){miny-=0.001;maxy+=0.001;}
env.addPoint(new Point(minx,miny));env.addPoint(new Point(maxx,maxy));}
return env;};Geometry.prototype.getCenter=function(){var env=this.getEnvelope();var cx=(env.points[1].x-env.points[0].x)/2+env.points[0].x;var cy=(env.points[1].y-env.points[0].y)/2+env.points[0].y;return new Point(cx,cy);};Geometry.prototype.getWidth=function(){var env=this.getEnvelope();return(env.points[1].x-env.points[0].x);};Geometry.prototype.getHeight=function(){var env=this.getEnvelope();return(env.points[1].y-env.points[0].y);};Geometry.prototype.getDescription=function(){return this.description||"";};Geometry.prototype.setDescription=function(desc){this.description=desc;};Geometry.prototype.within=function(geometry){var thisEnv=this.getEnvelope();var thatEnv=geometry.getEnvelope();var thisMinX=thisEnv.points[0].x;var thisMinY=thisEnv.points[0].y;var thisMaxX=thisEnv.points[1].x;var thisMaxY=thisEnv.points[1].y;var thatMinX=thatEnv.points[0].x;var thatMinY=thatEnv.points[0].y;var thatMaxX=thatEnv.points[1].x;var thatMaxY=thatEnv.points[1].y;if(thatMinX>thisMinX)return false;if(thatMaxX<thisMaxX)return false;if(thatMinY>thisMinY)return false;if(thatMaxY<thisMaxY)return false;return true;};Geometry.prototype.expandToInclude=function(geom){var result=new Geometry("Box");var env=this.getEnvelope();var otherEnv=geom.getEnvelope();var minx,max,miny,max;minx=Math.min(env.getPoints()[0].x,otherEnv.getPoints()[0].x);miny=Math.min(env.getPoints()[0].y,otherEnv.getPoints()[0].y);maxx=Math.max(env.getPoints()[1].x,otherEnv.getPoints()[1].x);maxy=Math.max(env.getPoints()[1].y,otherEnv.getPoints()[1].y);result.addPoint(new Point(minx,miny));result.addPoint(new Point(maxx,maxy));return result;};Geometry.prototype.dispose=function(){for(var i=0;i<this.points.length;++i){this.points[i]=null;}
this.points=null;this.type=null;};Geometry.prototype.toString=function(){var str=((this.type)?this.type:"Geometry")+"{";for(var i=0;i<this.points.length;i++){str=str+((i>0)?',':'')+'('+this.points[i].x+","+this.points[i].y+')';}
return str+"}";};Geometry.prototype.toBBOXString=function(){var geom=this.getEnvelope();var points=geom.getPoints();var str="";for(var i=0;i<points.length;i++){str+=(i>0?',':'')+points[i].x+","+points[i].y;}
return str;}
Geometry.valueOf=function(str){var startIndex=str.indexOf("{");var x="}";if(startIndex<0){return null;}
var type=str.substring(0,startIndex);var geom=new Geometry(type);var pointStr=str.substring(startIndex+2,str.length-2);if(pointStr===''){return geom;}
var points=pointStr.split('),(');for(var i=0;i<points.length;i++){var xy=points[i].trim().split(',');geom.addPoint(new Point(xy[0].trim()*1.0,xy[1].trim()*1.0));}
return geom;};Geometry.parseGeometry=function(str){var startIndex=str.indexOf('(');if(startIndex<0){return null;}
var type=str.substring(0,startIndex);var geom=new Geometry(type);var pointStr=str.substring(startIndex+1,str.length-1);if(pointStr===''){return geom;}
var points=pointStr.split(',');if((points.length%2)!==0){return geom;}
for(var i=0;i<points.length;i+=2){var x=points[i].trim();var y=points[i+1].trim();geom.addPoint(new Point(x,y));}
return geom;};function createGeometryCloseButton(geometry,location){var button=DIV({'class':'map-label'},'info');button.title=geometry.toString()+".  Click to close.";button.style.position='absolute';button.style.top=(location.y+1)+'px';button.style.left=location.x+'px';connect(button,'onclick',geometry,"remove");connect(button,'onmouseover',function(){button.style.cursor="pointer";});connect(button,'onmouseout',function(){button.style.cursor="default";});return button;}
GeometryFormat=function(){};GeometryFormat.inheritsFrom(Format);GeometryFormat.prototype.parseObject=function(lexical){return Geometry.valueOf(lexical);};GeometryFormat.prototype.format=function(geometry){return(!geometry)?null:geometry.toString();};datatypes.addType({uri:{prefix:'geo',namespaceURI:"geo",localPart:"geometry"},facets:{enumeration:['true','false']},isAtomic:true,isList:true,format:new GeometryFormat()});namespace("userSmarts.geo");function GeometryOverlay(mgr){if(this.isPrototype(arguments)){return;}
this.id='geometry-overlay';this.div=DIV({id:this.id});this.renderer=new userSmarts.geo.renderer.GeometryRenderer();var overlay=new Overlay({id:this.id});overlay.setContent(this.div);overlay.setPosition({x:0,y:0});mgr.add(overlay);}
GeometryOverlay.prototype.registerListenerTo=function(producer){if(producer.addChangeListener){producer.addChangeListener(bind(function(event){this.update(event.newValue);},this),'updated');}};GeometryOverlay.prototype.update=function(geometry){var div=this.renderer.render(geometry);if(!div){logWarning('Warning! Geometry could not be rendered!');return;}
var container=DIV({'class':'geo-container'},div);geometry.container=container;geometry.connect("updated",this,this.updateGeometryContainer);this.div.appendChild(container);};$prototype.updateGeometryContainer=function(event){var geometry=event.newValue;var div=geometry.container;var oldDiv=div.childNodes[0];var points=geometry.getPoints();var lastPoint=points[points.length-1];var newPoint=makePointDiv(lastPoint.x-1,lastPoint.y-1,3,3);oldDiv.appendChild(newPoint);if(points.length>1){var temp=DIV();var prevPoint=points[points.length-2];drawDottedLine(prevPoint.x,prevPoint.y,lastPoint.x,lastPoint.y,5,temp);oldDiv.appendChild(temp);}
if(div.childNodes.length<2){var closer=makeLabel(geometry.getPoints()[0].x+20,geometry.getPoints()[0].y-3,15,null,"X");connect(closer,'onclick',bind(function(child,event){this.div.removeChild(child);},this,div));div.appendChild(closer);}};namespace("userSmarts.geo");$namespace.GeocodeAction=Class.create(userSmarts.wt.action.Action);$prototype.initialize=function(superClass,properties){properties=setdefault(properties,{id:"com.usersmarts.geo.geocodeaction",text:"Geocode",toolTipText:"Geocode an location",image:"image.map"});superClass.call(this,properties);this.callback=bind(this.onDialogClosed,this);};$prototype.run=function(){var dialog=new userSmarts.geo.GeocodeDialog();var def=dialog.open();def.addCallback(this.callback);};$prototype.onDialogClosed=function(result){if(result&&typeof(this.out)=="function"){this.out(result);}};namespace("userSmarts.geo");$namespace.GeocodeDialog=Class.create(userSmarts.wt.dialogs.CDialog);$prototype.initialize=function(superClass,properties){properties=setdefault(properties,{width:650,height:450,title:"Geocode",enableKeys:false,enableDrag:false,showClose:true,image:"image.map",address:"",description:"Enter an address, place, zipcode, or "+"geographic coordinates (lon,lat) and "+"press [TAB] to locate it on the map."});superClass.call(this,properties);this.callback=bind(this.onResultsLoaded,this);this.errback=handleResponseError;};$prototype.createDialogArea=function(composite){composite.setLayout(new userSmarts.wt.layout.RowLayout({type:"vertical"}));var desc=new userSmarts.wt.widgets.Control({parent:composite,layoutData:{width:"100%",height:"30"},margin:{top:10,left:0,right:0,bottom:0}});desc.getNode().appendChild(document.createTextNode(this.description));this.input=new userSmarts.wt.forms.FieldControl({parent:composite,layoutData:{width:"100%",height:60},margin:{top:10,left:0,right:0,bottom:0},title:"Enter Location:",showLabel:true,binding:new BeanPropertyBinding(this,"address"),validator:null});this.inputListener=connect(this,"address",this,this.onInputChanged);var bottom=new userSmarts.wt.widgets.Composite({parent:composite,layoutData:{width:"100%",height:"*"},_layout:new userSmarts.wt.layout.RowLayout({type:"horizontal"})});this.model=new userSmarts.geo.GeocodeTableModel();this.modelListener=connect(this.model,"modified",this,this.onResultsLoaded);this.list=new userSmarts.wt.widgets.List({parent:bottom,layoutData:{width:"40%",height:"100%"},margin:{top:0,left:2,right:2,bottom:0},model:this.model});this.listListener=connect(this.list,"selected",this,this.displayOnMap);this.map=new userSmarts.maps.ol.Map({parent:bottom,layoutData:{width:"60%",height:"100%"},margin:{top:0,left:2,right:2,bottom:0},mapOptions:{maxExtent:new OpenLayers.Bounds(-180,0,-40,90),restrictedExtent:new OpenLayers.Bounds(-180,-90,180,90)},center:new OpenLayers.LonLat(-95.0,38.5),zoom:2,addControls:function(){}});};$prototype.focus=function(){this.input.focus();};$prototype.onInputChanged=function(event){var input=event.newValue;if(input){this.getOKButton().disabled=true;this.model.setQuery(input);}else{this.model.buffer=[];this.model.setProperty("modified",true);}};$prototype.onResultsLoaded=function(xml){if(!this.isOpen()||!this.node)return;this.getOKButton().disabled=false;};$prototype.displayOnMap=function(event){try{this.map.removeAllFeatures();var selection=event.newValue;if(selection){var zoom=null;if(this.map.getZoom()<5){zoom=9;}
var geom=selection.getWhere();this.map.addGeometry(geom,{style:OpenLayers.Feature.Vector.style['select']});this.map.setCenter(geom,zoom);}}catch(e){getLogger().logError("GeocodeDialog.displayOnMap() - "+"Error displaying selected result on map: "+e);}};$prototype.okPressed=function(){if(this.deferred){var selection=this.list.getSelected();if(selection){}
this.deferred.callback(selection);this.deferred=null;}};$prototype.close=function(){this.map.dispose();if(this.inputListener){disconnect(this.inputListener);this.inputListener=null;}
if(this.modelListener){disconnect(this.modelListener);this.modelListener=null;}
if(this.listListener){disconnect(this.listListener);this.listListener=null;}
userSmarts.wt.dialogs.CDialog.prototype.close.call(this);};namespace("userSmarts.geo");$namespace.GeocodeTableModel=Class.create(userSmarts.wt.widgets.TableModel);$prototype.initialize=function(superClass,properties){superClass.call(this,properties);this.resource=new userSmarts.pub.Resource({url:"geocode/",params:{format:"text/xml",style:"FULL",q:"",startPage:0,startIndex:0,count:10}});this.addColumn(new userSmarts.wt.widgets.TableColumn({label:"Address",getLabel:function(row){return row.getName();}}));this.addColumn(new userSmarts.wt.widgets.TableColumn({name:"location",getLabel:function(row){var g=row.getWhere();var p=g.getCenter();return"Lon: "+p.x+", Lat: "+p.y;}}));this.callback=bind(this.onResultsLoaded,this);this.errback=handleResponseError;};$prototype.size=function(){return this.matches||0;};$prototype.setQuery=function(q){this.resource.params.q=q;this.populate(0);};$prototype.populate=function(position){position=(typeof(position)=="number")?position:this.getOffset();this.currentRow=position;this.resource.params.startIndex=0;this.resource.params.startPage=Math.floor(this.getOffset()/this.getPageSize())+1;;this.resource.params.count=this.getPageSize();if(this.resource.params.q&&this.resource.params.q.length>0){var def=this.resource.get();def.addCallback(this.callback);def.addErrback(this.errback);}else{this.setProperty("modified",true);}};$prototype.onResultsLoaded=function(xml){var georss=new GeoRSS();var values=[];var root=xml.documentElement;var matches=DOMUtils.getChildText(root,"totalResults");var places=DOMUtils.getChildren(root,"Placemark");for(var i=0;i<places.length;++i){var location=new userSmarts.geo.Location();var name=DOMUtils.getChildText(places[i],"name");location.setName(name);var geometry=georss.parseObject(places[i]);location.setWhere(geometry);this.parseAddressDetails(places[i],location);values.push(location);}
this.buffer=values;this.matches=Coerce.toInteger(matches);this.setProperty("modified",true);};$prototype.parseAddressDetails=function(parentNode,location){var ad=DOMUtils.getChild(parentNode,"AddressDetails");var parts=DOMUtils.getChildren(ad,"addressPart");for(var i=0;i<parts.length;++i){var type=getNodeAttribute(parts[i],"type");var value=DOMUtils.getChildText(parts[i],"code");if("country"==type){location.setCountry(value);}else if("state"==type){location.setRegion(value);}else if("city"==type){location.setCity(value);}else if("county"==type){}else if("postal"==type){location.setPostal(value);}else if("street"==type){location.setAddress1(value);}}};namespace("userSmarts.geo");$namespace.Location=Class.create(Bean);$prototype.initialize=function(superClass,properties){properties=setdefault(properties,{});superClass.call(this,properties);};$prototype.getAddress1=function(){return this.addr1;};$prototype.setAddress1=function(addr){this.addr1=addr;};$prototype.getAddress2=function(){return this.addr2;};$prototype.setAddress2=function(addr){this.addr2=addr;};$prototype.getCity=function(){return this.city;};$prototype.setCity=function(city){this.city=city;};$prototype.getRegion=function(){return this.region;};$prototype.setRegion=function(region){this.region=region;};$prototype.getCountry=function(){return this.country;};$prototype.setCountry=function(country){this.country=country;};$prototype.getPostal=function(){return this.postal;};$prototype.setPostal=function(postal){this.postal=postal;};$prototype.getName=function(){return this.name;};$prototype.setName=function(name){this.name=name;};$prototype.getWhere=function(){return this.geometry;};$prototype.setWhere=function(geom){this.geometry=geom;};$prototype.toXml=function(parentNode){var ns="http://www.georss.org/georss";var root;var doc;if(!parentNode){doc=createXMLDocument('where',ns,null);root=doc.documentElement;}else{if(parentNode.nodeType!=9){doc=parentNode.ownerDocument;root=createElementNS(ns,"where",doc);parentNode.appendChild(root);}}
if(!root)return null;this.createTextElement(ns,"address1",this.getAddress1(),root,doc);this.createTextElement(ns,"address2",this.getAddress2(),root,doc);this.createTextElement(ns,"city",this.getCity(),root,doc);this.createTextElement(ns,"regionCode",this.getRegion(),root,doc);this.createTextElement(ns,"countryCode",this.getCountry(),root,doc);this.createTextElement(ns,"postalCode",this.getPostal(),root,doc);this.createTextElement(ns,"placeName",this.getName(),root,doc);new GeoRSS().format(this.getWhere(),root);return root;};$prototype.createTextElement=function(ns,nodeName,value,root,doc){if(value&&typeof(value)=="string"){var n=createElementNS(ns,nodeName,doc);n.appendChild(doc.createTextNode(value));root.appendChild(n);return n;}};$namespace.Location.parse=function(xml){if(!isXmlNode(xml)||DOMUtils.getName(xml,true)!="where"){return null;}
var location=new userSmarts.geo.Location();location.setAddress1(DOMUtils.getChildText(xml,"address1"));location.setAddress2(DOMUtils.getChildText(xml,"address2"));location.setCity(DOMUtils.getChildText(xml,"city"));location.setRegion(DOMUtils.getChildText(xml,"regionCode"));location.setPostal(DOMUtils.getChildText(xml,"postalCode"));location.setCountry(DOMUtils.getChildText(xml,"countryCode"));location.setName(DOMUtils.getChildText(xml,"placeName"));location.setWhere(new GeoRSS().parseObject(xml));return location;};$prototype.dispose=function(){this.setAddress1(null);this.setAddress2(null);this.setCity(null);this.setRegion(null);this.setCountry(null);this.setPostal(null);this.setName(null);this.setWhere(null);};namespace("userSmarts.geo");function loadImage(properties){var deferred=null;deferred=new Deferred();deferred.image=null;if(!properties.url){return deferred;}
var image=null;image=document.createElement("IMG");image.setAttribute("src","");image.src=null;if(properties.width){image.setAttribute('width',properties.width);}
if(properties.height){image.setAttribute('height',properties.height);}
image.style.position=(properties.position)?properties.position:'absolute';image.style.top=(properties.top)?properties.top+"px":'0px';image.style.left=(properties.left)?properties.left+"px":'0px';image.style.visibility='visible';image.onmousedown=function(e){return false;};image.ondrag=function(e){return false;};if(properties.opacity&&typeof(properties.opacity)=='number'){image.style.opacity=(properties.opacity*1.0);image.style.filter='alpha(opacity='+(properties.opacity*100)+')';}
image.deferred=deferred;connect(image,'onload',onImageLoad);connect(image,'onerror',onImageError);image.src=properties.url;return{deferred:deferred,image:image};}
function onImageLoad(evt){var img=evt.src();disconnectAll(img);var deferred=img.deferred;deferred.callback(img);img.deferred=undefined;if(typeof(evt.dispose)=='function'){evt.dispose();}}
function onImageError(evt){var img=evt.src();var deferred=img.deferred;img.deferred=undefined;disconnectAll(img);deferred.errback("Error loading image "+img.src);if(typeof(evt.dispose)=='function'){evt.dispose();}}
function disposeImage(image){if(image){image.id="deleted!";image.src=null;image.title=null;disconnectAll(image);image.onmouseout=null;image.onmouseover=null;image.onmousedown=null;image.onmouseup=null;image.ondrag=null;image=null;}}
function fixE(e){if(typeof e=='undefined'){e=window.event;}
if(typeof e.layerX=='undefined'){e.layerX=e.offsetX;}
if(typeof e.layerY=='undefined'){e.layerY=e.offsetY;}
return e;}
function getDistance(x1,y1,x2,y2){var radius=6378.137;var diam=12756.3;var pi=3.141529;var deg2rad=0.0174532925;var x1r=x1*deg2rad;var x2r=x2*deg2rad;var y1r=y1*deg2rad;var y2r=y2*deg2rad;var sin1=Math.sin(y1r)*Math.sin(y2r);var cos1=Math.cos(y1r)*Math.cos(y2r);var cos2=Math.cos(x2r-x1r);var acos1=Math.acos(sin1+cos1*cos2);var dist=radius*acos1;dist=dist*1000*3.2808399/5280;return dist;}
function distanceToDegrees(dist){var result=dist*1*0.54;result=(result*63360);result=(result*0.0254);result=(result/1852);result=(result/60);return result;}
function nearestDistanceFactor(d){var d1=0.00001;var d2=0.00002;var d3=0.00005;var factor=1;while(d1*Math.pow(10,factor)<d){++factor;}
var upperFactor=factor;var lowerFactor=factor-1;var lowerDiff=Math.abs(d-d3*Math.pow(10,lowerFactor));var upperDiff=Math.abs(d1*Math.pow(10,upperFactor)-d);if(lowerDiff<upperDiff){d1*=Math.pow(10,lowerFactor);d2*=Math.pow(10,lowerFactor);d3*=Math.pow(10,lowerFactor);}else{d1*=Math.pow(10,upperFactor);d2*=Math.pow(10,upperFactor);d3*=Math.pow(10,upperFactor);}
var dt1=Math.abs(d1-d);var dt2=Math.abs(d2-d);var dt3=Math.abs(d3-d);if(dt1<dt2){return d1;}else if(dt2<dt3){return d2;}else{return d3;}}
function convertUnits(value,fromUnits,toUnits){if(typeof(value)!='number'){return value;}
if(fromUnits=='mi'){if(toUnits=='km'){return 1.609344*value;}else if(toUnits=='m'){return 1609.344*value;}else if(toUnits=='ft'){return 5280*value;}else if(toUnits=='yd'){return 1760*value;}else{toUnits='mi';return value;}}else if(fromUnits=='km'){if(toUnits=='mi'){return 0.621371192*value;}else if(toUnits=='m'){return 1000.0*value;}else if(toUnits=='ft'){return 3280.8399*value;}else if(toUnits=='yd'){return 1093.6133*value;}else{toUnits='km';return value;}}else if(fromUnits=='m'){if(toUnits=='mi'){return 0.000621371192*value;}else if(toUnits=='km'){return 0.001*value;}else if(toUnits=='ft'){return 3.2808399*value;}else if(toUnits=='yd'){return 1.0936133*value;}else{toUnits='m';return value;}}else if(fromUnits=='ft'){if(toUnits=='mi'){return 0.000189393939*value;}else if(toUnits=='km'){return 0.0003048*value;}else if(toUnits=='m'){return 0.3048*value;}else if(toUnits=='yd'){return 0.333*value;}else{toUnits='ft';return value;}}else if(fromUnits=='yd'){if(toUnits=='mi'){return 0.000568181818*value;}else if(toUnits=='km'){return 0.0009144*value;}else if(toUnits=='m'){return 0.9144*value;}else if(toUnits=='ft'){return 3*value;}else{toUnits='yd';return value;}}else{return value;}}
function formatNumberWithCommas(amount){var temp=amount+'';var finalStr='';var start=temp.length-1;for(var i=0;i<temp.length;i++){if(temp.substring(i,i+1)=='.'){start=i-1;break;}}
var j=0;for(var i=start;i>=0;i--){if(j>0&&((j+1)%3)===0&&i!==0){finalStr=','+temp.substring(i,i+1)+finalStr;}else{finalStr=temp.substring(i,i+1)+finalStr;}
j++;}
return finalStr+temp.substring(start+1,temp.length);}
function formatNumber(val,wd,dd){val=val*1;if(dd>0){val=val.toFixed(dd);}
var strval=val+'';var arr=strval.split('.');var whole=(val<0)?(arr[0]*-1)+'':arr[0];if(dd>0){var decimal=arr[1];}
if(whole.length<wd){var padding='';for(var i=0;i<(wd-whole.length);++i){padding+='0';}
whole=padding+whole;}else if(whole.length>wd){}
return((val<0)?'-':'')+whole+((dd>0)?'.'+decimal:'');}
function makeLabel(x,y,width,height,text){var div=DIV({'class':'map-label'},text);div.style.position="absolute";var left=((width)?Math.ceil(x-(width/2)):x);var top=((height)?Math.ceil(y-(height/2)):y);div.style.left=left+'px';div.style.top=top+'px';if(width){div.style.width=width+'px';}
if(height){div.style.height=height+'px';}
return div;}
function spliceArray(arr1,index,numDeletedItems,arr2){if(index>=arr1.length){var resultArr=[];for(var i=0;i<arr1.length;i++){resultArr.push(arr1[i]);}
for(var i=0;i<arr2.length;i++){resultArr.push(arr2[i]);}
return resultArr;}else if(index>=0&&index<arr1.length){var resultArr=[];for(var i=0;i<index;i++){resultArr.push(arr1[i]);}
for(var i=0;i<arr2.length;i++){resultArr.push(arr2[i]);}
var i=Math.min(arr1.length,index+numDeletedItems);for(;i<arr1.length;i++){resultArr.push(arr1[i]);}
return resultArr;}else{return arr1;}}
function parseQueryString(){var params={};var href=location.href;var qsi=href.indexOf("?");if(qsi>0){var qs=href.substring(qsi,href.length);var args=qs.split("&");var arg;var argParts;for(var i=0;i<args.length;i++){arg=args[i];argParts=arg.split("=");if(argParts.length==2){params[argParts[0]]=argParts[1];}}}
return params;}
function getViewportScrollX(){var scrollX=0;if(document.documentElement&&document.documentElement.scrollLeft){scrollX=document.documentElement.scrollLeft;}
else if(document.body&&document.body.scrollLeft){scrollX=document.body.scrollLeft;}
else if(window.pageXOffset){scrollX=window.pageXOffset;}
else if(window.scrollX){scrollX=window.scrollX;}
return scrollX;}
function getViewportScrollY(){var scrollY=0;if(document.documentElement&&document.documentElement.scrollTop){scrollY=document.documentElement.scrollTop;}
else if(document.body&&document.body.scrollTop){scrollY=document.body.scrollTop;}
else if(window.pageYOffset){scrollY=window.pageYOffset;}
else if(window.scrollY){scrollY=window.scrollY;}
return scrollY;}
namespace("userSmarts.geo.renderer");namespace("userSmarts.geo.renderer");namespace("userSmarts.geo.renderer");$namespace.GeometryRenderer=function(properties){if(isPrototype(arguments)){return;}
properties=setdefault(properties,{showClose:true});setdefault(this,properties);this.spacerURL=userSmarts.runtime.Platform.getTheme().get("image.spacer");};$namespace.GeometryRenderer.prototype.render=function(geometry){if(!geometry.type){return null;}
switch(geometry.type){case'Ellipse':case'Circle':return this.renderEllipse(geometry);case'Line':var points=geometry.getPoints();return this.renderLine(points[0],points[1]);case'Point':return this.renderPoint(geometry);case'Box':return this.renderBox(geometry);default:return this.renderPolygon(geometry);}};$namespace.GeometryRenderer.prototype.renderPoint=function(point){var width=point.width||3;var height=point.height||3;var div=document.createElement('div');div.className="point";div.style.position="absolute";div.style.left=(point.x-(width/2))+'px';div.style.top=(point.y-(height/2))+'px';div.style.width=width+'px';div.style.height=height+'px';var img=document.createElement("img");img.setAttribute('src',this.spacerURL);img.setAttribute('width','1');img.setAttribute('height','1');div.appendChild(img);return div;};$namespace.GeometryRenderer.prototype.renderBox=function(box){var p0=box.points[0];var p2=box.points[1];var p1={x:p2.x,y:p0.y};var p3={x:p0.x,y:p2.y};var div=DIV({'class':"Polygon"});div.appendChild(this.renderPoint({x:p0.x-1,y:p0.y-1,width:3,height:3}));div.appendChild(this.renderLine(p0,p1,1,true));div.appendChild(this.renderPoint({x:p1.x-1,y:p1.y-1,width:3,height:3}));div.appendChild(this.renderLine(p1,p2,1,true));div.appendChild(this.renderPoint({x:p2.x-1,y:p2.y-1,width:3,height:3}));div.appendChild(this.renderLine(p2,p3,1,true));div.appendChild(this.renderPoint({x:p3.x-1,y:p3.y-1,width:3,height:3}));div.appendChild(this.renderLine(p3,p0,1,true));if(this.showClose){div.appendChild(createGeometryCloseButton(box,p3));}
return div;};$namespace.GeometryRenderer.prototype.renderLine=function(point1,point2,size,flag){var div=DIV({'class':'line'});var flag=!!flag;var dim=5;var x1=point1.x;var x2=point2.x;var y1=point1.y;var y2=point2.y;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,counter=0;if(dx>=dy){var pr=dy<<1,pru=pr-(dx<<1),p=pr-dx;while((dx--)>0){if(flag){if(drw){div.appendChild(this.renderPoint({x:x,y:y,width:size,height:size}));}
if((++counter)==dim){drw=!drw;counter=0;}}else{div.appendChild(this.renderPoint({x:x,y:y,width:size,height:size}));}
if(p>0){y+=yIncr;p+=pru;}
else{p+=pr;}
++x;}
if(flag){if(drw){div.appendChild(this.renderPoint({x:x,y:y,width:size,height:size}));}}else{div.appendChild(this.renderPoint({x:x,y:y,width:size,height:size}));}}else{var pr=dx<<1,pru=pr-(dy<<1),p=pr-dy;while((dy--)>0){if(flag){if(drw){div.appendChild(this.renderPoint({x:x,y:y,width:size,height:size}));}
if((++counter)==dim){drw=!drw;counter=0;}}else{div.appendChild(this.renderPoint({x:x,y:y,width:size,height:size}));}
y+=yIncr;if(p>0){++x;p+=pru;}else{p+=pr;}}
if(flag){if(drw){div.appendChild(this.renderPoint({x:x,y:y,width:size,height:size}));}}else{div.appendChild(this.renderPoint({x:x,y:y,width:size,height:size}));}}
return div;};$namespace.GeometryRenderer.prototype.renderPolygon=function(geometry){var div=DIV({'class':geometry.type});var points=geometry.getPoints();for(var i=0;i<points.length;i++){var point=points[i];div.appendChild(this.renderPoint({x:point.x-1,y:point.y-1,width:3,height:3}));if(i>0){var point1=points[i-1];div.appendChild(this.renderLine(point1,point,1,true));}}
if(points.length>0&&this.showClose){div.appendChild(createGeometryCloseButton(geometry,points[0]));}
return div;};$namespace.GeometryRenderer.prototype.renderEllipse=function(geometry){var div=DIV({'class':geometry.type});var bounds=geometry.getEnvelope();var left=bounds.points[0].x;var top=bounds.points[0].y;var width=bounds.points[1].x-bounds.points[0].x;var height=bounds.points[1].y-bounds.points[0].y;var dim=5;var counter=0;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){var arr=this.mkOvQds(cx,cy,-x,x+wod,-y,y+hod);for(var q=0;q<arr.length;q++){div.appendChild(arr[q]);}}
if((++counter)==dim){drw=!drw;counter=0;}}
if(this.showClose){div.appendChild(createGeometryCloseButton(geometry,{x:left+((width/2)-10),y:top}));}
return div;};$namespace.GeometryRenderer.prototype.mkOvQds=function(cx,cy,xl,xr,yt,yb){return[this.renderPoint({x:xr+cx,y:yt+cy,width:1,height:1}),this.renderPoint({x:xr+cx,y:yb+cy,width:1,height:1}),this.renderPoint({x:xl+cx,y:yb+cy,width:1,height:1}),this.renderPoint({x:xl+cx,y:yt+cy,width:1,height:1})];};namespace("userSmarts.geo.renderer");$namespace.VMLGeometryRenderer=function(){};$namespace.VMLGeometryRenderer.prototype.render=function(geometry){if(!geometry.type){return null;}
switch(geometry.type){case'Ellipse':case'Circle':return this.renderEllipse(geometry);case'Line':var points=geometry.getPoints();return this.renderLine(points[0],points[1]);case'Point':return this.renderPoint(geometry);case'Box':return this.renderBox(geometry);default:return this.renderPolygon(geometry);}};$namespace.VMLGeometryRenderer.prototype.renderPoint=function(point){var width=point.width||3;var height=point.height||3;var div=DIV();div.className='point';div.style.position='absolute';div.style.top=(point.y-(height/2))+'px';div.style.left=(point.x-(width/2))+'px';div.style.width=width+'px';div.style.height=height+'px';div.innerHTML='<v:oval style="width:'+width+'px; height:'+height+'px;" fillcolor="black" />';return div;};$namespace.VMLGeometryRenderer.prototype.renderBox=function(box){var p0=box.points[0];var p1=box.points[1];var width=Math.abs(p1.x-p0.x);var height=Math.abs(p1.y-p0.y);var left=Math.min(p0.x,p1.x);var top=Math.min(p0.y,p1.y);var div=DIV({'class':'polygon'});var str='<DIV><v:polyline strokecolor="black" strokeweight="1px" filled="false" fillcolor="transparent" points="';str+=left+"px,"+(top+height)+'px,';str+=(left+width)+"px,"+(top+height)+"px,";str+=(left+width)+"px,"+top+"px,";str+=left+"px,"+top+"px,";str+=left+"px,"+(top+height)+'px';str+='">'+'<v:stroke dashstyle="dash" />'+'</v:polyline></DIV>';div.innerHTML=str;div.appendChild(createGeometryCloseButton(box,{x:left,y:top}));logDebug("Drew box onto "+div.outerHTML);return div;};$namespace.VMLGeometryRenderer.prototype.renderLine=function(point1,point2,size,flag){var div=DIV({'class':'line'});div.style.position='absolute';div.style.top=Math.min(point1.y,point2.y)+'px';div.style.left=Math.min(point1.x,point2.x)+'px';div.style.width=Math.abs(point1.x-point2.x)+'px';div.style.height=Math.abs(point1.y-point2.y)+'px';var p1={x:point1.x,y:point1.y};var p2={x:point2.x,y:point2.y};if(p1.x<p2.x){p2.x-=p1.x;p1.x=0;}else{p1.x-=p2.x;p2.x=0;}
if(p1.y<p2.y){p2.y-=p1.y;p1.y=0;}else{p1.y-=p2.y;p2.y=0;}
var str='<v:line '+'from="'+p1.x+','+p1.y+'" '+'to="'+p2.x+','+p2.y+'" '+'strokecolor="#000000" strokeweight="'+size+'px">';if(flag){str+='<v:stroke dashstyle="dash" />';}
str+='</v:line>';div.innerHTML=str;return div;};$namespace.VMLGeometryRenderer.prototype.renderPolygon=function(geometry){var div=DIV({'class':geometry.type});var str='<v:polyline strokecolor="black" strokeweight="1px" filled="false" fillcolor="transparent" points="';var points=geometry.getPoints();for(var i=0;i<points.length;i++){var point=points[i];str+=((i>0)?',':'')+point.x+'px,'+point.y+'px';}
str+='">'+'<v:stroke dashstyle="dash" />'+'</v:polyline>';div.innerHTML="<DIV>"+str+"</DIV>";if(points.length>0){div.appendChild(createGeometryCloseButton(geometry,points[0]));}
logDebug("Drew polygon onto "+div.outerHTML);return div;};$namespace.VMLGeometryRenderer.prototype.renderEllipse=function(geometry){var bounds=geometry.getEnvelope();var left=bounds.points[0].x;var top=bounds.points[0].y;var width=bounds.points[1].x-bounds.points[0].x;var height=bounds.points[1].y-bounds.points[0].y;var div=DIV({'class':geometry.type});div.style.position='absolute';div.style.top=top+'px';div.style.left=left+'px';div.style.width=width+'px';div.style.height=width+'px';div.innerHTML='<v:oval style="width:'+width+'px; height:'+width+'px;" filled="false" fillcolor="transparent" strokeweight="1px">'+'<v:stroke dashstyle="dash" />'+'</v:oval>';div.appendChild(createGeometryCloseButton(geometry,{x:0,y:(height/2)}));return div;};namespace("userSmarts.ogc.filter");namespace('OGC');namespace("ogc.filter");OGC.NAMESPACE_URI="http://www.opengis.net/ogc";OGC.NAMESPACE_PREFIX="ogc";OGC.FilterOperation={OR:"Or",AND:"And",NOT:"Not",PROPERTYISEQUALTO:"PropertyIsEqualTo",PROPERTYISLESSTHAN:"PropertyIsLessThan",PROPERTYISLESSTHANOREQUALTO:"PropertyIsLessThanOrEqualTo",PROPERTYISGREATERTHAN:"PropertyIsGreaterThan",PROPERTYISGREATERTHANOREQUALTO:"PropertyIsGreaterThanOrEqualTo",PROPERTYISBETWEEN:"PropertyIsBetween",PROPERTYISLIKE:"PropertyIsLike",PROPERTYISNULL:"PropertyIsNull",BBOX:"BBOX",INTERSECTS:"Intersect",INTERSECT:"Intersect",DISJOINT:"Disjoint",WITHIN:"Within",OVERLAPS:"Overlaps",isLogicalOperation:function(operation){var opName;if(operation instanceof ogc.filter.Node){opName=operation.name;}else if(typeof operation=='string'){opName=operation;}
var result=false;if(opName){result=(opName==OGC.FilterOperation.OR)||(opName==OGC.FilterOperation.AND)||(opName==OGC.FilterOperation.NOT);}
return result;},isComparisonOperation:function(operation){var opName;if(operation instanceof ogc.filter.Node){opName=operation.name;}else if(typeof operation=='string'){opName=operation;}
var result=false;if(opName){result=(opName==OGC.FilterOperation.PROPERTYISBETWEEN)||(opName==OGC.FilterOperation.PROPERTYISEQUALTO)||(opName==OGC.FilterOperation.PROPERTYISGREATERTHAN)||(opName==OGC.FilterOperation.PROPERTYISGREATERTHANOREQUALTO)||(opName==OGC.FilterOperation.PROPERTYISLESSTHAN)||(opName==OGC.FilterOperation.PROPERTYISLESSTHANOREQUALTO)||(opName==OGC.FilterOperation.PROPERTYISLIKE)||(opName==OGC.FilterOperation.PROPERTYISNULL);}
return result;},isSpatialOperation:function(operation){var opName;if(operation instanceof ogc.filter.Node){opName=operation.name;}else if(typeof operation=='string'){opName=operation;}
var result=false;if(opName){result=(opName==OGC.FilterOperation.BBOX)||(opName==OGC.FilterOperation.INTERSECTS)||(opName==OGC.FilterOperation.DISJOINT)||(opName==OGC.FilterOperation.WITHIN)||(opName==OGC.FilterOperation.OVERLAPS);}
return result;}};namespace("userSmarts.ogc.filter");namespace("ogc.filter");$namespace.Node=Class.create(Bean);$prototype.initialize=function(superClass,properties){superClass.call(this,properties);};$prototype.getName=function(){return this.name;};$prototype.setName=function(name){this.name=name;};$namespace.Filter=Class.create(ogc.filter.Node);$prototype.initialize=function(superClass,properties){properties=setdefault(properties,{});properties.name="Filter";this.root=new ogc.filter.LogicalOperation({name:OGC.FilterOperation.OR});superClass.call(this,properties);};$prototype.setRoot=function(node){if(node instanceof ogc.filter.Node){this.root=node;}};$prototype.getRoot=function(){return this.root;};$prototype.toString=function(){var str='<'+OGC.NAMESPACE_PREFIX+':Filter xmlns:'+OGC.NAMESPACE_PREFIX+'="'+OGC.NAMESPACE_URI+'">';str+=this.root.toString();str+="</"+OGC.NAMESPACE_PREFIX+":Filter>";return str;};$prototype.toXml=function(doc){var element;if(!doc){doc=createXMLDocument('Filter',OGC.NAMESPACE_URI,null);element=doc.documentElement;}else{element=createElementNS(OGC.NAMESPACE_URI,"Filter",doc,OGC.NAMESPACE_PREFIX);}
element.appendChild(this.root.toXml(doc));return element;};$namespace.PropertyName=Class.create(ogc.filter.Node);$prototype.initialize=function(superClass,namespaceURI,value,prefix){properties={};properties.name="PropertyName";if(namespaceURI&&value&&prefix){properties.uri=namespaceURI;properties.prefix=prefix;properties.value=value;}else if(namespaceURI&&value){properties.uri=namespaceURI;properties.value=value;}else if(namespaceURI){properties.value=namespaceURI;}
superClass.call(this,properties);};$prototype.getValue=function(){return this.value;};$prototype.setValue=function(value){this.value=value;};$prototype.getNamespace=function(){return this.uri;};$prototype.setNamespace=function(uri){this.uri=uri;};$prototype.getPrefix=function(){return this.prefix;};$prototype.setPrefix=function(prefix){this.prefix=prefix;};$prototype.toString=function(){var str='<'+OGC.NAMESPACE_PREFIX+':PropertyName';if(this.uri&&this.prefix){str+=" xmlns:"+this.prefix+"=\""+this.uri+"\"";}
str+=">";if(this.prefix){str+=this.prefix+":";}
str+=this.value;str+='</'+OGC.NAMESPACE_PREFIX+':PropertyName>';return str;};$prototype.toXml=function(document){var element=createElementNS(OGC.NAMESPACE_URI,"PropertyName",document,OGC.NAMESPACE_PREFIX);if(this.uri&&this.prefix){setNodeAttribute(element,"xmlns:"+this.prefix,this.uri);}
element.appendChild(document.createTextNode((this.prefix?this.prefix:"")+this.value));return element;};$namespace.Literal=Class.create(ogc.filter.Node);$prototype.initialize=function(superClass,value,format){properties={};properties.name="Literal";properties.value=Coerce.toString(value);properties.format=format;superClass.call(this,properties);};$prototype.setValue=function(value){this.value=value;};$prototype.getValue=function(){if(this.format){return this.format.format(this.value);}
return this.value;};$prototype.toString=function(){var val=this.getValue();if(this.value===null){val='null';}
return'<'+OGC.NAMESPACE_PREFIX+':Literal>'+
val+'</'+OGC.NAMESPACE_PREFIX+':Literal>';};$prototype.toXml=function(document){var val=this.getValue();if(this.value===null){val='null';}
var element=createElementNS(OGC.NAMESPACE_URI,"Literal",document,OGC.NAMESPACE_PREFIX);element.appendChild(document.createTextNode(val));return element;};$namespace.ComparisonOperation=Class.create(ogc.filter.Node);$prototype.initialize=function(superClass,properties){properties=setdefault(properties,{propertyName:new ogc.filter.PropertyName("Any"),literal:new ogc.filter.Literal("*")});properties.name=OGC.FilterOperation.PROPERTYISEQUALTO;superClass.call(this,properties);};$prototype.setPropertyName=function(propertyName){if(propertyName instanceof ogc.filter.PropertyName){this.propertyName=propertyName;}};$prototype.getPropertyName=function(){return this.propertyName;};$prototype.setLiteral=function(literal){if(literal instanceof ogc.filter.Literal){this.literal=literal;}};$prototype.getLiteral=function(){return this.literal;};$prototype.toString=function(){var str='<'+OGC.NAMESPACE_PREFIX+':'+this.name+'>';str+=this.propertyName.toString();str+=this.literal.toString();str+='</'+OGC.NAMESPACE_PREFIX+':'+this.name+'>';return str;};$prototype.toXml=function(document){var element=createElementNS(OGC.NAMESPACE_URI,this.name,document,OGC.NAMESPACE_PREFIX);element.appendChild(this.propertyName.toXml(document));element.appendChild(this.literal.toXml(document));return element;};$namespace.BetweenComparison=Class.create(ogc.filter.ComparisonOperation);$prototype.initialize=function(superClass,properties){properties=setdefault(properties,{lower:new ogc.filter.Literal("*"),upper:new ogc.filter.Literal("*")});properties.name=OGC.FilterOperation.PROPERTYISBETWEEN;superClass.call(this,properties);};$prototype.setLowerBounds=function(literal){if(literal instanceof ogc.filter.Literal){this.lower=literal;}};$prototype.getLowerBounds=function(){return this.lower;};$prototype.setUpperBounds=function(literal){if(literal instanceof ogc.filter.Literal){this.upper=literal;}};$prototype.getUpperBounds=function(){return this.upper;};$prototype.toString=function(){var str='<'+OGC.NAMESPACE_PREFIX+':'+this.name+'>';str+=this.propertyName.toString();str+='<'+OGC.NAMESPACE_PREFIX+':LowerBoundary>';str+=this.lower.toString();str+='</'+OGC.NAMESPACE_PREFIX+':LowerBoundary>';str+='<'+OGC.NAMESPACE_PREFIX+':UpperBoundary>';str+=this.upper.toString();str+='</'+OGC.NAMESPACE_PREFIX+':UpperBoundary>';str+='</'+OGC.NAMESPACE_PREFIX+':'+this.name+'>';return str;};$prototype.toXml=function(document){var element=createElementNS(OGC.NAMESPACE_URI,this.name,document,OGC.NAMESPACE_PREFIX);element.appendChild(this.propertyName.toXml(document));var lowerElement=createElementNS(OGC.NAMESPACE_URI,'LowerBoundary',document,OGC.NAMESPACE_PREFIX);element.appendChild(lowerElement);lowerElement.appendChild(this.lower.toXml(document));var upperElement=createElementNS(OGC.NAMESPACE_URI,'UpperBoundary',document,OGC.NAMESPACE_PREFIX);element.appendChild(upperElement);upperElement.appendChild(this.upper.toXml(document));return element;};$namespace.LogicalOperation=Class.create(ogc.filter.Node);$prototype.initialize=function(superClass,properties){properties=setdefault(properties,{nodes:[],name:OGC.FilterOperation.OR});superClass.call(this,properties);};$prototype.addOperation=function(node){this.nodes.push(node);};$prototype.getOperations=function(){return this.nodes;};$prototype.toString=function(){var str="<"+OGC.NAMESPACE_PREFIX+":"+this.name+">";for(var i=0;i<this.nodes.length;i++){str+=this.nodes[i].toString();}
str+="</"+OGC.NAMESPACE_PREFIX+":"+this.name+">";return str;};$prototype.toXml=function(document){var element=createElementNS(OGC.NAMESPACE_URI,this.name,document,OGC.NAMESPACE_PREFIX);for(var i=0;i<this.nodes.length;i++){element.appendChild(this.nodes[i].toXml(document));}
return element;};$namespace.Or=Class.create(ogc.filter.LogicalOperation);$prototype.initialize=function(superClass,properties){properties=setdefault(properties,{});properties.name=OGC.FilterOperation.OR;superClass.call(this,properties);};$namespace.And=Class.create(ogc.filter.LogicalOperation);$prototype.initialize=function(superClass,properties){properties=setdefault(properties,{});properties.name=OGC.FilterOperation.AND;superClass.call(this,properties);};$namespace.Not=Class.create(ogc.filter.LogicalOperation);$prototype.initialize=function(superClass,properties){properties=setdefault(properties,{});properties.name=OGC.FilterOperation.NOT;superClass.call(this,properties);};$namespace.SpatialOperation=Class.create(ogc.filter.Node);$prototype.initialize=function(superClass,properties){properties=setdefault(properties,{propertyName:new ogc.filter.PropertyName("Any"),geometry:Geometry.valueOf('Box{(-180.0,-90.0),(180.0,90.0)}'),name:OGC.FilterOperation.BBOX,gmlOutput:true});superClass.call(this,properties);};$prototype.setPropertyName=function(propertyName){if(propertyName instanceof ogc.filter.PropertyName){this.propertyName=propertyName;}};$prototype.getPropertyName=function(){return this.propertyName;};$prototype.setGeometry=function(geometry){if(geometry instanceof Geometry){this.geometry=geometry;}};$prototype.getGeometry=function(){return this.geometry;};$prototype.toString=function(){var str='<'+OGC.NAMESPACE_PREFIX+':'+this.name+'>';str+=this.propertyName.toString();str+=this.geometry.toGmlString();str+='</'+OGC.NAMESPACE_PREFIX+':'+this.name+'>';return str;};$prototype.toXml=function(document){var element=createElementNS(OGC.NAMESPACE_URI,this.name,document);element.appendChild(this.propertyName.toXml(document));var geomString=(this.gmlOutput)?this.geometry.toGml(document):new GeoRSS().format(this.geometry,element);return element;};$namespace.BBOX=Class.create(ogc.filter.SpatialOperation);$prototype.initialize=function(superClass,properties){properties=setdefault(properties,{});properties.name=OGC.FilterOperation.BBOX;superClass.call(this,properties);};$namespace.Intersect=Class.create(ogc.filter.SpatialOperation);$prototype.initialize=function(superClass,properties){properties=setdefault(properties,{});properties.name=OGC.FilterOperation.INTERSECT;superClass.call(this,properties);};$namespace.Disjoint=Class.create(ogc.filter.SpatialOperation);$prototype.initialize=function(superClass,properties){properties=setdefault(properties,{});properties.name=OGC.FilterOperation.Disjoint;superClass.call(this,properties);};Geometry.prototype.toGmlString=function(){var type=this.getType();var points=this.getPoints();var pointStr='';for(var i=0;i<points.length;i++){if(i>0&&type!="Box"){pointStr+=',';}
else if(type=="Box"){pointStr+=' ';}
pointStr+=points[i].x+","+points[i].y;}
var str='<gml:'+type+' xmlns:gml="http://www.opengis.net/gml">';str+='<gml:coordinates>'+pointStr+'</gml:coordinates>';str+='</gml:'+type+'>';return str;};Geometry.prototype.toGml=function(document){var type=this.getType();var points=this.getPoints();var pointStr='';for(var i=0;i<points.length;i++){if(i>0){pointStr+=',';}
pointStr+=points[i].x+","+points[i].y;}
var element=createElementNS("http://www.opengis.net/gml",type,document,"gml");var coords=createElementNS("http://www.opengis.net/gml","coordinates",document,"gml");coords.appendChild(document.createTextNode(pointStr));element.appendChild(coords);return element;};namespace("userSmarts.ogc.filter");$namespace.FilterParser=Class.create();$prototype.initialize=function(superClass,properties){setdefault(this,properties);};$prototype.parse=function(node){if(!node||!isXmlNode(node)){getLogger().logError("FilterParser.parse() : "+"Argument is null or not XML");return null;}
var root;if(node.nodeType==1){root=node;}else if(node.nodeType==9){root=node.documentElement;}else{return null;}
return this.parseFilterNode(root);};$prototype.parseFilterNode=function(node){try{if(!node||!isXmlNode(node)){getLogger().logError("FilterParser.parseFilterNode() : "+"Argument is null or not XML");return null;}
if(node.nodeType!=1){logDebug("Ignoring non-Element node");return null;}
var out;var nodeName=DOMUtils.getName(node);if(nodeName=='Filter'){out=new ogc.filter.Filter();var op=this.parseFilterNode(node.childNodes[0]);if(op){out.setRoot(op);}else{getLogger().logError("FilterParser.parseFilterNode() : "+"No operations");}}else if(nodeName=="PropertyName"){out=this.parsePropertyName(node);}else if(nodeName=="Literal"){out=this.parseLiteral(node);}else if(OGC.FilterOperation.isLogicalOperation(nodeName)){out=this.parseLogicalOperation(node);}else if(OGC.FilterOperation.isComparisonOperation(nodeName)){out=this.parseComparisonOperation(node);}else if(OGC.FilterOperation.isSpatialOperation(nodeName)){out=this.parseSpatialOperation(node);}else{getLogger().logWarning("FilterParser.parseFilterNode() : "+"Unknown Filter node '"+nodeName+"'");}
return out;}catch(e){getLogger().logError("FilterParser.parseFilterNode() : "+e);}};$prototype.parsePropertyName=function(node){try{var name=scrapeText(node);var propertyName;var parts=name.split(":");if(parts.length>1){var uri=getNodeAttribute(node,"xmlns:"+parts[0]);propertyName=new ogc.filter.PropertyName(uri,parts[1],parts[0]);}else{propertyName=new ogc.filter.PropertyName(name);}
return propertyName;}catch(e){getLogger().logError("FilterParser.parsePropertyName() : "+e);}};$prototype.parseLiteral=function(node){try{var value=scrapeText(node);var literal=new ogc.filter.Literal(value);return literal;}catch(e){getLogger().logError("FilterParser.parseLiteral() : "+e);}};$prototype.parseLogicalOperation=function(node){try{var nodeName=DOMUtils.getName(node);var out=new ogc.filter.LogicalOperation({name:nodeName});var child;var children=DOMUtils.getChildren(node);for(var i=0;i<children.length;i++){child=this.parseFilterNode(children[i]);if(child){out.addOperation(child);}else{getLogger().logWarning("FilterParser.parseLogicalOperation() : "+"Unable to parse child of operation, possibly due to error");}}
return out;}catch(e){getLogger().logError("FilterParser.parseLogicalOperation() : "+e);}};$prototype.parseComparisonOperation=function(node){try{var nodeName=DOMUtils.getName(node);var propertyNameNode=node.getElementsByTagNameNS(OGC.NAMESPACE_URI,"PropertyName")[0];var propertyName=this.parseFilterNode(propertyNameNode);if(!propertyName){return null;}
var out;if(nodeName==OGC.FilterOperation.PROPERTYISBETWEEN){var lowerBoundaryNode=node.getElementsByTagNameNS(OGC.NAMESPACE_URI,"LowerBoundary")[0];var lowerBoundaryLiteralNode=lowerBoundaryNode.getElementsByTagNameNS(OGC.NAMESPACE_URI,"Literal")[0];var lowerBoundaryLiteral=this.parseFilterNode(lowerBoundaryLiteralNode);if(!lowerBoundaryLiteral){return null;}
var upperBoundaryNode=node.getElementsByTagNameNS(OGC.NAMESPACE_URI,"UpperBoundary")[0];var upperBoundaryLiteralNode=upperBoundaryNode.getElementsByTagNameNS(OGC.NAMESPACE_URI,"Literal")[0];var upperBoundaryLiteral=this.parseFilterNode(upperBoundaryLiteralNode);if(!upperBoundaryLiteral){return null;}
out=new ogc.filter.BetweenComparison({name:nodeName});out.setPropertyName(propertyName);out.setLowerBounds(lowerBoundaryLiteral);out.setUpperBounds(upperBoundaryLiteral);}else{var literalNode=node.getElementsByTagNameNS(OGC.NAMESPACE_URI,"Literal")[0];var literal=this.parseFilterNode(literalNode);if(!literal){return null;}
out=new ogc.filter.ComparisonOperation({name:nodeName});out.setPropertyName(propertyName);out.setLiteral(literal);}
return out;}catch(e){getLogger().logError("FilterParser.parseComparisonOperation() : "+e);}};$prototype.parseSpatialOperation=function(node){try{var nodeName=DOMUtils.getName(node);var propertyNameNode=node.getElementsByTagNameNS(OGC.NAMESPACE_URI,"PropertyName")[0];var propertyName=this.parseFilterNode(propertyNameNode);if(!propertyName){return null;}
var boxNode=node.getElementsByTagNameNS("http://www.opengis.net/gml","Box")[0];var coordNode=node.getElementsByTagNameNS("http://www.opengis.net/gml","coordinates")[0];var coordinates=scrapeText(coordNode);var coordArray=coordinates.split(',');forEach(coordArray,function(coord){coord.trim();});var coordStr='';for(var i=0;i<coordArray.length;i+=2){if(i>0){coordStr+=',';}
coordStr+='('+coordArray[i]+','+coordArray[i+1]+')';}
var geometry=Geometry.valueOf('Box{'+coordStr+'}');var out=new ogc.filter.SpatialOperation({name:nodeName,propertyName:propertyName,geometry:geometry});return out;}catch(e){getLogger().logError("FilterParser.parseSpatialOperation() : "+e);}};namespace("userSmarts.geo.proj");namespace("userSmarts.geo.proj");namespace("userSmarts.geo.proj");var PI=Math.PI;var HALF_PI=PI*0.5;var TWO_PI=PI*2.0;var EPSLN=1.0e-10;var R2D=57.2957795131;var D2R=0.0174532925199;var R=6370997.0;function lccinit(param){this.r_major=param[0];this.r_minor=param[1];var lat1=param[2]*D2R;var lat2=param[3]*D2R;this.center_lon=param[4]*D2R;this.center_lat=param[5]*D2R;this.false_easting=param[6];this.false_northing=param[7];if(Math.abs(lat1+lat2)<EPSLN){alert("Equal Latitiudes for St. Parallels on opposite sides of equator - lccinit");return;}
var temp=this.r_minor/this.r_major;this.e=Math.sqrt(1.0-temp*temp);var sin1=Math.sin(lat1);var cos1=Math.cos(lat1);var ms1=msfnz(this.e,sin1,cos1);var ts1=tsfnz(this.e,lat1,sin1);var sin2=Math.sin(lat2);var cos2=Math.cos(lat2);var ms2=msfnz(this.e,sin2,cos2);var ts2=tsfnz(this.e,lat2,sin2);var ts0=tsfnz(this.e,this.center_lat,Math.sin(this.center_lat));if(Math.abs(lat1-lat2)>EPSLN){this.ns=Math.log(ms1/ms2)/Math.log(ts1/ts2);}else{this.ns=sin1;}
this.f0=ms1/(this.ns*Math.pow(ts1,this.ns));this.rh=this.r_major*this.f0*Math.pow(ts0,this.ns);}
function ll2lcc(coords){var lon=coords[0];var lat=coords[1];if(lat<=90.0&&lat>=-90.0&&lon<=180.0&&lon>=-180.0){lat*=D2R;lon*=D2R;}else{alert("*** Input out of range ***: lon: "+lon+" - lat: "+lat);return null;}
var con=Math.abs(Math.abs(lat)-HALF_PI);var ts;if(con>EPSLN){ts=tsfnz(this.e,lat,Math.sin(lat));rh1=this.r_major*this.f0*Math.pow(ts,this.ns);}else{con=lat*this.ns;if(con<=0){alert("Point can not be projected - ll2lcc");return null;}
rh1=0;}
var theta=this.ns*adjust_lon(lon-this.center_lon);var x=rh1*Math.sin(theta)+this.false_easting;var y=this.rh-rh1*Math.cos(theta)+this.false_northing;return[x,y];}
function lcc2ll(coords){var rh1,con,ts;var lat,lon;x=coords[0]-this.false_easting;y=this.rh-coords[1]+this.false_northing;if(this.ns>0){rh1=Math.sqrt(x*x+y*y);con=1.0;}else{rh1=-Math.sqrt(x*x+y*y);con=-1.0;}
var theta=0.0;if(rh1!==0){theta=Math.atan2((con*x),(con*y));}
if((rh1!==0)||(this.ns>0.0)){con=1.0/this.ns;ts=Math.pow((rh1/(this.r_major*this.f0)),con);lat=phi2z(this.e,ts);if(lat==-9999){return null;}}else{lat=-HALF_PI;}
lon=adjust_lon(theta/this.ns+this.center_lon);return[R2D*lon,R2D*lat];}
function msfnz(eccent,sinphi,cosphi){var con=eccent*sinphi;return cosphi/(Math.sqrt(1.0-con*con));}
function tsfnz(eccent,phi,sinphi){var con=eccent*sinphi;var com=0.5*eccent;con=Math.pow(((1.0-con)/(1.0+con)),com);return(Math.tan(0.5*(HALF_PI-phi))/con);}
function phi2z(eccent,ts){var eccnth=0.5*eccent;var con,dphi;var phi=HALF_PI-2*Math.atan(ts);for(i=0;i<=15;i++){con=eccent*Math.sin(phi);dphi=HALF_PI-2*Math.atan(ts*(Math.pow(((1.0-con)/(1.0+con)),eccnth)))-phi;phi+=dphi;if(Math.abs(dphi)<=0.0000000001){return phi;}}
alert("Convergence error - phi2z");return-9999;}
function sign(x){return(x<0.0)?-1:1;}
function adjust_lon(x){x=(Math.abs(x)<PI)?x:(x-(sign(x)*TWO_PI));return(x);}
namespace("userSmarts.geo.proj");$namespace.LatLonProjection=function(params){this.units=params.units;this.unitsAbbr=params.unitsAbbr;this.title=params.title;this.bounds={minX:-180.0,minY:-90.0,maxX:180.0,maxY:90};this.boundsCheck=false;};$namespace.LatLonProjection.prototype.project=function(arg1,arg2){return[arg1,arg2];};$namespace.LatLonProjection.prototype.unproject=function(arg1,arg2){return[arg1,arg2];};namespace("userSmarts.geo.proj");$namespace.LCCProjection=function(params){this.r_major=params.majorAxis;this.r_minor=params.minorAxis;var lat1=params.firstStandardParallel*D2R;var lat2=params.secondStandardParallel*D2R;this.center_lon=params.centerLongitude*D2R;this.center_lat=params.centerLatitude*D2R;this.false_easting=params.falseEasting;this.false_northing=params.falseNorthing;this.units=params.units;this.unitsAbbr=params.unitsAbbr;this.title=params.title;this.bounds={minX:-32820917671486.5,minY:-25338353776102.9,maxX:3650389000.07957,maxY:7718697.93197062};this.boundsCheck=false;if(Math.abs(lat1+lat2)<EPSLN){alert("Standard Parallels cannot be equal and on opposite sides of the equator");return;}
var temp=this.r_minor/this.r_major;this.e=Math.sqrt(1.0-temp*temp);var sin1=Math.sin(lat1);var cos1=Math.cos(lat1);var ms1=msfnz(this.e,sin1,cos1);var ts1=tsfnz(this.e,lat1,sin1);var sin2=Math.sin(lat2);var cos2=Math.cos(lat2);var ms2=msfnz(this.e,sin2,cos2);var ts2=tsfnz(this.e,lat2,sin2);var ts0=tsfnz(this.e,this.center_lat,Math.sin(this.center_lat));if(Math.abs(lat1-lat2)>EPSLN){this.ns=Math.log(ms1/ms2)/Math.log(ts1/ts2);}else{this.ns=sin1;}
this.f0=ms1/(this.ns*Math.pow(ts1,this.ns));this.rh=this.r_major*this.f0*Math.pow(ts0,this.ns);};$namespace.LCCProjection.prototype.project=function(arg1,arg2){var lon=arg1;var lat=arg2;if(lat<=90.0&&lat>=-90.0&&lon<=180.0&&lon>=-180.0){lat*=D2R;lon*=D2R;}else{alert("Coordinate out of range - lon: "+lon+" - lat: "+lat);return[arg1,arg2];}
var con=Math.abs(Math.abs(lat)-HALF_PI);var ts;if(con>EPSLN){ts=tsfnz(this.e,lat,Math.sin(lat));rh1=this.r_major*this.f0*Math.pow(ts,this.ns);}else{con=lat*this.ns;if(con<=0){alert("Point can not be projected - ",arg1+','+arg2);return[arg1,arg2];}
rh1=0;}
var theta=this.ns*adjust_lon(lon-this.center_lon);var x=rh1*Math.sin(theta)+this.false_easting;var y=this.rh-rh1*Math.cos(theta)+this.false_northing;return[x,y];};$namespace.LCCProjection.prototype.unproject=function(arg1,arg2){var rh1,con,ts;var lat,lon;x=arg1-this.false_easting;y=this.rh-arg2+this.false_northing;if(this.ns>0){rh1=Math.sqrt(x*x+y*y);con=1.0;}else{rh1=-Math.sqrt(x*x+y*y);con=-1.0;}
var theta=0.0;if(rh1!==0){theta=Math.atan2((con*x),(con*y));}
if((rh1!==0)||(this.ns>0.0)){con=1.0/this.ns;ts=Math.pow((rh1/(this.r_major*this.f0)),con);lat=phi2z(this.e,ts);if(lat==-9999){return null;}}else{lat=-HALF_PI;}
lon=adjust_lon(theta/this.ns+this.center_lon);return[R2D*lon,R2D*lat];};namespace("userSmarts.geo.proj");function identity(coords){return coords;}
$namespace.ProjectionFactory=function(){};$namespace.ProjectionFactory.prototype={};$namespace.ProjectionFactory.instance=function(srs){srs=srs.toUpperCase();switch(srs){case"EPSG:4326":case"EPSG:4269":case"CRS:84":case"EPSG:4965":return userSmarts.geo.proj.ProjectionFactory.ESPG4326;case"EPSG:9802":case"EPSG:98020":return userSmarts.geo.proj.ProjectionFactory.ESPG98020;case"EPSG:42101":return userSmarts.geo.proj.ProjectionFactory.ESPG42101;case"EPSG:42304":return userSmarts.geo.proj.ProjectionFactory.ESPG42304;case"EPSG:26986":return userSmarts.geo.proj.ProjectionFactory.ESPG26986;case"EPSG:27561":return userSmarts.geo.proj.ProjectionFactory.ESPG27561;case"EPSG:27562":return userSmarts.geo.proj.ProjectionFactory.ESPG27562;case"EPSG:27572":case"EPSG:27582":return userSmarts.geo.proj.ProjectionFactory.ESPG27572;case"EPSG:27563":return userSmarts.geo.proj.ProjectionFactory.ESPG27563;case"EPSG:27564":return userSmarts.geo.proj.ProjectionFactory.ESPG27564;case"EPSG:2154":return userSmarts.geo.proj.ProjectionFactory.EPSG2154;default:return new userSmarts.geo.proj.LatLonProjection({units:'degrees',title:'Latitude/Longitude'});}};$namespace.ProjectionFactory.ESPG4326=new userSmarts.geo.proj.LatLonProjection({units:"degrees",unitsAbbr:"\u00b0",title:"Latitude/Longitude"});$namespace.ProjectionFactory.ESPG98020=new userSmarts.geo.proj.LCCProjection({units:'meters',unitsAbbr:"m",title:'Lambert Conformal Conic',majorAxis:6378137.0,minorAxis:6356752.314245,firstStandardParallel:33.0,secondStandardParallel:45.0,centerLongitude:-97.0,centerLatitude:40.0,falseEasting:0.0,falseNorthing:0.0});$namespace.ProjectionFactory.ESPG42101=new userSmarts.geo.proj.LCCProjection({units:'meters',unitsAbbr:"m",title:'Lambert Conformal Conic',majorAxis:6378137.0,minorAxis:6356752.314245,firstStandardParallel:49.0,secondStandardParallel:77.0,centerLongitude:-95.0,centerLatitude:0.0,falseEasting:0.0,falseNorthing:-8000000});$namespace.ProjectionFactory.ESPG42304=new userSmarts.geo.proj.LCCProjection({units:'meters',unitsAbbr:"m",title:'Lambert Conformal Conic',majorAxis:6378137.0,minorAxis:6356752.314,firstStandardParallel:49.0,secondStandardParallel:77.0,centerLongitude:-95.0,centerLatitude:49.0,falseEasting:0.0,falseNorthing:0});$namespace.ProjectionFactory.ESPG26986=new userSmarts.geo.proj.LCCProjection({units:'meters',unitsAbbr:"m",title:'Massachusetts Mainland (LCC)',majorAxis:6378137.0,minorAxis:6356752.314,firstStandardParallel:42.68333333333333,secondStandardParallel:41.71666666666667,centerLongitude:-71.5,centerLatitude:41.0,falseEasting:200000,falseNorthing:750000});$namespace.ProjectionFactory.ESPG27561=new userSmarts.geo.proj.LCCProjection({units:'meters',unitsAbbr:"m",title:'Lambert Conformal Conic',majorAxis:6378249.2,minorAxis:6356515.0,firstStandardParallel:49.50,secondStandardParallel:49.50,centerLongitude:2.33722916655,centerLatitude:49.50,falseEasting:600000.0,falseNorthing:200000.0});$namespace.ProjectionFactory.ESPG27562=new userSmarts.geo.proj.LCCProjection({units:'meters',unitsAbbr:"m",title:'Lambert Conformal Conic',majorAxis:6378249.2,minorAxis:6356515.0,firstStandardParallel:46.80,secondStandardParallel:46.80,centerLongitude:2.33722916655,centerLatitude:46.8,falseEasting:600000.0,falseNorthing:200000.0});$namespace.ProjectionFactory.ESPG27572=new userSmarts.geo.proj.LCCProjection({units:'meters',unitsAbbr:"m",title:'Lambert Conformal Conic',majorAxis:6378249.2,minorAxis:6356515.0,firstStandardParallel:46.80,secondStandardParallel:46.80,centerLongitude:2.33722916655,centerLatitude:46.8,falseEasting:600000.0,falseNorthing:2200000.0});$namespace.ProjectionFactory.ESPG27563=new userSmarts.geo.proj.LCCProjection({units:'meters',unitsAbbr:"m",title:'Lambert Conformal Conic',majorAxis:6378249.2,minorAxis:6356515.0,firstStandardParallel:44.10,secondStandardParallel:44.10,centerLongitude:2.33722916655,centerLatitude:44.10,falseEasting:600000.0,falseNorthing:200000.0});$namespace.ProjectionFactory.ESPG27564=new userSmarts.geo.proj.LCCProjection({units:'meters',unitsAbbr:"m",title:'Lambert Conformal Conic',majorAxis:6378249.2,minorAxis:6356515.0,firstStandardParallel:42.17,secondStandardParallel:42.17,centerLongitude:2.33722916655,centerLatitude:42.17,falseEasting:234.358,falseNorthing:185861.369});$namespace.ProjectionFactory.EPSG2154=new userSmarts.geo.proj.LCCProjection({units:'meters',unitsAbbr:"m",title:'Lambert Conformal Conic',majorAxis:6378137.0,minorAxis:6356752.3141,firstStandardParallel:44.00,secondStandardParallel:49.00,centerLongitude:3.00000000001,centerLatitude:46.50,falseEasting:700000.0,falseNorthing:6600000.0});