/* 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.getBoard=function(){
  return this.board;
}
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,true);
_6f=this.board.prev_move;
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>=4&&_83.substring(0,4)=="e.p."){
continue;
}
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);
// German translation
_83 = _83.replace(/Q/,"D");
_83 = _83.replace(/R/,"T");
_83 = _83.replace(/B/,"L");
_83 = _83.replace(/N/,"S");
_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://www.schach-emmen.ch";
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="";
if(loggedIn){
if(this.config.isEndgame){
_1a=_js("Endgame Problem Set")+": "+_js(startEndgameSetName);
}else{
_1a=_js("Tactics Problem Set")+": "+_js(startTacticsSetName);
}
}
var _1b=new YAHOO.widget.SimpleDialog("starttacticdialog1",{width:"300px",fixedcenter:true,modal:false,visible:true,draggable:false,close:false,text:"<div style=\"color:black\">"+_1a+"</div><br/>"+"<div style=\"color:black\">"+_js("Click start to begin solving problems")+"</div>",icon:YAHOO.widget.SimpleDialog.ICON_INFO,constraintoviewport:true,buttons:[{text:_js("Start"),handler:function(){
this.hide();
_19.problem.getProblem();
},isDefault:true}]});
var _1c=YAHOO.util.Dom.get("ctb-"+this.board.boardName);
_1b.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 _1f=new Object();
for(prop in o){
if(typeof (o[prop])=="object"){
_1f[prop]=o[prop];
}else{
_1f[prop]=o[prop];
}
}
return _1f;
}
function clone(o){
return cloneWork(o);
}
get_image_str=function(_21,_22,_23,_24,_25){
var _26=".vers"+SITE_VERSION;
if(!_25){
_26="";
}
if(check_bad_msie()){
return _22+"/images/"+_23+"/"+_21+_24+_26+".png";
}else{
return _22+"/images/"+_23+"/"+_21+_24+_26+".png";
}
};
check_bad_msie=function(){
var _27=(window.ActiveXObject&&(typeof document.body.style.maxHeight=="undefined"));
return _27;
};
fix_ie_png=function(img){
if(!check_bad_msie()){
return;
}
var _29=(img.id)?"id='"+img.id+"' ":"";
var _2a=(img.className)?"class='"+img.className+"' ":"";
var _2b=(img.title)?"title='"+img.title+"' ":"title='"+img.alt+"' ";
var _2c="display:inline-block;"+img.style.cssText;
if(img.align=="left"){
_2c="float:left;"+_2c;
}
if(img.align=="right"){
_2c="float:right;"+_2c;
}
if(img.parentElement.href){
_2c="cursor:hand;"+_2c;
}
var _2d="<span "+_29+_2a+_2b+" style=\""+"width:"+img.width+"px; height:"+img.height+"px;"+_2c+";"+"filter:progid:DXImageTransform.Microsoft.AlphaImageLoader"+"(src='"+img.src+"', sizingMethod='image');\"></span>";
img.outerHTML=_2d;
};
Move=function(_2e,_2f,_30,_31,_32,_33,_34){
this.fromColumn=_2e;
this.fromRow=_2f;
this.toColumn=_30;
this.toRow=_31;
this.take=_32;
this.promotion=_33;
this.moveString=_34;
this.prev=null;
this.next=null;
this.numVars=0;
this.prevMoveEnpassant=false;
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(_36){
var _37=this.take;
if(_36&&_37){
_37=_37.makeLightWeight();
}
var _38=new Move(this.fromColumn,this.fromRow,this.toColumn,this.toRow,_37,this.promotion,this.moveString);
_38.moveNum=this.moveNum;
_38.atEnd=this.atEnd;
_38.beforeComment=this.beforeComment;
_38.afterComment=this.afterComment;
_38.prevMoveEnpassant=this.prevMoveEnpassant;
if(this.vars){
_38.vars=[];
var cnt=0;
for(var i=0;i<this.vars.length;i++){
_38.vars[i]=this.vars[i].clone(_36);
cnt++;
}
_38.numVars=cnt;
}
return _38;
};
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,_43){
if(a1==a2){
return _43;
}
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]==_43){
return a2[i];
}
}
return null;
};
Move.prototype.toMoveString=function(){
var _45="";
if(this.promotion){
_45=this.promotion;
}
return Move.columnToChar(this.fromColumn)+""+(this.fromRow+1)+Move.columnToChar(this.toColumn)+""+(this.toRow+1)+_45;
};
function getTagValue(_46,_47){
var _48=_46.getElementsByTagName(_47);
if(_48==null){
YAHOO.log("got null node for tag:"+_47);
return null;
}
if(_48.length==0){
YAHOO.log("got empty array node for tag:"+_47);
return null;
}
if(_48[0].firstChild==null){
YAHOO.log("firstChild is null for tag:"+_47);
return null;
}
if(_48[0].firstChild.nodeValue==null){
YAHOO.log("firstChild.nodeValue is null for tag:"+_47);
return null;
}
if(typeof (_48[0].textContent)!="undefined"){
return _48[0].textContent;
}
return _48[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);
function unescapeHtml(s){
var n=document.createElement("div");
n.innerHTML=s;
if(n.innerText){
return n.innerText;
}else{
return n.textContent;
}
}
ChessPiece=function(div,_4c,_4d,_4e){
var id=div.id;
this.board=_4e;
this.icon=get_image_str(ChessPiece.pieceIconNames[_4c][_4d],this.board.boardImagePath,this.board.pieceSet,this.board.pieceSize,this.board.addVersion);
this.colour=_4c;
this.piece=_4d;
this.id=id;
this.div=div;
var _50=_4e.getPieceDragDiv();
var _51=false;
var _52="";
if(_50==null){
_50=document.createElement("div");
_50.id="pieceDragDiv";
_51=true;
YAHOO.util.Dom.setStyle(_50,"visibility","hidden");
YAHOO.util.Dom.setStyle(_50,"border","0px");
YAHOO.util.Dom.setStyle(_50,"position","absolute");
}
this.pieceDragEl=_50;
this.pieceDragElId="pieceDragDiv";
if(_51){
var _53=this.board.getDocBody();
if(_53){
_53.appendChild(_50);
}
}
if(YAHOO.util.Event.isIE){
var _54=this.div;
_54.innerHTML="<img src=\""+this.icon+"\"/>";
var img=_54.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(_56){
if(this.board.dragDisabled){
return false;
}
if(this.board.toMove!=this.colour){
return false;
}
return this.oldIsValidHandleChild(_56);
};
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 _5f=null;
if(this.board.currentMove){
if(this.board.currentMove.prev){
_5f=this.board.currentMove.prev;
}else{
_5f=this.board.prev_move;
}
}else{
_5f=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 _63=7-i;
var _64=j;
if(this.board.isFlipped){
_63=7-_63;
_64=7-_64;
}
if((_63==this.row&&_64==this.column)||this.board.canMove(this.makeLightWeight(),_64,_63,_5f,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 _69=YAHOO.util.Dom.getX("ctb-"+this.board.boardName);
var _6a=YAHOO.util.Dom.getY("ctb-"+this.board.boardName);
var c=parseInt((x-_69)/this.board.pieceSize);
var r=parseInt((y-_6a)/this.board.pieceSize);
var _6d=this.board.boardName+"-s"+c+""+(7-r);
var _6e=YAHOO.util.Dom.get(_6d);
if(this.board.highlightValidSquares){
if(this.board.lastOverSquare){
if(this.board.lastOverSquare!=_6e){
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(_6e,"ct-over-valid-square");
}else{
YAHOO.util.Dom.addClass(_6e,"ct-over-invalid-square");
}
}
}
this.board.lastOverSquare=_6e;
}
};
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 _73=YAHOO.util.Dom.getX("ctb-"+this.board.boardName);
var _74=YAHOO.util.Dom.getY("ctb-"+this.board.boardName);
var c=parseInt((x-_73)/this.board.pieceSize);
var r=parseInt((y-_74)/this.board.pieceSize);
if(this.board.isFlipped){
r=7-r;
c=7-c;
}
var _77=false;
if(!this.board.currentMove||this.board.currentMove.atEnd){
_77=true;
}
this.board.updatePiece(this,c,7-r,false,false,true);
if(!_77&&this.board.currentMove&&!this.board.allowingFreeMovement&&this.board.currentMove.atEnd){
this.board.toggleToMove();
this.board.updateToPlay();
}
};
ChessPiece.prototype.removeFromParent=function(){
var _78=this.div;
if(_78.parentNode){
_78.parentNode.removeChild(_78);
}
};
ChessPiece.prototype.setVisible=function(_79){
var _7a;
var _7b;
if(_79){
_7b="block";
_7a="visible";
}else{
_7b="none";
_7a="hidden";
}
YAHOO.util.Dom.setStyle(this.id,"visibility",_7a);
};
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(_7e){
var _7f=(_7e+"").toLowerCase().charAt(0);
switch(_7f){
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 _80=this.div;
_80.innerHTML="<img src=\""+this.icon+"\"/>";
var img=_80.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(_82,row){
var _84=this.board.getBoardDiv();
var _85=this.board.getXY();
var _86=_85[0];
var _87=_85[1];
var _88=[0,0];
if(this.board.isFlipped){
_88[0]=_86+((7-_82)*this.board.pieceSize);
_88[1]=_87+((row)*this.board.pieceSize);
}else{
_88[0]=_86+((_82)*this.board.pieceSize);
_88[1]=_87+((7-row)*this.board.pieceSize);
}
return _88;
};
ChessPiece.prototype.setPosition=function(_89,row,_8b,_8c,_8d){
this.column=_89;
this.row=row;
if(this.board.pieceMoveDisabled){
return;
}
var _8e=this.div;
var _8f=null;
if(this.board.isFlipped){
_8f=this.board.boardName+"-s"+(7-this.column)+""+(7-this.row);
}else{
_8f=this.board.boardName+"-s"+(this.column)+""+(this.row);
}
var _90=this.board.getBoardDivFromId(_8f);
if(!_8b){
if(!this.board.settingUpPosition){
var _91=this.getNewXYPosition(_89,row);
YAHOO.util.Dom.setXY(_8e,_91,false);
}else{
if(_8e.parentNode){
_8e.parentNode.removeChild(_8e);
}
_90.appendChild(_8e);
}
this.setVisible(true);
if(_8c){
_8c();
}
}else{
var _91=this.getNewXYPosition(_89,row);
var _92=new YAHOO.util.Motion(_8e,{points:{to:_91}});
_92.duration=_8d;
var _93=this;
_92.onComplete.subscribe(function(){
});
if(_8c){
_92.onComplete.subscribe(_8c);
}
_92.animate();
}
};
ChessPiece.prototype.getFenLetter=function(){
var _94=ChessPiece.pieceTypeToChar(this.piece)+"";
if(this.colour!=ChessPiece.WHITE){
_94=_94.toLowerCase();
}
return _94;
};
ChessPiece.pieceTypeToChar=function(_95){
switch(_95){
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,_97,_98,_99){
this.board=_99;
this.colour=_97;
this.piece=_98;
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(_9b){
};
LightweightChessPiece.prototype.free=function(){
};
LightweightChessPiece.prototype.setPosition=function(_9c,row,_9e,_9f,_a0){
this.column=_9c;
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(_a2){
var _a3=(_a2+"").toLowerCase().charAt(0);
switch(_a3){
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(_a4,_a5){
this.board=_a4;
this.displayType=_a5;
};
MovesDisplay.DEFAULT_DISPLAY_TYPE=0;
MovesDisplay.MAIN_ON_OWN_LINE=1;
Board=function(_a6){
this.boardName=_a6;
if(_a6){
this.initTarget("ctb-"+_a6,"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(_a7){
if(_a7==ChessPiece.WHITE){
return ChessPiece.BLACK;
}else{
return ChessPiece.WHITE;
}
};
Board.boardStyleToClassName=function(_a8){
var _a9="";
switch(_a8){
case 0:
_a9="-lightgrey";
break;
case 1:
_a9="-grey";
break;
case 2:
_a9="-brown";
break;
case 3:
_a9="-green";
break;
case 4:
_a9="-woodlight";
break;
case 5:
_a9="-wooddark";
break;
case 6:
_a9="-metal";
break;
case 7:
_a9="-marblebrown";
break;
case 8:
_a9="-stucco";
break;
case 9:
_a9="-goldsilver";
break;
case 10:
_a9="-sandsnow";
break;
case 11:
_a9="-crackedstone";
break;
case 12:
_a9="-granite";
break;
case 13:
_a9="-marblegreen";
break;
case 14:
_a9="-greenwhite";
break;
default:
}
return _a9;
};
Board.createBoardArray=function(){
var _aa=boardPool.getObject();
if(_aa==null){
_aa=new Array(8);
for(var i=0;i<8;i++){
_aa[i]=new Array(8);
}
}
return _aa;
};
Board.prototype.toggleToMove=function(){
if(this.toMove==ChessPiece.WHITE){
this.toMove=ChessPiece.BLACK;
}else{
this.toMove=ChessPiece.WHITE;
}
};
Board.prototype.setupPieceDivs=function(){
var _ac=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(_ae,_af,_b0,_b1,_b2,_b3){
YAHOO.util.Dom.removeClass(this.lastFromSquare,"ct-from-square");
YAHOO.util.Dom.removeClass(this.lastToSquare,"ct-to-square");
if(_b0==null){
return;
}
this.lastFromSquare=_ae;
this.lastToSquare=_af;
this.lastFromRow=_b0;
this.lastFromColumn=_b1;
this.lastToRow=_b2;
this.lastToColumn=_b3;
if(this.highlightFromTo){
YAHOO.util.Dom.addClass(_ae,"ct-from-square");
YAHOO.util.Dom.addClass(_af,"ct-to-square");
}
};
Board.prototype.makeMove=function(_b4,_b5,_b6,_b7,_b8,_b9,_ba,_bb){
var _bc;
var _bd;
if(!this.isFlipped){
_bc=YAHOO.util.Dom.get(this.boardName+"-s"+_b4.fromColumn+""+_b4.fromRow);
_bd=YAHOO.util.Dom.get(this.boardName+"-s"+_b4.toColumn+""+_b4.toRow);
}else{
_bc=YAHOO.util.Dom.get(this.boardName+"-s"+(7-_b4.fromColumn)+""+(7-_b4.fromRow));
_bd=YAHOO.util.Dom.get(this.boardName+"-s"+(7-_b4.toColumn)+""+(7-_b4.toRow));
}
if(_b9){
this.updateFromTo(_bc,_bd,_b4.fromRow,_b4.fromColumn,_b4.toRow,_b4.toColumn);
}
var _be=this.boardPieces[_b4.toColumn][_b4.toRow];
if(_be!=null){
_be.enPassant=false;
_be.castled=false;
}
if(_b5.piece==ChessPiece.PAWN&&_b4.toColumn!=_b4.fromColumn&&this.boardPieces[_b4.toColumn][_b4.toRow]==null){
_be=this.boardPieces[_b4.toColumn][_b4.fromRow];
this.boardPieces[_b4.toColumn][_b4.fromRow]=null;
if(_be!=null){
_be.enPassant=true;
}
}
var _bf=null;
if(_b5.piece==ChessPiece.KING&&Math.abs(_b4.toColumn-_b4.fromColumn)>1){
var _c0;
var _c1;
if(_b4.toColumn>_b4.fromColumn){
_bf=this.boardPieces[7][_b4.fromRow];
_c0=_b4.fromRow;
_c1=5;
this.boardPieces[7][_b4.toRow]=null;
}else{
_bf=this.boardPieces[0][_b4.fromRow];
_c0=_b4.fromRow;
_c1=3;
this.boardPieces[0][_b4.toRow]=null;
}
if(!_bf){
alert("No castle piece");
}else{
_bf.setPosition(_c1,_c0,_b6,null,_b7);
this.boardPieces[_bf.column][_bf.row]=_bf;
_bf.castled=true;
}
}
_b4.taken=_be;
if(_be&&_b8){
this.processTaken(_be,true);
}
this.moveNumber++;
this.board_xy=null;
_b5.setPosition(_b4.toColumn,_b4.toRow,_b6,function(){
var tp=_be;
if(tp){
tp.setVisible(false);
}
if(_b4.promotion!=null){
_b5.changePiece(_b4.promotion);
}
if(_ba){
_ba.call(_bb);
}
},_b7);
if(!_b6){
if(_b4.promotion!=null){
_b5.changePiece(_b4.promotion);
}
}
this.boardPieces[_b4.fromColumn][_b4.fromRow]=null;
this.boardPieces[_b4.toColumn][_b4.toRow]=_b5;
if(_bf!=null){
_b4.taken=_bf;
}
_b4.preCastleQueenSide=new Array(2);
_b4.preCastleKingSide=new Array(2);
_b4.preCastleQueenSide[0]=this.canCastleQueenSide[0];
_b4.preCastleQueenSide[1]=this.canCastleQueenSide[1];
_b4.preCastleKingSide[0]=this.canCastleKingSide[0];
_b4.preCastleKingSide[1]=this.canCastleKingSide[1];
if(_b5.piece==ChessPiece.ROOK){
if(_b4.fromColumn==0){
this.canCastleQueenSide[_b5.colour]=false;
}else{
if(_b4.fromColumn==7){
this.canCastleKingSide[_b5.colour]=false;
}
}
}else{
if(_b5.piece==ChessPiece.KING){
this.canCastleQueenSide[_b5.colour]=false;
this.canCastleKingSide[_b5.colour]=false;
}
}
};
Board.prototype.promptPromotion=function(_c3,col,row,_c6,_c7){
_c3.prePromotionColumn=_c3.column;
_c3.prePromotionRow=_c3.row;
_c3.setPosition(col,row,false,null,this.moveAnimationLength);
var _c8=this;
var _c9=new YAHOO.widget.Dialog("promotionDialogId",{width:"300px",fixedcenter:true,visible:true,modal:true,close:false,constraintoviewport:true,buttons:[{text:_js("Queen"),handler:function(){
_c9.hide();
_c8.updatePiece(_c3,col,row,_c6,_c7,false,"q");
},isDefault:true},{text:_js("Rook"),handler:function(){
_c9.hide();
_c8.updatePiece(_c3,col,row,_c6,_c7,false,"r");
},isDefault:false},{text:_js("Bishop"),handler:function(){
_c9.hide();
_c8.updatePiece(_c3,col,row,_c6,_c7,false,"b");
},isDefault:false},{text:_js("Knight"),handler:function(){
_c9.hide();
_c8.updatePiece(_c3,col,row,_c6,_c7,false,"n");
},isDefault:false}]});
_c9.setHeader(_js("Select Promotion Piece"));
_c9.setBody("<div></div>");
_c9.render(document.body);
};
Board.moveToLocale=function(_ca){
if(!_ca||_ca==""){
return _ca;
}
var _cb="";
for(var i=0;i<_ca.length;i++){
var _cd=_ca.charAt(i);
switch(_cd){
case "K":
_cd=_js("K");
break;
case "Q":
_cd=_js("Q");
break;
case "R":
_cd=_js("R");
break;
case "N":
_cd=_js("N");
break;
case "B":
_cd=_js("B");
break;
case "P":
_cd=_js("P");
break;
case "a":
_cd=_js("a");
break;
case "b":
_cd=_js("b");
break;
case "c":
_cd=_js("c");
break;
case "d":
_cd=_js("d");
break;
case "e":
_cd=_js("e");
break;
case "f":
_cd=_js("f");
break;
case "g":
_cd=_js("g");
break;
case "h":
_cd=_js("h");
break;
case "x":
_cd=_js("x");
break;
case "#":
_cd=_js("#");
break;
}
_cb+=_cd;
}
return _cb;
};
Board.prototype.updatePiece=function(_ce,col,row,_d1,_d2,_d3,_d4,_d5){
if(_d4){
this.board_xy=null;
if(_ce.prePromotionRow){
_ce.row=_ce.prePromotionRow;
_ce.column=_ce.prePromotionColumn;
}
}
if(_d4==null&&_ce.column==col&&_ce.row==row){
this.board_xy=null;
_ce.setPosition(_ce.column,_ce.row,false,null,this.moveAnimationLength);
if(clog){
console.log("moved piece back to its orig position");
}
return;
}
var _d6=null;
if(this.currentMove){
if(this.currentMove.prev){
_d6=this.currentMove.prev;
}else{
_d6=this.prev_move;
}
}else{
_d6=this.prev_move;
}
if(clog){
if(this.currentMove){
console.log("updatepiece currentMove:"+this.currentMove.output());
}else{
console.log("updatepiece currentmove null");
}
}
if(!_d1&&!this.canMove(_ce.makeLightWeight(),col,row,_d6,true)){
this.board_xy=null;
_ce.setPosition(_ce.column,_ce.row,false,null,0.5);
if(clog){
console.log("move not legal , move back to orig:"+this.toMove);
if(_d6){
console.log("prevMove was:"+_d6.output());
}else{
console.log("prevMove was null");
}
}
return;
}
var _d7="";
if(_d3&&_ce.piece==ChessPiece.PAWN&&(row==7||row==0)){
this.promptPromotion(_ce,col,row,_d1,_d2);
return;
}else{
if(_d4!=null){
_d7=_d4;
}
}
var _d8=true;
var _d9="";
_d9+=Move.columnToChar(_ce.column);
_d9+=String.fromCharCode("1".charCodeAt(0)+_ce.row);
_d9+=Move.columnToChar(col);
_d9+=String.fromCharCode("1".charCodeAt(0)+(row));
if(_d7){
_d9+=_d7;
}
var _da=this.createMoveFromString(_d9);
var _db=this.currentMove;
if(_db){
_da.moveNum=_db.moveNum;
}
var res=null;
for(var i=0;i<this.registeredUpdateListeners.length;i++){
_de=this.registeredUpdateListeners[i].updatePieceCallback(_d7,_ce,col,row,_d1,_d2,_d3,_d4,_d5,_d6,this.currentMove,_da);
if(!_de){
return false;
}
if(!_de.ignoreRetVal){
res=_de;
}
}
if(!res){
return false;
}
if(res.allowMove){
var _db=res.move;
for(var i=0;i<this.registeredUpdateAllowMoveListeners.length;i++){
var _df=this.registeredUpdateAllowMoveListeners[i].updateAllowMoveCallback(_d7,_ce,col,row,_d1,_d2,_d3,_d4,_d5,_db);
}
YAHOO.log("Made correct move");
this.makeMove(_db,_ce,_d2,this.moveAnimationLength,true,true);
var _e0=!res.dontMakeOpponentMove&&!_d1&&(this.currentMove&&this.currentMove.next&&!this.currentMove.next.atEnd);
if(clog){
if(_db.next){
console.log("setting current move in updatepiece to:"+_db.next.output());
}else{
console.log("in updatepiece, current move being set to null");
}
}
this.setCurrentMove(_db.next,false,_e0);
if(this.currentMove.atEnd){
for(var i=0;i<this.registeredUpdateEndOfMovesListeners.length;i++){
var res=this.registeredUpdateEndOfMovesListeners[i].updateEndOfMovesCallback(_d7,_ce,col,row,_d1,_d2,_d3,_d4,_d5);
}
}
if(_e0){
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 _db=res.move;
var _e1=_ce.column;
var _e2=_ce.row;
this.board_xy=null;
_ce.setPosition(_ce.column,_ce.row,false,null,this.moveAnimationLength);
for(var i=0;i<this.registeredUpdateWrongMoveListeners.length;i++){
var res=this.registeredUpdateWrongMoveListeners[i].updateWrongMoveCallback(_d7,_ce,col,row,_d1,_d2,_d3,_d4,_d5,_db);
}
}
for(var i=0;i<this.registeredUpdatePieceFinishedListeners.length;i++){
var _de=this.registeredUpdatePieceFinishedListeners[i].updatePieceFinishedCallback(_d7,_ce,col,row,_d1,_d2,_d3,_d4,_d5,_d6,this.currentMove,_da);
}
};
Board.prototype.addGotoMoveIndexListener=function(_e3){
this.registeredGotoMoveIndexListeners.push(_e3);
};
Board.prototype.addBackMovePreCurrentListener=function(_e4){
this.registeredBackMovePreCurrentListeners.push(_e4);
};
Board.prototype.addForwardMovePostUpdateListener=function(_e5){
this.registeredForwardMovePostUpdateListeners.push(_e5);
};
Board.prototype.addUpdatePieceListener=function(_e6){
this.registeredUpdateListeners.push(_e6);
};
Board.prototype.addUpdatePieceFinishedListener=function(_e7){
this.registeredUpdatePieceFinishedListeners.push(_e7);
};
Board.prototype.addUpdatePieceEndOfMovesListener=function(_e8){
this.registeredUpdateEndOfMovesListeners.push(_e8);
};
Board.prototype.addUpdatePieceHaveAltListener=function(_e9){
this.registeredUpdateHaveAltListeners.push(_e9);
};
Board.prototype.addUpdatePieceAllowMoveListener=function(_ea){
this.registeredUpdateAllowMoveListeners.push(_ea);
};
Board.prototype.addUpdatePieceWrongMoveListener=function(_eb){
this.registeredUpdateWrongMoveListeners.push(_eb);
};
Board.prototype.scoreToShortString=function(_ec){
if(_ec=="draw"){
return "D";
}
if(_ec>=0){
return "M"+_ec;
}else{
return "L"+(-1*_ec);
}
};
Board.prototype.scoreToLongString=function(_ed){
if(_ed=="draw"){
return _js("Draw");
}
if(_ed==0){
return _js("Mate");
}else{
if(_ed>0){
return __js("Mate in {NUMBER_MOVES}",[["NUMBER_MOVES",_ed]]);
}else{
return __js("Lose in {NUMBER_MOVES}",[["NUMBER_MOVES",(-1*_ed)]]);
}
}
};
Board.prototype.egMoveToScoreString=function(_ee){
var _ef=_ee.score;
var _f0=_ee.optimal_score;
var s=this.scoreToShortString(_ef);
var opt=this.scoreToShortString(_f0);
var _f3=this.scoreToLongString(_ef);
var _f4=this.scoreToLongString(_f0);
if(_ef==_f0){
return ["",_f3];
}else{
var _f5="ct-subopt-move-score";
if(_ef=="draw"||_ef<0){
_f5="ct-bad-move-score";
}
return ["<span class=\""+_f5+"\">"+s+"("+opt+")</span>",_f3+"("+_f4+")"];
}
};
Board.prototype.makeShortAlgabraic=function(_f6,_f7,_f8,_f9,_fa){
if(clog){
console.log("fromCol:"+_f6+" fromRow:"+_f7+" toCol:"+_f8+" toRow:"+_f9);
}
var _fb=this.boardPieces[_f6][_f7];
var _fc=_fb.piece;
var _fd=ChessPiece.pieceTypeToChar(_fc);
var _fe="";
if(_fc==ChessPiece.PAWN){
if(_f6==_f8){
_fe=Move.columnToChar(_f6)+""+(_f9+1);
}else{
_fe=Move.columnToChar(_f6)+"x"+Move.columnToChar(_f8)+""+(_f9+1);
if(!this.boardPieces[_f8][_f9]){
_fe+=" e.p.";
}
}
}else{
if(_fc==ChessPiece.KING){
var _ff=Math.abs(_f6-_f8);
if(_ff==1||_ff==0){
_fe=_fd;
if(this.boardPieces[_f8][_f9]){
_fe+="x";
}
_fe+=Move.columnToChar(_f8)+""+(_f9+1);
}else{
if(_f8==6){
_fe="O-O";
}else{
_fe="O-O-O";
}
}
}else{
var _100=[];
for(var row=0;row<8;row++){
for(var col=0;col<8;col++){
var cp=this.boardPieces[col][row];
if(cp&&cp.colour==_fb.colour&&cp.piece==_fc&&!(_fb.column==cp.column&&_fb.row==cp.row)){
var prev=null;
if(this.currentMove){
prev=this.currentMove.prev;
}
if(this.canMove(cp.makeLightWeight(),_f8,_f9,prev,true)){
_100.push(cp);
}
}
}
}
_fe=_fd;
if(_100.length>0){
var _105=false;
var _106=false;
for(var i=0;i<_100.length;i++){
if(_100[i].row==_f7){
_106=true;
}
if(_100[i].column==_f6){
_105=true;
}
}
if(_106||!(_106||_105)){
_fe+=Move.columnToChar(_f6);
}
if(_105){
_fe+=""+(_f7+1);
}
}
if(this.boardPieces[_f8][_f9]){
_fe+="x";
}
_fe+=Move.columnToChar(_f8)+""+(_f9+1);
}
}
var _108="";
var _109="";
if(_fa){
var _10a=this.cloneBoard();
var _10b=ChessPiece.WHITE;
if(_10a.boardPieces[_fa.fromColumn][_fa.fromRow].colour==ChessPiece.WHITE){
_10b=ChessPiece.BLACK;
}
_10a.makeMove(_fa,_10a.boardPieces[_fa.fromColumn][_fa.fromRow],false,_10a.moveAnimationLength,false,false);
if(!_10a.isKingSafe(_10b,_fa)){
_108="+";
if(_10a.isKingMated(_10b,_fa)){
_108="#";
}
}
if(_fa.promotion){
_109="="+((_fa.promotion+"").toUpperCase());
}
}
_fe+=_109+_108;
return _fe;
};
Board.getVarMove=function(move,row,col,_10f,_110){
if(move.vars&&move.vars.length>0){
var i=0;
for(var i=0;i<move.vars.length;i++){
var _112=move.vars[i];
if(_112.fromColumn==_10f.column&&_112.fromRow==_10f.row&&_112.toRow==row&&_112.toColumn==col&&(_110==""||(_110==_112.promotion))){
return _112;
}
}
}
};
Board.prototype.createMoveFromString=function(_113){
var _114=0;
var take=false;
var _116=null;
var _117=_113.charCodeAt(_114++);
var _118=_113.charCodeAt(_114++);
var _119=_113.split("|");
var pgn=null;
if(_119.length>1){
pgn=_119[1];
_113=_119[0];
}else{
_113=_119[0];
}
if(_113.charAt(_114)=="x"){
_114++;
take=true;
}
var _11b=_113.charCodeAt(_114++);
var _11c=_113.charCodeAt(_114++);
if(_114<_113.length){
_116=_113.charAt(_114);
}
var move=new Move(_117-("a".charCodeAt(0)),_118-("1".charCodeAt(0)),_11b-("a".charCodeAt(0)),_11c-("1".charCodeAt(0)),take,_116,_113);
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 _11f=this.getForwardButton();
var end=this.getEndButton();
var _121=this.getStartButton();
if(!this.currentMove){
if(back){
back.src=this.boardImagePath+"/images/resultset_previous_disabled"+this.getVersString()+".gif";
}
if(_121){
_121.src=this.boardImagePath+"/images/disabled_resultset_first"+this.getVersString()+".gif";
}
if(_11f){
_11f.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(_121){
_121.src=this.boardImagePath+"/images/disabled_resultset_first"+this.getVersString()+".gif";
}
}else{
if(back){
back.src=this.boardImagePath+"/images/resultset_previous"+this.getVersString()+".gif";
}
if(_121){
_121.src=this.boardImagePath+"/images/resultset_first"+this.getVersString()+".gif";
}
}
if(this.currentMove.atEnd){
if(_11f){
_11f.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(_11f){
_11f.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(_122){
var _123=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 _126=this.boardPieces[i][j];
var p=_126.makeHeavyWeight();
this.boardPieces[i][j]=p;
p.setPosition(p.column,p.row,false,null,this.moveAnimationLength);
p.setVisible(true);
}
}
}
var move=this.moveArray[_122];
while(move!=null){
if(move.taken){
move.taken=move.taken.makeHeavyWeight();
}
move=move.prev;
}
this.settingUpPosition=_123;
};
MovesDisplay.prototype.setToMove=function(_129){
this.toMove=_129;
};
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 _12c=t.id.substr((this.board.boardName+"-m").length);
if(clog){
console.log("got goto move index:"+_12c);
}
this.board.gotoMoveIndex(_12c,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(_12d,_12e,_12f,_130){
var _131="";
if(_12e>this.board.ml){
return _131;
}
if(this.board.ml==1&&_130>1){
return _131;
}
var _132=this.getMovesDisplay();
if(_132){
if(_12d==0&&this.displayType==MovesDisplay.MAIN_ON_OWN_LINE){
if(this.firstNonMove){
_131+="<div class=\"ct-mainline-commentary\"/>";
this.pendingLevelZeroCommentaryClose=true;
}
}
if(this.variationOnOwnLine){
_131+="<br/>";
}
if(this.board.showBracketsOnVariation&&(!this.board.hideBracketsOnTopLevelVariation||_12d>0)){
_131+="<span>"+this.board.variationStartString+"</span>";
}
}
this.firstNonMove=false;
return _131;
};
MovesDisplay.prototype.outputVariationEnd=function(_133,_134,_135,_136){
var _137=this.getMovesDisplay();
var _138="";
if(this.board.ml==1&&_134>0&&this.board.outputFirstVar){
return _138;
}
this.board.outputFirstVar=true;
if(_137){
if(this.board.showBracketsOnVariation&&(!this.board.hideBracketsOnTopLevelVariation||_133>1)){
_138+="<span>"+this.board.variationEndString+"</span>";
}
}
if(_133==1&&this.displayType==MovesDisplay.MAIN_ON_OWN_LINE){
}
this.firstNonMove=false;
return _138;
};
MovesDisplay.prototype.outputComment=function(_139,_13a,_13b){
if(this.board.ignoreCommentRegex){
var _13c=new RegExp(this.board.ignoreCommentRegex);
if(_13c.test(_139)){
return "";
}
}
var _13d="";
if(this.board.ml==1){
return _13d;
}
var _13e=this.getMovesDisplay();
if(_13e){
if(_13a==0&&this.displayType==MovesDisplay.MAIN_ON_OWN_LINE){
if(this.firstNonMove){
_13d+="<br/>";
}
_13d+="<div class=\"ct-mainline-commentary\">";
this.pendingLevelZeroCommentaryClose=true;
}
var _13f="ct-board-move-comment";
if(_13b){
_13f="ct-board-move-alt-comment";
}
_13d+="<span class=\""+_13f+"\"> "+_139+" </span>";
if(_13a==0&&this.displayType==MovesDisplay.MAIN_ON_OWN_LINE){
}
}
this.firstNonMove=false;
return _13d;
};
MovesDisplay.prototype.outputNag=function(_140){
var _141="";
var _142=this.getMovesDisplay();
if(_142){
var _143=null;
switch(_140){
case 11:
_143="=";
break;
case 14:
_143="+=";
break;
case 15:
_143="=+";
break;
case 16:
_143="+/-";
break;
case 17:
_143="-/+";
break;
case 18:
_143="+-";
break;
case 19:
_143="-+";
break;
case 20:
_143="+--";
break;
case 21:
_143="--+";
break;
default:
}
if(_143){
_141+="<span> "+_143+" </span>";
}
}
return _141;
};
MovesDisplay.prototype.outputResult=function(_144){
return "<span class=\"ct-result\">"+_144+"</span>";
};
MovesDisplay.prototype.outputMove=function(_145,_146,_147,_148,_149,_14a,_14b,move,_14d,_14e){
if(clog){
console.log("outputMove:"+_148+" hideScore:"+_14d);
}
var _14f="";
var _150=this.getMovesDisplay();
if(this.board.tr&&_146>0&&(_14a>1||_14b>3)&&!_149){
return _14f;
}
if(this.board.ml==1&&_14a>0&&this.board.outputFirstVar){
return _14f;
}
if(_150){
var _151=""+Math.round(_147/2)+". ";
if(_147%2!=1){
if(clog){
console.log("firstRav:"+_149+" firstNonMove:"+this.firstNonMove);
}
if(_149||!this.firstNonMove){
_151=Math.round(_147/2)+"... ";
}else{
_151="";
}
}
if(clog){
console.log("moveNum:"+_147+" moveNumOut:"+_151);
}
if(this.displayType==MovesDisplay.MAIN_ON_OWN_LINE&&_146==0&&(!this.firstNonMove||_147%2==1)){
if(this.pendingLevelZeroCommentaryClose){
this.pendingLevelZeroCommentaryClose=false;
_14f+="</div>";
}
if(this.board.newlineForEachMainMove){
_14f+="<br/>";
}
}
var _152="";
var _153="";
if(move&&move.eg_move){
var res=this.board.egMoveToScoreString(move.eg_move);
_152=res[0];
_153=res[1];
}
var _155="";
if(_14d){
_155="initially_hidden";
}
if(_152!=""){
_152=" "+_152;
}
var _156="title";
if(_14d){
_156="alt";
}
var _157="";
if(_14e){
_157=" rel=\""+_148+"\" ";
_148="___";
}
_14f+="<span "+_157+_156+"=\""+_153+"\" id=\""+this.board.boardName+"-m"+_145+"\" class=\""+((_146==0)?"ct-board-move-mainline":"ct-board-move-variation")+"\">"+_151+_148+"<span id=\""+this.board.boardName+"-msc"+_145+"\" class=\""+_155+"\">"+_152+"</span></span>";
}
this.firstNonMove=true;
return _14f;
};
Board.prototype.setMoveSeqLalg=function(_158,_159,_15a,_15b){
var _15c=new Array();
if(_158&&_158.length>0){
_15c=_158.replace(/\s+$/g,"").split(" ");
}
this.setupFromLalgArray(_15c,_15b,_15a,_159);
};
Board.prototype.setupFromLalgArray=function(_15d,_15e,_15f,_160){
this.outputFirstVar=false;
if(this.movesDisplay){
var md=this.movesDisplay.getMovesDisplay();
if(md){
YAHOO.util.Event.purgeElement(md,true);
}
}
if(!_160){
_160=new Array();
}
var _162=this.cloneBoard();
this.movesDisplay.firstNonMove=false;
var _163=new Array();
var _164=new Array();
if(this.prev_move){
_162.makeMove(this.prev_move,_162.boardPieces[this.prev_move.fromColumn][this.prev_move.fromRow],false,_162.moveAnimationLength,false,false);
}
var _165=_162.cloneBoard();
var _166=null;
var _167=0;
var _168="";
var _169=false;
var _16a=false;
var _16b=0;
var _16c=false;
var _16d=new Array();
var _16e=new Array();
_16e[0]=0;
var _16f=new Array();
var _170=new Array();
var _171=_15f*2-1;
var _172=_15f*2-1;
var _173=new Array();
var _174=ChessPiece.WHITE;
var _175=0;
var eval="";
var _177="";
var _178="";
var time="";
var _17a=-1;
var _17b=0;
for(var i=0;i<_15d.length;i++){
var _17d=0;
if(_15d[i]=="ALT"){
_16a=true;
continue;
}
if(_15d[i].indexOf("EVAL")==0){
eval=_15d[i].split(":")[1];
if(parseInt(eval)>=175&&_16b>0&&_16e[_16b]>1){
_16a=true;
}
continue;
}
if(_15d[i].indexOf("DEPTH")==0){
_177=_15d[i].split(":")[1];
continue;
}
if(_15d[i].indexOf("NODES")==0){
_178=_15d[i].split(":")[1];
continue;
}
if(_15d[i].indexOf("TIME")==0){
time=_15d[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 _17f=e.split(" ");
_17d=parseInt(_17f[1]);
e=_js("mate")+" "+_17f[1];
if(_16e[_16b]==1){
_17a=_17d;
}
}
_17b=_17d;
if(_17d<0){
_16a=false;
}else{
if(_17d>0&&_17d<8&&_16b>0&&_16e[_16b]>1){
_16a=true;
}
}
var _180="";
if(_16a){
_180=_js("ALT")+" ";
}
var t=parseInt(time);
var nps=" "+__js("nps:{NODES_PER_SECOND}",[["NODES_PER_SECOND",Math.round(parseInt(_178)/(parseInt(time)/1000))]]);
if(!this.showNPS){
nps="";
}
if(!(_16b>0&&_16e[_16b]>this.ml)){
_15d[i]=_180+e+" ("+__js("depth:{DEPTH}",[["DEPTH",_177]])+nps+")";
}else{
_15d[i]="";
}
}
if(_15d[i]=="}"){
_169=false;
if(this.movesDisplay){
_168=_168.replace(/\s+$/g,"");
_173.push(this.movesDisplay.outputComment(_168,_16b,_16a));
}
continue;
}else{
if(_169){
_168+=_15d[i]+" ";
continue;
}else{
if(_15d[i]=="{"){
_168="";
_169=true;
continue;
}else{
if(_15d[i]=="("){
if(!_16e[_16b+1]){
_16e[_16b+1]=0;
}
_16e[_16b+1]++;
if(this.movesDisplay){
_173.push(this.movesDisplay.outputVariationStart(_16b,_16e[_16b+1],_171,_16d[0]));
}
_16d[_16b]=_171;
_16f[_16b]=_166;
_170[_16b]=_174;
_163[_16b]=_162;
_164[_16b]=_165;
_162=_165.cloneBoard();
_16b++;
_171--;
_16c=true;
continue;
}else{
if(_15d[i]==")"){
if(this.movesDisplay){
_173.push(this.movesDisplay.outputVariationEnd(_16b,_16e[_16b],_171,_16d[0]));
}
var _183=new Move();
_183.atEnd=true;
_166.next=_183;
_183.prev=_166;
_16b--;
_171=_16d[_16b];
_166=_16f[_16b];
_174=_170[_16b];
_162=_163[_16b];
_165=_164[_16b];
_16a=false;
continue;
}else{
if(_15d[i].charAt(0)=="$"){
if(this.movesDisplay){
_173.push(this.movesDisplay.outputNag(parseInt(_15d[i].substring(1))));
}
continue;
}
}
}
}
}
}
var move=this.createMoveFromString(_15d[i]);
var _185=false;
if(_171==_172&&this.boardPieces[move.fromColumn][move.fromRow].colour==ChessPiece.BLACK){
_171++;
_185=true;
_174=ChessPiece.BLACK;
}
move.index=_167;
var _186=(move.pgn)?move.pgn:move.moveString;
if(move.pgn){
_186=move.pgn;
}else{
_186=_162.makeShortAlgabraic(move.fromColumn,move.fromRow,move.toColumn,move.toRow,move);
move.SAN=_186;
}
_186=Board.moveToLocale(_186);
if(this.movesDisplay){
this.movesDisplay.setToMove(_174);
_173.push(this.movesDisplay.outputMove(_167,_16b,_171,_186+" ",_16c,_16e[_16b],_16d[0]));
}
_174=(_174==ChessPiece.BLACK)?ChessPiece.WHITE:ChessPiece.BLACK;
move.moveNum=_171;
_171++;
if(_16b>0){
if(_16c){
var _187=_166;
if(_187==null){
alert("Got no previous move for variation:"+movesArra[i]);
}
if(_187.numVars==0){
_187.vars=new Array();
}
move.isAlt=_16a;
move.mateInMoves=_17b;
_187.vars[_187.numVars++]=move;
move.prev=_187.prev;
_16c=false;
}else{
move.prev=_166;
if(_166!=null){
_166.next=move;
}
}
}else{
move.prev=_166;
if(_166!=null){
_166.next=move;
}
}
_16e[_16b+1]=0;
if(_16b==0){
_175=_167;
}
_160[_167++]=move;
_162.moveArray[_167-1]=move;
_166=move;
_165=_162.cloneBoard();
_162.makeMove(move,_162.boardPieces[move.fromColumn][move.fromRow],false,_162.moveAnimationLength,false,false);
}
if(this.movesDisplay&&!this.disableMoveOutput){
var _188=this.movesDisplay.getMovesDisplay();
_173.push(this.movesDisplay.outputResult(_15e));
this.pendingMovesOutput=_173.join("");
this.pendingMovesOutputCount=_167;
}
this.lastMoveIndex=_175;
if(_166!=null){
var _183=new Move();
_183.atEnd=true;
_166.next=_183;
_183.prev=_166;
}
this.lastCount=_167;
};
Board.prototype.lalgToMoveList=function(_189,_18a,_18b,_18c,_18d){
if(ctime){
console.time("lalgToMoveList");
}
if(clog){
console.log("startMoveNum:"+_18b);
}
if(!_18c){
_18c=new Array();
}
var _18e=this.cloneBoard();
var _18f=new Array();
var _190=new Array();
if(!_18d&&this.prev_move){
_18e.makeMove(this.prev_move,_18e.boardPieces[this.prev_move.fromColumn][this.prev_move.fromRow],false,_18e.moveAnimationLength,false,false);
}
var _191=_18e.cloneBoard();
var nags=[];
var _193=null;
var _194=0;
var _195="";
var _196=false;
var _197=0;
var _198=false;
var _199=new Array();
var _19a=new Array();
_19a[0]=0;
var _19b=new Array();
var _19c=new Array();
var _19d=_18b*2-1;
var _19e=new Array();
var _19f=ChessPiece.WHITE;
var _1a0=0;
var _1a1=true;
for(var i=0;i<_189.length;i++){
if(_189[i]=="}"){
_196=false;
_195=_195.replace(/\s+$/g,"");
continue;
}else{
if(_196){
_195+=_189[i]+" ";
continue;
}else{
if(_189[i]=="{"){
if(_195){
if(_193){
_193.afterComment=trimStr(_195);
}
}
_195="";
_196=true;
continue;
}else{
if(_189[i]=="("){
if(_193){
_193.afterComment=trimStr(_195);
_195="";
}
if(!_19a[_197+1]){
_19a[_197+1]=0;
}
_19a[_197+1]++;
_199[_197]=_19d;
_19b[_197]=_193;
_19c[_197]=_19f;
_18f[_197]=_18e;
_190[_197]=_191;
_18e=_191.cloneBoard();
_197++;
_19d--;
_198=true;
continue;
}else{
if(_189[i]==")"){
if(_193){
_193.afterComment=trimStr(_195);
_195="";
}
var _1a3=new Move();
_1a3.atEnd=true;
_193.next=_1a3;
_1a3.prev=_193;
_197--;
_19d=_199[_197];
_193=_19b[_197];
_19f=_19c[_197];
_18e=_18f[_197];
_191=_190[_197];
continue;
}else{
if(_189[i].charAt(0)=="$"){
nags.push(parseInt(_189[i].substring(1)));
continue;
}
}
}
}
}
}
var move=this.createMoveFromString(_189[i]);
move.nags=nags;
move.beforeComment=trimStr(_195);
_195=null;
nags=[];
if(_1a1){
if(this.boardPieces[move.fromColumn][move.fromRow].colour==ChessPiece.BLACK){
_19d++;
_19f=ChessPiece.BLACK;
if(clog){
console.log("first move black new movenum:"+_19d);
}
}
_1a1=false;
}
move.index=_194;
var _1a5=(move.pgn)?move.pgn:move.moveString;
if(move.pgn){
_1a5=move.pgn;
move.SAN=move.pgn;
}else{
_1a5=_18e.makeShortAlgabraic(move.fromColumn,move.fromRow,move.toColumn,move.toRow,move);
move.SAN=_1a5;
}
_19f=(_19f==ChessPiece.BLACK)?ChessPiece.WHITE:ChessPiece.BLACK;
move.moveNum=_19d;
_19d++;
if(_197>0){
if(_198){
var _1a6=_193;
if(_1a6==null){
alert("Got no previous move for variation:"+movesArra[i]);
}
if(_1a6.numVars==0){
_1a6.vars=new Array();
}
_1a6.vars[_1a6.numVars++]=move;
move.prev=_1a6.prev;
_198=false;
}else{
move.prev=_193;
if(_193!=null){
_193.next=move;
}
}
}else{
move.prev=_193;
if(_193!=null){
_193.next=move;
}
}
_19a[_197+1]=0;
if(_197==0){
_1a0=_194;
}
_18c[_194++]=move;
_18e.moveArray[_194-1]=move;
_193=move;
_191=_18e.cloneBoard();
_18e.makeMove(move,_18e.boardPieces[move.fromColumn][move.fromRow],false,_18e.moveAnimationLength,false,false);
}
if(_193!=null){
var _1a3=new Move();
_1a3.atEnd=true;
_193.next=_1a3;
_1a3.prev=_193;
_193.afterComment=trimStr(_195);
}
if(ctime){
console.timeEnd("lalgToMoveList");
}
return _18c;
};
Board.prototype.reset=function(fen){
this.clearMoveList();
if(fen){
this.setupFromFen(fen);
}else{
this.setupFromFen(Board.INITIAL_FEN);
}
};
Board.prototype.clearMoveList=function(_1a8){
this.movesDisplay.firstNonMove=false;
var _1a9=this.movesDisplay.getMovesDisplay();
if(_1a9){
YAHOO.util.Event.purgeElement(_1a9,true);
_1a9.innerHTML="";
}
this.currentMove=null;
this.moveIndex=-1;
if(_1a8){
_1a8.prev=null;
this.startMoveNum=_1a8.moveNum;
}else{
this.startMoveNum=1;
}
};
Board.prototype.insertMovesFromMoveList=function(_1aa,_1ab,_1ac){
var _1ad=!_1ab;
if(ctime&&_1ad){
console.time("insertMovesFromMoveList");
}
if(!this.movesDisplay){
return;
}
if(_1ad){
this.clearMoveList(_1aa);
}
var _1ae=0;
var _1af=_1aa.moveNum;
var move=_1aa;
while(move!=null&&!move.atEnd){
if(clog){
console.log("move:"+move.output());
}
var _1b1=move.next;
if(clog){
if(this.currentMove){
console.log("current move:"+this.currentMove.output());
}else{
console.log("no current move");
}
if(_1b1){
console.log("next move:"+_1b1.output());
}else{
console.log("no next move");
}
}
if(_1ad||_1aa!=move||_1ac==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:"+_1ac.output()+" with move:"+move.output()+" and board:"+this.boardToFen());
}
this.replaceMove(_1ac,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 _1b2=move.index;
var bm=move.prev;
var _1b4=-1;
if(bm){
_1b4=bm.index;
}
var _1b5=move.numVars;
var vars=move.vars;
move.numVars=0;
move.vars=[];
for(var i=0;i<_1b5;i++){
this.gotoMoveIndex(_1b4,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:"+_1b2);
}
}
this.gotoMoveIndex(_1b2,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=_1b1;
}
if(_1ad){
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&&_1ad){
console.timeEnd("insertMovesFromMoveList");
}
};
Board.prototype.setupFromLalgArrayIncremental=function(_1ba,_1bb,_1bc,_1bd){
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 _1c0=0;
var _1c1=_1bc*2-1;
var _1c2="";
var _1c3=false;
var _1c4=false;
var _1c5=ChessPiece.WHITE;
var _1c6=false;
var _1c7=true;
this.currentMove=null;
for(var i=0;i<_1ba.length;i++){
if(_1ba[i]=="}"){
_1c6=false;
if(this.movesDisplay){
_1c2=_1c2.replace(/\s+$/g,"");
}
continue;
}else{
if(_1c6){
_1c2+=_1ba[i]+" ";
continue;
}else{
if(_1ba[i]=="{"){
_1c2="";
_1c6=true;
continue;
}else{
if(_1ba[i]=="("){
_1c3=true;
continue;
}else{
if(_1ba[i]==")"){
_1c4=true;
continue;
}else{
if(_1ba[i].charAt(0)=="$"){
continue;
}
}
}
}
}
}
var move=this.createMoveFromString(_1ba[i]);
var _1c9=false;
if(_1c7&&this.boardPieces[move.fromColumn][move.fromRow].colour==ChessPiece.BLACK){
_1c1++;
_1c9=true;
_1c5=ChessPiece.BLACK;
}
this.startMoveNum=_1c1;
_1c7=false;
move.index=_1c0++;
var _1ca=move.moveString;
_1ca=Board.moveToLocale(_1ca);
_1c5=(_1c5==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 _1cb=this.movesDisplay.getMovesDisplay();
if(_1cb){
_1cb.innerHTML=this.pendingMovesOutput;
var _1cc=new YAHOO.util.Scroll(_1cb,{scroll:{to:[0,0]}},0);
_1cc.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(_1cf,_1d0,_1d1,_1d2){
this.tacticMoveArray=new Array();
this.moveArray=this.tacticMoveArray;
this.setMoveSeqLalg(_1cf,this.tacticMoveArray,_1d1,_1d2);
this.tacticsmoveArrayLastMoveIndex=this.lastMoveIndex;
if(false&&_1d0!="NA"){
this.fullmoveArray=new Array();
this.disableMoveOutput=true;
this.setMoveSeqLalg(_1d0,this.fullmoveArray,_1d1,_1d2);
this.disableMoveOutput=false;
this.fullmoveArrayLastMoveIndex=this.lastMoveIndex;
}else{
this.fullmoveArray=null;
}
this.lastMoveIndex=this.tacticsmoveArrayLastMoveIndex;
};
Board.prototype.resetVariationsPreviousNodes=function(_1d3,_1d4){
if(_1d3.numVars>0){
for(var i=0;i<_1d3.numVars;i++){
_1d3.vars[i].prev=_1d4;
this.resetVariationsPreviousNodes(_1d3.vars[i],_1d4);
}
}
};
Board.prototype.reconnectNextNodeVariations=function(_1d6,_1d7){
if(!_1d7){
return;
}
if(_1d7.numVars>0){
for(var i=0;i<_1d7.numVars;i++){
_1d7.vars[i].prev=_1d6;
this.reconnectNextNodeVariations(_1d6,_1d7.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 _1dd=this.moveArray[0];
if(m!=_1dd){
return m;
}
}
return null;
}
};
Board.prototype.liftVariation=function(_1de){
if(!_1de){
return;
}
var _1df=null;
var _1e0=null;
if(_1de.prev){
_1df=_1de.prev.next;
}else{
_1df=this.moveArray[0];
_1e0=_1de;
}
var _1e1=null;
if(this.currentMove&&this.currentMove.prev){
_1e1=this.currentMove.prev;
}
if(_1df){
var _1e2=_1df.numVars;
var vars=_1df.vars;
_1df.numVars=0;
_1df.vars=[];
if(_1de.numVars==0){
_1de.vars=[];
}
for(var i=0;i<_1e2;i++){
var _1e5=vars[i];
if(clog){
console.log("processing var:"+_1e5.output());
}
if(_1e5==_1de){
if(clog){
console.log("inserted parent var");
}
_1de.vars.push(_1df);
_1de.numVars++;
}else{
_1de.vars.push(_1e5);
_1de.numVars++;
}
}
if(_1de.prev){
_1de.prev.next=_1de;
}
if(clog){
console.log("finished moving variations");
}
if(!_1e0){
_1e0=this.findFirstMoveFromList(_1de);
}
this.moveArray[0]=_1e0;
this.gotoMoveIndex(-1,true,true,true,true);
if(clog){
console.log("fm:"+_1e0.output());
}
this.insertMovesFromMoveList(_1e0);
}
if(_1e1){
this.gotoMoveIndex(_1e1.index);
}
};
Board.prototype.deleteMoveAndLine=function(move){
var m=move;
var oldM=m;
var _1e9=false;
var _1ea=null;
var _1eb=this.moveArray[0];
var _1ec=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");
}
_1e9=true;
_1ea=move.prev.next;
}else{
if(move&&!move.prev&&move!=this.moveArray[0]){
if(clog){
console.log("var is head and front of move list");
}
_1e9=true;
_1ea=this.moveArray[0];
}
}
if(clog){
console.log("isVariationHead:"+_1e9);
}
if(clog){
console.log("fm:"+_1eb.output());
}
var _1ed=m.prev;
if(_1e9){
_1ec=_1ea;
if(_1ea){
if(clog){
console.log("delete variation from parent:"+_1ea.output());
}
var _1ee=[];
for(var i=0;i<_1ea.numVars;i++){
if(!(_1ea.vars[i]==oldM)){
if(clog){
console.log("saving var:"+_1ea.vars[i].output());
}
_1ee.push(_1ea.vars[i]);
}else{
if(clog){
console.log("dropping var:"+_1ea.vars[i].output());
}
}
}
_1ea.vars=_1ee;
_1ea.numVars=_1ee.length;
}
}else{
if(_1ed){
_1ed.next=null;
_1ec=_1ed;
}else{
if(clog){
console.log("deleting entire list");
}
if(this.movesDisplay){
this.movesDisplay.firstNonMove=false;
}
YAHOO.util.Event.purgeElement(this.movesDisplay.getMovesDisplay(),true);
var _1f0=this.movesDisplay.getMovesDisplay();
if(_1f0){
_1f0.innerHTML="";
}
this.currentMove=null;
this.startMoveNum=_1eb.moveNum;
if(clog){
console.log("startFen:"+this.startFen);
}
this.moveIndex=-1;
this.setupFromFen(this.startFen);
return;
}
}
this.moveArray[0]=_1eb;
this.gotoMoveIndex(-1,true,true,true,true);
if(clog){
console.log("fm:"+_1eb.output());
}
this.insertMovesFromMoveList(_1eb);
if(_1ec){
this.gotoMoveIndex(_1ec.index);
}
};
Board.prototype.insertMoveAfter=function(_1f1,_1f2,_1f3,_1f4,_1f5,_1f6){
addToMovelist=!_1f3;
if(clog){
console.log("addToMovelist:"+addToMovelist);
}
var _1f7="null";
if(_1f1){
_1f7=_1f1.output();
}
if(clog){
console.log("insert newMove:"+_1f2.output()+" after:"+_1f7);
}
if(_1f1==null){
this.currentMove=_1f2;
_1f2.atEnd=0;
_1f2.prev=null;
_1f2.next=null;
this.firstMove=_1f2;
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{
_1f2.atEnd=_1f1.atEnd;
_1f2.prev=_1f1;
_1f1.atEnd=0;
if(clog){
if(_1f1.next){
console.log("prevMove.next:"+_1f1.next.output());
}
}
if(_1f2.equals(_1f1.next)||_1f2.equals(_1f1)){
if(clog){
console.log("inserting move that already exists in variation:"+_1f1.next.output());
}
var _1f8=_1f1.next;
if(this.firstMove==_1f8){
this.firstMove=_1f2;
}
if(_1f2.equals(_1f1)){
_1f8=_1f1;
}
if(_1f8.prev&&(_1f8.prev.next==_1f8)){
_1f8.prev.next=_1f2;
}
if(_1f8.next){
_1f8.next.prev=_1f2;
}
addToMovelist=false;
_1f2.moveNum=_1f8.moveNum;
_1f2.ravLevel=_1f8.ravLevel;
_1f2.index=_1f8.index;
_1f2.fen=_1f8.fen;
_1f2.nextFen=_1f8.nextFen;
_1f2.bestMoves=_1f8.bestMoves;
_1f2.correctMove=_1f8.correctMove;
_1f2.wrongMove=_1f8.wrongMove;
_1f2.next=_1f8.next;
_1f2.vars=_1f8.vars;
_1f2.numVars=_1f8.numVars;
this.reconnectNextNodeVariations(_1f2,_1f8.next);
this.moveArray[_1f2.index]=_1f2;
if(this.currentMove==_1f8){
this.setCurrentMove(_1f2);
}
}else{
_1f2.moveNum=_1f1.moveNum+1;
_1f2.ravLevel=_1f1.ravLevel;
_1f2.next=_1f1.next;
if(_1f2.next){
_1f2.next.prev=_1f2;
}
}
_1f1.next=_1f2;
}
if(addToMovelist){
this.insertIntoMoveDisplay(_1f1,_1f2,_1f4,_1f5,_1f6);
}
if(_1f2.next==null){
var _1f9=this.createMoveFromString("i1i2");
_1f2.next=_1f9;
_1f9.prev=_1f2;
_1f9.moveNum=_1f2.moveNum+1;
_1f9.ravLevel=_1f2.ravLevel;
_1f9.next=null;
_1f9.atEnd=1;
_1f9.endNode=true;
if(clog){
console.log("created endmove node in insertAfterMove:"+_1f9.output());
}
}else{
if(clog){
console.log("allready had a node at end:"+_1f2.next.output());
}
_1f2.next.moveNum=_1f2.moveNum+1;
}
};
function insertBefore(node,_1fb){
if(_1fb){
_1fb.parentNode.insertBefore(node,_1fb);
}
}
function insertAfter(node,_1fd){
var _1fe=_1fd.parentNode;
_1fe.insertBefore(node,_1fd.nextSibling);
}
Board.prototype.replaceIntoMoveDisplay=function(_1ff,_200,_201,_202,_203){
var _204="null";
if(_1ff){
_204=_1ff.output();
}
if(clog){
console.log("replace display newMove:"+_200.output()+" after:"+_204+" hideScore:"+_202);
}
if(!_1ff){
if(clog){
console.log("null oldMove");
}
this.insertIntoMoveDisplay(null,_200,false,_202);
}else{
if(clog){
console.log("about to get movesdsiplay in replace into move display:"+this.movesDisplay);
}
var _205=this.movesDisplay.getMovesDisplay();
if(clog){
console.log("got moves display");
}
if(!_205){
if(clog){
console.log("no movesd disiplay in replace into move display");
}
return;
}
var san=_200.SAN;
if(!san){
if(clog){
console.log("about to make san");
}
san=this.makeShortAlgabraic(_200.fromColumn,_200.fromRow,_200.toColumn,_200.toRow,_200);
if(clog){
console.log("about to made san:"+san);
}
_200.SAN=san;
}
if(clog){
console.log("oldMove.index:"+_1ff.index);
}
var _207=this.boardName+"-ms"+_1ff.index;
if(clog){
console.log("oldMoveId:"+_207);
}
var _208=YAHOO.util.Dom.get(_207);
if(_201){
this.moveIndex++;
_200.index=this.moveIndex;
this.moveArray[this.moveIndex]=_200;
if(clog){
console.log("replace as variation old:"+_1ff.output()+" new:"+_200.output());
}
var _209=document.createElement("span");
var _20a=this.movesDisplay.outputVariationStart(0,0,_200.moveNum,0);
_200.ravLevel=_1ff.ravlevel+1;
var _204=Board.moveToLocale(san);
if(_200.prev==null){
this.movesDisplay.firstNonMove=false;
}
var _20b=this.movesDisplay.outputMove(this.moveIndex,_200.ravLevel,_200.moveNum,_204,_201,0,_200.moveNum,_200,_202,_203);
var _20c=document.createElement("span");
_20c.id=(this.boardName+"-ms"+_200.index);
_20c.innerHTML=_20b+"&nbsp;";
var _20d=this.movesDisplay.outputVariationEnd(0,0,_200.moveNum,0);
this.movesDisplay.firstNonMove=true;
var _20e=document.createElement("span");
_20e.innerHTML=_20a;
var _20f=document.createElement("span");
_20f.innerHTML=_20d;
_209.appendChild(_20e);
_209.appendChild(_20c);
_209.appendChild(_20f);
_208.appendChild(_209);
}else{
_200.index=_1ff.index;
this.moveArray[_200.index]=_200;
var _204=Board.moveToLocale(san);
if(_200.prev==null){
this.movesDisplay.firstNonMove=false;
}
var _20b=this.movesDisplay.outputMove(_200.index,_200.ravLevel,_200.moveNum,_204,_201,0,_200.moveNum,_200,_202,_203);
var _20c=document.createElement("span");
_20c.innerHTML=_20b+"&nbsp;";
_20c.id=(this.boardName+"-ms"+_200.index);
var _210=[];
if(_208&&_208.childNodes){
for(var i=1;i<_208.childNodes.length;i++){
_210[i-1]=_208.childNodes[i];
}
}
if(clog){
console.log("replace as main line not variation old:"+_1ff.output()+" new:"+_200.output());
}
_208.parentNode.replaceChild(_20c,_208);
if(_210){
for(var i=0;i<_210.length;i++){
_20c.appendChild(_210[i]);
}
}
}
YAHOO.util.Event.removeListener(this.boardName+"-m"+_200.index);
YAHOO.util.Event.addListener((this.boardName+"-m"+_200.index),"click",this.movesDisplay.gotoMove,this.movesDisplay,true);
}
};
Board.prototype.insertCommentIntoMoveDisplay=function(move,_213,_214){
var _215=this.movesDisplay.getMovesDisplay();
if(!_215){
return;
}
var _216="b";
if(_214){
_216="a";
}
if(move){
var _217=this.boardName+"-mc"+_216+move.index;
var _218=YAHOO.util.Dom.get(_217);
var _219=false;
if(!_218){
_218=document.createElement("span");
_218.id=_217;
_219=true;
}
_218.innerHTML=this.movesDisplay.outputComment(_213,0);
var _21a=YAHOO.util.Dom.get((this.boardName+"-m"+move.index));
if(_21a){
if(_214){
move.afterComment=_213;
if(_219){
insertAfter(_218,_21a);
}
}else{
move.beforeComment=_213;
if(_219){
insertBefore(_218,_21a);
}
}
}
}else{
}
};
Board.prototype.insertIntoMoveDisplay=function(_21b,_21c,_21d,_21e,_21f){
var _220=this.movesDisplay.getMovesDisplay();
if(!_220){
return;
}
var _221="null";
if(_21b){
_221=_21b.output();
}
if(clog){
console.log("insert display newMove:"+_21c.output()+" after:"+_221);
}
var san=_21c.SAN;
if(!san){
san=this.makeShortAlgabraic(_21c.fromColumn,_21c.fromRow,_21c.toColumn,_21c.toRow,_21c);
_21c.SAN=san;
}
this.moveIndex++;
_21c.index=this.moveIndex;
this.moveArray[this.moveIndex]=_21c;
var _221=Board.moveToLocale(san);
var _223=this.movesDisplay.outputMove(this.moveIndex,_21c.ravLevel,_21c.moveNum,_221,false,0,_21c.moveNum,_21c,_21e,_21f);
var _224=document.createElement("span");
_224.innerHTML=_223+"&nbsp;";
_224.id=(this.boardName+"-ms"+this.moveIndex);
if(_21d){
YAHOO.util.Dom.setStyle(_224,"visibility","hidden");
}
if(_21b){
if(clog){
console.log("prevMove.index:"+_21b.index+"prevMove:"+_21b.output());
}
var _225=YAHOO.util.Dom.get((this.boardName+"-ms"+_21b.index));
if(_225){
insertAfter(_224,_225);
}else{
_220.appendChild(_224);
}
}else{
if(_21c.next){
var _226=YAHOO.util.Dom.get((this.boardName+"-ms"+_21c.next.index));
insertBefore(_224,_226);
}else{
_220.appendChild(_224);
}
}
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(_227,_228,_229,_22a,_22b,_22c){
var _22d="null";
if(_227){
_22d=_227.output();
}
if(clog){
console.log("replace newMove:"+_228.output()+" after:"+_22d+" replace as var"+_229+" rep move display:"+_22a+" hideScore:"+_22b);
if(_227&&_227.prev){
console.log("replace oldMove.prev:"+_227.prev.output());
}
if(_227&&_227.next){
console.log("replace oldMove.next:"+_227.next.output());
}
}
var _22e=false;
var _22f=null;
var _230=0;
if(_227.endNode){
if(clog){
console.log("asked to replace endNode,inserting before instead");
}
this.insertMoveAfter(_227.prev,_228,false,false,_22b,_22c);
_228.fen=_227.fen;
_228.nextFen=_227.nextFen;
return;
}
if(_228.equals(_227)){
if(clog){
console.log("new move is same as old move so not replacing as variation");
}
_229=false;
}else{
if(_227&&_227.numVars>0){
for(var i=0;i<_227.numVars;i++){
var _232=_227.vars[i];
if(_228.equals(_232)){
if(clog){
console.log("new move is same as an existing variation varNum:"+i);
console.log("variation:"+_232.output());
if(_232.next){
console.log("variation next:"+_232.next.output());
}
}
_22e=true;
_22f=_227;
_227=_232;
_230=i;
break;
}
}
}
}
if(_227==null){
if(clog){
console.log("replaced new move with null oldmove");
}
this.currentMove=_228;
_228.atEnd=1;
_228.next=null;
_228.prev=null;
if(this.startPositionAfterOpponentMove){
_228.fen=this.startPositionAfterOpponentMove;
_228.nextFen=null;
}
if(this.toMove==ChessPiece.WHITE){
this.currentMove.moveNum=1;
}else{
this.currentMove.moveNum=2;
}
this.firstMove=_228;
}else{
var _233=false;
if(_227&&_227.prev&&_227.prev.next!=_227){
_233=true;
}
if(this.currentMove==_227&&!_229){
this.currentMove=_228;
}else{
if(clog){
console.log("not setting current move in replacemove");
}
}
_228.atEnd=_227.atEnd;
_228.prev=_227.prev;
_228.next=_227.next;
_228.fen=_227.fen;
_228.nextFen=_227.nextFen;
_228.bestMoves=_227.bestMoves;
_228.correctMove=_227.correctMove;
_228.wrongMove=_227.wrongMove;
_228.moveNum=_227.moveNum;
_228.ravLevel=_227.ravLevel;
_228.index=_227.index;
if(clog){
console.log("replacingVariation with var not null:"+_22e);
}
if(_22e){
_22f.vars[_230]=_228;
_228.vars=_227.vars;
_228.numVars=_227.numVars;
this.reconnectNextNodeVariations(_228,_227.next);
if(_227.next){
_227.next.prev=_228;
}
this.moveArray[_228.index]=_228;
if(clog){
console.log("replacing existing sub variation of main line");
if(_228.next){
console.log("next of replacement variation:"+_228.next.output());
}
}
return;
}
if(!_229){
if(clog){
console.log("not replacing as variation");
}
if(!_233&&_227.prev){
_227.prev.next=_228;
}
if(_227.next){
_227.next.prev=_228;
}
_228.vars=_227.vars;
_228.numVars=_227.numVars;
this.reconnectNextNodeVariations(_228,_227.next);
if(this.firstMove==_227){
this.firstMove=_228;
}
this.moveArray[_228.index]=_228;
}else{
if(clog){
console.log("replacing as variation");
}
if(_227.numVars==0){
_227.vars=new Array();
}
_227.vars[_227.numVars++]=_228;
_227.atEnd=0;
_228.next=null;
var _234=this.createMoveFromString("i1i2");
_228.next=_234;
_234.prev=_228;
_234.next=null;
_234.atEnd=1;
_234.moveNum=_228.moveNum+1;
_234.ravLevel=_228.ravLevel;
_234.endNode=true;
}
}
if(_22a){
this.replaceIntoMoveDisplay(_227,_228,_229,_22b,_22c);
}
};
Board.prototype.setCurrentMove=function(move,_236,_237){
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 _238=this.boardName+"-m"+this.currentMove.prev.index;
if(clog){
console.log("setCurrentMove attempted highlight of id:"+_238+" for move:"+move.output());
}
var span=YAHOO.util.Dom.get(_238);
if(span){
var cls=span.className;
YAHOO.util.Dom.addClass(span,"ct-board-move-current");
if(this.autoScrollMoves){
if(!_237&&(this.scrollVariations||cls.indexOf("ct-board-move-variation")==-1)){
var _23b=this.movesDisplay.getMovesDisplay();
if(_23b){
var y=YAHOO.util.Dom.getY(span)-YAHOO.util.Dom.getY(_23b);
var _23d=new YAHOO.util.Scroll(_23b,{scroll:{by:[0,y]}},this.moveAnimationLength,YAHOO.util.Easing.easeOut);
_23d.animate();
}
}
}
}
}else{
if(move==null){
if(clog){
console.log("attempted to set current move on null node");
}
}
}
if(!_236){
this.setForwardBack();
}
};
Board.INITIAL_FEN="rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1";
Board.prototype.boardToFen=function(_23e){
var _23f="";
for(var row=7;row>=0;row--){
var _241=0;
var line="";
if(row<7){
line="/";
}
for(var col=0;col<8;col++){
var _244=this.boardPieces[col][row];
if(_244){
var _245="";
if(_241>0){
_245=_241+"";
}
line+=_245+_244.getFenLetter();
_241=0;
}else{
_241++;
}
}
if(_241>0){
line+=_241+"";
}
_23f+=line;
}
var fen=_23f;
var _247=" w ";
if(_23e){
if(this.toMove==ChessPiece.WHITE){
_247=" b ";
}
}else{
if(this.toMove==ChessPiece.BLACK){
_247=" b ";
}
}
fen+=_247;
var _248="";
_248+=Board.getFenCastleChar(this.canCastleKingSide,"K",ChessPiece.WHITE);
_248+=Board.getFenCastleChar(this.canCastleQueenSide,"Q",ChessPiece.WHITE);
_248+=Board.getFenCastleChar(this.canCastleKingSide,"K",ChessPiece.BLACK);
_248+=Board.getFenCastleChar(this.canCastleQueenSide,"Q",ChessPiece.BLACK);
if(_248==""){
fen+="- ";
}else{
fen+=_248+" ";
}
var _249=null;
if(this.currentMove){
if(this.currentMove.prev){
_249=this.currentMove.prev;
}else{
_249=this.prev_move;
}
}else{
_249=this.prev_move;
}
var _24a="- ";
if(_249){
if(_249){
var _24b=this.boardPieces[_249.toColumn][_249.toRow];
if(_24b){
if(_24b.piece==ChessPiece.PAWN){
if(_24b.colour==ChessPiece.WHITE){
if(_249.fromRow==1&&_249.toRow==3){
_24a=Move.columnToChar(_249.fromColumn)+"3 ";
}
}else{
if(_249.fromRow==6&&_249.toRow==4){
_24a=Move.columnToChar(_249.fromColumn)+"6 ";
}
}
}
}
}
}
fen+=_24a;
fen+=this.halfMoveNumber+" "+parseInt((this.moveNumber+1)/2);
if(clog){
console.log("moveNumber:"+this.moveNumber+" fen:"+fen);
}
return fen;
};
Board.getFenCastleChar=function(_24c,_24d,_24e){
if(_24c[_24e]){
if(_24e==ChessPiece.WHITE){
return _24d.toUpperCase();
}else{
return _24d.toLowerCase();
}
}
return "";
};
Board.prototype.getCastlingString=function(_24f){
var _250=_js("None");
if(this.canCastleKingSide[_24f]){
_250="O-O";
}
if(this.canCastleQueenSide[_24f]){
if(_250==_js("None")){
_250="O-O-O";
}else{
_250+=",O-O-O";
}
}
return _250;
};
Board.prototype.updateToPlay=function(){
if(this.disableUpdateToPlay){
return;
}
var _251=YAHOO.util.Dom.get("toPlay");
if(_251==null){
return;
}
if(this.toMove==ChessPiece.WHITE){
_251.src="/images/whiteknight"+this.getVersString()+".gif";
_251.alt=_js("White to play");
}else{
_251.src="/images/blackknight"+this.getVersString()+".gif";
_251.alt=_js("Black to play");
}
var _252=YAHOO.util.Dom.get("fenStatus");
if(_252){
var _253=this.getCastlingString(ChessPiece.BLACK);
var _254=this.getCastlingString(ChessPiece.WHITE);
var s="<div><span>"+_js("White Castling: ")+"</span><span>"+_254+"</span></div>"+"<div><span>"+_js("Black Castling: ")+"</span><span>"+_253+"</span></div>";
_252.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 _257=document.getElementsByTagName("body");
if(_257==null||_257.length==0){
alert("Could not find body tag");
}else{
this.docBody=_257[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 _258=YAHOO.util.Dom.get(this.boardName+"-fileLabels");
var _259=YAHOO.util.Dom.get(this.boardName+"-rankLabels");
if(!_258||!_259){
return;
}
YAHOO.util.Event.purgeElement(_258,true);
_259.innerHTML="";
_258.innerHTML="";
var _25a=YAHOO.util.Dom.get(this.boardName+"-boardBorder");
if(!this.showCoordinates){
YAHOO.util.Dom.setStyle(_258,"display","none");
YAHOO.util.Dom.setStyle(_259,"display","none");
var _25b=0;
YAHOO.util.Dom.setStyle(_25a,"width",(this.pieceSize*8+_25b)+"px");
YAHOO.util.Dom.setStyle(_25a,"height",(this.pieceSize*8+_25b)+"px");
return;
}
YAHOO.util.Dom.setStyle(_258,"display","block");
YAHOO.util.Dom.setStyle(_259,"display","block");
var _25b=15;
var _25c=0;
if(check_bad_msie()){
_25c=this.ie6FixCoordsOffsetSize;
}
if(YAHOO.util.Event.isIE){
_25c+=this.allIeFixCoordsOffsetSize;
}
YAHOO.util.Dom.setStyle(_25a,"width",(this.pieceSize*8+_25b+_25c)+"px");
YAHOO.util.Dom.setStyle(_25a,"height",(this.pieceSize*8+_25b)+"px");
this.coordinatesShown=true;
for(var i=0;i<8;i++){
var _25e=document.createElement("div");
YAHOO.util.Dom.setStyle(_25e,"height",this.pieceSize+"px");
YAHOO.util.Dom.setStyle(_25e,"width","15px");
YAHOO.util.Dom.setStyle(_25e,"text-align","center");
YAHOO.util.Dom.setStyle(_25e,"line-height",this.pieceSize+"px");
if(this.isFlipped){
_25e.innerHTML=""+(i+1);
}else{
_25e.innerHTML=""+9-(i+1);
}
_259.appendChild(_25e);
}
for(var i=0;i<9;i++){
var _25f=document.createElement("span");
YAHOO.util.Dom.setStyle(_25f,"float","left");
YAHOO.util.Dom.setStyle(_25f,"height","15px");
if(i==0){
YAHOO.util.Dom.setStyle(_25f,"width","15px");
YAHOO.util.Dom.setStyle(_25f,"clear","both");
YAHOO.util.Dom.setStyle(_25f,"margin-top","-5px");
if(_25c){
YAHOO.util.Dom.setStyle(_25f,"margin-left","-3px");
}else{
YAHOO.util.Dom.setStyle(_25f,"margin-left","-2px");
}
var _260="";
if(this.isFlipped){
_260="whiteblack-flipper.png";
}else{
_260="blackwhite-flipper.png";
}
_25f.innerHTML="<span><img id=\""+this.boardName+"-flipper\" title=\""+_js("Flip Board")+"\" src=\""+this.boardImagePath+"/images/"+_260+"\"/></span>";
YAHOO.util.Event.addListener(this.boardName+"-flipper","click",this.flipBoard,this,true);
}else{
YAHOO.util.Dom.setStyle(_25f,"width",this.pieceSize+"px");
YAHOO.util.Dom.setStyle(_25f,"text-align","center");
if(this.isFlipped){
_25f.innerHTML=_js(Move.columnToChar(8-(i)));
}else{
_25f.innerHTML=_js(Move.columnToChar((i-1)));
}
}
_258.appendChild(_25f);
}
var _261=YAHOO.util.Dom.get(this.boardName+"-flipper");
if(_261){
fix_ie_png(_261);
}
};
Board.prototype.createBoardUI=function(){
var _262=this.boardName+"-container";
var _263=YAHOO.util.Dom.get(_262);
if(_263==null){
alert("Could not find board container:"+_262);
return;
}
YAHOO.util.Dom.addClass(_263,"ct-board-container");
this.boardDiv=null;
var _264=document.createElement("div");
_264.id=this.boardName+"-boardBorder";
YAHOO.util.Dom.addClass(_264,"ct-board-border"+this.squareColorClass);
var _265=0;
if(this.showCoordinates){
_265=15;
}
YAHOO.util.Dom.setStyle(_264,"width",(this.pieceSize*8+_265)+"px");
YAHOO.util.Dom.setStyle(_264,"height",(this.pieceSize*8+_265)+"px");
var _266=document.createElement("div");
YAHOO.util.Dom.setStyle(_266,"float","left");
_266.id=this.boardName+"-rankLabels";
_264.appendChild(_266);
var _267=document.createElement("div");
YAHOO.util.Dom.addClass(_267,"ct-board");
YAHOO.util.Dom.setStyle(_267,"width",(this.pieceSize*8)+"px");
YAHOO.util.Dom.setStyle(_267,"height",(this.pieceSize*8)+"px");
_267.id="ctb-"+this.boardName;
var _268="ct-white-square"+this.squareColorClass;
var _269="";
var _26a=[];
for(var i=7;i>=0;i--){
var s="<div>";
for(var j=0;j<8;j++){
var _26e=document.createElement("div");
var _26f=this.boardName+"-s"+j+""+i;
var _270=(((j+1)*(i+1))%19/19*100);
var _271=((65-((j+1)*(i+1)))%19/19*100);
s+="<div id=\""+_26f+"\" class=\""+_268+"\" style=\"width:"+this.pieceSize+"px;height:"+this.pieceSize+"px;background-position:"+_270+"% "+_271+"%\"></div>";
_26a.push(_26f);
_268=(_268=="ct-black-square"+this.squareColorClass)?"ct-white-square"+this.squareColorClass:"ct-black-square"+this.squareColorClass;
}
_268=(_268=="ct-black-square"+this.squareColorClass)?"ct-white-square"+this.squareColorClass:"ct-black-square"+this.squareColorClass;
s+="</div>";
_269+=s;
}
_267.innerHTML=_269;
var _272=document.createElement("div");
_272.id=this.boardName+"-fileLabels";
_264.appendChild(_267);
_264.appendChild(_272);
_263.appendChild(_264);
this.createBoardCoords();
var _273=YAHOO.util.Dom.get(this.boardName+"-ct-nav-container");
if(!_273){
_273=document.createElement("div");
}else{
_273.innerHTML="";
}
_273.id=this.boardName+"-ct-nav-container";
if(!this.dontOutputNavButtons||this.r){
var _274="";
if(!this.dontOutputNavButtons){
if(!this.problem||!this.problem.isEndgame){
_274="<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("Zum letzten Zug")+"\"/>"+"<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 _275="<div class=\"ct-nav-buttons\" id=\""+this.boardName+"-navButtons\"><span id=\"nav-buttons-only\">";
if(!this.dontOutputNavButtons){
_275+="<img class=\"ct-start\" id=\""+this.boardName+"-start\" src=\""+this.boardImagePath+"/images/resultset_first"+this.getVersString()+".gif\" alt=\""+_js("Start position")+"\" title=\""+_js("Zum ersten Zug")+"\"/>"+"<img class=\"ct-back\" id=\""+this.boardName+"-back\" src=\""+this.boardImagePath+"/images/resultset_previous"+this.getVersString()+".gif\" alt=\""+_js("Previous Move")+"\" title=\""+_js("Einen Zug zurück")+"\"/>"+"<img class=\"ct-forward\" id=\""+this.boardName+"-forward\" src=\""+this.boardImagePath+"/images/resultset_next"+this.getVersString()+".gif\" alt=\""+_js("Next Move")+"\" title=\""+_js("Einen Zug vorwärts")+"\"/>"+_274;
}
if(this.r){
_275+="<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")+"\"/>";
_275+="<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")+"\"/>";
}
_275+="</span></div>";
_273.innerHTML=_275;
}
_263.appendChild(_273);
if(this.problem){
var body=YAHOO.util.Dom.get("body");
if(body){
YAHOO.util.Dom.setStyle(body,"min-width",((this.pieceSize*8+_265)+300+200+120)+"px");
}
}
};
Board.prototype.getPieceDiv=function(){
var _277=this.getBoardDiv();
var _278=document.createElement("div");
this.availPieceDivs[this.uptoId]=_278;
this.availIds[this.uptoId]=YAHOO.util.Dom.generateId(_278);
YAHOO.util.Dom.setStyle(_278,"visibility","hidden");
YAHOO.util.Dom.addClass(_278,"board-piece-start-style");
_277.appendChild(_278);
this.uptoId++;
return _278;
};
Board.prototype.flipToMove=function(_279){
return (_279=="w")?"b":"w";
};
Board.prototype.pieceCharToPieceNum=function(_27a){
var _27b;
switch(_27a){
case "K":
_27b=ChessPiece.KING;
break;
case "Q":
_27b=ChessPiece.QUEEN;
break;
case "R":
_27b=ChessPiece.ROOK;
break;
case "B":
_27b=ChessPiece.BISHOP;
break;
case "N":
_27b=ChessPiece.KNIGHT;
break;
case "P":
_27b=ChessPiece.PAWN;
break;
}
return _27b;
};
Board.prototype.pieceTypeToChar=function(_27c){
switch(_27c){
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(_27d,_27e,_27f,_280){
if(_27d+2==_27f&&_27e+1==_280){
return true;
}
if(_27d+2==_27f&&_27e-1==_280){
return true;
}
if(_27d-2==_27f&&_27e+1==_280){
return true;
}
if(_27d-2==_27f&&_27e-1==_280){
return true;
}
if(_27d+1==_27f&&_27e+2==_280){
return true;
}
if(_27d-1==_27f&&_27e+2==_280){
return true;
}
if(_27d+1==_27f&&_27e-2==_280){
return true;
}
if(_27d-1==_27f&&_27e-2==_280){
return true;
}
return false;
};
Board.prototype.canMovePawn=function(_281,_282,_283,_284,_285){
var _286=this.boardPieces[_283][_284];
var _287=this.boardPieces[_281][_282];
if(_285){
var _288=this.boardPieces[_285.toColumn][_285.toRow];
if(_288.piece==ChessPiece.PAWN){
if(_288.colour==ChessPiece.WHITE){
if(_285.fromRow==1&&_285.toRow==3){
if(_283==_285.fromColumn&&_282==3&&_284==2&&(_281==_283+1||_281==_283-1)){
return true;
}
}
}else{
if(_285.fromRow==6&&_285.toRow==4){
if(_283==_285.fromColumn&&_282==4&&_284==5&&(_281==_283+1||_281==_283-1)){
return true;
}
}
}
}
}
if(_286){
if(_287.colour==ChessPiece.WHITE){
if((_281==_283+1||_281==_283-1)&&(_282==_284-1)){
return true;
}
}else{
if((_281==_283+1||_281==_283-1)&&(_282==_284+1)){
return true;
}
}
}else{
if(_281==_283){
if(_287.colour==ChessPiece.WHITE){
if(_282==1){
if(_284==2){
return true;
}else{
if(_284==3&&this.boardPieces[_283][2]==null){
return true;
}
}
}else{
if(_282+1==_284){
return true;
}
}
}else{
if(_282==6){
if(_284==5){
return true;
}else{
if(_284==4&&this.boardPieces[_283][5]==null){
return true;
}
}
}else{
if(_282-1==_284){
return true;
}
}
}
}
}
return false;
};
Board.prototype.canMoveStraight=function(_289,_28a,_28b,_28c,_28d,_28e){
var _28f=_289;
var _290=_28a;
var _291=0;
var _292=0;
if(_28b>_289){
_291=1;
}else{
if(_28b<_289){
_291=-1;
}
}
if(_28c>_28a){
_292=1;
}else{
if(_28c<_28a){
_292=-1;
}
}
if(clog){
console.log("deltaRow:"+_292+" deltaCol:"+_291+" fromCol:"+_289+" fromRow:"+_28a+" toCol:"+_28b+" toRow:"+_28c);
}
if(_28d==ChessPiece.ROOK&&(_291!=0&&_292!=0)){
return false;
}
if(_28d==ChessPiece.BISHOP&&(_291==0||_292==0)){
return false;
}
var _293=0;
while(true){
_293++;
_289+=_291;
_28a+=_292;
if(_28d==ChessPiece.KING&&_293>1){
if(clog){
console.log("king count:"+_293+" toCol:"+_28b+" toRow:"+_28c);
}
if(_293!=2){
return false;
}
if(_292!=0){
return false;
}
if(!(_28b==6||_28b==2)){
return false;
}
if(_28b==2){
if(this.boardPieces[1][_28a]||this.boardPieces[2][_28a]||this.boardPieces[3][_28a]){
return false;
}
if(!this.canCastleQueenSide[_28e.colour]){
return false;
}
}else{
if(_28b==6){
if(this.boardPieces[5][_28a]||this.boardPieces[6][_28a]){
if(clog){
console.log("king can't castle intervening piece");
}
return false;
}
if(!this.canCastleKingSide[_28e.colour]){
if(clog){
console.log("king can't castle king side (made previously invalid) colour:"+_28e.colour);
}
return false;
}
}else{
if(clog){
console.log("king not in col 2 or 6");
}
return false;
}
}
var _294="";
_294+=Move.columnToChar(_28f);
_294+=String.fromCharCode("1".charCodeAt(0)+_290);
_294+=Move.columnToChar((_28f+_291));
_294+=String.fromCharCode("1".charCodeAt(0)+(_290+_292));
var move=this.createMoveFromString(_294);
var _296=this.boardPieces;
var _297=this.toMove;
var _298=this.saveCastling();
this.boardPieces=this.copyBoardPieces(true);
this.makeMove(move,this.boardPieces[_28f][_290],false,this.moveAnimationLength,false,false);
this.restoreCastling(_298);
kingSafe=this.isKingSafe(_28e.colour,move);
boardPool.putObject(this.boardPieces);
this.boardPieces=_296;
_296.count--;
this.toMove=_297;
if(clog){
console.log("kingSafe1:"+kingSafe);
}
if(!kingSafe){
return false;
}
var _294="";
_294+=Move.columnToChar(_28f);
_294+=String.fromCharCode("1".charCodeAt(0)+_290);
_294+=Move.columnToChar(_28f);
_294+=String.fromCharCode("1".charCodeAt(0)+_290);
var move=this.createMoveFromString(_294);
var _296=this.boardPieces;
var _297=this.toMove;
var _298=this.saveCastling();
this.boardPieces=this.copyBoardPieces(true);
this.makeMove(move,this.boardPieces[_28f][_290],false,this.moveAnimationLength,false,false);
this.restoreCastling(_298);
kingSafe=this.isKingSafe(_28e.colour,move);
boardPool.putObject(this.boardPieces);
this.boardPieces=_296;
_296.count--;
this.toMove=_297;
if(clog){
console.log("kingSafe2:"+kingSafe);
}
if(!kingSafe){
return false;
}
}
if(_289==_28b&&_28a==_28c){
return true;
}
if(_289<0||_289>7||_28a<0||_28a>7){
return false;
}
if(this.boardPieces[_289][_28a]!=null){
return false;
}
}
};
Board.prototype.canMove=function(_299,_29a,_29b,_29c,_29d){
var _29e=_299.column;
var _29f=_299.row;
if(_29a>7||_29a<0||_29b>7||_29b<0){
if(clog){
console.log("can't move coz out of bounds");
}
return false;
}
var _2a0=this.boardPieces[_29a][_29b];
var _2a1=this.boardPieces[_29e][_29f];
if(_2a1==null){
return false;
}
if(_2a0&&_2a0.colour==_2a1.colour){
return false;
}
var _2a2=false;
if(_299.piece==ChessPiece.PAWN){
_2a2=this.canMovePawn(_29e,_29f,_29a,_29b,_29c);
}else{
if(_299.piece==ChessPiece.KNIGHT){
_2a2=this.canMoveKnight(_29e,_29f,_29a,_29b);
}else{
_2a2=this.canMoveStraight(_29e,_29f,_29a,_29b,_299.piece,_299);
}
}
if(clog){
console.log("moveOk:"+_2a2);
}
var _2a3=true;
if(_2a2&&_29d){
var _2a4="";
_2a4+=Move.columnToChar(_29e);
_2a4+=String.fromCharCode("1".charCodeAt(0)+_29f);
_2a4+=Move.columnToChar(_29a);
_2a4+=String.fromCharCode("1".charCodeAt(0)+_29b);
var move=this.createMoveFromString(_2a4);
var _2a6=this.cloneBoard();
_2a6.makeMove(move,_2a6.boardPieces[_29e][_29f],false,this.moveAnimationLength,false,false);
_2a3=_2a6.isKingSafe(_299.colour,move);
}
return _2a2&&_2a3;
};
Board.prototype.isKingMated=function(_2a7,_2a8){
var _2a9=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==_2a7){
_2a9=bp;
break;
}
}
}
var _2ad=[[1,0],[1,1],[1,-1],[-1,0],[-1,1],[-1,-1],[0,1],[0,-1],[2,0],[-2,0]];
var bp=_2a9;
for(var k=0;k<_2ad.length;k++){
if(this.canMove(bp,bp.column+_2ad[k][0],bp.row+_2ad[k][1],_2a8,true)){
return false;
}
}
var _2af=this.getCandidateMoves(_2a7,_2a8,true,true);
if(_2af.length>0){
return false;
}
return true;
};
Board.prototype.getCandidateMoves=function(_2b0,_2b1,_2b2,_2b3){
var _2b4=new Array();
for(var i=0;i<8;i++){
for(var j=0;j<8;j++){
var bp=this.boardPieces[i][j];
var _2b8=[];
if(!bp||bp.colour!=_2b0){
continue;
}
switch(bp.piece){
case ChessPiece.KING:
if(_2b3){
continue;
}
_2b8=[[1,0],[1,1],[1,-1],[-1,0],[-1,1],[-1,-1],[0,1],[0,-1],[2,0],[-2,0]];
break;
case ChessPiece.KNIGHT:
_2b8=[[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++){
_2b8.push([1+k,1+k]);
_2b8.push([1+k,-1-k]);
_2b8.push([-1-k,1+k]);
_2b8.push([-1-k,-1-k]);
}
break;
case ChessPiece.QUEEN:
for(var k=0;k<8;k++){
_2b8.push([1+k,0]);
_2b8.push([1+k,1+k]);
_2b8.push([1+k,-1-k]);
_2b8.push([-1-k,0]);
_2b8.push([-1-k,1+k]);
_2b8.push([-1-k,-1-k]);
_2b8.push([0,-1-k]);
_2b8.push([0,1+k]);
}
break;
case ChessPiece.ROOK:
for(var k=0;k<8;k++){
_2b8.push([1+k,0]);
_2b8.push([-1-k,0]);
_2b8.push([0,-1-k]);
_2b8.push([0,1+k]);
}
break;
case ChessPiece.PAWN:
if(_2b0==ChessPiece.BLACK){
_2b8=[[0,-1],[1,-1],[-1,-1]];
if(j==6){
_2b8.push([0,-2]);
}
}else{
_2b8=[[0,1],[1,1],[-1,1]];
if(j==1){
_2b8.push([0,2]);
}
}
break;
}
for(var k=0;k<_2b8.length;k++){
if(this.canMove(bp,bp.column+_2b8[k][0],bp.row+_2b8[k][1],_2b1,true)){
_2b4.push(new Move(bp.column,bp.row,bp.column+_2b8[k][0],bp.row+_2b8[k][1]));
if(_2b2){
return _2b4;
}
}
}
}
}
return _2b4;
};
Board.prototype.isKingSafe=function(_2ba,_2bb){
var _2bc=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==_2ba){
_2bc=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!=_2ba){
if(this.canMove(bp,_2bc.column,_2bc.row,_2bb,false)){
return false;
}
}
}
}
return true;
};
Board.prototype.freeBoardPieces=function(_2c0){
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(_2c0){
this.boardPieces[i]=null;
}
}
}
if(_2c0){
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 _2c5=new Board();
_2c5.boardPieces=this.copyBoardPieces(true);
_2c5.moveArray=this.copyMoveArray(false);
_2c5.canCastleQueenSide=this.copyCastleQueenSide();
_2c5.canCastleKingSide=this.copyCastleKingSide();
_2c5.toMove=this.toMove;
_2c5.opponentColour=this.opponentColour;
_2c5.isFlipped=this.isFlipped;
_2c5.isUserFlipped=this.isUserFlipped;
_2c5.ignoreFlipping=this.ignoreFlipping;
_2c5.reverseFlip=this.reverseFlip;
_2c5.moveAnimationLength=this.moveAnimationLength;
_2c5.moveNumber=this.moveNumber;
_2c5.halfMoveNumber=this.halfMoveNumber;
_2c5.startFen=this.startFen;
if(this.prev_move){
_2c5.prev_move=this.prev_move.clone();
}else{
_2c5.prev_move=null;
}
return _2c5;
};
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(_2c6){
var _2c7=new Array();
if(!_2c6){
if(this.moveArray.length>0){
_2c7=this.moveArray.slice(0);
}
return _2c7;
}else{
for(var i=0;i<this.moveArray.length;i++){
var m=_2c7[i];
if(m){
var newM=m.clone(true);
_2c7[i]=newM;
}
}
return _2c7;
}
};
Board.prototype.copyBoardPieces=function(_2cb){
var _2cc=Board.createBoardArray();
for(var i=0;i<8;i++){
for(var j=0;j<8;j++){
if(this.boardPieces[i][j]!=null){
if(_2cb){
_2cc[i][j]=this.boardPieces[i][j].makeLightWeight();
}else{
_2cc[i][j]=this.boardPieces[i][j].copyPiece();
}
}else{
_2cc[i][j]=null;
}
}
}
return _2cc;
};
Board.prototype.createPiece=function(_2cf,_2d0,_2d1){
if(_2d1){
return new LightweightChessPiece(null,_2cf,_2d0,this);
}else{
return new ChessPiece(this.getPieceDiv(),_2cf,_2d0,this);
}
};
Board.prototype.restoreCastling=function(_2d2){
this.canCastleKingSide=_2d2.kingSide;
this.canCastleQueenSide=_2d2.queenSide;
};
Board.prototype.saveCastling=function(){
var _2d3=[this.canCastleQueenSide[0],this.canCastleQueenSide[1]];
var _2d4=[this.canCastleKingSide[0],this.canCastleKingSide[1]];
return {queenSide:_2d3,kingSide:_2d4};
};
var firstLightProf=true;
var firstHeavyProf=true;
Board.prototype.setupFromFenLightweight=function(fen,_2d6,flip,_2d8){
var _2d9=false&&firstLightProf;
if(_2d9){
console.profile("setupFromFenLight");
}
this.setupFromFenGeneric(fen,_2d6,flip,true,_2d8);
if(_2d9){
console.profileEnd();
}
};
Board.prototype.setupFromFenHeavyWeight=function(fen,_2db,flip,_2dd){
var _2de=false&&firstHeavyProf;
if(_2de){
console.profile("setupFromFenHeavy");
}
this.setupFromFenGeneric(fen,_2db,flip,false,_2dd);
if(_2de){
console.profileEnd();
}
};
Board.prototype.setupFromFen=function(fen,_2e0,flip,_2e2,_2e3){
if(_2e2){
this.setupFromFenLightweight(fen,_2e0,flip,_2e3);
}else{
this.setupFromFenHeavyWeight(fen,_2e0,flip,_2e3);
}
};
Board.prototype.setupFromFenGeneric=function(fen,_2e5,flip,_2e7,_2e8){
if(ctime){
console.time("setupFromFen"+_2e7);
}
this.settingUpPosition=true;
var _2e9=fen.split(" ");
var _2ea=_2e9[0].split("/");
this.halfMoveNumber=parseInt(_2e9[4]);
this.moveNumber=parseInt(_2e9[5])*2;
var _2eb=0;
var row=8;
this.uptoId=0;
this.board_xy=null;
var _2ed=_2e9[2];
var _2ee=null;
this.canCastleQueenSide=[false,false];
this.canCastleKingSide=[false,false];
if(_2ed!="-"){
if(_2ed.indexOf("K")>=0){
this.canCastleKingSide[ChessPiece.WHITE]=true;
}
if(_2ed.indexOf("Q")>=0){
this.canCastleQueenSide[ChessPiece.WHITE]=true;
}
if(_2ed.indexOf("k")>=0){
this.canCastleKingSide[ChessPiece.BLACK]=true;
}
if(_2ed.indexOf("q")>=0){
this.canCastleQueenSide[ChessPiece.BLACK]=true;
}
}
if(_2e9[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(_2e8){
var _2ef=_2e9[3];
if(_2ef!="-"&&_2ef.length==2){
var _2f0=_2ef[0];
var _2f1=parseInt(_2ef[1]);
if(_2f1==3){
_2ee=this.createMoveFromString(_2f0+"2"+_2f0+"4");
}else{
_2ee=this.createMoveFromString(_2f0+"7"+_2f0+"5");
}
_2ee.prevMoveEnpassant=true;
this.prev_move=_2ee;
}
}
if(_2e5){
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=_2ea[i];
row--;
_2eb=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 _2f8=this.boardPieces[_2eb][row];
this.boardPieces[_2eb][row]=null;
_2eb++;
}
}else{
var _2f9=(c+"").toLowerCase().charAt(0);
var _2fa=ChessPiece.WHITE;
if(_2f9==c){
_2fa=ChessPiece.BLACK;
}
var cp;
switch(_2f9){
case "k":
cp=this.createPiece(_2fa,ChessPiece.KING,_2e7);
break;
case "q":
cp=this.createPiece(_2fa,ChessPiece.QUEEN,_2e7);
break;
case "r":
cp=this.createPiece(_2fa,ChessPiece.ROOK,_2e7);
break;
case "b":
cp=this.createPiece(_2fa,ChessPiece.BISHOP,_2e7);
break;
case "n":
cp=this.createPiece(_2fa,ChessPiece.KNIGHT,_2e7);
break;
case "p":
cp=this.createPiece(_2fa,ChessPiece.PAWN,_2e7);
break;
default:
alert("unknown piece letter:"+_2f9+" for fen:"+fen);
}
if(isGecko||isOpera){
cp.setPosition(_2eb,row,false,null,this.moveAnimationLength);
cp.setVisible(true);
}
this.boardPieces[_2eb][row]=cp;
this.pieces[this.uptoPiece]=cp;
this.pieces[this.uptoPiece].column=_2eb;
this.pieces[this.uptoPiece].row=row;
this.uptoPiece++;
_2eb++;
}
}
}
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(!_2e7){
for(var i=0;i<this.uptoPiece;i++){
this.pieces[i].setVisible(true);
}
}
if(!_2e7){
this.createBoardCoords();
}
if(this.toMove==ChessPiece.WHITE){
this.moveNumber--;
}
this.settingUpPosition=false;
if(ctime){
console.timeEnd("setupFromFen"+_2e7);
}
};
Board.prototype.resetMoveListScrollPosition=function(){
var _2fc=this.movesDisplay.getMovesDisplay();
if(_2fc){
var _2fd=new YAHOO.util.Scroll(_2fc,{scroll:{to:[0,0]}},0);
_2fd.animate();
}
};
Board.prototype.changePieceSet=function(_2fe,_2ff){
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 _301=this.pieceSize;
this.pieceSet=_2fe;
this.pieceSize=_2ff;
var _302=YAHOO.util.Dom.get(this.boardName+"-boardBorder");
var _303=0;
if(this.showCoordinates){
_303=15;
}
_302.className="";
YAHOO.util.Dom.addClass(_302,"ct-board-border"+this.squareColorClass);
YAHOO.util.Dom.setStyle(_302,"width",(this.pieceSize*8+_303)+"px");
YAHOO.util.Dom.setStyle(_302,"height",(this.pieceSize*8+_303)+"px");
var _304=YAHOO.util.Dom.get("ctb-"+this.boardName);
YAHOO.util.Dom.setStyle(_304,"width",(this.pieceSize*8)+"px");
YAHOO.util.Dom.setStyle(_304,"height",(this.pieceSize*8)+"px");
var _305="ct-white-square"+this.squareColorClass;
for(var i=7;i>=0;i--){
for(var j=0;j<8;j++){
var _308=this.getBoardDivFromId(this.boardName+"-s"+j+""+i);
_308.className="";
YAHOO.util.Dom.addClass(_308,_305);
YAHOO.util.Dom.setStyle(_308,"width",this.pieceSize+"px");
YAHOO.util.Dom.setStyle(_308,"height",this.pieceSize+"px");
var _309=(((j+1)*(i+1))%19/19*100);
var _30a=((65-((j+1)*(i+1)))%19/19*100);
YAHOO.util.Dom.setStyle(_308,"background-position",_309+"% "+_30a+"%");
_305=(_305=="ct-black-square"+this.squareColorClass)?"ct-white-square"+this.squareColorClass:"ct-black-square"+this.squareColorClass;
}
_305=(_305=="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 _30c=cp.div;
_30c.innerHTML="<img src=\""+cp.icon+"\"/>";
var img=_30c.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 _30c=cp.div;
_30c.innerHTML="<img src=\""+cp.icon+"\"/>";
YAHOO.util.Dom.setStyle([cp.div],"position","relative");
var img=_30c.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+_303)+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 _312=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(!_312){
this.problem.processEndgame("",true);
}
this.toggleToMove();
this.updateToPlay();
}else{
if(clog){
console.log("forwarding move:"+move.output());
}
var _313=null;
piece=this.boardPieces[move.fromColumn][move.fromRow];
if(move.promotion){
_313=move.promotion;
piece.prePromotionColumn=null;
piece.prePromotionRow=null;
}
this.updatePiece(piece,move.toColumn,move.toRow,true,true,false,_313,true);
this.toggleToMove();
this.updateToPlay();
var _314=this.currentMove;
if(clog){
if(_314){
console.log("after forward curmove:"+_314.output());
}else{
console.log("after forward cur move null");
}
}
for(var i=0;i<this.registeredForwardMovePostUpdateListeners.length;i++){
var _316=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 _319=(e.target)?e.target:e.srcElement;
if(_319.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 _31f=YAHOO.util.Dom.get(this.boardName+"-s"+this.lastFromColumn+""+this.lastFromRow);
var _320=YAHOO.util.Dom.get(this.boardName+"-s"+this.lastToColumn+""+this.lastToRow);
}else{
var _31f=YAHOO.util.Dom.get(this.boardName+"-s"+(7-this.lastFromColumn)+""+(7-this.lastFromRow));
var _320=YAHOO.util.Dom.get(this.boardName+"-s"+(7-this.lastToColumn)+""+(7-this.lastToRow));
}
this.updateFromTo(_31f,_320,this.lastFromRow,this.lastFromColumn,this.lastToRow,this.lastToColumn);
}
};
Board.fenPositionOnly=function(fen){
var _322=fen.split(" ");
return _322[0]+" "+_322[1];
};
Board.fenStripMoveClock=function(fen){
var _324=fen.split(" ");
return _324[0]+" "+_324[1]+" "+_324[2]+" "+_324[3];
};
Board.fenSamePosition=function(fen1,fen2,_327){
if(!fen1||!fen2){
return false;
}
var f1=null;
var f2=null;
if(_327){
f1=Board.fenPositionOnly(fen1);
f2=Board.fenPositionOnly(fen2);
}else{
f1=Board.fenStripMoveClock(fen1);
f2=Board.fenStripMoveClock(fen2);
}
return (f1==f2);
};
Board.prototype.findFen=function(mv,brd,fen,_32d){
var res=this.findFen2(mv,brd,fen,true);
if(res.move){
return res.move;
}else{
if(_32d){
if(res.clockStrip){
return res.clockStrip;
}else{
if(res.fullStrip){
return res.fullStrip;
}
}
}
}
return null;
};
Board.prototype.findFen2=function(mv,brd,fen,_332){
var _333=brd.cloneBoard();
var res=Object();
var _335=null;
var _336=null;
res.move=null;
if(_332){
_333.gotoMoveIndex(-1,true,true,true,true);
}
var _337=null;
while(mv&&!mv.atEnd){
var _338=_333.boardToFen();
if(clog){
console.log("curFen:"+_338);
}
var _339=_333.boardToFen();
if(_339==fen){
res.move=_337;
res.clockStrip=null;
res.fullStrip=null;
return res;
}else{
if(Board.fenSamePosition(fen,_339)){
_335=_337;
}else{
if(Board.fenSamePosition(fen,_339,true)){
_336=_337;
}
}
}
if(mv.vars&&mv.vars.length>0){
for(var i=0;i<mv.vars.length;i++){
var _33b=findFen(mv.vars[i],_333,fen,false);
if(_33b.move){
return _33b;
}else{
if(_33b.clockStrip){
_335=_33b.clockStrip;
}else{
if(_33b.fullStrip){
_336=_33b.fullStrip;
}
}
}
}
}
if(clog){
console.log("about to make mv:"+mv.output());
}
_333.makeMove(mv,_333.boardPieces[mv.fromColumn][mv.fromRow],false,this.moveAnimationLength,false,false);
if(clog){
console.log("finished making mv");
}
_337=mv;
mv=mv.next;
if(clog){
console.log("toMove:"+_333.toMove);
}
_333.setCurrentMove(mv);
_333.toggleToMove();
}
if(_335){
res.clockStrip=_335;
}
if(_336){
res.fullStrip=_336;
}
return res;
};
Board.prototype.gotoFen=function(fen,_33d){
if(clog){
console.log("about to find fen for:"+fen);
}
var _33e=this.findFen(this.moveArray[0],this,fen,_33d);
if(_33e){
if(clog){
console.log("found move:"+_33e.output()+" for fen:"+fen);
}
this.gotoMoveIndex(_33e.index);
}else{
if(clog){
console.log("didn't find move for fen:"+fen);
}
}
};
Board.prototype.gotoMoveIndex=function(_33f,_340,_341,_342,_343){
if(clog){
console.log("going to move index:"+_33f);
}
var _344=!_341;
if(!this.moveArray||this.moveArray.length<=_33f){
return;
}
var _345=this.boardName+"-piecestaken";
var _346=YAHOO.util.Dom.get(_345);
if(_346){
_346.innerHTML="";
}
if(_33f==-1){
var flip=false;
if(this.prev_move&&!this.prev_move.prevMoveEnpassant){
flip=true;
}
this.setupFromFen(this.startFen,flip,false,_343);
if(this.prev_move&&!this.prev_move.prevMoveEnpassant){
this.makeMove(this.prev_move,this.boardPieces[this.prev_move.fromColumn][this.prev_move.fromRow],!_341,this.moveAnimationLength,true,true);
this.updateToPlay();
}
if(this.moveArray&&this.moveArray.length>0){
this.setCurrentMove(this.moveArray[0],_340);
}else{
this.setCurrentMove(this.firstMove,_340);
}
if(!_340){
this.setForwardBack();
}
if(!_342){
for(var i=0;i<this.registeredGotoMoveIndexListeners.length;i++){
var _349=this.registeredGotoMoveIndexListeners[i].gotoMoveIndexCallback(_33f);
}
}
return;
}
var _34a=new Array();
var move=this.moveArray[_33f];
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 _34c=0;
if(move.next!=null){
this.setCurrentMove(move.next,_340);
}else{
if(clog){
console.log("move next null with move:"+move.output());
}
}
while(move!=null&&!move.dummy){
_34a[_34c++]=move;
move=move.prev;
}
var flip=false;
if(this.prev_move&&!this.prev_move.prevMoveEnpassant){
flip=true;
}
this.setupFromFen(this.startFen,flip,false,true);
if(this.prev_move&&!this.prev_move.prevMoveEnpassant){
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=_34c-1;i>=1;i--){
var move=_34a[i];
this.makeMove(move,this.boardPieces[move.fromColumn][move.fromRow],false,this.moveAnimationLength,true,false);
this.toggleToMove();
}
if(!_340){
this.convertPiecesFromLightWeight(_33f);
}
var move=_34a[0];
this.makeMove(move,this.boardPieces[move.fromColumn][move.fromRow],_344,this.moveAnimationLength,true,true);
this.toggleToMove();
this.updateToPlay();
if(!_340){
this.setForwardBack();
}
if(!_342){
for(var i=0;i<this.registeredGotoMoveIndexListeners.length;i++){
var _349=this.registeredGotoMoveIndexListeners[i].gotoMoveIndexCallback(_33f);
}
}
};
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 _34f=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);
_34f=move.index;
this.toggleToMove();
this.setCurrentMove(move.next);
}
for(var i=0;i<this.registeredGotoMoveIndexListeners.length;i++){
var _352=this.registeredGotoMoveIndexListeners[i].gotoMoveIndexCallback(_34f);
}
};
/*
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 _355=".vers"+SITE_VERSION;
if(!this.addVersion){
_355="";
}
return _355;
};
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 _35b=new YAHOO.widget.SimpleDialog("fenDialog",{fixedcenter:true,visible:true,draggable:false,constraintoviewport:true,buttons:[{id:"linkbutton4",text:"Test"},{text:_js("Ok"),handler:function(){
_35b.hide();
},isDefault:true}]});
_35b.setHeader(_js("Position FEN"));
_35b.setBody("<textarea class=\"showPgn\" id=\"fenText\" rows=\"1\" readonly=\"true\" cols=\""+(fen.length+9)+"\">"+fen+"</textarea>");
_35b.render(document.body);
_35b.setFooter("<span id=\"copyToComment\"></span><span id=\"fenok\"></span>");
var _35c=this;
var _35d=new YAHOO.widget.Button({type:"button",label:_js("Copy To Comment"),container:"fenok",onclick:{fn:function(){
_35c.copyFenToComment(fen);
_35b.hide();
}}});
var _35e=new YAHOO.widget.Button({type:"button",label:_js("Ok"),container:"fenok",onclick:{fn:function(){
_35b.hide();
}}});
};
Board.prototype.copyFenToComment=function(fen){
if(this.problem){
this.problem.comments.copyFenToComment(fen);
}
};
Board.prototype.copyAnalysisToComment=function(_360,fen,flip){
if(this.problem){
this.problem.comments.copyAnalysisToComment(_360,fen,flip);
}
};
Board.prototype.analysePosition=function(e){
window.parentBoard=this;
var _364=(this.pieceSize*8)+450+50;
var _365=(this.pieceSize*8)+250;
var _366=window.open("/windows/analyse.html","analysis_window","width="+_364+",height="+_365+",resizable=1,scrollbars=1,location=0,copyhistory=0,status=0,toolbar=0,menubar=0");
_366.focus();
};
Board.prototype.backMove=function(e){
if(this.blockFowardBack||this.deferredBlockForwardBack){
return;
}
var _368=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 _369=false;
if(piece.piece==ChessPiece.KING&&Math.abs(move.fromColumn-move.toColumn)>1){
_369=true;
}
this.moveNumber--;
if(this.moveNumber<=0){
this.moveNumber=1;
}
if(takenPiece&&!_369){
this.board_xy=null;
var _36a=move.toColumn;
var _36b=move.toRow;
if(piece.piece==ChessPiece.PAWN&&move.fromColumn!=move.toColumn&&takenPiece.enPassant){
_36b=move.fromRow;
this.boardPieces[move.toColumn][move.toRow]=null;
}
takenPiece.setPosition(_36a,_36b,false,null,this.moveAnimationLength);
this.boardPieces[_36a][_36b]=takenPiece;
move.taken=null;
this.processTaken(takenPiece,false);
}else{
this.boardPieces[move.toColumn][move.toRow]=null;
}
if(_369){
var _36c=move.toRow;
var _36d;
var _36e;
if(move.fromColumn>move.toColumn){
_36d=0;
_36e=3;
}else{
_36d=7;
_36e=5;
}
var _36f=this.boardPieces[_36e][_36c];
_36f.setPosition(_36d,_36c,true,null,this.moveAnimationLength);
this.boardPieces[_36d][_36c]=_36f;
}
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 _371=this.registeredBackMovePreCurrentListeners[i].backMovePreCurrentCallback(move,_368);
}
this.setCurrentMove(move);
this.setForwardBack();
}
this.blockForwardBack=false;
};
Board.prototype.processTaken=function(_372,_373){
var _374=this.boardName+"-piecestaken";
var _375=YAHOO.util.Dom.get(_374);
if(_375){
if(_373){
var _376=get_image_str(ChessPiece.pieceIconNames[_372.colour][_372.piece],this.boardImagePath,this.pieceSet,this.pieceTakenSize,this.addVersion);
_375.innerHTML=_375.innerHTML+"<img src=\""+_376+"\"/>";
}else{
var _377=_375.innerHTML.split("<");
_375.innerHTML="";
for(var i=1;i<_377.length-1;i++){
_375.innerHTML=_375.innerHTML+"<"+_377[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(_37b){
var _37c=_37b.changedTouches,_37d=_37c[0],type="";
switch(_37b.type){
case "touchstart":
type="mousedown";
break;
case "touchmove":
type="mousemove";
break;
case "touchend":
type="mouseup";
break;
default:
return;
}
var _37f=document.createEvent("MouseEvent");
_37f.initMouseEvent(type,true,true,window,1,_37d.screenX,_37d.screenY,_37d.clientX,_37d.clientY,false,false,false,false,0,null);
_37d.target.dispatchEvent(_37f);
_37b.preventDefault();
}
function initIphone(_380){
_380.addEventListener("touchstart",touchHandler,true);
_380.addEventListener("touchmove",touchHandler,true);
_380.addEventListener("touchend",touchHandler,true);
_380.addEventListener("touchcancel",touchHandler,true);
}
FenBoard=function(fen,_382){
_382.pieceSize=24;
_382.fenBoard=true;
_382.dontOutputNavButtons=true;
this.chessapp=new ChessApp(_382);
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;
};


