var __hasProp=Object.prototype.hasOwnProperty,__extends=function(a,b){function c(){this.constructor=a}for(var d in b)__hasProp.call(b,d)&&(a[d]=b[d]);c.prototype=b.prototype;a.prototype=new c;a.__super__=b.prototype;return a},__bind=function(a,b){return function(){return a.apply(b,arguments)}},__indexOf=Array.prototype.indexOf||function(a){for(var b=0,c=this.length;b<c;b++)if(this[b]===a)return b;return-1},__slice=Array.prototype.slice;var ImageLoader={loading:[],timeoutRunning:null,timeout:function(){for(var a=ImageLoader,b=[],c=0;c<a.loading.length;c++)a.loading[c].complete?a.loading[c].fn(a.loading[c],a.loading[c].srcWanted):b.push(a.loading[c]);a.loading=b;a.loading.length?setTimeout(a.timeout,250):a.timeoutRunning=!1},load:function(a,b){var c=ImageLoader,d=new Image;c.loading.push(d);d.fn=b;d.src=a;d.srcWanted=a;d.onload=function(){if(d.complete)for(var a=0;a<c.loading.length;a++){if(c.loading[a]===this){c.loading.splice(a,
1);b(d,d.srcWanted);break}}else if(!c.timeoutRunning)c.timeoutRunning=!0,setTimeout(c.timeout,250)};return d}};function ImageView(a){this.init(a)}
ImageView.prototype={init:function(a){this.div=a;this.div.style.overflow="auto";this.div.style.textAlign="center";this.img=null;this.sequence=0;var b=this;this.waywardClicks=0;this.MaxWaywardClicks=3;$(this.div).click(function(){b.waywardClicks+=1;if(b.waywardClicks>b.MaxWaywardClicks)b.waywardClicks=0,showArrows()})},width:function(){return $(this.div).width()},setGrayed:function(a){this.img!==null&&$(this.img).css("opacity",a?"0.5":"1.0")},load:function(a){this.setGrayed(!0);var b=this;ImageLoader.load(a,
function(a,d){b.onLoaded(a,d)})},onLoaded:function(a){this.img!==null&&this.div.removeChild(this.img);this.img=a;this.div.appendChild(this.img);$(this.img).css("position","relative");if(this.sequence===0){var b=this;setTimeout(function(){$(b.img).css("opacity","0.99")},100)}this.sequence+=1},format:function(){}};function Overlay(a,b,c,d,e){this.colour=a||"transparent";this.left=b||0;this.top=c||0;this.width=d||$(window).width();this.height=e||$(window).height()}Overlay.prototype.hide=function(){this.div.remove()};
Overlay.prototype.show=function(a){this.div=$("<div>");$(window);this.div.css("position","fixed");this.div.css("background",this.colour);this.div.css("opacity","0.25");this.div.css("left",""+this.left+"px");this.div.css("top",""+this.top+"px");this.div.css("zindex","1");this.div.css("width",""+this.width+"px");this.div.css("height",""+this.height+"px");this.div.css("display","none");this.div.click(function(b){a(b)});$("body").append(this.div);this.div.fadeIn("normal")};if(!window.JSON)window.JSON={};
(function(){function a(a){return a<10?"0"+a:a}function b(a){e.lastIndex=0;return e.test(a)?'"'+a.replace(e,function(a){var b=g[a];return typeof b==="string"?b:"\\u"+("0000"+a.charCodeAt(0).toString(16)).slice(-4)})+'"':'"'+a+'"'}function c(a,d){var e,g,o,p,q=f,l,i=d[a];i&&typeof i==="object"&&typeof i.toJSON==="function"&&(i=i.toJSON(a));typeof j==="function"&&(i=j.call(d,a,i));switch(typeof i){case "string":return b(i);case "number":return isFinite(i)?String(i):"null";case "boolean":case "null":return String(i);
case "object":if(!i)return"null";f+=h;l=[];if(Object.prototype.toString.apply(i)==="[object Array]"){p=i.length;for(e=0;e<p;e+=1)l[e]=c(e,i)||"null";o=l.length===0?"[]":f?"[\n"+f+l.join(",\n"+f)+"\n"+q+"]":"["+l.join(",")+"]";f=q;return o}if(j&&typeof j==="object"){p=j.length;for(e=0;e<p;e+=1)g=j[e],typeof g==="string"&&(o=c(g,i))&&l.push(b(g)+(f?": ":":")+o)}else for(g in i)Object.hasOwnProperty.call(i,g)&&(o=c(g,i))&&l.push(b(g)+(f?": ":":")+o);o=l.length===0?"{}":f?"{\n"+f+l.join(",\n"+f)+"\n"+
q+"}":"{"+l.join(",")+"}";f=q;return o}}if(typeof Date.prototype.toJSON!=="function")Date.prototype.toJSON=function(){return isFinite(this.valueOf())?this.getUTCFullYear()+"-"+a(this.getUTCMonth()+1)+"-"+a(this.getUTCDate())+"T"+a(this.getUTCHours())+":"+a(this.getUTCMinutes())+":"+a(this.getUTCSeconds())+"Z":null},String.prototype.toJSON=Number.prototype.toJSON=Boolean.prototype.toJSON=function(){return""+this.valueOf()};var d=/[\u0000\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g,
e=/[\\\"\x00-\x1f\x7f-\x9f\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g,f,h,g={"\u0008":"\\b","\t":"\\t","\n":"\\n","\u000c":"\\f","\r":"\\r",'"':'\\"',"\\":"\\\\"},j;if(typeof window.JSON.stringify!=="function")window.JSON.stringify=function(a,b,d){var e;h=f="";if(typeof d==="number")for(e=0;e<d;e+=1)h+=" ";else typeof d==="string"&&(h=d);if((j=b)&&typeof b!=="function"&&(typeof b!=="object"||typeof b.length!=="number"))throw Error("JSON.stringify");
return c("",{"":a})};if(typeof window.JSON.parse!=="function")window.JSON.parse=function(a,b){function c(a,d){var e,f,g=a[d];if(g&&typeof g==="object")for(e in g)Object.hasOwnProperty.call(g,e)&&(f=c(g,e),f!==void 0?g[e]=f:delete g[e]);return b.call(a,d,g)}var e,a=String(a);d.lastIndex=0;d.test(a)&&(a=a.replace(d,function(a){return"\\u"+("0000"+a.charCodeAt(0).toString(16)).slice(-4)}));if(/^[\],:{}\s]*$/.test(a.replace(/\\(?:["\\\/bfnrt]|u[0-9a-fA-F]{4})/g,"@").replace(/"[^"\\\n\r]*"|true|false|null|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?/g,
"]").replace(/(?:^|:|,)(?:\s*\[)+/g,"")))return e=eval("("+a+")"),typeof b==="function"?c({"":e},""):e;throw new SyntaxError("JSON.parse");}})();var Wsd;
Wsd={email:null,send:function(a,b,c){var d;return d=jQuery.ajax({url:a,type:"POST",data:b,success:function(a){window.console.log(d);d.getResponseHeader("Content-type")==="application/x-json"&&(window.console.log(a),a=JSON.parse(a));return c(a,null)},error:function(a){return c(null,a.statusText)}})},addUser:function(a,b,c){return Wsd.send("/users/add",{email:a,password:b},c)},changeUser:function(a,b,c,d){return Wsd.send("/users/change",{email:a,oldpassword:b,newpassword:c},d)},authenticate:function(a,b,
c){return Wsd.send("/users/authenticate",{email:a,password:b},function(b,e){if(!e)Wsd.email=a;return c(b,e)})},logout:function(a){return Wsd.send("/users/logout",{},a)},getUserInfo:function(a){return Wsd.send("/users/info",{},function(b,c){return b?(Wsd.email=b.email,a(b,null)):a(b,c)})},createFile:function(a,b,c){return Wsd.send("/files/create",{name:a,contents:b},c)},listFiles:function(a){return Wsd.send("/files/list",{},a)},readFile:function(a,b){return Wsd.send("/files/read",{fileid:a,contentType:"text"},
b)},extractTitle:function(a){return(a=/^\s*title +(.+)/m.exec(a))?a[1]:"Untitled"}};var log=function(a,b){if(window.console){var c=[],d;if(!log.disabled[a]){var e=b[0].split("%s");c.push(e[0]);for(d=1;d<e.length;d++)d-1>=b.length-1?c.push("<too few args>"):typeof b[d]==="string"||typeof b[d]==="number"?c.push(b[d]):c.push(JSON.stringify(b[d])),c.push(e[d]);c=c.join("");for(d=0;d<log.listeners.length;d++)log.listeners[d](a,c)}}};log.disabled={};log.listeners=[];log.enable=function(a,b){log.disabled[a]=!b};
log.create=function(a,b){b===!1&&(log.disabled[a]=!0);return function(b){log(a,arguments)}};log.addListener=function(a){log.listeners.push(a)};log.enableConsole=function(){log.emulatedConsole||log.listeners.push(function(a,b){window.console.log(a+": "+b)})};
if(!("console"in window))log.emulatedConsole=!0,window.console={log:function(){for(var a=[],b=0;b<arguments.length;b++)a.push(JSON.stringify(arguments[b]));for(b=0;b<log.listeners.length;b++)log.listeners[b]("Console",a.join(""))}},window.console.error=window.console.log;var EventEmitter=function(){this.events={}};EventEmitter.prototype.log=log.create("EventEmitter");EventEmitter.prototype.emit=function(a,b){var c;c=Array.prototype.slice.call(arguments,1);setTimeout(__bind(function(){var b,e,f,h;if(a in this.events){h=this.events[a];for(e=0,f=h.length;e<f;e++)b=h[e],this.log("Emit %s",a),b.apply(null,c)}},this),0);return this};EventEmitter.prototype.on=function(a,b){this.bind(a,b);return this};
EventEmitter.prototype.bind=function(a,b){a in this.events?this.events[a].push(b):this.events[a]=[b];return b};EventEmitter.prototype.unbind=function(a,b){var c,d,e;if(a in this.events){c=this.events[a];for(d=0,e=c.length-1;d<=e;d+=1)if(c[d]===b){c.splice(d,1);break}}};EventEmitter.prototype.joinEvents=function(a){var b;if(a.events!==this.events){for(b in a.events)this.events[b]=b in this.events?this.events[b].concat(a.events[b]):a.events[b];a.events=this.events}};var Sheet=function(a){this.name=a;Sheet.__super__.constructor.call(this);this.div=$("#"+a);this.div.css("position","absolute");this.div.css("left","0px");this.div.css("top","0px");this.div.css("width","100%");this.div.css("height","100%");this.div.css("z-index","10");this.div.css("border","none");this.div.css("border-radius","0")};__extends(Sheet,EventEmitter);Sheet.prototype.log=log.create("Sheet");
Sheet.prototype.show=function(){var a,b;Sheet.current&&Sheet.current.hide();Sheet.current=this;b=$(window).width();a=$(window).height();this.onResize(b,a);this.div.show();return this.on("cancel",__bind(function(){return this.hide()},this))};Sheet.prototype.onResize=function(){};Sheet.prototype.hide=function(){if(Sheet.current===this)return this.div.hide(),Sheet.current=null};Sheet.current=null;
Sheet.emit=function(){var a;a=1<=arguments.length?__slice.call(arguments,0):[];Sheet.current&&Sheet.current.emit.apply(Sheet.current,a)};$(window).resize(function(){var a,b;if(Sheet.current)return b=$(window).width(),a=$(window).height(),Sheet.current.onResize(b,a)});var Dialog=function(a){this.name=a;Dialog.__super__.constructor.call(this);this.div=$("#"+a);this.overlay=null};__extends(Dialog,EventEmitter);Dialog.prototype.log=log.create("Dialog");
Dialog.prototype.show=function(){Dialog.current&&Dialog.current.hide();this.log("Set Dialog.current");Dialog.current=this;this.overlay=new Overlay("black");this.overlay.show(__bind(function(){return this.hide()},this));this.onResize();this.div.slideDown("fast");return this.on("cancel",__bind(function(){return this.hide()},this))};
Dialog.prototype.onResize=function(){var a,b;b=$(window).width();a=$(window).height();this.div.css("left",""+(b/2-this.div.outerWidth()/2)+"px");return this.div.css("top",""+(a/2-this.div.outerHeight()/2)+"px")};Dialog.prototype.hide=function(){if(Dialog.current===this)return this.overlay.hide(),this.div.hide(),Dialog.current=null,this.log("Clear Dialog.current")};Dialog.current=null;
Dialog.emit=function(){var a;a=1<=arguments.length?__slice.call(arguments,0):[];Dialog.current&&Dialog.current.emit.apply(Dialog.current,a)};$(window).resize(function(){if(Dialog.current)return Dialog.current.onResize()});var CreateAccountDialog=function(){CreateAccountDialog.__super__.constructor.call(this,"dialog-create-account");$("#emailInput").focus();this.on("create",__bind(function(){return this.onCreate()},this))};__extends(CreateAccountDialog,Dialog);
CreateAccountDialog.prototype.onCreate=function(){var a,b;b=$("#passwordInput1").val();a=$("#passwordInput2").val();b!==a?$("#createaccounterror").text("Passwords do not match"):(a=$("#emailInput").val(),Wsd.addUser(a,b,__bind(function(a,b){return b?$("#createaccounterror").text(b):this.emit("cancel")},this)))};
var ChangeAccountDialog=function(){ChangeAccountDialog.__super__.constructor.call(this,"dialog-change-account");Wsd.email&&$("#emailInput-Change").val(Wsd.email);$("#emailInput-Change").focus();this.on("create",__bind(function(){return this.onCreate()},this))};__extends(ChangeAccountDialog,Dialog);
ChangeAccountDialog.prototype.onCreate=function(){var a,b,c;b=$("#passwordInput1-Change").val();c=$("#passwordInput2-Change").val();a=$("#passwordInput3-Change").val();c!==a?$("#changeaccounterror").text("Passwords do not match"):(a=$("#emailInput-Change").val(),Wsd.changeUser(a,b,c,__bind(function(a,b){return b?$("#changeaccounterror").text(b):this.emit("cancel")},this)))};var OpenDialog=function(){OpenDialog.__super__.constructor.call(this,"dialog-open");this.file=null;Wsd.listFiles(__bind(function(a){return this.onGotFileList(a)},this))};__extends(OpenDialog,Dialog);OpenDialog.prototype.okay=function(){$("#fileinput").val()?document.getElementById("uploadform").submit():this.file&&app.open(this.file);return this.hide()};
OpenDialog.prototype.onGotFileList=function(a){var b,c,d,e,f,h,g,j,n;d=a.files;d.sort(function(a,b){return b.mtime-a.mtime});f=$("#filelist");f.empty();e=null;for(j=0,n=d.length;j<n;j++)a=d[j],c=(new Date(a.mtime*1E3)).toDateString(),g=$("<tr>"),h=$("<td>"),b=$("<a href='javascript:void(0)'>"),b.text(a.name),h.append(b),g.append(h),h=$("<td>"),h.text(c),g.append(h),f.append(g),c=__bind(function(a,c){b.click(__bind(function(){return this.onFileClicked(a)},this));c.click(__bind(function(){e&&e.removeClass("selected");
e=c;e.addClass("selected");return this.onFileClicked(a)},this));return c.dblclick(__bind(function(){this.file=a;return this.okay()},this))},this),c(a,g);return $("#filelist tr:even").addClass("evenRow")};OpenDialog.prototype.onFileClicked=function(a){var b;window.console.log(a);b="/files/render?fileid="+a.fileid+"&width=300&height=300";$("#preview").attr("src",b);return this.file=a};var WsdApp=function(){multiuser&&Wsd.getUserInfo(__bind(function(a){if(a)return this.onLoggedIn(a)},this));this.zoom="width"};WsdApp.prototype.log=log.create("WsdApp");WsdApp.prototype.onLoggedIn=function(){$("#signin").hide();$("#signout").show();return $("#changeButton").show()};WsdApp.prototype.onLoggedOut=function(){$("#signout").hide();$("#changeButton").hide();return $("#signin").show()};WsdApp.prototype.changeAccount=function(){return(new ChangeAccountDialog).show()};
WsdApp.prototype.openClicked=function(){return(new OpenDialog).show()};WsdApp.prototype.open=function(a){return Wsd.readFile(a.fileid,__bind(function(a,c){return c?alert(c):$("#text").val(a).change()},this))};WsdApp.prototype.zoomClicked=function(){this.zoom==="width"?($("#zoombutton").val("Zoomed to 100%"),this.zoom="full"):($("#zoombutton").val("Shrunk to fit"),this.zoom="width");return newImage()};function MakeAjaxRequest(a,b,c,d,e){var f=this;e!=="GET"&&e!=="POST"&&(e="POST");try{f.xmlHttpReq=new XMLHttpRequest}catch(h){try{f.xmlHttpReq=new ActiveXObject("Msxml2.XMLHTTP")}catch(g){try{f.xmlHttpReq=new ActiveXObject("Microsoft.XMLHTTP")}catch(j){f.xmlHttpReq=null}}}var n="",k=!0,m;for(m in b)k||(n+="&"),k=!1,n+=m+"="+encodeURIComponent(b[m]);e==="GET"&&(a+="?"+n);f.xmlHttpReq.open(e,a,!0);f.xmlHttpReq.setRequestHeader("Content-Type","application/x-www-form-urlencoded");f.xmlHttpReq.onreadystatechange=
function(){f.xmlHttpReq.readyState===4&&c&&c(f.xmlHttpReq.responseText,d)};e==="POST"&&f.xmlHttpReq.send(n)}
function MakeAjaxRequestWithStatus(a,b,c,d){var e;d!=="GET"&&d!=="POST"&&(d="POST");try{e=new XMLHttpRequest}catch(f){try{e=new ActiveXObject("Msxml2.XMLHTTP")}catch(h){try{e=new ActiveXObject("Microsoft.XMLHTTP")}catch(g){e=null}}}var j="",n=!0,k;for(k in b)n||(j+="&"),n=!1,j+=k+"="+encodeURIComponent(b[k]);d==="GET"&&j.length>0&&(a+="?"+j);e.open(d,a,!0);e.setRequestHeader("Content-Type","application/x-www-form-urlencoded");e.onreadystatechange=function(){if(e.readyState===4){var a={},b="ok";if(e.status===
200)try{a=eval("("+e.responseText+")"),"status"in a&&(b=a.status)}catch(d){b="Error in server response: "+d}else b=e.message?e.message:e.status===0?"Network error. Check internet connection":"Server returned status "+e.status;c(a,b)}};d==="POST"?e.send(j):e.send("")}
function AjaxDownload(a,b){var c=document.createElement("form"),d,e;document.body.appendChild(c);c.method="post";c.action=a;for(e in b)d=document.createElement("input"),d.type="hidden",c.appendChild(d),d.name=e,d.value=b[e];d=document.createElement("input");d.type="submit";c.appendChild(d);c.submit();document.body.removeChild(c)};function LinkDialog(){var a=getWsdLink(document.getElementById("text").value,document.getElementById("stylechoice").value),b=window.location.host;a?(document.getElementById("linkimage").value="http://"+b+"/cgi-bin/cdraw?"+a,document.getElementById("linkpage").value="http://"+b+"/?"+a):(document.getElementById("linkimage").value="Diagram too large.",document.getElementById("linkpage").value="Diagram too large.")}LinkDialog.prototype={};
function SaveDialog(){$("#SaveDialog-name").val(Wsd.extractTitle($("#text").val()));this.tab="export";this.exportTabClicked();this.changed()}
SaveDialog.prototype={doExport:function(){var a,b;document.getElementById("pdfRadioButton").checked?a="pdf":document.getElementById("pngRadioButton").checked?(a="png",b="image/png"):(a="txt",b="text");page.hideDialog();var c=document.getElementById("text").value,d=document.getElementById("stylechoice").value,e=document.getElementById("paginateCheckbox").checked,f=document.getElementById("landscapeCheckbox").checked,h=document.getElementById("paperSelect").value;a==="pdf"?MakeAjaxRequest("index.php",
{message:c,style:d,paginate:e?"1":"0",paper:h,landscape:f?"1":"0",format:a},function(a){a=eval("("+a+")");window.location.href="index.php"+a.img},null,"POST"):AjaxDownload("index.php",{"function":"export",name:"diagram."+a,contentType:b,style:d,content:c})},doSave:function(){var a=$("#SaveDialog-name").val(),b=$("#text").val();$("#SaveDialog-working").show();$("#SaveDialog-body").hide();Wsd.createFile(a,b,function(a,b){$("#SaveDialog-working").hide();$("#SaveDialog-body").show();b?$("#SaveDialog-error").text(b):
page.hideDialog()})},okay:function(){this.tab==="export"?this.doExport():this.doSave()},changed:function(){document.getElementById("pdfRadioButton").checked?($("#pdfControls").removeClass("disabled"),document.getElementById("paginateCheckbox").disabled=!1,document.getElementById("paginateCheckbox").checked?($("#paginateControls").removeClass("disabled"),document.getElementById("paperSelect").disabled=!1,document.getElementById("landscapeCheckbox").disabled=!1):($("#paginateControls").addClass("disabled"),
document.getElementById("paperSelect").disabled=!0,document.getElementById("landscapeCheckbox").disabled=!0)):($("#pdfControls").addClass("disabled"),$("#paginateControls").addClass("disabled"),document.getElementById("paginateCheckbox").disabled=!0,document.getElementById("paperSelect").disabled=!0,document.getElementById("landscapeCheckbox").disabled=!0)},exportTabClicked:function(){this.tab="export";$("#SaveDialog-SaveTab").removeClass("tabselected");$("#SaveDialog-ExportTab").addClass("tabselected");
$("#SaveDialog-SaveBox").hide();$("#SaveDialog-ExportBox").show()},saveTabClicked:function(){this.tab="save";$("#SaveDialog-ExportTab").removeClass("tabselected");$("#SaveDialog-SaveTab").addClass("tabselected");$("#SaveDialog-ExportBox").hide();$("#SaveDialog-SaveBox").show()}};function LicenseDialog(){}
LicenseDialog.prototype={init:function(){$("#LicenseDialogMain").show();$("#LicenseDialogWorking").hide();$("#LicenseDialogError").text("");$("#licensetext").focus()},okay:function(){$("#LicenseDialogMain").hide();$("#LicenseDialogWorking").show();page.centreDialog();this.modal=!0;var a=this;MakeAjaxRequestWithStatus("index.php",{"function":"setProductKey",key:document.getElementById("licensetext").value},function(b,c){c==="ok"?(a.modal=!1,page.hideDialog(),alert("The product key was accepted."),
window.location.href="/status.html"):($("#LicenseDialogWorking").hide(),$("#LicenseDialogError").text(c),$("#LicenseDialogMain").show(),page.centreDialog())},"POST")}};var Dialogs={LinkDialog:LinkDialog,SaveDialog:SaveDialog,OpenDialog:OpenDialog,LicenseDialog:LicenseDialog};
function Page(){this.dlg=null;this.overlay=new Overlay;var a=document.getElementById("uploadtarget");$(a).load(function(){var b=a.contentDocument.body.innerHTML;page.hideDialog();try{b=window.JSON.parse(b).data,b=b.replace(/&gt;/g,">"),b=b.replace(/&lt;/g,"<"),b=b.replace(/&amp;/g,"&"),b=b.replace(/&quot;/g,'"'),b=b.replace(/&apos;/g,"'"),document.getElementById("text").value=b,onTextChanged()}catch(c){alert("Error opening file: "+c)}})}
Page.prototype={onCreateAccountClicked:function(){(new CreateAccountDialog).show()},showDialog:function(a,b){var c=this;this.hideDialog();this.overlay.show(function(){(!c.dlg||!c.dlg.modal)&&c.hideDialog()});this.dlg=new Dialogs[a](b);this.dlgName=a;var d=$("#"+a);this.dlgDiv=d;this.centreDialog();d.slideDown("fast");"init"in this.dlg&&this.dlg.init()},centreDialog:function(){if(this.dlg){var a=this.dlgDiv,b=a.width(),c=a.height(),d=$(window).width(),e=$(window).height();a.css("left",""+(d/2-b/2)+
"px");a.css("top",""+(e/2-c/2)+"px")}},hideDialog:function(){if(this.dlg!==null)$("#"+this.dlgName).slideUp("fast"),this.overlay.hide(),this.dlg=null},login:function(){var a=$("#emailSignin").val(),b=$("#passwordSignin").val();Wsd.authenticate(a,b,function(b,d){if(d)$("#loginerror").text(d);else app.onLoggedIn(a)})},logout:function(){Wsd.logout(function(a,b){if(!b)app.onLoggedOut()})},test:function(){(new Sheet("TestSheet")).show()}};var imageView,textWanted="",textHave="",page=null,multiuser=!1,app=null;function IsWebEdition(){return document.location.href.indexOf("http://www.websequencediagrams.com")===0}function onImageDone(a,b){if(textWanted===b){textHave=b;var c=eval("("+a+")");imageView.load("index.php"+c.img);for(var d=document.getElementById("errorDiv"),e="",f=0;f<c.errors.length;f++)e+=c.errors[f]+"<p>";e===""&&(e="<p>No errors.");d.innerHTML=e}}var Notices=[];
function addNotice(a){var b=document.createElement("div");b.innerHTML=a;a=document.createElement("a");a.style.display="inline";a.style.cssFloat="right";a.appendChild(document.createTextNode("X"));a.style.color="white";a.style.background="#888";a.style.cursor="pointer";a.style.border="2px solid #735005";b.appendChild(a);var c=document.createElement("div");c.style.clear="both";var d=document.createElement("div");$(d).addClass("notice");d.appendChild(b);d.appendChild(c);Notices.push(d);var e=document.getElementById("imageDiv");
e.insertBefore(d,e.firstChild);a.onclick=function(){e.removeChild(d);for(var a=0;a<Notices.length;a++)Notices[a]===d&&Notices.splice(a,1);$(window).resize()};$(window).resize()}function displayAd(){IsWebEdition()&&addNotice("Access <a href='examples.html#parallel' target='_blank'>advanced features</a>, and run WebSequenceDiagrams in your own network for <a href='order.html' target='_blank'>as little as $99.</a>")}var NumberLoaded=0;
function updateImage(a){if(textHave===a)imageView.setGrayed(!1);else{NumberLoaded+=1;NumberLoaded===7&&(displayAd(),window._kmq&&window._kmq.push(["record","used_7"]));textWanted=a;var b={message:a,style:document.getElementById("stylechoice").value,scale:"100",paginate:"0",paper:"letter",landscape:"0",format:"png"};if(app.zoom==="width")b.width=$("#imageDiv").width();MakeAjaxRequest("index.php",b,onImageDone,a,"POST")}}
function newImage(){textHave="";updateImage(document.getElementById("text").value)}var oldTimeout=null;function onTextChanged(){var a=document.getElementById("text").value;oldTimeout!==null&&clearTimeout(oldTimeout);oldTimeout=setTimeout(function(){a=document.getElementById("text").value;updateImage(a)},1E3);imageView.setGrayed(!0)}function showArrows(){$("#arrows").show();setTimeout(function(){$("#arrows").fadeOut("slow")},5E3)}
function splitQueryString(a){for(var b={},a=a.split("?"),a=a[a.length-1].split("&"),c=0;c<a.length;c++){var d=a[c].split("=");if(d[0])try{d.length>1?window.decodeURIComponent?b[d[0].toLowerCase()]=decodeURIComponent(d[1].replace(/\+/g," ")):b[d[0].toLowerCase()]=unescape(d[1]):b[d[0].toLowerCase()]=""}catch(e){}}return b}function SetStyle(a){document.getElementById("stylechoice").value=a}
function init(){page=new Page;$(window).resize(function(){var a=$(window).height(),c=$(window).width(),d=$("#menuDiv").height(),e=$("#errorDiv").height(),f=$("#templateDiv").width(),h=$("#text").outerWidth(),e=a-d-e,g=c-f-h,j=$("#banner").width();$("#mainDiv").height(a-d);$("#textDiv").height(a-d);$("#text").height(e);$("#errorDiv").width(h);$("#imageDiv").css("left",""+(h+f)+"px");$("#imageDiv").css("top","0px");$("#imageDiv").width(c-f-h);$("#imageDiv").height(a-d);$("#templateDiv").css("height",
""+(a-d)+"px");jQuery.support.boxModel||$("#errorDiv").css("top",""+e+"px");$("#errorDiv").css("left",""+f+"px");$("#banner").css("left",""+(g+j)/2+"px");for(d=c=0;d<Notices.length;d++)c+=$(Notices[d]).outerHeight();$("#imageView").height($("#imageDiv").height()-c);c=$("#imageView").offset().top;$("#styleSelect").css("top",""+(c+10)+"px");$("#arrows").css("top",""+(a/2-$("#arrows").height()/2)+"px");$("#arrows").css("left",""+(f+h-$("#arrows").width()/2)+"px")});$(window).resize();imageView=new ImageView(document.getElementById("imageView"));
var a=splitQueryString(window.location.href);"s"in a?SetStyle(a.s):IsWebEdition()||SetStyle("default");if(a.license==="new"||window.LICENSE_VALID===!1)$(".unlicensed").show(),page.showDialog("LicenseDialog",null);"multiuser"in a&&($(".multiuser").show(),$(".nomultiuser").hide(),multiuser=!0);$("#text").keydown(function(){onTextChanged()});$("#text").change(function(){onTextChanged()});onTextChanged();showArrows();app=new WsdApp}
function getWsdLink(a,b){function c(){this.str="";this.partialSize=this.partial=0;this.table="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_";this.addBits=function(a,b){this.partial=this.partial<<b|a;for(this.partialSize+=b;this.partialSize>=6;)this.str+=this.table.charAt(this.partial>>this.partialSize-6&63),this.partialSize-=6};this.finish=function(){if(this.partialSize)this.str+=this.table.charAt(this.partial<<6-this.partialSize&63),this.partial=this.partialSize=0}}function d(a){return a>=
16383?String.fromCharCode(128|a>>14&127)+String.fromCharCode(128|a>>7&127)+String.fromCharCode(a&127):a>=127?String.fromCharCode(128|a>>7&127)+String.fromCharCode(a&127):String.fromCharCode(a)}var b="&s="+b,a=function(a){for(var b=new c,d=0;d<a.length;d++)b.addBits(a.charCodeAt(d),8);b.finish();return b.str}(function(a){var b="",c=0,e={},n=a.length-4,k;for(k=4;k<a.length;k++){var m=a.substr(k-4,4);e[m]===void 0&&(e[m]=[]);e[m].push(k-4)}for(;c<n;){var m=4,r=!1,o=0,p=0;k=a.substr(c,4);var q=e[k];if(q!==
void 0)for(k=0;k<q.length;k++){var l=q[k];if(l+m>=c)break;for(;l+m<c;)if(a.substr(l,m)===a.substr(c,m)){var i=m;m++;r&&i>p&&(o=c-l-i,p=i);r=!0}else break}p?(b+=String.fromCharCode(0)+d(o)+d(p),c+=p):(b+=a.charCodeAt(c)!==0?a.charAt(c):String.fromCharCode(0)+String.fromCharCode(0),c++)}return b+a.slice(c).replace(/\x00/g,"\x00\x00")}(function(a){for(var a=a.replace(/\r\n/g,"\n"),b="",c=0;c<a.length;c++){var d=a.charCodeAt(c);d<128?b+=String.fromCharCode(d):(d>127&&d<2048?b+=String.fromCharCode(d>>
6|192):(b+=String.fromCharCode(d>>12|224),b+=String.fromCharCode(d>>6&63|128)),b+=String.fromCharCode(d&63|128))}return b}(a))),e="lz="+a+b;return e.length<2048?e:null}function hide(a){document.getElementById(a).style.display="none"}function show(a){document.getElementById(a).style.display="block"}function onMoreSpace(){var a=document.getElementById("templates"),b=document.getElementById("gen");b.rows=20;a.style.height=b.offsetHeight+"px";hide("linkmorespace")}
function onPaginateChanged(){var a=document.forms.paginateForm,b=a.paginate.checked;a.paper.disabled=!b;a.landscape.disabled=!b;document.getElementById("paginateControls").style.color=b?"black":"gray"}function onShowExamples(){window.open("examples.html")}function onShowEmbed(){window.open("embedding.html")}var ImageNode=null,_showPermaLink=!1;function onPdfDone(a){a=window.JSON.parse(a);window.location.href=a.img}
function onPdf(){var a=document.forms.entryForm,b=document.forms.paginateForm;MakeAjaxRequest("index.php",{message:a.message.value,style:a.stylechoice.value,paginate:b.paginate.checked?"1":"0",paper:b.paper.value,landscape:b.landscape.checked?"1":"0",format:"pdf"},onPdfDone,null,"POST")}function addText(a){var b=document.getElementById("text"),c=b.value;c.length>0&&c.substr(c.length-1,1)!=="\n"&&(c+="\n");c+=a;b.value=c;onTextChanged()}
function onSignal(a){var b="",c=!1;a==="signal"?b="A->B: text\n":a==="dotted"?b="A--\>B: text\n":a==="alt"?b="alt text1\n    A->B: text\nelse text2\n    A->B: text\nend\n":a==="opt"?b="opt text\n    A->B: text\nend\n":a==="loop"?b="loop text\n    A->B: text\nend\n":a==="self"?b="A->A: text\n":a==="activate"?b="A->B: text\nactivate B\nB--\>A: text\ndeactivate B\n":a==="notes"?b="note over A,B: text1\nnote left of A: text2\nnote right of A\n    multiline\n    text\nend note\n":a==="parallel"?(b="parallel {\n    A->B: signal 1\n    B->C: signal2\n}\n",
c=!0):a==="state"&&(b="state over A: Initial state\n",c=!0);addText(b);c&&IsWebEdition()&&alert("This feature is only available in a purchased version.")};window.page=page;window.Dialog=Dialog;Dialog.emit=Dialog.emit;SaveDialog.prototype.okay=SaveDialog.prototype.okay;LicenseDialog.prototype.init=LicenseDialog.prototype.init;LicenseDialog.prototype.okay=LicenseDialog.prototype.okay;window.Sheet=Sheet;Sheet.emit=Sheet.emit;

