
function NewDoc(){tinyMCE.resetForm(0);document.forms["greendoc"].title.value='Untitled';document.forms["greendoc"].docid.value=0;document.forms["greendoc"].category.selectedIndex=0;$$('div.file-list').each(function(e){e.visualEffect('blind_up','d1',{duration:1.5})});setTimeout(OpenTabs,500);return true;}
function SaveDoc(docid){var docTitle=document.forms["greendoc"].title.value;var docCati=document.forms["greendoc"].category.selectedIndex;var docContent=tinyMCE.getInstanceById('content');if(!docTitle){docTitle='Untitled';}
if(!docCati){docCat='0';}
var options={method:'post',postBody:'title='+docTitle+'&content='+encodeURIComponent(docContent.getHTML())+'&cat='+docCati,onSuccess:SaveSuccess,onFailure:SaveError}
if($('tips'))Element.update('tips','<b>Saving ...</b>');new Ajax.Request('/save/'+docid,options);$$('div.file-list').each(function(e){e.visualEffect('blind_up','d1',{duration:1.5})});}
function FilePage(page){new Ajax.Request('/open/filelist/'+page,{onSuccess:UpdateList});}
function OpenDoc(docid){if($('tips'))Element.update('tips','<b>Loading ...</b>');document.forms["greendoc"].docid.value=docid;new Ajax.Request('/open/content/'+docid,{onSuccess:UpdateContent,onFailure:UpdateError});new Ajax.Request('/open/title/'+docid,{onSuccess:UpdateTitle,onFailure:UpdateError});$$('div.file-list').each(function(e){e.visualEffect('blind_up','d1',{duration:1.5})});}
var UpdateContent=function(x){var newContent=tinyMCE.getInstanceById('content');var url='/open/tabs';newContent.setHTML(x.responseText);if($('tips'))Element.update('tips','<b>Status:</b> Document ready.');if(document.forms["greendoc"].docid.value)
url+='/'+document.forms["greendoc"].docid.value;new Ajax.Request(url,{onSuccess:UpdateTabs});}
function CloseTab(docid){tinyMCE.resetForm(0);document.forms["greendoc"].title.value='Untitled';document.forms["greendoc"].docid.value=0;new Ajax.Request('/close/tab/'+docid);setTimeout(OpenTabs,500);}
function OpenTabs(){var url='/open/tabs';if(document.forms["greendoc"].docid.value)
url+='/'+document.forms["greendoc"].docid.value;new Ajax.Request(url,{onSuccess:UpdateTabs,onFailure:UpdateTabs});}
var UpdateTabs=function(x){if(x.responseText){Element.update('tabs',x.responseText);}else{Element.update('tabs','');}
new Ajax.Request('/open/filelist',{onSuccess:UpdateList,onFailure:SaveError});}
var UpdateTitle=function(x){if(x.responseText)
document.forms["greendoc"].title.value=x.responseText;else
document.forms["greendoc"].title.value='Untitled';}
var UpdateError=function(x){if($('tips'))Element.update('tips','<b>Warning:</b> Failed to load document. Please try again.');}
var SaveSuccess=function(x){var newDocId=x.responseText;if(newDocId){document.forms["greendoc"].docid.value=newDocId;}
OpenTabs();if($('tips'))Element.update('tips','<b>Status:</b> Document saved.');}
var SaveError=function(x){if($('tips'))Element.update('tips','<b>Warning:</b> Failed to save current document. Please try again.');}
var UpdateList=function(y){Element.update('filelist',y.responseText);if(document.forms["greendoc"].docid.value){url='/open/category/'+document.forms["greendoc"].docid.value;new Ajax.Request(url,{onSuccess:UpdateCat});}}
var UpdateCat=function(z){document.forms["greendoc"].category.selectedIndex=z.responseText;}
function AutoSave(){if($('tips'))Element.update('tips','<b>Auto Saving ...</b>');SaveDoc(document.forms["greendoc"].docid.value);}
function CloseTips(){Element.remove('tips');newTips.stop();}
function ShareDoc(docid){window.location='/share/'+docid;}
function ForgotForm(){new Ajax.Request('/account/forgot/form',{onSuccess:UpdateForgot});}
var UpdateForgot=function(x){Element.update('forgot',x.responseText);}