/* 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();
_3.applyConfig(_1);
if(!window._pvObject){
window._pvObject=new Array();
}
window._pvObject[_3.boardName]=this;
_1=_3;
_1.pgnMode=true;
this.chessapp=new ChessApp(_1);
this.finishedCallback=_2;
if(_1.loadImmediately){
this.chessapp.init();
}else{
YAHOO.util.Event.addListener(window,"load",this.chessapp.init,this.chessapp,true);
}
};
PgnViewer.prototype.setupFromPgn=function(_4){
this.chessapp.pgn.setupFromPGN(_4);
};
PGNGame=function(_5,_6,_7,_8,_9,_a,_b,_c,_d,_e,_uploader, _id){
this.movesseq=_5;
this.startFen=_6;
this.blackPlayer=_7;
this.whitePlayer=_8;
this.pgn_result=_9;
this.event=_a;
this.site=_b;
this.date=_c;
this.round=_d;
this.start_movenum=_e;
this.uploader=_uploader;
this.id = _id;
};
PGN=function(_f){
this.board=_f;
this.pgnGames=new Array();
};
PGN.prototype.getPGNFromURL=function(url){
YAHOO.util.Connect.asyncRequest("POST",url,{success:function(o){
this.setupFromPGN(o.responseText);
},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(_13,_14,_15){
var _16=false;
var _17=false;
var _18=false;
var _19;
var _1a=null;
var _1b=false;
var _1c=null;
if(_13.charAt(_13.length-1)=="#"){
_17=true;
_16=true;
_13=_13.substr(0,_13.length-1);
}else{
if(_13.charAt(_13.length-1)=="+"){
_17=true;
if(_13.length>1&&_13.charAt(_13.length-2)=="+"){
_16=true;
_13=_13.substr(0,_13.length-2);
}else{
_13=_13.substr(0,_13.length-1);
}
}
}
if(_13=="O-O-O"){
if(_14=="w"){
return this.board.createMoveFromString("e1c1");
}else{
return this.board.createMoveFromString("e8c8");
}
}else{
if(_13=="O-O"){
if(_14=="w"){
return this.board.createMoveFromString("e1g1");
}else{
return this.board.createMoveFromString("e8g8");
}
}
}
var _1d=_13.indexOf("=");
if(_1d>=0){
var _1e;
_1a=_13.substr(_1d+1,1);
_1e=_1a.charAt(0);
_19=this.board.pieceCharToPieceNum(_1e);
_18=true;
_13=_13.substr(0,_1d);
}
var _1f=_13.substr(_13.length-2,2);
var _20=_1f.charCodeAt(0)-"a".charCodeAt(0);
var _21=_1f.charCodeAt(1)-"1".charCodeAt(0);
if(_20>7||_20<0||_21>7||_21<0){
alert("PgnViewer: Error processing to Square:"+_1f+" on move:"+_13);
return null;
}
if(_13.length>2){
if(_13.charAt(_13.length-3)=="x"){
_1b=true;
_1c=_13.substr(0,_13.length-3);
}else{
_1c=_13.substr(0,_13.length-2);
}
}
var _22=new Array();
var _23=0;
var _24=null;
var _25=(_14=="w")?ChessPiece.WHITE:ChessPiece.BLACK;
switch(_13.charAt(0)){
case "K":
case "k":
_24=ChessPiece.KING;
break;
case "Q":
case "q":
_24=ChessPiece.QUEEN;
break;
case "R":
case "r":
_24=ChessPiece.ROOK;
break;
case "B":
_24=ChessPiece.BISHOP;
break;
case "N":
case "n":
_24=ChessPiece.KNIGHT;
break;
case "P":
case "p":
_24=ChessPiece.PAWN;
break;
default:
_24=ChessPiece.PAWN;
}
var _26=null;
var _27=null;
if(_1c){
var _28=_1c.toLowerCase().charAt(0);
if(_28==_1c.charAt(0)&&_28>="a"&&_28<="h"){
_27=_28;
if(_1c.length==2){
_26=_1c.charAt(1);
}
}else{
if(_1c.length>1){
if(_1c.length==2){
var c=_1c.charAt(1);
if(c>="1"&&c<="8"){
_26=c;
}else{
_27=c;
}
}else{
if(_1c.length==3){
_27=_1c.charAt(1);
_26=_1c.charAt(2);
if(_27>="1"&&_27<="9"){
var tmp=_27;
_27=_26;
_26=tmp;
}
}else{
alert("PgnViewer: Error: unhandled fromChars:"+_1c);
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==_25&&bp.piece==_24){
if(this.board.canMove(bp,_20,_21,_15,true)){
var _2e=String.fromCharCode("a".charCodeAt(0)+i).charAt(0);
var _2f=String.fromCharCode("1".charCodeAt(0)+j).charAt(0);
if((_27==null||_27==_2e)&&(_26==null||_26==_2f)){
_22[_23++]=bp;
}else{
}
}
}
}
}
if(_23==0){
alert("PgnViewer: no candidate pieces for:"+_13);
return null;
}
if(_23>1){
alert("PgnViewer: Ambiguous:"+_13+" with fromChars:"+_1c+" disRow:"+_26+" disCol:"+_27);
return null;
}
var _30=_22[0];
var _31="";
_31+=String.fromCharCode("a".charCodeAt(0)+_30.column);
_31+=String.fromCharCode("1".charCodeAt(0)+_30.row);
if(_1b){
_31+="x";
}
_31+=_1f;
if(_1a){
_31+=_1a;
}
var _32=this.board.createMoveFromString(_31);
return _32;
};
PGN.prototype.parseTag=function(_33,pgn,_35){
if(pgn.substr(_35,_33.length+3)=="["+_33+" \""){
var _36=pgn.indexOf("\"",_35+_33.length+3);
if(_36>=0){
return pgn.substring(_35+_33.length+3,_36);
}
}
return null;
};
PGN.prototype.setupFromPGN=function(pgn){
var _38=new Array();
var _39=new Array();
var _3a=0;
this.pgnGames=new Array();
pgn=pgn.replace(/^\s+|\s+$/g,"");
var _3b=0;
this.pgn=pgn;
this.setupFromPGN_cont(_38,_39,_3a,_3b);
};
PGN.prototype.setupFromPGN_cont=function(_3c,_3d,_3e,_3f){
var _40=new Date().getTime();
var pgn=this.pgn;
var _42=this.board.boardName+"-progress";
var _43=YAHOO.util.Dom.get(_42);
while(_3f<pgn.length){
var _44="";
var _45="";
var _46="";
var _47="";
var _48="";
var _49="";
var _uploader="";
var _id = "";
var _4a="";
var _4b="w";
var _4c=0;
var _4d=0;
var _4e=new Array();
var _4f=0;
var _50="";
var _51=null;
var _52=null;
var _53=new Array();
var _54=new Array();
var _55=new Array();
var _56=new Array();
var _57=new Array();
this.board.pieceMoveDisabled=true;
this.board.startFen="rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1";
var i=0;
for(i=_3f;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!="?"){
			_4a=tag;
		}else{
			tag=this.parseTag("Black",pgn,i);
			if(tag&&tag!="?"){
				_45=tag;
			}else{
				tag=this.parseTag("Result",pgn,i);
				if(tag&&tag!="?"){
					_44=tag;
				}else{
					tag=this.parseTag("Event",pgn,i);
					if(tag&&tag!="?"){
						_46=tag;
					}else{
						tag=this.parseTag("Site",pgn,i);
						if(tag&&tag!="?"){
							_47=tag;
						}else{
							tag=this.parseTag("Date",pgn,i);
							if(tag&&tag!="?"){
								_48=tag;
							}else{
								tag=this.parseTag("Round",pgn,i);
								if(tag&&tag!="?"){
									_49=tag;
								}else{
									tag=this.parseTag("Uploader",pgn,i);
									if(tag&&tag!="?"){
										_uploader=tag;
									}
									else{
										tag=this.parseTag("ID",pgn,i);
										if(tag&&tag!="?"){
											_id=tag;
										}
									}
								}
							}
						}
					}
				}
			}
		}
	}
if(pgn.charAt(i)=="["){
var j=pgn.indexOf;
for(j=i+1;j<pgn.length&&pgn.charAt(j)!="]";j++){
}
if(j==pgn.length){
alert("PgnViewer: Error parsing PGN. Found unclosed [");
return false;
}
i=j-1;
continue;
}
if(pgn.charAt(i)=="{"){
var _5b=pgn.indexOf("}",i+1);
if(_5b>=0){
var _5c=pgn.substring(i+1,_5b);
i=_5b;
_50+="{ "+_5c+" } ";
}else{
alert("PgnViewer: Error parsing PGN. Found unclosed {");
return false;
}
continue;
}
var _5d=1;
if(pgn.substr(i,1)=="."){
var j=i-1;
while(j>0&&pgn.charAt(j)>="0"&&pgn.charAt(j)<="9"){
j--;
}
if(j>0){
_5d=parseInt(pgn.substring(j+1,i));
}
break;
}
}
if(pgn.substr(i,1)!="."){
alert("PgnViewer: Error: Could not find movelist:"+pgn.substr(i));
return false;
}
this.board.setupFromFen(this.board.startFen,false,false,true);
var _5e=i;
var _5f=null;
for(i=i;i<pgn.length;i++){
var _60=-1;
if(pgn.substr(i,3)=="1-0"||pgn.substr(i,3)=="0-1"){
_60=3;
}else{
if(pgn.substr(i,7)=="1/2-1/2"){
_60=7;
}else{
if(pgn.substr(i,1)=="*"){
_60=1;
}
}
}
if(_60>0){
_5f=pgn.substr(i,_60);
_3f=i+_60;
break;
}
if(pgn.charAt(i)=="["){
_3f=i;
break;
}
if(pgn.charAt(i)==" "||pgn.charAt(i)=="\t"||pgn.charAt(i)=="\n"||pgn.charAt(i)=="\r"){
_5e=i+1;
continue;
}
if(pgn.charAt(i)>="0"&&pgn.charAt(i)<="9"){
continue;
}
if(pgn.charAt(i)=="."){
var _61=pgn.substring(_5e,i).replace(/^\s+|\s+$/g,"");
_5e=i;
while(i+1<pgn.length&&pgn.charAt(i+1)=="."){
i++;
}
if(_5e!=i){
_4b="b";
}else{
_4b="w";
}
_5e=i+1;
}else{
if(pgn.charAt(i)=="{"){
var _5b=pgn.indexOf("}",i+1);
if(_5b>=0){
var _5c=pgn.substring(i+1,_5b);
i=_5b;
_50+="{ "+_5c+" } ";
}
_5e=i+1;
}else{
if(pgn.charAt(i)=="("){
_53[_4c]=this.board.boardPieces;
_54[_4c]=_4b;
_56[_4c]=_51;
_57[_4c]=_52;
this.board.boardPieces=_55[_4c];
this.board.boardPieces=this.board.copyBoardPieces(false);
_51=_52;
_4c++;
_5e=i+1;
_50+="( ";
}else{
if(pgn.charAt(i)==")"){
boardPool.putObject(_53[_4c]);
_4c--;
this.board.boardPieces=_53[_4c];
_4b=_54[_4c];
_51=_56[_4c];
_52=_57[_4c];
_5e=i+1;
_50+=") ";
}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 _62=parseInt(pgn.substr(i+1,j+1));
if(_62<=9){
switch(_62){
case 1:
_50=_50.substr(0,_50.length-1)+"! ";
break;
case 2:
_50=_50.substr(0,_50.length-1)+"? ";
break;
case 3:
_50=_50.substr(0,_50.length-1)+"!! ";
break;
case 4:
_50=_50.substr(0,_50.length-1)+"?? ";
break;
case 5:
_50=_50.substr(0,_50.length-1)+"!? ";
break;
case 6:
_50=_50.substr(0,_50.length-1)+"?! ";
break;
case 7:
case 8:
case 9:
case 0:
default:
}
}else{
_50+=pgn.substring(i,j+1)+" ";
}
i=j;
}
continue;
}else{
var _63=-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"){
_63=j;
break;
}
}
if(_63==-1){
_63=pgn.length;
}
var _64=_5e;
var _65=pgn.substring(_5e,_63).replace(/^\s+|\s+$/g,"");
_5e=_63;
i=_5e-1;
if(_65.length==0){
alert("PgnViewer: Error: got empty move endMoveInd:"+_63+" upto:"+_64+" from:"+pgn.substr(_64)+"#");
return false;
}
var _66=_65.length-1;
while(_66>=0){
if(_65.charAt(_66)=="?"){
_66--;
}else{
if(_65.charAt(_66)=="!"){
_66--;
}else{
break;
}
}
}
var _67=_65.substring(0,_66+1);
var _68=this.getMoveFromPGNMove(_67,_4b,_51);
if(_68==null){
_50+="unknown ";
alert("PgnViewer: Error parsing:"+_65);
return false;
}
_52=_51;
_51=_68;
var _69=this.board.boardPieces[_68.fromColumn][_68.fromRow];
boardPool.putObject(_55[_4c]);
_55[_4c]=this.board.copyBoardPieces(false);
if(_69){
this.board.makeMove(_68,_69,false,0.5,false,false);
}
_4d=_4c;
_4f++;
_4b=this.board.flipToMove(_4b);
_50+=_68.moveString+"|"+_65+" ";
}
}
}
}
}
}
if(_3f<i){
_3f=i;
}
var _6a=pgn.indexOf("{",_3f);
var _6b=pgn.indexOf("[",_3f);
if(_6a>=0){
if(_6b==-1||_6a<_6b){
var _6c=pgn.indexOf("}",_6a+1);
if(_6c>=0){
var _5c=pgn.substring(_6a+1,_6c);
_3f=_6c+1;
_50+="{ "+_5c+" } ";
}else{
alert("PgnViewer: Error: Unclosed {");
return false;
}
}
}
_50=_50.replace(/^\s+|\s+$/g,"");
this.board.pieceMoveDisabled=false;
if(_5f!=null){
if(_44.length==0||_44=="?"){
_44=_5f;
}
}
this.pgnGames[_3e++]=new PGNGame(_50,this.board.startFen,_45,_4a,_44,_46,_47,_48,_49,_5d,_uploader,_id);
if(_43){
_43.innerHTML="Loaded "+_3e+" games";
}
if(new Date().getTime()-_40>500){
setTimeout("window._pvObject[\""+this.board.boardName+"\"].chessapp.pgn.setupFromPGN_cont(\""+_3c+"\",\""+_3d+"\",\""+_3e+"\",\""+_3f+"\");",0);
return;
}
}
var _6d=YAHOO.util.Dom.get(this.board.boardName+"-problemSelectorForm");
if(_6d){
_6d.parentNode.removeChild(_6d);
}
if(this.pgnGames.length==0){
alert("PgnViewer: Error: Unable to find any pgn games in:"+pgn);
return false;
}
if(this.pgnGames.length==1){
this.showGame(0);
}else{
var _6e=this.board.boardName+"-container";
var _6f=YAHOO.util.Dom.get(_6e);
var _70=document.createElement("div");
var _71="<form id=\""+this.board.boardName+"-problemSelectorForm\" action=\"\" method=\"\"><select id=\""+this.board.boardName+"-problemSelector\" name=\""+this.board.boardName+"-problemSelector\">";
for(i=0;i<this.pgnGames.length;i++){
var _72=this.pgnGames[i];
var _73=this.board.boardName+"-game-"+i;
var _74=(i+1)+". "+_72.whitePlayer+" - "+_72.blackPlayer;
if(_72.pgn_result.length>0&&_72.pgn_result!="?"&&this.board.showResult==1){
_74+=" "+_72.pgn_result;
}
if(_72.event.length>0&&_72.event!="?"&&this.board.showEvent==1){
_74+=" "+_72.event;
}
if(_72.round.length>0&&_72.round!="?"&&this.board.showRound==1){
_74+=" Rnd:"+_72.round;
}
if(_72.site.length>0&&_72.site!="?"&&this.board.showSite==1){
_74+=" "+_72.site;
}
if(_72.date.length>0&&_72.date!="?"&&this.board.showDate==1){
_74+=" "+_72.date;
}
_71+="<option id=\""+_73+"\" value=\""+i+"\">"+_74+"</option>";
}
_71+="</select></form>";
_70.innerHTML=_71;
_6f.insertBefore(_70,_6f.firstChild);
YAHOO.util.Event.addListener(this.board.boardName+"-problemSelector","change",this.selectGame,this,true);
this.showGame(0);
}
if(_43){
YAHOO.util.Dom.setStyle(_43,"visibility","hidden");
_43.appendChild(_43);
}
if(window._pvObject[this.board.boardName].finishedCallback){
window._pvObject[this.board.boardName].finishedCallback();
}
return;
};
PGN.prototype.selectGame=function(e){
var _76=YAHOO.util.Event.getTarget(e).selectedIndex;
this.showGame(_76);
var _77=this.board.boardName+"-piecestaken";
var _78=YAHOO.util.Dom.get(_77);
if(_78){
_78.innerHTML="";
}
this.board.resetMoveListScrollPosition();
};
// main function per game [Joris]
PGN.prototype.showGame=function(_79){
this.board.startFen=this.pgnGames[_79].startFen;
this.board.setupFromFen(this.pgnGames[_79].startFen,false,false,false);
this.board.setMoveSequence(this.pgnGames[_79],"NA",this.pgnGames[_79].start_movenum,this.pgnGames[_79].pgn_result);
this.board.displayPendingMoveList();
this.board.setCurrentMove(this.board.moveArray[0]);
if(this.board.autoplayFirst){
this.board.forwardMove();
}
this.board.displayMode=true;
};

var SITE_VERSION=1;
var clog=false;
var move_obj_id_counter=0;
BoardConfig=function(){
this.boardName="board";
this.pgnString=null;
this.pgnFile=null;
this.pieceSet="merida";
this.pieceSize=46;
this.isEndgame=false;
this.tr=false;
this.addVersion=true;
this.ml=9999;
this.autoScrollMoves=false;
this.moveAnimationLength=0.5;
this.showBracketsOnVariation=true;
this.newlineForEachMainMove=true;
this.showNPS=false;
this.squareColorClass="";
this.pieceTakenSize=this.pieceSize;
this.pauseBetweenMoves=800;
this.pgnMode=false;
this.previewMode=false;
this.movesFormat="default";
this.boardImagePath="http://chesstempo.com";
this.showCoordinates=false;
this.highlightFromTo=false;
this.highlightValidSquares=false;
this.showResult=1;
this.showEvent=1;
this.showRound=0;
this.showSite=1;
this.showDate=1;
this.ignoreFlipping=false;
this.reverseFlip=false;
this.autoplayFirst=false;
this.dontOutputNavButtons=false;
};
BoardConfig.prototype.applyConfig=function(_1){
for(var _2 in _1){
this[_2]=_1[_2];
}
};
ChessApp=function(_3){
this.displayMode=false;
this.config=_3;
this.board=null;
};
ChessApp.prototype.setDisplayMode=function(_4){
this.displayMode=_4;
};
ChessApp.prototype.setProblemNumber=function(_5,_6){
this.problemNumber=_5;
this.attId=_6;
};
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)?null:new TacticsUI(this.board);
this.problem=(this.config.pgnMode||this.config.previewMode)?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 _8=MovesDisplay.DEFAULT_DISPLAY_TYPE;
if(this.config.movesFormat=="main_on_own_line"){
_8=MovesDisplay.MAIN_ON_OWN_LINE;
}
this.movesDisplay=new MovesDisplay(this.board,_8);
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.addVersion=this.config.addVersion;
this.board.autoScrollMoves=this.config.autoScrollMoves;
this.board.moveAnimationLength=this.config.moveAnimationLength;
this.board.showBracketsOnVariation=this.config.showBracketsOnVariation;
this.board.newlineForEachMainMove=this.config.newlineForEachMainMove;
this.board.pieceSize=this.config.pieceSize;
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.dontOutputNavButtons=this.config.dontOutputNavButtons;
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);
}else{
if(this.config.pgnString){
this.pgn.setupFromPGN(this.config.pgnString);
}
}
}else{
if(this.tactics){
YAHOO.util.Event.addListener(window,"unload",this.tactics.leavingPage,this.tactics,true);
this.tactics.updateSessionDisplay(0,0);
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 _b=new Object();
for(prop in o){
if(typeof (o[prop])=="object"){
_b[prop]=o[prop];
}else{
_b[prop]=o[prop];
}
}
return _b;
}
function clone(o){
return cloneWork(o);
}
get_image_str=function(_d,_e,_f,_10,_11){
var _12=".vers"+SITE_VERSION;
if(!_11){
_12="";
}
if(check_bad_msie()){
return _e+"/images/"+_f+"/"+_d+_10+_12+".png";
}else{
return _e+"/images/"+_f+"/"+_d+_10+_12+".png";
}
};
check_bad_msie=function(){
return (window.ActiveXObject&&(typeof document.body.style.maxHeight=="undefined"));
};
fix_ie_png=function(img){
if(!check_bad_msie()){
return;
}
var _14=(img.id)?"id='"+img.id+"' ":"";
var _15=(img.className)?"class='"+img.className+"' ":"";
var _16=(img.title)?"title='"+img.title+"' ":"title='"+img.alt+"' ";
var _17="display:inline-block;"+img.style.cssText;
if(img.align=="left"){
_17="float:left;"+_17;
}
if(img.align=="right"){
_17="float:right;"+_17;
}
if(img.parentElement.href){
_17="cursor:hand;"+_17;
}
var _18="<span "+_14+_15+_16+" style=\""+"width:"+img.width+"px; height:"+img.height+"px;"+_17+";"+"filter:progid:DXImageTransform.Microsoft.AlphaImageLoader"+"(src='"+img.src+"', sizingMethod='image');\"></span>";
img.outerHTML=_18;
};
Move=function(_19,_1a,_1b,_1c,_1d,_1e,_1f){
this.fromColumn=_19;
this.fromRow=_1a;
this.toColumn=_1b;
this.toRow=_1c;
this.take=_1d;
this.promotion=_1e;
this.moveString=_1f;
this.prev=null;
this.next=null;
this.numVars=0;
this.ravLevel=0;
this.atEnd=false;
this.obj_id=move_obj_id_counter++;
};
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;
};
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.prototype.toMoveString=function(){
var _23="";
if(this.promotion){
_23=this.promotion;
}
return Move.columnToChar(this.fromColumn)+""+(this.fromRow+1)+Move.columnToChar(this.toColumn)+""+(this.toRow+1)+_23;
};
function getTagValue(_24,_25){
var _26=_24.getElementsByTagName(_25);
if(_26==null){
YAHOO.log("got null node for tag:"+_25);
return null;
}
if(_26.length==0){
YAHOO.log("got empty array node for tag:"+_25);
return null;
}
if(_26[0].firstChild==null){
YAHOO.log("firstChild is null for tag:"+_25);
return null;
}
if(_26[0].firstChild.nodeValue==null){
YAHOO.log("firstChild.nodeValue is null for tag:"+_25);
return null;
}
if(typeof (_26[0].textContent)!="undefined"){
return _26[0].textContent;
}
return _26[0].firstChild.nodeValue;
}
ChessPiece=function(div,_28,_29,_2a){
var ua=navigator.userAgent.toLowerCase();
var _2c=(ua.indexOf("opera")>-1);
var id=div.id;
this.board=_2a;
this.icon=get_image_str(ChessPiece.pieceIconNames[_28][_29],this.board.boardImagePath,this.board.pieceSet,this.board.pieceSize,this.board.addVersion);
this.colour=_28;
this.piece=_29;
this.id=id;
this.div=div;
var _2e=_2a.getPieceDragDiv();
var _2f=false;
if(_2e==null){
_2e=document.createElement("div");
_2e.id="pieceDragDiv";
_2f=true;
YAHOO.util.Dom.setStyle(_2e,"visibility","hidden");
YAHOO.util.Dom.setStyle(_2e,"border","0px");
YAHOO.util.Dom.setStyle(_2e,"position","absolute");
}
this.pieceDragEl=_2e;
this.pieceDragElId="pieceDragDiv";
if(_2f){
var _30=document.getElementsByTagName("body");
if(_30==null||_30.length==0){
alert("Could not find body tag");
}else{
_30[0].appendChild(_2e);
}
}
if(YAHOO.util.Event.isIE){
var _31=this.div;
_31.innerHTML="<img src=\""+this.icon+"\"/>";
var img=_31.firstChild;
if(!_2c){
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");
}
YAHOO.util.Dom.setStyle([this.div],"height",this.board.pieceSize+"px");
YAHOO.util.Dom.setStyle([this.div],"width",this.board.pieceSize+"px");
YAHOO.util.Dom.setStyle([this.div],"border","0px");
YAHOO.util.Dom.setStyle([this.div],"padding","0px");
var ua=navigator.userAgent.toLowerCase();
var _2c=(ua.indexOf("opera")>-1);
if(false&&_2c){
YAHOO.util.Dom.setStyle([this.div],"position","absolute");
}else{
YAHOO.util.Dom.setStyle([this.div],"position","relative");
}
this.init(id,"ct-"+this.board.boardName+"-boardandpieces",{dragElId:this.pieceDragElId,resizeFrame:false,centreFrame:true,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.isValidHandleChild=function(_33){
if(this.board.dragDisabled){
return false;
}
if(this.board.toMove!=this.colour){
return false;
}
return this.oldIsValidHandleChild(_33);
};
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;
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 _3f=7-i;
var _40=j;
if(this.board.isFlipped){
_3f=7-_3f;
_40=7-_40;
}
if((_3f==this.row&&_40==this.column)||this.board.canMove(this.makeLightWeight(),_40,_3f,this.board.currentMove.prev,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 _45=YAHOO.util.Dom.getX("ctb-"+this.board.boardName);
var _46=YAHOO.util.Dom.getY("ctb-"+this.board.boardName);
var c=parseInt((x-_45)/this.board.pieceSize);
var r=parseInt((y-_46)/this.board.pieceSize);
var _49=this.board.boardName+"-s"+c+""+(7-r);
var _4a=YAHOO.util.Dom.get(_49);
if(this.board.highlightValidSquares){
if(this.board.lastOverSquare){
if(this.board.lastOverSquare!=_4a){
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&&this.candidates[c][r]){
YAHOO.util.Dom.addClass(_4a,"ct-over-valid-square");
}else{
YAHOO.util.Dom.addClass(_4a,"ct-over-invalid-square");
}
}
}
this.board.lastOverSquare=_4a;
}
};
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 _4f=YAHOO.util.Dom.getX("ctb-"+this.board.boardName);
var _50=YAHOO.util.Dom.getY("ctb-"+this.board.boardName);
var c=parseInt((x-_4f)/this.board.pieceSize);
var r=parseInt((y-_50)/this.board.pieceSize);
if(this.board.isFlipped){
r=7-r;
c=7-c;
}
var _53=false;
if(!this.board.currentMove||this.board.currentMove.atEnd){
_53=true;
}
this.board.updatePiece(this,c,7-r,false,false,true);
if(!_53&&this.board.currentMove&&this.board.currentMove.atEnd){
this.board.toggleToMove();
this.board.updateToPlay();
}
};
ChessPiece.prototype.removeFromParent=function(){
var _54=this.div;
if(_54.parentNode){
_54.parentNode.removeChild(_54);
}
};
ChessPiece.prototype.setVisible=function(_55){
var _56;
var _57;
if(_55){
_57="block";
_56="visible";
}else{
_57="none";
_56="hidden";
}
YAHOO.util.Dom.setStyle(this.id,"visibility",_56);
};
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(_5a){
var ua=navigator.userAgent.toLowerCase();
var _5c=(ua.indexOf("opera")>-1);
var _5d=(_5a+"").toLowerCase().charAt(0);
switch(_5d){
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 _5e=this.div;
_5e.innerHTML="<img src=\""+this.icon+"\"/>";
var img=_5e.firstChild;
if(!_5c){
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(_60,row){
var _62=this.board.getBoardDiv();
var _63=this.board.getXY();
var _64=_63[0];
var _65=_63[1];
var _66=[0,0];
if(this.board.isFlipped){
_66[0]=_64+((7-_60)*this.board.pieceSize);
_66[1]=_65+((row)*this.board.pieceSize);
}else{
_66[0]=_64+((_60)*this.board.pieceSize);
_66[1]=_65+((7-row)*this.board.pieceSize);
}
return _66;
};
ChessPiece.prototype.setPosition=function(_67,row,_69,_6a,_6b){
this.column=_67;
this.row=row;
if(this.board.pieceMoveDisabled){
return;
}
var _6c=this.div;
if(!_69){
if(!this.board.settingUpPosition){
var _6d=this.getNewXYPosition(_67,row);
YAHOO.util.Dom.setXY(_6c,_6d,false);
}else{
var _6e=null;
if(this.board.isFlipped){
_6e=this.board.boardName+"-s"+(7-this.column)+""+(7-this.row);
}else{
_6e=this.board.boardName+"-s"+(this.column)+""+(this.row);
}
var _6f=this.board[_6e];
if(_6c.parentNode){
_6c.parentNode.removeChild(_6c);
}
_6f.appendChild(_6c);
}
this.setVisible(true);
if(_6a){
_6a();
}
}else{
var _6d=this.getNewXYPosition(_67,row);
var _70=new YAHOO.util.Motion(_6c,{points:{to:_6d}});
_70.duration=_6b;
var _71=this;
_70.onComplete.subscribe(function(){
});
if(_6a){
_70.onComplete.subscribe(_6a);
}
_70.animate();
}
};
LightweightChessPiece=function(div,_73,_74,_75){
this.board=_75;
this.colour=_73;
this.piece=_74;
this.div=div;
};
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(_77){
};
LightweightChessPiece.prototype.unreg=function(){
};
LightweightChessPiece.prototype.setPosition=function(_78,row,_7a,_7b,_7c){
this.column=_78;
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(_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:
}
};
MovesDisplay=function(_80,_81){
this.board=_80;
this.displayType=_81;
};
MovesDisplay.DEFAULT_DISPLAY_TYPE=0;
MovesDisplay.MAIN_ON_OWN_LINE=1;
Board=function(_82){
this.boardName=_82;
if(_82){
this.initTarget("ctb-"+_82,"ct-"+this.boardName+"-boardandpieces");
this.boardPieces=Board.createBoardArray();
}
this.settingUpPosition=false;
this.pendingLevelZeroCommentaryClose=false;
this.isUserFlipped=false;
};
Board.prototype=new YAHOO.util.DDTarget();
Board.createBoardArray=function(){
var _83=boardPool.getObject();
if(_83==null){
_83=new Array(8);
for(var i=0;i<8;i++){
_83[i]=new Array(8);
}
}
return _83;
};
Board.prototype.toggleToMove=function(){
if(this.toMove==ChessPiece.WHITE){
this.toMove=ChessPiece.BLACK;
}else{
this.toMove=ChessPiece.WHITE;
}
};
Board.prototype.setupPieceDivs=function(){
var _85=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].unreg();
}
}
}
this.availIds=new Array(32);
this.availPieceDivs=new Array(32);
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(_87,_88,_89,_8a,_8b,_8c){
YAHOO.util.Dom.removeClass(this.lastFromSquare,"ct-from-square");
YAHOO.util.Dom.removeClass(this.lastToSquare,"ct-to-square");
if(_89==null){
return;
}
this.lastFromSquare=_87;
this.lastToSquare=_88;
this.lastFromRow=_89;
this.lastFromColumn=_8a;
this.lastToRow=_8b;
this.lastToColumn=_8c;
if(this.highlightFromTo){
YAHOO.util.Dom.addClass(_87,"ct-from-square");
YAHOO.util.Dom.addClass(_88,"ct-to-square");
}
};
Board.prototype.makeMove=function(_8d,_8e,_8f,_90,_91,_92,_93,_94){
var _95;
var _96;
if(!this.isFlipped){
_95=YAHOO.util.Dom.get(this.boardName+"-s"+_8d.fromColumn+""+_8d.fromRow);
_96=YAHOO.util.Dom.get(this.boardName+"-s"+_8d.toColumn+""+_8d.toRow);
}else{
_95=YAHOO.util.Dom.get(this.boardName+"-s"+(7-_8d.fromColumn)+""+(7-_8d.fromRow));
_96=YAHOO.util.Dom.get(this.boardName+"-s"+(7-_8d.toColumn)+""+(7-_8d.toRow));
}
if(_92){
this.updateFromTo(_95,_96,_8d.fromRow,_8d.fromColumn,_8d.toRow,_8d.toColumn);
}
var _97=this.boardPieces[_8d.toColumn][_8d.toRow];
if(_97!=null){
_97.enPassant=false;
_97.castled=false;
}
if(_8e.piece==ChessPiece.PAWN&&_8d.toColumn!=_8d.fromColumn&&this.boardPieces[_8d.toColumn][_8d.toRow]==null){
_97=this.boardPieces[_8d.toColumn][_8d.fromRow];
this.boardPieces[_8d.toColumn][_8d.fromRow]=null;
if(_97!=null){
_97.enPassant=true;
}
}
var _98=null;
if(_8e.piece==ChessPiece.KING&&Math.abs(_8d.toColumn-_8d.fromColumn)>1){
var _99;
var _9a;
if(_8d.toColumn>_8d.fromColumn){
_98=this.boardPieces[7][_8d.fromRow];
_99=_8d.fromRow;
_9a=5;
this.boardPieces[7][_8d.toRow]=null;
}else{
_98=this.boardPieces[0][_8d.fromRow];
_99=_8d.fromRow;
_9a=3;
this.boardPieces[0][_8d.toRow]=null;
}
if(!_98){
alert("No castle piece");
}else{
_98.setPosition(_9a,_99,_8f,null,_90);
this.boardPieces[_98.column][_98.row]=_98;
_98.castled=true;
}
}
_8d.taken=_97;
if(_97&&_91){
this.processTaken(_97,true);
}
this.board_xy=null;
_8e.setPosition(_8d.toColumn,_8d.toRow,_8f,function(){
var tp=_97;
if(tp){
tp.setVisible(false);
}
if(_8d.promotion!=null){
_8e.changePiece(_8d.promotion);
}
if(_93){
_93.call(_94);
}
},_90);
if(!_8f){
if(_8d.promotion!=null){
_8e.changePiece(_8d.promotion);
}
}
this.boardPieces[_8d.fromColumn][_8d.fromRow]=null;
this.boardPieces[_8d.toColumn][_8d.toRow]=_8e;
if(_98!=null){
_8d.taken=_98;
}
if(_8e.piece==ChessPiece.ROOK){
if(_8d.fromColumn==0){
this.canCastleQueenSide[_8e.colour]=false;
}else{
if(_8d.fromColumn==7){
this.canCastleKingSide[_8e.colour]=false;
}
}
}else{
if(_8e.piece==ChessPiece.KING){
this.canCastleQueenSide[_8e.colour]=false;
this.canCastleKingSide[_8e.colour]=false;
}
}
};
Board.prototype.promptPromotion=function(_9c,col,row,_9f,_a0){
_9c.prePromotionColumn=_9c.column;
_9c.prePromotionRow=_9c.row;
_9c.setPosition(col,row,false,null,this.moveAnimationLength);
var _a1=this;
var _a2=new YAHOO.widget.Dialog("promotionDialogId",{width:"300px",fixedcenter:true,visible:true,modal:true,close:false,constraintoviewport:true,buttons:[{text:_js("Queen"),handler:function(){
_a2.hide();
_a1.updatePiece(_9c,col,row,_9f,_a0,false,"q");
},isDefault:true},{text:_js("Rook"),handler:function(){
_a2.hide();
_a1.updatePiece(_9c,col,row,_9f,_a0,false,"r");
},isDefault:false},{text:_js("Bishop"),handler:function(){
_a2.hide();
_a1.updatePiece(_9c,col,row,_9f,_a0,false,"b");
},isDefault:false},{text:_js("Knight"),handler:function(){
_a2.hide();
_a1.updatePiece(_9c,col,row,_9f,_a0,false,"n");
},isDefault:false}]});
_a2.setHeader(_js("Select Promotion Piece"));
_a2.setBody("<div></div>");
_a2.render(document.body);
};
Board.prototype.moveToLocale=function(_a3){
if(!_a3||_a3==""){
return _a3;
}
var _a4="";
for(var i=0;i<_a3.length;i++){
var _a6=_a3.charAt(i);
switch(_a6){
case "K":
_a6=_js("K");
break;
case "Q":
_a6=_js("Q");
break;
case "R":
_a6=_js("R");
break;
case "N":
_a6=_js("N");
break;
case "B":
_a6=_js("B");
break;
case "a":
_a6=_js("a");
break;
case "b":
_a6=_js("b");
break;
case "c":
_a6=_js("c");
break;
case "d":
_a6=_js("d");
break;
case "e":
_a6=_js("e");
break;
case "f":
_a6=_js("f");
break;
case "g":
_a6=_js("g");
break;
case "h":
_a6=_js("h");
break;
case "x":
_a6=_js("x");
break;
case "#":
_a6=_js("#");
break;
}
_a4+=_a6;
}
return _a4;
};
Board.prototype.updatePiece=function(_a7,col,row,_aa,_ab,_ac,_ad,_ae){
if(_ad){
this.board_xy=null;
if(_a7.prePromotionRow){
_a7.row=_a7.prePromotionRow;
_a7.column=_a7.prePromotionColumn;
}
}
if(_ad==null&&_a7.column==col&&_a7.row==row){
this.board_xy=null;
_a7.setPosition(_a7.column,_a7.row,false,null,this.moveAnimationLength);
if(clog){
console.log("moved piece back to its orig position");
}
return;
}
var _af=null;
if(this.currentMove){
_af=this.currentMove.prev;
}
var _b0="";
if(_ac&&_a7.piece==ChessPiece.PAWN&&(row==7||row==0)){
this.promptPromotion(_a7,col,row,_aa,_ab);
return;
}else{
if(_ad!=null){
_b0=_ad;
}
}
if(this.problem&&this.problem.isEndgame){
if(!this.canMove(_a7.makeLightWeight(),col,row,_af,true)){
this.board_xy=null;
_a7.setPosition(_a7.column,_a7.row,false,null,this.moveAnimationLength);
if(clog){
console.log("move not legal , move back to orig");
}
return;
}else{
if(clog){
console.log("move is legal");
}
}
var _b1=Move.columnToChar(_a7.column)+""+(_a7.row+1)+""+Move.columnToChar(col)+""+(row+1)+_b0;
var _b2=this.createMoveFromString(_b1);
if(clog){
console.log("creating pending move:"+_b2.output());
}
this.problem.endgamePendingPiece=_a7;
this.problem.endgameOldPosition=[_a7.column,_a7.row];
this.problem.endgamePendingMove=_b2;
if(!this.currentMove||this.currentMove.next==null||!this.currentMove.bestMoves||!_ae){
var _b3="currmovenull";
if(this.currentMove){
if(clog){
console.log("in endgame updatepiece calling processEndgame currentMove:"+this.currentMove.output()+" fens:"+this.currentMove.fen);
}
}
if(!_ae){
if(clog){
console.log("col:"+col+" row:"+row);
}
_a7.setPosition(col,row,false,null,this.moveAnimationLength);
}
if(this.tactics&&this.tactics.problemFirstMoveDate==0){
this.tactics.problemFirstMoveDate=new Date().getTime();
}
this.problem.processEndgame(_b1,_ae);
}else{
_b1=this.currentMove;
this.makeMove(_b1,_a7,_ab,this.moveAnimationLength,true,true);
this.setCurrentMove(this.currentMove.next);
var cm=this.currentMove;
}
}else{
if(this.tactics&&this.tactics.problemActive){
this.tactics.hideProblemStatus();
}
if(!this.currentMove||this.currentMove.atEnd){
this.board_xy=null;
_a7.setPosition(_a7.column,_a7.row,false,null,this.moveAnimationLength);
YAHOO.log("already at end of move list");
alert("already at end");
return;
}
_b1=this.currentMove;
if(_b1.fromColumn==_a7.column&&_b1.fromRow==_a7.row&&_b1.toRow==row&&_b1.toColumn==col&&(_b0==""||(_b0==_b1.promotion))){
if(this.tactics&&this.tactics.problemFirstMoveDate==0){
this.tactics.problemFirstMoveDate=new Date().getTime();
}
YAHOO.log("Made correct move");
this.makeMove(_b1,_a7,_ab,this.moveAnimationLength,true,true);
this.setCurrentMove(this.currentMove.next);
if(this.currentMove.atEnd){
if(this.tactics&&this.tactics.problemActive){
var _b5=0;
if(this.tactics.session&&this.tactics.session.continueCorrect==1){
_b5=1;
}
this.tactics.markProblem(true,_b5,"NULL","NULL");
}
}
if(!_aa&&!this.currentMove.atEnd){
opponentMove=this.currentMove;
YAHOO.log("Updating opponent move fromcol:"+opponentMove.fromColumn+" frowRow:"+opponentMove.fromRow);
this.updatePiece(this.boardPieces[opponentMove.fromColumn][opponentMove.fromRow],opponentMove.toColumn,opponentMove.toRow,true,true,false);
}
}else{
var _b6=_a7.column;
var _b7=_a7.row;
var _b8=false;
var _b9=null;
if(_b1.vars&&_b1.vars.length>0){
var i=0;
for(var i=0;i<_b1.vars.length;i++){
_b9=_b1.vars[i];
if(_b9.isAlt&&_b9.fromColumn==_b6&&_b9.fromRow==_b7&&_b9.toRow==row&&_b9.toColumn==col){
_b8=true;
break;
}
}
}
if(_b8){
if(this.tactics){
var _bb=_js("That");
if(_b9&&_b9.SAN){
_bb=this.moveToLocale(_b9.SAN);
}
this.tactics.showProblemStatus(_js("Keep Looking"),__js("{ALTERNATIVE_MOVE} was a good move, but not the computer's first choice.<br/> Please keep looking for another move.",[["ALTERNATIVE_MOVE",_bb]]));
this.tactics.aCount++;
}
}
this.board_xy=null;
_a7.setPosition(_a7.column,_a7.row,false,null,this.moveAnimationLength);
if(!_b8&&this.canMove(_a7.makeLightWeight(),col,row,this.currentMove.prev,true)){
if(this.tactics){
this.tactics.autoForward=false;
}
if(this.tactics&&this.tactics.problemActive){
var _bc=false;
if(this.tactics.session){
_bc=(this.tactics.session.continueFailed==1);
}
var _bd=Math.round(_b1.moveNum/2);
var _be=Move.columnToChar(_a7.column)+""+(_a7.row+1)+""+Move.columnToChar(col)+""+(row+1);
_be+="|"+this.makeShortAlgabraic(_a7.column,_a7.row,col,row);
this.tactics.markProblem(false,_bc,_bd,_be);
}
}
}
}
};
Board.prototype.scoreToShortString=function(_bf){
if(_bf=="draw"){
return "D";
}
if(_bf>=0){
return "M"+_bf;
}else{
return "L"+(-1*_bf);
}
};
Board.prototype.scoreToLongString=function(_c0){
if(_c0=="draw"){
return _js("Draw");
}
if(_c0==0){
return _js("Mate");
}else{
if(_c0>0){
return __js("Mate in {NUMBER_MOVES}",[["NUMBER_MOVES",_c0]]);
}else{
return __js("Lose in {NUMBER_MOVES}",[["NUMBER_MOVES",(-1*_c0)]]);
}
}
};
Board.prototype.egMoveToScoreString=function(_c1){
var _c2=_c1.score;
var _c3=_c1.optimal_score;
var s=this.scoreToShortString(_c2);
var opt=this.scoreToShortString(_c3);
var _c6=this.scoreToLongString(_c2);
var _c7=this.scoreToLongString(_c3);
if(_c2==_c3){
return ["",_c6];
}else{
var _c8="ct-subopt-move-score";
if(_c2=="draw"||_c2<0){
_c8="ct-bad-move-score";
}
return ["<span class=\""+_c8+"\">"+s+"("+opt+")</span>",_c6+"("+_c7+")"];
}
};
Board.prototype.makeShortAlgabraic=function(_c9,_ca,_cb,_cc,_cd){
if(clog){
console.log("fromCol:"+_c9+" fromRow:"+_ca+" toCol:"+_cb+" toRow:"+_cc);
}
var _ce=this.boardPieces[_c9][_ca];
var _cf=_ce.piece;
var _d0=this.pieceTypeToChar(_cf);
var _d1="";
if(_cf==ChessPiece.PAWN){
if(_c9==_cb){
_d1=Move.columnToChar(_c9)+""+(_cc+1);
}else{
_d1=Move.columnToChar(_c9)+"x"+Move.columnToChar(_cb)+""+(_cc+1);
if(!this.boardPieces[_cb][_cc]){
_d1+=" e.p.";
}
}
}else{
if(_cf==ChessPiece.KING){
var _d2=Math.abs(_c9-_cb);
if(_d2==1||_d2==0){
_d1=_d0;
if(this.boardPieces[_cb][_cc]){
_d1+="x";
}
_d1+=Move.columnToChar(_cb)+""+(_cc+1);
}else{
if(_cb==6){
_d1="O-O";
}else{
_d1="O-O-O";
}
}
}else{
var _d3=[];
for(var row=0;row<8;row++){
for(var col=0;col<8;col++){
var cp=this.boardPieces[col][row];
if(cp&&cp.colour==_ce.colour&&cp.piece==_cf&&!(_ce.column==cp.column&&_ce.row==cp.row)){
var _d7=null;
if(this.currentMove){
_d7=this.currentMove.prev;
}
if(this.canMove(cp.makeLightWeight(),_cb,_cc,_d7,true)){
_d3.push(cp);
}
}
}
}
_d1=_d0;
if(_d3.length>0){
var _d8=false;
var _d9=false;
for(var i=0;i<_d3.length;i++){
if(_d3[i].row==_ca){
_d9=true;
}
if(_d3[i].column==_c9){
_d8=true;
}
}
if(_d9||!(_d9||_d8)){
_d1+=Move.columnToChar(_c9);
}
if(_d8){
_d1+=""+(_ca+1);
}
}
if(this.boardPieces[_cb][_cc]){
_d1+="x";
}
_d1+=Move.columnToChar(_cb)+""+(_cc+1);
}
}
var _db="";
var _dc="";
if(_cd){
var _dd=this.cloneBoard();
var _de=ChessPiece.WHITE;
if(_dd.boardPieces[_cd.fromColumn][_cd.fromRow].colour==ChessPiece.WHITE){
_de=ChessPiece.BLACK;
}
_dd.makeMove(_cd,_dd.boardPieces[_cd.fromColumn][_cd.fromRow],false,_dd.moveAnimationLength,false,false);
if(!_dd.isKingSafe(_de,_cd)){
_db="+";
if(_dd.isKingMated(_de,_cd)){
_db="#";
}
}
if(_cd.promotion){
_dc="="+((_cd.promotion+"").toUpperCase());
}
}
_d1+=_dc+_db;
return _d1;
};
Board.prototype.createMoveFromString=function(_df){
var _e0=0;
var _e1=false;
var _e2=null;
var _e3=_df.charCodeAt(_e0++);
var _e4=_df.charCodeAt(_e0++);
var _e5=_df.split("|");
var pgn=null;
if(_e5.length>1){
pgn=_e5[1];
_df=_e5[0];
}else{
_df=_e5[0];
}
if(_df.charAt(_e0)=="x"){
_e0++;
_e1=true;
}
var _e7=_df.charCodeAt(_e0++);
var _e8=_df.charCodeAt(_e0++);
if(_e0<_df.length){
_e2=_df.charAt(_e0);
}
var _e9=new Move(_e3-("a".charCodeAt(0)),_e4-("1".charCodeAt(0)),_e7-("a".charCodeAt(0)),_e8-("1".charCodeAt(0)),_e1,_e2,_df);
_e9.pgn=pgn;
return _e9;
};
Board.prototype.setForwardBack=function(){
var _ea=YAHOO.util.Dom.get(this.boardName+"-back");
var _eb=YAHOO.util.Dom.get(this.boardName+"-forward");
var end=YAHOO.util.Dom.get(this.boardName+"-end");
var _ed=YAHOO.util.Dom.get(this.boardName+"-start");
if(!this.currentMove){
if(_ea){
_ea.src=this.boardImagePath+"/images/resultset_previous_disabled"+this.getVersString()+".gif";
}
if(_ed){
_ed.src=this.boardImagePath+"/images/disabled_resultset_first"+this.getVersString()+".gif";
}
if(_eb){
_eb.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(_ea){
_ea.src=this.boardImagePath+"/images/resultset_previous_disabled"+this.getVersString()+".gif";
}
if(_ed){
_ed.src=this.boardImagePath+"/images/disabled_resultset_first"+this.getVersString()+".gif";
}
}else{
if(_ea){
_ea.src=this.boardImagePath+"/images/resultset_previous"+this.getVersString()+".gif";
}
if(_ed){
_ed.src=this.boardImagePath+"/images/resultset_first"+this.getVersString()+".gif";
}
}
if(this.currentMove.atEnd){
if(_eb){
_eb.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(_eb){
_eb.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(_ee){
var _ef=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 _f2=this.boardPieces[i][j];
var p=_f2.makeHeavyWeight();
this.boardPieces[i][j]=p;
p.setPosition(p.column,p.row,false,null,this.moveAnimationLength);
p.setVisible(true);
}
}
}
var _f4=this.moveArray[_ee];
while(_f4!=null){
if(_f4.taken){
_f4.taken=_f4.taken.makeHeavyWeight();
}
_f4=_f4.prev;
}
this.settingUpPosition=_ef;
};
MovesDisplay.prototype.setToMove=function(_f5){
this.toMove=_f5;
};
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 _f8=t.id.substr((this.board.boardName+"-m").length);
if(clog){
console.log("got goto move index:"+_f8);
}
this.board.gotoMoveIndex(_f8);
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(_f9,_fa,_fb,_fc){
var _fd="";
if(_fa>this.board.ml){
return _fd;
}
if(this.board.ml==1&&_fc>1){
return _fd;
}
var _fe=this.getMovesDisplay();
if(_fe){
if(_f9==0&&this.displayType==MovesDisplay.MAIN_ON_OWN_LINE){
if(this.firstNonMove){
_fd+="<div class=\"ct-mainline-commentary\"/>";
this.pendingLevelZeroCommentaryClose=true;
}
}
if(this.variationOnOwnLine){
_fd+="<br/>";
}
if(this.board.showBracketsOnVariation){
_fd+="<span>( </span>";
}
}
this.firstNonMove=false;
return _fd;
};
MovesDisplay.prototype.outputVariationEnd=function(_ff,_100,_101,_102){
var _103=this.getMovesDisplay();
var _104="";
if(_100>this.board.ml){
return _104;
}
if(this.board.ml==1&&_102>3){
return _104;
}
if(_103){
if(this.board.showBracketsOnVariation){
_104+="<span>) </span>";
}
}
if(_ff==1&&this.displayType==MovesDisplay.MAIN_ON_OWN_LINE){
}
this.firstNonMove=false;
return _104;
};
MovesDisplay.prototype.outputComment=function(_105,_106,_107){
var _108="";
if(this.board.ml==1){
return _108;
}
var _109=this.getMovesDisplay();
if(_109){
if(_106==0&&this.displayType==MovesDisplay.MAIN_ON_OWN_LINE){
if(this.firstNonMove){
_108+="<br/>";
}
_108+="<div class=\"ct-mainline-commentary\">";
this.pendingLevelZeroCommentaryClose=true;
}
var _10a="ct-board-move-comment";
if(_107){
_10a="ct-board-move-alt-comment";
}
_108+="<span class=\""+_10a+"\"> "+_105+" </span>";
if(_106==0&&this.displayType==MovesDisplay.MAIN_ON_OWN_LINE){
}
}
this.firstNonMove=false;
return _108;
};
MovesDisplay.prototype.outputNag=function(_10b){
var _10c="";
var _10d=this.getMovesDisplay();
if(_10d){
var _10e=null;
switch(_10b){
case 11:
_10e="=";
break;
case 14:
_10e="+=";
break;
case 15:
_10e="=+";
break;
case 16:
_10e="+/-";
break;
case 17:
_10e="-/+";
break;
case 18:
_10e="+-";
break;
case 19:
_10e="-+";
break;
case 20:
_10e="+--";
break;
case 21:
_10e="--+";
break;
default:
}
if(_10e){
_10c+="<span> "+_10e+" </span>";
}
}
return _10c;
};
MovesDisplay.prototype.outputResult=function(_10f){
return "<span class=\"ct-result\">"+_10f+"</span>";
};
MovesDisplay.prototype.outputUploader=function(_uploader){
if(_uploader&&_uploader!="?"){
return "<br /><span class=\"ct-result\"> Geupload door "+_uploader+"</span>";
}
else{
return "";
}
};
MovesDisplay.prototype.outputMove=function(_110,_111,_112,_113,_114,_115,_116,move,_118,_119){
if(clog){
console.log("outputMove:"+_113+" hideScore:"+_118);
}
var _11a="";
var _11b=this.getMovesDisplay();
if(this.board.tr&&_111>0&&(_115>1||_116>3)&&!_114){
return _11a;
}
if(_111>0&&_115>this.board.ml){
return _11a;
}
if(_111>0&&_116>3&&this.board.ml==1){
return _11a;
}
if(_11b){
var _11c=""+Math.round(_112/2)+". ";
if(_112%2!=1){
if(clog){
console.log("firstRav:"+_114+" firstNonMove:"+this.firstNonMove);
}
if(_114||!this.firstNonMove){
_11c=Math.round(_112/2)+"... ";
}else{
_11c="";
}
}
if(this.displayType==MovesDisplay.MAIN_ON_OWN_LINE&&_111==0&&(!this.firstNonMove||_112%2==1)){
if(this.pendingLevelZeroCommentaryClose){
this.pendingLevelZeroCommentaryClose=false;
_11a+="</div>";
}
if(this.board.newlineForEachMainMove){
_11a+="<br/>";
}
}
var _11d="";
var _11e="";
if(move&&move.eg_move){
var res=this.board.egMoveToScoreString(move.eg_move);
_11d=res[0];
_11e=res[1];
}
var _120="";
if(_118){
_120="initially_hidden";
}
if(_11d!=""){
_11d=" "+_11d;
}
var _121="title";
if(_118){
_121="alt";
}
var _122="";
if(_119){
_122=" rel=\""+_113+"\" ";
_113="___";
}
_11a+="<span "+_122+_121+"=\""+_11e+"\" id=\""+this.board.boardName+"-m"+_110+"\" class=\""+((_111==0)?"ct-board-move-mainline":"ct-board-move-variation")+"\">"+_11c+_113+"<span id=\""+this.board.boardName+"-msc"+_110+"\" class=\""+_120+"\">"+_11d+"</span></span>";
}
this.firstNonMove=true;
return _11a;
};
Board.prototype.setMoveSeqLalg=function(_game,_124,_125,_126){
var _123 = _game.movesseq;
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 _129=this.cloneBoard();
this.movesDisplay.firstNonMove=false;
var _12a=new Array();
var _12b=new Array();
if(this.prev_move){
_129.makeMove(this.prev_move,_129.boardPieces[this.prev_move.fromColumn][this.prev_move.fromRow],false,_129.moveAnimationLength,false,false);
}
var _12c=_129.cloneBoard();
var _12d=_123.replace(/\s+$/g,"").split(" ");
var _12e=null;
var _12f=0;
var _130="";
var _131=false;
var _132=false;
var _133=0;
var _134=false;
var _135=new Array();
var _136=new Array();
_136[0]=0;
var _137=new Array();
var _138=new Array();
var _139=_125*2-1;
var _13a=new Array();
var _13b=ChessPiece.WHITE;
var _13c=0;
var eval="";
var _13e="";
var _13f="";
var time="";
var _141=-1;
for(var i=0;i<_12d.length;i++){
var _142=0;
if(_12d[i]=="ALT"){
_132=true;
continue;
}
if(_12d[i].indexOf("EVAL")==0){
eval=_12d[i].split(":")[1];
if(parseInt(eval)>=175&&_133>0&&_136[_133]>1){
_132=true;
}
continue;
}
if(_12d[i].indexOf("DEPTH")==0){
_13e=_12d[i].split(":")[1];
continue;
}
if(_12d[i].indexOf("NODES")==0){
_13f=_12d[i].split(":")[1];
continue;
}
if(_12d[i].indexOf("TIME")==0){
time=_12d[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 _144=e.split(" ");
_142=parseInt(_144[1]);
e=_js("mate")+" "+_144[1];
if(_136[_133]==1){
_141=_142;
}
}
if(_142<0){
_132=false;
}else{
if(_142>0&&_142<8&&_133>0&&_136[_133]>1){
_132=true;
}
}
var _145="";
if(_132){
_145=_js("ALT")+" ";
}
var t=parseInt(time);
var nps=" "+__js("nps:{NODES_PER_SECOND}",[["NODES_PER_SECOND",Math.round(parseInt(_13f)/(parseInt(time)/1000))]]);
if(!this.showNPS){
nps="";
}
if(!(_133>0&&_136[_133]>this.ml)){
_12d[i]=_145+e+" ("+__js("depth:{DEPTH}",[["DEPTH",_13e]])+nps+")";
}else{
_12d[i]="";
}
}
if(_12d[i]=="}"){
_131=false;
if(this.movesDisplay){
_130=_130.replace(/\s+$/g,"");
_13a.push(this.movesDisplay.outputComment(_130,_133,_132));
}
continue;
}else{
if(_131){
_130+=_12d[i]+" ";
continue;
}else{
if(_12d[i]=="{"){
_130="";
_131=true;
continue;
}else{
if(_12d[i]=="("){
if(!_136[_133+1]){
_136[_133+1]=0;
}
_136[_133+1]++;
if(this.movesDisplay){
_13a.push(this.movesDisplay.outputVariationStart(_133,_136[_133+1],_139,_135[0]));
}
_135[_133]=_139;
_137[_133]=_12e;
_138[_133]=_13b;
_12a[_133]=_129;
_12b[_133]=_12c;
_129=_12c.cloneBoard();
_133++;
_139--;
_134=true;
continue;
}else{
if(_12d[i]==")"){
if(this.movesDisplay){
_13a.push(this.movesDisplay.outputVariationEnd(_133,_136[_133],_139,_135[0]));
}
var _148=new Move();
_148.atEnd=true;
_12e.next=_148;
_148.prev=_12e;
_133--;
_139=_135[_133];
_12e=_137[_133];
_13b=_138[_133];
_129=_12a[_133];
_12c=_12b[_133];
_132=false;
continue;
}else{
if(_12d[i].charAt(0)=="$"){
if(this.movesDisplay){
_13a.push(this.movesDisplay.outputNag(parseInt(_12d[i].substring(1))));
}
continue;
}
}
}
}
}
}
var move=this.createMoveFromString(_12d[i]);
var _14a=false;
if(_139==1&&this.boardPieces[move.fromColumn][move.fromRow].colour==ChessPiece.BLACK){
_139++;
_14a=true;
_13b=ChessPiece.BLACK;
}
move.index=_12f;
var _14b=(move.pgn)?move.pgn:move.moveString;
if(move.pgn){
_14b=move.pgn;
}else{
_14b=_129.makeShortAlgabraic(move.fromColumn,move.fromRow,move.toColumn,move.toRow,move);
move.SAN=_14b;
}
_14b=this.moveToLocale(_14b);
if(this.movesDisplay){
this.movesDisplay.setToMove(_13b);
_13a.push(this.movesDisplay.outputMove(_12f,_133,_139,_14b+" ",_134,_136[_133],_135[0]));
}
_13b=(_13b==ChessPiece.BLACK)?ChessPiece.WHITE:ChessPiece.BLACK;
move.moveNum=_139;
_139++;
if(_133>0){
if(_134){
var _14c=_12e;
if(_14c==null){
alert("Got no previous move for variation:"+movesArra[i]);
}
if(_14c.numVars==0){
_14c.vars=new Array();
}
move.isAlt=_132;
_14c.vars[_14c.numVars++]=move;
move.prev=_14c.prev;
_134=false;
}else{
move.prev=_12e;
if(_12e!=null){
_12e.next=move;
}
}
}else{
move.prev=_12e;
if(_12e!=null){
_12e.next=move;
}
}
_136[_133+1]=0;
if(_133==0){
_13c=_12f;
}
_124[_12f++]=move;
_129.moveArray[_12f-1]=move;
_12e=move;
_12c=_129.cloneBoard();
_129.makeMove(move,_129.boardPieces[move.fromColumn][move.fromRow],false,_129.moveAnimationLength,false,false);
}
if(this.movesDisplay&&!this.disableMoveOutput){
var _14d=this.movesDisplay.getMovesDisplay();
_13a.push(this.movesDisplay.outputResult(_126));
// output uploader [JORIS]
_13a.push(this.movesDisplay.outputUploader(_game.uploader));
// comments here [JORIS]
jQuery("#comments_ajax").load(document.location.href + "?getcomments=" + _game.id);
this.pendingMovesOutput=_13a.join("");
this.pendingMovesOutputCount=_12f;
}
this.lastMoveIndex=_13c;
if(_12e!=null){
var _148=new Move();
_148.atEnd=true;
_12e.next=_148;
_148.prev=_12e;
}
this.lastCount=_12f;
};
Board.prototype.displayPendingMoveList=function(){
if(this.pendingMovesOutput&&this.movesDisplay){
var _14e=this.movesDisplay.getMovesDisplay();
if(_14e){
_14e.innerHTML=this.pendingMovesOutput;
var _14f=new YAHOO.util.Scroll(_14e,{scroll:{to:[0,0]}},0);
_14f.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(_151,_153,_154,_155){
var _152 = _151.movesseq;
this.tacticMoveArray=new Array();
this.moveArray=this.tacticMoveArray;
this.setMoveSeqLalg(_151,this.tacticMoveArray,_154,_155);
this.tacticsmoveArrayLastMoveIndex=this.lastMoveIndex;
if(false&&_153!="NA"){
this.fullmoveArray=new Array();
this.disableMoveOutput=true;
this.setMoveSeqLalg(_153,this.fullmoveArray,_154,_155);
this.disableMoveOutput=false;
this.fullmoveArrayLastMoveIndex=this.lastMoveIndex;
}else{
this.fullmoveArray=null;
}
this.lastMoveIndex=this.tacticsmoveArrayLastMoveIndex;
};
Board.prototype.resetVariationsPreviousNodes=function(_156,_157){
if(_156.numVars>0){
for(var i=0;i<_156.numVars;i++){
_156.vars[i].prev=_157;
this.resetVariationsPreviousNodes(_156.vars[i],_157);
}
}
};
Board.prototype.reconnectNextNodeVariations=function(_159,_15a){
if(!_15a){
return;
}
if(_15a.numVars>0){
for(var i=0;i<_15a.numVars;i++){
_15a.vars[i].prev=_159;
this.reconnectNextNodeVariations(_159,_15a.vars[i]);
}
}
};
Board.prototype.insertMoveAfter=function(_15c,_15d,_15e,_15f,_160,_161){
addToMovelist=!_15e;
if(clog){
console.log("addToMovelist:"+addToMovelist);
}
var _162="null";
if(_15c){
_162=_15c.output();
}
if(clog){
console.log("insert newMove:"+_15d.output()+" after:"+_162);
}
if(_15c==null){
this.currentMove=_15d;
_15d.atEnd=1;
_15d.prev=null;
_15d.next=null;
this.firstMove=_15d;
if(this.toMove==ChessPiece.WHITE){
this.currentMove.moveNum=1;
}else{
this.currentMove.moveNum=2;
}
}else{
_15d.atEnd=_15c.atEnd;
_15d.prev=_15c;
_15c.atEnd=0;
if(clog){
if(_15c.next){
console.log("prevMove.next:"+_15c.next.output());
}
}
if(_15d.equals(_15c.next)||_15d.equals(_15c)){
if(clog){
console.log("inserting move that already exists in variation:"+_15c.next.output());
}
var _163=_15c.next;
if(this.firstMove==_163){
this.firstMove=_15d;
}
if(_15d.equals(_15c)){
_163=_15c;
}
if(_163.prev&&(_163.prev.next==_163)){
_163.prev.next=_15d;
}
if(_163.next){
_163.next.prev=_15d;
}
addToMovelist=false;
_15d.moveNum=_163.moveNum;
_15d.ravLevel=_163.ravLevel;
_15d.index=_163.index;
_15d.fen=_163.fen;
_15d.nextFen=_163.nextFen;
_15d.bestMoves=_163.bestMoves;
_15d.correctMove=_163.correctMove;
_15d.wrongMove=_163.wrongMove;
_15d.next=_163.next;
_15d.vars=_163.vars;
_15d.numVars=_163.numVars;
this.reconnectNextNodeVariations(_15d,_163.next);
this.moveArray[_15d.index]=_15d;
if(this.currentMove==_163){
this.setCurrentMove(_15d);
}
}else{
_15d.moveNum=_15c.moveNum+1;
_15d.ravLevel=_15c.ravLevel;
_15d.next=_15c.next;
if(_15d.next){
_15d.next.prev=_15d;
}
}
_15c.next=_15d;
}
if(addToMovelist){
this.insertIntoMoveDisplay(_15c,_15d,_15f,_160,_161);
}
if(_15d.next==null){
var _164=this.createMoveFromString("i1i2");
_15d.next=_164;
_164.prev=_15d;
_164.moveNum=_15d.moveNum+1;
_164.ravLevel=_15d.ravLevel;
_164.next=null;
_164.atEnd=1;
_164.endNode=true;
if(clog){
console.log("created endmove node in insertAfterMove:"+_164.output());
}
}else{
if(clog){
console.log("allready had a node at end:"+_15d.next.output());
}
_15d.next.moveNum=_15d.moveNum+1;
}
};
function insertAfter(node,_166){
var _167=_166.parentNode;
_167.insertBefore(node,_166.nextSibling);
}
Board.prototype.replaceIntoMoveDisplay=function(_168,_169,_16a,_16b,_16c){
var _16d="null";
if(_168){
_16d=_168.output();
}
if(clog){
console.log("replace display newMove:"+_169.output()+" after:"+_16d+" hideScore:"+_16b);
}
if(!_168){
if(clog){
console.log("null oldMove");
}
this.insertIntoMoveDisplay(null,_169,false,_16b);
}else{
if(clog){
console.log("about to get movesdsiplay in replace into move display:"+this.movesDisplay);
}
var _16e=this.movesDisplay.getMovesDisplay();
if(clog){
console.log("got moves display");
}
if(!_16e){
if(clog){
console.log("no movesd disiplay in replace into move display");
}
return;
}
var san=_169.SAN;
if(!san){
if(clog){
console.log("about to make san");
}
san=this.makeShortAlgabraic(_169.fromColumn,_169.fromRow,_169.toColumn,_169.toRow,_169);
if(clog){
console.log("about to made san:"+san);
}
_169.SAN=san;
}
if(clog){
console.log("oldMove.index:"+_168.index);
}
var _170=YAHOO.util.Dom.get((this.boardName+"-ms"+_168.index));
if(_16a){
this.moveIndex++;
_169.index=this.moveIndex;
this.moveArray[this.moveIndex]=_169;
if(clog){
console.log("replace as variation old:"+_168.output()+" new:"+_169.output());
}
var _171=document.createElement("span");
var _172=this.movesDisplay.outputVariationStart(0,0,_169.moveNum,0);
_169.ravLevel=_168.ravlevel+1;
var _16d=this.moveToLocale(san);
if(_169.prev==null){
this.movesDisplay.firstNonMove=false;
}
var _173=this.movesDisplay.outputMove(this.moveIndex,_169.ravLevel,_169.moveNum,_16d,_16a,0,_169.moveNum,_169,_16b,_16c);
var _174=document.createElement("span");
_174.id=(this.boardName+"-ms"+_169.index);
_174.innerHTML=_173+"&nbsp;";
var _175=this.movesDisplay.outputVariationEnd(0,0,_169.moveNum,0);
this.movesDisplay.firstNonMove=true;
var _176=document.createElement("span");
_176.innerHTML=_172;
var _177=document.createElement("span");
_177.innerHTML=_175;
_171.appendChild(_176);
_171.appendChild(_174);
_171.appendChild(_177);
_170.appendChild(_171);
}else{
_169.index=_168.index;
this.moveArray[_169.index]=_169;
var _16d=this.moveToLocale(san);
if(_169.prev==null){
this.movesDisplay.firstNonMove=false;
}
var _173=this.movesDisplay.outputMove(_169.index,_169.ravLevel,_169.moveNum,_16d,_16a,0,_169.moveNum,_169,_16b,_16c);
var _174=document.createElement("span");
_174.innerHTML=_173+"&nbsp;";
_174.id=(this.boardName+"-ms"+_169.index);
var _178=[];
if(_170&&_170.childNodes){
for(var i=1;i<_170.childNodes.length;i++){
_178[i-1]=_170.childNodes[i];
}
}
if(clog){
console.log("replace as main line not variation old:"+_168.output()+" new:"+_169.output());
}
_170.parentNode.replaceChild(_174,_170);
if(_178){
for(var i=0;i<_178.length;i++){
_174.appendChild(_178[i]);
}
}
}
YAHOO.util.Event.removeListener(this.boardName+"-m"+_169.index);
YAHOO.util.Event.addListener((this.boardName+"-m"+_169.index),"click",this.movesDisplay.gotoMove,this.movesDisplay,true);
}
};
Board.prototype.insertIntoMoveDisplay=function(_17a,_17b,_17c,_17d,_17e){
var _17f=this.movesDisplay.getMovesDisplay();
if(!_17f){
return;
}
var _180="null";
if(_17a){
_180=_17a.output();
}
if(clog){
console.log("insert display newMove:"+_17b.output()+" after:"+_180);
}
var san=_17b.SAN;
if(!san){
san=this.makeShortAlgabraic(_17b.fromColumn,_17b.fromRow,_17b.toColumn,_17b.toRow,_17b);
_17b.SAN=san;
}
this.moveIndex++;
_17b.index=this.moveIndex;
this.moveArray[this.moveIndex]=_17b;
var _180=this.moveToLocale(san);
var _182=this.movesDisplay.outputMove(this.moveIndex,_17b.ravLevel,_17b.moveNum,_180,false,0,_17b.moveNum,_17b,_17d,_17e);
var _183=document.createElement("span");
_183.innerHTML=_182+"&nbsp;";
_183.id=(this.boardName+"-ms"+this.moveIndex);
if(_17c){
YAHOO.util.Dom.setStyle(_183,"visibility","hidden");
}
if(_17a){
if(clog){
console.log("prevMove.index:"+_17a.index+"prevMove:"+_17a.output());
}
var _184=YAHOO.util.Dom.get((this.boardName+"-ms"+_17a.index));
if(_184){
insertAfter(_183,_184);
}else{
_17f.appendChild(_183);
}
}else{
if(_17b.next){
var _185=YAHOO.util.Dom.get((this.boardName+"-ms"+_17b.next.index));
insertBefore(_183,_185);
}else{
_17f.appendChild(_183);
}
}
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(_186,_187,_188,_189,_18a,_18b){
var _18c="null";
if(_186){
_18c=_186.output();
}
if(clog){
console.log("replace newMove:"+_187.output()+" after:"+_18c+" replace as var"+_188+" rep move display:"+_189+" hideScore:"+_18a);
if(_186&&_186.prev){
console.log("replace oldMove.prev:"+_186.prev.output());
}
if(_186&&_186.next){
console.log("replace oldMove.next:"+_186.next.output());
}
}
var _18d=false;
var _18e=null;
var _18f=0;
if(_186.endNode){
if(clog){
console.log("asked to replace endNode,inserting before instead");
}
this.insertMoveAfter(_186.prev,_187,false,false,_18a,_18b);
_187.fen=_186.fen;
_187.nextFen=_186.nextFen;
return;
}
if(_187.equals(_186)){
if(clog){
console.log("new move is same as old move so not replacing as variation");
}
_188=false;
}else{
if(_186&&_186.numVars>0){
for(var i=0;i<_186.numVars;i++){
var _191=_186.vars[i];
if(_187.equals(_191)){
if(clog){
console.log("new move is same as an existing variation varNum:"+i);
console.log("variation:"+_191.output());
if(_191.next){
console.log("variation next:"+_191.next.output());
}
}
_18d=true;
_18e=_186;
_186=_191;
_18f=i;
break;
}
}
}
}
if(_186==null){
if(clog){
console.log("replaced new move with null oldmove");
}
this.currentMove=_187;
_187.atEnd=1;
_187.next=null;
_187.prev=null;
if(this.startPositionAfterOpponentMove){
_187.fen=this.startPositionAfterOpponentMove;
_187.nextFen=null;
}
if(this.toMove==ChessPiece.WHITE){
this.currentMove.moveNum=1;
}else{
this.currentMove.moveNum=2;
}
this.firstMove=_187;
}else{
var _192=false;
if(_186&&_186.prev&&_186.prev.next!=_186){
_192=true;
}
if(this.currentMove==_186&&!_188){
this.currentMove=_187;
}
_187.atEnd=_186.atEnd;
_187.prev=_186.prev;
_187.next=_186.next;
_187.fen=_186.fen;
_187.nextFen=_186.nextFen;
_187.bestMoves=_186.bestMoves;
_187.correctMove=_186.correctMove;
_187.wrongMove=_186.wrongMove;
_187.moveNum=_186.moveNum;
_187.ravLevel=_186.ravLevel;
_187.index=_186.index;
if(_18d){
_18e.vars[_18f]=_187;
_187.vars=_186.vars;
_187.numVars=_186.numVars;
this.reconnectNextNodeVariations(_187,_186.next);
if(_186.next){
_186.next.prev=_187;
}
this.moveArray[_187.index]=_187;
if(clog){
console.log("replacing existing sub variation of main line");
if(_187.next){
console.log("next of replacement variation:"+_187.next.output());
}
}
return;
}
if(!_188){
if(clog){
console.log("not replacing as variation");
}
if(!_192&&_186.prev){
_186.prev.next=_187;
}
if(_186.next){
_186.next.prev=_187;
}
_187.vars=_186.vars;
_187.numVars=_186.numVars;
this.reconnectNextNodeVariations(_187,_186.next);
if(this.firstMove==_186){
this.firstMove=_187;
}
this.moveArray[_187.index]=_187;
}else{
if(clog){
console.log("replacing as variation");
}
if(_186.numVars==0){
_186.vars=new Array();
}
_186.vars[_186.numVars++]=_187;
_186.atEnd=0;
_187.next=null;
var _193=this.createMoveFromString("i1i2");
_187.next=_193;
_193.prev=_187;
_193.next=null;
_193.atEnd=1;
_193.moveNum=_187.moveNum+1;
_193.ravLevel=_187.ravLevel;
_193.endNode=true;
}
}
if(_189){
this.replaceIntoMoveDisplay(_186,_187,_188,_18a,_18b);
}
};
Board.prototype.setCurrentMove=function(move,_195){
if(this.currentMove!=null&&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 _196=this.boardName+"-m"+this.currentMove.prev.index;
if(clog){
console.log("setCurrentMove attempted highlight of id:"+_196+" for move:"+move.output());
}
var span=YAHOO.util.Dom.get(_196);
if(span){
var cls=span.className;
YAHOO.util.Dom.addClass(span,"ct-board-move-current");
if(this.autoScrollMoves){
if(cls.indexOf("ct-board-move-variation")==-1){
var _199=this.movesDisplay.getMovesDisplay();
if(_199){
var y=YAHOO.util.Dom.getY(span)-YAHOO.util.Dom.getY(_199);
var _19b=new YAHOO.util.Scroll(_199,{scroll:{by:[0,y]}},this.moveAnimationLength,YAHOO.util.Easing.easeOut);
_19b.animate();
}
}
}
}
}else{
if(move==null){
if(clog){
console.log("attempted to set current move on null node");
}
}
}
if(!_195){
this.setForwardBack();
}
};
Board.prototype.getCastlingString=function(_19c){
var _19d=_js("None");
if(this.canCastleKingSide[_19c]){
_19d="O-O";
}
if(this.canCastleQueenSide[_19c]){
if(_19d=="None"){
_19d="O-O-O";
}else{
_19d+=",O-O-O";
}
}
return _19d;
};
Board.prototype.updateToPlay=function(){
var _19e=YAHOO.util.Dom.get("toPlay");
if(_19e==null){
return;
}
if(this.toMove==ChessPiece.WHITE){
_19e.src="/images/whiteknight"+this.getVersString()+".gif";
_19e.alt=_js("White to play");
}else{
_19e.src="/images/blackknight"+this.getVersString()+".gif";
_19e.alt=_js("Black to play");
}
var _19f=YAHOO.util.Dom.get("fenStatus");
if(_19f){
var _1a0=this.getCastlingString(ChessPiece.BLACK);
var _1a1=this.getCastlingString(ChessPiece.WHITE);
var s="<div><span>"+_js("White Castling: ")+"</span><span>"+_1a1+"</span></div>"+"<div><span>"+_js("Black Castling: ")+"</span><span>"+_1a0+"</span></div>";
_19f.innerHTML=s;
}
};
Board.prototype.getBoardDiv=function(){
if(!this.boardDiv){
this.boardDiv=YAHOO.util.Dom.get("ctb-"+this.boardName);
}
return this.boardDiv;
};
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 _1a3=YAHOO.util.Dom.get(this.boardName+"-fileLabels");
var _1a4=YAHOO.util.Dom.get(this.boardName+"-rankLabels");
if(!_1a3||!_1a4){
return;
}
_1a4.innerHTML="";
_1a3.innerHTML="";
var _1a5=YAHOO.util.Dom.get(this.boardName+"-boardBorder");
if(!this.showCoordinates){
YAHOO.util.Dom.setStyle(_1a3,"display","none");
YAHOO.util.Dom.setStyle(_1a4,"display","none");
var _1a6=0;
YAHOO.util.Dom.setStyle(_1a5,"width",(this.pieceSize*8+_1a6)+"px");
YAHOO.util.Dom.setStyle(_1a5,"height",(this.pieceSize*8+_1a6)+"px");
return;
}
YAHOO.util.Dom.setStyle(_1a3,"display","block");
YAHOO.util.Dom.setStyle(_1a4,"display","block");
var _1a6=15;
var _1a7=0;
if(check_bad_msie()){
_1a7=4;
}
YAHOO.util.Dom.setStyle(_1a5,"width",(this.pieceSize*8+_1a6+_1a7)+"px");
YAHOO.util.Dom.setStyle(_1a5,"height",(this.pieceSize*8+_1a6)+"px");
this.coordinatesShown=true;
for(var i=0;i<8;i++){
var _1a9=document.createElement("div");
YAHOO.util.Dom.setStyle(_1a9,"height",this.pieceSize+"px");
YAHOO.util.Dom.setStyle(_1a9,"width","15px");
YAHOO.util.Dom.setStyle(_1a9,"text-align","center");
YAHOO.util.Dom.setStyle(_1a9,"line-height",this.pieceSize+"px");
if(this.isFlipped){
_1a9.innerHTML=""+(i+1);
}else{
_1a9.innerHTML=""+9-(i+1);
}
_1a4.appendChild(_1a9);
}
for(var i=0;i<9;i++){
var _1aa=document.createElement("span");
YAHOO.util.Dom.setStyle(_1aa,"float","left");
YAHOO.util.Dom.setStyle(_1aa,"height","15px");
if(i==0){
YAHOO.util.Dom.setStyle(_1aa,"width","15px");
YAHOO.util.Dom.setStyle(_1aa,"clear","both");
YAHOO.util.Dom.setStyle(_1aa,"margin-top","-5px");
if(_1a7){
YAHOO.util.Dom.setStyle(_1aa,"margin-left","-3px");
}else{
YAHOO.util.Dom.setStyle(_1aa,"margin-left","-2px");
}
var _1ab="";
if(this.isFlipped){
_1ab="whiteblack-flipper.png";
}else{
_1ab="blackwhite-flipper.png";
}
_1aa.innerHTML="<span><img id=\""+this.boardName+"-flipper\" title=\""+_js("Flip Board")+"\" src=\""+this.boardImagePath+"/images/"+_1ab+"\"/></span>";
YAHOO.util.Event.addListener(this.boardName+"-flipper","click",this.flipBoard,this,true);
}else{
YAHOO.util.Dom.setStyle(_1aa,"width",this.pieceSize+"px");
YAHOO.util.Dom.setStyle(_1aa,"text-align","center");
if(this.isFlipped){
_1aa.innerHTML=_js(Move.columnToChar(8-(i)));
}else{
_1aa.innerHTML=_js(Move.columnToChar((i-1)));
}
}
_1a3.appendChild(_1aa);
}
var _1ac=YAHOO.util.Dom.get(this.boardName+"-flipper");
if(_1ac){
fix_ie_png(_1ac);
}
};
Board.prototype.createBoardUI=function(){
var _1ad=this.boardName+"-container";
var _1ae=YAHOO.util.Dom.get(_1ad);
if(_1ae==null){
alert("Could not find board container:"+_1ad);
return;
}
YAHOO.util.Dom.addClass(_1ae,"ct-board-container");
this.boardDiv=null;
var _1af=document.createElement("div");
_1af.id=this.boardName+"-boardBorder";
YAHOO.util.Dom.addClass(_1af,"ct-board-border"+this.squareColorClass);
var _1b0=0;
if(this.showCoordinates){
_1b0=15;
}
YAHOO.util.Dom.setStyle(_1af,"width",(this.pieceSize*8+_1b0)+"px");
YAHOO.util.Dom.setStyle(_1af,"height",(this.pieceSize*8+_1b0)+"px");
var _1b1=document.createElement("div");
YAHOO.util.Dom.setStyle(_1b1,"float","left");
_1b1.id=this.boardName+"-rankLabels";
_1af.appendChild(_1b1);
var _1b2=document.createElement("div");
YAHOO.util.Dom.addClass(_1b2,"ct-board");
YAHOO.util.Dom.setStyle(_1b2,"width",(this.pieceSize*8)+"px");
YAHOO.util.Dom.setStyle(_1b2,"height",(this.pieceSize*8)+"px");
_1b2.id="ctb-"+this.boardName;
var _1b3="ct-white-square"+this.squareColorClass;
for(var i=7;i>=0;i--){
var _1b1=document.createElement("div");
for(var j=0;j<8;j++){
var _1b6=document.createElement("div");
_1b6.id=this.boardName+"-s"+j+""+i;
this[_1b6.id]=_1b6;
YAHOO.util.Dom.addClass(_1b6,_1b3);
YAHOO.util.Dom.setStyle(_1b6,"width",this.pieceSize+"px");
YAHOO.util.Dom.setStyle(_1b6,"height",this.pieceSize+"px");
var _1b7=(((j+1)*(i+1))%19/19*100);
var _1b8=((65-((j+1)*(i+1)))%19/19*100);
YAHOO.util.Dom.setStyle(_1b6,"background-position",_1b7+"% "+_1b8+"%");
_1b1.appendChild(_1b6);
_1b3=(_1b3=="ct-black-square"+this.squareColorClass)?"ct-white-square"+this.squareColorClass:"ct-black-square"+this.squareColorClass;
}
_1b3=(_1b3=="ct-black-square"+this.squareColorClass)?"ct-white-square"+this.squareColorClass:"ct-black-square"+this.squareColorClass;
_1b2.appendChild(_1b1);
}
var _1b9=document.createElement("div");
_1b9.id=this.boardName+"-fileLabels";
_1af.appendChild(_1b2);
_1af.appendChild(_1b9);
_1ae.appendChild(_1af);
this.createBoardCoords();
var _1ba=YAHOO.util.Dom.get(this.boardName+"-ct-nav-container");
if(!_1ba){
_1ba=document.createElement("div");
}else{
_1ba.innerHTML="";
}
_1ba.id=this.boardName+"-ct-nav-container";
if(!this.dontOutputNavButtons){
var _1bb="";
if(!this.problem||!this.problem.isEndgame){
_1bb="<span id=\"playStopSpan\"><img class=\"ct-end\" id=\""+this.boardName+"-end\" src=\""+this.boardImagePath+"/images/resultset_last"+this.getVersString()+".gif\" alt=\""+_js("End position")+"\" title=\""+_js("Go to final position")+"\"/>"+"<img class=\"ct-play\" id=\""+this.boardName+"-play\" src=\""+this.boardImagePath+"/images/control_play_blue"+this.getVersString()+".gif\" alt=\""+_js("Play moves")+"\" title=\""+_js("Play sequence of moves")+"\"/>"+"<img class=\"ct-stop\" id=\""+this.boardName+"-stop\" src=\""+this.boardImagePath+"/images/control_stop_blue"+this.getVersString()+".gif\" alt=\""+_js("Stop playing")+"\" title=\""+_js("Stop playing move sequence")+"\"/></span>";
}
var _1bc="<div class=\"ct-nav-buttons\" id=\""+this.boardName+"-navButtons\"><span id=\"nav-buttons-only\">";
_1bc+="<img class=\"ct-start\" id=\""+this.boardName+"-start\" src=\""+this.boardImagePath+"/images/resultset_first"+this.getVersString()+".gif\" alt=\""+_js("Start position")+"\" title=\""+_js("Go to starting position")+"\"/>"+"<img class=\"ct-back\" id=\""+this.boardName+"-back\" src=\""+this.boardImagePath+"/images/resultset_previous"+this.getVersString()+".gif\" alt=\""+_js("Previous Move")+"\" title=\""+_js("Go back a move")+"\"/>"+"<img class=\"ct-forward\" id=\""+this.boardName+"-forward\" src=\""+this.boardImagePath+"/images/resultset_next"+this.getVersString()+".gif\" alt=\""+_js("Next Move")+"\" title=\""+_js("Go forward a move")+"\"/>"+_1bb;
_1bc+="</span></div>";
_1ba.innerHTML=_1bc;
}
_1ae.appendChild(_1ba);
var body=YAHOO.util.Dom.get("body");
if(body){
YAHOO.util.Dom.setStyle(body,"min-width",((this.pieceSize*8+_1b0)+300+250)+"px");
}
};
Board.prototype.getPieceDiv=function(){
var _1be=this.getBoardDiv();
var _1bf=document.createElement("div");
this.availPieceDivs[this.uptoId]=_1bf;
this.availIds[this.uptoId]=YAHOO.util.Dom.generateId(_1bf);
YAHOO.util.Dom.setStyle(_1bf,"visibility","hidden");
_1be.appendChild(_1bf);
this.uptoId++;
return _1bf;
};
Board.prototype.flipToMove=function(_1c0){
return (_1c0=="w")?"b":"w";
};
Board.prototype.pieceCharToPieceNum=function(_1c1){
var _1c2;
switch(_1c1){
case "K":
_1c2=ChessPiece.KING;
break;
case "Q":
_1c2=ChessPiece.QUEEN;
break;
case "R":
_1c2=ChessPiece.ROOK;
break;
case "B":
_1c2=ChessPiece.BISHOP;
break;
case "N":
_1c2=ChessPiece.KNIGHT;
break;
case "P":
_1c2=ChessPiece.PAWN;
break;
}
return _1c2;
};
Board.prototype.pieceTypeToChar=function(_1c3){
switch(_1c3){
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(_1c4,_1c5,_1c6,_1c7){
if(_1c4+2==_1c6&&_1c5+1==_1c7){
return true;
}
if(_1c4+2==_1c6&&_1c5-1==_1c7){
return true;
}
if(_1c4-2==_1c6&&_1c5+1==_1c7){
return true;
}
if(_1c4-2==_1c6&&_1c5-1==_1c7){
return true;
}
if(_1c4+1==_1c6&&_1c5+2==_1c7){
return true;
}
if(_1c4-1==_1c6&&_1c5+2==_1c7){
return true;
}
if(_1c4+1==_1c6&&_1c5-2==_1c7){
return true;
}
if(_1c4-1==_1c6&&_1c5-2==_1c7){
return true;
}
return false;
};
Board.prototype.canMovePawn=function(_1c8,_1c9,_1ca,_1cb,_1cc){
var _1cd=this.boardPieces[_1ca][_1cb];
var _1ce=this.boardPieces[_1c8][_1c9];
if(_1cc){
var _1cf=this.boardPieces[_1cc.toColumn][_1cc.toRow];
if(_1cf.piece==ChessPiece.PAWN){
if(_1cf.colour==ChessPiece.WHITE){
if(_1cc.fromRow==1&&_1cc.toRow==3){
if(_1ca==_1cc.fromColumn&&_1c9==3&&_1cb==2&&(_1c8==_1ca+1||_1c8==_1ca-1)){
return true;
}
}
}else{
if(_1cc.fromRow==6&&_1cc.toRow==4){
if(_1ca==_1cc.fromColumn&&_1c9==4&&_1cb==5&&(_1c8==_1ca+1||_1c8==_1ca-1)){
return true;
}
}
}
}
}
if(_1cd){
if(_1ce.colour==ChessPiece.WHITE){
if((_1c8==_1ca+1||_1c8==_1ca-1)&&(_1c9==_1cb-1)){
return true;
}
}else{
if((_1c8==_1ca+1||_1c8==_1ca-1)&&(_1c9==_1cb+1)){
return true;
}
}
}else{
if(_1c8==_1ca){
if(_1ce.colour==ChessPiece.WHITE){
if(_1c9==1){
if(_1cb==2){
return true;
}else{
if(_1cb==3&&this.boardPieces[_1ca][2]==null){
return true;
}
}
}else{
if(_1c9+1==_1cb){
return true;
}
}
}else{
if(_1c9==6){
if(_1cb==5){
return true;
}else{
if(_1cb==4&&this.boardPieces[_1ca][5]==null){
return true;
}
}
}else{
if(_1c9-1==_1cb){
return true;
}
}
}
}
}
return false;
};
Board.prototype.canMoveStraight=function(_1d0,_1d1,_1d2,_1d3,_1d4,_1d5){
var _1d6=_1d0;
var _1d7=_1d1;
var _1d8=0;
var _1d9=0;
if(_1d2>_1d0){
_1d8=1;
}else{
if(_1d2<_1d0){
_1d8=-1;
}
}
if(_1d3>_1d1){
_1d9=1;
}else{
if(_1d3<_1d1){
_1d9=-1;
}
}
if(clog){
console.log("deltaRow:"+_1d9+" deltaCol:"+_1d8+" fromCol:"+_1d0+" fromRow:"+_1d1+" toCol:"+_1d2+" toRow:"+_1d3);
}
if(_1d4==ChessPiece.ROOK&&(_1d8!=0&&_1d9!=0)){
return false;
}
if(_1d4==ChessPiece.BISHOP&&(_1d8==0||_1d9==0)){
return false;
}
var _1da=0;
while(true){
_1da++;
_1d0+=_1d8;
_1d1+=_1d9;
if(_1d4==ChessPiece.KING&&_1da>1){
if(clog){
console.log("king count:"+_1da+" toCol:"+_1d2+" toRow:"+_1d3);
}
if(_1da!=2){
return false;
}
if(_1d9!=0){
return false;
}
if(!(_1d2==6||_1d2==2)){
return false;
}
if(_1d2==2){
if(this.boardPieces[1][_1d1]||this.boardPieces[2][_1d1]||this.boardPieces[3][_1d1]){
return false;
}
if(!this.canCastleQueenSide[_1d5.colour]){
return false;
}
}else{
if(_1d2==6){
if(this.boardPieces[5][_1d1]||this.boardPieces[6][_1d1]){
if(clog){
console.log("king can't castle intervening piece");
}
return false;
}
if(!this.canCastleKingSide[_1d5.colour]){
if(clog){
console.log("king can't castle king side (made previously invalid) colour:"+_1d5.colour);
}
return false;
}
}else{
if(clog){
console.log("king not in col 2 or 6");
}
return false;
}
}
var _1db="";
_1db+=Move.columnToChar(_1d6);
_1db+=String.fromCharCode("1".charCodeAt(0)+_1d7);
_1db+=Move.columnToChar((_1d6+_1d8));
_1db+=String.fromCharCode("1".charCodeAt(0)+(_1d7+_1d9));
var move=this.createMoveFromString(_1db);
var _1dd=this.boardPieces;
var _1de=this.toMove;
var _1df=this.saveCastling();
this.boardPieces=this.copyBoardPieces(true);
this.makeMove(move,this.boardPieces[_1d6][_1d7],false,this.moveAnimationLength,false,false);
this.restoreCastling(_1df);
kingSafe=this.isKingSafe(_1d5.colour,move);
boardPool.putObject(this.boardPieces);
this.boardPieces=_1dd;
_1dd.count--;
this.toMove=_1de;
if(clog){
console.log("kingSafe1:"+kingSafe);
}
if(!kingSafe){
return false;
}
var _1db="";
_1db+=Move.columnToChar(_1d6);
_1db+=String.fromCharCode("1".charCodeAt(0)+_1d7);
_1db+=Move.columnToChar(_1d6);
_1db+=String.fromCharCode("1".charCodeAt(0)+_1d7);
var move=this.createMoveFromString(_1db);
var _1dd=this.boardPieces;
var _1de=this.toMove;
var _1df=this.saveCastling();
this.boardPieces=this.copyBoardPieces(true);
this.makeMove(move,this.boardPieces[_1d6][_1d7],false,this.moveAnimationLength,false,false);
this.restoreCastling(_1df);
kingSafe=this.isKingSafe(_1d5.colour,move);
boardPool.putObject(this.boardPieces);
this.boardPieces=_1dd;
_1dd.count--;
this.toMove=_1de;
if(clog){
console.log("kingSafe2:"+kingSafe);
}
if(!kingSafe){
return false;
}
}
if(_1d0==_1d2&&_1d1==_1d3){
return true;
}
if(_1d0<0||_1d0>7||_1d1<0||_1d1>7){
return false;
}
if(this.boardPieces[_1d0][_1d1]!=null){
return false;
}
}
};
Board.prototype.canMove=function(_1e0,_1e1,_1e2,_1e3,_1e4){
var _1e5=_1e0.column;
var _1e6=_1e0.row;
if(_1e1>7||_1e1<0||_1e2>7||_1e2<0){
if(clog){
console.log("can't move coz out of bounds");
}
return false;
}
var _1e7=this.boardPieces[_1e1][_1e2];
var _1e8=this.boardPieces[_1e5][_1e6];
if(_1e8==null){
return false;
}
if(_1e7&&_1e7.colour==_1e8.colour){
return false;
}
var _1e9=false;
if(_1e0.piece==ChessPiece.PAWN){
_1e9=this.canMovePawn(_1e5,_1e6,_1e1,_1e2,_1e3);
}else{
if(_1e0.piece==ChessPiece.KNIGHT){
_1e9=this.canMoveKnight(_1e5,_1e6,_1e1,_1e2);
}else{
_1e9=this.canMoveStraight(_1e5,_1e6,_1e1,_1e2,_1e0.piece,_1e0);
}
}
if(clog){
console.log("moveOk:"+_1e9);
}
var _1ea=true;
if(_1e9&&_1e4){
var _1eb="";
_1eb+=Move.columnToChar(_1e5);
_1eb+=String.fromCharCode("1".charCodeAt(0)+_1e6);
_1eb+=Move.columnToChar(_1e1);
_1eb+=String.fromCharCode("1".charCodeAt(0)+_1e2);
var move=this.createMoveFromString(_1eb);
var _1ed=this.boardPieces;
var _1ee=this.toMove;
var _1ef=this.saveCastling();
this.boardPieces=this.copyBoardPieces(true);
if(clog){
console.log("in canMove about to make move:"+move.output()+" fromCol:"+_1e5+" fromRow:"+_1e6);
}
this.makeMove(move,this.boardPieces[_1e5][_1e6],false,this.moveAnimationLength,false,false);
this.restoreCastling(_1ef);
_1ea=this.isKingSafe(_1e0.colour,move);
boardPool.putObject(this.boardPieces);
this.boardPieces=_1ed;
_1ed.count--;
this.toMove=_1ee;
}
return _1e9&&_1ea;
};
Board.prototype.isKingMated=function(_1f0,_1f1){
var _1f2=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==_1f0){
_1f2=bp;
break;
}
}
}
var _1f6=[[1,0],[1,1],[1,-1],[-1,0],[-1,1],[-1,-1],[0,1],[0,-1],[2,0],[-2,0]];
var bp=_1f2;
for(var k=0;k<_1f6.length;k++){
if(this.canMove(bp,bp.column+_1f6[k][0],bp.row+_1f6[k][1],_1f1,true)){
return false;
}
}
var _1f8=this.getCandidateMoves(_1f0,_1f1,true,true);
if(_1f8.length>0){
return false;
}
return true;
};
Board.prototype.getCandidateMoves=function(_1f9,_1fa,_1fb,_1fc){
var _1fd=new Array();
for(var i=0;i<8;i++){
for(var j=0;j<8;j++){
var bp=this.boardPieces[i][j];
var _201=[];
if(!bp||bp.colour!=_1f9){
continue;
}
switch(bp.piece){
case ChessPiece.KING:
if(_1fc){
continue;
}
_201=[[1,0],[1,1],[1,-1],[-1,0],[-1,1],[-1,-1],[0,1],[0,-1],[2,0],[-2,0]];
break;
case ChessPiece.KNIGHT:
_201=[[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++){
_201.push([1+k,1+k]);
_201.push([1+k,-1-k]);
_201.push([-1-k,1+k]);
_201.push([-1-k,-1-k]);
}
break;
case ChessPiece.QUEEN:
for(var k=0;k<8;k++){
_201.push([1+k,0]);
_201.push([1+k,1+k]);
_201.push([1+k,-1-k]);
_201.push([-1-k,0]);
_201.push([-1-k,1+k]);
_201.push([-1-k,-1-k]);
_201.push([0,-1-k]);
_201.push([0,1+k]);
}
break;
case ChessPiece.ROOK:
for(var k=0;k<8;k++){
_201.push([1+k,0]);
_201.push([-1-k,0]);
_201.push([0,-1-k]);
_201.push([0,1+k]);
}
break;
case ChessPiece.PAWN:
_201=[[0,1],[0,-1],[1,1],[1,-1],[-1,1],[-1,-1]];
break;
}
for(var k=0;k<_201.length;k++){
if(this.canMove(bp,bp.column+_201[k][0],bp.row+_201[k][1],_1fa,true)){
_1fd.push(new Move(bp.column,bp.row,bp.column+_201[k][0],bp.row+_201[k][1]));
if(_1fb){
return _1fd;
}
}
}
}
}
return _1fd;
};
Board.prototype.isKingSafe=function(_203,_204){
var _205=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==_203){
_205=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!=_203){
if(this.canMove(bp,_205.column,_205.row,_204,false)){
return false;
}
}
}
}
return true;
};
Board.prototype.cloneBoard=function(){
var _209=new Board();
_209.boardPieces=this.copyBoardPieces(true);
_209.moveArray=this.copyMoveArray();
_209.canCastleQueenSide=this.copyCastleQueenSide();
_209.canCastleKingSide=this.copyCastleKingSide();
_209.toMove=this.toMove;
_209.opponentColour=this.opponentColour;
_209.isFlipped=this.isFlipped;
_209.isUserFlipped=this.isUserFlipped;
_209.ignoreFlipping=this.ignoreFlipping;
_209.reverseFlip=this.reverseFlip;
_209.moveAnimationLength=this.moveAnimationLength;
return _209;
};
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(){
var _20a=new Array();
if(this.moveArray.length>0){
_20a=this.moveArray.slice(0);
}
return _20a;
};
Board.prototype.copyBoardPieces=function(_20b){
var _20c=Board.createBoardArray();
for(var i=0;i<8;i++){
for(var j=0;j<8;j++){
if(this.boardPieces[i][j]!=null){
if(_20b){
_20c[i][j]=this.boardPieces[i][j].makeLightWeight();
}else{
_20c[i][j]=this.boardPieces[i][j].copyPiece();
}
}else{
_20c[i][j]=null;
}
}
}
return _20c;
};
Board.prototype.createPiece=function(_20f,_210,_211){
if(_211){
return new LightweightChessPiece(null,_20f,_210,this);
}else{
return new ChessPiece(this.getPieceDiv(),_20f,_210,this);
}
};
Board.prototype.restoreCastling=function(_212){
this.canCastleKingSide=_212.kingSide;
this.canCastleQueenSide=_212.queenSide;
};
Board.prototype.saveCastling=function(){
var _213=[this.canCastleQueenSide[0],this.canCastleQueenSide[1]];
var _214=[this.canCastleKingSide[0],this.canCastleKingSide[1]];
return {queenSide:_213,kingSide:_214};
};
Board.prototype.setupFromFen=function(fen,_216,flip,_218){
this.settingUpPosition=true;
var ua=navigator.userAgent.toLowerCase(),_21a=(ua.indexOf("opera")>-1),_21b=(ua.indexOf("safari")>-1),_21c=(!_21a&&!_21b&&ua.indexOf("gecko")>-1),isIE=(!_21a&&ua.indexOf("msie")>-1);
var _21e=fen.split(" ");
var _21f=_21e[0].split("/");
var _220=0;
var row=8;
this.uptoId=0;
this.board_xy=null;
var _222=_21e[2];
this.canCastleQueenSide=[false,false];
this.canCastleKingSide=[false,false];
if(_222!="-"){
if(_222.indexOf("K")>=0){
this.canCastleKingSide[ChessPiece.WHITE]=true;
}
if(_222.indexOf("Q")>=0){
this.canCastleQueenSide[ChessPiece.WHITE]=true;
}
if(_222.indexOf("k")>=0){
this.canCastleKingSide[ChessPiece.BLACK]=true;
}
if(_222.indexOf("q")>=0){
this.canCastleQueenSide[ChessPiece.BLACK]=true;
}
}
if(_21e[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(_216){
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=_21f[i];
row--;
_220=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 _229=this.boardPieces[_220][row];
this.boardPieces[_220][row]=null;
_220++;
}
}else{
var _22a=(c+"").toLowerCase().charAt(0);
var _22b=ChessPiece.WHITE;
if(_22a==c){
_22b=ChessPiece.BLACK;
}
var cp;
switch(_22a){
case "k":
cp=this.createPiece(_22b,ChessPiece.KING,_218);
break;
case "q":
cp=this.createPiece(_22b,ChessPiece.QUEEN,_218);
break;
case "r":
cp=this.createPiece(_22b,ChessPiece.ROOK,_218);
break;
case "b":
cp=this.createPiece(_22b,ChessPiece.BISHOP,_218);
break;
case "n":
cp=this.createPiece(_22b,ChessPiece.KNIGHT,_218);
break;
case "p":
cp=this.createPiece(_22b,ChessPiece.PAWN,_218);
break;
default:
}
if(_21c||_21a){
cp.setPosition(_220,row,false,null,this.moveAnimationLength);
cp.setVisible(true);
}
this.boardPieces[_220][row]=cp;
this.pieces[this.uptoPiece]=cp;
this.pieces[this.uptoPiece].column=_220;
this.pieces[this.uptoPiece].row=row;
this.uptoPiece++;
_220++;
}
}
}
if(!_21c){
for(var i=0;i<this.uptoPiece;i++){
this.pieces[i].setPosition(this.pieces[i].column,this.pieces[i].row,false,null,0);
}
}
if(!_218){
for(var i=0;i<this.uptoPiece;i++){
this.pieces[i].setVisible(true);
}
}
this.createBoardCoords();
this.settingUpPosition=false;
};
Board.prototype.resetMoveListScrollPosition=function(){
var _22d=this.movesDisplay.getMovesDisplay();
if(_22d){
var _22e=new YAHOO.util.Scroll(_22d,{scroll:{to:[0,0]}},0);
_22e.animate();
}
};
Board.prototype.changePieceSet=function(_22f,_230){
var ua=navigator.userAgent.toLowerCase();
var _232=(ua.indexOf("opera")>-1);
if(!this.showedIE6Warning){
alert(_js("Depending on your browser you may need to reload the\n page for piece size changes to properly take effect."));
}
this.showedIE6Warning=true;
if(check_bad_msie()){
if(!this.showedIE6Warning){
alert(_js("Internet Explorer version 6 does not support dynamic piece size changes.\n Please reload page to view new settings."));
}
this.showedIE6Warning=true;
return;
}
var _233=this.pieceSize;
this.pieceSet=_22f;
this.pieceSize=_230;
var _234=YAHOO.util.Dom.get(this.boardName+"-boardBorder");
var _235=0;
if(this.showCoordinates){
_235=15;
}
_234.className="";
YAHOO.util.Dom.addClass(_234,"ct-board-border"+this.squareColorClass);
YAHOO.util.Dom.setStyle(_234,"width",(this.pieceSize*8+_235)+"px");
YAHOO.util.Dom.setStyle(_234,"height",(this.pieceSize*8+_235)+"px");
var _236=YAHOO.util.Dom.get("ctb-"+this.boardName);
YAHOO.util.Dom.setStyle(_236,"width",(this.pieceSize*8)+"px");
YAHOO.util.Dom.setStyle(_236,"height",(this.pieceSize*8)+"px");
var _237="ct-white-square"+this.squareColorClass;
for(var i=7;i>=0;i--){
for(var j=0;j<8;j++){
var _23a=this[this.boardName+"-s"+j+""+i];
_23a.className="";
YAHOO.util.Dom.addClass(_23a,_237);
YAHOO.util.Dom.setStyle(_23a,"width",this.pieceSize+"px");
YAHOO.util.Dom.setStyle(_23a,"height",this.pieceSize+"px");
var _23b=(((j+1)*(i+1))%19/19*100);
var _23c=((65-((j+1)*(i+1)))%19/19*100);
YAHOO.util.Dom.setStyle(_23a,"background-position",_23b+"% "+_23c+"%");
_237=(_237=="ct-black-square"+this.squareColorClass)?"ct-white-square"+this.squareColorClass:"ct-black-square"+this.squareColorClass;
}
_237=(_237=="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 _23e=cp.div;
_23e.innerHTML="<img src=\""+cp.icon+"\"/>";
var img=_23e.firstChild;
if(!_232){
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 _23e=cp.div;
_23e.innerHTML="<img src=\""+cp.icon+"\"/>";
YAHOO.util.Dom.setStyle([cp.div],"position","relative");
var img=_23e.firstChild;
if(!_232){
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;
}
}
var body=YAHOO.util.Dom.get("body");
if(body){
YAHOO.util.Dom.setStyle(body,"min-width",((this.pieceSize*8+_235)+300+250)+"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 _244=false;
if(this.tactics&&this.tactics.problemActive){
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(!_244){
this.problem.processEndgame("",true);
}
this.toggleToMove();
this.updateToPlay();
}else{
if(clog){
console.log("forwarding move:"+move.output());
}
var _245=null;
piece=this.boardPieces[move.fromColumn][move.fromRow];
if(move.promotion){
_245=move.promotion;
piece.prePromotionColumn=null;
piece.prePromotionRow=null;
}
this.updatePiece(piece,move.toColumn,move.toRow,true,true,false,_245,true);
this.toggleToMove();
this.updateToPlay();
var _246=this.currentMove;
if(this.problem&&_246){
var _247=false;
if(_246.bestMoves){
if(_246.bestMoves.length>0){
var bm=_246.bestMoves[0];
if(bm.score!="draw"&&bm.score==0){
if(clog){
console.log("move is mate");
}
_247=true;
}
}else{
_247=true;
}
}
if(_247&&_246.endNode){
this.problem.clearBestMoves();
}else{
this.problem.showBestMoves(_246,_246.bestMoves,_246.correctMove,_246.wrongMove);
}
}
}
}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(document,"keydown",function(e){
var _24a=(e.target)?e.target:e.srcElement;
if(_24a.form){
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);
};
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 _250=YAHOO.util.Dom.get(this.boardName+"-s"+this.lastFromColumn+""+this.lastFromRow);
var _251=YAHOO.util.Dom.get(this.boardName+"-s"+this.lastToColumn+""+this.lastToRow);
}else{
var _250=YAHOO.util.Dom.get(this.boardName+"-s"+(7-this.lastFromColumn)+""+(7-this.lastFromRow));
var _251=YAHOO.util.Dom.get(this.boardName+"-s"+(7-this.lastToColumn)+""+(7-this.lastToRow));
}
this.updateFromTo(_250,_251,this.lastFromRow,this.lastFromColumn,this.lastToRow,this.lastToColumn);
}
};
Board.prototype.gotoMoveIndex=function(_252,_253){
var _254=this.boardName+"-piecestaken";
var _255=YAHOO.util.Dom.get(_254);
if(_255){
_255.innerHTML="";
}
if(_252==-1){
var flip=false;
if(this.prev_move){
flip=true;
}
this.setupFromFen(this.startFen,flip,false,false);
if(this.prev_move){
this.makeMove(this.prev_move,this.boardPieces[this.prev_move.fromColumn][this.prev_move.fromRow],true,this.moveAnimationLength,true,true);
this.updateToPlay();
}
if(this.moveArray&&this.moveArray.length>0){
this.setCurrentMove(this.moveArray[0],_253);
}else{
this.setCurrentMove(this.firstMove,_253);
}
if(!_253){
this.setForwardBack();
}
return;
}
var _257=new Array();
var move=this.moveArray[_252];
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.next:"+move.prev.output());
}
}
var _259=0;
if(move.next!=null){
this.setCurrentMove(move.next,_253);
}else{
if(clog){
console.log("move next null with move:"+move.output());
}
}
while(move!=null){
_257[_259++]=move;
move=move.prev;
}
var flip=false;
if(this.prev_move){
flip=true;
}
this.setupFromFen(this.startFen,flip,false,true);
if(this.prev_move){
if(clog){
console.log("gotomoveindex prev_move:"+this.prev_move.output());
}
this.makeMove(this.prev_move,this.boardPieces[this.prev_move.fromColumn][this.prev_move.fromRow],false,this.moveAnimationLength,true,true);
this.updateToPlay();
}
for(var i=_259-1;i>=1;i--){
var move=_257[i];
this.makeMove(move,this.boardPieces[move.fromColumn][move.fromRow],false,this.moveAnimationLength,true,true);
this.toggleToMove();
}
if(!_253){
this.convertPiecesFromLightWeight(_252);
}
var move=_257[0];
this.makeMove(move,this.boardPieces[move.fromColumn][move.fromRow],true,this.moveAnimationLength,true,true);
this.toggleToMove();
this.updateToPlay();
if(!_253){
this.setForwardBack();
}
};
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(this.lastMoveIndex);
};
Board.prototype.playMove=function(self){
if(!self.keepPlayingMoves||!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 _25f=".vers"+SITE_VERSION;
if(!this.addVersion){
_25f="";
}
return _25f;
};
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.backMove=function(e){
if(this.blockFowardBack||this.deferredBlockForwardBack){
return;
}
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);
var _264=false;
if(piece.piece==ChessPiece.KING&&Math.abs(move.fromColumn-move.toColumn)>1){
_264=true;
}
if(takenPiece&&!_264){
this.board_xy=null;
var _265=move.toColumn;
var _266=move.toRow;
if(piece.piece==ChessPiece.PAWN&&move.fromColumn!=move.toColumn&&takenPiece.enPassant){
_266=move.fromRow;
this.boardPieces[move.toColumn][move.toRow]=null;
}
takenPiece.setPosition(_265,_266,false,null,this.moveAnimationLength);
this.boardPieces[_265][_266]=takenPiece;
move.taken=null;
this.processTaken(takenPiece,false);
}else{
this.boardPieces[move.toColumn][move.toRow]=null;
}
if(_264){
var _267=move.toRow;
var _268;
var _269;
if(move.fromColumn>move.toColumn){
_268=0;
_269=3;
}else{
_268=7;
_269=5;
}
var _26a=this.boardPieces[_269][_267];
_26a.setPosition(_268,_267,true,null,this.moveAnimationLength);
this.boardPieces[_268][_267]=_26a;
}
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");
}
}
}
if(this.problem&&this.problem.isEndgame){
if(this.currentMove){
if(this.currentMove.bestMoves){
var cm=this.currentMove;
this.problem.showBestMoves(cm,cm.bestMoves,cm.correctMove,cm.wrongMove);
}
}else{
if(this.problem.initialBestMoves){
this.problem.showBestMoves(this.currentMove,this.problem.initialBestMoves,null,null);
}
}
}
this.setCurrentMove(move);
this.setForwardBack();
}
this.blockForwardBack=false;
};
Board.prototype.processTaken=function(_26c,_26d){
var _26e=this.boardName+"-piecestaken";
var _26f=YAHOO.util.Dom.get(_26e);
if(_26f){
if(_26d){
var _270=get_image_str(ChessPiece.pieceIconNames[_26c.colour][_26c.piece],this.boardImagePath,this.pieceSet,this.pieceTakenSize,this.addVersion);
_26f.innerHTML=_26f.innerHTML+"<img src=\""+_270+"\"/>";
}else{
var _271=_26f.innerHTML.split("<");
_26f.innerHTML="";
for(var i=1;i<_271.length-1;i++){
_26f.innerHTML=_26f.innerHTML+"<"+_271[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();

