var ImageViewer=Class.create({initialize:function(links){this.options=Object.extend({langCaption:'',langPrevious:'',langNext:'',langPlay:'',langPause:'',langEnlarge:'',langClose:'',imgBlankSrc:'',imgMenuSrc:'',imgPlaySrc:'',imgPreviousSrc:'',imgNextSrc:'',imgEnlargeSrc:'',imgPauseSrc:'',imgCloseSrc:'',imgPlayHoverSrc:'',imgPreviousHoverSrc:'',imgNextHoverSrc:'',imgEnlargeHoverSrc:'',imgPauseHoverSrc:'',imgCloseHoverSrc:'',slideShowDuration:5},arguments[1]||{});this.links=links;this.currentIndex=0;this.maxWidth=document.viewport.getWidth()-60;this.maxHeight=document.viewport.getHeight()-60;this.isOpen=false;this.isPlaying=false;this.isOverMenu=false;this.currentImage=null;this.menuIsAppearing=false;this.createFrame();links.invoke('observe','click',this.open.bindAsEventListener(this));this.cacheBoundingFunctions();},open:function(evt){element=evt.findElement();if(element.nodeName.toLowerCase()=='a'){this.currentLink=element;}
else{this.currentLink=element.parentNode;}
this.links.each(function(link,index){if(this.currentLink==link){this.currentIndex=index;}}.bind(this));this.show(true);evt.stop();},show:function(startFromCurrentLink){var startFromCurrentLink=arguments[0]?arguments[0]:false;this.background.appear({duration:0.2,to:0.6});if(IS_IE6){$$('select').invoke('setStyle','visibility: hidden');}
if(startFromCurrentLink&&this.currentLink.down('img')&&!IS_IE6&&!IS_SAFARI_MOBILE){var left=this.currentLink.down('img').viewportOffset()['left'];var top=this.currentLink.down('img').viewportOffset()['top'];if(IS_OPERA){var topOffset=document.viewport.getScrollOffsets();top-=topOffset.top;}
this.currentImage=new Element('img',{'src':this.options.imgBlankSrc,'style':'left: '+left+'px; top: '+top+'px; width: '+this.currentLink.down('img').getWidth()+'px; height: '+this.currentLink.down('img').getHeight()+'px;'}).addClassName('imageViewerCurrentImage');}
else{var left=document.viewport.getWidth()/2-200;var top=document.viewport.getHeight()/2-100+(IS_IE6||IS_SAFARI_MOBILE?document.viewport.getScrollOffsets().top:0);this.currentImage=new Element('img',{'src':this.options.imgBlankSrc,'style':'left: '+left+'px; top: '+top+'px;'}).addClassName('imageViewerCurrentImage');}
$$('body')[0].insert(this.currentImage);this.isOpen=true;this.showMenu();this.writeInfoLine();this.registerEventHandlers();this.loadImage(this.currentLink.href);},close:function(evt){if(evt!=null&&evt.type=='keyup'&&evt.keyCode!=Event.KEY_ESC&&evt.keyCode!=Event.KEY_BACKSPACE){return;}
this.isOpen=false;this.unregisterEventHandlers();if(this.menuTimer){this.menuTimer.stop();}
this.menu.hide();this.currentImage.remove();if(this.isPlaying){this.play();}
this.resetButtons();this.background.fade({duration:0.2});if(IS_IE6){$$('select').invoke('setStyle','visibility: visible');}
evt.stop();},cacheBoundingFunctions:function(){this._changeWindow=this.changeWindow.bindAsEventListener(this);this._showMenu=this.showMenu.bindAsEventListener(this);this._close=this.close.bindAsEventListener(this);this._enlarge=this.enlarge.bindAsEventListener(this);this._hoverMenu=this.hoverMenu.bindAsEventListener(this);this._hoverCloseButton=this.hoverCloseButton.bindAsEventListener(this);this._hoverEnlargeButton=this.hoverEnlargeButton.bindAsEventListener(this);this._hoverPlayButton=this.hoverPlayButton.bindAsEventListener(this);this._hoverPreviousButton=this.hoverPreviousButton.bindAsEventListener(this);this._hoverNextButton=this.hoverNextButton.bindAsEventListener(this);this._previous=this.previous.bindAsEventListener(this);this._play=this.play.bindAsEventListener(this);this._next=this.next.bindAsEventListener(this);},registerEventHandlers:function(){Event.observe(window,'resize',this._changeWindow);document.observe('mousemove',this._showMenu);document.observe('keyup',this._close);this.menu.observe('mouseover',this._hoverMenu);this.menu.observe('mouseout',this._hoverMenu);this.closeButton.observe('click',this._close);this.closeButton.observe('mouseover',this._hoverCloseButton);this.closeButton.observe('mouseout',this._hoverCloseButton);this.enlargeButton.observe('click',this._enlarge);this.enlargeButton.observe('mouseover',this._hoverEnlargeButton);this.enlargeButton.observe('mouseout',this._hoverEnlargeButton);this.background.observe('click',this._close);if(this.links.length>1){document.observe('keyup',this._next);document.observe('keyup',this._previous);document.observe('keydown',this._play);this.previousButton.observe('click',this._previous);this.previousButton.observe('mouseover',this._hoverPreviousButton);this.previousButton.observe('mouseout',this._hoverPreviousButton);this.playButton.observe('click',this._play);this.playButton.observe('mouseover',this._hoverPlayButton);this.playButton.observe('mouseout',this._hoverPlayButton);this.nextButton.observe('click',this._next);this.nextButton.observe('mouseover',this._hoverNextButton);this.nextButton.observe('mouseout',this._hoverNextButton);this.currentImage.observe('click',this._next);}},unregisterEventHandlers:function(){Event.stopObserving(window,'resize',this._changeWindow);document.stopObserving('mousemove',this._showMenu);document.stopObserving('keyup',this._close);this.menu.stopObserving();this.closeButton.stopObserving();this.enlargeButton.stopObserving();this.background.stopObserving();if(this.links.length>1){document.stopObserving('keyup',this._next);document.stopObserving('keyup',this._previous);document.stopObserving('keydown',this._play);this.previousButton.stopObserving();this.playButton.stopObserving();this.nextButton.stopObserving();this.currentImage.stopObserving();}},enlarge:function(){location.href=this.currentLink.href;},loadImage:function(url){this.currentImage.addClassName('imageViewerLoading');this.newImage=new Image();this.newImage.onload=function(){this.exchangeImage();}.bindAsEventListener(this);this.newImage.onerror=function(){if(this.currentLink.down('img')){this.newImage.src=this.currentLink.down('img').src;}
else{this.newImage.src=this.options.imgCloseSrc;}
this.exchangeImage();}.bindAsEventListener(this);this.newImage.src=url;},writeInfoLine:function(){this.caption.update(eval(this.options.langCaption));},exchangeImage:function(){var size=this.calculateSize(this.newImage);var left=document.viewport.getWidth()/2-size['width']/2;var top=document.viewport.getHeight()/2-size['height']/2;if(IS_IE){this.caption.setStyle('top: '+(document.viewport.getScrollOffsets().top+5)+'px; width: '+$$('body')[0].getWidth()+'px;');}
new Effect.Morph(this.currentImage,{duration:0.5,style:'height: '+size['height']+'px; width: '+size['width']+'px; left: '+left+'px; top: '+(IS_IE6||IS_SAFARI_MOBILE?document.viewport.getScrollOffsets().top+top:top)+'px;',afterFinish:function(){this.currentImage.src=this.newImage.src;this.currentImage.removeClassName('imageViewerLoading');if(this.isPlaying)this.playingTimer=window.setTimeout(this.next.bind(this),this.options.slideShowDuration*1000);this.changeWindow();}.bind(this)});},calculateSize:function(image){if(image.width>this.maxWidth||image.height>this.maxHeight){if(this.maxWidth/image.width<this.maxHeight/image.height){width=this.maxWidth;height=Math.round(image.height*(width/image.width));}
else{height=this.maxHeight;width=Math.round(image.width*(height/image.height));}}
else{width=image.width;height=image.height;}
return{'width':width,'height':height};},createFrame:function(){this.background=new Element('div').addClassName('imageViewerBackground');if(IS_IE6||IS_SAFARI_MOBILE){this.background.setStyle('height: '+$$('body')[0].getHeight()+'px; width: '+$$('body')[0].getWidth()+'px;');}
this.background.hide();$$('body')[0].insert(this.background);this.caption=new Element('p').addClassName('imageViewerCaption');this.background.insert(this.caption);this.menu=new Element('div',{'style':'left: '+(document.viewport.getWidth()/2-200/2)+'px;'}).addClassName('imageViewerMenu');this.menu.hide();this.previousButton=new Element('img',{'id':'previousImage','src':this.options.imgPreviousSrc,'style':'margin: 0 10px; cursor: pointer','title':this.options.langPrevious});if(this.links.length==1){this.previousButton.setOpacity(0.2);this.previousButton.setStyle({cursor:'default'});this.previousButton.title='';}
this.menu.insert(this.previousButton);this.playButton=new Element('img',{'id':'playImage','src':this.options.imgPlaySrc,'style':'margin: 0 10px; cursor: pointer','title':this.options.langPlay});if(this.links.length==1){this.playButton.setOpacity(0.2);this.playButton.setStyle({cursor:'default'});this.playButton.title='';}
this.menu.insert(this.playButton);this.nextButton=new Element('img',{'id':'nextImage','src':this.options.imgNextSrc,'style':'margin: 0 10px; cursor: pointer','title':this.options.langNext});if(this.links.length==1){this.nextButton.setOpacity(0.2);this.nextButton.setStyle({cursor:'default'});this.nextButton.title='';}
this.menu.insert(this.nextButton);this.enlargeButton=new Element('img',{'id':'enlargeButton','src':this.options.imgEnlargeSrc,'style':'margin: 0 10px; cursor: pointer','title':this.options.langEnlarge});this.menu.insert(this.enlargeButton);this.closeButton=new Element('img',{'id':'closeImageViewer','src':this.options.imgCloseSrc,'style':'margin: 0 10px; cursor: pointer','title':this.options.langClose});this.menu.insert(this.closeButton);$$('body')[0].insert(this.menu);},resetButtons:function(){if(this.links.length>1){this.previousButton.src=this.options.imgPreviousSrc;this.playButton.src=this.options.imgPlaySrc;this.nextButton.src=this.options.imgNextSrc;}
this.enlargeButton.src=this.options.imgEnlargeSrc;this.closeButton.src=this.options.imgCloseSrc;},hoverMenu:function(evt){if(evt.type=='mouseover'){this.isOverMenu=true;}
else{this.isOverMenu=false;}},hoverCloseButton:function(evt){this.closeButton.src=evt.type=='mouseout'?this.options.imgCloseSrc:this.options.imgCloseHoverSrc;},hoverEnlargeButton:function(evt){this.enlargeButton.src=evt.type=='mouseout'?this.options.imgEnlargeSrc:this.options.imgEnlargeHoverSrc;},hoverPreviousButton:function(evt){this.previousButton.src=evt.type=='mouseout'?this.options.imgPreviousSrc:this.options.imgPreviousHoverSrc;},hoverNextButton:function(evt){this.nextButton.src=evt.type=='mouseout'?this.options.imgNextSrc:this.options.imgNextHoverSrc;},hoverPlayButton:function(evt){if(this.isPlaying){this.playButton.src=evt.type=='mouseout'?this.options.imgPauseSrc:this.options.imgPauseHoverSrc;}
else{this.playButton.src=evt.type=='mouseout'?this.options.imgPlaySrc:this.options.imgPlayHoverSrc;}},play:function(evt){if(evt!=null&&evt.type=='keydown'&&evt.keyCode!=32){return;}
if(this.isPlaying){window.clearTimeout(this.playingTimer);if(evt!=null&&evt.type=='keydown'){this.showMenu();setTimeout(function(){this.playButton.src=this.options.imgPauseHoverSrc;setTimeout(function(){this.playButton.src=this.options.imgPlayHoverSrc;setTimeout(function(){this.playButton.src=this.options.imgPlaySrc;}.bind(this),100);}.bind(this),100);}.bind(this),100);}
else{this.playButton.src=this.options.imgPlayHoverSrc;}
this.playButton.title=this.options.langPlay;this.isPlaying=false;}
else{this.playingTimer=window.setTimeout(this.next.bind(this),this.options.slideShowDuration*1000);if(evt!=null&&evt.type=='keydown'){this.showMenu();setTimeout(function(){this.playButton.src=this.options.imgPlayHoverSrc;setTimeout(function(){this.playButton.src=this.options.imgPauseHoverSrc;setTimeout(function(){this.playButton.src=this.options.imgPauseSrc;}.bind(this),100);}.bind(this),100);}.bind(this),100);}
else{if(this.isOverMenu){this.playButton.src=this.options.imgPauseHoverSrc;}
else{this.playButton.src=this.options.imgPauseSrc;}}
this.playButton.title=this.options.langPause;this.isPlaying=true;}
if(evt!=null&&evt.type=='keydown')evt.stop();},showMenu:function(){if(this.isOpen&&!this.menuIsAppearing){this.menu.appear({duration:0.1,to:0.6,beforeStart:function(){this.menuIsAppearing=true;}.bind(this),afterFinish:function(){this.menuIsAppearing=false;if(!this.isOpen){this.hideMenu();}}.bind(this)});if(this.menuTimer!=null){this.menuTimer.stop();}
if(!this.isOverMenu){this.menuTimer=new PeriodicalExecuter(this.hideMenu.bind(this),2);}}},hideMenu:function(){if(this.menu&&!IS_SAFARI_MOBILE){this.menu.fade({duration:0.1});}
if(this.menuTimer){this.menuTimer.stop();}},next:function(evt){if(evt!=null&&evt.type=='keyup'&&evt.keyCode!=Event.KEY_RIGHT){return;}
window.clearTimeout(this.playingTimer);if(evt!=null&&evt.type=='keyup'){this.showMenu();setTimeout(function(){this.nextButton.src=this.options.imgNextHoverSrc;setTimeout(function(){this.nextButton.src=this.options.imgNextSrc;}.bind(this),100);}.bind(this),100);}
this.currentImage.src=this.options.imgBlankSrc;if(this.currentIndex+1==this.links.size()){this.currentIndex=0;}
else{this.currentIndex++;}
this.currentLink=this.links[this.currentIndex];this.scrollToCurrentImage();this.writeInfoLine();this.loadImage(this.currentLink.href);},previous:function(evt){if(evt!=null&&evt.type=='keyup'&&evt.keyCode!=Event.KEY_LEFT){return;}
if(evt!=null&&evt.type=='keyup'){this.showMenu();setTimeout(function(){this.previousButton.src=this.options.imgPreviousHoverSrc;setTimeout(function(){this.previousButton.src=this.options.imgPreviousSrc;}.bind(this),100);}.bind(this),100);}
this.currentImage.src=this.options.imgBlankSrc;if(this.currentIndex==0){this.currentIndex=this.links.size()-1;}
else{this.currentIndex--;}
this.currentLink=this.links[this.currentIndex];this.scrollToCurrentImage();this.writeInfoLine();this.loadImage(this.currentLink.href);},scrollToCurrentImage:function(){var linkPos1=this.currentLink.cumulativeOffset()[1];var linkPos2=linkPos1+this.currentLink.getHeight();var viewportPos1=document.viewport.getScrollOffsets()[1];var viewportPos2=viewportPos1+document.viewport.getHeight();if(!IS_IE6&&!IS_SAFARI_MOBILE&&!(linkPos1>viewportPos1&&linkPos1<viewportPos2||linkPos2>viewportPos1&&linkPos2<viewportPos2)){this.currentLink.scrollTo();}},changeWindow:function(){this.maxWidth=document.viewport.getWidth()-60;this.maxHeight=document.viewport.getHeight()-60;var size=this.calculateSize(this.newImage);var left=document.viewport.getWidth()/2-size['width']/2;var top=document.viewport.getHeight()/2-size['height']/2+ +(IS_IE6||IS_SAFARI_MOBILE?document.viewport.getScrollOffsets().top:0);this.currentImage.setStyle('height: '+size['height']+'px; width: '+size['width']+'px; left: '+left+'px; top: '+top+'px;');this.menu.setStyle('left: '+(document.viewport.getWidth()/2-this.menu.getWidth()/2)+'px;');if(IS_SAFARI_MOBILE)this.menu.setStyle('top: '+(document.viewport.getScrollOffsets().top+document.viewport.getHeight()-this.menu.getHeight()-20)+'px;');}});function MultiPagesLinks(){this.pageLink='';this.setPageLink=function(pageLink){this.pageLink=pageLink;}
this.startPageNumberInput=function(element){element.style.display='none';element.nextSibling.style.display='block';element.nextSibling.value='';element.nextSibling.onkeydown=function(e){return multiPagesLinks.handlePageNumberInput(e);};element.nextSibling.onblur=function(){multiPagesLinks.stopPageNumberInput(this);};element.nextSibling.focus();}
this.handlePageNumberInput=function(event){if(!event)event=window.event;if(event.which){var keyCode=event.which;}
else if(event.keyCode){var keyCode=event.keyCode;}
var target;if(event.target)target=event.target;else if(event.srcElement)target=event.srcElement;if(keyCode==13){document.location.href=fixURL(this.pageLink.replace(/%d/,parseInt(target.value)));}
if(keyCode==13||keyCode==27){this.stopPageNumberInput(target);}
return true;}
this.stopPageNumberInput=function(element){element.style.display='none';element.previousSibling.style.display='block';}}
var multiPagesLinks=new MultiPagesLinks();function ImageResizer(){this.defaultMaxWidth=530;this.resize=function(){if(!INLINE_IMAGE_MAX_WIDTH){INLINE_IMAGE_MAX_WIDTH=this.defaultMaxWidth;}
for(var i=0;i<document.images.length;i++){if(document.images[i].className=='resizeImage'){var imageWidth=document.images[i].width;var imageHeight=document.images[i].height;if(imageWidth>INLINE_IMAGE_MAX_WIDTH){document.images[i].width=INLINE_IMAGE_MAX_WIDTH;document.images[i].height=Math.round(imageHeight*(INLINE_IMAGE_MAX_WIDTH/imageWidth));if(!this.isLinked(document.images[i])){var popupLink=document.createElement("a");popupLink.className='externalURL';popupLink.setAttribute('href',document.images[i].src);popupLink.appendChild(document.images[i].cloneNode(true));document.images[i].parentNode.replaceChild(popupLink,document.images[i]);}}}}}
this.isLinked=function(node){do{node=node.parentNode;if(node==undefined)break;if(node.nodeName=='A')return true;}
while(node.nodeName!='TD'&&node.nodeName!='P'&&node.nodeName!='DIV'&&node.nodeName!='BODY');return false;}
this.resize();}
onloadEvents.push(function(){new ImageResizer();});onloadEvents.push(function(){$$('.embeddedAttachment').each(function(image){image.setStyle({width:'auto',height:'auto'});});});var MultiQuote=Class.create({initialize:function(data,formURL){this.options=Object.extend({langButtonQuote:'',langButtonQuoteMultiple:'',langQuoteDirectly:'',langMarkToQuote:'',langQuoteTextDirectly:'',langMarkTextToQuote:'',langRemoveQuotes:'',langQuoteParagraphDirectly:'',langMarkParagraphToQuote:'',langQuoteParagraphsDirectly:'',langMarkParagraphsToQuote:'',iconMessageQuoteOptions:''},arguments[2]||{});this.data=data;this.formURL=formURL;var multiQuote=this;this.data.each(function(objectData){multiQuote.initializeObject.apply(multiQuote,[objectData]);});},initializeObject:function(objectData){var multiQuote=this;var button=$(objectData.value.objectType+'Quote'+objectData.value.objectID);if(!button){var buttonBar=document.getElementById(objectData.value.objectType+'Buttons'+objectData.value.objectID);if(buttonBar){var li=document.createElement('li');li.className='options';if(buttonBar.childNodes.length<2){buttonBar.appendChild(li);}
else{buttonBar.insertBefore(li,buttonBar.childNodes[2]);}
button=new Element('a');button.id=objectData.value.objectType+'Quote'+objectData.value.objectID;li.appendChild(button);var img=document.createElement('img');img.src=this.options.iconMessageQuoteOptions;button.appendChild(img);button.appendChild(document.createTextNode(' '));var span=document.createElement('span');button.appendChild(span);span.appendChild(document.createTextNode(this.options.langButtonQuote));}}
if(button){button.up().addClassName('options');button.href="javascript:void(0);";if(this.formURL){button.ondblclick=function(){multiQuote.quoteDirectly.apply(multiQuote,[objectData.value.objectType,objectData.value.objectID]);};}
if(button.firstChild&&button.firstChild.src){var icon=button.firstChild;icon.src=this.options.iconMessageQuoteOptions;}
button.onmousedown=function(){multiQuote.showMenu.apply(multiQuote,[objectData.value.objectType,objectData.value.objectID]);};var menuDiv=document.createElement('div');menuDiv.id=objectData.value.objectType+'Quote'+objectData.value.objectID+'Menu';menuDiv.className='hidden';button.parentNode.appendChild(menuDiv);popupMenuList.register(objectData.value.objectType+'Quote'+objectData.value.objectID);}
if(objectData.value.quotes>0){this.updateQuoteButton(objectData.value.objectType,objectData.value.objectID);}},updateQuoteButton:function(objectType,objectID){var button=$(objectType+'Quote'+objectID);if(button){var objectValue=this.data.get(objectType+'-'+objectID);if(objectValue.quotes>0){button.up().addClassName('selected');}
else{button.up().removeClassName('selected');}
if(button.childNodes[2]&&button.childNodes[2].firstChild){button.childNodes[2].removeChild(button.childNodes[2].firstChild);button.childNodes[2].appendChild(document.createTextNode(eval(this.options.langButtonQuoteMultiple)));}}},getSelectedText:function(objectType,objectID){this.selectedText='';var selectedText='';if(window.getSelection){selectedText=window.getSelection().toString();if(selectedText==undefined){selectedText=new String(window.getSelection());}}
else if(document.getSelection){selectedText=document.getSelection().toString();}
else if(document.selection){selectedText=document.selection.createRange().text;}
if(selectedText!=''){var availableText=this.getAvailableText(objectType,objectID);availableText=availableText.replace(/\s+/g,'');var text=new String(selectedText).replace(/\s+/g,'');if(availableText.indexOf(text)!=-1){this.selectedText=new String(selectedText);}}},getAvailableText:function(objectType,objectID){var element=document.getElementById(objectType+'Text'+objectID);if(!element)return'';return this.getNodeText(element);},getNodeText:function(node){var nodeText='';for(var i=0;i<node.childNodes.length;i++){if(node.childNodes[i].nodeType==3){nodeText+=node.childNodes[i].nodeValue;}
else{if(IS_MOZILLA&&node.childNodes[i].nodeName.toLowerCase()=='img'&&node.childNodes[i].alt){nodeText+=node.childNodes[i].alt;}
if(IS_IE&&node.childNodes[i].nodeName.toLowerCase()=='br'){nodeText+='\n';}
nodeText+=this.getNodeText(node.childNodes[i]);}}
return nodeText;},getQuoteOptions:function(objectType,objectID){var multiQuote=this;var options=new Array();var i=0;this.getSelectedText(objectType,objectID);if(this.formURL){options[i]=new Object();options[i]['function']=function(){multiQuote.quoteDirectly.apply(multiQuote,[objectType,objectID]);};options[i]['text']=(this.selectedText!=''?this.options.langQuoteTextDirectly:this.options.langQuoteDirectly);i++;}
options[i]=new Object();options[i]['function']=function(){multiQuote.markToQuote.apply(multiQuote,[objectType,objectID]);};options[i]['text']=(this.selectedText!=''?this.options.langMarkTextToQuote:this.options.langMarkToQuote);options[i]['className']='bottomSeparator';i++;if(this.selectedText!=''){if(this.formURL){options[i]=new Object();options[i]['function']=function(){multiQuote.quoteParagraphDirectly.apply(multiQuote,[objectType,objectID]);};options[i]['text']=this.options.langQuoteParagraphDirectly;i++;}
options[i]=new Object();options[i]['function']=function(){multiQuote.markParagraphToQuote.apply(multiQuote,[objectType,objectID]);};options[i]['text']=this.options.langMarkParagraphToQuote;i++;}
else{if(this.formURL){options[i]=new Object();options[i]['function']=function(){multiQuote.quoteParagraphsDirectly.apply(multiQuote,[objectType,objectID]);};options[i]['text']=this.options.langQuoteParagraphsDirectly;i++;}
options[i]=new Object();options[i]['function']=function(){multiQuote.markParagraphsToQuote.apply(multiQuote,[objectType,objectID]);};options[i]['text']=this.options.langMarkParagraphsToQuote;i++;}
var objectValue=this.data.get(objectType+'-'+objectID);if(objectValue.quotes){options[i]=new Object();options[i]['function']=function(){multiQuote.removeQuotes.apply(multiQuote,[objectType,objectID]);};options[i]['text']=this.options.langRemoveQuotes;options[i]['className']='topSeparator';i++;}
return options;},showMenu:function(objectType,objectID){var options=this.getQuoteOptions(objectType,objectID);this.createMenu(options,objectType,objectID);},createMenu:function(options,objectType,objectID){var menuDiv=document.getElementById(objectType+'Quote'+objectID+'Menu');while(menuDiv.hasChildNodes()){menuDiv.removeChild(menuDiv.firstChild);}
var menuUL=document.createElement('ul');menuDiv.appendChild(menuUL);for(var i=0;i<options.length;i++){var menuLI=document.createElement('li');menuUL.appendChild(menuLI);if(options[i]['className'])menuLI.className=options[i]['className'];var menuA=document.createElement('a');menuA.onclick=options[i]['function'];menuLI.appendChild(menuA);menuA.appendChild(document.createTextNode(options[i]['text']));}},quoteDirectly:function(objectType,objectID){this.saveQuote(objectType,objectID,this.selectedText,true);},getParagraphText:function(objectType,objectID){var text=this.getAvailableText(objectType,objectID);var selectionStart=text.indexOf(this.selectedText);if(selectionStart!=-1){var linebreak=false;for(var paragraphStart=selectionStart;paragraphStart>=0;paragraphStart--){if(text.charAt(paragraphStart)=='\n'){if(linebreak){paragraphStart=paragraphStart+2;break;}
else{linebreak=true;}}
else{linebreak=false;}}
linebreak=false;for(var paragraphEnd=selectionStart+this.selectedText.length;paragraphEnd<text.length;paragraphEnd++){if(text.charAt(paragraphEnd)=='\n'){if(linebreak){paragraphEnd=paragraphEnd-1;break;}
else{linebreak=true;}}
else{linebreak=false;}}
return text.substring(paragraphStart,paragraphEnd).strip();}
return'';},getParagraphs:function(objectType,objectID){var text=this.getAvailableText(objectType,objectID);var paragraphs=new Array();var linebreak=false;var lastPosition=0;for(var i=0;i<text.length;i++){if(text.charAt(i)=='\n'){if(linebreak){var paragraphText=text.substring(lastPosition,i-1).strip();if(paragraphText!='')paragraphs.push(paragraphText);lastPosition=i+1;}
else{linebreak=true;}}
else{linebreak=false;}}
var paragraphText=text.substring(lastPosition).strip();if(paragraphText!='')paragraphs.push(paragraphText);return paragraphs;},quoteParagraphDirectly:function(objectType,objectID){var paragraphText=this.getParagraphText(objectType,objectID);if(paragraphText!=''){this.saveQuote(objectType,objectID,paragraphText,true);}},markParagraphToQuote:function(objectType,objectID){var paragraphText=this.getParagraphText(objectType,objectID);if(paragraphText!=''){this.saveQuote(objectType,objectID,paragraphText,false);var objectValue=this.data.get(objectType+'-'+objectID);objectValue.quotes++;this.updateQuoteButton(objectType,objectID);}},quoteParagraphsDirectly:function(objectType,objectID){var paragraphs=this.getParagraphs(objectType,objectID);if(paragraphs.length>0){this.saveQuote(objectType,objectID,paragraphs,true);}},markParagraphsToQuote:function(objectType,objectID){var paragraphs=this.getParagraphs(objectType,objectID);if(paragraphs.length>0){this.saveQuote(objectType,objectID,paragraphs,false);var objectValue=this.data.get(objectType+'-'+objectID);objectValue.quotes=objectValue.quotes+paragraphs.length;this.updateQuoteButton(objectType,objectID);}},markToQuote:function(objectType,objectID){this.saveQuote(objectType,objectID,this.selectedText,false);var objectValue=this.data.get(objectType+'-'+objectID);objectValue.quotes++;this.updateQuoteButton(objectType,objectID);},removeQuotes:function(objectType,objectID){var ajaxRequest=new AjaxRequest();ajaxRequest.openPost('index.php?action=MessageQuotesRemove&t='+SECURITY_TOKEN+SID_ARG_2ND,'objectType='+objectType+'&objectID='+objectID);var objectValue=this.data.get(objectType+'-'+objectID);objectValue.quotes=0;this.updateQuoteButton(objectType,objectID);if(this.manager){this.manager.removeQuotes(objectType,objectID);this.manager.showQuotes();}},saveQuote:function(objectType,objectID,text,singleQuote){document.fire('wcf:MultiQuote:saveQuote');var multiQuote=this;var quoteData=this.data.get(objectType+'-'+objectID);this.ajaxRequest=new AjaxRequest();var postData='objectType='+objectType+'&objectID='+objectID;if(text instanceof Array){for(i=0;i<text.length;i++){var quoteID=this.getQuoteID();postData+='&text['+quoteID+']='+encodeURIComponent(text[i]);if(this.manager){this.manager.storeQuote(quoteID,objectType,objectID,text[i],quoteData.author,quoteData.url);}}}
else{var quoteID=this.getQuoteID();postData+='&text['+quoteID+']='+encodeURIComponent(text);if(this.manager){this.manager.storeQuote(quoteID,objectType,objectID,(text!=''?text:this.getAvailableText(objectType,objectID)),quoteData.author,quoteData.url);}}
this.ajaxRequest.openPost('index.php?action='+objectType.substring(0,1).toUpperCase()+objectType.substring(1)+'MessageQuote&t='+SECURITY_TOKEN+SID_ARG_2ND,postData,(singleQuote?function(){multiQuote.receiveResponse.apply(multiQuote);}:false));if(this.manager){this.manager.showQuotes();}},receiveResponse:function(){if(this.ajaxRequest&&this.ajaxRequest.xmlHttpRequest.readyState==4){document.location.href=fixURL(this.formURL);}},setManager:function(manager){this.manager=manager;},getQuoteID:function(){var chars='abcdef1234567890';var quoteID='';for(var i=0;i<40;i++){quoteID+=chars.charAt(Math.floor(Math.random()*16.0));}
return quoteID;}});
