/* Copyright 2007-2010 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+")");
};

CTSound=function(_1){
this.sounds=[];
this.soundPath=_1.soundPath;
var _2=!!((myAudioTag=document.createElement("audio")).canPlayType);
var _3=null;
if(typeof Audio!="undefined"){
_3=new Audio("");
}
this.haveAudio=_3&&!!(_3.canPlayType);
if(this.haveAudio){
this.canPlayOgg=(("no"!=_3.canPlayType("audio/ogg"))&&(""!=_3.canPlayType("audio/ogg")));
this.canPlayMp3=(("no"!=_3.canPlayType("audio/mpeg"))&&(""!=_3.canPlayType("audio/mpeg")));
this.canPlayWav=(("no"!=_3.canPlayType("audio/wav"))&&(""!=_3.canPlayType("audio/wav")));
}
};
CTSound.prototype.createSound=function(_4,_5){
if(!this.haveAudio){
return;
}
var _6=null;
var _7="";
if(this.canPlayMp3){
_7=this.soundPath+"/"+_4+".mp3";
}else{
if(this.canPlayOgg){
_7=this.soundPath+"/"+_4+".ogg";
}else{
if(this.canPlayWav){
_7=this.soundPath+"/"+_4+".wav";
}
}
}
if(_7){
_6=new Audio(_7);
}
if(_6){
_6.id=_5+"-"+_4;
this.sounds[_4]=_6;
if(_5){
this.sounds[_5]=_6;
}
}
};
CTSound.prototype.playSound=function(_8){
var _9=this.sounds[_8];
if(_9){
_9.play();
}
};

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

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

var SITE_VERSION=1;
var clog=false;
var ctime=false;
var cprof=false;
var move_obj_id_counter=0;
var activeBoard=null;
var boardSounds=new CTSound({soundPath:"/sounds"});
YAHOO.util.Event.onDOMReady(function(){
boardSounds.createSound("takesounds/78263__SuGu14__Metall01","takePiece1");
boardSounds.createSound("movesounds/77971__SuGu14__Fusta_0_05","movePiece3");
boardSounds.createSound("movesounds/10537__batchku__Hit_knuckle_15_004","movePiece7");
});
function isMouseOver(_1,e){
var el=YAHOO.util.Dom.get(_1);
if(!el){
return false;
}
var _4=YAHOO.util.Dom.getRegion(el);
if(!_4){
return false;
}
var _5=_4.top;
var _6=_4.left;
var _7=_4.bottom;
var _8=_4.right;
var _9=YAHOO.util.Event.getXY(e);
var mX=_9[0];
var mY=_9[1];
var _c=(mX>_6&&mX<_8&&mY>_5&&mY<_7);
}
function trimStr(_d){
if(!_d){
return "";
}
var _d=_d.replace(/^\s\s*/,"");
var ws=/\s/;
var i=_d.length;
while(ws.test(_d.charAt(--i))){
}
return _d.slice(0,i+1);
}
BoardConfig=function(){
this.boardName="board";
this.puzzle=false;
this.showToMoveIndicators=false;
this.scrollVariations=false;
this.pgnString=null;
this.pgnFile=null;
this.handleCommentClicks=false;
this.pollPGNMilliseconds=0;
this.pollPGNMillisecondsPostResult=30000;
this.numberPollsAfterResult=5;
this.gotoEndOnRefresh=false;
this.pieceSet="merida";
this.pieceSize=46;
this.isEndgame=false;
this.tr=false;
this.ie6FixCoordsOffsetSize=4;
this.allIeFixCoordsOffsetSize=0;
this.addVersion=true;
this.ml=9999;
this.r=false;
this.g=false;
this.canPasteFen=false;
this.makeActive=false;
this.avoidMouseoverActive=false;
this.autoScrollMoves=false;
this.moveAnimationLength=0.25;
this.showBracketsOnVariation=true;
this.hideBracketsOnTopLevelVariation=false;
this.variationStartString=" ( ";
this.variationEndString=" ) ";
this.ignoreCommentRegex=null;
this.newlineForEachMainMove=true;
this.useDivClearForNewline=false;
this.showNPS=false;
this.squareColorClass="";
this.pieceTakenSize=this.pieceSize;
this.pauseBetweenMoves=800;
this.pgnMode=false;
this.hidePGNErrors=false;
this.previewMode=false;
this.movesFormat="default";
this.boardImagePath = "include/PGNviewer";
//this.boardImagePath = "http://chesstempo.com";
this.showCoordinates = false;
this.highlightFromTo=false;
this.highlightValidSquares=false;
this.showResult=1;
this.showEvent=1;
this.showRound=1;
this.showSite=1;
this.showDate=1;
this.ignoreFlipping=false;
this.reverseFlip=false;
this.autoplayFirst=false;
this.dontOutputNavButtons=false;
this.dontCheckLeavingPage=false;
this.clickAndClick=false;
this.whiteMoveSoundName="movePiece3";
this.blackMoveSoundName="movePiece7";
this.whiteTakeSoundName="takePiece1";
this.blackTakeSoundName="takePiece1";
this.soundEnabled=false;
this.gamedb = false;
this.startGameAuto = false;
};
BoardConfig.prototype.applyConfig=function(_10){
for(var _11 in _10){
this[_11]=_10[_11];
}
};
ChessApp=function(_12){
this.displayMode=false;
this.config=_12;
this.board=null;
};
ChessApp.prototype.setDisplayMode=function(_13){
this.displayMode=_13;
};
ChessApp.prototype.setProblemNumber=function(_14,_15){
this.problemNumber=_14;
this.attId=_15;
};
ChessApp.prototype.init = function(us) {
    ChessPiece.init();
    this.board = new Board(this.config.boardName);
    this.board.moveArray = new Array();
    if (!this.hideOnInit) {
        YAHOO.util.Dom.setStyle(this.config.boardName + "-container", "display", "block");
        YAHOO.util.Dom.setStyle("toPlaySpan", "display", "inline");
    }
    this.tactics = (this.displayMode || this.config.pgnMode || this.config.previewMode || this.config.fenBoard) ? null : new TacticsUI(this.board);
    this.problem = (this.config.pgnMode || this.config.previewMode || this.config.fenBoard) ? null : new ProblemUI(this.board, this.tactics);
    this.board.tactics = this.tactics;
    this.board.problem = this.problem;
    this.board.puzzle = this.config.puzzle;
    if (this.problem) {
        this.problem.autoPlayOpponent = 1;
    }
    this.pgn = (this.config.pgnMode) ? new PGN(this.board) : null;
    var _17 = MovesDisplay.DEFAULT_DISPLAY_TYPE;
    if (this.config.movesFormat == "main_on_own_line") {
        _17 = MovesDisplay.MAIN_ON_OWN_LINE;
    }
    this.movesDisplay = new MovesDisplay(this.board, _17);
    this.movesDisplay.variationOnOwnLine = this.config.variationOnOwnLine;
    this.board.movesDisplay = this.movesDisplay;
    this.board.boardImagePath = this.config.boardImagePath;
    this.board.showNPS = this.config.showNPS;
    this.board.squareColorClass = this.config.squareColorClass;
    this.board.tr = this.config.tr;
    this.board.scrollToBoardTop = this.config.scrollToBoardTop;
    this.board.ml = this.config.ml;
    this.board.r = this.config.r;
    this.board.g = this.config.g;
    this.board.canPasteFen = this.config.canPasteFen;
    this.board.addVersion = this.config.addVersion;
    this.board.ie6FixCoordsOffsetSize = this.config.ie6FixCoordsOffsetSize;
    this.board.allIeFixCoordsOffsetSize = this.config.allIeFixCoordsOffsetSize;
    this.board.allowingFreeMovement = this.config.allowingFreeMovement;
    this.board.autoScrollMoves = this.config.autoScrollMoves;
    this.board.moveAnimationLength = this.config.moveAnimationLength;
    this.board.showBracketsOnVariation = this.config.showBracketsOnVariation;
    this.board.hideBracketsOnTopLevelVariation = this.config.hideBracketsOnTopLevelVariation;
    this.board.variationStartString = this.config.variationStartString;
    this.board.variationEndString = this.config.variationEndString;
    this.board.ignoreCommentRegex = this.config.ignoreCommentRegex;
    this.board.newlineForEachMainMove = this.config.newlineForEachMainMove;
    this.board.useDivClearForNewline = this.config.useDivClearForNewline;
    this.board.pieceSize = this.config.pieceSize;
    this.board.showToMoveIndicators = this.config.showToMoveIndicators;
    this.board.handleCommentClicks = this.config.handleCommentClicks;
    this.board.pollPGNMilliseconds = this.config.pollPGNMilliseconds;
    this.board.pollPGNMillisecondsPostResult = this.config.pollPGNMillisecondsPostResult;
    this.board.numberPollsAfterResult = this.config.numberPollsAfterResult;
    this.board.gotoEndOnRefresh = this.config.gotoEndOnRefresh;
    this.board.pieceTakenSize = this.config.pieceTakenSize;
    this.board.pieceSet = this.config.pieceSet;
    this.board.pauseBetweenMoves = this.config.pauseBetweenMoves;
    this.board.showCoordinates = this.config.showCoordinates;
    this.board.highlightFromTo = this.config.highlightFromTo;
    this.board.highlightValidSquares = this.config.highlightValidSquares;
    this.board.showDate = this.config.showDate;
    this.board.showEvent = this.config.showEvent;
    this.board.showGame = this.config.showGame;
    this.board.showResult = this.config.showResult;
    this.board.showRound = this.config.showRound;
    this.board.showSite = this.config.showSite;
    this.board.ignoreFlipping = this.config.ignoreFlipping;
    this.board.reverseFlip = this.config.reverseFlip;
    this.board.autoplayFirst = this.config.autoplayFirst;
    this.board.scrollVariations = this.config.scrollVariations;
    this.board.dontOutputNavButtons = this.config.dontOutputNavButtons;
    this.board.clickAndClick = this.config.clickAndClick;
    this.board.avoidMouseoverActive = this.config.avoidMouseoverActive;
    this.board.dontCheckLeavingPage = this.config.dontCheckLeavingPage;
    this.board.whiteMoveSoundName = this.config.whiteMoveSoundName;
    this.board.whiteTakeSoundName = this.config.whiteTakeSoundName;
    this.board.blackMoveSoundName = this.config.blackMoveSoundName;
    this.board.blackTakeSoundName = this.config.blackTakeSoundName;
    this.board.soundEnabled = this.config.soundEnabled;
    this.board.hidePGNErrors = this.config.hidePGNErrors;
    this.board.gamedb = this.config.gamedb;
    this.board.startGameAuto = this.config.startGameAuto;
    if (this.config.makeActive) {
        activeBoard = this.board;
    }
    if (this.problem) {
        this.problem.isEndgame = this.config.isEndgame;
    }
    if (!this.board.puzzle && 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.board.puzzle) {
        if (this.problem) {
            this.problem.createProblemUI();
        }
        if (this.tactics) {
            this.tactics.initProblemCompleteOverlay();
        }
        if (this.problem) {
            this.problem.initLoadingOverlay();
        }
        if (this.config.pgnMode) {
            if (this.config.pgnFile) {
                this.pgn.getPGNFromURL(this.config.pgnFile, this.config.gotoEndOnRefresh);
                if (this.config.pollPGNMilliseconds) {
                    this.pgn.foundResult = false;
                    this.pgn.foundResultPolls = 0;
                    this.pgn.pollPGNFromURL(this.config.pgnFile, this.config.gotoEndOnRefresh, this.config.pollPGNMilliseconds);
                }
            } else {
                if (this.config.pgnString) {
                    this.pgn.setupFromPGN(this.config.pgnString);
                }
            }
        } else {
            if (!this.board.dontCheckLeavingPage && this.tactics) {
                YAHOO.util.Event.addListener(window, "beforeunload", this.tactics.checkLeavingPage, this.tactics, true);
                YAHOO.util.Event.addListener(window, "unload", this.tactics.leavingPage, this.tactics, true);
                this.tactics.updateSessionDisplay(0, 0);
                if (typeof showingStart != "undefined" && showingStart) {
                    var _18 = this;
                    var _19 = "";
                    if (loggedIn) {
                        if (this.config.isEndgame) {
                            _19 = _js("Endgame Problem Set") + ": <span id=\"startProblemSetStr\">" + _js(startEndgameSetName) + "</span>";
                        } else {
                            _19 = _js("Tactics Problem Set") + ": <span id=\"startProblemSetStr\">" + _js(startTacticsSetName) + "</span>";
                        }
                    }
                    var _1a = new YAHOO.widget.SimpleDialog("starttacticdialog1", { width: "300px", fixedcenter: true, modal: false, visible: true, draggable: true, close: false, text: "<div style=\"color:black\">" + _19 + "</div><br/>" + "<div style=\"color:black\">" + _js("Click start to begin solving problems") + "</div>", icon: YAHOO.widget.SimpleDialog.ICON_INFO, constraintoviewport: true, buttons: [{ text: _js("Start"), handler: function() {
                        this.hide();
                        _18.problem.getProblem();
                    }, isDefault: true}]
                    });
                    var _1b = YAHOO.util.Dom.get("ctb-" + this.board.boardName);
                    _1a.render(document.body);
                } else {
                    this.problem.getProblem();
                }
            } else {
                if (this.problem) {
                    if (this.problemNumber != "") {
                        YAHOO.util.Dom.setStyle("boardandmoves", "display", "block");
                        this.problem.getProblem(this.problemNumber, this.attId);
                    }
                }
            }
        }
    }
    this.board.setupEventHandlers();
    if (this.problem) {
        this.problem.setupEventHandlers();
    }
    if (this.tactics) {
        this.tactics.setupEventHandlers();
    }
    if (this.board.scrollToBoardTop) {
        var xy = YAHOO.util.Dom.getXY(this.board.boardName + "-boardBorder");
        window.scrollTo(xy[0], xy[1]);
    }

    if (this.board.startGameAuto == true)
        this.board.playMoves(this);
};
function clearClone(o){
if(o==null){
return;
}
for(prop in o){
if(typeof (o[prop])=="object"&&o[prop]!=null&&o[prop].alreadyCloned){
o[prop].alreadyCloned=false;
clearClone(o[prop]);
}
}
}
function cloneWork(o){
if(o==null){
return null;
}
var _1f=new Object();
for(prop in o){
if(typeof (o[prop])=="object"){
_1f[prop]=o[prop];
}else{
_1f[prop]=o[prop];
}
}
return _1f;
}
function clone(o){
return cloneWork(o);
}
get_image_str = function(_21, _22, _23, _24, _25) {
    var _26 = ".vers" + SITE_VERSION;
    if (!_25) {
        _26 = "";
    }

    if (check_bad_msie()) {
        return _22 + "/images/" + _23 + "/" + _21 + _24 + _26 + ".png";
    } else {
        return _22 + "/images/" + _23 + "/" + _21 + _24 + _26 + ".png";
    }
};
check_bad_msie=function(){
var _27=(window.ActiveXObject&&(typeof document.body.style.maxHeight=="undefined"));
return _27;
};
fix_ie_png=function(img){
if(!check_bad_msie()){
return;
}
var _29=(img.id)?"id='"+img.id+"' ":"";
var _2a=(img.className)?"class='"+img.className+"' ":"";
var _2b=(img.title)?"title='"+img.title+"' ":"title='"+img.alt+"' ";
var _2c="display:inline-block;"+img.style.cssText;
if(img.align=="left"){
_2c="float:left;"+_2c;
}
if(img.align=="right"){
_2c="float:right;"+_2c;
}
if(img.parentElement.href){
_2c="cursor:hand;"+_2c;
}
var _2d="<span "+_29+_2a+_2b+" style=\""+"width:"+img.width+"px; height:"+img.height+"px;"+_2c+";"+"filter:progid:DXImageTransform.Microsoft.AlphaImageLoader"+"(src='"+img.src+"', sizingMethod='image');\"></span>";
img.outerHTML=_2d;
};
Move=function(_2e,_2f,_30,_31,_32,_33,_34){
this.fromColumn=_2e;
this.fromRow=_2f;
this.toColumn=_30;
this.toRow=_31;
this.take=_32;
this.promotion=_33;
this.moveString=_34;
this.prev=null;
this.next=null;
this.numVars=0;
this.prevMoveEnpassant=false;
this.ravLevel=0;
this.atEnd=false;
this.obj_id=move_obj_id_counter++;
this.beforeComment="";
this.afterComment="";
};
Move.prototype.freeMove=function(){
if(this.taken){
this.taken=null;
}
if(this.vars&&this.vars.length>0){
var i=0;
for(var i=0;i<this.vars.length;i++){
this.vars[i].freeMove();
}
}
};
Move.prototype.clone=function(_36){
var _37=this.take;
if(_36&&_37){
_37=_37.makeLightWeight();
}
var _38=new Move(this.fromColumn,this.fromRow,this.toColumn,this.toRow,_37,this.promotion,this.moveString);
_38.moveNum=this.moveNum;
_38.atEnd=this.atEnd;
_38.beforeComment=this.beforeComment;
_38.afterComment=this.afterComment;
_38.prevMoveEnpassant=this.prevMoveEnpassant;
if(this.vars){
_38.vars=[];
var cnt=0;
for(var i=0;i<this.vars.length;i++){
_38.vars[i]=this.vars[i].clone(_36);
cnt++;
}
_38.numVars=cnt;
}
return _38;
};
Move.columnToChar=function(col){
var a=String.fromCharCode("a".charCodeAt(0)+col);
return a;
};
Move.prototype.output=function(){
return Move.columnToChar(this.fromColumn)+""+(this.fromRow+1)+":"+Move.columnToChar(this.toColumn)+""+(this.toRow+1)+" prom:"+this.promotion+" objid:"+this.obj_id+" dummy:"+this.dummy+" endNode:"+this.endNode+" index:"+this.index+" moveNum:"+this.moveNum+" atEnd:"+this.atEnd+" beforeCom:"+this.beforeComment+" afterCom:"+this.afterComment;
};
Move.prototype.equals=function(m){
return (m&&(this.fromColumn==m.fromColumn&&this.fromRow==m.fromRow&&this.promotion==m.promotion&&this.toColumn==m.toColumn&&this.toRow==m.toRow));
};
Move.moveArraysEqual=function(a1,a2){
if(a1==a2){
return true;
}
if(a1==null||a2==null){
return false;
}
if(a1.length!=a2.length){
return false;
}
for(var i=0;i<a1.length;i++){
if(!a1[i].equals(a2[i])){
return false;
}
if(!Move.moveArraysEqual(a1[i].vars,a2[i].vars)){
return false;
}
}
return true;
};
Move.findMoveInNewArray=function(a1,a2,_43){
if(a1==a2){
return _43;
}
if(a1==null||a2==null){
return null;
}
if(a1.length!=a2.length){
return null;
}
for(var i=0;i<a1.length;i++){
if(!a1[i].equals(a2[i])){
return null;
}
if(!Move.moveArraysEqual(a1[i].vars,a2[i].vars)){
return null;
}
if(a1[i]==_43){
return a2[i];
}
}
return null;
};
Move.prototype.toMoveString=function(){
var _45="";
if(this.promotion){
_45=this.promotion;
}
return Move.columnToChar(this.fromColumn)+""+(this.fromRow+1)+Move.columnToChar(this.toColumn)+""+(this.toRow+1)+_45;
};
function getTagValue(_46,_47){
var _48=_46.getElementsByTagName(_47);
if(_48==null){
YAHOO.log("got null node for tag:"+_47);
return null;
}
if(_48.length==0){
YAHOO.log("got empty array node for tag:"+_47);
return null;
}
if(_48[0].firstChild==null){
YAHOO.log("firstChild is null for tag:"+_47);
return null;
}
if(_48[0].firstChild.nodeValue==null){
YAHOO.log("firstChild.nodeValue is null for tag:"+_47);
return null;
}
if(typeof (_48[0].textContent)!="undefined"){
return _48[0].textContent;
}
return _48[0].firstChild.nodeValue;
}
var ua=navigator.userAgent.toLowerCase();
var isOpera=(ua.indexOf("opera")>-1);
var isIphone=(navigator.userAgent.match(/iPhone/i))||(navigator.userAgent.match(/iPod/i));
var isIpad=(navigator.userAgent.match(/iPad/i));
var isSafari=(ua.indexOf("safari")>-1);
var isGecko=(!isOpera&&!isSafari&&ua.indexOf("gecko")>-1);
var isIE=(!isOpera&&ua.indexOf("msie")>-1);
function unescapeHtml(s){
var n=document.createElement("div");
n.innerHTML=s;
if(n.innerText){
return n.innerText;
}else{
return n.textContent;
}
}
ChessPiece=function(div,_4c,_4d,_4e){
var id=div.id;
this.board=_4e;
this.icon=get_image_str(ChessPiece.pieceIconNames[_4c][_4d],this.board.boardImagePath,this.board.pieceSet,this.board.pieceSize,this.board.addVersion);
this.colour=_4c;
this.piece=_4d;
this.id=id;
this.div=div;
var _50=_4e.getPieceDragDiv();
var _51=false;
var _52="";
if(_50==null){
_50=document.createElement("div");
_50.id="pieceDragDiv";
_51=true;
YAHOO.util.Dom.setStyle(_50,"visibility","hidden");
YAHOO.util.Dom.setStyle(_50,"border","0px");
YAHOO.util.Dom.setStyle(_50,"position","absolute");
}
this.pieceDragEl=_50;
this.pieceDragElId="pieceDragDiv";
if(_51){
var _53=this.board.getDocBody();
if(_53){
_53.appendChild(_50);
}
}
if(YAHOO.util.Event.isIE||isOpera){
var _54=this.div;
_54.innerHTML="<img src=\""+this.icon+"\"/>";
var img=_54.firstChild;
fix_ie_png(img);
}else{
YAHOO.util.Dom.setStyle([this.div],"backgroundImage","url("+this.icon+")");
}
YAHOO.util.Dom.setStyle([this.div],"height",this.board.pieceSize+"px");
YAHOO.util.Dom.setStyle([this.div],"width",this.board.pieceSize+"px");
if(isIphone||isIpad){
initIphone(this.div);
}
YAHOO.util.Dom.setStyle([this.div],"position","relative");
if(!this.board.clickAndClick){
this.init(id,"ct-"+this.board.boardName+"-boardandpieces",{dragElId:this.pieceDragElId,resizeFrame:true,centerFrame: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.materialValue=function(_56){
switch(_56){
case ChessPiece.PAWN:
return 1;
break;
case ChessPiece.BISHOP:
return 3;
break;
case ChessPiece.KNIGHT:
return 3;
break;
case ChessPiece.ROOK:
return 5;
break;
case ChessPiece.KING:
return 0;
break;
case ChessPiece.QUEEN:
return 9;
break;
}
return 0;
};
ChessPiece.prototype.free=function(){
if(!this.board.clickAndClick){
this.unreg();
}
};
ChessPiece.prototype.clickValidator=function(e){
if(this.board.dragDisabled){
return false;
}
if(this.board.toMove!=this.colour){
return false;
}
if(this.board.clickAndClick){
return false;
}
var _58=YAHOO.util.Event.getTarget(e);
var _59=(this.isValidHandleChild(_58)&&(this.id==this.handleElId||this.DDM.handleWasClicked(_58,this.id)));
if(!_59){
YAHOO.util.Event.preventDefault(e);
}
return _59;
};
ChessPiece.prototype.onDragOut=function(e,id){
this.insideBoard=false;
};
ChessPiece.prototype.onDragEnter=function(e,id){
this.insideBoard=true;
};
ChessPiece.prototype.endDrag=function(e){
if(this.board.lastOverSquare){
YAHOO.util.Dom.removeClass(this.board.lastOverSquare,"ct-over-valid-square");
YAHOO.util.Dom.removeClass(this.board.lastOverSquare,"ct-over-invalid-square");
}
this.board.lastOverSquare=null;
if(!this.insideBoard){
this.board.board_xy=null;
this.setPosition(this.column,this.row,false,null,this.board.moveAnimationLength);
}
YAHOO.util.Dom.setStyle(this.getEl(),"visibility","visible");
};
ChessPiece.prototype.startDrag=function(x,y){
this.insideBoard=true;
var _61=null;
if(this.board.currentMove){
if(this.board.currentMove.prev){
_61=this.board.currentMove.prev;
}else{
_61=this.board.prev_move;
}
}else{
_61=this.board.prev_move;
}
if(this.board.highlightValidSquares){
this.candidates=null;
this.candidates=new Array(8);
for(var i=0;i<8;i++){
this.candidates[i]=new Array(8);
for(var j=0;j<8;j++){
this.candidates[i][j]=false;
}
}
}
this.pieceDragEl.innerHTML="<img src=\""+this.icon+"\"/>";
var img=this.pieceDragEl.firstChild;
fix_ie_png(img);
YAHOO.util.Dom.setStyle(this.pieceDragEl,"zIndex",1000);
YAHOO.util.Dom.setStyle(this.pieceDragEl,"height",this.board.pieceSize+"px");
YAHOO.util.Dom.setStyle(this.pieceDragEl,"width",this.board.pieceSize+"px");
YAHOO.util.Dom.setStyle(this.getEl(),"visibility","hidden");
if(this.board.highlightValidSquares){
for(var i=0;i<8;i++){
for(var j=0;j<8;j++){
var _65=7-i;
var _66=j;
if(this.board.isFlipped){
_65=7-_65;
_66=7-_66;
}
if((_65==this.row&&_66==this.column)||this.board.canMove(this.makeLightWeight(),_66,_65,_61,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 _6b=YAHOO.util.Dom.getX("ctb-"+this.board.boardName);
var _6c=YAHOO.util.Dom.getY("ctb-"+this.board.boardName);
var c=parseInt((x-_6b)/this.board.pieceSize);
var r=parseInt((y-_6c)/this.board.pieceSize);
var _6f=this.board.boardName+"-s"+c+""+(7-r);
var _70=YAHOO.util.Dom.get(_6f);
if(this.board.highlightValidSquares){
if(this.board.lastOverSquare){
if(this.board.lastOverSquare!=_70){
YAHOO.util.Dom.removeClass(this.board.lastOverSquare,"ct-over-valid-square");
YAHOO.util.Dom.removeClass(this.board.lastOverSquare,"ct-over-invalid-square");
this.board.lastOverSquare=null;
if(this.candidates&&c<8&&c>=0&&r<8&&r>=0&&this.candidates[c][r]){
YAHOO.util.Dom.addClass(_70,"ct-over-valid-square");
}else{
YAHOO.util.Dom.addClass(_70,"ct-over-invalid-square");
}
}
}
this.board.lastOverSquare=_70;
}
};
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 _75=YAHOO.util.Dom.getX("ctb-"+this.board.boardName);
var _76=YAHOO.util.Dom.getY("ctb-"+this.board.boardName);
var c=parseInt((x-_75)/this.board.pieceSize);
var r=parseInt((y-_76)/this.board.pieceSize);
if(this.board.isFlipped){
r=7-r;
c=7-c;
}
var _79=false;
if(!this.board.currentMove||this.board.currentMove.atEnd){
_79=true;
}
this.board.updatePiece(this,c,7-r,false,false,true);
if(!_79&&this.board.currentMove&&!this.board.allowingFreeMovement&&this.board.currentMove.atEnd){
this.board.toggleToMove();
this.board.updateToPlay();
}
};
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.removeFromParent=function(){
var _7b=this.div;
if(_7b.parentNode){
_7b.parentNode.removeChild(_7b);
}
};
ChessPiece.prototype.setVisible=function(_7c){
var _7d;
var _7e;
if(_7c){
_7e="block";
_7d="visible";
}else{
_7e="none";
_7d="hidden";
}
YAHOO.util.Dom.setStyle(this.id,"visibility",_7d);
};
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.changePieceKeepImage=function(_81){
var _82=(_81+"").toLowerCase().charAt(0);
switch(_82){
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:
}
};
ChessPiece.prototype.changePiece = function(_83) {
    this.changePieceKeepImage(_83);
    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 || isOpera) {
        var _84 = this.div;
        _84.innerHTML = "<img src=\"" + this.icon + "\"/>";
        var img = _84.firstChild;
        if (!isOpera) {
            fix_ie_png(img);
        }
    } else {
        YAHOO.util.Dom.setStyle(this.div, "backgroundImage", "url(" + this.icon + ")");
        YAHOO.util.Dom.setStyle(this.div, "background-repeat", "no-repeat");
    }
};
ChessPiece.prototype.getNewXYPosition=function(_86,row){
var _88=this.board.getBoardDiv();
var _89=this.board.getXY();
var _8a=_89[0];
var _8b=_89[1];
var _8c=[0,0];
if(this.board.isFlipped){
_8c[0]=_8a+((7-_86)*this.board.pieceSize);
_8c[1]=_8b+((row)*this.board.pieceSize);
}else{
_8c[0]=_8a+((_86)*this.board.pieceSize);
_8c[1]=_8b+((7-row)*this.board.pieceSize);
}
return _8c;
};
ChessPiece.prototype.setPosition=function(_8d,row,_8f,_90,_91,_92,_93){
this.column=_8d;
this.row=row;
if(this.board.pieceMoveDisabled){
return;
}
var _94=this.div;
var _95=null;
if(this.board.isFlipped){
_95=this.board.boardName+"-s"+(7-this.column)+""+(7-this.row);
}else{
_95=this.board.boardName+"-s"+(this.column)+""+(this.row);
}
var _96=this.board.getBoardDivFromId(_95);
var _97=null;
if(!_92){
_97=(this.colour==ChessPiece.WHITE)?this.board.whiteMoveSoundName:this.board.blackMoveSoundName;
}else{
_97=(this.colour==ChessPiece.WHITE)?this.board.whiteTakeSoundName:this.board.blackTakeSoundName;
}
if(!_8f){
if(!this.board.settingUpPosition){
var _98=this.getNewXYPosition(_8d,row);
YAHOO.util.Dom.setXY(_94,_98,false);
}else{
if(_94.parentNode){
_94.parentNode.removeChild(_94);
}
_96.appendChild(_94);
}
this.setVisible(true);
if(_93&&this.board.soundEnabled){
boardSounds.playSound(_97);
}
if(_90){
_90();
}
}else{
var _98=this.getNewXYPosition(_8d,row);
if(this.board.oldAnim&&this.board.oldAnim.isAnimated()){
this.board.oldAnim.stop();
YAHOO.util.Dom.setXY(this.board.oldAnimPieceDiv,this.board.old_new_xy,false);
}
var _99=new YAHOO.util.Motion(_94,{points:{to:_98}});
this.board.oldAnim=_99;
this.board.oldAnimPieceDiv=_94;
this.board.old_new_xy=_98;
_99.duration=_91;
var _9a=this;
_99.onComplete.subscribe(function(){
if(_9a.board.soundEnabled){
boardSounds.playSound(_97);
}
});
if(_90){
_99.onComplete.subscribe(_90);
}
_99.animate();
}
};
ChessPiece.prototype.getFenLetter=function(){
var _9b=ChessPiece.pieceTypeToChar(this.piece)+"";
if(this.colour!=ChessPiece.WHITE){
_9b=_9b.toLowerCase();
}
return _9b;
};
ChessPiece.pieceTypeToChar=function(_9c){
switch(_9c){
case ChessPiece.KING:
return "K";
case ChessPiece.QUEEN:
return "Q";
case ChessPiece.ROOK:
return "R";
case ChessPiece.BISHOP:
return "B";
case ChessPiece.KNIGHT:
return "N";
case ChessPiece.PAWN:
return "P";
}
return "?";
};
LightweightChessPiece=function(div,_9e,_9f,_a0){
this.board=_a0;
this.colour=_9e;
this.piece=_9f;
this.div=div;
};
LightweightChessPiece.prototype.getFenLetter=ChessPiece.prototype.getFenLetter;
LightweightChessPiece.prototype.makeLightWeight=function(){
return this.copyPiece();
};
LightweightChessPiece.prototype.makeHeavyWeight=function(){
var cp=this.board.createPiece(this.colour,this.piece,false);
cp.column=this.column;
cp.row=this.row;
cp.enPassant=this.enPassant;
cp.castled=this.castled;
return cp;
};
LightweightChessPiece.prototype.setVisible=function(_a2){
};
LightweightChessPiece.prototype.free=function(){
};
LightweightChessPiece.prototype.setPosition=function(_a3,row,_a5,_a6,_a7){
this.column=_a3;
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(_a9){
this.changePieceKeepImage(_a9);
};
LightweightChessPiece.prototype.changePieceKeepImage=function(_aa){
var _ab=(_aa+"").toLowerCase().charAt(0);
switch(_ab){
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(_ac,_ad){
this.board=_ac;
this.displayType=_ad;
};
MovesDisplay.DEFAULT_DISPLAY_TYPE=0;
MovesDisplay.MAIN_ON_OWN_LINE=1;
Board=function(_ae){
this.boardName=_ae;
if(_ae){
this.initTarget("ctb-"+_ae,"ct-"+this.boardName+"-boardandpieces");
this.boardPieces=Board.createBoardArray();
}
this.currentMove=null;
this.moveIndex=-1;
this.settingUpPosition=false;
this.pendingLevelZeroCommentaryClose=false;
this.isUserFlipped=false;
this.registeredForwardAtEndListeners=[];
this.registeredPasteFenClickedListeners=[];
this.registeredGotoMoveIndexListeners=[];
this.registeredBackMovePreCurrentListeners=[];
this.registeredForwardMovePostUpdateListeners=[];
this.registeredUpdateListeners=[];
this.registeredUpdatePieceFinishedListeners=[];
this.registeredUpdateEndOfMovesListeners=[];
this.registeredUpdateHaveAltListeners=[];
this.registeredUpdateWrongMoveListeners=[];
this.registeredUpdateAllowMoveListeners=[];
this.moveNumber=1;
this.halfMoveNumber=0;
};
Board.prototype=new YAHOO.util.DDTarget();
Board.invertToMove=function(_af){
if(_af==ChessPiece.WHITE){
return ChessPiece.BLACK;
}else{
return ChessPiece.WHITE;
}
};
Board.boardStyleToClassName=function(_b0){
var _b1="";
switch(_b0){
case 0:
_b1="-lightgrey";
break;
case 1:
_b1="-grey";
break;
case 2:
_b1="-brown";
break;
case 3:
_b1="-green";
break;
case 4:
_b1="-woodlight";
break;
case 5:
_b1="-wooddark";
break;
case 6:
_b1="-metal";
break;
case 7:
_b1="-marblebrown";
break;
case 8:
_b1="-stucco";
break;
case 9:
_b1="-goldsilver";
break;
case 10:
_b1="-sandsnow";
break;
case 11:
_b1="-crackedstone";
break;
case 12:
_b1="-granite";
break;
case 13:
_b1="-marblegreen";
break;
case 14:
_b1="-greenwhite";
break;
default:
}
return _b1;
};
Board.createBoardArray=function(){
var _b2=boardPool.getObject();
if(_b2==null){
_b2=new Array(8);
for(var i=0;i<8;i++){
_b2[i]=new Array(8);
}
}
return _b2;
};
Board.prototype.selectDestSquare=function(e){
var x=YAHOO.util.Event.getPageX(e);
var y=YAHOO.util.Event.getPageY(e);
var _b7=YAHOO.util.Dom.getX("ctb-"+this.boardName);
var _b8=YAHOO.util.Dom.getY("ctb-"+this.boardName);
var c=parseInt((x-_b7)/this.pieceSize);
var r=parseInt((y-_b8)/this.pieceSize);
var _bb=this.boardName+"-s"+c+""+(7-r);
var _bc=YAHOO.util.Dom.get(_bb);
if(_bc==this.oldSelectedSquare){
YAHOO.util.Dom.removeClass(_bc,"ct-source-square");
this.oldSelectedSquare=null;
if(this.oldDestSquare){
YAHOO.util.Dom.removeClass(this.oldDestSquare,"ct-dest-square");
this.oldDestSquare=null;
}
return true;
}
if(this.isFlipped){
c=7-c;
r=7-r;
}
r=7-r;
var _bd=this.boardPieces[c][r];
if(_bd&&(_bd.colour==this.toMove)){
if(this.oldSelectedSquare){
YAHOO.util.Dom.removeClass(this.oldSelectedSquare,"ct-source-square");
this.oldSelectedSquare=null;
}
if(this.oldDestSquare){
YAHOO.util.Dom.removeClass(this.oldDestSquare,"ct-dest-square");
this.oldDestSquare=null;
}
YAHOO.util.Dom.addClass(_bc,"ct-source-square");
this.oldSelectedSquare=_bc;
this.oldSelectedPiece=_bd;
}else{
if(this.oldSelectedSquare){
var _be=null;
if(this.currentMove){
if(this.currentMove.prev){
_be=this.currentMove.prev;
}else{
_be=this.prev_move;
}
}else{
_be=this.prev_move;
}
if(this.canMove(this.oldSelectedPiece.makeLightWeight(),c,r,_be,true)){
this.lastDestSquare=_bc;
this.lastDestRow=r;
this.lastDestColumn=c;
YAHOO.util.Dom.removeClass(this.oldSelectedSquare,"ct-source-square");
var _bf=false;
if(!this.currentMove||this.currentMove.atEnd){
_bf=true;
}
this.updatePiece(this.oldSelectedPiece,c,r,false,false,true);
this.oldSelectedPiece=null;
this.oldSelectedSquare=null;
if(!_bf&&this.currentMove&&!this.allowingFreeMovement&&this.currentMove.atEnd){
this.toggleToMove();
this.updateToPlay();
}
}
}else{
return true;
}
}
};
Board.prototype.selectSourcePiece=function(_c0){
if(this.lastSourceSquare){
YAHOO.util.Dom.removeClass(_c1,"ct-source-square");
}
var r=_c0.row;
var c=_c0.column;
if(this.isFlipped){
r=7-r;
c=7-c;
}
var _c4=this.boardName+"-s"+c+""+r;
var _c1=YAHOO.util.Dom.get(_c4);
YAHOO.util.Dom.addClass(_c1,"ct-source-square");
this.lastSourceSquare=_c1;
this.lastSourcePiece=_c0;
this.lastSourceRow=_c0.row;
this.lastSourceColumn=_c0.column;
};
Board.prototype.toggleToMove=function(){
if(this.toMove==ChessPiece.WHITE){
this.toMove=ChessPiece.BLACK;
}else{
this.toMove=ChessPiece.WHITE;
}
};
Board.prototype.setupPieceDivs=function(){
var _c5=this.getBoardDiv();
if(this.pieces){
for(var i=0;i<32;i++){
if(this.pieces[i]){
this.pieces[i].setVisible(false);
this.pieces[i].free();
this.pieces[i]=null;
}
}
}
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]);
}
}
}
}
this.availids=null;
this.availIds=new Array(32);
this.availPieceDivs=null;
this.availPieceDivs=new Array(32);
this.pieces=null;
this.pieces=new Array(32);
this.uptoId=0;
this.uptoPiece=0;
};
Board.prototype.getXY=function(){
if(true||!this.board_xy){
this.board_xy=YAHOO.util.Dom.getXY("ctb-"+this.boardName);
}
return this.board_xy;
};
Board.prototype.updateFromTo=function(_c7,_c8,_c9,_ca,_cb,_cc){
YAHOO.util.Dom.removeClass(this.lastFromSquare,"ct-from-square");
YAHOO.util.Dom.removeClass(this.lastToSquare,"ct-to-square");
if(_c9==null){
return;
}
this.lastFromSquare=_c7;
this.lastToSquare=_c8;
this.lastFromRow=_c9;
this.lastFromColumn=_ca;
this.lastToRow=_cb;
this.lastToColumn=_cc;
if(this.highlightFromTo){
YAHOO.util.Dom.addClass(_c7,"ct-from-square");
YAHOO.util.Dom.addClass(_c8,"ct-to-square");
}
};
Board.prototype.makeMove=function(_cd,_ce,_cf,_d0,_d1,_d2,_d3,_d4,_d5){
var _d6;
var _d7;
if(!this.isFlipped){
_d6=YAHOO.util.Dom.get(this.boardName+"-s"+_cd.fromColumn+""+_cd.fromRow);
_d7=YAHOO.util.Dom.get(this.boardName+"-s"+_cd.toColumn+""+_cd.toRow);
}else{
_d6=YAHOO.util.Dom.get(this.boardName+"-s"+(7-_cd.fromColumn)+""+(7-_cd.fromRow));
_d7=YAHOO.util.Dom.get(this.boardName+"-s"+(7-_cd.toColumn)+""+(7-_cd.toRow));
}
if(this.oldSelectedSquare){
YAHOO.util.Dom.removeClass(this.oldSelectedSquare,"ct-source-square");
this.oldSelectedSquare=null;
}
if(_d2){
this.updateFromTo(_d6,_d7,_cd.fromRow,_cd.fromColumn,_cd.toRow,_cd.toColumn);
}
var _d8=this.boardPieces[_cd.toColumn][_cd.toRow];
if(_d8!=null){
_d8.enPassant=false;
_d8.castled=false;
}
if(_ce.piece==ChessPiece.PAWN&&_cd.toColumn!=_cd.fromColumn&&this.boardPieces[_cd.toColumn][_cd.toRow]==null){
_d8=this.boardPieces[_cd.toColumn][_cd.fromRow];
this.boardPieces[_cd.toColumn][_cd.fromRow]=null;
if(_d8!=null){
_d8.enPassant=true;
}
}
var _d9=null;
if(_ce.piece==ChessPiece.KING&&Math.abs(_cd.toColumn-_cd.fromColumn)>1){
var _da;
var _db;
if(_cd.toColumn>_cd.fromColumn){
_d9=this.boardPieces[7][_cd.fromRow];
_da=_cd.fromRow;
_db=5;
this.boardPieces[7][_cd.toRow]=null;
}else{
_d9=this.boardPieces[0][_cd.fromRow];
_da=_cd.fromRow;
_db=3;
this.boardPieces[0][_cd.toRow]=null;
}
if(!_d9){
alert("No castle piece");
}else{
_d9.setPosition(_db,_da,_cf,null,_d0,null,_d5);
this.boardPieces[_d9.column][_d9.row]=_d9;
_d9.castled=true;
}
}
_cd.taken=_d8;
if(_d8&&_d1){
this.processTaken(_d8,true);
}
this.moveNumber++;
this.board_xy=null;
if(_cd.promotion!=null){
_ce.changePieceKeepImage(_cd.promotion);
}
_ce.setPosition(_cd.toColumn,_cd.toRow,_cf,function(){
var tp=_d8;
if(tp){
tp.setVisible(false);
}
if(_cd.promotion!=null){
_ce.changePiece(_cd.promotion);
}
if(_d3){
_d3.call(_d4);
}
},_d0,_d8,_d5);
if(!_cf){
if(_cd.promotion!=null){
_ce.changePiece(_cd.promotion);
}
}
this.boardPieces[_cd.fromColumn][_cd.fromRow]=null;
this.boardPieces[_cd.toColumn][_cd.toRow]=_ce;
if(_d9!=null){
_cd.taken=_d9;
}
_cd.preCastleQueenSide=new Array(2);
_cd.preCastleKingSide=new Array(2);
_cd.preCastleQueenSide[0]=this.canCastleQueenSide[0];
_cd.preCastleQueenSide[1]=this.canCastleQueenSide[1];
_cd.preCastleKingSide[0]=this.canCastleKingSide[0];
_cd.preCastleKingSide[1]=this.canCastleKingSide[1];
if(_ce.piece==ChessPiece.ROOK){
if(_cd.fromColumn==0){
this.canCastleQueenSide[_ce.colour]=false;
}else{
if(_cd.fromColumn==7){
this.canCastleKingSide[_ce.colour]=false;
}
}
}else{
if(_ce.piece==ChessPiece.KING){
this.canCastleQueenSide[_ce.colour]=false;
this.canCastleKingSide[_ce.colour]=false;
}
}
};
Board.prototype.promptPromotion=function(_dd,col,row,_e0,_e1){
_dd.prePromotionColumn=_dd.column;
_dd.prePromotionRow=_dd.row;
_dd.setPosition(col,row,false,null,this.moveAnimationLength);
var _e2=this;
var _e3=new YAHOO.widget.Dialog("promotionDialogId",{width:"300px",fixedcenter:true,visible:true,modal:true,close:false,constraintoviewport:true,buttons:[{text:_js("Queen"),handler:function(){
_e3.hide();
_e2.updatePiece(_dd,col,row,_e0,_e1,false,"q");
},isDefault:true},{text:_js("Rook"),handler:function(){
_e3.hide();
_e2.updatePiece(_dd,col,row,_e0,_e1,false,"r");
},isDefault:false},{text:_js("Bishop"),handler:function(){
_e3.hide();
_e2.updatePiece(_dd,col,row,_e0,_e1,false,"b");
},isDefault:false},{text:_js("Knight"),handler:function(){
_e3.hide();
_e2.updatePiece(_dd,col,row,_e0,_e1,false,"n");
},isDefault:false}]});
_e3.setHeader(_js("Select Promotion Piece"));
_e3.setBody("<div></div>");
_e3.render(document.body);
};
Board.moveToLocale=function(_e4){
if(!_e4||_e4==""){
return _e4;
}
var _e5="";
for(var i=0;i<_e4.length;i++){
var _e7=_e4.charAt(i);
switch(_e7){
case "K":
_e7=_js("K");
break;
case "Q":
_e7=_js("Q");
break;
case "R":
_e7=_js("R");
break;
case "N":
_e7=_js("N");
break;
case "B":
_e7=_js("B");
break;
case "P":
_e7=_js("P");
break;
case "a":
_e7=_js("a");
break;
case "b":
_e7=_js("b");
break;
case "c":
_e7=_js("c");
break;
case "d":
_e7=_js("d");
break;
case "e":
_e7=_js("e");
break;
case "f":
_e7=_js("f");
break;
case "g":
_e7=_js("g");
break;
case "h":
_e7=_js("h");
break;
case "x":
_e7=_js("x");
break;
case "#":
_e7=_js("#");
break;
}
_e5+=_e7;
}
return _e5;
};
Board.prototype.updatePiece=function(_e8,col,row,_eb,_ec,_ed,_ee,_ef){
if(_ee){
this.board_xy=null;
if(_e8.prePromotionRow){
_e8.row=_e8.prePromotionRow;
_e8.column=_e8.prePromotionColumn;
}
}
if(_ee==null&&_e8.column==col&&_e8.row==row){
this.board_xy=null;
_e8.setPosition(_e8.column,_e8.row,false,null,this.moveAnimationLength);
if(clog){
console.log("moved piece back to its orig position");
}
return;
}
var _f0=null;
if(this.currentMove){
if(this.currentMove.prev){
_f0=this.currentMove.prev;
}else{
_f0=this.prev_move;
}
}else{
_f0=this.prev_move;
}
if(clog){
if(this.currentMove){
console.log("updatepiece currentMove:"+this.currentMove.output());
}else{
console.log("updatepiece currentmove null");
}
}
if(!_eb&&!this.canMove(_e8.makeLightWeight(),col,row,_f0,true)){
this.board_xy=null;
_e8.setPosition(_e8.column,_e8.row,false,null,0.5);
if(clog){
console.log("move not legal , move back to orig:"+this.toMove);
if(_f0){
console.log("prevMove was:"+_f0.output());
}else{
console.log("prevMove was null");
}
}
return;
}
var _f1="";
if(_ed&&_e8.piece==ChessPiece.PAWN&&(row==7||row==0)){
this.promptPromotion(_e8,col,row,_eb,_ec);
return;
}else{
if(_ee!=null){
_f1=_ee;
}
}
var _f2=true;
var _f3="";
_f3+=Move.columnToChar(_e8.column);
_f3+=String.fromCharCode("1".charCodeAt(0)+_e8.row);
_f3+=Move.columnToChar(col);
_f3+=String.fromCharCode("1".charCodeAt(0)+(row));
if(_f1){
_f3+=_f1;
}
var _f4=this.createMoveFromString(_f3);
var _f5=this.currentMove;
if(_f5){
_f4.moveNum=_f5.moveNum;
}
var res=null;
for(var i=0;i<this.registeredUpdateListeners.length;i++){
_f8=this.registeredUpdateListeners[i].updatePieceCallback(_f1,_e8,col,row,_eb,_ec,_ed,_ee,_ef,_f0,this.currentMove,_f4);
if(!_f8){
return false;
}
if(!_f8.ignoreRetVal){
res=_f8;
}
}
if(!res){
return false;
}
if(res.allowMove){
if(this.oldSelectedSquare){
YAHOO.util.Dom.removeClass(this.oldSelectedSquare,"ct-source-square");
}
var _f5=res.move;
for(var i=0;i<this.registeredUpdateAllowMoveListeners.length;i++){
var _f9=this.registeredUpdateAllowMoveListeners[i].updateAllowMoveCallback(_f1,_e8,col,row,_eb,_ec,_ed,_ee,_ef,_f5);
}
this.makeMove(_f5,_e8,_ec,this.moveAnimationLength,true,true,null,null,true);
var _fa=!res.dontMakeOpponentMove&&!_eb&&(this.currentMove&&this.currentMove.next&&!this.currentMove.next.atEnd);
if(clog){
if(_f5.next){
console.log("setting current move in updatepiece to:"+_f5.next.output());
}else{
console.log("in updatepiece, current move being set to null");
}
}
this.setCurrentMove(_f5.next,false,_fa);
if(this.currentMove.atEnd){
for(var i=0;i<this.registeredUpdateEndOfMovesListeners.length;i++){
var res=this.registeredUpdateEndOfMovesListeners[i].updateEndOfMovesCallback(_f1,_e8,col,row,_eb,_ec,_ed,_ee,_ef);
}
}
if(_fa){
opponentMove=this.currentMove;
if(this.currentMove&&this.currentMove.next.atEnd){
this.toggleToMove();
}
this.updatePiece(this.boardPieces[opponentMove.fromColumn][opponentMove.fromRow],opponentMove.toColumn,opponentMove.toRow,true,true,false);
}
}else{
var _f5=res.move;
var _fb=_e8.column;
var _fc=_e8.row;
this.board_xy=null;
_e8.setPosition(_e8.column,_e8.row,false,null,this.moveAnimationLength);
for(var i=0;i<this.registeredUpdateWrongMoveListeners.length;i++){
var res=this.registeredUpdateWrongMoveListeners[i].updateWrongMoveCallback(_f1,_e8,col,row,_eb,_ec,_ed,_ee,_ef,_f5);
}
}
for(var i=0;i<this.registeredUpdatePieceFinishedListeners.length;i++){
var _f8=this.registeredUpdatePieceFinishedListeners[i].updatePieceFinishedCallback(_f1,_e8,col,row,_eb,_ec,_ed,_ee,_ef,_f0,this.currentMove,_f4);
}
};
Board.prototype.addGotoMoveIndexListener=function(_fd){
this.registeredGotoMoveIndexListeners.push(_fd);
};
Board.prototype.addPasteFenClickedListener=function(_fe){
this.registeredPasteFenClickedListeners.push(_fe);
};
Board.prototype.addBackMovePreCurrentListener=function(_ff){
this.registeredBackMovePreCurrentListeners.push(_ff);
};
Board.prototype.addForwardMovePostUpdateListener=function(_100){
this.registeredForwardMovePostUpdateListeners.push(_100);
};
Board.prototype.addForwardAtEndListener=function(_101){
this.registeredForwardAtEndListeners.push(_101);
};
Board.prototype.addUpdatePieceListener=function(_102){
this.registeredUpdateListeners.push(_102);
};
Board.prototype.addUpdatePieceFinishedListener=function(_103){
this.registeredUpdatePieceFinishedListeners.push(_103);
};
Board.prototype.addUpdatePieceEndOfMovesListener=function(_104){
this.registeredUpdateEndOfMovesListeners.push(_104);
};
Board.prototype.addUpdatePieceHaveAltListener=function(_105){
this.registeredUpdateHaveAltListeners.push(_105);
};
Board.prototype.addUpdatePieceAllowMoveListener=function(_106){
this.registeredUpdateAllowMoveListeners.push(_106);
};
Board.prototype.addUpdatePieceWrongMoveListener=function(_107){
this.registeredUpdateWrongMoveListeners.push(_107);
};
Board.prototype.scoreToShortString=function(_108){
if(_108=="draw"){
return "D";
}
if(_108>=0){
return "M"+_108;
}else{
return "L"+(-1*_108);
}
};
Board.prototype.scoreToLongString=function(_109){
if(_109=="draw"){
return _js("Draw");
}
if(_109==0){
return _js("Mate");
}else{
if(_109>0){
return __js("Mate in {NUMBER_MOVES}",[["NUMBER_MOVES",_109]]);
}else{
return __js("Lose in {NUMBER_MOVES}",[["NUMBER_MOVES",(-1*_109)]]);
}
}
};
Board.prototype.egMoveToScoreString=function(_10a){
var _10b=_10a.score;
var _10c=_10a.optimal_score;
var s=this.scoreToShortString(_10b);
var opt=this.scoreToShortString(_10c);
var _10f=this.scoreToLongString(_10b);
var _110=this.scoreToLongString(_10c);
if(_10b==_10c){
return ["",_10f];
}else{
var _111="ct-subopt-move-score";
if(_10b=="draw"||_10b<0){
_111="ct-bad-move-score";
}
return ["<span class=\""+_111+"\">"+s+"("+opt+")</span>",_10f+"("+_110+")"];
}
};
Board.prototype.makeShortAlgabraic=function(_112,_113,_114,_115,_116){
if(clog){
console.log("fromCol:"+_112+" fromRow:"+_113+" toCol:"+_114+" toRow:"+_115);
}
var _117=this.boardPieces[_112][_113];
var _118=_117.piece;
var _119=ChessPiece.pieceTypeToChar(_118);
var move="";
if(_118==ChessPiece.PAWN){
if(_112==_114){
move=Move.columnToChar(_112)+""+(_115+1);
}else{
move=Move.columnToChar(_112)+"x"+Move.columnToChar(_114)+""+(_115+1);
if(!this.boardPieces[_114][_115]){
move+=" e.p.";
}
}
}else{
if(_118==ChessPiece.KING){
var _11b=Math.abs(_112-_114);
if(_11b==1||_11b==0){
move=_119;
if(this.boardPieces[_114][_115]){
move+="x";
}
move+=Move.columnToChar(_114)+""+(_115+1);
}else{
if(_114==6){
move="O-O";
}else{
move="O-O-O";
}
}
}else{
var _11c=[];
for(var row=0;row<8;row++){
for(var col=0;col<8;col++){
var cp=this.boardPieces[col][row];
if(cp&&cp.colour==_117.colour&&cp.piece==_118&&!(_117.column==cp.column&&_117.row==cp.row)){
var prev=null;
if(this.currentMove){
prev=this.currentMove.prev;
}
if(this.canMove(cp.makeLightWeight(),_114,_115,prev,true)){
_11c.push(cp);
}
}
}
}
move=_119;
if(_11c.length>0){
var _121=false;
var _122=false;
for(var i=0;i<_11c.length;i++){
if(_11c[i].row==_113){
_122=true;
}
if(_11c[i].column==_112){
_121=true;
}
}
if(_122||!(_122||_121)){
move+=Move.columnToChar(_112);
}
if(_121){
move+=""+(_113+1);
}
}
if(this.boardPieces[_114][_115]){
move+="x";
}
move+=Move.columnToChar(_114)+""+(_115+1);
}
}
var _124="";
var _125="";
if(_116){
var _126=this.cloneBoard();
var _127=ChessPiece.WHITE;
if(_126.boardPieces[_116.fromColumn][_116.fromRow].colour==ChessPiece.WHITE){
_127=ChessPiece.BLACK;
}
_126.makeMove(_116,_126.boardPieces[_116.fromColumn][_116.fromRow],false,_126.moveAnimationLength,false,false);
if(!_126.isKingSafe(_127,_116)){
_124="+";
if(_126.isKingMated(_127,_116)){
_124="#";
}
}
if(_116.promotion){
_125="="+((_116.promotion+"").toUpperCase());
}
}
move+=_125+_124;
return move;
};
Board.getVarMove=function(move,row,col,_12b,_12c){
if(move.vars&&move.vars.length>0){
var i=0;
for(var i=0;i<move.vars.length;i++){
var _12e=move.vars[i];
if(_12e.fromColumn==_12b.column&&_12e.fromRow==_12b.row&&_12e.toRow==row&&_12e.toColumn==col&&(_12c==""||(_12c==_12e.promotion))){
return _12e;
}
}
}
};
Board.prototype.createMoveFromString=function(_12f){
var _130=0;
var take=false;
var _132=null;
var _133=_12f.charCodeAt(_130++);
var _134=_12f.charCodeAt(_130++);
var _135=_12f.split("|");
var pgn=null;
if(_135.length>1){
pgn=_135[1];
_12f=_135[0];
}else{
_12f=_135[0];
}
if(_12f.charAt(_130)=="x"){
_130++;
take=true;
}
var _137=_12f.charCodeAt(_130++);
var _138=_12f.charCodeAt(_130++);
if(_130<_12f.length){
_132=_12f.charAt(_130);
}
var move=new Move(_133-("a".charCodeAt(0)),_134-("1".charCodeAt(0)),_137-("a".charCodeAt(0)),_138-("1".charCodeAt(0)),take,_132,_12f);
move.pgn=pgn;
return move;
};
Board.prototype.getBackButton=function(){
if(!this.backButton){
this.backButton=YAHOO.util.Dom.get(this.boardName+"-back");
}
return this.backButton;
};
Board.prototype.getForwardButton=function(){
if(!this.forwardButton){
this.forwardButton=YAHOO.util.Dom.get(this.boardName+"-forward");
}
return this.forwardButton;
};
Board.prototype.getEndButton=function(){
if(!this.endButton){
this.endButton=YAHOO.util.Dom.get(this.boardName+"-end");
}
return this.endButton;
};
Board.prototype.getStartButton=function(){
if(!this.startButton){
this.startButton=YAHOO.util.Dom.get(this.boardName+"-start");
}
return this.startButton;
};
Board.prototype.setForwardBack = function() {
    var back = this.getBackButton();
    var _13b = this.getForwardButton();
    var end = this.getEndButton();
    var _13d = this.getStartButton();
    if (!this.currentMove) {
        if (back) {
            back.src = this.boardImagePath + "/images/resultset_previous_disabled" + this.getVersString() + ".gif";
        }
        if (_13d) {
            _13d.src = this.boardImagePath + "/images/disabled_resultset_first" + this.getVersString() + ".gif";
        }
        if (_13b) {
            _13b.src = this.boardImagePath + "/images/resultset_next_disabled" + this.getVersString() + ".gif";
        }
        if (end) {
            end.src = this.boardImagePath + "/images/disabled_resultset_last" + this.getVersString() + ".gif";
        }
        return;
    }
    if (this.currentMove.prev == null) {
        if (back) {
            back.src = this.boardImagePath + "/images/resultset_previous_disabled" + this.getVersString() + ".gif";
        }
        if (_13d) {
            _13d.src = this.boardImagePath + "/images/disabled_resultset_first" + this.getVersString() + ".gif";
        }
    } else {
        if (back) {
            back.src = this.boardImagePath + "/images/resultset_previous" + this.getVersString() + ".gif";
        }
        if (_13d) {
            _13d.src = this.boardImagePath + "/images/resultset_first" + this.getVersString() + ".gif";
        }
    }
    if (this.currentMove.atEnd) {
        if (_13b) {
            _13b.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 (_13b) {
            _13b.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(_13e){
var _13f=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 _142=this.boardPieces[i][j];
var p=_142.makeHeavyWeight();
this.boardPieces[i][j]=p;
p.setPosition(p.column,p.row,false,null,this.moveAnimationLength);
p.setVisible(true);
}
}
}
var move=this.moveArray[_13e];
while(move!=null){
if(move.taken){
move.taken=move.taken.makeHeavyWeight();
}
move=move.prev;
}
this.settingUpPosition=_13f;
};
MovesDisplay.prototype.setToMove=function(_145){
this.toMove=_145;
};
MovesDisplay.prototype.clickComment=function(e){
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 _148=t.id.substr((this.board.boardName+"-mcX").length);
var _149=true;
if(t.id.indexOf("-mca")>=0){
_149=false;
}
var move=this.board.moveArray[_148];
var _14b="";
if(_149){
_14b=move.beforeComment;
}else{
_14b=move.afterComment;
}
mySimpleDialog=new YAHOO.widget.SimpleDialog(this.boardName+"-editCommentDialog",{width:"20em",fixedcenter:true,modal:true,visible:false,draggable:false});
mySimpleDialog.setHeader("Edit Comment");
mySimpleDialog.setBody("<textarea id=\""+this.board.boardName+"-editComment\">"+_14b+"</textarea>");
mySimpleDialog.cfg.setProperty("icon",YAHOO.widget.SimpleDialog.ICON_INFO);
var me=this;
var _14d=function(){
if(_149){
move.beforeComment=null;
}else{
move.afterComment=null;
}
t.innerHTML="";
this.hide();
};
var _14e=function(){
var _14f=YAHOO.util.Dom.get(me.board.boardName+"-editComment");
var txt=trimStr(_14f.value);
if(_149){
move.beforeComment=txt;
}else{
move.afterComment=txt;
}
if(_149){
t.innerHTML=me.outputComment(txt,0)+" ";
}else{
t.innerHTML=" "+me.outputComment(txt,0);
}
this.hide();
};
var _151=function(){
this.hide();
};
var _152=[{text:"Delete",handler:_14d},{text:"Save",handler:_14e},{text:"Cancel",handler:_151,isDefault:true}];
mySimpleDialog.cfg.queueProperty("buttons",_152);
mySimpleDialog.render(document.body);
mySimpleDialog.show();
};
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 _155=t.id.substr((this.board.boardName+"-m").length);
if(clog){
console.log("got goto move index:"+_155);
}
this.board.gotoMoveIndex(_155,false,false,false,false);
if(this.board.problem){
if(this.board.currentMove.bestMoves){
this.board.problem.showBestMoves(this.board.currentMove,this.board.currentMove.bestMoves,this.board.currentMove.correctMove,this.board.currentMove.wrongMove);
}else{
this.board.problem.clearBestMoves();
}
}
};
MovesDisplay.prototype.getMovesDisplay=function(){
if(!this.cachedMovesDisplay&&!this.allreadyCachedMovesDisplay){
var name=this.board.boardName+"-moves";
if(this.moveListName){
name=this.moveListName;
}
this.cachedMovesDisplay=YAHOO.util.Dom.get(name);
this.allreadyCachedMovesDisplay=true;
}
return this.cachedMovesDisplay;
};
MovesDisplay.prototype.outputVariationStart=function(_157,_158,_159,_15a){
var _15b="";
if(_158>this.board.ml){
return _15b;
}
if(this.board.ml==1&&_15a>1){
return _15b;
}
var _15c=this.getMovesDisplay();
if(_15c){
if(_157==0&&this.displayType==MovesDisplay.MAIN_ON_OWN_LINE){
if(this.firstNonMove){
if(this.board.useDivClearForNewline){
_15b+="<div style=\"clear:both;\"></div>";
}
_15b+="<div class=\"ct-mainline-commentary\"/>";
this.pendingLevelZeroCommentaryClose=true;
}
}
if(this.variationOnOwnLine){
if(this.board.useDivClearForNewline){
_15b+="<div style=\"clear:both;\"></div>";
}else{
_15b+="<br/>";
}
}
if(this.board.showBracketsOnVariation&&(!this.board.hideBracketsOnTopLevelVariation||_157>0)){
_15b+="<span>"+this.board.variationStartString+"</span>";
}
}
this.firstNonMove=false;
return _15b;
};
MovesDisplay.prototype.outputVariationEnd=function(_15d,_15e,_15f,_160){
var _161=this.getMovesDisplay();
var _162="";
if(this.board.ml==1&&_15e>0&&this.board.outputFirstVar){
return _162;
}
this.board.outputFirstVar=true;
if(_161){
if(this.board.showBracketsOnVariation&&(!this.board.hideBracketsOnTopLevelVariation||_15d>1)){
_162+="<span>"+this.board.variationEndString+"</span>";
}
}
if(_15d==1&&this.displayType==MovesDisplay.MAIN_ON_OWN_LINE){
}
this.firstNonMove=false;
return _162;
};
MovesDisplay.prototype.outputComment=function(_163,_164,_165){
if(this.board.ignoreCommentRegex){
var _166=new RegExp(this.board.ignoreCommentRegex);
if(_166.test(_163)){
return "";
}
}
var _167="";
if(this.board.ml==1){
return _167;
}
var _168=this.getMovesDisplay();
if(_168){
if(_164==0&&this.displayType==MovesDisplay.MAIN_ON_OWN_LINE){
if(this.firstNonMove){
_167+="<br/>";
}
_167+="<div class=\"ct-mainline-commentary\">";
this.pendingLevelZeroCommentaryClose=true;
}
var _169="ct-board-move-comment";
if(_165){
_169="ct-board-move-alt-comment";
}
if(this.board.handleCommentClicks){
_169+=" ct-board-clickable-comment";
}
_167+="<span class=\""+_169+"\"> "+_163+" </span>";
if(_164==0&&this.displayType==MovesDisplay.MAIN_ON_OWN_LINE){
}
}
this.firstNonMove=false;
return _167;
};
MovesDisplay.prototype.outputNag=function(_16a){
var _16b="";
var _16c=this.getMovesDisplay();
if(_16c){
var _16d=null;
switch(_16a){
case 11:
_16d="=";
break;
case 14:
_16d="+=";
break;
case 15:
_16d="=+";
break;
case 16:
_16d="+/-";
break;
case 17:
_16d="-/+";
break;
case 18:
_16d="+-";
break;
case 19:
_16d="-+";
break;
case 20:
_16d="+--";
break;
case 21:
_16d="--+";
break;
default:
}
if(_16d){
_16b+="<span> "+_16d+" </span>";
}
}
return _16b;
};
MovesDisplay.prototype.outputResult=function(_16e){
return "<span class=\"ct-result\">"+_16e+"</span>";
};
MovesDisplay.prototype.outputMove=function(_16f,_170,_171,_172,_173,_174,_175,move,_177,_178){
if(clog){
console.log("outputMove:"+_172+" hideScore:"+_177);
}
var _179="";
var _17a=this.getMovesDisplay();
if(this.board.tr&&_170>0&&(_174>1||_175>3)&&!_173){
return _179;
}
if(this.board.ml==1&&_174>0&&this.board.outputFirstVar){
return _179;
}
if(_17a){
var _17b=""+Math.round(_171/2)+". ";
var _17c=false;
if(_171%2!=1){
if(clog){
console.log("firstRav:"+_173+" firstNonMove:"+this.firstNonMove);
}
if(_173||!this.firstNonMove){
_17b=Math.round(_171/2)+"... ";
_17c=true;
}else{
_17b="";
}
}
if(clog){
console.log("moveNum:"+_171+" moveNumOut:"+_17b);
}
if(this.displayType==MovesDisplay.MAIN_ON_OWN_LINE&&_170==0&&(!this.firstNonMove||_171%2==1)){
if(this.pendingLevelZeroCommentaryClose){
this.pendingLevelZeroCommentaryClose=false;
_179+="</div>";
}
if(this.board.newlineForEachMainMove){
if(this.board.useDivClearForNewline){
_179+="<div style=\"clear:both;\"></div>";
}else{
_179+="<br/>";
}
}
}
var _17d="";
var _17e="";
if(move&&move.eg_move){
var res=this.board.egMoveToScoreString(move.eg_move);
_17d=res[0];
_17e=res[1];
}
var _180="";
if(_177){
_180="initially_hidden";
}
if(_17d!=""){
_17d=" "+_17d;
}
var _181="title";
if(_177){
_181="alt";
}
var _182="";
if(_178){
_182=" rel=\""+_172+"\" ";
_172="___";
}
var _183="";
if(_17c&&_170==0){
_183="<span class=\"ct-board-move-dottedempty\">&nbsp;</span>";
}
var _184="";
if(_17b){
_184="<span class=\"ct-board-move-movenum\">"+_17b+"</span>";
}
_179+="<span "+_182+_181+"=\""+_17e+"\" id=\""+this.board.boardName+"-m"+_16f+"\" class=\""+((_170==0)?"ct-board-move-mainline":"ct-board-move-variation")+"\">"+_184+_183+"<span class=\"ct-board-move-movetext\">"+_172+"</span><span id=\""+this.board.boardName+"-msc"+_16f+"\" class=\""+_180+"\">"+_17d+"</span></span>";
}
this.firstNonMove=true;
return _179;
};
Board.prototype.setMoveSeqLalg=function(_185,_186,_187,_188){
var _189=new Array();
if(_185&&_185.length>0){
_189=_185.replace(/\s+$/g,"").split(" ");
}
this.setupFromLalgArray(_189,_188,_187,_186);
};
Board.prototype.setupFromLalgArray=function(_18a,_18b,_18c,_18d){
this.outputFirstVar=false;
if(this.movesDisplay){
this.movesDisplay.pendingLevelZeroCommentaryClose=false;
var md=this.movesDisplay.getMovesDisplay();
if(md){
YAHOO.util.Event.purgeElement(md,true);
md.innerHTML="";
}
}
if(!_18d){
_18d=new Array();
}
var _18f=this.cloneBoard();
this.movesDisplay.firstNonMove=false;
var _190=new Array();
var _191=new Array();
if(this.prev_move){
_18f.makeMove(this.prev_move,_18f.boardPieces[this.prev_move.fromColumn][this.prev_move.fromRow],false,_18f.moveAnimationLength,false,false);
}
var _192=_18f.cloneBoard();
var _193=null;
var _194=0;
var _195="";
var _196=false;
var _197=false;
var _198=0;
var _199=false;
var _19a=new Array();
var _19b=new Array();
_19b[0]=0;
var _19c=new Array();
var _19d=new Array();
var _19e=_18c*2-1;
var _19f=_18c*2-1;
var _1a0=new Array();
var _1a1=ChessPiece.WHITE;
var _1a2=0;
var eval="";
var _1a4="";
var _1a5="";
var time="";
var _1a7=-1;
var _1a8=0;
for(var i=0;i<_18a.length;i++){
var _1aa=0;
if(_18a[i]=="ALT"){
_197=true;
continue;
}
if(_18a[i].indexOf("EVAL")==0){
eval=_18a[i].split(":")[1];
if(parseInt(eval)>=175&&_198>0&&_19b[_198]>1){
_197=true;
}
continue;
}
if(_18a[i].indexOf("DEPTH")==0){
_1a4=_18a[i].split(":")[1];
continue;
}
if(_18a[i].indexOf("NODES")==0){
_1a5=_18a[i].split(":")[1];
continue;
}
if(_18a[i].indexOf("TIME")==0){
time=_18a[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 _1ac=e.split(" ");
_1aa=parseInt(_1ac[1]);
e=_js("mate")+" "+_1ac[1];
if(_19b[_198]==1){
_1a7=_1aa;
}
}
_1a8=_1aa;
if(_1aa<0){
_197=false;
}else{
if(_1aa>0&&_1aa<8&&_198>0&&_19b[_198]>1){
_197=true;
}
}
var _1ad="";
if(_197){
_1ad=_js("ALT")+" ";
}
var t=parseInt(time);
var nps=" "+__js("nps:{NODES_PER_SECOND}",[["NODES_PER_SECOND",Math.round(parseInt(_1a5)/(parseInt(time)/1000))]]);
if(!this.showNPS){
nps="";
}
if(!(_198>0&&_19b[_198]>this.ml)){
_18a[i]=_1ad+e+" ("+__js("depth:{DEPTH}",[["DEPTH",_1a4]])+nps+")";
}else{
_18a[i]="";
}
}
if(_18a[i]=="}"){
_196=false;
if(this.movesDisplay){
_195=_195.replace(/\s+$/g,"");
_1a0.push(this.movesDisplay.outputComment(_195,_198,_197));
}
continue;
}else{
if(_196){
_195+=_18a[i]+" ";
continue;
}else{
if(_18a[i]=="{"){
_195="";
_196=true;
continue;
}else{
if(_18a[i]=="("){
if(!_19b[_198+1]){
_19b[_198+1]=0;
}
_19b[_198+1]++;
if(this.movesDisplay){
_1a0.push(this.movesDisplay.outputVariationStart(_198,_19b[_198+1],_19e,_19a[0]));
}
_19a[_198]=_19e;
_19c[_198]=_193;
_19d[_198]=_1a1;
_190[_198]=_18f;
_191[_198]=_192;
_18f=_192.cloneBoard();
_198++;
_19e--;
_199=true;
continue;
}else{
if(_18a[i]==")"){
if(this.movesDisplay){
_1a0.push(this.movesDisplay.outputVariationEnd(_198,_19b[_198],_19e,_19a[0]));
}
var _1b0=new Move();
_1b0.atEnd=true;
_193.next=_1b0;
_1b0.prev=_193;
_198--;
_19e=_19a[_198];
_193=_19c[_198];
_1a1=_19d[_198];
_18f=_190[_198];
_192=_191[_198];
_197=false;
continue;
}else{
if(_18a[i].charAt(0)=="$"){
if(this.movesDisplay){
_1a0.push(this.movesDisplay.outputNag(parseInt(_18a[i].substring(1))));
}
continue;
}
}
}
}
}
}
var move=this.createMoveFromString(_18a[i]);
var _1b2=false;
if(_19e==_19f&&this.boardPieces[move.fromColumn][move.fromRow].colour==ChessPiece.BLACK){
_19e++;
_1b2=true;
_1a1=ChessPiece.BLACK;
}
move.index=_194;
var _1b3=(move.pgn)?move.pgn:move.moveString;
if(move.pgn){
_1b3=move.pgn;
}else{
_1b3=_18f.makeShortAlgabraic(move.fromColumn,move.fromRow,move.toColumn,move.toRow,move);
move.SAN=_1b3;
}
_1b3=Board.moveToLocale(_1b3);
if(this.movesDisplay){
this.movesDisplay.setToMove(_1a1);
_1a0.push(this.movesDisplay.outputMove(_194,_198,_19e,_1b3+" ",_199,_19b[_198],_19a[0]));
}
_1a1=(_1a1==ChessPiece.BLACK)?ChessPiece.WHITE:ChessPiece.BLACK;
move.moveNum=_19e;
_19e++;
if(_198>0){
if(_199){
var _1b4=_193;
if(_1b4==null){
alert("Got no previous move for variation:"+movesArra[i]);
}
if(_1b4.numVars==0){
_1b4.vars=new Array();
}
move.isAlt=_197;
move.mateInMoves=_1a8;
_1b4.vars[_1b4.numVars++]=move;
move.prev=_1b4.prev;
_199=false;
}else{
move.prev=_193;
if(_193!=null){
_193.next=move;
}
}
}else{
move.prev=_193;
if(_193!=null){
_193.next=move;
}
}
_19b[_198+1]=0;
if(_198==0){
_1a2=_194;
}
_18d[_194++]=move;
_18f.moveArray[_194-1]=move;
_193=move;
_192=_18f.cloneBoard();
_18f.makeMove(move,_18f.boardPieces[move.fromColumn][move.fromRow],false,_18f.moveAnimationLength,false,false);
}
if(this.movesDisplay&&!this.disableMoveOutput){
var _1b5=this.movesDisplay.getMovesDisplay();
_1a0.push(this.movesDisplay.outputResult(_18b));
this.pendingMovesOutput=_1a0.join("");
this.pendingMovesOutputCount=_194;
}
this.lastMoveIndex=_1a2;
if(_193!=null){
var _1b0=new Move();
_1b0.atEnd=true;
_193.next=_1b0;
_1b0.prev=_193;
}
this.lastCount=_194;
};
Board.prototype.getMaterialCount=function(){
var _1b6=0;
var _1b7=0;
for(var i=0;i<8;i++){
for(var j=0;j<8;j++){
var _1ba=this.boardPieces[i][j];
if(_1ba){
if(_1ba.colour==ChessPiece.WHITE){
_1b6+=ChessPiece.materialValue(_1ba.piece);
}else{
_1b7+=ChessPiece.materialValue(_1ba.piece);
}
}
}
}
return [_1b6,_1b7];
};
Board.prototype.getMaterialBalance=function(){
var cnt=this.getMaterialCount();
return cnt[0]-cnt[1];
};
Board.prototype.getMaterialBalances=function(){
var _1bc=this.cloneBoard();
var mv=this.moveArray[0];
_1bc.gotoMoveIndex(-1,true,true,true,true);
var _1be=[];
while(mv&&!mv.atEnd){
_1bc.makeMove(mv,_1bc.boardPieces[mv.fromColumn][mv.fromRow],false,this.moveAnimationLength,false,false);
_1be.push(_1bc.getMaterialBalance());
mv=mv.next;
_1bc.toggleToMove();
}
return _1be;
};
Board.prototype.lalgToMoveList=function(_1bf,_1c0,_1c1,_1c2,_1c3){
if(ctime){
console.time("lalgToMoveList");
}
if(clog){
console.log("startMoveNum:"+_1c1);
}
if(!_1c2){
_1c2=new Array();
}
var _1c4=this.cloneBoard();
var _1c5=new Array();
var _1c6=new Array();
if(!_1c3&&this.prev_move){
_1c4.makeMove(this.prev_move,_1c4.boardPieces[this.prev_move.fromColumn][this.prev_move.fromRow],false,_1c4.moveAnimationLength,false,false);
}
var _1c7=_1c4.cloneBoard();
var nags=[];
var _1c9=null;
var _1ca=0;
var _1cb="";
var _1cc=false;
var _1cd=0;
var _1ce=false;
var _1cf=new Array();
var _1d0=new Array();
_1d0[0]=0;
var _1d1=new Array();
var _1d2=new Array();
var _1d3=_1c1*2-1;
var _1d4=new Array();
var _1d5=ChessPiece.WHITE;
var _1d6=0;
var _1d7=true;
for(var i=0;i<_1bf.length;i++){
if(_1bf[i]=="}"){
_1cc=false;
_1cb=_1cb.replace(/\s+$/g,"");
continue;
}else{
if(_1cc){
_1cb+=_1bf[i]+" ";
continue;
}else{
if(_1bf[i]=="{"){
if(_1cb){
if(_1c9){
_1c9.afterComment=trimStr(_1cb);
}
}
_1cb="";
_1cc=true;
continue;
}else{
if(_1bf[i]=="("){
if(clog){
console.log("var start comment:"+_1cb);
}
if(_1c9){
_1c9.afterComment=trimStr(_1cb);
_1cb="";
}
if(clog){
if(_1c9){
console.log("old:"+_1c9.output());
}else{
console.log("no old move");
}
}
if(!_1d0[_1cd+1]){
_1d0[_1cd+1]=0;
}
_1d0[_1cd+1]++;
_1cf[_1cd]=_1d3;
_1d1[_1cd]=_1c9;
_1d2[_1cd]=_1d5;
_1c5[_1cd]=_1c4;
_1c6[_1cd]=_1c7;
_1c4=_1c7.cloneBoard();
_1cd++;
_1d3--;
_1ce=true;
continue;
}else{
if(_1bf[i]==")"){
if(_1c9){
if(clog){
console.log("var end comment:"+_1cb);
console.log("var end comment:"+_1c9.output());
}
_1c9.afterComment=trimStr(_1cb);
_1cb="";
}
var _1d9=new Move();
_1d9.atEnd=true;
_1c9.next=_1d9;
_1d9.prev=_1c9;
_1cd--;
_1d3=_1cf[_1cd];
_1c9=_1d1[_1cd];
_1d5=_1d2[_1cd];
_1c4=_1c5[_1cd];
_1c7=_1c6[_1cd];
continue;
}else{
if(_1bf[i].charAt(0)=="$"){
nags.push(parseInt(_1bf[i].substring(1)));
continue;
}
}
}
}
}
}
var move=this.createMoveFromString(_1bf[i]);
move.nags=nags;
move.beforeComment=trimStr(_1cb);
_1cb=null;
nags=[];
if(_1d7){
if(this.boardPieces[move.fromColumn][move.fromRow].colour==ChessPiece.BLACK){
_1d3++;
_1d5=ChessPiece.BLACK;
if(clog){
console.log("first move black new movenum:"+_1d3);
}
}
_1d7=false;
}
move.index=_1ca;
var _1db=(move.pgn)?move.pgn:move.moveString;
if(move.pgn){
_1db=move.pgn;
move.SAN=move.pgn;
}else{
_1db=_1c4.makeShortAlgabraic(move.fromColumn,move.fromRow,move.toColumn,move.toRow,move);
move.SAN=_1db;
}
_1d5=(_1d5==ChessPiece.BLACK)?ChessPiece.WHITE:ChessPiece.BLACK;
move.moveNum=_1d3;
_1d3++;
if(_1cd>0){
if(_1ce){
var _1dc=_1c9;
if(_1dc==null){
alert("Got no previous move for variation:"+movesArra[i]);
}
if(_1dc.numVars==0){
_1dc.vars=new Array();
}
_1dc.vars[_1dc.numVars++]=move;
move.prev=_1dc.prev;
_1ce=false;
}else{
move.prev=_1c9;
if(_1c9!=null){
_1c9.next=move;
}
}
}else{
move.prev=_1c9;
if(_1c9!=null){
_1c9.next=move;
}
}
_1d0[_1cd+1]=0;
if(_1cd==0){
_1d6=_1ca;
}
_1c2[_1ca++]=move;
_1c4.moveArray[_1ca-1]=move;
_1c9=move;
_1c7=_1c4.cloneBoard();
_1c4.makeMove(move,_1c4.boardPieces[move.fromColumn][move.fromRow],false,_1c4.moveAnimationLength,false,false);
}
if(_1c9!=null){
var _1d9=new Move();
_1d9.atEnd=true;
_1c9.next=_1d9;
_1d9.prev=_1c9;
if(_1cb){
_1c9.afterComment=trimStr(_1cb);
}
}
if(ctime){
console.timeEnd("lalgToMoveList");
}
return _1c2;
};
Board.prototype.reset=function(fen){
if(this.lastFromSquare){
YAHOO.util.Dom.removeClass(this.lastFromSquare,"ct-from-square");
}
if(this.lastToSquare){
YAHOO.util.Dom.removeClass(this.lastToSquare,"ct-to-square");
}
this.clearMoveList();
if(fen){
this.startFen=fen;
this.setupFromFen(fen,false,this.isFlipped,false,false,true);
}else{
this.startFen=Board.INITIAL_FEN;
this.setupFromFen(Board.INITIAL_FEN,false,this.isFlipped,false,false,true);
}
this.setForwardBack();
};
Board.prototype.clearMoveList=function(_1de){
this.movesDisplay.firstNonMove=false;
var _1df=this.movesDisplay.getMovesDisplay();
if(_1df){
YAHOO.util.Event.purgeElement(_1df,true);
_1df.innerHTML="";
}
this.currentMove=null;
this.moveIndex=-1;
this.moveArray=new Array();
if(_1de){
_1de.prev=null;
this.startMoveNum=_1de.moveNum;
}else{
this.startMoveNum=1;
}
};
Board.prototype.insertMovesFromMoveList=function(_1e0,_1e1,_1e2){
var _1e3=!_1e1;
if(ctime&&_1e3){
console.time("insertMovesFromMoveList");
}
if(!this.movesDisplay){
return;
}
if(_1e3){
this.clearMoveList(_1e0);
}
var _1e4=0;
var _1e5=_1e0.moveNum;
var move=_1e0;
while(move!=null&&!move.atEnd){
if(clog){
console.log("move:"+move.output());
}
var _1e7=move.next;
if(clog){
if(this.currentMove){
console.log("current move:"+this.currentMove.output());
}else{
console.log("no current move");
}
if(_1e7){
console.log("next move:"+_1e7.output());
}else{
console.log("no next move");
}
}
if(_1e3||_1e0!=move||_1e2==null){
if(clog){
console.log("about to call insertmoveafter");
}
this.insertMoveAfter(this.currentMove,move);
if(clog){
console.log("finished call to insertmoveafter");
}
}else{
if(clog){
console.log("about to replace variationParent:"+_1e2.output()+" with move:"+move.output()+" and board:"+this.boardToFen());
}
this.replaceMove(_1e2,move,true,true);
}
if(move.beforeComment){
this.insertCommentIntoMoveDisplay(move,move.beforeComment,false);
}
if(move.afterComment){
this.insertCommentIntoMoveDisplay(move,move.afterComment,true);
}
if(clog){
console.log("about to make move:"+move.output()+" with board pos:"+this.boardToFen());
}
this.makeMove(move,this.boardPieces[move.fromColumn][move.fromRow],false,this.moveAnimationLength,false,false);
if(clog){
console.log("made move");
}
this.setCurrentMove(move,true,true);
if(move.numVars>0){
var _1e8=move.index;
var bm=move.prev;
var _1ea=-1;
if(bm){
_1ea=bm.index;
}
var _1eb=move.numVars;
var vars=move.vars;
move.numVars=0;
move.vars=[];
for(var i=0;i<_1eb;i++){
this.gotoMoveIndex(_1ea,true,true,true,true);
if(clog){
console.log("about to call insertMovesFromMoveList with head of variation");
}
this.insertMovesFromMoveList(vars[i],true,move);
if(clog){
console.log("about to reset currentMoveIndex  after variation insert:"+_1e8);
}
}
this.gotoMoveIndex(_1e8,true,true,true,true);
this.backMove();
var cm=this.currentMove;
this.makeMove(cm,this.boardPieces[cm.fromColumn][cm.fromRow],false,this.moveAnimationLength,false,false);
if(clog){
if(this.currentMove){
console.log("popped up from variation, current set back to:"+this.currentMove.output());
}else{
console.log("popped up from variation, current set to null");
}
}
}
move=_1e7;
}
if(_1e3){
this.gotoMoveIndex(-1,false,false,false,false);
}
if(clog){
var m=this.currentMove;
while(m){
console.log("m:"+m.output());
m=m.next;
}
}
if(ctime&&_1e3){
console.timeEnd("insertMovesFromMoveList");
}
};
Board.prototype.setupFromLalgArrayIncremental=function(_1f0,_1f1,_1f2,_1f3){
this.outputFirstVar=false;
if(this.movesDisplay&&this.lastCount){
this.movesDisplay.pendingLevelZeroCommentaryClose=false;
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 _1f6=0;
var _1f7=_1f2*2-1;
var _1f8="";
var _1f9=false;
var _1fa=false;
var _1fb=ChessPiece.WHITE;
var _1fc=false;
var _1fd=true;
this.currentMove=null;
for(var i=0;i<_1f0.length;i++){
if(_1f0[i]=="}"){
_1fc=false;
if(this.movesDisplay){
_1f8=_1f8.replace(/\s+$/g,"");
}
continue;
}else{
if(_1fc){
_1f8+=_1f0[i]+" ";
continue;
}else{
if(_1f0[i]=="{"){
_1f8="";
_1fc=true;
continue;
}else{
if(_1f0[i]=="("){
_1f9=true;
continue;
}else{
if(_1f0[i]==")"){
_1fa=true;
continue;
}else{
if(_1f0[i].charAt(0)=="$"){
continue;
}
}
}
}
}
}
var move=this.createMoveFromString(_1f0[i]);
var _1ff=false;
if(_1fd&&this.boardPieces[move.fromColumn][move.fromRow].colour==ChessPiece.BLACK){
_1f7++;
_1ff=true;
_1fb=ChessPiece.BLACK;
}
this.startMoveNum=_1f7;
_1fd=false;
move.index=_1f6++;
var _200=move.moveString;
_200=Board.moveToLocale(_200);
_1fb=(_1fb==ChessPiece.BLACK)?ChessPiece.WHITE:ChessPiece.BLACK;
this.insertMoveAfter(this.currentMove,move);
if(clog){
if(move.prev){
if(move.prev.next){
console.log("move.prev.next:"+move.prev.next.output());
}else{
console.log("move.prev:"+move.prev.output()+" next null");
}
}
}
this.makeMove(move,this.boardPieces[move.fromColumn][move.fromRow],false,this.moveAnimationLength,false,false);
this.setCurrentMove(move);
}
this.gotoMoveIndex(-1,false,false,false,false);
};
Board.prototype.displayPendingMoveList=function(){
if(this.pendingMovesOutput&&this.movesDisplay){
var _201=this.movesDisplay.getMovesDisplay();
if(_201){
_201.innerHTML=this.pendingMovesOutput;
var _202=new YAHOO.util.Scroll(_201,{scroll:{to:[0,0]}},0);
_202.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);
if(this.handleCommentClicks){
var _205=YAHOO.util.Dom.get(this.boardName+"-mcb"+i);
if(_205){
YAHOO.util.Event.addListener(_205,"click",this.movesDisplay.clickComment,this.movesDisplay,true);
}
_205=YAHOO.util.Dom.get(this.boardName+"-mca"+i);
if(_205){
YAHOO.util.Event.addListener(_205,"click",this.movesDisplay.clickComment,this.movesDisplay,true);
}
}
}
}
}
}
};
Board.prototype.setMoveSequence=function(_206,_207,_208,_209){
this.tacticMoveArray=new Array();
this.moveArray=this.tacticMoveArray;
this.setMoveSeqLalg(_206,this.tacticMoveArray,_208,_209);
this.tacticsmoveArrayLastMoveIndex=this.lastMoveIndex;
if(false&&_207!="NA"){
this.fullmoveArray=new Array();
this.disableMoveOutput=true;
this.setMoveSeqLalg(_207,this.fullmoveArray,_208,_209);
this.disableMoveOutput=false;
this.fullmoveArrayLastMoveIndex=this.lastMoveIndex;
}else{
this.fullmoveArray=null;
}
this.lastMoveIndex=this.tacticsmoveArrayLastMoveIndex;
};
Board.prototype.resetVariationsPreviousNodes=function(_20a,_20b){
if(_20a.numVars>0){
for(var i=0;i<_20a.numVars;i++){
_20a.vars[i].prev=_20b;
this.resetVariationsPreviousNodes(_20a.vars[i],_20b);
}
}
};
Board.prototype.reconnectNextNodeVariations=function(_20d,_20e){
if(!_20e){
return;
}
if(_20e.numVars>0){
for(var i=0;i<_20e.numVars;i++){
_20e.vars[i].prev=_20d;
this.reconnectNextNodeVariations(_20d,_20e.vars[i]);
}
}
};
Board.prototype.findFirstMoveFromList=function(move){
var m=move;
while(m&&m.prev!=null){
m=m.prev;
}
return m;
};
Board.prototype.findVariationHeadFromMove=function(move){
var m=move;
while(m&&m.prev&&m.prev.next==m){
m=m.prev;
}
if(m&&m.prev&&m.prev.next!=m){
return m;
}else{
if(m&&!m.prev){
var _214=this.moveArray[0];
if(m!=_214){
return m;
}
}
return null;
}
};
Board.prototype.liftVariation=function(_215){
if(!_215){
return;
}
var _216=null;
var _217=null;
if(_215.prev){
_216=_215.prev.next;
}else{
_216=this.moveArray[0];
_217=_215;
}
var _218=null;
if(this.currentMove&&this.currentMove.prev){
_218=this.currentMove.prev;
}
if(_216){
var _219=_216.numVars;
var vars=_216.vars;
_216.numVars=0;
_216.vars=[];
if(_215.numVars==0){
_215.vars=[];
}
for(var i=0;i<_219;i++){
var _21c=vars[i];
if(clog){
console.log("processing var:"+_21c.output());
}
if(_21c==_215){
if(clog){
console.log("inserted parent var");
}
_215.vars.push(_216);
_215.numVars++;
}else{
_215.vars.push(_21c);
_215.numVars++;
}
}
if(_215.prev){
_215.prev.next=_215;
}
if(clog){
console.log("finished moving variations");
}
if(!_217){
_217=this.findFirstMoveFromList(_215);
}
this.moveArray[0]=_217;
this.gotoMoveIndex(-1,true,true,true,true);
if(clog){
console.log("fm:"+_217.output());
}
this.insertMovesFromMoveList(_217);
}
if(_218){
this.gotoMoveIndex(_218.index);
}
};
Board.prototype.deleteMoveAndLine=function(move){
var m=move;
var oldM=m;
var _220=false;
var _221=null;
var _222=this.moveArray[0];
var _223=null;
if(clog){
console.log("delete line:"+move.output());
}
if(clog){
console.log("delete line prev:"+move.prev);
}
if(clog&&move.prev){
console.log("delete line prev.next:"+move.prev.next);
}
if(move&&move.prev&&move.prev.next!=move){
if(clog){
console.log("var is head and not front of move list");
}
_220=true;
_221=move.prev.next;
}else{
if(move&&!move.prev&&move!=this.moveArray[0]){
if(clog){
console.log("var is head and front of move list");
}
_220=true;
_221=this.moveArray[0];
}
}
if(clog){
console.log("isVariationHead:"+_220);
}
if(clog){
console.log("fm:"+_222.output());
}
var _224=m.prev;
if(_220){
_223=_221;
if(_221){
if(clog){
console.log("delete variation from parent:"+_221.output());
}
var _225=[];
for(var i=0;i<_221.numVars;i++){
if(!(_221.vars[i]==oldM)){
if(clog){
console.log("saving var:"+_221.vars[i].output());
}
_225.push(_221.vars[i]);
}else{
if(clog){
console.log("dropping var:"+_221.vars[i].output());
}
}
}
_221.vars=_225;
_221.numVars=_225.length;
}
}else{
if(_224){
_224.next=null;
_223=_224;
}else{
if(clog){
console.log("deleting entire list");
}
if(this.movesDisplay){
this.movesDisplay.firstNonMove=false;
YAHOO.util.Event.purgeElement(this.movesDisplay.getMovesDisplay(),true);
this.movesDisplay.pendingLevelZeroCommentaryClose=false;
}
var _227=this.movesDisplay.getMovesDisplay();
if(_227){
_227.innerHTML="";
}
this.currentMove=null;
this.startMoveNum=_222.moveNum;
if(clog){
console.log("startFen:"+this.startFen);
}
this.moveIndex=-1;
this.moveArray=[];
this.setupFromFen(this.startFen);
if(this.lastFromSquare){
YAHOO.util.Dom.removeClass(this.lastFromSquare,"ct-from-square");
}
if(this.lastToSquare){
YAHOO.util.Dom.removeClass(this.lastToSquare,"ct-to-square");
}
this.setForwardBack();
return;
}
}
this.moveArray[0]=_222;
this.gotoMoveIndex(-1,true,true,true,true);
if(clog){
console.log("fm:"+_222.output());
}
this.insertMovesFromMoveList(_222);
if(_223){
this.gotoMoveIndex(_223.index);
}
};
Board.prototype.insertMoveAfter=function(_228,_229,_22a,_22b,_22c,_22d){
addToMovelist=!_22a;
if(clog){
console.log("addToMovelist:"+addToMovelist);
}
var _22e="null";
if(_228){
_22e=_228.output();
}
if(clog){
console.log("insert newMove:"+_229.output()+" after:"+_22e);
}
if(_228==null){
this.currentMove=_229;
_229.atEnd=0;
_229.prev=null;
_229.next=null;
this.firstMove=_229;
if(this.startMoveNum>0){
this.currentMove.moveNum=this.startMoveNum;
}else{
if(this.toMove==ChessPiece.WHITE){
this.currentMove.moveNum=1;
}else{
this.currentMove.moveNum=2;
}
}
if(clog){
console.log("startMoveNum:"+this.startMoveNum+" currMoveNum:"+this.currentMove.moveNum);
}
}else{
_229.atEnd=_228.atEnd;
_229.prev=_228;
_228.atEnd=0;
if(clog){
if(_228.next){
console.log("prevMove.next:"+_228.next.output());
}
}
if(_229.equals(_228.next)||_229.equals(_228)){
if(clog){
console.log("inserting move that already exists in variation:"+_228.next.output());
}
var _22f=_228.next;
if(this.firstMove==_22f){
this.firstMove=_229;
}
if(_229.equals(_228)){
_22f=_228;
}
if(_22f.prev&&(_22f.prev.next==_22f)){
_22f.prev.next=_229;
}
if(_22f.next){
_22f.next.prev=_229;
}
addToMovelist=false;
_229.moveNum=_22f.moveNum;
_229.ravLevel=_22f.ravLevel;
_229.index=_22f.index;
_229.fen=_22f.fen;
_229.nextFen=_22f.nextFen;
_229.bestMoves=_22f.bestMoves;
_229.correctMove=_22f.correctMove;
_229.wrongMove=_22f.wrongMove;
_229.next=_22f.next;
_229.vars=_22f.vars;
_229.numVars=_22f.numVars;
this.reconnectNextNodeVariations(_229,_22f.next);
this.moveArray[_229.index]=_229;
if(this.currentMove==_22f){
this.setCurrentMove(_229);
}
}else{
_229.moveNum=_228.moveNum+1;
_229.ravLevel=_228.ravLevel;
_229.next=_228.next;
if(_229.next){
_229.next.prev=_229;
}
}
_228.next=_229;
}
if(addToMovelist){
this.insertIntoMoveDisplay(_228,_229,_22b,_22c,_22d);
}
if(_229.next==null){
var _230=this.createMoveFromString("i1i2");
_229.next=_230;
_230.prev=_229;
_230.moveNum=_229.moveNum+1;
_230.ravLevel=_229.ravLevel;
_230.next=null;
_230.atEnd=1;
_230.endNode=true;
if(clog){
console.log("created endmove node in insertAfterMove:"+_230.output());
}
}else{
if(clog){
console.log("allready had a node at end:"+_229.next.output());
}
_229.next.moveNum=_229.moveNum+1;
}
};
function insertBefore(node,_232){
if(_232){
_232.parentNode.insertBefore(node,_232);
}
}
function insertAfter(node,_234){
var _235=_234.parentNode;
_235.insertBefore(node,_234.nextSibling);
}
Board.prototype.replaceIntoMoveDisplay=function(_236,_237,_238,_239,_23a){
var _23b="null";
if(_236){
_23b=_236.output();
}
if(clog){
console.log("replace display newMove:"+_237.output()+" after:"+_23b+" hideScore:"+_239);
}
if(!_236){
if(clog){
console.log("null oldMove");
}
this.insertIntoMoveDisplay(null,_237,false,_239);
}else{
if(clog){
console.log("about to get movesdsiplay in replace into move display:"+this.movesDisplay);
}
var _23c=this.movesDisplay.getMovesDisplay();
if(clog){
console.log("got moves display");
}
if(!_23c){
if(clog){
console.log("no movesd disiplay in replace into move display");
}
return;
}
var san=_237.SAN;
if(!san){
if(clog){
console.log("about to make san");
}
san=this.makeShortAlgabraic(_237.fromColumn,_237.fromRow,_237.toColumn,_237.toRow,_237);
if(clog){
console.log("about to made san:"+san);
}
_237.SAN=san;
}
if(clog){
console.log("oldMove.index:"+_236.index);
}
var _23e=this.boardName+"-ms"+_236.index;
if(clog){
console.log("oldMoveId:"+_23e);
}
var _23f=YAHOO.util.Dom.get(_23e);
if(_238){
this.moveIndex++;
_237.index=this.moveIndex;
this.moveArray[this.moveIndex]=_237;
if(clog){
console.log("replace as variation old:"+_236.output()+" new:"+_237.output());
}
var _240=document.createElement("span");
var _241=this.movesDisplay.outputVariationStart(0,0,_237.moveNum,0);
_237.ravLevel=_236.ravlevel+1;
var _23b=Board.moveToLocale(san);
if(_237.prev==null){
this.movesDisplay.firstNonMove=false;
}
var _242=this.movesDisplay.outputMove(this.moveIndex,_237.ravLevel,_237.moveNum,_23b,_238,0,_237.moveNum,_237,_239,_23a);
var _243=document.createElement("span");
_243.id=(this.boardName+"-ms"+_237.index);
_243.innerHTML=_242+"&nbsp;";
var _244=this.movesDisplay.outputVariationEnd(0,0,_237.moveNum,0);
this.movesDisplay.firstNonMove=true;
var _245=document.createElement("span");
_245.innerHTML=_241;
var _246=document.createElement("span");
_246.innerHTML=_244;
_240.appendChild(_245);
_240.appendChild(_243);
_240.appendChild(_246);
_23f.appendChild(_240);
}else{
_237.index=_236.index;
this.moveArray[_237.index]=_237;
var _23b=Board.moveToLocale(san);
if(_237.prev==null){
this.movesDisplay.firstNonMove=false;
}
var _242=this.movesDisplay.outputMove(_237.index,_237.ravLevel,_237.moveNum,_23b,_238,0,_237.moveNum,_237,_239,_23a);
var _243=document.createElement("span");
_243.innerHTML=_242+"&nbsp;";
_243.id=(this.boardName+"-ms"+_237.index);
var _247=[];
if(_23f&&_23f.childNodes){
for(var i=1;i<_23f.childNodes.length;i++){
_247[i-1]=_23f.childNodes[i];
}
}
if(clog){
console.log("replace as main line not variation old:"+_236.output()+" new:"+_237.output());
}
_23f.parentNode.replaceChild(_243,_23f);
if(_247){
for(var i=0;i<_247.length;i++){
_243.appendChild(_247[i]);
}
}
}
YAHOO.util.Event.removeListener(this.boardName+"-m"+_237.index);
YAHOO.util.Event.addListener((this.boardName+"-m"+_237.index),"click",this.movesDisplay.gotoMove,this.movesDisplay,true);
}
};
Board.prototype.insertCommentIntoMoveDisplay=function(move,_24a,_24b){
var _24c=this.movesDisplay.getMovesDisplay();
if(!_24c){
return;
}
var _24d="b";
if(_24b){
_24d="a";
}
if(move){
var _24e=this.boardName+"-mc"+_24d+move.index;
var _24f=YAHOO.util.Dom.get(_24e);
var _250=false;
if(!_24f){
_24f=document.createElement("span");
_24f.id=_24e;
_250=true;
}
_24f.innerHTML=this.movesDisplay.outputComment(_24a,0);
var _251=YAHOO.util.Dom.get((this.boardName+"-m"+move.index));
if(_251){
if(_24b){
move.afterComment=_24a;
if(_250){
insertAfter(_24f,_251);
}
}else{
move.beforeComment=_24a;
if(_250){
insertBefore(_24f,_251);
}
}
}
if(_24f&&_250&&this.handleCommentClicks){
YAHOO.util.Event.addListener(_24f,"click",this.movesDisplay.clickComment,this.movesDisplay,true);
}
}else{
}
};
Board.prototype.insertIntoMoveDisplay=function(_252,_253,_254,_255,_256){
var _257=this.movesDisplay.getMovesDisplay();
if(!_257){
return;
}
var _258="null";
if(_252){
_258=_252.output();
}
if(clog){
console.log("insert display newMove:"+_253.output()+" after:"+_258);
}
var san=_253.SAN;
if(!san){
san=this.makeShortAlgabraic(_253.fromColumn,_253.fromRow,_253.toColumn,_253.toRow,_253);
_253.SAN=san;
}
this.moveIndex++;
_253.index=this.moveIndex;
this.moveArray[this.moveIndex]=_253;
var _258=Board.moveToLocale(san);
var _25a=this.movesDisplay.outputMove(this.moveIndex,_253.ravLevel,_253.moveNum,_258,false,0,_253.moveNum,_253,_255,_256);
var _25b=document.createElement("span");
_25b.innerHTML=_25a+"&nbsp;";
_25b.id=(this.boardName+"-ms"+this.moveIndex);
if(_254){
YAHOO.util.Dom.setStyle(_25b,"visibility","hidden");
}
if(_252){
if(clog){
console.log("prevMove.index:"+_252.index+"prevMove:"+_252.output());
}
var _25c=YAHOO.util.Dom.get((this.boardName+"-ms"+_252.index));
if(_25c){
insertAfter(_25b,_25c);
}else{
_257.appendChild(_25b);
}
}else{
if(_253.next){
var _25d=YAHOO.util.Dom.get((this.boardName+"-ms"+_253.next.index));
insertBefore(_25b,_25d);
}else{
_257.appendChild(_25b);
}
}
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(_25e,_25f,_260,_261,_262,_263){
var _264="null";
if(_25e){
_264=_25e.output();
}
if(clog){
console.log("replace newMove:"+_25f.output()+" after:"+_264+" replace as var"+_260+" rep move display:"+_261+" hideScore:"+_262);
if(_25e&&_25e.prev){
console.log("replace oldMove.prev:"+_25e.prev.output());
}
if(_25e&&_25e.next){
console.log("replace oldMove.next:"+_25e.next.output());
}
}
var _265=false;
var _266=null;
var _267=0;
if(_25e.endNode){
if(clog){
console.log("asked to replace endNode,inserting before instead");
}
this.insertMoveAfter(_25e.prev,_25f,false,false,_262,_263);
_25f.fen=_25e.fen;
_25f.nextFen=_25e.nextFen;
return;
}
if(_25f.equals(_25e)){
if(clog){
console.log("new move is same as old move so not replacing as variation");
}
_260=false;
}else{
if(_25e&&_25e.numVars>0){
for(var i=0;i<_25e.numVars;i++){
var _269=_25e.vars[i];
if(_25f.equals(_269)){
if(clog){
console.log("new move is same as an existing variation varNum:"+i);
console.log("variation:"+_269.output());
if(_269.next){
console.log("variation next:"+_269.next.output());
}
}
_265=true;
_266=_25e;
_25e=_269;
_267=i;
break;
}
}
}
}
if(_25e==null){
if(clog){
console.log("replaced new move with null oldmove");
}
this.currentMove=_25f;
_25f.atEnd=1;
_25f.next=null;
_25f.prev=null;
if(this.startPositionAfterOpponentMove){
_25f.fen=this.startPositionAfterOpponentMove;
_25f.nextFen=null;
}
if(this.toMove==ChessPiece.WHITE){
this.currentMove.moveNum=1;
}else{
this.currentMove.moveNum=2;
}
this.firstMove=_25f;
}else{
var _26a=false;
if(_25e&&_25e.prev&&_25e.prev.next!=_25e){
_26a=true;
}
if(this.currentMove==_25e&&!_260){
this.currentMove=_25f;
}else{
if(clog){
console.log("not setting current move in replacemove");
}
}
_25f.atEnd=_25e.atEnd;
_25f.prev=_25e.prev;
_25f.next=_25e.next;
_25f.fen=_25e.fen;
_25f.nextFen=_25e.nextFen;
_25f.bestMoves=_25e.bestMoves;
_25f.correctMove=_25e.correctMove;
_25f.wrongMove=_25e.wrongMove;
_25f.moveNum=_25e.moveNum;
_25f.ravLevel=_25e.ravLevel;
_25f.index=_25e.index;
if(clog){
console.log("replacingVariation with var not null:"+_265);
}
if(_265){
_266.vars[_267]=_25f;
_25f.vars=_25e.vars;
_25f.numVars=_25e.numVars;
this.reconnectNextNodeVariations(_25f,_25e.next);
if(_25e.next){
_25e.next.prev=_25f;
}
this.moveArray[_25f.index]=_25f;
if(clog){
console.log("replacing existing sub variation of main line");
if(_25f.next){
console.log("next of replacement variation:"+_25f.next.output());
}
}
return;
}
if(!_260){
if(clog){
console.log("not replacing as variation");
}
if(!_26a&&_25e.prev){
_25e.prev.next=_25f;
}
if(_25e.next){
_25e.next.prev=_25f;
}
_25f.vars=_25e.vars;
_25f.numVars=_25e.numVars;
this.reconnectNextNodeVariations(_25f,_25e.next);
if(this.firstMove==_25e){
this.firstMove=_25f;
}
this.moveArray[_25f.index]=_25f;
}else{
if(clog){
console.log("replacing as variation");
}
if(_25e.numVars==0){
_25e.vars=new Array();
}
_25e.vars[_25e.numVars++]=_25f;
_25e.atEnd=0;
_25f.next=null;
var _26b=this.createMoveFromString("i1i2");
_25f.next=_26b;
_26b.prev=_25f;
_26b.next=null;
_26b.atEnd=1;
_26b.moveNum=_25f.moveNum+1;
_26b.ravLevel=_25f.ravLevel;
_26b.endNode=true;
}
}
if(_261){
this.replaceIntoMoveDisplay(_25e,_25f,_260,_262,_263);
}
};
Board.prototype.setCurrentMove=function(move,_26d,_26e){
if(!this.cloned&&this.currentMove!=null){
if(this.currentMove.prev!=null){
YAHOO.util.Dom.removeClass(this.boardName+"-m"+this.currentMove.prev.index,"ct-board-move-current");
}
}
this.currentMove=move;
if(!this.cloned&&this.currentMove!=null&&this.currentMove.prev!=null){
var _26f=this.boardName+"-m"+this.currentMove.prev.index;
if(clog){
console.log("setCurrentMove attempted highlight of id:"+_26f+" for move:"+move.output());
}
var span=YAHOO.util.Dom.get(_26f);
if(span){
var cls=span.className;
YAHOO.util.Dom.addClass(span,"ct-board-move-current");
if(this.autoScrollMoves){
if(!_26e&&(this.scrollVariations||cls.indexOf("ct-board-move-variation")==-1)){
var _272=this.movesDisplay.getMovesDisplay();
if(_272){
var y=YAHOO.util.Dom.getY(span)-YAHOO.util.Dom.getY(_272);
var _274=new YAHOO.util.Scroll(_272,{scroll:{by:[0,y]}},this.moveAnimationLength,YAHOO.util.Easing.easeOut);
_274.animate();
}
}
}
}
}else{
if(move==null){
if(clog){
console.log("attempted to set current move on null node");
}
}
}
if(!_26d){
this.setForwardBack();
}
};
Board.INITIAL_FEN="rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1";
Board.prototype.boardToFen=function(_275){
var _276="";
for(var row=7;row>=0;row--){
var _278=0;
var line="";
if(row<7){
line="/";
}
for(var col=0;col<8;col++){
var _27b=this.boardPieces[col][row];
if(_27b){
var _27c="";
if(_278>0){
_27c=_278+"";
}
line+=_27c+_27b.getFenLetter();
_278=0;
}else{
_278++;
}
}
if(_278>0){
line+=_278+"";
}
_276+=line;
}
var fen=_276;
var _27e=" w ";
if(_275){
if(this.toMove==ChessPiece.WHITE){
_27e=" b ";
}
}else{
if(this.toMove==ChessPiece.BLACK){
_27e=" b ";
}
}
fen+=_27e;
var _27f="";
_27f+=Board.getFenCastleChar(this.canCastleKingSide,"K",ChessPiece.WHITE);
_27f+=Board.getFenCastleChar(this.canCastleQueenSide,"Q",ChessPiece.WHITE);
_27f+=Board.getFenCastleChar(this.canCastleKingSide,"K",ChessPiece.BLACK);
_27f+=Board.getFenCastleChar(this.canCastleQueenSide,"Q",ChessPiece.BLACK);
if(_27f==""){
fen+="- ";
}else{
fen+=_27f+" ";
}
var _280=null;
if(this.currentMove){
if(this.currentMove.prev){
_280=this.currentMove.prev;
}else{
_280=this.prev_move;
}
}else{
_280=this.prev_move;
}
var _281="- ";
if(_280){
if(_280){
var _282=this.boardPieces[_280.toColumn][_280.toRow];
if(_282){
if(_282.piece==ChessPiece.PAWN){
if(_282.colour==ChessPiece.WHITE){
if(_280.fromRow==1&&_280.toRow==3){
_281=Move.columnToChar(_280.fromColumn)+"3 ";
}
}else{
if(_280.fromRow==6&&_280.toRow==4){
_281=Move.columnToChar(_280.fromColumn)+"6 ";
}
}
}
}
}
}
fen+=_281;
fen+=this.halfMoveNumber+" "+parseInt((this.moveNumber+1)/2);
if(clog){
console.log("moveNumber:"+this.moveNumber+" fen:"+fen);
}
return fen;
};
Board.getFenCastleChar=function(_283,_284,_285){
if(_283[_285]){
if(_285==ChessPiece.WHITE){
return _284.toUpperCase();
}else{
return _284.toLowerCase();
}
}
return "";
};
Board.prototype.getCastlingString=function(_286){
var _287=_js("None");
if(this.canCastleKingSide[_286]){
_287="O-O";
}
if(this.canCastleQueenSide[_286]){
if(_287==_js("None")){
_287="O-O-O";
}else{
_287+=",O-O-O";
}
}
return _287;
};
Board.prototype.updateToPlay=function(){
if(this.disableUpdateToPlay){
return;
}
if(this.showToMoveIndicators){
if(this.isFlipped){
YAHOO.util.Dom.setStyle(this.boardName+"-top-to-move-inner","background-color","white");
YAHOO.util.Dom.setStyle(this.boardName+"-top-to-move-inner","border","1px solid black");
YAHOO.util.Dom.setStyle(this.boardName+"-bottom-to-move-inner","background-color","black");
YAHOO.util.Dom.setStyle(this.boardName+"-bottom-to-move-inner","border","1px solid white");
}else{
YAHOO.util.Dom.setStyle(this.boardName+"-bottom-to-move-inner","background-color","white");
YAHOO.util.Dom.setStyle(this.boardName+"-bottom-to-move-inner","border","1px solid black");
YAHOO.util.Dom.setStyle(this.boardName+"-top-to-move-inner","background-color","black");
YAHOO.util.Dom.setStyle(this.boardName+"-top-to-move-inner","border","1px solid white");
}
if(this.toMove==ChessPiece.WHITE){
if(this.isFlipped){
YAHOO.util.Dom.addClass(this.boardName+"-top-to-move-outer","ct-to-move-active");
YAHOO.util.Dom.removeClass(this.boardName+"-bottom-to-move-outer","ct-to-move-active");
}else{
YAHOO.util.Dom.addClass(this.boardName+"-bottom-to-move-outer","ct-to-move-active");
YAHOO.util.Dom.removeClass(this.boardName+"-top-to-move-outer","ct-to-move-active");
}
}else{
if(this.isFlipped){
YAHOO.util.Dom.addClass(this.boardName+"-bottom-to-move-outer","ct-to-move-active");
YAHOO.util.Dom.removeClass(this.boardName+"-top-to-move-outer","ct-to-move-active");
}else{
YAHOO.util.Dom.addClass(this.boardName+"-top-to-move-outer","ct-to-move-active");
YAHOO.util.Dom.removeClass(this.boardName+"-bottom-to-move-outer","ct-to-move-active");
}
}
}
var _288=YAHOO.util.Dom.get("toPlay");
if(_288==null){
return;
}
if(this.toMove==ChessPiece.WHITE){
_288.src="/images/whiteknight"+this.getVersString()+".gif";
_288.alt=_js("White to play");
}else{
_288.src="/images/blackknight"+this.getVersString()+".gif";
_288.alt=_js("Black to play");
}
var _289=YAHOO.util.Dom.get("fenStatus");
if(_289){
var _28a=this.getCastlingString(ChessPiece.BLACK);
var _28b=this.getCastlingString(ChessPiece.WHITE);
var s="<div><span>"+_js("White Castling: ")+"</span><span>"+_28b+"</span></div>"+"<div><span>"+_js("Black Castling: ")+"</span><span>"+_28a+"</span></div>";
_289.innerHTML=s;
}
};
Board.prototype.getBoardDivFromId=function(id){
if(!this[id]){
this[id]=YAHOO.util.Dom.get(id);
}
return this[id];
};
Board.prototype.getBoardDiv=function(){
if(!this.boardDiv){
this.boardDiv=YAHOO.util.Dom.get("ctb-"+this.boardName);
}
return this.boardDiv;
};
Board.prototype.getDocBody=function(){
if(!this.docBody){
var _28e=document.getElementsByTagName("body");
if(_28e==null||_28e.length==0){
alert("Could not find body tag");
}else{
this.docBody=_28e[0];
}
}
return this.docBody;
};
Board.prototype.getPieceDragDiv=function(){
if(!this.pieceDragDiv){
this.pieceDragDiv=YAHOO.util.Dom.get("pieceDragDiv");
}
return this.pieceDragDiv;
};
Board.prototype.createBoardCoords = function() {
    this.coordinatesShown = false;
    var _28f = YAHOO.util.Dom.get(this.boardName + "-fileLabels");
    var _290 = YAHOO.util.Dom.get(this.boardName + "-rankLabels");
    if (!_28f || !_290) {
        return;
    }
    YAHOO.util.Event.purgeElement(_28f, true);
    _290.innerHTML = "";
    _28f.innerHTML = "";
    var _291 = YAHOO.util.Dom.get(this.boardName + "-boardBorder");
    if (!this.showCoordinates) {
        YAHOO.util.Dom.setStyle(_28f, "display", "none");
        YAHOO.util.Dom.setStyle(_290, "display", "none");
        var _292 = 0;
        YAHOO.util.Dom.setStyle(_291, "width", (this.pieceSize * 8 + _292) + "px");
        YAHOO.util.Dom.setStyle(_291, "height", (this.pieceSize * 8 + _292) + "px");
        return;
    }
    YAHOO.util.Dom.setStyle(_28f, "display", "block");
    YAHOO.util.Dom.setStyle(_290, "display", "block");
    var _292 = 15;
    var _293 = 0;
    if (check_bad_msie()) {
        _293 = this.ie6FixCoordsOffsetSize;
    }
    if (YAHOO.util.Event.isIE) {
        _293 += this.allIeFixCoordsOffsetSize;
        if (document.compatMode != "CSS1Compat") {
            _293 = 8;
        }
    }
    YAHOO.util.Dom.setStyle(_291, "width", (this.pieceSize * 8 + _292 + _293) + "px");
    YAHOO.util.Dom.setStyle(_291, "height", (this.pieceSize * 8 + _292) + "px");
    this.coordinatesShown = true;

    for (var i = 0; i < 8; i++) {
        var _295 = document.createElement("div");
        YAHOO.util.Dom.setStyle(_295, "height", this.pieceSize + "px");
        YAHOO.util.Dom.setStyle(_295, "width", "15px");
        YAHOO.util.Dom.setStyle(_295, "text-align", "center");
        YAHOO.util.Dom.setStyle(_295, "line-height", this.pieceSize + "px");
        if (this.isFlipped) {
            _295.innerHTML = "" + (i + 1);
        } else {
            _295.innerHTML = "" + 9 - (i + 1);
        }
        _290.appendChild(_295);
    }
    for (var i = 0; i < 9; i++) {
        var _296 = document.createElement("span");
        YAHOO.util.Dom.setStyle(_296, "float", "left");
        YAHOO.util.Dom.setStyle(_296, "height", "15px");
        if (i == 0) {
            YAHOO.util.Dom.setStyle(_296, "width", "15px");
            YAHOO.util.Dom.setStyle(_296, "clear", "both");
            YAHOO.util.Dom.setStyle(_296, "margin-top", "-5px");
            if (_293) {
                YAHOO.util.Dom.setStyle(_296, "margin-left", "-3px");
            } else {
                YAHOO.util.Dom.setStyle(_296, "margin-left", "-2px");
            }
            var _297 = "";
            if (this.isFlipped) {
                _297 = "whiteblack-flipper" + this.getVersString() + ".png";
            } else {
                _297 = "blackwhite-flipper" + this.getVersString() + ".png";
            }
            _296.innerHTML = "<span><img id=\"" + this.boardName + "-flipper\" title=\"" + _js("Tábla forgatás") + "\" src=\"" + this.boardImagePath + "/images/" + _297 + "\"/></span>";
            YAHOO.util.Event.addListener(this.boardName + "-flipper", "click", this.flipBoard, this, true);
        } else {
            YAHOO.util.Dom.setStyle(_296, "width", this.pieceSize + "px");
            YAHOO.util.Dom.setStyle(_296, "text-align", "center");
            if (this.isFlipped) {
                _296.innerHTML = _js(Move.columnToChar(8 - (i)));
            } else {
                _296.innerHTML = _js(Move.columnToChar((i - 1)));
            }
        }
        _28f.appendChild(_296);
    }
    var _298 = YAHOO.util.Dom.get(this.boardName + "-flipper");
    if (_298) {
        fix_ie_png(_298);
    }
};
Board.prototype.createBoardUI = function() {
    var _299 = this.boardName + "-container";
    var _29a = YAHOO.util.Dom.get(_299);
    if (_29a == null) {
        alert("Could not find board container:" + _299);
        return;
    }
    YAHOO.util.Dom.addClass(_29a, "ct-board-container");
    this.boardDiv = null;
    var _29b = document.createElement("div");
    _29b.id = this.boardName + "-boardBorder";
    YAHOO.util.Dom.addClass(_29b, "ct-board-border" + this.squareColorClass);
    var _29c = 0;
    if (this.showCoordinates) {
        _29c = 15;
    }
    YAHOO.util.Dom.setStyle(_29b, "width", (this.pieceSize * 8 + _29c) + "px");
    YAHOO.util.Dom.setStyle(_29b, "height", (this.pieceSize * 8 + _29c) + "px");
    var _29d = document.createElement("div");
    YAHOO.util.Dom.setStyle(_29d, "float", "left");
    _29d.id = this.boardName + "-rankLabels";
    _29b.appendChild(_29d);
    var _29e = document.createElement("div");
    YAHOO.util.Dom.addClass(_29e, "ct-board");
    YAHOO.util.Dom.setStyle(_29e, "width", (this.pieceSize * 8) + "px");
    YAHOO.util.Dom.setStyle(_29e, "height", (this.pieceSize * 8) + "px");
    _29e.id = "ctb-" + this.boardName;
    var _29f = "ct-white-square" + this.squareColorClass;
    var _2a0 = "";
    var _2a1 = [];
    for (var i = 7; i >= 0; i--) {
        var s = "<div>";
        for (var j = 0; j < 8; j++) {
            var _2a5 = document.createElement("div");
            var _2a6 = this.boardName + "-s" + j + "" + i;
            var _2a7 = (((j + 1) * (i + 1)) % 19 / 19 * 100);
            var _2a8 = ((65 - ((j + 1) * (i + 1))) % 19 / 19 * 100);
            s += "<div id=\"" + _2a6 + "\" class=\"" + _29f + "\" style=\"width:" + this.pieceSize + "px;height:" + this.pieceSize + "px;background-position:" + _2a7 + "% " + _2a8 + "%\"></div>";
            _2a1.push(_2a6);
            _29f = (_29f == "ct-black-square" + this.squareColorClass) ? "ct-white-square" + this.squareColorClass : "ct-black-square" + this.squareColorClass;
        }
        _29f = (_29f == "ct-black-square" + this.squareColorClass) ? "ct-white-square" + this.squareColorClass : "ct-black-square" + this.squareColorClass;
        s += "</div>";
        _2a0 += s;
    }
    _29e.innerHTML = _2a0;
    var _2a9 = document.createElement("div");
    _2a9.id = this.boardName + "-fileLabels";
    _29b.appendChild(_29e);
    _29b.appendChild(_2a9);
    _29a.appendChild(_29b);
    if (this.showToMoveIndicators) {
        var _2aa = document.createElement("div");
        _2aa.id = this.boardName + "-moveIndicators";
        YAHOO.util.Dom.addClass(_2aa, "ct-move-indicators");
        _2aa.innerHTML = "<div class=\"ct-top-to-move-outer\" id=\"" + this.boardName + "-top-to-move-outer\"><div  class=\"ct-top-to-move-inner\" id=\"" + this.boardName + "-top-to-move-inner\"></div></div><div class=\"ct-bottom-to-move-outer\"  id=\"" + this.boardName + "-bottom-to-move-outer\"><div class=\"ct-bottom-to-move-inner\" id=\"" + this.boardName + "-bottom-to-move-inner\" ></div>";
        _29a.appendChild(_2aa);
        YAHOO.util.Dom.setStyle(_29b, "float", "left");
        YAHOO.util.Dom.setStyle(_2aa, "float", "left");
        YAHOO.util.Dom.setStyle(_2aa, "margin-left", "2px");
        YAHOO.util.Dom.setStyle(_2aa, "height", ((this.pieceSize * 8) + 2) + "px");
        YAHOO.util.Dom.setStyle(_2aa, "position", "relative");
        var _2ab = document.createElement("div");
        YAHOO.util.Dom.setStyle(_2ab, "clear", "both");
        _29a.appendChild(_2ab);
    }
    //    this.createBoardCoords() BUG ha pgn stringet töltök be akkor duplán fut le;
    var _2ac = YAHOO.util.Dom.get(this.boardName + "-ct-nav-container");
    if (!_2ac) {
        _2ac = document.createElement("div");
    } else {
        _2ac.innerHTML = "";
    }
    _2ac.id = this.boardName + "-ct-nav-container";
    if (!this.dontOutputNavButtons || this.r) {
        var _2ad = "";
        if (!this.dontOutputNavButtons) {
            if (!this.problem || !this.problem.isEndgame) {
                _2ad = "<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("Ugrás végére") + "\"/>" + "<img class=\"ct-play\" id=\"" + this.boardName + "-play\" src=\"" + this.boardImagePath + "/images/control_play_blue" + this.getVersString() + ".gif\" alt=\"" + _js("Play moves") + "\" title=\"" + _js("Visszajátszás indítása") + "\"/>" + "<img class=\"ct-stop\" id=\"" + this.boardName + "-stop\" src=\"" + this.boardImagePath + "/images/control_stop_blue" + this.getVersString() + ".gif\" alt=\"" + _js("Stop playing") + "\" title=\"" + _js("Visszajátszás megállítása") + "\"/></span>";
            }
        }
        var _2ae = "<div class=\"ct-nav-buttons\" id=\"" + this.boardName + "-navButtons\"><span id=\"" + this.boardName + "-nav-buttons-only\">";
        if (!this.dontOutputNavButtons) {
            var size = "";
            if (isIphone) {
                size = " width=\"50px\" height=\"34px\" ";
                _2ad = "";
            }
            if (!isIphone) {
                _2ae += "<img class=\"ct-start\" id=\"" + this.boardName + "-start\" src=\"" + this.boardImagePath + "/images/resultset_first" + this.getVersString() + ".gif\" alt=\"" + _js("Start position") + "\" title=\"" + _js("Ugrás kezdésre") + "\"/>";
            }
            _2ae += "<img class=\"ct-back\" id=\"" + this.boardName + "-back\" " + size + " src=\"" + this.boardImagePath + "/images/resultset_previous" + this.getVersString() + ".gif\" alt=\"" + _js("Previous Move") + "\" title=\"" + _js("Előző lépés") + "\"/>" + "<img class=\"ct-forward\" id=\"" + this.boardName + "-forward\" " + size + " src=\"" + this.boardImagePath + "/images/resultset_next" + this.getVersString() + ".gif\" alt=\"" + _js("Next Move") + "\" title=\"" + _js("Következő lépés") + "\"/>" + _2ad;
        }
        if (this.r) {
            _2ae += "<img class=\"ct-forward\" id=\"" + this.boardName + "-analyse\" src=\"" + this.boardImagePath + "/images/anboard" + this.getVersString() + ".gif\" alt=\"" + _js("Analyse") + "\" title=\"" + _js("Launch analysis board to explore different lines in this position") + "\"/>";
            if (!this.g) {
                _2ae += "<img class=\"ct-forward\" id=\"" + this.boardName + "-showfen\" src=\"" + this.boardImagePath + "/images/copy_fen" + this.getVersString() + ".gif\" alt=\"" + _js("Copy FEN") + "\" title=\"" + _js("Show FEN for current position") + "\"/>";
            }
        }
        if (this.canPasteFen) {
            _2ae += "<img class=\"ct-forward\" id=\"" + this.boardName + "-pastefen\" src=\"" + this.boardImagePath + "/images/paste_fen" + this.getVersString() + ".gif\" alt=\"" + _js("Input FEN") + "\" title=\"" + _js("Setup position from user supplied FEN or move list") + "\"/>";
        }
        _2ae += "</span>";
        _2ae += "</div>";
        if (this.puzzle) {
            var _2b0 = "";
            var _2b1 = "";
            var _2b2 = "";
            var _2b3 = "";
            if (this.pieceSize >= 29) {
                _2b0 = _js("Easy");
                _2b1 = _js("Medium");
                _2b2 = _js("Hard");
                _2b3 = _js("Help");
            } else {
                _2b0 = _js("D1");
                _2b1 = _js("D2");
                _2b2 = _js("D3");
                _2b3 = _js("?");
            }
            _2ae += "<div><form action=\"\"><button type=\"button\" id=\"" + this.boardName + "-puzzleSolution\" class=\"asolution-button\">" + _js("Show") + "</button><button id=\"" + this.boardName + "-easyPuzzle\" type=\"button\" class=\"puzzle-difficulty\">" + _2b0 + "</button>" + "<button id=\"" + this.boardName + "-mediumPuzzle\" type=\"button\" class=\"puzzle-difficulty\">" + _2b1 + "</button>" + "<button id=\"" + this.boardName + "-hardPuzzle\" type=\"button\" class=\"puzzle-difficulty\">" + _2b2 + "</button>" + "<button id=\"" + this.boardName + "-puzzleHelp\" type=\"button\" class=\"puzzle-difficulty\">" + _2b3 + "</button>" + "<img alt=\"\" class=\"ct-forward\" id=\"" + this.boardName + "-problemState\"></img><span id=\"" + this.boardName + "-puzzleResult\"></span></form></div>";
            _2ae += "<div class=\"initially_hidden initially_invisible\" id=\"" + this.boardName + "-moves\"></div>";
            _2ae += "<div class=\"initially_hidden initially_invisible\" id=\"" + this.boardName + "-moves\"></div>";
        }
        _2ac.innerHTML = _2ae;
    }
    _29a.appendChild(_2ac);
    if (this.problem) {
        var body = YAHOO.util.Dom.get("body");
        if (body) {
            YAHOO.util.Dom.setStyle(body, "min-width", ((this.pieceSize * 8 + _29c) + 300 + 200 + 120) + "px");
        }
    }
};
Board.prototype.getPieceDiv=function(){
var _2b5=this.getBoardDiv();
var _2b6=document.createElement("div");
this.availPieceDivs[this.uptoId]=_2b6;
this.availIds[this.uptoId]=YAHOO.util.Dom.generateId(_2b6);
YAHOO.util.Dom.setStyle(_2b6,"visibility","hidden");
YAHOO.util.Dom.addClass(_2b6,"board-piece-start-style");
_2b5.appendChild(_2b6);
this.uptoId++;
return _2b6;
};
Board.prototype.flipToMove=function(_2b7){
return (_2b7=="w")?"b":"w";
};
Board.prototype.pieceCharToPieceNum=function(_2b8){
var _2b9;
switch(_2b8){
case "K":
_2b9=ChessPiece.KING;
break;
case "Q":
_2b9=ChessPiece.QUEEN;
break;
case "R":
_2b9=ChessPiece.ROOK;
break;
case "B":
_2b9=ChessPiece.BISHOP;
break;
case "N":
_2b9=ChessPiece.KNIGHT;
break;
case "P":
_2b9=ChessPiece.PAWN;
break;
}
return _2b9;
};
Board.prototype.pieceTypeToChar=function(_2ba){
switch(_2ba){
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(_2bb,_2bc,_2bd,_2be){
if(_2bb+2==_2bd&&_2bc+1==_2be){
return true;
}
if(_2bb+2==_2bd&&_2bc-1==_2be){
return true;
}
if(_2bb-2==_2bd&&_2bc+1==_2be){
return true;
}
if(_2bb-2==_2bd&&_2bc-1==_2be){
return true;
}
if(_2bb+1==_2bd&&_2bc+2==_2be){
return true;
}
if(_2bb-1==_2bd&&_2bc+2==_2be){
return true;
}
if(_2bb+1==_2bd&&_2bc-2==_2be){
return true;
}
if(_2bb-1==_2bd&&_2bc-2==_2be){
return true;
}
return false;
};
Board.prototype.canMovePawn=function(_2bf,_2c0,_2c1,_2c2,_2c3){
var _2c4=this.boardPieces[_2c1][_2c2];
var _2c5=this.boardPieces[_2bf][_2c0];
if(_2c3){
var _2c6=this.boardPieces[_2c3.toColumn][_2c3.toRow];
if(_2c6.piece==ChessPiece.PAWN){
if(_2c6.colour==ChessPiece.WHITE){
if(_2c3.fromRow==1&&_2c3.toRow==3){
if(_2c1==_2c3.fromColumn&&_2c0==3&&_2c2==2&&(_2bf==_2c1+1||_2bf==_2c1-1)){
return true;
}
}
}else{
if(_2c3.fromRow==6&&_2c3.toRow==4){
if(_2c1==_2c3.fromColumn&&_2c0==4&&_2c2==5&&(_2bf==_2c1+1||_2bf==_2c1-1)){
return true;
}
}
}
}
}
if(_2c4){
if(_2c5.colour==ChessPiece.WHITE){
if((_2bf==_2c1+1||_2bf==_2c1-1)&&(_2c0==_2c2-1)){
return true;
}
}else{
if((_2bf==_2c1+1||_2bf==_2c1-1)&&(_2c0==_2c2+1)){
return true;
}
}
}else{
if(_2bf==_2c1){
if(_2c5.colour==ChessPiece.WHITE){
if(_2c0==1){
if(_2c2==2){
return true;
}else{
if(_2c2==3&&this.boardPieces[_2c1][2]==null){
return true;
}
}
}else{
if(_2c0+1==_2c2){
return true;
}
}
}else{
if(_2c0==6){
if(_2c2==5){
return true;
}else{
if(_2c2==4&&this.boardPieces[_2c1][5]==null){
return true;
}
}
}else{
if(_2c0-1==_2c2){
return true;
}
}
}
}
}
return false;
};
Board.prototype.canMoveStraight=function(_2c7,_2c8,_2c9,_2ca,_2cb,_2cc){
var _2cd=_2c7;
var _2ce=_2c8;
var _2cf=0;
var _2d0=0;
if(_2c9>_2c7){
_2cf=1;
}else{
if(_2c9<_2c7){
_2cf=-1;
}
}
if(_2ca>_2c8){
_2d0=1;
}else{
if(_2ca<_2c8){
_2d0=-1;
}
}
if(clog){
console.log("deltaRow:"+_2d0+" deltaCol:"+_2cf+" fromCol:"+_2c7+" fromRow:"+_2c8+" toCol:"+_2c9+" toRow:"+_2ca);
}
if(_2cb==ChessPiece.ROOK&&(_2cf!=0&&_2d0!=0)){
return false;
}
if(_2cb==ChessPiece.BISHOP&&(_2cf==0||_2d0==0)){
return false;
}
var _2d1=0;
while(true){
_2d1++;
_2c7+=_2cf;
_2c8+=_2d0;
if(_2cb==ChessPiece.KING&&_2d1>1){
if(clog){
console.log("king count:"+_2d1+" toCol:"+_2c9+" toRow:"+_2ca);
}
if(_2d1!=2){
return false;
}
if(_2d0!=0){
return false;
}
if(!(_2c9==6||_2c9==2)){
return false;
}
if(_2c9==2){
if(this.boardPieces[1][_2c8]||this.boardPieces[2][_2c8]||this.boardPieces[3][_2c8]){
return false;
}
if(!this.canCastleQueenSide[_2cc.colour]){
return false;
}
}else{
if(_2c9==6){
if(this.boardPieces[5][_2c8]||this.boardPieces[6][_2c8]){
if(clog){
console.log("king can't castle intervening piece");
}
return false;
}
if(!this.canCastleKingSide[_2cc.colour]){
if(clog){
console.log("king can't castle king side (made previously invalid) colour:"+_2cc.colour);
}
return false;
}
}else{
if(clog){
console.log("king not in col 2 or 6");
}
return false;
}
}
var _2d2="";
_2d2+=Move.columnToChar(_2cd);
_2d2+=String.fromCharCode("1".charCodeAt(0)+_2ce);
_2d2+=Move.columnToChar((_2cd+_2cf));
_2d2+=String.fromCharCode("1".charCodeAt(0)+(_2ce+_2d0));
var move=this.createMoveFromString(_2d2);
var _2d4=this.boardPieces;
var _2d5=this.toMove;
var _2d6=this.saveCastling();
this.boardPieces=this.copyBoardPieces(true);
this.makeMove(move,this.boardPieces[_2cd][_2ce],false,this.moveAnimationLength,false,false);
this.restoreCastling(_2d6);
kingSafe=this.isKingSafe(_2cc.colour,move);
boardPool.putObject(this.boardPieces);
this.boardPieces=_2d4;
_2d4.count--;
this.toMove=_2d5;
if(clog){
console.log("kingSafe1:"+kingSafe);
}
if(!kingSafe){
return false;
}
var _2d2="";
_2d2+=Move.columnToChar(_2cd);
_2d2+=String.fromCharCode("1".charCodeAt(0)+_2ce);
_2d2+=Move.columnToChar(_2cd);
_2d2+=String.fromCharCode("1".charCodeAt(0)+_2ce);
var move=this.createMoveFromString(_2d2);
var _2d4=this.boardPieces;
var _2d5=this.toMove;
var _2d6=this.saveCastling();
this.boardPieces=this.copyBoardPieces(true);
this.makeMove(move,this.boardPieces[_2cd][_2ce],false,this.moveAnimationLength,false,false);
this.restoreCastling(_2d6);
kingSafe=this.isKingSafe(_2cc.colour,move);
boardPool.putObject(this.boardPieces);
this.boardPieces=_2d4;
_2d4.count--;
this.toMove=_2d5;
if(clog){
console.log("kingSafe2:"+kingSafe);
}
if(!kingSafe){
return false;
}
}
if(_2c7==_2c9&&_2c8==_2ca){
return true;
}
if(_2c7<0||_2c7>7||_2c8<0||_2c8>7){
return false;
}
if(this.boardPieces[_2c7][_2c8]!=null){
return false;
}
}
};
Board.prototype.canMove=function(_2d7,_2d8,_2d9,_2da,_2db){
var _2dc=_2d7.column;
var _2dd=_2d7.row;
if(_2d8>7||_2d8<0||_2d9>7||_2d9<0){
if(clog){
console.log("can't move coz out of bounds");
}
return false;
}
var _2de=this.boardPieces[_2d8][_2d9];
var _2df=this.boardPieces[_2dc][_2dd];
if(_2df==null){
return false;
}
if(_2de&&_2de.colour==_2df.colour){
return false;
}
var _2e0=false;
if(_2d7.piece==ChessPiece.PAWN){
_2e0=this.canMovePawn(_2dc,_2dd,_2d8,_2d9,_2da);
}else{
if(_2d7.piece==ChessPiece.KNIGHT){
_2e0=this.canMoveKnight(_2dc,_2dd,_2d8,_2d9);
}else{
_2e0=this.canMoveStraight(_2dc,_2dd,_2d8,_2d9,_2d7.piece,_2d7);
}
}
if(clog){
console.log("moveOk:"+_2e0);
}
var _2e1=true;
if(_2e0&&_2db){
var _2e2="";
_2e2+=Move.columnToChar(_2dc);
_2e2+=String.fromCharCode("1".charCodeAt(0)+_2dd);
_2e2+=Move.columnToChar(_2d8);
_2e2+=String.fromCharCode("1".charCodeAt(0)+_2d9);
var move=this.createMoveFromString(_2e2);
var _2e4=this.cloneBoard();
_2e4.makeMove(move,_2e4.boardPieces[_2dc][_2dd],false,this.moveAnimationLength,false,false);
_2e1=_2e4.isKingSafe(_2d7.colour,move);
}
return _2e0&&_2e1;
};
Board.prototype.isKingMated=function(_2e5,_2e6){
var _2e7=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==_2e5){
_2e7=bp;
break;
}
}
}
var _2eb=[[1,0],[1,1],[1,-1],[-1,0],[-1,1],[-1,-1],[0,1],[0,-1],[2,0],[-2,0]];
var bp=_2e7;
for(var k=0;k<_2eb.length;k++){
if(this.canMove(bp,bp.column+_2eb[k][0],bp.row+_2eb[k][1],_2e6,true)){
return false;
}
}
var _2ed=this.getCandidateMoves(_2e5,_2e6,true,true);
if(_2ed.length>0){
return false;
}
return true;
};
Board.prototype.getCandidateMoves=function(_2ee,_2ef,_2f0,_2f1){
var _2f2=new Array();
for(var i=0;i<8;i++){
for(var j=0;j<8;j++){
var bp=this.boardPieces[i][j];
var _2f6=[];
if(!bp||bp.colour!=_2ee){
continue;
}
switch(bp.piece){
case ChessPiece.KING:
if(_2f1){
continue;
}
_2f6=[[1,0],[1,1],[1,-1],[-1,0],[-1,1],[-1,-1],[0,1],[0,-1],[2,0],[-2,0]];
break;
case ChessPiece.KNIGHT:
_2f6=[[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++){
_2f6.push([1+k,1+k]);
_2f6.push([1+k,-1-k]);
_2f6.push([-1-k,1+k]);
_2f6.push([-1-k,-1-k]);
}
break;
case ChessPiece.QUEEN:
for(var k=0;k<8;k++){
_2f6.push([1+k,0]);
_2f6.push([1+k,1+k]);
_2f6.push([1+k,-1-k]);
_2f6.push([-1-k,0]);
_2f6.push([-1-k,1+k]);
_2f6.push([-1-k,-1-k]);
_2f6.push([0,-1-k]);
_2f6.push([0,1+k]);
}
break;
case ChessPiece.ROOK:
for(var k=0;k<8;k++){
_2f6.push([1+k,0]);
_2f6.push([-1-k,0]);
_2f6.push([0,-1-k]);
_2f6.push([0,1+k]);
}
break;
case ChessPiece.PAWN:
if(_2ee==ChessPiece.BLACK){
_2f6=[[0,-1],[1,-1],[-1,-1]];
if(j==6){
_2f6.push([0,-2]);
}
}else{
_2f6=[[0,1],[1,1],[-1,1]];
if(j==1){
_2f6.push([0,2]);
}
}
break;
}
for(var k=0;k<_2f6.length;k++){
if(this.canMove(bp,bp.column+_2f6[k][0],bp.row+_2f6[k][1],_2ef,true)){
_2f2.push(new Move(bp.column,bp.row,bp.column+_2f6[k][0],bp.row+_2f6[k][1]));
if(_2f0){
return _2f2;
}
}
}
}
}
return _2f2;
};
Board.prototype.isKingSafe=function(_2f8,_2f9){
var _2fa=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==_2f8){
_2fa=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!=_2f8){
if(this.canMove(bp,_2fa.column,_2fa.row,_2f9,false)){
return false;
}
}
}
}
return true;
};
Board.prototype.freeBoardPieces=function(_2fe){
if(this.boardPieces){
for(var i=0;i<8;i++){
for(var j=0;j<8;j++){
if(this.boardPieces[i][j]!=null){
this.boardPieces[i][j].free();
this.boardPieces[i][j]=null;
}
}
if(_2fe){
this.boardPieces[i]=null;
}
}
}
if(_2fe){
this.boardPieces=null;
}
};
Board.prototype.freeBoard=function(){
this.freeBoardPieces(true);
this.freeMoveArray();
};
Board.prototype.freeMoveArray=function(){
if(this.moveArray){
for(var i=0;i<this.moveArray.length;i++){
var m=this.moveArray[i];
if(m){
m.freeMove();
this.moveArray[i]=null;
}
}
}
};
Board.prototype.cloneBoard=function(){
var _303=new Board();
_303.boardName=this.boardName;
_303.cloned=true;
_303.boardPieces=this.copyBoardPieces(true);
_303.moveArray=this.copyMoveArray(false);
_303.canCastleQueenSide=this.copyCastleQueenSide();
_303.canCastleKingSide=this.copyCastleKingSide();
_303.toMove=this.toMove;
_303.opponentColour=this.opponentColour;
_303.isFlipped=this.isFlipped;
_303.isUserFlipped=this.isUserFlipped;
_303.ignoreFlipping=this.ignoreFlipping;
_303.reverseFlip=this.reverseFlip;
_303.moveAnimationLength=this.moveAnimationLength;
_303.moveNumber=this.moveNumber;
_303.halfMoveNumber=this.halfMoveNumber;
_303.startFen=this.startFen;
_303.boardImagePath=this.boardImagePath;
if(this.prev_move){
_303.prev_move=this.prev_move.clone();
}else{
_303.prev_move=null;
}
return _303;
};
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(_304){
var _305=new Array();
if(!_304){
if(this.moveArray.length>0){
_305=this.moveArray.slice(0);
}
return _305;
}else{
for(var i=0;i<this.moveArray.length;i++){
var m=_305[i];
if(m){
var newM=m.clone(true);
_305[i]=newM;
}
}
return _305;
}
};
Board.prototype.copyBoardPieces=function(_309){
var _30a=Board.createBoardArray();
for(var i=0;i<8;i++){
for(var j=0;j<8;j++){
if(this.boardPieces[i][j]!=null){
if(_309){
_30a[i][j]=this.boardPieces[i][j].makeLightWeight();
}else{
_30a[i][j]=this.boardPieces[i][j].copyPiece();
}
}else{
_30a[i][j]=null;
}
}
}
return _30a;
};
Board.prototype.createPiece=function(_30d,_30e,_30f){
if(_30f){
return new LightweightChessPiece(null,_30d,_30e,this);
}else{
return new ChessPiece(this.getPieceDiv(),_30d,_30e,this);
}
};
Board.prototype.restoreCastling=function(_310){
this.canCastleKingSide=_310.kingSide;
this.canCastleQueenSide=_310.queenSide;
};
Board.prototype.saveCastling=function(){
var _311=[this.canCastleQueenSide[0],this.canCastleQueenSide[1]];
var _312=[this.canCastleKingSide[0],this.canCastleKingSide[1]];
return {queenSide:_311,kingSide:_312};
};
var firstLightProf=true;
var firstHeavyProf=true;
Board.prototype.setupFromFenLightweight=function(fen,_314,flip,_316,_317){
var _318=false&&firstLightProf;
if(_318){
console.profile("setupFromFenLight");
}
this.setupFromFenGeneric(fen,_314,flip,true,_316,_317);
if(_318){
console.profileEnd();
}
};
Board.prototype.setupFromFenHeavyWeight=function(fen,_31a,flip,_31c,_31d){
var _31e=false&&firstHeavyProf;
if(_31e){
console.profile("setupFromFenHeavy");
}
this.setupFromFenGeneric(fen,_31a,flip,false,_31c,_31d);
if(_31e){
console.profileEnd();
}
};
Board.prototype.setupFromFen=function(fen,_320,flip,_322,_323,_324){
if(_322){
this.setupFromFenLightweight(fen,_320,flip,_323,_324);
}else{
this.setupFromFenHeavyWeight(fen,_320,flip,_323,_324);
}
};
Board.prototype.setupFromFenGeneric = function(fen, _326, flip, _328, _329, _32a) {
    if (ctime) {
        console.time("setupFromFen" + _328);
    }
    this.settingUpPosition = true;
    var _32b = fen.split(" ");
    var _32c = _32b[0].split("/");
    this.halfMoveNumber = parseInt(_32b[4]);
    this.moveNumber = parseInt(_32b[5]) * 2;
    var _32d = 0;
    var row = 8;
    this.uptoId = 0;
    this.board_xy = null;
    var _32f = _32b[2];
    var _330 = null;
    this.canCastleQueenSide = [false, false];
    this.canCastleKingSide = [false, false];
    if (_32f != "-") {
        if (_32f.indexOf("K") >= 0) {
            this.canCastleKingSide[ChessPiece.WHITE] = true;
        }
        if (_32f.indexOf("Q") >= 0) {
            this.canCastleQueenSide[ChessPiece.WHITE] = true;
        }
        if (_32f.indexOf("k") >= 0) {
            this.canCastleKingSide[ChessPiece.BLACK] = true;
        }
        if (_32f.indexOf("q") >= 0) {
            this.canCastleQueenSide[ChessPiece.BLACK] = true;
        }
    }
    if (_32a) {
        this.startMoveNum = this.moveNumber;
    }
    if (_32b[1] == "w") {
        if (_32a) {
            this.startMoveNum--;
        }
        this.toMove = ChessPiece.WHITE;
        this.opponentColour = ChessPiece.WHITE;
        this.isFlipped = false;
        this.moveNumber--;
    } else {
        this.toMove = ChessPiece.BLACK;
        this.opponentColour = ChessPiece.BLACK;
        this.isFlipped = true;
    }
    if (_329) {
        var _331 = _32b[3];
        if (_331 != "-" && _331.length == 2) {
            var _332 = _331[0];
            var _333 = parseInt(_331[1]);
            if (_333 == 3) {
                _330 = this.createMoveFromString(_332 + "2" + _332 + "4");
            } else {
                _330 = this.createMoveFromString(_332 + "7" + _332 + "5");
            }
            _330.prevMoveEnpassant = true;
            this.prev_move = _330;
        }
    }
    if (_326) {
        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 = _32c[i];
        row--;
        _32d = 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 _33a = this.boardPieces[_32d][row];
                    this.boardPieces[_32d][row] = null;
                    _32d++;
                }
            } else {
                var _33b = (c + "").toLowerCase().charAt(0);
                var _33c = ChessPiece.WHITE;
                if (_33b == c) {
                    _33c = ChessPiece.BLACK;
                }
                var cp;
                switch (_33b) {
                    case "k":
                        cp = this.createPiece(_33c, ChessPiece.KING, _328);
                        break;
                    case "q":
                        cp = this.createPiece(_33c, ChessPiece.QUEEN, _328);
                        break;
                    case "r":
                        cp = this.createPiece(_33c, ChessPiece.ROOK, _328);
                        break;
                    case "b":
                        cp = this.createPiece(_33c, ChessPiece.BISHOP, _328);
                        break;
                    case "n":
                        cp = this.createPiece(_33c, ChessPiece.KNIGHT, _328);
                        break;
                    case "p":
                        cp = this.createPiece(_33c, ChessPiece.PAWN, _328);
                        break;
                    default:
                        alert("unknown piece letter:" + _33b + " for fen:" + fen);
                }
                if (isGecko || isOpera) {
                    cp.setPosition(_32d, row, false, null, this.moveAnimationLength);
                    cp.setVisible(true);
                }
                this.boardPieces[_32d][row] = cp;
                this.pieces[this.uptoPiece] = cp;
                this.pieces[this.uptoPiece].column = _32d;
                this.pieces[this.uptoPiece].row = row;
                this.uptoPiece++;
                _32d++;
            }
        }
    }
    if (!isGecko) {
        for (var i = 0; i < this.uptoPiece; i++) {
            this.pieces[i].setPosition(this.pieces[i].column, this.pieces[i].row, false, null, 0);
        }
    }
    if (!_328) {
        for (var i = 0; i < this.uptoPiece; i++) {
            this.pieces[i].setVisible(true);
        }
    }
    if (!_328) {
        this.createBoardCoords();
    }
    this.settingUpPosition = false;
    if (ctime) {
        console.timeEnd("setupFromFen" + _328);
    }
};
Board.prototype.resetMoveListScrollPosition=function(){
var _33e=this.movesDisplay.getMovesDisplay();
if(_33e){
var _33f=new YAHOO.util.Scroll(_33e,{scroll:{to:[0,0]}},0);
_33f.animate();
}
};
Board.prototype.changePieceSet=function(_340,_341){
if(!this.showedIE6Warning){
var str=_js("Depending on your browser you may need to reload the<br/> page for piece size changes to properly take effect.");
alert(str.replace("<br/>","\n"));
}
this.showedIE6Warning=true;
if(check_bad_msie()){
if(!this.showedIE6Warning){
var str=_js("Internet Explorer version 6 does not support dynamic piece size changes.<br/> Please reload page to view new settings.");
alert(str.replace("<br/>","\n"));
}
this.showedIE6Warning=true;
return;
}
var _343=this.pieceSize;
this.pieceSet=_340;
this.pieceSize=_341;
var _344=YAHOO.util.Dom.get(this.boardName+"-boardBorder");
var _345=0;
if(this.showCoordinates){
_345=15;
}
_344.className="";
YAHOO.util.Dom.addClass(_344,"ct-board-border"+this.squareColorClass);
YAHOO.util.Dom.setStyle(_344,"width",(this.pieceSize*8+_345)+"px");
YAHOO.util.Dom.setStyle(_344,"height",(this.pieceSize*8+_345)+"px");
var _346=YAHOO.util.Dom.get("ctb-"+this.boardName);
YAHOO.util.Dom.setStyle(_346,"width",(this.pieceSize*8)+"px");
YAHOO.util.Dom.setStyle(_346,"height",(this.pieceSize*8)+"px");
var _347="ct-white-square"+this.squareColorClass;
for(var i=7;i>=0;i--){
for(var j=0;j<8;j++){
var _34a=this.getBoardDivFromId(this.boardName+"-s"+j+""+i);
_34a.className="";
YAHOO.util.Dom.addClass(_34a,_347);
YAHOO.util.Dom.setStyle(_34a,"width",this.pieceSize+"px");
YAHOO.util.Dom.setStyle(_34a,"height",this.pieceSize+"px");
var _34b=(((j+1)*(i+1))%19/19*100);
var _34c=((65-((j+1)*(i+1)))%19/19*100);
YAHOO.util.Dom.setStyle(_34a,"background-position",_34b+"% "+_34c+"%");
_347=(_347=="ct-black-square"+this.squareColorClass)?"ct-white-square"+this.squareColorClass:"ct-black-square"+this.squareColorClass;
}
_347=(_347=="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||isOpera){
var _34e=cp.div;
_34e.innerHTML="<img src=\""+cp.icon+"\"/>";
var img=_34e.firstChild;
if(!isOpera){
fix_ie_png(img);
}
}else{
YAHOO.util.Dom.setStyle([cp.div],"backgroundImage","url("+cp.icon+")");
YAHOO.util.Dom.setStyle([cp.div],"background-repeat","no-repeat");
}
YAHOO.util.Dom.setStyle([cp.div],"height",this.pieceSize+"px");
YAHOO.util.Dom.setStyle([cp.div],"width",this.pieceSize+"px");
YAHOO.util.Dom.setStyle([cp.div],"left","");
YAHOO.util.Dom.setStyle([cp.div],"top","");
var xy=cp.getNewXYPosition(cp.column,cp.row);
YAHOO.util.Dom.setXY(cp.div,xy,false);
}
}
}
if(this.moveArray){
var move=this.moveArray[0];
while(move!=null){
if(move.taken){
var cp=move.taken;
if(cp.getNewXYPosition){
cp.icon=get_image_str(ChessPiece.pieceIconNames[cp.colour][cp.piece],cp.board.boardImagePath,cp.board.pieceSet,cp.board.pieceSize,cp.board.addVersion);
if(YAHOO.util.Event.isIE||isOpera){
var _34e=cp.div;
_34e.innerHTML="<img src=\""+cp.icon+"\"/>";
YAHOO.util.Dom.setStyle([cp.div],"position","relative");
var img=_34e.firstChild;
if(!isOpera){
fix_ie_png(img);
}
}else{
YAHOO.util.Dom.setStyle([cp.div],"backgroundImage","url("+cp.icon+")");
YAHOO.util.Dom.setStyle([cp.div],"background-repeat","no-repeat");
}
YAHOO.util.Dom.setStyle([cp.div],"height",this.pieceSize+"px");
YAHOO.util.Dom.setStyle([cp.div],"width",this.pieceSize+"px");
YAHOO.util.Dom.setStyle([cp.div],"left","");
YAHOO.util.Dom.setStyle([cp.div],"top","");
var xy=cp.getNewXYPosition(cp.column,cp.row);
YAHOO.util.Dom.setXY(cp.div,xy,false);
}
}
move=move.next;
}
}
if(this.problem){
var body=YAHOO.util.Dom.get("body");
if(body){
YAHOO.util.Dom.setStyle(body,"min-width",((this.pieceSize*8+_345)+300+200+120)+"px");
}
}
this.createBoardCoords();
};
Board.prototype.forwardMove=function(e){
if(this.blockFowardBack||this.deferredBlockForwardBack){
if(clog){
console.log("returning early from forward due to block forward on");
}
return;
}
var _354=false;
if(this.tactics&&this.tactics.problemActive){
if(clog){
console.log("not forwarding, tactic is active");
}
return;
}
this.blockForwardBack=true;
if(this.currentMove&&!this.currentMove.atEnd){
move=this.currentMove;
if(move){
if(clog){
console.log("forward move:"+move.output());
}
}else{
if(clog){
console.log("forward move with currentmove null");
}
}
if(move.endNode){
if(clog){
console.log("calling processendgame from forward move");
}
if(!_354){
this.problem.processEndgame("",true);
}
this.toggleToMove();
this.updateToPlay();
}else{
if(clog){
console.log("forwarding move:"+move.output());
}
var _355=null;
piece=this.boardPieces[move.fromColumn][move.fromRow];
if(move.promotion){
_355=move.promotion;
piece.prePromotionColumn=null;
piece.prePromotionRow=null;
}
this.updatePiece(piece,move.toColumn,move.toRow,true,true,false,_355,true);
this.toggleToMove();
this.updateToPlay();
var _356=this.currentMove;
if(clog){
if(_356){
console.log("after forward curmove:"+_356.output());
}else{
console.log("after forward cur move null");
}
}
for(var i=0;i<this.registeredForwardMovePostUpdateListeners.length;i++){
var _358=this.registeredForwardMovePostUpdateListeners[i].forwardMovePostUpdateCallback(move);
}
}
}else{
if(clog){
console.log("already at end");
}
for(var i=0;i<this.registeredForwardAtEndListeners.length;i++){
var _358=this.registeredForwardAtEndListeners[i].forwardAtEndCallback();
}
}
this.blockForwardBack=false;
};
Board.prototype.setupEventHandlers=function(){
this.timesLostFocus=0;
YAHOO.util.Event.addListener(document,"blur",this.lostFocus,this,true);
if(!this.avoidMouseoverActive){
YAHOO.util.Event.addListener(this.boardName+"-container","mouseover",function(e){
activeBoard=this;
},this,true);
}
YAHOO.util.Event.addListener(this.boardName+"-container","click",this.selectDestSquare,this,true);
var _35a="keydown";
if(isGecko){
_35a="keypress";
}
YAHOO.util.Event.addListener(document,_35a,function(e){
var _35c=(e.target)?e.target:e.srcElement;
if(_35c.form){
return true;
}
if(activeBoard!=this){
return true;
}
switch(YAHOO.util.Event.getCharCode(e)){
case 37:
this.backMove();
break;
case 39:
this.forwardMove();
break;
default:
}
return true;
},this,true);
YAHOO.util.Event.addListener(this.boardName+"-forward","click",this.forwardMove,this,true);
YAHOO.util.Event.addListener(this.boardName+"-back","click",this.backMove,this,true);
YAHOO.util.Event.addListener(this.boardName+"-start","click",this.gotoStart,this,true);
YAHOO.util.Event.addListener(this.boardName+"-end","click",this.gotoEnd,this,true);
YAHOO.util.Event.addListener(this.boardName+"-play","click",this.playMoves,this,true);
YAHOO.util.Event.addListener(this.boardName+"-stop","click",this.stopPlayingMoves,this,true);
if(this.r){
YAHOO.util.Event.addListener(this.boardName+"-analyse","click",this.analysePosition,this,true);
YAHOO.util.Event.addListener(this.boardName+"-showfen","click",this.showBoardFen,this,true);
}
if(this.canPasteFen){
YAHOO.util.Event.addListener(this.boardName+"-pastefen","click",this.pasteFen,this,true);
}
};
Board.prototype.flipBoard = function() {
    this.isUserFlipped = !this.isUserFlipped;
    this.isFlipped = !this.isFlipped;
    this.redrawBoard();
    this.updateToPlay();
};
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 _362=YAHOO.util.Dom.get(this.boardName+"-s"+this.lastFromColumn+""+this.lastFromRow);
var _363=YAHOO.util.Dom.get(this.boardName+"-s"+this.lastToColumn+""+this.lastToRow);
}else{
var _362=YAHOO.util.Dom.get(this.boardName+"-s"+(7-this.lastFromColumn)+""+(7-this.lastFromRow));
var _363=YAHOO.util.Dom.get(this.boardName+"-s"+(7-this.lastToColumn)+""+(7-this.lastToRow));
}
this.updateFromTo(_362,_363,this.lastFromRow,this.lastFromColumn,this.lastToRow,this.lastToColumn);
}
};
Board.fenPositionOnly=function(fen){
var _365=fen.split(" ");
return _365[0]+" "+_365[1];
};
Board.fenStripMoveClock=function(fen){
var _367=fen.split(" ");
return _367[0]+" "+_367[1]+" "+_367[2]+" "+_367[3];
};
Board.fenSamePosition=function(fen1,fen2,_36a){
if(!fen1||!fen2){
return false;
}
var f1=null;
var f2=null;
if(_36a){
f1=Board.fenPositionOnly(fen1);
f2=Board.fenPositionOnly(fen2);
}else{
f1=Board.fenStripMoveClock(fen1);
f2=Board.fenStripMoveClock(fen2);
}
return (f1==f2);
};
Board.prototype.findFen=function(mv,brd,fen,_370){
var res=this.findFen2(mv,brd,fen,true);
if(res.move){
return res.move;
}else{
if(_370){
if(res.clockStrip){
return res.clockStrip;
}else{
if(res.fullStrip){
return res.fullStrip;
}
}
}
}
return null;
};
Board.prototype.findFen2=function(mv,brd,fen,_375){
var _376=brd.cloneBoard();
var res=Object();
var _378=null;
var _379=null;
res.move=null;
if(_375){
_376.gotoMoveIndex(-1,true,true,true,true);
}
var _37a=null;
while(mv){
var _37b=_376.boardToFen();
if(_37b==fen){
res.move=_37a;
res.clockStrip=null;
res.fullStrip=null;
return res;
}else{
if(Board.fenSamePosition(fen,_37b)){
_378=_37a;
}else{
if(Board.fenSamePosition(fen,_37b,true)){
_379=_37a;
}
}
}
if(mv.atEnd){
break;
}
if(mv.vars&&mv.vars.length>0){
for(var i=0;i<mv.vars.length;i++){
var _37d=findFen(mv.vars[i],_376,fen,false);
if(_37d.move){
return _37d;
}else{
if(_37d.clockStrip){
_378=_37d.clockStrip;
}else{
if(_37d.fullStrip){
_379=_37d.fullStrip;
}
}
}
}
}
if(clog){
console.log("about to make mv:"+mv.output());
}
_376.makeMove(mv,_376.boardPieces[mv.fromColumn][mv.fromRow],false,this.moveAnimationLength,false,false);
if(clog){
console.log("finished making mv");
}
_37a=mv;
mv=mv.next;
if(clog){
console.log("toMove:"+_376.toMove);
}
_376.setCurrentMove(mv);
_376.toggleToMove();
}
if(_378){
res.clockStrip=_378;
}
if(_379){
res.fullStrip=_379;
}
return res;
};
Board.prototype.gotoFen=function(fen,_37f){
if(clog){
console.log("about to find fen for:"+fen);
}
var _380=this.findFen(this.moveArray[0],this,fen,_37f);
if(_380){
if(clog){
console.log("found move:"+_380.output()+" for fen:"+fen);
}
this.gotoMoveIndex(_380.index);
}else{
if(clog){
console.log("didn't find move for fen:"+fen);
}
}
};
Board.prototype.getMaxMoveIndex=function(){
return this.moveArray.length-1;
};
Board.prototype.gotoMoveIndex=function(_381,_382,_383,_384,_385){
if(clog){
console.log("going to move index:"+_381);
}
var _386=!_383;
if(!this.moveArray||this.moveArray.length<=_381||(_381==-1&&this.moveArray.length==0)){
return;
}
var _387=this.boardName+"-piecestaken";
var _388=YAHOO.util.Dom.get(_387);
if(_388){
_388.innerHTML="";
}
if(_381==-1){
var flip=false;
if(this.prev_move&&!this.prev_move.prevMoveEnpassant){
flip=true;
}
this.setupFromFen(this.startFen,flip,false,_385);
if(this.prev_move&&!this.prev_move.prevMoveEnpassant){
this.makeMove(this.prev_move,this.boardPieces[this.prev_move.fromColumn][this.prev_move.fromRow],!_383,this.moveAnimationLength,true,true);
this.updateToPlay();
}
if(this.moveArray&&this.moveArray.length>0){
this.setCurrentMove(this.moveArray[0],_382);
}else{
this.setCurrentMove(this.firstMove,_382);
}
if(!_382){
this.setForwardBack();
}
if(!_384){
for(var i=0;i<this.registeredGotoMoveIndexListeners.length;i++){
var _38b=this.registeredGotoMoveIndexListeners[i].gotoMoveIndexCallback(_381);
}
}
return;
}
var _38c=new Array();
var move=this.moveArray[_381];
if(clog&&move){
console.log("gotomoveindex move:"+move.output());
if(move.next){
console.log("gotomoveindex move.next:"+move.next.output());
}
if(move.prev){
console.log("gotomoveindex move.prev:"+move.prev.output());
}
}
var _38e=0;
if(move.next!=null){
this.setCurrentMove(move.next,_382);
}else{
if(clog){
console.log("move next null with move:"+move.output());
}
}
while(move!=null&&!move.dummy){
_38c[_38e++]=move;
move=move.prev;
}
var flip=false;
if(this.prev_move&&!this.prev_move.prevMoveEnpassant){
flip=true;
}
this.setupFromFen(this.startFen,flip,false,true);
if(this.prev_move&&!this.prev_move.prevMoveEnpassant){
if(clog){
console.log("gotomoveindex prev_move:"+this.prev_move.output());
}
this.makeMove(this.prev_move,this.boardPieces[this.prev_move.fromColumn][this.prev_move.fromRow],false,this.moveAnimationLength,true,true);
this.updateToPlay();
}
for(var i=_38e-1;i>=1;i--){
var move=_38c[i];
this.makeMove(move,this.boardPieces[move.fromColumn][move.fromRow],false,this.moveAnimationLength,true,false);
this.toggleToMove();
}
if(!_382){
this.convertPiecesFromLightWeight(_381);
}
var move=_38c[0];
this.makeMove(move,this.boardPieces[move.fromColumn][move.fromRow],_386,this.moveAnimationLength,true,true);
this.toggleToMove();
this.updateToPlay();
if(!_382){
this.setForwardBack();
}
if(!_384){
for(var i=0;i<this.registeredGotoMoveIndexListeners.length;i++){
var _38b=this.registeredGotoMoveIndexListeners[i].gotoMoveIndexCallback(_381);
}
}
};
Board.prototype.gotoStart=function(e){
if(this.lastFromSquare){
YAHOO.util.Dom.removeClass(this.lastFromSquare,"ct-from-square");
}
if(this.lastToSquare){
YAHOO.util.Dom.removeClass(this.lastToSquare,"ct-to-square");
}
this.gotoMoveIndex(-1);
if(this.problem){
if(this.currentMove&&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(clog){
console.log("goto end called");
}
if(this.tactics&&this.tactics.problemActive){
this.tactics.autoForward=false;
this.tactics.markProblem(false,false,"NULL","NULL");
}
if(clog){
console.log("jumping to start");
}
this.gotoMoveIndex(-1,true,true,true);
var _391=0;
while(this.currentMove&&this.currentMove.next!=null){
var move=this.currentMove;
if(clog){
console.log("going to end move:"+move.output());
}
this.makeMove(move,this.boardPieces[move.fromColumn][move.fromRow],false,this.moveAnimationLength,true,true);
_391=move.index;
this.toggleToMove();
this.setCurrentMove(move.next);
}
for(var i=0;i<this.registeredGotoMoveIndexListeners.length;i++){
var _394=this.registeredGotoMoveIndexListeners[i].gotoMoveIndexCallback(_391);
}
};
Board.prototype.gotoPly=function(_395,_396){
if(clog){
console.log("goto ply called");
}
this.gotoMoveIndex(-1,true,true,true);
var cnt=1;
var _398=0;
while(cnt<=_395&&this.currentMove&&this.currentMove.next!=null){
var move=this.currentMove;
if(clog){
console.log("going to end move:"+move.output());
}
this.makeMove(move,this.boardPieces[move.fromColumn][move.fromRow],false,this.moveAnimationLength,true,true);
_398=move.index;
this.toggleToMove();
this.setCurrentMove(move.next);
cnt++;
}
if(_396){
for(var i=0;i<this.registeredGotoMoveIndexListeners.length;i++){
var _39b=this.registeredGotoMoveIndexListeners[i].gotoMoveIndexCallback(_398);
}
}
};
Board.prototype.playMove = function(self) {
    if (!self.keepPlayingMoves || !self.currentMove || !self.currentMove.next) {
        var play = YAHOO.util.Dom.get(this.boardName + "-play");
        play.src = this.boardImagePath + "/images/control_play_blue" + this.getVersString() + ".gif";
        self.keepPlayingMoves = false;
        return;
    }
    self.forwardMove();
    setTimeout(function() {
        self.playMove(self);
    }, self.pauseBetweenMoves);
};
Board.prototype.getVersString=function(){
var _39e=".vers"+SITE_VERSION;
if(!this.addVersion){
_39e="";
}
return _39e;
};
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.pasteFen=function(e){
for(var i=0;i<this.registeredPasteFenClickedListeners.length;i++){
var _3a4=this.registeredPasteFenClickedListeners[i].pasteFenClickedCallback();
}
};
Board.prototype.showBoardFen=function(e){
var fen=this.boardToFen();
var _3a7=new YAHOO.widget.SimpleDialog("fenDialog",{fixedcenter:true,visible:true,draggable:false,constraintoviewport:true,buttons:[{id:"linkbutton4",text:"Test"},{text:_js("Ok"),handler:function(){
_3a7.hide();
},isDefault:true}]});
_3a7.setHeader(_js("Position FEN"));
_3a7.setBody("<textarea class=\"showPgn\" id=\"fenText\" rows=\"1\" readonly=\"true\" cols=\""+(fen.length+9)+"\">"+fen+"</textarea>");
_3a7.render(document.body);
_3a7.setFooter("<span id=\"copyToComment\"></span><span id=\"fenok\"></span>");
var _3a8=this;
if(this.problem&&this.problem.comments){
var _3a9=new YAHOO.widget.Button({type:"button",label:_js("Copy To Comment"),container:"fenok",onclick:{fn:function(){
_3a8.copyFenToComment(fen,Board.COPY_COMMENT_PROBLEM);
_3a7.hide();
}}});
}
if(this.gameComments){
var _3aa=new YAHOO.widget.Button({type:"button",label:_js("Copy To Game Comment"),container:"fenok",onclick:{fn:function(){
_3a8.copyFenToComment(fen,Board.COPY_COMMENT_GAME);
_3a7.hide();
}}});
}
if(this.playerComments){
var _3ab=new YAHOO.widget.Button({type:"button",label:_js("Copy To Player Comment"),container:"fenok",onclick:{fn:function(){
_3a8.copyFenToComment(fen,Board.COPY_COMMENT_PLAYER);
_3a7.hide();
}}});
}
if(this.openingComments){
var _3ac=new YAHOO.widget.Button({type:"button",label:_js("Copy To Opening Comment"),container:"fenok",onclick:{fn:function(){
_3a8.copyFenToComment(fen,Board.COPY_COMMENT_OPENING);
_3a7.hide();
}}});
}
var _3ad=new YAHOO.widget.Button({type:"button",label:_js("Ok"),container:"fenok",onclick:{fn:function(){
_3a7.hide();
}}});
};
Board.prototype.copyFenToComment=function(fen,_3af){
switch(_3af){
case (Board.COPY_COMMENT_PROBLEM):
if(this.problem){
var flip=false;
var col=fen.split(" ")[1];
var col2=this.startFen.split(" ")[1];
if(col==col2){
flip=true;
}
this.problem.comments.copyFenToComment(fen,flip);
}
break;
case (Board.COPY_COMMENT_GAME):
this.gameComments.copyFenToComment(fen);
break;
case (Board.COPY_COMMENT_PLAYER):
this.playerComments.copyFenToComment(fen);
break;
case (Board.COPY_COMMENT_OPENING):
this.openingComments.copyFenToComment(fen);
break;
}
};
Board.COPY_COMMENT_PROBLEM=0;
Board.COPY_COMMENT_PLAYER=1;
Board.COPY_COMMENT_GAME=2;
Board.COPY_COMMENT_OPENING=3;
Board.prototype.copyAnalysisToComment=function(_3b3,fen,flip,_3b6){
switch(_3b6){
case (Board.COPY_COMMENT_PROBLEM):
if(this.problem){
this.problem.comments.copyAnalysisToComment(_3b3,fen,flip);
}
break;
case (Board.COPY_COMMENT_GAME):
this.gameComments.copyAnalysisToComment(_3b3,fen,flip);
break;
case (Board.COPY_COMMENT_PLAYER):
this.playerComments.copyAnalysisToComment(_3b3,fen,flip);
break;
case (Board.COPY_COMMENT_OPENING):
this.openingComments.copyAnalysisToComment(_3b3,fen,flip);
break;
}
};
Board.prototype.analysePosition=function(e){
window.parentBoard=this;
var _3b8=(this.pieceSize*8)+450+50;
var _3b9=(this.pieceSize*8)+250;
var _3ba=window.open("/windows/analyse.html","analysis_window","width="+_3b8+",height="+_3b9+",resizable=1,scrollbars=1,location=0,copyhistory=0,status=0,toolbar=0,menubar=0");
_3ba.focus();
};
Board.prototype.backMove=function(e){
if(this.blockFowardBack||this.deferredBlockForwardBack){
return;
}
var _3bc=this.currentMove;
if(this.tactics){
if(this.tactics.problemActive){
return;
}
}
this.blockForwardBack=true;
if(this.currentMove&&this.currentMove.prev!=null){
YAHOO.util.Dom.removeClass(this.lastFromSquare,"ct-from-square");
YAHOO.util.Dom.removeClass(this.lastToSquare,"ct-to-square");
this.lastFromRow=null;
this.toggleToMove();
this.updateToPlay();
move=this.currentMove.prev;
if(move){
if(clog){
console.log("backwards moving to prev move:"+move.output()+" from current move:"+this.currentMove.output());
}
}
this.setCurrentMove(move);
piece=this.boardPieces[move.toColumn][move.toRow];
if(!piece){
if(clog){
console.log("got empty piece in backMove");
}
}
takenPiece=move.taken;
this.board_xy=null;
piece.setPosition(move.fromColumn,move.fromRow,true,null,this.moveAnimationLength);
this.boardPieces[move.fromColumn][move.fromRow]=piece;
if(move.promotion){
piece.changePiece("p");
}
piece.setVisible(true);
this.canCastleQueenSide[0]=move.preCastleQueenSide[0];
this.canCastleQueenSide[1]=move.preCastleQueenSide[1];
this.canCastleKingSide[0]=move.preCastleKingSide[0];
this.canCastleKingSide[1]=move.preCastleKingSide[1];
var _3bd=false;
if(piece.piece==ChessPiece.KING&&Math.abs(move.fromColumn-move.toColumn)>1){
_3bd=true;
}
this.moveNumber--;
if(this.moveNumber<=0){
this.moveNumber=1;
}
if(takenPiece&&!_3bd){
this.board_xy=null;
var _3be=move.toColumn;
var _3bf=move.toRow;
if(piece.piece==ChessPiece.PAWN&&move.fromColumn!=move.toColumn&&takenPiece.enPassant){
_3bf=move.fromRow;
this.boardPieces[move.toColumn][move.toRow]=null;
}
takenPiece.setPosition(_3be,_3bf,false,null,this.moveAnimationLength);
this.boardPieces[_3be][_3bf]=takenPiece;
move.taken=null;
this.processTaken(takenPiece,false);
}else{
this.boardPieces[move.toColumn][move.toRow]=null;
}
if(_3bd){
var _3c0=move.toRow;
var _3c1;
var _3c2;
if(move.fromColumn>move.toColumn){
_3c1=0;
_3c2=3;
}else{
_3c1=7;
_3c2=5;
}
var _3c3=this.boardPieces[_3c2][_3c0];
_3c3.setPosition(_3c1,_3c0,true,null,this.moveAnimationLength);
this.boardPieces[_3c1][_3c0]=_3c3;
this.boardPieces[_3c2][_3c0]=null;
}
if(move!=null&&move.prev!=null&&move.prev.next!=move){
move=move.prev.next;
if(clog){
if(move){
console.log("moving backwards out of variation moving to:"+move.output());
}else{
console.log("jumping out of variation to null move");
}
}
}
for(var i=0;i<this.registeredBackMovePreCurrentListeners.length;i++){
var _3c5=this.registeredBackMovePreCurrentListeners[i].backMovePreCurrentCallback(move,_3bc);
}
this.setCurrentMove(move);
this.setForwardBack();
}
this.blockForwardBack=false;
};
Board.prototype.getMovesToCurrent=function(){
var mvs=[];
var res=[];
var mv=this.currentMove;
if(!mv||!mv.prev){
return res;
}
mv=mv.prev;
while(mv){
mvs.push(mv);
mv=mv.prev;
}
for(var i=mvs.length-1;i>=0;i--){
res.push(mvs[i].toMoveString());
}
return res;
};
Board.prototype.processTaken=function(_3ca,_3cb){
var _3cc=this.boardName+"-piecestaken";
var _3cd=YAHOO.util.Dom.get(_3cc);
if(_3cd){
if(_3cb){
var _3ce=get_image_str(ChessPiece.pieceIconNames[_3ca.colour][_3ca.piece],this.boardImagePath,this.pieceSet,this.pieceTakenSize,this.addVersion);
_3cd.innerHTML=_3cd.innerHTML+"<img src=\""+_3ce+"\"/>";
}else{
var _3cf=_3cd.innerHTML.split("<");
_3cd.innerHTML="";
for(var i=1;i<_3cf.length-1;i++){
_3cd.innerHTML=_3cd.innerHTML+"<"+_3cf[i];
}
}
}
};
Pool=function(){
this.pool=new Array();
this.count=-1;
this.numGot=0;
this.numPut=0;
};
Pool.prototype.getObject=function(){
var o=null;
if(this.count>=0){
this.numGot++;
o=this.pool[this.count--];
}
return o;
};
Pool.prototype.putObject=function(o){
if(o!=null){
this.numPut++;
this.pool[++this.count]=o;
}
};
var boardPool=new Pool();
function touchHandler(_3d3){
var _3d4=_3d3.changedTouches,_3d5=_3d4[0],type="";
switch(_3d3.type){
case "touchstart":
type="mousedown";
break;
case "touchmove":
type="mousemove";
break;
case "touchend":
type="mouseup";
break;
default:
return;
}
var _3d7=document.createEvent("MouseEvent");
_3d7.initMouseEvent(type,true,true,window,1,_3d5.screenX,_3d5.screenY,_3d5.clientX,_3d5.clientY,false,false,false,false,0,null);
_3d5.target.dispatchEvent(_3d7);
_3d3.preventDefault();
}
function initIphone(_3d8){
_3d8.addEventListener("touchstart",touchHandler,true);
_3d8.addEventListener("touchmove",touchHandler,true);
_3d8.addEventListener("touchend",touchHandler,true);
_3d8.addEventListener("touchcancel",touchHandler,true);
}
FenBoard=function(fen,_3da){
if(typeof _3da.pieceSize=="undefined"){
_3da.pieceSize=24;
}
_3da.fenBoard=true;
_3da.dontOutputNavButtons=true;
_3da.avoidMouseoverActive=true;
this.chessapp=new ChessApp(_3da);
this.chessapp.init();
this.chessapp.board.disableUpdateToPlay=true;
this.chessapp.board.setupFromFen(fen,false,false,false);
this.board=this.chessapp.board;
this.board.startFen=fen;
};

