
var CAPTION_CONTENTS='Contents';var CAPTION_DOCUMENT='Document';var CAPTION_LABEL='Label';var CAPTION_PREVIEW='Preview';var FIELD_CONTENTS='contents';var FIELD_NAMES='names';var MAX_LEN_ID=32;var MAX_LEN_NAME=128;

function PageTextContent(elementId,contentName,contentId,editorHeight)
{this.elementId=elementId;this.contentName=contentName;this.editorHeight=editorHeight;this.contentId=contentId;}
function PageTextValue(id,name,revision,contents,creatorId,createdDate,lastModifierId,lastModifiedDate)
{this.id=id;this.name=name;this.revision=revision;this.contents=contents;this.creatorId=creatorId;this.createdDate=createdDate;this.lastModifierId=lastModifierId;this.lastModifiedDate=lastModifiedDate;}

function PinkContentCalls(rootPath)
{if(undefined==rootPath)
this.rootPath='/content';else
this.rootPath=rootPath;this.cdataElements=new Array();this.cdataElements[FIELD_NAME]=FIELD_NAME;this.cdataElements[FIELD_CONTENTS]=FIELD_CONTENTS;this.modules=new Array();}
PinkContentCalls.prototype=new AjaxHelper();PinkContentCalls.prototype.accessRSA=function(userName,password,tokenCode,nextTokenCode)
{var value={userName:userName,password:password,tokenCode:tokenCode,nextTokenCode:nextTokenCode};return this.synchPostMap(this.rootPath+'/accessRSA',value);}
PinkContentCalls.prototype.addAppDestination=function(value,callback)
{this.asynchPostMap(this.rootPath+'/admin/addAppDestination.json',value,callback);}
PinkContentCalls.prototype.canAuthor=function()
{return this.synchCall(this.rootPath+'/canAuthor.json').payload;}
PinkContentCalls.prototype.deleteAppDestination=function(value,callback)
{this.asynchPostMap(this.rootPath+'/admin/deleteAppDestination.json',value,callback);}
PinkContentCalls.prototype.getAppDestinations=function(filter,callback)
{this.asynchPostMap(this.rootPath+'/author/getAppDestinations.json',filter,callback);}
PinkContentCalls.prototype.getAuditPageDocUrl=function(id)
{var queryString='';queryString=this.toQueryString(queryString,FIELD_ID,id);return this.rootPath+'/author/viewAuditPageDoc'+queryString;}
PinkContentCalls.prototype.getAuditPageDocWorklist=function(filter,callback)
{this.asynchPostMap(this.rootPath+'/author/getAuditPageDocWorklist.json',filter,callback);}
PinkContentCalls.prototype.getAuditPageText=function(id,callback)
{this.asynchPostMap(this.rootPath+'/author/getAuditPageText.json',{id:id},callback);}
PinkContentCalls.prototype.getAuditPageTextWorklist=function(criteria,callback)
{this.asynchPostMap(this.rootPath+'/author/getAuditPageTextWorklist.json',criteria,callback);}
PinkContentCalls.prototype.getGlossaryItem=function(id,callback)
{var url=this.rootPath+'/getGlossaryItem.json';var params={id:id};if(undefined==callback)
return this.synchPostMap(url,params);this.asynchPostMap(url,params,callback);}
PinkContentCalls.prototype.getGlossaryList=function(callback)
{this.asynchCall(this.rootPath+'/getGlossaryList.json',callback);}
PinkContentCalls.prototype.getGlossaryWorklist=function(filter,callback)
{this.asynchPostMap(this.rootPath+'/author/getGlossaryWorklist.json',filter,callback);}
PinkContentCalls.prototype.getPageDoc=function(id,name,callback)
{var url=this.rootPath+'/getPageDoc.json';var params={id:id,name:name};if(undefined==callback)
return this.synchPostMap(url,params);this.asynchPostMap(url,params,callback);}
PinkContentCalls.prototype.getPageDocUrl=function(id,name)
{var queryString='';queryString=this.toQueryString(queryString,FIELD_ID,id);queryString=this.toQueryString(queryString,FIELD_NAME,name);return this.rootPath+'/doc'+queryString;}
PinkContentCalls.prototype.getPageDocNames=function(name,pageSize,callback)
{var url=this.rootPath+'/author/getPageDocNames.json';var params={name:name,pageSize:pageSize};if(undefined==callback)
return this.synchPostMap(url,params);this.asynchPostMap(url,params,callback);}
PinkContentCalls.prototype.getPageText=function(id,name,callback)
{var url=this.rootPath+'/getPageText.json';var params={id:id,name:name};if(undefined==callback)
return this.synchPostMap(url,params);this.asynchPostMap(url,params,callback);}
PinkContentCalls.prototype.getPageTextNames=function(name,pageSize,callback)
{var url=this.rootPath+'/author/getPageTextNames.json';var params={name:name,pageSize:pageSize};if(undefined==callback)
return this.synchPostMap(url,params);this.asynchPostMap(url,params,callback);}
PinkContentCalls.prototype.getPublicationOptions=function(filter,callback)
{this.asynchPostMap(this.rootPath+'/author/getPublicationOptions.json',filter,callback);}
PinkContentCalls.prototype.loadAdminModule=function()
{this.loadModule('/common/scripts/dropdown.js');this.loadModule(this.rootPath+'/scripts/admin.js');}
PinkContentCalls.prototype.loadModule=function(url)
{if(this.modules[url])
return false;;var head=document.getElementsByTagName('head')[0];var elem=document.createElement('script');elem.type='text/javascript';elem.src=url;head.appendChild(elem);return(this.modules[url]=true);}
PinkContentCalls.prototype.publishResources=function(value,callback)
{this.asynchPostMap(this.rootPath+'/author/publishResources.json',value,callback);}
PinkContentCalls.prototype.rollbackDoc=function(id)
{return this.synchPostMap(this.rootPath+'/author/rollbackDoc.json',{id:id});}
PinkContentCalls.prototype.setGlossary=function(value,callback)
{this.asynchPostMap(this.rootPath+'/author/setGlossary.json',this.convertAll(value),callback);}
PinkContentCalls.prototype.setPageDocUrl=function()
{return this.rootPath+'/author/setPageDoc.txt';}
PinkContentCalls.prototype.setPageText=function(value,callback)
{this.asynchPostMap(this.rootPath+'/author/setPageText.json',this.convertAll(value),callback);}
PinkContentCalls.prototype.swapGlossaryOrder=function(firstId,secondId)
{return this.synchPostMap(this.rootPath+'/author/swapGlossaryOrder.json',{firstId:firstId,secondId:secondId});}
PinkContentCalls.prototype.updateAppDestination=function(value,callback)
{this.asynchPostMap(this.rootPath+'/admin/updateAppDestination.json',value,callback);}
function PinkContentDataHandler(body){this.body=body;}
PinkContentDataHandler.prototype.handleRequestData=function(value)
{if((undefined!=value)&&(undefined!=value.contents))
this.body.innerHTML=value.contents;}

function ContentInlineEditor(caller,context)
{this.caller=caller;this.context=context;this.document=window.document;this.inputField=new InputField();this.itemsById=undefined;}
ContentInlineEditor.prototype.DEFAULT_HEIGHT='100%';ContentInlineEditor.prototype.EDIT='Edit';ContentInlineEditor.prototype.PREVIEW='Preview';ContentInlineEditor.prototype.ROLLBACK='Rollback';ContentInlineEditor.prototype.getRevisionList=function()
{if(undefined==this.revisionList)
this.revisionList=new RevisionManager(this.caller,new TextRevisionsDOM(),undefined,this);return this.revisionList;}
ContentInlineEditor.prototype.getDocManager=function()
{if(undefined==this.docManager)
this.docManager=new DocManagerSimple(this.caller,new PageManagerDOM(),undefined,this);return this.docManager;}
ContentInlineEditor.prototype.init=function(context)
{if(undefined==context)
{if(undefined==this.context)
return;context=this.context;}
this.canAuthor=this.caller.canAuthor();if(this.canAuthor)
this.caller.loadAdminModule();this.itemsById=new Array();for(var i=0;i<context.length;i++)
{var item=context[i];item.element=(item.elementId.tagName)?item.elementId:this.document.getElementById(item.elementId);this.caller.getPageText(item.contentId,item.contentName,new ContentInlineEditorInit(this,item));}}
ContentInlineEditor.prototype.initElement=function(item,content)
{var element=item.element;if(undefined==content)
{var innerContent=item.innerContent;var _contents=(undefined!=innerContent)?innerContent.innerHTML:element.innerHTML;content=new PageTextValue(item.contentId,item.contentName,0,_contents);}
else
this.itemsById[content.id]=item;if(undefined==item.editorHeight)
item.editorHeight=this.DEFAULT_HEIGHT;item.record=content;element.innerHTML='';item.innerContent=document.createElement('div');item.innerContent.className='widgetPackage';element.appendChild(item.innerContent);if(this.canAuthor)
{item.myActions=document.createElement('div');item.myActions.className='widgetPackage';element.appendChild(item.myActions);}
this.toReadonly(item);this.decorate(element,item);}
ContentInlineEditor.prototype.handleEdit=function(ev)
{var me=this.myCallback;me.toWritable(this.myItem,true,this.PREVIEW,CAPTION_PREVIEW,me.handlePreview);}
ContentInlineEditor.prototype.getTextValue=function(theForm)
{var contents=theForm.contents;if(undefined==contents)
throw'Not editable';return contents.value;}
ContentInlineEditor.prototype.handlePreview=function(ev)
{var me=this.myCallback;var item=this.myItem;item.record.contents=me.getTextValue(this.form);me.toWritable(item,false,this.EDIT,CAPTION_EDIT,me.handleEdit);}
ContentInlineEditor.prototype.handleSubmit=function(ev)
{var me=this.myCallback;var item=this.myItem;var form=this.form;var record=item.record;var value=new PageTextValue(record.id,record.name,record.revision,me.getTextValue(form));me.caller.setPageText(value,{handleRequestData:function(status){record.contents=value.contents;record.revision++;me.toReadonly(item);},handleRequestError:function(error){window.alert(error.message?error.message:error);form.contents.focus();}});}
ContentInlineEditor.prototype.handleCancel=function(ev)
{var me=this.myCallback;var item=this.myItem;item.record.contents=item.origContents;me.toReadonly(item);}
ContentInlineEditor.prototype.handleRollback=function(ev)
{var me=this.myCallback;var item=this.myItem;var record=item.record;me.getRevisionList().byId(record.id);}
ContentInlineEditor.prototype.handleDocuments=function(ev)
{this.myCallback.getDocManager().open();}
ContentInlineEditor.prototype.handleRollbackSelection=function(id,name,contents)
{var item=this.itemsById[id];item.record.contents=contents;this.toWritable(item,false,this.EDIT,CAPTION_EDIT,this.handleEdit);}
ContentInlineEditor.prototype.toReadonly=function(item)
{var contentBlock=item.innerContent;contentBlock.innerHTML=item.record.contents;item.origContents=item.record.contents;contentBlock.style.display='block';if(this.canAuthor)
{var output=document.createElement('form');output.className='widgetPackage';var button=this.inputField.genButton('edit',CAPTION_EDIT,this.handleEdit);this.decorate(button,item);output.appendChild(button);if(undefined!=item.record.id)
{output.appendChild(this.createSpan('&nbsp;'));button=this.inputField.genButton('rollback',this.ROLLBACK,this.handleRollback);this.decorate(button,item);output.appendChild(button);}
output.appendChild(this.createSpan('&nbsp;'));button=this.inputField.genButton('docs','Docs',this.handleDocuments);this.decorate(button,item);output.appendChild(button);item.myActions.innerHTML='';item.myActions.appendChild(output);}}
ContentInlineEditor.prototype.toWritable=function(item,isEditable,mainActionId,mainActionCaption,mainActionOnClick)
{var contentBody=item.innerContent;var output=document.createElement('form');output.className='widgetPackage';output.appendChild(document.createElement('br'));output.appendChild(document.createElement('br'));var elem,value=item.record.contents;if(isEditable)
{elem=this.inputField.genTextArea('contents');elem.style.width='100%';elem.style.height=item.editorHeight;elem.value=value;contentBody.style.display='none';}
else
{elem=this.inputField.genHidden('contents',item.record.contents);contentBody.innerHTML=value;contentBody.style.display='block';}
output.appendChild(elem);elem=this.inputField.genButton(mainActionId,mainActionCaption,mainActionOnClick);this.decorate(elem,item);output.appendChild(elem);output.appendChild(this.createSpan('&nbsp;'));elem=this.inputField.genButton('submit',CAPTION_SUBMIT,this.handleSubmit);this.decorate(elem,item);output.appendChild(elem);output.appendChild(this.createSpan('&nbsp;'));elem=this.inputField.genButton('cancel',CAPTION_CANCEL,this.handleCancel);this.decorate(elem,item);output.appendChild(elem);item.myActions.innerHTML='';item.myActions.appendChild(output);}
ContentInlineEditor.prototype.createSpan=function(value)
{var output=document.createElement('span');output.innerHTML=value;return output;}
ContentInlineEditor.prototype.decorate=function(elem,item)
{elem.myCallback=this;elem.myItem=item;}
function ContentInlineEditorInit(callback,contextItem)
{this.callback=callback;this.contextItem=contextItem;}
ContentInlineEditorInit.prototype.handleRequestData=function(value)
{this.callback.initElement(this.contextItem,value);}

function GlossaryDecorator(caller,doc)
{this.caller=caller;this.doc=(undefined==doc)?window.document:doc;this.cache=new Array();}
GlossaryDecorator.prototype.CSS_POPUP_ACTIVE='tooltipActive';GlossaryDecorator.prototype.CSS_POPUP_HIDDEN='tooltipHidden';GlossaryDecorator.prototype.MAX_WIDTH=200;GlossaryDecorator.prototype.doAll=function(){this.run(undefined,this.doc.body);}
GlossaryDecorator.prototype.doSection=function(body){this.run(undefined,body);}
GlossaryDecorator.prototype.run=function(criteria,body)
{this.doItem(body);}
GlossaryDecorator.prototype.doItem=function(elem)
{if(elem.psGlossaryId)
{var me=this;elem.myCallback=this;elem.onmouseout=this.handleMouseOut;elem.onmouseover=this.handleMouseOver;}
var children=elem.childNodes;for(var i=0;i<children.length;i++)
this.doItem(children[i]);}
GlossaryDecorator.prototype.doPopup=function(elem,value)
{if(!elem.psMouseOver)
return;if(undefined==this.popup)
{this.popup=this.doc.createElement('div');this.popup.className=this.CSS_POPUP_HIDDEN;this.doc.body.appendChild(this.popup);}
this.popup.innerHTML=value.contents;this.popup.className=this.CSS_POPUP_ACTIVE;if(this.popup.offsetWidth>this.MAX_WIDTH)
this.popup.style.width=this.MAX_WIDTH;positionBelowElement(this.popup,elem);}
GlossaryDecorator.prototype.cacheValue=function(value){this.cache[value.id]=value;}
GlossaryDecorator.prototype.handleMouseOver=function(ev)
{this.psMouseOver=true;this.style.cursor='pointer';var me=this.myCallback;var value=me.cache[this.psGlossaryId];if(undefined!=value)
me.doPopup(this,value);else
me.caller.getGlossaryItem(this.psGlossaryId,new GlossaryDecoratorCallback(me,this));}
GlossaryDecorator.prototype.handleMouseOut=function(ev)
{this.psMouseOver=false;this.style.cursor='default';var me=this.myCallback;if(undefined!=me.popup)
me.popup.className=me.CSS_POPUP_HIDDEN;}
GlossaryDecorator.prototype.handleRequestData=function(value,elem)
{this.cacheValue(value);this.doPopup(elem,value);}
function GlossaryDecoratorCallback(callback,elem)
{this.callback=callback;this.elem=elem;}
GlossaryDecoratorCallback.prototype.handleRequestData=function(value)
{this.callback.handleRequestData(value,this.elem);}
