/*
 * 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.pub");namespace("userSmarts.pub");namespace("userSmarts.pub");function doAjaxGet(url,params){url=attachQueryString(url,params);if(params&&params.format&&(params.format=="text/json"||params.format=="application/atom+json")){return parseJSON(url);}else{return parseXML(url);}}
function doAjaxPost(url,content,params){var req=getXMLHttpRequest();url=attachQueryString(url,params);req.open("POST",url,true);var def=sendXMLHttpRequest(req,content);if(params&&params.format&&(params.format=="text/json"||params.format=="application/atom+json")){def.addCallback(parseJSONCallback);}else{return parseXML(parseXMLCallback);}
return def;}
function doAjaxPut(url,content,params){var req=getXMLHttpRequest();url=attachQueryString(url,params);req.open("PUT",url,true);var def=sendXMLHttpRequest(req,content);if(params&&params.format&&(params.format=="text/json"||params.format=="application/atom+json")){def.addCallback(parseJSONCallback);}else{return parseXML(parseXMLCallback);}
return def;}
function doAjaxDelete(url,content,params){var req=getXMLHttpRequest();url=attachQueryString(url,params);req.open("DELETE",url,true);return sendXMLHttpRequest(req,content);}
function doAjaxHead(url,content,params){var req=getXMLHttpRequest();url=attachQueryString(url,params);req.open("HEAD",url,true);return sendXMLHttpRequest(req,content);}
function doSimpleXMLHttpGet(url,params){url=attachQueryString(url,params);return parseXML(url);}
function doSimpleXMLHttpPost(url,content,params){var req=getXMLHttpRequest();url=attachQueryString(url,params);req.open("POST",url,true);return sendXMLHttpRequest(req,content);}
function doSimpleXMLHttpPut(url,content,params){var req=getXMLHttpRequest();url=attachQueryString(url,params);req.open("PUT",url,true);return sendXMLHttpRequest(req,content);}
function doSimpleXMLHttpDelete(url,content,params){var req=getXMLHttpRequest();url=attachQueryString(url,params);req.open("DELETE",url,true);return sendXMLHttpRequest(req,content);}
function doSimpleXMLHttpHead(url,params){var req=getXMLHttpRequest();url=attachQueryString(url,params);req.open("HEAD",url,true);return sendXMLHttpRequest(req,null);}
function attachQueryString(url,params){if(params){var qs=queryString(params);if(qs){var qsi=url.indexOf("?");if(qsi>0){if(qsi<(url.length-1)){url+="&"+qs;}else{url+=qs;}}else{url+="?"+qs;}}}
return url;}
function handleResponseError(e,fallbackMsg){var status=500;var msg="";if(e.req){status=e.req.status||500;msg=e.req.statusText||fallbackMsg;}else{msg=e.message||fallbackMsg;}
var error="Error ("+status+") - "+msg;alert(error);logError(error);}
function parseXMLCallback(req){var xml=req.responseXML;return xml;}
function parseXML(url,async){if(arguments.length<2){async=true;}
var d;if(location.href.startsWith("file:")){d=new Deferred();var req=new XmlDocumentLoader(function(xmlDoc){d.callback(xmlDoc);});try{req.load(url,async);}catch(e){deferred.errback(e);}}else{d=doSimpleXMLHttpRequest(url);d.addCallback(parseXMLCallback);}
return d;}
function createXMLDocument(rootElementName,namespaceURI,documentType){var xmlDocument=null;namespaceURI=namespaceURI||'';documentType=documentType||null;if(document.implementation&&document.implementation.createDocument){xmlDocument=document.implementation.createDocument(namespaceURI,rootElementName,documentType);}else if(typeof ActiveXObject!='undefined'){try{xmlDocument=new ActiveXObject('Microsoft.XMLDOM');var rootElement=xmlDocument.createNode(1,rootElementName,namespaceURI);xmlDocument.appendChild(rootElement);}catch(e){}}
return xmlDocument;}
function createElementNS(namespaceURI,elementName,ownerDocument){var element=null;if(typeof ownerDocument.createElementNS!='undefined'){element=ownerDocument.createElementNS(namespaceURI,elementName);}else if(typeof ownerDocument.createNode!='undefined'){element=ownerDocument.createNode(1,elementName,namespaceURI);}
return element;}
function serializeNode(node){if(typeof XMLSerializer!='undefined'){return new XMLSerializer().serializeToString(node);}else if(typeof node.xml!='undefined'){return node.xml;}else{return'';}}
function isXmlNode(node){var result=false;if(node&&node.nodeType&&(node.nodeType>0&&node.nodeType<10)){result=true;}
return result;}
function parseJSON(url){var d=doSimpleXMLHttpRequest(url);d.addCallback(parseJSONCallback);return d;}
function parseJSONCallback(req){var text=req.responseText;return JSON.parse(text);}
namespace("userSmarts.pub");function XmlDocumentLoader(callback){if(isPrototype(arguments)){return;}
this.document=null;this.callback=callback;}
XmlDocumentLoader.prototype.load=function(file,async){if(arguments.length<2){async=false;}
this.filename=file;this.hasLoaded=false;var parser=this;var xmlDoc=undefined;if(document.implementation&&document.implementation.createDocument){xmlDoc=document.implementation.createDocument("","",null);xmlDoc.async=async;xmlDoc.onload=function(){parser.callback(parser.document);};}else if(window.ActiveXObject){xmlDoc=new ActiveXObject("Microsoft.XMLDOM");xmlDoc.async=async;xmlDoc.onreadystatechange=function(arg){if(xmlDoc.readyState==4){parser.callback(parser.document);xmlDoc=null;parser=null;}};}else{alert("Your browser can't handle this script");return;}
this.document=xmlDoc;xmlDoc.load(file);var temp=0;};namespace("userSmarts.pub");$namespace.Resource=Class.create(Bean);$prototype.initialize=function(superClass,properties){superClass.call(this,properties);if(!this.params){this.params={requestId:Math.random()};}else{this.params.requestId=Math.random();}};$prototype.getURL=function(){return this.url;};$prototype.setURL=function(url){this.url=url;};$prototype.setParameter=function(name,value){this.params[name]=value;};$prototype.getParameter=function(name){return this.params[name];};$prototype.get=function(){var d=null;var url=this.getURL();if(url){this.setParameter("requestId",Math.random());d=doAjaxGet(url,this.params);}else{d=new Deferred();d.errback("No URL specified for GET operation");}
return d;};$prototype.del=function(){var d=null;var url=this.getURL();if(url){this.setParameter("requestId",Math.random());d=doSimpleXMLHttpDelete(url,null,this.params);}else{d=new Deferred();d.errback("No URL specified for DELETE operation");}
return d;};$prototype.put=function(content){var d=null;if(isXmlNode(content)){content=serializeNode(content);}
var url=this.getURL();if(url){this.setParameter("requestId",Math.random());d=doSimpleXMLHttpPut(url,content,this.params);}else{d=new Deferred();d.errback("No URL specified for PUT operation");}
return d;};$prototype.post=function(content){var d=null;if(isXmlNode(content)){content=serializeNode(content);}
var url=this.getURL();if(url){this.setParameter("requestId",Math.random());d=doSimpleXMLHttpPost(url,content,this.params);}else{d=new Deferred();d.errback("No URL specified for POST operation");}
return d;};$prototype.head=function(){var d=null;var url=this.getURL();if(url){this.setParameter("requestId",Math.random());d=doSimpleXMLHttpHead(url,this.params);}else{d=new Deferred();d.errback("No URL specified for HEAD operation");}
return d;};$prototype.dispose=function(){this.url=null;this.params=null;Bean.prototype.dispose.call(this);};namespace("userSmarts.pub");$namespace.AjaxDOMTableModel=Class.create(userSmarts.wt.widgets.DOMTableModel);$prototype.initialize=function(superclass,properties){setdefault(properties,{resource:new userSmarts.pub.Resource({params:{format:"text/xml"}}),matches:0,depth:0,nodeOffset:0,nodeNames:[]});superclass.call(this,properties);this.loadCallback=bind(this.onDocumentLoad,this);this.errback=bind(this.onDocumentError,this);this.sourceListener=connect(this,'source',this.onSourceChange);};$prototype.setURL=function(url){if(this.resource){this.resource.setURL(url);this.resource.setParameter("format","text/xml");}
this.populate(0);}
$prototype.onSourceChange=function(event){this.setURL(event.newValue);};$prototype.populate=function(position){if(position!==undefined&&position!==null&&(position>=0&&position<this.size())){this.currentRow=position*1;}
if(this.resource){var deferred=this.resource.get();deferred.addCallback(this.loadCallback);deferred.addErrback(this.errback);this.setProperty("populating",true);}else{this.loadCallback(null);}};$prototype.onDocumentLoad=function(document){this.buffer=[];this.matches=0;var root=this.getRootNode(document);if(root){this.buffer=this.parseRows(root);}else{getLogger().logError("AjaxDOMTableModel.onDocumentLoad() - "+"Unable to populate model, root element of response was null");}
this.setProperty("modified",true);};$prototype.getRootNode=function(document){if(!document||!isXmlNode(document))return null;if(document.nodeType==9){return document.documentElement;}
return document;};$prototype.parseRows=function(root){var buffer=[];var nodes=this.findRowNodes(root);this.matches=nodes.length;var start=0;var end=nodes.length;if(start>=0&&start<end){var node;for(var i=start;i<end;++i){node=nodes[i];buffer.push(new NodeWrapper(node));}}
return buffer;};$prototype.findRowNodes=function(root){var nodes=[];if(this.nodeNames||this.nodeNames.length>0){this.getChildrenByNames(root,nodes);}else{for(var i=0;i<this.depth;++i){if(!node)break;node=this.getNthChildNode(node,this.nodeOffset);}
if(node){nodes.push(node);}}
return nodes;};$prototype.getChildrenByNames=function(node,results){var child;var children=DOMUtils.getChildren(node);for(var i=0;i<children.length;++i){child=node.childNodes[i];if(child.nodeType!=1)continue;if(this.nodeNames.contains(DOMUtils.getName(child))){results.push(child);}else{this.getChildrenByNames(child,results);}}}
$prototype.getNthChildNode=function(root,n){var position=0;var children=root.childNodes;for(var i=0;i<children.length;++i){if(children[i].nodeType==1){if(position==n)return children[i];++position;}}
return null;};$prototype.onDocumentError=function(e){logError(e);this.loadCallback(null);};$prototype.dispose=function(){if(this.sourceListener){disconnect(this.sourceListener);this.sourceListener=null;}
this.loadCallback=null;this.errback=null;this.resource=null;userSmarts.wt.widgets.DOMTableModel.prototype.dispose.call(this);};namespace("userSmarts.pub");$namespace.AjaxDOMTreeModel=Class.create(userSmarts.wt.widgets.DOMTreeModel);$prototype.initialize=function(superClass,properties){properties=setdefault(properties,{resource:new userSmarts.pub.Resource({params:{format:"text/xml"}}),useAttributes:false});superClass.call(this,properties);this.sourceListener=connect(this,"source",this,this.onSourceChange)
this.loadCallback=bind(this.onDocumentLoad,this);this.errback=bind(this.onDocumentError,this);};$prototype.onSourceChange=function(event){this.resource.setURL(event.newValue);this.populate(0);};$prototype.setSource=function(url){this.resource.setURL(url);this.populate(0);};$prototype.onDocumentLoad=function(document){if(isXmlNode(document)){if(document.nodeType==9){this.root=document.documentElement;}else{this.root=document;}}else{this.root=null;}
this.setProperty("modified",true);};$prototype.onDocumentError=function(e){getLogger().logError(e);this.loadCallback(null);};$prototype.dispose=function(){if(this.sourceListener){disconnect(this.sourceListener);this.sourceListener=null;}
this.loadCallback=null;this.errback=null;this.resource=null;userSmarts.wt.widgets.DOMTreeModel.prototype.dispose.call(this);};namespace("userSmarts.pub");$namespace.AjaxJSONTableModel=Class.create(userSmarts.wt.widgets.TableModel);$prototype.initialize=function(superclass,properties){setdefault(properties,{resource:new userSmarts.pub.Resource({params:{format:"text/json"}}),matches:0,depth:0,nodeOffset:0,nodeNames:[]});superclass.call(this,properties);this.loadCallback=bind(this.onDocumentLoad,this);this.errback=bind(this.onDocumentError,this);this.sourceListener=connect(this,'source',this.onSourceChange);};$prototype.onSourceChange=function(event){if(this.resource){this.resource.setProperty("url",this.source);this.resource.params.format="text/json";}
this.populate(0);};$prototype.populate=function(position){if(position!==undefined&&position!==null&&(position>=0&&position<this.size())){this.currentRow=position*1;}
if(this.resource){var deferred=this.resource.get();deferred.addCallback(this.loadCallback);deferred.addErrback(this.errback);this.setProperty("populating",true);}else{this.loadCallback(null);}};$prototype.onDocumentLoad=function(jsonObj){this.buffer=[];this.matches=0;if(jsonObj){this.buffer=this.parseRows(jsonObj);}else{getLogger().logError("AjaxJSONTableModel.onDocumentLoad() - "+"Unable to populate model, response was null");}
this.setProperty("modified",true);};$prototype.parseRows=function(parent){var buffer=[];var nodes=this.findRowNodes(parent);this.matches=nodes.length;var start=0;var end=nodes.length;if(start>=0&&start<end){var node;for(var i=start;i<end;++i){node=nodes[i];buffer.push(node);}}
return buffer;};$prototype.findRowNodes=function(parent){var nodes=[];if(this.nodeNames||this.nodeNames.length>0){this.getChildrenByNames(parent,nodes);}
return nodes;};$prototype.getChildrenByNames=function(parent,results){var child;for(var k in parent){if(this.nodeNames.contains(k)){child=parent[k];results.push(child);}else{this.getChildrenByNames(child,results);}}}
$prototype.onDocumentError=function(e){getLogger().logError(e);this.loadCallback(null);};$prototype.dispose=function(){if(this.sourceListener){disconnect(this.sourceListener);this.sourceListener=null;}
this.loadCallback=null;this.errback=null;this.resource=null;userSmarts.wt.widgets.TableModel.prototype.dispose.call(this);};namespace("userSmarts.pub");$namespace.OpenSearchTableModel=Class.create(userSmarts.pub.AjaxDOMTableModel);$prototype.initialize=function(superClass,properties){properties=setdefault(properties,{sortElement:null,sortOrder:true,keywords:[]});superClass.call(this,properties);}
$prototype.populate=function(position){if(position!==undefined&&position!==null&&(position>=0&&position<this.size())){this.currentRow=position*1;}
if(this.resource){this.resource.setParameter("startIndex",this.getStartIndex());this.resource.setParameter("startPage",this.getStartPage());this.resource.setParameter("count",this.getPageSize());this.resource.setParameter("format","text/xml");this.resource.setParameter("q",this.getKeywords().toString(" "));this.resource.setParameter("useAnd",this.useAndOperator);var sortElement=this.getSortElement();var sortOrder=this.getSortOrder();if(sortElement&&typeof(sortOrder)!='undefined'){this.resource.setParameter("sortElement",sortElement);this.resource.setParameter("sortOrder",sortOrder);}else{this.resource.setParameter("sortElement","");this.resource.setParameter("sortOrder","");}
var deferred=this.resource.get();deferred.addCallback(this.loadCallback);this.setProperty("populating",true);}else{this.loadCallback(null);}};$prototype.parseRows=function(root){var buffer=userSmarts.pub.AjaxDOMTableModel.prototype.parseRows.call(this,root);this.matches=this.getOpenSearchResponseInfo(root,buffer.length);return buffer;};$prototype.getOpenSearchResponseInfo=function(root,fallback){return Coerce.toInteger(DOMUtils.getChildText(root,"totalResults"),0);};$prototype.getStartIndex=function(){return 0;};$prototype.getStartPage=function(){return Math.floor(this.getOffset()/this.getPageSize())+1;};$prototype.getSortElement=function(){return this.sortElement;};$prototype.setSortElement=function(name){this.sortElement=name;};$prototype.getSortOrder=function(){return this.sortOrder;};$prototype.setSortOrder=function(order){this.sortOrder=(order===true||order==="true");};$prototype.setKeywords=function(keywords){if(typeof(keywords.push)=='function'){this.keywords=keywords;this.populate(0);}else if(typeof(keywords)=='string'){this.keywords=[keywords];this.populate(0);}else{logWarning("Unrecognized keywords type - "+typeof(keywords)+" - ignoring keywords!");}};$prototype.getKeywords=function(){return this.keywords;};$prototype.sort=function(column){if(column){var sortElement=this.getSortElement();if(sortElement&&sortElement==column.name){column.order=!column.order;}
this.setSortOrder(column.order);this.setSortElement(column.name);}else{this.setSortElement("");}
this.populate(this.getOffset());};namespace("userSmarts.pub");$namespace.GeoOpenSearchTableModel=Class.create(userSmarts.pub.OpenSearchTableModel);$prototype.initialize=function(superClass,properties){properties=setdefault(properties,{bbox:null});superClass.call(this,properties);};$prototype.populate=function(position){if(this.resource){this.resource.params.bbox="";if(this.aoi){var points=this.aoi.getPoints();this.resource.params.bbox=points[0].x+","+points[0].y+","+points[1].x+","+points[1].y;}}
userSmarts.pub.OpenSearchTableModel.prototype.populate.call(this,position);};$prototype.parseRows=function(root){var buffer=userSmarts.pub.OpenSearchTableModel.prototype.parseRows.call(this,root);this.setProperty("bbox",this.getFeedBoundingBox(root));return buffer;};$prototype.getFeedBoundingBox=function(root){var bbox=null;var boxNodes=root.getElementsByTagName("box");if(boxNodes.length>1){var boxNode=boxNodes[0];if(boxNode){var boxStr=scrapeText(boxNode);if(boxStr){var coords=boxStr.split(" ");if(coords.length==4){bbox=new Geometry("Box");bbox.addPoint(new Point(coords[0],coords[1]));bbox.addPoint(new Point(coords[2],coords[3]));}}}}
return bbox;};$prototype.getBoundingBox=function(){return this.bbox;};$prototype.setAOI=function(aoi){if(aoi instanceof Geometry){if(aoi.getPoints().length>2){aoi=aoi.getEnvelope();}
this.aoi=aoi;this.populate(0);}};namespace("userSmarts.pub.atom");namespace("userSmarts.pub.atom");namespace("userSmarts.pub.atom");$namespace.Entry=function(properties){if(isPrototype(arguments)){return;}
properties=setdefault(properties,{links:{},extensionElements:[]});Bean.call(this,properties);};$namespace.Entry.inheritsFrom(Bean);$namespace.Entry.NAMESPACE_URI="http://www.w3.org/2005/Atom";$prototype.getId=function(){return this.getValue("id","id","");};$prototype.setId=function(id){this.id=id;};$prototype.getTitle=function(){return this.getValue("title","title","");};$prototype.setTitle=function(title){this.title=title;};$prototype.getSummary=function(){return this.getValue("summary","summary","");};$prototype.setSummary=function(summary){this.summary=summary;};$prototype.getContent=function(){return this.getElement("content","content",null);};$prototype.setContent=function(content){if(isXmlNode(content)){this.content=content;}};$prototype.getModified=function(){return this.getValue("modified","updated","");};$prototype.setModified=function(date){this.modified=date;};$prototype.getUpdated=function(){return this.getModified();};$prototype.setUpdated=function(date){this.setModified(date);};$prototype.getPublished=function(){return this.getValue("published","published","");};$prototype.setPublished=function(date){this.published=date;};$prototype.getAuthor=function(){if(!this.author&&this.node){var authorn=this.getFirstElement(this.node,"author",null);if(authorn){this.author=this.getFirstElementText(authorn,"authorName",null);}}
return this.author;};$prototype.setAuthor=function(author){this.author=author;};$prototype.getContributor=function(){if(!this.contributor&&this.node){var contribn=this.getFirstElement(this.node,"contributor",null);if(contribn){this.contributor=this.getFirstElementText(contribn,"authorName",null);}}
return this.contributor;};$prototype.setContributor=function(contrib){this.contributor=contrib;};$prototype.getLink=function(rel){rel=rel||"alternate";if(!this.links[rel]&&this.node){var linkNode;var linkRel;var nodes=this.node.getElementsByTagName("link");for(var i=0;i<nodes.length;i++){linkNode=nodes[i];linkRel=getNodeAttribute(linkNode,"rel","alternate");if(!this.links[linkRel]){this.links[linkRel]=getNodeAttribute(linkNode,"href");}}}
return this.links[rel];};$prototype.getLinkAttr=function(rel,attrName){rel=rel||"alternate";if(this.node){var linkNode;var linkRel;var nodes=this.node.getElementsByTagName("link");for(var i=0;i<nodes.length;i++){linkNode=nodes[i];linkRel=getNodeAttribute(linkNode,"rel","alternate");if(linkRel==rel){return getNodeAttribute(linkNode,attrName);}}}
return null;};$prototype.getLinks=function(){this.getLink();return this.links;};$prototype.setLink=function(rel,href){if(rel){this.links[rel]=href;}};$prototype.getCategories=function(){if(this.categories==null){var results=[];var nodes=DOMUtils.getChildren(this.node,"category");for(var i=0;i<nodes.length;++i){results.push(scrapeText(nodes[i]));}
this.categories=results;}
return this.categories||[];};$prototype.isDraft=function(){if(typeof(this.draft)=='undefined'){var node=DOMUtils.getChild(this.node,"control");if(node){this.draft=Coerce.toBoolean(DOMUtils.getChildText(node,"draft"),true);}else{this.draft=true;}}
return this.draft;};$prototype.setDraft=function(draft){this.draft=Coerce.toBoolean(draft,true);};$prototype.getFirstElement=function(node,tagName,fallback){var value=fallback;var nodes=node.getElementsByTagName(tagName);if(nodes.length>0&&nodes[0].firstChild){value=nodes[0];}
return value;}
$prototype.getFirstElementText=function(node,tagName,fallback){var value=fallback;var nodes=node.getElementsByTagName(tagName);if(nodes.length>0&&nodes[0].firstChild){value=nodes[0].firstChild.nodeValue;}
return value;};$prototype.getElementsText=function(node,tagName){var values=[];var nodes=node.getElementsByTagName(tagName);for(var i=0;i<nodes.length;++i){values.push(scrapeText(nodes[i]));}
return values;};$prototype.getValue=function(varName,tagName,fallback,format){var value=this[varName];if(!value&&this.node){value=this[varName]=this.getFirstElementText(this.node,tagName,fallback);}
if(value&&format){value=format.parseObject(value);}
return value;};$prototype.getValues=function(varName,tagName){var results=this[varName];if((!results||typeof(results.push)=='undefined')&&this.node){results=this[varName]=this.getElementsText(this.node,tagName);}
return results;};$prototype.getElement=function(varName,tagName,fallback){var value=this[varName];if(!value&&this.node){value=this[varName]=this.getFirstElement(this.node,tagName,fallback);}
return value;};$prototype.appendElementWithText=function(parent,uri,local,text){if(uri&&local&&text){var doc=parent.ownerDocument;var node=createElementNS(uri,local,doc);parent.appendChild(node);node.appendChild(doc.createTextNode(text));return node;}
return null;};$prototype.appendElementWithChild=function(parent,uri,local,child){if(uri&&local&&child&&isXmlNode(child)){var doc=parent.ownerDocument;var node=createElementNS(uri,local,doc);parent.appendChild(node);if(typeof(doc.importNode)=='function'){node.appendChild(doc.importNode(child,true));}else{node.appendChild(child);}
return node;}
return null;};$prototype.appendElementWithAttributes=function(parent,uri,local,attrs){if(uri&&local){var doc=parent.ownerDocument;var node=createElementNS(uri,local,doc);parent.appendChild(node);if(attrs){for(var i=0;i<attrs.length;++i){setNodeAttribute(node,attrs[i].name,attrs[i].value);}}
return node;}
return null;};$prototype.checkExtension=function(ns,tagName){if(ns==userSmarts.pub.atom.Entry.NAMESPACE_URI){if(tagName=="id"){this.setId(value);return false;}else if(tagName=="title"){this.setTitle(value);return false;}else if(tagName=="summary"){this.setSummary(value);return false;}else if(tagName=="updated"){this.setUpdated(value);return false;}else if(tagName=="published"){this.setPublished(value);return false;}else if(tagName=="author"){this.setAuthor(value);return false;}else if(tagName=="content"){this.setContent(value);return false;}}
return true;};$prototype.setValue=function(tagName,value,ns,format){if(!ns){ns=userSmarts.pub.atom.Entry.NAMESPACE_URI;}
if(!this.checkExtension(ns,tagName))return;var key="{"+ns+"#}"+tagName;if(!this[key]){var param={namespaceURI:ns,localPart:tagName};this.extensionElements.push(param);}
if(value&&format){value=format.format(value);}
this[key]=value;};$prototype.toXml=function(doc){var ns=userSmarts.pub.atom.Entry.NAMESPACE_URI;if(!doc||doc.nodeType!=9){doc=createXMLDocument('entry',ns,null);}else{doc.appendChild(createElementNS(ns,'entry',doc));}
var entry=doc.documentElement;this.appendElementWithText(entry,ns,"id",this.getId());this.appendElementWithText(entry,ns,"title",this.getTitle());this.appendElementWithText(entry,ns,"summary",this.getSummary());this.appendElementWithText(entry,ns,"updated",this.getUpdated());this.appendElementWithText(entry,ns,"published",this.getPublished());var author=this.getAuthor();if(author){var authore=createElementNS(ns,"author",doc);entry.appendChild(authore);this.appendElementWithText(authore,ns,"authorName",author);}
var contributor=this.getContributor();if(contributor){var contribe=createElementNS(ns,"contributor",doc);entry.appendChild(contribe);this.appendElementWithText(contribe,ns,"authorName",contributor);}
var draft=this.isDraft();if(!draft){var controle=createElementNS('http://www.w3.org/2007/app',"control",doc);entry.appendChild(controle);this.appendElementWithText(controle,'http://www.w3.org/2007/app',"draft","no");}
this.appendElementWithChild(entry,ns,"content",this.getContent());for(var i=0;i<this.extensionElements.length;++i){this.appendExtensionElement(entry,this.extensionElements[i]);}
return entry;};$prototype.appendExtensionElement=function(entry,extension){if(extension){var key="{"+extension.namespaceURI+"#}"+extension.localPart;var value=this[key];if(value){if(isXmlNode(value)&&value.nodeType!=9){this.appendElementWithChild(entry,extension.namespaceURI,extension.localPart,value);}else if(typeof(value)=="string"){this.appendElementWithText(entry,extension.namespaceURI,extension.localPart,value);}else if(typeof(value)=="number"){this.appendElementWithText(entry,extension.namespaceURI,extension.localPart,value+"");}else if(typeof(value.toString)=="function"){this.appendElementWithText(entry,extension.namespaceURI,extension.localPart,value.toString());}}}};namespace("userSmarts.pub.atom");$namespace.Entry2=Class.create(userSmarts.pub.Resource);$prototype.initialize=function(superClass,properties){properties=setdefault(properties,{id:null,title:null,updated:null,author:null,content:null,summary:null,links:{},categories:[],contributor:null,published:null,source:null,rights:null,categoryTerms:[],extensions:{},contentType:null,collection:null,loaded:false,modified:false,stale:false,disposed:false});superClass.call(this,properties);this.retrievedCallback=bind(this.onRetrieved,this);this.updatedCallback=bind(this.onUpdated,this);this.deletedCallback=bind(this.onDeleted,this);this.listener=connect(this,"*",this,this.onPropertyModified);if(this.node){this.parse();}};$namespace.Entry2.ATOM_NS_URI="http://www.w3.org/2005/Atom";$namespace.Entry2.APP_NS_URI="http://www.w3.org/2007/app";$prototype.getId=function(){return this.id;};$prototype.setId=function(value){this.id=value;this.modified=true;};$prototype.getTitle=function(){return this.title;};$prototype.setTitle=function(value){this.title=value;this.modified=true;};$prototype.getUpdated=function(){return this.updated;};$prototype.setUpdated=function(value){this.updated=value;this.modified=true;};$prototype.getAuthor=function(){return this.author;};$prototype.setAuthor=function(value){this.author=value;this.modified=true;};$prototype.getContent=function(){return this.content;};$prototype.setContent=function(value){this.content=value;this.modified=true;};$prototype.getContentType=function(){return this.contentType;};$prototype.setContentType=function(value){this.contentType=value;this.modified=true;};$prototype.getSummary=function(){return this.summary;};$prototype.setSummary=function(value){this.summary=value;this.modified=true;};$prototype.getLinks=function(){return this.links;};$prototype.getLink=function(rel){rel=rel||"alternate";return this.links[rel];};$prototype.setLink=function(rel,value){rel=rel||"alternate";this.links[rel]=value;this.modified=true;};$prototype.getCategories=function(){return this.categories;};$prototype.getCategoryTerms=function(){return this.categoryTerms;};$prototype.getCategory=function(term){for(var c=0;c<this.categories.length;++c){if(this.categories[c].term=term){return this.categories[c];}}
return null;};$prototype.setCategory=function(term,scheme,label){var category=this.getCategory(term);if(category){category.term=term;category.scheme=scheme;category.label=label;}else{this.categories.push({term:term,scheme:scheme,label:label});this.categoryTerms.push(term);}
this.modified=true;};$prototype.getContributor=function(){return this.contributor;};$prototype.setContributor=function(value){this.contributor=value;this.modified=true;};$prototype.getPublished=function(){return this.published;};$prototype.setPublished=function(value){this.published=value;this.modified=true;};$prototype.getSource=function(){return this.source;};$prototype.setSource=function(value){this.source=value;this.modified=true;};$prototype.getRights=function(){return this.rights;};$prototype.setRights=function(value){this.rights=value;this.modified=true;};$prototype.getIcon=function(){return this.icon;};$prototype.setIcon=function(iconUrl){this.icon=iconUrl;};$prototype.getExtensions=function(){return this.extensions;};$prototype.getExtension=function(name){return this.extensions[name];};$prototype.setExtension=function(name,value,ns){var extension=this.getExtension(name);if(extension){extension.value=value;if(ns)extension.uri=ns;}else{this.extensions[name]={value:value,uri:ns};}
this.modified=true;};$prototype.equals=function(arg){if(arg&&arg instanceof userSmarts.pub.atom.Entry2){return this.getId()==arg.getId();}
return false;};$prototype.getCollection=function(){return this.collection;};$prototype.isLoaded=function(){return this.loaded;};$prototype.isStale=function(){return this.stale;};$prototype.isModified=function(){return this.modified;};$prototype.isDisposed=function(){return this.disposed;};$prototype.dispose=function(){if(this.isDisposed())return;this.title=this.updated=null;this.author=this.content=this.summary=null;this.links={};this.categories={};this.contributor=this.published=this.source=this.rights=null;this.contentType=null;this.extensions={};this.node=null;disconnect(this.listener);this.listener=null;this.retrievedCallback=null;this.updatedCallback=null;this.deferred=null;this.loaded=false;this.modified=false;this.stale=false;userSmarts.pub.Resource.prototype.dispose.call(this);this.disposed=true;};$prototype.getPOSTUrl=function(){return this.url||this.getLink("edit")||this.getLink();};$prototype.getPUTUrl=function(){return this.url||this.getLink("edit")||this.getLink();};$prototype.getDELUrl=function(){return this.url||this.getLink("edit")||this.getLink();};$prototype.get=function(){var deferred=new Deferred();var msg=this.checkForRequirements();if(msg){deferred.errback(msg);}else{this.deferred=deferred;var d=userSmarts.pub.Resource.prototype.get.call(this);d.addCallback(this.retrievedCallback);d.addErrback(handleResponseError);}
return deferred;};$prototype.put=function(){var deferred=new Deferred();var msg=this.checkForRequirements();if(msg){deferred.errback(msg);}else{this.deferred=deferred;var d=userSmarts.pub.Resource.prototype.put.call(this,this.toXml());d.addCallback(this.updatedCallback);d.addErrback(handleResponseError);}
return deferred;};$prototype.del=function(){var deferred=new Deferred();var msg=this.checkForRequirements();if(msg){deferred.errback(msg);}else{this.deferred=deferred;var d=userSmarts.pub.Resource.prototype.del.call(this);d.addCallback(this.deletedCallback);d.addErrback(handleResponseError);}
return deferred;};$prototype.post=function(entry){var deferred=new Deferred();deferred.errback("Method not allowed for collections.  "+"Collections may only be altered by adding or removing entries");return deferred;};$prototype.checkForRequirements=function(){if(!this.url){if(this.isLoaded()){var link=this.getLink();if(link){this.url=link;return null;}}
return"No url specified";}
return null;};$prototype.onRetrieved=function(xml){if(isXmlNode(xml)){var root=xml.documentElement;this.parse(root);}else if(xml){this.parse(xml);}else{this.deferred.errback("Unable to parse response from server");this.deferred=null;return;}
this.deferred.callback(this);return;};$prototype.onUpdated=function(response){var xml=response.responseXML;if(xml){var root=xml.documentElement;if(root){this.parse(root);this.deferred.callback(this);return;}}
this.deferred.errback("Unable to parse response from server");this.deferred=null;};$prototype.onDeleted=function(response){this.deferred.callback(true);this.deferred=null;this.dispose();};$prototype.onPropertyModified=function(event){var property=event.propertyName;var value=event.newValue;this.modified=true;};$prototype.parse=function(node){if(!node){node=this.node;}else{this.node=node;}
this.id=this.title=this.updated=null;this.author=this.content=this.summary=null;this.links={};this.categories={};this.contributor=this.published=this.source=this.rights=null;this.contentType=null;this.icon=null;this.extensions={};if(isXmlNode(node)){var element;var elements=DOMUtils.getChildren(node);for(var e=0;e<elements.length;++e){element=elements[e];this.updateValueFromElement(element);}}else if(node){for(var k in node){this.updateValueFromJSONObj(k,node[k]);}}
this.loaded=true;this.stale=false;this.modified=false;};$prototype.updateValueFromElement=function(node){if(!isXmlNode(node)||node.nodeType!=1)return;var name=DOMUtils.getName(node,true);if(!name)return;var ns=getNodeAttribute(node,"xmlns");if("id"==name||"title"==name||"updated"==name||"summary"==name||"published"==name||"rights"==name||"icon"==name){this[name]=scrapeText(node);}else if("author"==name||"contributor"==name){var child=DOMUtils.getChild(node,"name");this[name]=scrapeText(child);}else if("link"==name){var rel=getNodeAttribute(node,"rel")||"alternate";var href=getNodeAttribute(node,"href");this.links[rel]=href;if(!this.url&&rel=="alternate"){this.url=href;}}else if("category"==name){var term=getNodeAttribute(node,"term");var scheme=getNodeAttribute(node,"scheme");var label=getNodeAttribute(node,"label");this.categories[term]={term:term,scheme:scheme,label:label};}else if("content"==name){this.parseContentNode(node);}else if("source"==name){}else{var content=null;var firstElementChild=DOMUtils.getFirstChildOfType(node,1);if(firstElementChild){content=node;}else{content=scrapeText(node);}
this.extensions[name]={value:content,uri:ns,attrs:[]};}};$prototype.updateValueFromJSONObj=function(name,value){if("id"==name||"title"==name||"updated"==name||"summary"==name||"published"==name||"rights"==name||"icon"==name||"category"==name){this[name]=value;}else if("author"==name||"contributor"==name){value=value.name;this[name]=value;}else if("links"==name&&value&&typeof(value.push)!="undefined"){for(var i=0;i<value.length;++i){this.updateValueFromJSONObj("link",value[i])}}else if("link"==name){var rel=value.rel||"alternate";var href=value.href;this.links[rel]=href;if(!this.url&&rel=="alternate"){this.url=href;}}else if("categories"==name&&value&&typeof(value.push)!="undefined"){for(var i=0;i<value.length;++i){this.updateValueFromJSONObj("category",value[i]);}}else if("content"==name){var type=value.type||"text";type=type.toLowerCase();this.contentType=type;if(type.indexOf("xml")>=0||type.indexOf("html")>=0){this.content=value.value;}}else if("source"==name){}else{this.extensions[name]={value:value,uri:"",attrs:[]};}};$prototype.parseContentNode=function(node){var type=getNodeAttribute(node,"type");if(!type){var children=DOMUtils.getChildren(node);if(children.length==1){if(children[0].nodeType==3){this.contentType="text";this.content=scrapeText(node);}else if(children[0].nodeType==1){this.contentType="xml";this.content=children[0];}}else if(children.length>0){var childNodes=[];for(var i=0;i<children.length;++i){if(children[i].nodeType==1){childNodes.push(children[i]);}}
this.contentType="xml";if(childNodes.length>1){this.content=childNodes;}else if(childNodes.length==1){this.content=childNodes[0];}}}else{type=type.toLowerCase();this.contentType=type;if(type.indexOf("xml")>=0||type.indexOf("html")>=0){var children=DOMUtils.getChildren(node);if(children.length==1){if(children[0].nodeType==3){this.contentType="text";this.content=scrapeText(node);}else if(children[0].nodeType==1){this.contentType="xml";this.content=children[0];}}else if(children.length>0){var childNodes=[];for(var i=0;i<children.length;++i){if(children[i].nodeType==1){childNodes.push(children[i]);}}
if(childNodes.length>1){this.content=childNodes;}else if(childNodes.length==1){this.content=childNodes[0];}}}else{this.content=scrapeText(node);}}}
$prototype.toXml=function(doc){var atomNS=userSmarts.pub.atom.Entry2.ATOM_NS_URI;var appNS=userSmarts.pub.atom.Entry2.APP_NS_URI;if(!doc||doc.nodeType!=9){doc=createXMLDocument('entry',atomNS,null);}else{doc.appendChild(createElementNS(atomNS,'entry',doc));}
var entry=doc.documentElement;this.appendElement(entry,"id",this.getId()||"",atomNS);this.appendElement(entry,"title",this.getTitle()||"",atomNS);this.appendElement(entry,"updated",this.getUpdated()||"",atomNS);this.appendElement(entry,"author/name",this.getAuthor(),atomNS);this.appendElement(entry,"summary",this.getSummary(),atomNS);for(var rel in this.getLinks()){this.appendElementWithAttributes(entry,"link",{rel:rel,href:this.getLink(rel)},atomNS);}
var content=this.appendElement(entry,"content",this.getContent(),atomNS);if(content){setNodeAttribute(content,"type",this.getContentType());}
this.appendElement(entry,"published",this.getPublished(),atomNS);this.appendElement(entry,"contributor/name",this.getContributor(),atomNS);this.appendElement(entry,"rights",this.getRights(),atomNS);var categories=this.getCategories();for(var c=0;c<categories.length;++c){this.appendElementWithAttributes(entry,"category",categories[c],atomNS);}
if(this.getIcon()){this.appendElement(entry,"icon",this.getIcon(),atomNS);}
var extensions=this.getExtensions();var extension;var elem;for(var ext in extensions){extension=this.getExtension(ext);elem=this.appendElement(entry,ext,extension.value,extension.uri);for(var a in extension.attrs){var atype=typeof(extension.attrs[a]);if(atype=="string"||atype=="number"){setNodeAttribute(elem,a,extension.attrs[a]);}}}
return entry;};$prototype.appendElement=function(parentNode,tagName,content,uri){if(!parentNode||!tagName||!content)return null;uri=uri||userSmarts.pub.atom.Entry2.ATOM_NS_URI;var doc=parentNode.ownerDocument;var nodeNames=tagName.split("/");var node;var parent=parentNode;for(var n=0;n<nodeNames.length;++n){node=createElementNS(uri,nodeNames[n],doc);parent.appendChild(node);parent=node;}
if(isXmlNode(content)){var children=DOMUtils.getChildren(content);for(var c=0;c<children.length;++c){node.appendChild(children[c]);}}else{var type=typeof(content.push);if(type=="function"){var values=[];for(var c=0;c<content.length;++c){if(isXmlNode(content[c])){node.appendChild(content[c]);}else if(type=="string"||type=="number"||type=="boolean"){values.push((c>0?",":"")+content[c]);}}}else{type=typeof(content);if(type=="string"||type=="number"||type=="boolean"){node.appendChild(doc.createTextNode(content+""));}}}
return node;};$prototype.appendElementWithAttributes=function(parentNode,tagName,attrs,uri){if(!parentNode||!tagName||!attrs)return null;uri=uri||userSmarts.pub.atom.Entry2.ATOM_NS_URI;var doc=parentNode.ownerDocument;var nodeNames=tagName.split("/");var node;var parent=parentNode;for(var n=0;n<nodeNames.length;++n){node=createElementNS(uri,nodeNames[n],doc);parent.appendChild(node);parent=node;}
if(typeof(attrs.push)=="function"){for(var i=0;i<attrs.length;++i){setNodeAttribute(node,attrs[i].name,attrs[i].value);}}else{var v;for(var a in attrs){v=attrs[a];if(v){setNodeAttribute(node,a,v);}}}
return node;};namespace("userSmarts.pub.atom");$namespace.GeoEntry=Class.create(userSmarts.pub.atom.Entry2);$prototype.initialize=function(superClass,properties){superClass.call(this,properties);};$prototype.getWhereType=function(){var result=null;var geometry=this.getWhere();if(geometry){result=geometry.getType();}
return result;};$prototype.getWhere=function(){if(!this.geometry&&this.node){this.geometry=new GeoRSS().parseObject(this.node);}
return this.geometry;};$prototype.setWhere=function(geometry){this.geometry=geometry;};$prototype.setGeometry=function(geometry){this.setWhere(geometry);};$prototype.toXml=function(doc){var entry=userSmarts.pub.atom.Entry2.prototype.toXml.call(this,doc);if(entry){if(this.geometry){new GeoRSS().format(this.geometry,entry);}}
return entry;};namespace("userSmarts.pub.atom");$namespace.DefaultEntryFactory=Class.create();$prototype.initialize=function(superClass,properties){setdefault(this,properties);};$prototype.createEntry=function(entryNode,collection){if(this.entryClass){return newInstance(this.entryClass,{node:entryNode,collection:collection});}else{return new userSmarts.pub.atom.Entry2({node:entryNode,collection:collection});}};namespace("userSmarts.pub.atom");$namespace.Service=Class.create(userSmarts.pub.Resource);$prototype.initialize=function(superClass,properties){superClass.call(this,properties);this.retrievedCallback=bind(this.onRetrieved,this);this.workspaces=[];};$prototype.getWorkspace=function(arg){if(typeof(arg)=="number"){return this.workspaces[arg];}
return null;};$prototype.get=function(){var deferred=new Deferred();var msg=this.checkForRequirements();if(msg){deferred.errback(msg);}else{var d=userSmarts.pub.Resource.prototype.get.call(this);d.addCallback(this.retrievedCallback);d.addErrback(handleResponseError);this.deferred=deferred;}
return deferred;};$prototype.onRetrieved=function(xml){var root=xml.documentElement;if(root){this.workspaces=[];var wnode;var workspace;var wses=DOMUtils.getChildren(root,"workspace");for(var e=0;e<wses.length;++e){wnode=wses[e];workspace=userSmarts.pub.atom.Workspace({node:wnode});if(workspace){this.workspaces.push(workspace);}}
this.deferred.callback(this);}
this.deferred.errback("Missing root element in service document");};$prototype.checkForRequirements=function(){if(!this.url){return"No url specified";}
return null;};$prototype.dispose=function(){for(var w=0;w<this.workspaces.length;++w){this.workspaces[w].dispose();}
this.workspaces=[];userSmarts.pub.Resource.prototype.dispose.call(this);};namespace("userSmarts.pub.atom");$namespace.Workspace=Class.create(Bean);$prototype.initialize=function(superClass,properties){properties=setdefault(properties,{collections:[]});superClass.call(this,properties);if(this.node){this.parse();this.node=null;}};$prototype.getCollection=function(arg){if(typeof(arg)=="string"){return this.collections[arg];}
return null;};$prototype.parse=function(){if(node){this.collections=[];var cnode;var title;var href;var cols=DOMUtils.getChildren(this.node,"collection");for(var e=0;e<cols.length;++e){cnode=cols[e];title=DOMUtils.getChildText(cnode,"title","UNKNOWN");href=getNodeAttribute(cnode,'href');this.collections[title]=new userSmarts.pub.atom.Collection({url:href,title:title});}}};$prototype.dispose=function(){for(var c=0;c<this.collections.length;++c){this.collections[c].dispose();}
this.collections=[];Bean.prototype.dispose.call(this);};namespace("userSmarts.pub.atom");$namespace.Collection=Class.create(userSmarts.pub.Resource);$prototype.initialize=function(superClass,properties){properties=setdefault(properties,{url:null,title:"",updated:null,author:null,link:null,categories:[],contributor:null,icon:null,logo:null,rights:null,generator:null,subtitle:null,entries:[],stale:false,loaded:false,factory:new userSmarts.pub.atom.DefaultEntryFactory(),params:{format:"text/xml"}});superClass.call(this,properties);this.retrievedCallback=bind(this.onRetrieved,this);this.createdCallback=bind(this.onCreated,this);this.errback=bind(this.onError,this);if(this.autoLoad){this.get();}};$prototype.isStale=function(){return stale;};$prototype.setStale=function(stale){this.stale=(stale==true);};$prototype.getTitle=function(){return this.title;};$prototype.getId=function(){return this.id;};$prototype.getUpdated=function(){return this.updated;};$prototype.getSubtitle=function(){return this.subtitle;};$prototype.getAuthor=function(){return this.author;};$prototype.getContributor=function(){return this.contributor;};$prototype.getLink=function(rel){rel=rel||"alternate";return this.links[rel];};$prototype.getIcon=function(){return this.icon;};$prototype.getLogo=function(){return this.logo;};$prototype.getRights=function(){return this.rights;};$prototype.getCategories=function(){return this.categories;};$prototype.hasCategory=function(category){if(!category)return false;for(var c=0;c<this.categories.length;++c){if(this.categories[c]==category){return true;}}
return false;};$prototype.isLoaded=function(){return!this.stale&&this.loaded;};$prototype.getSize=function(){return this.entries.length;};$prototype.getEntry=function(arg){if(typeof(arg)=="number"){return this.entries[arg];}else if(typeof(arg)=="string"){for(var ci=0;ci<this.entries.length;++ci){if(this.entries[ci].getId()==arg){return this.entries[ci];}}}
return null;};$prototype.getEntries=function(){return this.entries;};$prototype.removeEntry=function(arg){var index=-1;if(typeof(arg)=="number"){if(this.entries[arg]){index=arg;}}else if(typeof(arg)=="string"){for(var ci=0;ci<this.entries.length;++ci){if(this.entries[ci].getId()==arg){index=ci;break;}}}else{for(var ci=0;ci<this.entries.length;++ci){if(this.entries[ci]==arg){index=ci;break;}}}
if(index>=0){this.entries[index].collection=null;this.entries.splice(index,1);}};$prototype.removeAllEntries=function(){var entries=this.getEntries();var len=entries.length;for(var i=0;i<len;++i){entries.pop().dispose();}};$prototype.filter=function(args){var result=new userSmarts.pub.atom.Collection({url:this.url,title:title,params:args});return result;};$prototype.setStartPage=function(value){this.params.startPage=value;};$prototype.setStartIndex=function(value){this.params.startIndex=value;};$prototype.setCount=function(value){this.params.count=value;};$prototype.get=function(){return this.load();};$prototype.load=function(){var deferred=new Deferred();var msg=this.checkForRequirements();if(msg){deferred.errback(msg);}else{if(!this.loading){this.loading=true;var d=userSmarts.pub.Resource.prototype.get.call(this);d.addCallback(this.retrievedCallback);d.addErrback(handleResponseError);this.deferred=deferred;}}
return deferred;};$prototype.put=function(){var deferred=new Deferred();deferred.errback("Method not allowed for collections.  "+"Collections may only be altered by adding or removing entries");return deferred;};$prototype.add=function(entry){var deferred=new Deferred();var msg=this.checkForRequirements();if(msg){deferred.errback(msg);}else if(!entry){deferred.errback("Must provide a valid entry to post to the collection");}else{this.deferred=deferred;var xml=entry.toXml();var d=this.post(xml);d.addCallback(this.createdCallback);d.addErrback(handleResponseError);}
return deferred;};$prototype.onError=function(e){this.loading=false;this.loaded=false;handleResponseError(e);if(this.deferred){this.deferred.errback(e);this.deferred=null;}};$prototype.onRetrieved=function(xml){var len=this.entries.length;while(len>0){this.entries.pop().dispose();len=this.entries.length;}
this.entries=[];if(isXmlNode(xml)){this.parseXML(xml.documentElement);}else if(xml){this.parseJSON(xml);}
this.stale=false;this.loaded=true;this.loading=false;if(this.deferred){this.deferred.callback(this);this.deferred=null;}};$prototype.parseXML=function(root){if(root){this.updateFromChildValue(root,"id");this.updateFromChildValue(root,"title");this.updateFromChildValue(root,"subtitle");this.updateFromChildValue(DOMUtils.getChild(root,"author"),"name","author");this.updateFromChildValue(DOMUtils.getChild(root,"contributor"),"name","contributor");this.updateFromChildValue(root,"updated");this.updateFromChildrenValues(root,"category","categories");this.updateFromChildValue(root,"icon");this.updateFromChildValue(root,"logo");this.updateFromChildValue(root,"rights");this.links=[];var rel;var links=DOMUtils.getChildren(root,"link");for(var l=0;l<links.length;++l){rel=getNodeAttribute(links[l],"rel")||"alternate";this.links[rel]=getNodeAttribute(links[l],"href");}
var entries=DOMUtils.getChildren(root,"entry");for(var ei=0;ei<entries.length;++ei){var enode=entries[ei];var entry=this.createEntry(enode);if(entry)this.entries.push(entry);}}};$prototype.updateFromChildValue=function(parentNode,tagName,localName){if(!parentNode||!tagName)return;if(!localName){localName=tagName;}
var value=DOMUtils.getChildText(parentNode,tagName);if(value)this[localName]=value;};$prototype.updateFromChildrenValues=function(parentNode,tagName,localName){if(!parentNode||!tagName)return;if(!localName){localName=tagName;}
var results=[];var children=DOMUtils.getChildren(parentNode,tagName);for(var c=0;c<children.length;++c){results.push(scrapeText(children[c]));}
this[localName]=results;};$prototype.parseJSON=function(jsonObj){if(jsonObj){this.updateFromValue("id",jsonObj.id);this.updateFromValue("title",jsonObj.title);this.updateFromValue("subtitle",jsonObj.subtitle);this.updateFromValue("author",(jsonObj.author?jsonObj.author.name:null));this.updateFromValue("contributor",(jsonObj.contributor?jsonObj.contributor.name:null));this.updateFromValue("updated",jsonObj.updated);this.updateFromValue("icon",jsonObj.icon);this.updateFromValue("logo",jsonObj.logo);this.updateFromValue("rights",jsonObj.rights);this.links=[];var rel;var links=jsonObj.links;if(links&&typeof(links.push)!="undefined"){for(var l=0;l<links.length;++l){rel=links[l].rel||"alternate";this.links[rel]=links[l].href;}}
var entries=jsonObj.entries;for(var ei=0;ei<entries.length;++ei){var enode=entries[ei];var entry=this.createEntry(enode);if(entry)this.entries.push(entry);}}};$prototype.updateFromValue=function(localName,value){if(!localName)return;this[localName]=value;};$prototype.onCreated=function(response){var xml=response.responseXML;if(xml){var root=xml.documentElement;if(root){var entry=this.createEntry(root);this.entries.push(entry);if(this.deferred){this.deferred.callback(entry);}
return;}}
this.deferred.errback("Unable to parse response from server");this.deferred=null;};$prototype.createEntry=function(entryNode){return this.factory.createEntry(entryNode,this);};$prototype.checkForRequirements=function(){if(!this.url){return"No url specified";}
return null;};$prototype.dispose=function(){for(var e=0;e<this.entries.length;++e){this.entries[e].dispose();}
this.entries=[];if(this.deferred){this.deferred=null;}
userSmarts.pub.Resource.prototype.dispose.call(this);};namespace("userSmarts.pub.atom");$namespace.PagingCollection=Class.create(userSmarts.pub.atom.Collection);$prototype.initialize=function(superClass,properties){properties=setdefault(properties,{params:{startIndex:0,startPage:1,count:9999,format:"text/xml"}});superClass.call(this,properties);};$prototype.getSize=function(){return this.totalResults;};$prototype.setStartPage=function(value){this.params.startPage=value;};$prototype.setStartIndex=function(value){this.params.startIndex=value;};$prototype.setCount=function(value){this.params.count=value;};$prototype.parseXML=function(root){if(root){var results=DOMUtils.getChildText(root,"totalResults");this.totalResults=Coerce.toInteger(results,0);}
userSmarts.pub.atom.Collection.prototype.parseXML.call(this,root);this.totalResults=Math.max(this.totalResults,this.entries.length);};$prototype.parseJSON=function(jsonObj){if(jsonObj){var results=jsonObj["totalResults"];this.totalResults=Coerce.toInteger(results,0);}
userSmarts.pub.atom.Collection.prototype.parseJSON.call(this,jsonObj);this.totalResults=Math.max(this.totalResults,this.entries.length);};namespace("userSmarts.pub.atom");$namespace.GeoCollection=Class.create(userSmarts.pub.atom.PagingCollection);$prototype.initialize=function(superClass,properties){properties=setdefault(properties,{factory:new userSmarts.pub.atom.DefaultEntryFactory({entryClass:"userSmarts.pub.atom.GeoEntry"})});superClass.call(this,properties);};$prototype.getWhere=function(){return this.geometry;};$prototype.setWhere=function(geometry){this.geometry=geometry;};$prototype.getEnvelope=function(){if(this.geometry instanceof Geometry){return this.geometry.getEnvelope();}
return null;};$prototype.parseXML=function(root){if(root){var geometry=new GeoRSS().parseObject(root);if(geometry){this.geometry=geometry;}}
userSmarts.pub.atom.PagingCollection.prototype.parseXML.call(this,root);};$prototype.parseJSON=function(jsonObj){if(jsonObj){var geometry=new GeoRSS().parseObject(jsonObj);if(geometry){this.geometry=geometry;}}
userSmarts.pub.atom.PagingCollection.prototype.parseJSON.call(this,jsonObj);};namespace("userSmarts.pub.atom");$namespace.FeedModel=Class.create(userSmarts.pub.OpenSearchTableModel);$prototype.initialize=function(superClass,properties){properties=setdefault(properties,{keywords:[]});superClass.call(this,properties);this.loadCallback=bind(this.onLoaded,this);this.errback=bind(this.onError,this);this.sourceListener=connect(this,'source',this.onSourceChange);};$prototype.setURL=function(url){this.source=url;this.onSourceChange();};$prototype.setSource=function(arg){if(typeof(arg)=="string"){this.setURL(arg);}else if(arg instanceof userSmarts.pub.atom.Collection){this.collection=arg;}};$prototype.onSourceChange=function(event){if(this.source){if(!this.collection){this.collection=new userSmarts.pub.atom.PagingCollection({url:this.source});}else{this.collection.url=this.source;}
this.populate(0);}};$prototype.updateCollectionParameters=function(params){if(this.collection){for(var k in params){this.collection.params[k]=params[k];}}};$prototype.setCollectionParameters=function(params){this.collection.params=params;};$prototype.setCollectionParameter=function(property,value){this.collection.setParameter(property,value);};$prototype.getCollectionParameter=function(property){return this.collection.getParameter(property);};$prototype.addColumn=function(column){if(!this.columns)this.columns=[];this.columns.push(column);};$prototype.getLabel=function(column,row){return column.getLabel(row);};$prototype.getClassName=function(column,row){return"entry-table-cell";};$prototype.getColumnLabel=function(column,row){return column.getColumnLabel();};$prototype.getColumnClassName=function(column,row){return"entry-table-column";};$prototype.getColumns=function(){return this.columns;};$prototype.getImage=function(column,row){var result=null;var iconURL=row.getIcon();if(iconURL){if(typeof(iconURL)=="string"){var theme=userSmarts.runtime.Platform.getTheme();result=theme?theme.getImage(iconURL):null;if(!result){result=IMG({src:iconURL,width:16,height:16});}}else{result=iconURL;}}
return result;};$prototype.getRows=function(){var result=null;if(this.collection&&this.collection.isLoaded()){if(this.collection instanceof userSmarts.pub.atom.PagingCollection){result=this.collection.getEntries();}else{result=this.collection.getEntries().subset(this.currentRow,this.currentRow+this.pageSize);}}else{result=[];}
return result;};$prototype.size=function(){if(this.collection&&this.collection.isLoaded()){return this.collection.getSize();}
return 0;};$prototype.populate=function(position){if(position!==undefined&&position!==null&&(position>=0&&position<this.size())){this.currentRow=position*1;}
if(this.collection&&this.collection.getURL()){if(this.collection instanceof userSmarts.pub.atom.PagingCollection){this.collection.setStartPage(this.getStartPage());this.collection.setStartIndex(this.getStartIndex());this.collection.setCount(this.getPageSize());}
var def=this.collection.get();def.addCallback(this.loadCallback);def.addErrback(this.errback);this.setProperty("populating",true);return;}
this.loadCallback(null);};$prototype.onLoaded=function(coll){this.setProperty("modified",true);};$prototype.onError=function(e){getLogger().logError("Error loading collection: "+e);this.setProperty("modified",false);};$prototype.dispose=function(){if(this.sourceListener){disconnect(this.sourceListener);this.sourceListener=null;}
this.loadCallback=null;this.errback=null;this.resource=null;if(this.collection){this.collection.dispose();}
userSmarts.wt.widgets.TableModel.prototype.dispose.call(this);};$prototype.getWhere=function(){if(this.collection&&this.collection instanceof userSmarts.pub.atom.GeoCollection){return this.collection.getWhere();}
return null;};$prototype.getSortElement=function(){return this.getCollectionParameter("sortElement");};$prototype.getSortOrder=function(){return Coerce.toBoolean(this.getCollectionParameter("sortOrder"),true);};$prototype.setSortElement=function(el){this.setCollectionParameter("sortElement",el);};$prototype.setSortOrder=function(order){this.setCollectionParameter("sortOrder",(order===true));};$prototype.getKeywords=function(){var keystr=this.getCollectionParameter("q");keystr=Coerce.toString(keystr,"");return keystr.split(",");};$prototype.setKeywords=function(keys){if(typeof(keys)=="string"){this.setCollectionParameter("q",keys);}else if(typeof(keys.push)!="undefined"){this.setCollectionParameter("q",keys.toString());}};$prototype.getAndTerms=function(){return Coerce.toBoolean(this.getCollectionParameter("useAnd"),false);};$prototype.setAndTerms=function(and){this.setCollectionParameter("useAnd",(and===true));};$prototype.setBoundingBox=function(arg){if(!this.resource)return;if(arg instanceof Geometry){arg=arg.getEnvelope().toBBOXString();}else if(typeof(arg)!="string"){arg="";}
this.setCollectionParameter("bbox",arg);};$prototype.getBoundingBox=function(){var str=this.getCollectionParameter("bbox");if(str){var parts=str.split(",");var geom=new Geometry("Box");geom.addPoint(new Point(parts[0]*1.0,parts[1]*1.0));geom.addPoint(new Point(parts[2]*1.0,parts[3]*1.0));return geom;}
return null;};$prototype.sort=function(column){if(column){var sortElement=this.getSortElement();if(sortElement&&sortElement==column.name){column.order=!column.order;}
this.setSortOrder(column.order);this.setSortElement(column.name);}else{this.setSortElement("");}
this.populate(this.getOffset());};namespace("userSmarts.pub.atom");$namespace.EntryColumn=Class.create(userSmarts.wt.widgets.TableColumn);$prototype.initialize=function(superclass,properties){setdefault(properties,{label:null,name:"title",fallback:""});superclass.call(this,properties);this.entryProperties={id:"getId",title:"getTitle",summary:"getSummary",authorName:"getAuthor",published:"getPublished",updated:"getUpdated",link:"getLink",content:"getContent"};};$prototype.getColumnLabel=function(entry){return this.label;};$prototype.getLabel=function(entry,name){var result="";var tagName=name||this.name;if(tagName&&entry){result=this.getEntryValue(entry,tagName);}
if(!result){result=this.fallback;}else{if(this.format&&typeof(this.format.format)=="function"){result=this.format.format(result);}}
return result;};$prototype.getEntryValue=function(entry,property){var result=null;var methodName=this.entryProperties[property];if(methodName){if(typeof(entry[methodName])=="function"){if(property=="link"){result=entry[methodName].call(entry,this.relValue);}else{result=entry[methodName].call(entry);}
if(!result&&property=="authorName"){result=entry.getCollection().getAuthor();}
if(property=="content"){var ctype=entry.getContentType();if(ctype=="text"){}else if(ctype=="html"||ctype=="text/html"||ctype=="xhtml"||ctype=="text/xhtml"){}else{result="";}}}}else{result=this.getNodeValue(entry,property);}
return result;};$prototype.getNodeValue=function(entry,path){if(!entry)return null;var node=entry.node;if(!node)return null;if(isXmlNode(node)){var nodePath=path.split("/");var step;for(var n=0;n<nodePath.length;++n){step=nodePath[n];if(step.length>0){if(step.indexOf("@")>=0){if(step.indexOf("@")>0){var nodeName=step.substring(0,step.indexOf("@"));node=DOMUtils.getChild(node,nodeName);}
var attrName=step.substring(step.indexOf("@")+1,step.length);return(node)?getNodeAttribute(node,attrName):null;}
node=DOMUtils.getChild(node,step);if(node==null){return null;}}}
if(node){return(node.childNodes.length>1)?"[node]":scrapeText(node);}}else{var nodePath=path.split("/");var step;for(var n=0;n<nodePath.length;++n){step=nodePath[n];if(step.length>0){node=node[step];if(typeof(node)=="undefined"||node==null){return null;}}}
return node;}
return null;};$prototype.compare=function(entry1,entry2){if(this.name){var rv1=this.getLabel(entry1);var rv2=this.getLabel(entry2);if(typeof(rv1)=='string'&&typeof(rv2)=='string'){try{rv1=parseInt(rv1);}catch(Error){rv1=this.getLabel(entry1);}
if(isNaN(rv1))rv1=this.getLabel(entry1);try{rv2=parseInt(rv2);}catch(Error){rv2=this.getLabel(entry2);}
if(isNaN(rv2))rv2=this.getLabel(entry2);if(rv1>rv2){return 1;}else if(rv1<rv2){return-1;}else if(rv1==rv2){return 0;}}else if(typeof(rv1.compare)=='function'){return rv1.compare(rv2);}}
return-1;};$prototype.dispose=function(){this.entryProperties=null;userSmarts.wt.widgets.TableColumn.prototype.dispose.call(this);};