﻿function fplay(t,id){clearTimeout(this.timer);if(t)this.timer=setTimeout(function(){$('next'+id).click();fplay(t,id)},t)}
function fgo(id,n){
  if(id==null)id='';
  var o=$('go'+id);
  //o.onmouseover=function(){if(this.isreload)return;this.isreload=1;fgo(id)};
  var go=new Go(o);
  o.oncontextmenu=function(){go.Redo();return false};
  go.loadSGF($('SGF'+id).value);
  var s='<div class="Goto">'
    +'<input type="button" onclick="fgoto(\''+id+'\',-361)" value="开始">'
    +'<input type="button" onclick="fgoto(\''+id+'\',-5)" value="快退">'
    +'<input type="button" onclick="fgoto(\''+id+'\',-1)" value="上手">'
    +'<input class="auto" size="2" id="fsgf'+id+'" onchange="fgoto(\''+id+'\')" title="到第n手" class="center">'
    +'<input type="button" onclick="fgoto(\''+id+'\',1)" id="next'+id+'" value="下手">'
    +'<input type="button" onclick="fgoto(\''+id+'\',5)" value="快进">'
    +'<input type="button" onclick="fgoto(\''+id+'\',361)" value="结束">'
    +'<input type="button" onclick="window[\'go'+id+'\'].Char()" value="数字">'
    +'<input type="button" onclick="editSGF(this,\''+id+'\')" value="标注">'
    +'<input type="button" onclick="getSGF(this,\''+id+'\')" value="导出">'
    +'<input type="button" onclick="freload(\''+id+'\')" value="刷新">'
    +'<select class="auto" onchange="fplay(value,\''+id+'\');var o=nextSibling;o.style.display=value?\'\':\'none\';style.display=value?\'none\':\'\';">'
    +'<option value="">自动打谱</option>'
    +'<option value="100">0.1秒</option>'
    +'<option value="500">0.5秒</option>'
    +'<option value="1000">1秒</option>'
    +'<option value="2000">2秒</option>'
    +'<option value="5000">5秒</option>'
    +'<option value="10000">10秒</option>'
    +'</select><input type="button" value="停止" onclick="var o=previousSibling;o.value=\'\';o.onchange()" style="display:none;">'
    +'</div>';
        
  $('Goto'+id).innerHTML=s;
  go.sgfo=$('fsgf'+id);
  window['go'+id]=go;
  if(go.sgf)fgoto(id,n?n:361);
  return go;
}
function fgoto(id,n){
  var o=window['go'+id];
  var c=o.Move(n);
  o=$('MSG'+id);
  if(o)o.innerHTML=c?c:'';
}
function freload(id){
  var o=$('SGF'+id);
  if(o.rvalue)o.value=o.rvalue;
  fgo(id);
}
function editSGF(o,id){
  var b=o.value=='标注';
  o.value=b?'结束':'标注';
  var g=window['go'+id];
  g.edit=b;
  if(!g.edit){
    var a=g.E;
    for(var i=0;i<a.length;i++){
      a[i].innerHTML='';
    }
    g.E=[];
  }
}
function getSGF(o,id){
  if(id==null)id='';
  var c=window['go'+id].getMiniSGF();
  var s=c?c.s:'';
  var o=$('SGF'+id);
  if(!o.rvalue)o.rvalue=o.value;
  o.value=s;
  var b=o.style.display=='';
  o.style.display=b?'none':'';
  
}


