var Inbox=function(){var content=$('.inbox-content');var loading=$('.inbox-loading');var listListing='';var loadInbox=function(el,name){var url='inbox_inbox.html';var title=$('.inbox-nav > li.'+name+' a').attr('data-title');listListing=name;loading.show();content.html('');toggleButton(el);$.ajax({type:"GET",cache:false,url:url,dataType:"html",success:function(res)
{toggleButton(el);$('.inbox-nav > li.active').removeClass('active');$('.inbox-nav > li.'+name).addClass('active');$('.inbox-header > h1').text(title);loading.hide();content.html(res);if(Layout.fixContentHeight){Layout.fixContentHeight();}
Metronic.initUniform();},error:function(xhr,ajaxOptions,thrownError)
{toggleButton(el);},async:false});jQuery('body').on('change','.mail-group-checkbox',function(){var set=jQuery('.mail-checkbox');var checked=jQuery(this).is(":checked");jQuery(set).each(function(){$(this).attr("checked",checked);});jQuery.uniform.update(set);});}
var loadMessage=function(el,name,resetMenu){var url='inbox_view.html';loading.show();content.html('');toggleButton(el);var message_id=el.parent('tr').attr("data-messageid");$.ajax({type:"GET",cache:false,url:url,dataType:"html",data:{'message_id':message_id}, success:function(res)
{toggleButton(el);if(resetMenu){$('.inbox-nav > li.active').removeClass('active');}
$('.inbox-header > h1').text('View Message');loading.hide();content.html(res);Layout.fixContentHeight();Metronic.initUniform();},error:function(xhr,ajaxOptions,thrownError)
{toggleButton(el);},async:false});}
var initWysihtml5=function(){$('.inbox-wysihtml5').wysihtml5({"stylesheets":["../../assets/global/plugins/bootstrap-wysihtml5/wysiwyg-color.css"]});}
var initFileupload=function(){$('#fileupload').fileupload({url:'../../assets/global/plugins/jquery-file-upload/server/php/',autoUpload:true});if($.support.cors){$.ajax({url:'../../assets/global/plugins/jquery-file-upload/server/php/',type:'HEAD'}).fail(function(){$('<span class="alert alert-error"/>')
.text('Upload server currently unavailable - '+
new Date())
.appendTo('#fileupload');});}}
var loadCompose=function(el){var url='inbox_compose.html';loading.show();content.html('');toggleButton(el);$.ajax({type:"GET",cache:false,url:url,dataType:"html",success:function(res)
{ toggleButton(el);$('.inbox-nav > li.active').removeClass('active');$('.inbox-header > h1').text('Compose');loading.hide();content.html(res);initFileupload();initWysihtml5();$('.inbox-wysihtml5').focus();Layout.fixContentHeight();Metronic.initUniform();},error:function(xhr,ajaxOptions,thrownError)
{toggleButton(el);},async:false});}
var loadReply=function(el){var messageid=$(el).attr("data-messageid");var url='inbox_reply.html?messageid='+messageid;loading.show();content.html('');toggleButton(el);$.ajax({type:"GET",cache:false,url:url,dataType:"html",success:function(res)
{toggleButton(el);$('.inbox-nav > li.active').removeClass('active');$('.inbox-header > h1').text('Reply');loading.hide();content.html(res);$('[name="message"]').val($('#reply_email_content_body').html());handleCCInput();initFileupload();initWysihtml5();Layout.fixContentHeight();Metronic.initUniform();},error:function(xhr,ajaxOptions,thrownError)
{toggleButton(el);},async:false});}
var loadSearchResults=function(el){var url='inbox_inbox.html';loading.show();content.html('');toggleButton(el);$.ajax({type:"GET",cache:false,url: url,dataType:"html",success:function(res)
{toggleButton(el);$('.inbox-nav > li.active').removeClass('active');$('.inbox-header > h1').text('Search');loading.hide();content.html(res);Layout.fixContentHeight();Metronic.initUniform();},error:function(xhr,ajaxOptions,thrownError)
{toggleButton(el);},async:false});}
var handleCCInput=function(){var the=$('.inbox-compose .mail-to .inbox-cc');var input=$('.inbox-compose .input-cc');the.hide();input.show();$('.close',input).click(function(){input.hide();the.show();});}
var handleBCCInput=function(){var the=$('.inbox-compose .mail-to .inbox-bcc');var input=$('.inbox-compose .input-bcc');the.hide();input.show();$('.close',input).click(function(){input.hide();the.show();});}
var toggleButton=function(el){if(typeof el=='undefined'){return;}
if(el.attr("disabled")){el.attr("disabled",false);}else{el.attr("disabled",true);}}
return{init:function(){$('.inbox').on('click','.compose-btn a',function(){loadCompose($(this));});$('.inbox').on('click','.inbox-discard-btn',function(e){e.preventDefault();loadInbox($(this),listListing);});$('.inbox').on('click','.reply-btn',function(){loadReply($(this));});$('.inbox-content').on('click','.view-message',function(){loadMessage($(this));});$('.inbox-nav > li.inbox > a').click(function(){loadInbox($(this),'inbox');});$('.inbox-nav > li.sent > a').click(function(){loadInbox($(this),'sent');});$('.inbox-nav > li.draft > a').click(function(){loadInbox($(this),'draft');});$('.inbox-nav > li.trash > a').click(function(){loadInbox($(this),'trash');});$('.inbox-content').on('click','.mail-to .inbox-cc',function(){handleCCInput();});$('.inbox-content').on('click','.mail-to .inbox-bcc',function(){handleBCCInput();});if(Metronic.getURLParameter("a")==="view"){loadMessage();}else if(Metronic.getURLParameter("a")==="compose"){loadCompose();}else{$('.inbox-nav > li.inbox > a').click();}}};}();