
SAPO.namespace('Dom');SAPO.Dom.Element={get:function(elm){if(typeof elm!=='undefined'){if(typeof elm==='string'){return document.getElementById(elm);}
return elm;}
return null;},create:function(tag,properties){var el=document.createElement(tag);SAPO.extendObj(el,properties);return el;},remove:function(el){var parEl;if(el&&(parEl=el.parentNode)){parEl.removeChild(el);}},scrollTo:function(elm){elm=this.get(elm);if(elm){if(elm.scrollIntoView){return elm.scrollIntoView();}
var elmOffset={},elmTop=0,elmLeft=0;do{elmTop+=elm.offsetTop||0;elmLeft+=elm.offsetLeft||0;elm=elm.offsetParent;}while(elm);elmOffset={x:elmLeft,y:elmTop};window.scrollTo(elmOffset.x,elmOffset.y);}},offsetTop:function(elm){elm=this.get(elm);var offset=elm.offsetTop;while(elm.offsetParent){if(elm.offsetParent.tagName.toLowerCase()!=="body"){elm=elm.offsetParent;offset+=elm.offsetTop;}else{break;}}
return offset;},offsetLeft:function(elm){elm=this.get(elm);var offset=elm.offsetLeft;while(elm.offsetParent){if(elm.offsetParent.tagName.toLowerCase()!=="body"){elm=elm.offsetParent;offset+=elm.offsetLeft;}else{break;}}
return offset;},positionedOffset:function(element){var valueTop=0,valueLeft=0;element=this.get(element);do{valueTop+=element.offsetTop||0;valueLeft+=element.offsetLeft||0;element=element.offsetParent;if(element){if(element.tagName.toLowerCase()==='body'){break;}
var value=element.style.position;if(!value&&element.currentStyle){value=element.currentStyle.position;}
if((!value||value==='auto')&&typeof getComputedStyle!=='undefined'){var css=getComputedStyle(element,null);value=css?css.position:null;}
if(value==='relative'||value==='absolute'){break;}}}while(element);return[valueLeft,valueTop];},offset:function(elm){return[this.offsetLeft(elm),this.offsetTop(elm)];},scroll:function(elm){elm=elm?s$(elm):document.body;return[((!window.pageXOffset)?elm.scrollLeft:window.pageXOffset),((!window.pageYOffset)?elm.scrollTop:window.pageYOffset)];},_getPropPx:function(cs,prop){var n,c;var val=cs.getPropertyValue?cs.getPropertyValue(prop):cs[prop];if(!val){n=0;}
else{c=val.indexOf('px');if(c===-1){n=0;}
else{n=parseInt(val,10);}}
return n;},offset2:function(el){el=s$(el);var bProp=['border-left-width','border-top-width'];var res=[0,0];var dRes,bRes,parent,cs;var getPropPx=SAPO.Dom.Element._getPropPx;do{cs=window.getComputedStyle?window.getComputedStyle(el,null):el.currentStyle;dRes=[el.offsetLeft|0,el.offsetTop|0];bRes=[getPropPx(cs,bProp[0]),getPropPx(cs,bProp[1])];if(SAPO.Browser.OPERA){res[0]+=dRes[0];res[1]+=dRes[1];}
else{res[0]+=dRes[0]+bRes[0];res[1]+=dRes[1]+bRes[1];}
parent=el.offsetParent;}while(el=parent);bRes=[getPropPx(cs,bProp[0]),getPropPx(cs,bProp[1])];if(SAPO.Browser.OPERA){}
else if(SAPO.Browser.GECKO){res[0]+=bRes[0];res[1]+=bRes[1];}
else{res[0]-=bRes[0];res[1]-=bRes[1];}
return res;},hasAttribute:function(elm,attr){return elm.hasAttribute?elm.hasAttribute(attr):!!elm.getAttribute(attr);},insertAfter:function(newElm,targetElm){if(targetElm=this.get(targetElm)){targetElm.parentNode.insertBefore(newElm,targetElm.nextSibling);}},insertTop:function(newElm,targetElm){if(targetElm=this.get(targetElm)){targetElm.insertBefore(newElm,targetElm.firstChild);}},textContent:function(node){node=s$(node);var text;switch(node&&node.nodeType){case 9:return this.textContent(node.documentElement||node.body&&node.body.parentNode||node.body);case 1:text=node.innerText;if(typeof text!=='undefined'){return text;}
case 11:text=node.textContent;if(typeof text!=='undefined'){return text;}
if(node.firstChild===node.lastChild){return this.textContent(node.firstChild);}
text=[];for(var k=0,child,cs=node.childNodes,m=cs.length;k<m;k++){child=cs[k];text.push(this.textContent(child));}
return text.join('');case 3:case 4:return node.nodeValue;}
return'';},setTextContent:function(node,text){node=s$(node);switch(node&&node.nodeType)
{case 1:if('innerText'in node){node.innerText=text;break;}
case 11:if('textContent'in node){node.textContent=text;break;}
case 9:while(node.firstChild){node.removeChild(node.firstChild);}
if(text!==''){var doc=node.ownerDocument||node;node.appendChild(doc.createTextNode(text));}
break;case 3:case 4:node.nodeValue=text;break;}},isLink:function(element){var b=element&&element.nodeType===1&&((/^a|area$/i).test(element.tagName)||element.hasAttributeNS&&element.hasAttributeNS('http://www.w3.org/1999/xlink','href'));return!!b;},isAncestorOf:function(ancestor,node){if(!node||!ancestor){return false;}
if(node.compareDocumentPosition){return(ancestor.compareDocumentPosition(node)&0x10)!==0;}
while(node=node.parentNode){if(node===ancestor){return true;}}
return false;},descendantOf:function(node,descendant){return node!==descendant&&this.isAncestorOf(node,descendant);},firstElementChild:function(elm){if(!elm){return null;}
if('firstElementChild'in elm){return elm.firstElementChild;}
var child=elm.firstChild;while(child&&child.nodeType!==1){child=child.nextSibling;}
return child;},lastElementChild:function(elm){if(!elm){return null;}
if('lastElementChild'in elm){return elm.lastElementChild;}
var child=elm.lastChild;while(child&&child.nodeType!==1){child=child.previousSibling;}
return child;},nextElementSibling:function(node){var sibling=null;if(!node){return sibling;}
if("nextElementSibling"in node){return node.nextElementSibling;}else{sibling=node.nextSibling;while(sibling&&sibling.nodeType!==1){sibling=sibling.nextSibling;}
return sibling;}},previousElementSibling:function(node){var sibling=null;if(!node){return sibling;}
if("previousElementSibling"in node){return node.previousElementSibling;}else{sibling=node.previousSibling;while(sibling&&sibling.nodeType!==1){sibling=sibling.previousSibling;}
return sibling;}},elementWidth:function(element){if(typeof element==="string"){element=document.getElementById(element);}
return element.offsetWidth;},elementHeight:function(element){if(typeof element==="string"){element=document.getElementById(element);}
return element.offsetHeight;},elementLeft:function(element){if(typeof element==="string"){element=document.getElementById(element);}
return element.offsetLeft;},elementTop:function(element){if(typeof element==="string"){element=document.getElementById(element);}
return element.offsetTop;},elementDimensions:function(element){if(typeof element==="string"){element=document.getElementById(element);}
return Array(element.offsetWidth,element.offsetHeight);},clonePosition:function(cloneTo,cloneFrom){cloneTo.style.top=this.offsetTop(cloneFrom)+'px';cloneTo.style.left=this.offsetLeft(cloneFrom)+'px';return cloneTo;},ellipsizeText:function(element,ellipsis){if(element=s$(element)){while(element&&element.scrollHeight>(element.offsetHeight+8)){element.textContent=element.textContent.replace(/(\s+\S+)\s*$/,replace||'\u2026');}}},findUpwardsByClass:function(element,className){var re=new RegExp("(^|\\s)"+className+"(\\s|$)");while(true){if(typeof(element.className)!=='undefined'&&re.test(element.className)){return element;}
else{element=element.parentNode;if(!element||element.nodeType!==1){return false;}}}},findUpwardsByTag:function(element,tag){while(true){if(element&&element.nodeName.toUpperCase()===tag.toUpperCase()){return element;}else{element=element.parentNode;if(!element||element.nodeType!==1){return false;}}}},findUpwardsById:function(element,id){while(true){if(typeof(element.id)!=='undefined'&&element.id===id){return element;}else{element=element.parentNode;if(!element||element.nodeType!==1){return false;}}}},getChildrenText:function(el,removeIt){var node,j,part,nodes=el.childNodes,jLen=nodes.length,text='';if(!el){return text;}
for(j=0;j<jLen;++j){node=nodes[j];if(!node){continue;}
if(node.nodeType===3){part=this._trimString(String(node.data));if(part.length>0){text+=part;if(removeIt){el.removeChild(node);}}
else{el.removeChild(node);}}}
return text;},_trimString:function(text){return(String.prototype.trim)?text.trim():text.replace(/^\s*/,'').replace(/\s*$/,'');},getSelectValues:function(select){var selectEl=s$(select);var values=[];for(var i=0;i<selectEl.options.length;++i){values.push(selectEl.options[i].value);}
return values;},_normalizeData:function(data){var d,data2=[];for(var i=0,f=data.length;i<f;++i){d=data[i];if(!(d instanceof Array)){d=[d,d];}
else if(d.length===1){d.push(d[0]);}
data2.push(d);}
return data2;},fillSelect:function(container,data,skipEmpty,defaultValue){var containerEl=s$(container);if(!containerEl){return;}
containerEl.innerHTML='';var d,optionEl;if(!skipEmpty){optionEl=document.createElement('option');optionEl.setAttribute('value','');containerEl.appendChild(optionEl);}
data=SAPO.Dom.Element._normalizeData(data);for(var i=0,f=data.length;i<f;++i){d=data[i];optionEl=document.createElement('option');optionEl.setAttribute('value',d[0]);if(d.length>2){optionEl.setAttribute('extra',d[2]);}
optionEl.appendChild(document.createTextNode(d[1]));if(d[0]===defaultValue){optionEl.setAttribute('selected','selected');}
containerEl.appendChild(optionEl);}},fillSelect2:function(ctn,opts){ctn=s$(ctn);ctn.innerHTML='';var defs={skipEmpty:false,skipCreate:false,emptyLabel:'none',createLabel:'create',optionsGroupLabel:'groups',emptyOptionsGroupLabel:'none exist',defaultValue:''};if(!opts){throw'param opts is a requirement!';}
if(!opts.data){throw'opts.data is a requirement!';}
opts=SAPO.extendObj(defs,opts);var optionEl,optGroupEl,d;var optGroupValuesEl=document.createElement('optgroup');optGroupValuesEl.setAttribute('label',opts.optionsGroupLabel);opts.data=SAPO.Dom.Element._normalizeData(opts.data);if(!opts.skipCreate){opts.data.unshift(['$create$',opts.createLabel]);}
if(!opts.skipEmpty){opts.data.unshift(['',opts.emptyLabel]);}
for(var i=0,f=opts.data.length;i<f;++i){d=opts.data[i];optionEl=document.createElement('option');optionEl.setAttribute('value',d[0]);optionEl.appendChild(document.createTextNode(d[1]));if(d[0]===opts.defaultValue){optionEl.setAttribute('selected','selected');}
if(d[0]===''||d[0]==='$create$'){ctn.appendChild(optionEl);}
else{optGroupValuesEl.appendChild(optionEl);}}
var lastValIsNotOption=function(data){var lastVal=data[data.length-1][0];return(lastVal===''||lastVal==='$create$');};if(lastValIsNotOption(opts.data)){optionEl=document.createElement('option');optionEl.setAttribute('value','$dummy$');optionEl.setAttribute('disabled','disabled');optionEl.appendChild(document.createTextNode(opts.emptyOptionsGroupLabel));optGroupValuesEl.appendChild(optionEl);}
ctn.appendChild(optGroupValuesEl);var addOption=function(v,l){var optionEl=ctn.options[ctn.options.length-1];if(optionEl.getAttribute('disabled')){optionEl.parentNode.removeChild(optionEl);}
optionEl=document.createElement('option');optionEl.setAttribute('value',v);optionEl.appendChild(document.createTextNode(l));optGroupValuesEl.appendChild(optionEl);ctn.options[ctn.options.length-1].setAttribute('selected',true);};if(!opts.skipCreate){ctn.onchange=function(){if((ctn.value==='$create$')&&(typeof opts.onCreate==='function')){opts.onCreate(ctn,addOption);}};}},fillRadios:function(insertAfterEl,name,data,skipEmpty,defaultValue,splitEl){var afterEl=s$(insertAfterEl);afterEl=afterEl.nextSibling;while(afterEl&&afterEl.nodeType!==1){afterEl=afterEl.nextSibling;}
var containerEl=document.createElement('span');if(afterEl){afterEl.parentNode.insertBefore(containerEl,afterEl);}
else{s$(insertAfterEl).appendChild(containerEl);}
data=SAPO.Dom.Element._normalizeData(data);if(name.substring(name.length-1)!==']'){name+='[]';}
var d,inputEl;if(!skipEmpty){inputEl=document.createElement('input');inputEl.setAttribute('type','radio');inputEl.setAttribute('name',name);inputEl.setAttribute('value','');containerEl.appendChild(inputEl);if(splitEl){containerEl.appendChild(document.createElement(splitEl));}}
for(var i=0;i<data.length;++i){d=data[i];inputEl=document.createElement('input');inputEl.setAttribute('type','radio');inputEl.setAttribute('name',name);inputEl.setAttribute('value',d[0]);containerEl.appendChild(inputEl);containerEl.appendChild(document.createTextNode(d[1]));if(splitEl){containerEl.appendChild(document.createElement(splitEl));}
if(d[0]===defaultValue){inputEl.checked=true;}}
return containerEl;},fillChecks:function(insertAfterEl,name,data,defaultValue,splitEl){var afterEl=s$(insertAfterEl);afterEl=afterEl.nextSibling;while(afterEl&&afterEl.nodeType!==1){afterEl=afterEl.nextSibling;}
var containerEl=document.createElement('span');if(afterEl){afterEl.parentNode.insertBefore(containerEl,afterEl);}
else{s$(insertAfterEl).appendChild(containerEl);}
data=SAPO.Dom.Element._normalizeData(data);if(name.substring(name.length-1)!==']'){name+='[]';}
var d,inputEl;for(var i=0;i<data.length;++i){d=data[i];inputEl=document.createElement('input');inputEl.setAttribute('type','checkbox');inputEl.setAttribute('name',name);inputEl.setAttribute('value',d[0]);containerEl.appendChild(inputEl);containerEl.appendChild(document.createTextNode(d[1]));if(splitEl){containerEl.appendChild(document.createElement(splitEl));}
if(d[0]===defaultValue){inputEl.checked=true;}}
return containerEl;},parentIndexOf:function(parentEl,childEl){var node,idx=0;for(var i=0,f=parentEl.childNodes.length;i<f;++i){node=parentEl.childNodes[i];if(node.nodeType===1){if(node===childEl){return idx;}
++idx;}}
return-1;},nextSiblings:function(elm){if(typeof(elm)==="string"){elm=document.getElementById(elm);}
if(typeof(elm)==='object'&&elm!==null&&elm.nodeType&&elm.nodeType===1){var elements=[],siblings=elm.parentNode.children,index=SAPO.Dom.Element.parentIndexOf(elm.parentNode,elm);for(var i=++index,len=siblings.length;i<len;i++){elements.push(siblings[i]);}
return elements;}
return[];},previousSiblings:function(elm){if(typeof(elm)==="string"){elm=document.getElementById(elm);}
if(typeof(elm)==='object'&&elm!==null&&elm.nodeType&&elm.nodeType===1){var elements=[],siblings=elm.parentNode.children,index=SAPO.Dom.Element.parentIndexOf(elm.parentNode,elm);for(var i=0,len=index;i<len;i++){elements.push(siblings[i]);}
return elements;}
return[];},siblings:function(elm){if(typeof(elm)==="string"){elm=document.getElementById(elm);}
if(typeof(elm)==='object'&&elm!==null&&elm.nodeType&&elm.nodeType===1){var elements=[],siblings=elm.parentNode.children;for(var i=0,len=siblings.length;i<len;i++){if(elm!==siblings[i]){elements.push(siblings[i]);}}
return elements;}
return[];},childElementCount:function(elm){elm=s$(elm);if('childElementCount'in elm){return elm.childElementCount;}
if(!elm){return 0;}
return this.siblings(elm).length+1;},appendHTML:function(elm,html){var temp=document.createElement('div');temp.innerHTML=html;var tempChildren=temp.children;for(var i=0;i<tempChildren.length;i++){elm.appendChild(tempChildren[i]);}},prependHTML:function(elm,html){var temp=document.createElement('div');temp.innerHTML=html;var first=elm.firstChild;var tempChildren=temp.children;for(var i=tempChildren.length-1;i>=0;i--){elm.insertBefore(tempChildren[i],first);first=elm.firstChild;}},htmlToFragment:function(html){if(typeof document.createRange==='function'&&typeof Range.prototype.createContextualFragment==='function'){this.htmlToFragment=function(html){var range;if(typeof html!=='string'){return document.createDocumentFragment();}
range=document.createRange();range.selectNode(document.body);return range.createContextualFragment(html);};}else{this.htmlToFragment=function(html){var fragment=document.createDocumentFragment(),tempElement,current;if(typeof html!=='string'){return fragment;}
tempElement=document.createElement('div');tempElement.innerHTML=html;while(current=tempElement.firstChild){fragment.appendChild(current);}
return fragment;};}
return this.htmlToFragment.call(this,html);},data:function(selector){if(typeof selector!=='object'&&typeof selector!=='string'){throw'[SAPO.Dom.Element.data] :: Invalid selector defined';}
if(typeof selector==='object'){this._element=selector;}else{this._element=SAPO.Dom.Selector.select(selector);if(this._element.length<=0){throw"[SAPO.Dom.Element.data] :: Can't find any element with the specified selector";}
this._element=this._element[0];}
var dataset={};var
attributesElements=this._element.dataset||this._element.attributes||{},prop;var propName,i;for(prop in attributesElements){if(typeof attributesElements[prop]==='undefined'){continue;}else if(typeof attributesElements[prop]==='object'){try{prop=attributesElements[prop].name||prop;if(((attributesElements[prop].name||attributesElements[prop].nodeValue)&&(prop.indexOf('data-')!==0))||!(attributesElements[prop].nodeValue||attributesElements[prop].value||attributesElements[prop])){continue;}}catch(e){continue;}}
propName=prop.replace('data-','');if(propName.indexOf('-')!==-1){propName=propName.split("-");for(i=1;i<propName.length;i+=1){propName[i]=propName[i].substr(0,1).toUpperCase()+propName[i].substr(1);}
propName=propName.join('');}
dataset[propName]=attributesElements[prop].nodeValue||attributesElements[prop].value||attributesElements[prop];if(dataset[propName]==="true"||dataset[propName]==="false"){dataset[propName]=(dataset[propName]==='true');}}
return dataset;},moveCursorTo:function(el,t){if(el.setSelectionRange){el.setSelectionRange(t,t);}
else{var range=el.createTextRange();range.collapse(true);range.moveEnd('character',t);range.moveStart('character',t);range.select();}}};