
JSON=YAHOO.lang.JSON;SUGAR.quickCompose={};SUGAR.quickCompose=function(){return{parentPanel:null,options:null,loadingMessgPanl:null,frameLoaded:false,resourcesLoaded:false,cachedComposedResponses:{},initComposePackage:function(c)
{SUGAR.email2.addressBook.initFixForDatatableSort();SUGAR.quickCompose.resourcesLoaded=true;var callback={success:function(o)
{var responseData=JSON.parse(o.responseText);var scriptTag=document.createElement('script');scriptTag.id='quickComposeScript';scriptTag.setAttribute('type','text/javascript');if(YAHOO.env.ua.ie>0)
scriptTag.text=responseData.jsData;else
scriptTag.appendChild(document.createTextNode(responseData.jsData));document.getElementsByTagName("head")[0].appendChild(scriptTag);var divTag=document.createElement("div");divTag.innerHTML=responseData.divData;divTag.id='quickCompose';YAHOO.util.Dom.insertBefore(divTag,'footer');SUGAR.quickCompose.frameLoaded=true;SUGAR.quickCompose.initUI(c.data);}}
if(!SUGAR.quickCompose.frameLoaded)
YAHOO.util.Connect.asyncRequest('GET','index.php?entryPoint=GenerateQuickComposeFrame',callback,null);else
SUGAR.quickCompose.initUI(c.data);},initUI:function(options)
{var SQ=SUGAR.quickCompose;this.options=options;loadingMessgPanl.hide();if(SQ.parentPanel==null)
{theme=SUGAR.themes.theme_name;var idx=0;if(!SE.composeLayout.composeTemplate)
SE.composeLayout.composeTemplate=new YAHOO.SUGAR.Template(SE.templates['compose']);SQ.parentPanel=new YAHOO.widget.Panel("container1",{modal:true,visible:true,constraintoviewport:true,width:'880px',height:'400px',shadow:true,draggable:true,resize:true});SQ.parentPanel.setHeader(SUGAR.language.get('app_strings','LBL_EMAIL_QUICK_COMPOSE'));SQ.parentPanel.setBody("<div id='htmleditordiv"+idx+"'></div>");var composePanel=SE.composeLayout.getQuickComposeLayout(SQ.parentPanel,this.options);var resize=new YAHOO.util.Resize('container1',{handles:['br'],autoRatio:false,minWidth:400,minHeight:350,status:false});resize.on('resize',function(args){var panelHeight=args.height;this.cfg.setProperty("height",panelHeight+"px");var layout=SE.composeLayout[SE.composeLayout.currentInstanceId];layout.set("height",panelHeight-50);layout.resize(true);SE.composeLayout.resizeEditor(SE.composeLayout.currentInstanceId);},SQ.parentPanel,true);YAHOO.util.Dom.setStyle("container1","z-index",1);tinymce.dom.Event.domLoaded=true;tinyMCE.init({convert_urls:false,theme_advanced_toolbar_align:tinyConfig.theme_advanced_toolbar_align,width:tinyConfig.width,theme:tinyConfig.theme,theme_advanced_toolbar_location:tinyConfig.theme_advanced_toolbar_location,theme_advanced_buttons1:tinyConfig.theme_advanced_buttons1,theme_advanced_buttons2:tinyConfig.theme_advanced_buttons2,theme_advanced_buttons3:tinyConfig.theme_advanced_buttons3,plugins:tinyConfig.plugins,elements:tinyConfig.elements,language:tinyConfig.language,extended_valid_elements:tinyConfig.extended_valid_elements,mode:tinyConfig.mode,strict_loading_mode:true});SUGAR.email2.composeLayout.forceCloseCompose=function(o){SUGAR.quickCompose.parentPanel.hide();}}
else
{this.options.composePackage.subject=' ';this.options.composePackage.currentInstanceId=0;this.options.composePackage.clearBody=true;this.options.composePackage.body=' ';document.getElementById("addressCC0").value="";document.getElementById("addressBCC0").value="";SE.composeLayout.hideHiddenAddresses('0');SE.composeLayout.quickCreateComposePackage(this.options);SQ.parentPanel.show();}
SQ.parentPanel.center();},init:function(o){loadingMessgPanl=new YAHOO.widget.SimpleDialog('loading',{width:'200px',close:true,modal:true,visible:true,fixedcenter:true,constraintoviewport:true,draggable:false});loadingMessgPanl.setHeader(SUGAR.language.get('app_strings','LBL_EMAIL_PERFORMING_TASK'));loadingMessgPanl.setBody(SUGAR.language.get('app_strings','LBL_EMAIL_ONE_MOMENT'));loadingMessgPanl.render(document.body);loadingMessgPanl.show();SUGAR.quickCompose.loadComposePackage(o);},loadComposePackage:function(o){if(typeof(o.composeOptionsLink)!='undefined')
{var cacheMan=SUGAR.quickCompose.cachedComposedResponses;if(typeof(o.id)!='undefined'&&typeof(cacheMan[o.id])!='undefined')
SUGAR.quickCompose.afterComposePackageLoad(cacheMan[o.id]);else
{var baseUrl='index.php?module=Emails&action=Compose&to_pdf=true&ajaxCall=true';var fullUrl=baseUrl+'&'+o.composeOptionsLink;var callback={success:function(o)
{var resp=JSON.parse(o.responseText);var composePackage={'composePackage':resp};if(typeof(resp.parent_id)!='undefined')
SUGAR.quickCompose.cachedComposedResponses[resp.parent_id]=composePackage;SUGAR.quickCompose.afterComposePackageLoad(composePackage);}};YAHOO.util.Connect.asyncRequest('GET',fullUrl,callback,null);}}
else
SUGAR.quickCompose.afterComposePackageLoad(o);},afterComposePackageLoad:function(o){if(!SUGAR.quickCompose.resourcesLoaded)
this.loadResources(o);else
this.initUI(o);},loadResources:function(o)
{window.skipTinyMCEInitPhase=true;var loader=new YAHOO.util.YUILoader({require:["layout","element","tabview","menu","cookie","tinymce","securejson","sugarwidgets","sugarquickcompose","sugarquickcomposecss"],loadOptional:true,skin:{base:'blank',defaultSkin:''},data:o,onSuccess:this.initComposePackage,allowRollup:true,base:"include/javascript/yui/build/"});loader.addModule({name:"tinymce",type:"js",fullpath:"include/javascript/tiny_mce/tiny_mce.js"});loader.addModule({name:"securejson",type:"js",fullpath:"include/JSON.js"});loader.addModule({name:"sugarwidgets",type:"js",fullpath:"include/javascript/sugarwidgets/SugarYUIWidgets.js",varName:"YAHOO.SUGAR",requires:["datatable","dragdrop","treeview","tabview"]});loader.addModule({name:"sugarquickcompose",type:"js",fullpath:"include/javascript/sugar_grp_quickcomp.js"});loader.addModule({name:"sugarquickcomposecss",type:"css",fullpath:"modules/Emails/EmailUI.css"});loader.insert();}};}();