/*
  toolkit.js -- MetaCarta JavaScript Toolkit Package

  Copyright (C) MetaCarta, Incorporated. An unpublished work created
  2007 - 2008.  All rights reserved.  This software contains the confidential
  and proprietary information of MetaCarta, Incorporated
  ("MetaCarta").  Copying, distribution or reverse engineering without
  MetaCarta's express written permission is prohibited.

  IF YOU ARE READING THIS, YOU ARE VIOLATING YOUR LICENSE AGREEMENT.
*/

/* Contains portions of Prototype.js, specifically Event handling,
 * AJAX, Try/Bind and Element functions and objects
 *
 *  Prototype is copyright (c) 2005-2007 Sam Stephenson, it is freely
 *  distributable under the following license:
 *
 * Permission is hereby granted, free of charge, to any person
 * obtaining a copy of this software and associated documentation
 * files (), to deal in the Software without restriction, including
 * without limitation the rights to use, copy, modify, merge, publish,
 * distribute, sublicense, and/or sell copies of the Software, and to
 * permit persons to whom the Software is furnished to do so, subject
 * to the following conditions:
 *
 * THE SOFTWARE IS AS , WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 * SOFTWARE.
 */
/* $Id: query-objects.js,v 1.1 2008/11/13 00:59:38 skumar Exp $ */
/* $Id: query-objects.js,v 1.1 2008/11/13 00:59:38 skumar Exp $ */
/* $Id: query-objects.js,v 1.1 2008/11/13 00:59:38 skumar Exp $ */
/* $Id: query-objects.js,v 1.1 2008/11/13 00:59:38 skumar Exp $ */
/* $Id: query-objects.js,v 1.1 2008/11/13 00:59:38 skumar Exp $ */
/* $Id: query-objects.js,v 1.1 2008/11/13 00:59:38 skumar Exp $ */
/* $Id: query-objects.js,v 1.1 2008/11/13 00:59:38 skumar Exp $ */
/* $Id: query-objects.js,v 1.1 2008/11/13 00:59:38 skumar Exp $ */
/* $Id: query-objects.js,v 1.1 2008/11/13 00:59:38 skumar Exp $ */
/* $Id: query-objects.js,v 1.1 2008/11/13 00:59:38 skumar Exp $ */
/* $Id: query-objects.js,v 1.1 2008/11/13 00:59:38 skumar Exp $ */
/* $Id: query-objects.js,v 1.1 2008/11/13 00:59:38 skumar Exp $ */
/* $Id: query-objects.js,v 1.1 2008/11/13 00:59:38 skumar Exp $ */
if(typeof MetaCarta=="undefined"){var MetaCarta=new Object();}
if(typeof MetaCarta.Util=="undefined"){MetaCarta.Util={_counter:0,createUniqueID:function(prefix){if(prefix==null){prefix="id_";}
return prefix+this._counter++;},extend:function(destination,source){if(destination&&source){for(var property in source){destination[property]=source[property];}
if(source.hasOwnProperty&&source.hasOwnProperty('toString')){destination.toString=source.toString;}}
return destination;},applyDefaults:function(destination,source){if(destination&&source){for(var property in source){if(typeof destination[property]=="undefined"){destination[property]=source[property];}}
if(destination.hasOwnProperty&&source.hasOwnProperty&&!destination.hasOwnProperty('toString')&&source.hasOwnProperty('toString')){destination.toString=source.toString;}}
return destination;},Try:function(){var returnValue=null;for(var i=0;i<arguments.length;i++){var lambda=arguments[i];try{returnValue=lambda();break;}catch(e){}}
return returnValue;},createParameterString:function(params){paramsArray=[];for(var key in params){var value=params[key];if((value!=null)&&(typeof value!='function')){var encodedValue;if(typeof value=='object'&&value.constructor==Array){var encodedItemArray=[];for(var itemIndex=0;itemIndex<value.length;itemIndex++){encodedItemArray.push(encodeURIComponent(value[itemIndex]));}
encodedValue=encodedItemArray.join(",");}
else{encodedValue=encodeURIComponent(value);}
paramsArray.push(encodeURIComponent(key)+"="+encodedValue);}}
return paramsArray.join("&");},getParameters:function(url){url=url||window.location.href;var paramsString="";if(MetaCarta.String.contains(url,'?')){var start=url.indexOf('?')+1;var end=MetaCarta.String.contains(url,"#")?url.indexOf('#'):url.length;paramsString=url.substring(start,end);}
var parameters={};var pairs=paramsString.split(/[&;]/);for(var i=0;i<pairs.length;++i){var keyValue=pairs[i].split('=');if(keyValue[0]){var key=decodeURIComponent(keyValue[0]);var value=keyValue[1]||'';value=value.split(",");for(var j=0;j<value.length;j++){value[j]=decodeURIComponent(value[j]);}
if(value.length==1){value=value[0];}
parameters[key]=value;}}
return parameters;},getBrowserName:function(){var browserName="";var ua=navigator.userAgent.toLowerCase();if(ua.indexOf("opera")!=-1){browserName="opera";}else if(ua.indexOf("msie")!=-1){browserName="msie";}else if(ua.indexOf("safari")!=-1){browserName="safari";}else if(ua.indexOf("mozilla")!=-1){if(ua.indexOf("firefox")!=-1){browserName="firefox";}else{browserName="mozilla";}}
return browserName;},CLASS_NAME:"MetaCarta.Util"};}
MetaCarta.Number={limitSigDigs:function(num,sig){var fig;if(sig>0){fig=parseFloat(num.toPrecision(sig));}else{fig=0;}
return fig;},format:function(number,sigDigs){if(MetaCarta.String.contains(number.toString(),".")){var msg="format() can not be called on a floating "+"point number.";MetaCarta.Console.error(msg);return null;}
if(sigDigs==null){sigDigs=3;}
var rounded=MetaCarta.Number.limitSigDigs(number,sigDigs);numStr=rounded.toString();var formatNum="";while(numStr.length>3){formatNum=","+numStr.slice(numStr.length-3)+formatNum;numStr=numStr.slice(0,numStr.length-3)}
formatNum=numStr+formatNum;if(rounded!=number){formatNum="~"+formatNum;}
return formatNum;}};MetaCarta.Function={bind:function(func,object){var args=Array.prototype.slice.apply(arguments,[2]);return function(){var newArgs=args.concat(Array.prototype.slice.apply(arguments,[0]));return func.apply(object,newArgs);};},bindAsEventListener:function(func,object){return function(event){return func.call(object,event||window.event);};}};MetaCarta.Array={indexOf:function(array,obj){var index=-1;for(var i=0;i<array.length;i++){if(array[i]==obj){index=i;break;}}
return index;},removeIndex:function(array,index){var returnArray=null;if((index<0)||(index>=array.length)){returnArray=array.slice();}else{returnArray=array.slice(0,index).concat(array.slice(index+1));}
return returnArray;},removeElement:function(array,element){var index=MetaCarta.Array.indexOf(array,element);return MetaCarta.Array.removeIndex(array,index);},intersect:function(arr1,arr2){var response=new Array();var temp=arr1.concat(arr2);temp.sort();for(var i=0;i<temp.length-1;i++){if(temp[i]==temp[i+1]){response.push(temp[i]);i++;}}
return response;}};MetaCarta.String={startsWith:function(str,sub){return(str.indexOf(sub)==0);},contains:function(str,sub){return(str.indexOf(sub)!=-1);},trim:function(str){return str.replace(/^\s*(.*?)\s*$/,"$1");},camelize:function(str){var oStringList=str.split('-');var camelizedString=oStringList[0];for(var i=1;i<oStringList.length;i++){var s=oStringList[i];camelizedString+=s.charAt(0).toUpperCase()+s.substring(1);}
return camelizedString;}};if(typeof MetaCarta=="undefined"){MetaCarta=new Object();}
if(typeof MetaCarta.Window=="undefined"){MetaCarta.Window={setStyleHeightFromParent:function(elem){var originalElem=elem;while(elem&&!elem.clientHeight&&(!elem.style||(elem.style.height==""))){elem=elem.parentNode;}
if(elem&&elem.style&&elem.style.height){originalElem.style.height=elem.style.height;}else if(elem&&elem.clientHeight){originalElem.style.height=elem.clientHeight+"px";}},adjustSize:function(width,height,elem,options){MetaCarta.Window.adjustWidth(width,elem,options);MetaCarta.Window.adjustHeight(height,elem,options);},adjustWidth:function(px,elem,options){MetaCarta.Window.adjustDimension("width",px,elem,options);},adjustHeight:function(px,elem,options){MetaCarta.Window.adjustDimension("height",px,elem,options);},adjustDimension:function(dimension,px,elem,options){options=options||new Object();var lowerDim=dimension.toLowerCase();var camelDim=lowerDim.charAt(0).toUpperCase()+
lowerDim.substr(1);if((lowerDim=="width")||(lowerDim=="height")){var windowPx=window["inner"+camelDim]||document.documentElement["client"+camelDim]||document.body["client"+camelDim];if(windowPx){var minPx=(lowerDim=="width")?options.minWidth:options.minHeight;if(minPx==null){minPx=100;}
elem.style[lowerDim]=Math.max(windowPx-px,minPx)+"px";}}},CLASS_NAME:"MetaCarta.Window"};}
if(typeof MetaCarta=="undefined"){var MetaCarta=new Object();}
if(typeof MetaCarta.Class=="undefined"){MetaCarta.Class=function(){var Class=function(){this.initialize.apply(this,arguments);}
var extended=new Object();var parent;for(var i=0;i<arguments.length;++i){if(typeof arguments[i]=="function"){parent=arguments[i].prototype;}else{parent=arguments[i];}
MetaCarta.Util.extend(extended,parent);}
Class.prototype=extended;return Class;};}
if(typeof MetaCarta=="undefined"){MetaCarta=new Object();}
MetaCarta.Console={log:function(){},debug:function(){},info:function(){},warn:function(){},error:function(){},assert:function(){},dir:function(){},dirxml:function(){},trace:function(){},group:function(){},groupEnd:function(){},time:function(){},timeEnd:function(){},profile:function(){},profileEnd:function(){},count:function(){},CLASS_NAME:"MetaCarta.Console"};(function(){if(window.console){var scripts=document.getElementsByTagName("script");for(var i=0;i<scripts.length;++i){if(scripts[i].src.indexOf("firebug.js")!=-1){MetaCarta.Util.extend(MetaCarta.Console,console);break;}}}})();if(typeof MetaCarta=="undefined"){var MetaCarta=new Object();}
if(typeof MetaCarta.Debug=="undefined"){MetaCarta.Debug=MetaCarta.Class({indent:"    ",space:" ",newline:"\n",level:0,pretty:false,encodeForHTML:true,initialize:function(options){MetaCarta.Util.extend(this,options);},read:function(json,filter){try{if(/^("(\\.|[^"\\\n\r])*?"|[,:{}\[\]0-9.\-+Eaeflnr-u \n\r\t])+?$/.test(json)){var object=eval('('+json+')');if(typeof filter==='function'){function walk(k,v){if(v&&typeof v==='object'){for(var i in v){if(v.hasOwnProperty(i)){v[i]=walk(i,v[i]);}}}
return filter(k,v);}
object=walk('',object);}
return object;}}catch(e){}
return null;},write:function(value,pretty,options){this.pretty=!!pretty;var json=null;var type=typeof value;if(this.serialize[type]){json=this.serialize[type].apply(this,[value,options]);}
return json;},writeIndent:function(){var pieces=[];if(this.pretty){for(var i=0;i<this.level;++i){pieces.push(this.indent);}}
return pieces.join('');},writeNewline:function(){return(this.pretty)?this.newline:'';},writeSpace:function(){return(this.pretty)?this.space:'';},serialize:{'object':function(object,options){options=options||{};if(object==null){return"null";}
if(object.constructor==Date){return this.serialize.date.apply(this,[object]);}
if(object.constructor==Array){return this.serialize.array.apply(this,[object,options]);}
var pieces=['{'];this.level+=1;var key,keyJSON,valueJSON;var addComma=false;var params=options.params;if(!params){params=[];for(var key in object){params.push(key);}}
if(options.noPrint&&options.noPrint.length){for(var i=0;i<options.noPrint.length;i++){var noPrint=options.noPrint[i];if(typeof noPrint=="string"){params=MetaCarta.Array.removeElement(params,noPrint);}}}
for(var i=0;i<params.length;i++){var key=params[i];if(object.hasOwnProperty(key)){var newOptions=options;if(options.noPrint&&options.noPrint.length){for(var j=0;j<options.noPrint.length;j++){var noPrint=options.noPrint[j];if(typeof noPrint=="object"&&noPrint.param==key){newOptions={'noPrint':noPrint.noPrint};}}}
keyJSON=MetaCarta.Debug.prototype.write.apply(this,[key,this.pretty]);valueJSON=MetaCarta.Debug.prototype.write.apply(this,[object[key],this.pretty,newOptions]);if(keyJSON!=null&&valueJSON!=null){if(addComma){pieces.push(',');}
pieces.push(this.writeNewline(),this.writeIndent(),keyJSON,':',this.writeSpace(),valueJSON);addComma=true;}}}
this.level-=1;pieces.push(this.writeNewline(),this.writeIndent(),'}');return pieces.join('');},'array':function(array,options){var json;var pieces=['['];this.level+=1;for(var i=0;i<array.length;++i){json=MetaCarta.Debug.prototype.write.apply(this,[array[i],this.pretty,options]);if(json!=null){if(i>0){pieces.push(',');}
pieces.push(this.writeNewline(),this.writeIndent(),json);}}
this.level-=1;pieces.push(this.writeNewline(),this.writeIndent(),']');return pieces.join('');},'string':function(string){var m={'\b':'\\b','\t':'\\t','\n':'\\n','\f':'\\f','\r':'\\r','"':'\\"','\\':'\\\\'};if(/["\\\x00-\x1f]/.test(string)){string=string.replace(/([\x00-\x1f\\"])/g,function(a,b){var c=m[b];if(c){return c;}
c=b.charCodeAt();return'\\u00'+
Math.floor(c/16).toString(16)+
(c%16).toString(16);});}
if(this.encodeForHTML&&(/[<>]/.test(string))){string=string.replace(/</g,"&lt;");string=string.replace(/>/g,"&gt;");}
return'"'+string+'"';},'number':function(number){return isFinite(number)?String(number):"null";},'boolean':function(bool){return String(bool);},'date':function(date){function format(number){return(number<10)?'0'+number:number;}
return'"'+date.getFullYear()+'-'+
format(date.getMonth()+1)+'-'+
format(date.getDate())+'T'+
format(date.getHours())+':'+
format(date.getMinutes())+':'+
format(date.getSeconds())+'"';}},CLASS_NAME:"MetaCarta.Debug"});}
if(typeof MetaCarta=="undefined"){MetaCarta=new Object();}
MetaCarta.Element={visible:function(element){return element.style.display!='none';},toggle:function(){for(var i=0;i<arguments.length;i++){var element=arguments[i];var visible=MetaCarta.Element.visible(element);MetaCarta.Element.display(element,!visible);}},hide:function(){for(var i=0;i<arguments.length;i++){var element=arguments[i];if(element.style.display!="none"){element.style._display=element.style.display;element.style.display='none';}}},show:function(){for(var i=0;i<arguments.length;i++){var element=arguments[i];if(element.style.display=="none"){var display=(element.style._display)||'block';element.style.display=display;}}},display:function(element,display){if(display){MetaCarta.Element.show(element);}else{MetaCarta.Element.hide(element);}},remove:function(element){element.parentNode.removeChild(element);},getHeight:function(element){return element.offsetHeight;},getDimensions:function(element){var dimensions={'width':element.offsetWidth,'height':element.offsetHeight};if(MetaCarta.Element.getStyle(element,'display')=='none'){var els=element.style;var originalVisibility=els.visibility;var originalPosition=els.position;els.visibility='hidden';els.position='absolute';els.display='';dimensions.width=element.clientWidth;dimensions.height=element.clientHeight;els.display='none';els.position=originalPosition;els.visibility=originalVisibility;}
return dimensions;},getStyle:function(element,style){var value=element.style[MetaCarta.String.camelize(style)];if(!value){if(document.defaultView&&document.defaultView.getComputedStyle){var css=document.defaultView.getComputedStyle(element,null);value=css?css.getPropertyValue(style):null;}else if(element.currentStyle){value=element.currentStyle[MetaCarta.String.camelize(style)];}}
var positions=['left','top','right','bottom'];if(window.opera&&(MetaCarta.Array.indexOf(positions,style)!=-1)&&(MetaCarta.Element.getStyle(element,'position')=='static')){value='auto';}
return value=='auto'?null:value;},replaceClassName:function(element,currentClassName,newClassName){var re=new RegExp('\\b'+currentClassName+'\\b');element.className=element.className.replace(re,newClassName);},hasClassName:function(element,className){var re=new RegExp('\\b'+className+'\\b');return(element.className.match(re)!=null);}};if(typeof MetaCarta=="undefined"){var MetaCarta=new Object();}
MetaCarta.parseXMLString=function(text){var index=text.indexOf('<');if(index>0){text=text.substring(index);}
var ajaxResponse=MetaCarta.Util.Try(function(){var xmldom=new ActiveXObject('Microsoft.XMLDOM');xmldom.loadXML(text);return xmldom;},function(){return new DOMParser().parseFromString(text,'text/xml');},function(){var req=new XMLHttpRequest();req.open("GET","data:"+"text/xml"+";charset=utf-8,"+encodeURIComponent(text),false);if(req.overrideMimeType){req.overrideMimeType("text/xml");}
req.send(null);return req.responseXML;});return ajaxResponse;};MetaCarta.Ajax={emptyFunction:function(){},getTransport:function(){return MetaCarta.Util.Try(function(){return new XMLHttpRequest()},function(){return new ActiveXObject('Msxml2.XMLHTTP')},function(){return new ActiveXObject('Microsoft.XMLHTTP')})||false;},activeRequestCount:0};MetaCarta.Ajax.ProxyHost="";MetaCarta.Ajax.Responders={responders:[],register:function(responderToAdd){for(var i=0;i<this.responders.length;i++){if(responderToAdd==this.responders[i]){return;}}
this.responders.push(responderToAdd);},unregister:function(responderToRemove){MetaCarta.Array.removeElement(this.reponders,responderToRemove);},dispatch:function(callback,request,transport){for(var i=0;i<this.responders.length;i++){responder=this.responders[i];if(responder[callback]&&typeof responder[callback]=='function'){try{responder[callback].apply(responder,[request,transport]);}catch(e){}}}}};MetaCarta.Ajax.Responders.register({onCreate:function(){MetaCarta.Ajax.activeRequestCount++;},onComplete:function(){MetaCarta.Ajax.activeRequestCount--;}});MetaCarta.Ajax.Base=MetaCarta.Class({initialize:function(options){this.options={method:'post',asynchronous:true,contentType:'application/xml',parameters:''};MetaCarta.Util.extend(this.options,options||{});this.options.method=this.options.method.toLowerCase();if(typeof this.options.parameters=='string'){this.options.parameters=MetaCarta.Util.getParameters(this.options.parameters);}}});MetaCarta.Ajax.Request=MetaCarta.Class(MetaCarta.Ajax.Base,{_complete:false,initialize:function(url,options){MetaCarta.Ajax.Base.prototype.initialize.apply(this,[options]);this.transport=MetaCarta.Ajax.getTransport();this.request(url);},request:function(url){this.url=url;this.method=this.options.method;var params=MetaCarta.Util.extend({},this.options.parameters);if(this.method!='get'&&this.method!='post'){params['_method']=this.method;this.method='post';}
this.parameters=params;if(params=MetaCarta.Util.createParameterString(params)){if(this.method=='get'){this.url+=((this.url.indexOf('?')>-1)?'&':'?')+params;}else if(/Konqueror|Safari|KHTML/.test(navigator.userAgent)){params+='&_=';}}
try{var response=new MetaCarta.Ajax.Response(this);if(this.options.onCreate){this.options.onCreate(response);}
MetaCarta.Ajax.Responders.dispatch('onCreate',this,response);var postData="";if(MetaCarta.Ajax.ProxyHost&&MetaCarta.String.startsWith(url,"http")){postData="&url="+url;this.url=MetaCarta.Ajax.ProxyHost;}
this.transport.open(this.method.toUpperCase(),this.url,this.options.asynchronous);if(this.options.asynchronous){window.setTimeout(MetaCarta.Function.bind(this.respondToReadyState,this,1),10);}
this.transport.onreadystatechange=MetaCarta.Function.bind(this.onStateChange,this);this.setRequestHeaders();this.body=this.method=='post'?(this.options.postBody||params):null;this.body+=postData;this.transport.send(this.body);if(!this.options.asynchronous&&this.transport.overrideMimeType){this.onStateChange();}}catch(e){if(e=="Permission denied to call method XMLHttpRequest.open"){e="You attempted to open the URL: "+url+". "+"This is in violation of the Same Origin Policy, "+"which means the request does not match your current "+"host of: '"+location.host+"' and "+"port of: '"+location.port+"'. ";if(MetaCarta.Ajax.ProxyHost){e+="You have specified a ProxyHost of: '"+
MetaCarta.Ajax.ProxyHost+"'.";}else{e+="You should look into using a proxy for these "+"requests. This is done by setting the variable "+"MetaCarta.Ajax.ProxyHost.";}}
this.dispatchException(e);}},onStateChange:function(){var readyState=this.transport.readyState;if(readyState>1&&!((readyState==4)&&this._complete)){this.respondToReadyState(this.transport.readyState);}},setRequestHeaders:function(){var headers={'X-Requested-With':'XMLHttpRequest','Accept':'text/javascript, text/html, application/xml, text/xml, */*','OpenLayers':true};if(this.method=='post'){headers['Content-type']=this.options.contentType+
(this.options.encoding?'; charset='+this.options.encoding:'');if(this.transport.overrideMimeType&&(navigator.userAgent.match(/Gecko\/(\d{4})/)||[0,2005])[1]<2005){headers['Connection']='close';}}
if(typeof this.options.requestHeaders=='object'){var extras=this.options.requestHeaders;if(typeof extras.push=='function'){for(var i=0,length=extras.length;i<length;i+=2){headers[extras[i]]=extras[i+1];}}else{for(var i in extras){headers[i]=pair[i];}}}
for(var name in headers){this.transport.setRequestHeader(name,headers[name]);}},success:function(){var status=this.getStatus();return!status||(status>=200&&status<300);},getStatus:function(){try{return this.transport.status||0;}catch(e){return 0;}},respondToReadyState:function(readyState){var state=MetaCarta.Ajax.Request.Events[readyState];var response=new MetaCarta.Ajax.Response(this);if(state=='Complete'){try{this._complete=true;(this.options['on'+response.status]||this.options['on'+(this.success()?'Success':'Failure')]||MetaCarta.Ajax.emptyFunction)(response);}catch(e){this.dispatchException(e);}
var contentType=response.getHeader('Content-type');}
try{(this.options['on'+state]||MetaCarta.Ajax.emptyFunction)(response);MetaCarta.Ajax.Responders.dispatch('on'+state,this,response);}catch(e){this.dispatchException(e);}
if(state=='Complete'){this.transport.onreadystatechange=MetaCarta.Ajax.emptyFunction;}},getHeader:function(name){try{return this.transport.getResponseHeader(name);}catch(e){return null;}},dispatchException:function(exception){var handler=this.options.onException;if(handler){handler(this,exception);MetaCarta.Ajax.Responders.dispatch('onException',this,exception);}else{var listener=false;var responders=MetaCarta.Ajax.Responders.responders;for(var i=0;i<responders.length;i++){if(responders[i].onException){listener=true;break;}}
if(listener){MetaCarta.Ajax.Responders.dispatch('onException',this,exception);}else{throw exception;}}}});MetaCarta.Ajax.Request.Events=['Uninitialized','Loading','Loaded','Interactive','Complete'];MetaCarta.Ajax.Response=MetaCarta.Class({status:0,statusText:'',initialize:function(request){this.request=request;var transport=this.transport=request.transport,readyState=this.readyState=transport.readyState;if((readyState>2&&!(!!(window.attachEvent&&!window.opera)))||readyState==4){this.status=this.getStatus();this.statusText=this.getStatusText();this.responseText=transport.responseText==null?'':String(transport.responseText);}
if(readyState==4){var xml=transport.responseXML;this.responseXML=xml===undefined?null:xml;}},getStatus:MetaCarta.Ajax.Request.prototype.getStatus,getStatusText:function(){try{return this.transport.statusText||'';}catch(e){return'';}},getHeader:MetaCarta.Ajax.Request.prototype.getHeader,getResponseHeader:function(name){return this.transport.getResponseHeader(name);}});MetaCarta.Ajax.getElementsByTagNameNS=function(parentnode,nsuri,nsprefix,tagname){var elem=null;if(parentnode.getElementsByTagNameNS){elem=parentnode.getElementsByTagNameNS(nsuri,tagname);}else{elem=parentnode.getElementsByTagName(nsprefix+':'+tagname);}
return elem;};MetaCarta.Ajax.serializeXMLToString=function(xmldom){var serializer=new XMLSerializer();var data=serializer.serializeToString(xmldom);return data;}
if(typeof MetaCarta=="undefined"){MetaCarta=new Object();}
MetaCarta.Event={observers:false,KEY_BACKSPACE:8,KEY_TAB:9,KEY_RETURN:13,KEY_ESC:27,KEY_LEFT:37,KEY_UP:38,KEY_RIGHT:39,KEY_DOWN:40,KEY_DELETE:46,element:function(event){return event.target||event.srcElement;},isLeftClick:function(event){return(((event.which)&&(event.which==1))||((event.button)&&(event.button==1)));},stop:function(event,allowDefault){if(!allowDefault){if(event.preventDefault){event.preventDefault();}else{event.returnValue=false;}}
if(event.stopPropagation){event.stopPropagation();}else{event.cancelBubble=true;}},findElement:function(event,tagName){var element=MetaCarta.Event.element(event);while(element.parentNode&&(!element.tagName||(element.tagName.toUpperCase()!=tagName.toUpperCase())))
element=element.parentNode;return element;},observe:function(element,name,observer,useCapture){useCapture=useCapture||false;if(name=='keypress'&&(navigator.appVersion.match(/Konqueror|Safari|KHTML/)||element.attachEvent)){name='keydown';}
if(!this.observers){this.observers=new Object();}
if(!element._eventCacheID){var idPrefix="eventCacheID_";if(element.id){idPrefix=element.id+"_"+idPrefix;}
element._eventCacheID=MetaCarta.Util.createUniqueID(idPrefix);}
var cacheID=element._eventCacheID;if(!this.observers[cacheID]){this.observers[cacheID]=[];}
this.observers[cacheID].push({'element':element,'name':name,'observer':observer,'useCapture':useCapture});if(element.addEventListener){element.addEventListener(name,observer,useCapture);}else if(element.attachEvent){element.attachEvent('on'+name,observer);}
return observer;},stopObservingElement:function(element){var cacheID=element._eventCacheID;this._removeElementObservers(MetaCarta.Event.observers[cacheID]);},_removeElementObservers:function(elementObservers){if(elementObservers){for(var i=elementObservers.length-1;i>=0;i--){var entry=elementObservers[i];var args=new Array(entry.element,entry.name,entry.observer,entry.useCapture);var removed=MetaCarta.Event.stopObserving.apply(this,args);}}},stopObserving:function(element,name,observer,useCapture){useCapture=useCapture||false;var cacheID=element._eventCacheID;if(name=='keypress'){if(navigator.appVersion.match(/Konqueror|Safari|KHTML/)||element.detachEvent){name='keydown';}}
var foundEntry=false;var elementObservers=MetaCarta.Event.observers[cacheID];if(elementObservers){var i=0;while(!foundEntry&&i<elementObservers.length){var cacheEntry=elementObservers[i];if((cacheEntry.name==name)&&(cacheEntry.observer==observer)&&(cacheEntry.useCapture==useCapture)){elementObservers.splice(i,1);if(elementObservers.length==0){delete MetaCarta.Event.observers[cacheID];}
foundEntry=true;break;}
i++;}}
if(foundEntry){if(element.removeEventListener){element.removeEventListener(name,observer,useCapture);}else if(element&&element.detachEvent){element.detachEvent('on'+name,observer);}}
return foundEntry;},unloadCache:function(){if(MetaCarta.Event.observers){for(var cacheID in MetaCarta.Event.observers){var elementObservers=MetaCarta.Event.observers[cacheID];MetaCarta.Event._removeElementObservers.apply(this,[elementObservers]);}
MetaCarta.Event.observers=false;}},CLASS_NAME:"MetaCarta.Event"};MetaCarta.Event.observe(window,'unload',MetaCarta.Event.unloadCache,false);MetaCarta.Events=MetaCarta.Class({BROWSER_EVENTS:["mouseover","mouseout","mousedown","mouseup","mousemove","click","dblclick","resize","focus","blur"],listeners:null,object:null,element:null,eventTypes:null,eventHandler:null,fallThrough:null,initialize:function(object,element,eventTypes,fallThrough){this.object=object;this.element=element;this.eventTypes=eventTypes;this.fallThrough=fallThrough;this.listeners=new Object();this.eventHandler=MetaCarta.Function.bindAsEventListener(this.handleBrowserEvent,this);if(this.eventTypes!=null){for(var i=0;i<this.eventTypes.length;i++){this.addEventType(this.eventTypes[i]);}}
if(this.element!=null){this.attachToElement(element);}},destroy:function(){if(this.element){MetaCarta.Event.stopObservingElement(this.element);}
this.element=null;this.clear();delete this.listeners;delete this.object;delete this.eventTypes;delete this.fallThrough;delete this.eventHandler;delete this.BROWSER_EVENTS;},addEventType:function(eventName){if(!this.listeners[eventName]){this.listeners[eventName]=[];}},attachToElement:function(element){for(var i=0;i<this.BROWSER_EVENTS.length;i++){var eventType=this.BROWSER_EVENTS[i];this.addEventType(eventType);MetaCarta.Event.observe(element,eventType,this.eventHandler);}
MetaCarta.Event.observe(element,"dragstart",MetaCarta.Event.stop);},register:function(type,func,scope){if(func!=null){if(scope==null){scope=this.object;}
var listeners=this.listeners[type];if(listeners!=null){listeners.push({obj:scope,func:func});}}},unregister:function(type,func,scope){if(scope==null){scope=this.object;}
var listeners=this.listeners[type];if(listeners!=null){for(var i=0;i<listeners.length;i++){if(listeners[i].obj==scope&&listeners[i].func==func){listeners.splice(i,1);break;}}}},clear:function(type){var listenerList=this.listeners[type];if(listenerList){while(listenerList.length){var listener=listenerList.shift();delete listener.obj;delete listener.func;}}},triggerEvent:function(type,evt){if(evt==null){evt=new Object();}
evt.object=this.object;evt.element=this.element;var listeners=(this.listeners[type])?this.listeners[type].slice():null;if((listeners!=null)&&(listeners.length>0)){for(var i=0;i<listeners.length;i++){var callback=listeners[i];var continueChain;if(callback.obj!=null){continueChain=callback.func.call(callback.obj,evt);}else{continueChain=callback.func(evt);}
if((continueChain!=null)&&(continueChain==false)){break;}}
if(!this.fallThrough){MetaCarta.Event.stop(evt,true);}}},handleBrowserEvent:function(evt){evt.xy=this.getMousePosition(evt);this.triggerEvent(evt.type,evt)},getMousePosition:function(evt){var returnPX=null;var scrollLeft=(document.documentElement.scrollLeft||document.body.scrollLeft);var scrollTop=(document.documentElement.scrollTop||document.body.scrollTop);if(!this.element.offsets){this.element.offsets=MetaCarta.Util.pagePosition(this.element);this.element.offsets[0]+=scrollLeft;this.element.offsets[1]+=scrollTop;}
returnPX={x:(evt.clientX+scrollLeft)-this.element.offsets[0],y:(evt.clientY+scrollTop)-this.element.offsets[1]};return returnPX;},CLASS_NAME:"MetaCarta.Events"});if(typeof MetaCarta=="undefined"){MetaCarta=new Object();}
if(typeof MetaCarta.JSON=="undefined"){MetaCarta.JSON={callbackParameter:"callback",requests:new Object(),request:function(url,obj){if(obj==null){obj={'callback':function(){}};}
var requestObject=null;obj.httpMethod=obj.httpMethod||'POST';switch(obj.httpMethod){case'GET':MetaCarta.JSON.scriptRequest(url,obj);break;case'POST':default:requestObject=MetaCarta.JSON.AJAXRequest(url,obj);}
return requestObject;},scriptRequest:function(url,obj){obj.scriptElem=document.createElement("script");obj.hash_id=MetaCarta.Util.createUniqueID("JSONObject_");MetaCarta.JSON.requests[obj.hash_id]=obj;var handler=function(result){this.callback(result);if(this.scriptElem.parentNode){this.scriptElem.parentNode.removeChild(this.scriptElem);}
delete MetaCarta.JSON.requests[this.hash_id];};obj.handler=MetaCarta.Function.bind(handler,obj);var lastChar=url.charAt(url.length-1);switch(lastChar){case"?":break;case"&":break;default:var hasQuestionMark=(url.indexOf("?")!=-1);if(hasQuestionMark){url+="&";}else{url+="?";}
break;}
url+=this.callbackParameter+"="+"MetaCarta.JSON.requests['"+obj.hash_id+"'].handler";obj.scriptElem.src=url;var head=document.getElementsByTagName("HEAD")[0];head.appendChild(obj.scriptElem);},AJAXRequest:function(url,obj){var urlParts=url.split("?");url=urlParts[0];var postData=urlParts[1];var handler=function(req){if(req.statusText=="OK"){var json=MetaCarta.JSON.parseJSONString(req.responseText);this.callback(json);}};var requestOptions={method:'post',onSuccess:MetaCarta.Function.bind(handler,obj),onFailure:obj.onFailure,postBody:postData,requestHeaders:['Content-type','application/x-www-form-urlencoded']};return new MetaCarta.Ajax.Request(url,requestOptions);},parseJSONString:function(str){try{return!(/[^,:{}\[\]0-9.\-+Eaeflnr-u \n\r\t]/.test(str.replace(/"(\\.|[^"\\])*"/g,'')))&&eval('('+str+')');}catch(e){return false;}},CLASS_NAME:"MetaCarta.JSON"};}/*
   query-objects.js -- MetaCarta JavaScript Query Object Package

  Copyright (C) MetaCarta, Incorporated. An unpublished work created
  2007 - 2008.  All rights reserved.  This software contains the confidential
  and proprietary information of MetaCarta, Incorporated
  ("MetaCarta").  Copying, distribution or reverse engineering without
  MetaCarta's express written permission is prohibited.

  IF YOU ARE READING THIS, YOU ARE VIOLATING YOUR LICENSE AGREEMENT.
*/
/* $Id: query-objects.js,v 1.1 2008/11/13 00:59:38 skumar Exp $ */
/* $Id: query-objects.js,v 1.1 2008/11/13 00:59:38 skumar Exp $ */
/* $Id: query-objects.js,v 1.1 2008/11/13 00:59:38 skumar Exp $ */
/* $Id: query-objects.js,v 1.1 2008/11/13 00:59:38 skumar Exp $ */
/* $Id: query-objects.js,v 1.1 2008/11/13 00:59:38 skumar Exp $ */
/* $Id: query-objects.js,v 1.1 2008/11/13 00:59:38 skumar Exp $ */
/* $Id: query-objects.js,v 1.1 2008/11/13 00:59:38 skumar Exp $ */
/* $Id: query-objects.js,v 1.1 2008/11/13 00:59:38 skumar Exp $ */
/* $Id: query-objects.js,v 1.1 2008/11/13 00:59:38 skumar Exp $ */
/* $Id: query-objects.js,v 1.1 2008/11/13 00:59:38 skumar Exp $ */
/* $Id: query-objects.js,v 1.1 2008/11/13 00:59:38 skumar Exp $ */
/* $Id: query-objects.js,v 1.1 2008/11/13 00:59:38 skumar Exp $ */
/* $Id: query-objects.js,v 1.1 2008/11/13 00:59:38 skumar Exp $ */
/* $Id: query-objects.js,v 1.1 2008/11/13 00:59:38 skumar Exp $ */
/* $Id: query-objects.js,v 1.1 2008/11/13 00:59:38 skumar Exp $ */
/* $Id: query-objects.js,v 1.1 2008/11/13 00:59:38 skumar Exp $ */
if(typeof MetaCarta=="undefined"){var MetaCarta=new Object();}
if(typeof MetaCarta.Query=="undefined"){MetaCarta.Query=MetaCarta.Class({EVENT_TYPES:["queryRun","queryResponse","queryError"],events:null,httpMethod:'POST',processParallelRequests:true,url:null,version:null,customParams:null,lastRequest:null,initialize:function(options){this.customParams={};this.events=new MetaCarta.Events(this,null,this.EVENT_TYPES);this.setDefaults();MetaCarta.Util.extend(this,options);},destroy:function(){this.EVENT_TYPES=null;this.events.destroy();this.events=null;this.httpMethod=null;this.processParallelRequests=null;this.url=null;this.version=null;this.customParams=null;this.lastRequest=null;},clone:function(queryObject){if(queryObject==null){queryObject=new MetaCarta.Query();}
queryObject.url=this.url;queryObject.version=this.version;queryObject.httpMethod=this.httpMethod;for(var key in this.customParams){queryObject.customParams[key]=this.customParams[key];}
return queryObject;},registerListener:function(type,func,scope){this.events.register(type,func,scope);},unregisterListener:function(type,func,scope){this.events.unregister(type,func,scope);},run:function(options){options=options||{};var requestString=this.createRequestString(options.newParams);var context={'queryObject':this,'requestData':options.requestData,'callback':(options.altCallback)||this.callback,'handleError':(options.altError)||this.handleError};context.requestID=MetaCarta.Util.createUniqueID("Request_ID_");var onSuccess=function(response){if(this.queryObject.processParallelRequests||(this.requestID==this.queryObject.lastRequest.id)){this.queryObject.lastRequest=null;if(response.Warnings&&response.Warnings.length){for(var i=0;i<response.Warnings.length;i++){MetaCarta.Console.warn(response.Warnings[i]);}}
var args=[response,this.requestData];if(response.Errors&&response.Errors.length){this.handleError.apply(this.queryObject,args);}else{this.callback.apply(this.queryObject,args);}}};if(this.processParallelRequests||!this.lastRequest){this.events.triggerEvent("queryRun");}
if(!this.processParallelRequests&&(this.lastRequest&&this.lastRequest.requestObject)){this.lastRequest.requestObject.transport.abort();}
this.lastRequest={'id':context.requestID};var requestObject=MetaCarta.JSON.request(requestString,{'httpMethod':this.httpMethod,'callback':MetaCarta.Function.bind(onSuccess,context),'onFailure':MetaCarta.Function.bind(context.handleError,this)});this.lastRequest.requestObject=requestObject;return requestObject;},callback:function(response,requestData){var evt={'response':response,'requestData':requestData};this.events.triggerEvent("queryResponse",evt);},handleError:function(response,requestData){var evt={'response':response,'requestData':requestData};this.events.triggerEvent("queryError",evt);},clear:function(){this.url=null;this.customParams={};this.version=null;},reset:function(){this.clear();this.setDefaults();},setDefaults:function(){},getParams:function(){var params={'version':this.version};return params;},createRequestString:function(newParams){var requestString=this.url;var params=MetaCarta.Util.extend({},this.getParams());params=MetaCarta.Util.extend(params,this.customParams);params=MetaCarta.Util.extend(params,newParams);var urlParams=MetaCarta.Util.getParameters(this.url);for(var key in params){if(key in urlParams){delete params[key];}}
var paramsString=MetaCarta.Util.createParameterString(params);if(paramsString!=""){var lastServerChar=this.url.charAt(this.url.length-1);if((lastServerChar=="&")||(lastServerChar=="?")){requestString+=paramsString;}else{if(!MetaCarta.String.contains(this.url,'?')){requestString+='?'+paramsString;}else{requestString+='&'+paramsString;}}}
return requestString;},debugString:function(options){options=options||{};var debug=new MetaCarta.Debug(options);var writeOptions={'params':this.getDebugParams()};var debugString=debug.write(this,true,writeOptions);return debugString;},getDebugParams:function(){var params=['httpMethod','url','version','customParams'];return params;},CLASS_NAME:"MetaCarta.Query"});MetaCarta.Query.STANDARD_ERROR_HANDLER=function(evt){var msg="Communication Error with GTS Appliance.";if(evt&&evt.response){var errors=evt.response.Errors;if(errors){var errorMessages=[];for(var i=0;i<errors.length;i++){errorMessages.push(errors[i].Message);}
msg=errorMessages.join("\n\n");}else if(evt.response.statusText){msg="Status: "+evt.response.status+"\n"+"Status Text: "+evt.response.statusText;}}
alert("Transport Error:\n\n"+msg);return msg;};}
if(MetaCarta.Query&&typeof MetaCarta.Query.Paging=="undefined"){MetaCarta.Query.Paging=MetaCarta.Class({lastStartRef:null,lastMaxRefs:null,lastNumRefsReturned:null,lastTotalNumRefs:null,lastApproxNumRefsQuery:null,lastApproxNumDocsQuery:null,pagingRequest:null,initialize:function(pagingRequest){this.pagingRequest=pagingRequest;},destroy:function(){this.lastStartRef=null;this.lastMaxRefs=null;this.lastNumRefsReturned=null;this.lastTotalNumRefs=null;this.lastApproxNumRefsQuery=null;this.lastApproxNumDocsQuery=null;this.pagingRequest=null;},clear:function(){this.lastStartRef=null;this.lastMaxRefs=null;this.lastNumRefsReturned=null;this.lastTotalNumRefs=null;this.lastApproxNumRefsQuery=null;this.lastApproxNumDocsQuery=null;},pageStart:function(options){options=options||{};options.newParams=options.newParams||{};var runQuery=(this.lastStartRef!=null);if(runQuery){options.newParams.startRef=0;this.pagingRequest(options);}
return runQuery;},pageForward:function(options){options=options||{};options.newParams=options.newParams||{};var runQuery=(this.lastStartRef!=null);if(runQuery){if(this.lastNumRefsReturned<this.lastMaxRefs){if(options.loop){options.newParams.startRef=0;}else{runQuery=false;}}else{var stepRefs=this.maxRefs||this.lastMaxRefs;options.newParams.startRef=this.lastStartRef+stepRefs;}}
if(runQuery){this.pagingRequest(options);}
return runQuery;},pageBackward:function(options){options=options||{};options.newParams=options.newParams||{};var runQuery=((this.lastStartRef!=null)&&(this.lastStartRef>0));if(runQuery){var stepRefs=this.maxRefs||this.lastMaxRefs;options.newParams.startRef=Math.max(0,this.lastStartRef-stepRefs);this.pagingRequest(options);}
return runQuery;},pageEnd:function(options){options=options||{};options.newParams=options.newParams||{};var runQuery=((this.lastStartRef!=null)&&(this.lastTotalNumRefs!=null));if(runQuery){var stepRefs=this.maxRefs||this.lastMaxRefs;options.newParams.startRef=this.lastTotalNumRefs-stepRefs;this.pagingRequest(options);}
return runQuery;},getCurrentPageNumber:function(){if(!this.lastMaxRefs)return null;return parseInt(this.lastStartRef/this.lastMaxRefs)+1;},getLastPageNumber:function(){if(!this.lastMaxRefs)return null;return Math.ceil((this.lastTotalNumRefs||this.lastApproxNumRefsQuery)/this.lastMaxRefs);},storeLastRefsInfo:function(obj){this.lastStartRef=obj.startRef;this.lastMaxRefs=obj.maxRefs;this.lastNumRefsReturned=obj.numRefsReturned;this.lastTotalNumRefs=obj.totalNumRefs;this.lastApproxNumRefsQuery=obj.approxNumRefsQuery;this.lastApproxNumDocsQuery=obj.approxNumDocsQuery;},CLASS_NAME:"MetaCarta.Query.Paging"});}
if(MetaCarta.Query&&typeof MetaCarta.Query.LocationFinder=="undefined"){MetaCarta.Query.LocationFinder=MetaCarta.Class(MetaCarta.Query,MetaCarta.Query.Paging,{processParallelRequests:false,query:null,mime:null,geometry:null,jsonResponse:null,jsonLocations:null,startRef:null,maxRefs:null,initialize:function(options){MetaCarta.Query.prototype.initialize.apply(this,arguments);var newArgs=[this.queryFromCache];MetaCarta.Query.Paging.prototype.initialize.apply(this,newArgs);},destroy:function(){MetaCarta.Query.prototype.destroy.apply(this,arguments);MetaCarta.Query.Paging.prototype.destroy.apply(this,arguments);this.query=null;this.mime=null;this.geometry=null;this.jsonResponse=null;this.jsonLocations=null;this.startRef=null;this.maxRefs=null;},clone:function(lfQueryObject){if(lfQueryObject==null){lfQueryObject=new MetaCarta.Query.LocationFinder();}
lfQueryObject=MetaCarta.Query.prototype.clone.apply(this,[lfQueryObject]);lfQueryObject.query=this.query;lfQueryObject.mime=this.mime;lfQueryObject.geometry=this.geometry;lfQueryObject.startRef=this.startRef;lfQueryObject.maxRefs=this.maxRefs;return lfQueryObject;},setDefaults:function(){this.url=MetaCarta.Query.LocationFinder.DEFAULT_URL;this.version=MetaCarta.Query.LocationFinder.DEFAULT_VERSION;this.mime=MetaCarta.Query.LocationFinder.DEFAULT_MIME;},clear:function(){MetaCarta.Query.prototype.clear.apply(this,arguments);MetaCarta.Query.Paging.prototype.clear.apply(this,arguments);this.query=null;this.mime=null;this.geometry=null;this.jsonResponse=null;this.jsonLocations=null;this.startRef=null;this.maxRefs=null;},callback:function(response,requestData){this.jsonResponse=response;this.jsonLocations=response.Locations;var options={'requestData':requestData};this.queryFromCache(options);},queryFromCache:function(options){options=options||{};options.newParams=options.newParams||{};var startRef=(options.newParams.startRef!=null)?options.newParams.startRef:this.startRef;if((startRef==null)||(startRef<0)){startRef=0;}
var maxRefs=(options.newParams.maxRefs!=null)?options.newParams.maxRefs:this.maxRefs;if(maxRefs==null){maxRefs=MetaCarta.Query.LocationFinder.DEFAULT_MAX_REFS;};delete this.jsonResponse.Locations;this.jsonResponse.Locations=this.jsonLocations.slice(startRef,startRef+maxRefs);if(options.altCallback){var args=[this.jsonResponse,options.requestData];options.altCallback.apply(this,args);}else{var json=this.jsonResponse;var responseObject=new MetaCarta.Query.LocationFinder.Response(json);responseObject.totalNumRefs=this.jsonLocations.length;responseObject.startRef=startRef;responseObject.maxRefs=maxRefs;responseObject.numRefsReturned=this.jsonResponse.Locations.length;this.storeLastRefsInfo(responseObject);var newArgs=[responseObject,options.requestData];MetaCarta.Query.prototype.callback.apply(this,newArgs);}},getParams:function(){var baseParams=MetaCarta.Query.prototype.getParams.apply(this,arguments);var params={'query':this.query,'mime':this.mime,'geometry':this.geometry};var fullParams=MetaCarta.Util.extend(baseParams,params);return fullParams;},getDebugParams:function(){var params=MetaCarta.Query.prototype.getDebugParams.apply(this,arguments);params=params.concat(['query','mime','geometry']);return params;},CLASS_NAME:"MetaCarta.Query.LocationFinder"});MetaCarta.Query.LocationFinder.DEFAULT_URL="/services/location-finder/JSON";MetaCarta.Query.LocationFinder.DEFAULT_VERSION="2.0.0";MetaCarta.Query.LocationFinder.DEFAULT_MIME="text/plain";MetaCarta.Query.LocationFinder.DEFAULT_MAX_REFS=100;}
if(MetaCarta.Query&&typeof MetaCarta.Query.QueryParser=="undefined"){MetaCarta.Query.QueryParser=MetaCarta.Class(MetaCarta.Query,{processParallelRequests:false,query:null,geometry:null,BBOX:null,minQueryConfidence:null,minLocationWeight:null,maxQueries:null,maxLocations:null,initialize:function(options){MetaCarta.Query.prototype.initialize.apply(this,arguments);},destroy:function(){MetaCarta.Query.prototype.destroy.apply(this,arguments);this.query=null;this.geometry=null;this.BBOX=null;this.minQueryConfidence=null;this.minLocationWeight=null;this.maxQueries=null;this.maxLocations=null;},clone:function(qpQueryObject){if(qpQueryObject==null){qpQueryObject=new MetaCarta.Query.QueryParser();}
qpQueryObject=MetaCarta.Query.prototype.clone.apply(this,[qpQueryObject]);qpQueryObject.query=this.query;qpQueryObject.geometry=this.geometry;if(this.BBOX){qpQueryObject.BBOX=this.BBOX.slice();}
qpQueryObject.minQueryConfidence=this.minQueryConfidence;qpQueryObject.minLocationWeight=this.minLocationWeight;qpQueryObject.maxQueries=this.maxQueries;qpQueryObject.maxLocations=this.maxLocations;return qpQueryObject;},setDefaults:function(){this.url=MetaCarta.Query.QueryParser.DEFAULT_URL;this.version=MetaCarta.Query.QueryParser.DEFAULT_VERSION;},clear:function(){MetaCarta.Query.prototype.clear.apply(this,arguments);this.query=null;this.geometry=null;this.BBOX=null;this.minQueryConfidence=null;this.minLocationWeight=null;this.maxQueries=null;this.maxLocations=null;},callback:function(response,requestData){var responseObject=new MetaCarta.Query.QueryParser.Response(response);var newArgs=[responseObject,requestData];MetaCarta.Query.prototype.callback.apply(this,newArgs);},getParams:function(){var baseParams=MetaCarta.Query.prototype.getParams.apply(this,arguments);var params={'query':this.query,'geometry':this.geometry,'BBOX':this.BBOX,'minQueryConfidence':this.minQueryConfidence,'minLocationWeight':this.minLocationWeight,'maxQueries':this.maxQueries,'maxLocations':this.maxLocations};var fullParams=MetaCarta.Util.extend(baseParams,params);return fullParams;},getDebugParams:function(){var params=MetaCarta.Query.prototype.getDebugParams.apply(this,arguments);params=params.concat(['query','geometry','BBOX','minQueryConfidence','minLocationWeight','maxQueries','maxLocations']);return params;},CLASS_NAME:"MetaCarta.Query.QueryParser"});MetaCarta.Query.QueryParser.DEFAULT_URL="/services/query-parser/JSON";MetaCarta.Query.QueryParser.DEFAULT_VERSION="2.0.0";}
if(MetaCarta.Query&&typeof MetaCarta.Query.SearchManager=="undefined"){MetaCarta.Query.SearchManager=MetaCarta.Class(MetaCarta.Query,{sortBy:null,sortOrder:null,initialize:function(options){MetaCarta.Query.prototype.initialize.apply(this,arguments);this.events.addEventType("listSavedSearchesResponse");},destroy:function(){this.sortBy=null;this.sortOrder=null;MetaCarta.Query.prototype.destroy.apply(this,arguments);},clone:function(searchManagerQueryObject){if(searchManagerQueryObject==null){searchManagerQueryObject=new MetaCarta.Query.SearchManager();}
searchManagerQueryObject=MetaCarta.Query.prototype.clone.apply(this,[searchManagerQueryObject]);searchManagerQueryObject.sortBy=this.sortBy;searchManagerQueryObject.sortOrder=this.sortOrder;return searchManagerQueryObject;},setDefaults:function(){this.url=MetaCarta.Query.SearchManager.DEFAULT_URL;this.version=MetaCarta.Query.SearchManager.DEFAULT_VERSION;},run:function(options,defaultOptions){options=options||{};defaultOptions=defaultOptions||{};options.newParams=MetaCarta.Util.applyDefaults(options.newParams||{},defaultOptions.newParams);if(typeof options.requestData=="undefined"){options.requestData=defaultOptions.requestData;}
if(typeof options.altCallback=="undefined"){options.altCallback=defaultOptions.altCallback;}
return MetaCarta.Query.prototype.run.apply(this,[options]);},listSavedSearches:function(options){var defaultOptions={'newParams':{'action':"listSearches",'sortby':this.sortBy,'sortorder':this.sortOrder},'requestData':null,'altCallback':this.listSavedSearchesCallback};return this.run(options,defaultOptions);},listSavedSearchesCallback:function(response,requestData){var savedSearches=[];if(response.Searches!=null&&response.Searches.length){for(var i=0;i<response.Searches.length;i++){var ssJSON=response.Searches[i];var savedSearch=this.loadSavedSearchFromJSON(ssJSON);savedSearches.push(savedSearch);}}
var evt={'response':{'savedSearches':savedSearches,'notifyeeTypes':response.NotifyeeTypes||{},'responseJSON':response,'debugString':function(options){options=options||{};var debug=new MetaCarta.Debug(options);var writeOptions={'noPrint':['responseJSON','debugString',{'param':'savedSearches','noPrint':['responseObject','events']}]};var debugString=debug.write(this,true,writeOptions);return debugString;}}};this.events.triggerEvent("listSavedSearchesResponse",evt);},loadSavedSearchFromJSON:function(ssJSON,savedSearch){var options={'owner':ssJSON.Owner,'id':ssJSON.Id,'name':ssJSON.Name,'UIVersion':ssJSON.UIVersion,'queryParameters':{'query':ssJSON.QueryParameters.Query,'BBOX':[ssJSON.QueryParameters.BBox.MinLongitude,ssJSON.QueryParameters.BBox.MinLatitude,ssJSON.QueryParameters.BBox.MaxLongitude,ssJSON.QueryParameters.BBox.MaxLatitude]},'browserState':ssJSON.BrowserState,'executionFrequency':ssJSON.ExecutionFrequency,'realTimeFrequency':ssJSON.RealTimeFrequency,'creationTime':new Date(ssJSON.CreationTime*10),'lastExecuteTime':new Date(ssJSON.LastExecuteTime*10),'lastNotificationTime':new Date(ssJSON.LastNotificationTime*10),'availableNotifyeeTypes':ssJSON.AvailableNotifyeeTypes};if(ssJSON.LatestDocTime){options.latestDocTime=new Date(ssJSON.LatestDocTime*10);}
if(ssJSON.QueryParameters.MinExtractedTime){options.queryParameters.minExtractedTime=new Date(ssJSON.QueryParameters.MinExtractedTime*10);}
if(ssJSON.QueryParameters.MaxExtractedTime){options.queryParameters.maxExtractedTime=new Date(ssJSON.QueryParameters.MaxExtractedTime*10);}
options.notifyees=[];if(ssJSON.Notifyees&&ssJSON.Notifyees.length){for(var j=0;j<ssJSON.Notifyees.length;j++){var notifyee=ssJSON.Notifyees[j];var newNotifyee={'id':notifyee.Id,'address':notifyee.Address,'type':notifyee.Type};options.notifyees.push(newNotifyee);}}
if(savedSearch){MetaCarta.Util.extend(savedSearch,options);}else{savedSearch=new MetaCarta.Query.SearchManager.SavedSearch(this,options);}
return savedSearch;},createNewSavedSearch:function(options){var savedSearch=new MetaCarta.Query.SearchManager.SavedSearch(this,options);return savedSearch;},createNewSavedSearchFromQueryObject:function(queryObject){var options={'queryParameters':{'query':queryObject.serializeQueryParameters(),'BBOX':queryObject.BBOX.slice()}};if(queryObject.minExtractedTime){options.queryParameters.minExtractedTime=new Date(queryObject.minExtractedTime);}
if(queryObject.maxExtractedTime){options.queryParameters.maxExtractedTime=new Date(queryObject.maxExtractedTime);}
var savedSearch=this.createNewSavedSearch(options);return savedSearch;},addNewSavedSearch:function(savedSearch,options){var newParams={'action':"addSearch",'owner':savedSearch.owner,'name':savedSearch.name,'uiversion':savedSearch.UIVersion,'query':savedSearch.queryParameters.query,'bbox':savedSearch.queryParameters.BBOX,'executionfrequency':savedSearch.executionFrequency,'realtimefrequency':savedSearch.realTimeFrequency,'browserstate':savedSearch.browserState};if(savedSearch.queryParameters.minExtractedTime!=null){var minTime=savedSearch.queryParameters.minExtractedTime;newParams.queryminextractedtime=Date.parse(minTime)/10;}
if(savedSearch.queryParameters.maxExtractedTime!=null){var maxTime=savedSearch.queryParameters.maxExtractedTime;newParams.querymaxextractedtime=Date.parse(maxTime)/10;}
if(savedSearch.notifyees&&savedSearch.notifyees.length){newParams.numnotifyees=savedSearch.notifyees.length;for(var i=0;i<savedSearch.notifyees.length;i++){newParams["notifyeetype_"+i]=savedSearch.notifyees[i].type;newParams["notifyeeaddress_"+i]=savedSearch.notifyees[i].address;}}
var defaultOptions={'newParams':newParams,'requestData':{'savedSearch':savedSearch},'altCallback':this.addNewSavedSearchCallback};return this.run(options,defaultOptions);},addNewSavedSearchCallback:function(response,requestData){if(requestData&&requestData.savedSearch){var savedSearch=requestData.savedSearch;if(response.Searches!=null&&response.Searches.length){var ssJSON=response.Searches[0];this.loadSavedSearchFromJSON(ssJSON,savedSearch);}
savedSearch.saveState()
savedSearch.events.triggerEvent("added");}},deleteSavedSearch:function(savedSearch,options){var defaultOptions={'newParams':{'action':"deleteSearch",'owner':savedSearch.owner,'name':savedSearch.name},'requestData':{'savedSearch':savedSearch},'altCallback':function(response,requestData){if(requestData&&requestData.savedSearch){requestData.savedSearch.events.triggerEvent("deleted");}}};return this.run(options,defaultOptions);},renameSavedSearch:function(savedSearch,options){var defaultOptions={'newParams':{'action':"renameSearch",'owner':savedSearch.owner,'name':savedSearch.savedAttributes.name,'newname':savedSearch.name},'requestData':{'savedSearch':savedSearch},'altCallback':function(response,requestData){if(requestData&&requestData.savedSearch){requestData.savedSearch.nameUpdated();requestData.savedSearch.events.triggerEvent("updated");}}};return this.run(options,defaultOptions);},updateSavedSearchExecutionFrequency:function(savedSearch,options){var defaultOptions={'newParams':{'action':"updateSearchSchedule",'owner':savedSearch.owner,'name':savedSearch.name,'executionfrequency':savedSearch.executionFrequency},'requestData':{'savedSearch':savedSearch},'altCallback':function(response,requestData){if(requestData&&requestData.savedSearch){requestData.savedSearch.executionFrequencyUpdated();requestData.savedSearch.events.triggerEvent("updated");}}};return this.run(options,defaultOptions);},updateSavedSearchRealTimeFrequency:function(savedSearch,options){var defaultOptions={'newParams':{'action':"updateSearchRealTime",'owner':savedSearch.owner,'name':savedSearch.name,'realtimefrequency':savedSearch.realTimeFrequency},'requestData':{'savedSearch':savedSearch},'altCallback':function(response,requestData){if(requestData&&requestData.savedSearch){requestData.savedSearch.realTimeFrequencyUpdated();requestData.savedSearch.events.triggerEvent("updated");}}};return this.run(options,defaultOptions);},addSavedSearchNotifyees:function(savedSearch,newNotifyees,options){var newParams={'action':"addNotifyees",'owner':savedSearch.owner,'name':savedSearch.name,'numnotifyees':newNotifyees.length};for(var i=0;i<newNotifyees.length;i++){newParams["notifyeetype_"+i]=newNotifyees[i].type;newParams["notifyeeaddress_"+i]=newNotifyees[i].address;}
var defaultOptions={'newParams':newParams,'requestData':{'savedSearch':savedSearch,'newNotifyees':newNotifyees},'altCallback':function(response,requestData){if(requestData&&requestData.savedSearch&&requestData.newNotifyees){requestData.savedSearch.notifyeesAdded(requestData.newNotifyees);requestData.savedSearch.events.triggerEvent("updated");}}};return this.run(options,defaultOptions);},deleteSavedSearchNotifyees:function(savedSearch,deadNotifyees,options){var newParams={'action':"deleteNotifyees",'owner':savedSearch.owner,'name':savedSearch.name,'numnotifyees':deadNotifyees.length};for(var i=0;i<deadNotifyees.length;i++){newParams["notifyeeid_"+i]=deadNotifyees[i].id;}
var defaultOptions={'newParams':newParams,'requestData':{'savedSearch':savedSearch,'deadNotifyees':deadNotifyees},'altCallback':function(response,requestData){if(requestData&&requestData.savedSearch&&requestData.deadNotifyees){requestData.savedSearch.notifyeesDeleted(requestData.deadNotifyees);requestData.savedSearch.events.triggerEvent("updated");}}};return this.run(options,defaultOptions);},getDebugParams:function(){var params=MetaCarta.Query.prototype.getDebugParams.apply(this,arguments);params=params.concat(['sortBy','sortOrder']);return params;},CLASS_NAME:"MetaCarta.Query.SearchManager"});MetaCarta.Query.SearchManager.DEFAULT_URL="/services/saved-search/JSON";MetaCarta.Query.SearchManager.DEFAULT_VERSION="2.0.0";}
if(MetaCarta.Query&&typeof MetaCarta.Query.Search=="undefined"){MetaCarta.Query.Search=MetaCarta.Class(MetaCarta.Query,MetaCarta.Query.Paging,{processParallelRequests:false,action:null,query:null,queryParameters:null,BBOX:null,SRS:null,mime:null,startRef:null,maxRefs:null,grid:null,densityGrid:null,densityFormat:null,minExtractedTime:null,maxExtractedTime:null,key:null,docToken:null,initialize:function(options){this.queryParameters={};MetaCarta.Query.prototype.initialize.apply(this,arguments);var newArgs=[this.run];MetaCarta.Query.Paging.prototype.initialize.apply(this,newArgs);this.deserializeQueryString();this.events.addEventType("getMetadataKeysResponse");this.events.addEventType("getMetadataValuesResponse");this.events.addEventType("getDocumentContentsResponse");},destroy:function(){MetaCarta.Query.prototype.destroy.apply(this,arguments);MetaCarta.Query.Paging.prototype.destroy.apply(this,arguments);this.action=null;this.query=null;this.queryParameters=null;this.BBOX=null;this.SRS=null;this.mime=null;this.startRef=null;this.maxRefs=null;this.grid=null;this.densityGrid=null;this.densityFormat=null;this.minExtractedTime=null;this.maxExtractedTime=null;this.key=null;this.docToken=null;},clone:function(searchQueryObject){if(searchQueryObject==null){searchQueryObject=new MetaCarta.Query.Search();}
searchQueryObject=MetaCarta.Query.prototype.clone.apply(this,[searchQueryObject]);searchQueryObject.action=this.action;searchQueryObject.query=this.query;if(this.queryParameters){searchQueryObject.queryParameters={};for(var key in this.queryParameters){var value=this.queryParameters[key]
if(typeof value.length!="undefined"){searchQueryObject.queryParameters[key]=value.slice();}else{searchQueryObject.queryParameters[key]={};for(var subkey in value){searchQueryObject.queryParameters[key][subkey]=value[subkey].slice();}}};}
if(this.BBOX){searchQueryObject.BBOX=this.BBOX.slice();}
searchQueryObject.SRS=this.SRS;searchQueryObject.mime=this.mime;searchQueryObject.startRef=this.startRef;searchQueryObject.maxRefs=this.maxRefs;searchQueryObject.grid=this.grid;searchQueryObject.densityGrid=this.densityGrid;searchQueryObject.densityFormat=this.densityFormat;if(this.minExtractedTime!=null){searchQueryObject.minExtractedTime=new Date(this.minExtractedTime);}
if(this.maxExtractedTime!=null){searchQueryObject.maxExtractedTime=new Date(this.maxExtractedTime);}
searchQueryObject.key=this.key;searchQueryObject.docToken=this.docToken;return searchQueryObject;},setDefaults:function(){this.url=MetaCarta.Query.Search.DEFAULT_URL;this.version=MetaCarta.Query.Search.DEFAULT_VERSION;},clear:function(){MetaCarta.Query.prototype.clear.apply(this,arguments);MetaCarta.Query.Paging.prototype.clear.apply(this,arguments);this.action=null;this.mime=null;this.query=null;this.queryParameters={};this.BBOX=null;this.SRS=null;this.startRef=null;this.maxRefs=null;this.grid=null;this.densityGrid=null;this.densityFormat=null;this.minExtractedTime=null;this.maxExtractedTime=null;this.key=null;this.docToken=null;},deserializeQueryString:function(options){options=options||{};if(!options.preserveQueryParameters){this.queryParameters={};}
var query=this.query||"";var r=new RegExp('"[^"]*"');var phrases=[];var phrase=null;while(phrase=r.exec(query)){phrases.push(phrase[0]);query=query.replace(r,"");}
r=new RegExp("[^' ]+(?:'[^']+')?");while(phrase=r.exec(query)){phrases.push(phrase[0]);query=query.replace(r,"");}
var leftoverQuery=[];for(var i=0;i<phrases.length;i++){var phrase=phrases[i];var quotelessPhrase=(phrase.charAt(0)!='"')?phrase:phrase.substring(1,phrase.length-1);if(!this.parsePhrase(quotelessPhrase,options)){leftoverQuery.push(phrase);}}
this.query=leftoverQuery.join(" ");},parsePhrase:function(phrase,options){var phraseParsed=false;var colon=phrase.indexOf(":");if(colon!=-1){var key=phrase.substring(0,colon);var value=phrase.substring(colon+1);if((options.parseKeys==null)||(typeof options.parseKeys[key]!="undefined")){var safeKey=key.replace(new RegExp("^[+|-]"),"");switch(safeKey){case'site':case'url':if(!this.queryParameters[key]){this.queryParameters[key]=[];}
this.queryParameters[key].push(value);phraseParsed=true;break;case'feature':case'metadata':if(!this.queryParameters[key]){this.queryParameters[key]={};}
var equals=value.indexOf("=");var subkey=null;var subvalue=null;if(equals==-1){subkey=value;}else{subkey=value.substring(0,equals);subvalue=value.substring(equals+1);}
if((options.parseKeys==null)||(options.parseKeys[key]==null)||(typeof options.parseKeys[key][subkey]!="undefined")){if(!this.queryParameters[key][subkey]){this.queryParameters[key][subkey]=[];}
this.queryParameters[key][subkey].push(subvalue);phraseParsed=true;}
break;default:}}}
return phraseParsed;},serializeQueryParameters:function(suppressKeys){if(typeof suppressKeys=="undefined"){suppressKeys={};}
var phrases=[];if(suppressKeys!=null){for(var key in this.queryParameters){if((typeof suppressKeys[key]=="undefined")||(suppressKeys[key]!=null)){var value=this.queryParameters[key];if(typeof value.length!="undefined"){for(var i=0;i<value.length;i++){var phrase=key+":"+value[i];phrases.push(phrase);}}else{for(var subkey in value){if((typeof suppressKeys[key]=="undefined")||(typeof suppressKeys[key][subkey]=="undefined")){var subvalue=value[subkey];for(var i=0;i<subvalue.length;i++){var phrase=key+":"+subkey;if(subvalue[i]!=null){phrase+="="+subvalue[i];}
phrases.push(phrase);}}}}}}
for(var i=0;i<phrases.length;i++){phrases[i]='"'+phrases[i]+'"';}}
var queryString=this.query;if(phrases.length){queryString+=" "+phrases.join(" ");}
return queryString;},getSearchingCollections:function(allCollections,noCollectionsName){var qp=this.queryParameters;var collections=null;if(qp["metadata"]){collections=qp["metadata"]["collection_name"];}
var exclCollections=null;if(qp["-metadata"]){exclCollections=qp["-metadata"]["collection_name"];}
var searchingCollections=null;if((collections||exclCollections)&&(allCollections&&(allCollections.length>0))){searchingCollections=[];if(exclCollections&&(exclCollections[0]==null)){searchingCollections.push(noCollectionsName);}else{if(exclCollections){searchingCollections=allCollections.slice();for(var i=0;i<exclCollections.length;i++){searchingCollections=MetaCarta.Array.removeElement(searchingCollections,exclCollections[i]);}
if(!collections||(collections[0]!=null)){searchingCollections.push(noCollectionsName);}}else{var collection=collections[0];if(collection==null){searchingCollections=allCollections.slice();}else{searchingCollections=[collection];}}}}
return searchingCollections;},run:function(options){options=options||{};this.action="getDocumentReferences";return MetaCarta.Query.prototype.run.apply(this,[options]);},getMetadataKeys:function(options){options=options||{};this.action="getMetadataKeys";options.altCallback=this.getMetadataKeysCallback;return MetaCarta.Query.prototype.run.apply(this,[options]);},getMetadataValues:function(key,options){options=options||{};this.action="getMetadataValues";options.newParams={'key':key};options.altCallback=this.getMetadataValuesCallback;return MetaCarta.Query.prototype.run.apply(this,[options]);},getDocumentContents:function(docToken,options){options=options||{};this.action="getDocumentContents";options.newParams={'docToken':docToken};options.altCallback=this.getDocumentContentsCallback;return MetaCarta.Query.prototype.run.apply(this,[options]);},callback:function(response,requestData){var byLocation=(response.Locations!=null);var responseObject=new MetaCarta.Query.Search.Response(response,byLocation);responseObject.numRefsReturned=responseObject.refs.length;this.storeLastRefsInfo(responseObject);var newArgs=[responseObject,requestData];MetaCarta.Query.prototype.callback.apply(this,newArgs);},getMetadataKeysCallback:function(response){var evt={'response':response.MetadataKeys};this.events.triggerEvent("getMetadataKeysResponse",evt);},getMetadataValuesCallback:function(response){var valuesArray=null;var values=response.MetadataValues;for(var key in values){var value=values[key];if(typeof value!="function"){valuesArray=value;break;}}
var evt={'response':valuesArray};this.events.triggerEvent("getMetadataValuesResponse",evt);},getDocumentContentsCallback:function(response){var evt={'response':response.DocumentContents[0]};this.events.triggerEvent("getDocumentContentsResponse",evt);},getParams:function(){var baseParams=MetaCarta.Query.prototype.getParams.apply(this,arguments);var params={};params.action=this.action;params.mime=this.mime;if((this.action=="getLocationReferences")||(this.action=="getDocumentReferences")){params.query=this.serializeQueryParameters();params.BBOX=this.BBOX;params.SRS=this.SRS;if(this.startRef!=null){params.startRef=this.startRef;}
if(this.maxRefs!=null){params.maxRefs=this.maxRefs;}
if(this.grid!=null){params.grid=this.grid;}
if(this.densityGrid!=null){params.densityGrid=this.densityGrid;params.densityFormat=this.densityFormat;}
if(this.minExtractedTime!=null){params.minExtractedTime=Date.parse(this.minExtractedTime)/10;}
if(this.maxExtractedTime!=null){params.maxExtractedTime=Date.parse(this.maxExtractedTime)/10;}}
var fullParams=MetaCarta.Util.extend(baseParams,params);return fullParams;},getDebugParams:function(){var params=MetaCarta.Query.prototype.getDebugParams.apply(this,arguments);params=params.concat(['query','BBOX','SRS','mime','startRef','maxRefs','grid','densityGrid','densityFormat','minExtractedTime','maxExtractedTime']);return params;},CLASS_NAME:"MetaCarta.Query.Search"});MetaCarta.Query.Search.DEFAULT_URL="/services/search/JSON";MetaCarta.Query.Search.DEFAULT_VERSION="2.0.0";MetaCarta.Query.Search.FEATURE_FIPS="fips_id";MetaCarta.Query.Search.METADATA_COLLECTION_NAME="collection_name";}
if(MetaCarta.Query&&MetaCarta.Query.LocationFinder&&typeof MetaCarta.Query.LocationFinder.Location=="undefined"){MetaCarta.Query.LocationFinder.Location=MetaCarta.Class({responseObject:null,style:null,name:null,centroid:null,type:null,viewBox:null,population:null,fipsCode:null,geometry:null,paths:null,initialize:function(responseObject,responseJSON){this.responseObject=responseObject;this.parseAttributes(responseJSON);},destroy:function(){this.responseObject=null;this.style=null;this.name=null;this.centroid=null;this.type=null;this.viewBox=null;this.population=null;this.fipsCode=null;this.geometry=null;this.paths=null;},parseAttributes:function(obj){var attributes={"style":"Style","name":"Name","centroid":"Centroid","type":"Type","viewBox":"ViewBox","population":"Population","geometry":"Geometry","paths":"Paths","fipsCode":"FIPSCode"};for(output_style in attributes){if(typeof(attributes[output_style])=='string'){var lAttribute=output_style;var uAttribute=attributes[output_style];this[lAttribute]=obj[uAttribute];}}},CLASS_NAME:"MetaCarta.Query.LocationFinder.Location"});}
if(MetaCarta.Query&&MetaCarta.Query.LocationFinder&&typeof MetaCarta.Query.LocationFinder.Response=="undefined"){MetaCarta.Query.LocationFinder.Response=MetaCarta.Class({styles:null,types:null,warnings:null,locs:null,systemVersion:null,query:null,regionReference:null,resultsCreationTime:null,viewBox:null,attribution:null,startRef:null,maxRefs:null,numRefsReturned:null,totalNumRefs:null,responseJSON:null,initialize:function(responseJSON){this.responseJSON=responseJSON;this.parseResponseJSON(responseJSON);},destroy:function(){this.styles=null;this.types=null;this.warnings=null;if(this.locs){while(this.locs.length){var loc=this.locs.pop();loc.destroy();}};this.locs=null;this.systemVersion=null;this.query=null;this.regionReference=null;this.resultsCreationTime=null;this.viewBox=null;this.attribution=null;this.startRef=null;this.maxRefs=null;this.numRefsReturned=null;this.totalNumRefs=null;},parseResponseJSON:function(obj){var attributes=["types","warnings","systemVersion","query","viewBox","attribution","regionReference"];for(var i=0;i<attributes.length;i++){var lAttribute=attributes[i];var uAttribute=lAttribute.charAt(0).toUpperCase()+
lAttribute.substring(1);this[lAttribute]=obj[uAttribute];}
this.resultsCreationTime=new Date(obj.ResultsCreationTime);this.styles={};if(obj.Styles){for(var key in obj.Styles){var val=obj.Styles[key];if(typeof val!="function"){var style={};style.URL=val.DefaultSymbol.URL;style.width=val.DefaultSymbol.Width;style.height=val.DefaultSymbol.Height;this.styles[key]=style;}}}
this.locs=[];if(obj.Locations&&obj.Locations.length>0){for(var i=0;i<obj.Locations.length;i++){var responseJSON=obj.Locations[i];var locationObj=new MetaCarta.Query.LocationFinder.Location(this,responseJSON);this.locs.push(locationObj);}}},debugString:function(options){options=options||{};var debug=new MetaCarta.Debug(options);options.noPrint=['responseJSON',{'param':'locs','noPrint':['responseObject']}];var debugString=debug.write(this,true,options);return debugString;},CLASS_NAME:"MetaCarta.Query.LocationFinder.Response"});}
if(MetaCarta.Query&&MetaCarta.Query.QueryParser&&typeof MetaCarta.Query.QueryParser.Query=="undefined"){MetaCarta.Query.QueryParser.Query=MetaCarta.Class({responseObject:null,confidence:null,remainingQuery:null,geoRef:null,locations:null,initialize:function(responseObject,responseJSON){this.responseObject=responseObject;this.parseAttributes(responseJSON);},destroy:function(){this.responseObject=null;this.confidence=null;this.remainingQuery=null;this.geoRef=null;if(this.locations){while(this.locations.length){var location=this.locations.pop();location.destroy();}}
this.locations=null;},parseAttributes:function(obj){this.confidence=obj.Confidence;this.remainingQuery=obj.RemainingQuery;this.geoRef=obj.GeoRef;this.locations=[];if(obj.Locations){for(var i=0;i<obj.Locations.length;i++){var responseJSON=obj.Locations[i];var locationObj=new MetaCarta.Query.QueryParser.Location(this,responseJSON);this.locations.push(locationObj);}}},CLASS_NAME:"MetaCarta.Query.QueryParser.Query"});}
if(MetaCarta.Query&&MetaCarta.Query.QueryParser&&typeof MetaCarta.Query.QueryParser.Response=="undefined"){MetaCarta.Query.QueryParser.Response=MetaCarta.Class({styles:null,types:null,warnings:null,queries:null,viewBox:null,systemVersion:null,resultsCreationTime:null,responseJSON:null,query:null,BBOX:null,minQueryConfidence:null,minLocationWeight:null,initialize:function(responseJSON){this.responseJSON=responseJSON;this.parseResponseJSON(responseJSON);},destroy:function(){this.styles=null;this.types=null;this.warnings=null;if(this.queries){while(this.queries.length){var query=this.queries.pop();query.destroy();}};this.queries=null;this.query=null;this.BBOX=null;this.viewBox=null;this.minQueryConfidence=null;this.minLocationWeight=null;this.systemVersion=null;this.resultsCreationTime=null;},parseResponseJSON:function(obj){var attributes=["types","warnings","systemVersion","query","minLocationWeight","minQueryConfidence"];for(var i=0;i<attributes.length;i++){var lAttribute=attributes[i];var uAttribute=lAttribute.charAt(0).toUpperCase()+
lAttribute.substring(1);this[lAttribute]=obj[uAttribute];}
this.resultsCreationTime=new Date(obj.ResultsCreationTime);var boundsAttributes=["maxLatitude","minLatitude","maxLongitude","minLongitude"];this.BBOX={};this.viewBox={};for(var i=0;i<boundsAttributes.length;i++){var lAttribute=boundsAttributes[i];var uAttribute=lAttribute.charAt(0).toUpperCase()+
lAttribute.substring(1);this.BBOX[lAttribute]=obj.BBox[uAttribute];this.viewBox[lAttribute]=obj.ViewBox[uAttribute];}
this.styles={};if(obj.Styles){for(var key in obj.Styles){var val=obj.Styles[key];if(typeof val!="function"){var style={};style.URL=val.DefaultSymbol.URL;style.width=val.DefaultSymbol.Width;style.height=val.DefaultSymbol.Height;this.styles[key]=style;}}}
this.queries=[];if(obj.Queries&&obj.Queries.length>0){for(var i=0;i<obj.Queries.length;i++){var responseJSON=obj.Queries[i];var queryObj=new MetaCarta.Query.QueryParser.Query(this,responseJSON);this.queries.push(queryObj);}}},debugString:function(options){options=options||{};var debug=new MetaCarta.Debug(options);options.noPrint=['responseJSON',{'param':'queries','noPrint':['responseObject',{'param':'locations','noPrint':['responseObject']}]}];var debugString=debug.write(this,true,options);return debugString;},CLASS_NAME:"MetaCarta.Query.QueryParser.Response"});}
if(MetaCarta.Query&&MetaCarta.Query.SearchManager&&typeof MetaCarta.Query.SearchManager.SavedSearch=="undefined"){MetaCarta.Query.SearchManager.SavedSearch=MetaCarta.Class({EVENT_TYPES:["added","deleted","updated"],events:null,searchManager:null,savedAttributes:null,owner:null,id:null,'name':null,UIVersion:null,queryParameters:null,executionFrequency:null,realTimeFrequency:null,notifyees:null,creationTime:null,lastExecuteTime:null,lastNotificationTime:null,latestDocTime:null,browserState:null,availableNotifyeeTypes:null,initialize:function(searchManager,options){this.queryParameters={};this.notifyees=[];this.events=new MetaCarta.Events(this,null,this.EVENT_TYPES);this.searchManager=searchManager;MetaCarta.Util.extend(this,options);if(this.id){this.saveState();}},destroy:function(){this.EVENT_TYPES=null;this.events.destroy();this.events=null;this.searchManager=null;if(this.savedAttributes){this.savedAttributes.name=null;this.savedAttributes.executionFrequency=null;this.savedAttributes.realTimeFrequency=null;this.savedAttributes.notifyees=null;}
this.savedAttributes=null;this.owner=null;this.id=null;this.name=null;this.UIVersion=null;if(this.queryParameters){this.queryParameters.query=null;this.queryParameters.BBOX=null;this.queryParameters.minExtractedTime=null;this.queryParameters.maxExtractedTime=null;}
this.queryParameters=null;this.executionFrequency=null;this.realTimeFrequency=null;this.creationTime=null;this.lastExecuteTime=null;this.lastNotificationTime=null;this.latestDocTime=null;this.browserState=null;this.notifyees=null;this.availableNotifyeeTypes=null;},clone:function(){var savedSearch=new MetaCarta.Query.SearchManager.SavedSearch(this.searchManager);savedSearch.owner=this.owner;savedSearch.id=this.id;savedSearch.name=this.name;savedSearch.UIVersion=this.UIVersion;savedSearch.queryParameters={'query':this.queryParameters.query};if(this.queryParameters.BBOX){savedSearch.queryParameters.BBOX=this.queryParameters.BBOX.slice();}
if(this.queryParameters.minExtractedTime){savedSearch.queryParameters.minExtractedTime=new Date(this.queryParameters.minExtractedTime);}
if(this.queryParameters.maxExtractedTime){savedSearch.queryParameters.maxExtractedTime=new Date(this.queryParameters.maxExtractedTime);}
if(this.creationTime!=null){savedSearch.creationTime=new Date(this.creationTime);}
if(this.lastExecuteTime!=null){savedSearch.lastExecuteTime=new Date(this.lastExecuteTime);}
if(this.lastNotificationTime!=null){savedSearch.lastNotificationTime=new Date(this.lastNotificationTime);}
if(this.latestDocTime!=null){savedSearch.latestDocTime=new Date(this.latestDocTime);}
savedSearch.executionFrequency=this.executionFrequency;savedSearch.realTimeFrequency=this.realTimeFrequency;savedSearch.availableNotifyeeTypes=this.availableNotifyeeTypes.slice();savedSearch.notifyees=[];for(var i=0;i<this.notifyees.length;i++){var notifyee=this.notifyees[i];savedSearch.notifyees.push({'id':notifyee.id,'address':notifyee.address,'type':notifyee.type});}
savedSearch.browserState=this.browserState;return savedSearch;},update:function(){var savedAttributes=this.savedAttributes;if(savedAttributes==null){this.searchManager.addNewSavedSearch(this);}else{if(this.name!=savedAttributes.name){this.searchManager.renameSavedSearch(this);}
if(this.executionFrequency!=savedAttributes.executionFrequency){this.searchManager.updateSavedSearchExecutionFrequency(this);}
if(this.realTimeFrequency!=savedAttributes.realTimeFrequency){this.searchManager.updateSavedSearchRealTimeFrequency(this);}
var deadNotifyees=[];for(var i=0;i<savedAttributes.notifyees.length;i++){var savedNotifyee=savedAttributes.notifyees[i];var found=false;for(var j=0;j<this.notifyees.length;j++){var notifyee=this.notifyees[j];if((savedNotifyee.id==notifyee.id)&&(savedNotifyee.type==notifyee.type)&&(savedNotifyee.address==notifyee.address)){found=true;break;}}
if(!found){deadNotifyees.push(savedNotifyee);}}
var newNotifyees=[];for(var i=0;i<this.notifyees.length;i++){var notifyee=this.notifyees[i];var found=false;for(var j=0;j<savedAttributes.notifyees.length;j++){var savedNotifyee=savedAttributes.notifyees[j];if((notifyee.id==savedNotifyee.id)&&(notifyee.type==savedNotifyee.type)&&(notifyee.address==savedNotifyee.address)){found=true;break;}}
if(!found){newNotifyees.push(notifyee);}}
if(deadNotifyees.length>0){var options;if(newNotifyees.length>0){var options={'requestData':{'savedSearch':this,'deadNotifyees':deadNotifyees,'newNotifyees':newNotifyees},'altCallback':function(response,requestData){if(requestData&&requestData.savedSearch&&requestData.deadNotifyees&&requestData.newNotifyees){var ss=requestData.savedSearch;ss.notifyeesDeleted(requestData.deadNotifyees);ss.events.triggerEvent("updated");ss.searchManager.addSavedSearchNotifyees(ss,requestData.newNotifyees);}}}}
this.searchManager.deleteSavedSearchNotifyees(this,deadNotifyees,options);}else if(newNotifyees.length>0){this.searchManager.addSavedSearchNotifyees(this,newNotifyees);}}},'delete':function(){this.searchManager.deleteSavedSearch(this);},setSearchQueryObject:function(queryObject){queryObject.queryParameters={};queryObject.query=this.queryParameters.query;queryObject.BBOX=this.queryParameters.BBOX.slice();queryObject.minExtractedTime=null;if(this.queryParameters.minExtractedTime){queryObject.minExtractedTime=new Date(this.queryParameters.minExtractedTime);}
queryObject.maxExtractedTime=null;if(this.queryParameters.maxExtractedTime){queryObject.maxExtractedTime=new Date(this.queryParameters.maxExtractedTime);}},saveState:function(){if(this.savedAttributes==null){this.savedAttributes={};}
this.nameUpdated();this.executionFrequencyUpdated();this.realTimeFrequencyUpdated();this.notifyeesUpdated();},nameUpdated:function(){this.savedAttributes.name=this.name;},executionFrequencyUpdated:function(){this.savedAttributes.executionFrequency=this.executionFrequency;},realTimeFrequencyUpdated:function(){this.savedAttributes.realTimeFrequency=this.realTimeFrequency;},notifyeesUpdated:function(){this.savedAttributes.notifyees=[];for(var i=0;i<this.notifyees.length;i++){this.savedAttributes.notifyees.push(this.notifyees[i]);}},notifyeesAdded:function(newNotifyees){this.savedAttributes.notifyees=this.savedAttributes.notifyees.concat(newNotifyees);},notifyeesDeleted:function(deadNotifyees){for(var i=0;i<deadNotifyees.length;i++){this.savedAttributes.notifyees=MetaCarta.Array.removeElement(this.savedAttributes.notifyees,deadNotifyees[i]);}},CLASS_NAME:"MetaCarta.Query.SearchManager.SavedSearch"});}
if(MetaCarta.Query&&MetaCarta.Query.Search&&typeof MetaCarta.Query.Search.Document=="undefined"){MetaCarta.Query.Search.Document=MetaCarta.Class({responseObject:null,docToken:null,extractedTime:null,timeExtract:null,title:null,URL:null,highestRelevance:null,refs:null,locs:null,initialize:function(responseObject,responseJSON,fromReference){this.responseObject=responseObject;this.refs=[];this.locs=[];this.parseAttributes(responseJSON);if(!fromReference){this.parseReferences(responseJSON);}},destroy:function(){this.responseObject=null;this.docToken=null;this.extractedTime=null;this.title=null;this.URL=null;this.highestRelevance=null;this.refs=null;},parseAttributes:function(obj){var attributes=["docToken","title","highestRelevance","URL"];for(var i=0;i<attributes.length;i++){var lAttribute=attributes[i];var uAttribute=lAttribute.charAt(0).toUpperCase()+
lAttribute.substring(1);this[lAttribute]=obj[uAttribute];}
if(obj.ExtractedTime[0]){this.extractedTime=new Date(obj.ExtractedTime[0].Time*10);this.timeExtract=obj.ExtractedTime[0].Extract;}},parseReferences:function(obj){if(obj.References&&obj.References.length>0){for(var i=0;i<obj.References.length;i++){var refObj=obj.References[i];var loc=this.responseObject.getLocation(refObj.LocID);if(!loc){loc=new MetaCarta.Query.Search.Location(this.responseObject,refObj,true);this.responseObject.locs.push(loc);}
var ref=new MetaCarta.Query.Search.Reference(refObj,this,loc);this.addReference(ref);this.addLocation(loc);loc.addReference(ref);loc.addDocument(this);this.responseObject.refs.push(ref);}}},addReference:function(ref){this.refs.push(ref);if(!this.highestRelevance||(ref.relevance>this.highestRelevance)){this.highestRelevance=ref.relevance;}},addLocation:function(loc){if(MetaCarta.Array.indexOf(this.locs,loc)==-1){this.locs.push(loc);}},CLASS_NAME:"MetaCarta.Query.Search.Document"});}
if(MetaCarta.Query&&MetaCarta.Query.Search&&typeof MetaCarta.Query.Search.Location=="undefined"){MetaCarta.Query.Search.Location=MetaCarta.Class({responseObject:null,locID:null,centroid:null,style:null,highestRelevance:null,refs:null,docs:null,initialize:function(responseObject,responseJSON,fromReference){this.responseObject=responseObject;this.refs=[];this.docs=[];this.parseAttributes(responseJSON);if(!fromReference){this.parseReferences(responseJSON);}},destroy:function(){this.responseObject=null;this.locID=null;this.centroid=null;this.style=null;this.highestRelevance=null;this.refs=null;},parseAttributes:function(obj){var attributes=["locID","style","centroid","highestRelevance"];for(var i=0;i<attributes.length;i++){var lAttribute=attributes[i];var uAttribute=lAttribute.charAt(0).toUpperCase()+
lAttribute.substring(1);this[lAttribute]=obj[uAttribute];}},parseReferences:function(obj){if(obj.References&&obj.References.length>0){for(var i=0;i<obj.References.length;i++){var refObj=obj.References[i];var doc=this.responseObject.getDocument(refObj.DocToken);if(!doc){doc=new MetaCarta.Query.Search.Document(this.responseObject,refObj,true);this.responseObject.docs.push(doc);}
var ref=new MetaCarta.Query.Search.Reference(refObj,doc,this);this.addReference(ref);this.addDocument(doc);doc.addReference(ref);doc.addLocation(this);this.responseObject.refs.push(ref);}}},addReference:function(ref){this.refs.push(ref);if(!this.highestRelevance||(ref.relevance>this.highestRelevance)){this.highestRelevance=ref.relevance;}},addDocument:function(doc){if(MetaCarta.Array.indexOf(this.docs,doc)==-1){this.docs.push(doc);}},CLASS_NAME:"MetaCarta.Query.Search.Location"});}
if(MetaCarta.Query&&MetaCarta.Query.Search&&typeof MetaCarta.Query.Search.Reference=="undefined"){MetaCarta.Query.Search.Reference=MetaCarta.Class({geoConfidence:null,geoExtract:null,geoRef:null,extract:null,relevance:null,doc:null,loc:null,initialize:function(responseJSON,doc,loc){this.parseAttributes(responseJSON);this.doc=doc;this.loc=loc;},destroy:function(){this.geoConfidence=null;this.geoExtract=null;this.geoRef=null;this.extract=null;this.relevance=null;this.doc=null;this.loc=null;},parseAttributes:function(obj){var attributes=["geoConfidence","geoExtract","geoRef","extract","relevance"];for(var i=0;i<attributes.length;i++){var lAttribute=attributes[i];var uAttribute=lAttribute.charAt(0).toUpperCase()+
lAttribute.substring(1);this[lAttribute]=obj[uAttribute];}},CLASS_NAME:"MetaCarta.Query.Search.Reference"});}
if(MetaCarta.Query&&MetaCarta.Query.Search&&typeof MetaCarta.Query.Search.Response=="undefined"){MetaCarta.Query.Search.Response=MetaCarta.Class({symbols:null,warnings:null,attribution:null,resultsCreationTime:null,numDocsCorpus:null,approxNumDocsQuery:null,numRefsCorpus:null,approxNumRefsQuery:null,refs:null,docs:null,locs:null,query:null,BBOX:null,SRS:null,startRef:null,maxRefs:null,grid:null,density:null,minExtractedTime:null,maxExtractedTime:null,systemVersion:null,responseJSON:null,initialize:function(responseJSON,byLocation){this.responseJSON=responseJSON;this.parseResponseJSON(responseJSON,byLocation);},destroy:function(){this.symbols=null;this.warnings=null;this.attribution=null;this.resultsCreationTime=null;this.numDocsCorpus=null;this.approxNumDocsQuery=null;this.numRefsCorpus=null;this.approxNumRefsQuery=null;if(this.refs){while(this.refs.length){var ref=this.refs.pop();ref.destroy();}}
this.refs=null;if(this.docs){while(this.docs.length){var doc=this.docs.pop();doc.destroy();}}
this.docs=null;if(this.locs){while(this.locs.length){var loc=this.locs.pop();loc.destroy();}}
this.locs=null;this.query=null;this.BBOX=null;this.SRS=null;this.startRef=null;this.maxRefs=null;this.grid=null;this.density=null;this.minExtractedTime=null;this.maxExtractedTime=null;this.systemVersion=null;},parseResponseJSON:function(obj,byLocation){var attributes=["warnings","attribution","numDocsCorpus","approxNumDocsQuery","numRefsCorpus","approxNumRefsQuery","query","SRS","startRef","maxRefs","grid","density","systemVersion"];for(var i=0;i<attributes.length;i++){var lAttribute=attributes[i];var uAttribute=lAttribute.charAt(0).toUpperCase()+
lAttribute.substring(1);this[lAttribute]=obj[uAttribute];}
var bboxAttributes=["maxLatitude","minLatitude","maxLongitude","minLongitude","maxX","minX","maxY","minY"];this.BBOX={};for(var i=0;i<bboxAttributes.length;i++){var lAttribute=bboxAttributes[i];var uAttribute=lAttribute.charAt(0).toUpperCase()+
lAttribute.substring(1);this.BBOX[lAttribute]=obj.BBox[uAttribute];}
this.resultsCreationTime=new Date(obj.ResultsCreationTime);if(obj.MinExtractedTime){this.minExtractedTime=new Date(obj.MinExtractedTime*10);}
if(obj.MaxExtractedTime){this.maxExtractedTime=new Date(obj.MaxExtractedTime*10);}
this.symbols={};if(obj.Styles){for(var key in obj.Styles){var val=obj.Styles[key];if(typeof val!="function"){var symbol={};symbol.URL=val.DefaultSymbol.URL;symbol.width=val.DefaultSymbol.Width;symbol.height=val.DefaultSymbol.Height;this.symbols[key]=symbol;}}}
this.locs=[];this.docs=[];this.refs=[];var jsonArray=(byLocation)?obj.Locations:obj.Documents;var itemClass=(byLocation)?MetaCarta.Query.Search.Location:MetaCarta.Query.Search.Document;var responseArray=(byLocation)?this.locs:this.docs;if(jsonArray&&jsonArray.length>0){for(var i=0;i<jsonArray.length;i++){var item=new itemClass(this,jsonArray[i],false);responseArray.push(item);}}
var compareByHighestRelevance=function(a,b){return b.highestRelevance-a.highestRelevance;};var nonResponseArray=(byLocation)?this.docs:this.locs;nonResponseArray.sort(compareByHighestRelevance);var compareByRelevance=function(a,b){return b.relevance-a.relevance;};this.refs.sort(compareByRelevance);},getLocation:function(locID){var loc=null;for(var i=0;i<this.locs.length;i++){if(this.locs[i].locID==locID){loc=this.locs[i];break;}}
return loc;},getDocument:function(docToken){var doc=null;for(var i=0;i<this.docs.length;i++){if(this.docs[i].docToken==docToken){doc=this.docs[i];break;}}
return doc;},debugString:function(options){options=options||{};var debug=new MetaCarta.Debug(options);var writeOptions={'noPrint':['responseJSON',{'param':'docs','noPrint':['responseObject',{'param':'locs','noPrint':['responseObject','refs','docs']},{'param':'refs','noPrint':['loc','doc']}]},{'param':'locs','noPrint':['responseObject',{'param':'docs','noPrint':['responseObject','refs','locs']},{'param':'refs','noPrint':['loc','doc']}]},{'param':'refs','noPrint':[{'param':'doc','noPrint':['responseObject','refs','locs']},{'param':'loc','noPrint':['responseObject','refs','docs']}]}]};var debugString=debug.write(this,true,writeOptions);return debugString;},CLASS_NAME:"MetaCarta.Query.Search.Response"});}
if(MetaCarta.Query&&MetaCarta.Query.QueryParser&&typeof MetaCarta.Query.QueryParser.Location=="undefined"){MetaCarta.Query.QueryParser.Location=MetaCarta.Class(MetaCarta.Query.LocationFinder.Location,{responseObject:null,weight:null,initialize:function(responseObject,responseJSON){MetaCarta.Query.LocationFinder.Location.prototype.initialize.apply(this,arguments);},destroy:function(){this.weight=null;MetaCarta.Query.LocationFinder.Location.prototype.destroy.apply(this,arguments);},parseAttributes:function(obj){this.weight=obj.Weight;MetaCarta.Query.LocationFinder.Location.prototype.parseAttributes.apply(this,arguments);},CLASS_NAME:"MetaCarta.Query.QueryParser.Location"});}