var xd,yd;var zd=false;var od=DIFF_EASY;var sd=ADVANCED;var $d,_d,ae,be,ce,de,ee,fe,ge,he,ie,bd,md,je;var ke=[];var le=[];var curr_menu=0;var me=false;var ne=[];var oe=[];function g(a){return document.getElementById(a);}
function lb(e){var x=0;var y=0;while(e){x+=e.offsetLeft;y+=e.offsetTop;e=e.offsetParent;}
return[x,y];}
function pe(a,b){if(a<b)return a;else return b;}
function qe(a,b){if(a>b)return a;else return b;}
function re(se){var r=se[0],g=se[1],b=se[2];var h,s,v;var te,ue,ve;te=pe(r,pe(g,b));ue=qe(r,qe(g,b));v=ue;ve=ue-te;if(ue!=0){s=ve/ue;}
else{s=0;h=-1;return[h,s,v];}
if(r==ue){h=(g-b)/ve;}
else if(g==ue){h=2+(b-r)/ve;}
else{h=4+(r-g)/ve;}
h*=60;if(h<0)h+=360;return[h,s,v];}
function we(h,s,v){var i;var f,p,q,t;if(s==0){return[v,v,v];}
h/=60;i=Math.floor(h);f=h-i;p=v*(1-s);q=v*(1-s*f);t=v*(1-s*(1-f));if(i==0)return[v,t,p];else if(i==1)return[q,v,p];else if(i==2)return[p,v,t];else if(i==3)return[p,q,v];else if(i==4)return[t,p,v];else return[v,p,q];}
function xe(pc,ye){var ze=re(pc);ze[1]*=ye;ze[2]*=ye;var se=we(ze[0],ze[1],ze[2]);return[Math.floor(se[0]),Math.floor(se[1]),Math.floor(se[2])];}
function cd($e,_e){var fb=g($e);fb.innerHTML=af(_e);}
function bf(r,c){var cf=g("grid");var df=cf.rows[r].cells[c];df.innerHTML=ef(r,c);}
function wc(r,c,n,_e){var cf=g("grid");var df=cf.rows[r].cells[c];df.innerHTML=_e?ff(r,c,n,_e):gf(r,c,n);}
function gf(r,c,n){if(n==0)n='';return hf(r,c,'<tr><td class="numtd"><div class="num">'+n+'</div></td></tr>');}
function ff(r,c,n,_e){if(n==0)n='';return hf(r,c,'<tr><td class="numtd"><div class="const">'+n+'</div></td></tr>',_e);}
function hf(r,c,jf,_e){var kf=_e?'"custom_change_focus('+r+','+c+'); return false;"':'"change_focus('+r+', '+c+'); return false;"';var lf=_e?"":'onmouseover="set_poss_highlight('+r+','+c+')" onmouseout="redraw_posses_cell('+r+','+c+')"';return'<table class="celltable" '+lf+' id="celltbl'+r+c+'" onclick='+kf+' oncontextmenu='+kf+'>'+jf+'</table>';}
function ef(r,c){var mf='';var nf="poss"+r+c;for(var i=1;i<10;i++){if(i%3==1)mf+="<tr>";mf+='<td class="celltd" id="'+nf+i+'">'+i+'</td>';if(i%3==0)mf+="</tr>";}
return hf(r,c,mf);}
function of(r,c,_e){if(_e)return ff(r,c,0,true);var kc=State.get_number(r,c);if(kc==0){return ef(r,c);}
else{if(State.is_constant(r,c))return ff(r,c,kc);else
return gf(r,c,kc);}
}
function pf(qf,_e){var mf='<tr>';var rf='';if(qf==0)rf+="height: 52px; ";if(qf==3||qf==6){rf+="height: 52px; border-top-width: 3px; ";}
else if(qf==2||qf==5||qf==8){rf+="height: 52px;"}
var nf="cell"+qf;for(var i=0;i<DIM;i++){var sf=rf;if(i==3||i==6){sf+="border-left-width: 3px; ";}
mf+='<td class="gridtd" id="'+nf+i+'" style="'+sf+'">'+of(qf,i,_e)+'</td>\n';}
mf+='</tr>\n';return mf;}
function af(_e){var mf='<table class="grid" id="grid" oncontextmenu="return false;">';for(var i=0;i<DIM;i++)mf+=pf(i,_e);mf+='</table>';return mf;}
function tf(){if(sd==SIMPLE){g("simple_mode_radio").checked=true;}
else{g("advanced_mode_radio").checked=true;}
}
function uf(i){return function(e){vf(i)}
;}
function wf(i){return function(e){this.style.fontWeight='';this.style.background=(State.get_coloring()==(i+1)?oc(C_coloring):"");}
;}
function xf(){var n=State.get_coloring();var yf=State.tally_number_counts();var t=g("highlight-indicator");for(var i=0;i<DIM;i++){var uc=t.rows[0].cells[i];if(yf[i+1]==DIM){uc.style.background="#aaaaaa";uc.style.fontWeight="";uc.onclick=null;uc.onmouseover=null;uc.onmouseout=null;}
else{uc.style.background="";uc.style.fontWeight="";if($b){uc.onmouseover=function(e){this.style.fontWeight='bold';this.style.background="yellow";}
;uc.onmouseout=wf(i);}
uc.onclick=uf(i+1);}
}
if(n>0&&yf[n]==DIM){State.set_coloring(0);}
else{if(n>0){var zf=document.getElementById("h"+n);zf.style.background=oc(C_coloring);zf.style.fontWeight="bold";}
}
}
function $f(_f){var ag=Math.floor(_f/3600000);_f-=ag*3600000;var bg=Math.floor(_f/60000);if(bg<10&&ag>0)bg="0"+bg;_f-=bg*60000;var cg=Math.floor(_f/1000);if(cg<10)cg="0"+cg;var dg=bg+":"+cg;if(ag>0)dg=ag+":"+dg;return dg;}
function eg(){if(zd)return;var fg=g("clock");fg.innerHTML=$f((new Date()).getTime()-xd);setTimeout(eg,500);}
function yc(gg,b,c){b.style.background=c[gg%2];if(gg>0)setTimeout(function(){yc(gg-1,b,c);}
,500);}
function nd(hg,ig){var jg=g("messagebox");jg.innerHTML=hg;if(!ig){var t=g("message_title");yc(3,t,["#ddddff","#88cc44"]);}
}
function kg(){nd("&nbsp;",true);}
function lg(){mg=od.length;s=od.charAt(0).toUpperCase()+od.substring(1,mg);ng("Puzzle difficulty: "+s+" &nbsp; Solver mode: "+(sd==SIMPLE?"Traditional":"Sumo"));}
function ng(text){var og=g("time");og.innerHTML=text;}
function pause(pg){var jg=g("pausebox");var qg="";if(zd){if(State.has_won())return;jg.innerHTML=PAUSE_BUTTON;zd=false;xd+=((new Date()).getTime()-yd);yd=0;setTimeout(eg,500);if(!pg)$d.hide();}
else{yd=(new Date()).getTime();zd=true;jg.innerHTML=PLAY_BUTTON;qg="hidden";if(!pg){$d.set_position_obj(CENTERED,g("grid"),MIDDLE,MIDDLE);$d.manifest();}
}
if(!pg)rg(qg);}
function toggle_clock(){var c=g("clock");var n;if(c.style.visibility=="hidden")n="";else
n="hidden";c.style.visibility=n;sg("clock",n);}
function sg(n,tg){ug[n]=tg;if(vg[n])vg[n](tg);wg();}
function xg(){var yg=qd("prefs");if(!yg)yg="autofill=true::no_incorrect=false::email_bookmark=true::logo=true";var zg=unescape(location.search.slice(1)).split("&");var $g=yg.split("::");if(!_g)$g=$g.concat(zg);ug["logo"]=true;for(var i in $g){var ah=$g[i].split("=");var bh=ah[0];var ch=ah[1];if(ch=="true")ch=true;else if(ch=="false")ch=false;ug[bh]=ch;if(vg[bh])vg[bh](ch);}
}
function dh(){delete ug["difficulty"];delete ug["welcome"];delete ug["bookmark"];delete ug[""];}
function wg(){dh();var eh=[];for(var i in ug){eh.push(i+"="+ug[i]);}
var fh=eh.join("::");gh("prefs",fh,100000);}
function hh(){var eh=[];for(var i in ih){eh.push(i+"="+ih[i]);}
var fh=eh.join("::");gh("stats",fh,100000);}
function jh(){if(confirm("Are you sure you want to clear your puzzle completion statistics?")){kh("stats");ih={}
;nd("Stats cleared!");}
}
function lh(){var yg=qd("stats");if(yg==null)return;var $g=yg.split("::");for(var i in $g){var ah=$g[i].split("=");var bh=ah[0];var ch=ah[1];ih[bh]=ch;}
}
function mh(nh,db){var bh=od+nh;ih[bh]=db(isNaN(ih[bh])?0:parseInt(ih[bh]));hh();return ih[bh];}
function oh(nh){return ih[od+nh];}
function ph(qh){var mf=new Object();for(var s in qh){var rh=0;for(var d in DIFFS){var bh=DIFFS[d]+qh[s];rh+=isNaN(ih[bh])?0:ih[bh]*1;}
mf["all"+qh[s]]=rh;}
return mf;}
function sh(){var th=["autofill","no_incorrect"];for(var a in th){var b=th[a];var jg=g(b);jg.checked=ug[b];jg.blur();}
}
var uh=["You can save your progress and continue a puzzle later by doing 'Tools&rarr;Save/share this puzzle'.","Tired of typing? Use 'Tools&rarr;Print to PDF' to generate a PDF file of the current puzzle that you can print out and take with you.","Screwed up? No need to start over. 'Smart Hints&rarr;Undo mistakes' will restore your board to the last time it was correct.","Save a shift key. To add candidates, you can use =n as well as +n.","Want to share a puzzle with a friend? Save it ('Tools&rarr;Save/share this puzzle') and send the number (or forward the email) along.","If you're really lazy, turn on 'Preferences&rarr;Disallow incorrect moves'.","Use colors (see the Controls menu) to aid you in solving tougher puzzles.","Use 'Highlight Candidates' to save you from the drudgery of figuring out where all the 6s could go.","Click on the clock icon above to hide the timer.","Feeling dumb after getting an obvious hint? Next time, click on 'Do I need a Smart Hint?' to figure out whether you're just missing something obvious.","Sudoku Slam will remember your preferences, solver mode, and preferred puzzle difficulty when you visit next if you use the same computer.","Found a bug or have a feature suggestion? Send us some feedback.","Double-click on a candidate to set the cell to that number.","Getting frustrated with dumbed-down hints in Traditional mode? Swich to Sumo mode for a better experience.","You can also pause and unpause the game with the 'p' key.","Daily newspaper puzzle got you down? Use our custom puzzle interface ('New Puzzles&rarr;Enter your own puzzle') and solve it with the Slam!","Right-click on a square to select it without toggling a candidate."];function vh(){var wh;if(xh){wh="Use Highlight Candidates to find obvious boxes to fill in. Click on the Controls menu to learn how to interact. And explore the rest of the menu to discover more features.";}
else{wh=uh[parseInt(Math.random()*uh.length)];}
nd("Tip: "+wh);}
var menu_tooltips=["<i>Restart this puzzle</i> restarts the game with only the fixed numbers in place, even if you've loaded a saved puzzle.<br><br>Click on a difficulty level to load a new puzzle of that difficulty.<br><br>All puzzles are created in-house and rated using human logic. <i>Piledriver</i> puzzles have some steps that are too hard for our Smart Hints to solve.<br><br>You can also solve an external puzzle (say, from your newspaper) with <i>Enter your own puzzle</i>.<br><br><i>Go offline...</i> enables you to download puzzles to your computer so that you can play them without internet access (say, on your morning commute). You must keep the browser window open for this feature to work!","<i>Change solver mode</i>: Traditional mode is in the style of traditional online Sudoku sites: you start with empty squares and add and delete candidates. Sumo mode works better for harder boards: each square starts with all possible candidates, and you remove them till there is only one left. <i>Note: switching between modes mid-puzzle may lose some of your candidate annotations.</i><br><br><i>Auto-fill in obvious numbers</i> saves you from some drudgery. In Traditional mode, it automatically fills in a square if it\'s the only empty one in a row, column, or box. In Sumo mode, it fills in a square if there\'s only one candidate remaining for it.<br><br><i>Disallow incorrect moves</i>, if checked, prevents you from entering an incorrect number, or eliminating the correct candidate, from any square. <i>Note: setting this preference strongly decreases the challenge of many hard puzzles.</i>","<i>Print to PDF</i> creates a PDF file of the current board so that you can print it out and continue your progress offline.<br><br>Use the <i>Save/share this puzzle</i> feature to save your progress on this puzzle for later or send it to a friend.<br><br><i>Session/no cookies bookmark</i> allows you to keep your preferences even if you have a browser that does not store cookies.","The Sudoku Slam puzzle grid is controlled via the keyboard and the mouse. Use these keys to solve puzzles faster. Also, use colors to solve trickier puzzles."];function yh(i){var fb=g("inner-tab-box");fb.style.background="url(images/"+ic[i]+") no-repeat center center;";}
function zh(){yh(curr_menu);}
function $h(i){var _h=hc[curr_menu];g(_h+"-tab").style.color="";g(_h+"-panel").style.display="none";curr_menu=i;var n=hc[curr_menu];g(n+"-tab").style.color="teal";g(n+"-panel").style.display="block";zh();}
function ai(f,i,j){return function(){f(i,j);}
;}
function bi(){for(var i in hc){var o=g(hc[i]+"-tab");o.onmouseover=ai(yh,i);o.onmouseout=zh;o.onclick=ai($h,i);if($b){o.attachEvent("onmouseout",ai(function(fb,ci){fb.style.color=(ci==curr_menu?"teal":"");}
,o,i));}
}
$h(0);}
function toggle_pref(n){var b=ug[n];var di=g(n);di.checked=b?"":"checked";di.blur();sg(n,!b);}
function rg(qg){for(j=0;j<9;j++){for(i=0;i<9;i++){var fb=g("cell"+i+j);fb.style.visibility=qg;}
}
}
function ei(e){if(!e)var e=window.event;if(e.stopPropagation)e.stopPropagation();e.cancelBubble=true;}
function fi(){g("hide-logo").onclick=function(){var gi=!ug["logo"];sg("logo",gi);}
;$d=new Box();$d.width=400;$d.set_clickon(function(t){pause();}
);$d.grab_keys=true;$d.content=g("paused-box");ae=new Box();ae.width=400;ae.dim_screen=true;ae.grab_keys=true;ae.set_clickaway(function(t){t.hide();}
);ae.content=g("feedback-box");g("feedback-send").onclick=function(){ae.hide();hi();}
;g("feedback-close").onclick=function(){ae.hide();}
;g("feedback-go").onclick=ii;bd=new Box();bd.width=230;bd.x=10;g("enter-puzzle-send").onclick=vd;g("enter-puzzle-cancel").onclick=function(){ld();}
g("enter-puzzle-go").onclick=_c;ji=new Box();ji.width=400;ji.dim_screen=true;ji.grab_keys=true;ji.set_clickaway(function(t){t.hide();}
);ji.content=g("offline-box");g("offline-close").onclick=function(){ji.hide();}
;g("offline-send").onclick=ki;g("offline-go").onclick=li;md=new Box();md.width=230;md.content="Analyzing puzzle difficulty....";ee=new Box();ee.width=300;ee.x=10;ee.y=10;_d=new Box();_d.width=400;_d.dim_screen=true;_d.grab_keys=true;_d.set_clickaway(function(t){t.hide();}
);_d.content=g("friend-box");g("friend-send").onclick=mi;g("friend-close").onclick=function(){_d.hide();}
;g("friend-go").onclick=ni;be=new Box();be.width=400;be.dim_screen=true;be.grab_keys=true;be.set_clickaway(function(t){t.hide();}
);be.content=g("link-box");g("link-close").onclick=function(){be.hide();}
;g("link-go").onclick=oi;fe=new Box();fe.width=400;fe.dim_screen=true;fe.grab_keys=true;fe.set_clickaway(function(t){t.hide();}
);fe.content=g("win-box");g("win-close").onclick=function(){fe.hide();}
;g("win-display-stats").onclick=function(){sg("win-stats",true);pi;}
ge=new Box();ge.x=10;ge.y=10;ge.set_clickaway(function(t){t.hide();}
);ge.set_clickon(function(t){t.hide();}
);ge.content=g("need-hint-box");g("need-hint-close").onclick=function(){ge.hide();}
;g("need-hint-go").onclick=function(e){if(!zd)qi(e,true);}
g("get-hint-go").onclick=function(e){if(!zd)qi(e,false);}
je=new Box();je.width=400;je.set_clickaway(function(t){t.hide();}
);je.grab_keys=true;je.dim_screen=true;je.content=g("cookies-box");g("cookies-go").onclick=ri;g("cookies-close").onclick=function(e){je.hide();}
;g("clear-stats-go").onclick=jh;he=new Box();he.width=400;he.set_clickaway(function(t){t.hide();}
);he.grab_keys=true;he.dim_screen=true;he.content=g("bookmark-box");g("bookmark-go").onclick=si;g("bookmark-send").onclick=ti;g("bookmark-close").onclick=function(e){he.hide();}
;ie=new Box();ie.width=400;ie.set_clickaway(function(t){t.hide();}
);ie.set_clickon(function(t){t.hide();}
);ui=new Box();ui.width=400;ui.set_clickaway(function(t){t.hide();}
);ui.grab_keys=true;ui.dim_screen=true;ui.content=g("load-bookmark-box");g("load-bookmark-go").onclick=vi;g("load-bookmark-send").onclick=wi;g("load-bookmark-close").onclick=function(e){ui.hide();}
;g("print-go").onclick=function(e){xi(yi('is_visibly_possible'));}
;g("tour-go").onclick=function(e){if(zd)alert("Please unpause the game first.");else zi();}
g("restart-go").onclick=$i;g("hints-go").onclick=function(e){_i();}
;g("stats-go").onclick=function(e){aj();}
;g("undo-go").onclick=function(e){if(!zd)bj();}
g("undo-move-go").onclick=function(e){if(!zd)cj();}
ce=new Box();ce.width=400;ce.grab_keys=true;ce.dim_screen=true;ce.has_shadow=true;ce.content=g("welcome-box");g("welcome-close").onclick=function(e){welcome_close(-1);}
;de=new Box();de.width=400;de.grab_keys=true;de.dim_screen=true;de.content=g("about-box");de.set_clickaway(function(t){t.hide();}
);g("about-go").onclick=function(e){ei(e);de.set_position_obj(CENTERED,g("grid"),MIDDLE,MIDDLE);de.manifest();}
;g("about-close").onclick=function(t){de.hide();}
}
function _i(dj){if(dj!=null)ej='hints.html#'+dj;else ej='hints.html';window.open(ej,'_blank');}
function aj(){ej='report.html';window.open(ej,'_blank');}
var fj=null;function gj(f){fj=f;g("tutorial").checked=true;ce.set_position_obj(CENTERED,null,MIDDLE,MIDDLE);ce.manifest();}
function welcome_close(a){ce.hide();gh("welcome_done",true,36500);xh=g("tutorial").checked;switch(a){case-1:xh=false;fj();break;case SIMPLE:sd=a;fj();gh(rd,sd,300);break;case ADVANCED:sd=a;fj();gh(rd,sd,300);break;}
}
function hj(ij,jj,kj,n,lj,mj,nj){var kd;oj++;kg();if(nj<3)kd="easy";else if(nj<4)kd="a little tricky";else if(nj<8)kd="hard";else
kd="really hard";g("need-hint-diff").innerHTML=kd;if(HINT_A_NAMES[nj]!=null)g("need-hint-kind").innerHTML=" <a href='hints.html#"+HINT_A_NAMES[nj]+"' target='hintspop'>(more info)</a>";else
g("need-hint-kind").innerHTML="";ge.manifest(true);}
function pj(status){kg();if(status==REQUEST_ERROR_CONTACTING_SERVER){ge.hide();alert("No hints are available at this time.");}
else{g("need-hint-diff").innerHTML="fiendish";g("need-hint-kind").innerHTML=" (Too hard for Smart Hints!)";ge.manifest(true);}
}
function hi(){nd("Thanks for the feedback!");var e=g("feedback-from");var b=g("feedback-value");qj("feedback",[["email",e.value],["feedback",b.value],["host",document.location]],null);b.value="";sg("email",e.value);}
function mi(){var rj=g("friend-from").value;if(rj.indexOf('@')==-1){alert("Please enter your email address.");return;}
_d.hide();nd("Your friends will love you.");var sj=g("friend-to");var hg=g("friend-value");qj("friend",[["from",rj],["to",sj.value],["message",hg.value]],null);sj.value="";sg("email",rj);}
function ii(e){ei(e);if(ug["email"])g("feedback-from").value=ug["email"];ae.set_position_obj(CENTERED,g("grid"),MIDDLE,MIDDLE);ae.manifest();}
function ni(e){ei(e);if(ug["email"])g("friend-from").value=ug["email"];_d.set_position_obj(CENTERED,g("grid"),MIDDLE,MIDDLE);_d.manifest();}
function oi(e){ei(e);be.set_position_obj(CENTERED,g("grid"),MIDDLE,MIDDLE);be.manifest();}
function tooltip(event,fb,text){ee.content=text;var tj=fb.onmouseout;fb.onmouseout=function(e){ee.hide();this.onmouseout=tj;}
;ee.set_position_point(AUTO,event.clientX,event.clientY);ee.manifest();return false;}
function pi(){g("win-stats-table").style.visibility="";g("win-display-stats").innerHTML="[ Hide stats ]";g("win-display-stats").onclick=function(){sg("win-stats",false);uj;}
}
function uj(){g("win-stats-table").style.visibility="hidden";g("win-display-stats").innerHTML="[ Show stats ]";g("win-display-stats").onclick=function(){sg("win-stats",true);pi;}
}
function vj(){var wj=(new Date()).getTime()-xd;var xj=mh("_f",function(v){return v+1;}
);var yj=mh("_b",function(v){if(v==0)return wj;return(v<wj?v:wj);}
);var zj=od;if(zj!=DIFF_MEDIUM&&zj!=DIFF_HARD&&zj!=DIFF_BODYSLAM&&zj!=DIFF_PILEDRIVER)zj=DIFF_EASY;var $j=mh("_a",function(v){if(v==0)v=wj;return(v*(xj-1)+wj)/xj;}
);qj("finished_puzzle",[["difficulty",od],["time",wj],["localdate",(new Date()).toString()],["tag",State.get_tag()],["uid",_j()],["mode",sd],["num_hints",ak],["num_undos",bk],["num_need_hints",oj],["init_puzzle",State.grid_to_string(State.constants_grid,true)]],null);g("win-time").innerHTML=$f(wj);g("win-hints").innerHTML=ak;g("win-undos").innerHTML=bk;g("win-best-title").innerHTML="Best "+zj+" time:";g("win-best").innerHTML=$f(yj);g("win-avg-title").innerHTML="Average "+zj+" time:";g("win-avg").innerHTML=$f($j);var ck=zj.substr(0,1).toUpperCase()+zj.substr(1,zj.length);g("win-started-title").innerHTML=ck+" puzzles started:";g("win-started").innerHTML=oh('_s');g("win-finished-title").innerHTML=ck+" puzzles finished:";g("win-finished").innerHTML=xj;g("win-another-puzzle").value="Play another "+zj+" puzzle";g("win-another-puzzle").onclick=function(){fe.hide();set_difficulty(zj);}
;pause(true);fe.set_position_obj(CENTERED,g("grid"),MIDDLE,MIDDLE);fe.manifest();}
function ri(e){ei(e);dh();var ej="?welcome=false&difficulty="+od;for(var i in ug){if(i!="")ej+="&"+escape(i)+"="+escape(ug[i]);}
g("cookies-url").innerHTML="<a href='"+ej+"'>Custom Sudoku Slam link</a>";je.set_position_obj(CENTERED,g("grid"),MIDDLE,MIDDLE);je.manifest();}
function li(e){ei(e);if(me){alert("You are already offline.");return;}
g("offline-ind").style.color="black";ji.set_position_obj(CENTERED,g("grid"),MIDDLE,MIDDLE);ji.manifest();}
function ki(e){ei(e);var dk=[];var ek=0;for(var d in DIFFS){var fk=parseInt(g("offline-"+DIFFS[d]).value);if(isNaN(fk))fk=0;ek+=fk;dk.push([DIFFS[d],fk]);}
if(ek==0){alert("Please enter a number of puzzles to download.");return;}
g("offline-send").value="Please wait...";qj("go_offline",dk,gk);}
function offline_new_puzzle(kd,hk){if(ik>0&&!State.has_won()&&!confirm("Are you sure you want to start a new puzzle?"))return;var c=ne[kd];c+=hk;if(c<0||c>oe[kd].length-1)return;ne[kd]=c;od=kd;jk(oe[kd][c][0],oe[kd][c][1],"OFFLINE");kk();}
function kk(){for(var lk in DIFFS){var d=DIFFS[lk];var mg=oe[d].length;var mk=(mg==0?0:ne[d]+1);g(d+"-off-num").innerHTML=" ("+mk+"/"+mg+") ";}
}
function gk(nk){ji.hide();ne=[];for(var lk in DIFFS){var d=DIFFS[lk];oe[d]=[];ne[d]=0;var ok=nk.getElementsByTagName(d);ne[d]=0;g(d+"-off-display").style.display="inline";g(d+"-go").onclick=new Function("offline_new_puzzle('"+d+"', 0)");g(d+"-off-num").onclick=new Function("offline_new_puzzle('"+d+"', 0)");if(d==od){var jd=State.grid_to_string(State.solution_grid,true),pk=State.grid_to_string(State.constants_grid,true);oe[d].push([pk,jd]);}
if(ok.length==0)continue;var qk=ok[0].getElementsByTagName('puzzle');for(var i=0;i<qk.length;i++){oe[d].push([rk(qk[i],'grid'),rk(qk[i],'solution')]);}
}
me=true;kk();g("offline-ind").style.color="gray";nd("Switch difficulties by clicking on the difficulty level. Switch between puzzles of the same difficulty by clicking on the appropriate - or +.");}
function si(e){ei(e);var sk=g("bookmark-send");sk.value="Save your progress";sk.disabled=false;if(ug["email"])g("email-bookmark-to").value=ug["email"];he.set_position_obj(CENTERED,g("grid"),MIDDLE,MIDDLE);he.manifest();}
function ti(e){ei(e);var tk=g("email-bookmark").checked;sg("email_bookmark",tk);var rj=g("email-bookmark-to").value;if(tk){if(rj.indexOf('@')==-1){alert("You have requested an email of this puzzle progress number. Please enter your email address.");return;}
sg("email",rj);}
else{rj="";}
var sk=g("bookmark-send");sk.value="Please wait...";sk.disabled=true;bookmark(rj,uk);}
function uk(nk){var sk=g("bookmark-send");sk.value="Save your progress";sk.disabled=false;he.hide();var vk=0;try{vk=nk.getElementsByTagName("bookmark_id")[0].firstChild.nodeValue;}
catch(e){alert("Sorry, there was an error saving your progress. Please try again later.");return;}
ie.content="<div style='text-align: center;'>Your puzzle progress number is<br><span style='font-size: 32pt;'>"+vk+"</span></div>";ie.set_position_obj(CENTERED,g("grid"),MIDDLE,MIDDLE);ie.manifest();if(ke.length>=NUM_RECENT_BOOKMARKS)ke.pop();ke.unshift(vk);var fh=ke.join("::");gh("recent_bookmarks",fh,100000);le=[];}
function vi(e){ei(e);g("load-bookmark-number").value="";if(ke.length==0){g("recent-bookmarks-enclosure").style.display="none";}
else if(le.length==0){g("recent-bookmarks-enclosure").style.display="";g("recent-bookmarks").innerHTML="<b>Loading recently saved puzzles...</b>";var fh=ke.join(",");qj("load_bookmarks",[["bookmark_ids",fh]],wk);}
ui.set_position_obj(CENTERED,g("grid"),MIDDLE,MIDDLE);ui.manifest();}
function load_recent_bookmark(i){ui.hide();xk(le[i]);}
function wk(nk){var dg="<center><table class='recent-bookmarks'><tr><td><b>Number</b></td><td><b>Time</b></td><td><b>Difficulty</b></td><td><b>Date</b></td></tr></center>";try{var yk=nk.getElementsByTagName("bookmark");for(var i=0;i<yk.length;i++){var zk=yk[i];var vk=zk.getAttribute("id");var $k=parseInt(rk(zk,"duration"));var difficulty=rk(zk,"diff");var date=parseInt(rk(zk,"date"));var _k=new Date(date);var al=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"];var bl=_k.toLocaleTimeString()+", "+_k.getDate()+" "+al[_k.getMonth()]+" "+_k.getFullYear();var tj="onmouseover=\"this.style.color='blue'\" onmouseout=\"this.style.color='black'\" onclick=\"load_recent_bookmark("+i+")\"";dg+="<tr style='cursor: pointer' "+tj+"><td>"+vk+"</td><td>"+$f($k)+"</td><td><i>"+difficulty+"</i></td><td>"+bl+"</td></tr>";le.push(zk);}
dg+="</table>";g("recent-bookmarks").innerHTML=dg;ui.manifest(true);}
catch(e){le=[];g("recent-bookmarks").innerHTML="<b>Error loading recent puzzles.</b>";return;}
}
function wi(e){ei(e);var vk=g("load-bookmark-number").value;var sk=g("load-bookmark-send");sk.value="Please wait...";sk.disabled=true;var db=function(nk){sk.value="Load saved progress";sk.disabled=false;ui.hide();xk(nk);}
qj("load_bookmarks",[["bookmark_ids",vk]],db);}
function cl(gi){var l=g("logo");var f=g("hide-logo");if(gi){l.src="images/text-logo-white.png";f.innerHTML="Hide sumo";}
else{l.src="images/text-logo-small-white.png";f.innerHTML="Show sumo";}
}
function dl(el){var fl=new Array();var gl=document.getElementsByTagName("*");for(var i=0;i<gl.length;i++){if(gl[i].className==el){fl.push(gl[i]);}
}
return fl;}
function hl(fb,il){return function(e){fb.style.color=il;}
;}
var ug=[];var vg=[];vg["autofill"]=function(a){jl();}
;vg["email_bookmark"]=function(a){g("email-bookmark").checked=a;}
;vg["clock"]=function(a){g("clock").style.visibility=a;}
;vg["logo"]=function(a){cl(a);}
;vg["win-stats"]=function(a){if(a)pi();else uj();}
;var ih=[];function kl(){if($b){var ll=dl("action");for(var a in ll){ll[a].attachEvent("onmouseover",hl(ll[a],"blue"));ll[a].attachEvent("onmouseout",hl(ll[a],"black"));}
}
bi();fi();}
function ml(){cd("puzzle");tf();xg();lh();var yg=qd("recent_bookmarks");if(yg)ke=yg.split("::");sh();xf();xd=(new Date()).getTime();zd=false;eg();}
