var MOSH=MOSH||{};MOSH.QuickSearch=function(){var that=this;var form;var quicksearch;var btnSubmit;var local={quicksearch:"search"};function init(){var node;quicksearch=document.getElementById("quicksearch");quicksearch2=document.getElementById("quicksearch2");if(quicksearch){quicksearch.value=local.quicksearch;quicksearch.onfocus=QuickSearch_onFocus;quicksearch.onblur=QuickSearch_onBlur;node=quicksearch.parentNode;while(node){if(node.tagName.toUpperCase()==="FORM"){form=node;break;} node=node.parentNode;} if(form){form.onsubmit=QuickSearch_onSubmit;}} if(quicksearch2){quicksearch2.value=local.quicksearch;quicksearch2.onfocus=QuickSearch_onFocus;quicksearch2.onblur=QuickSearch_onBlur;}} function QuickSearch_onFocus(e){if(this.value===local.quicksearch){this.value="";}else{this.select();}} function QuickSearch_onBlur(e){if(this.value.length===0){this.value=local.quicksearch;}} function QuickSearch_onSubmit(e){var value=quicksearch.value;if(value===local.quicksearch||value.length===0){MOSH.Event.preventDefault(e);}} window.onload=init;return{setLocal:function(obj){local=obj;this.setQuickSearch(local.quicksearch);},setQuickSearch:function(value){if(quicksearch){quicksearch.value=value;}}};}();MOSH.Util={parseUrl:function(path){path=path.substr(path.lastIndexOf("/")+1);return path.replace(/\.\w+/,'');}};MOSH.Modules=function(moduleNames,callback){var locked;var currentModule;var nextModule;var querystring;var onModuleChangeSubscribers=[];function init(){var module;var link;var i;var l;for(i=0,l=moduleNames.length;i0){link=link[0];if(link.parentNode){link.onclick=module_onClick;}}}}} function module_onClick(e){var url;MOSH.Event.preventDefault(e);if(!locked){if(this.parentNode.className.indexOf("selected")===-1){locked=true;nextModule=this.parentNode.parentNode.id;var qs=new MOSH.QueryString(this.href.substr(this.href.indexOf("?")+1));url="/common/ajaxMobile/"+qs.get("section");if(querystring&&querystring.length>0){url=url+"?"+querystring;} MOSH.TIDE(url,null,buildModule);}}} function buildModule(response,refresh,container){var containerID;var link;var header;if(!container){container=document.getElementById(nextModule);}else{container=document.getElementById(container);} containerID=container.id;link=container.getElementsByTagName("a");if(link.length>0){link=link[0];link.onclick=module_onClick;header=link.parentNode;header.className="selected";} if(!refresh){container.innerHTML=container.innerHTML+response;if(currentModule&¤tModule.length>0){container=document.getElementById(currentModule);if(container){link=container.getElementsByTagName("a");if(link.length>0){header=link[0].parentNode;header.className="";var content=header.nextSibling;while(content){container.removeChild(content);content=header.nextSibling;}}}}}else{container.innerHTML=response;container.insertBefore(header,container.firstChild);} currentModule=containerID;location.href="#"+currentModule;locked=false;for(var i=0;i%response%";var errorSnippet="
%response%
";var timer;function init(action,response){if(action.container){if(response.error==null){action.container.innerHTML=messageSnippet.replace('%response%',response.result.msg);action.btn.firstChild.nodeValue=response.result.buttonText;action.btn.href=response.result.href;}else{action.container.innerHTML=errorSnippet.replace('%response%',response.error);} if(timer){clearTimeout(timer);} timer=setTimeout(function(){action.container.innerHTML="";},3000);}} return{init:init};}();MOSH.GetContent=function(){var messageSnippet="
%response%
";var errorSnippet="
%response%
";var source;var intTimer;function init(){clearTimeout(intTimer);buildCollectionAdd();} function buildGet(response){var container=document.getElementById(source.target);if(container){container.innerHTML=response;init();}} function btnCollectionAdd_onClick(e){if(this.className.indexOf('signedOut')!=-1){return true;} var entityId=this.href.split('content/')[1].split('/')[0];MOSH.TIDE('/common/ajax/collectTo?entityId='+entityId,null,buildCollectionAdd);MOSH.Event.preventDefault(e);} function buildCollectionAdd(response){var btnCollectionCancel;var btnCollectionNew;var collections;var i,l;var li,link;var container=document.getElementById(source.target);if(container){btnCollectionCancel=document.getElementById("btnCollectionCancel");if(btnCollectionCancel){btnCollectionCancel.onclick=btnCancel_onClick;} btnCollectionNew=document.getElementById("btnCollectionNew");if(btnCollectionNew){btnCollectionNew.onclick=btnCollectionNew_onClick;} collections=container.getElementsByTagName("li");for(i=0,l=collections.length;i0){link[0].onclick=collection_onClick;}}}} function buildCollectionNew(response){var frmCollectionNew;var btnCollectionNewCancel;var container=document.getElementById(source.target);if(container){container.innerHTML=response;frmCollectionNew=document.getElementById("frmCollectionNew");if(frmCollectionNew){frmCollectionNew.onsubmit=frmCollectionNew_onSubmit;} btnCollectionNewCancel=document.getElementById("btnCollectionNewCancel");if(btnCollectionNewCancel){btnCollectionNewCancel.onclick=btnCancel_onClick;}}} function buildCollectionDone(response){var container=document.getElementById(source.target);var btnGetContentCollectionClose;if(container){if(response.error!=null){container.innerHTML=errorSnippet.replace("%response%",response.error);}else{if(typeof response.result!='object'){var msg=response.result;}else{var msg=response.result.msg;} container.innerHTML=messageSnippet.replace("%response%",msg);} intTimer=setTimeout(function(){container.innerHTML="";},3000);}} function btnCancel_onClick(e){var container=document.getElementById(source.target);if(container){container.innerHTML="";} MOSH.Event.preventDefault(e);} function collection_onClick(e){MOSH.TIDE(this.href+"&output=json",null,buildCollectionDone,"GET");MOSH.Event.preventDefault(e);} function btnCollectionNew_onClick(e){var qs=new MOSH.QueryString(this.href);var entityId=qs.get('entityId');MOSH.TIDE("/common/ajax/collectionAdd?output=ajax&entityId="+entityId,null,buildCollectionNew);MOSH.Event.preventDefault(e);} function frmCollectionNew_onSubmit(e){MOSH.Event.preventDefault(e);var form=document.getElementById('frmCollectionNew');var data=Schematic.Form.toQueryString("frmCollectionNew");MOSH.TIDE(form.action+'?output=json',data,buildCollectionDone,"POST");} return{init:function(s){source=s;init();}};}();MOSH.Mail={};MOSH.Mail.Compose=function(){var messageSnippet="
%response%
";var errorSnippet="
%response%
";var source;var intTimer;function init(action,response){var container=document.getElementById(source.target);clearTimeout(intTimer);document.getElementById('sendMail').onsubmit=function(e){MOSH.Event.preventDefault(e);var userId=Schematic.Form.getValue('toUsername','sendMail');MOSH.TIDE('/mymosh/messages/compose/'+userId+'/send?output=ajax',Schematic.Form.toQueryString('sendMail'),handleResponse,'POST');};document.getElementById('mailCancelBtn').onclick=function(e){MOSH.Event.preventDefault(e);container.innerHTML='';};} function handleResponse(response){var container=document.getElementById(source.target);var btnGetContentCollectionClose;response=eval("("+response+")");if(container){if(response.error!=null){container.innerHTML=errorSnippet.replace("%response%",response.error);}else{var msg=response.result;container.innerHTML=messageSnippet.replace("%response%",msg);} intTimer=setTimeout(function(){container.innerHTML="";},3000);}} return{init:function(s){source=s;init();}};}();MOSH.Mail.Reply=function(){var messageSnippet="
%response%
";var errorSnippet="
%response%
";var source;var intTimer;function init(action,response){var container=document.getElementById(source.target);clearTimeout(intTimer);document.getElementById('mailReply').onsubmit=function(e){MOSH.Event.preventDefault(e);var formAction=Schematic.Form.getAction('mailReply');MOSH.TIDE(formAction+'?output=ajax',Schematic.Form.toQueryString('mailReply'),handleResponse,'POST');};document.getElementById('mailCancelBtn').onclick=function(e){MOSH.Event.preventDefault(e);container.innerHTML='';};} function handleResponse(response){var container=document.getElementById(source.target);var btnGetContentCollectionClose;response=eval("("+response+")");if(container){if(response.error!=null){container.innerHTML=errorSnippet.replace("%response%",response.error);}else{var msg=response.result;container.innerHTML=messageSnippet.replace("%response%",msg);} intTimer=setTimeout(function(){container.innerHTML="";},3000);}} return{init:function(s){source=s;init();}};}();MOSH.Mail.Confirm=function(){function submitForm(action){var f=document.createElement('form');document.getElementsByTagName('body')[0].appendChild(f);f.action=action;f.method='POST' f.submit();} return{init:function(){var btnDelete=document.getElementById('btnDelete');var btnSpam=document.getElementById('btnSpam');btnDelete.onclick=this.del;btnSpam.onclick=this.spam;},del:function(e){MOSH.Event.preventDefault(e);if(confirm('Are you sure you want to delete this conversation?')){submitForm(this.href);}},spam:function(e){MOSH.Event.preventDefault(e);if(confirm('Are you sure you want to mark this conversation as spam?')){submitForm(this.href);}}}}();MOSH.Pager=function(modulesInstance){if(!modulesInstance){return;} function init(root){if(typeof root!="object"){root=document;} var allDivs=root.getElementsByTagName('div');for(var i=0;i0){querystring=querystring.replace(/\+/g,' ');var args=querystring.split("&");for(i=0,l=args.length;i