// (c)2010 Michael Holtstrom

function Sheet(dbid,aryid,top,left,stamp,img,width,height,label,opened)
{dbg('Sheet.constructor');var o=null;this.dbid=dbid;this.aryid=aryid;this.stamp=stamp;this.dirty=false;this.pgs=1;this.remover=Array();this.levels=Array();this.levels['character']=0;this.closing=false;this.xhr=new Xhr();o=document.createElement('div');o.className='tile';o.style.top=top+'px';o.style.left=left+'px';if(opened)
{o.style.visibility='hidden';}
this.remover[this.remover.length]=util.bind(this,'dragTile','mousedown',o);this.tile=o;o=document.createElement('div');o.className='tbar';this.tile.appendChild(o);o=document.createElement('div');o.className='icoOpen';o.title='Open';this.icoOpen=o;util.add(this.icoOpen,'mousedown',util.cancel);this.remover[this.remover.length]=util.bind(this,'DOicoOpen','click',o);this.tile.appendChild(o);o=document.createElement('div');o.className='avatar';o.style.width=width+'px';o.style.height=height+'px';if(img!=''){o.style.backgroundImage='url('+img+')';}
this.tile.appendChild(o);this.avatar=o;o=document.createElement('div');o.style.cssFloat='left';o.style.width=util.lmin(width-7,0)+'px';o.style.height=util.lmin(height-7-15+4,0)+'px';this.tile.appendChild(o);this.damn=o;o=document.createElement('span');o.className='bigtitle';o.innerHTML=label;this.tile.appendChild(o);this.label=o;document.body.appendChild(this.tile);var addIcon=function(obj,name,text)
{obj[name]=document.createElement('div');obj[name].className=name;obj[name].title=text;obj.sheet.appendChild(obj[name]);obj.remover[obj.remover.length]=util.bind(obj,'DO'+name,'click',obj[name]);};o=document.createElement('div');o.className='sheets';o.style.width='7.9in';o.style.height='10.4in';o.style.visibility='hidden';this.sheet=o;o=document.createElement('div');o.className='sht_bdr_lft';o.style.top='0px';o.style.height='11in';this.sheet.appendChild(o);this.bdr_lft=o;o=document.createElement('div');o.className='sht_bdr_rht';o.style.top='0px';o.style.height='11in';this.sheet.appendChild(o);this.bdr_rht=o;o=document.createElement('div');o.className='sht_bdr_btm';this.sheet.appendChild(o);o=document.createElement('div');o.className='dragger';this.sheet.appendChild(o);this.remover[this.remover.length]=util.bind(this,'dragSheet','mousedown',o);o=document.createElement('div');o.className='sht_bdr_lft';o.style.top='-5px';o.style.height='5px';this.sheet.appendChild(o);o=document.createElement('div');o.className='gone';o.style.top='11in';o.innerHTML='<div class="sht_bdr_spc1"></div><div class="sht_bdr_spc2"></div>';this.sheet.appendChild(o);this.bdr_spc=o;addIcon(this,'icoClose','Save and Close');addIcon(this,'icoSave','Save');addIcon(this,'icoPrint','Print Preview');addIcon(this,'icoFont','Change Fonts');addIcon(this,'icoBoxLayout','Switch To Box Layout Mode');addIcon(this,'icoPageup','Remove A Page');addIcon(this,'icoPagedown','Add A Page');util.add(this.icoClose,'mousedown',util.cancel);o=document.createElement('div');o.className='pad';o.style.height='10.4in';this.sheet.appendChild(o);this.pad=o;o=document.createElement('div');o.className='gone';o.innerHTML='<div class="boxhdl boxtl" </div>'
+'<div class="boxhdl boxtm" </div>'
+'<div class="boxhdl boxtr" </div>'
+'<div class="boxhdl boxml" </div>'
+'<div class="boxhdl boxmr" </div>'
+'<div class="boxhdl boxbl" </div>'
+'<div class="boxhdl boxbm" </div>'
+'<div class="boxhdl boxbr" </div>';this.pad.appendChild(o);this.mask=o;this.remover[this.remover.length]=util.bind(this,'moveMask','mousedown',this.mask);document.body.appendChild(this.sheet);util.add(this.sheet,'contextmenu',util.cancel);this.remover[this.remover.length]=util.bind(this,'sheetMouseUp','mouseup',this.sheet);this.laid=null;this.topBox=null;if(opened)
{this.DOicoOpenImpl(top,left);}};Sheet.prototype.cleanup=function()
{dbg('Sheet.cleanup');if(main.topObj==this.sheet||main.topObj==this.tile)
{main.topObj=null;}
util.remove(this.icoOpen,'mousedown',util.cancel);util.remove(this.icoClose,'mousedown',util.cancel);util.remove(this.sheet,'contextmenu',util.cancel);for(var i=0;i<this.remover.length;i++)
{util.remover(this.remover[i]);this.remover[i]=null;}
for(var i=0;i<this.pad.childNodes.length;i++)
{if(this.pad.childNodes[i].className.indexOf('box')>=0)
{this.rmvBox(this.pad.childNodes[i]);}}
this.xhr.cleanup();document.body.removeChild(this.tile);document.body.removeChild(this.sheet);};Sheet.prototype.sheetMouseUp=function(e,o)
{if(!util.isrc(e)){return;}
dbg('Sheet.sheetMouseUp');pop.raise(e,at('rcsheet'),this,null);return util.cancel(e);};Sheet.prototype.rcNewBox=function(menu)
{dbg('Sheet.rcNewBox');var box=this.rcNewBoxImpl(menu);var ent=this.addEntry(box,'blank...',1,0);if(this.icoBoxLayout.className!='icoBoxEdit')
{ent.obj.gotxt();}};Sheet.prototype.rcNewImage=function(menu)
{dbg('Sheet.rcNewImage');var p=this.pad;var w=300;var h=200;var x=menu.offsetLeft-p.offsetLeft-Math.floor(w/4);var y=menu.offsetTop-p.offsetTop-Math.floor(h/4);if(x<0){x=0;}
else if(x+w>p.offsetLeft+p.offsetWidth)
{x=p.offsetLeft+p.offsetWidth-w;}
if(y<0){y=0;}
else if(y+h>p.offsetTop+p.offsetHeight)
{y=p.offsetTop+p.offsetHeight-h;}
var img=this.addImage(x,y,w,h,null);};Sheet.prototype.rcNewLevel=function(menu)
{dbg('Sheet.rcNewLevel');var box=this.rcNewBoxImpl(menu);box.style.left='0px';box.style.width=this.pad.offsetWidth+'px';box.kind='Monk';box.lvl=1;var tag=box.kind.toLowerCase();if(this.levels[tag]==undefined)
{this.levels[tag]=box.lvl;}
else{box.lvl=++(this.levels[tag]);}
box.clvl=++(this.levels['character']);box.sp=lvls.ary[tag][0][1]+rules['intelligence'].emin;if(box.lvl==1){box.sp=box.sp*4;}
var lvl=lvls.get(tag,box.lvl);if(lvl==null)
{err.msg("Couldn't load "+box.kind+" level "+box.lvl);}
else
{var ent=null;var kind=lvls.ary[tag][0][0];ent=this.addEntry(box,'',0,1);ent.obj.txt.value=kind+': '+lvl[0];ent.obj.txt.className='gone hack';ent.obj.gospn();ent.obj.sleft.innerHTML='<span class="title">'+kind+'</span> (level '+box.lvl+') ';ent=this.addEntry(box,'blank...',0,2);ent.obj.sleft.innerHTML='<strong>Skills:</strong> ('+box.sp+' points available) ';ent.obj.sp=box.sp;ent.obj.kind=kind+': ';for(var i=0;i<lvl[1].length;i++)
{var feat=feats[lvl[1][i]];ent=this.addEntry(box,'<strong>'+feat[0]+':</strong> '+feat[1],0,1);}
if(lvl[2]!='')
{ent=this.addEntry(box,'blank...',0,3);ent.obj.sleft.innerHTML='<strong>Bonus Feat:</strong> ('+lvl[2]+') ';}}};Sheet.prototype.rcNewBoxImpl=function(menu)
{dbg('Sheet.rcNewBoxImpl');var p=this.pad;var w=300;var h=200;var x=menu.offsetLeft-p.offsetLeft-Math.floor(w/4);var y=menu.offsetTop-p.offsetTop-Math.floor(h/4);if(x<0){x=0;}
else if(x+w>p.offsetLeft+p.offsetWidth)
{x=p.offsetLeft+p.offsetWidth-w;}
if(y<0){y=0;}
else if(y+h>p.offsetTop+p.offsetHeight)
{y=p.offsetTop+p.offsetHeight-h;}
var box=this.addBox(x,y,w,h);if(this.icoBoxLayout.className=='icoBoxEdit')
{this.sheetToggleBox(box);}
return box;};Sheet.prototype.boxMouseUp=function(e,o)
{if(!util.isrc(e)){return;}
dbg('Sheet.boxMouseUp');var elm=util.elm(e);while(elm)
{if(elm.className&&elm.className.indexOf('ent')==0)
{break;}
elm=elm.parentNode;}
if(!elm){return;}
if(!(elm.obj.smpl)){return;}
at('rcUseTitle').className='rcentry bigtitle';at('rcUseHeading').className='rcentry title';at('rcUseEntry').className='rcentry';if(elm.obj.style=='bigtitle'){at('rcUseTitle').className+=' rchot';}
else if(elm.obj.style=='title'){at('rcUseHeading').className+=' rchot';}
else{at('rcUseEntry').className+=' rchot';}
pop.raise(e,at('rcbox'),this,elm);return util.cancel(e);};Sheet.prototype.rcUseTitle=function(menu)
{this.dirty=true;dbg('Sheet.rcUseTitle '+this.dirty,1);pop.mask.targ.obj.restyle('bigtitle');};Sheet.prototype.rcUseHeading=function(menu)
{this.dirty=true;dbg('Sheet.rcUseHeading '+this.dirty,1);pop.mask.targ.obj.restyle('title');};Sheet.prototype.rcUseEntry=function(menu)
{this.dirty=true;dbg('Sheet.rcUseEntry '+this.dirty,1);pop.mask.targ.obj.restyle('');};Sheet.prototype.addBox=function(x,y,w,h,px)
{this.dirty=true;dbg('Sheet.addBox '+this.dirty);var box,btn;box=document.createElement('div');box.className='box';box.style.left=x+(px?'':'px');box.style.top=y+(px?'':'px');box.style.width=w+(px?'':'px');box.style.height=h+(px?'':'px');box.events=Array();box.events[box.events.length]=util.bind(this,'boxMouseUp','mouseup',box);box.mousedownRmvr=null;box.pad=document.createElement('div');box.pad.className='pad';box.appendChild(box.pad);btn=document.createElement('div');btn.className='icoGoLayout';btn.title='Switch To Layout Mode';btn.style.visibility='hidden';box.pad.appendChild(btn);box.icoGoLayout=btn;box.events[box.events.length]=util.bind(this,'DOicoGoLayout','click',btn);btn=document.createElement('div');btn.className='icoNewEntry';btn.title='Add An Entry';btn.style.visibility='hidden';box.pad.appendChild(btn);box.icoNewEntry=btn;box.events[box.events.length]=util.bind(this,'DOicoNewEntry','click',btn);box.events[box.events.length]=util.bind(this,'boxOver','mouseover',box);box.events[box.events.length]=util.bind(this,'boxOut','mouseout',box);this.pad.appendChild(box);return box;};Sheet.prototype.rmvBox=function(box)
{this.dirty=true;dbg('Sheet.rmvBox '+this.dirty,1);if(this.topBox==box)
{this.topBox=null;}
for(var i=0;i<box.events.length;i++)
{util.remover(box.events[i]);box.events[i]=null;}
if(box.mousedownRmvr!=null)
{util.remover(box.mousedownRmvr);box.mousedownRmvr=null;}
for(var i=0;i<box.pad.childNodes.length;i++)
{if(box.pad.childNodes[i].className.indexOf('ent')==0)
{box.pad.childNodes[i].obj.cleanup();}}
this.pad.removeChild(box);};Sheet.prototype.addImage=function(x,y,w,h,url)
{this.dirty=true;dbg('Sheet.addImage '+this.dirty,1);err.msg('Not yet implemented.');return null;}
Sheet.prototype.addEntry=function(box,val,mov,fet)
{this.dirty=true;dbg('Sheet.addEntry '+this.dirty);var ent,obj;ent=document.createElement('div');ent.className='ent';ent.obj=new Entry(val,this,box,mov,fet);ent.appendChild(ent.obj.sleft);ent.appendChild(ent.obj.spn);ent.appendChild(ent.obj.txt);ent.appendChild(ent.obj.sright);box.pad.appendChild(ent);return ent;};Sheet.prototype.nextEntry=function(box,obj)
{dbg('Sheet.nextEntry');obj.gospn();found=null;done=false;hits=0;for(var i=0;i<box.pad.childNodes.length;i++)
{if(box.pad.childNodes[i].className.indexOf('ent')>=0)
{hits++;if(found!=null)
{box.pad.childNodes[i].obj.gotxt();done=true;break;}
if(box.pad.childNodes[i].obj==obj)
{found=box.pad.childNodes[i];}}}
if(!done&&found!=null)
{if((obj.spn.innerHTML=='blank...'||obj.spn.innerHTML=='&nbsp;&nbsp;')&&hits>1)
{obj.cleanup();box.pad.removeChild(found);}
else
{var ent=this.addEntry(box,'blank...',1,0);ent.obj.gotxt();}}};Sheet.prototype.boxOver=function(e,o)
{dbg('Sheet.boxOver');if(this.topBox!=null)
{this.topBox.style.zIndex=3;this.topBox.icoGoLayout.style.visibility='hidden';this.topBox.icoNewEntry.style.visibility='hidden';if(this.topBox.icoGoLayout.className!='gone')
{this.topBox.className='box';}}
this.topBox=o;this.topBox.style.zIndex=4;o.icoGoLayout.style.visibility='visible';o.icoNewEntry.style.visibility='visible';if(o.icoGoLayout.className!='gone')
{o.className='boxstill';}};Sheet.prototype.boxOut=function(e,o)
{dbg('Sheet.boxOut');};Sheet.prototype.startMask=function(e,o)
{if(util.isrc(e)){return;}
dbg('Sheet.startMask');this.mask.targ=o;this.workMask(e,o);move.startMask(e,this.mask.targ,this.mask);return util.cancel(e);};Sheet.prototype.moveMask=function(e,o)
{if(util.isrc(e)){return;}
dbg('Sheet.moveMask');this.workMask(e,o);move.moveMask(e,this.mask.targ,this.mask);return util.cancel(e);};Sheet.prototype.workMask=function(e,o)
{this.dirty=true;dbg('Sheet.workMask '+this.dirty,1);move.cleanup();move.data[6]=0;move.data[7]=this.pad.offsetWidth;move.data[8]=0;move.data[9]=this.pad.offsetHeight;this.still();var m=move.xtra;pos=util.pos(this.pad);m[20]=pos[0]-15;m[21]=m[20]+this.pad.offsetWidth+30;m[22]=pos[1]-15;m[23]=m[22]+this.pad.offsetHeight+30;m[28]=pos[0]
m[29]=pos[1]
var trash=at('trash');trash.parentNode.removeChild(trash);document.body.appendChild(trash);var bound=this;move.data[16]=function(){bound.stopMask();}
if(this.mask.targ.clvl&&this.mask.targ.clvl!=this.levels['character']){;}
else
{move.data[15]=function(xy){bound.trashMask(xy);}}};Sheet.prototype.trashMask=function(xy)
{dbgx('Sheet.trashMask');var m=move.xtra;if(xy[0]<m[20]||xy[0]>m[21]||xy[1]<m[22]||xy[1]>m[23])
{at('trash').style.left=(xy[0]-13)+'px';at('trash').style.top=(xy[1]-15)+'px';if(at('trash').className=='trash')
{return;}
at('trash').className='trash';this.mask.className='gone';this.mask.targ.className='gone';}
else
{if(at('trash').className!='trash')
{return;}
at('trash').className='gone';this.mask.className='boxmask';this.mask.targ.className='boxstill';}};Sheet.prototype.stopMask=function()
{dbgx('Sheet.stopMask');this.unstill();if(at('trash').className!='trash')
{return;}
at('trash').className='gone';this.rmvBox(this.mask.targ);};Sheet.prototype.still=function()
{dbg('Sheet.still');for(var i=0;i<this.pad.childNodes.length;i++)
{if(this.pad.childNodes[i].className=='boxlit')
{this.pad.childNodes[i].className='boxstill';}}};Sheet.prototype.unstill=function()
{dbg('Sheet.unstill');for(var i=0;i<this.pad.childNodes.length;i++)
{if(this.pad.childNodes[i].className=='boxstill')
{this.pad.childNodes[i].className='boxlit';}}};Sheet.prototype.dragSheet=function(e,o)
{if(util.isrc(e)){return;}
this.dirty=true;dbg('Sheet.dragSheet '+o.parentNode.className+' '+this.dirty,1);move.cleanup();if(main.topObj!=null){main.topObj.style.zIndex=1;}
main.topObj=this.sheet;main.topObj.style.zIndex=2;move.startSimple(e,o.parentNode);return util.cancel(e);};Sheet.prototype.dragTile=function(e,o)
{if(util.isrc(e)){return;}
this.dirty=true;dbg('Sheet.dragTile '+this.dirty,1);move.cleanup();if(main.topObj!=null){main.topObj.style.zIndex=1;}
main.topObj=this.tile;main.topObj.style.zIndex=2;move.startSimple(e,o);return util.cancel(e);};Sheet.prototype.startGhost=function(e,o)
{if(util.isrc(e)){return;}
dbg('Sheet.startGhost');var ent=null;var elm=util.elm(e);while(elm)
{if(elm.className=='entlayout')
{ent=elm;break;}
else if(elm.className=='pad')
{break;}
elm=elm.parentNode;}
if(ent!=null)
{for(var i=0;i<o.childNodes.length;i++)
{if(o.childNodes[i].className=='entlayout')
{o.childNodes[i].className='entstill';}}
ent.className='entmove';var mouse=util.mouse(e);var ghost=at('ghost');ghost.parentNode.removeChild(ghost);o.appendChild(ghost);ghost.style.left=(ent.offsetLeft+1)+'px';ghost.style.width=(ent.offsetWidth-2)+'px';ghost.style.top=(ent.offsetTop+0)+'px';ghost.style.height=(ent.offsetHeight-2)+'px';ghost.className='ghost';var trash=at('trash');trash.parentNode.removeChild(trash);o.appendChild(trash);trash.style.left=ghost.style.left;trash.style.top=ghost.style.top;var pos=util.pos(ghost);var tp=at('tpic');tp.style.left=(mouse[0]-pos[0]-Math.floor(tp.offsetWidth/2))+'px';tp.style.top=(mouse[1]-pos[1]-Math.floor(tp.offsetHeight/2))+'px';move.cleanup();var m=move.xtra;pos=util.pos(o);m[16]=pos[0]-15;m[17]=m[16]+o.offsetWidth+30;m[18]=pos[1]-15;m[19]=m[18]+o.offsetHeight+30;m[30]=pos[0]
m[31]=pos[1]
pos=util.pos(this.pad);m[20]=pos[0]-15;m[21]=m[20]+this.pad.offsetWidth+30;m[22]=pos[1]-15;m[23]=m[22]+this.pad.offsetHeight+30;m[28]=pos[0]
m[29]=pos[1]
m[24]=o
m[25]=ent
m[26]=this.pad
m[27]=o
var bound=this;move.data[14]=trash;move.data[15]=function(xy){bound.moveGhost(xy);}
move.data[16]=function(){bound.stopGhost();}
move.startSimple(e,ghost);}
return util.cancel(e);};Sheet.prototype.moveGhost=function(xy)
{dbgx('Sheet.moveGhost');var m=move.xtra;if(xy[0]>m[16]&&xy[0]<m[17]&&xy[1]>m[18]&&xy[1]<m[19])
{var x=xy[0]-m[30];var y=xy[1]-m[31];var hit=null;for(var i=0;i<m[24].childNodes.length;i++)
{if(y<m[24].childNodes[i].offsetTop)
{hit=m[24].childNodes[i];break;}}
if(hit)
{if(hit==m[25]){return;}}
else
{if(m[24].lastChild==m[25]){return;}}
if(m[27]==null)
{at('ghost').className='ghost';at('trash').className='gone';}
else
{m[25].parentNode.removeChild(m[25]);}
if(hit){m[24].insertBefore(m[25],hit);}
else{m[24].appendChild(m[25]);}
m[27]=m[24];}
else if(xy[0]<m[20]||xy[0]>m[21]||xy[1]<m[22]||xy[1]>m[23])
{if(m[27]==null)
{return;}
at('ghost').className='gone';at('trash').className='trash';m[25].parentNode.removeChild(m[25]);m[27]=null;}
else
{var x=xy[0]-m[28];var y=xy[1]-m[29];var box=null;for(var i=0;i<m[26].childNodes.length;i++)
{box=m[26].childNodes[i];if(box.className=='box'&&box!=m[24]&&x>box.offsetLeft&&x<box.offsetLeft+box.offsetWidth&&y>box.offsetTop&&y<box.offsetTop+box.offsetHeight)
{if(box.pad==m[27])
{return;}
if(m[27]==null)
{at('ghost').className='ghost';at('trash').className='gone';}
else
{m[25].parentNode.removeChild(m[25]);}
box.pad.appendChild(m[25]);m[27]=box.pad;m[25].obj.box=box;return;}}}};Sheet.prototype.stopGhost=function()
{this.dirty=true;dbg('Sheet.stopGhost '+this.dirty,1);var m=move.xtra;at('ghost').className='gone';at('trash').className='gone';for(var i=0;i<m[24].childNodes.length;i++)
{if(m[24].childNodes[i].className=='entstill'||m[24].childNodes[i].className=='entmove')
{m[24].childNodes[i].className='entlayout';}}
if(m[27]!=m[24])
{m[25].className='ent';}
if(m[27]==null)
{m[25].obj.cleanup();}
m[24]=m[25]=m[26]=m[27]=null;};Sheet.prototype.DOicoOpen=function(e,o)
{if(util.isrc(e)){return;}
dbg('Sheet.DOicoOpen',1);this.DOicoOpenImpl(33,8);return util.cancel(e);};Sheet.prototype.DOicoOpenImpl=function(top,left)
{dbg('Sheet.DOicoOpenImpl');this.tile.style.visibility='hidden';this.sheet.style.top=top+'px';this.sheet.style.left=left+'px';this.sheet.style.visibility='visible';};Sheet.prototype.DOicoClose=function(e,o)
{if(util.isrc(e)){return;}
dbg('Sheet.DOicoClose');if(this.dirty)
{err.msg('Saving...');this.save(true);err.msg('Saved in the browser.');if(main.user_id>0)
{this.closing=true;var bound=this;this.xhr.save(bound);}}
if(!this.dirty||main.user_id<=0)
{this.sheet.style.visibility='hidden';this.tile.style.visibility='visible';}
return util.cancel(e);};Sheet.prototype.DOicoPrint=function(e,o)
{if(util.isrc(e)){return;}
dbg('Sheet.DOicoPrint');var w=window.open();var d=w.document;d.open("text/html","replace");var p='<?xml version="1.0" encoding="UTF-8"?>'
+'<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">'
+'<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">'
+'<head>'
+'<meta http-equiv="content-type" content="text/html; charset=UTF-8" />'
+'<link rel="icon" type="image/png" href="widgets/icon.png" />'
+'<title>Evil Goblin</title>'
+'<link rel="StyleSheet" href="print.css" type="text/css" />'
+'<script type="text/javascript">'
+'function doit() { document.getElementById("warn").className="gone"; document.getElementById("sheet").className="pad"; }'
+'</script>'
+'</head>'
+'<body>'
+'<div id="warn">'
+'<table align="center"><tr><td style="text-align: left; width: 620px; padding: 5px;" colspan="2">Before printing, you must change your page setup to have no margins, no header and no footer. '
+'<span class="slink" onclick="doit()">CONTINUE</span></td></tr><tr><td valign="top">'
+'<img src="screens/pagesetup1.png" /></td><td>'
+'<img src="screens/pagesetup2.png" /></td></tr></table>'
+'</div>'
+'<div id="sheet" class="gone" style="top: 0.3in; left: 0.3in; height: '+this.pad.style.height+'">'
+this.pad.innerHTML
+'</div>'
+'</body>'
+'</html>';d.write(p);d.close();return util.cancel(e);};Sheet.prototype.DOicoFont=function(e,o)
{if(util.isrc(e)){return;}
dbg('Sheet.DOicoFont');err.msg('Not yet implemented.');return util.cancel(e);};Sheet.prototype.DOicoBoxLayout=function(e,o)
{if(util.isrc(e)){return;}
dbg('Sheet.DOicoBoxLayout');if(o.className=='icoBoxEdit')
{this.mask.className='gone';for(var i=0;i<this.pad.childNodes.length;i++)
{var obj=this.pad.childNodes[i];if(obj.className=='boxlit')
{util.remover(obj.mousedownRmvr);obj.mousedownRmvr=null;obj.className='box';obj.icoGoLayout.className='icoGoLayout';obj.icoNewEntry.className='icoNewEntry';}}
o.className='icoBoxLayout';o.title='Switch To Box Layout Mode';}
else
{if(this.laid)
{this.toggleAbox(this.laid);}
for(var i=0;i<this.pad.childNodes.length;i++)
{if(this.pad.childNodes[i].className=='box')
{this.sheetToggleBox(this.pad.childNodes[i]);}}
o.className='icoBoxEdit';o.title='Switch To Edit Mode';}
return util.cancel(e);};Sheet.prototype.DOicoSave=function(e,o)
{if(util.isrc(e)){return;}
dbg('Sheet.DOicoSave @ '+this.dbid+','+this.aryid);err.msg('Saving...');this.save(true);err.msg('Saved in the browser.');if(main.user_id>0)
{var bound=this;this.xhr.save(bound);}
else
{util.setCookie('user_name','');}
return util.cancel(e);};Sheet.prototype.DOicoSaved=function(res)
{dbg('Sheet.DOicoSaved @ '+this.dbid+','+this.aryid+','+res);var id=parseInt(res);if(id>0&&''+id==res)
{if(this.dbid!=id)
{this.dbid=id;this.save(false);}
err.msg('Saved at the server.');if(this.closing)
{this.sheet.style.visibility='hidden';this.tile.style.visibility='visible';}}
else if(res=='-1')
{err.sess();err.msg('There is already a newer record in the database. Refresh your browser to load it.');}
else
{err.sess();err.msg('I couldn\'t save this sheet. Try again later.');}
this.closing=false;};Sheet.prototype.DOicoPageup=function(e,o)
{if(util.isrc(e)){return;}
dbg('Sheet.DOicoPageup');err.msg('Not yet implemented.');return util.cancel(e);};Sheet.prototype.DOicoPagedown=function(e,o)
{if(util.isrc(e)){return;}
dbg('Sheet.DOicoPagedown');this.dirty=true;this.pgdwnimpl();return util.cancel(e);};Sheet.prototype.pgdwnimpl=function()
{dbg('Sheet.pgdwnimpl');var h=parseFloat(this.sheet.style.height);this.sheet.style.height=(h+11)+'in';this.bdr_lft.style.height=(h+11.6)+'in';this.bdr_rht.style.height=(h+11.6)+'in';this.bdr_spc.className='sht_bdr_spc';this.bdr_spc.style.top=(h+0.6)+'in';this.pad.style.height=(h+11)+'in';this.pgs++;};Sheet.prototype.DOicoGoLayout=function(e,o)
{if(util.isrc(e)){return;}
dbg('Sheet.DOicoGoLayout');this.toggleAbox(o.parentNode.parentNode);return util.cancel(e);};Sheet.prototype.DOicoNewEntry=function(e,o)
{if(util.isrc(e)){return;}
dbg('Sheet.DOicoNewEntry');var ent=this.addEntry(o.parentNode.parentNode,'blank...',1,0);ent.obj.gotxt();return util.cancel(e);};Sheet.prototype.toggleAbox=function(box)
{dbg('Sheet.toggleAbox');if(this.laid&&box.icoGoLayout.className=='icoGoLayout')
{this.toggleAbox(this.laid);}
if(box.icoGoLayout.className=='icoGoEdit')
{for(var i=0;i<box.pad.childNodes.length;i++)
{if(box.pad.childNodes[i].className=='entlayout')
{box.pad.childNodes[i].className='ent';}}
util.remover(box.mousedownRmvr);box.mousedownRmvr=null;box.icoNewEntry.className='icoNewEntry';box.icoGoLayout.className='icoGoLayout';box.icoGoLayout.title='Switch To Layout Mode';this.laid=null;}
else
{for(var i=0;i<box.pad.childNodes.length;i++)
{if(box.pad.childNodes[i].className=='ent'&&box.pad.childNodes[i].obj.mov==1)
{box.pad.childNodes[i].className='entlayout';}}
box.mousedownRmvr=util.bind(this,'startGhost','mousedown',box.pad);box.icoNewEntry.className='gone';box.icoGoLayout.className='icoGoEdit';box.icoGoLayout.title='Switch To Edit Mode';this.laid=box;}};Sheet.prototype.sheetToggleBox=function(box)
{dbg('Sheet.sheetToggleBox');box.className='boxlit';box.icoGoLayout.className='gone';box.icoNewEntry.className='gone';box.mousedownRmvr=util.bind(this,'startMask','mousedown',box);};Sheet.prototype.save=function(ustamp)
{dbg('Sheet.save');this.dirty=false;var gotit=false;var label='Character';for(var i=0;i<this.pad.childNodes.length;i++)
{if(this.pad.childNodes[i].className.indexOf('box')==0)
{for(var j=0;j<this.pad.childNodes[i].pad.childNodes.length;j++)
{if(this.pad.childNodes[i].pad.childNodes[j].className.indexOf('ent')==0)
{var obj=this.pad.childNodes[i].pad.childNodes[j].obj;if(obj.style=='bigtitle')
{gotit=true;label=obj.spn.innerHTML;break;}}}
if(gotit){break;}}}
this.label.innerHTML=label;if(ustamp)
{this.stamp=util.now();}
var save=Array();save[0]=this.dbid;save[1]=[parseInt(this.tile.style.top),parseInt(this.tile.style.left),this.stamp,'widgets/avatar.png',60,68,this.label.innerHTML,this.pgs];for(var i=0;i<this.pad.childNodes.length;i++)
{var box=this.pad.childNodes[i];if(box.className.indexOf('box')==0)
{if(box.kind){continue;}
var ary=Array();save[save.length++]=ary;ary[0]=box.style.left;ary[1]=box.style.top;ary[2]=box.style.width;ary[3]=box.style.height;ary[4]=Array();for(var j=0;j<box.pad.childNodes.length;j++)
{var ent=box.pad.childNodes[j];if(ent.className.indexOf('ent')==0)
{if(ent.obj.att!=null)
{ary[4][ary[4].length++]=[2,ent.obj.att.tag,ent.obj.att.base];}
else if(ent.obj.mod!=null)
{ary[4][ary[4].length++]=[1,ent.obj.mod.txtval];}
else
{ary[4][ary[4].length++]=[0,ent.obj.spn.innerHTML,ent.obj.style];}}}}}
localStorage['s'+this.aryid]=JSON.stringify(save);localStorage.nsheets=main.nsheets;};