if(Object.isUndefined(Chat)){var Chat={}}Chat.Confirm={instance:null,content:null,contentPrevContainer:null,data:null,handlerAccept:null,handlerDeny:null,templatesCache:new Hash(),templateSyntax:/(^|.|\r|\n|\/)(#\[\s*(\w+)\s*\])/,show:function(content,options,isTemplate,templateData){options=options||{};var windowOptions=Object.extend({className:"messenger-dialog",destroyOnClose:false,width:360,height:100,maximizable:false,resizable:false,minimizable:false,draggable:false,zIndex:5},options);
if(Chat.Confirm.instance){Chat.Confirm.destroy()}Chat.Confirm.data=options.data;Chat.Confirm.handlerAccept=options.onSuccess;Chat.Confirm.handlerDeny=options.onFailure;Chat.Confirm.content=content;Chat.Confirm.instance=new Window(windowOptions);if(Object.isFunction(options.onFailure)){Chat.Confirm.instance.setCloseCallback(function(){options.onFailure();return true})}if(isTemplate){if(Object.isUndefined(this.templatesCache.get(content))){var text=$(content).innerHTML;
text=text.gsub("#%5B","#[");text=text.gsub("%5D","]");this.templatesCache.set(content,new Template(text,this.templateSyntax))}Chat.Confirm.instance.getContent().insert(this.templatesCache.get(content).evaluate(templateData))}else{if($(content)){this.contentPrevContainer=$(content).up();Chat.Confirm.instance.getContent().insert($(content))}else{Chat.Confirm.instance.getContent().update(content)}}Chat.Confirm.instance.showCenter(options.modal||false)
},template:function(content,options,templateData){this.show(content,options,true,templateData)},ajax:function(url,options){Chat.Confirm.show(null,options);var ajaxOptions={method:"get",asynchronous:(!Object.isUndefined(options.asynchronous)?options.asynchronous:true),onComplete:options.ajaxOnComplete,overlayer:{id:Chat.Confirm.instance.getContent().identify()}};Chat.Confirm.instance.setAjaxContent(url,ajaxOptions,true)
},deny:function(){if(Chat.Confirm.handlerDeny){Chat.Confirm.handlerDeny(Chat.Confirm.data)}Chat.Confirm.destroy()},accept:function(){if(Chat.Confirm.handlerAccept){if(Chat.Confirm.handlerAccept(Chat.Confirm.data)===false){return}}try{Statistics.update()}catch(ex){}Chat.Confirm.destroy()},destroy:function(){Chat.Confirm.instance.close();if(Chat.Confirm.contentPrevContainer&&$(Chat.Confirm.content)){Chat.Confirm.contentPrevContainer.insert($(Chat.Confirm.content));
Chat.Confirm.contentPrevContainer=null}Chat.Confirm.instance.destroy();Chat.Confirm.instance=null;Chat.Confirm.handlerAccept=null;Chat.Confirm.handlerDeny=null;Chat.Confirm.data=null}};
