/* Copyright 2007-2009 Richard Jones
This work is licensed under the Creative Commons Attribution-Noncommercial-No Derivative Works License. To view a copy of this license, visit http://creativecommons.org/licenses/by-nc-nd/2.5/au/
*/
Gettext=function(_1){
this.domain="messages";
this.locale_data=undefined;
var _2=["domain","locale_data"];
if(this.isValidObject(_1)){
for(var i in _1){
for(var j=0;j<_2.length;j++){
if(i==_2[j]){
if(this.isValidObject(_1[i])){
this[i]=_1[i];
}
}
}
}
}
this.try_load_lang();
return this;
};
Gettext.context_glue="\x04";
Gettext._locale_data={};
Gettext.prototype.try_load_lang=function(){
if(typeof (this.locale_data)!="undefined"){
var _5=this.locale_data;
this.locale_data=undefined;
this.parse_locale_data(_5);
if(typeof (Gettext._locale_data[this.domain])=="undefined"){
throw new Error("Error: Gettext 'locale_data' does not contain the domain '"+this.domain+"'");
}
}
var _6=this.get_lang_refs();
if(typeof (_6)=="object"&&_6.length>0){
for(var i=0;i<_6.length;i++){
var _8=_6[i];
if(_8.type=="application/json"){
if(!this.try_load_lang_json(_8.href)){
throw new Error("Error: Gettext 'try_load_lang_json' failed. Unable to exec xmlhttprequest for link ["+_8.href+"]");
}
}else{
if(_8.type=="application/x-po"){
if(!this.try_load_lang_po(_8.href)){
throw new Error("Error: Gettext 'try_load_lang_po' failed. Unable to exec xmlhttprequest for link ["+_8.href+"]");
}
}else{
throw new Error("TODO: link type ["+_8.type+"] found, and support is planned, but not implemented at this time.");
}
}
}
}
};
Gettext.prototype.parse_locale_data=function(_9){
if(typeof (Gettext._locale_data)=="undefined"){
Gettext._locale_data={};
}
for(var _a in _9){
if((!_9.hasOwnProperty(_a))||(!this.isValidObject(_9[_a]))){
continue;
}
var _b=false;
for(var _c in _9[_a]){
_b=true;
break;
}
if(!_b){
continue;
}
var _d=_9[_a];
if(_a==""){
_a="messages";
}
if(!this.isValidObject(Gettext._locale_data[_a])){
Gettext._locale_data[_a]={};
}
if(!this.isValidObject(Gettext._locale_data[_a].head)){
Gettext._locale_data[_a].head={};
}
if(!this.isValidObject(Gettext._locale_data[_a].msgs)){
Gettext._locale_data[_a].msgs={};
}
for(var _e in _d){
if(_e==""){
var _f=_d[_e];
for(var _10 in _f){
var h=_10.toLowerCase();
Gettext._locale_data[_a].head[h]=_f[_10];
}
}else{
Gettext._locale_data[_a].msgs[_e]=_d[_e];
}
}
}
for(var _a in Gettext._locale_data){
if(this.isValidObject(Gettext._locale_data[_a].head["plural-forms"])&&typeof (Gettext._locale_data[_a].head.plural_func)=="undefined"){
var _12=Gettext._locale_data[_a].head["plural-forms"];
var _13=new RegExp("^(\\s*nplurals\\s*=\\s*[0-9]+\\s*;\\s*plural\\s*=\\s*(?:\\s|[-\\?\\|&=!<>+*/%:;a-zA-Z0-9_()])+)","m");
if(_13.test(_12)){
var pf=Gettext._locale_data[_a].head["plural-forms"];
if(!/;\s*$/.test(pf)){
pf=pf.concat(";");
}
var _15="var plural; var nplurals; "+pf+" return { \"nplural\" : nplurals, \"plural\" : (plural === true ? 1 : plural ? plural : 0) };";
Gettext._locale_data[_a].head.plural_func=new Function("n",_15);
}else{
throw new Error("Syntax error in language file. Plural-Forms header is invalid ["+_12+"]");
}
}else{
if(typeof (Gettext._locale_data[_a].head.plural_func)=="undefined"){
Gettext._locale_data[_a].head.plural_func=function(n){
var p=(n!=1)?1:0;
return {"nplural":2,"plural":p};
};
}
}
}
return;
};
Gettext.prototype.try_load_lang_po=function(uri){
var _19=this.sjax(uri);
if(!_19){
return;
}
var _1a=this.uri_basename(uri);
var _1b=this.parse_po(_19);
var rv={};
if(_1b){
if(!_1b[""]){
_1b[""]={};
}
if(!_1b[""]["domain"]){
_1b[""]["domain"]=_1a;
}
_1a=_1b[""]["domain"];
rv[_1a]=_1b;
this.parse_locale_data(rv);
}
return 1;
};
Gettext.prototype.uri_basename=function(uri){
var rv;
if(rv=uri.match(/^(.*\/)?(.*)/)){
var _1f;
if(_1f=rv[2].match(/^(.*)\..+$/)){
return _1f[1];
}else{
return rv[2];
}
}else{
return "";
}
};
Gettext.prototype.parse_po=function(_20){
var rv={};
var _22={};
var _23="";
var _24=[];
var _25=_20.split("\n");
for(var i=0;i<_25.length;i++){
_25[i]=_25[i].replace(/(\n|\r)+$/,"");
var _27;
if(/^$/.test(_25[i])){
if(typeof (_22["msgid"])!="undefined"){
var _28=(typeof (_22["msgctxt"])!="undefined"&&_22["msgctxt"].length)?_22["msgctxt"]+Gettext.context_glue+_22["msgid"]:_22["msgid"];
var _29=(typeof (_22["msgid_plural"])!="undefined"&&_22["msgid_plural"].length)?_22["msgid_plural"]:null;
var _2a=[];
for(var str in _22){
var _27;
if(_27=str.match(/^msgstr_(\d+)/)){
_2a[parseInt(_27[1])]=_22[str];
}
}
_2a.unshift(_29);
if(_2a.length>1){
rv[_28]=_2a;
}
_22={};
_23="";
}
}else{
if(/^#/.test(_25[i])){
continue;
}else{
if(_27=_25[i].match(/^msgctxt\s+(.*)/)){
_23="msgctxt";
_22[_23]=this.parse_po_dequote(_27[1]);
}else{
if(_27=_25[i].match(/^msgid\s+(.*)/)){
_23="msgid";
_22[_23]=this.parse_po_dequote(_27[1]);
}else{
if(_27=_25[i].match(/^msgid_plural\s+(.*)/)){
_23="msgid_plural";
_22[_23]=this.parse_po_dequote(_27[1]);
}else{
if(_27=_25[i].match(/^msgstr\s+(.*)/)){
_23="msgstr_0";
_22[_23]=this.parse_po_dequote(_27[1]);
}else{
if(_27=_25[i].match(/^msgstr\[0\]\s+(.*)/)){
_23="msgstr_0";
_22[_23]=this.parse_po_dequote(_27[1]);
}else{
if(_27=_25[i].match(/^msgstr\[(\d+)\]\s+(.*)/)){
_23="msgstr_"+_27[1];
_22[_23]=this.parse_po_dequote(_27[2]);
}else{
if(/^"/.test(_25[i])){
_22[_23]+=this.parse_po_dequote(_25[i]);
}else{
_24.push("Strange line ["+i+"] : "+_25[i]);
}
}
}
}
}
}
}
}
}
}
if(typeof (_22["msgid"])!="undefined"){
var _28=(typeof (_22["msgctxt"])!="undefined"&&_22["msgctxt"].length)?_22["msgctxt"]+Gettext.context_glue+_22["msgid"]:_22["msgid"];
var _29=(typeof (_22["msgid_plural"])!="undefined"&&_22["msgid_plural"].length)?_22["msgid_plural"]:null;
var _2a=[];
for(var str in _22){
var _27;
if(_27=str.match(/^msgstr_(\d+)/)){
_2a[parseInt(_27[1])]=_22[str];
}
}
_2a.unshift(_29);
if(_2a.length>1){
rv[_28]=_2a;
}
_22={};
_23="";
}
if(rv[""]&&rv[""][1]){
var cur={};
var _2d=rv[""][1].split(/\\n/);
for(var i=0;i<_2d.length;i++){
if(!_2d.length){
continue;
}
var pos=_2d[i].indexOf(":",0);
if(pos!=-1){
var key=_2d[i].substring(0,pos);
var val=_2d[i].substring(pos+1);
var _31=key.toLowerCase();
if(cur[_31]&&cur[_31].length){
_24.push("SKIPPING DUPLICATE HEADER LINE: "+_2d[i]);
}else{
if(/#-#-#-#-#/.test(_31)){
_24.push("SKIPPING ERROR MARKER IN HEADER: "+_2d[i]);
}else{
val=val.replace(/^\s+/,"");
cur[_31]=val;
}
}
}else{
_24.push("PROBLEM LINE IN HEADER: "+_2d[i]);
cur[_2d[i]]="";
}
}
rv[""]=cur;
}else{
rv[""]={};
}
return rv;
};
Gettext.prototype.parse_po_dequote=function(str){
var _33;
if(_33=str.match(/^"(.*)"/)){
str=_33[1];
}
str=str.replace(/\\"/,"");
return str;
};
Gettext.prototype.try_load_lang_json=function(uri){
var _35=this.sjax(uri);
if(!_35){
return;
}
var rv=this.JSON(_35);
this.parse_locale_data(rv);
return 1;
};
Gettext.prototype.get_lang_refs=function(){
var _37=new Array();
var _38=document.getElementsByTagName("link");
for(var i=0;i<_38.length;i++){
if(_38[i].rel=="gettext"&&_38[i].href){
if(typeof (_38[i].type)=="undefined"||_38[i].type==""){
if(/\.json$/i.test(_38[i].href)){
_38[i].type="application/json";
}else{
if(/\.js$/i.test(_38[i].href)){
_38[i].type="application/json";
}else{
if(/\.po$/i.test(_38[i].href)){
_38[i].type="application/x-po";
}else{
if(/\.mo$/i.test(_38[i].href)){
_38[i].type="application/x-mo";
}else{
throw new Error("LINK tag with rel=gettext found, but the type and extension are unrecognized.");
}
}
}
}
}
_38[i].type=_38[i].type.toLowerCase();
if(_38[i].type=="application/json"){
_38[i].type="application/json";
}else{
if(_38[i].type=="text/javascript"){
_38[i].type="application/json";
}else{
if(_38[i].type=="application/x-po"){
_38[i].type="application/x-po";
}else{
if(_38[i].type=="application/x-mo"){
_38[i].type="application/x-mo";
}else{
throw new Error("LINK tag with rel=gettext found, but the type attribute ["+_38[i].type+"] is unrecognized.");
}
}
}
}
_37.push(_38[i]);
}
}
return _37;
};
Gettext.prototype.textdomain=function(_3a){
if(_3a&&_3a.length){
this.domain=_3a;
}
return this.domain;
};
Gettext.prototype.gettext=function(_3b){
var _3c;
var _3d;
var n;
var _3f;
return this.dcnpgettext(null,_3c,_3b,_3d,n,_3f);
};
Gettext.prototype.dgettext=function(_40,_41){
var _42;
var _43;
var n;
var _45;
return this.dcnpgettext(_40,_42,_41,_43,n,_45);
};
Gettext.prototype.dcgettext=function(_46,_47,_48){
var _49;
var _4a;
var n;
return this.dcnpgettext(_46,_49,_47,_4a,n,_48);
};
Gettext.prototype.ngettext=function(_4c,_4d,n){
var _4f;
var _50;
return this.dcnpgettext(null,_4f,_4c,_4d,n,_50);
};
Gettext.prototype.dngettext=function(_51,_52,_53,n){
var _55;
var _56;
return this.dcnpgettext(_51,_55,_52,_53,n,_56);
};
Gettext.prototype.dcngettext=function(_57,_58,_59,n,_5b){
var _5c;
return this.dcnpgettext(_57,_5c,_58,_59,n,_5b,_5b);
};
Gettext.prototype.pgettext=function(_5d,_5e){
var _5f;
var n;
var _61;
return this.dcnpgettext(null,_5d,_5e,_5f,n,_61);
};
Gettext.prototype.dpgettext=function(_62,_63,_64){
var _65;
var n;
var _67;
return this.dcnpgettext(_62,_63,_64,_65,n,_67);
};
Gettext.prototype.dcpgettext=function(_68,_69,_6a,_6b){
var _6c;
var n;
return this.dcnpgettext(_68,_69,_6a,_6c,n,_6b);
};
Gettext.prototype.npgettext=function(_6e,_6f,_70,n){
var _72;
return this.dcnpgettext(null,_6e,_6f,_70,n,_72);
};
Gettext.prototype.dnpgettext=function(_73,_74,_75,_76,n){
var _78;
return this.dcnpgettext(_73,_74,_75,_76,n,_78);
};
Gettext.prototype.dcnpgettext=function(_79,_7a,_7b,_7c,n,_7e){
if(!this.isValidObject(_7b)){
return "";
}
var _7f=this.isValidObject(_7c);
var _80=this.isValidObject(_7a)?_7a+Gettext.context_glue+_7b:_7b;
var _81=this.isValidObject(_79)?_79:this.isValidObject(this.domain)?this.domain:"messages";
var _82="LC_MESSAGES";
var _7e=5;
var _83=new Array();
if(typeof (Gettext._locale_data)!="undefined"&&this.isValidObject(Gettext._locale_data[_81])){
_83.push(Gettext._locale_data[_81]);
}else{
if(typeof (Gettext._locale_data)!="undefined"){
for(var dom in Gettext._locale_data){
_83.push(Gettext._locale_data[dom]);
}
}
}
var _85=[];
var _86=false;
var _87;
if(_83.length){
for(var i=0;i<_83.length;i++){
var _89=_83[i];
if(this.isValidObject(_89.msgs[_80])){
for(var j=0;j<_89.msgs[_80].length;j++){
_85[j]=_89.msgs[_80][j];
}
_85.shift();
_87=_89;
_86=true;
if(_85.length>0&&_85[0].length!=0){
break;
}
}
}
}
if(_85.length==0||_85[0].length==0){
_85=[_7b,_7c];
}
var _8b=_85[0];
if(_7f){
var p;
if(_86&&this.isValidObject(_87.head.plural_func)){
var rv=_87.head.plural_func(n);
if(!rv.plural){
rv.plural=0;
}
if(!rv.nplural){
rv.nplural=0;
}
if(rv.nplural<=rv.plural){
rv.plural=0;
}
p=rv.plural;
}else{
p=(n!=1)?1:0;
}
if(this.isValidObject(_85[p])){
_8b=_85[p];
}
}
return _8b;
};
Gettext.strargs=function(str,_8f){
if(null==_8f||"undefined"==typeof (_8f)){
_8f=[];
}else{
if(_8f.constructor!=Array){
_8f=[_8f];
}
}
var _90="";
while(true){
var i=str.indexOf("%");
var _92;
if(i==-1){
_90+=str;
break;
}
_90+=str.substr(0,i);
if(str.substr(i,2)=="%%"){
_90+="%";
str=str.substr((i+2));
}else{
if(_92=str.substr(i).match(/^%(\d+)/)){
var _93=parseInt(_92[1]);
var _94=_92[1].length;
if(_93>0&&_8f[_93-1]!=null&&typeof (_8f[_93-1])!="undefined"){
_90+=_8f[_93-1];
}
str=str.substr((i+1+_94));
}else{
_90+="%";
str=str.substr((i+1));
}
}
}
return _90;
};
Gettext.prototype.strargs=function(str,_96){
return Gettext.strargs(str,_96);
};
Gettext.prototype.isArray=function(_97){
return this.isValidObject(_97)&&_97.constructor==Array;
};
Gettext.prototype.isValidObject=function(_98){
if(null==_98){
return false;
}else{
if("undefined"==typeof (_98)){
return false;
}else{
return true;
}
}
};
Gettext.prototype.sjax=function(uri){
var _9a;
if(window.XMLHttpRequest){
_9a=new XMLHttpRequest();
}else{
if(navigator.userAgent.toLowerCase().indexOf("msie 5")!=-1){
_9a=new ActiveXObject("Microsoft.XMLHTTP");
}else{
_9a=new ActiveXObject("Msxml2.XMLHTTP");
}
}
if(!_9a){
throw new Error("Your browser doesn't do Ajax. Unable to support external language files.");
}
_9a.open("GET",uri,false);
try{
_9a.send(null);
}
catch(e){
return;
}
var _9b=_9a.status;
if(_9b==200||_9b==0){
return _9a.responseText;
}else{
var _9c=_9a.statusText+" (Error "+_9a.status+")";
if(_9a.responseText.length){
_9c+="\n"+_9a.responseText;
}
alert(_9c);
return;
}
};
Gettext.prototype.JSON=function(_9d){
return eval("("+_9d+")");
};

function getLocale(){
if(navigator){
if(navigator.language){
return navigator.language;
}else{
if(navigator.browserLanguage){
return navigator.browserLanguage;
}else{
if(navigator.systemLanguage){
return navigator.systemLanguage;
}else{
if(navigator.userLanguage){
return navigator.userLanguage;
}
}
}
}
}
}
var gt=null;
function init_gettext(){
if(typeof json_locale_data!=="undefined"){
var _1={"domain":"js-messages","locale_data":json_locale_data};
gt=new Gettext(_1);
}
}
init_gettext();
function _js(_2){
if(gt){
return gt.gettext(_2);
}else{
return _2;
}
}
function __js(_3,a){
var _3=_js(_3);
for(var i=0;i<a.length;i++){
var re=new RegExp("{"+a[i][0]+"}","g");
_3=_3.replace(re,a[i][1]);
}
return _3;
}
function _jn(_7,_8,_9){
var _a;
if(gt){
_a=gt.ngettext(_7,_8,_9);
}else{
if(_9==0||_9>1){
_a=_8;
}else{
_a=_7;
}
}
return _a;
}
function __jn(_b,_c,_d,a){
var _f=_jn(_b,_c,_d);
return __gt_expand(_f,a);
return _f;
}
function __gt_expand(msg,a){
for(var i=0;i<a.length;i++){
var re=new RegExp("{"+a[i][0]+"}","g");
msg=msg.replace(re,a[i][1]);
}
return msg;
}

PgnViewer=function(_1,_2){
var _3=new BoardConfig();
if(_1){
_3.applyConfig(_1);
}
if(!window._pvObject){
window._pvObject=new Array();
}
window._pvObject[_3.boardName]=this;
_1=_3;
_1.pgnMode=true;
_1.scrollVariations=true;
this.chessapp=new ChessApp(_1);
this.finishedCallback=_2;
if(_1.loadImmediately){
this.chessapp.init();
this.board=this.chessapp.board;
this.board.addUpdatePieceListener(this);
}else{
YAHOO.util.Event.addListener(window,"load",this.setup,this,true);
}
};
PgnViewer.prototype.setup=function(){
this.chessapp.init();
this.board=this.chessapp.board;
this.board.addUpdatePieceListener(this);
};
PgnViewer.prototype.updatePieceCallback=function(_4,_5,_6,_7,_8,_9,_a,_b,_c,_d,_e,_f){
var _10=new Object();
var _11=_e;
var _12=false;
var _13=Board.getVarMove(_11,_7,_6,_5,_4);
if(_11.fromColumn==_5.column&&_11.fromRow==_5.row&&_11.toRow==_7&&_11.toColumn==_6&&(_4==""||(_4==_11.promotion))){
_12=true;
}else{
if(_13){
_11=_13;
_12=true;
}
}
_10.move=_11;
_10.allowMove=_12;
_10.dontMakeOpponentMove=false;
return _10;
};
PgnViewer.prototype.setupFromPgn=function(pgn,_15){
this.chessapp.pgn.setupFromPGN(pgn,_15);
};
PgnViewer.prototype.setupFromFen=function(fen,_17,_18,_19){
this.chessapp.pgn.board.setupFromFen(fen,_17,_18,_19);
};
PGNGame=function(_1a,_1b,_1c,_1d,_1e,_1f,_20,_21,_22,_23){
this.movesseq=_1a;
this.startFen=_1b;
this.blackPlayer=_1c;
this.whitePlayer=_1d;
this.pgn_result=_1e;
this.event=_1f;
this.site=_20;
this.date=_21;
this.round=_22;
this.start_movenum=_23;
};
PGN=function(_24){
this.board=_24;
this.pgnGames=new Array();
this.lastShownGame=0;
};
PGN.prototype.pollPGNFromURL=function(url,_26,_27){
var _28=this;
this.getPGNFromURL(url,_26);
setTimeout(function(){
_28.pollPGNFromURL(url,_26,_27);
},_27);
};
PGN.prototype.getPGNFromURL=function(url,_2a){
YAHOO.util.Connect.asyncRequest("GET",url,{success:function(o){
this.setupFromPGN(o.responseText,_2a);
},failure:function(o){
YAHOO.log("pgn load failed:"+o.statusText+" for file:"+url);
alert("pgn load failed:"+o.statusText+" for file:"+url);
},scope:this},"emptyText");
};
PGN.prototype.getMoveFromPGNMove=function(_2d,_2e,_2f){
var _30=false;
var _31=false;
var _32=false;
var _33;
var _34=null;
var _35=false;
var _36=null;
if(_2d.charAt(_2d.length-1)=="#"){
_31=true;
_30=true;
_2d=_2d.substr(0,_2d.length-1);
}else{
if(_2d.charAt(_2d.length-1)=="+"){
_31=true;
if(_2d.length>1&&_2d.charAt(_2d.length-2)=="+"){
_30=true;
_2d=_2d.substr(0,_2d.length-2);
}else{
_2d=_2d.substr(0,_2d.length-1);
}
}
}
if(_2d=="O-O-O"){
if(_2e=="w"){
return this.board.createMoveFromString("e1c1");
}else{
return this.board.createMoveFromString("e8c8");
}
}else{
if(_2d=="O-O"){
if(_2e=="w"){
return this.board.createMoveFromString("e1g1");
}else{
return this.board.createMoveFromString("e8g8");
}
}
}
var _37=_2d.indexOf("=");
if(_37>=0){
var _38;
_34=_2d.substr(_37+1,1);
_38=_34.charAt(0);
_33=this.board.pieceCharToPieceNum(_38);
_32=true;
_2d=_2d.substr(0,_37);
}
var _39=_2d.substr(_2d.length-2,2);
var _3a=_39.charCodeAt(0)-"a".charCodeAt(0);
var _3b=_39.charCodeAt(1)-"1".charCodeAt(0);
if(_3a>7||_3a<0||_3b>7||_3b<0){
this.lastMoveFromError=__js("Error processing to Square:{TO_SQUARE} on move:{MOVE}",[["TO_SQUARE",_39],["MOVE",_2d]]);
return null;
}
if(_2d.length>2){
if(_2d.charAt(_2d.length-3)=="x"){
_35=true;
_36=_2d.substr(0,_2d.length-3);
}else{
_36=_2d.substr(0,_2d.length-2);
}
}
var _3c=new Array();
var _3d=0;
var _3e=null;
var _3f=(_2e=="w")?ChessPiece.WHITE:ChessPiece.BLACK;
switch(_2d.charAt(0)){
case "K":
case "k":
_3e=ChessPiece.KING;
break;
case "Q":
case "q":
_3e=ChessPiece.QUEEN;
break;
case "R":
case "r":
_3e=ChessPiece.ROOK;
break;
case "B":
_3e=ChessPiece.BISHOP;
break;
case "N":
case "n":
_3e=ChessPiece.KNIGHT;
break;
case "P":
case "p":
_3e=ChessPiece.PAWN;
break;
default:
_3e=ChessPiece.PAWN;
}
var _40=null;
var _41=null;
if(_36){
var _42=_36.toLowerCase().charAt(0);
if(_42==_36.charAt(0)&&_42>="a"&&_42<="h"){
_41=_42;
if(_36.length==2){
_40=_36.charAt(1);
}
}else{
if(_36.length>1){
if(_36.length==2){
var c=_36.charAt(1);
if(c>="1"&&c<="8"){
_40=c;
}else{
_41=c;
}
}else{
if(_36.length==3){
_41=_36.charAt(1);
_40=_36.charAt(2);
if(_41>="1"&&_41<="9"){
var tmp=_41;
_41=_40;
_40=tmp;
}
}else{
this.lastMoveFromError=__js("Error: unhandled fromChars:{FROM_CHARS}",[["FROM_CHARS",_36]]);
return null;
}
}
}
}
}
for(var i=0;i<8;i++){
for(var j=0;j<8;j++){
var bp=this.board.boardPieces[i][j];
if(bp!=null&&bp.colour==_3f&&bp.piece==_3e){
if(this.board.canMove(bp,_3a,_3b,_2f,true)){
var _48=String.fromCharCode("a".charCodeAt(0)+i).charAt(0);
var _49=String.fromCharCode("1".charCodeAt(0)+j).charAt(0);
if((_41==null||_41==_48)&&(_40==null||_40==_49)){
_3c[_3d++]=bp;
}else{
}
}
}
}
}
if(_3d==0){
this.lastMoveFromError=__js("no candidate pieces for:{MOVE}",[["MOVE",_2d]]);
return null;
}
if(_3d>1){
this.lastMoveFromError=__js("Ambiguous:{MOVE} with fromChars:{FROM_CHARS} disambigRow:{DISAMBIG_ROW} disambigCol:{DISAMBIG_COL}",[["MOVE",_2d],["FROM_CHARS",_36],["DISAMBIG_ROW",_40],["DISAMBIG_COL",_41]]);
return null;
}
var _4a=_3c[0];
var _4b="";
_4b+=String.fromCharCode("a".charCodeAt(0)+_4a.column);
_4b+=String.fromCharCode("1".charCodeAt(0)+_4a.row);
if(_35){
_4b+="x";
}
_4b+=_39;
if(_34){
_4b+=_34;
}
var _4c=this.board.createMoveFromString(_4b);
return _4c;
};
PGN.prototype.parseTag=function(_4d,pgn,_4f){
if(pgn.substr(_4f,_4d.length+3)=="["+_4d+" \""){
var _50=pgn.indexOf("\"",_4f+_4d.length+3);
if(_50>=0){
return pgn.substring(_4f+_4d.length+3,_50);
}
}
return null;
};
PGN.prototype.parsePGN=function(pgn,_52,_53){
if(ctime){
console.time("parsePGN");
}
pgn=pgn.replace(/^\s+|\s+$/g,"");
var _54=0;
this.pgn=pgn;
var _55=new Array();
var _56=1;
var _57=0;
this.pgnGames=new Array();
this.finishedParseCallback=_52;
this.startParseTime=new Date().getTime();
var ret=this.parsePGN_cont(_55,_56,_57,_54,_53);
var _59=new Object();
if(!ret){
_59.parsedOk=true;
_59.pgnGames=this.pgnGames;
}else{
_59.parsedOk=false;
_59.errorString=ret;
_59.pgnGames=null;
}
if(ctime){
console.timeEnd("parsePGN");
}
return _59;
};
PGN.prototype.parsePGN_cont=function(_5a,_5b,_5c,_5d,_5e){
var pgn=this.pgn;
var _60=this.board.boardName+"-progress";
var _61=YAHOO.util.Dom.get(_60);
while(_5d<pgn.length){
var _62="";
var _63="";
var _64="";
var _65="";
var _66="";
var _67="";
var _68="";
var _69="w";
var _6a=0;
var _6b=0;
var _6c=new Array();
var _6d=0;
var _6e="";
var _6f=null;
var _70=null;
var _71=new Array();
var _72=new Array();
var _73=new Array();
var _74=new Array();
var _75=new Array();
this.board.pieceMoveDisabled=true;
if(this.board.initialFen){
this.board.startFen=this.board.initialFen;
}else{
this.board.startFen="rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1";
}
var i=0;
for(i=_5d;i<pgn.length;i++){
var tag=this.parseTag("FEN",pgn,i);
if(tag&&tag!="?"){
this.board.startFen=tag;
}else{
tag=this.parseTag("White",pgn,i);
if(tag&&tag!="?"){
_68=tag;
}else{
tag=this.parseTag("Black",pgn,i);
if(tag&&tag!="?"){
_63=tag;
}else{
tag=this.parseTag("Result",pgn,i);
if(tag&&tag!="?"){
_62=tag;
}else{
tag=this.parseTag("Event",pgn,i);
if(tag&&tag!="?"){
_64=tag;
}else{
tag=this.parseTag("Site",pgn,i);
if(tag&&tag!="?"){
_65=tag;
}else{
tag=this.parseTag("Date",pgn,i);
if(tag&&tag!="?"){
_66=tag;
}else{
tag=this.parseTag("Round",pgn,i);
if(tag&&tag!="?"){
_67=tag;
}
}
}
}
}
}
}
}
if(pgn.charAt(i)=="["){
var j=pgn.indexOf;
for(j=i+1;j<pgn.length&&pgn.charAt(j)!="]";j++){
}
if(j==pgn.length){
var err=_js("PgnViewer: Error parsing PGN. Found unclosed [");
if(this.finishedParseCallback){
this.finishedParseCallback(_5e,err);
}
return err;
}
i=j-1;
continue;
}
if(pgn.charAt(i)=="{"){
var _7a=pgn.indexOf("}",i+1);
if(_7a>=0){
var _7b=pgn.substring(i+1,_7a);
i=_7a;
_6e+="{ "+_7b+" } ";
}else{
var err=_js("PgnViewer: Error parsing PGN. Found unclosed {");
if(this.finishedParseCallback){
this.finishedParseCallback(_5e,err);
}
return err;
}
continue;
}
if(pgn.substr(i,1)=="."){
var j=i-1;
while(j>=0&&pgn.charAt(j)>="0"&&pgn.charAt(j)<="9"){
j--;
}
j++;
if(pgn.charAt(j)>="0"&&pgn.charAt(j)<="9"){
_5b=parseInt(pgn.substring(j,i));
}
break;
}
}
if(pgn.substr(i,1)!="."){
}
this.board.setupFromFen(this.board.startFen,false,false,true);
var _7c=i;
var _7d=null;
for(i=i;i<pgn.length;i++){
var _7e=-1;
if(pgn.substr(i,3)=="1-0"||pgn.substr(i,3)=="0-1"){
_7e=3;
}else{
if(pgn.substr(i,7)=="1/2-1/2"){
_7e=7;
}else{
if(pgn.substr(i,1)=="*"){
_7e=1;
}
}
}
if(_7e>0){
_7d=pgn.substr(i,_7e);
_5d=i+_7e;
break;
}
if(pgn.charAt(i)=="["){
_5d=i;
break;
}
if(pgn.charAt(i)==" "||pgn.charAt(i)=="\t"||pgn.charAt(i)=="\n"||pgn.charAt(i)=="\r"){
_7c=i+1;
continue;
}
if(pgn.charAt(i)>="0"&&pgn.charAt(i)<="9"){
continue;
}
if(pgn.charAt(i)=="."){
var _7f=pgn.substring(_7c,i).replace(/^\s+|\s+$/g,"");
_7c=i;
while(i+1<pgn.length&&pgn.charAt(i+1)=="."){
i++;
}
if(_7c!=i){
_69="b";
}else{
_69="w";
}
_7c=i+1;
}else{
if(pgn.charAt(i)=="{"){
var _7a=pgn.indexOf("}",i+1);
if(_7a>=0){
var _7b=pgn.substring(i+1,_7a);
i=_7a;
_6e+="{ "+_7b+" } ";
}
_7c=i+1;
}else{
if(pgn.charAt(i)=="("){
_71[_6a]=this.board.boardPieces;
_72[_6a]=_69;
_74[_6a]=_6f;
_75[_6a]=_70;
this.board.boardPieces=_73[_6a];
this.board.boardPieces=this.board.copyBoardPieces(false);
_6f=_70;
_6a++;
_7c=i+1;
_6e+="( ";
}else{
if(pgn.charAt(i)==")"){
boardPool.putObject(_71[_6a]);
_6a--;
this.board.boardPieces=_71[_6a];
_69=_72[_6a];
_6f=_74[_6a];
_70=_75[_6a];
_7c=i+1;
_6e+=") ";
}else{
if(pgn.charAt(i)=="$"){
var j;
for(j=i+1;j<pgn.length&&pgn.charAt(j)>="0"&&pgn.charAt(j)<="9";j++){
}
j--;
if(j>i){
var _80=parseInt(pgn.substr(i+1,j+1));
if(_80<=9){
switch(_80){
case 1:
_6e=_6e.substr(0,_6e.length-1)+"! ";
break;
case 2:
_6e=_6e.substr(0,_6e.length-1)+"? ";
break;
case 3:
_6e=_6e.substr(0,_6e.length-1)+"!! ";
break;
case 4:
_6e=_6e.substr(0,_6e.length-1)+"?? ";
break;
case 5:
_6e=_6e.substr(0,_6e.length-1)+"!? ";
break;
case 6:
_6e=_6e.substr(0,_6e.length-1)+"?! ";
break;
case 7:
case 8:
case 9:
case 0:
default:
}
}else{
_6e+=pgn.substring(i,j+1)+" ";
}
i=j;
}
continue;
}else{
var _81=-1;
for(var j=i+1;j<pgn.length;j++){
if(pgn.charAt(j)==")"||pgn.charAt(j)=="("||pgn.charAt(j)=="{"||pgn.charAt(j)=="}"||pgn.charAt(j)==" "||pgn.charAt(j)=="\t"||pgn.charAt(j)=="\n"||pgn.charAt(j)=="\r"){
_81=j;
break;
}
}
if(_81==-1){
_81=pgn.length;
}
var _82=_7c;
var _83=pgn.substring(_7c,_81).replace(/^\s+|\s+$/g,"");
_7c=_81;
i=_7c-1;
if(_83.length==0){
var err=__js("PgnViewer: Error: got empty move endMoveInd:{ENDMOVE_INDEX} upto:{UPTO} from:{FROM}",[["ENDMOVE_INDEX",_81],["UPTO",_82],["FROM",pgn.substr(_82)]]);
if(this.finishedParseCallback){
this.finishedParseCallback(_5e,err);
}
return err;
}
var _84=_83.length-1;
while(_84>=0){
if(_83.charAt(_84)=="?"){
_84--;
}else{
if(_83.charAt(_84)=="!"){
_84--;
}else{
break;
}
}
}
var _85=_83.substring(0,_84+1);
var _86=this.getMoveFromPGNMove(_85,_69,_6f);
if(_86==null){
_6e+="unknown ";
var err=__js("PgnViewer: Error parsing:{MOVE}, {ERROR_REASON}",[["MOVE",_83],["ERROR_REASON",this.lastMoveFromError]]);
if(this.finishedParseCallback){
this.finishedParseCallback(_5e,err);
}
return err;
}
_70=_6f;
_6f=_86;
var _87=this.board.boardPieces[_86.fromColumn][_86.fromRow];
boardPool.putObject(_73[_6a]);
_73[_6a]=this.board.copyBoardPieces(false);
if(_87){
this.board.makeMove(_86,_87,false,0.5,false,false);
}
_6b=_6a;
_6d++;
_69=this.board.flipToMove(_69);
_6e+=_86.moveString+"|"+_83+" ";
}
}
}
}
}
}
if(_5d<i){
_5d=i;
}
var _88=pgn.indexOf("{",_5d);
var _89=pgn.indexOf("[",_5d);
if(_88>=0){
if(_89==-1||_88<_89){
var _8a=pgn.indexOf("}",_88+1);
if(_8a>=0){
var _7b=pgn.substring(_88+1,_8a);
_5d=_8a+1;
_6e+="{ "+_7b+" } ";
}else{
var err=_js("PgnViewer: Error: Unclosed {");
if(this.finishedParseCallback){
this.finishedParseCallback(_5e,err);
}
return err;
}
}
}
_6e=_6e.replace(/^\s+|\s+$/g,"");
this.board.pieceMoveDisabled=false;
if(_7d!=null){
if(_62.length==0||_62=="?"){
_62=_7d;
}
}
this.pgnGames[_5c++]=new PGNGame(_6e,this.board.startFen,_63,_68,_62,_64,_65,_66,_67,_5b);
if(_61){
_61.innerHTML="Loaded "+_5c+" games";
}
if(this.finishedParseCallback&&new Date().getTime()-this.startParseTime>500){
this.startParseTime=new Date().getTime();
setTimeout("window._pvObject[\""+this.board.boardName+"\"].chessapp.pgn.parsePGN_cont(\""+_5a+"\",\""+_5b+"\",\""+_5c+"\",\""+_5d+"\",\""+_5e+"\");",0);
return;
}
}
if(this.finishedParseCallback){
this.finishedParseCallback(_5e);
}
return false;
};
PGN.prototype.setupFromPGN=function(pgn,_8c){
this.parsePGN(pgn,this.setupFromPGNCallback,_8c);
};
PGN.prototype.setupFromPGNCallback=function(_8d,err){
var _8f=this.board.boardName+"-progress";
var _90=YAHOO.util.Dom.get(_8f);
if(err){
alert(err);
return false;
}
if(this.pgnGames.length==0){
alert("PgnViewer: Error: Unable to find any pgn games in:"+pgn);
return false;
}
if(this.pgnGames.length==1){
var _91=0;
if(_8d){
_91=-1;
}
this.showGame(0,_91);
}else{
var _92=this.board.boardName+"-container";
var _93=YAHOO.util.Dom.get(_92);
var _94=YAHOO.util.Dom.get(this.board.boardName+"-problemSelector");
var _95=document.createElement("div");
var _96="<form id=\""+this.board.boardName+"-problemSelectorForm\" action=\"\" method=\"\">";
var _97="<select id=\""+this.board.boardName+"-problemSelector\" name=\""+this.board.boardName+"-problemSelector\" style=\"width: "+this.board.pieceSize*8+"px;\">";
var _98="";
for(i=0;i<this.pgnGames.length;i++){
var _99=this.pgnGames[i];
var _9a=this.board.boardName+"-game-"+i;
var _9b=(i+1)+". "+_99.whitePlayer+" vs "+_99.blackPlayer;
if(_99.pgn_result.length>0&&_99.pgn_result!="?"&&this.board.showResult==1){
_9b+=" "+_99.pgn_result;
}
if(_99.event.length>0&&_99.event!="?"&&this.board.showEvent==1){
_9b+=" "+_99.event;
}
if(_99.round.length>0&&_99.round!="?"&&this.board.showRound==1){
_9b+=" Rnd:"+_99.round;
}
if(_99.site.length>0&&_99.site!="?"&&this.board.showSite==1){
_9b+=" "+_99.site;
}
if(_99.date.length>0&&_99.date!="?"&&this.board.showDate==1){
_9b+=" "+_99.date;
}
var sel="";
if(i==this.lastShownGame){
sel="selected=\"\"";
}
_98+="<option "+sel+" id=\""+_9a+"\" value=\""+i+"\">"+_9b+"</option>";
}
if(_94){
if(this.board.selectorBody!=_98){
_94.innerHTML=_98;
this.board.selectorBody=_98;
}
}else{
_96+=_97+_98+"</select></form>";
_95.innerHTML=_96;
_93.insertBefore(_95,_93.firstChild);
this.board.selectorBody=_98;
}
var _94=YAHOO.util.Dom.get(this.board.boardName+"-problemSelector");
YAHOO.util.Event.addListener(_94,"change",this.selectGame,this,true);
var _91=0;
var _9d=0;
if(_8d){
_91=-1;
_9d=this.lastShownGame;
}
this.showGame(_9d,_91);
}
if(_90){
YAHOO.util.Dom.setStyle(_90,"visibility","hidden");
}
if(window._pvObject[this.board.boardName].finishedCallback){
window._pvObject[this.board.boardName].finishedCallback();
}
return;
};
PGN.prototype.selectGame=function(e){
var _9f=YAHOO.util.Event.getTarget(e).selectedIndex;
var _a0=0;
if(this.board.gotoEndOnRefresh){
_a0=-1;
}
this.showGame(_9f,_a0);
var _a1=this.board.boardName+"-piecestaken";
var _a2=YAHOO.util.Dom.get(_a1);
if(_a2){
_a2.innerHTML="";
}
this.board.resetMoveListScrollPosition();
};
PGN.prototype.showGame=function(_a3,_a4){
_a4=(typeof _a4=="undefined")?0:_a4;
var _a5=this.lastShownGame;
this.lastShownGame=_a3;
var _a6=this.board.moveArray;
var _a7=this.board.currentMove;
var _a8=false;
if(_a7&&_a7.atEnd){
_a8=true;
}
this.board.startFen=this.pgnGames[_a3].startFen;
this.board.setupFromFen(this.pgnGames[_a3].startFen,false,false,false);
this.board.setMoveSequence(this.pgnGames[_a3].movesseq,"NA",this.pgnGames[_a3].start_movenum,this.pgnGames[_a3].pgn_result);
var _a9=true;
var _aa=-1;
if(_a3==_a5&&_a8){
_aa=this.board.moveArray.length-1;
}
if(!Move.moveArraysEqual(_a6,this.board.moveArray)){
_a9=false;
}else{
var _ab=Move.findMoveInNewArray(_a6,this.board.moveArray,_a7);
if(_ab&&_ab.prev){
_aa=_ab.prev.index;
}
}
this.board.displayPendingMoveList();
if(this.board.moveArray.length>0){
this.board.setCurrentMove(this.board.moveArray[0]);
}
if(_a9){
if(_aa>0&&_aa<this.board.moveArray.length){
if(clog){
console.log("going to currMoveIndex:"+_aa);
}
this.board.gotoMoveIndex(_aa,false,true);
}else{
}
}else{
if(_a4==-1){
var _ac=this.board.moveArray.length-1;
if(_ac>=0){
this.board.gotoMoveIndex(_ac,false,true);
}
}else{
if(_a4!=0){
this.board.gotoMoveIndex(_a4);
}
}
if(_a4!=-1&&this.board.autoplayFirst){
this.board.forwardMove();
}
}
this.board.displayMode=true;
if(clog){
if(this.board.currentMove){
console.log("after show game currentMove:"+this.board.currentMove.output());
}else{
console.log("after show game currentMove is null");
}
}
};

var SITE_VERSION=1;
var clog=false;
var ctime=false;
var cprof=false;
var move_obj_id_counter=0;
var activeBoard=null;
function isMouseOver(_1,e){
var el=YAHOO.util.Dom.get(_1);
if(!el){
return false;
}
var _4=YAHOO.util.Dom.getRegion(el);
if(!_4){
return false;
}
var _5=_4.top;
var _6=_4.left;
var _7=_4.bottom;
var _8=_4.right;
var _9=YAHOO.util.Event.getXY(e);
var mX=_9[0];
var mY=_9[1];
var _c=(mX>_6&&mX<_8&&mY>_5&&mY<_7);
alert("reg:"+_4+" mx:"+mX+" my:"+mY+" isOver:"+_c);
}
function trimStr(_d){
if(!_d){
return "";
}
var _d=_d.replace(/^\s\s*/,"");
var ws=/\s/;
var i=_d.length;
while(ws.test(_d.charAt(--i))){
}
return _d.slice(0,i+1);
}
BoardConfig=function(){
this.boardName="board";
this.scrollVariations=false;
this.pgnString=null;
this.pgnFile=null;
this.pollPGNMilliseconds=0;
this.gotoEndOnRefresh=false;
this.pieceSet="merida";
this.pieceSize=46;
this.isEndgame=false;
this.tr=false;
this.ie6FixCoordsOffsetSize=4;
this.allIeFixCoordsOffsetSize=0;
this.addVersion=true;
this.ml=9999;
this.r=false;
this.makeActive=false;
this.autoScrollMoves=false;
this.moveAnimationLength=0.5;
this.showBracketsOnVariation=true;
this.hideBracketsOnTopLevelVariation=false;
this.variationStartString=" ( ";
this.variationEndString=" ) ";
this.ignoreCommentRegex=null;
this.newlineForEachMainMove=true;
this.showNPS=false;
this.squareColorClass="";
this.pieceTakenSize=this.pieceSize;
this.pauseBetweenMoves=800;
this.pgnMode=false;
this.previewMode=false;
this.movesFormat="default";
this.boardImagePath="http://chesstempo.com";
this.showCoordinates=false;
this.highlightFromTo=false;
this.highlightValidSquares=false;
this.showResult=1;
this.showEvent=1;
this.showRound=1;
this.showSite=1;
this.showDate=1;
this.ignoreFlipping=false;
this.reverseFlip=false;
this.autoplayFirst=false;
this.dontOutputNavButtons=false;
};
BoardConfig.prototype.applyConfig=function(_10){
for(var _11 in _10){
this[_11]=_10[_11];
}
};
ChessApp=function(_12){
this.displayMode=false;
this.config=_12;
this.board=null;
};
ChessApp.prototype.setDisplayMode=function(_13){
this.displayMode=_13;
};
ChessApp.prototype.setProblemNumber=function(_14,_15){
this.problemNumber=_14;
this.attId=_15;
};
ChessApp.prototype.init=function(us){
ChessPiece.init();
this.board=new Board(this.config.boardName);
this.board.moveArray=new Array();
if(!this.hideOnInit){
YAHOO.util.Dom.setStyle(this.config.boardName+"-container","display","block");
YAHOO.util.Dom.setStyle("toPlaySpan","display","inline");
}
this.tactics=(this.displayMode||this.config.pgnMode||this.config.previewMode||this.config.fenBoard)?null:new TacticsUI(this.board);
this.problem=(this.config.pgnMode||this.config.previewMode||this.config.fenBoard)?null:new ProblemUI(this.board,this.tactics);
this.board.tactics=this.tactics;
this.board.problem=this.problem;
if(this.problem){
this.problem.autoPlayOpponent=1;
}
this.pgn=(this.config.pgnMode)?new PGN(this.board):null;
var _17=MovesDisplay.DEFAULT_DISPLAY_TYPE;
if(this.config.movesFormat=="main_on_own_line"){
_17=MovesDisplay.MAIN_ON_OWN_LINE;
}
this.movesDisplay=new MovesDisplay(this.board,_17);
this.movesDisplay.variationOnOwnLine=this.config.variationOnOwnLine;
this.board.movesDisplay=this.movesDisplay;
this.board.boardImagePath=this.config.boardImagePath;
this.board.showNPS=this.config.showNPS;
this.board.squareColorClass=this.config.squareColorClass;
this.board.tr=this.config.tr;
this.board.ml=this.config.ml;
this.board.r=this.config.r;
this.board.addVersion=this.config.addVersion;
this.board.ie6FixCoordsOffsetSize=this.config.ie6FixCoordsOffsetSize;
this.board.allIeFixCoordsOffsetSize=this.config.allIeFixCoordsOffsetSize;
this.board.allowingFreeMovement=this.config.allowingFreeMovement;
this.board.autoScrollMoves=this.config.autoScrollMoves;
this.board.moveAnimationLength=this.config.moveAnimationLength;
this.board.showBracketsOnVariation=this.config.showBracketsOnVariation;
this.board.hideBracketsOnTopLevelVariation=this.config.hideBracketsOnTopLevelVariation;
this.board.variationStartString=this.config.variationStartString;
this.board.variationEndString=this.config.variationEndString;
this.board.ignoreCommentRegex=this.config.ignoreCommentRegex;
this.board.newlineForEachMainMove=this.config.newlineForEachMainMove;
this.board.pieceSize=this.config.pieceSize;
this.board.pollPGNMilliseconds=this.config.pollPGNMilliseconds;
this.board.gotoEndOnRefresh=this.config.gotoEndOnRefresh;
this.board.pieceTakenSize=this.config.pieceTakenSize;
this.board.pieceSet=this.config.pieceSet;
this.board.pauseBetweenMoves=this.config.pauseBetweenMoves;
this.board.showCoordinates=this.config.showCoordinates;
this.board.highlightFromTo=this.config.highlightFromTo;
this.board.highlightValidSquares=this.config.highlightValidSquares;
this.board.showDate=this.config.showDate;
this.board.showEvent=this.config.showEvent;
this.board.showGame=this.config.showGame;
this.board.showResult=this.config.showResult;
this.board.showRound=this.config.showRound;
this.board.showSite=this.config.showSite;
this.board.ignoreFlipping=this.config.ignoreFlipping;
this.board.reverseFlip=this.config.reverseFlip;
this.board.autoplayFirst=this.config.autoplayFirst;
this.board.scrollVariations=this.config.scrollVariations;
this.board.dontOutputNavButtons=this.config.dontOutputNavButtons;
if(this.config.makeActive){
activeBoard=this.board;
}
if(this.problem){
this.problem.isEndgame=this.config.isEndgame;
}
if(typeof loginManager!="undefined"){
if(this.tactics){
loginManager.setLoginCallback(this.tactics.loginCallback,this.tactics);
loginManager.setLogoutCallback(this.tactics.logoutCallback,this.tactics);
}
if(this.problem){
loginManager.setSessionCallback(this.problem.sessionCallback,this.problem);
}
}
YAHOO.util.DragDropMgr.clickTimeThresh=50;
YAHOO.util.DragDropMgr.clickPixelThresh=1;
this.board.createBoardUI();
if(this.problem){
this.problem.createProblemUI();
}
if(this.tactics){
this.tactics.initProblemCompleteOverlay();
}
if(this.problem){
this.problem.initLoadingOverlay();
}
if(this.config.pgnMode){
if(this.config.pgnFile){
this.pgn.getPGNFromURL(this.config.pgnFile,this.config.gotoEndOnRefresh);
if(this.config.pollPGNMilliseconds){
var _18=this;
setTimeout(function(){
_18.pgn.pollPGNFromURL(_18.config.pgnFile,_18.config.gotoEndOnRefresh,_18.config.pollPGNMilliseconds);
},_18.config.pollPGNMilliseconds);
}
}else{
if(this.config.pgnString){
this.pgn.setupFromPGN(this.config.pgnString);
}
}
}else{
if(this.tactics){
YAHOO.util.Event.addListener(window,"beforeunload",this.tactics.checkLeavingPage,this.tactics,true);
YAHOO.util.Event.addListener(window,"unload",this.tactics.leavingPage,this.tactics,true);
this.tactics.updateSessionDisplay(0,0);
if(typeof showingStart!="undefined"&&showingStart){
var _19=this;
var _1a=new YAHOO.widget.SimpleDialog("starttacticdialog1",{width:"300px",fixedcenter:true,modal:false,visible:true,draggable:false,close:false,text:"<span style=\"color:black\">"+_js("Click start to begin solving problems")+"</span>",icon:YAHOO.widget.SimpleDialog.ICON_INFO,constraintoviewport:true,buttons:[{text:_js("Start"),handler:function(){
this.hide();
_19.problem.getProblem();
},isDefault:true}]});
var _1b=YAHOO.util.Dom.get("ctb-"+this.board.boardName);
_1a.render(document.body);
}else{
this.problem.getProblem();
}
}else{
if(this.problem){
if(this.problemNumber!=""){
YAHOO.util.Dom.setStyle("boardandmoves","display","block");
this.problem.getProblem(this.problemNumber,this.attId);
}
}
}
}
this.board.setupEventHandlers();
if(this.problem){
this.problem.setupEventHandlers();
}
if(this.tactics){
this.tactics.setupEventHandlers();
}
};
function clearClone(o){
if(o==null){
return;
}
for(prop in o){
if(typeof (o[prop])=="object"&&o[prop]!=null&&o[prop].alreadyCloned){
o[prop].alreadyCloned=false;
clearClone(o[prop]);
}
}
}
function cloneWork(o){
if(o==null){
return null;
}
var _1e=new Object();
for(prop in o){
if(typeof (o[prop])=="object"){
_1e[prop]=o[prop];
}else{
_1e[prop]=o[prop];
}
}
return _1e;
}
function clone(o){
return cloneWork(o);
}
get_image_str=function(_20,_21,_22,_23,_24){
var _25=".vers"+SITE_VERSION;
if(!_24){
_25="";
}
if(check_bad_msie()){
return _21+"/images/"+_22+"/"+_20+_23+_25+".png";
}else{
return _21+"/images/"+_22+"/"+_20+_23+_25+".png";
}
};
check_bad_msie=function(){
var _26=(window.ActiveXObject&&(typeof document.body.style.maxHeight=="undefined"));
return _26;
};
fix_ie_png=function(img){
if(!check_bad_msie()){
return;
}
var _28=(img.id)?"id='"+img.id+"' ":"";
var _29=(img.className)?"class='"+img.className+"' ":"";
var _2a=(img.title)?"title='"+img.title+"' ":"title='"+img.alt+"' ";
var _2b="display:inline-block;"+img.style.cssText;
if(img.align=="left"){
_2b="float:left;"+_2b;
}
if(img.align=="right"){
_2b="float:right;"+_2b;
}
if(img.parentElement.href){
_2b="cursor:hand;"+_2b;
}
var _2c="<span "+_28+_29+_2a+" style=\""+"width:"+img.width+"px; height:"+img.height+"px;"+_2b+";"+"filter:progid:DXImageTransform.Microsoft.AlphaImageLoader"+"(src='"+img.src+"', sizingMethod='image');\"></span>";
img.outerHTML=_2c;
};
Move=function(_2d,_2e,_2f,_30,_31,_32,_33){
this.fromColumn=_2d;
this.fromRow=_2e;
this.toColumn=_2f;
this.toRow=_30;
this.take=_31;
this.promotion=_32;
this.moveString=_33;
this.prev=null;
this.next=null;
this.numVars=0;
this.ravLevel=0;
this.atEnd=false;
this.obj_id=move_obj_id_counter++;
this.beforeComment="";
this.afterComment="";
};
Move.prototype.freeMove=function(){
if(this.taken){
this.taken=null;
}
if(this.vars&&this.vars.length>0){
var i=0;
for(var i=0;i<this.vars.length;i++){
this.vars[i].freeMove();
}
}
};
Move.prototype.clone=function(_35){
var _36=this.take;
if(_35&&_36){
_36=_36.makeLightWeight();
}
var _37=new Move(this.fromColumn,this.fromRow,this.toColumn,this.toRow,_36,this.promotion,this.moveString);
_37.moveNum=this.moveNum;
_37.atEnd=this.atEnd;
_37.beforeComment=this.beforeComment;
_37.afterComment=this.afterComment;
if(this.vars){
_37.vars=[];
var cnt=0;
for(var i=0;i<this.vars.length;i++){
_37.vars[i]=this.vars[i].clone(_35);
cnt++;
}
_37.numVars=cnt;
}
return _37;
};
Move.columnToChar=function(col){
var a=String.fromCharCode("a".charCodeAt(0)+col);
return a;
};
Move.prototype.output=function(){
return Move.columnToChar(this.fromColumn)+""+(this.fromRow+1)+":"+Move.columnToChar(this.toColumn)+""+(this.toRow+1)+" prom:"+this.promotion+" objid:"+this.obj_id+" dummy:"+this.dummy+" endNode:"+this.endNode+" index:"+this.index+" moveNum:"+this.moveNum+" atEnd:"+this.atEnd;
};
Move.prototype.equals=function(m){
return (m&&(this.fromColumn==m.fromColumn&&this.fromRow==m.fromRow&&this.promotion==m.promotion&&this.toColumn==m.toColumn&&this.toRow==m.toRow));
};
Move.moveArraysEqual=function(a1,a2){
if(a1==a2){
return true;
}
if(a1==null||a2==null){
return false;
}
if(a1.length!=a2.length){
return false;
}
for(var i=0;i<a1.length;i++){
if(!a1[i].equals(a2[i])){
return false;
}
if(!Move.moveArraysEqual(a1[i].vars,a2[i].vars)){
return false;
}
}
return true;
};
Move.findMoveInNewArray=function(a1,a2,_42){
if(a1==a2){
return _42;
}
if(a1==null||a2==null){
return null;
}
if(a1.length!=a2.length){
return null;
}
for(var i=0;i<a1.length;i++){
if(!a1[i].equals(a2[i])){
return null;
}
if(!Move.moveArraysEqual(a1[i].vars,a2[i].vars)){
return null;
}
if(a1[i]==_42){
return a2[i];
}
}
return null;
};
Move.prototype.toMoveString=function(){
var _44="";
if(this.promotion){
_44=this.promotion;
}
return Move.columnToChar(this.fromColumn)+""+(this.fromRow+1)+Move.columnToChar(this.toColumn)+""+(this.toRow+1)+_44;
};
function getTagValue(_45,_46){
var _47=_45.getElementsByTagName(_46);
if(_47==null){
YAHOO.log("got null node for tag:"+_46);
return null;
}
if(_47.length==0){
YAHOO.log("got empty array node for tag:"+_46);
return null;
}
if(_47[0].firstChild==null){
YAHOO.log("firstChild is null for tag:"+_46);
return null;
}
if(_47[0].firstChild.nodeValue==null){
YAHOO.log("firstChild.nodeValue is null for tag:"+_46);
return null;
}
if(typeof (_47[0].textContent)!="undefined"){
return _47[0].textContent;
}
return _47[0].firstChild.nodeValue;
}
var ua=navigator.userAgent.toLowerCase();
var isOpera=(ua.indexOf("opera")>-1);
var isIphone=(navigator.userAgent.match(/iPhone/i))||(navigator.userAgent.match(/iPod/i));
var isSafari=(ua.indexOf("safari")>-1);
var isGecko=(!isOpera&&!isSafari&&ua.indexOf("gecko")>-1);
var isIE=(!isOpera&&ua.indexOf("msie")>-1);
ChessPiece=function(div,_49,_4a,_4b){
var id=div.id;
this.board=_4b;
this.icon=get_image_str(ChessPiece.pieceIconNames[_49][_4a],this.board.boardImagePath,this.board.pieceSet,this.board.pieceSize,this.board.addVersion);
this.colour=_49;
this.piece=_4a;
this.id=id;
this.div=div;
var _4d=_4b.getPieceDragDiv();
var _4e=false;
var _4f="";
if(_4d==null){
_4d=document.createElement("div");
_4d.id="pieceDragDiv";
_4e=true;
YAHOO.util.Dom.setStyle(_4d,"visibility","hidden");
YAHOO.util.Dom.setStyle(_4d,"border","0px");
YAHOO.util.Dom.setStyle(_4d,"position","absolute");
}
this.pieceDragEl=_4d;
this.pieceDragElId="pieceDragDiv";
if(_4e){
var _50=this.board.getDocBody();
if(_50){
_50.appendChild(_4d);
}
}
if(YAHOO.util.Event.isIE){
var _51=this.div;
_51.innerHTML="<img src=\""+this.icon+"\"/>";
var img=_51.firstChild;
fix_ie_png(img);
}else{
YAHOO.util.Dom.setStyle([this.div],"backgroundImage","url("+this.icon+")");
}
YAHOO.util.Dom.setStyle([this.div],"height",this.board.pieceSize+"px");
YAHOO.util.Dom.setStyle([this.div],"width",this.board.pieceSize+"px");
if(isIphone){
initIphone(this.div);
}
YAHOO.util.Dom.setStyle([this.div],"position","relative");
this.init(id,"ct-"+this.board.boardName+"-boardandpieces",{dragElId:this.pieceDragElId,resizeFrame:false,centerFrame:false,isTarget:false});
this.initFrame();
};
ChessPiece.prototype=new YAHOO.util.DDProxy();
ChessPiece.init=function(){
ChessPiece.PAWN=0;
ChessPiece.BISHOP=1;
ChessPiece.KNIGHT=2;
ChessPiece.ROOK=3;
ChessPiece.KING=4;
ChessPiece.QUEEN=5;
ChessPiece.WHITE=0;
ChessPiece.BLACK=1;
ChessPiece.pieceIconNames=new Array(2);
ChessPiece.pieceIconNames[0]=new Array(6);
ChessPiece.pieceIconNames[1]=new Array(6);
ChessPiece.pieceIconNames[ChessPiece.WHITE][ChessPiece.PAWN]="whitepawn";
ChessPiece.pieceIconNames[ChessPiece.WHITE][ChessPiece.BISHOP]="whitebishop";
ChessPiece.pieceIconNames[ChessPiece.WHITE][ChessPiece.KNIGHT]="whiteknight";
ChessPiece.pieceIconNames[ChessPiece.WHITE][ChessPiece.ROOK]="whiterook";
ChessPiece.pieceIconNames[ChessPiece.WHITE][ChessPiece.KING]="whiteking";
ChessPiece.pieceIconNames[ChessPiece.WHITE][ChessPiece.QUEEN]="whitequeen";
ChessPiece.pieceIconNames[ChessPiece.BLACK][ChessPiece.PAWN]="blackpawn";
ChessPiece.pieceIconNames[ChessPiece.BLACK][ChessPiece.BISHOP]="blackbishop";
ChessPiece.pieceIconNames[ChessPiece.BLACK][ChessPiece.KNIGHT]="blackknight";
ChessPiece.pieceIconNames[ChessPiece.BLACK][ChessPiece.ROOK]="blackrook";
ChessPiece.pieceIconNames[ChessPiece.BLACK][ChessPiece.KING]="blackking";
ChessPiece.pieceIconNames[ChessPiece.BLACK][ChessPiece.QUEEN]="blackqueen";
};
ChessPiece.prototype.oldIsValidHandleChild=ChessPiece.prototype.isValidHandleChild;
ChessPiece.prototype.oldStartDrag=ChessPiece.prototype.startDrag;
ChessPiece.prototype.free=function(){
this.unreg();
};
ChessPiece.prototype.isValidHandleChild=function(_53){
if(this.board.dragDisabled){
return false;
}
if(this.board.toMove!=this.colour){
return false;
}
return this.oldIsValidHandleChild(_53);
};
ChessPiece.prototype.onDragOut=function(e,id){
this.insideBoard=false;
};
ChessPiece.prototype.onDragEnter=function(e,id){
this.insideBoard=true;
};
ChessPiece.prototype.makeLightWeight=function(){
var cp=this.board.createPiece(this.colour,this.piece,true);
cp.column=this.column;
cp.row=this.row;
cp.enPassant=this.enPassant;
cp.castled=this.castled;
return cp;
};
ChessPiece.prototype.endDrag=function(e){
if(this.board.lastOverSquare){
YAHOO.util.Dom.removeClass(this.board.lastOverSquare,"ct-over-valid-square");
YAHOO.util.Dom.removeClass(this.board.lastOverSquare,"ct-over-invalid-square");
}
this.board.lastOverSquare=null;
if(!this.insideBoard){
this.board.board_xy=null;
this.setPosition(this.column,this.row,false,null,this.board.moveAnimationLength);
}
YAHOO.util.Dom.setStyle(this.getEl(),"visibility","visible");
};
ChessPiece.prototype.startDrag=function(x,y){
this.insideBoard=true;
var _5c=null;
if(this.board.currentMove){
if(this.board.currentMove.prev){
_5c=this.board.currentMove.prev;
}else{
_5c=this.board.prev_move;
}
}else{
_5c=this.board.prev_move;
}
if(this.board.highlightValidSquares){
this.candidates=null;
this.candidates=new Array(8);
for(var i=0;i<8;i++){
this.candidates[i]=new Array(8);
for(var j=0;j<8;j++){
this.candidates[i][j]=false;
}
}
}
this.pieceDragEl.innerHTML="<img src=\""+this.icon+"\"/>";
var img=this.pieceDragEl.firstChild;
fix_ie_png(img);
YAHOO.util.Dom.setStyle(this.pieceDragEl,"zIndex",1000);
YAHOO.util.Dom.setStyle(this.pieceDragEl,"height",this.board.pieceSize+"px");
YAHOO.util.Dom.setStyle(this.pieceDragEl,"width",this.board.pieceSize+"px");
YAHOO.util.Dom.setStyle(this.getEl(),"visibility","hidden");
if(this.board.highlightValidSquares){
for(var i=0;i<8;i++){
for(var j=0;j<8;j++){
var _60=7-i;
var _61=j;
if(this.board.isFlipped){
_60=7-_60;
_61=7-_61;
}
if((_60==this.row&&_61==this.column)||this.board.canMove(this.makeLightWeight(),_61,_60,_5c,true)){
this.candidates[j][i]=true;
}
}
}
}
};
ChessPiece.prototype.onDragOver=function(e,id){
var x=YAHOO.util.Event.getPageX(e);
var y=YAHOO.util.Event.getPageY(e);
var _66=YAHOO.util.Dom.getX("ctb-"+this.board.boardName);
var _67=YAHOO.util.Dom.getY("ctb-"+this.board.boardName);
var c=parseInt((x-_66)/this.board.pieceSize);
var r=parseInt((y-_67)/this.board.pieceSize);
var _6a=this.board.boardName+"-s"+c+""+(7-r);
var _6b=YAHOO.util.Dom.get(_6a);
if(this.board.highlightValidSquares){
if(this.board.lastOverSquare){
if(this.board.lastOverSquare!=_6b){
YAHOO.util.Dom.removeClass(this.board.lastOverSquare,"ct-over-valid-square");
YAHOO.util.Dom.removeClass(this.board.lastOverSquare,"ct-over-invalid-square");
this.board.lastOverSquare=null;
if(this.candidates&&c<8&&c>=0&&r<8&&r>=0&&this.candidates[c][r]){
YAHOO.util.Dom.addClass(_6b,"ct-over-valid-square");
}else{
YAHOO.util.Dom.addClass(_6b,"ct-over-invalid-square");
}
}
}
this.board.lastOverSquare=_6b;
}
};
ChessPiece.prototype.onDragDrop=function(e,id){
if(this.board.blockFowardBack||this.board.deferredBlockForwardBack){
return false;
}
if(this.board.lastOverSquare){
YAHOO.util.Dom.removeClass(this.board.lastOverSquare,"ct-over-valid-square");
YAHOO.util.Dom.removeClass(this.board.lastOverSquare,"ct-over-invalid-square");
}
var x=YAHOO.util.Event.getPageX(e);
var y=YAHOO.util.Event.getPageY(e);
var _70=YAHOO.util.Dom.getX("ctb-"+this.board.boardName);
var _71=YAHOO.util.Dom.getY("ctb-"+this.board.boardName);
var c=parseInt((x-_70)/this.board.pieceSize);
var r=parseInt((y-_71)/this.board.pieceSize);
if(this.board.isFlipped){
r=7-r;
c=7-c;
}
var _74=false;
if(!this.board.currentMove||this.board.currentMove.atEnd){
_74=true;
}
this.board.updatePiece(this,c,7-r,false,false,true);
if(!_74&&this.board.currentMove&&!this.board.allowingFreeMovement&&this.board.currentMove.atEnd){
this.board.toggleToMove();
this.board.updateToPlay();
}
};
ChessPiece.prototype.removeFromParent=function(){
var _75=this.div;
if(_75.parentNode){
_75.parentNode.removeChild(_75);
}
};
ChessPiece.prototype.setVisible=function(_76){
var _77;
var _78;
if(_76){
_78="block";
_77="visible";
}else{
_78="none";
_77="hidden";
}
YAHOO.util.Dom.setStyle(this.id,"visibility",_77);
};
ChessPiece.prototype.moveResponse=function(o){
};
ChessPiece.prototype.getIcon=function(){
return this.icon;
};
ChessPiece.prototype.makeHeavyWeight=function(){
return this.copyPiece();
};
ChessPiece.prototype.copyPiece=function(){
var cp=new ChessPiece(this.div,this.colour,this.piece,this.board);
cp.column=this.column;
cp.row=this.row;
cp.enPassant=this.enPassant;
cp.castled=this.castled;
return cp;
};
ChessPiece.prototype.changePiece=function(_7b){
var _7c=(_7b+"").toLowerCase().charAt(0);
switch(_7c){
case "k":
this.piece=ChessPiece.KING;
break;
case "q":
this.piece=ChessPiece.QUEEN;
break;
case "r":
this.piece=ChessPiece.ROOK;
break;
case "b":
this.piece=ChessPiece.BISHOP;
break;
case "n":
this.piece=ChessPiece.KNIGHT;
break;
case "p":
this.piece=ChessPiece.PAWN;
break;
default:
}
this.icon=get_image_str(ChessPiece.pieceIconNames[this.colour][this.piece],this.board.boardImagePath,this.board.pieceSet,this.board.pieceSize,this.board.addVersion);
if(YAHOO.util.Event.isIE){
var _7d=this.div;
_7d.innerHTML="<img src=\""+this.icon+"\"/>";
var img=_7d.firstChild;
if(!isOpera){
fix_ie_png(img);
}
}else{
YAHOO.util.Dom.setStyle(this.div,"backgroundImage","url("+this.icon+")");
YAHOO.util.Dom.setStyle(this.div,"background-repeat","no-repeat");
}
};
ChessPiece.prototype.getNewXYPosition=function(_7f,row){
var _81=this.board.getBoardDiv();
var _82=this.board.getXY();
var _83=_82[0];
var _84=_82[1];
var _85=[0,0];
if(this.board.isFlipped){
_85[0]=_83+((7-_7f)*this.board.pieceSize);
_85[1]=_84+((row)*this.board.pieceSize);
}else{
_85[0]=_83+((_7f)*this.board.pieceSize);
_85[1]=_84+((7-row)*this.board.pieceSize);
}
return _85;
};
ChessPiece.prototype.setPosition=function(_86,row,_88,_89,_8a){
this.column=_86;
this.row=row;
if(this.board.pieceMoveDisabled){
return;
}
var _8b=this.div;
var _8c=null;
if(this.board.isFlipped){
_8c=this.board.boardName+"-s"+(7-this.column)+""+(7-this.row);
}else{
_8c=this.board.boardName+"-s"+(this.column)+""+(this.row);
}
var _8d=this.board.getBoardDivFromId(_8c);
if(!_88){
if(!this.board.settingUpPosition){
var _8e=this.getNewXYPosition(_86,row);
YAHOO.util.Dom.setXY(_8b,_8e,false);
}else{
if(_8b.parentNode){
_8b.parentNode.removeChild(_8b);
}
_8d.appendChild(_8b);
}
this.setVisible(true);
if(_89){
_89();
}
}else{
var _8e=this.getNewXYPosition(_86,row);
var _8f=new YAHOO.util.Motion(_8b,{points:{to:_8e}});
_8f.duration=_8a;
var _90=this;
_8f.onComplete.subscribe(function(){
});
if(_89){
_8f.onComplete.subscribe(_89);
}
_8f.animate();
}
};
ChessPiece.prototype.getFenLetter=function(){
var _91=ChessPiece.pieceTypeToChar(this.piece)+"";
if(this.colour!=ChessPiece.WHITE){
_91=_91.toLowerCase();
}
return _91;
};
ChessPiece.pieceTypeToChar=function(_92){
switch(_92){
case ChessPiece.KING:
return "K";
case ChessPiece.QUEEN:
return "Q";
case ChessPiece.ROOK:
return "R";
case ChessPiece.BISHOP:
return "B";
case ChessPiece.KNIGHT:
return "N";
case ChessPiece.PAWN:
return "P";
}
return "?";
};
LightweightChessPiece=function(div,_94,_95,_96){
this.board=_96;
this.colour=_94;
this.piece=_95;
this.div=div;
};
LightweightChessPiece.prototype.getFenLetter=ChessPiece.prototype.getFenLetter;
LightweightChessPiece.prototype.makeLightWeight=function(){
return this.copyPiece();
};
LightweightChessPiece.prototype.makeHeavyWeight=function(){
var cp=this.board.createPiece(this.colour,this.piece,false);
cp.column=this.column;
cp.row=this.row;
cp.enPassant=this.enPassant;
cp.castled=this.castled;
return cp;
};
LightweightChessPiece.prototype.setVisible=function(_98){
};
LightweightChessPiece.prototype.free=function(){
};
LightweightChessPiece.prototype.setPosition=function(_99,row,_9b,_9c,_9d){
this.column=_99;
this.row=row;
};
LightweightChessPiece.prototype.copyPiece=function(){
var cp=new LightweightChessPiece(this.id,this.colour,this.piece,this.board);
cp.column=this.column;
cp.row=this.row;
return cp;
};
LightweightChessPiece.prototype.changePiece=function(_9f){
var _a0=(_9f+"").toLowerCase().charAt(0);
switch(_a0){
case "k":
this.piece=ChessPiece.KING;
break;
case "q":
this.piece=ChessPiece.QUEEN;
break;
case "r":
this.piece=ChessPiece.ROOK;
break;
case "b":
this.piece=ChessPiece.BISHOP;
break;
case "n":
this.piece=ChessPiece.KNIGHT;
break;
case "p":
this.piece=ChessPiece.PAWN;
break;
default:
}
};
MovesDisplay=function(_a1,_a2){
this.board=_a1;
this.displayType=_a2;
};
MovesDisplay.DEFAULT_DISPLAY_TYPE=0;
MovesDisplay.MAIN_ON_OWN_LINE=1;
Board=function(_a3){
this.boardName=_a3;
if(_a3){
this.initTarget("ctb-"+_a3,"ct-"+this.boardName+"-boardandpieces");
this.boardPieces=Board.createBoardArray();
}
this.currentMove=null;
this.moveIndex=-1;
this.settingUpPosition=false;
this.pendingLevelZeroCommentaryClose=false;
this.isUserFlipped=false;
this.registeredGotoMoveIndexListeners=[];
this.registeredBackMovePreCurrentListeners=[];
this.registeredForwardMovePostUpdateListeners=[];
this.registeredUpdateListeners=[];
this.registeredUpdatePieceFinishedListeners=[];
this.registeredUpdateEndOfMovesListeners=[];
this.registeredUpdateHaveAltListeners=[];
this.registeredUpdateWrongMoveListeners=[];
this.registeredUpdateAllowMoveListeners=[];
this.moveNumber=1;
this.halfMoveNumber=0;
};
Board.prototype=new YAHOO.util.DDTarget();
Board.invertToMove=function(_a4){
if(_a4==ChessPiece.WHITE){
return ChessPiece.BLACK;
}else{
return ChessPiece.WHITE;
}
};
Board.boardStyleToClassName=function(_a5){
var _a6="";
switch(_a5){
case 0:
_a6="-lightgrey";
break;
case 1:
_a6="-grey";
break;
case 2:
_a6="-brown";
break;
case 3:
_a6="-green";
break;
case 4:
_a6="-woodlight";
break;
case 5:
_a6="-wooddark";
break;
case 6:
_a6="-metal";
break;
case 7:
_a6="-marblebrown";
break;
case 8:
_a6="-stucco";
break;
case 9:
_a6="-goldsilver";
break;
case 10:
_a6="-sandsnow";
break;
case 11:
_a6="-crackedstone";
break;
case 12:
_a6="-granite";
break;
case 13:
_a6="-marblegreen";
break;
case 14:
_a6="-greenwhite";
break;
default:
}
return _a6;
};
Board.createBoardArray=function(){
var _a7=boardPool.getObject();
if(_a7==null){
_a7=new Array(8);
for(var i=0;i<8;i++){
_a7[i]=new Array(8);
}
}
return _a7;
};
Board.prototype.toggleToMove=function(){
if(this.toMove==ChessPiece.WHITE){
this.toMove=ChessPiece.BLACK;
}else{
this.toMove=ChessPiece.WHITE;
}
};
Board.prototype.setupPieceDivs=function(){
var _a9=this.getBoardDiv();
if(this.availPieceDivs){
for(var i=0;i<32;i++){
if(this.availPieceDivs[i]){
if(this.availPieceDivs[i].parentNode){
this.availPieceDivs[i].parentNode.removeChild(this.availPieceDivs[i]);
}
}
}
}
if(this.pieces){
for(var i=0;i<32;i++){
if(this.pieces[i]){
this.pieces[i].setVisible(false);
this.pieces[i].free();
this.pieces[i]=null;
}
}
}
this.availids=null;
this.availIds=new Array(32);
this.availPieceDivs=null;
this.availPieceDivs=new Array(32);
this.pieces=null;
this.pieces=new Array(32);
this.uptoId=0;
this.uptoPiece=0;
};
Board.prototype.getXY=function(){
if(true||!this.board_xy){
this.board_xy=YAHOO.util.Dom.getXY("ctb-"+this.boardName);
}
return this.board_xy;
};
Board.prototype.updateFromTo=function(_ab,_ac,_ad,_ae,_af,_b0){
YAHOO.util.Dom.removeClass(this.lastFromSquare,"ct-from-square");
YAHOO.util.Dom.removeClass(this.lastToSquare,"ct-to-square");
if(_ad==null){
return;
}
this.lastFromSquare=_ab;
this.lastToSquare=_ac;
this.lastFromRow=_ad;
this.lastFromColumn=_ae;
this.lastToRow=_af;
this.lastToColumn=_b0;
if(this.highlightFromTo){
YAHOO.util.Dom.addClass(_ab,"ct-from-square");
YAHOO.util.Dom.addClass(_ac,"ct-to-square");
}
};
Board.prototype.makeMove=function(_b1,_b2,_b3,_b4,_b5,_b6,_b7,_b8){
var _b9;
var _ba;
if(!this.isFlipped){
_b9=YAHOO.util.Dom.get(this.boardName+"-s"+_b1.fromColumn+""+_b1.fromRow);
_ba=YAHOO.util.Dom.get(this.boardName+"-s"+_b1.toColumn+""+_b1.toRow);
}else{
_b9=YAHOO.util.Dom.get(this.boardName+"-s"+(7-_b1.fromColumn)+""+(7-_b1.fromRow));
_ba=YAHOO.util.Dom.get(this.boardName+"-s"+(7-_b1.toColumn)+""+(7-_b1.toRow));
}
if(_b6){
this.updateFromTo(_b9,_ba,_b1.fromRow,_b1.fromColumn,_b1.toRow,_b1.toColumn);
}
var _bb=this.boardPieces[_b1.toColumn][_b1.toRow];
if(_bb!=null){
_bb.enPassant=false;
_bb.castled=false;
}
if(_b2.piece==ChessPiece.PAWN&&_b1.toColumn!=_b1.fromColumn&&this.boardPieces[_b1.toColumn][_b1.toRow]==null){
_bb=this.boardPieces[_b1.toColumn][_b1.fromRow];
this.boardPieces[_b1.toColumn][_b1.fromRow]=null;
if(_bb!=null){
_bb.enPassant=true;
}
}
var _bc=null;
if(_b2.piece==ChessPiece.KING&&Math.abs(_b1.toColumn-_b1.fromColumn)>1){
var _bd;
var _be;
if(_b1.toColumn>_b1.fromColumn){
_bc=this.boardPieces[7][_b1.fromRow];
_bd=_b1.fromRow;
_be=5;
this.boardPieces[7][_b1.toRow]=null;
}else{
_bc=this.boardPieces[0][_b1.fromRow];
_bd=_b1.fromRow;
_be=3;
this.boardPieces[0][_b1.toRow]=null;
}
if(!_bc){
alert("No castle piece");
}else{
_bc.setPosition(_be,_bd,_b3,null,_b4);
this.boardPieces[_bc.column][_bc.row]=_bc;
_bc.castled=true;
}
}
_b1.taken=_bb;
if(_bb&&_b5){
this.processTaken(_bb,true);
}
this.moveNumber++;
this.board_xy=null;
_b2.setPosition(_b1.toColumn,_b1.toRow,_b3,function(){
var tp=_bb;
if(tp){
tp.setVisible(false);
}
if(_b1.promotion!=null){
_b2.changePiece(_b1.promotion);
}
if(_b7){
_b7.call(_b8);
}
},_b4);
if(!_b3){
if(_b1.promotion!=null){
_b2.changePiece(_b1.promotion);
}
}
this.boardPieces[_b1.fromColumn][_b1.fromRow]=null;
this.boardPieces[_b1.toColumn][_b1.toRow]=_b2;
if(_bc!=null){
_b1.taken=_bc;
}
_b1.preCastleQueenSide=new Array(2);
_b1.preCastleKingSide=new Array(2);
_b1.preCastleQueenSide[0]=this.canCastleQueenSide[0];
_b1.preCastleQueenSide[1]=this.canCastleQueenSide[1];
_b1.preCastleKingSide[0]=this.canCastleKingSide[0];
_b1.preCastleKingSide[1]=this.canCastleKingSide[1];
if(_b2.piece==ChessPiece.ROOK){
if(_b1.fromColumn==0){
this.canCastleQueenSide[_b2.colour]=false;
}else{
if(_b1.fromColumn==7){
this.canCastleKingSide[_b2.colour]=false;
}
}
}else{
if(_b2.piece==ChessPiece.KING){
this.canCastleQueenSide[_b2.colour]=false;
this.canCastleKingSide[_b2.colour]=false;
}
}
};
Board.prototype.promptPromotion=function(_c0,col,row,_c3,_c4){
_c0.prePromotionColumn=_c0.column;
_c0.prePromotionRow=_c0.row;
_c0.setPosition(col,row,false,null,this.moveAnimationLength);
var _c5=this;
var _c6=new YAHOO.widget.Dialog("promotionDialogId",{width:"300px",fixedcenter:true,visible:true,modal:true,close:false,constraintoviewport:true,buttons:[{text:_js("Queen"),handler:function(){
_c6.hide();
_c5.updatePiece(_c0,col,row,_c3,_c4,false,"q");
},isDefault:true},{text:_js("Rook"),handler:function(){
_c6.hide();
_c5.updatePiece(_c0,col,row,_c3,_c4,false,"r");
},isDefault:false},{text:_js("Bishop"),handler:function(){
_c6.hide();
_c5.updatePiece(_c0,col,row,_c3,_c4,false,"b");
},isDefault:false},{text:_js("Knight"),handler:function(){
_c6.hide();
_c5.updatePiece(_c0,col,row,_c3,_c4,false,"n");
},isDefault:false}]});
_c6.setHeader(_js("Select Promotion Piece"));
_c6.setBody("<div></div>");
_c6.render(document.body);
};
Board.prototype.moveToLocale=function(_c7){
if(!_c7||_c7==""){
return _c7;
}
var _c8="";
for(var i=0;i<_c7.length;i++){
var _ca=_c7.charAt(i);
switch(_ca){
case "K":
_ca=_js("K");
break;
case "Q":
_ca=_js("Q");
break;
case "R":
_ca=_js("R");
break;
case "N":
_ca=_js("N");
break;
case "B":
_ca=_js("B");
break;
case "P":
_ca=_js("P");
break;
case "a":
_ca=_js("a");
break;
case "b":
_ca=_js("b");
break;
case "c":
_ca=_js("c");
break;
case "d":
_ca=_js("d");
break;
case "e":
_ca=_js("e");
break;
case "f":
_ca=_js("f");
break;
case "g":
_ca=_js("g");
break;
case "h":
_ca=_js("h");
break;
case "x":
_ca=_js("x");
break;
case "#":
_ca=_js("#");
break;
}
_c8+=_ca;
}
return _c8;
};
Board.prototype.updatePiece=function(_cb,col,row,_ce,_cf,_d0,_d1,_d2){
if(_d1){
this.board_xy=null;
if(_cb.prePromotionRow){
_cb.row=_cb.prePromotionRow;
_cb.column=_cb.prePromotionColumn;
}
}
if(_d1==null&&_cb.column==col&&_cb.row==row){
this.board_xy=null;
_cb.setPosition(_cb.column,_cb.row,false,null,this.moveAnimationLength);
if(clog){
console.log("moved piece back to its orig position");
}
return;
}
var _d3=null;
if(this.currentMove){
if(this.currentMove.prev){
_d3=this.currentMove.prev;
}else{
_d3=this.prev_move;
}
}
if(!_ce&&!this.canMove(_cb.makeLightWeight(),col,row,_d3,true)){
this.board_xy=null;
_cb.setPosition(_cb.column,_cb.row,false,null,0.5);
if(clog){
console.log("move not legal , move back to orig:"+this.toMove);
}
return;
}
var _d4="";
if(_d0&&_cb.piece==ChessPiece.PAWN&&(row==7||row==0)){
this.promptPromotion(_cb,col,row,_ce,_cf);
return;
}else{
if(_d1!=null){
_d4=_d1;
}
}
var _d5=true;
var _d6="";
_d6+=Move.columnToChar(_cb.column);
_d6+=String.fromCharCode("1".charCodeAt(0)+_cb.row);
_d6+=Move.columnToChar(col);
_d6+=String.fromCharCode("1".charCodeAt(0)+(row));
if(_d4){
_d6+=_d4;
}
var _d7=this.createMoveFromString(_d6);
var _d8=this.currentMove;
if(_d8){
_d7.moveNum=_d8.moveNum;
}
var res=null;
for(var i=0;i<this.registeredUpdateListeners.length;i++){
_db=this.registeredUpdateListeners[i].updatePieceCallback(_d4,_cb,col,row,_ce,_cf,_d0,_d1,_d2,_d3,this.currentMove,_d7);
if(!_db){
return false;
}
if(!_db.ignoreRetVal){
res=_db;
}
}
if(!res){
return false;
}
if(res.allowMove){
var _d8=res.move;
for(var i=0;i<this.registeredUpdateAllowMoveListeners.length;i++){
var _dc=this.registeredUpdateAllowMoveListeners[i].updateAllowMoveCallback(_d4,_cb,col,row,_ce,_cf,_d0,_d1,_d2,_d8);
}
YAHOO.log("Made correct move");
this.makeMove(_d8,_cb,_cf,this.moveAnimationLength,true,true);
var _dd=!res.dontMakeOpponentMove&&!_ce&&(this.currentMove&&this.currentMove.next&&!this.currentMove.next.atEnd);
if(clog){
if(_d8.next){
console.log("setting current move in updatepiece to:"+_d8.next.output());
}else{
console.log("in updatepiece, current move being set to null");
}
}
this.setCurrentMove(_d8.next,false,_dd);
if(this.currentMove.atEnd){
for(var i=0;i<this.registeredUpdateEndOfMovesListeners.length;i++){
var res=this.registeredUpdateEndOfMovesListeners[i].updateEndOfMovesCallback(_d4,_cb,col,row,_ce,_cf,_d0,_d1,_d2);
}
}
if(_dd){
opponentMove=this.currentMove;
if(this.currentMove&&this.currentMove.next.atEnd){
this.toggleToMove();
}
this.updatePiece(this.boardPieces[opponentMove.fromColumn][opponentMove.fromRow],opponentMove.toColumn,opponentMove.toRow,true,true,false);
}
}else{
var _d8=res.move;
var _de=_cb.column;
var _df=_cb.row;
this.board_xy=null;
_cb.setPosition(_cb.column,_cb.row,false,null,this.moveAnimationLength);
for(var i=0;i<this.registeredUpdateWrongMoveListeners.length;i++){
var res=this.registeredUpdateWrongMoveListeners[i].updateWrongMoveCallback(_d4,_cb,col,row,_ce,_cf,_d0,_d1,_d2,_d8);
}
}
for(var i=0;i<this.registeredUpdatePieceFinishedListeners.length;i++){
var _db=this.registeredUpdatePieceFinishedListeners[i].updatePieceFinishedCallback(_d4,_cb,col,row,_ce,_cf,_d0,_d1,_d2,_d3,this.currentMove,_d7);
}
};
Board.prototype.addGotoMoveIndexListener=function(_e0){
this.registeredGotoMoveIndexListeners.push(_e0);
};
Board.prototype.addBackMovePreCurrentListener=function(_e1){
this.registeredBackMovePreCurrentListeners.push(_e1);
};
Board.prototype.addForwardMovePostUpdateListener=function(_e2){
this.registeredForwardMovePostUpdateListeners.push(_e2);
};
Board.prototype.addUpdatePieceListener=function(_e3){
this.registeredUpdateListeners.push(_e3);
};
Board.prototype.addUpdatePieceFinishedListener=function(_e4){
this.registeredUpdatePieceFinishedListeners.push(_e4);
};
Board.prototype.addUpdatePieceEndOfMovesListener=function(_e5){
this.registeredUpdateEndOfMovesListeners.push(_e5);
};
Board.prototype.addUpdatePieceHaveAltListener=function(_e6){
this.registeredUpdateHaveAltListeners.push(_e6);
};
Board.prototype.addUpdatePieceAllowMoveListener=function(_e7){
this.registeredUpdateAllowMoveListeners.push(_e7);
};
Board.prototype.addUpdatePieceWrongMoveListener=function(_e8){
this.registeredUpdateWrongMoveListeners.push(_e8);
};
Board.prototype.scoreToShortString=function(_e9){
if(_e9=="draw"){
return "D";
}
if(_e9>=0){
return "M"+_e9;
}else{
return "L"+(-1*_e9);
}
};
Board.prototype.scoreToLongString=function(_ea){
if(_ea=="draw"){
return _js("Draw");
}
if(_ea==0){
return _js("Mate");
}else{
if(_ea>0){
return __js("Mate in {NUMBER_MOVES}",[["NUMBER_MOVES",_ea]]);
}else{
return __js("Lose in {NUMBER_MOVES}",[["NUMBER_MOVES",(-1*_ea)]]);
}
}
};
Board.prototype.egMoveToScoreString=function(_eb){
var _ec=_eb.score;
var _ed=_eb.optimal_score;
var s=this.scoreToShortString(_ec);
var opt=this.scoreToShortString(_ed);
var _f0=this.scoreToLongString(_ec);
var _f1=this.scoreToLongString(_ed);
if(_ec==_ed){
return ["",_f0];
}else{
var _f2="ct-subopt-move-score";
if(_ec=="draw"||_ec<0){
_f2="ct-bad-move-score";
}
return ["<span class=\""+_f2+"\">"+s+"("+opt+")</span>",_f0+"("+_f1+")"];
}
};
Board.prototype.makeShortAlgabraic=function(_f3,_f4,_f5,_f6,_f7){
if(clog){
console.log("fromCol:"+_f3+" fromRow:"+_f4+" toCol:"+_f5+" toRow:"+_f6);
}
var _f8=this.boardPieces[_f3][_f4];
var _f9=_f8.piece;
var _fa=ChessPiece.pieceTypeToChar(_f9);
var _fb="";
if(_f9==ChessPiece.PAWN){
if(_f3==_f5){
_fb=Move.columnToChar(_f3)+""+(_f6+1);
}else{
_fb=Move.columnToChar(_f3)+"x"+Move.columnToChar(_f5)+""+(_f6+1);
if(!this.boardPieces[_f5][_f6]){
_fb+=" e.p.";
}
}
}else{
if(_f9==ChessPiece.KING){
var _fc=Math.abs(_f3-_f5);
if(_fc==1||_fc==0){
_fb=_fa;
if(this.boardPieces[_f5][_f6]){
_fb+="x";
}
_fb+=Move.columnToChar(_f5)+""+(_f6+1);
}else{
if(_f5==6){
_fb="O-O";
}else{
_fb="O-O-O";
}
}
}else{
var _fd=[];
for(var row=0;row<8;row++){
for(var col=0;col<8;col++){
var cp=this.boardPieces[col][row];
if(cp&&cp.colour==_f8.colour&&cp.piece==_f9&&!(_f8.column==cp.column&&_f8.row==cp.row)){
var prev=null;
if(this.currentMove){
prev=this.currentMove.prev;
}
if(this.canMove(cp.makeLightWeight(),_f5,_f6,prev,true)){
_fd.push(cp);
}
}
}
}
_fb=_fa;
if(_fd.length>0){
var _102=false;
var _103=false;
for(var i=0;i<_fd.length;i++){
if(_fd[i].row==_f4){
_103=true;
}
if(_fd[i].column==_f3){
_102=true;
}
}
if(_103||!(_103||_102)){
_fb+=Move.columnToChar(_f3);
}
if(_102){
_fb+=""+(_f4+1);
}
}
if(this.boardPieces[_f5][_f6]){
_fb+="x";
}
_fb+=Move.columnToChar(_f5)+""+(_f6+1);
}
}
var _105="";
var _106="";
if(_f7){
var _107=this.cloneBoard();
var _108=ChessPiece.WHITE;
if(_107.boardPieces[_f7.fromColumn][_f7.fromRow].colour==ChessPiece.WHITE){
_108=ChessPiece.BLACK;
}
_107.makeMove(_f7,_107.boardPieces[_f7.fromColumn][_f7.fromRow],false,_107.moveAnimationLength,false,false);
if(!_107.isKingSafe(_108,_f7)){
_105="+";
if(_107.isKingMated(_108,_f7)){
_105="#";
}
}
if(_f7.promotion){
_106="="+((_f7.promotion+"").toUpperCase());
}
}
_fb+=_106+_105;
return _fb;
};
Board.getVarMove=function(move,row,col,_10c,_10d){
if(move.vars&&move.vars.length>0){
var i=0;
for(var i=0;i<move.vars.length;i++){
var _10f=move.vars[i];
if(_10f.fromColumn==_10c.column&&_10f.fromRow==_10c.row&&_10f.toRow==row&&_10f.toColumn==col&&(_10d==""||(_10d==_10f.promotion))){
return _10f;
}
}
}
};
Board.prototype.createMoveFromString=function(_110){
var _111=0;
var take=false;
var _113=null;
var _114=_110.charCodeAt(_111++);
var _115=_110.charCodeAt(_111++);
var _116=_110.split("|");
var pgn=null;
if(_116.length>1){
pgn=_116[1];
_110=_116[0];
}else{
_110=_116[0];
}
if(_110.charAt(_111)=="x"){
_111++;
take=true;
}
var _118=_110.charCodeAt(_111++);
var _119=_110.charCodeAt(_111++);
if(_111<_110.length){
_113=_110.charAt(_111);
}
var move=new Move(_114-("a".charCodeAt(0)),_115-("1".charCodeAt(0)),_118-("a".charCodeAt(0)),_119-("1".charCodeAt(0)),take,_113,_110);
move.pgn=pgn;
return move;
};
Board.prototype.getBackButton=function(){
if(!this.backButton){
this.backButton=YAHOO.util.Dom.get(this.boardName+"-back");
}
return this.backButton;
};
Board.prototype.getForwardButton=function(){
if(!this.forwardButton){
this.forwardButton=YAHOO.util.Dom.get(this.boardName+"-forward");
}
return this.forwardButton;
};
Board.prototype.getEndButton=function(){
if(!this.endButton){
this.endButton=YAHOO.util.Dom.get(this.boardName+"-end");
}
return this.endButton;
};
Board.prototype.getStartButton=function(){
if(!this.startButton){
this.startButton=YAHOO.util.Dom.get(this.boardName+"-start");
}
return this.startButton;
};
Board.prototype.setForwardBack=function(){
var back=this.getBackButton();
var _11c=this.getForwardButton();
var end=this.getEndButton();
var _11e=this.getStartButton();
if(!this.currentMove){
if(back){
back.src=this.boardImagePath+"/images/resultset_previous_disabled"+this.getVersString()+".gif";
}
if(_11e){
_11e.src=this.boardImagePath+"/images/disabled_resultset_first"+this.getVersString()+".gif";
}
if(_11c){
_11c.src=this.boardImagePath+"/images/resultset_next_disabled"+this.getVersString()+".gif";
}
if(end){
end.src=this.boardImagePath+"/images/disabled_resultset_last"+this.getVersString()+".gif";
}
return;
}
if(this.currentMove.prev==null){
if(back){
back.src=this.boardImagePath+"/images/resultset_previous_disabled"+this.getVersString()+".gif";
}
if(_11e){
_11e.src=this.boardImagePath+"/images/disabled_resultset_first"+this.getVersString()+".gif";
}
}else{
if(back){
back.src=this.boardImagePath+"/images/resultset_previous"+this.getVersString()+".gif";
}
if(_11e){
_11e.src=this.boardImagePath+"/images/resultset_first"+this.getVersString()+".gif";
}
}
if(this.currentMove.atEnd){
if(_11c){
_11c.src=this.boardImagePath+"/images/resultset_next_disabled"+this.getVersString()+".gif";
}
if(end){
end.src=this.boardImagePath+"/images/disabled_resultset_last"+this.getVersString()+".gif";
}
}else{
if(_11c){
_11c.src=this.boardImagePath+"/images/resultset_next"+this.getVersString()+".gif";
}
if(end){
end.src=this.boardImagePath+"/images/resultset_last"+this.getVersString()+".gif";
}
}
};
Board.prototype.convertPiecesFromLightWeight=function(_11f){
var _120=this.settingUpPosition;
this.settingUpPosition=true;
for(var i=0;i<8;i++){
for(var j=0;j<8;j++){
if(this.boardPieces[i][j]!=null){
var _123=this.boardPieces[i][j];
var p=_123.makeHeavyWeight();
this.boardPieces[i][j]=p;
p.setPosition(p.column,p.row,false,null,this.moveAnimationLength);
p.setVisible(true);
}
}
}
var move=this.moveArray[_11f];
while(move!=null){
if(move.taken){
move.taken=move.taken.makeHeavyWeight();
}
move=move.prev;
}
this.settingUpPosition=_120;
};
MovesDisplay.prototype.setToMove=function(_126){
this.toMove=_126;
};
MovesDisplay.prototype.gotoMove=function(e){
if(this.board.tactics&&this.board.tactics.problemActive){
return;
}
var t=e.currentTarget?e.currentTarget:e.targetElement?e.targetElement:false;
if(!t){
t=YAHOO.util.Event.getTarget(e);
}
if(!t.id){
t=t.parentNode;
}
var _129=t.id.substr((this.board.boardName+"-m").length);
if(clog){
console.log("got goto move index:"+_129);
}
this.board.gotoMoveIndex(_129,false,false,false,false);
if(this.board.problem){
if(this.board.currentMove.bestMoves){
this.board.problem.showBestMoves(this.board.currentMove,this.board.currentMove.bestMoves,this.board.currentMove.correctMove,this.board.currentMove.wrongMove);
}else{
this.board.problem.clearBestMoves();
}
}
};
MovesDisplay.prototype.getMovesDisplay=function(){
if(!this.cachedMovesDisplay&&!this.allreadyCachedMovesDisplay){
this.cachedMovesDisplay=YAHOO.util.Dom.get(this.board.boardName+"-moves");
this.allreadyCachedMovesDisplay=true;
}
return this.cachedMovesDisplay;
};
MovesDisplay.prototype.outputVariationStart=function(_12a,_12b,_12c,_12d){
var _12e="";
if(_12b>this.board.ml){
return _12e;
}
if(this.board.ml==1&&_12d>1){
return _12e;
}
var _12f=this.getMovesDisplay();
if(_12f){
if(_12a==0&&this.displayType==MovesDisplay.MAIN_ON_OWN_LINE){
if(this.firstNonMove){
_12e+="<div class=\"ct-mainline-commentary\"/>";
this.pendingLevelZeroCommentaryClose=true;
}
}
if(this.variationOnOwnLine){
_12e+="<br/>";
}
if(this.board.showBracketsOnVariation&&(!this.board.hideBracketsOnTopLevelVariation||_12a>0)){
_12e+="<span>"+this.board.variationStartString+"</span>";
}
}
this.firstNonMove=false;
return _12e;
};
MovesDisplay.prototype.outputVariationEnd=function(_130,_131,_132,_133){
var _134=this.getMovesDisplay();
var _135="";
if(this.board.ml==1&&_131>0&&this.board.outputFirstVar){
return _135;
}
this.board.outputFirstVar=true;
if(_134){
if(this.board.showBracketsOnVariation&&(!this.board.hideBracketsOnTopLevelVariation||_130>1)){
_135+="<span>"+this.board.variationEndString+"</span>";
}
}
if(_130==1&&this.displayType==MovesDisplay.MAIN_ON_OWN_LINE){
}
this.firstNonMove=false;
return _135;
};
MovesDisplay.prototype.outputComment=function(_136,_137,_138){
if(this.board.ignoreCommentRegex){
var _139=new RegExp(this.board.ignoreCommentRegex);
if(_139.test(_136)){
return "";
}
}
var _13a="";
if(this.board.ml==1){
return _13a;
}
var _13b=this.getMovesDisplay();
if(_13b){
if(_137==0&&this.displayType==MovesDisplay.MAIN_ON_OWN_LINE){
if(this.firstNonMove){
_13a+="<br/>";
}
_13a+="<div class=\"ct-mainline-commentary\">";
this.pendingLevelZeroCommentaryClose=true;
}
var _13c="ct-board-move-comment";
if(_138){
_13c="ct-board-move-alt-comment";
}
_13a+="<span class=\""+_13c+"\"> "+_136+" </span>";
if(_137==0&&this.displayType==MovesDisplay.MAIN_ON_OWN_LINE){
}
}
this.firstNonMove=false;
return _13a;
};
MovesDisplay.prototype.outputNag=function(_13d){
var _13e="";
var _13f=this.getMovesDisplay();
if(_13f){
var _140=null;
switch(_13d){
case 11:
_140="=";
break;
case 14:
_140="+=";
break;
case 15:
_140="=+";
break;
case 16:
_140="+/-";
break;
case 17:
_140="-/+";
break;
case 18:
_140="+-";
break;
case 19:
_140="-+";
break;
case 20:
_140="+--";
break;
case 21:
_140="--+";
break;
default:
}
if(_140){
_13e+="<span> "+_140+" </span>";
}
}
return _13e;
};
MovesDisplay.prototype.outputResult=function(_141){
return "<span class=\"ct-result\">"+_141+"</span>";
};
MovesDisplay.prototype.outputMove=function(_142,_143,_144,_145,_146,_147,_148,move,_14a,_14b){
if(clog){
console.log("outputMove:"+_145+" hideScore:"+_14a);
}
var _14c="";
var _14d=this.getMovesDisplay();
if(this.board.tr&&_143>0&&(_147>1||_148>3)&&!_146){
return _14c;
}
if(this.board.ml==1&&_147>0&&this.board.outputFirstVar){
return _14c;
}
if(_14d){
var _14e=""+Math.round(_144/2)+". ";
if(_144%2!=1){
if(clog){
console.log("firstRav:"+_146+" firstNonMove:"+this.firstNonMove);
}
if(_146||!this.firstNonMove){
_14e=Math.round(_144/2)+"... ";
}else{
_14e="";
}
}
if(clog){
console.log("moveNum:"+_144+" moveNumOut:"+_14e);
}
if(this.displayType==MovesDisplay.MAIN_ON_OWN_LINE&&_143==0&&(!this.firstNonMove||_144%2==1)){
if(this.pendingLevelZeroCommentaryClose){
this.pendingLevelZeroCommentaryClose=false;
_14c+="</div>";
}
if(this.board.newlineForEachMainMove){
_14c+="<br/>";
}
}
var _14f="";
var _150="";
if(move&&move.eg_move){
var res=this.board.egMoveToScoreString(move.eg_move);
_14f=res[0];
_150=res[1];
}
var _152="";
if(_14a){
_152="initially_hidden";
}
if(_14f!=""){
_14f=" "+_14f;
}
var _153="title";
if(_14a){
_153="alt";
}
var _154="";
if(_14b){
_154=" rel=\""+_145+"\" ";
_145="___";
}
_14c+="<span "+_154+_153+"=\""+_150+"\" id=\""+this.board.boardName+"-m"+_142+"\" class=\""+((_143==0)?"ct-board-move-mainline":"ct-board-move-variation")+"\">"+_14e+_145+"<span id=\""+this.board.boardName+"-msc"+_142+"\" class=\""+_152+"\">"+_14f+"</span></span>";
}
this.firstNonMove=true;
return _14c;
};
Board.prototype.setMoveSeqLalg=function(_155,_156,_157,_158){
var _159=new Array();
if(_155&&_155.length>0){
_159=_155.replace(/\s+$/g,"").split(" ");
}
this.setupFromLalgArray(_159,_158,_157,_156);
};
Board.prototype.setupFromLalgArray=function(_15a,_15b,_15c,_15d){
this.outputFirstVar=false;
if(this.movesDisplay){
var md=this.movesDisplay.getMovesDisplay();
if(md){
YAHOO.util.Event.purgeElement(md,true);
}
}
if(!_15d){
_15d=new Array();
}
var _15f=this.cloneBoard();
this.movesDisplay.firstNonMove=false;
var _160=new Array();
var _161=new Array();
if(this.prev_move){
_15f.makeMove(this.prev_move,_15f.boardPieces[this.prev_move.fromColumn][this.prev_move.fromRow],false,_15f.moveAnimationLength,false,false);
}
var _162=_15f.cloneBoard();
var _163=null;
var _164=0;
var _165="";
var _166=false;
var _167=false;
var _168=0;
var _169=false;
var _16a=new Array();
var _16b=new Array();
_16b[0]=0;
var _16c=new Array();
var _16d=new Array();
var _16e=_15c*2-1;
var _16f=_15c*2-1;
var _170=new Array();
var _171=ChessPiece.WHITE;
var _172=0;
var eval="";
var _174="";
var _175="";
var time="";
var _177=-1;
var _178=0;
for(var i=0;i<_15a.length;i++){
var _17a=0;
if(_15a[i]=="ALT"){
_167=true;
continue;
}
if(_15a[i].indexOf("EVAL")==0){
eval=_15a[i].split(":")[1];
if(parseInt(eval)>=175&&_168>0&&_16b[_168]>1){
_167=true;
}
continue;
}
if(_15a[i].indexOf("DEPTH")==0){
_174=_15a[i].split(":")[1];
continue;
}
if(_15a[i].indexOf("NODES")==0){
_175=_15a[i].split(":")[1];
continue;
}
if(_15a[i].indexOf("TIME")==0){
time=_15a[i].split(":")[1];
var e=eval;
if(eval.indexOf("mate")!=0){
e=(parseFloat(eval)/100).toFixed(2);
if(e>0){
e="+"+e;
}
}else{
e=e.replace(/_/," ");
var _17c=e.split(" ");
_17a=parseInt(_17c[1]);
e=_js("mate")+" "+_17c[1];
if(_16b[_168]==1){
_177=_17a;
}
}
_178=_17a;
if(_17a<0){
_167=false;
}else{
if(_17a>0&&_17a<8&&_168>0&&_16b[_168]>1){
_167=true;
}
}
var _17d="";
if(_167){
_17d=_js("ALT")+" ";
}
var t=parseInt(time);
var nps=" "+__js("nps:{NODES_PER_SECOND}",[["NODES_PER_SECOND",Math.round(parseInt(_175)/(parseInt(time)/1000))]]);
if(!this.showNPS){
nps="";
}
if(!(_168>0&&_16b[_168]>this.ml)){
_15a[i]=_17d+e+" ("+__js("depth:{DEPTH}",[["DEPTH",_174]])+nps+")";
}else{
_15a[i]="";
}
}
if(_15a[i]=="}"){
_166=false;
if(this.movesDisplay){
_165=_165.replace(/\s+$/g,"");
_170.push(this.movesDisplay.outputComment(_165,_168,_167));
}
continue;
}else{
if(_166){
_165+=_15a[i]+" ";
continue;
}else{
if(_15a[i]=="{"){
_165="";
_166=true;
continue;
}else{
if(_15a[i]=="("){
if(!_16b[_168+1]){
_16b[_168+1]=0;
}
_16b[_168+1]++;
if(this.movesDisplay){
_170.push(this.movesDisplay.outputVariationStart(_168,_16b[_168+1],_16e,_16a[0]));
}
_16a[_168]=_16e;
_16c[_168]=_163;
_16d[_168]=_171;
_160[_168]=_15f;
_161[_168]=_162;
_15f=_162.cloneBoard();
_168++;
_16e--;
_169=true;
continue;
}else{
if(_15a[i]==")"){
if(this.movesDisplay){
_170.push(this.movesDisplay.outputVariationEnd(_168,_16b[_168],_16e,_16a[0]));
}
var _180=new Move();
_180.atEnd=true;
_163.next=_180;
_180.prev=_163;
_168--;
_16e=_16a[_168];
_163=_16c[_168];
_171=_16d[_168];
_15f=_160[_168];
_162=_161[_168];
_167=false;
continue;
}else{
if(_15a[i].charAt(0)=="$"){
if(this.movesDisplay){
_170.push(this.movesDisplay.outputNag(parseInt(_15a[i].substring(1))));
}
continue;
}
}
}
}
}
}
var move=this.createMoveFromString(_15a[i]);
var _182=false;
if(_16e==_16f&&this.boardPieces[move.fromColumn][move.fromRow].colour==ChessPiece.BLACK){
_16e++;
_182=true;
_171=ChessPiece.BLACK;
}
move.index=_164;
var _183=(move.pgn)?move.pgn:move.moveString;
if(move.pgn){
_183=move.pgn;
}else{
_183=_15f.makeShortAlgabraic(move.fromColumn,move.fromRow,move.toColumn,move.toRow,move);
move.SAN=_183;
}
_183=this.moveToLocale(_183);
if(this.movesDisplay){
this.movesDisplay.setToMove(_171);
_170.push(this.movesDisplay.outputMove(_164,_168,_16e,_183+" ",_169,_16b[_168],_16a[0]));
}
_171=(_171==ChessPiece.BLACK)?ChessPiece.WHITE:ChessPiece.BLACK;
move.moveNum=_16e;
_16e++;
if(_168>0){
if(_169){
var _184=_163;
if(_184==null){
alert("Got no previous move for variation:"+movesArra[i]);
}
if(_184.numVars==0){
_184.vars=new Array();
}
move.isAlt=_167;
move.mateInMoves=_178;
_184.vars[_184.numVars++]=move;
move.prev=_184.prev;
_169=false;
}else{
move.prev=_163;
if(_163!=null){
_163.next=move;
}
}
}else{
move.prev=_163;
if(_163!=null){
_163.next=move;
}
}
_16b[_168+1]=0;
if(_168==0){
_172=_164;
}
_15d[_164++]=move;
_15f.moveArray[_164-1]=move;
_163=move;
_162=_15f.cloneBoard();
_15f.makeMove(move,_15f.boardPieces[move.fromColumn][move.fromRow],false,_15f.moveAnimationLength,false,false);
}
if(this.movesDisplay&&!this.disableMoveOutput){
var _185=this.movesDisplay.getMovesDisplay();
_170.push(this.movesDisplay.outputResult(_15b));
this.pendingMovesOutput=_170.join("");
this.pendingMovesOutputCount=_164;
}
this.lastMoveIndex=_172;
if(_163!=null){
var _180=new Move();
_180.atEnd=true;
_163.next=_180;
_180.prev=_163;
}
this.lastCount=_164;
};
Board.prototype.lalgToMoveList=function(_186,_187,_188,_189){
if(ctime){
console.time("lalgToMoveList");
}
if(clog){
console.log("startMoveNum:"+_188);
}
if(!_189){
_189=new Array();
}
var _18a=this.cloneBoard();
var _18b=new Array();
var _18c=new Array();
if(this.prev_move){
_18a.makeMove(this.prev_move,_18a.boardPieces[this.prev_move.fromColumn][this.prev_move.fromRow],false,_18a.moveAnimationLength,false,false);
}
var _18d=_18a.cloneBoard();
var nags=[];
var _18f=null;
var _190=0;
var _191="";
var _192=false;
var _193=0;
var _194=false;
var _195=new Array();
var _196=new Array();
_196[0]=0;
var _197=new Array();
var _198=new Array();
var _199=_188*2-1;
var _19a=new Array();
var _19b=ChessPiece.WHITE;
var _19c=0;
var _19d=true;
for(var i=0;i<_186.length;i++){
if(_186[i]=="}"){
_192=false;
_191=_191.replace(/\s+$/g,"");
continue;
}else{
if(_192){
_191+=_186[i]+" ";
continue;
}else{
if(_186[i]=="{"){
if(_191){
if(_18f){
_18f.afterComment=trimStr(_191);
}
}
_191="";
_192=true;
continue;
}else{
if(_186[i]=="("){
if(_18f){
_18f.afterComment=trimStr(_191);
_191="";
}
if(!_196[_193+1]){
_196[_193+1]=0;
}
_196[_193+1]++;
_195[_193]=_199;
_197[_193]=_18f;
_198[_193]=_19b;
_18b[_193]=_18a;
_18c[_193]=_18d;
_18a=_18d.cloneBoard();
_193++;
_199--;
_194=true;
continue;
}else{
if(_186[i]==")"){
if(_18f){
_18f.afterComment=trimStr(_191);
_191="";
}
var _19f=new Move();
_19f.atEnd=true;
_18f.next=_19f;
_19f.prev=_18f;
_193--;
_199=_195[_193];
_18f=_197[_193];
_19b=_198[_193];
_18a=_18b[_193];
_18d=_18c[_193];
continue;
}else{
if(_186[i].charAt(0)=="$"){
nags.push(parseInt(_186[i].substring(1)));
continue;
}
}
}
}
}
}
var move=this.createMoveFromString(_186[i]);
move.nags=nags;
move.beforeComment=trimStr(_191);
_191=null;
nags=[];
if(_19d){
if(this.boardPieces[move.fromColumn][move.fromRow].colour==ChessPiece.BLACK){
_199++;
_19b=ChessPiece.BLACK;
if(clog){
console.log("first move black new movenum:"+_199);
}
}
_19d=false;
}
move.index=_190;
var _1a1=(move.pgn)?move.pgn:move.moveString;
if(move.pgn){
_1a1=move.pgn;
move.SAN=move.pgn;
}else{
_1a1=_18a.makeShortAlgabraic(move.fromColumn,move.fromRow,move.toColumn,move.toRow,move);
move.SAN=_1a1;
}
_19b=(_19b==ChessPiece.BLACK)?ChessPiece.WHITE:ChessPiece.BLACK;
move.moveNum=_199;
_199++;
if(_193>0){
if(_194){
var _1a2=_18f;
if(_1a2==null){
alert("Got no previous move for variation:"+movesArra[i]);
}
if(_1a2.numVars==0){
_1a2.vars=new Array();
}
_1a2.vars[_1a2.numVars++]=move;
move.prev=_1a2.prev;
_194=false;
}else{
move.prev=_18f;
if(_18f!=null){
_18f.next=move;
}
}
}else{
move.prev=_18f;
if(_18f!=null){
_18f.next=move;
}
}
_196[_193+1]=0;
if(_193==0){
_19c=_190;
}
_189[_190++]=move;
_18a.moveArray[_190-1]=move;
_18f=move;
_18d=_18a.cloneBoard();
_18a.makeMove(move,_18a.boardPieces[move.fromColumn][move.fromRow],false,_18a.moveAnimationLength,false,false);
}
if(_18f!=null){
var _19f=new Move();
_19f.atEnd=true;
_18f.next=_19f;
_19f.prev=_18f;
_18f.afterComment=trimStr(_191);
}
if(ctime){
console.timeEnd("lalgToMoveList");
}
return _189;
};
Board.prototype.insertMovesFromMoveList=function(_1a3,_1a4,_1a5){
var _1a6=!_1a4;
if(ctime&&_1a6){
console.time("insertMovesFromMoveList");
}
if(!this.movesDisplay){
return;
}
if(_1a6){
YAHOO.util.Event.purgeElement(this.movesDisplay.getMovesDisplay(),true);
this.movesDisplay.firstNonMove=false;
var _1a7=this.movesDisplay.getMovesDisplay();
if(_1a7){
_1a7.innerHTML="";
}
this.currentMove=null;
_1a3.prev=null;
this.startMoveNum=_1a3.moveNum;
this.moveIndex=-1;
}
var _1a8=0;
var _1a9=_1a3.moveNum;
var move=_1a3;
while(move!=null&&!move.atEnd){
if(clog){
console.log("move:"+move.output());
}
var _1ab=move.next;
if(clog){
if(this.currentMove){
console.log("current move:"+this.currentMove.output());
}else{
console.log("no current move");
}
if(_1ab){
console.log("next move:"+_1ab.output());
}else{
console.log("no next move");
}
}
if(_1a6||_1a3!=move||_1a5==null){
if(clog){
console.log("about to call insertmoveafter");
}
this.insertMoveAfter(this.currentMove,move);
if(clog){
console.log("finished call to insertmoveafter");
}
}else{
if(clog){
console.log("about to replace variationParent:"+_1a5.output()+" with move:"+move.output()+" and board:"+this.boardToFen());
}
this.replaceMove(_1a5,move,true,true);
}
if(move.beforeComment){
this.insertCommentIntoMoveDisplay(move,move.beforeComment,false);
}
if(move.afterComment){
this.insertCommentIntoMoveDisplay(move,move.afterComment,true);
}
if(clog){
console.log("about to make move:"+move.output()+" with board pos:"+this.boardToFen());
}
this.makeMove(move,this.boardPieces[move.fromColumn][move.fromRow],false,this.moveAnimationLength,false,false);
if(clog){
console.log("made move");
}
this.setCurrentMove(move,true,true);
if(move.numVars>0){
var _1ac=move.index;
var bm=move.prev;
var _1ae=-1;
if(bm){
_1ae=bm.index;
}
var _1af=move.numVars;
var vars=move.vars;
move.numVars=0;
move.vars=[];
for(var i=0;i<_1af;i++){
this.gotoMoveIndex(_1ae,true,true,true,true);
if(clog){
console.log("about to call insertMovesFromMoveList with head of variation");
}
this.insertMovesFromMoveList(vars[i],true,move);
if(clog){
console.log("about to reset currentMoveIndex  after variation insert:"+_1ac);
}
}
this.gotoMoveIndex(_1ac,true,true,true,true);
this.backMove();
var cm=this.currentMove;
this.makeMove(cm,this.boardPieces[cm.fromColumn][cm.fromRow],false,this.moveAnimationLength,false,false);
if(clog){
if(this.currentMove){
console.log("popped up from variation, current set back to:"+this.currentMove.output());
}else{
console.log("popped up from variation, current set to null");
}
}
}
move=_1ab;
}
if(_1a6){
this.gotoMoveIndex(-1,false,false,false,false);
}
if(clog){
var m=this.currentMove;
while(m){
console.log("m:"+m.output());
m=m.next;
}
}
if(ctime&&_1a6){
console.timeEnd("insertMovesFromMoveList");
}
};
Board.prototype.setupFromLalgArrayIncremental=function(_1b4,_1b5,_1b6,_1b7){
this.outputFirstVar=false;
if(this.movesDisplay&&this.lastCount){
for(var i=0;i<this.lastCount;i++){
var mv=YAHOO.util.Dom.get(this.boardName+"-m"+i);
if(mv){
YAHOO.util.Event.purgeElement(mv);
}
}
}
var _1ba=0;
var _1bb=_1b6*2-1;
var _1bc="";
var _1bd=false;
var _1be=false;
var _1bf=ChessPiece.WHITE;
var _1c0=false;
var _1c1=true;
this.currentMove=null;
for(var i=0;i<_1b4.length;i++){
if(_1b4[i]=="}"){
_1c0=false;
if(this.movesDisplay){
_1bc=_1bc.replace(/\s+$/g,"");
}
continue;
}else{
if(_1c0){
_1bc+=_1b4[i]+" ";
continue;
}else{
if(_1b4[i]=="{"){
_1bc="";
_1c0=true;
continue;
}else{
if(_1b4[i]=="("){
_1bd=true;
continue;
}else{
if(_1b4[i]==")"){
_1be=true;
continue;
}else{
if(_1b4[i].charAt(0)=="$"){
continue;
}
}
}
}
}
}
var move=this.createMoveFromString(_1b4[i]);
var _1c3=false;
if(_1c1&&this.boardPieces[move.fromColumn][move.fromRow].colour==ChessPiece.BLACK){
_1bb++;
_1c3=true;
_1bf=ChessPiece.BLACK;
}
this.startMoveNum=_1bb;
_1c1=false;
move.index=_1ba++;
var _1c4=move.moveString;
_1c4=this.moveToLocale(_1c4);
_1bf=(_1bf==ChessPiece.BLACK)?ChessPiece.WHITE:ChessPiece.BLACK;
this.insertMoveAfter(this.currentMove,move);
if(clog){
if(move.prev){
if(move.prev.next){
console.log("move.prev.next:"+move.prev.next.output());
}else{
console.log("move.prev:"+move.prev.output()+" next null");
}
}
}
this.makeMove(move,this.boardPieces[move.fromColumn][move.fromRow],false,this.moveAnimationLength,false,false);
this.setCurrentMove(move);
}
this.gotoMoveIndex(-1,false,false,false,false);
};
Board.prototype.displayPendingMoveList=function(){
if(this.pendingMovesOutput&&this.movesDisplay){
var _1c5=this.movesDisplay.getMovesDisplay();
if(_1c5){
_1c5.innerHTML=this.pendingMovesOutput;
var _1c6=new YAHOO.util.Scroll(_1c5,{scroll:{to:[0,0]}},0);
_1c6.animate();
}
if(this.movesDisplay){
for(var i=0;i<this.pendingMovesOutputCount;i++){
var mv1=YAHOO.util.Dom.get(this.boardName+"-m"+i);
if(mv1){
YAHOO.util.Event.addListener(mv1,"click",this.movesDisplay.gotoMove,this.movesDisplay,true);
}
}
}
}
};
Board.prototype.setMoveSequence=function(_1c9,_1ca,_1cb,_1cc){
this.tacticMoveArray=new Array();
this.moveArray=this.tacticMoveArray;
this.setMoveSeqLalg(_1c9,this.tacticMoveArray,_1cb,_1cc);
this.tacticsmoveArrayLastMoveIndex=this.lastMoveIndex;
if(false&&_1ca!="NA"){
this.fullmoveArray=new Array();
this.disableMoveOutput=true;
this.setMoveSeqLalg(_1ca,this.fullmoveArray,_1cb,_1cc);
this.disableMoveOutput=false;
this.fullmoveArrayLastMoveIndex=this.lastMoveIndex;
}else{
this.fullmoveArray=null;
}
this.lastMoveIndex=this.tacticsmoveArrayLastMoveIndex;
};
Board.prototype.resetVariationsPreviousNodes=function(_1cd,_1ce){
if(_1cd.numVars>0){
for(var i=0;i<_1cd.numVars;i++){
_1cd.vars[i].prev=_1ce;
this.resetVariationsPreviousNodes(_1cd.vars[i],_1ce);
}
}
};
Board.prototype.reconnectNextNodeVariations=function(_1d0,_1d1){
if(!_1d1){
return;
}
if(_1d1.numVars>0){
for(var i=0;i<_1d1.numVars;i++){
_1d1.vars[i].prev=_1d0;
this.reconnectNextNodeVariations(_1d0,_1d1.vars[i]);
}
}
};
Board.prototype.findFirstMoveFromList=function(move){
var m=move;
while(m&&m.prev!=null){
m=m.prev;
}
return m;
};
Board.prototype.findVariationHeadFromMove=function(move){
var m=move;
while(m&&m.prev&&m.prev.next==m){
m=m.prev;
}
if(m&&m.prev&&m.prev.next!=m){
return m;
}else{
if(m&&!m.prev){
var _1d7=this.moveArray[0];
if(m!=_1d7){
return m;
}
}
return null;
}
};
Board.prototype.liftVariation=function(_1d8){
if(!_1d8){
return;
}
var _1d9=null;
var _1da=null;
if(_1d8.prev){
_1d9=_1d8.prev.next;
}else{
_1d9=this.moveArray[0];
_1da=_1d8;
}
var _1db=null;
if(this.currentMove&&this.currentMove.prev){
_1db=this.currentMove.prev;
}
if(_1d9){
var _1dc=_1d9.numVars;
var vars=_1d9.vars;
_1d9.numVars=0;
_1d9.vars=[];
if(_1d8.numVars==0){
_1d8.vars=[];
}
for(var i=0;i<_1dc;i++){
var _1df=vars[i];
if(clog){
console.log("processing var:"+_1df.output());
}
if(_1df==_1d8){
if(clog){
console.log("inserted parent var");
}
_1d8.vars.push(_1d9);
_1d8.numVars++;
}else{
_1d8.vars.push(_1df);
_1d8.numVars++;
}
}
if(_1d8.prev){
_1d8.prev.next=_1d8;
}
if(clog){
console.log("finished moving variations");
}
if(!_1da){
_1da=this.findFirstMoveFromList(_1d8);
}
this.moveArray[0]=_1da;
this.gotoMoveIndex(-1,true,true,true,true);
if(clog){
console.log("fm:"+_1da.output());
}
this.insertMovesFromMoveList(_1da);
}
if(_1db){
this.gotoMoveIndex(_1db.index);
}
};
Board.prototype.deleteMoveAndLine=function(move){
var m=move;
var oldM=m;
var _1e3=false;
var _1e4=null;
var _1e5=this.moveArray[0];
var _1e6=null;
if(clog){
console.log("delete line:"+move.output());
}
if(clog){
console.log("delete line prev:"+move.prev);
}
if(clog&&move.prev){
console.log("delete line prev.next:"+move.prev.next);
}
if(move&&move.prev&&move.prev.next!=move){
if(clog){
console.log("var is head and not front of move list");
}
_1e3=true;
_1e4=move.prev.next;
}else{
if(move&&!move.prev&&move!=this.moveArray[0]){
if(clog){
console.log("var is head and front of move list");
}
_1e3=true;
_1e4=this.moveArray[0];
}
}
if(clog){
console.log("isVariationHead:"+_1e3);
}
if(clog){
console.log("fm:"+_1e5.output());
}
var _1e7=m.prev;
if(_1e3){
_1e6=_1e4;
if(_1e4){
if(clog){
console.log("delete variation from parent:"+_1e4.output());
}
var _1e8=[];
for(var i=0;i<_1e4.numVars;i++){
if(!_1e4.vars[i]==oldM){
_1e8.push(_1e4.vars[i]);
}
}
_1e4.vars=_1e8;
_1e4.numVars=_1e8.length;
}
}else{
if(_1e7){
_1e7.next=null;
_1e6=_1e7;
}else{
if(clog){
console.log("deleting entire list");
}
if(this.movesDisplay){
this.movesDisplay.firstNonMove=false;
}
YAHOO.util.Event.purgeElement(this.movesDisplay.getMovesDisplay(),true);
var _1ea=this.movesDisplay.getMovesDisplay();
if(_1ea){
_1ea.innerHTML="";
}
this.currentMove=null;
this.startMoveNum=_1e5.moveNum;
if(clog){
console.log("startFen:"+this.startFen);
}
this.moveIndex=-1;
this.setupFromFen(this.startFen);
return;
}
}
this.moveArray[0]=_1e5;
this.gotoMoveIndex(-1,true,true,true,true);
if(clog){
console.log("fm:"+_1e5.output());
}
this.insertMovesFromMoveList(_1e5);
if(_1e6){
this.gotoMoveIndex(_1e6.index);
}
};
Board.prototype.insertMoveAfter=function(_1eb,_1ec,_1ed,_1ee,_1ef,_1f0){
addToMovelist=!_1ed;
if(clog){
console.log("addToMovelist:"+addToMovelist);
}
var _1f1="null";
if(_1eb){
_1f1=_1eb.output();
}
if(clog){
console.log("insert newMove:"+_1ec.output()+" after:"+_1f1);
}
if(_1eb==null){
this.currentMove=_1ec;
_1ec.atEnd=0;
_1ec.prev=null;
_1ec.next=null;
this.firstMove=_1ec;
if(this.startMoveNum>0){
this.currentMove.moveNum=this.startMoveNum;
}else{
if(this.toMove==ChessPiece.WHITE){
this.currentMove.moveNum=1;
}else{
this.currentMove.moveNum=2;
}
}
}else{
_1ec.atEnd=_1eb.atEnd;
_1ec.prev=_1eb;
_1eb.atEnd=0;
if(clog){
if(_1eb.next){
console.log("prevMove.next:"+_1eb.next.output());
}
}
if(_1ec.equals(_1eb.next)||_1ec.equals(_1eb)){
if(clog){
console.log("inserting move that already exists in variation:"+_1eb.next.output());
}
var _1f2=_1eb.next;
if(this.firstMove==_1f2){
this.firstMove=_1ec;
}
if(_1ec.equals(_1eb)){
_1f2=_1eb;
}
if(_1f2.prev&&(_1f2.prev.next==_1f2)){
_1f2.prev.next=_1ec;
}
if(_1f2.next){
_1f2.next.prev=_1ec;
}
addToMovelist=false;
_1ec.moveNum=_1f2.moveNum;
_1ec.ravLevel=_1f2.ravLevel;
_1ec.index=_1f2.index;
_1ec.fen=_1f2.fen;
_1ec.nextFen=_1f2.nextFen;
_1ec.bestMoves=_1f2.bestMoves;
_1ec.correctMove=_1f2.correctMove;
_1ec.wrongMove=_1f2.wrongMove;
_1ec.next=_1f2.next;
_1ec.vars=_1f2.vars;
_1ec.numVars=_1f2.numVars;
this.reconnectNextNodeVariations(_1ec,_1f2.next);
this.moveArray[_1ec.index]=_1ec;
if(this.currentMove==_1f2){
this.setCurrentMove(_1ec);
}
}else{
_1ec.moveNum=_1eb.moveNum+1;
_1ec.ravLevel=_1eb.ravLevel;
_1ec.next=_1eb.next;
if(_1ec.next){
_1ec.next.prev=_1ec;
}
}
_1eb.next=_1ec;
}
if(addToMovelist){
this.insertIntoMoveDisplay(_1eb,_1ec,_1ee,_1ef,_1f0);
}
if(_1ec.next==null){
var _1f3=this.createMoveFromString("i1i2");
_1ec.next=_1f3;
_1f3.prev=_1ec;
_1f3.moveNum=_1ec.moveNum+1;
_1f3.ravLevel=_1ec.ravLevel;
_1f3.next=null;
_1f3.atEnd=1;
_1f3.endNode=true;
if(clog){
console.log("created endmove node in insertAfterMove:"+_1f3.output());
}
}else{
if(clog){
console.log("allready had a node at end:"+_1ec.next.output());
}
_1ec.next.moveNum=_1ec.moveNum+1;
}
};
function insertBefore(node,_1f5){
if(_1f5){
_1f5.parentNode.insertBefore(node,_1f5);
}
}
function insertAfter(node,_1f7){
var _1f8=_1f7.parentNode;
_1f8.insertBefore(node,_1f7.nextSibling);
}
Board.prototype.replaceIntoMoveDisplay=function(_1f9,_1fa,_1fb,_1fc,_1fd){
var _1fe="null";
if(_1f9){
_1fe=_1f9.output();
}
if(clog){
console.log("replace display newMove:"+_1fa.output()+" after:"+_1fe+" hideScore:"+_1fc);
}
if(!_1f9){
if(clog){
console.log("null oldMove");
}
this.insertIntoMoveDisplay(null,_1fa,false,_1fc);
}else{
if(clog){
console.log("about to get movesdsiplay in replace into move display:"+this.movesDisplay);
}
var _1ff=this.movesDisplay.getMovesDisplay();
if(clog){
console.log("got moves display");
}
if(!_1ff){
if(clog){
console.log("no movesd disiplay in replace into move display");
}
return;
}
var san=_1fa.SAN;
if(!san){
if(clog){
console.log("about to make san");
}
san=this.makeShortAlgabraic(_1fa.fromColumn,_1fa.fromRow,_1fa.toColumn,_1fa.toRow,_1fa);
if(clog){
console.log("about to made san:"+san);
}
_1fa.SAN=san;
}
if(clog){
console.log("oldMove.index:"+_1f9.index);
}
var _201=this.boardName+"-ms"+_1f9.index;
if(clog){
console.log("oldMoveId:"+_201);
}
var _202=YAHOO.util.Dom.get(_201);
if(_1fb){
this.moveIndex++;
_1fa.index=this.moveIndex;
this.moveArray[this.moveIndex]=_1fa;
if(clog){
console.log("replace as variation old:"+_1f9.output()+" new:"+_1fa.output());
}
var _203=document.createElement("span");
var _204=this.movesDisplay.outputVariationStart(0,0,_1fa.moveNum,0);
_1fa.ravLevel=_1f9.ravlevel+1;
var _1fe=this.moveToLocale(san);
if(_1fa.prev==null){
this.movesDisplay.firstNonMove=false;
}
var _205=this.movesDisplay.outputMove(this.moveIndex,_1fa.ravLevel,_1fa.moveNum,_1fe,_1fb,0,_1fa.moveNum,_1fa,_1fc,_1fd);
var _206=document.createElement("span");
_206.id=(this.boardName+"-ms"+_1fa.index);
_206.innerHTML=_205+"&nbsp;";
var _207=this.movesDisplay.outputVariationEnd(0,0,_1fa.moveNum,0);
this.movesDisplay.firstNonMove=true;
var _208=document.createElement("span");
_208.innerHTML=_204;
var _209=document.createElement("span");
_209.innerHTML=_207;
_203.appendChild(_208);
_203.appendChild(_206);
_203.appendChild(_209);
_202.appendChild(_203);
}else{
_1fa.index=_1f9.index;
this.moveArray[_1fa.index]=_1fa;
var _1fe=this.moveToLocale(san);
if(_1fa.prev==null){
this.movesDisplay.firstNonMove=false;
}
var _205=this.movesDisplay.outputMove(_1fa.index,_1fa.ravLevel,_1fa.moveNum,_1fe,_1fb,0,_1fa.moveNum,_1fa,_1fc,_1fd);
var _206=document.createElement("span");
_206.innerHTML=_205+"&nbsp;";
_206.id=(this.boardName+"-ms"+_1fa.index);
var _20a=[];
if(_202&&_202.childNodes){
for(var i=1;i<_202.childNodes.length;i++){
_20a[i-1]=_202.childNodes[i];
}
}
if(clog){
console.log("replace as main line not variation old:"+_1f9.output()+" new:"+_1fa.output());
}
_202.parentNode.replaceChild(_206,_202);
if(_20a){
for(var i=0;i<_20a.length;i++){
_206.appendChild(_20a[i]);
}
}
}
YAHOO.util.Event.removeListener(this.boardName+"-m"+_1fa.index);
YAHOO.util.Event.addListener((this.boardName+"-m"+_1fa.index),"click",this.movesDisplay.gotoMove,this.movesDisplay,true);
}
};
Board.prototype.insertCommentIntoMoveDisplay=function(move,_20d,_20e){
var _20f=this.movesDisplay.getMovesDisplay();
if(!_20f){
return;
}
var _210="b";
if(_20e){
_210="a";
}
if(move){
var _211=this.boardName+"-mc"+_210+move.index;
var _212=YAHOO.util.Dom.get(_211);
var _213=false;
if(!_212){
_212=document.createElement("span");
_212.id=_211;
_213=true;
}
_212.innerHTML=this.movesDisplay.outputComment(_20d,0);
var _214=YAHOO.util.Dom.get((this.boardName+"-m"+move.index));
if(_214){
if(_20e){
move.afterComment=_20d;
if(_213){
insertAfter(_212,_214);
}
}else{
move.beforeComment=_20d;
if(_213){
insertBefore(_212,_214);
}
}
}
}else{
}
};
Board.prototype.insertIntoMoveDisplay=function(_215,_216,_217,_218,_219){
var _21a=this.movesDisplay.getMovesDisplay();
if(!_21a){
return;
}
var _21b="null";
if(_215){
_21b=_215.output();
}
if(clog){
console.log("insert display newMove:"+_216.output()+" after:"+_21b);
}
var san=_216.SAN;
if(!san){
san=this.makeShortAlgabraic(_216.fromColumn,_216.fromRow,_216.toColumn,_216.toRow,_216);
_216.SAN=san;
}
this.moveIndex++;
_216.index=this.moveIndex;
this.moveArray[this.moveIndex]=_216;
var _21b=this.moveToLocale(san);
var _21d=this.movesDisplay.outputMove(this.moveIndex,_216.ravLevel,_216.moveNum,_21b,false,0,_216.moveNum,_216,_218,_219);
var _21e=document.createElement("span");
_21e.innerHTML=_21d+"&nbsp;";
_21e.id=(this.boardName+"-ms"+this.moveIndex);
if(_217){
YAHOO.util.Dom.setStyle(_21e,"visibility","hidden");
}
if(_215){
if(clog){
console.log("prevMove.index:"+_215.index+"prevMove:"+_215.output());
}
var _21f=YAHOO.util.Dom.get((this.boardName+"-ms"+_215.index));
if(_21f){
insertAfter(_21e,_21f);
}else{
_21a.appendChild(_21e);
}
}else{
if(_216.next){
var _220=YAHOO.util.Dom.get((this.boardName+"-ms"+_216.next.index));
insertBefore(_21e,_220);
}else{
_21a.appendChild(_21e);
}
}
YAHOO.util.Event.removeListener(this.boardName+"-m"+this.moveIndex);
YAHOO.util.Event.addListener((this.boardName+"-m"+this.moveIndex),"click",this.movesDisplay.gotoMove,this.movesDisplay,true);
};
Board.prototype.replaceMove=function(_221,_222,_223,_224,_225,_226){
var _227="null";
if(_221){
_227=_221.output();
}
if(clog){
console.log("replace newMove:"+_222.output()+" after:"+_227+" replace as var"+_223+" rep move display:"+_224+" hideScore:"+_225);
if(_221&&_221.prev){
console.log("replace oldMove.prev:"+_221.prev.output());
}
if(_221&&_221.next){
console.log("replace oldMove.next:"+_221.next.output());
}
}
var _228=false;
var _229=null;
var _22a=0;
if(_221.endNode){
if(clog){
console.log("asked to replace endNode,inserting before instead");
}
this.insertMoveAfter(_221.prev,_222,false,false,_225,_226);
_222.fen=_221.fen;
_222.nextFen=_221.nextFen;
return;
}
if(_222.equals(_221)){
if(clog){
console.log("new move is same as old move so not replacing as variation");
}
_223=false;
}else{
if(_221&&_221.numVars>0){
for(var i=0;i<_221.numVars;i++){
var _22c=_221.vars[i];
if(_222.equals(_22c)){
if(clog){
console.log("new move is same as an existing variation varNum:"+i);
console.log("variation:"+_22c.output());
if(_22c.next){
console.log("variation next:"+_22c.next.output());
}
}
_228=true;
_229=_221;
_221=_22c;
_22a=i;
break;
}
}
}
}
if(_221==null){
if(clog){
console.log("replaced new move with null oldmove");
}
this.currentMove=_222;
_222.atEnd=1;
_222.next=null;
_222.prev=null;
if(this.startPositionAfterOpponentMove){
_222.fen=this.startPositionAfterOpponentMove;
_222.nextFen=null;
}
if(this.toMove==ChessPiece.WHITE){
this.currentMove.moveNum=1;
}else{
this.currentMove.moveNum=2;
}
this.firstMove=_222;
}else{
var _22d=false;
if(_221&&_221.prev&&_221.prev.next!=_221){
_22d=true;
}
if(this.currentMove==_221&&!_223){
this.currentMove=_222;
}else{
if(clog){
console.log("not setting current move in replacemove");
}
}
_222.atEnd=_221.atEnd;
_222.prev=_221.prev;
_222.next=_221.next;
_222.fen=_221.fen;
_222.nextFen=_221.nextFen;
_222.bestMoves=_221.bestMoves;
_222.correctMove=_221.correctMove;
_222.wrongMove=_221.wrongMove;
_222.moveNum=_221.moveNum;
_222.ravLevel=_221.ravLevel;
_222.index=_221.index;
if(clog){
console.log("replacingVariation with var not null:"+_228);
}
if(_228){
_229.vars[_22a]=_222;
_222.vars=_221.vars;
_222.numVars=_221.numVars;
this.reconnectNextNodeVariations(_222,_221.next);
if(_221.next){
_221.next.prev=_222;
}
this.moveArray[_222.index]=_222;
if(clog){
console.log("replacing existing sub variation of main line");
if(_222.next){
console.log("next of replacement variation:"+_222.next.output());
}
}
return;
}
if(!_223){
if(clog){
console.log("not replacing as variation");
}
if(!_22d&&_221.prev){
_221.prev.next=_222;
}
if(_221.next){
_221.next.prev=_222;
}
_222.vars=_221.vars;
_222.numVars=_221.numVars;
this.reconnectNextNodeVariations(_222,_221.next);
if(this.firstMove==_221){
this.firstMove=_222;
}
this.moveArray[_222.index]=_222;
}else{
if(clog){
console.log("replacing as variation");
}
if(_221.numVars==0){
_221.vars=new Array();
}
_221.vars[_221.numVars++]=_222;
_221.atEnd=0;
_222.next=null;
var _22e=this.createMoveFromString("i1i2");
_222.next=_22e;
_22e.prev=_222;
_22e.next=null;
_22e.atEnd=1;
_22e.moveNum=_222.moveNum+1;
_22e.ravLevel=_222.ravLevel;
_22e.endNode=true;
}
}
if(_224){
this.replaceIntoMoveDisplay(_221,_222,_223,_225,_226);
}
};
Board.prototype.setCurrentMove=function(move,_230,_231){
if(this.currentMove!=null){
if(this.currentMove.prev!=null){
YAHOO.util.Dom.removeClass(this.boardName+"-m"+this.currentMove.prev.index,"ct-board-move-current");
}
}
this.currentMove=move;
if(this.currentMove!=null&&this.currentMove.prev!=null){
var _232=this.boardName+"-m"+this.currentMove.prev.index;
if(clog){
console.log("setCurrentMove attempted highlight of id:"+_232+" for move:"+move.output());
}
var span=YAHOO.util.Dom.get(_232);
if(span){
var cls=span.className;
YAHOO.util.Dom.addClass(span,"ct-board-move-current");
if(this.autoScrollMoves){
if(!_231&&(this.scrollVariations||cls.indexOf("ct-board-move-variation")==-1)){
var _235=this.movesDisplay.getMovesDisplay();
if(_235){
var y=YAHOO.util.Dom.getY(span)-YAHOO.util.Dom.getY(_235);
var _237=new YAHOO.util.Scroll(_235,{scroll:{by:[0,y]}},this.moveAnimationLength,YAHOO.util.Easing.easeOut);
_237.animate();
}
}
}
}
}else{
if(move==null){
if(clog){
console.log("attempted to set current move on null node");
}
}
}
if(!_230){
this.setForwardBack();
}
};
Board.INITIAL_FEN="rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1";
Board.prototype.boardToFen=function(_238){
var _239="";
for(var row=7;row>=0;row--){
var _23b=0;
var line="";
if(row<7){
line="/";
}
for(var col=0;col<8;col++){
var _23e=this.boardPieces[col][row];
if(_23e){
var _23f="";
if(_23b>0){
_23f=_23b+"";
}
line+=_23f+_23e.getFenLetter();
_23b=0;
}else{
_23b++;
}
}
if(_23b>0){
line+=_23b+"";
}
_239+=line;
}
var fen=_239;
var _241=" w ";
if(_238){
if(this.toMove==ChessPiece.WHITE){
_241=" b ";
}
}else{
if(this.toMove==ChessPiece.BLACK){
_241=" b ";
}
}
fen+=_241;
var _242="";
_242+=Board.getFenCastleChar(this.canCastleKingSide,"K",ChessPiece.WHITE);
_242+=Board.getFenCastleChar(this.canCastleQueenSide,"Q",ChessPiece.WHITE);
_242+=Board.getFenCastleChar(this.canCastleKingSide,"K",ChessPiece.BLACK);
_242+=Board.getFenCastleChar(this.canCastleQueenSide,"Q",ChessPiece.BLACK);
if(_242==""){
fen+="- ";
}else{
fen+=_242+" ";
}
var _243=null;
if(this.currentMove){
if(this.currentMove.prev){
_243=this.currentMove.prev;
}else{
_243=this.prev_move;
}
}
var _244="- ";
if(_243){
if(_243){
var _245=this.boardPieces[_243.toColumn][_243.toRow];
if(_245){
if(_245.piece==ChessPiece.PAWN){
if(_245.colour==ChessPiece.WHITE){
if(_243.fromRow==1&&_243.toRow==3){
_244=Move.columnToChar(_243.fromColumn)+"3 ";
}
}else{
if(_243.fromRow==6&&_243.toRow==4){
_244=Move.columnToChar(_243.fromColumn)+"6 ";
}
}
}
}
}
}
fen+=_244;
fen+=this.halfMoveNumber+" "+parseInt((this.moveNumber+1)/2);
if(clog){
console.log("moveNumber:"+this.moveNumber+" fen:"+fen);
}
return fen;
};
Board.getFenCastleChar=function(_246,_247,_248){
if(_246[_248]){
if(_248==ChessPiece.WHITE){
return _247.toUpperCase();
}else{
return _247.toLowerCase();
}
}
return "";
};
Board.prototype.getCastlingString=function(_249){
var _24a=_js("None");
if(this.canCastleKingSide[_249]){
_24a="O-O";
}
if(this.canCastleQueenSide[_249]){
if(_24a==_js("None")){
_24a="O-O-O";
}else{
_24a+=",O-O-O";
}
}
return _24a;
};
Board.prototype.updateToPlay=function(){
if(this.disableUpdateToPlay){
return;
}
var _24b=YAHOO.util.Dom.get("toPlay");
if(_24b==null){
return;
}
if(this.toMove==ChessPiece.WHITE){
_24b.src="/images/whiteknight"+this.getVersString()+".gif";
_24b.alt=_js("White to play");
}else{
_24b.src="/images/blackknight"+this.getVersString()+".gif";
_24b.alt=_js("Black to play");
}
var _24c=YAHOO.util.Dom.get("fenStatus");
if(_24c){
var _24d=this.getCastlingString(ChessPiece.BLACK);
var _24e=this.getCastlingString(ChessPiece.WHITE);
var s="<div><span>"+_js("White Castling: ")+"</span><span>"+_24e+"</span></div>"+"<div><span>"+_js("Black Castling: ")+"</span><span>"+_24d+"</span></div>";
_24c.innerHTML=s;
}
};
Board.prototype.getBoardDivFromId=function(id){
if(!this[id]){
this[id]=YAHOO.util.Dom.get(id);
}
return this[id];
};
Board.prototype.getBoardDiv=function(){
if(!this.boardDiv){
this.boardDiv=YAHOO.util.Dom.get("ctb-"+this.boardName);
}
return this.boardDiv;
};
Board.prototype.getDocBody=function(){
if(!this.docBody){
var _251=document.getElementsByTagName("body");
if(_251==null||_251.length==0){
alert("Could not find body tag");
}else{
this.docBody=_251[0];
}
}
return this.docBody;
};
Board.prototype.getPieceDragDiv=function(){
if(!this.pieceDragDiv){
this.pieceDragDiv=YAHOO.util.Dom.get("pieceDragDiv");
}
return this.pieceDragDiv;
};
Board.prototype.createBoardCoords=function(){
this.coordinatesShown=false;
var _252=YAHOO.util.Dom.get(this.boardName+"-fileLabels");
var _253=YAHOO.util.Dom.get(this.boardName+"-rankLabels");
if(!_252||!_253){
return;
}
YAHOO.util.Event.purgeElement(_252,true);
_253.innerHTML="";
_252.innerHTML="";
var _254=YAHOO.util.Dom.get(this.boardName+"-boardBorder");
if(!this.showCoordinates){
YAHOO.util.Dom.setStyle(_252,"display","none");
YAHOO.util.Dom.setStyle(_253,"display","none");
var _255=0;
YAHOO.util.Dom.setStyle(_254,"width",(this.pieceSize*8+_255)+"px");
YAHOO.util.Dom.setStyle(_254,"height",(this.pieceSize*8+_255)+"px");
return;
}
YAHOO.util.Dom.setStyle(_252,"display","block");
YAHOO.util.Dom.setStyle(_253,"display","block");
var _255=15;
var _256=0;
if(check_bad_msie()){
_256=this.ie6FixCoordsOffsetSize;
}
if(YAHOO.util.Event.isIE){
_256+=this.allIeFixCoordsOffsetSize;
}
YAHOO.util.Dom.setStyle(_254,"width",(this.pieceSize*8+_255+_256)+"px");
YAHOO.util.Dom.setStyle(_254,"height",(this.pieceSize*8+_255)+"px");
this.coordinatesShown=true;
for(var i=0;i<8;i++){
var _258=document.createElement("div");
YAHOO.util.Dom.setStyle(_258,"height",this.pieceSize+"px");
YAHOO.util.Dom.setStyle(_258,"width","15px");
YAHOO.util.Dom.setStyle(_258,"text-align","center");
YAHOO.util.Dom.setStyle(_258,"line-height",this.pieceSize+"px");
if(this.isFlipped){
_258.innerHTML=""+(i+1);
}else{
_258.innerHTML=""+9-(i+1);
}
_253.appendChild(_258);
}
for(var i=0;i<9;i++){
var _259=document.createElement("span");
YAHOO.util.Dom.setStyle(_259,"float","left");
YAHOO.util.Dom.setStyle(_259,"height","15px");
if(i==0){
YAHOO.util.Dom.setStyle(_259,"width","15px");
YAHOO.util.Dom.setStyle(_259,"clear","both");
YAHOO.util.Dom.setStyle(_259,"margin-top","-5px");
if(_256){
YAHOO.util.Dom.setStyle(_259,"margin-left","-3px");
}else{
YAHOO.util.Dom.setStyle(_259,"margin-left","-2px");
}
var _25a="";
if(this.isFlipped){
_25a="whiteblack-flipper.png";
}else{
_25a="blackwhite-flipper.png";
}
_259.innerHTML="<span><img id=\""+this.boardName+"-flipper\" title=\""+_js("Flip Board")+"\" src=\""+this.boardImagePath+"/images/"+_25a+"\"/></span>";
YAHOO.util.Event.addListener(this.boardName+"-flipper","click",this.flipBoard,this,true);
}else{
YAHOO.util.Dom.setStyle(_259,"width",this.pieceSize+"px");
YAHOO.util.Dom.setStyle(_259,"text-align","center");
if(this.isFlipped){
_259.innerHTML=_js(Move.columnToChar(8-(i)));
}else{
_259.innerHTML=_js(Move.columnToChar((i-1)));
}
}
_252.appendChild(_259);
}
var _25b=YAHOO.util.Dom.get(this.boardName+"-flipper");
if(_25b){
fix_ie_png(_25b);
}
};
Board.prototype.createBoardUI=function(){
var _25c=this.boardName+"-container";
var _25d=YAHOO.util.Dom.get(_25c);
if(_25d==null){
alert("Could not find board container:"+_25c);
return;
}
YAHOO.util.Dom.addClass(_25d,"ct-board-container");
this.boardDiv=null;
var _25e=document.createElement("div");
_25e.id=this.boardName+"-boardBorder";
YAHOO.util.Dom.addClass(_25e,"ct-board-border"+this.squareColorClass);
var _25f=0;
if(this.showCoordinates){
_25f=15;
}
YAHOO.util.Dom.setStyle(_25e,"width",(this.pieceSize*8+_25f)+"px");
YAHOO.util.Dom.setStyle(_25e,"height",(this.pieceSize*8+_25f)+"px");
var _260=document.createElement("div");
YAHOO.util.Dom.setStyle(_260,"float","left");
_260.id=this.boardName+"-rankLabels";
_25e.appendChild(_260);
var _261=document.createElement("div");
YAHOO.util.Dom.addClass(_261,"ct-board");
YAHOO.util.Dom.setStyle(_261,"width",(this.pieceSize*8)+"px");
YAHOO.util.Dom.setStyle(_261,"height",(this.pieceSize*8)+"px");
_261.id="ctb-"+this.boardName;
var _262="ct-white-square"+this.squareColorClass;
var _263="";
var _264=[];
for(var i=7;i>=0;i--){
var s="<div>";
for(var j=0;j<8;j++){
var _268=document.createElement("div");
var _269=this.boardName+"-s"+j+""+i;
var _26a=(((j+1)*(i+1))%19/19*100);
var _26b=((65-((j+1)*(i+1)))%19/19*100);
s+="<div id=\""+_269+"\" class=\""+_262+"\" style=\"width:"+this.pieceSize+"px;height:"+this.pieceSize+"px;background-position:"+_26a+"% "+_26b+"%\"></div>";
_264.push(_269);
_262=(_262=="ct-black-square"+this.squareColorClass)?"ct-white-square"+this.squareColorClass:"ct-black-square"+this.squareColorClass;
}
_262=(_262=="ct-black-square"+this.squareColorClass)?"ct-white-square"+this.squareColorClass:"ct-black-square"+this.squareColorClass;
s+="</div>";
_263+=s;
}
_261.innerHTML=_263;
var _26c=document.createElement("div");
_26c.id=this.boardName+"-fileLabels";
_25e.appendChild(_261);
_25e.appendChild(_26c);
_25d.appendChild(_25e);
this.createBoardCoords();
var _26d=YAHOO.util.Dom.get(this.boardName+"-ct-nav-container");
if(!_26d){
_26d=document.createElement("div");
}else{
_26d.innerHTML="";
}
_26d.id=this.boardName+"-ct-nav-container";
if(!this.dontOutputNavButtons||this.r){
var _26e="";
if(!this.dontOutputNavButtons){
if(!this.problem||!this.problem.isEndgame){
_26e="<span id=\"playStopSpan\"><img class=\"ct-end\" id=\""+this.boardName+"-end\" src=\""+this.boardImagePath+"/images/resultset_last"+this.getVersString()+".gif\" alt=\""+_js("End position")+"\" title=\""+_js("Go to final position")+"\"/>"+"<img class=\"ct-play\" id=\""+this.boardName+"-play\" src=\""+this.boardImagePath+"/images/control_play_blue"+this.getVersString()+".gif\" alt=\""+_js("Play moves")+"\" title=\""+_js("Play sequence of moves")+"\"/>"+"<img class=\"ct-stop\" id=\""+this.boardName+"-stop\" src=\""+this.boardImagePath+"/images/control_stop_blue"+this.getVersString()+".gif\" alt=\""+_js("Stop playing")+"\" title=\""+_js("Stop playing move sequence")+"\"/></span>";
}
}
var _26f="<div class=\"ct-nav-buttons\" id=\""+this.boardName+"-navButtons\"><span id=\"nav-buttons-only\">";
if(!this.dontOutputNavButtons){
_26f+="<img class=\"ct-start\" id=\""+this.boardName+"-start\" src=\""+this.boardImagePath+"/images/resultset_first"+this.getVersString()+".gif\" alt=\""+_js("Start position")+"\" title=\""+_js("Go to starting position")+"\"/>"+"<img class=\"ct-back\" id=\""+this.boardName+"-back\" src=\""+this.boardImagePath+"/images/resultset_previous"+this.getVersString()+".gif\" alt=\""+_js("Previous Move")+"\" title=\""+_js("Go back a move")+"\"/>"+"<img class=\"ct-forward\" id=\""+this.boardName+"-forward\" src=\""+this.boardImagePath+"/images/resultset_next"+this.getVersString()+".gif\" alt=\""+_js("Next Move")+"\" title=\""+_js("Go forward a move")+"\"/>"+_26e;
}
if(this.r){
_26f+="<img class=\"ct-forward\" id=\""+this.boardName+"-analyse\" src=\""+this.boardImagePath+"/images/anboard"+this.getVersString()+".gif\" alt=\""+_js("Analyse")+"\" title=\""+_js("Launch analysis board to explore different lines in this position")+"\"/>";
_26f+="<img class=\"ct-forward\" id=\""+this.boardName+"-showfen\" src=\""+this.boardImagePath+"/images/copy_fen"+this.getVersString()+".gif\" alt=\""+_js("Copy FEN")+"\" title=\""+_js("Show FEN for current position")+"\"/>";
}
_26f+="</span></div>";
_26d.innerHTML=_26f;
}
_25d.appendChild(_26d);
if(this.problem){
var body=YAHOO.util.Dom.get("body");
if(body){
YAHOO.util.Dom.setStyle(body,"min-width",((this.pieceSize*8+_25f)+300+200+120)+"px");
}
}
};
Board.prototype.getPieceDiv=function(){
var _271=this.getBoardDiv();
var _272=document.createElement("div");
this.availPieceDivs[this.uptoId]=_272;
this.availIds[this.uptoId]=YAHOO.util.Dom.generateId(_272);
YAHOO.util.Dom.setStyle(_272,"visibility","hidden");
YAHOO.util.Dom.addClass(_272,"board-piece-start-style");
_271.appendChild(_272);
this.uptoId++;
return _272;
};
Board.prototype.flipToMove=function(_273){
return (_273=="w")?"b":"w";
};
Board.prototype.pieceCharToPieceNum=function(_274){
var _275;
switch(_274){
case "K":
_275=ChessPiece.KING;
break;
case "Q":
_275=ChessPiece.QUEEN;
break;
case "R":
_275=ChessPiece.ROOK;
break;
case "B":
_275=ChessPiece.BISHOP;
break;
case "N":
_275=ChessPiece.KNIGHT;
break;
case "P":
_275=ChessPiece.PAWN;
break;
}
return _275;
};
Board.prototype.pieceTypeToChar=function(_276){
switch(_276){
case ChessPiece.KING:
return "K";
case ChessPiece.QUEEN:
return "Q";
case ChessPiece.ROOK:
return "R";
case ChessPiece.BISHOP:
return "B";
case ChessPiece.KNIGHT:
return "N";
case ChessPiece.PAWN:
return "P";
}
return "?";
};
Board.prototype.canMoveKnight=function(_277,_278,_279,_27a){
if(_277+2==_279&&_278+1==_27a){
return true;
}
if(_277+2==_279&&_278-1==_27a){
return true;
}
if(_277-2==_279&&_278+1==_27a){
return true;
}
if(_277-2==_279&&_278-1==_27a){
return true;
}
if(_277+1==_279&&_278+2==_27a){
return true;
}
if(_277-1==_279&&_278+2==_27a){
return true;
}
if(_277+1==_279&&_278-2==_27a){
return true;
}
if(_277-1==_279&&_278-2==_27a){
return true;
}
return false;
};
Board.prototype.canMovePawn=function(_27b,_27c,_27d,_27e,_27f){
var _280=this.boardPieces[_27d][_27e];
var _281=this.boardPieces[_27b][_27c];
if(_27f){
var _282=this.boardPieces[_27f.toColumn][_27f.toRow];
if(_282.piece==ChessPiece.PAWN){
if(_282.colour==ChessPiece.WHITE){
if(_27f.fromRow==1&&_27f.toRow==3){
if(_27d==_27f.fromColumn&&_27c==3&&_27e==2&&(_27b==_27d+1||_27b==_27d-1)){
return true;
}
}
}else{
if(_27f.fromRow==6&&_27f.toRow==4){
if(_27d==_27f.fromColumn&&_27c==4&&_27e==5&&(_27b==_27d+1||_27b==_27d-1)){
return true;
}
}
}
}
}
if(_280){
if(_281.colour==ChessPiece.WHITE){
if((_27b==_27d+1||_27b==_27d-1)&&(_27c==_27e-1)){
return true;
}
}else{
if((_27b==_27d+1||_27b==_27d-1)&&(_27c==_27e+1)){
return true;
}
}
}else{
if(_27b==_27d){
if(_281.colour==ChessPiece.WHITE){
if(_27c==1){
if(_27e==2){
return true;
}else{
if(_27e==3&&this.boardPieces[_27d][2]==null){
return true;
}
}
}else{
if(_27c+1==_27e){
return true;
}
}
}else{
if(_27c==6){
if(_27e==5){
return true;
}else{
if(_27e==4&&this.boardPieces[_27d][5]==null){
return true;
}
}
}else{
if(_27c-1==_27e){
return true;
}
}
}
}
}
return false;
};
Board.prototype.canMoveStraight=function(_283,_284,_285,_286,_287,_288){
var _289=_283;
var _28a=_284;
var _28b=0;
var _28c=0;
if(_285>_283){
_28b=1;
}else{
if(_285<_283){
_28b=-1;
}
}
if(_286>_284){
_28c=1;
}else{
if(_286<_284){
_28c=-1;
}
}
if(clog){
console.log("deltaRow:"+_28c+" deltaCol:"+_28b+" fromCol:"+_283+" fromRow:"+_284+" toCol:"+_285+" toRow:"+_286);
}
if(_287==ChessPiece.ROOK&&(_28b!=0&&_28c!=0)){
return false;
}
if(_287==ChessPiece.BISHOP&&(_28b==0||_28c==0)){
return false;
}
var _28d=0;
while(true){
_28d++;
_283+=_28b;
_284+=_28c;
if(_287==ChessPiece.KING&&_28d>1){
if(clog){
console.log("king count:"+_28d+" toCol:"+_285+" toRow:"+_286);
}
if(_28d!=2){
return false;
}
if(_28c!=0){
return false;
}
if(!(_285==6||_285==2)){
return false;
}
if(_285==2){
if(this.boardPieces[1][_284]||this.boardPieces[2][_284]||this.boardPieces[3][_284]){
return false;
}
if(!this.canCastleQueenSide[_288.colour]){
return false;
}
}else{
if(_285==6){
if(this.boardPieces[5][_284]||this.boardPieces[6][_284]){
if(clog){
console.log("king can't castle intervening piece");
}
return false;
}
if(!this.canCastleKingSide[_288.colour]){
if(clog){
console.log("king can't castle king side (made previously invalid) colour:"+_288.colour);
}
return false;
}
}else{
if(clog){
console.log("king not in col 2 or 6");
}
return false;
}
}
var _28e="";
_28e+=Move.columnToChar(_289);
_28e+=String.fromCharCode("1".charCodeAt(0)+_28a);
_28e+=Move.columnToChar((_289+_28b));
_28e+=String.fromCharCode("1".charCodeAt(0)+(_28a+_28c));
var move=this.createMoveFromString(_28e);
var _290=this.boardPieces;
var _291=this.toMove;
var _292=this.saveCastling();
this.boardPieces=this.copyBoardPieces(true);
this.makeMove(move,this.boardPieces[_289][_28a],false,this.moveAnimationLength,false,false);
this.restoreCastling(_292);
kingSafe=this.isKingSafe(_288.colour,move);
boardPool.putObject(this.boardPieces);
this.boardPieces=_290;
_290.count--;
this.toMove=_291;
if(clog){
console.log("kingSafe1:"+kingSafe);
}
if(!kingSafe){
return false;
}
var _28e="";
_28e+=Move.columnToChar(_289);
_28e+=String.fromCharCode("1".charCodeAt(0)+_28a);
_28e+=Move.columnToChar(_289);
_28e+=String.fromCharCode("1".charCodeAt(0)+_28a);
var move=this.createMoveFromString(_28e);
var _290=this.boardPieces;
var _291=this.toMove;
var _292=this.saveCastling();
this.boardPieces=this.copyBoardPieces(true);
this.makeMove(move,this.boardPieces[_289][_28a],false,this.moveAnimationLength,false,false);
this.restoreCastling(_292);
kingSafe=this.isKingSafe(_288.colour,move);
boardPool.putObject(this.boardPieces);
this.boardPieces=_290;
_290.count--;
this.toMove=_291;
if(clog){
console.log("kingSafe2:"+kingSafe);
}
if(!kingSafe){
return false;
}
}
if(_283==_285&&_284==_286){
return true;
}
if(_283<0||_283>7||_284<0||_284>7){
return false;
}
if(this.boardPieces[_283][_284]!=null){
return false;
}
}
};
Board.prototype.canMove=function(_293,_294,_295,_296,_297){
var _298=_293.column;
var _299=_293.row;
if(_294>7||_294<0||_295>7||_295<0){
if(clog){
console.log("can't move coz out of bounds");
}
return false;
}
var _29a=this.boardPieces[_294][_295];
var _29b=this.boardPieces[_298][_299];
if(_29b==null){
return false;
}
if(_29a&&_29a.colour==_29b.colour){
return false;
}
var _29c=false;
if(_293.piece==ChessPiece.PAWN){
_29c=this.canMovePawn(_298,_299,_294,_295,_296);
}else{
if(_293.piece==ChessPiece.KNIGHT){
_29c=this.canMoveKnight(_298,_299,_294,_295);
}else{
_29c=this.canMoveStraight(_298,_299,_294,_295,_293.piece,_293);
}
}
if(clog){
console.log("moveOk:"+_29c);
}
var _29d=true;
if(_29c&&_297){
var _29e="";
_29e+=Move.columnToChar(_298);
_29e+=String.fromCharCode("1".charCodeAt(0)+_299);
_29e+=Move.columnToChar(_294);
_29e+=String.fromCharCode("1".charCodeAt(0)+_295);
var move=this.createMoveFromString(_29e);
var _2a0=this.cloneBoard();
_2a0.makeMove(move,_2a0.boardPieces[_298][_299],false,this.moveAnimationLength,false,false);
_29d=_2a0.isKingSafe(_293.colour,move);
}
return _29c&&_29d;
};
Board.prototype.isKingMated=function(_2a1,_2a2){
var _2a3=null;
for(var i=0;i<8;i++){
for(var j=0;j<8;j++){
var bp=this.boardPieces[i][j];
if(bp!=null&&bp.piece==ChessPiece.KING&&bp.colour==_2a1){
_2a3=bp;
break;
}
}
}
var _2a7=[[1,0],[1,1],[1,-1],[-1,0],[-1,1],[-1,-1],[0,1],[0,-1],[2,0],[-2,0]];
var bp=_2a3;
for(var k=0;k<_2a7.length;k++){
if(this.canMove(bp,bp.column+_2a7[k][0],bp.row+_2a7[k][1],_2a2,true)){
return false;
}
}
var _2a9=this.getCandidateMoves(_2a1,_2a2,true,true);
if(_2a9.length>0){
return false;
}
return true;
};
Board.prototype.getCandidateMoves=function(_2aa,_2ab,_2ac,_2ad){
var _2ae=new Array();
for(var i=0;i<8;i++){
for(var j=0;j<8;j++){
var bp=this.boardPieces[i][j];
var _2b2=[];
if(!bp||bp.colour!=_2aa){
continue;
}
switch(bp.piece){
case ChessPiece.KING:
if(_2ad){
continue;
}
_2b2=[[1,0],[1,1],[1,-1],[-1,0],[-1,1],[-1,-1],[0,1],[0,-1],[2,0],[-2,0]];
break;
case ChessPiece.KNIGHT:
_2b2=[[2,1],[2,-1],[-2,1],[-2,-1],[1,2],[1,-2],[-1,2],[-1,-2]];
break;
case ChessPiece.BISHOP:
for(var k=0;k<8;k++){
_2b2.push([1+k,1+k]);
_2b2.push([1+k,-1-k]);
_2b2.push([-1-k,1+k]);
_2b2.push([-1-k,-1-k]);
}
break;
case ChessPiece.QUEEN:
for(var k=0;k<8;k++){
_2b2.push([1+k,0]);
_2b2.push([1+k,1+k]);
_2b2.push([1+k,-1-k]);
_2b2.push([-1-k,0]);
_2b2.push([-1-k,1+k]);
_2b2.push([-1-k,-1-k]);
_2b2.push([0,-1-k]);
_2b2.push([0,1+k]);
}
break;
case ChessPiece.ROOK:
for(var k=0;k<8;k++){
_2b2.push([1+k,0]);
_2b2.push([-1-k,0]);
_2b2.push([0,-1-k]);
_2b2.push([0,1+k]);
}
break;
case ChessPiece.PAWN:
_2b2=[[0,1],[0,-1],[1,1],[1,-1],[-1,1],[-1,-1]];
break;
}
for(var k=0;k<_2b2.length;k++){
if(this.canMove(bp,bp.column+_2b2[k][0],bp.row+_2b2[k][1],_2ab,true)){
_2ae.push(new Move(bp.column,bp.row,bp.column+_2b2[k][0],bp.row+_2b2[k][1]));
if(_2ac){
return _2ae;
}
}
}
}
}
return _2ae;
};
Board.prototype.isKingSafe=function(_2b4,_2b5){
var _2b6=null;
for(var i=0;i<8;i++){
for(var j=0;j<8;j++){
var bp=this.boardPieces[i][j];
if(bp!=null&&bp.piece==ChessPiece.KING&&bp.colour==_2b4){
_2b6=bp;
break;
}
}
}
for(var i=0;i<8;i++){
for(var j=0;j<8;j++){
var bp=this.boardPieces[i][j];
if(bp!=null&&bp.colour!=_2b4){
if(this.canMove(bp,_2b6.column,_2b6.row,_2b5,false)){
return false;
}
}
}
}
return true;
};
Board.prototype.freeBoardPieces=function(_2ba){
if(this.boardPieces){
for(var i=0;i<8;i++){
for(var j=0;j<8;j++){
if(this.boardPieces[i][j]!=null){
this.boardPieces[i][j].free();
this.boardPieces[i][j]=null;
}
}
if(_2ba){
this.boardPieces[i]=null;
}
}
}
if(_2ba){
this.boardPieces=null;
}
};
Board.prototype.freeBoard=function(){
this.freeBoardPieces(true);
this.freeMoveArray();
};
Board.prototype.freeMoveArray=function(){
if(this.moveArray){
for(var i=0;i<this.moveArray.length;i++){
var m=this.moveArray[i];
if(m){
m.freeMove();
this.moveArray[i]=null;
}
}
}
};
Board.prototype.cloneBoard=function(){
var _2bf=new Board();
_2bf.boardPieces=this.copyBoardPieces(true);
_2bf.moveArray=this.copyMoveArray(false);
_2bf.canCastleQueenSide=this.copyCastleQueenSide();
_2bf.canCastleKingSide=this.copyCastleKingSide();
_2bf.toMove=this.toMove;
_2bf.opponentColour=this.opponentColour;
_2bf.isFlipped=this.isFlipped;
_2bf.isUserFlipped=this.isUserFlipped;
_2bf.ignoreFlipping=this.ignoreFlipping;
_2bf.reverseFlip=this.reverseFlip;
_2bf.moveAnimationLength=this.moveAnimationLength;
_2bf.moveNumber=this.moveNumber;
_2bf.halfMoveNumber=this.halfMoveNumber;
_2bf.startFen=this.startFen;
return _2bf;
};
Board.prototype.copyCastleQueenSide=function(){
return [this.canCastleQueenSide[0],this.canCastleQueenSide[1]];
};
Board.prototype.copyCastleKingSide=function(){
return [this.canCastleKingSide[0],this.canCastleKingSide[1]];
};
Board.prototype.copyMoveArray=function(_2c0){
var _2c1=new Array();
if(!_2c0){
if(this.moveArray.length>0){
_2c1=this.moveArray.slice(0);
}
return _2c1;
}else{
for(var i=0;i<this.moveArray.length;i++){
var m=_2c1[i];
if(m){
var newM=m.clone(true);
_2c1[i]=newM;
}
}
return _2c1;
}
};
Board.prototype.copyBoardPieces=function(_2c5){
var _2c6=Board.createBoardArray();
for(var i=0;i<8;i++){
for(var j=0;j<8;j++){
if(this.boardPieces[i][j]!=null){
if(_2c5){
_2c6[i][j]=this.boardPieces[i][j].makeLightWeight();
}else{
_2c6[i][j]=this.boardPieces[i][j].copyPiece();
}
}else{
_2c6[i][j]=null;
}
}
}
return _2c6;
};
Board.prototype.createPiece=function(_2c9,_2ca,_2cb){
if(_2cb){
return new LightweightChessPiece(null,_2c9,_2ca,this);
}else{
return new ChessPiece(this.getPieceDiv(),_2c9,_2ca,this);
}
};
Board.prototype.restoreCastling=function(_2cc){
this.canCastleKingSide=_2cc.kingSide;
this.canCastleQueenSide=_2cc.queenSide;
};
Board.prototype.saveCastling=function(){
var _2cd=[this.canCastleQueenSide[0],this.canCastleQueenSide[1]];
var _2ce=[this.canCastleKingSide[0],this.canCastleKingSide[1]];
return {queenSide:_2cd,kingSide:_2ce};
};
var firstLightProf=true;
var firstHeavyProf=true;
Board.prototype.setupFromFenLightweight=function(fen,_2d0,flip){
var _2d2=false&&firstLightProf;
if(_2d2){
console.profile("setupFromFenLight");
}
this.setupFromFenGeneric(fen,_2d0,flip,true);
if(_2d2){
console.profileEnd();
}
};
Board.prototype.setupFromFenHeavyWeight=function(fen,_2d4,flip){
var _2d6=false&&firstHeavyProf;
if(_2d6){
console.profile("setupFromFenHeavy");
}
this.setupFromFenGeneric(fen,_2d4,flip,false);
if(_2d6){
console.profileEnd();
}
};
Board.prototype.setupFromFen=function(fen,_2d8,flip,_2da){
if(_2da){
this.setupFromFenLightweight(fen,_2d8,flip);
}else{
this.setupFromFenHeavyWeight(fen,_2d8,flip);
}
};
Board.prototype.setupFromFenGeneric=function(fen,_2dc,flip,_2de){
if(ctime){
console.time("setupFromFen"+_2de);
}
this.settingUpPosition=true;
var _2df=fen.split(" ");
var _2e0=_2df[0].split("/");
this.halfMoveNumber=parseInt(_2df[4]);
this.moveNumber=parseInt(_2df[5])*2;
var _2e1=0;
var row=8;
this.uptoId=0;
this.board_xy=null;
var _2e3=_2df[2];
this.canCastleQueenSide=[false,false];
this.canCastleKingSide=[false,false];
if(_2e3!="-"){
if(_2e3.indexOf("K")>=0){
this.canCastleKingSide[ChessPiece.WHITE]=true;
}
if(_2e3.indexOf("Q")>=0){
this.canCastleQueenSide[ChessPiece.WHITE]=true;
}
if(_2e3.indexOf("k")>=0){
this.canCastleKingSide[ChessPiece.BLACK]=true;
}
if(_2e3.indexOf("q")>=0){
this.canCastleQueenSide[ChessPiece.BLACK]=true;
}
}
if(_2df[1]=="w"){
this.toMove=ChessPiece.WHITE;
this.opponentColour=ChessPiece.WHITE;
this.isFlipped=false;
}else{
this.toMove=ChessPiece.BLACK;
this.opponentColour=ChessPiece.BLACK;
this.isFlipped=true;
}
if(_2dc){
this.toMove=(ChessPiece.BLACK==this.toMove)?ChessPiece.WHITE:ChessPiece.BLACK;
this.isFlipped=!this.isFlipped;
}
if(flip){
this.isFlipped=true;
}
if(this.reverseFlip){
this.isFlipped=!this.isFlipped;
}
if(this.ignoreFlipping){
this.isFlipped=false;
}
if(this.isUserFlipped){
this.isFlipped=!this.isFlipped;
}
this.updateToPlay();
this.setupPieceDivs();
for(var i=0;i<8;i++){
for(var j=0;j<8;j++){
this.boardPieces[i][j]=null;
}
}
for(var i=0;i<8;i++){
var line=_2e0[i];
row--;
_2e1=0;
for(var j=0;j<line.length;j++){
var c=line.charAt(j);
var code=line.charCodeAt(j);
var num=code-"0".charCodeAt(0);
if(num>0&&num<9){
while(num--){
var _2ea=this.boardPieces[_2e1][row];
this.boardPieces[_2e1][row]=null;
_2e1++;
}
}else{
var _2eb=(c+"").toLowerCase().charAt(0);
var _2ec=ChessPiece.WHITE;
if(_2eb==c){
_2ec=ChessPiece.BLACK;
}
var cp;
switch(_2eb){
case "k":
cp=this.createPiece(_2ec,ChessPiece.KING,_2de);
break;
case "q":
cp=this.createPiece(_2ec,ChessPiece.QUEEN,_2de);
break;
case "r":
cp=this.createPiece(_2ec,ChessPiece.ROOK,_2de);
break;
case "b":
cp=this.createPiece(_2ec,ChessPiece.BISHOP,_2de);
break;
case "n":
cp=this.createPiece(_2ec,ChessPiece.KNIGHT,_2de);
break;
case "p":
cp=this.createPiece(_2ec,ChessPiece.PAWN,_2de);
break;
default:
alert("unknown piece letter:"+_2eb+" for fen:"+fen);
}
if(isGecko||isOpera){
cp.setPosition(_2e1,row,false,null,this.moveAnimationLength);
cp.setVisible(true);
}
this.boardPieces[_2e1][row]=cp;
this.pieces[this.uptoPiece]=cp;
this.pieces[this.uptoPiece].column=_2e1;
this.pieces[this.uptoPiece].row=row;
this.uptoPiece++;
_2e1++;
}
}
}
if(!isGecko){
for(var i=0;i<this.uptoPiece;i++){
this.pieces[i].setPosition(this.pieces[i].column,this.pieces[i].row,false,null,0);
}
}
if(!_2de){
for(var i=0;i<this.uptoPiece;i++){
this.pieces[i].setVisible(true);
}
}
if(!_2de){
this.createBoardCoords();
}
if(this.toMove==ChessPiece.WHITE){
this.moveNumber--;
}
this.settingUpPosition=false;
if(ctime){
console.timeEnd("setupFromFen"+_2de);
}
};
Board.prototype.resetMoveListScrollPosition=function(){
var _2ee=this.movesDisplay.getMovesDisplay();
if(_2ee){
var _2ef=new YAHOO.util.Scroll(_2ee,{scroll:{to:[0,0]}},0);
_2ef.animate();
}
};
Board.prototype.changePieceSet=function(_2f0,_2f1){
if(!this.showedIE6Warning){
var str=_js("Depending on your browser you may need to reload the<br/> page for piece size changes to properly take effect.");
alert(str.replace("<br/>","\n"));
}
this.showedIE6Warning=true;
if(check_bad_msie()){
if(!this.showedIE6Warning){
var str=_js("Internet Explorer version 6 does not support dynamic piece size changes.<br/> Please reload page to view new settings.");
alert(str.replace("<br/>","\n"));
}
this.showedIE6Warning=true;
return;
}
var _2f3=this.pieceSize;
this.pieceSet=_2f0;
this.pieceSize=_2f1;
var _2f4=YAHOO.util.Dom.get(this.boardName+"-boardBorder");
var _2f5=0;
if(this.showCoordinates){
_2f5=15;
}
_2f4.className="";
YAHOO.util.Dom.addClass(_2f4,"ct-board-border"+this.squareColorClass);
YAHOO.util.Dom.setStyle(_2f4,"width",(this.pieceSize*8+_2f5)+"px");
YAHOO.util.Dom.setStyle(_2f4,"height",(this.pieceSize*8+_2f5)+"px");
var _2f6=YAHOO.util.Dom.get("ctb-"+this.boardName);
YAHOO.util.Dom.setStyle(_2f6,"width",(this.pieceSize*8)+"px");
YAHOO.util.Dom.setStyle(_2f6,"height",(this.pieceSize*8)+"px");
var _2f7="ct-white-square"+this.squareColorClass;
for(var i=7;i>=0;i--){
for(var j=0;j<8;j++){
var _2fa=this.getBoardDivFromId(this.boardName+"-s"+j+""+i);
_2fa.className="";
YAHOO.util.Dom.addClass(_2fa,_2f7);
YAHOO.util.Dom.setStyle(_2fa,"width",this.pieceSize+"px");
YAHOO.util.Dom.setStyle(_2fa,"height",this.pieceSize+"px");
var _2fb=(((j+1)*(i+1))%19/19*100);
var _2fc=((65-((j+1)*(i+1)))%19/19*100);
YAHOO.util.Dom.setStyle(_2fa,"background-position",_2fb+"% "+_2fc+"%");
_2f7=(_2f7=="ct-black-square"+this.squareColorClass)?"ct-white-square"+this.squareColorClass:"ct-black-square"+this.squareColorClass;
}
_2f7=(_2f7=="ct-black-square"+this.squareColorClass)?"ct-white-square"+this.squareColorClass:"ct-black-square"+this.squareColorClass;
}
for(var i=0;i<8;i++){
for(var j=0;j<8;j++){
var cp=this.boardPieces[i][j];
if(cp){
cp.icon=get_image_str(ChessPiece.pieceIconNames[cp.colour][cp.piece],cp.board.boardImagePath,cp.board.pieceSet,cp.board.pieceSize,cp.board.addVersion);
if(YAHOO.util.Event.isIE){
var _2fe=cp.div;
_2fe.innerHTML="<img src=\""+cp.icon+"\"/>";
var img=_2fe.firstChild;
if(!isOpera){
fix_ie_png(img);
}
}else{
YAHOO.util.Dom.setStyle([cp.div],"backgroundImage","url("+cp.icon+")");
YAHOO.util.Dom.setStyle([cp.div],"background-repeat","no-repeat");
}
YAHOO.util.Dom.setStyle([cp.div],"height",this.pieceSize+"px");
YAHOO.util.Dom.setStyle([cp.div],"width",this.pieceSize+"px");
YAHOO.util.Dom.setStyle([cp.div],"left","");
YAHOO.util.Dom.setStyle([cp.div],"top","");
var xy=cp.getNewXYPosition(cp.column,cp.row);
YAHOO.util.Dom.setXY(cp.div,xy,false);
}
}
}
if(this.moveArray){
var move=this.moveArray[0];
while(move!=null){
if(move.taken){
var cp=move.taken;
if(cp.getNewXYPosition){
cp.icon=get_image_str(ChessPiece.pieceIconNames[cp.colour][cp.piece],cp.board.boardImagePath,cp.board.pieceSet,cp.board.pieceSize,cp.board.addVersion);
if(YAHOO.util.Event.isIE){
var _2fe=cp.div;
_2fe.innerHTML="<img src=\""+cp.icon+"\"/>";
YAHOO.util.Dom.setStyle([cp.div],"position","relative");
var img=_2fe.firstChild;
if(!isOpera){
fix_ie_png(img);
}
}else{
YAHOO.util.Dom.setStyle([cp.div],"backgroundImage","url("+cp.icon+")");
YAHOO.util.Dom.setStyle([cp.div],"background-repeat","no-repeat");
}
YAHOO.util.Dom.setStyle([cp.div],"height",this.pieceSize+"px");
YAHOO.util.Dom.setStyle([cp.div],"width",this.pieceSize+"px");
YAHOO.util.Dom.setStyle([cp.div],"left","");
YAHOO.util.Dom.setStyle([cp.div],"top","");
var xy=cp.getNewXYPosition(cp.column,cp.row);
YAHOO.util.Dom.setXY(cp.div,xy,false);
}
}
move=move.next;
}
}
if(this.problem){
var body=YAHOO.util.Dom.get("body");
if(body){
YAHOO.util.Dom.setStyle(body,"min-width",((this.pieceSize*8+_2f5)+300+200+120)+"px");
}
}
this.createBoardCoords();
};
Board.prototype.forwardMove=function(e){
if(this.blockFowardBack||this.deferredBlockForwardBack){
if(clog){
console.log("returning early from forward due to block forward on");
}
return;
}
var _304=false;
if(this.tactics&&this.tactics.problemActive){
if(clog){
console.log("not forwarding, tactic is active");
}
return;
}
this.blockForwardBack=true;
if(this.currentMove&&!this.currentMove.atEnd){
move=this.currentMove;
if(move){
if(clog){
console.log("forward move:"+move.output());
}
}else{
if(clog){
console.log("forward move with currentmove null");
}
}
if(move.endNode){
if(clog){
console.log("calling processendgame from forward move");
}
if(!_304){
this.problem.processEndgame("",true);
}
this.toggleToMove();
this.updateToPlay();
}else{
if(clog){
console.log("forwarding move:"+move.output());
}
var _305=null;
piece=this.boardPieces[move.fromColumn][move.fromRow];
if(move.promotion){
_305=move.promotion;
piece.prePromotionColumn=null;
piece.prePromotionRow=null;
}
this.updatePiece(piece,move.toColumn,move.toRow,true,true,false,_305,true);
this.toggleToMove();
this.updateToPlay();
var _306=this.currentMove;
if(clog){
if(_306){
console.log("after forward curmove:"+_306.output());
}else{
console.log("after forward cur move null");
}
}
for(var i=0;i<this.registeredForwardMovePostUpdateListeners.length;i++){
var _308=this.registeredForwardMovePostUpdateListeners[i].forwardMovePostUpdateCallback(move);
}
}
}else{
if(clog){
console.log("already at end");
}
}
this.blockForwardBack=false;
};
Board.prototype.setupEventHandlers=function(){
this.timesLostFocus=0;
YAHOO.util.Event.addListener(document,"blur",this.lostFocus,this,true);
YAHOO.util.Event.addListener(this.boardName+"-container","mouseover",function(e){
activeBoard=this;
},this,true);
YAHOO.util.Event.addListener(document,"keydown",function(e){
var _30b=(e.target)?e.target:e.srcElement;
if(_30b.form){
return true;
}
if(activeBoard!=this){
return true;
}
switch(YAHOO.util.Event.getCharCode(e)){
case 37:
this.backMove();
break;
case 39:
this.forwardMove();
break;
default:
}
return true;
},this,true);
YAHOO.util.Event.addListener(this.boardName+"-forward","click",this.forwardMove,this,true);
YAHOO.util.Event.addListener(this.boardName+"-back","click",this.backMove,this,true);
YAHOO.util.Event.addListener(this.boardName+"-start","click",this.gotoStart,this,true);
YAHOO.util.Event.addListener(this.boardName+"-end","click",this.gotoEnd,this,true);
YAHOO.util.Event.addListener(this.boardName+"-play","click",this.playMoves,this,true);
YAHOO.util.Event.addListener(this.boardName+"-stop","click",this.stopPlayingMoves,this,true);
if(this.r){
YAHOO.util.Event.addListener(this.boardName+"-analyse","click",this.analysePosition,this,true);
YAHOO.util.Event.addListener(this.boardName+"-showfen","click",this.showBoardFen,this,true);
}
};
Board.prototype.flipBoard=function(){
this.isUserFlipped=!this.isUserFlipped;
this.isFlipped=!this.isFlipped;
this.redrawBoard();
};
Board.prototype.lostFocus=function(){
this.timesLostFocus++;
};
Board.prototype.redrawBoard=function(){
for(var i=0;i<8;i++){
for(var j=0;j<8;j++){
var cp=this.boardPieces[i][j];
if(cp){
var xy=cp.getNewXYPosition(cp.column,cp.row);
YAHOO.util.Dom.setXY(cp.div,xy,false);
}
}
}
if(this.moveArray){
var move=this.moveArray[0];
while(move!=null){
if(move.taken){
var cp=move.taken;
if(cp.getNewXYPosition){
var xy=cp.getNewXYPosition(cp.column,cp.row);
YAHOO.util.Dom.setXY(cp.div,xy,false);
}
}
move=move.next;
}
}
this.createBoardCoords();
if(this.highlightFromTo){
if(!this.isFlipped){
var _311=YAHOO.util.Dom.get(this.boardName+"-s"+this.lastFromColumn+""+this.lastFromRow);
var _312=YAHOO.util.Dom.get(this.boardName+"-s"+this.lastToColumn+""+this.lastToRow);
}else{
var _311=YAHOO.util.Dom.get(this.boardName+"-s"+(7-this.lastFromColumn)+""+(7-this.lastFromRow));
var _312=YAHOO.util.Dom.get(this.boardName+"-s"+(7-this.lastToColumn)+""+(7-this.lastToRow));
}
this.updateFromTo(_311,_312,this.lastFromRow,this.lastFromColumn,this.lastToRow,this.lastToColumn);
}
};
Board.prototype.gotoMoveIndex=function(_313,_314,_315,_316,_317){
if(clog){
console.log("going to move index:"+_313);
}
var _318=!_315;
if(!this.moveArray||this.moveArray.length<=_313){
return;
}
var _319=this.boardName+"-piecestaken";
var _31a=YAHOO.util.Dom.get(_319);
if(_31a){
_31a.innerHTML="";
}
if(_313==-1){
var flip=false;
if(this.prev_move){
flip=true;
}
this.setupFromFen(this.startFen,flip,false,_317);
if(this.prev_move){
this.makeMove(this.prev_move,this.boardPieces[this.prev_move.fromColumn][this.prev_move.fromRow],!_315,this.moveAnimationLength,true,true);
this.updateToPlay();
}
if(this.moveArray&&this.moveArray.length>0){
this.setCurrentMove(this.moveArray[0],_314);
}else{
this.setCurrentMove(this.firstMove,_314);
}
if(!_314){
this.setForwardBack();
}
if(!_316){
for(var i=0;i<this.registeredGotoMoveIndexListeners.length;i++){
var _31d=this.registeredGotoMoveIndexListeners[i].gotoMoveIndexCallback(_313);
}
}
return;
}
var _31e=new Array();
var move=this.moveArray[_313];
if(clog&&move){
console.log("gotomoveindex move:"+move.output());
if(move.next){
console.log("gotomoveindex move.next:"+move.next.output());
}
if(move.prev){
console.log("gotomoveindex move.prev:"+move.prev.output());
}
}
var _320=0;
if(move.next!=null){
this.setCurrentMove(move.next,_314);
}else{
if(clog){
console.log("move next null with move:"+move.output());
}
}
while(move!=null&&!move.dummy){
_31e[_320++]=move;
move=move.prev;
}
var flip=false;
if(this.prev_move){
flip=true;
}
this.setupFromFen(this.startFen,flip,false,true);
if(this.prev_move){
if(clog){
console.log("gotomoveindex prev_move:"+this.prev_move.output());
}
this.makeMove(this.prev_move,this.boardPieces[this.prev_move.fromColumn][this.prev_move.fromRow],false,this.moveAnimationLength,true,true);
this.updateToPlay();
}
for(var i=_320-1;i>=1;i--){
var move=_31e[i];
this.makeMove(move,this.boardPieces[move.fromColumn][move.fromRow],false,this.moveAnimationLength,true,false);
this.toggleToMove();
}
if(!_314){
this.convertPiecesFromLightWeight(_313);
}
var move=_31e[0];
this.makeMove(move,this.boardPieces[move.fromColumn][move.fromRow],_318,this.moveAnimationLength,true,true);
this.toggleToMove();
this.updateToPlay();
if(!_314){
this.setForwardBack();
}
if(!_316){
for(var i=0;i<this.registeredGotoMoveIndexListeners.length;i++){
var _31d=this.registeredGotoMoveIndexListeners[i].gotoMoveIndexCallback(_313);
}
}
};
Board.prototype.gotoStart=function(e){
this.gotoMoveIndex(-1);
if(this.problem){
if(this.currentMove.bestMoves){
this.problem.showBestMoves(this.currentMove,this.currentMove.bestMoves,this.currentMove.correctMove,this.currentMove.wrongMove);
}else{
this.problem.clearBestMoves();
}
}
};
Board.prototype.gotoEnd=function(e){
if(this.tactics&&this.tactics.problemActive){
this.tactics.autoForward=false;
this.tactics.markProblem(false,false,"NULL","NULL");
}
this.gotoMoveIndex(-1,true,true,true);
var _323=0;
while(this.currentMove&&this.currentMove.next!=null){
var move=this.currentMove;
if(clog){
console.log("going to end move:"+move.output());
}
this.makeMove(move,this.boardPieces[move.fromColumn][move.fromRow],false,this.moveAnimationLength,true,true);
_323=move.index;
this.toggleToMove();
this.setCurrentMove(move.next);
}
for(var i=0;i<this.registeredGotoMoveIndexListeners.length;i++){
var _326=this.registeredGotoMoveIndexListeners[i].gotoMoveIndexCallback(_323);
}
};
Board.prototype.playMove=function(self){
if(!self.keepPlayingMoves||!self.currentMove||!self.currentMove.next){
var play=YAHOO.util.Dom.get(this.boardName+"-play");
play.src=this.boardImagePath+"/images/control_play_blue"+this.getVersString()+".gif";
self.keepPlayingMoves=false;
return;
}
self.forwardMove();
setTimeout(function(){
self.playMove(self);
},self.pauseBetweenMoves);
};
Board.prototype.getVersString=function(){
var _329=".vers"+SITE_VERSION;
if(!this.addVersion){
_329="";
}
return _329;
};
Board.prototype.playMoves=function(e){
this.keepPlayingMoves=true;
var play=YAHOO.util.Dom.get(this.boardName+"-play");
play.src=this.boardImagePath+"/images/disabled_control_play_blue"+this.getVersString()+".gif";
this.playMove(this);
};
Board.prototype.stopPlayingMoves=function(e){
this.keepPlayingMoves=false;
};
Board.prototype.showBoardFen=function(e){
var fen=this.boardToFen();
var _32f=new YAHOO.widget.SimpleDialog("fenDialog",{fixedcenter:true,visible:true,draggable:false,constraintoviewport:true,buttons:[{id:"linkbutton4",text:"Test"},{text:_js("Ok"),handler:function(){
_32f.hide();
},isDefault:true}]});
_32f.setHeader(_js("Position FEN"));
_32f.setBody("<textarea class=\"showPgn\" id=\"fenText\" rows=\"1\" readonly=\"true\" cols=\""+(fen.length+9)+"\">"+fen+"</textarea>");
_32f.render(document.body);
_32f.setFooter("<span id=\"copyToComment\"></span><span id=\"fenok\"></span>");
var _330=this;
var _331=new YAHOO.widget.Button({type:"button",label:_js("Copy To Comment"),container:"fenok",onclick:{fn:function(){
_330.copyFenToComment(fen);
_32f.hide();
}}});
var _332=new YAHOO.widget.Button({type:"button",label:_js("Ok"),container:"fenok",onclick:{fn:function(){
_32f.hide();
}}});
};
Board.prototype.copyFenToComment=function(fen){
var _334=YAHOO.util.Dom.get("commentField");
if(_334){
_334.value=_334.value+"[fen]"+fen+"[/fen]";
if(this.problem){
this.problem.commentSetup();
}
}
};
Board.prototype.copyAnalysisToComment=function(_335,fen,flip){
var _338=YAHOO.util.Dom.get("commentField");
if(_338){
var _339="";
if(flip=="true"){
_339="flip=true ";
}
_338.value=_338.value+"[moves "+_339+"start="+fen+"]"+_335+"[/moves]";
if(this.problem){
this.problem.commentSetup();
}
if(_338.scrollIntoView){
_338.scrollIntoView();
}
}
};
Board.prototype.analysePosition=function(e){
window.parentBoard=this;
var _33b=(this.pieceSize*8)+450+50;
var _33c=(this.pieceSize*8)+250;
var _33d=window.open("/windows/analyse.html","analysis_window","width="+_33b+",height="+_33c+",resizable=1,scrollbars=1,location=0,copyhistory=0,status=0,toolbar=0,menubar=0");
_33d.focus();
};
Board.prototype.backMove=function(e){
if(this.blockFowardBack||this.deferredBlockForwardBack){
return;
}
var _33f=this.currentMove;
if(this.tactics){
if(this.tactics.problemActive){
return;
}
}
this.blockForwardBack=true;
YAHOO.util.Dom.removeClass(this.lastFromSquare,"ct-from-square");
YAHOO.util.Dom.removeClass(this.lastToSquare,"ct-to-square");
this.lastFromRow=null;
if(this.currentMove&&this.currentMove.prev!=null){
this.toggleToMove();
this.updateToPlay();
move=this.currentMove.prev;
if(move){
if(clog){
console.log("backwards moving to prev move:"+move.output()+" from current move:"+this.currentMove.output());
}
}
this.setCurrentMove(move);
piece=this.boardPieces[move.toColumn][move.toRow];
if(!piece){
if(clog){
console.log("got empty piece in backMove");
}
}
takenPiece=move.taken;
this.board_xy=null;
piece.setPosition(move.fromColumn,move.fromRow,true,null,this.moveAnimationLength);
this.boardPieces[move.fromColumn][move.fromRow]=piece;
if(move.promotion){
piece.changePiece("p");
}
piece.setVisible(true);
this.canCastleQueenSide[0]=move.preCastleQueenSide[0];
this.canCastleQueenSide[1]=move.preCastleQueenSide[1];
this.canCastleKingSide[0]=move.preCastleKingSide[0];
this.canCastleKingSide[1]=move.preCastleKingSide[1];
var _340=false;
if(piece.piece==ChessPiece.KING&&Math.abs(move.fromColumn-move.toColumn)>1){
_340=true;
}
this.moveNumber--;
if(this.moveNumber<=0){
this.moveNumber=1;
}
if(takenPiece&&!_340){
this.board_xy=null;
var _341=move.toColumn;
var _342=move.toRow;
if(piece.piece==ChessPiece.PAWN&&move.fromColumn!=move.toColumn&&takenPiece.enPassant){
_342=move.fromRow;
this.boardPieces[move.toColumn][move.toRow]=null;
}
takenPiece.setPosition(_341,_342,false,null,this.moveAnimationLength);
this.boardPieces[_341][_342]=takenPiece;
move.taken=null;
this.processTaken(takenPiece,false);
}else{
this.boardPieces[move.toColumn][move.toRow]=null;
}
if(_340){
var _343=move.toRow;
var _344;
var _345;
if(move.fromColumn>move.toColumn){
_344=0;
_345=3;
}else{
_344=7;
_345=5;
}
var _346=this.boardPieces[_345][_343];
_346.setPosition(_344,_343,true,null,this.moveAnimationLength);
this.boardPieces[_344][_343]=_346;
}
if(move!=null&&move.prev!=null&&move.prev.next!=move){
move=move.prev.next;
if(clog){
if(move){
console.log("moving backwards out of variation moving to:"+move.output());
}else{
console.log("jumping out of variation to null move");
}
}
}
for(var i=0;i<this.registeredBackMovePreCurrentListeners.length;i++){
var _348=this.registeredBackMovePreCurrentListeners[i].backMovePreCurrentCallback(move,_33f);
}
this.setCurrentMove(move);
this.setForwardBack();
}
this.blockForwardBack=false;
};
Board.prototype.processTaken=function(_349,_34a){
var _34b=this.boardName+"-piecestaken";
var _34c=YAHOO.util.Dom.get(_34b);
if(_34c){
if(_34a){
var _34d=get_image_str(ChessPiece.pieceIconNames[_349.colour][_349.piece],this.boardImagePath,this.pieceSet,this.pieceTakenSize,this.addVersion);
_34c.innerHTML=_34c.innerHTML+"<img src=\""+_34d+"\"/>";
}else{
var _34e=_34c.innerHTML.split("<");
_34c.innerHTML="";
for(var i=1;i<_34e.length-1;i++){
_34c.innerHTML=_34c.innerHTML+"<"+_34e[i];
}
}
}
};
Pool=function(){
this.pool=new Array();
this.count=-1;
this.numGot=0;
this.numPut=0;
};
Pool.prototype.getObject=function(){
var o=null;
if(this.count>=0){
this.numGot++;
o=this.pool[this.count--];
}
return o;
};
Pool.prototype.putObject=function(o){
if(o!=null){
this.numPut++;
this.pool[++this.count]=o;
}
};
var boardPool=new Pool();
function touchHandler(_352){
var _353=_352.changedTouches,_354=_353[0],type="";
switch(_352.type){
case "touchstart":
type="mousedown";
break;
case "touchmove":
type="mousemove";
break;
case "touchend":
type="mouseup";
break;
default:
return;
}
var _356=document.createEvent("MouseEvent");
_356.initMouseEvent(type,true,true,window,1,_354.screenX,_354.screenY,_354.clientX,_354.clientY,false,false,false,false,0,null);
_354.target.dispatchEvent(_356);
_352.preventDefault();
}
function initIphone(_357){
_357.addEventListener("touchstart",touchHandler,true);
_357.addEventListener("touchmove",touchHandler,true);
_357.addEventListener("touchend",touchHandler,true);
_357.addEventListener("touchcancel",touchHandler,true);
}
FenBoard=function(fen,_359){
_359.pieceSize=24;
_359.fenBoard=true;
_359.dontOutputNavButtons=true;
this.chessapp=new ChessApp(_359);
this.chessapp.init();
this.chessapp.board.disableUpdateToPlay=true;
this.chessapp.board.setupFromFen(fen,false,false,false);
this.board=this.chessapp.board;
this.board.startFen=fen;
};


