
var smashion;if(!smashion)smashion={};if(!smashion.xui)smashion.xui={}
smashion.xui.InPlaceEditor=Class.create({initialize:function(url,fieldId,fieldStatusId,fieldName,options){this.status=$(fieldStatusId);this.fieldName=fieldName;var defaultOptions={okButton:false,okLink:true,okText:'Submit',cancelText:'Cancel',rows:1,formId:fieldId+"Form",callback:this.submitForm.bind(this),onComplete:this.onCompleteCallback.bind(this),onCreateForm:this.onCreateFormCallback.bind(this)};if(options!=null){Object.extend(defaultOptions,options);}
this.editor=new Ajax.InPlaceEditor(fieldId,url,defaultOptions);},submitForm:function(form,value){return"field="+this.fieldName+"&value="+encodeURIComponent(this.unescapeHtml(value));},onCompleteCallback:function(transport,element){if(transport==null){this.status.innerHTML="";return;}
var json=transport.getResponseHeader("X-JSON").evalJSON(true);if(json.status!="SUCCESS"){this.status.innerHTML=json.message;}else{this.status.innerHTML="";}},onCreateFormCallback:function(form){if(form==null||form=="undefined"){return;}
var txs=form.getElementsByTagName("textarea");for(var i=0;i<txs.length;i++){new smashion.xui.ResizingTextArea(txs[i]);}},escapeHtml:function(str){if(str==null){return str;}
return str.replace(/</g,"&lt;").replace(/>/g,"&gt;");},unescapeHtml:function(str){if(str==null){return str;}
return str.replace(/&lt;/g,"<").replace(/&gt;/g,">");},dispose:function(){this.editor.dispose();}})
smashion.xui.ResizingTextArea=Class.create({initialize:function(element,options){this.field=$(element);this.options=Object.extend({maxLength:-1,counter:null,counterText:"Characters left: "},options||{});this.defaultRows=Math.max(this.field.rows,1);Event.observe(this.field,"click",this.resize.bindAsEventListener(this));Event.observe(this.field,"keyup",this.resize.bindAsEventListener(this));if(this.options.maxLength>0){Event.observe(this.field,"keyup",this.countSize.bindAsEventListener(this));this.showCounter(this.options.maxLength);}},resize:function(){var t=this.field;var lines=t.value.split('\n');var newRows=lines.length;var oldRows=t.rows;for(var i=0;i<lines.length;i++)
{var line=lines[i];if(line.length>=t.cols)newRows+=Math.floor(line.length/t.cols);}
if(newRows>t.rows)t.rows=newRows;if(newRows<t.rows)t.rows=Math.max(this.defaultRows,newRows);},countSize:function(event){var limit=this.options.maxLength;var input=this.field.value;var len=input.length;if(len>limit){input=input.substring(0,limit);this.field.value=input;return false;}
this.showCounter(limit-len);},showCounter:function(num){var n=this.options.maxLength-this.field.value.length;if($(this.options.counter)){$(this.options.counter).update(this.options.counterText+n);}},dispose:function(){}})
smashion.xui.MoreLess=Class.create({initialize:function(control,container,options){this.control=$(control);this.container=$(container);this.options=Object.extend({moreText:"More",lessText:"Less",initiallyHidden:false,moreImage:"/images/icons/icons/icon_arrow_right.png",lessImage:"/images/icons/icons/icon_arrow_down.png",useImage:false,linkClass:"",showTransition:false},options||{});this.createControl();},createControl:function(){this.link=new Element("a",{href:"javascript:void(0)","class":this.options.linkClass});Event.observe(this.link,'click',this.onclick.bindAsEventListener(this));this.control.update();this.control.appendChild(this.link);if(this.options.initiallyHidden){this.hide();}else{this.show();}},onclick:function(event){if(this.container.visible()){this.hide();}else{this.show();}},show:function(){if(this.options.showTransition){Effect.BlindDown(this.container.identify(),{scaleContent:false});}else{this.container.show();}
if(this.options.useImage){this.link.update();var img=new Element("img",{"style":"vertical-align:middle",src:this.options.lessImage});this.link.appendChild(img);}else{this.link.update();this.link.appendChild(document.createTextNode(this.options.lessText));}},hide:function(){if(this.options.showTransition){Effect.BlindUp(this.container.identify(),{scaleContent:false});}else{this.container.hide();}
if(this.options.useImage){this.link.update();var img=new Element("img",{"style":"vertical-align:middle",src:this.options.moreImage});this.link.appendChild(img);}else{this.link.update();this.link.appendChild(document.createTextNode(this.options.moreText));}},dispose:function(){}})
smashion.xui.ClickToEdit=Class.create({initialize:function(element,editFunc,options){this.element=$(element);this.editFunc=editFunc;this.options=Object.extend({highlightcolor:Ajax.InPlaceEditor.defaultHighlightColor,clickToEditText:"Click to edit",showEmpty:false,emptyText:"click to edit...",emptyClassName:"inplaceeditor-empty"},options||{});this.originalBackground=Element.getStyle(this.element,'background-color');if(!this.originalBackground){this.originalBackground="transparent";}
this.element.title=this.options.clickToEditText;Event.observe(this.element,'click',this.enterEditMode.bindAsEventListener(this));Event.observe(this.element,'mouseover',this.enterHover.bindAsEventListener(this));Event.observe(this.element,'mouseout',this.leaveHover.bindAsEventListener(this));if(this.options.showEmpty){this.hint=new Element("span",{"class":this.options.emptyClassName});this.hint.style.backgroundColor=this.originalBackground;this.hint.update(this.options.emptyText);this.hint.hide();this.element.parentNode.insertBefore(this.hint,this.element);Event.observe(this.hint,'click',this.enterEditMode.bindAsEventListener(this));Event.observe(this.hint,'mouseover',this.enterHover.bindAsEventListener(this));Event.observe(this.hint,'mouseout',this.leaveHover.bindAsEventListener(this));}},showEmptyHint:function(){if(!this.options.showEmpty){return;}
var noText=false;if(this.element.innerHTML.length<4){noText=true;}else if(this.element.innerHTML=="\n"){noText=true;}
if(noText){this.hint.show();}},enterHover:function(event){var theElement=event.element();theElement.style.backgroundColor=this.options.highlightcolor;if(this.effect){this.effect.cancel();}},leaveHover:function(event){var theElement=event.element();this.effect=new Effect.Highlight(theElement,{startcolor:this.options.highlightcolor,endcolor:this.options.highlightendcolor,restorecolor:this.originalBackground});},enterEditMode:function(){if(this.hint){this.hint.hide();}
this.element.style.backgroundColor=this.originalBackground;if(this.editFunc!=null){this.editFunc();}},dispose:function(){}})