Valid XHTML    Valid CSS2    

Listing du fichier chess.js

 

00001     //CPGv2.2
00002     
00003     
00004     // set page background color;
00005     document.bgColor=lC;
00006     
00007     //find colors or images
00008     var wsq="bgcolor="+wQ;
00009     if(wQ.indexOf(".gif")!=-1||wQ.indexOf(".jpg")!=-1){
00010      wsq="background="+wQ;
00011      }
00012     var bsq="bgcolor="+bQ;
00013     if(bQ.indexOf(".gif")!=-1||bQ.indexOf(".jpg")!=-1){
00014      bsq="background="+bQ;
00015      }
00016     var bsu="background-color:"+boardBACKING;
00017     
00018     
00019     
00020     //preload images
00021     var pn=new Array('r','n','b','q','k','b','n','r','p','p','p','p','p','p','p','p','X','X','X','X','X','X','X','X','X','X','X','X','X','X','X','X','X','X','X','X','X','X','X','X','X','X','X','X','X','X','X','X','wp','wp','wp','wp','wp','wp','wp','wp','wr','wn','wb','wq','wk','wb','wn','wr');
00022     var imgs=new Array;
00023     for(i=0;i<pn.length;i++){
00024      if(pn[i]!="X"){
00025      imgs[pn[i]]=new Image;
00026      imgs[pn[i]].src=pf+pn[i]+".gif";
00027      }
00028      }
00029     imgs["X"]=new Image;
00030     imgs["X"].src="_program/_icons/X.gif";
00031     
00032     
00033     var tb='<table border=0 cellspacing=0 cellpadding=';
00034     var stb='</table>';
00035     var ctb='</td></tr>'+stb;
00036     
00037     
00038     
00039     // total reset
00040     var pla=false;
00041     var down=true;
00042     function allReset(activate){
00043     
00044      if (!pla){
00045      return false;
00046      }
00047     
00048      dc=document.forms["chessform"];
00049     
00050      // reset notation covers
00051      lCov.style.top=arT-16;
00052      nCov.style.left=arL+(sqS*3)+(sqS*8)+2;
00053      down=true;
00054     
00055      // redefine initial arrays
00056      bCCr=true;
00057      wCCr=true;
00058      bCCl=true;
00059      wCCl=true;
00060      XiP=arL;
00061      YiP=arT;
00062      pp=new Array;
00063      bb=new Array;
00064      bw=new Array;
00065      bnb=new Array;
00066      bnw=new Array;
00067      pn=new Array('r','n','b','q','k','b','n','r','p','p','p','p','p','p','p','p','X','X','X','X','X','X','X','X','X','X','X','X','X','X','X','X','X','X','X','X','X','X','X','X','X','X','X','X','X','X','X','X','wp','wp','wp','wp','wp','wp','wp','wp','wr','wn','wb','wq','wk','wb','wn','wr');
00068      Dfn=new Array('r','n','b','q','k','b','n','r','p','p','p','p','p','p','p','p','X','X','X','X','X','X','X','X','X','X','X','X','X','X','X','X','X','X','X','X','X','X','X','X','X','X','X','X','X','X','X','X','wp','wp','wp','wp','wp','wp','wp','wp','wr','wn','wb','wq','wk','wb','wn','wr');
00069      xn=new Array;
00070      alSt="-r-n-b-q-k-b-n-r-p-p-p-p-p-p-p-p-wr-wn-wb-wq-wk-wb-wn-wr-wp-wp-wp-wp-wp-wp-wp-wp";
00071     
00072      // reset black bin
00073      blF=false;
00074      XiP=arL+sqS;
00075      YiP=arT;
00076      i=0;
00077      img=15;
00078      for (bh=0;bh<2;bh++){
00079      for (bv=0;bv<8;bv++){
00080      bb[i]=new Array(XiP,YiP);
00081      bnb[i]="X";
00082      bS[i].style.left=bb[i][0];
00083      bS[i].style.top=bb[i][1];
00084      bI[i].src=imgs[pn[img]].src;
00085      YiP+=sqS;
00086      i++;
00087      img--;
00088      }
00089      YiP=arT;XiP-=sqS;
00090      }
00091     
00092      // reset board pieces
00093      XiP=arL+(sqS*3);
00094      YiP=arT;
00095      i=0;
00096      for (bv=0;bv<8;bv++){
00097      for (bh=0;bh<8;bh++){
00098      pp[i]=new Array(XiP,YiP);
00099      pI[i].src=imgs["X"].src;
00100      pS[i].style.visibility="hidden";
00101      pS[i].style.left=pp[i][0];
00102      pS[i].style.top=pp[i][1];
00103      XiP+=sqS;
00104      i++;
00105      }
00106      XiP=arL+(sqS*3);YiP+=sqS;
00107      }
00108     
00109      // reset white bin
00110      whF=false;
00111      XiP=arL+(sqS*11)+(5*2)+20;
00112      YiP=arT;
00113      i=0;
00114      img=48;
00115      for (bh=0;bh<2;bh++){
00116      for (bv=0;bv<8;bv++){
00117      bw[i]=new Array(XiP,YiP);
00118      bnw[i]="X";
00119      wS[i].style.left=bw[i][0];
00120      wS[i].style.top=bw[i][1];
00121      wI[i].src=imgs[pn[img]].src;
00122      YiP+=sqS;
00123      i++;
00124      img++;
00125      }
00126      YiP=arT;XiP+=sqS;
00127      }
00128     
00129      //castle status
00130      dc["wccr"].value=wCCr;
00131      dc["bccr"].value=bCCr;
00132      dc["wccl"].value=wCCl;
00133      dc["bccl"].value=bCCl;
00134     
00135      // reset game counter
00136      gaP=new Array;
00137      moves=-1;
00138     
00139     
00140      if (activate){
00141     
00142      //handle recorded game
00143      shownIt=false;
00144      dc["gp"].value=0;
00145     
00146      star="";
00147      dc["ant"].value="";
00148      if(annt[0]&&annt[0]!=""){star="*";dc["ant"].value=annt[0];}
00149      var lsNum=Math.round((reco.length-1)/2);if(lsNum==0){lsNum="..";}
00150     
00151     
00152      dc["gpv"].value=".."+star+" /"+lsNum;
00153     
00154      //start again at entry point string
00155      var eString=dc["entry"].value;
00156      if (eString!=""){
00157      dc["start"].value=eString;
00158      if(pla){allReset(false);}setP('custom');
00159      // start again with blank but active board
00160      }else{
00161      dc["start"].value="8/8/8/8/8/8/8/8 w KQkq - 0 1";
00162      if(pla){allReset(false);}setP('custom');
00163      }
00164      }
00165      }
00166     
00167     
00168     
00169     // board left and top
00170     var arL,arT;
00171     arL=4+bsPos;
00172     arT=76+bsPos;
00173     
00174     
00175     //pieces can castle
00176     var bCCr=true;
00177     var wCCr=true;
00178     var bCCl=true;
00179     var wCCl=true;
00180     
00181     // logfile moves array
00182     var moL=new Array;
00183     var moC=new Array;
00184     var loN=0;
00185     
00186     // square codes
00187     var lCo=new Array('a','b','c','d','e','f','g','h');
00188     var cc=new Array;
00189     var sqid=new Array;
00190     
00191     //recording enabled
00192     var ato=false;
00193     
00194     //reco
00195     var reco=new Array;
00196     var rNum=0;
00197     var chessTimer;
00198     var gMoves=new Array;
00199     var finalPos="";
00200     var savG=new Array;
00201     var savN=new Array;
00202     var paC="";
00203     var allC=false;
00204     var pcfM=new Array;
00205     var pcfXd=new Array;
00206     var fenXd=new Array;
00207     var annt=new Array;
00208     var star="";
00209     var ckC=0;
00210     var taNa=new Array("Event","Site","Date","Round","White","Black","Result","WhiteElo","BlackElo","WhiteNationality","BlackNationality");
00211     var taVa=new Array(aE,aS,aD,aR,aW,aB,aRe,aWE,aBE,aWN,aBN);
00212     
00213     //validation
00214     var tVal=new Array;
00215     var tNVal=new Array;
00216     var tvNum=0;
00217     var aSq=new Array;
00218     var valEnp=-1;
00219     
00220     var xIC='<img src="'+imgs["X"].src+'" width=14 height=14 border=0 alt="">';
00221     
00222     // compile chessboard
00223     var cb='';
00224     var odd=0;
00225     
00226     
00227     
00228     cb+='<div style="z-index:1\;position:absolute\;left:'+(arL+(sqS*3)-18)+'px\;top:'+(arT-18)+'px\;">';
00229     cb+=tb+'2><tr><td bgcolor="'+bC+'">';
00230     
00231     
00232     cb+=tb+'0 '+bsu+'>';
00233     cb+=tb+'0 style="'+bsu+'">';
00234     cb+='<tr>';
00235     cb+='<td>'+xIC+'</td>';
00236     cb+='<td><span style="font-size:8px;font-family:arial;color:'+bC+';"><img src="'+imgs["X"].src+'" width=2 height=11></span></td>';
00237     var letters=new Array('A','B','C','D','E','F','G','H');
00238     for (i=7;i>=0;i--){
00239      cb+='<td width="'+sqS+'" align=center><span style="cursor:default;font-size:8px;font-family:arial;color:'+bC+';">'+letters[i]+'</span></td>';
00240      }
00241     cb+='<td>'+xIC+'</td>';
00242     cb+='</tr>';
00243     cb+='<tr>';
00244     cb+='<td height="'+sqS+'" align=center><span style="cursor:default;font-size:8px;font-family:arial;color:'+bC+';">8</span></td>';
00245     cb+='<td colspan=9 rowspan=8 align=center>';
00246     
00247     cb+=tb+'2 width='+((sqS*8)+4)+' height='+((sqS*8)+4)+'><tr><td bgcolor="'+bC+'"><table border=0 cellspacing=0 cellpadding=0 bgcolor="'+lC+'"><tr><td>';
00248     cb+=tb+'0 width='+(sqS*8)+' height='+(sqS*8)+' bgcolor="'+lC+'">';
00249     
00250     i=0;
00251     var CL=0;
00252     var CN=8;
00253     
00254     for (bv=0;bv<8;bv++){
00255      cb+='<tr>';
00256      for (bh=0;bh<8;bh++){
00257      // square name
00258      cc[i]=lCo[CL]+CN;
00259      //square ident
00260      sqid[i]=new Array(bv,bh);
00261      // square
00262      odd++;
00263      var cellBG=wsq;
00264      var ssnC=dC;
00265      if ((parseInt(odd/2))==(odd/2)){
00266      cellBG=bsq;
00267      ssnC=lC;
00268      }
00269      var ssn='';
00270      var sno=i;
00271      if (showSquareInfo=="names"){sno=cc[i];}
00272      if (showSquareInfo=="both"){sno=i+"<br>"+cc[i];}
00273      if (showSquareInfo!=""){ssn='<span style="font-size:9px\;font-family:verdana\;color:'+ssnC+'">'+sno+'</span>';}
00274      cb+='<td width='+sqS+' height='+sqS+' align=center valign=middle '+cellBG+'><img src="'+imgs["X"].src+'" width=1 height=1 alt="" border=0>'+ssn+'</td>';
00275      CL++;i++;
00276      if (CL>7){CL=0;CN--;}
00277      }
00278      cb+='</tr>';
00279      odd+=1;
00280      }
00281     
00282     cb+=stb;
00283     cb+=ctb;
00284     cb+=ctb;
00285     
00286     var oTD='<td height="'+sqS+'" align=center><span style="cursor:default;font-size:8px;font-family:arial;color:'+bC+';">';
00287     
00288     cb+='</td>';
00289     cb+=oTD+'1</span></td>';
00290     cb+='</tr>';
00291     var j=7;
00292     for (i=2;i<9;i++){
00293      cb+='<tr>';
00294      cb+=oTD+j+'</span></td>';
00295      cb+=oTD+i+'</span></td>';
00296      cb+='</tr>';
00297      j--;
00298      }
00299     cb+='<tr>';
00300     cb+='<td>'+xIC+'</td>';
00301     cb+='<td><img src="'+imgs["X"].src+'" width=2 height=11></td>';
00302     for (i=0;i<8;i++){
00303      cb+='<td width="'+sqS+'" align=center><span style="cursor:default;font-size:8px;font-family:arial;color:'+bC+';">'+letters[i]+'</span></td>';
00304      }
00305     cb+='<td>'+xIC+'</td>';
00306     cb+='</tr>';
00307     cb+=stb;
00308     
00309     
00310     cb+=ctb;
00311     cb+='</div>';
00312     
00313     
00314     
00315     
00316     // make inital piece position and identity arrays
00317     var XiP=arL;
00318     var YiP=arT;
00319     
00320     var pp=new Array;
00321     var on=new Array;
00322     var mp=new Array;
00323     var gaP=new Array;var moves=-1;
00324     var bb=new Array;
00325     var bw=new Array;
00326     var bnb=new Array;
00327     var bnw=new Array;
00328     var Dfn=new Array('r','n','b','q','k','b','n','r','p','p','p','p','p','p','p','p','X','X','X','X','X','X','X','X','X','X','X','X','X','X','X','X','X','X','X','X','X','X','X','X','X','X','X','X','X','X','X','X','wp','wp','wp','wp','wp','wp','wp','wp','wr','wn','wb','wq','wk','wb','wn','wr');
00329     var fpn=new Array('r','n','b','q','k','b','n','r','p','p','p','p','p','p','p','p','X','X','X','X','X','X','X','X','X','X','X','X','X','X','X','X','X','X','X','X','X','X','X','X','X','X','X','X','X','X','X','X','wp','wp','wp','wp','wp','wp','wp','wp','wr','wn','wb','wq','wk','wb','wn','wr');
00330     var xn=new Array;
00331     
00332     
00333     
00334     // board piece objects
00335     var pS=new Array;
00336     var pI=new Array;
00337     
00338     //square names to numbers
00339     var sqn=new Array;
00340     var iq=0;
00341     for(jq=8;jq>0;jq--){
00342      for(nq=0;nq<8;nq++){
00343      sqn[iq]=lCo[nq]+jq;
00344      iq++;
00345      }
00346      }
00347     
00348     //create an array of pieces indexed by square name
00349     var sqp=new Array;
00350     for(i=0;i<64;i++){
00351      sqp[cc[i]]=new Array(Dfn[i],i);
00352      }
00353     
00354     
00355     
00356     
00357     
00358     // script string for default board layout
00359     var alSt="-r-n-b-q-k-b-n-r-p-p-p-p-p-p-p-p-wr-wn-wb-wq-wk-wb-wn-wr-wp-wp-wp-wp-wp-wp-wp-wp";
00360     
00361     var xDe=new Array;
00362     
00363     // prx sensitivity
00364     var prx=sqS/2;
00365     
00366     
00367     // html string
00368     var pc='';
00369     
00370     // compile black bin images
00371     
00372     var XiP=arL+sqS;
00373     var YiP=arT;
00374     
00375     var i=0;
00376     var img=15;
00377     
00378     for (bh=0;bh<2;bh++){
00379      for (bv=0;bv<8;bv++){
00380      bb[i]=new Array(XiP,YiP);
00381      bnb[i]="X";
00382      pc+='<span id="binb'+i+'" style="visibility:visible\;z-index:1\;position:absolute\;left:'+bb[i][0]+'px\;top:'+bb[i][1]+'px\;" onmouseover="setpieceid(this)" onmouseout="setpieceid(null)">';
00383      pc+='<img name="binbpeace'+i+'" src="'+imgs["X"].src+'" width='+sqS+' height='+sqS+'>';
00384      pc+='</span>';
00385      YiP+=sqS;
00386      i++;
00387      img--;
00388      }
00389      YiP=arT;XiP-=sqS;
00390      }
00391     
00392     
00393     
00394     
00395     // compile last move borders
00396     pc+='<span id="lm0" style="z-index:2\;visibility:hidden\;position:absolute\;left:'+(arL+(sqS*3))+'px\;top:'+arT+'px\;">';
00397     var pvTA=tb+'0 style="border:2px solid red"><tr><td><img src="'+imgs["X"].src+'" width='+(sqS-4)+' height='+(sqS-4)+' alt="" border=0>'+ctb;
00398     pc+=pvTA;
00399     pc+='</span>';
00400     pc+='<span id="lm1" style="z-index:2\;visibility:hidden\;position:absolute\;left:'+(arL+(sqS*3))+'px\;top:'+arT+'px\;">';
00401     pc+=pvTA;
00402     pc+='</span>';
00403     
00404     
00405     
00406     
00407     
00408     
00409     
00410     // compile chessboard images
00411     
00412     var XiP=arL+(sqS*3);
00413     var YiP=arT;
00414     
00415     var vmm='';
00416     
00417     // store code separately
00418     var nsc=new Array;
00419     
00420     i=0;odd=0;
00421     
00422     for (bv=0;bv<8;bv++){
00423      for (bh=0;bh<8;bh++){
00424      pp[i]=new Array(XiP,YiP);
00425      on[i]=new Array(XiP,YiP);
00426      nsc[i]='';
00427     
00428      //legal move markers
00429      vmm+='<span id="square'+i+'" style="position:absolute\;width:'+sqS+'px\;height:'+sqS+'px;visibility:hidden\;z-index:2\;position:absolute\;left:'+(pp[i][0])+'px\;top:'+(pp[i][1])+'px\;"><img src="_program/_icons/valid.gif" width='+sqS+' height='+sqS+' alt="" border=0></span>';
00430      nsc[i]+='<span id="play'+i+'" style="visibility:hidden\;z-index:4\;position:absolute\;left:'+pp[i][0]+'px\;top:'+pp[i][1]+'px\;" onmouseover="init()\;setpieceid(this)" onmouseout="setpieceid(null)">';
00431      var shadFilter="";
00432      if(ie5p&&shadowCOLOR!=""){
00433      shadFilter= ' style="filter:shadow(color='+shadowCOLOR+',direction=135,strength=1,enabled=false)"';
00434      }
00435      nsc[i]+='<img name="peace'+i+'" id="peace" src="'+imgs["X"].src+'" width='+sqS+' height='+sqS+shadFilter+'>';
00436      nsc[i]+='</span>';
00437      pc+=nsc[i];
00438      XiP+=sqS;
00439      i++;
00440      }
00441      XiP=arL+(sqS*3);YiP+=sqS;
00442     
00443      }
00444     
00445     
00446     
00447     // compile white bin images
00448     
00449     var XiP=arL+(sqS*11)+(5*2)+20;
00450     var YiP=arT;
00451     
00452     i=0;
00453     img=48;
00454     
00455     for (bh=0;bh<2;bh++){
00456      for (bv=0;bv<8;bv++){
00457      bw[i]=new Array(XiP,YiP);
00458      bnw[i]="X";
00459      pc+='<span id="binw'+i+'" style="visibility:visible\;z-index:1\;position:absolute\;left:'+bw[i][0]+'px\;top:'+bw[i][1]+'px\;" onmouseover="setpieceid(this)" onmouseout="setpieceid(null)">';
00460      pc+='<img name="binwpeace'+i+'" src="'+imgs["X"].src+'" width='+sqS+' height='+sqS+'>';
00461      pc+='</span>';
00462      YiP+=sqS;
00463      i++;
00464      img++;
00465      }
00466      YiP=arT;XiP+=sqS;
00467      }
00468     
00469     
00470     
00471     // compile notation covers
00472     var nc='';
00473     nc+='<span id="lcover" style="'+bsu+'\;z-index:10\;position:absolute\;left:'+(arL+(sqS*3))+'px\;top:'+(arT-16)+'px\; width:'+(sqS*8)+'px\;height:14px\;"><img src="'+imgs["X"].src+'" height=1 width=1 border=0 alt=""></span>';
00474     nc+='<span id="ncover" style="'+bsu+'\;z-index:10\;position:absolute\;left:'+(arL+(sqS*3)+(sqS*8)+2)+'px\;top:'+(arT)+'px\; width:14px\;height:'+(sqS*8)+'px\;"><img src="'+imgs["X"].src+'" height=1 width=1 border=0 alt=""></span>';
00475     
00476     
00477     
00478     
00479     
00480     // draw the chessboard, blank pieces and notation covers
00481     if (!exclude){
00482      document.open();
00483      document.write(vmm);
00484      document.write(cb);
00485      document.write(nc);
00486      document.write(pc);
00487      document.close();
00488      }
00489     
00490     
00491     //compile array of square IDs
00492     var sq=new Array;
00493     var sqc=new Array;
00494     for (i=0;i<64;i++){
00495      sq[i]=document.getElementById("square"+i);
00496      }
00497     
00498     
00499     
00500     // notation cover objects
00501     var lCov=document.getElementById("lcover");
00502     var nCov=document.getElementById("ncover");
00503     
00504     
00505     
00506     
00507     // black bin piece objects
00508     var bS=new Array;
00509     var bI=new Array;
00510     var blF=false;
00511     // white bin piece objects
00512     var wS=new Array;
00513     var wI=new Array;
00514     var whF=false;
00515     
00516     // build bin id arrays
00517     for (i=0;i<16;i++){
00518      bS[i]=document.getElementById("binb"+i);
00519      bI[i]=document.getElementById("binb"+i).firstChild;
00520      wS[i]=document.getElementById("binw"+i);
00521      wI[i]=document.getElementById("binw"+i).firstChild;
00522      }
00523     
00524     
00525     
00526     // plot start positions
00527     
00528     
00529     
00530     var s;
00531     var qFound=false;
00532     var lastmove=false;
00533     var movea='';
00534     var moveb='';
00535     
00536     var lmS=new Array;
00537     lmS[0]=document.getElementById("lm0");
00538     lmS[1]=document.getElementById("lm1");
00539     
00540     
00541     
00542     
00543     
00544     // hide last position indicators
00545     function hideLastMove(){
00546      // reset last move indicators
00547      lmS[0].style.visibility="hidden";
00548      lmS[1].style.visibility="hidden";
00549      }
00550     
00551     
00552     
00553     // find and move last position indicators
00554     var shownIt=false;
00555     function findLastMove(lastmove){
00556      if (lastmove&&lastmove!=''){
00557      if(shownIt){return false;}
00558      shownIt=true;
00559      movea=lastmove.charAt(0)+lastmove.charAt(1);
00560      moveb=lastmove.charAt(2)+lastmove.charAt(3);
00561      for (i=0;i<64;i++){
00562      if (cc[i]==movea){
00563      lmS[0].style.left=on[i][0];
00564      lmS[0].style.top=on[i][1];
00565      lmS[0].style.visibility="visible";
00566      }
00567      if (cc[i]==moveb){
00568      lmS[1].style.left=on[i][0];
00569      lmS[1].style.top=on[i][1];
00570      lmS[1].style.visibility="visible";
00571      }
00572      }
00573      }
00574      }
00575     
00576     
00577     
00578     var flNum=-1;
00579     var qsLast='';
00580     var lpdone=false;
00581     var storeQS='';
00582     var inputV="";
00583     var iRecorder=new Array;
00584     var ui=false;
00585     var dc;
00586     var firstLast="";
00587     var prvC=-1;
00588     var panels=new Array(true,true,true,true,true);
00589     var secu=false;
00590     var cecu=false;
00591     var cecu="%26nbsp%3B%3CSPAN%20class%3Ddaco%3EChessPlayer%20v2.0%20by%20%3C/SPAN%3E%3CA%20class%3Ddaco%20style%3D%22CURSOR%3A%20hand%3B%20TEXT-DECORATION%3A%20none%22%20href%3D%22http%3A//www.brothercake.com/%22%20target%3D_blank%3E%3CIMG%20class%3Dlogo%20height%3D16%20alt%3D%22%22%20src%3D%22_program/_icons/favicon.gif%22%20width%3D16%20border%3D0%3EBrothercake%3C/A%3E%3CSPAN%20class%3Ddaco%3E%20in%20association%20with%20%3C/SPAN%3E%3CA%20class%3Ddaco%20style%3D%22CURSOR%3A%20hand%3B%20TEXT-DECORATION%3A%20none%22%20href%3D%22http%3A//www.chessworld.net/%22%20target%3D_blank%3EChessWorld.net%3C/A%3E%3CILAYER%20id%3Dmsg%3E%3C/ILAYER%3E";
00592     
00593     function setP(layout,lastmove,logurl,viewauto){
00594     
00595      dc=document.forms["chessform"];
00596     
00597      secu=document.getElementById("msg");
00598      //if(secu&&secu.length&&secu.length>1){if(secu[0].innerHTML!=unescape(cecu)){secu[0].innerHTML="";secu=false;}}
00599     
00600      if(!secu){return false;}
00601     
00602      // first time setup
00603      if (!pla){
00604     
00605      window.defaultStatus="Compiling ...";
00606     
00607      // assign button names
00608      dc["sv"].value="Switch viewpoint";
00609      dc["ato"].value="Record";
00610      dc["ato"].title="Record";
00611      dc["rp"].value="Play";
00612      dc["rp"].title="Play through";
00613      dc["gp"].value="0";
00614      dc["ls"].value=-1;
00615      dc["gpv"].value=".. /..";
00616      dc["b"].value="«";
00617      dc["rw"].value="<";
00618      dc["ff"].value=">";
00619      dc["e"].value="»";
00620      dc["sp"].value="« In";
00621      dc["op"].value="« Out";
00622      dc["vr"].value=-1;
00623      dc["vw"].value=true;
00624      dc["ant"].value="";
00625     
00626      if(showLEGAL){dc["slm"].checked=true;}
00627      if(blockILLEGAL){dc["dim"].checked=true;}
00628     
00629      dc["aE"].value=taVa[0];
00630      dc["aS"].value=taVa[1];
00631      dc["aD"].value=taVa[2];
00632      dc["aR"].value=taVa[3];
00633      dc["aW"].value=taVa[4];
00634      dc["aB"].value=taVa[5];
00635      dc["aRe"].value=taVa[6];
00636      dc["aWE"].value=taVa[7];
00637      dc["aBE"].value=taVa[8];
00638      dc["aWN"].value=taVa[9];
00639      dc["aBN"].value=taVa[10];
00640     
00641      dc["newg"].value="New game";
00642      dc["clrb"].value="Clear";
00643     
00644      dc["andan"].style.visibility="visible";
00645     
00646      //reset reco
00647      if(!gIn){
00648      reco=new Array;
00649      rNum=0;
00650      reco[rNum]=dc["start"].value;
00651      rNum++;
00652      }
00653     
00654      //if game input, add values to reco
00655      if(gIn){
00656     
00657      var lsNum=Math.round((reco.length-1)/2);if(lsNum==0){lsNum="..";}
00658     
00659     
00660     
00661      if(firstLast!=""){
00662      //alert(flNum);
00663      dc["ls"].value=(flNum);
00664      dc["gp"].value=(flNum+1);
00665      star="";
00666      dc["ant"].value="";
00667      if(annt[(flNum+1)]&&annt[(flNum+1)]!=""){star="*";dc["ant"].value=annt[(flNum+1)];}
00668      var gpVal=(flNum+1)/2;
00669      if(parseFloat(gpVal)!=parseInt(gpVal)){gpVal=Math.round(gpVal);gpVal+=".";}
00670      else{if(gpVal>0){gpVal+="..";}else{gpVal="..";}}
00671      dc["gpv"].value=gpVal+star+" /"+lsNum;
00672      }else{
00673      dc["ls"].value=-1;
00674      dc["gp"].value=0;
00675      star="";
00676      dc["ant"].value="";
00677      if(annt[0]&&annt[0]!=""){star="*";dc["ant"].value=annt[0];}
00678      dc["gpv"].value=".."+star+" /"+lsNum;
00679      }
00680     
00681      }
00682     
00683      //change form text to indicate processed game
00684      dc["ato"].disabled=false;
00685      dc["ato"].value="Record";
00686      dc["ato"].title="Record";
00687      if(gIn) {
00688      dc["reco"].options[1].style.color=bC;
00689      dc["reco"].options[2].style.color=bC;
00690      dc["reco"].options[3].style.color=bC;
00691      if(ie5p&&enablePgnImport) { dc["reco"].options[8].style.color=bC; }
00692      else { dc["reco"].options[7].style.color=bC; }
00693      }
00694      //turn off input conversion
00695      gIn=false;
00696     
00697      }
00698     
00699     
00700     
00701      // look for query string
00702      if (!qFound){
00703     
00704      getQuery(true);
00705     
00706      // if position specified
00707      if (location.search){
00708     
00709      var qInfo="rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1";
00710      if(qStr['pos']){qInfo=qStr['pos'];}
00711      qFound=true;
00712     
00713      // if panel preferences specified
00714      if (qStr['panels']){
00715      panels=qStr['panels'].split(",");
00716     
00717      var tabs=new Array("cog","vog","rog","mog","pog");
00718      for(j=0;j<5;j++){
00719      if(panels[j]=="false"){showP[j]=false;dog(tabs[j]+"-tab").click();}
00720      }
00721     
00722      dc["panels"].value=qStr['panels'];
00723      }
00724     
00725      // if last move specified
00726      if (qStr['last']){
00727      //findLastMove(qStr['last']);
00728      qsLast=qStr['last'];
00729      }
00730     
00731      // if recorded game input
00732      if (qStr['game']){
00733      storeQS=qStr['game'];
00734     
00735      //if last move is specified, set board to final position
00736      if(qStr['last']){
00737      firstLast=qStr['last'];
00738      //qInfo=qStr['finalpos'];
00739      }
00740     
00741      processGame(qStr['game']);
00742      }
00743     
00744      //if fixed alternative view specified
00745      if (qStr['view']){
00746      inputV=qStr['view'];
00747      }
00748     
00749     
00750      //if validation/display specified
00751      if (qStr['showLegal']){
00752      if (qStr['showLegal']=="true"){
00753      showLEGAL=true;
00754      dc["slm"].checked=true;
00755      }
00756      if (qStr['showLegal']=="false"){
00757      showLEGAL=false;
00758      dc["slm"].checked=false;
00759      }
00760      }
00761      if (qStr['blockIllegal']){
00762      if (qStr['blockIllegal']=="true"){
00763      blockILLEGAL=true;
00764      dc["dim"].checked=true;
00765      }
00766      if (qStr['blockIllegal']=="false"){
00767      blockILLEGAL=false;
00768      dc["dim"].checked=false;
00769      }
00770      }
00771     
00772      //show last position if specified
00773      if(firstLast!=""){
00774      //alert(flNum);
00775      qInfo=reco[(flNum+1)];
00776      //firstLast="";
00777      lgc=dog("logcell"+(flNum+1));
00778      if(showP[3]){
00779      dog("movetable").scrollTop=lgc.offsetTop-2;
00780      }
00781      lgc.style.backgroundColor=lC;
00782      lgc.style.color=dC;
00783      prvC=(flNum+1);
00784      }
00785     
00786      //display
00787      dc["start"].value=qInfo;
00788      dc["current"].value=qInfo;
00789      dc["entry"].value=qInfo;
00790      if(pla){allReset(false);}setP('custom');
00791      return false;
00792      }
00793      }
00794     
00795     
00796      // find if start position was specified
00797      if (exclude||layout==null||layout==""){return false;}
00798     
00799     
00800      // find last move
00801      findLastMove(lastmove);
00802     
00803     
00804      // write custom position to text field and initialise
00805      if (layout!="custom"&&layout!=""){
00806      if (moves>-1){return false;}
00807      var presetLayout=layout;
00808      dc["start"].value=presetLayout;
00809      dc["entry"].value=presetLayout;
00810      if(pla){allReset(false);}setP('custom');
00811      return false;
00812      }
00813     
00814      if (moves>-1){return false;}
00815     
00816      // bin numbers
00817      var ibb=0;var ibw=0;
00818      dc["vbb"].value=ibb;
00819      dc["vbw"].value=ibw;
00820     
00821      s=0;
00822      //extract basic position string
00823      var sInfo=dc["start"].value.split(" ");
00824      var sPos=sInfo[0];
00825     
00826      //compenate if extra FEN info is not there or fully there
00827      if(!sInfo[1]){
00828      sInfo[1]="w";
00829      VW=true;
00830      dc["vw"].value=VW;
00831      }
00832     
00833      //extra FEN information
00834      for(i=0;i<sInfo.length;i++){
00835      xDe[i]=sInfo[i];
00836      }
00837      xDe[4]=parseInt(xDe[4]);
00838      xDe[5]=parseInt(xDe[5]);
00839      //alert(xDe[1]+"\n"+xDe[2]+"\n"+xDe[3]+"\n"+xDe[4]+"\n"+xDe[5]);
00840     
00841      //FEN information to hidden form
00842      dc["ctm"].value=xDe[1];
00843      //castle status
00844      if(xDe[2].indexOf("K")!=-1){wCCr=true;}else{wCCr=false;}
00845      if(xDe[2].indexOf("Q")!=-1){wCCl=true;}else{wCCl=false;}
00846      if(xDe[2].indexOf("k")!=-1){bCCr=true;}else{bCCr=false;}
00847      if(xDe[2].indexOf("q")!=-1){bCCl=true;}else{bCCl=false;}
00848      dc["wccr"].value=wCCr;
00849      dc["bccr"].value=bCCr;
00850      dc["wccl"].value=wCCl;
00851      dc["bccl"].value=bCCl;
00852      dc["enp"].value=xDe[3];
00853      if(xDe[3]!="-"){
00854      for(xd=0;xd<sqn.length;xd++){
00855      if(xDe[3]==sqn[xd]){enpn=xd;}
00856      }
00857      }
00858      dc["hmc"].value=xDe[4];
00859      dc["fmc"].value=xDe[5];
00860     
00861      // add first position to game progress array
00862      if (moves<0){
00863      moves++;
00864      gaP[moves]=dc["start"].value;
00865      moves++;
00866      }
00867     
00868     
00869      // filter position string for slash, space and line breaks
00870      while ((sPos.indexOf("/")!=-1)||(sPos.indexOf(/[\ ]/g)!=-1)||(sPos.indexOf(/\n?\r?/g)!=-1)){
00871      sPos=sPos.replace('/','');
00872      sPos=sPos.replace(/[\ ]/g,'');
00873      sPos=sPos.replace(/\n?\r?/g,'');
00874      }
00875     
00876     
00877      // build name and position arrays - convert blank numbers into "X"s and filled squares into piece names
00878      for (i=0;i<sPos.length;i++){
00879      var st=sPos.charAt(i);
00880      var nt=Number(st);
00881      if(s<64){
00882      if ((nt*1)>=0){
00883      st=Number(st);
00884      //s=0;
00885      //alert(s+"-"+on[s]);
00886      for (ps=0;ps<st;ps++){
00887      xn[s]="X";
00888      //alert(on[s]);
00889      mp[s]=new Array(on[s][0],on[s][1]);
00890      s++;
00891      }
00892      }else{
00893      xn[s]=st;
00894      mp[s]=new Array(on[s][0],on[s][1]);
00895      var tpn=xn[s].toLowerCase();
00896      if (tpn!=xn[s]){xn[s]="w"+tpn;}
00897      alSt=alSt.replace('-'+xn[s],'');
00898      //alert(alSt);
00899      s++;
00900      }
00901      }
00902      }
00903     
00904     
00905     
00906      //build id arrays
00907      for (as=0;as<64;as++){
00908      pS[as]=document.getElementById("play"+as);
00909      pI[as]=document.getElementById("play"+as).firstChild;
00910      }
00911     
00912     
00913      var dObj=new Array;
00914      var stringValid=false;
00915     
00916     
00917      // if string is valid
00918      if (xn.length==64){
00919      // draw pieces
00920      for (i=0;i<64;i++){
00921      if (pn[i]!="X"){
00922      // set pieces
00923      pI[i].src=imgs[pn[i]].src;
00924      }
00925      }
00926     
00927     
00928      // enable form
00929      dc["op"].disabled=false;
00930      dc["sv"].disabled=false;
00931      stringValid=true;
00932      // shift pieces to start positions
00933      movePieces();
00934      // initialise event detection
00935      init();
00936     
00937      //single view switch
00938      if(inputV!=""){
00939      if(inputV=="b"&&!pla){dc["sv"].click();}
00940      }
00941     
00942      // enable reset function
00943      pla=true;
00944     
00945      //hide last position indicators if already visible
00946      if(lmS[0]&&lmS[0].style.visibility=="visible"){hideLastMove();lpdone=true;}
00947     
00948      //indicate last move
00949      if(qsLast!=""&&!lpdone){findLastMove(qsLast);}
00950     
00951      window.defaultStatus="Done";
00952     
00953      }else{
00954      dc["start"].value="Incorrect input string";
00955      window.defaultStatus="Incorrect input string";
00956      gaP[1]='';
00957      gaP[0]='';
00958      moves=-1;
00959      }
00960     
00961      }
00962     
00963     
00964     
00965     
00966     // move pieces to start position once drawn
00967     function movePieces(){
00968     
00969      // bin status
00970      var ibb=dc["vbb"].value;
00971      var ibw=dc["vbw"].value;
00972     
00973      for (i=0;i<64;i++){
00974     
00975      // if default location not the same as input location
00976      if(pn[i]!=xn[i]){
00977     
00978      // change image srcs if images can be swapped
00979      if (xn[i]!="X"){
00980      pI[i].src=imgs[xn[i]].src;
00981      // swap names
00982      var tempXN=xn[i];
00983      xn[i]=pn[i];
00984      pn[i]=tempXN;
00985     
00986      // or assign Xs if piece has been taken
00987      }else{
00988      pI[i].src=imgs["X"].src;
00989      pn[i]="X";
00990      }
00991     
00992      }
00993      }
00994     
00995      // compare arrays to find which pieces are in the bin
00996      var found=new Array;
00997      for (i=0;i<64;i++){
00998      found[i]=false;
00999      }
01000     
01001      for (j=0;j<64;j++){
01002      for (i=0;i<64;i++){
01003      if (!found[i]){
01004      if (Dfn[j]==pn[i]){
01005      Dfn[j]="f";
01006      found[i]=true;
01007      }
01008      }
01009      }
01010      }
01011     
01012      // reset bin pieces to blank
01013      for (i=0;i<16;i++){
01014      bI[i].src=imgs["X"].src;
01015      wI[i].src=imgs["X"].src;
01016      }
01017     
01018     
01019      // draw bin pieces
01020      for (i=0;i<64;i++){
01021      if (Dfn[i]!="f"){
01022      //alert(Dfn[i]+" - "+i);
01023      // white bin
01024      if (Dfn[i].indexOf("w")!=-1){
01025      if (wI[ibw]){wI[ibw].src=imgs[Dfn[i]].src;}
01026      bnw[ibw]=Dfn[i];
01027      ibw++;
01028      // black bin
01029      }else{
01030      if (bI[ibb]){bI[ibb].src=imgs[Dfn[i]].src;}
01031      bnb[ibb]=Dfn[i];
01032      ibb++;
01033      }
01034     
01035      }
01036     
01037      // show chess pieces
01038      pS[i].style.visibility="visible";
01039      }
01040     
01041      // write bin fullness to form
01042      var ibb=dc["vbb"].value=ibb;
01043      var ibw=dc["vbw"].value=ibw;
01044     
01045     
01046      // show bin pieces
01047      for (i=0;i<16;i++){
01048      bS[i].style.visibility="visible";wS[i].style.visibility="visible";
01049      }
01050     
01051      }
01052     
01053     
01054     
01055     
01056     
01057     
01058     
01059     // reload page at different scale
01060     function scaleReload(){
01061      if(!secu){dc["scale"].options[0].selected=true;return false;}
01062      var scrScale=dc["scale"].options[document.forms.chessform.scale.selectedIndex].value;
01063      var scrLoc='';
01064      var nQS=window.location.search.substr(1);
01065      nQS=nQS.replace("&size="+sqS,"");
01066      nQS=nQS.replace("&pieces="+pf.replace('/',''),"");
01067      nQS=nQS.replace("&showLegal="+showLEGAL,"");
01068      nQS=nQS.replace("&blockIllegal="+blockILLEGAL,"");
01069      nQS=nQS.replace("&view=b","");
01070      nQS=nQS.replace("&view=w","");
01071      nQS=nQS.replace("&panels="+dc['panels'].value,"");
01072      for(j=0;j<taNa.length;j++){
01073      nQS=nQS.replace("&"+taNa[j]+"="+taVa[j],"");
01074      }
01075      var colStr="&view=w";
01076      if(inputV=="b"){colStr="&view=b";}
01077      if(nQS){scrLoc=pageName+"?"+nQS+"&panels="+dc['panels'].value+"&size="+parseInt(squareSIZE*scrScale)+colStr+"&pieces="+pf.replace('/','')+"&showLegal="+showLEGAL+"&blockIllegal="+blockILLEGAL;}
01078      else{
01079      findPieceIds();
01080      var scrPos=dc["entry"].value;
01081      scrLoc=pageName+"?pos="+scrPos+"&panels="+dc['panels'].value+"&size="+parseInt(squareSIZE*scrScale)+colStr+"&pieces="+pf.replace('/','')+"&showLegal="+showLEGAL+"&blockIllegal="+blockILLEGAL;
01082      }
01083      for(j=0;j<taNa.length;j++){
01084      scrLoc+="&"+taNa[j]+"="+taVa[j];
01085      }
01086      self.document.location=scrLoc
01087      }
01088     
01089     
01090     
01091     
01092     var dragokay=false;
01093     var moveokay=false;
01094     var movedone=false;
01095     
01096     var activated=false;
01097     
01098     
01099     function init(){
01100      if (!activated){
01101      document.onmousedown=mouseDown;
01102      document.onmousemove=mouseMove;
01103      document.onmouseup=mouseUp;
01104      document.ondblclick=changePiece;
01105      activated=true;
01106      }
01107      }
01108     
01109     
01110     function doNothing(){}
01111     function uninit(){
01112      document.onmousedown=doNothing;
01113      document.onmousemove=doNothing;
01114      document.onmouseup=doNothing;
01115      activated=false;
01116      }
01117     
01118     var forced=false;
01119     
01120     
01121     
01122     var ICOut = false;
01123     //is the king in check
01124     function isInCheck(selfSq) {
01125     
01126      //theoretical board position for validation
01127      if(selfSq) {
01128      //remove self square
01129      var aSqLen = aSq.length;
01130      for(i=0;i<aSqLen;i++){
01131      if(aSq[i]==selfSq) {
01132      aSq.splice(i,1);
01133      }
01134      }
01135      window.status = aSq;
01136     
01137      aSqLen = aSq.length;
01138      for(i=0;i<aSqLen;i++){
01139     
01140     
01141     
01142     
01143      }
01144     
01145      ICOut=false;
01146      }
01147     
01148      //generic "is king in check"
01149      else {
01150      //window.status = "generic";
01151      ICOut=true;
01152      }
01153     
01154     
01155      var asqLen = aSq.length;
01156     
01157      }
01158     
01159     
01160     
01161     // change any square to any piece
01162     function changePiece(){
01163     
01164      // check event came from the board
01165      var ckx=dc["kxinfo"].value;
01166      var cky=dc["kyinfo"].value;
01167      if ((ckx<on[0][0]||ckx>(on[7][0]+sqS)) || (cky<on[0][1]||cky>(on[63][1]+sqS))){return false;}
01168     
01169      // find piece id from hidden form
01170      var piece=dc["pieceid"].value;
01171      var cmName=prompt("Enter piece code","");
01172      // if invalid
01173      if (cmName==""||cmName==null) return false;
01174      // check if black or white
01175      var tempCM=cmName.toLowerCase();
01176      var iokay=false
01177      for (i=0;i<9;i++){if (tempCM==fpn[i]||tempCM=="x"){iokay=true;}}
01178      if(!iokay){
01179      return false;
01180      }else{
01181      if (tempCM=="x"){cmName="X";}
01182      else if (tempCM!=cmName){
01183      cmName="w"+tempCM;
01184      }
01185      }
01186      // change image and identity
01187      if(cmName=="X"){pI[piece].src=imgs["X"].src;}
01188      else{pI[piece].src=imgs[cmName].src;}
01189      pn[piece]=cmName;
01190      }
01191     
01192     
01193     
01194     
01195     
01196     
01197     //to check if two pieces are the same color
01198     var pAt=new Array;
01199     var same=false;
01200     function comC(scA,scB){
01201      same=false;
01202      if(scA.indexOf("g")!=-1){scA=scA.replace("g","w");}
01203      if(scA.indexOf("v")!=-1){scA=scA.replace("v","");}
01204      if(scA&&scB){
01205      if ((scA.indexOf("w")!=-1&&scB.indexOf("w")!=-1) || (scA.indexOf("w")!=-1&&scB.indexOf("v")!=-1) || (scA.indexOf("w")==-1&&scB.indexOf("w")==-1)){
01206      same=true;
01207      }
01208      }
01209      }
01210     
01211     
01212     
01213     
01214     //automated comparisons
01215     function com(aObj,bObj){
01216      if(pAt[bObj]&&pAt[bObj]!="X"){
01217      comC(aObj,pAt[bObj]);
01218      if(same){bObj=vmr;}
01219      }
01220      }
01221     
01222     
01223     
01224     
01225     //find which moves are valid
01226     var fakeView=false;
01227     var showingValid=false;
01228     var vmr=-1;var vpn=-1;var decn;
01229     function findValidMoves(vmp,vmn,remote){
01230     
01231      pAt=new Array;
01232     
01233      //alert(vmp.offsetLeft);
01234     
01235      // get square id
01236      for (i=0;i<64;i++){
01237      // find square names
01238      if (vmp.style.pixelLeft==on[i][0]&&vmp.style.pixelTop==on[i][1]){
01239      vmr=i;
01240      }
01241     
01242     
01243      //check each square for a piece
01244      for (j=0;j<64;j++){
01245      // find all board objects
01246      if (pS[j].style.pixelLeft==on[i][0]&&pS[j].style.pixelTop==on[i][1]){
01247      pAt[i]=pn[j];
01248      }
01249      }
01250      }
01251     
01252      dc["vr"].value=vmr+"-"+vmn;
01253     
01254      //validations
01255      var sqR;
01256      var sqm;
01257      var vc=0;
01258      var vd=false;
01259     
01260      fakeView=false;
01261     
01262      if(dc["vw"].value=="false"){
01263      fakeView=true;
01264      if(vmn.indexOf("w")!=-1){vmn=vmn.replace("w","");vmn="g"+vmn;}
01265      else{vmn="v"+vmn;}
01266      }
01267     
01268      //white pawn
01269      if(vmn=="wp"||vmn=="vp"){
01270      sqR=new Array(vmr);
01271      if(sqid[vmr][0]==6){
01272      sqR=new Array(vmr);
01273      sqR[2]=vmr-7;
01274      if(pAt[sqR[2]]=="X"||(sqid[sqR[2]]&&sqid[sqR[2]][0]==sqid[vmr][0])){sqR[2]=vmr;}
01275      else{comC(vmn,pAt[sqR[2]]);if(same){sqR[2]=vmr;}}
01276      sqR[3]=vmr-9;
01277      if(pAt[sqR[3]]=="X"||(sqid[sqR[3]]&&sqid[sqR[3]][0]==sqid[vmr][0])){sqR[3]=vmr;}
01278      else{comC(vmn,pAt[sqR[3]]);if(same){sqR[3]=vmr;}}
01279      sqR[1]=vmr-8;
01280      if(pAt[sqR[1]]!="X"){sqR[1]=vmr;}
01281      else{
01282      sqR[4]=vmr-16;
01283      if(pAt[sqR[4]]!="X"){sqR[4]=vmr;}
01284      }
01285      }
01286      else if(sqid[vmr][0]<6){
01287      sqR=new Array(vmr);
01288      sqR[2]=vmr-7;
01289      if(pAt[sqR[2]]=="X"||(sqid[sqR[2]]&&sqid[sqR[2]][0]==sqid[vmr][0])){sqR[2]=vmr;}
01290      else{comC(vmn,pAt[sqR[2]]);if(same){sqR[2]=vmr;}}
01291      sqR[3]=vmr-9;
01292      if(pAt[sqR[3]]=="X"||(sqid[sqR[3]]&&sqid[sqR[3]][0]==sqid[vmr][0])){sqR[3]=vmr;}
01293      else{comC(vmn,pAt[sqR[3]]);if(same){sqR[3]=vmr;}}
01294      sqR[1]=vmr-8;
01295      if(pAt[sqR[1]]!="X"){sqR[1]=vmr;}
01296      }
01297      for(j=0;j<sqR.length;j++){
01298      if(String(parseInt(sqR[j]/8))!="NaN"){
01299      if((parseInt(vmr/8)-parseInt(sqR[j]/8))>1){if((vmr-sqR[j])!=16){sqR[j]=vmr;}}
01300      }
01301      }
01302      //en-passent square
01303      decn=dc["enp"].value;
01304      if(decn!="-"){
01305      epn=sqp[decn][1];
01306      if(fakeView){epn=63-epn;}
01307      if((epn>=16&&epn<=23)&&(vmr>=24&&vmr<=31)&&(vmr==(epn+9)||vmr==(epn+7))){sqR[sqR.length]=epn;}
01308      }else{
01309      epn=-1;
01310      }
01311      }
01312      //black pawn
01313      if(vmn=="p"||vmn=="gp"){
01314      sqR=new Array(vmr);
01315      if(sqid[vmr][0]==1){
01316      sqR=new Array(vmr);
01317      sqR[2]=vmr+7;
01318      if(pAt[sqR[2]]=="X"||(sqid[sqR[2]]&&sqid[sqR[2]][0]==sqid[vmr][0])){sqR[2]=vmr;}
01319      else{comC(vmn,pAt[sqR[2]]);if(same){sqR[2]=vmr;}}
01320      sqR[3]=vmr+9;
01321      if(pAt[sqR[3]]=="X"||(sqid[sqR[3]]&&sqid[sqR[3]][0]==sqid[vmr][0])){sqR[3]=vmr;}
01322      else{comC(vmn,pAt[sqR[3]]);if(same){sqR[3]=vmr;}}
01323      sqR[1]=vmr+8;
01324      if(pAt[sqR[1]]!="X"){sqR[1]=vmr;}
01325      else{
01326      sqR[4]=vmr+16;
01327      if(pAt[sqR[4]]!="X"){sqR[4]=vmr;}
01328      }
01329      }
01330      else if(sqid[vmr][0]>1){
01331      sqR=new Array(vmr);
01332      sqR[2]=vmr+7;
01333      if(pAt[sqR[2]]=="X"||(sqid[sqR[2]]&&sqid[sqR[2]][0]==sqid[vmr][0])){sqR[2]=vmr;}
01334      else{comC(vmn,pAt[sqR[2]]);if(same){sqR[2]=vmr;}}
01335      sqR[3]=vmr+9;
01336      if(pAt[sqR[3]]=="X"||(sqid[sqR[3]]&&sqid[sqR[3]][0]==sqid[vmr][0])){sqR[3]=vmr;}
01337      else{comC(vmn,pAt[sqR[3]]);if(same){sqR[3]=vmr;}}
01338      sqR[1]=vmr+8;
01339      if(pAt[sqR[1]]!="X"){sqR[1]=vmr;}
01340      }
01341      for(j=0;j<sqR.length;j++){
01342      if(String(parseInt(sqR[j]/8))!="NaN"){
01343      if((parseInt(sqR[j]/8)-parseInt(vmr/8))>1){if((sqR[j])-vmr!=16){sqR[j]=vmr;}}
01344      }
01345      }
01346      //en-passent square
01347      decn=dc["enp"].value;
01348      if(decn!="-"){
01349      epn=sqp[decn][1];
01350      if(fakeView){epn=63-epn;}
01351      if((epn>=40&&epn<=47)&&(vmr>=32&&vmr<=39)&&(vmr==(epn-9)||vmr==(epn-7))){sqR[sqR.length]=epn;}
01352      }else{
01353      epn=-1;
01354      }
01355      }
01356      //knight
01357      if(vmn=="n"||vmn=="gn"||vmn=="wn"||vmn=="vn"){
01358      sqR=new Array(vmr,vmr);
01359      for(j=0;j<(6-sqid[vmr][1]);j++){
01360      sqR[2]=vmr-6;
01361      com(vmn,sqR[2]);
01362      sqR[3]=vmr+10;
01363      com(vmn,sqR[3]);
01364      }
01365      for(j=0;j<(sqid[vmr][1]-1);j++){
01366      sqR[4]=vmr+6;
01367      com(vmn,sqR[4]);
01368      sqR[5]=vmr-10;
01369      com(vmn,sqR[5]);
01370      }
01371      for(j=0;j<(6-sqid[vmr][0]);j++){
01372      for(k=0;k<(7-sqid[vmr][1]);k++){
01373      sqR[6]=vmr+17;
01374      com(vmn,sqR[6]);
01375      }
01376      for(k=0;k<(sqid[vmr][1]);k++){
01377      sqR[7]=vmr+15;
01378      com(vmn,sqR[7]);
01379      }
01380      }
01381      for(j=0;j<(sqid[vmr][0]-1);j++){
01382      for(k=0;k<(7-sqid[vmr][1]);k++){
01383      sqR[8]=vmr-15;
01384      com(vmn,sqR[8]);
01385      }
01386      for(k=0;k<(sqid[vmr][1]);k++){
01387      sqR[9]=vmr-17;
01388      com(vmn,sqR[9]);
01389      }
01390      }
01391      }
01392      //king
01393      if(vmn=="wk"||vmn=="vk"||vmn=="k"||vmn=="gk"){
01394      //alert(sqid[vmr]);
01395      //(row,column)
01396      sqR=new Array(vmr,vmr);
01397      for(j=0;j<sqid[vmr][1];j++){
01398      if(sqid[(vmr-1)]&&(sqid[vmr][1]-sqid[(vmr-1)][1]==1)){
01399      sqR[2]=vmr-1;
01400      com(vmn,sqR[2]);
01401      }
01402      if(sqid[(vmr-9)]&&(sqid[vmr][1]-sqid[(vmr-9)][1]==1&&sqid[vmr][0]-sqid[(vmr-9)][0]==1)){
01403      sqR[3]=vmr-9;
01404      com(vmn,sqR[3]);
01405      }
01406      }
01407      for(j=0;j<(7-sqid[vmr][1]);j++){
01408      if(sqid[(vmr+1)]&&(sqid[(vmr+1)][1]-sqid[vmr][1]==1)){
01409      sqR[4]=vmr+1;
01410      com(vmn,sqR[4]);
01411      }
01412      if(sqid[(vmr+9)]&&(sqid[(vmr+9)][1]-sqid[vmr][1]==1&&sqid[(vmr+9)][0]-sqid[vmr][0]==1)){
01413      sqR[5]=vmr+9;
01414      com(vmn,sqR[5]);
01415      }
01416      }
01417      for(j=0;j<sqid[vmr][0];j++){
01418      if(sqid[(vmr-8)]&&(sqid[vmr][0]-sqid[(vmr-8)][0]==1)){
01419      sqR[6]=vmr-8;
01420      com(vmn,sqR[6]);
01421      }
01422      if(sqid[(vmr-7)]&&(sqid[vmr][0]-sqid[(vmr-7)][0]==1&&sqid[(vmr-7)][1]-sqid[vmr][1]==1)){
01423      sqR[7]=vmr-7;
01424      com(vmn,sqR[7]);
01425      }
01426      }
01427      for(j=0;j<(7-sqid[vmr][0]);j++){
01428      if(sqid[(vmr+8)]&&(sqid[(vmr+8)][0]-sqid[vmr][0]==1)){
01429      sqR[8]=vmr+8
01430      com(vmn,sqR[8]);
01431      }
01432      if(sqid[(vmr+7)]&&(sqid[vmr][1]-sqid[(vmr+7)][1]==1&&sqid[(vmr+7)][0]-sqid[vmr][0]==1)){
01433      sqR[9]=vmr+7
01434      com(vmn,sqR[9]);
01435      }
01436      }
01437      var caq=new Array(60,4);
01438      var pccd=new Array(wCCr,wCCl,bCCr,bCCl);
01439      if(fakeView){
01440      caq=new Array(59,3);
01441      pccd=new Array(bCCl,bCCr,wCCl,wCCr);
01442      }
01443      if(vmr==caq[0]){
01444      if(pccd[0]){sqR[10]=vmr+2;}
01445      if(pccd[1]){sqR[11]=vmr-2;}
01446      }
01447      if(vmr==caq[1]){
01448      if(pccd[2]){sqR[12]=vmr+2;}
01449      if(pccd[3]){sqR[13]=vmr-2;}
01450      }
01451      }
01452      //rook and queen
01453      if(vmn=="vr"||vmn=="wr"||vmn=="r"||vmn=="gr"||vmn=="wq"||vmn=="vq"||vmn=="q"||vmn=="gq"){
01454      sqR=new Array(vmr);
01455      sqm=1;
01456      vd=false;vc=0;
01457      for(j=0;j<sqid[vmr][1];j++){
01458      sqR[sqm]=vmr-(j+1);
01459      if(vc==0){
01460      comC(vmn,pAt[sqR[sqm]]);
01461      }
01462      if(!vd&&pAt[sqR[sqm]]&&pAt[sqR[sqm]]!="X"){
01463      if(same){vc=2;}
01464      else{vc=1;}
01465      vd=true;
01466      }
01467      if(vc==2){vc=0;vd=false;break;}
01468      if(vc==1){vc=2;}
01469      sqm++;
01470      }
01471      vd=false;vc=0;
01472      for(j=0;j<(7-sqid[vmr][1]);j++){
01473      sqR[sqm]=vmr+(j+1);
01474      if(vc==0){
01475      comC(vmn,pAt[sqR[sqm]]);
01476      }
01477      if(!vd&&pAt[sqR[sqm]]&&pAt[sqR[sqm]]!="X"){
01478      if(same){vc=2;}
01479      else{vc=1;}
01480      vd=true;
01481      }
01482      if(vc==2){vc=0;vd=false;break;}
01483      if(vc==1){vc=2;}
01484      sqm++;
01485      }
01486      vd=false;vc=0;
01487      for(j=0;j<sqid[vmr][0];j++){
01488      sqR[sqm]=vmr-((j+1)*8);
01489      if(vc==0){
01490      comC(vmn,pAt[sqR[sqm]]);
01491      }
01492      if(!vd&&pAt[sqR[sqm]]&&pAt[sqR[sqm]]!="X"){
01493      if(vmn.indexOf("q")!=-1){
01494      if(same){
01495      if(sqid[vmr][0]==7){vc=1;}
01496      else{vc=2;}
01497      }
01498      }
01499      if(vmn.indexOf("r")!=-1){
01500      if(sqid[vmr][0]==7){
01501      break;
01502      }
01503      else if(same){
01504      {vc=2;}
01505      }
01506      else{
01507      vc=1;
01508      }
01509      }
01510      else{vc=1;}
01511      vd=true;
01512      }
01513      if(vc==2){vc=0;vd=false;break;}
01514      if(vc==1){vc=2;}
01515      sqm++;
01516      }
01517     
01518      vd=false;vc=0;
01519      for(j=0;j<(7-sqid[vmr][0]);j++){
01520      sqR[sqm]=vmr+((j+1)*8)
01521      if(vc==0){
01522      comC(vmn,pAt[sqR[sqm]]);
01523      }
01524      if(!vd&&pAt[sqR[sqm]]&&pAt[sqR[sqm]]!="X"){
01525      if(same||vmn.indexOf("r")!=-1){vc=2;}
01526      else{vc=1;}
01527      vd=true;
01528      }
01529      if(vc==2){vc=0;vd=false;break;}
01530      if(vc==1){vc=2;}
01531      sqm++;
01532      }
01533     
01534      }
01535      //bishop and queen
01536      if(vmn=="wb"||vmn=="vb"||vmn=="b"||vmn=="gb"||vmn=="wq"||vmn=="vq"||vmn=="q"||vmn=="gq"){
01537      if(vmn=="wb"||vmn=="vb"||vmn=="b"||vmn=="gb"){
01538      sqR=new Array(vmr);
01539      sqm=1;
01540      }
01541      vd=false;vc=0;
01542      for(j=0;j<sqid[vmr][1];j++){
01543      sqR[sqm]=vmr-(j+1)-(8*(j+1));
01544      if(vc==0){
01545      comC(vmn,pAt[sqR[sqm]]);
01546      }
01547      if(!vd&&pAt[sqR[sqm]]&&pAt[sqR[sqm]]!="X"){
01548      if(same){vc=2;}
01549      else{vc=1;}
01550      vd=true;
01551      }
01552      if(vc==2){vc=0;vd=false;break;}
01553      if(vc==1){vc=2;}
01554      sqm++;
01555      }
01556      vd=false;vc=0;
01557      for(j=0;j<(7-sqid[vmr][1]);j++){
01558      sqR[sqm]=vmr+(j+1)+(8*(j+1));
01559      if(vc==0){
01560      comC(vmn,pAt[sqR[sqm]]);
01561      }
01562      if(!vd&&pAt[sqR[sqm]]&&pAt[sqR[sqm]]!="X"){
01563      if(same){vc=2;}
01564      else{vc=1;}
01565      vd=true;
01566      }
01567      if(vc==2){vc=0;vd=false;break;}
01568      if(vc==1){vc=2;}
01569      sqm++;
01570      }
01571     
01572      vd=false;vc=0;
01573      for(j=0;j<sqid[vmr][1];j++){
01574      sqR[sqm]=vmr+((j+1)*8)-(j+1);
01575      if(vc==0){
01576      comC(vmn,pAt[sqR[sqm]]);
01577      }
01578      if(!vd&&pAt[sqR[sqm]]&&pAt[sqR[sqm]]!="X"){
01579      if(same){vc=2;}
01580      if(sqid[vmr][1]==7){vc=2;}else{vc=1;}
01581      vd=true;
01582      }
01583      if(vc==2){vc=0;vd=false;break;}
01584      if(vc==1){vc=2;}
01585      sqm++;
01586      }
01587      vd=false;vc=0;
01588      for(j=0;j<(7-sqid[vmr][1]);j++){
01589      sqR[sqm]=vmr-((j+1)*8)+(j+1);
01590      if(vc==0){
01591      comC(vmn,pAt[sqR[sqm]]);
01592      }
01593      if(!vd&&pAt[sqR[sqm]]&&pAt[sqR[sqm]]!="X"){
01594      vc=2;
01595      vd=true;
01596      }
01597      if(vc==2){vc=0;vd=false;break;}
01598      if(vc==1){vc=2;}
01599      sqm++;
01600      }
01601      }
01602     
01603     
01604     
01605      //compile valid moves
01606      if(sqR&&sqR.length>=1){
01607     
01608      tVal=new Array;
01609      tNVal=new Array;
01610      for(i=0;i<sqR.length;i++){
01611      if(sq[sqR[i]]&&pAt[sqR[i]]){
01612     
01613      //alert(pAt[sqR[i]]);
01614     
01615      //store values
01616      tVal[i]=sqR[i];
01617      tNVal[i]="*";
01618     
01619      //king cannot be a target square
01620      if(pAt[sqR[i]].indexOf("k")!=-1){
01621      tNVal[i]=tVal[i];
01622      tVal[i]="*";
01623      }
01624     
01625      //final check for same-color pieces
01626      if(pAt[sqR[i]]!="X"){
01627      comC(vmn,pAt[sqR[i]]);
01628      if(same){
01629      tNVal[i]=tVal[i];
01630      tVal[i]="*";
01631      }
01632      }
01633     
01634      }
01635      }
01636     
01637     
01638      //store aSq for validation
01639      aSq=new Array;
01640      var sASQ=new Array;
01641      var asn=0;
01642     
01643      for(i=0;i<sqR.length;i++){
01644      if(sq[sqR[i]]){
01645      //find markers
01646      if(tVal[i]!="*"){
01647      if(ato){
01648      comC(vmn,dc["ctm"].value);
01649      if(!same){tVal[i]="*";}
01650      }
01651      aSq[asn]=tVal[i];
01652      sASQ[asn]=tVal[i];
01653      asn++;
01654      }
01655      }
01656      }
01657      aSq[asn]=vmr;
01658     
01659     
01660      //final output
01661      //dc["ant"].value=aSq;
01662     
01663      //would king be in check
01664      if(vmn=="wk"||vmn=="vk"||vmn=="k"||vmn=="gk"){ isInCheck(vmr); }
01665     
01666     
01667      //show markers
01668      for(i=0;i<sqR.length;i++){
01669      if(sq[sqR[i]]){
01670      //show markers
01671      if(showLEGAL&&tVal[i]!="*"){
01672      if(sq[tVal[i]]){sq[tVal[i]].style.visibility="visible";}
01673      }
01674      }
01675      }
01676     
01677     
01678     
01679     
01680      //alert(tVal);
01681      showingValid=true;
01682      return aSq;
01683     
01684      if(remote) {
01685      alert(aSq);
01686     
01687      }
01688     
01689      }
01690      return false;
01691      }
01692     
01693     
01694     
01695     
01696     
01697     
01698     
01699     function hideValidMoves(){
01700      if(showingValid){
01701      for(i=0;i<64;i++){
01702      sq[i].style.visibility="hidden";
01703      }
01704      showingValid=false;
01705      }
01706      }
01707     
01708     
01709     
01710     
01711     
01712     
01713     
01714     function mouseDown(e){
01715     
01716      // hide last move indicators
01717      hideLastMove()
01718     
01719      // filter mouse button and find mouse position
01720      if (event.button!=1) return true;
01721      var x=event.x;
01722      var y=event.y;
01723      // store initial mouse location
01724      dc["kxinfo"].value=x;
01725      dc["kyinfo"].value=y;
01726      // find piece id from hidden form
01727      var piece=dc["pieceid"].value;
01728      var group=dc["info"].value;
01729      // verify its a piece and find inital location
01730     
01731      if ((group.indexOf("X")==-1)&&(group.indexOf("-")!=-1)){
01732     
01733      // if main board piece
01734      var tempId=pS[piece];
01735     
01736      //find/show valid moves
01737      if(showLEGAL||blockILLEGAL){
01738      if (group.indexOf("play")!=-1){
01739      findValidMoves(pS[piece],pn[piece]);
01740      }
01741      }
01742     
01743      // if white bin piece
01744      if (group.indexOf("binw")!=-1){
01745     
01746      if(blockILLEGAL) { dc["dim"].click(); }
01747     
01748      // clear bin space
01749      var tempId=wS[piece];
01750      wI[piece].src=imgs["X"].src;
01751      // look for blank board piece to swap it with
01752      var foundSpace=false;
01753      for (i=0;i<64;i++){
01754      if (!foundSpace){
01755      // swap identities and write to form
01756      if (pn[i]=="X"){
01757      pI[i].src=imgs[bnw[piece]].src;
01758      pn[i]=bnw[piece];
01759      xn[i]=bnw[piece];
01760      pS[i].style.left=pp[i][0];
01761      pS[i].style.top=pp[i][1];
01762      dc["info"].value="play"+i+" - "+i;
01763      dc["pieceid"].value=i;
01764      forced=true;
01765      foundSpace=true;
01766      }
01767      }
01768      }
01769      bnw[piece]="X";
01770      }
01771     
01772      // if black bin piece
01773      if (group.indexOf("binb")!=-1){
01774     
01775      if(blockILLEGAL) { dc["dim"].click(); }
01776     
01777      // clear bin space
01778      var tempId=bS[piece];
01779      bI[piece].src=imgs["X"].src;
01780      // look for blank board piece to swap it with
01781      var foundSpace=false;
01782      for (i=0;i<64;i++){
01783      if (!foundSpace){
01784      // swap identities and write to form
01785      if (pn[i]=="X"){
01786      pI[i].src=imgs[bnb[piece]].src;
01787      pn[i]=bnb[piece];
01788      xn[i]=bnb[piece];
01789      pS[i].style.left=pp[i][0];
01790      pS[i].style.top=pp[i][1];
01791      dc["info"].value="play"+i+" - "+i;
01792      dc["pieceid"].value=i;
01793      var tempI=i;
01794      forced=true;
01795      foundSpace=true;
01796      }
01797      }
01798      }
01799      bnb[piece]="X";
01800      }
01801     
01802      // store initial mouse positions
01803      sx=x-(tempId.offsetLeft);sy=y-(tempId.offsetTop);
01804     
01805      if(ie5p&&shadowCOLOR!=""){
01806      if(tempId.firstChild.filters[0]){
01807      tempId.firstChild.filters[0].enabled=true;
01808      tempId.style.left=x-sx-1;
01809      tempId.style.top=y-sy-1;
01810      }
01811      }
01812     
01813      // approve dragging
01814      movedone=false;
01815      dragokay=true;
01816      }
01817      return true;
01818      }
01819     
01820     
01821     
01822     function mouseMove(e){
01823     
01824      // reset for bin piece transfer
01825      if (forced){return false;}
01826     
01827      // find mouse position
01828      var x=event.x;
01829      var y=event.y;
01830     
01831      if(ie5p&&shadowCOLOR!=""){x--;y--;}
01832     
01833      // find piece id from hidden form
01834      var piece=dc["pieceid"].value;
01835      // move piece and raise z order
01836      var group=dc["info"].value;
01837      var tempId=pS[piece];
01838      // if dragging is approved
01839      if (dragokay&&((group.indexOf("X")==-1)&&(group.indexOf("-")!=-1))){
01840      tempId.style.zIndex+=20;
01841      tempId.style.left=x-sx;
01842      tempId.style.top=y-sy;
01843      }
01844      return false
01845      }
01846     
01847     var n=0;
01848     var outString=new Array;
01849     
01850     
01851     
01852     
01853     
01854     // build output string array
01855     function addToOutputString(obGroup){
01856     
01857      // find src of object at each location
01858      outString[n]=obGroup.src.replace(".gif","");
01859     
01860      // convert to name code
01861      var fk0=outString[n].charAt((outString[n].length-2));
01862      var fk1=outString[n].charAt((outString[n].length-1));
01863      outString[n]=fk0+fk1;
01864      if (outString[n].indexOf("/")!=-1){outString[n]=outString[n].replace("/","");}
01865     
01866      }
01867     
01868     
01869     var oString;
01870     
01871     
01872     //convert "X"s to number
01873     var Xfs="";var fs="";
01874     function convertX(Xfs){
01875     
01876      Xfs=Xfs.replace(/XXXXXXXX/g,'8');
01877      Xfs=Xfs.replace(/XXXXXXX/g,'7');
01878      Xfs=Xfs.replace(/XXXXXX/g,'6');
01879      Xfs=Xfs.replace(/XXXXX/g,'5');
01880      Xfs=Xfs.replace(/XXXX/g,'4');
01881      Xfs=Xfs.replace(/XXX/g,'3');
01882      Xfs=Xfs.replace(/XX/g,'2');
01883      Xfs=Xfs.replace(/X/g,'1');
01884     
01885      fs=Xfs;
01886      }
01887     
01888     
01889     
01890     // convert output string to standard format
01891     function convertOutputString(oString,writeForm,doSwitch,manualS,fr,cdo,tno,ccd){
01892     
01893      // convert to standard format
01894      var finalString='';
01895     
01896     
01897      //invert output string for black viewpoint
01898      if(!VW){oString.reverse();}
01899     
01900      // convert white piece names
01901      for (i=0;i<64;i++){
01902      var chr=oString[i];
01903      if (chr.indexOf("w")!=-1){
01904      chr=chr.replace("w","");
01905      oString[i]=chr.toUpperCase();
01906      }
01907      }
01908     
01909      // add slashes
01910      for (i=0;i<64;i++){
01911      finalString+=oString[i];
01912      if (i==7||i==15||i==23||i==31||i==39||i==47||i==55){finalString+="/";}
01913      }
01914     
01915      // convert "X"s to number
01916      convertX(finalString);
01917      finalString=fs;
01918     
01919      //check castling availability
01920      var ccStr='';
01921      if(wCCr){ccStr+="K";}
01922      if(wCCl){ccStr+="Q";}
01923      if(bCCr){ccStr+="k";}
01924      if(bCCl){ccStr+="q";}
01925      if(ccStr==''){ccStr='-';}
01926      xDe[2]=ccStr;
01927     
01928      //add extra FEN information to output string
01929      finalString+=" "+xDe[1]+" "+xDe[2]+" "+xDe[3]+" "+xDe[4]+" "+xDe[5];
01930     
01931      //recorded output
01932      if(ato&&!manualS){
01933     
01934      //get rNum from form
01935      rNum=parseInt(dc["gp"].value)+1;
01936      reco.length=rNum;
01937      moL.length=rNum-1;
01938      moC.length=rNum-1;
01939      gIn=false;
01940      reco[rNum]=finalString;
01941      dc["start"].value=reco[rNum];
01942      dc["current"].value=reco[rNum];
01943      dc["gp"].value=rNum;
01944      star="";
01945     
01946      prvC=rNum;
01947     
01948      dc["ant"].value="";
01949      if(annt[rNum]&&annt[rNum]!=""){star="*";dc["ant"].value=annt[rNum];}
01950     
01951      if(rNum>0){
01952      dc["reco"].options[1].style.color=bC;
01953      dc["reco"].options[2].style.color=bC;
01954      dc["reco"].options[3].style.color=bC;
01955      if(ie5p&&enablePgnImport) { dc["reco"].options[8].style.color=bC; }
01956      else { dc["reco"].options[7].style.color=bC; }
01957      }
01958     
01959      var gpVal=rNum/2;
01960      if(parseFloat(gpVal)!=parseInt(gpVal)){gpVal=Math.round(gpVal);gpVal+=".";}
01961      else{if(gpVal>0){gpVal+="..";}else{gpVal="..";}}
01962      var lsNum=Math.round((reco.length-1)/2);if(lsNum==0){lsNum="..";}
01963     
01964     
01965      dc["gpv"].value=gpVal+star+" /"+lsNum;
01966     
01967      //increase log array number
01968      rNum++;
01969      }
01970     
01971      //manual output
01972      if (writeForm){
01973      if(manualS){dc["current"].value=finalString;}
01974      }else if(!gIn){
01975      moC[loN]=finalString;
01976      }
01977      moves++;
01978     
01979     
01980     
01981     
01982      }
01983     
01984     
01985     
01986     // game progress array;
01987     var gameWin;
01988     
01989     // find location of objects and produce output string
01990     function findPieceIds(manS){
01991     
01992     if (moves>-1){
01993      n=0;
01994      outString=new Array;
01995     
01996      // find page location to extract image src
01997      var ddl=document.location.href;
01998     
01999      // find all objects
02000      for (i=0;i<64;i++){
02001      for (j=0;j<64;j++){
02002      // check main board objects
02003      if (pS[j].style.pixelLeft==on[i][0]&&pS[j].style.pixelTop==on[i][1]){
02004      addToOutputString(pI[j]);
02005      }
02006      }
02007      n++;
02008      }
02009     
02010      convertOutputString(outString,true,false,manS);
02011      }
02012      }
02013     
02014     
02015     
02016     
02017     
02018     
02019     // validate move
02020     function validateMove(vmx,vmy,vcd,vp,vg){
02021     
02022     
02023     // manual move into bin
02024     
02025      if (vcd<16){
02026     
02027      // put it in the bin
02028      var ibb=dc["vbb"].value;
02029      var ibw=dc["vbw"].value;
02030     
02031      // if piece is close to a black bin square and is black
02032      if ((pn[vp].indexOf("w")==-1) && ((vmx>(bb[cd][0]-prx)&&vmx<(bb[cd][0]+prx))&&(vmy>(bb[cd][1]-prx)&&vmy<(bb[cd][1]+prx)))){
02033     
02034      var biS=false;
02035      if (ibb>=16){
02036      blF=true;
02037      for (d=0;d<16;d++){
02038      if (!biS){if (bnb[d]=="X"){ibb=d;biS=true;}}
02039      }
02040      if(d==16&&biS==false){
02041      return false;
02042      }
02043      }
02044      bI[ibb].src=imgs[pn[vp]].src;
02045      bnb[ibb]=pn[vp];
02046      pI[vp].src=imgs["X"].src;
02047      pn[vp]="X";
02048      if (!blF){ibb++;}else{ibb=16;}
02049      }
02050     
02051      // if piece is close to a white bin square and is white
02052      if ((pn[vp].indexOf("w")!=-1) && ((vmx>(bw[cd][0]-prx)&&vmx<(bw[cd][0]+prx))&&(vmy>(bw[cd][1]-prx)&&vmy<(bw[cd][1]+prx)))){
02053     
02054      var biS=false;
02055      if (ibw>=16){
02056      whF=true;
02057      for (d=0;d<16;d++){
02058      if (!biS){if (bnw[d]=="X"){ibw=d;biS=true;}}
02059      }
02060      if(d==16&&biS==false){
02061      return false;
02062      }
02063      }
02064      wI[ibw].src=imgs[pn[vp]].src;
02065      bnw[ibw]=pn[vp];
02066      pI[vp].src=imgs["X"].src;
02067      pn[vp]="X";
02068      if (!whF){ibw++;}else{ibw=16;}
02069      }
02070     
02071      dc["vbb"].value=ibb;
02072      dc["vbw"].value=ibw;
02073     
02074      }
02075     
02076     
02077     // normal move
02078     
02079      // if piece is close to another square
02080      if ((vmx>(pp[cd][0]-prx)&&vmx<(pp[cd][0]+prx))&&(vmy>(pp[cd][1]-prx)&&vmy<(pp[cd][1]+prx))){
02081     
02082      // if landing piece is not the same color or blank
02083      if ((pn[vcd]!="X"&&pn[vp]!="X") && (((pn[vcd].indexOf("w")!=-1)&&(pn[vp].indexOf("w")!=-1))||((pn[vcd].indexOf("w")==-1)&&(pn[vp].indexOf("w")==-1)))){
02084      moveokay=false;
02085      }else{
02086      moveokay=true;
02087     
02088      //block invalid moves
02089      if(blockILLEGAL){
02090      // find square
02091      var newRef;
02092      for (i=0;i<64;i++){
02093      if (pp[vcd][0]==on[i][0]&&pp[vcd][1]==on[i][1]){
02094      newRef=i;
02095      }
02096      }
02097     
02098      var itsOkay=false;
02099     
02100      for(j=0;j<aSq.length;j++){
02101      if(newRef==aSq[j]){itsOkay=true;}
02102      }
02103     
02104      if(itsOkay){
02105      moveokay=true;
02106      var tvcd=sqn[vcd];
02107      sqn[vcd]=sqn[vp];
02108      sqn[vp]=tvcd;
02109      }else{
02110      moveokay=false;
02111      }
02112      }
02113     
02114     
02115      //whose turn is it
02116      if((xDe[1]=="w"&&pn[vp].indexOf("w")==-1)||(xDe[1]=="b"&&pn[vp].indexOf("w")!=-1)){
02117      if(ato){moveokay=false;}
02118      }
02119     
02120      }
02121      }else{
02122      moveokay=false;
02123      }
02124      }
02125     
02126     
02127     
02128     
02129     
02130     // reassign ids after move
02131     function reassignIDs(){
02132      dc["largetext"].value=pp;
02133     
02134      }
02135     
02136     
02137     
02138     
02139     // ** set and read cookie by Ronnie.T.Moore - http://javascript.internet.com/
02140     var expDays,expDate;
02141     function getExpiry(eNum){
02142     expDays=eNum;
02143     expDate=new Date();
02144     expDate.setTime(expDate.getTime()+ (24 * 60 * 60 * 1000 * expDays));
02145     return expDate
02146     }
02147     function getCookieVal (offset){
02148     var endstr=document.cookie.indexOf (";", offset);
02149     if (endstr==-1)
02150     endstr=document.cookie.length;
02151     return unescape(document.cookie.substring(offset, endstr));
02152     }
02153     function GetCookie (name){
02154     var arg=name+"=";
02155     var alen=arg.length;
02156     var clen=document.cookie.length;
02157     var i=0;
02158     while (i < clen){
02159     var j=i+alen;
02160     if (document.cookie.substring(i, j)==arg)
02161     return getCookieVal (j);
02162     i=document.cookie.indexOf(" ", i)+1;
02163     if (i==0) break;
02164     }
02165     return null;
02166     }
02167     
02168     function SetCookie (name, value){
02169     var argv=SetCookie.arguments;
02170     var argc=SetCookie.arguments.length;
02171     var expires=(argc > 2) ? argv[2] : null;
02172     var path=(argc > 3) ? argv[3] : null;
02173     var domain=(argc > 4) ? argv[4] : null;
02174     var secure=(argc > 5) ? argv[5] : false;
02175     document.cookie=name+"="+escape (value)+
02176     ((expires==null) ? "" : (";expires="+expires.toGMTString()))+
02177     ((path==null) ? "" : (";path="+path))+
02178     ((domain==null) ? "" : (";domain="+domain))+
02179     ((secure==true) ? ";secure" : "");
02180     }
02181     //************************************************************************************
02182     
02183     
02184     
02185     //create line breaks to restrict line lengths
02186     var ohtm=true;
02187     if(outputToNotepad){ohtm=false;}
02188     var lenInfo,tempLen;
02189     function checkLen(lenData){
02190      var ln=75;if(ohtm){ln=150;}
02191      //alert(lenInfo.length);
02192      if(lenInfo.length>ln){
02193      if(ohtm){tempLen="<br>"+tempLen;}
02194      else{tempLen="\n"+tempLen;}
02195      if(ohtm){tempLen=tempLen.replace("&nbsp;","");}
02196      else{tempLen=tempLen.replace(" ","");}
02197      lenInfo="";
02198      }
02199     
02200      }
02201     
02202     
02203     // create log export
02204     var fenWin,outputWindow,EXPobj;
02205     function generateExport(expFrom){
02206      outputWindow=false;
02207      EXPobj=new Array;
02208     
02209      if(expFrom=="fen"){
02210      if(moC.length<1){return false;}
02211      //check array is full
02212      var logFull=true;
02213      for(f=0;f<moC.length;f++){
02214      if(!moC[f]||moC[f]==""){logFull=false;}
02215      }
02216      if(gIn&&!logFull){return false;}
02217     
02218      //compile output
02219      for(i=0;i<reco.length;i++){
02220      EXPobj[i]="";
02221      if(i==0){
02222      for(j=0;j<taNa.length;j++){
02223      if(ohtm){EXPobj[i]+="<tr><td><font color='#000066' face=verdana size=2>";}
02224      EXPobj[i]+="["+taNa[j]+" \""+taVa[j]+"\"]";
02225      if(ohtm){EXPobj[i]+="</td></tr>";}
02226      else{EXPobj[i]+="\n";}
02227      }
02228      if(ohtm){EXPobj[i]+="<tr><td><br></td></tr>";}
02229      else{EXPobj[i]+="\n";}
02230      }
02231      else{
02232      if(ohtm){EXPobj[i]+="<tr><td><font color='#000066' face=verdana size=2>";}
02233      EXPobj[i]+=reco[i];
02234      if(annt[i]){
02235      if(ohtm){
02236      EXPobj[i]+="&nbsp;</font>";
02237      }else{
02238      EXPobj[i]+=" ";
02239      }
02240      if(ohtm){EXPobj[i]+="<font color='#993333' face=verdana size=2>";}
02241      EXPobj[i]+="{"+annt[i]+"}";
02242      if(ohtm){EXPobj[i]+="</font>";}
02243      }
02244      else{
02245      if(ohtm){EXPobj[i]+="</td><td>&nbsp;";}
02246      else{EXPobj[i]+=" ";}
02247      }
02248      if(ohtm){EXPobj[i]+="</td></tr>";}
02249      else{EXPobj[i]+="\n";}
02250      }
02251      }
02252      if(ohtm){outputWindow=true;}
02253      else{outputWindow=false;}
02254      }
02255     
02256      if(expFrom=="smith"){
02257     
02258      var logObj=moL;
02259     
02260      if(logObj.length<1){return false;}
02261      //check array is full
02262      var logFull=true;
02263      for(f=0;f<logObj.length;f++){
02264      if(!logObj[f]||logObj[f]==""){logFull=false;}
02265      }
02266      if(gIn&&!logFull){return false;}
02267     
02268      //compile output
02269      var fCount=1;
02270      lenInfo="";
02271      for(i=0;i<logObj.length;i++){
02272      EXPobj[i]="";
02273      if(i==0){
02274      for(j=0;j<taNa.length;j++){
02275      if(ohtm){EXPobj[i]+="<tr><td><font color='#000066' face=verdana size=2>";}
02276      EXPobj[i]+="["+taNa[j]+" \""+taVa[j]+"\"]";
02277      if(ohtm){EXPobj[i]+="</td></tr>";}
02278      else{EXPobj[i]+="\n";}
02279      }
02280      if(ohtm){EXPobj[i]+="<tr><td><br></td></tr>";}
02281      else{EXPobj[i]+="\n";}
02282      }
02283      else{
02284      if(i==1){
02285      if(ohtm){EXPobj[i]+="<tr><td><font color='#000066' face=verdana size=2>";}
02286      if(ohtm){tempLen=fCount+".&nbsp;"+logObj[(i-1)];}
02287      else{tempLen=fCount+". "+logObj[(i-1)];}
02288      lenInfo+=tempLen;
02289      checkLen(lenInfo);
02290      EXPobj[i]+=tempLen;
02291      if(ohtm){EXPobj[i]+="</font>";}
02292      if(annt[i]){
02293      if(ohtm){EXPobj[i]+="<font color='#993333' face=verdana size=2>";}
02294      tempLen="{"+annt[i]+"}"
02295      lenInfo+=tempLen;
02296      checkLen(lenInfo);
02297      EXPobj[i]+=tempLen;
02298      if(ohtm){EXPobj[i]+="</font>";}
02299      }
02300      }
02301      if((i>0&&parseInt(i/2)==i/2)||annt[i]){
02302      if(i>0&&parseInt(i/2)==i/2){fCount++;}
02303      if(ohtm){EXPobj[i]+="<font color='#000066' face=verdana size=2>";}
02304      if(ohtm){tempLen="&nbsp;"+fCount+".";}
02305      else{tempLen=" "+fCount+".";}
02306      if((parseInt(i/2)!=i/2)&&annt[i]){tempLen+="..";}
02307      lenInfo+=tempLen
02308      checkLen(lenInfo);
02309      EXPobj[i]+=tempLen;
02310      //if((parseInt(i/2)!=i/2)&&annt[i]){EXPobj[i]+="..";}
02311      if(ohtm){EXPobj[i]+="</font>";}
02312      }
02313      if(ohtm){EXPobj[i]+="<font color='#000066' face=verdana size=2>";}
02314      if(ohtm){tempLen="&nbsp;"+logObj[i];}
02315      else{tempLen=" "+logObj[i];}
02316      lenInfo+=tempLen
02317      checkLen(lenInfo);
02318      EXPobj[i]+=tempLen;
02319      if(ohtm){EXPobj[i]+="</font>";}
02320      if(annt[(i+1)]){
02321      if(ohtm){EXPobj[i]+="<font color='#993333' face=verdana size=2>";}
02322      tempLen="{"+annt[(i+1)]+"}";
02323      lenInfo+=tempLen;
02324      checkLen(lenInfo);
02325      EXPobj[i]+=tempLen;
02326      if(ohtm){EXPobj[i]+="</font>";}
02327      }
02328      if(i==(logObj.length-1)){
02329      if(ohtm){EXPobj[i]+="</td></tr>";}
02330      }
02331      }
02332     
02333     
02334      }
02335      if(ohtm){outputWindow=true;}
02336      else{outputWindow=false;}
02337      }
02338     
02339      if(expFrom=="query"){
02340      if(reco.length<=1){return false;}
02341      //check array is full
02342      var logFull=true;
02343      for(f=0;f<moL.length;f++){
02344      if(!moL[f]||moL[f]==""||!moC[f]||moC[f]==""){logFull=false;}
02345      }
02346      if(gIn&&!logFull){return false;}
02347     
02348      //compile output
02349      var colStr="&view=w";
02350      if(inputV=="b"){colStr="&view=b";}
02351      EXPobj[i]="";
02352     
02353      if(ohtm){
02354      EXPobj[i]+='<p><font size=2 face=verdana>This is the raw game data; copy and paste this entire string into the <b>import (Player format)</b> prompt to recreate the game:</font>';
02355      EXPobj[i]+='<p><form name="stringform"><textarea cols=75 rows=5>';
02356      }
02357     
02358      var mot='';
02359      for(j=0;j<moL.length;j++){
02360      mot+=moL[j];
02361      if(j!=(moL.length-1)) { mot+=','; }
02362      }
02363     
02364      var exp='';
02365      exp+="game="+mot+"&last="+moL[(moL.length-1)]+"&panels="+dc['panels'].value+"&size="+sqS+colStr+"&pieces="+pf.replace('/','')+"&showLegal="+showLEGAL+"&blockIllegal="+blockILLEGAL;
02366      for(j=0;j<taNa.length;j++){
02367      exp+="&"+taNa[j]+"="+taVa[j];
02368      }
02369      var qCols="&lightCOLOR="+lC+"&darkCOLOR="+dC+"&borderCOLOR="+bC+"&whiteSQUARES="+wQ+"&blackSQUARES="+bQ+"&boardBACKING="+boardBACKING+"&shadowCOLOR="+shadowCOLOR;
02370      qCols=qCols.replace(/[\#]/g,'');
02371      exp+=qCols;
02372     
02373      var ddl=document.location.href;
02374      ddl=ddl.split(pageName);
02375      if(pagePath!="") { ddl[0]=pagePath; }
02376     
02377      EXPobj[i]+=exp;
02378      if(ohtm){
02379      EXPobj[i]+='</textarea>';
02380     
02381      if((ddl[0].indexOf("http://")==-1)&&(pagePath=="")) {
02382      ddl[0]="http://www.brothercake.com/chess/ChessPlayer/";
02383      }
02384     
02385      EXPobj[i]+='<p><font size=2 face=verdana>This is the game data built into a link, which is suitable for copying and pasting into an email, or a forum which understands internet links (most do). Others will be able to play-through and analyse your game simply by clicking the link:</font>';
02386      EXPobj[i]+='<p><textarea name="linkhtml" cols=75 rows=5>'+ddl[0]+pageName+'?'+exp+'</textarea>';
02387     
02388      var def = 'Click here to play through the game';
02389      EXPobj[i]+='<p><font size=2 face=verdana>This is the same link in HTML format, which you can paste into the source code of an HTML email or web page:</font>';
02390      EXPobj[i]+='<p><textarea name="linkcode" cols=75 rows=5>&lt;a href="'+ddl[0]+pageName+'?'+exp+'" target="_blank"&gt;'+def+'&lt;/a&gt;</textarea>';
02391     
02392      EXPobj[i]+='</form>';
02393      }
02394     
02395      if(ohtm){outputWindow=true;}
02396      else{outputWindow=false;}
02397      }
02398     
02399      //output data
02400      var fenStr="";
02401      if(ohtm){fenStr+='<html><head><meta name="generator" content="ChessPlayer v2.2 by Brothercake"><title>'+taVa[0]+'</title></head><body bgcolor=white>'+tb+'0>';}
02402      for(f=0;f<EXPobj.length;f++){
02403      if(EXPobj[f]){fenStr+=EXPobj[f];}
02404      }
02405      if(ohtm){fenStr+=stb+"</body></html>";}
02406     
02407      //write html to browser window
02408      if(outputWindow){
02409      if(fenWin){fenWin.close();}
02410      fenWin=window.open("","fenWin");
02411      fenWin.document.open();
02412      fenWin.document.write(fenStr);
02413      fenWin.document.close();
02414      }
02415     
02416      //write plain text
02417      else{
02418      dc["VBOutput"].value=fenStr;
02419      document.getElementById("wadf").click();
02420      }
02421     
02422      }
02423     
02424     
02425     //save game
02426     function saveGame(){
02427     
02428      if(reco.length<=1){return false;}
02429      //check array is full
02430      var logFull=true;
02431      for(f=0;f<moL.length;f++){
02432      if(!moL[f]||moL[f]==""||!moC[f]||moC[f]==""){logFull=false;}
02433      }
02434      if(gIn&&!logFull){return false;}
02435     
02436      //compile output
02437      var colStr="&view=w";
02438      if(inputV=="b"){colStr="&view=b";}
02439      var sgl=savG.length;
02440      savG[sgl]="game="+moL+"&last="+moL[(moL.length-1)]+"&panels="+dc['panels'].value+"&size="+sqS+colStr+"&pieces="+pf.replace('/','')+"&showLegal="+showLEGAL+"&blockIllegal="+blockILLEGAL;
02441      for(j=0;j<taNa.length;j++){
02442      savG[sgl]+="&"+taNa[j]+"="+taVa[j];
02443      }
02444      savG[sgl]+="&lightCOLOR="+lC+"&darkCOLOR="+dC+"&borderCOLOR="+bC+"&whiteSQUARES="+wQ+"&blackSQUARES="+bQ+"&boardBACKING="+boardBACKING+"&shadowCOLOR="+shadowCOLOR;
02445      //remove #
02446      savG[sgl]=savG[sgl].replace(/[\#]/g,'');
02447     
02448      //prompt for filename
02449      savN[sgl]=prompt("Please enter a name.\n(letters, numbers and spaces only)","");
02450      if(savN[sgl]){
02451     
02452      //name cannot contain special characters
02453      savN[sgl]=savN[sgl].replace(/[\ ]/g,'_');
02454      savN[sgl]=savN[sgl].replace(/[\s\W]/g,'');
02455      //name cannot contain the word "game" - changes it to encoded format
02456      while(savN[sgl].indexOf("game")!=-1){savN[sgl]=savN[sgl].replace("game","emag");}
02457     
02458      //maximum length of cookie
02459      var temGN = escape("*cpg*"+savN[sgl]);
02460      var temGG = escape(savG[sgl]);
02461      var cookieLen = (document.cookie.length+temGN.length+temGG.length);
02462      if(cookieLen>4096||(dc["reco"].options.length>=32)) {
02463      alert("Recorder memory is full");
02464      return false;
02465      }
02466     
02467      //write the cookie
02468      getExpiry(36525);
02469      SetCookie("*cpg*"+savN[sgl],savG[sgl],expDate);
02470     
02471      //update form
02472      var rsn=dc["reco"].options.length;
02473     
02474      var writeSG=savN[sgl].replace(/[\_]/g,' ');
02475      writeSG=writeSG.replace("emag","game");
02476     
02477      //if no current saved games
02478      if(dc["reco"].options[(rsn-1)].value=="save"){
02479      dc["reco"].length=rsn+2;
02480      dc["reco"].options[rsn].text="Load saved game:";
02481      dc["reco"].options[rsn].value="";
02482      dc["reco"].options[(rsn+1)].text=" "+(sgl+1)+". "+writeSG;
02483      dc["reco"].options[(rsn+1)].value="*cpg*"+savN[sgl];
02484      }
02485      //else
02486      else{
02487      var opn=rsn;
02488      if(dc["reco"].options[(rsn-1)].value=="delete"){
02489      opn=rsn-1;
02490      }
02491      else{
02492      dc["reco"].length=rsn+1;
02493      }
02494      dc["reco"].options[opn].text=" "+(sgl+1)+". "+writeSG;
02495      dc["reco"].options[opn].value="*cpg*"+savN[sgl];
02496      }
02497     
02498      }
02499     
02500      }
02501     
02502     
02503     function loadGame(lgInfo){
02504     
02505      var loadInfo=GetCookie(lgInfo);
02506      if(loadInfo){self.document.location=pageName+"?cookie="+lgInfo+"&"+loadInfo;}
02507     
02508      }
02509     
02510     
02511     function deleteGame(){
02512      if(gaC!=""){
02513      getExpiry(-1);
02514      SetCookie("*cpg*"+gaC,gaC,expDate);
02515      }
02516      self.document.location=pageName;
02517     
02518      }
02519     
02520     
02521     
02522     //find if piece should be taken and transfer to bin
02523     function discardPiece(dp,dpName){
02524     
02525      if (pn[dp]!="X"&&pn[dp]!=dpName){
02526     
02527      //reset halfmove clock
02528      xDe[4]=-1;
02529     
02530      // put it in the bin
02531      var ibb=dc["vbb"].value;
02532      var ibw=dc["vbw"].value;
02533     
02534      if (pn[dp].indexOf("w")!=-1){
02535      // white bin
02536      var biS=false;
02537      if (ibw>=16){
02538      whF=true;
02539      for (d=0;d<16;d++){
02540      if (!biS){if (bnw[d]=="X"){ibw=d;biS=true;}}
02541      }
02542      if(d==16&&biS==false){
02543      return false;
02544      }
02545      }
02546      wI[ibw].src=imgs[pn[dp]].src;
02547      bnw[ibw]=pn[dp];
02548      if (!whF){ibw++;}else{ibw=16;}
02549     
02550      }else{
02551      // black bin
02552      var biS=false;
02553      if (ibb>=16){
02554      blF=true;
02555      for (d=0;d<16;d++){
02556      if (!biS){if (bnb[d]=="X"){ibb=d;biS=true;}}
02557      }
02558      if(d==16&&biS==false){
02559      return false;
02560      }
02561      }
02562      bI[ibb].src=imgs[pn[dp]].src;
02563      bnb[ibb]=pn[dp];
02564      if (!blF){ibb++;}else{ibb=16;}
02565     
02566      }
02567     
02568     
02569      // change object name
02570      pI[dp].src=imgs["X"].src;
02571      pn[dp]="X";
02572     
02573     
02574      dc["vbb"].value=ibb;
02575      dc["vbw"].value=ibw;
02576     
02577     
02578     
02579      }
02580      }
02581     
02582     
02583     //find en-passent target square
02584     var enpn=-1;
02585     var enpx=-1;
02586     function findEnPassent(epiece,ecd){
02587     
02588      //forced en-passent for previously occupied squares
02589      if(pn[epiece].indexOf("p")!=-1){
02590      if(dc["enp"].value!=""&&dc["enp"].value==sqn[epiece]&&enpn!=ecd) {
02591      if(pn[epiece].indexOf("wp")!=-1){
02592      discardPiece((sqp[sqn[epiece]][1]-8),"wp");
02593      pI[(sqp[sqn[epiece]][1]-8)].src=imgs["X"].src;
02594      pn[(sqp[sqn[epiece]][1]-8)]="X";
02595      }
02596      else{
02597      discardPiece((sqp[sqn[epiece]][1]+8),"p");
02598      pI[(sqp[sqn[epiece]][1]+8)].src=imgs["X"].src;
02599      pn[(sqp[sqn[epiece]][1]+8)]="X";
02600      }
02601      }
02602      }
02603     
02604      //forced en-passent where previous move was from recorder
02605      //if(pn[epiece].indexOf("p")!=-1){
02606      // alert("dc['enp'].value="+dc["enp"].value+" : sqn[epiece]="+sqn[epiece]+"\n\nenpn="+enpn+" : ecd="+ecd);
02607      // }
02608     
02609      //en passent quick-swap
02610      if((pn[epiece].indexOf("p")!=-1)&&(enpn==ecd)){
02611      if(pn[epiece].indexOf("wp")!=-1){
02612      //alert(pn[epiece]+"-"+pn[ecd]+"-"+pn[(ecd-8)]+"-top");
02613      if(pn[(ecd-8)].indexOf("X")==-1){
02614      pI[ecd].src=imgs["p"].src;
02615      pI[(ecd-8)].src=imgs["X"].src;
02616      //if(pI[(ecd-8)].src.indexOf("p.gif")!=-1){pI[(ecd-8)].src=imgs["X"].src;}
02617      //if(pI[(ecd+8)].src.indexOf("p.gif")!=-1){pI[(ecd+8)].src=imgs["X"].src;}
02618      pn[ecd]="p";
02619      pn[(ecd-8)]="X";
02620      }
02621      }
02622      else{
02623      //alert(pn[epiece]+"-"+pn[ecd]+"-"+pn[(ecd+8)]+"-bot");
02624      if(pn[(ecd+8)].indexOf("X")==-1){
02625      pI[ecd].src=imgs["wp"].src;
02626      pI[(ecd+8)].src=imgs["X"].src;
02627      //if(pI[(ecd-8)].src.indexOf("wp.gif")!=-1){pI[(ecd-8)].src=imgs["X"].src;}
02628      //if(pI[(ecd+8)].src.indexOf("wp.gif")!=-1){pI[(ecd+8)].src=imgs["X"].src;}
02629      pn[ecd]="wp";
02630      pn[(ecd+8)]="X";
02631      }
02632      }
02633      }
02634     
02635      var enp="";
02636      if(pn[epiece].indexOf("p")!=-1){
02637      //if it was moved two
02638      if((pp[epiece][1]==on[48][1])&&(pp[ecd][1]==on[32][1])){
02639      if(VW){
02640      enp="3";
02641      enpx=40;
02642      }else{
02643      enp="6";
02644      enpx=16;
02645      }
02646      }
02647      if((pp[epiece][1]==on[8][1])&&(pp[ecd][1]==on[24][1])){
02648      if(VW){
02649      enp="6";
02650      enpx=16;
02651      }else{
02652      enp="3";
02653      enpx=40;
02654      }
02655      }
02656      }
02657      if(enp!=""){
02658      //find letter
02659      var enL='';
02660      for(ep=0;ep<8;ep++){
02661      if(pp[epiece][0]==on[ep][0]){
02662      if(VW){
02663      enL=lCo[ep];
02664      enpn=ep;
02665      }else{
02666      enL=lCo[(7-ep)];
02667      enpn=(7-ep);
02668      }
02669      }
02670      }
02671      xDe[3]=enL+enp;
02672      //en passent target square number
02673      enpn+=enpx;
02674      }else{
02675      xDe[3]='-';
02676      }
02677      dc["enp"].value=xDe[3];
02678     
02679      }
02680     
02681     
02682     
02683     
02684     
02685     //halfmove clock
02686     function halfMove(hpiece,hcd,hname){
02687      xDe[4]++;
02688      if((pn[hpiece].indexOf("p")!=-1)||(hname!="X")){xDe[4]=0;}
02689      dc["hmc"].value=xDe[4];
02690      }
02691     
02692     
02693     
02694     //fullmove clock
02695     function fullMove(fpiece,fcd,rev){
02696      if(pn[fpiece].indexOf("w")==-1){
02697      if(rev){xDe[5]--;}
02698      else{xDe[5]++;}
02699      dc["fmc"].value=xDe[5];
02700      }
02701      }
02702     
02703     
02704     
02705     //piece to move
02706     function pieceMove(pmpiece,pmcd,frec,rev){
02707      if(ato||frec){
02708      if(pn[pmpiece].indexOf("w")!=-1){xDe[1]="b";}else{xDe[1]="w";}
02709      if(rev){if(xDe[1]=="b"){xDe[1]="w";}else{xDe[1]="b";}}
02710      dc["ctm"].value=xDe[1];
02711      }
02712      }
02713     
02714     
02715     // promote pawn to queen
02716     var whQ=false;
02717     var bhQ=false;
02718     function promotePawn(qpiece,pcd){
02719     
02720      if (pn[qpiece].indexOf("p")!=-1){
02721     
02722      // white pawn
02723      if (pn[qpiece].indexOf("wp")!=-1&&!whQ){
02724     
02725      if (pp[qpiece][1]==on[0][1]){
02726      pn[qpiece]="wq";
02727      pI[qpiece].src=imgs["wq"].src;
02728      paC="w";
02729      whQ=true;
02730      xDe[4]=-1;
02731      }
02732     
02733      }
02734     
02735      // black pawn
02736      else if (pn[qpiece].indexOf("p")!=-1&&!bhQ){
02737     
02738      if (pp[qpiece][1]==on[63][1]){
02739      pn[qpiece]="q";
02740      pI[qpiece].src=imgs["q"].src;
02741      paC="b";
02742      bhQ=true;
02743      xDe[4]=-1;
02744      }
02745     
02746      }
02747     
02748      }
02749      }
02750     
02751     
02752     
02753     
02754     //auto-castle
02755     function autoCastle(kpiece,kcd){
02756     
02757      if (pn[kpiece].indexOf("k")!=-1){
02758     
02759      var castleokay=0;
02760      //white king
02761     
02762      fakeView=false;
02763      if(dc["vw"].value=="false"){
02764      fakeView=true;
02765      on=on.reverse();
02766      }
02767     
02768      if (pn[kpiece].indexOf("wk")!=-1){
02769     
02770      //if king lands on correct square
02771      if((((pp[kpiece][0]==on[62][0])||(pp[kpiece][0]==on[58][0]))&&(pp[kpiece][1]==on[63][1]))){
02772      if(pp[kpiece][0]==on[58][0]){
02773      //if left castle is there
02774      if(pp[56][0]==on[56][0]&&pp[56][1]==on[56][1]){
02775      //if intervening spaces are clear
02776      var thisR=-1;
02777      for(wcc=0;wcc<pp.length;wcc++){
02778      if(on[57][0]==pp[wcc][0]&&on[57][1]==pp[wcc][1]){
02779      if(pI[wcc].src.indexOf("X.gif")!=-1){castleokay++;}
02780      }
02781      if(on[59][0]==pp[wcc][0]&&on[59][1]==pp[wcc][1]){
02782      if(pI[wcc].src.indexOf("X.gif")!=-1){thisR=wcc;castleokay++;}
02783      }
02784      }
02785      if(castleokay==2&&wCCl){
02786      // move rook
02787      pI[thisR].src=imgs["wr"].src;
02788      pI[56].src=imgs["X"].src;
02789      pn[thisR]="wr";
02790      pn[56]="X";
02791      wCCl=false;
02792      wCCr=false;
02793      }
02794      }
02795      }
02796      //if king lands on correct square
02797      if(pp[kpiece][0]==on[62][0]){
02798      //if right castle is there
02799      if(pp[63][0]==on[63][0]&&pp[63][1]==on[63][1]){
02800      //if intervening spaces are clear
02801      var thisR=-1;
02802      for(wcc=0;wcc<pp.length;wcc++){
02803      if(on[61][0]==pp[wcc][0]&&on[61][1]==pp[wcc][1]){
02804      if(pI[wcc].src.indexOf("X.gif")!=-1){thisR=wcc;castleokay++;}
02805      }
02806      }
02807      if(castleokay==1&&wCCr){
02808      // move rook
02809      pI[thisR].src=imgs["wr"].src;
02810      pI[63].src=imgs["X"].src;
02811      pn[thisR]="wr";
02812      pn[63]="X";
02813      wCCl=false;
02814      wCCr=false;
02815      }
02816      }
02817      }
02818      }
02819     
02820      //black king
02821      }else{
02822     
02823      //if king lands on correct square
02824      if((((pp[kpiece][0]==on[2][0])||(pp[kpiece][0]==on[6][0]))&&(pp[kpiece][1]==on[0][1]))){
02825      if(pp[kpiece][0]==on[2][0]){
02826      //if left castle is there
02827      if(pp[0][0]==on[0][0]&&pp[0][1]==on[0][1]){
02828      //if intervening spaces are clear
02829      var thisR=-1;
02830      for(bcc=0;bcc<pp.length;bcc++){
02831      if(on[1][0]==pp[bcc][0]&&on[1][1]==pp[bcc][1]){
02832      if(pI[bcc].src.indexOf("X.gif")!=-1){castleokay++;}
02833      }
02834      if(on[3][0]==pp[bcc][0]&&on[3][1]==pp[bcc][1]){
02835      if(pI[bcc].src.indexOf("X.gif")!=-1){thisR=bcc;castleokay++;}
02836      }
02837      }
02838      if(castleokay==2&&bCCl){
02839      // move rook
02840      pI[thisR].src=imgs["r"].src;
02841      pI[0].src=imgs["X"].src;
02842      pn[thisR]="r";
02843      pn[0]="X";
02844      bCCl=false;
02845      bCCr=false;
02846      }
02847      }
02848      }
02849      //if king lands on correct square
02850      if(pp[kpiece][0]==on[6][0]){
02851      //if right castle is there
02852      if(pp[7][0]==on[7][0]&&pp[7][1]==on[7][1]){
02853      //if intervening spaces are clear
02854      var thisR=-1;
02855      for(bcc=0;bcc<pp.length;bcc++){
02856      if(on[5][0]==pp[bcc][0]&&on[5][1]==pp[bcc][1]){
02857      if(pI[bcc].src.indexOf("X.gif")!=-1){thisR=bcc;castleokay++;}
02858      }
02859      }
02860      if(castleokay==1&&bCCr){
02861      // move rook
02862      pI[thisR].src=imgs["r"].src;
02863      pI[7].src=imgs["X"].src;
02864      pn[thisR]="r";
02865      pn[7]="X";
02866      bCCl=false;
02867      bCCr=false;
02868      }
02869      }
02870      }
02871      }
02872      }
02873     
02874      if(fakeView){
02875      on=on.reverse();
02876      }
02877     
02878      }
02879      //if king is otherwise moved
02880      if (pn[kpiece].indexOf("k")!=-1){
02881      if (pn[kpiece].indexOf("wk")!=-1){
02882      wCCl=false;wCCr=false;
02883      }else{
02884      bCCl=false;bCCr=false;
02885      }
02886      }
02887      //if rook is moved, castling no longer okay
02888      var tok=new Array(kpiece,kcd);
02889      for(j=0;j<2;j++){
02890      fakeView=false;
02891      if (pn[tok[j]].indexOf("wr")!=-1){
02892      if(tok[j]==56){wCCl=false;}
02893      if(tok[j]==63){wCCr=false;}
02894      }else{
02895      if(tok[j]==0){bCCl=false;}
02896      if(tok[j]==7){bCCr=false;}
02897      }
02898      }
02899     
02900     
02901      //final castle status
02902      dc["wccr"].value=wCCr;
02903      dc["bccr"].value=bCCr;
02904      dc["wccl"].value=wCCl;
02905      dc["bccl"].value=bCCl;
02906     
02907      }
02908     
02909     
02910     
02911     
02912     
02913     
02914     function mouseUp(e){
02915     
02916      //hide valid moves
02917      if(showLEGAL||blockILLEGAL){hideValidMoves();}
02918     
02919      //clear recorder playback
02920      var stopit=false;
02921      if(event.button>1){return false;}
02922      if(event.srcElement.name!="rp"){firstPlay=false;}
02923      if(event.srcElement.name=="rp"||event.srcElement.name=="andan"||event.srcElement.name=="newg"||event.srcElement.name=="clrb"||event.srcElement.name=="reco"){
02924      stopit=true;
02925      }
02926     
02927      if(stopit){
02928      //clear reco playback
02929      clearTimeout(chessTimer);
02930      if(event.srcElement.name!="rp"){firstPlay=false;}
02931      dc["rp"].value="Play";
02932      dc["rp"].title="Play through";
02933      dc["gpv"].style.backgroundColor=dC;
02934      dc["gpv"].style.color=lC;
02935      }
02936     
02937      // reset for bin piece transfer
02938      if (forced){forced=false;}
02939     
02940      // find piece id from hidden form
02941      var piece=dc["pieceid"].value;
02942      // drop piece and reset z order
02943      if (dragokay&&(pp[piece]||bb[piece]||bw[piece])){
02944     
02945      // find if piece came from board or bin
02946      var group="board";
02947      // retrieve initial mouse position
02948      var kx=dc["kxinfo"].value;
02949      var ky=dc["kyinfo"].value;
02950      if (kx<on[0][0]){group="black";}
02951      if (kx>(on[7][0]+sqS)){group="white";}
02952     
02953      // find group and object name and position
02954      var tmS=pS[piece];
02955      if(ie5p&&shadowCOLOR!=""){
02956      if(tmS.firstChild.filters[0]){
02957      tmS.firstChild.filters[0].enabled=false;
02958      }
02959      }
02960     
02961      var tmN=pn[piece];
02962      var ibb=dc["vbb"].value;
02963      var ibw=dc["vbw"].value;
02964      if (group=="board"){
02965      var tmP=new Array(pp[piece][0],pp[piece][1]);
02966      }
02967      if (group=="black"){
02968      var biS=false;
02969      if (ibb>=16){
02970      blF=true;
02971      for (d=0;d<16;d++){
02972      if (!biS){if (bnb[d]=="X"){ibb=d;biS=true;}}
02973      }
02974      }
02975      var tmP=new Array(bb[ibb][0],bb[ibb][1]);
02976      if (blF){ibb=16;}
02977      }
02978      if (group=="white"){
02979      var biS=false;
02980      if (ibw>=16){
02981      whF=true;
02982      for (d=0;d<16;d++){
02983      if (!biS){if (bnw[d]=="X"){ibw=d;biS=true;}}
02984      }
02985      }
02986      var tmP=new Array(bw[ibw][0],bw[ibw][1]);
02987      if (whF){ibw=16;}
02988      }
02989     
02990      tmS.style.zIndex=4;
02991      // dropped location
02992      var mx=tmS.style.pixelLeft;
02993      var my=tmS.style.pixelTop;
02994     
02995      for (cd=0;cd<64;cd++){
02996     
02997      // validate move
02998      if (!movedone){validateMove(mx,my,cd,piece);}
02999     
03000      // if move is validated
03001      if (moveokay&&!movedone){
03002     
03003      //remember piece movement for benefit of reverse-playback
03004      //ckC=1;
03005     
03006      //store separate en-passent info for validation
03007      if((piece>=48&&piece<=55)&&(cd>=32&&cd<=39)){valEnp=(cd+8);}
03008      else if((piece>=8&&piece<=15)&&(cd>=24&&cd<=31)){valEnp=(cd-8);}
03009      else{valEnp=-1;}
03010     
03011     
03012      // store current piece info
03013      var cdS=pS[cd];
03014      var cdN=pn[cd];
03015      var tmPi=piece;
03016     
03017      // swap pieces
03018      tmS.style.left=pp[cd][0];
03019      tmS.style.top=pp[cd][1];
03020      cdS.style.left=tmP[0];
03021      cdS.style.top=tmP[1];
03022     
03023      //en passent target square
03024      findEnPassent(piece,cd);
03025     
03026      //fullmove clock
03027      fullMove(piece,cd);
03028     
03029      //swap values
03030      pp[piece][0]=pp[cd][0];
03031      pp[piece][1]=pp[cd][1];
03032      pp[cd][0]=tmP[0];
03033      pp[cd][1]=tmP[1];
03034     
03035      promotePawn(piece,cd);
03036      autoCastle(piece,cd);
03037      discardPiece(cd,tmN);
03038      pieceMove(piece,cd);
03039      halfMove(piece,cd,cdN);
03040     
03041      // move has finished
03042      movedone=true;
03043     
03044     
03045      // if move logging is enabled
03046      if (ato){
03047      n=0;
03048      outString=new Array;
03049     
03050      var mainRef=parseInt(dc["ls"].value);
03051      if (mainRef==-1){
03052      dc["lss"].value=-1;
03053      dc["lsss"].value=-1;
03054      }
03055     
03056     
03057      // get notated move and position string
03058      var oldRef;var newRef;
03059      for (i=0;i<64;i++){
03060     
03061      // find square names
03062      if (tmS.style.pixelLeft==on[i][0]&&tmS.style.pixelTop==on[i][1]){
03063      newRef=i;
03064      }
03065      if (cdS.style.pixelLeft==on[i][0]&&cdS.style.pixelTop==on[i][1]){
03066      oldRef=i;
03067      }
03068      for (j=0;j<64;j++){
03069     
03070      // find all board objects
03071      if (pS[j].style.pixelLeft==on[i][0]&&pS[j].style.pixelTop==on[i][1]){
03072      addToOutputString(pI[j]);
03073      }
03074      }
03075     
03076      n++;
03077      }
03078     
03079      // get position string
03080      convertOutputString(outString,false,true,false);
03081     
03082      //set current log number
03083      loN=mainRef+1;
03084     
03085      //record smith position
03086      moL[loN]=cc[oldRef]+cc[newRef];
03087     
03088      //write game to smith log
03089      var rl="";
03090      var rln=0;
03091      rl+='<table border=0 cellspacing=4 cellpadding=0 width="100%" style="cursor:default">';
03092      for(i=0;i<moL.length;i+=2){
03093      rln++;
03094      if(moL[i]){
03095      rl+='<tr id="findmove">';
03096      rl+='<td class=daco width="2%" align=center>'+rln+'.</td>';
03097      rl+='<td onclick="goToPosition('+(i+1)+')" class=daco width="49%" id="logcell'+(i+1)+'" style="cursor:hand\;background-color:'+dC+'" onmouseover="cellOver(this)" onmouseout="cellOut(this)">&nbsp;'+moL[i]+'</td>';
03098      if(moL[(i+1)]){rl+='<td onclick="goToPosition('+(i+2)+')" class=daco width="49%" id="logcell'+(i+2)+'" style="cursor:hand\;background-color:'+dC+'" onmouseover="cellOver(this)" onmouseout="cellOut(this)">&nbsp;'+moL[(i+1)]+'</td>';}
03099      rl+='</tr>';
03100      }
03101      }
03102      rl+=stb;
03103      dog("movetable").innerHTML=rl;
03104      dog("movetable").scrollTop=dog("logcell"+(i-1)).offsetTop;
03105     
03106      // set next log id
03107      dc["ls"].value=loN;
03108      loN++;
03109     
03110     
03111      }
03112     
03113      }
03114      }
03115     
03116     
03117      // if invalid move, return to original place
03118      if (!moveokay){
03119      tmS.style.left=pp[piece][0]
03120      tmS.style.top=pp[piece][1];
03121      }
03122     
03123      dragokay=false;
03124      }
03125      return true
03126      }
03127     
03128     
03129     
03130     
03131     // set id of selected piece and write to form
03132     
03133     function setpieceid(pObj){
03134      if (!dragokay&&document.forms){
03135      if (pObj!=null&&dc){
03136      var obId=pObj.id;
03137      //alert(obId);
03138      if (obId.indexOf("binw")!=-1&&dc["info"]){
03139      var pNum=Number(obId.replace("binw",""));
03140      dc["info"].value=pObj.id+" - "+bnw[pNum];
03141      dc["pieceid"].value=pNum;
03142      }
03143      if (obId.indexOf("binb")!=-1&&dc["info"]){
03144      var pNum=Number(obId.replace("binb",""));
03145      dc["info"].value=pObj.id+" - "+bnb[pNum];
03146      dc["pieceid"].value=pNum;
03147      }
03148      if (obId.indexOf("play")!=-1&&dc["info"]){
03149      var pNum=Number(obId.replace("play",""));
03150      dc["info"].value=pObj.id+" - "+pn[pNum];
03151      dc["pieceid"].value=pNum;
03152      }
03153      }else{
03154      if (dc&&dc["info"]){
03155      dc["info"].value="";
03156      dc["pieceid"].value="";
03157      }
03158      }
03159      }
03160      }
03161     
03162     
03163     
03164     
03165     
03166     // flip the board
03167     var WV=true;
03168     var VW=true;
03169     
03170     function flipBoard(){
03171      if(!secu){return false;}
03172     
03173      //if(ato){dc["ato"].click();}
03174     
03175      if (moves>-1){
03176     
03177      // find all objects
03178      var fOb=new Array;
03179      var fN=new Array;
03180      var flipCode=new Array;
03181      var n=0;
03182      var q=63;
03183      for (i=0;i<64;i++){
03184     
03185      // store square codes
03186      flipCode[i]=cc[q];
03187     
03188      for (j=0;j<64;j++){
03189      // find main board objects
03190      if (pS[j].style.pixelLeft==on[i][0]&&pS[j].style.pixelTop==on[i][1]){
03191      fOb[n]=pS[j];
03192      fN[n]=j;
03193      }
03194      }
03195      n++;
03196      q-=1;
03197      }
03198     
03199      // flip all objects
03200      var q=63;
03201      for (i=0;i<64;i++){
03202     
03203     
03204      if (WV){
03205      fOb[i].style.left=on[q][0];
03206      fOb[i].style.top=on[q][1];
03207      pp[fN[i]][0]=on[q][0];
03208      pp[fN[i]][1]=on[q][1];
03209      // swap square codes
03210      cc[i]=flipCode[i];
03211     
03212      }else{
03213      pp[fN[i]][0]=on[i][0];
03214      pp[fN[i]][1]=on[i][1];
03215      // swap square codes
03216      cc[i]=flipCode[q];
03217      }
03218      q-=1;
03219      }
03220      if (WV){
03221      WV=false;
03222      }else{
03223      WV=true;
03224      flipBoard();
03225      }
03226      }
03227      }
03228     
03229     
03230     
03231     // move notation covers
03232     function flipCovers(){
03233      if(!secu){return false;}
03234     
03235      if (moves>-1){
03236      if (down){
03237      lCov.style.top=arT+(sqS*8)+2;
03238      nCov.style.left=arL+(sqS*3)-16;
03239      down=false;
03240      }else{
03241      lCov.style.top=arT-16;
03242      nCov.style.left=arL+(sqS*3)+(sqS*8)+2;
03243      down=true;
03244      }
03245      if(VW){VW=false;}
03246      else{VW=true;}
03247      dc["vw"].value=VW;
03248     
03249      }
03250      }
03251     
03252     
03253     
03254     
03255     
03256     //start recording
03257     function startRecording(){
03258      if(!secu){return false;}
03259     
03260      //if(gIn&&!allC){return false;}
03261     
03262      // hide last move indicators
03263      hideLastMove();
03264     
03265      //clear reco playback
03266      clearTimeout(chessTimer);
03267      firstPlay=false;
03268     
03269      dc["rp"].value="Play";
03270      dc["rp"].title="Play through";
03271     
03272      if(!ato){
03273     
03274      ato=true;
03275      dc["ato"].value="Stop";
03276      dc["ato"].title="Stop";
03277      dc["gpv"].style.backgroundColor = "#dc5656";
03278      dc["gpv"].style.color = "#333399";
03279      }
03280      else{
03281      ato=false;
03282      dc["ato"].value="Record";
03283      dc["ato"].title="Record";
03284      dc["gpv"].style.backgroundColor = dC;
03285      dc["gpv"].style.color = lC;
03286      }
03287     
03288      }
03289     
03290     
03291     
03292     
03293     
03294     //reco 'shuttle' controls
03295     var thB='';var thatOutput='';
03296     var bra=false;var uic=0;
03297     var lgc;
03298     function recoMove(thGP){
03299      if(!secu){return false;}
03300     
03301      thB='';ui=false;
03302     
03303      // hide last move indicators
03304      hideLastMove();
03305     
03306      //if(ato){dc["ato"].click();}
03307     
03308      if(thGP=="e"){
03309      thGP=reco.length-1;
03310      thB="e"
03311      }
03312      if(thGP=="rw"){
03313      thGP=parseInt(dc["gp"].value)-1;
03314      if(thGP<0){thGP=0;}
03315      thB="rw";
03316      }
03317      if(thGP=="ff"){
03318      thGP=parseInt(dc["gp"].value)+1;
03319      if(thGP>=reco.length){thGP=reco.length-1;}
03320      thB="ff";
03321      }
03322     
03323     
03324      dc["gp"].value=thGP;
03325     
03326      star="";
03327      dc["ant"].value="";
03328      if(annt[thGP]&&annt[thGP]!=""){star="*";dc["ant"].value=annt[thGP];}
03329     
03330      //move log
03331      if(prvC>-1){
03332      lgc=dog("logcell"+prvC);
03333      if(lgc){
03334      lgc.style.backgroundColor=dC;
03335      lgc.style.color=lC;
03336      }
03337      }
03338      lgc=dog("logcell"+thGP);
03339      if(lgc&&thGP>0){
03340      if(showP[3]){
03341      dog("movetable").scrollTop=lgc.offsetTop-2;
03342      }
03343      lgc.style.backgroundColor=lC;
03344      lgc.style.color=dC;
03345      prvC=thGP;
03346      }else{
03347      prvC=-1;
03348      if(showP[3]){
03349      dog("movetable").scrollTop=0;
03350      }
03351      }
03352     
03353      var gpVal=thGP/2;
03354      if(parseFloat(gpVal)!=parseInt(gpVal)){gpVal=Math.round(gpVal);gpVal+=".";}
03355      else{if(gpVal>0){gpVal+="..";}else{gpVal="..";}}
03356      var lsNum=Math.round((reco.length-1)/2);if(lsNum==0){lsNum="..";}if(lsNum==0){lsNum="..";}
03357     
03358      dc["gpv"].value=gpVal+star+" /"+lsNum;
03359      dc["ls"].value=thGP-1;
03360     
03361      var thO=reco[thGP];
03362     
03363     
03364      //update board with position
03365      dc["start"].value=thO;
03366      if(pla){allReset(false);}setP('custom');
03367      dc["current"].value=thO;
03368     
03369      if(inputV=="b"){
03370      VW=true;
03371      dc["vw"].value=VW;
03372      dc["sv"].click();
03373      }
03374     
03375     
03376     
03377      //update castling availability in reverse game
03378      if(thB=="rw"&&ui){
03379      alert("3798");
03380      wCCr=false;bCCr=false;
03381      wCCl=false;bCCl=false;
03382      var ca=pcfXd[arrNum][1];
03383      if(ca.indexOf("K")!=-1){wCCr=true;}
03384      if(ca.indexOf("Q")!=-1){wCCl=true;}
03385      if(ca.indexOf("k")!=-1){bCCr=true;}
03386      if(ca.indexOf("q")!=-1){bCCl=true;}
03387     
03388      dc["wccr"].value=wCCr;
03389      dc["bccr"].value=bCCr;
03390      dc["wccl"].value=wCCl;
03391      dc["bccl"].value=bCCl;
03392      }
03393     
03394     
03395     
03396      }
03397     
03398     
03399     
03400     function stopRecorder() {
03401     
03402      dc["rp"].value="Play";
03403      dc["rp"].title="Play through";
03404      dc["gpv"].style.backgroundColor = dC;
03405      dc["gpv"].style.color = lC;
03406      clearTimeout(chessTimer);
03407      firstPlay=false;
03408      playing=false;
03409     
03410      }
03411     
03412     
03413     //play control
03414     var firstPlay=false;
03415     var playing=false;
03416     function playRecorder(butt){
03417     
03418     
03419      if(!secu){return false;}
03420      // hide last move indicators
03421      hideLastMove();
03422     
03423      if(reco.length<=1){return false;}
03424     
03425      //stop reco if recording
03426      if(ato){dc["ato"].click();}
03427     
03428      //begin playback
03429      if(!firstPlay){
03430      dc["rp"].value="Stop";
03431      dc["rp"].title="Stop";
03432      dc["gpv"].style.backgroundColor = "#76bc76";
03433      dc["gpv"].style.color = "#333399";
03434      //go back to beginning if at end
03435      if(parseInt(dc["gp"].value)==(reco.length-1)){
03436      dc["b"].click();
03437      }
03438      firstPlay=true;
03439      }
03440      //go to next move
03441      else if(!butt) { dc["ff"].click(); }
03442     
03443      if(parseInt(dc["gp"].value)<(reco.length-1)&&dc["rp"].value=="Stop"){
03444      if(!playing){dc["ff"].click(); playing=true; }
03445      if(playing){
03446      chessTimer=setTimeout("playRecorder()",playbackSpeed);
03447      }
03448      }
03449      else{ stopRecorder(); }
03450     
03451     
03452      }
03453     
03454     
03455     
03456     
03457     //precompile extra FEN information
03458     var scrLog="";
03459     var rl;
03460     var promWQ=false;
03461     var promBQ=false;
03462     var feny=new Array;
03463     feny[0]=new Array("r","n","b","q","k","b","n","r","p","p","p","p","p","p","p","p","X","X","X","X","X","X","X","X","X","X","X","X","X","X","X","X","X","X","X","X","X","X","X","X","X","X","X","X","X","X","X","X","P","P","P","P","P","P","P","P","R","N","B","Q","K","B","N","R");
03464     fenXd[0]="rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR";
03465     function precompileFEN(){
03466     
03467      for(i=0;i<gMoves.length;i++){
03468     
03469      //split move
03470      pcfM[i]=new Array(gMoves[i].charAt(0)+gMoves[i].charAt(1),gMoves[i].charAt(2)+gMoves[i].charAt(3));
03471     
03472      //alert(sqp[pcfM[i][0]][0]+"-"+sqp[pcfM[i][1]][0]+"\n"+sqp[pcfM[i][0]][1]+"-"+sqp[pcfM[i][1]][1]);
03473     
03474      //extra FEN data
03475      var Xctm="b";
03476      if(i>0){if(i/2!=parseInt(i/2)){Xctm="w"}}
03477      var Xkcc="KQkq";
03478      if(i>0){Xkcc=pcfXd[(i-1)][1];}
03479      var Xenp="-";
03480      if(i>0){Xenp=pcfXd[(i-1)][2];}
03481      var Xhmc=0;
03482      if(i>0){Xhmc=pcfXd[(i-1)][3];}
03483      var Xfmc=1;
03484      if(i>0){Xfmc=pcfXd[(i-1)][4];}
03485      var Xptq="";
03486      if(i>0){Xptq=pcfXd[(i-1)][7];}
03487     
03488      pcfXd[i]=new Array(Xctm,Xkcc,Xenp,Xhmc,Xfmc,"X",-1,Xptq);
03489     
03490      //store current values
03491      var tmPCF=new Array
03492      tmPCF[0]=new Array(sqp[pcfM[i][0]][0],sqp[pcfM[i][1]][0]);
03493      tmPCF[1]=new Array(sqp[pcfM[i][0]][1],sqp[pcfM[i][1]][1]);
03494     
03495      //alert(sqp[pcfM[i][0]]);
03496     
03497      //copy fen array from previous
03498      feny[(i+1)]=new Array;
03499      for (j=0;j<64;j++){
03500      feny[(i+1)][j]=feny[i][j];
03501      }
03502     
03503     
03504      //check for pawn-queen conversion
03505      if(sqp[pcfM[i][0]][0].indexOf("p")!=-1){
03506      //white
03507      if(sqp[pcfM[i][0]][0].indexOf("wp")!=-1){
03508      if(!promWQ&&(sqp[pcfM[i][0]][1]>=8&&sqp[pcfM[i][0]][1]<=15)&&(sqp[pcfM[i][1]][1]>=0&&sqp[pcfM[i][1]][1]<=7)){
03509      //alert(sqp[pcfM[i][0]][0]+"\n"+sqp[pcfM[i][1]][0]+"\n\n"+sqp[pcfM[i][0]][1]+"\n"+sqp[pcfM[i][1]][1]);
03510      pcfXd[i][7]="wp";
03511      promWQ=true;
03512      feny[(i+1)][tmPCF[1][0]]="Q";
03513      }else{
03514      pcfXd[i][7]="";
03515      }
03516      }else{
03517      //black
03518      if(!promBQ&&(sqp[pcfM[i][0]][1]>=48&&sqp[pcfM[i][0]][1]<=55)&&(sqp[pcfM[i][1]][1]>=56&&sqp[pcfM[i][1]][1]<=63)){
03519      //alert(sqp[pcfM[i][0]][0]+"\n"+sqp[pcfM[i][1]][0]+"\n\n"+sqp[pcfM[i][0]][1]+"\n"+sqp[pcfM[i][1]][1]);
03520      pcfXd[i][7]="p";
03521      promBQ=true;
03522      feny[(i+1)][tmPCF[1][0]]="q";
03523      }else{
03524      pcfXd[i][7]="";
03525      }
03526      }
03527      }
03528     
03529     
03530     
03531      //king can castle (assumes that the castle move is legal)
03532      //check for rook movement
03533      if(sqp[pcfM[i][0]][0].indexOf("r")!=-1){
03534      //white
03535      if(sqp[pcfM[i][0]][0].indexOf("wr")!=-1){
03536      if(sqp[pcfM[i][0]][1]==63){pcfXd[i][1]=pcfXd[i][1].replace("K","");}
03537      if(sqp[pcfM[i][0]][1]==56){pcfXd[i][1]=pcfXd[i][1].replace("Q","");}
03538      }else{
03539      //black
03540      if(sqp[pcfM[i][0]][1]==7){pcfXd[i][1]=pcfXd[i][1].replace("k","");}
03541      if(sqp[pcfM[i][0]][1]==0){pcfXd[i][1]=pcfXd[i][1].replace("q","");}
03542      }
03543      }
03544      //check for king movement
03545      if(sqp[pcfM[i][0]][0].indexOf("k")!=-1){
03546      //white
03547      //alert(pcfXd[i][1]);
03548      if(pcfXd[i][1]!=""&&pcfXd[i][1]!="-"){
03549      if(sqp[pcfM[i][0]][0].indexOf("wk")!=-1){
03550      //kingside
03551      if(sqp[pcfM[i][1]][1]==62){
03552      feny[(i+1)][(tmPCF[1][1]+1)]="X";
03553      feny[(i+1)][(tmPCF[1][1]-1)]="R";
03554      sqp['e1'][0]="X"
03555      sqp['f1'][0]="wr";
03556      sqp['g1'][0]="wk";
03557      sqp['h1'][0]="X";
03558      }
03559      //queenside
03560      if(sqp[pcfM[i][1]][1]==58){
03561      feny[(i+1)][(tmPCF[1][1]-2)]="X";
03562      feny[(i+1)][(tmPCF[1][1]+1)]="R";
03563      sqp['e1'][0]="X"
03564      sqp['d1'][0]="wr";
03565      sqp['c1'][0]="wk";
03566      sqp['a1'][0]="X";
03567      }
03568      pcfXd[i][1]=pcfXd[i][1].replace("K","");
03569      pcfXd[i][1]=pcfXd[i][1].replace("Q","");
03570      }else{
03571      //black
03572      //kingside
03573      if(sqp[pcfM[i][1]][1]==6){
03574      feny[(i+1)][(tmPCF[1][1]+1)]="X";
03575      feny[(i+1)][(tmPCF[1][1]-1)]="r";
03576      sqp['e8'][0]="X"
03577      sqp['f8'][0]="wr";
03578      sqp['g8'][0]="wk";
03579      sqp['h8'][0]="X";
03580      }
03581      //queenside
03582      if(sqp[pcfM[i][1]][1]==2){
03583      feny[(i+1)][(tmPCF[1][1]-2)]="X";
03584      feny[(i+1)][(tmPCF[1][1]+1)]="r";
03585      sqp['e8'][0]="X"
03586      sqp['d8'][0]="wr";
03587      sqp['c8'][0]="wk";
03588      sqp['a8'][0]="X";
03589      }
03590      pcfXd[i][1]=pcfXd[i][1].replace("k","");
03591      pcfXd[i][1]=pcfXd[i][1].replace("q","");
03592      }
03593      }
03594      if(pcfXd[i][1]==""){pcfXd[i][1]="-";}
03595      }
03596     
03597     
03598     
03599     
03600     
03601      //en-passent
03602      pcfXd[i][2]="-";
03603      if(sqp[pcfM[i][0]][0].indexOf("p")!=-1){
03604      //white
03605      if(sqp[pcfM[i][0]][0].indexOf("wp")!=-1){
03606      if(sqp[pcfM[i][0]][1]>=48&&sqp[pcfM[i][0]][1]<=55){
03607      if(sqp[pcfM[i][1]][1]>=32&&sqp[pcfM[i][1]][1]<=39){
03608      //alert(cc[(sqp[pcfM[i][0]][1]-8)]);
03609      pcfXd[i][2]=cc[(sqp[pcfM[i][0]][1]-8)];
03610      }
03611      }else{
03612      }
03613      }else{
03614      //black
03615      if(sqp[pcfM[i][0]][1]>=8&&sqp[pcfM[i][0]][1]<=15){
03616      if(sqp[pcfM[i][1]][1]>=24&&sqp[pcfM[i][1]][1]<=31){
03617      pcfXd[i][2]=cc[(sqp[pcfM[i][0]][1]+8)];
03618      }
03619      }else{
03620      }
03621      }
03622      }
03623      if(i>0){
03624      if(pcfXd[(i-1)][2]!="-"){
03625      if(sqp[pcfXd[(i-1)][2]][1]==tmPCF[1][1]){
03626      //alert(sqp[pcfXd[(i-1)][2]]+"\n"+tmPCF[1][1]);
03627      var tep=tmPCF[1][1];
03628      if(tep>=16&&tep<=23){
03629      feny[(i+1)][tmPCF[1][1]]="p";
03630      feny[(i+1)][(tmPCF[1][1]+8)]="X";
03631      }
03632      if(tep>=40&&tep<=47){
03633      feny[(i+1)][tmPCF[1][1]]="P";
03634      feny[(i+1)][(tmPCF[1][1]-8)]="X";
03635      }
03636      }
03637      }
03638      }
03639     
03640     
03641     
03642     
03643      //half-move clock
03644      pcfXd[i][3]++;
03645      //alert(sqp[pcfM[i][0]][0]+"\n"+sqp[pcfM[i][1]][0]);
03646      if((sqp[pcfM[i][0]][0].indexOf("p")!=-1)||(sqp[pcfM[i][1]][0]!="X")){if(sqp[pcfM[i][1]][0].indexOf("k")==-1){pcfXd[i][3]=0;}}
03647     
03648      //full-move clock
03649      if(parseInt(i/2)!=(i/2)){pcfXd[i][4]++;}
03650     
03651      //alert(sqp[pcfM[i][0]][1]+" - "+sqp[pcfM[i][0]][0]);
03652     
03653      //store taken pieces info
03654      if(sqp[pcfM[i][1]][0]!="X"){
03655      //alert(sqp[pcfM[i][1]][0]+" - "+sqp[pcfM[i][1]][1]);
03656      pcfXd[i][5]=sqp[pcfM[i][1]][0];
03657      pcfXd[i][6]=sqp[pcfM[i][1]][1];
03658      }
03659     
03660     
03661      //swap values
03662      sqp[pcfM[i][0]][0]="X";
03663      sqp[pcfM[i][1]][0]=tmPCF[0][0];
03664     
03665      sqp[pcfM[i][0]][1]=tmPCF[1][0];
03666      sqp[pcfM[i][1]][1]=tmPCF[1][1];
03667     
03668     
03669     
03670     
03671      //build main FEN position
03672     
03673      //change values
03674      var temFen=feny[(i+1)][tmPCF[1][1]];
03675      feny[(i+1)][tmPCF[1][1]]=feny[(i+1)][tmPCF[1][0]];
03676      if(temFen){
03677      feny[(i+1)][tmPCF[1][0]]="X";
03678      }
03679     
03680      // build string from array
03681      fenXd[(i+1)]="";
03682      for (j=0;j<64;j++){
03683      fenXd[(i+1)]+=feny[(i+1)][j];
03684      if (j==7||j==15||j==23||j==31||j==39||j==47||j==55){fenXd[(i+1)]+="/";}
03685      }
03686     
03687      // convert "X"s to number
03688      convertX(fenXd[(i+1)]);
03689      fenXd[(i+1)]=fs;
03690     
03691     
03692      //alert(fenXd[(i+1)]);
03693     
03694      //add extra fen info
03695      fenXd[(i+1)]+=" "+pcfXd[(i)][0]+" "+pcfXd[(i)][1]+" "+pcfXd[(i)][2]+" "+pcfXd[(i)][3]+" "+pcfXd[(i)][4];
03696     
03697     
03698      //add to arrays
03699      moL[i]=pcfM[i][0]+pcfM[i][1];
03700      if(firstLast!=""){
03701      if(moL[i]==firstLast){flNum=i;}
03702      }
03703      reco[(i+1)]=fenXd[(i+1)];
03704      moC[i]=fenXd[(i+1)];
03705     
03706      }
03707      reco[0]="rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1";
03708     
03709     
03710      //enable output and recording
03711      allC=true;
03712     
03713     
03714     
03715      //write game to smith log
03716      var rl="";
03717      var rln=0;
03718      rl+='<table border=0 cellspacing=4 cellpadding=0 width="100%" style="cursor:default">';
03719      for(i=0;i<fenXd.length;i+=2){
03720      rln++;
03721      if(pcfM[i]){
03722      rl+='<tr>';
03723      rl+='<td class=daco width="2%" align=center>'+rln+'.</td>';
03724      rl+='<td onclick="goToPosition('+(i+1)+')" class=daco width="49%" id="logcell'+(i+1)+'" style="cursor:hand\;background-color:'+dC+'" onmouseover="cellOver(this)" onmouseout="cellOut(this)">&nbsp;'+moL[i]+'</td>';
03725      if(pcfM[(i+1)]){rl+='<td onclick="goToPosition('+(i+2)+')" class=daco width="49%" id="logcell'+(i+2)+'" style="cursor:hand\;background-color:'+dC+'" onmouseover="cellOver(this)" onmouseout="cellOut(this)">&nbsp;'+moL[(i+1)]+'</td>';}
03726      rl+='</tr>';
03727      }
03728      }
03729      rl+=stb;
03730      dog("movetable").innerHTML=rl;
03731     
03732      //test function
03733      rl="";
03734      rl+='<table border=0 cellspacing=4 cellpadding=0 width="100%">';
03735      for(i=0;i<fenXd.length;i+=1){
03736      rl+='<tr>';
03737      rl+='<td>'+i+": "+fenXd[i]+'</td>';
03738      rl+='</tr>';
03739      }
03740      rl+=stb;
03741     
03742     
03743      //alert("finished compiling");
03744     
03745     
03746      }
03747     
03748     
03749     //log functions
03750     function cellOver(cell){
03751      cell.style.backgroundColor=lC;
03752      cell.style.color=dC;
03753      }
03754     function cellOut(cell){
03755      var cellid=cell.id.replace("logcell","");
03756      cellid=parseInt(cellid);
03757      if(cellid!=prvC){
03758      cell.style.backgroundColor=dC;
03759      cell.style.color=lC;
03760      }
03761      }
03762     function goToPosition(bpNum){
03763     
03764      if(ato){dc["ato"].click();}
03765     
03766      dc["start"].value=reco[bpNum];
03767      dc["sp"].click();
03768      dc["current"].value=reco[bpNum];
03769      dc["gp"].value=bpNum;
03770     
03771      star="";
03772      if(annt[bpNum]&&annt[bpNum]!=""){star="*";dc["ant"].value=annt[bpNum];}else{dc["ant"].value="";}
03773      var lsNum=Math.round((reco.length-1)/2);if(lsNum==0){lsNum="..";}
03774     
03775     
03776      var gpVal=bpNum/2;
03777      if(parseFloat(gpVal)!=parseInt(gpVal)){gpVal=Math.round(gpVal);gpVal+=".";}
03778      else{gpVal=Math.round(gpVal);gpVal+="..";}
03779      dc["gpv"].value=gpVal+star+" /"+lsNum;
03780     
03781      if(prvC>-1){
03782      lgc=dog("logcell"+prvC);
03783      lgc.style.backgroundColor=dC;
03784      lgc.style.color=lC;
03785      }
03786      lgc=dog("logcell"+bpNum);
03787      lgc.focus();
03788      lgc.blur();
03789      lgc.style.backgroundColor=lC;
03790      lgc.style.color=dC;
03791      prvC=bpNum;
03792     
03793      dc["ls"].value=bpNum-1;
03794     
03795     
03796      if(inputV=="b"){
03797      VW=true;
03798      dc["vw"].value=VW;
03799      dc["sv"].click();
03800      }
03801      }
03802     
03803     
03804     
03805     
03806     
03807     
03808     
03809     
03810     //process input game
03811     var gIn=false;
03812     function processGame(gDetails){
03813      gIn=true;
03814      gMoves=gDetails.split(",");
03815     
03816      precompileFEN();
03817     
03818      }
03819     
03820     
03821     
03822     
03823     //clear recorder memory
03824     var doClear;
03825     function clearRecorder(toWhere){
03826     
03827      doClear=false;
03828      if(reco.length<=1){
03829      doClear=true;
03830      }
03831      else if(confirm("Are you sure you wish to clear this game?")){
03832      doClear=true;
03833      }
03834      else {
03835      doClear=false;
03836      }
03837     
03838      if(doClear){
03839     
03840      if(toWhere){
03841      if(toWhere=="new"){
03842      if(pla){allReset(false);}
03843      setP('rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1')
03844      dc["current"].value='rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1';
03845      }
03846      if(toWhere=="clear"){
03847      if(pla){allReset(false);}
03848      setP('8/8/8/8/8/8/8/8 w KQkq - 0 1');
03849      dc["current"].value='8/8/8/8/8/8/8/8 w KQkq - 0 1';
03850      }
03851      }
03852     
03853      dc["gp"].value=0;
03854      dc["gpv"].value=".. /..";
03855     
03856      //change form text to indicate processed game
03857      dc["ato"].disabled=false;
03858      ato=false;
03859      //if(dc["ato"].value==""){
03860      dc["ato"].value="Record";
03861      dc["ato"].title="Record";
03862      dc["reco"].options[1].style.color=lC;
03863      dc["reco"].options[2].style.color=lC;
03864      dc["reco"].options[3].style.color=lC;
03865      if(ie5p&&enablePgnImport) { dc["reco"].options[8].style.color=lC; }
03866      else { dc["reco"].options[7].style.color=lC; }
03867      // }
03868     
03869      dog("movetable").innerHTML="";
03870     
03871      //reset arrays
03872      rNum=1;
03873      reco.length=rNum;
03874      fenXd.length=rNum;
03875      prvC=-1;
03876      annt.length=rNum;
03877      annt[0]="";
03878      moL.length=rNum-1;
03879      moC.length=rNum-1;
03880      gIn=false;
03881      dc["ls"].value=(rNum-2);
03882     
03883      //turn off input conversion
03884      gIn=false;
03885     
03886      //clear game annotation
03887      taVa=new Array("?","?","?","?","?","?","*","-","-","?","?");
03888      dc["aE"].value=taVa[0];
03889      dc["aS"].value=taVa[1];
03890      dc["aD"].value=taVa[2];
03891      dc["aR"].value=taVa[3];
03892      dc["aW"].value=taVa[4];
03893      dog("wPlayer").innerText="";
03894      dog("bPlayer").innerText="";
03895      dog("wRating").innerText="";
03896      dog("bRating").innerText="";
03897      dog("wFlag").src=imgs["X"].src;
03898      dog("bFlag").src=imgs["X"].src;
03899      dog("indW").src=imgs["X"].src;
03900      dog("indB").src=imgs["X"].src;
03901      dc["ant"].value="";
03902      dc["aB"].value=taVa[5];
03903      dc["aRe"].value=taVa[6];
03904      dc["aWE"].value=taVa[7];
03905      dc["aBE"].value=taVa[8];
03906      dc["aWN"].value=taVa[9];
03907      dc["aBN"].value=taVa[10];
03908      updateTagInformation();
03909     
03910      document.title="ChessPlayer v2.2 by Brothercake";
03911     
03912      }
03913     
03914      }
03915     
03916     
03917     
03918     
03919     
03920     //advanced reco controls
03921     function advancedControls(avc){
03922      // hide last move indicators
03923      hideLastMove();
03924     
03925      if(!secu){dc["reco"].options[0].selected=true;return false;}
03926      //export FEN log
03927      if(avc=="fen"){generateExport('fen');}
03928      //export Smith Notation log
03929      if(avc=="smith"){generateExport('smith');}
03930      //export PGN Notation log
03931      if(avc=="pgn"){generateExport('pgn');}
03932      //export query string
03933      if(avc=="query"){generateExport('query');}
03934      //import query string
03935      if(avc=="queryin"){
03936      var thQu=prompt('Please enter a Player format game string','');
03937      if(thQu!=null&&thQu!=""){
03938      thQu=thQu.replace("*cpg*","");
03939      thQu=thQu.replace("*cpg*","");
03940      self.document.location=pageName+"?"+thQu;
03941      }
03942      }
03943      //import pgn file
03944      if(avc=="pgnin"){
03945      var ddl=document.location.href;
03946      var cbLoc;
03947      if(location.search) {
03948      ddl=ddl.split("?");
03949      cbLoc=ddl[0];
03950      }
03951      else { cbLoc=ddl; }
03952      var exp='';
03953      exp+="loc="+cbLoc+"&panels="+dc['panels'].value+"&size="+sqS+"&view=w&pieces="+pf.replace('/','')+"&showLegal="+showLEGAL+"&blockIllegal="+blockILLEGAL;
03954      var qCols="&lightCOLOR="+lC+"&darkCOLOR="+dC+"&borderCOLOR="+bC+"&whiteSQUARES="+wQ+"&blackSQUARES="+bQ+"&boardBACKING="+boardBACKING+"&shadowCOLOR="+shadowCOLOR;
03955      qCols=qCols.replace(/[\#]/g,'');
03956      exp+=qCols;
03957      if(!live) { pgnProcess="pgnImport.html"; }
03958      var pgnLogWin = open("_program/_import/"+pgnProcess+"?"+exp,"pgnLogWin","left=0,top=0,width=397,height=450,status=yes,menubar=no,toolbar=no,scrollbars=yes,resizable=yes")
03959      }
03960      //save game
03961      if(avc=="save"){saveGame();}
03962      //load game
03963      if(avc.indexOf("*cpg*")!=-1){loadGame(avc);}
03964      //delete game
03965      if(avc=="delete"){deleteGame();}
03966      //reset selector
03967      dc["reco"].options[0].selected=true;
03968      }
03969     
03970     
03971     
03972     
03973     
03974     
03975     
03976     //add annt
03977     var added=false;
03978     function addAnnotation(){
03979      if(!secu){return false;}
03980      if(added){
03981      added=false;
03982      return false;
03983      }
03984      var aNum=parseInt(dc["gp"].value);
03985     
03986      aText=dc["ant"].value;
03987     
03988      //annotation cannot contain &=sign
03989      //aText=aText.replace(/[\&\=]/g,'');
03990      //yes it can, unless its going to be in query string
03991     
03992      if(aText==""){
03993      annt[aNum]="";
03994      var aGPV=dc["gpv"].value;
03995      if(aGPV.indexOf("*")!=-1){
03996      aGPV=aGPV.replace("*","");
03997      }
03998      dc["gpv"].value=aGPV;
03999      }
04000      if(aText!=""){
04001      annt[aNum]=aText;
04002      dc["ant"].value="";
04003      var aGPV=dc["gpv"].value;
04004      if(aGPV.indexOf("*")==-1){
04005      aGPV=aGPV.replace("/","*/");
04006      }
04007      dc["gpv"].value=aGPV;
04008      }
04009      added=true;
04010      return false;
04011      }
04012     
04013     
04014     
04015     
04016     // program help
04017     var programWin;
04018     function programHelp(){
04019      programWin=window.open("_program/help.html?lico="+(lC.replace('#',''))+"&daco="+(dC.replace('#',''))+"&borco="+(bC.replace('#',''))+"&size=small","programWin","left=32,top=32,width=455,height=440,status=yes,menubar=no,toolbar=yes,scrollbars=yes,resizable=yes");
04020      }
04021     
04022     // help functions trigger
04023     var basicWin,advancedWin,fenhelpWin,pgnWin,openingsWin;
04024     function launchHelp(helpType){
04025      if(!secu){dc["help"].options[0].selected=true;return false;}
04026      if (helpType=="program"){programHelp();}
04027      else{
04028      if (helpType=="basic"){
04029      if (!basicWin||basicWin.closed){basicWin=window.open(basicHELP,'basicWin');}
04030      }
04031      if (helpType=="advanced"){
04032      if (!advancedWin||advancedWin.closed){advancedWin=window.open(advancedHELP,'advancedWin');}
04033      }
04034      if (helpType=="fen"){
04035      if (!fenhelpWin||fenhelpWin.closed){fenhelpWin=window.open(fenHELP,'fenhelpWin');}
04036      }
04037      if (helpType=="pgn"){
04038      if (!pgnWin||pgnWin.closed){pgnWin=window.open(pgnHELP,'pgnWin');}
04039      }
04040      if (helpType=="openings"){
04041      if (!openingsWin||openingsWin.closed){openingsWin=window.open(openingsHELP,'openingsWin');}
04042      }
04043      }
04044      //reset selector
04045      dc["help"].options[0].selected=true;
04046      }
04047     
04048     
04049     
04050     //presets
04051     function presetP(prPos){
04052      if(!secu){return false;}
04053      if(prPos=="new"){
04054      clearRecorder("new");
04055      }
04056     
04057      if (prPos=="clear"){
04058      clearRecorder("clear");
04059      }
04060      }
04061     
04062     
04063     
04064     //add main game annotation
04065     function gameAnnotation(){
04066      if(!secu){return false;}
04067      var aWin=open("_program/annotate.html?pf="+pf+"&lico="+(lC.replace('#',''))+"&daco="+(dC.replace('#',''))+"&borco="+(bC.replace('#','')),"aWin","left=64,top=64,width=301,height=364,status=yes,menubar=no,toolbar=no,scrollbars=no,resizable=no");
04068      }
04069     
04070     //update tag values with annotation information
04071     function updateTagInformation(){
04072      taVa[0]=dc["aE"].value;
04073      taVa[1]=dc["aS"].value;
04074      taVa[2]=dc["aD"].value;
04075      taVa[3]=dc["aR"].value;
04076      taVa[4]=dc["aW"].value;
04077      taVa[5]=dc["aB"].value
04078      taVa[6]=dc["aRe"].value;
04079      taVa[7]=dc["aWE"].value;
04080      taVa[8]=dc["aBE"].value;
04081      taVa[9]=dc["aWN"].value;
04082      taVa[10]=dc["aBN"].value;
04083      }
04084     
04085     
04086     
04087     var openP=new Array;
04088     openP['cog']=new Array(152,152,0);
04089     openP['vog']=new Array(111,111,1);
04090     openP['rog']=new Array(85,85,2);
04091     openP['mog']=new Array(112,112,3);
04092     openP['pog']=new Array(0,0,4);
04093     var showP=new Array(true,true,true,true,true);
04094     var totalH=451;
04095     
04096     
04097     //contract/retract boxes
04098     function retract(tab){
04099     
04100      if(!secu){return false;}
04101     
04102      totalH=119+imgH
04103      hTab=tab.id;
04104      dog(hTab).style.cursor="hand";
04105     
04106      var pTab=hTab.replace("-tab","");
04107      pTab=hTab.replace("tab-hide","");
04108     
04109      if(hTab.indexOf("-tab")!=-1){
04110      hTab=hTab.replace("-tab","");
04111      dog(hTab).style.display="none";
04112      dog(hTab+"-hide").style.display="inline";
04113     
04114      showP[openP[hTab][2]]=false;
04115     
04116      if(hTab=="pog"){
04117      if(window.name&&window.name=="chessWin"){
04118     
04119      if(!exclude&&window.name&&window.name=="chessWin"){
04120      boW=(14*sqS)+2;
04121      if(boW<492){boW=492;}
04122      boH=(8*sqS)+61;
04123      if(boH<341){boH=341;}
04124      window.resizeTo(184+boW+chrW,68+boH+chrH);
04125      }
04126     
04127      }
04128      dog("pog-spacer").style.height=23;
04129      dog("msgdiv").style.top=imgH+arT-20-bsPos;
04130      }
04131     
04132      if(hTab!="mog"){
04133     
04134      openP[hTab][0]=20;
04135      if(hTab=="pog"){openP[hTab][0]=65;}
04136      openP['mog'][0]=totalH-(openP['cog'][0]+openP['vog'][0]+openP['rog'][0]+openP['pog'][0]);
04137     
04138      }
04139     
04140      }
04141      if(hTab.indexOf("tab-hide")!=-1){
04142      hTab=hTab.replace("tab-hide","");
04143     
04144      showP[openP[hTab][2]]=true;
04145     
04146      if(hTab=="pog"){
04147     
04148      if(!exclude&&window.name&&window.name=="chessWin"){
04149      boW=(14*sqS)+2;
04150      if(boW<492){boW=492;}
04151      boH=(8*sqS)+61;
04152      if(boH<341){boH=341;}
04153      window.resizeTo(184+boW+chrW,133+boH+chrH);
04154      }
04155     
04156      dog("pog-spacer").style.height=88;
04157      dog("msgdiv").style.top=imgH+arT+47-bsPos;
04158      }
04159     
04160      if(hTab!="mog"){
04161     
04162      openP[hTab][0]=openP[hTab][1];
04163      openP['mog'][0]=totalH-(openP['cog'][0]+openP['vog'][0]+openP['rog'][0]+openP['pog'][0]);
04164     
04165      }
04166     
04167      dog(hTab+"-hide").style.display="none";
04168      dog(hTab).style.display="inline";
04169      }
04170     
04171     
04172     
04173      if(pTab!="mog"){
04174     
04175      //alert(moL.length);
04176     
04177      var mtxt='';
04178      mtxt+='<img src="_program/_icons/expanded.gif" vspace=3 onclick="retract(this)" id="mog-tab" title="Contract" style="filter:alpha(opacity=64)\;cursor:hand\;position:relative\;top:1px\;border:1px outset '+lC+'" hspace=1 width=141 height=8 alt="" border=0>';
04179      mtxt+='<div id="movetable" style="margin-top:6px\;height:'+(openP['mog'][0]-24)+'px\;overflow-y:scroll\;scrollbar-base-color:'+dC+'\;scrollbar-arrow-color:'+lC+'">';
04180      mtxt+='</div></div>';
04181      dog("mog").innerHTML=mtxt;
04182     
04183      if(moL.length>1){
04184      var rl="";
04185      var rln=0;
04186      rl+='<table border=0 cellspacing=4 cellpadding=0 width="100%" style="cursor:default">';
04187      for(i=0;i<moL.length;i+=2){
04188      rln++;
04189      if(moL[i]){
04190      rl+='<tr>';
04191      rl+='<td class=daco width="2%" align=center>'+rln+'.</td>';
04192      rl+='<td onclick="goToPosition('+(i+1)+')" class=daco width="49%" id="logcell'+(i+1)+'" style="cursor:hand\;background-color:'+dC+'" onmouseover="cellOver(this)" onmouseout="cellOut(this)">&nbsp;'+moL[i]+'</td>';
04193      if(moL[(i+1)]){rl+='<td onclick="goToPosition('+(i+2)+')" class=daco width="49%" id="logcell'+(i+2)+'" style="cursor:hand\;background-color:'+dC+'" onmouseover="cellOver(this)" onmouseout="cellOut(this)">&nbsp;'+moL[(i+1)]+'</td>';}
04194      rl+='</tr>';
04195      }
04196      }
04197      rl+=stb;
04198      dog("movetable").innerHTML=rl;
04199      }
04200     
04201      }
04202     
04203      dc["panels"].value=showP;
04204      }
04205     
04206     

Pour ne pas voir les numéros de ligne, ajoutez &nl=non à la suite du nom du fichier.

 

 

retour gH    Retour à la page principale de   (gH)