
/* Merged Plone Javascript file
 * This file is dynamically assembled from separate parts.
 * Some of these parts have 3rd party licenses or copyright information attached
 * Such information is valid for that section,
 * not for the entire composite file
 * originating files are separated by - filename.js -
 */

/* - kupunoi18n.js - */
// http://10.228.150.75:8080/cms/portal_javascripts/kupunoi18n.js?original=1
window._=function(msgid,interpolations){if(interpolations){for(var id in interpolations){var value=interpolations[id];var reg=new RegExp('\\\$\\\{'+id+'\\\}','g');msgid=msgid.replace(reg,""+value)}};return msgid};

/* - sarissa_ieemu_xpath.js - */
// http://10.228.150.75:8080/cms/portal_javascripts/sarissa_ieemu_xpath.js?original=1
if(_SARISSA_HAS_DOM_FEATURE&&document.implementation.hasFeature("XPath","3.0")){var xmldoc=window.XMLDocument||window.Document;
function SarissaNodeList(i){this.length=i};SarissaNodeList.prototype.item=function(i){return(i<0||i>=this.length)?null:this[i]};SarissaNodeList.prototype.expr="";xmldoc.prototype.setProperty=function(x,y){};Sarissa.setXpathNamespaces=function(oDoc,sNsSet){oDoc._sarissa_useCustomResolver=true;var namespaces=sNsSet.indexOf(" ")>-1?sNsSet.split(" "):new Array(sNsSet);oDoc._sarissa_xpathNamespaces=new Array(namespaces.length);for(var i=0;i<namespaces.length;i++){var ns=namespaces[i];var colonPos=ns.indexOf(":");var assignPos=ns.indexOf("=");if(colonPos==5&&assignPos>colonPos+2){var prefix=ns.substring(colonPos+1,assignPos);var uri=ns.substring(assignPos+2,ns.length-1);oDoc._sarissa_xpathNamespaces[prefix]=uri}else{throw "Bad format on namespace declaration(s) given"}}};xmldoc.prototype._sarissa_useCustomResolver=false;xmldoc.prototype._sarissa_xpathNamespaces=new Array();xmldoc.prototype.selectNodes=function(sExpr,contextNode){var nsDoc=this;var nsresolver=this._sarissa_useCustomResolver? function(prefix){var s=nsDoc._sarissa_xpathNamespaces[prefix];if(s)return s;else throw "No namespace URI found for prefix: '"+prefix+"'"}:this.createNSResolver(this.documentElement);var oResult=this.evaluate(sExpr,(contextNode?contextNode:this),nsresolver,XPathResult.ORDERED_NODE_SNAPSHOT_TYPE,null);var nodeList=new SarissaNodeList(oResult.snapshotLength);nodeList.expr=sExpr;for(var i=0;i<nodeList.length;i++)
nodeList[i]=oResult.snapshotItem(i);return nodeList};Element.prototype.selectNodes=function(sExpr){var doc=this.ownerDocument;if(doc.selectNodes)
return doc.selectNodes(sExpr,this);else
throw "Method selectNodes is only supported by XML Elements"};xmldoc.prototype.selectSingleNode=function(sExpr,contextNode){var ctx=contextNode?contextNode:null;sExpr="("+sExpr+")[1]";var nodeList=this.selectNodes(sExpr,ctx);if(nodeList.length>0)
return nodeList.item(0);else
return null};Element.prototype.selectSingleNode=function(sExpr){var doc=this.ownerDocument;if(doc.selectSingleNode)
return doc.selectSingleNode(sExpr,this);else
throw "Method selectNodes is only supported by XML Elements"};Sarissa.IS_ENABLED_SELECT_NODES=true;xmldoc=undefined};

/* - kupuhelpers.js - */
// http://10.228.150.75:8080/cms/portal_javascripts/kupuhelpers.js?original=1
function addEventHandler(element,event,method,context){var wrappedmethod=new ContextFixer(method,context);var args=new Array(null,null);for(var i=4;i<arguments.length;i++){args.push(arguments[i])};wrappedmethod.args=args;try{if(element.addEventListener){element.addEventListener(event,wrappedmethod.execute,false)} else if(element.attachEvent){element.attachEvent("on"+event,wrappedmethod.execute)} else{throw _("Unsupported browser!")};return wrappedmethod.execute} catch(e){alert(_('exception ${message} while registering an event handler '+'for element ${element}, event ${event}, method ${method}',{'message':e.message,'element':element,'event':event,'method':method}))}};
function removeEventHandler(element,event,method){if(element.removeEventListener){element.removeEventListener(event,method,false)} else if(element.detachEvent){element.detachEvent("on"+event,method)} else{throw _("Unsupported browser!")}};
function getFromSelector(selector){var match=/#(\S+)\s*([^ .]+)\.(\S+)/.exec(selector);if(!match){return window.document.getElementById(selector)}
var id=match[1],tag=match[2],className=match[3];var base=window.document.getElementById(id);return getBaseTagClass(base,tag,className)}
function getBaseTagClass(base,tag,className){var classPat=new RegExp('\\b'+className+'\\b');var nodes=base.getElementsByTagName(tag);for(var i=0;i<nodes.length;i++){if(classPat.test(nodes[i].className)){return nodes[i]}}
return null}
function openPopup(url,width,height){var sw=screen.width;var sh=screen.height;var left=sw/ 2 - width / 2;var top=sh/ 2 - height / 2;var win=window.open(url,'someWindow','width='+width+',height='+height+',left='+left+',top='+top);return win};
function selectSelectItem(select,item){for(var i=0;i<select.options.length;i++){var option=select.options[i];if(option.value==item){select.selectedIndex=i;return}}
select.selectedIndex=0};
function ParentWithStyleChecker(tagnames,style,stylevalue,command){return function(selNode,button,editor,event){if(command){var result=editor.getInnerDocument().queryCommandState(command)
if(result||editor.getSelection().getContentLength()==0){return result}};var currnode=selNode;while(currnode&&currnode.style){for(var i=0;i<tagnames.length;i++){if(currnode.nodeName.toLowerCase()==tagnames[i].toLowerCase()){return true}};if(style&&currnode.style[style]==stylevalue){return true};currnode=currnode.parentNode};return false}};
function _load_dict_helper(element){var dict={};for(var i=0;i<element.childNodes.length;i++){var child=element.childNodes[i];if(child.nodeType==1){var value='';for(var j=0;j<child.childNodes.length;j++){if(child.childNodes[j].nodeType==1){value=_load_dict_helper(child);break} else if(typeof(value)==typeof('')){value+=child.childNodes[j].nodeValue}};if(typeof(value)==typeof('')&&!isNaN(parseInt(value))&&parseInt(value).toString().length==value.length){value=parseInt(value)} else if(typeof(value)!=typeof('')){if(value.length==1){value=value[0]}};var name=child.nodeName.toLowerCase();if(child.attributes[0]&&/^_/.test(child.attributes[0])){name+=child.attributes[0].toLowerCase()}
if(dict[name]!=undefined){if(!dict[name].push){dict[name]=new Array(dict[name],value)} else{dict[name].push(value)}} else{dict[name]=value}}};return dict};
function loadDictFromXML(document,islandid){var dict={};var confnode=getFromSelector(islandid);var root=null;for(var i=0;i<confnode.childNodes.length;i++){if(confnode.childNodes[i].nodeType==1){root=confnode.childNodes[i];break}};if(!root){throw(_('No element found in the config island!'))};dict=_load_dict_helper(root);return dict};
function NodeIterator(node,continueatnextsibling){this.node=node;this.current=node;this.terminator=continueatnextsibling?null:node;this.next=function(){if(this.current===false){this.current=this.node};var current=this.current;if(current.firstChild){this.current=current.firstChild} else{while(current!=this.terminator&&!current.nextSibling){current=current.parentNode};if(current==this.terminator){this.current=false} else{this.current=current.nextSibling}};return this.current};this.reset=function(){this.current=this.node};this.setCurrent=function(node){this.current=node}};
function BaseSelection(){this.splitNodeAtSelection=function(node){if(!this.selectionInsideNode(node)){throw(_('Selection not inside the node!'))};var doc=this.document.getDocument();var br=doc.createElement('br');br.setAttribute('node_splitter','indeed');this.replaceWithNode(br);var clone=node.cloneNode(true);var iterator=new NodeIterator(node);var currnode=iterator.next();var remove=false;while(currnode){if(currnode.nodeName.toLowerCase()=='br'&&currnode.getAttribute('node_splitter')=='indeed'){remove=true};var lastnode=currnode;currnode=iterator.next();if(remove&&(lastnode.nodeType==3||!lastnode.hasChildNodes())){lastnode.parentNode.removeChild(lastnode)}};var iterator=new NodeIterator(clone);var currnode=iterator.next();var remove=true;while(currnode){var lastnode=currnode;currnode=iterator.next();if(lastnode.nodeName.toLowerCase()=='br'&&lastnode.getAttribute('node_splitter')=='indeed'){lastnode.parentNode.removeChild(lastnode);remove=false};if(remove&&(lastnode.nodeType==3||!lastnode.hasChildNodes())){lastnode.parentNode.removeChild(lastnode)}};if(node.nextSibling){node.parentNode.insertBefore(clone,node.nextSibling)} else{node.parentNode.appendChild(clone)};this.reset();return clone};this.selectionInsideNode=function(node){var currnode=this.parentElement();while(currnode){if(currnode==node){return true};currnode=currnode.parentNode};return false}};
function MozillaSelection(document){this.document=document;this.selection=document.getWindow().getSelection();this.selectNodeContents=function(node){this.selection.removeAllRanges();this.selection.selectAllChildren(node)};this.collapse=function(collapseToEnd){try{if(!collapseToEnd){this.selection.collapseToStart()} else{this.selection.collapseToEnd()}} catch(e){}};this.replaceWithNode=function(node,selectAfterPlace){var range=this.selection.getRangeAt(0);this.selection.removeAllRanges();range.deleteContents();var container=range.startContainer;var pos=range.startOffset;var range=this.document.getDocument().createRange();if(container.nodeType==3&&node.nodeType==3){container.insertData(pos,node.nodeValue);range.setEnd(container,pos+node.length);range.setStart(container,pos+node.length)} else{var afterNode;if(container.nodeType==3){var textNode=container;var container=textNode.parentNode;var text=textNode.nodeValue;var textBefore=text.substr(0,pos);var textAfter=text.substr(pos);var beforeNode=this.document.getDocument().createTextNode(textBefore);afterNode=this.document.getDocument().createTextNode(textAfter);container.insertBefore(afterNode,textNode);container.insertBefore(node,afterNode);container.insertBefore(beforeNode,node);container.removeChild(textNode)} else{afterNode=container.childNodes[pos];if(afterNode){container.insertBefore(node,afterNode)} else{container.appendChild(node)}}
range.setEnd(afterNode,0);range.setStart(afterNode,0)}
if(selectAfterPlace){this.selection=this.document.getWindow().getSelection();this.selection.addRange(range);if(selectAfterPlace.nodeType==1){this.selection.selectAllChildren(selectAfterPlace)} else{if(node.hasChildNodes()){this.selection.selectAllChildren(node)} else{var range=this.selection.getRangeAt(0).cloneRange();this.selection.removeAllRanges();range.selectNode(node);this.selection.addRange(range)}};this.document.getWindow().focus()};return node};this.startOffset=function(){var startnode=this.startNode();var startnodeoffset=0;if(startnode==this.selection.anchorNode){startnodeoffset=this.selection.anchorOffset} else{startnodeoffset=this.selection.focusOffset};var parentnode=this.parentElement();if(startnode==parentnode){return startnodeoffset};var currnode=parentnode.firstChild;var offset=0;if(!currnode){if(startnodeoffset!=0){throw(_('Start node offset detected in a node without children!'))};return 0};while(currnode!=startnode){if(currnode.nodeType==3){offset+=currnode.nodeValue.length};currnode=currnode.nextSibling};return offset+startnodeoffset};this.startNode=function(){var anode=this.selection.anchorNode;var aoffset=this.selection.anchorOffset;var onode=this.selection.focusNode;var ooffset=this.selection.focusOffset;var arange=this.document.getDocument().createRange();arange.setStart(anode,aoffset);var orange=this.document.getDocument().createRange();orange.setStart(onode,ooffset);return arange.compareBoundaryPoints('START_TO_START',orange)<=0?anode:onode};this.endOffset=function(){var endnode=this.endNode();var endnodeoffset=0;if(endnode=this.selection.focusNode){endnodeoffset=this.selection.focusOffset} else{endnodeoffset=this.selection.anchorOffset};var parentnode=this.parentElement();var currnode=parentnode.firstChild;var offset=0;if(parentnode==endnode){for(var i=0;i<parentnode.childNodes.length;i++){var child=parentnode.childNodes[i];if(i==endnodeoffset){return offset};if(child.nodeType==3){offset+=child.nodeValue.length}}};if(!currnode){if(endnodeoffset!=0){var msg=_('End node offset detected in a node without '+'children!');alert(msg);throw(msg)};return 0};while(currnode!=endnode){if(currnode.nodeType==3){offset+=currnode.nodeValue.length};currnode=currnode.nextSibling};return offset+endnodeoffset};this.endNode=function(){var anode=this.selection.anchorNode;var aoffset=this.selection.anchorOffset;var onode=this.selection.focusNode;var ooffset=this.selection.focusOffset;var arange=this.document.getDocument().createRange();arange.setStart(anode,aoffset);var orange=this.document.getDocument().createRange();orange.setStart(onode,ooffset);return arange.compareBoundaryPoints('START_TO_START',orange)>0?anode:onode};this.getContentLength=function(){return this.selection.toString().length};this.cutChunk=function(startOffset,endOffset){var range=this.selection.getRangeAt(0);var offsetParent=this.parentElement();var currnode=offsetParent.firstChild;var curroffset=0;var startparent=null;var startparentoffset=0;while(currnode){if(currnode.nodeType==3){var nodelength=currnode.nodeValue.length;if(curroffset+nodelength<startOffset){curroffset+=nodelength} else{startparent=currnode;startparentoffset=startOffset-curroffset;break}};currnode=currnode.nextSibling};var currnode=offsetParent.firstChild;var curroffset=0;var endparent=null;var endoffset=0;while(currnode){if(currnode.nodeType==3){var nodelength=currnode.nodeValue.length;if(curroffset+nodelength<endOffset){curroffset+=nodelength} else{endparent=currnode;endparentoffset=endOffset-curroffset;break}};currnode=currnode.nextSibling};if(!startparent){throw(_('Start offset out of range!'))};if(!endparent){throw(_('End offset out of range!'))};var newrange=range.cloneRange();newrange.setStart(startparent,startparentoffset);newrange.setEnd(endparent,endparentoffset);return newrange.extractContents()};this.getElementLength=function(element){var length=0;var currnode=element.firstChild;while(currnode){if(currnode.nodeType==3){length+=currnode.nodeValue.length};currnode=currnode.nextSibling};return length};this.parentElement=function(){if(this.selection.rangeCount==0){var parent=this.document.getDocument().body;while(parent.firstChild){parent=parent.firstChild}} else{var range=this.selection.getRangeAt(0);var parent=range.commonAncestorContainer;var inv=range.compareBoundaryPoints(Range.START_TO_END,range)<0;var startNode=inv?range.endContainer:range.startContainer;var startOffset=inv?range.endOffset:range.startOffset;var endNode=inv?range.startContainer:range.endContainer;var endOffset=inv?range.startOffset:range.endOffset;var selectedChild=null;var child=parent.firstChild;while(child){if(range.intersectsNode(child)&&!(child==startNode&&startOffset==child.length)&&!(child==endNode&&endOffset==0)){if(selectedChild){selectedChild=null;break} else{selectedChild=child}} else if(selectedChild){break};child=child.nextSibling};if(selectedChild){parent=selectedChild}};if(parent.nodeType==Node.TEXT_NODE){parent=parent.parentNode};return parent};this.getSelectedNode=this.parentElement;this.moveStart=function(offset){var offsetparent=this.parentElement();var startoffset=this.startOffset();var realoffset=offset+startoffset;if(realoffset>=0){var currnode=offsetparent.firstChild;var curroffset=0;var startparent=null;var startoffset=0;while(currnode){if(currnode.nodeType==3){var nodelength=currnode.nodeValue.length;if(curroffset+nodelength>=realoffset){var range=this.selection.getRangeAt(0);range.setStart(currnode,realoffset-curroffset);return}};currnode=currnode.nextSibling};var currnode=offsetparent.nextSibling;while(currnode){if(currnode.nodeType==3){var nodelength=currnode.nodeValue.length;if(curroffset+nodelength>=realoffset){var range=this.selection.getRangeAt(0);var endnode=this.endNode();var endoffset=this.endOffset();range.setEnd(currnode,realoffset-curroffset);range.setStart(endnode,endoffset);return};curroffset+=nodelength};currnode=currnode.nextSibling};throw(_('Offset out of document range'))} else if(realoffset<0){var currnode=offsetparent.prevSibling;var curroffset=0;while(currnode){if(currnode.nodeType==3){var currlength=currnode.nodeValue.length;if(curroffset-currlength<realoffset){var range=this.selection.getRangeAt(0);range.setStart(currnode,realoffset-curroffset)};curroffset-=currlength};currnode=currnode.prevSibling}} else{var range=this.selection.getRangeAt(0);range.setStart(offsetparent,0)}};this.moveEnd=function(offset){};this.reset=function(){this.selection=this.document.getWindow().getSelection()};this.cloneContents=function(){var range=this.selection.getRangeAt(0);return range.cloneContents()};this.containsNode=function(node){return this.selection.containsNode(node,true)}
this.toString=function(){return this.selection.toString()};this.getRange=function(){return this.selection.getRangeAt(0)}
this.restoreRange=function(range){var selection=this.selection;selection.removeAllRanges();selection.addRange(range)}};MozillaSelection.prototype=new BaseSelection;
function IESelection(document){this.document=document;this.selection=document.getDocument().selection;var doc=document.getDocument();var range=this.selection.createRange()
var parent=this.selection.type=="Text"?range.parentElement():this.selection.type=="Control"?range.parentElement:null;if(parent&&parent.ownerDocument!=doc){var range=doc.body.createTextRange();range.collapse();range.select()}
this.selectNodeContents=function(node){var range=this.selection.createRange().duplicate();range.moveToElementText(node);range.moveStart('character',1);range.moveStart('character',-1);range.moveEnd('character',-1);range.moveEnd('character',1);range.select();this.selection=this.document.getDocument().selection};this.collapse=function(collapseToEnd){var range=this.selection.createRange();range.collapse(!collapseToEnd);range.select();this.selection=document.getDocument().selection};this.replaceWithNode=function(newnode,selectAfterPlace){if(this.selection.type=='Control'){var range=this.selection.createRange();range.item(0).parentNode.replaceChild(newnode,range.item(0));for(var i=1;i<range.length;i++){range.item(i).parentNode.removeChild(range[i])};if(selectAfterPlace){var range=this.document.getDocument().body.createTextRange();range.moveToElementText(newnode);range.select()}} else{var document=this.document.getDocument();var range=this.selection.createRange();range.pasteHTML('<img id="kupu-tempnode">');tempnode=document.getElementById('kupu-tempnode');tempnode.replaceNode(newnode);if(selectAfterPlace){if(selectAfterPlace.nodeType==Node.ELEMENT_NODE){range.moveToElementText(selectAfterPlace)} else{range.moveToElementText(newnode)};range.select()}};this.reset();return newnode};this.startOffset=function(){var startoffset=0;var selrange=this.selection.createRange();var parent=selrange.parentElement();var elrange=selrange.duplicate();elrange.moveToElementText(parent);var tempstart=selrange.duplicate();while(elrange.compareEndPoints('StartToStart',tempstart)<0){startoffset++;tempstart.moveStart('character',-1)};return startoffset};this.endOffset=function(){var endoffset=0;var selrange=this.selection.createRange();var parent=selrange.parentElement();var elrange=selrange.duplicate();elrange.moveToElementText(parent);var tempend=selrange.duplicate();while(elrange.compareEndPoints('EndToEnd',tempend)>0){endoffset++;tempend.moveEnd('character',1)};return endoffset};this.getContentLength=function(){if(this.selection.type=='Control'){return this.selection.createRange().length};var contentlength=0;var range=this.selection.createRange();var endrange=range.duplicate();while(range.compareEndPoints('StartToEnd',endrange)<0){range.move('character',1);contentlength++};return contentlength};this.cutChunk=function(startOffset,endOffset){var range=this.selection.createRange().duplicate();range.moveStart('character',startOffset);range.moveEnd('character',-endOffset);range.pasteHTML('')};this.getElementLength=function(element){var length=0;var range=this.selection.createRange().duplicate();range.moveToElementText(element);range.moveStart('character',1);range.moveEnd('character',-1);var endpoint=range.duplicate();endpoint.collapse(false);range.collapse();while(!range.isEqual(endpoint)){range.moveEnd('character',1);range.moveStart('character',1);length++};return length};this.parentElement=function(){if(this.selection.type=='Control'){return this.selection.createRange().item(0)} else{return this.selection.createRange().parentElement()}};this.getSelectedNode=this.parentElement;this.moveStart=function(offset){var range=this.selection.createRange();range.moveStart('character',offset);range.select()};this.moveEnd=function(offset){var range=this.selection.createRange();range.moveEnd('character',offset);range.select()};this.reset=function(){this.selection=this.document.getDocument().selection};this.cloneContents=function(){var contents=this.selection.createRange().htmlText;var doc=this.document.getDocument();var docfrag=doc.createElement('span');docfrag.innerHTML=contents;return docfrag};this.containsNode=function(node){var selected=this.selection.createRange();if(this.selection.type.toLowerCase()=='text'){var range=doc.body.createTextRange();range.moveToElementText(node);if(selected.compareEndPoints('StartToEnd',range)>=0||selected.compareEndPoints('EndToStart',range)<=0){return false}
return true} else{for(var i=0;i<selected.length;i++){if(selected.item(i).contains(node)){return true}}
return false}};this.getRange=function(){return this.selection.createRange()}
this.restoreRange=function(range){try{range.select()} catch(e){}}
this.toString=function(){return this.selection.createRange().text}};IESelection.prototype=new BaseSelection;
function ContextFixer(func,context){this.func=func;this.context=context;this.args=arguments;var self=this;this.execute=function(){var args=new Array();for(var i=0;i<self.args.length-2;i++){args.push(self.args[i+2])};for(var i=0;i<arguments.length;i++){args.push(arguments[i])};return self.func.apply(self.context,args)}};
function Timer(){this.lastid=0;this.functions={};this.registerFunction=function(object,func,timeout){var args=new Array();for(var i=0;i<arguments.length-3;i++){args.push(arguments[i+3])}
var id=this._createUniqueId();this.functions[id]=new Array(object,func,args);setTimeout("timer_instance._handleFunction("+id+")",timeout)};this._handleFunction=function(id){var obj=this.functions[id][0];var func=this.functions[id][1];var args=this.functions[id][2];this.functions[id]=null;func.apply(obj,args)};this._createUniqueId=function(){while(this.lastid in this.functions&&this.functions[this.lastid]){this.lastid++;if(this.lastid>100000){this.lastid=0}}
return this.lastid}};timer_instance=new Timer();Array.prototype.contains=function(element,objectequality){for(var i=0;i<this.length;i++){if(objectequality){if(element===this[i]){return true}} else{if(element==this[i]){return true}}};return false};Array.prototype.removeDoubles=function(){var ret=[];for(var i=0;i<this.length;i++){if(!ret.contains(this[i])){ret.push(this[i])}};return ret};Array.prototype.map=function(func){for(var i=0;i<this.length;i++){this[i]=func(this[i])}};Array.prototype.reversed=function(){var ret=[];for(var i=this.length;i>0;i--){ret.push(this[i-1])};return ret};String.prototype.strip=function(){var stripspace=/^\s*([\s\S]*?)\s*$/;return stripspace.exec(this)[1]};String.prototype.reduceWhitespace=function(){var spacereg=/(\s+)/g;var copy=this;while(true){var match=spacereg.exec(copy);if(!match){return copy};copy=copy.replace(match[0],' ')}};String.prototype.entitize=function(){var ret=this.replace(/&/g,'&amp;');ret=ret.replace(/"/g,'&quot;');ret=ret.replace(/'/g, '&apos;');ret=ret.replace(/</g,'&lt;');ret=ret.replace(/>/g,'&gt;');return ret};String.prototype.deentitize=function(){var ret=this.replace(/&gt;/g,'>');ret=ret.replace(/&lt;/g,'<');ret=ret.replace(/&quot;/g,'"');ret=ret.replace(/&apos;/g,"'");ret=ret.replace(/&amp;/g,'&');return ret};String.prototype.urldecode=function(){var reg=/%([a-fA-F0-9]{2})/g;var str=this;while(true){var match=reg.exec(str);if(!match||!match.length){break};var repl=new RegExp(match[0],'g');str=str.replace(repl,String.fromCharCode(parseInt(match[1],16)))};return str};String.prototype.centerTruncate=function(maxlength){if(this.length<=maxlength){return this};var chunklength=maxlength/2-3;var start=this.substr(0,chunklength);var end=this.substr(this.length-chunklength);return start+' ... '+end};
function debug(str,win){if(!win){win=window};var doc=win.document;var div=doc.createElement('div');div.appendChild(doc.createTextNode(str));doc.getElementsByTagName('body')[0].appendChild(div)};
function Exception(){return};UpdateStateCancelBubble=new Exception();

/* - kupueditor.js - */
// http://10.228.150.75:8080/cms/portal_javascripts/kupueditor.js?original=1
function KupuDocument(iframe){this.editable=iframe;this.window=this.editable.contentWindow;this.document=this.window.document;this._browser=_SARISSA_IS_IE?'IE':'Mozilla';this.execCommand=function(command,arg){if(arg===undefined) arg=null;this.document.execCommand(command,false,arg)};this.reloadSource=function(){document.location=document.location};this.getDocument=function(){return this.document};this.getWindow=function(){return this.window};this.getSelection=function(){if(this._browser=='Mozilla'){return new MozillaSelection(this)} else{return new IESelection(this)}};this.getEditable=function(){return this.editable}};
function KupuEditor(document,config,logger){this.document=document;this.config=config;this.log=logger;this.tools={};this.filters=new Array();this._designModeSetAttempts=0;this._initialized=false;this._previous_range=null;this.content_changed=false;this.initialize=function(){this._initializeEventHandlers();if(this.getBrowserName()=="IE"){var body=this.getInnerDocument().getElementsByTagName('body')[0];body.setAttribute('contentEditable','true');this._initialized=true;if(this.afterInit){this.afterInit()};this._saveSelection()} else{this._setDesignModeWhenReady()};this.logMessage(_('Editor initialized'))};this.setContextMenu=function(menu){menu.initialize(this)};this.registerTool=function(id,tool){this.tools[id]=tool;tool.initialize(this)};this.getTool=function(id){return this.tools[id]};this.registerFilter=function(filter){this.filters.push(filter);filter.initialize(this)};this.updateStateHandler=function(event){var interesting_codes=new Array(8,13,37,38,39,40,46);this._saveSelection();if(event.type=='click'||event.type=='mouseup'||(event.type=='keyup'&&interesting_codes.contains(event.keyCode))){this.updateState(event)}};this.updateState=function(event){var selNode=this.getSelectedNode();for(var id in this.tools){try{this.tools[id].updateState(selNode,event)} catch(e){if(e==UpdateStateCancelBubble){this.updateState(event);break} else{this.logMessage(_('Exception while processing updateState on '+'${id}: ${msg}',{'id':id,'msg':e}),2)}}}};this.saveDocument=function(redirect,synchronous){if(!this.config.dst){this.logMessage(_('No destination URL available!'),2);return}
var sourcetool=this.getTool('sourceedittool');if(sourcetool){sourcetool.cancelSourceMode()};if(!this._initialized){return}
this._initialized=false;window.status=_("Please wait while saving document...");for(var id in this.tools){var tool=this.tools[id];if(tool.beforeSave){try{tool.beforeSave()} catch(e){alert(e);this._initialized=true;return}}};this.logMessage(_("Starting HTML cleanup"));var transform=this._filterContent(this.getInnerDocument().documentElement);var contents=this._serializeOutputToString(transform);this.logMessage(_("Cleanup done, sending document to server"));var request=new XMLHttpRequest();if(!synchronous){request.onreadystatechange=(new ContextFixer(this._saveCallback,this,request,redirect)).execute;request.open("PUT",this.config.dst,true);request.setRequestHeader("Content-type",this.config.content_type);request.send(contents);this.logMessage(_("Request sent to server"))} else{this.logMessage(_('Sending request to server'));request.open("PUT",this.config.dst,false);request.setRequestHeader("Content-type",this.config.content_type);request.send(contents);this.handleSaveResponse(request,redirect)}};this.prepareForm=function(form,id){var sourcetool=this.getTool('sourceedittool');if(sourcetool){sourcetool.cancelSourceMode()};if(!this._initialized){return}
this._initialized=false;window.status=_("Please wait while saving document...");for(var tid in this.tools){var tool=this.tools[tid];if(tool.beforeSave){try{tool.beforeSave()} catch(e){alert(e);this._initialized=true;return}}};if(!id){id='kupu'};this.logMessage(_("Starting HTML cleanup"));var transform=this._filterContent(this.getInnerDocument().documentElement);var contents=this._serializeOutputToString(transform);this.logMessage(_("Cleanup done, sending document to server"));var document=form.ownerDocument?form.ownerDocument:window.document;var ta=document.createElement('textarea');ta.style.visibility='hidden';var text=document.createTextNode(contents);ta.appendChild(text);ta.setAttribute('name',id);form.appendChild(ta);return true};this.execCommand=function(command,param){if(!this._initialized){this.logMessage(_('Editor not initialized yet!'));return};if(this.getBrowserName()=="IE"){this._restoreSelection()} else{this.focusDocument();if(command!='useCSS'){this.content_changed=true;this.getDocument().execCommand('useCSS',!this.config.use_css)}};this.getDocument().execCommand(command,param);var message=_('Command ${command} executed',{'command':command});if(param){message=_('Command ${command} executed with parameter ${param}',{'command':command,'param':param})}
this.updateState();this.logMessage(message)};this.getSelection=function(){this._restoreSelection();return this.getDocument().getSelection()};this.getSelectedNode=function(){return this.getSelection().parentElement()};this.getNearestParentOfType=function(node,type){var type=type.toLowerCase();while(node){if(node.nodeName.toLowerCase()==type){return node}
var node=node.parentNode}
return false};this.removeNearestParentOfType=function(node,type){var nearest=this.getNearestParentOfType(node,type);if(!nearest){return false};var parent=nearest.parentNode;while(nearest.childNodes.length){var child=nearest.firstChild;child=nearest.removeChild(child);parent.insertBefore(child,nearest)};parent.removeChild(nearest)};this.getDocument=function(){return this.document};this.getInnerDocument=function(){return this.getDocument().getDocument()};this.insertNodeAtSelection=function(insertNode,selectNode){if(!this._initialized){this.logMessage(_('Editor not initialized yet!'));return};this.content_changed=true;var browser=this.getBrowserName();if(browser!="IE"){this.focusDocument()};var ret=this.getSelection().replaceWithNode(insertNode,selectNode);this._saveSelection();return ret};this.focusDocument=function(){this.getDocument().getWindow().focus()}
this.logMessage=function(message,severity){this.log.log(message,severity)};this.registerContentChanger=function(element){addEventHandler(element,'change', function(){this.content_changed=true},this)};this.getBrowserName=function(){if(_SARISSA_IS_MOZ){return "Mozilla"} else if(_SARISSA_IS_IE){return "IE"} else{throw _("Browser not supported!")}};this.handleSaveResponse=function(request,redirect){if(request.status!='200'&&request.status!='204'&&request.status!='1223'){var msg=_('Error saving your data.\nResponse status: '+'${status}.\nCheck your server log for more '+'information.',{'status':request.status});alert(msg);window.status=_("Error saving document")} else if(redirect){window.document.location=redirect;this.content_changed=false} else{this.content_changed=false;if(this.config.reload_after_save){this.reloadSrc()};window.status=_("Document saved")};this._initialized=true};this._addEventHandler=addEventHandler;this._saveCallback=function(request,redirect){if(request.readyState==4){this.handleSaveResponse(request,redirect)}};this.reloadSrc=function(){this.getDocument().reloadSource();if(this.getBrowserName()=="Mozilla"){this.getInnerDocument().designMode="On"}};this._initializeEventHandlers=function(){this._addEventHandler(this.getInnerDocument(),"click",this.updateStateHandler,this);this._addEventHandler(this.getInnerDocument(),"dblclick",this.updateStateHandler,this);this._addEventHandler(this.getInnerDocument(),"keyup",this.updateStateHandler,this);this._addEventHandler(this.getInnerDocument(),"keyup", function(){this.content_changed=true},this);this._addEventHandler(this.getInnerDocument(),"mouseup",this.updateStateHandler,this)};this._setDesignModeWhenReady=function(){this._designModeSetAttempts++;if(this._designModeSetAttempts>25){alert(_('Couldn\'t set design mode. Kupu will not work on this browser.'));return};var success=false;try{this._setDesignMode();success=true} catch(e){timer_instance.registerFunction(this,this._setDesignModeWhenReady,100)};if(success){if(this.afterInit){this.afterInit()}}};this._setDesignMode=function(){this.getInnerDocument().designMode="On";this.execCommand("undo");this._initialized=true};this._saveSelection=function(){if(this._isDocumentSelected()){var currange=this.getInnerDocument().selection.createRange();this._previous_range=currange}};this._restoreSelection=function(){if(this._previous_range&&!this._isDocumentSelected()){try{this._previous_range.select()} catch(e){alert("Error placing back selection");this.logMessage(_('Error placing back selection'))}}};if(this.getBrowserName()!="IE"){this._saveSelection=function(){};this._restoreSelection=function(){}}
this._isDocumentSelected=function(){var editable_body=this.getInnerDocument().getElementsByTagName('body')[0];try{var selrange=this.getInnerDocument().selection.createRange()} catch(e){return false}
var someelement=selrange.parentElement?selrange.parentElement():selrange.item(0);while(someelement.nodeName.toLowerCase()!='body'){someelement=someelement.parentNode};return someelement==editable_body};this._clearSelection=function(){this._previous_range=null};this._filterContent=function(documentElement){var xhtmldoc=Sarissa.getDomDocument();var doc=this._convertToSarissaNode(xhtmldoc,documentElement);for(var i=0;i<this.filters.length;i++){var doc=this.filters[i].filter(xhtmldoc,doc)};this._fixXML(doc,xhtmldoc);return doc};this.getXMLBody=function(transform){var bodies=transform.getElementsByTagName('body');var data='';for(var i=0;i<bodies.length;i++){data+=Sarissa.serialize(bodies[i])}
return this.layoutsource(this.escapeEntities(data))};this.getHTMLBody=function(){var doc=this.getInnerDocument();var docel=doc.documentElement;var bodies=docel.getElementsByTagName('body');var data='';for(var i=0;i<bodies.length;i++){data+=bodies[i].innerHTML}
return this.layoutsource(this.escapeEntities(data))};this.setHTMLBody=function(text){var bodies=this.getInnerDocument().documentElement.getElementsByTagName('body');for(var i=0;i<bodies.length-1;i++){bodies[i].parentNode.removeChild(bodies[i])}
bodies[bodies.length-1].innerHTML=text};this._fixXML=function(doc,document){var heads=doc.getElementsByTagName('head');var titles=doc.getElementsByTagName('title');if(!heads.length){var body=doc.getElementsByTagName('body')[0];var head=document.createElement('head');body.parentNode.insertBefore(head,body);var title=document.createElement('title');var titletext=document.createTextNode('');head.appendChild(title);title.appendChild(titletext)} else if(!titles.length){var head=heads[0];var title=document.createElement('title');var titletext=document.createTextNode('');head.appendChild(title);title.appendChild(titletext)};var dualtons=new Array('a','abbr','acronym','address','applet','b','bdo','big','blink','blockquote','button','caption','center','cite','comment','del','dfn','dir','div','dl','dt','em','embed','fieldset','font','form','frameset','h1','h2','h3','h4','h5','h6','i','iframe','ins','kbd','label','legend','li','listing','map','marquee','menu','multicol','nobr','noembed','noframes','noscript','object','ol','optgroup','option','p','pre','q','s','script','select','small','span','strike','strong','style','sub','sup','table','tbody','td','textarea','tfoot','th','thead','title','tr','tt','u','ul','xmp');for(var i=0;i<dualtons.length;i++){var elname=dualtons[i];var els=doc.getElementsByTagName(elname);for(var j=0;j<els.length;j++){var el=els[j];if(!el.hasChildNodes()){var child=document.createTextNode('');el.appendChild(child)}}}};this.xhtmlvalid=new XhtmlValidation(this);this._convertToSarissaNode=function(ownerdoc,htmlnode){return this.xhtmlvalid._convertToSarissaNode(ownerdoc,htmlnode)};this._fixupSingletons=function(xml){return xml.replace(/<([^>]+)\/>/g,"<$1 />")}
this._serializeOutputToString=function(transform){if(this.config.strict_output){var contents='<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" '+'"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">\n'+'<html xmlns="http://www.w3.org/1999/xhtml">'+Sarissa.serialize(transform.getElementsByTagName("head")[0])+Sarissa.serialize(transform.getElementsByTagName("body")[0])+'</html>'} else{var contents='<html>'+Sarissa.serialize(transform.getElementsByTagName("head")[0])+Sarissa.serialize(transform.getElementsByTagName("body")[0])+'</html>'};contents=this.escapeEntities(contents);if(this.config.compatible_singletons){contents=this._fixupSingletons(contents)};return contents};this.layoutsource=function(data){data=data.replace(/\s*(<(p|div|h.|ul|ol|dl|menu|dir|pre|blockquote|address|center|table|thead|tbody|tfoot|tr|th|td))\b/ig,'\n$1');data=data.replace(/\s*(<\/(p|div|h.|ul|ol|dl|menu|dir|pre|blockquote|address|center|table|thead|tbody|tfoot|tr|th|td)>)\s*/ig,'$1\n');return data.strip()}
this.escapeEntities=function(xml){return xml;return xml.replace(/[^\r\n -\177]/g,
function(c){return '&#'+c.charCodeAt(0)+';'})}
this.getFullEditor=function(){var fulleditor=this.getDocument().getEditable();while(!/kupu-fulleditor/.test(fulleditor.className)){fulleditor=fulleditor.parentNode}
return fulleditor}
this.setClass=function(name){this.getFullEditor().className+=' '+name}
this.clearClass=function(name){var fulleditor=this.getFullEditor();fulleditor.className=fulleditor.className.replace(' '+name,'')}
this.suspendEditing=function(){this._previous_range=this.getSelection().getRange();this.setClass('kupu-modal');for(var id in this.tools){this.tools[id].disable()}
if(this.getBrowserName()=="IE"){var body=this.getInnerDocument().getElementsByTagName('body')[0];body.setAttribute('contentEditable','false')} else{this.getInnerDocument().designMode="Off";var iframe=this.getDocument().getEditable();iframe.style.position=iframe.style.position?"":"relative"}
this.suspended=true}
this.resumeEditing=function(){if(!this.suspended){return}
this.suspended=false;this.clearClass('kupu-modal');for(var id in this.tools){this.tools[id].enable()}
if(this.getBrowserName()=="IE"){this._restoreSelection();var body=this.getInnerDocument().getElementsByTagName('body')[0];body.setAttribute('contentEditable','true')} else{var doc=this.getInnerDocument();doc.designMode="On";this.getSelection().restoreRange(this._previous_range)}}}


/* - kupubasetools.js - */
// http://10.228.150.75:8080/cms/portal_javascripts/kupubasetools.js?original=1
function KupuTool(){this.toolboxes={};this.initialize=function(editor){this.editor=editor};this.registerToolBox=function(id,toolbox){this.toolboxes[id]=toolbox;toolbox.initialize(this,this.editor)};this.updateState=function(selNode,event){for(id in this.toolboxes){this.toolboxes[id].updateState(selNode,event)}};this.enable=function(){}
this.disable=function(){}
addEventHandler=addEventHandler;this._selectSelectItem=function(select,item){this.editor.logMessage(_('Deprecation warning: KupuTool._selectSelectItem'))};this._fixTabIndex=function(element){var tabIndex=this.editor.getDocument().getEditable().tabIndex-1;if(tabIndex&&!element.tabIndex){element.tabIndex=tabIndex}}}
function KupuToolBox(){this.initialize=function(tool,editor){this.tool=tool;this.editor=editor};this.updateState=function(selNode,event){};this._selectSelectItem=function(select,item){this.editor.logMessage(_('Deprecation warning: KupuToolBox._selectSelectItem'))}};
function NoContextMenu(object){object.createContextMenuElements=function(selNode,event){return []}
return object}
function KupuButtonDisable(button){button=button||this.button;button.disabled="disabled";button.className+=' disabled'}
function KupuButtonEnable(button){button=button||this.button;button.disabled="";button.className=button.className.replace(/ *\bdisabled\b/g,'')}
function KupuButton(buttonid,commandfunc,tool){this.buttonid=buttonid;this.button=getFromSelector(buttonid);this.commandfunc=commandfunc;this.tool=tool;this.initialize=function(editor){this.editor=editor;this._fixTabIndex(this.button);addEventHandler(this.button,'click',this.execCommand,this)};this.execCommand=function(){this.commandfunc(this,this.editor,this.tool)};this.updateState=function(selNode,event){};this.disable=KupuButtonDisable;this.enable=KupuButtonEnable};KupuButton.prototype=new KupuTool;
function KupuStateButton(buttonid,commandfunc,checkfunc,offclass,onclass){this.buttonid=buttonid;this.button=getFromSelector(buttonid);this.commandfunc=commandfunc;this.checkfunc=checkfunc;this.offclass=offclass;this.onclass=onclass;this.pressed=false;this.execCommand=function(){this.button.className=(this.pressed?this.offclass:this.onclass);this.pressed=!this.pressed;this.editor.focusDocument();this.commandfunc(this,this.editor)};this.updateState=function(selNode,event){var currclass=this.button.className;var newclass=null;if(this.checkfunc(selNode,this,this.editor,event)){newclass=this.onclass;this.pressed=true} else{newclass=this.offclass;this.pressed=false};if(currclass!=newclass){this.button.className=newclass}}};KupuStateButton.prototype=new KupuButton;
function KupuLateFocusStateButton(buttonid,commandfunc,checkfunc,offclass,onclass){KupuStateButton.apply(this,[buttonid,commandfunc,checkfunc,offclass,onclass]);this.execCommand=function(){this.button.className=(this.pressed?this.offclass:this.onclass);this.pressed=!this.pressed;this.commandfunc(this,this.editor);this.editor.focusDocument()}}
KupuLateFocusStateButton.prototype=new KupuStateButton;
function KupuRemoveElementButton(buttonid,element_name,cssclass){this.button=getFromSelector(buttonid);this.onclass='invisible';this.offclass=cssclass;this.pressed=false;this.commandfunc=function(button,editor){editor.removeNearestParentOfType(editor.getSelectedNode(),element_name)};this.checkfunc=function(currnode,button,editor,event){var element=editor.getNearestParentOfType(currnode,element_name);return(element?false:true)}};KupuRemoveElementButton.prototype=new KupuStateButton;
function KupuUI(textstyleselectid){this.tsselect=getFromSelector(textstyleselectid);var paraoptions=[];var tableoptions=[];this.optionstate=-1;this.otherstyle=null;this.tablestyles={};this.styles={};this.initialize=function(editor){this.editor=editor;this.cleanStyles();this.enableOptions(false);this._fixTabIndex(this.tsselect);this._selectevent=addEventHandler(this.tsselect,'change',this.setTextStyleHandler,this)};this.getStyles=function(){if(!paraoptions){this.cleanStyles()}
return [paraoptions,tableoptions]}
this.setTextStyleHandler=function(event){this.setTextStyle(this.tsselect.options[this.tsselect.selectedIndex].value)};this.basicButtonHandler=function(action){this.editor.execCommand(action);this.editor.updateState()};this.saveButtonHandler=function(){this.editor.saveDocument()};this.saveAndExitButtonHandler=function(redirect_url){this.editor.saveDocument(redirect_url)};this.cutButtonHandler=function(){try{this.editor.execCommand('Cut')} catch(e){if(this.editor.getBrowserName()=='Mozilla'){alert(_('Cutting from JavaScript is disabled on your Mozilla due to security settings. For more information, read http://www.mozilla.org/editor/midasdemo/securityprefs.html'))} else{throw e}};this.editor.updateState()};this.copyButtonHandler=function(){try{this.editor.execCommand('Copy')} catch(e){if(this.editor.getBrowserName()=='Mozilla'){alert(_('Copying from JavaScript is disabled on your Mozilla due to security settings. For more information, read http://www.mozilla.org/editor/midasdemo/securityprefs.html'))} else{throw e}};this.editor.updateState()};this.pasteButtonHandler=function(){try{this.editor.execCommand('Paste')} catch(e){if(this.editor.getBrowserName()=='Mozilla'){alert(_('Pasting from JavaScript is disabled on your Mozilla due to security settings. For more information, read http://www.mozilla.org/editor/midasdemo/securityprefs.html'))} else{throw e}};this.editor.updateState()};this.cleanStyles=function(){var options=this.tsselect.options;var parastyles=this.styles;var tablestyles=this.tablestyles;tableoptions.push([options[0].text,'td|']);tablestyles['td']=0;paraoptions.push([options[0].text,'p|']);parastyles['p']=0;while(options.length>1){opt=options[1];var v=opt.value;if (/^thead|tbody|table|t[rdh]\b/i.test(v)){var otable=tableoptions;var styles=tablestyles} else{var otable=paraoptions;var styles=parastyles}
if(v.indexOf('|')>-1){var split=v.split('|');v=split[0].toLowerCase()+"|"+split[1]} else{v=v.toLowerCase()+"|"};otable.push([opt.text,v]);styles[v]=otable.length-1;options[1]=null}
options[0]=null}
this.enableOptions=function(inTable){var select=this.tsselect;var options=select.options;if(this.otherstyle){options[options.length-1]=null;this.otherstyle=null}
if(this.optionstate==inTable) return;var valid=inTable?tableoptions:paraoptions;while(options.length) options[0]=null;this.otherstyle=null;for(var i=0;i<valid.length;i++){var opt=document.createElement('option');opt.text=valid[i][0];opt.value=valid[i][1];options.add(opt)}
select.selectedIndex=0;this.optionstate=inTable}
this.setIndex=function(currnode,tag,index,styles){var className=currnode.className;this.styletag=tag;this.classname=className;var style=tag+'|'+className;if(style in styles){return styles[style]} else if(!className&&tag in styles){return styles[tag]}
return index}
this.nodeStyle=function(node){var currnode=node;var index=-1;var options=this.tsselect.options;this.styletag=undefined;this.classname='';this.intable=false;while(currnode){var tag=currnode.nodeName.toLowerCase();if (/^body$/.test(tag)){if(!this.styletag){return-1}
break}
if (/^(p|div|h.|ul|ol|dl|menu|dir|pre|blockquote|address|center)$/.test(tag)){index=this.setIndex(currnode,tag,index,this.styles)}
if (/^thead|tbody|table|t[rdh]$/.test(tag)){this.intable=true;index=this.setIndex(currnode,tag,index,this.tablestyles);if(index>0||tag=='table'){return index}}
currnode=currnode.parentNode}
return index}
this.updateState=function(selNode){var index=undefined;var mixed=false;var styletag,classname;var selection=this.editor.getSelection();for(var el=selNode.firstChild;el;el=el.nextSibling){if(el.nodeType==1&&selection.containsNode(el)){var i=this.nodeStyle(el);if(index===undefined){index=i;styletag=this.styletag;classname=this.classname}
if(index!=i||styletag!=this.styletag||classname!=this.classname){mixed=true;break}}};if(index===undefined){index=this.nodeStyle(selNode)}
this.enableOptions(this.intable);if(index<0||mixed){if(mixed){var caption='Mixed styles'} else if(this.styletag){var caption='Other: '+this.styletag+' '+this.classname} else{var caption='<no style>'}
var opt=document.createElement('option');opt.text=caption;this.otherstyle=opt;this.tsselect.options.add(opt);index=this.tsselect.length-1}
this.tsselect.selectedIndex=Math.max(index,0)};this._cleanNode=function(node){var len=node.childNodes.length;
function stripspace(){var c;while((c=node.lastChild)&&c.nodeType==3&&/^\s*$/.test(c.data)){node.removeChild(c)}}
stripspace();var c=node.lastChild;if(c&&c.nodeType==1&&c.tagName=='BR'){node.removeChild(c)}
stripspace();if(node.childNodes.length==0){node.parentNode.removeChild(node)}}
this._cleanCell=function(eltype,classname){var selNode=this.editor.getSelectedNode();var el=this.editor.getNearestParentOfType(selNode,eltype);if(!el){el=this.editor.getNearestParentOfType(selNode,eltype=='TD'?'TH':'TD')}
if(!el) return;var node,nxt,n;for(node=el.firstChild;node;){if (/DIV|P/.test(node.nodeName)){for(var n=node.firstChild;n;){var nxt=n.nextSibling;el.insertBefore(n,node);n=nxt}
nxt=node.nextSibling;el.removeChild(node);node=nxt} else{node=node.nextSibling}}
if(eltype!=el.tagName){var node=el.ownerDocument.createElement(eltype);var parent=el.parentNode;parent.insertBefore(node,el);while(el.firstChild){node.appendChild(el.firstChild)}
parent.removeChild(el);el=node}
if(classname){el.className=classname} else{el.removeAttribute("class");el.removeAttribute("className")}}
this._setClass=function(el,classname){var parent=el.parentNode;if(parent.tagName=='DIV'){var gp=parent.parentNode;if(el!=parent.firstChild){var previous=parent.cloneNode(false);while(el!=parent.firstChild){previous.appendChild(parent.firstChild)}
gp.insertBefore(previous,parent);this._cleanNode(previous)}
gp.insertBefore(el,parent);this._cleanNode(el);this._cleanNode(parent)} else{this._cleanNode(el)}
if(classname){el.className=classname} else{el.removeAttribute("class");el.removeAttribute("className")}}
this.setTextStyle=function(style,noupdate){var classname='';var eltype=style.toUpperCase();if(style.indexOf('|')>-1){style=style.split('|');eltype=style[0].toUpperCase();classname=style[1]};var command=eltype;if(this.editor.getBrowserName()=='IE'){command='<'+eltype+'>'};if (/T[RDH]/.test(eltype)){this._cleanCell(eltype,classname)}
else{this.editor.getDocument().execCommand('formatblock',command);var selNode=this.editor.getSelectedNode();var el=this.editor.getNearestParentOfType(selNode,eltype);if(el){this._setClass(el,classname)} else{var selection=this.editor.getSelection();var elements=selNode.getElementsByTagName(eltype);for(var i=0;i<elements.length;i++){el=elements[i];if(selection.containsNode(el)){this._setClass(el,classname)}}}}
if(el){this.editor.getSelection().selectNodeContents(el)}
if(!noupdate){this.editor.updateState()}};this.createContextMenuElements=function(selNode,event){var ret=new Array();ret.push(new ContextMenuElement(_('Cut'),this.cutButtonHandler,this));ret.push(new ContextMenuElement(_('Copy'),this.copyButtonHandler,this));ret.push(new ContextMenuElement(_('Paste'),this.pasteButtonHandler,this));return ret};this.disable=function(){this.tsselect.disabled="disabled"}
this.enable=function(){this.tsselect.disabled=""}}
KupuUI.prototype=new KupuTool;
function ColorchooserTool(fgcolorbuttonid,hlcolorbuttonid,colorchooserid){this.fgcolorbutton=getFromSelector(fgcolorbuttonid);this.hlcolorbutton=getFromSelector(hlcolorbuttonid);this.ccwindow=getFromSelector(colorchooserid);this.command=null;this.initialize=function(editor){this.editor=editor;this.createColorchooser(this.ccwindow);addEventHandler(this.fgcolorbutton,"click",this.openFgColorChooser,this);addEventHandler(this.hlcolorbutton,"click",this.openHlColorChooser,this);addEventHandler(this.ccwindow,"click",this.chooseColor,this);this.hide();this.editor.logMessage(_('Colorchooser tool initialized'))};this.updateState=function(selNode){this.hide()};this.openFgColorChooser=function(){this.command="forecolor";this.show()};this.openHlColorChooser=function(){if(this.editor.getBrowserName()=="IE"){this.command="backcolor"} else{this.command="hilitecolor"}
this.show()};this.chooseColor=function(event){var target=_SARISSA_IS_MOZ?event.target:event.srcElement;var cell=this.editor.getNearestParentOfType(target,'td');this.editor.execCommand(this.command,cell.getAttribute('bgColor'));this.hide();this.editor.logMessage(_('Color chosen'))};this.show=function(command){this.ccwindow.style.display="block"};this.hide=function(){this.command=null;this.ccwindow.style.display="none"};this.createColorchooser=function(table){var chunks=new Array('00','33','66','99','CC','FF');table.setAttribute('id','kupu-colorchooser-table');table.style.borderWidth='2px';table.style.borderStyle='solid';table.style.position='absolute';table.style.cursor='default';table.style.display='none';var tbody=document.createElement('tbody');for(var i=0;i<6;i++){var tr=document.createElement('tr');var r=chunks[i];for(var j=0;j<6;j++){var g=chunks[j];for(var k=0;k<6;k++){var b=chunks[k];var color='#'+r+g+b;var td=document.createElement('td');td.setAttribute('bgColor',color);td.style.backgroundColor=color;td.style.borderWidth='1px';td.style.borderStyle='solid';td.style.fontSize='1px';td.style.width='10px';td.style.height='10px';var text=document.createTextNode('\u00a0');td.appendChild(text);tr.appendChild(td)}}
tbody.appendChild(tr)}
table.appendChild(tbody);return table};this.enable=function(){KupuButtonEnable(this.fgcolorbutton);KupuButtonEnable(this.hlcolorbutton)}
this.disable=function(){KupuButtonDisable(this.fgcolorbutton);KupuButtonDisable(this.hlcolorbutton)}}
ColorchooserTool.prototype=new KupuTool;
function PropertyTool(titlefieldid,descfieldid){this.titlefield=getFromSelector(titlefieldid);this.descfield=getFromSelector(descfieldid);this.initialize=function(editor){this.editor=editor;addEventHandler(this.titlefield,"change",this.updateProperties,this);addEventHandler(this.descfield,"change",this.updateProperties,this);var heads=this.editor.getInnerDocument().getElementsByTagName('head');if(!heads[0]){this.editor.logMessage(_('No head in document!'),1)} else{var head=heads[0];var titles=head.getElementsByTagName('title');if(titles.length){this.titlefield.value=titles[0].text}
var metas=head.getElementsByTagName('meta');if(metas.length){for(var i=0;i<metas.length;i++){var meta=metas[i];if(meta.getAttribute('name')&&meta.getAttribute('name').toLowerCase()=='description'){this.descfield.value=meta.getAttribute('content');break}}}}
this.editor.logMessage(_('Property tool initialized'))};this.updateProperties=function(){var doc=this.editor.getInnerDocument();var heads=doc.getElementsByTagName('HEAD');if(!heads){this.editor.logMessage(_('No head in document!'),1);return}
var head=heads[0];var titles=head.getElementsByTagName('title');if(!titles){var title=doc.createElement('title');var text=doc.createTextNode(this.titlefield.value);title.appendChild(text);head.appendChild(title)} else{var title=titles[0];if(title.childNodes.length==0){title.removeNode(true);title=doc.createElement('title');title.innerText=this.titlefield.value;head.appendChild(title)} else{title.childNodes[0].nodeValue=this.titlefield.value}}
document.title=this.titlefield.value;var metas=doc.getElementsByTagName('meta');var descset=0;for(var i=0;i<metas.length;i++){var meta=metas[i];if(meta.getAttribute('name')&&meta.getAttribute('name').toLowerCase()=='description'){meta.setAttribute('content',this.descfield.value);descset=1}}
if(!descset){var meta=doc.createElement('meta');meta.setAttribute('name','description');meta.setAttribute('content',this.descfield.value);head.appendChild(meta)}
this.editor.logMessage(_('Properties modified'))}}
PropertyTool.prototype=new KupuTool;
function LinkTool(){this.initialize=function(editor){this.editor=editor;this.editor.logMessage(_('Link tool initialized'))};this.createLinkHandler=function(event){var linkWindow=openPopup('kupupopups/link.html',300,200);linkWindow.linktool=this;linkWindow.focus()};this.updateLink=function(linkel,url,type,name,target,title){if(type&&type=='anchor'){linkel.removeAttribute('href');linkel.setAttribute('name',name)} else{linkel.href=url;if(linkel.innerHTML==""){var doc=this.editor.getInnerDocument();linkel.appendChild(doc.createTextNode(title||url))}
if(title){linkel.title=title} else{linkel.removeAttribute('title')}
if(target){linkel.setAttribute('target',target)}
else{linkel.removeAttribute('target')};linkel.style.color=this.linkcolor}};this.formatSelectedLink=function(url,type,name,target,title){var currnode=this.editor.getSelectedNode();var linkel=this.editor.getNearestParentOfType(currnode,'A');if(linkel){this.updateLink(linkel,url,type,name,target,title);return true}
if(currnode.nodeType!=1) return false;var linkelements=currnode.getElementsByTagName('A');var selection=this.editor.getSelection();var containsLink=false;for(var i=0;i<linkelements.length;i++){linkel=linkelements[i];if(selection.containsNode(linkel)){this.updateLink(linkel,url,type,name,target,title);containsLink=true}};return containsLink}
this.createLink=function(url,type,name,target,title){if(!this.formatSelectedLink(url,type,name,target,title)){this.editor.execCommand("CreateLink",url);if(!this.formatSelectedLink(url,type,name,target,title)){var doc=this.editor.getInnerDocument();linkel=doc.createElement("a");linkel.setAttribute('href',url);linkel.setAttribute('class','generated');this.editor.getSelection().replaceWithNode(linkel,true);this.updateLink(linkel,url,type,name,target,title)}}
this.editor.logMessage(_('Link added'));this.editor.updateState()};this.deleteLink=function(){var currnode=this.editor.getSelectedNode();var linkel=this.editor.getNearestParentOfType(currnode,'a');if(!linkel){this.editor.logMessage(_('Not inside link'));return};while(linkel.childNodes.length){linkel.parentNode.insertBefore(linkel.childNodes[0],linkel)};linkel.parentNode.removeChild(linkel);this.editor.logMessage(_('Link removed'));this.editor.updateState()};this.createContextMenuElements=function(selNode,event){var ret=new Array();var link=this.editor.getNearestParentOfType(selNode,'a');if(link){ret.push(new ContextMenuElement(_('Delete link'),this.deleteLink,this))} else{ret.push(new ContextMenuElement(_('Create link'),this.createLinkHandler,this))};return ret}}
LinkTool.prototype=new KupuTool;
function LinkToolBox(inputid,buttonid,toolboxid,plainclass,activeclass){this.input=getFromSelector(inputid);this.button=getFromSelector(buttonid);this.toolboxel=getFromSelector(toolboxid);this.plainclass=plainclass;this.activeclass=activeclass;this.initialize=function(tool,editor){this.tool=tool;this.editor=editor;addEventHandler(this.input,"blur",this.updateLink,this);addEventHandler(this.button,"click",this.addLink,this)};this.updateState=function(selNode){var linkel=this.editor.getNearestParentOfType(selNode,'a');if(linkel){if(this.toolboxel){this.toolboxel.className=this.activeclass};this.input.value=linkel.getAttribute('href')} else{if(this.toolboxel){this.toolboxel.className=this.plainclass};this.input.value=''}};this.addLink=function(event){var url=this.input.value;this.tool.createLink(url)};this.updateLink=function(){var currnode=this.editor.getSelectedNode();var linkel=this.editor.getNearestParentOfType(currnode,'A');if(!linkel){return}
var url=this.input.value;linkel.setAttribute('href',url);this.editor.logMessage(_('Link modified'))}};LinkToolBox.prototype=new LinkToolBox;
function ImageTool(){this.initialize=function(editor){this.editor=editor;this.editor.logMessage(_('Image tool initialized'))};this.createImageHandler=function(event){var imageWindow=openPopup('kupupopups/image.html',300,200);imageWindow.imagetool=this;imageWindow.focus()};this.createImage=function(url,alttext,imgclass){var img=this.editor.getInnerDocument().createElement('img');img.src=url;img.removeAttribute('height');img.removeAttribute('width');if(alttext){img.alt=alttext};if(imgclass){img.className=imgclass};img=this.editor.insertNodeAtSelection(img,1);this.editor.logMessage(_('Image inserted'));this.editor.updateState();return img};this.setImageClass=function(imgclass){var currnode=this.editor.getSelectedNode();var currimg=this.editor.getNearestParentOfType(currnode,'IMG');if(currimg){currimg.className=imgclass}};this.createContextMenuElements=function(selNode,event){return new Array(new ContextMenuElement(_('Create image'),this.createImageHandler,this))}}
ImageTool.prototype=new KupuTool;
function ImageToolBox(inputfieldid,insertbuttonid,classselectid,toolboxid,plainclass,activeclass){this.inputfield=getFromSelector(inputfieldid);this.insertbutton=getFromSelector(insertbuttonid);this.classselect=getFromSelector(classselectid);this.toolboxel=getFromSelector(toolboxid);this.plainclass=plainclass;this.activeclass=activeclass;this.initialize=function(tool,editor){this.tool=tool;this.editor=editor;addEventHandler(this.classselect,"change",this.setImageClass,this);addEventHandler(this.insertbutton,"click",this.addImage,this)};this.updateState=function(selNode,event){var imageel=this.editor.getNearestParentOfType(selNode,'img');if(imageel){if(this.toolboxel){this.toolboxel.className=this.activeclass;this.inputfield.value=imageel.getAttribute('src');var imgclass=imageel.className?imageel.className:'image-inline';selectSelectItem(this.classselect,imgclass)}} else{if(this.toolboxel){this.toolboxel.className=this.plainclass}}};this.addImage=function(){var url=this.inputfield.value;var sel_class=this.classselect.options[this.classselect.selectedIndex].value;this.tool.createImage(url,null,sel_class);this.editor.focusDocument()};this.setImageClass=function(){var sel_class=this.classselect.options[this.classselect.selectedIndex].value;this.tool.setImageClass(sel_class);this.editor.focusDocument()}};ImageToolBox.prototype=new KupuToolBox;
function TableTool(){this.createContextMenuElements=function(selNode,event){var table=this.editor.getNearestParentOfType(selNode,'table');if(!table){ret=new Array();var el=new ContextMenuElement(_('Add table'),this.addPlainTable,this);ret.push(el);return ret} else{var ret=new Array();ret.push(new ContextMenuElement(_('Add row'),this.addTableRow,this));ret.push(new ContextMenuElement(_('Delete row'),this.delTableRow,this));ret.push(new ContextMenuElement(_('Add column'),this.addTableColumn,this));ret.push(new ContextMenuElement(_('Delete column'),this.delTableColumn,this));ret.push(new ContextMenuElement(_('Delete Table'),this.delTable,this));return ret}};this.addPlainTable=function(){this.createTable(2,3,1,'plain')};this.createTable=function(rows,cols,makeHeader,tableclass){if(rows<1||rows>99||cols<1||cols>99){this.editor.logMessage(_('Invalid table size'),1);return};var doc=this.editor.getInnerDocument();table=doc.createElement("table");table.className=tableclass;if(makeHeader){var tr=doc.createElement("tr");var thead=doc.createElement("thead");for(i=0;i<cols;i++){var th=doc.createElement("th");th.appendChild(doc.createTextNode("Col "+i+1));tr.appendChild(th)}
thead.appendChild(tr);table.appendChild(thead)}
tbody=doc.createElement("tbody");for(var i=0;i<rows;i++){var tr=doc.createElement("tr");for(var j=0;j<cols;j++){var td=doc.createElement("td");var content=doc.createTextNode('\u00a0');td.appendChild(content);tr.appendChild(td)}
tbody.appendChild(tr)}
table.appendChild(tbody);this.editor.insertNodeAtSelection(table);this._setTableCellHandlers(table);this.editor.logMessage(_('Table added'));this.editor.updateState();return table};this._setTableCellHandlers=function(table){addEventHandler(table,'click',this._selectContentIfEmpty,this);var cells=table.getElementsByTagName('td');for(var i=0;i<cells.length;i++){addEventHandler(cells[i],'click',this._selectContentIfEmpty,this)};var firstcell=cells[0];if(firstcell){var children=firstcell.childNodes;if(children.length==1&&children[0].nodeType==3&&children[0].nodeValue=='\xa0'){var selection=this.editor.getSelection();selection.selectNodeContents(firstcell)}}};this._selectContentIfEmpty=function(){var selNode=this.editor.getSelectedNode();var cell=this.editor.getNearestParentOfType(selNode,'td');if(!cell){return};var children=cell.childNodes;if(children.length==1&&children[0].nodeType==3&&children[0].nodeValue=='\xa0'){var selection=this.editor.getSelection();selection.selectNodeContents(cell)}};this.addTableRow=function(){var currnode=this.editor.getSelectedNode();var currtbody=this.editor.getNearestParentOfType(currnode,"TBODY");var bodytype="tbody";if(!currtbody){currtbody=this.editor.getNearestParentOfType(currnode,"THEAD");bodytype="thead"}
var parentrow=this.editor.getNearestParentOfType(currnode,"TR");var nextrow=parentrow.nextSibling;var colcount=0;for(var i=0;i<currtbody.childNodes.length;i++){var el=currtbody.childNodes[i];if(el.nodeType!=1){continue}
if(el.nodeName.toLowerCase()=='tr'){var cols=0;for(var j=0;j<el.childNodes.length;j++){if(el.childNodes[j].nodeType==1){cols++}}
if(cols>colcount){colcount=cols}}}
var newrow=this.editor.getInnerDocument().createElement("TR");for(var i=0;i<colcount;i++){var newcell;if(bodytype=='tbody'){newcell=this.editor.getInnerDocument().createElement("TD")} else{newcell=this.editor.getInnerDocument().createElement("TH")}
var newcellvalue=this.editor.getInnerDocument().createTextNode("\u00a0");newcell.appendChild(newcellvalue);newrow.appendChild(newcell)}
if(!nextrow){currtbody.appendChild(newrow)} else{currtbody.insertBefore(newrow,nextrow)}
this.editor.focusDocument();this.editor.logMessage(_('Table row added'))};this.delTableRow=function(){var currnode=this.editor.getSelectedNode();var parentrow=this.editor.getNearestParentOfType(currnode,"TR");if(!parentrow){this.editor.logMessage(_('No row to delete'),1);return}
var selection=this.editor.getSelection();if(parentrow.nextSibling){selection.selectNodeContents(parentrow.nextSibling.firstChild)} else if(parentrow.previousSibling){selection.selectNodeContents(parentrow.previousSibling.firstChild)};parentrow.parentNode.removeChild(parentrow);this.editor.focusDocument();this.editor.logMessage(_('Table row removed'))};this.addTableColumn=function(){var currnode=this.editor.getSelectedNode();var currtd=this.editor.getNearestParentOfType(currnode,'TD');if(!currtd){currtd=this.editor.getNearestParentOfType(currnode,'TH')}
if(!currtd){this.editor.logMessage(_('No parentcolumn found!'),1);return}
var currtr=this.editor.getNearestParentOfType(currnode,'TR');var currtable=this.editor.getNearestParentOfType(currnode,'TABLE');var tdindex=this._getColIndex(currtd);this.editor.logMessage(_('tdindex: ${tdindex}'));var theads=currtable.getElementsByTagName('THEAD');if(theads){for(var i=0;i<theads.length;i++){var currthead=theads[i];for(var j=0;j<currthead.childNodes.length;j++){var tr=currthead.childNodes[j];if(tr.nodeType!=1){continue}
var currindex=0;for(var k=0;k<tr.childNodes.length;k++){var th=tr.childNodes[k];if(th.nodeType!=1){continue}
if(currindex==tdindex){var doc=this.editor.getInnerDocument();var newth=doc.createElement('th');var text=doc.createTextNode('\u00a0');newth.appendChild(text);if(tr.childNodes.length==k+1){tr.appendChild(newth)} else{tr.insertBefore(newth,tr.childNodes[k+1])}
break}
currindex++}}}}
var tbodies=currtable.getElementsByTagName('TBODY');if(tbodies){for(var i=0;i<tbodies.length;i++){var currtbody=tbodies[i];for(var j=0;j<currtbody.childNodes.length;j++){var tr=currtbody.childNodes[j];if(tr.nodeType!=1){continue}
var currindex=0;for(var k=0;k<tr.childNodes.length;k++){var td=tr.childNodes[k];if(td.nodeType!=1){continue}
if(currindex==tdindex){var doc=this.editor.getInnerDocument();var newtd=doc.createElement('td');var text=doc.createTextNode('\u00a0');newtd.appendChild(text);if(tr.childNodes.length==k+1){tr.appendChild(newtd)} else{tr.insertBefore(newtd,tr.childNodes[k+1])}
break}
currindex++}}}}
this.editor.focusDocument();this.editor.logMessage(_('Table column added'))};this.delTableColumn=function(){var currnode=this.editor.getSelectedNode();var currtd=this.editor.getNearestParentOfType(currnode,'TD');if(!currtd){currtd=this.editor.getNearestParentOfType(currnode,'TH')}
var currcolindex=this._getColIndex(currtd);var currtable=this.editor.getNearestParentOfType(currnode,'TABLE');var selection=this.editor.getSelection();if(currtd.nextSibling){selection.selectNodeContents(currtd.nextSibling)} else if(currtd.previousSibling){selection.selectNodeContents(currtd.previousSibling)};var heads=currtable.getElementsByTagName('THEAD');if(heads.length){for(var i=0;i<heads.length;i++){var thead=heads[i];for(var j=0;j<thead.childNodes.length;j++){var tr=thead.childNodes[j];if(tr.nodeType!=1){continue}
var currindex=0;for(var k=0;k<tr.childNodes.length;k++){var th=tr.childNodes[k];if(th.nodeType!=1){continue}
if(currindex==currcolindex){tr.removeChild(th);break}
currindex++}}}}
var bodies=currtable.getElementsByTagName('TBODY');for(var i=0;i<bodies.length;i++){var currtbody=bodies[i];var relevant_rowspan=0;for(var j=0;j<currtbody.childNodes.length;j++){var tr=currtbody.childNodes[j];if(tr.nodeType!=1){continue}
var currindex=0
for(var k=0;k<tr.childNodes.length;k++){var cell=tr.childNodes[k];if(cell.nodeType!=1){continue}
var colspan=cell.colSpan;if(currindex==currcolindex){tr.removeChild(cell);break}
currindex++}}}
this.editor.focusDocument();this.editor.logMessage(_('Table column deleted'))};this.delTable=function(){var currnode=this.editor.getSelectedNode();var table=this.editor.getNearestParentOfType(currnode,'table');if(!table){this.editor.logMessage(_('Not inside a table!'));return};table.parentNode.removeChild(table);this.editor.logMessage(_('Table removed'))};this.setColumnAlign=function(newalign){var currnode=this.editor.getSelectedNode();var currtd=this.editor.getNearestParentOfType(currnode,"TD");var bodytype='tbody';if(!currtd){currtd=this.editor.getNearestParentOfType(currnode,"TH");bodytype='thead'}
var currcolindex=this._getColIndex(currtd);var currtable=this.editor.getNearestParentOfType(currnode,"TABLE");for(var i=0;i<currtable.childNodes.length;i++){var currtbody=currtable.childNodes[i];if(currtbody.nodeType!=1||(currtbody.nodeName.toUpperCase()!="THEAD"&&currtbody.nodeName.toUpperCase()!="TBODY")){continue}
for(var j=0;j<currtbody.childNodes.length;j++){var row=currtbody.childNodes[j];if(row.nodeType!=1){continue}
var index=0;for(var k=0;k<row.childNodes.length;k++){var cell=row.childNodes[k];if(cell.nodeType!=1){continue}
if(index==currcolindex){if(this.editor.config.use_css){cell.style.textAlign=newalign} else{cell.setAttribute('align',newalign)}
cell.className='align-'+newalign}
index++}}}};this.setTableClass=function(sel_class){var currnode=this.editor.getSelectedNode();var currtable=this.editor.getNearestParentOfType(currnode,'TABLE');if(currtable){currtable.className=sel_class}};this._getColIndex=function(currcell){var prevsib=currcell.previousSibling;var currcolindex=0;while(prevsib){if(prevsib.nodeType==1&&(prevsib.tagName.toUpperCase()=="TD"||prevsib.tagName.toUpperCase()=="TH")){var colspan=prevsib.colSpan;if(colspan){currcolindex+=parseInt(colspan)} else{currcolindex++}}
prevsib=prevsib.previousSibling;if(currcolindex>30){alert(_("Recursion detected when counting column position"));return}}
return currcolindex};this._getColumnAlign=function(selNode){var align;var td=this.editor.getNearestParentOfType(selNode,'td');if(!td){td=this.editor.getNearestParentOfType(selNode,'th')};if(td){align=td.getAttribute('align');if(this.editor.config.use_css){align=td.style.textAlign}};return align};this.fixTable=function(event){var currnode=this.editor.getSelectedNode();var table=this.editor.getNearestParentOfType(currnode,'TABLE');if(!table){this.editor.logMessage(_('Not inside a table!'));return};this._fixTableHelper(table)};this._isBodyRow=function(row){for(var node=row.firstChild;node;node=node.nextSibling){if (/TD/.test(node.nodeName)){return true}}
return false}
this._cleanCell=function(el){dump('_cleanCell('+el.innerHTML+')\n');var node,nxt,n;for(node=el.firstChild;node;){if (/DIV|P/.test(node.nodeName)){for(var n=node.firstChild;n;){var nxt=n.nextSibling;el.insertBefore(n,node);n=nxt}
nxt=node.nextSibling;el.removeChild(node);node=nxt} else{node=node.nextSibling}}
var c;while(el.firstChild&&(c=el.firstChild).nodeType==3&&/^\s+/.test(c.data)){c.data=c.data.replace(/^\s+/,'');if(!c.data){el.removeChild(c)} else{break}};while(el.lastChild&&(c=el.lastChild).nodeType==3&&/\s+$/.test(c.data)){c.data=c.data.replace(/\s+$/,'');if(!c.data){el.removeChild(c)} else{break}};el.removeAttribute('colSpan');el.removeAttribute('rowSpan')}
this._countCols=function(rows,numcols){for(var i=0;i<rows.length;i++){var row=rows[i];var currnumcols=0;for(var node=row.firstChild;node;node=node.nextSibling){if (/td|th/i.test(node.nodeName)){currnumcols+=parseInt(node.getAttribute('colSpan')||'1')}};if(currnumcols>numcols){numcols=currnumcols}};return numcols}
this._cleanRows=function(rows,container,numcols){for(var i=0;i<rows.length;i++){dump("row "+i+'\n');var row=rows[i];var doc=this.editor.getInnerDocument();var newrow=doc.createElement('tr');if(row.className){newrow.className=row.className}
for(var node=row.firstChild;node;){dump("child\n");var nxt=node.nextSibling;if (/TD|TH/.test(node.nodeName)){this._cleanCell(node);newrow.appendChild(node)};node=nxt};if(newrow.childNodes.length){container.appendChild(newrow)}};for(row=container.firstChild;row;row=row.nextSibling){var cellname=row.lastChild.nodeName;while(row.childNodes.length<numcols){var cell=doc.createElement(cellname);var nbsp=doc.createTextNode('\u00a0');cell.appendChild(nbsp);row.appendChild(cell)}}};this._fixTableHelper=function(table){var doc=this.editor.getInnerDocument();var thead=doc.createElement('thead');var tbody=doc.createElement('tbody');var tfoot=doc.createElement('tfoot');var table_classes=this.editor.config.table_classes;
function cleanClassName(name){var allowed_classes=table_classes['class'];for(var i=0;i<allowed_classes.length;i++){var classname=allowed_classes[i];classname=classname.classname||classname;if(classname==name) return name};return allowed_classes[0]}
if(table_classes){table.className=cleanClassName(table.className)} else{table.removeAttribute('class');table.removeAttribute('className')};table.removeAttribute('border');table.removeAttribute('cellpadding');table.removeAttribute('cellPadding');table.removeAttribute('cellspacing');table.removeAttribute('cellSpacing');var hrows=[],brows=[],frows=[];for(var node=table.firstChild;node;node=node.nextSibling){var nodeName=node.nodeName;if (/TR/.test(node.nodeName)){brows.push(node)} else if (/THEAD|TBODY|TFOOT/.test(node.nodeName)){var rows=nodeName=='THEAD'?hrows:nodeName=='TFOOT'?frows:brows;for(var inode=node.firstChild;inode;inode=inode.nextSibling){if (/TR/.test(inode.nodeName)){rows.push(inode)}}}};dump('extract head and foot\n');while(brows.length&&!this._isBodyRow(brows[0])){hrows.push(brows[0]);brows.shift()}
while(brows.length&&!this._isBodyRow(brows[brows.length-1])){var last=brows[brows.length-1];brows.length-=1;frows.unshift(last)}
dump('count cols\n');var numcols=this._countCols(hrows,0);numcols=this._countCols(brows,numcols);numcols=this._countCols(frows,numcols);dump('clean rows\n');this._cleanRows(hrows,thead);this._cleanRows(brows,tbody);this._cleanRows(frows,tfoot);dump('remove old\n');while(table.firstChild){table.removeChild(table.firstChild)}
if(hrows.length)
table.appendChild(thead);if(brows.length)
table.appendChild(tbody);if(frows.length)
table.appendChild(tfoot);dump('finish up\n');this.editor.focusDocument();this.editor.logMessage(_('Table cleaned up'))};this.fixAllTables=function(){var tables=this.editor.getInnerDocument().getElementsByTagName('table');for(var i=0;i<tables.length;i++){this._fixTableHelper(tables[i])}}};TableTool.prototype=new KupuTool;
function TableToolBox(addtabledivid,edittabledivid,newrowsinputid,newcolsinputid,makeheaderinputid,classselectid,alignselectid,addtablebuttonid,addrowbuttonid,delrowbuttonid,addcolbuttonid,delcolbuttonid,fixbuttonid,fixallbuttonid,toolboxid,plainclass,activeclass){this.addtablediv=getFromSelector(addtabledivid);this.edittablediv=getFromSelector(edittabledivid);this.newrowsinput=getFromSelector(newrowsinputid);this.newcolsinput=getFromSelector(newcolsinputid);this.makeheaderinput=getFromSelector(makeheaderinputid);this.classselect=getFromSelector(classselectid);this.alignselect=getFromSelector(alignselectid);this.addtablebutton=getFromSelector(addtablebuttonid);this.addrowbutton=getFromSelector(addrowbuttonid);this.delrowbutton=getFromSelector(delrowbuttonid);this.addcolbutton=getFromSelector(addcolbuttonid);this.delcolbutton=getFromSelector(delcolbuttonid);this.fixbutton=getFromSelector(fixbuttonid);this.fixallbutton=getFromSelector(fixallbuttonid);this.toolboxel=getFromSelector(toolboxid);this.plainclass=plainclass;this.activeclass=activeclass;this.initialize=function(tool,editor){this.tool=tool;this.editor=editor;if(this.editor.config.table_classes){var classes=this.editor.config.table_classes['class'];while(this.classselect.hasChildNodes()){this.classselect.removeChild(this.classselect.firstChild)};for(var i=0;i<classes.length;i++){var classname=classes[i];classname=classname.classname||classname;var option=document.createElement('option');var content=document.createTextNode(classname);option.appendChild(content);option.setAttribute('value',classname);this.classselect.appendChild(option)}};addEventHandler(this.addtablebutton,"click",this.addTable,this);addEventHandler(this.addrowbutton,"click",this.tool.addTableRow,this.tool);addEventHandler(this.delrowbutton,"click",this.tool.delTableRow,this.tool);addEventHandler(this.addcolbutton,"click",this.tool.addTableColumn,this.tool);addEventHandler(this.delcolbutton,"click",this.tool.delTableColumn,this.tool);addEventHandler(this.alignselect,"change",this.setColumnAlign,this);addEventHandler(this.classselect,"change",this.setTableClass,this);addEventHandler(this.fixbutton,"click",this.tool.fixTable,this.tool);addEventHandler(this.fixallbutton,"click",this.tool.fixAllTables,this.tool);this.addtablediv.style.display="block";this.edittablediv.style.display="none";this.editor.logMessage(_('Table tool initialized'))};this.updateState=function(selNode){var table=this.editor.getNearestParentOfType(selNode,'table');if(table){this.addtablediv.style.display="none";this.edittablediv.style.display="block";var align=this.tool._getColumnAlign(selNode);selectSelectItem(this.alignselect,align);selectSelectItem(this.classselect,table.className);if(this.toolboxel){this.toolboxel.className=this.activeclass}} else{this.edittablediv.style.display="none";this.addtablediv.style.display="block";this.alignselect.selectedIndex=0;this.classselect.selectedIndex=0;if(this.toolboxel){this.toolboxel.className=this.plainclass}}};this.addTable=function(){var rows=this.newrowsinput.value;var cols=this.newcolsinput.value;var makeHeader=this.makeheaderinput.checked;var classchooser=getFromSelector("kupu-table-classchooser-add");var tableclass=this.classselect.options[this.classselect.selectedIndex].value;this.tool.createTable(rows,cols,makeHeader,tableclass)};this.setColumnAlign=function(){var newalign=this.alignselect.options[this.alignselect.selectedIndex].value;this.tool.setColumnAlign(newalign)};this.setTableClass=function(){var sel_class=this.classselect.options[this.classselect.selectedIndex].value;if(sel_class){this.tool.setTableClass(sel_class)}}};TableToolBox.prototype=new KupuToolBox;
function ListTool(addulbuttonid,addolbuttonid,ulstyleselectid,olstyleselectid){this.addulbutton=getFromSelector(addulbuttonid);this.addolbutton=getFromSelector(addolbuttonid);this.ulselect=getFromSelector(ulstyleselectid);this.olselect=getFromSelector(olstyleselectid);this.style_to_type={'decimal':'1','lower-alpha':'a','upper-alpha':'A','lower-roman':'i','upper-roman':'I','disc':'disc','square':'square','circle':'circle','none':'none'};this.type_to_style={'1':'decimal','a':'lower-alpha','A':'upper-alpha','i':'lower-roman','I':'upper-roman','disc':'disc','square':'square','circle':'circle','none':'none'};this.initialize=function(editor){this.editor=editor;this._fixTabIndex(this.addulbutton);this._fixTabIndex(this.addolbutton);this._fixTabIndex(this.ulselect);this._fixTabIndex(this.olselect);addEventHandler(this.addulbutton,"click",this.addUnorderedList,this);addEventHandler(this.addolbutton,"click",this.addOrderedList,this);addEventHandler(this.ulselect,"change",this.setUnorderedListStyle,this);addEventHandler(this.olselect,"change",this.setOrderedListStyle,this);this.ulselect.style.display="none";this.olselect.style.display="none";this.editor.logMessage(_('List style tool initialized'))};this._handleStyles=function(currnode,onselect,offselect){if(this.editor.config.use_css){var currstyle=currnode.style.listStyleType} else{var currstyle=this.type_to_style[currnode.getAttribute('type')]}
selectSelectItem(onselect,currstyle);offselect.style.display="none";onselect.style.display="inline";offselect.selectedIndex=0};this.updateState=function(selNode){for(var currnode=selNode;currnode;currnode=currnode.parentNode){var tag=currnode.nodeName.toLowerCase();if(tag=='ul'){this._handleStyles(currnode,this.ulselect,this.olselect);return} else if(tag=='ol'){this._handleStyles(currnode,this.olselect,this.ulselect);return}}
with(this.ulselect){selectedIndex=0;style.display="none"};with(this.olselect){selectedIndex=0;style.display="none"}};this.addList=function(command){this.ulselect.style.display="inline";this.olselect.style.display="none";this.editor.execCommand(command);this.editor.focusDocument()};this.addUnorderedList=function(){this.addList("insertunorderedlist")};this.addOrderedList=function(){this.addList("insertorderedlist")};this.setListStyle=function(tag,select){var currnode=this.editor.getSelectedNode();var l=this.editor.getNearestParentOfType(currnode,tag);var style=select.options[select.selectedIndex].value;if(this.editor.config.use_css){l.style.listStyleType=style} else{l.setAttribute('type',this.style_to_type[style])}
this.editor.focusDocument();this.editor.logMessage(_('List style changed'))};this.setUnorderedListStyle=function(){this.setListStyle('ul',this.ulselect)};this.setOrderedListStyle=function(){this.setListStyle('ol',this.olselect)};this.enable=function(){KupuButtonEnable(this.addulbutton);KupuButtonEnable(this.addolbutton);this.ulselect.disabled="";this.olselect.disabled=""}
this.disable=function(){KupuButtonDisable(this.addulbutton);KupuButtonDisable(this.addolbutton);this.ulselect.disabled="disabled";this.olselect.disabled="disabled"}};ListTool.prototype=new KupuTool;
function ShowPathTool(){this.updateState=function(selNode){var path='';var url=null;var currnode=selNode;while(currnode!=null&&currnode.nodeName!='#document'){if(currnode.nodeName.toLowerCase()=='a'){url=currnode.getAttribute('href')};path='/'+currnode.nodeName.toLowerCase()+path;currnode=currnode.parentNode}
try{window.status=url?(path.toString()+' - contains link to \''+url.toString()+'\''):path} catch(e){this.editor.logMessage(_('Could not set status bar message, '+'check your browser\'s security settings.'),1)}}};ShowPathTool.prototype=new KupuTool;
function ViewSourceTool(){this.sourceWindow=null;this.viewSource=function(){if(this.sourceWindow){this.sourceWindow.close()};this.sourceWindow=window.open('#','sourceWindow');var contents='<html>\n'+this.editor.getInnerDocument().documentElement.innerHTML+'\n</html>';var doc=this.sourceWindow.document;doc.write('\xa0');doc.close();var body=doc.getElementsByTagName("body")[0];while(body.hasChildNodes()){body.removeChild(body.firstChild)};var pre=doc.createElement('pre');var textNode=doc.createTextNode(contents);body.appendChild(pre);pre.appendChild(textNode)};this.createContextMenuElements=function(selNode,event){return new Array(new ContextMenuElement(_('View source'),this.viewSource,this))}};ViewSourceTool.prototype=new KupuTool;
function DefinitionListTool(dlbuttonid){this.dlbutton=getFromSelector(dlbuttonid);this.initialize=function(editor){this.editor=editor;this._fixTabIndex(this.dlbutton);addEventHandler(this.dlbutton,'click',this.createDefinitionList,this);addEventHandler(editor.getInnerDocument(),'keyup',this._keyDownHandler,this);addEventHandler(editor.getInnerDocument(),'keypress',this._keyPressHandler,this)};this.handleEnterPress=function(selNode){var dl=this.editor.getNearestParentOfType(selNode,'dl');if(dl){var dt=this.editor.getNearestParentOfType(selNode,'dt');if(dt){if(dt.childNodes.length==1&&dt.childNodes[0].nodeValue=='\xa0'){this.escapeFromDefinitionList(dl,dt,selNode);return};var selection=this.editor.getSelection();var startoffset=selection.startOffset();var endoffset=selection.endOffset();if(endoffset>startoffset){selection.cutChunk(startoffset,endoffset);selection=this.editor.getSelection();startoffset=selection.startOffset()};var ellength=selection.getElementLength(selection.parentElement());if(startoffset>=ellength-1){this.createDefinition(dl,dt)} else{var doc=this.editor.getInnerDocument();var newdt=selection.splitNodeAtSelection(dt);var newdd=doc.createElement('dd');while(newdt.hasChildNodes()){if(newdt.firstChild!=newdt.lastChild||newdt.firstChild.nodeName.toLowerCase()!='br'){newdd.appendChild(newdt.firstChild)}};newdt.parentNode.replaceChild(newdd,newdt);selection.selectNodeContents(newdd);selection.collapse()}} else{var dd=this.editor.getNearestParentOfType(selNode,'dd');if(!dd){this.editor.logMessage(_('Not inside a definition list element!'));return};if(dd.childNodes.length==1&&dd.childNodes[0].nodeValue=='\xa0'){this.escapeFromDefinitionList(dl,dd,selNode);return};var selection=this.editor.getSelection();var startoffset=selection.startOffset();var endoffset=selection.endOffset();if(endoffset>startoffset){selection.cutChunk(startoffset,endoffset);selection=this.editor.getSelection();startoffset=selection.startOffset()};var ellength=selection.getElementLength(selection.parentElement());if(startoffset>=ellength-1){this.createDefinitionTerm(dl,dd)} else{var br=this.editor.getInnerDocument().createElement('br');this.editor.insertNodeAtSelection(br,1);selection.collapse(true)}}}};this.handleTabPress=function(selNode){};this._keyDownHandler=function(event){var selNode=this.editor.getSelectedNode();var dl=this.editor.getNearestParentOfType(selNode,'dl');if(!dl){return};switch(event.keyCode){case 13:if(event.preventDefault){event.preventDefault()} else{event.returnValue=false};break}};this._keyPressHandler=function(event){var selNode=this.editor.getSelectedNode();var dl=this.editor.getNearestParentOfType(selNode,'dl');if(!dl){return};switch(event.keyCode){case 13:this.handleEnterPress(selNode);if(event.preventDefault){event.preventDefault()} else{event.returnValue=false};break;case 9:if(event.preventDefault){event.preventDefault()} else{event.returnValue=false};this.handleTabPress(selNode)}};this.createDefinitionList=function(){var selection=this.editor.getSelection();var doc=this.editor.getInnerDocument();var selection=this.editor.getSelection();var cloned=selection.cloneContents();var iterator=new NodeIterator(cloned);var currnode=null;var remove=false;while(currnode=iterator.next()){if(currnode.nodeName.toLowerCase()=='br'){remove=true};if(remove){var next=currnode;while(!next.nextSibling){next=next.parentNode};next=next.nextSibling;iterator.setCurrent(next);currnode.parentNode.removeChild(currnode)}};var dtcontentcontainer=cloned;var collapsetoend=false;var dl=doc.createElement('dl');this.editor.insertNodeAtSelection(dl);var dt=this.createDefinitionTerm(dl);if(dtcontentcontainer.hasChildNodes()){collapsetoend=true;while(dt.hasChildNodes()){dt.removeChild(dt.firstChild)};while(dtcontentcontainer.hasChildNodes()){dt.appendChild(dtcontentcontainer.firstChild)}};var selection=this.editor.getSelection();selection.selectNodeContents(dt);selection.collapse(collapsetoend)};this.createDefinitionTerm=function(dl,dd){var doc=this.editor.getInnerDocument();var dt=doc.createElement('dt');if(dd){if(dd.lastChild.nodeName.toLowerCase()=='br'){dd.removeChild(dd.lastChild)}};if(!dd||dl==dd.lastChild){dl.appendChild(dt)} else{var nextsibling=dd.nextSibling;if(nextsibling){dl.insertBefore(dt,nextsibling)} else{dl.appendChild(dt)}};var nbsp=doc.createTextNode('\xa0');dt.appendChild(nbsp);var selection=this.editor.getSelection();selection.selectNodeContents(dt);selection.collapse();this.editor.focusDocument();return dt};this.createDefinition=function(dl,dt,initial_content){var doc=this.editor.getInnerDocument();var dd=doc.createElement('dd');var nextsibling=dt.nextSibling;if(dt){if(dt.lastChild.nodeName.toLowerCase()=='br'){dt.removeChild(dt.lastChild)}};while(nextsibling){var name=nextsibling.nodeName.toLowerCase();if(name=='dd'||name=='dt'){break} else{nextsibling=nextsibling.nextSibling}};if(nextsibling){dl.insertBefore(dd,nextsibling)} else{dl.appendChild(dd)};if(initial_content){for(var i=0;i<initial_content.length;i++){dd.appendChild(initial_content[i])}};var nbsp=doc.createTextNode('\xa0');dd.appendChild(nbsp);var selection=this.editor.getSelection();selection.selectNodeContents(dd);selection.collapse()};this.escapeFromDefinitionList=function(dl,currel,selNode){var doc=this.editor.getInnerDocument();var p=doc.createElement('p');var nbsp=doc.createTextNode('\xa0');p.appendChild(nbsp);if(dl.lastChild==currel){dl.parentNode.insertBefore(p,dl.nextSibling)} else{for(var i=0;i<dl.childNodes.length;i++){var child=dl.childNodes[i];if(child==currel){var newdl=this.editor.getInnerDocument().createElement('dl');while(currel.nextSibling){newdl.appendChild(currel.nextSibling)};dl.parentNode.insertBefore(newdl,dl.nextSibling);dl.parentNode.insertBefore(p,dl.nextSibling)}}};currel.parentNode.removeChild(currel);var selection=this.editor.getSelection();selection.selectNodeContents(p);selection.collapse();this.editor.focusDocument()};this._fixStructure=function(doc,dl,offsetnode){var currname=offsetnode.nodeName.toLowerCase();var currnode=offsetnode.nextSibling;while(currnode){if(currnode.nodeType==1){var nodename=currnode.nodeName.toLowerCase();if(currname=='dt'&&nodename=='dt'){var dd=doc.createElement('dd');while(currnode.hasChildNodes()){dd.appendChild(currnode.childNodes[0])};currnode.parentNode.replaceChild(dd,currnode)} else if(currname=='dd'&&nodename=='dd'){var dt=doc.createElement('dt');while(currnode.hasChildNodes()){dt.appendChild(currnode.childNodes[0])};currnode.parentNode.replaceChild(dt,currnode)}};currnode=currnode.nextSibling}}};DefinitionListTool.prototype=new KupuTool;
function KupuZoomTool(buttonid,firsttab,lasttab){this.button=getFromSelector(buttonid);firsttab=firsttab||'kupu-tb-styles';lasttab=lasttab||'kupu-logo-button';this.initialize=function(editor){this.offclass='kupu-zoom';this.onclass='kupu-zoom-pressed';this.pressed=false;this.baseinitialize(editor);this.button.tabIndex=this.editor.document.editable.tabIndex;addEventHandler(window,"resize",this.onresize,this);addEventHandler(window,"scroll",this.onscroll,this);var lastbutton=getFromSelector(lasttab);var firstbutton=getFromSelector(firsttab);var iframe=editor.getInnerDocument();this.setTabbing(iframe,firstbutton,lastbutton);this.setTabbing(firstbutton,null,editor.getDocument().getWindow());this.editor.logMessage(_('Zoom tool initialized'))}};KupuZoomTool.prototype=new KupuLateFocusStateButton;KupuZoomTool.prototype.baseinitialize=KupuZoomTool.prototype.initialize;KupuZoomTool.prototype.onscroll=function(){if(!this.zoomed) return;var top=window.pageYOffset!=undefined?window.pageYOffset:document.documentElement.scrollTop;var left=window.pageXOffset!=undefined?window.pageXOffset:document.documentElement.scrollLeft;if(top||left) window.scrollTo(0,0)}
KupuZoomTool.prototype.setTabbing=function(control,forward,backward){
function TabDown(event){if(event.keyCode!=9||!this.zoomed) return;var target=event.shiftKey?backward:forward;if(!target) return;if(event.stopPropogation) event.stopPropogation();event.cancelBubble=true;event.returnValue=false;target.focus();return false}
addEventHandler(control,"keydown",TabDown,this)}
KupuZoomTool.prototype.onresize=function(){if(!this.zoomed) return;var editor=this.editor;var iframe=editor.getDocument().editable;var sourcetool=editor.getTool('sourceedittool');var sourceArea=sourcetool?sourcetool.getSourceArea():null;var fulleditor=iframe.parentNode;var body=document.body;if(window.innerWidth){var width=window.innerWidth;var height=window.innerHeight} else if(document.documentElement){if(!window._IE_VERSION){_IE_VERSION=/MSIE\s*([0-9.]*)/.exec(navigator.appVersion)};var kludge=(_IE_VERSION[1]<7)?5:0;var width=document.documentElement.offsetWidth-kludge;var height=document.documentElement.offsetHeight-kludge} else{var width=document.body.offsetWidth-5;var height=document.body.offsetHeight-5}
width=width+'px';var offset=iframe.parentNode.offsetTop;var nheight=Math.max(height-offset-1,10)+'px';fulleditor.style.width=width;iframe.style.width=width;iframe.style.height=nheight;if(sourceArea){sourceArea.style.width=width;sourceArea.style.height=nheight}}
KupuZoomTool.prototype.checkfunc=function(selNode,button,editor,event){return this.zoomed}
KupuZoomTool.prototype.commandfunc=function(button,editor){var zoom=button.pressed;this.zoomed=zoom;var zoomClass='kupu-fulleditor-zoomed';var iframe=editor.getDocument().getEditable();var body=document.body;var html=document.getElementsByTagName('html')[0];if(zoom){html.style.overflow='hidden';window.scrollTo(0,0);editor.setClass(zoomClass);body.className+=' '+zoomClass;this.onresize()} else{html.style.overflow='';var fulleditor=iframe.parentNode;fulleditor.style.width='';body.className=body.className.replace(/ *kupu-fulleditor-zoomed/,'');editor.clearClass(zoomClass);iframe.style.width='';iframe.style.height='';var sourcetool=editor.getTool('sourceedittool');var sourceArea=sourcetool?sourcetool.getSourceArea():null;if(sourceArea){sourceArea.style.width='';sourceArea.style.height=''}}
var doc=editor.getInnerDocument();doc.designMode=doc.designMode;window.scrollTo(0,iframe.offsetTop);editor.focusDocument()}


/* - kupuloggers.js - */
// http://10.228.150.75:8080/cms/portal_javascripts/kupuloggers.js?original=1
function DebugLogger(){this.log=function(message,severity){if(severity>1){alert("Error: "+message)} else if(severity==1){alert("Warning: "+message)} else{alert("Log message: "+message)}}}
function PlainLogger(debugelid,maxlength){this.debugel=getFromSelector(debugelid);this.maxlength=maxlength;this.log=function(message,severity){if(severity>1){throw message} else{if(this.maxlength){if(this.debugel.childNodes.length>this.maxlength-1){this.debugel.removeChild(this.debugel.childNodes[0])}}
var now=new Date();var time=now.getHours()+':'+now.getMinutes()+':'+now.getSeconds();var div=document.createElement('div');var text=document.createTextNode(time+' - '+message);div.appendChild(text);this.debugel.appendChild(div)}}}
function DummyLogger(){this.log=function(message,severity){if(severity>1){throw message}}};

/* - kupucontentfilters.js - */
// http://10.228.150.75:8080/cms/portal_javascripts/kupucontentfilters.js?original=1
function NonXHTMLTagFilter(){if(arguments.length){this.filterdata=arguments[0]} else{this.filterdata={'html':1,'body':1,'head':1,'title':1,'a':1,'abbr':1,'acronym':1,'address':1,'b':1,'base':1,'blockquote':1,'br':1,'caption':1,'cite':1,'code':1,'col':1,'colgroup':1,'dd':1,'dfn':1,'div':1,'dl':1,'dt':1,'em':1,'h1':1,'h2':1,'h3':1,'h4':1,'h5':1,'h6':1,'h7':1,'i':1,'img':1,'kbd':1,'li':1,'link':1,'meta':1,'ol':1,'p':1,'pre':1,'q':1,'samp':1,'script':1,'span':1,'strong':1,'style':1,'sub':1,'sup':1,'table':1,'tbody':1,'td':1,'tfoot':1,'th':1,'thead':1,'tr':1,'ul':1,'u':1,'var':1,'font':1,'center':0}};this.initialize=function(editor){this.editor=editor};this.filter=function(ownerdoc,htmlnode){return this._filterHelper(ownerdoc,htmlnode)};this._filterHelper=function(ownerdoc,node){if(node.nodeType==3){return ownerdoc.createTextNode(node.nodeValue)} else if(node.nodeType==4){return ownerdoc.createCDATASection(node.nodeValue)};var newnode=ownerdoc.createElement(node.nodeName);for(var i=0;i<node.attributes.length;i++){var attr=node.attributes[i];newnode.setAttribute(attr.nodeName,attr.nodeValue)};for(var i=0;i<node.childNodes.length;i++){var child=node.childNodes[i];var nodeType=child.nodeType;var nodeName=child.nodeName.toLowerCase();if(nodeType==3||nodeType==4){newnode.appendChild(this._filterHelper(ownerdoc,child))};if(nodeName in this.filterdata&&this.filterdata[nodeName]){newnode.appendChild(this._filterHelper(ownerdoc,child))} else if(nodeName in this.filterdata){for(var j=0;j<child.childNodes.length;j++){newnode.appendChild(this._filterHelper(ownerdoc,child.childNodes[j]))}}};return newnode}};
function XhtmlValidation(editor){this.Set=function(ary){if(typeof(ary)==typeof('')) ary=[ary];if(ary instanceof Array){for(var i=0;i<ary.length;i++){this[ary[i]]=1}}
else{for(var v in ary){this[v]=1}}}
this._exclude=function(array,exceptions){var ex;if(exceptions.split){ex=exceptions.split("|")} else{ex=exceptions}
var exclude=new this.Set(ex);var res=[];for(var k=0;k<array.length;k++){if(!exclude[array[k]]) res.push(array[k])}
return res}
this.setAttrFilter=function(attributes,filter){for(var j=0;j<attributes.length;j++){var attr=attributes[j];this.attrFilters[attr]=filter||this._defaultCopyAttribute}}
this.setTagAttributes=function(tags,attributes){for(var j=0;j<tags.length;j++){this.tagAttributes[tags[j]]=attributes}}
this.includeTagAttributes=function(tags,attributes){for(var j=0;j<tags.length;j++){var tag=tags[j];this.tagAttributes[tag]=this.tagAttributes[tag].concat(attributes)}}
this.excludeTagAttributes=function(tags,attributes){var bad=new this.Set(attributes);var tagset=new this.Set(tags);for(var tag in tagset){var val=this.tagAttributes[tag];if(val){for(var i=val.length;i>=0;i--){if(bad[val[i]]){val=val.concat();val.splice(i,1)}}}
this.tagAttributes[tag]=val;this.badTagAttributes[tag]=attributes}}
this.excludeTags=function(badtags){if(typeof(badtags)==typeof('')) badtags=[badtags];for(var i=0;i<badtags.length;i++){delete this.tagAttributes[badtags[i]]}}
this.excludeAttributes=function(badattrs){this.excludeTagAttributes(this.tagAttributes,badattrs);for(var i=0;i<badattrs.length;i++){delete this.attrFilters[badattrs[i]]}}
if(editor.getBrowserName()=="IE"){this._getTagName=function(htmlnode){var nodename=htmlnode.nodeName.toLowerCase();if(htmlnode.scopeName&&htmlnode.scopeName!="HTML"){nodename=htmlnode.scopeName+':'+nodename}
return nodename}} else{this._getTagName=function(htmlnode){return htmlnode.nodeName.toLowerCase()}};this.elements=new function(validation){this.attributes=['abbr','accept','accept-charset','accesskey','action','align','alink','alt','archive','axis','background','bgcolor','border','cellpadding','cellspacing','char','charoff','charset','checked','cite','class','classid','clear','code','codebase','codetype','color','cols','colspan','compact','content','coords','data','datetime','declare','defer','dir','disabled','enctype','face','for','frame','frameborder','headers','height','href','hreflang','hspace','http-equiv','id','ismap','label','lang','language','link','longdesc','marginheight','marginwidth','maxlength','media','method','multiple','name','nohref','noshade','nowrap','object','onblur','onchange','onclick','ondblclick','onfocus','onkeydown','onkeypress','onkeyup','onload','onmousedown','onmousemove','onmouseout','onmouseover','onmouseup','onreset','onselect','onsubmit','onunload','profile','prompt','readonly','rel','rev','rows','rowspan','rules','scheme','scope','scrolling','selected','shape','size','span','src','standby','start','style','summary','tabindex','target','text','title','type','usemap','valign','value','valuetype','vlink','vspace','width','xml:lang','xml:space','xmlns'];this.coreattrs=['id','title','style','class'];this.i18n=['lang','dir','xml:lang'];this.events='onclick|ondblclick|onmousedown|onmouseup|onmouseover|onmousemove|onmouseout|onkeypress|onkeydown|onkeyup'.split('|');this.focusevents=[];this.loadevents=[];this.formevents=[];this.inputevents=[] ;this.focus=['accesskey','tabindex'].concat(this.focusevents);this.attrs=[].concat(this.coreattrs,this.i18n,this.events);this.special_extra=['object','applet','img','map','iframe'];this.special_basic=['br','span','bdo'];this.special=[].concat(this.special_basic,this.special_extra);this.fontstyle_extra=['big','small','font','basefont'];this.fontstyle_basic=['tt','i','b','u','s','strike'];this.fontstyle=[].concat(this.fontstyle_basic,this.fontstyle_extra);this.phrase_extra=['sub','sup'];this.phrase_basic=['em','strong','dfn','code','q','samp','kbd','var','cite','abbr','acronym'];this.inline_forms=['input','select','textarea','label','button'];this.misc_inline=['ins','del'];this.misc=['noscript'].concat(this.misc_inline);this.inline=['a'].concat(this.special,this.fontstyle,this.phrase,this.inline_forms);this.Inline=['#PCDATA'].concat(this.inline,this.misc_inline);this.heading=['h1','h2','h3','h4','h5','h6'];this.lists=['ul','ol','dl','menu','dir'];this.blocktext=['pre','hr','blockquote','address','center','noframes'];this.block=['p','div','isindex','fieldset','table'].concat(this.heading,this.lists,this.blocktext);this.Flow=['#PCDATA','form'].concat(this.block,this.inline)}(this);this._commonsetting=function(self,names,value){for(var n=0;n<names.length;n++){self[names[n]]=value}}
this.tagAttributes=new function(el,validation){this.title=el.i18n.concat('id');this.html=this.title.concat('xmlns');this.head=this.title.concat('profile');this.base=['id','href','target'];this.meta=this.title.concat('http-equiv','name','content','scheme');this.link=el.attrs.concat('charset','href','hreflang','type','rel','rev','media','target');this.style=this.title.concat('type','media','title','xml:space');this.script=['id','charset','type','language','src','defer','xml:space'];this.iframe=['longdesc','name','src','frameborder','marginwidth','marginheight','scrolling','align','height','width'].concat(el.coreattrs);this.body=['background','bgcolor','text','link','vlink','alink'].concat(el.attrs,el.loadevents);validation._commonsetting(this,['p','div'].concat(el.heading),['align'].concat(el.attrs));this.dl=this.dir=this.menu=el.attrs.concat('compact');this.ul=this.menu.concat('type');this.ol=this.ul.concat('start');this.li=el.attrs.concat('type','value');this.hr=el.attrs.concat('align','noshade','size','width');this.pre=el.attrs.concat('width','xml:space');this.blockquote=this.q=el.attrs.concat('cite');this.ins=this.del=this.blockquote.concat('datetime');this.a=el.attrs.concat(el.focus,'charset','type','name','href','hreflang','rel','rev','shape','coords','target');this.bdo=el.coreattrs.concat(el.events,'lang','xml:lang','dir');this.br=el.coreattrs.concat('clear');validation._commonsetting(this,['noscript','noframes','dt','dd','address','center','span','em','strong','dfn','code','samp','kbd','var','cite','abbr','acronym','sub','sup','tt','i','b','big','small','u','s','strike','fieldset'],el.attrs);this.basefont=['id','size','color','face'];this.font=el.coreattrs.concat(el.i18n,'size','color','face');this.object=el.attrs.concat('declare','classid','codebase','data','type','codetype','archive','standby','height','width','usemap','name','tabindex','align','border','hspace','vspace');this.param=['id','name','value','valuetype','type'];this.applet=el.coreattrs.concat('codebase','archive','code','object','alt','name','width','height','align','hspace','vspace');this.img=el.attrs.concat('src','alt','name','longdesc','height','width','usemap','ismap','align','border','hspace','vspace');this.map=this.title.concat('title','name','style','class',el.events);this.area=el.attrs.concat('shape','coords','href','nohref','alt','target',el.focus);this.form=el.attrs.concat('action','method','name','enctype',el.formevents,'accept','accept-charset','target');this.label=el.attrs.concat('for','accesskey',el.focusevents);this.input=el.attrs.concat('type','name','value','checked','disabled','readonly','size','maxlength','src','alt','usemap',el.input,'accept','align',el.focus);this.select=el.attrs.concat('name','size','multiple','disabled','tabindex',el.focusevents,el.input);this.optgroup=el.attrs.concat('disabled','label');this.option=el.attrs.concat('selected','disabled','label','value');this.textarea=el.attrs.concat('name','rows','cols','disabled','readonly',el.inputevents,el.focus);this.legend=el.attrs.concat('accesskey','align');this.button=el.attrs.concat('name','value','type','disabled',el.focus);this.isindex=el.coreattrs.concat('prompt',el.i18n);this.table=el.attrs.concat('summary','width','border','frame','rules','cellspacing','cellpadding','align','bgcolor');this.caption=el.attrs.concat('align');this.col=this.colgroup=el.attrs.concat('span','width','align','char','charoff','valign');this.thead=el.attrs.concat('align','char','charoff','valign');this.tfoot=this.tbody=this.thead;this.tr=this.thead.concat('bgcolor');this.td=this.th=this.tr.concat('abbr','axis','headers','scope','rowspan','colspan','nowrap','width','height')}(this.elements,this);this.badTagAttributes=new this.Set({});this.States=new function(el,validation){var here=this;
function setStates(tags,value){var valset=new validation.Set(value);for(var i=0;i<tags.length;i++){here[tags[i]]=valset}}
setStates(['html'],['head','body']);setStates(['head'],['title','base','script','style','meta','link','object','isindex']);setStates(['base','meta','link','hr','param','img','area','input','br','basefont','isindex','col',],[]);setStates(['title','style','script','option','textarea'],['#PCDATA']);setStates(['noscript','iframe','noframes','body','div','li','dd','blockquote','center','ins','del','td','th',],el.Flow);setStates(el.heading,el.Inline);setStates(['p','dt','address','span','bdo','caption','em','strong','dfn','code','samp','kbd','var','cite','abbr','acronym','q','sub','sup','tt','i','b','big','small','u','s','strike','font','label','legend'],el.Inline);setStates(['ul','ol','menu','dir','ul',],['li']);setStates(['dl'],['dt','dd']);setStates(['pre'],validation._exclude(el.Inline,"img|object|applet|big|small|sub|sup|font|basefont"));setStates(['a'],validation._exclude(el.Inline,"a"));setStates(['applet','object'],['#PCDATA','param','form'].concat(el.block,el.inline,el.misc));setStates(['map'],['form','area'].concat(el.block,el.misc));setStates(['form'],validation._exclude(el.Flow,['form']));setStates(['select'],['optgroup','option']);setStates(['optgroup'],['option']);setStates(['fieldset'],['#PCDATA','legend','form'].concat(el.block,el.inline,el.misc));setStates(['button'],validation._exclude(el.Flow,['a','form','iframe'].concat(el.inline_forms)));setStates(['table'],['caption','col','colgroup','thead','tfoot','tbody','tr']);setStates(['thead','tfoot','tbody'],['tr']);setStates(['colgroup'],['col']);setStates(['tr'],['th','td'])}(this.elements,this);this.styleWhitelist=new this.Set(['text-align','list-style-type','float']);this.classBlacklist=new this.Set(['MsoNormal','MsoTitle','MsoHeader','MsoFootnoteText','Bullet1','Bullet2']);this.classFilter=function(value){var classes=value.split(' ');var filtered=[];for(var i=0;i<classes.length;i++){var c=classes[i];if(c&&!this.classBlacklist[c]){filtered.push(c)}}
return filtered.join(' ')}
this._defaultCopyAttribute=function(name,htmlnode,xhtmlnode){var val=htmlnode.getAttribute(name);if(val) xhtmlnode.setAttribute(name,val)}
var filter=this;this.attrFilters=new function(validation,editor){var attrs=validation.elements.attributes;for(var i=0;i<attrs.length;i++){this[attrs[i]]=validation._defaultCopyAttribute}
this['class']=function(name,htmlnode,xhtmlnode){var val=htmlnode.getAttribute('class');if(val) val=validation.classFilter(val);if(val) xhtmlnode.setAttribute('class',val)}
this['*']=function(name,htmlnode,xhtmlnode){var nodeName=filter._getTagName(htmlnode);var bad=filter.badTagAttributes[nodeName];for(var i=0;i<htmlnode.attributes.length;i++){var attr=htmlnode.attributes[i];if(bad&&bad.contains(attr.name)){continue};if(attr.value!==null&&attr.value!==undefined){xhtmlnode.setAttribute(attr.name,attr.value)}}}
if(editor.getBrowserName()=="IE"){this['class']=function(name,htmlnode,xhtmlnode){var val=htmlnode.className;if(val) val=validation.classFilter(val);if(val) xhtmlnode.setAttribute('class',val)}
this['http-equiv']=function(name,htmlnode,xhtmlnode){var val=htmlnode.httpEquiv;if(val) xhtmlnode.setAttribute('http-equiv',val)}
this['xml:lang']=this['xml:space']=function(name,htmlnode,xhtmlnode){try{var val=htmlnode.getAttribute(name);if(val) xhtmlnode.setAttribute(name,val)} catch(e){}}}
this.rowspan=this.colspan=function(name,htmlnode,xhtmlnode){var val=htmlnode.getAttribute(name);if(val&&val!='1') xhtmlnode.setAttribute(name,val)}
this.style=function(name,htmlnode,xhtmlnode){var val=htmlnode.style.cssText;if(val) xhtmlnode.setAttribute('style',val)}}(this,editor);this.excludeTags(['center']);if(editor.config&&editor.config.htmlfilter){this.filterStructure=editor.config.htmlfilter.filterstructure;var exclude=editor.config.htmlfilter;if(exclude.a)
this.excludeAttributes(exclude.a);if(exclude.t)
this.excludeTags(exclude.t);if(exclude.c){var c=exclude.c;if(!c.length) c=[c];for(var i=0;i<c.length;i++){this.excludeTagAttributes(c[i].t,c[i].a)}}
if(exclude.xstyle){var s=exclude.xstyle;for(var i=0;i<s.length;i++){this.styleWhitelist[s[i]]=1}}
if(exclude['class']){var c=exclude['class'];for(var i=0;i<c.length;i++){this.classBlacklist[c[i]]=1}}};this._copyAttributes=function(htmlnode,xhtmlnode,valid){if(valid.contains('*')){this.attrFilters['*'](name,htmlnode,xhtmlnode);return};for(var i=0;i<valid.length;i++){var name=valid[i];var filter=this.attrFilters[name];if(filter) filter(name,htmlnode,xhtmlnode)}}
this._convertToSarissaNode=function(ownerdoc,htmlnode,xhtmlparent){return this._convertNodes(ownerdoc,htmlnode,xhtmlparent,new this.Set(['html']))};this._convertNodes=function(ownerdoc,htmlnode,xhtmlparent,permitted){var name,parentnode=xhtmlparent;var nodename=this._getTagName(htmlnode);var nostructure=!this.filterstructure;var validattrs=this.tagAttributes[nodename];if(validattrs&&(nostructure||permitted[nodename])){try{var xhtmlnode=ownerdoc.createElement(nodename);parentnode=xhtmlnode} catch(e){};if(validattrs&&xhtmlnode)
this._copyAttributes(htmlnode,xhtmlnode,validattrs)}
var kids=htmlnode.childNodes;var permittedChildren=this.States[parentnode.tagName]||permitted;if(kids.length==0){if(htmlnode.text&&htmlnode.text!=""&&(nostructure||permittedChildren['#PCDATA'])){var text=htmlnode.text;var tnode=ownerdoc.createTextNode(text);parentnode.appendChild(tnode)}} else{for(var i=0;i<kids.length;i++){var kid=kids[i];if(kid.parentNode!==htmlnode){if(kid.tagName=='BODY'){if(nodename!='html') continue} else if(kid.parentNode.tagName===htmlnode.tagName){continue}}
if(kid.nodeType==1){var newkid=this._convertNodes(ownerdoc,kid,parentnode,permittedChildren);if(newkid!=null){parentnode.appendChild(newkid)}} else if(kid.nodeType==3){if(nostructure||permittedChildren['#PCDATA'])
parentnode.appendChild(ownerdoc.createTextNode(kid.nodeValue))} else if(kid.nodeType==4){if(nostructure||permittedChildren['#PCDATA'])
parentnode.appendChild(ownerdoc.createCDATASection(kid.nodeValue))}}}
return xhtmlnode}}


/* - kupucontextmenu.js - */
// http://10.228.150.75:8080/cms/portal_javascripts/kupucontextmenu.js?original=1
function ContextMenu(){this.contextmenu=null;this.seperator=1;this.initialize=function(editor){this.editor=editor;addEventHandler(this.editor.getInnerDocument(),"contextmenu",this.createContextMenu,this);addEventHandler(document,"focus",this.hideContextMenu,this);addEventHandler(editor.getInnerDocument(),"mousedown",this.hideContextMenu,this);addEventHandler(document,"mousedown",this.hideContextMenu,this)};this.createContextMenu=function(event){if(event.stopPropagation){event.stopPropagation()};event.returnValue=false;if(this.editor.getBrowserName()=='IE'){this.editor._saveSelection()};if(this.editor.getBrowserName()=='Mozilla'&&this.contextmenu){return false};this.hideContextMenu();var selNode=this.editor.getSelectedNode();var elements=new Array();for(var id in this.editor.tools){var tool=this.editor.tools[id];if(tool.createContextMenuElements){var els=tool.createContextMenuElements(selNode,event);elements=elements.concat(els)}};this._createNewContextMenu(elements,event);this.last_event=event;return false};this.hideContextMenu=function(event){if(this.contextmenu){try{window.document.getElementsByTagName('body')[0].removeChild(this.contextmenu)} catch(e){};this.contextmenu=null}};this._createNewContextMenu=function(elements,event){var doc=window.document;var menu=doc.createElement('div');menu.contentEditable=false;menu.designMode='Off';this._setMenuStyle(menu);for(var i=0;i<elements.length;i++){var element=elements[i];if(element!==this.seperator){var div=doc.createElement('div');div.style.width='100%';var label=doc.createTextNode('\u00a0'+element.label);div.appendChild(label);menu.appendChild(div);element.element=div;addEventHandler(div,"mousedown",element.action,element.context);addEventHandler(div,"mouseover",element.changeOverStyle,element);addEventHandler(div,"mouseout",element.changeNormalStyle,element);addEventHandler(div,"mouseup",this.hideContextMenu,this)} else{var hr=doc.createElement('hr');menu.appendChild(hr)}};var iframe=this.editor.getDocument().getEditable();var left=event.clientX;var top=event.clientY;var currnode=iframe;if(this.editor.getBrowserName()=='IE'){while(currnode){left+=currnode.offsetLeft+currnode.clientLeft;top+=currnode.offsetTop+currnode.clientTop;currnode=currnode.offsetParent}} else{while(currnode){left+=currnode.offsetLeft;top+=currnode.offsetTop;currnode=currnode.offsetParent}};menu.style.left=left+'px';menu.style.top=top+'px';menu.style.visibility='visible';addEventHandler(menu,'focus', function(){this.blur},menu)
doc.getElementsByTagName('body')[0].appendChild(menu);this.contextmenu=menu};this._setMenuStyle=function(menu){menu.style.position='absolute';menu.style.backgroundColor='white';menu.style.fontFamily='Verdana, Arial, Helvetica, sans-serif';menu.style.fontSize='12px';menu.style.lineHeight='16px';menu.style.borderWidth='1px';menu.style.borderStyle='solid';menu.style.borderColor='black';menu.style.cursor='default';menu.style.width="8em"};this._showOriginalMenu=function(event){window.document.dispatchEvent(this._last_event)}};
function ContextMenuElement(label,action,context){this.label=label;this.action=action;this.context=context;this.element=null;this.changeOverStyle=function(event){this.element.style.backgroundColor='blue'};this.changeNormalStyle=function(event){this.element.style.backgroundColor='white'}};

/* - kupuploneeditor.js - */
// http://10.228.150.75:8080/cms/portal_javascripts/kupuploneeditor.js?original=1
KupuEditor.prototype._getBase=function(dom){var base=dom.getElementsByTagName('base');if(base.length){return base[0].getAttribute('href')} else{return ''}}
KupuEditor.prototype.makeLinksRelative=function(contents,base,debug){var href=base.replace(/\/[^\/]*$/,'/');var hrefparts=href.split('/');return contents.replace(/(<[^>]* (?:src|href)=")([^"]*)"/g,
function(str,tag,url,offset,contents){var resolveuid=url.indexOf('/resolveuid/');if(resolveuid!=-1){str=tag+url.substr(resolveuid+1)+'"';return str}
var urlparts=url.split('#');var anchor=urlparts[1]||'';url=urlparts[0];var urlparts=url.split('/');var common=0;while(common<urlparts.length&&common<hrefparts.length&&urlparts[common]==hrefparts[common])
common++;var last=urlparts[common];if(common+1==urlparts.length&&last=='emptypage'){urlparts[common]=''}
if(common>2){var path=new Array();var i=0;for(;i+common<hrefparts.length-1;i++){path[i]='..'};while(common<urlparts.length){path[i++]=urlparts[common++]};if(i==0){path[i++]='.'}
str=path.join('/');if(anchor){str=[str,anchor].join('#')}
str=tag+str+'"'};return str})};KupuEditor.prototype.saveDataToField=function(form,field){var sourcetool=this.getTool('sourceedittool');if(sourcetool){sourcetool.cancelSourceMode()};if(!this._initialized){return};this._initialized=false;window.status="Please wait while saving document...";this.logMessage("Starting HTML cleanup");var transform=this._filterContent(this.getInnerDocument().documentElement);var contents=kupu.getXMLBody(transform);if (/^<body[^>]*>(<\/?(p|br)[^>]*>|\&nbsp;)*<\/body>$/.test(contents)){contents=''}
var base=this._getBase(transform);contents=this._fixupSingletons(contents);contents=this.makeLinksRelative(contents,base).replace(/<\/?body[^>]*>/g,"");this.logMessage("Cleanup done, sending document to server");var document=form.ownerDocument;field.value=contents;kupu.content_changed=false};

/* - kupuploneui.js - */
// http://10.228.150.75:8080/cms/portal_javascripts/kupuploneui.js?original=1


/* - kupusourceedit.js - */
// http://10.228.150.75:8080/cms/portal_javascripts/kupusourceedit.js?original=1
function SourceEditTool(sourcebuttonid,sourceareaid){this.sourceButton=getFromSelector(sourcebuttonid);this.sourcemode=false;this._currently_editing=null;this.getSourceArea=function(){return getFromSelector(sourceareaid)}};SourceEditTool.prototype=new KupuTool;SourceEditTool.prototype.cancelSourceMode=function(){if(this._currently_editing){this.switchSourceEdit(null,true)}};SourceEditTool.prototype.updateState=SourceEditTool.prototype.cancelSourceMode;SourceEditTool.prototype.initialize=function(editor){this.editor=editor;this._fixTabIndex(this.sourceButton);addEventHandler(this.sourceButton,"click",this.switchSourceEdit,this);this.editor.logMessage(_('Source edit tool initialized'))};SourceEditTool.prototype.switchSourceEdit=function(event,nograb){var kupu=this.editor;var docobj=this._currently_editing||kupu.getDocument();var editorframe=docobj.getEditable();var sourcearea=this.getSourceArea();var kupudoc=docobj.getDocument();var sourceClass='kupu-sourcemode';if(!this.sourcemode){if(window.drawertool){window.drawertool.closeDrawer()};if (/on/i.test(kupudoc.designMode)){kupudoc.designMode='Off'};kupu._initialized=false;var data='';if(kupu.config.filtersourceedit){window.status=_('Cleaning up HTML...');var transform=kupu._filterContent(kupu.getInnerDocument().documentElement);data=kupu.getXMLBody(transform);data=kupu._fixupSingletons(data).replace(/<\/?body[^>]*>/g,"");if(kupu._getBase&&kupu.makeLinksRelative){var base=kupu._getBase(transform);data=kupu.makeLinksRelative(data,base).replace(/<\/?body[^>]*>/g,"")};window.status=''} else{data=kupu.getHTMLBody()};sourcearea.value=data.strip();kupu.setClass(sourceClass);editorframe.style.display='none';sourcearea.style.display='block';if(!nograb){sourcearea.focus()};this._currently_editing=docobj} else{kupu.setHTMLBody(sourcearea.value);kupu.clearClass(sourceClass);sourcearea.style.display='none';editorframe.style.display='block';if (/off/i.test(kupudoc.designMode)){kupudoc.designMode='On'};if(!nograb){docobj.getWindow().focus();var selection=this.editor.getSelection();selection.collapse()};kupu._initialized=true;this._currently_editing=null;this.editor.updateState()};this.sourcemode=!this.sourcemode};SourceEditTool.prototype.enable=function(){KupuButtonEnable(this.sourceButton)};SourceEditTool.prototype.disable=function(){KupuButtonDisable(this.sourceButton)};
function MultiSourceEditTool(sourcebuttonid,textareaprefix){this.sourceButton=getFromSelector(sourcebuttonid);this.textareaprefix=textareaprefix;this._currently_editing=null};MultiSourceEditTool.prototype=new SourceEditTool;MultiSourceEditTool.prototype.getSourceArea=function(){var docobj=this._currently_editing||kupu.getDocument();var sourceareaid=this.textareaprefix+docobj.getEditable().id;return getFromSelector(sourceareaid)};

/* - kupudrawers.js - */
// http://10.228.150.75:8080/cms/portal_javascripts/kupudrawers.js?original=1
function DrawerTool(){this.drawers={};this.current_drawer=null;this.initialize=function(editor){this.editor=editor;this.isIE=this.editor.getBrowserName()=='IE';window.drawertool=this};this.registerDrawer=function(id,drawer,editor){this.drawers[id]=drawer;drawer.initialize(editor||this.editor,this)};this.openDrawer=function(id){if(this.current_drawer){this.closeDrawer()};var drawer=this.drawers[id];if(this.isIE){drawer.editor._saveSelection()}
drawer.createContent();drawer.editor.suspendEditing();this.current_drawer=drawer};this.updateState=function(selNode){};this.closeDrawer=function(button){if(!this.current_drawer){return};this.current_drawer.hide();this.current_drawer.editor.resumeEditing();this.current_drawer=null}};DrawerTool.prototype=new KupuTool;
function Drawer(elementid,tool){this.element=getFromSelector(elementid);this.tool=tool;this.initialize=function(editor,drawertool){this.editor=editor;this.drawertool=drawertool};this.createContent=function(){this.element.style.display='block';this.focusElement()};this.hide=function(){this.element.style.display='none';this.focussed=false};this.focusElement=function(){this.focussed=false;var iterator=new NodeIterator(this.element);var currnode=iterator.next();while(currnode){if(currnode.tagName&&(currnode.tagName.toUpperCase()=='BUTTON'||(currnode.tagName.toUpperCase()=='INPUT'&&!(/nofocus/.test(currnode.className))))){this.focussed=true;
function focusit(){currnode.focus()}
timer_instance.registerFunction(this,focusit,100);return}
currnode=iterator.next()}}};
function LinkDrawer(elementid,tool,wrap){this.element=getFromSelector(elementid);this.tool=tool;
function wrap(id,tag){return '#'+this.element.id+' '+tag+'.'+id}
var input=getBaseTagClass(this.element,'input','kupu-linkdrawer-input');var preview=getBaseTagClass(this.element,'iframe','kupu-linkdrawer-preview');this.target="";this.createContent=function(){var currnode=this.editor.getSelectedNode();var linkel=this.editor.getNearestParentOfType(currnode,'a');input.value="";this.preview();if(linkel){input.value=linkel.getAttribute('href')} else{input.value='http://'};this.element.style.display='block';this.focusElement()};this.save=function(){this.editor.resumeEditing();var url=input.value;this.tool.createLink(url,null,null,this.target);input.value='';this.drawertool.closeDrawer()};this.preview=function(){preview.src=input.value;if(this.editor.getBrowserName()=='IE'){preview.width="800";preview.height="365";preview.style.zoom="60%"}}
this.preview_loaded=function(){if(input.value!=preview.src){input.value=preview.src}}};LinkDrawer.prototype=new Drawer;
function TableDrawer(elementid,tool){this.element=getFromSelector(elementid);this.tool=tool;this.addpanel=getBaseTagClass(this.element,'div','kupu-tabledrawer-addtable');this.editpanel=getBaseTagClass(this.element,'div','kupu-tabledrawer-edittable');var editclassselect=getBaseTagClass(this.element,'select','kupu-tabledrawer-editclasschooser');var addclassselect=getBaseTagClass(this.element,'select','kupu-tabledrawer-addclasschooser');var alignselect=getBaseTagClass(this.element,'select','kupu-tabledrawer-alignchooser');var newrowsinput=getBaseTagClass(this.element,'input','kupu-tabledrawer-newrows');var newcolsinput=getBaseTagClass(this.element,'input','kupu-tabledrawer-newcols');var makeheadercheck=getBaseTagClass(this.element,'input','kupu-tabledrawer-makeheader');this.createContent=function(){var editor=this.editor;var selNode=editor.getSelectedNode();
function fixClasses(classselect){if(editor.config.table_classes){var classes=editor.config.table_classes['class'];while(classselect.hasChildNodes()){classselect.removeChild(classselect.firstChild)};for(var i=0;i<classes.length;i++){var classinfo=classes[i];var caption=classinfo.xcaption||classinfo;var classname=classinfo.classname||classinfo;var option=document.createElement('option');var content=document.createTextNode(caption);option.appendChild(content);option.setAttribute('value',classname);classselect.appendChild(option)}}};fixClasses(addclassselect);fixClasses(editclassselect);var table=editor.getNearestParentOfType(selNode,'table');if(!table){show=this.addpanel;hide=this.editpanel} else{show=this.editpanel;hide=this.addpanel;var align=this.tool._getColumnAlign(selNode);selectSelectItem(alignselect,align);selectSelectItem(editclassselect,table.className)};hide.style.display='none';show.style.display='block';this.element.style.display='block';this.focusElement()};this.createTable=function(){this.editor.resumeEditing();var rows=newrowsinput.value;var cols=newcolsinput.value;var style=addclassselect.value;var add_header=makeheadercheck.checked;this.tool.createTable(parseInt(rows),parseInt(cols),add_header,style);this.drawertool.closeDrawer()};this.delTableRow=function(){this.editor.resumeEditing();this.tool.delTableRow();this.editor.suspendEditing()};this.addTableRow=function(){this.editor.resumeEditing();this.tool.addTableRow();this.editor.suspendEditing()};this.delTableColumn=function(){this.editor.resumeEditing();this.tool.delTableColumn();this.editor.suspendEditing()};this.addTableColumn=function(){this.editor.resumeEditing();this.tool.addTableColumn();this.editor.suspendEditing()};this.fixTable=function(){this.editor.resumeEditing();this.tool.fixTable();this.editor.suspendEditing()};this.fixAllTables=function(){this.editor.resumeEditing();this.tool.fixAllTables();this.editor.suspendEditing()};this.setTableClass=function(className){this.editor.resumeEditing();this.tool.setTableClass(className);this.editor.suspendEditing()};this.setColumnAlign=function(align){this.editor.resumeEditing();this.tool.setColumnAlign(align);this.editor.suspendEditing()}};TableDrawer.prototype=new Drawer;
function LibraryDrawer(tool,xsluri,libsuri,searchuri,baseelement){this.init=function(tool,xsluri,libsuri,searchuri,baseelement){this.drawerid='kupu-librarydrawer';this.librariespanelid='kupu-librariespanel';this.resourcespanelid='kupu-resourcespanel';this.propertiespanelid='kupu-propertiespanel';if(baseelement){this.baseelement=getFromSelector(baseelement)} else{this.baseelement=getBaseTagClass(document.body,'div','kupu-librarydrawer-parent')}
this.tool=tool;this.element=document.getElementById(this.drawerid);if(!this.element){var e=document.createElement('div');e.id=this.drawerid;e.className='kupu-drawer '+this.drawerid;this.baseelement.appendChild(e);this.element=e}
this.shared.xsluri=xsluri;this.shared.libsuri=libsuri;this.shared.searchuri=searchuri;this.shared.newimages=null;this.shared.xsl=null;this.shared.xmldata=null};if(tool){this.init(tool,xsluri,libsuri,searchuri)}
this.initialize=function(editor,drawertool){this.editor=editor;this.drawertool=drawertool;this.selecteditemid='';var wrapped_callback=new ContextFixer(this._libsXslCallback,this);this._loadXML(this.shared.xsluri,wrapped_callback.execute)};this._libsXslCallback=function(dom){this.shared.xsl=dom;try{var xsltproc=new XSLTProcessor();this.shared.xsltproc=xsltproc;xsltproc.importStylesheet(dom);xsltproc.setParameter("","drawertype",this.drawertype);xsltproc.setParameter("","drawertitle",this.drawertitle);xsltproc.setParameter("","showupload",this.showupload);if(this.editor.config.captions){xsltproc.setParameter("","usecaptions",'yes')}} catch(e){return}};this.createContent=function(){if(this.element.parentNode!=this.baseelement){this.baseelement.appendChild(this.element)}
if(!this.shared.xmldata){if(!window.XSLTProcessor){alert("This function requires better XML support in your browser.");return}
this.loadLibraries()} else{if(this.shared.newimages){this.reloadCurrent();this.shared.newimages=null};this.updateDisplay();this.initialSelection()};this.element.style.display='block'};this._singleLibsXslCallback=function(dom){this.singlelibxsl=dom};this.loadLibraries=function(){var wrapped_callback=new ContextFixer(this._libsContentCallback,this);this._loadXML(this.shared.libsuri,wrapped_callback.execute)};this._libsContentCallback=function(dom){this.shared.xmldata=dom;this.shared.xmldata.setProperty("SelectionLanguage","XPath");this.updateDisplay(this.drawerid);this.initialSelection()};this.initialSelection=function(){var libnode_path='/libraries/library[@selected]';var libnode=this.shared.xmldata.selectSingleNode(libnode_path);if(libnode){var id=libnode.getAttribute('id');this.selectLibrary(id)}}
this.updateDisplay=function(id){if(!id){id=this.drawerid};try{this.shared.xsltproc.setParameter("","showupload",this.showupload)} catch(e){};var doc=this._transformXml();var sourcenode=doc.selectSingleNode('//*[@id="'+id+'"]');var targetnode=document.getElementById(id);Sarissa.copyChildNodes(sourcenode,targetnode);if(!this.focussed){this.focusElement()}
if(this.editor.getBrowserName()=='IE'&&id==this.resourcespanelid){this.updateDisplay(this.drawerid)}};this.deselectActiveCollection=function(){while(1){var selected=this.shared.xmldata.selectSingleNode('//*[@selected]');if(!selected){return};selected.removeAttribute('selected')}};this.selectLibrary=function(id){this.deselectActiveCollection();var divs=this.element.getElementsByTagName('div');for(var i=0;i<divs.length;i++){if(divs[i].className=='kupu-libsource-selected'){divs[i].className='kupu-libsource'}};var libnode_path='/libraries/library[@id="'+id+'"]';var libnode=this.shared.xmldata.selectSingleNode(libnode_path);libnode.setAttribute('selected','1');var items_xpath="items";var items_node=libnode.selectSingleNode(items_xpath);if(items_node&&!this.shared.newimages){this.updateDisplay(this.resourcespanelid);this.updateDisplay(this.propertiespanelid)} else{var src_uri=libnode.selectSingleNode('src/text()').nodeValue;src_uri=src_uri.strip();var wrapped_callback=new ContextFixer(this._libraryContentCallback,this);this._loadXML(src_uri,wrapped_callback.execute,null);this.shared.newimages=null};var newseldiv=document.getElementById(id);newseldiv.className='kupu-libsource-selected'};this._libraryContentCallback=function(dom,src_uri){var libnode=this.shared.xmldata.selectSingleNode('//*[@selected]');var itemsnode=libnode.selectSingleNode("items");var newitemsnode=dom.selectSingleNode("//items");if(this.editor.getBrowserName()=='IE'){newitemsnode=newitemsnode.cloneNode(true)} else{newitemsnode=this.shared.xmldata.importNode(newitemsnode,true)}
if(!itemsnode){libnode.appendChild(newitemsnode)} else{libnode.replaceChild(newitemsnode,itemsnode)};this.updateDisplay(this.resourcespanelid);this.updateDisplay(this.propertiespanelid)};this.selectCollection=function(id){this.deselectActiveCollection();this.removeSelection();var leafnode_path="//collection[@id='"+id+"']";var leafnode=this.shared.xmldata.selectSingleNode(leafnode_path);var loadedInNode=leafnode.getAttribute('loadedInNode');if(loadedInNode){var collnode_path="/libraries/collection[@id='"+loadedInNode+"']";var collnode=this.shared.xmldata.selectSingleNode(collnode_path);if(collnode){collnode.setAttribute('selected','1');this.updateDisplay(this.resourcespanelid);this.updateDisplay(this.propertiespanelid);return}};uri=leafnode.selectSingleNode('uri/text()').nodeValue;uri=(new String(uri)).strip();var collnode_path="/libraries/collection/uri[text()='"+uri+"']/..";var collnode=this.shared.xmldata.selectSingleNode(collnode_path);if(collnode){id=collnode.getAttribute('id');leafnode.setAttribute('loadedInNode',id);collnode.setAttribute('selected','1');this.updateDisplay(this.resourcespanelid);this.updateDisplay(this.propertiespanelid);return};leafnode.setAttribute('selected','1');var src_uri=leafnode.selectSingleNode('src/text()').nodeValue;src_uri=src_uri.strip();var wrapped_callback=new ContextFixer(this._collectionContentCallback,this);this._loadXML(src_uri,wrapped_callback.execute,null)};this._collectionContentCallback=function(dom,src_uri){date=new Date();time=date.getTime();var leafnode=this.shared.xmldata.selectSingleNode('//*[@selected]');leafnode.setAttribute('loadedInNode',time);this.deselectActiveCollection()
var collnode=dom.selectSingleNode('/collection');collnode.setAttribute('id',time);collnode.setAttribute('selected','1');var libraries=this.shared.xmldata.selectSingleNode('/libraries');if(this.editor.getBrowserName()=='IE'){collnode=collnode.cloneNode(true)} else{collnode=this.shared.xmldata.importNode(collnode,true)}
libraries.appendChild(collnode);this.updateDisplay(this.resourcespanelid);this.updateDisplay(this.propertiespanelid)};this.reloadCurrent=function(){this.showupload='';var current=this.shared.xmldata.selectSingleNode('//*[@selected]');if(current.tagName=="resource"){current.removeAttribute("selected");current=current.parentNode;current.setAttribute("selected","1")};var src_node=current.selectSingleNode('src');if(!src_node){return};var src_uri=src_node.selectSingleNode('text()').nodeValue;src_uri=src_uri.strip();var wrapped_callback=new ContextFixer(this._libraryContentCallback,this);this._loadXML(src_uri,wrapped_callback.execute)};this.removeSelection=function(){var oldselxpath='/libraries/*[@selected]//resource[@selected]';var oldselitem=this.shared.xmldata.selectSingleNode(oldselxpath);if(oldselitem){oldselitem.removeAttribute("selected")};if(this.selecteditemid){var item=document.getElementById(this.selecteditemid);if(item){var span=item.getElementsByTagName('span');if(span.length>0){span=span[0];span.className=span.className.replace(' selected-item','')}}
this.selecteditemid=''}
this.showupload=''}
this.selectUpload=function(){this.removeSelection();this.showupload='yes';this.updateDisplay(this.resourcespanelid);this.updateDisplay(this.propertiespanelid)}
this.selectItem=function(item,id){this.removeSelection();var newselxpath='/libraries/*[@selected]//resource[@id="'+id+'"]';var newselitem=this.shared.xmldata.selectSingleNode(newselxpath);newselitem.setAttribute("selected","1");this.updateDisplay(this.propertiespanelid);var span=item.getElementsByTagName('span');if(span.length>0){span=span[0];span.className+=' selected-item'}
this.selecteditemid=id;if(this.editor.getBrowserName()=='IE'){var ppanel=document.getElementById(this.propertiespanelid)
var height=ppanel.clientHeight;if(height>ppanel.scrollHeight) height=ppanel.scrollHeight;if(height<260) height=260;document.getElementById(this.resourcespanelid).style.height=height+'px'}
return}
this.search=function(){var searchvalue=getFromSelector('kupu-searchbox-input').value;var body='SearchableText='+escape(searchvalue);var chunks=this.shared.searchuri.split('?');var searchuri=chunks[0];if(chunks[1]){body+="&"+chunks[1]};var wrapped_callback=new ContextFixer(this._searchCallback,this);this._loadXML(searchuri,wrapped_callback.execute,body)};this._searchCallback=function(dom){var resultlib=dom.selectSingleNode("/library");var items=resultlib.selectNodes("items/*");if(!items.length){alert("No results found.");return};date=new Date();time=date.getTime();resultlib.setAttribute("id",time);this.deselectActiveCollection();resultlib.setAttribute("selected","1");if(this.editor.getBrowserName()=='IE'){resultlib=resultlib.cloneNode(true)} else{resultlib=this.shared.xmldata.importNode(resultlib,true)}
var libraries=this.shared.xmldata.selectSingleNode("/libraries");libraries.appendChild(resultlib);this.updateDisplay(this.drawerid);var newseldiv=getFromSelector(time);newseldiv.className='selected'};this.save=function(){throw "Not yet implemented"};this._transformXml=function(){var doc=Sarissa.getDomDocument();var result=this.shared.xsltproc.transformToDocument(this.shared.xmldata);return result};this._loadXML=function(uri,callback,body){var xmlhttp=new XMLHttpRequest();var method='GET';if(body){method='POST'} else{body=null};xmlhttp.open(method,uri,true);var wrapped_callback=new ContextFixer(this._sarissaCallback,xmlhttp,callback,uri);xmlhttp.onreadystatechange=wrapped_callback.execute;if(method=="POST"){xmlhttp.setRequestHeader('content-type','application/x-www-form-urlencoded')};xmlhttp.send(body)};this._sarissaCallback=function(user_callback,uri){var errmessage='Error loading XML: ';if(uri){errmessage='Error loading '+uri+':'};if(this.readyState==4){if(this.status&&this.status!=200){alert(errmessage+this.status);throw "Error loading XML"};var dom=this.responseXML;user_callback(dom,uri)}}};LibraryDrawer.prototype=new Drawer;LibraryDrawer.prototype.shared={};
function ImageLibraryDrawer(tool,xsluri,libsuri,searchuri,baseelement){this.drawertitle="Insert Image";this.drawertype="image";this.showupload='';if(tool){this.init(tool,xsluri,libsuri,searchuri,baseelement)}
this.uploadImage=function(){var form=document.kupu_upload_form;if(!form||form.node_prop_image.value=='') return;if(form.node_prop_caption.value==""){alert("Please enter a title for the image you are uploading");return};var targeturi=this.shared.xmldata.selectSingleNode('/libraries/*[@selected]/uri/text()').nodeValue
document.kupu_upload_form.action=targeturi+"/kupuUploadImage";document.kupu_upload_form.submit()};this.cancelUpload=function(msg){var s=this.shared.xmldata.selectSingleNode('/libraries/*[@selected]');s.removeAttribute("selected");this.updateDisplay();if(msg!=''){alert(msg)}};this.finishUpload=function(url){this.editor.resumeEditing();var imgclass='image-inline';if(this.editor.config.captions){imgclass+=" captioned"};this.tool.createImage(url,null,imgclass);this.shared.newimages=1;this.drawertool.closeDrawer()};this.save=function(){this.editor.resumeEditing();var selxpath='//resource[@selected]';var selnode=this.shared.xmldata.selectSingleNode(selxpath);if(!selnode){var uploadbutton=this.shared.xmldata.selectSingleNode("/libraries/*[@selected]//uploadbutton");if(uploadbutton){this.uploadImage()};return};var sizeselector=document.getElementsByName('image-size-selector');if(sizeselector&&sizeselector.length>0){sizeselector=sizeselector[0];var uri=sizeselector.options[sizeselector.selectedIndex].value} else{var uri=selnode.selectSingleNode('uri/text()').nodeValue}
uri=uri.strip();var alt=getFromSelector('image_alt').value;var radios=document.getElementsByName('image-align');for(var i=0;i<radios.length;i++){if(radios[i].checked){var imgclass=radios[i].value}};var caption=document.getElementsByName('image-caption');if(caption&&caption.length>0&&caption[0].checked){imgclass+=" captioned"};this.tool.createImage(uri,alt,imgclass);this.drawertool.closeDrawer()}};ImageLibraryDrawer.prototype=new LibraryDrawer;ImageLibraryDrawer.prototype.shared={};
function LinkLibraryDrawer(tool,xsluri,libsuri,searchuri,baseelement){this.drawertitle="Insert Link";this.drawertype="link";this.showupload='';if(tool){this.init(tool,xsluri,libsuri,searchuri,baseelement)}
this.save=function(){this.editor.resumeEditing();var selxpath='//resource[@selected]';var selnode=this.shared.xmldata.selectSingleNode(selxpath);if(!selnode){return};var uri=selnode.selectSingleNode('uri/text()').nodeValue;uri=uri.strip();var title='';title=selnode.selectSingleNode('title/text()').nodeValue;title=title.strip();var type=null;var name=getFromSelector('link_name').value;var node=getFromSelector('link_target');var target=node&&node.value;this.tool.createLink(uri,type,name,target,title);this.drawertool.closeDrawer()}};LinkLibraryDrawer.prototype=new LibraryDrawer;LinkLibraryDrawer.prototype.shared={};
function HandleDrawerEnter(event,clickid){var key;event=event||window.event;key=event.which||event.keyCode;if(key==13){if(clickid){var button=document.getElementById(clickid);if(button){button.click()}}
event.cancelBubble=true;if(event.stopPropogation) event.stopPropogation();return false}
return true}


/* - kupuspellchecker.js - */
// http://10.228.150.75:8080/cms/portal_javascripts/kupuspellchecker.js?original=1
function KupuSpellChecker(buttonid,scripturl,spanstyle,winwidth,winheight,skip_tags){this.button=document.getElementById(buttonid);this.scripturl=scripturl;this.spanstyle=spanstyle||'color: red; '+'text-decoration: underline;';this.winwidth=winwidth||'600';this.winheight=winheight||'400';this.skip_tags=skip_tags||['head','script']};KupuSpellChecker.prototype=new KupuTool;KupuSpellChecker.prototype.initialize=function(editor){this.editor=editor;addEventHandler(this.button,'click',this.check,this)};KupuSpellChecker.prototype.check=function(){var request=new XMLHttpRequest();request.open('POST',this.scripturl,true);request.setRequestHeader('Content-Type','application/x-www-form-urlencoded');request.onreadystatechange=new ContextFixer(this.stateChangeHandler,this,request).execute;var result=this.getCurrentContents();result=escape(result.strip().replace('\n',' ').reduceWhitespace());request.send('text='+result)};KupuSpellChecker.prototype.stateChangeHandler=function(request){if(request.readyState==4){if(request.status=='200'){var result=request.responseXML;result=this.xmlToMapping(result);if(!result){alert(_('There were no errors.'))} else{this.displayUnrecognized(result)}} else{alert(_('Error loading data, status ${status}',{'status':request.status}))}}};KupuSpellChecker.prototype.getCurrentContents=function(){var doc=this.editor.getInnerDocument().documentElement;var iterator=new NodeIterator(doc);var bits=[];while(true){var node=iterator.next();if(!node){break};while(this.skip_tags.contains(node.nodeName.toLowerCase())){node=node.nextSibling;iterator.setCurrent(node)};if(node.nodeType==3){bits.push(node.nodeValue)}};return bits.join(' ')};KupuSpellChecker.prototype.displayUnrecognized=function(mapping){var doc=this.editor.getInnerDocument();var docel=doc.documentElement;var win=window.open('kupublank.html','spellchecker','width='+this.winwidth+','+'height='+this.winheight+',toolbar=no,'+'menubar=no,scrollbars=yes,status=yes');if(!win){alert(_('This feature requires pop-ups to be enabled on your browser!'));return};var html=docel.innerHTML;html=html.replace(/<meta[^>]*http-equiv="[Cc]ontent-[Tt]ype"[^>]*>/gm,'');win.document.write('<html>'+html+'</html>');win.deentitize=function(str){return str.deentitize()};win.document.close();if(!win.document.getElementsByTagName('body').length){addEventHandler(win,'load',this.continueDisplay,this,win,mapping)} else{this.continueDisplay(win,mapping)}};KupuSpellChecker.prototype.continueDisplay=function(win,mapping){timer_instance.registerFunction(this,this.continueDisplayHelper,1000,win,mapping)};KupuSpellChecker.prototype.continueDisplayHelper=function(win,mapping){var body=win.document.getElementsByTagName('body')[0];body.setAttribute('contentEditable','false');var iterator=new NodeIterator(body);var node=iterator.next();timer_instance.registerFunction(this,this.displayHelperNodeLoop,10,iterator,node,win,mapping)};KupuSpellChecker.prototype.displayHelperNodeLoop=function(iterator,node,win,mapping){if(!node){return};var next=iterator.next();if(node.nodeType==3){if(win.closed){return};var span=win.document.createElement('span');var before=node.nodeValue;var after=this.colourText(before,mapping);if(before!=after){span.innerHTML=after;var last=span.lastChild;var parent=node.parentNode;parent.replaceChild(last,node);while(span.hasChildNodes()){parent.insertBefore(span.firstChild,last)}}} else if(node.nodeType==1&&node.nodeName.toLowerCase()=='a'){var cancelEvent=function(e){if(e.preventDefault){e.preventDefault()} else{e.returnValue=false};return false};addEventHandler(node,'click',cancelEvent);addEventHandler(node,'mousedown',cancelEvent);addEventHandler(node,'mouseup',cancelEvent)};timer_instance.registerFunction(this,this.displayHelperNodeLoop,10,iterator,next,win,mapping)};KupuSpellChecker.prototype.colourText=function(text,mapping){var currtext=text;var newtext='';for(var word in mapping){var replacements=mapping[word];replacements=replacements.entitize();replacements=replacements.replace(/\'/g,"&apos;");var reg=new RegExp('^(.*\\\W)?('+word+')(\\\W.*)?$','mg');while(true){var match=reg.exec(currtext);if(!match){newtext+=currtext;currtext=newtext;newtext='';break};var m=(match[1]||'')+match[2];newtext+=currtext.substr(0,currtext.indexOf(m));newtext+=(match[1]||'')+'<span style="'+this.spanstyle+'" '+'onclick="alert(deentitize(\''+replacements+'\'));" '+'title="'+replacements+'">'+match[2]+'</span>';currtext=currtext.substr(currtext.indexOf(m)+m.length)}};return currtext};KupuSpellChecker.prototype.xmlToMapping=function(docnode){var docel=docnode.documentElement;var result={};var incorrect=docel.getElementsByTagName('incorrect');for(var i=0;i<incorrect.length;i++){var word=incorrect[i].firstChild.firstChild.nodeValue;var replacements='';if(incorrect[i].lastChild.hasChildNodes()){replacements=incorrect[i].lastChild.firstChild.nodeValue};result[word]=replacements};var attrs=[];return result};

/* - kupuploneinit.js - */
// http://10.228.150.75:8080/cms/portal_javascripts/kupuploneinit.js?original=1
function initPloneKupu(editorId){var topnode=getFromSelector(editorId);var prefix='#'+editorId+' ';var iframe=getFromSelector(prefix+'iframe.kupu-editor-iframe');var textarea=getFromSelector(prefix+'textarea.kupu-editor-textarea');var l=new DummyLogger();var ibody=iframe.contentWindow.document.body;var form=textarea.form;var initialtext=textarea.value||(_SARISSA_IS_IE?'<p></p>':'<p><br></p>');var conf=loadDictFromXML(document,prefix+'xml.kupuconfig');var doc=new KupuDocument(iframe);var kupu=new KupuEditor(doc,conf,l);kupu.setHTMLBody(initialtext);var cm=new ContextMenu();kupu.setContextMenu(cm);var ui=new KupuUI(prefix+'select.kupu-tb-styles');kupu.registerTool('ui',ui);var execCommand=function(cmd){return function(button,editor){editor.execCommand(cmd)}};var boldchecker=ParentWithStyleChecker(new Array('b','strong'),'font-weight','bold');var boldbutton=new KupuStateButton(prefix+'button.kupu-bold',execCommand('bold'),boldchecker,'kupu-bold','kupu-bold-pressed');kupu.registerTool('boldbutton',boldbutton);var italicschecker=ParentWithStyleChecker(new Array('i','em'),'font-style','italic');var italicsbutton=new KupuStateButton(prefix+'button.kupu-italic',execCommand('italic'),italicschecker,'kupu-italic','kupu-italic-pressed');kupu.registerTool('italicsbutton',italicsbutton);var subscriptchecker=ParentWithStyleChecker(new Array('sub'));var subscriptbutton=new KupuStateButton(prefix+'button.kupu-subscript',execCommand('subscript'),subscriptchecker,'kupu-subscript','kupu-subscript-pressed');kupu.registerTool('subscriptbutton',subscriptbutton);var superscriptchecker=ParentWithStyleChecker(new Array('super','sup'));var superscriptbutton=new KupuStateButton(prefix+'button.kupu-superscript',execCommand('superscript'),superscriptchecker,'kupu-superscript','kupu-superscript-pressed');kupu.registerTool('superscriptbutton',superscriptbutton);var justifyleftbutton=new KupuButton(prefix+'button.kupu-justifyleft',execCommand('justifyleft'));kupu.registerTool('justifyleftbutton',justifyleftbutton);var justifycenterbutton=new KupuButton(prefix+'button.kupu-justifycenter',execCommand('justifycenter'));kupu.registerTool('justifycenterbutton',justifycenterbutton);var justifyrightbutton=new KupuButton(prefix+'button.kupu-justifyright',execCommand('justifyright'));kupu.registerTool('justifyrightbutton',justifyrightbutton);var outdentbutton=new KupuButton(prefix+'button.kupu-outdent',execCommand('outdent'));kupu.registerTool('outdentbutton',outdentbutton);var indentbutton=new KupuButton(prefix+'button.kupu-indent',execCommand('indent'));kupu.registerTool('indentbutton',indentbutton);var undobutton=new KupuButton(prefix+'button.kupu-undo',execCommand('undo'));kupu.registerTool('undobutton',undobutton);var redobutton=new KupuButton(prefix+'button.kupu-redo',execCommand('redo'));kupu.registerTool('redobutton',redobutton);var removeimagebutton=new KupuRemoveElementButton(prefix+'button.kupu-removeimage','img','kupu-removeimage');kupu.registerTool('removeimagebutton',removeimagebutton);var removelinkbutton=new KupuRemoveElementButton(prefix+'button.kupu-removelink','a','kupu-removelink');kupu.registerTool('removelinkbutton',removelinkbutton);var listtool=new ListTool(prefix+'button.kupu-insertunorderedlist',prefix+'button.kupu-insertorderedlist',prefix+'select.kupu-ulstyles',prefix+'select.kupu-olstyles');kupu.registerTool('listtool',listtool);var definitionlisttool=new DefinitionListTool(prefix+'button.kupu-insertdefinitionlist');kupu.registerTool('definitionlisttool',definitionlisttool);var tabletool=new TableTool();kupu.registerTool('tabletool',tabletool);var showpathtool=new ShowPathTool('kupu-showpath-field');kupu.registerTool('showpathtool',showpathtool);var sourceedittool=new SourceEditTool(prefix+'button.kupu-source',prefix+'textarea.kupu-editor-textarea');kupu.registerTool('sourceedittool',sourceedittool);var imagetool=NoContextMenu(new ImageTool());kupu.registerTool('imagetool',imagetool);var linktool=NoContextMenu(new LinkTool());kupu.registerTool('linktool',linktool);var zoom=new KupuZoomTool(prefix+'button.kupu-zoom',prefix+'select.kupu-tb-styles',prefix+'button.kupu-logo');kupu.registerTool('zoomtool',zoom);if(typeof KupuSpellChecker!='undefined'){var spellchecker=new KupuSpellChecker('kupu-spellchecker-button','kupu_library_tool/spellcheck');kupu.registerTool('spellchecker',spellchecker)} else{var spellchecker_tool=document.getElementById('kupu-spellchecker');spellchecker_tool.style.display='none'}
var beforeunloadTool=window.onbeforeunload&&window.onbeforeunload.tool;if(beforeunloadTool){var initialBody=ibody.innerHTML;beforeunloadTool.addHandler(function(){return ibody.innerHTML!=initialBody});beforeunloadTool.chkId[textarea.id]=function(){return false}
beforeunloadTool.addForm(form)}
var fmtname=textarea.name+'_text_format';var pulldown=form[fmtname];if(pulldown&&pulldown.type=='select-one'){for(var i=0 ;i<pulldown.length;i++){var opt=pulldown.options[i];opt.selected=opt.defaultSelected=(opt.value=='text/html')}
pulldown.disabled=true;var hidden=document.createElement('input');hidden.type='hidden';hidden.name=fmtname;hidden.value='text/html';pulldown.parentNode.appendChild(hidden)};var opendrawer=function(drawerid){return function(button,editor){drawertool.openDrawer(prefix+drawerid)}};var imagelibdrawerbutton=new KupuButton(prefix+'button.kupu-image',opendrawer('imagelibdrawer'));kupu.registerTool('imagelibdrawerbutton',imagelibdrawerbutton);var linklibdrawerbutton=new KupuButton(prefix+'button.kupu-inthyperlink',opendrawer('linklibdrawer'));kupu.registerTool('linklibdrawerbutton',linklibdrawerbutton);var linkdrawerbutton=new KupuButton(prefix+'button.kupu-exthyperlink',opendrawer('linkdrawer'));kupu.registerTool('linkdrawerbutton',linkdrawerbutton);var tabledrawerbutton=new KupuButton(prefix+'button.kupu-table',opendrawer('tabledrawer'));kupu.registerTool('tabledrawerbutton',tabledrawerbutton);var drawertool=window.drawertool||new DrawerTool();kupu.registerTool('drawertool',drawertool);var drawerparent=prefix+'div.kupu-librarydrawer-parent';var linklibdrawer=new LinkLibraryDrawer(linktool,conf['link_xsl_uri'],conf['link_libraries_uri'],conf['search_links_uri'],drawerparent);drawertool.registerDrawer(prefix+'linklibdrawer',linklibdrawer,kupu);var imagelibdrawer=new ImageLibraryDrawer(imagetool,conf['image_xsl_uri'],conf['image_libraries_uri'],conf['search_images_uri'],drawerparent);drawertool.registerDrawer(prefix+'imagelibdrawer',imagelibdrawer,kupu);var linkdrawer=new LinkDrawer(prefix+'div.kupu-linkdrawer',linktool);drawertool.registerDrawer(prefix+'linkdrawer',linkdrawer,kupu);var tabledrawer=new TableDrawer(prefix+'div.kupu-tabledrawer',tabletool);drawertool.registerDrawer(prefix+'tabledrawer',tabledrawer,kupu);
function prepareForm(event){kupu.saveDataToField(this.form,this);var drawer=window.document.getElementById('kupu-librarydrawer');if(drawer){drawer.parentNode.removeChild(drawer)}};addEventHandler(textarea.form,'submit',prepareForm,textarea);return kupu};
