/* Copyright (c) 1995-2008 Choice Hotels International, Inc. All Rights Reserved. */
var $DOM=$Class.create({_ctor:function(doc){if(doc){if(doc.nodeType==9)this.doc=doc;else this.doc=doc.ownerDocument}else this.doc=$DOM.newDocument()},dispose:function(){$DOM.disposeChildren(this.doc)},getDocument:function(){return this.doc},create:function(tag,attrs,children){return this._create(tag,attrs,arguments,2)},setRoot:function(elem){$DOM.append(this.doc,elem);return elem},_create:function(tag,attrs,children,offset){var node=(tag=="img")?new Image:this.doc.createElement(tag);$DOM.setAttrs(node,attrs);$DOM._appendList(node,children,offset);return node},text:function(txt){return this.doc.createTextNode(txt)},get:function(id){return this.doc.getElementById(id)},select:function(xpathexp){if(window.XPathEvaluator){var evator=new XPathEvaluator();var iter=evator.evaluate(xpathexp,this.doc,null,XPathResult.ORDERED_NODE_ITERATOR_TYPE,null);var result=new Array;if(iter!=null){for(var elem=iter.iterateNext();elem;elem=iter.iterateNext())result.push(elem)}return result}else if(this.doc.selectNodes){return $A(this.doc.selectNodes(xpathexp))}return null},createCSSStylesheet:function(media){return CSSStylesheet.create(this,media)}});$DOM.append=function(parent,children){this._appendList(parent,arguments,1);return parent};$DOM.removeChildren=function(parent,startindex,endindex){if(startindex==null)startindex=0;if(endindex==null)endindex=parent.childNodes.length;for(var i=endindex-1;i>=startindex;i--)parent.removeChild(parent.childNodes[i]);return parent};$DOM.removeFromParent=function(node){if(node.parentNode)node.parentNode.removeChild(node)};$DOM.newDocument=function(fthread){if(document.implementation&&document.implementation.createDocument)return document.implementation.createDocument("","",null);else if(window.ActiveXObject){var objname=fthread?["MSXML2.FreeThreadedDOMDocument.3.0","MSXML.FreeThreadedDOMDocument"]:["MSXML2.DOMDocument.3.0","MSXML.DOMDocument"];for(var i=0;i<objname.length;i++){try{return new ActiveXObject(objname[i])}catch(error){}}}else throw new Error("XML DOM object not supported by this browser.")};$DOM.disposeChildren=function(node){while(node.lastChild){var child=node.lastChild;node.removeChild(child);this.disposeChildren(child)}return node};$DOM.empty=function(node){while(node.lastChild)node.removeChild(node.lastChild);return node};$DOM.setAttrs=function(node,attrs){if(node&&attrs){for(var prop in attrs){var value=attrs[prop];if(value!=null){if(prop=="className")node.className=value;else if(prop.startsWith("on"))Event.addEventHandler(node,prop.substring(2),value);else node.setAttribute(prop,value)}}}return node};$DOM.css=function(node,attrs){if(node&&attrs){for(var prop in attrs)node.style[prop]=attrs[prop]}return node};$DOM.parseXML=function(doc,xmlstr){var newdoc=null;if(window.DOMParser)newdoc=new DOMParser().parseFromString(xmlstr,"text/xml");else {newdoc=$DOM.newDocument(false);newdoc.preserveWhiteSpace=true;newdoc.loadXML(xmlstr)}if(doc){return $DOM.importNodes(doc,newdoc.childNodes,true)}else {return newdoc}};$DOM._append=function(node,value){if(value!=null){if(value.nodeType!=null)node.appendChild(value);else if((typeof value)=="string")node.appendChild(node.ownerDocument.createTextNode(value));else if(value instanceof Array){for(var i=0;i<value.length;i++)this._append(node,value[i])}else if((typeof value)=="function")this._append(node,value());else this._append(node,value.toString())}return node};$DOM._appendList=function(node,children,offset){for(var i=offset||0;i<children.length;i++)this._append(node,children[i]);return node};$DOM.importNode=function(doc,node,deep){var newnode;if(node.nodeType==1){newnode=doc.createElement(node.nodeName);for(var i=0;i<node.attributes.length;i++){var attr=node.attributes[i];if(attr.value){if(attr.name=="style")this._parseStyle(newnode,attr.value);else if(attr.name=="class")newnode.className=attr.value;else newnode.setAttribute(attr.name,attr.value)}}if(node.style&&node.style.cssText)newnode.style.cssText=node.style.cssText}else if(node.nodeType==11){newnode=doc.createDocumentFragment()}else if(node.nodeType==3){newnode=doc.createTextNode(node.nodeValue)}else if(node.nodeType==7){return null}else throw new Error("Import not implemented for node type: "+node.nodeType);if(deep&&node.hasChildNodes()){for(var i=0;i<node.childNodes.length;i++)newnode.appendChild(this.importNode(doc,node.childNodes[i],true))}return newnode};$DOM.importNodes=function(doc,nodes,deep){var result=[];for(var i=0;i<nodes.length;i++){var newnode=this.importNode(doc,nodes[i],deep);if(newnode)result.push(newnode)}return result};$DOM._parseStyle=function(elem,str){var attr=str.split(";");for(var i=attr.length-1;i>=0;i--){var idx=attr[i].indexOf(":");if(idx>0){var name=attr[i].substring(0,idx).trim();name=name.replace(/-./g,function(match){return match.charAt(1).toUpperCase()});elem.style[name]=attr[i].substring(idx+1).trim()}}};$DOM.nodeToString=function(node){switch(node.nodeType){case 1:{var buffer=new StringBuffer("<");buffer.append(node.nodeName);for(var i=0;i<node.attributes.length;i++){buffer.append(" ");buffer.append(this.nodeToString(node.attributes.item(i)))}if(node.childNodes.length>0){buffer.append(">");for(var i=0;i<node.childNodes.length;i++)buffer.append(this.nodeToString(node.childNodes[i]));buffer.append("</");buffer.append(node.nodeName);buffer.append(">")}else buffer.append("/>");return buffer.toString()}case 2:{return node.nodeName+"=\""+node.nodeValue+"\""}case 3:{return node.nodeValue}case 9:{return this.nodeToString(node.documentElement)}case 11:{var buffer=new StringBuffer;for(var i=0;i<node.childNodes.length;i++)buffer.append(this.nodeToString(node.childNodes[i]));return buffer.toString()}}return ""};var $HTMLDOM=$DOM.extend({_ctor:function(doc){this.$super(doc||document)},_createSpecial:function(tag,args){return this._create(tag,args[0],args,1)},NBSP:"\xa0",DIV:function(attrs,children){return this._createSpecial("DIV",arguments)},SPAN:function(attrs,children){return this._createSpecial("SPAN",arguments)},IMG:function(attrs){return this._createSpecial("IMG",arguments)},A:function(attrs,children){return this._createSpecial("A",arguments)},INPUT:function(attrs){return this._createSpecial("INPUT",arguments)},OPTION:function(attrs){return this._createSpecial("OPTION",arguments)},FORM:function(attrs){return this._createSpecial("FORM",arguments)},TABLE:function(attrs,children){return this._createSpecial("TABLE",arguments)},THEAD:function(attrs,children){return this._createSpecial("THEAD",arguments)},TBODY:function(attrs,children){return this._createSpecial("TBODY",arguments)},TD:function(attrs,children){return this._createSpecial("TD",arguments)},TR:function(attrs,children){return this._createSpecial("TR",arguments)},BR:function(attrs){return this._createSpecial("BR",arguments)}});var $HTML=new $HTMLDOM;var CSSStylesheet=$Class.create({_ctor:function(dom,media){this.dom=dom;this.stylesheet=dom.create("style",{type:"text/css",media:media||"all"});dom.doc.getElementsByTagName("head")[0].appendChild(this.stylesheet)},dispose:function(){this.dom=null;this.stylesheet=null},addRule:function(selector,styles){$DOM.append(this.stylesheet,selector+" {"+styles+"}")}});CSSStylesheet.create=function(dom,media){var agent=navigator?navigator.userAgent.toLowerCase():null;var ie=agent&&/msie/.test(agent)&&!/opera/.test(agent)&&/win/.test(agent);return (ie&&dom.doc.styleSheets&&(dom.doc.styleSheets.length>0))?new IECSSStylesheet(dom,media):new CSSStylesheet(dom,media)};var IECSSStylesheet=CSSStylesheet.extend({_ctor:function(dom,media){this.$super(dom,media);this.stylesheet=dom.doc.styleSheets[dom.doc.styleSheets.length-1]},addRule:function(selector,styles){if(this.stylesheet.addRule)this.stylesheet.addRule(selector,styles);else if(this.stylesheet.insertRule)this.stylesheet.insertRule(selector+" {"+styles+"}",0)}});