dojo.require("dojo.window");dojo.require("dojo.number");dojo.require("dojo.parser");dojo.require("dojo.back");dojo.require("dijit._base.place");dojo.require("dojox.fx.scroll");dojo.require("dijit.form.Form");dojo.require("dijit.form.Button");dojo.require("dijit.form.DropDownButton");dojo.require("dijit.form.TextBox");dojo.require("dijit.form.ValidationTextBox");dojo.require("dijit.form.CheckBox");dojo.require("dijit.form.DateTextBox");dojo.require("dijit.form.Select");dojo.require("dijit.form.SimpleTextarea");dojo.require("dijit.layout.ContentPane");dojo.require("dijit.layout.TabContainer");dojo.require("dijit.Tooltip");dojo.require("dijit.TooltipDialog");var ChessboardInterface=new Object();ChessboardInterface=function(a){this.needcorrectPNG=(dojo.isIE&&dojo.isIE<7&&!dojo.isOpera)?true:false;this.startFEN="rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR";this.MainNode=null;this.GameContentDiv=null;this.UpTimerDiv=null;this.DownTimerDiv=null;this.boardContainer=null;this.parentRef=null;this.divBoard=null;this.BoardInfoDiv=null;this.RightButtonsDiv=null;this.GameButtonsNumber=0;this.boardOuter=null;this.gameStateImg=null;this.gameStateInfo=null;this.game={};this.game.timeout=false;this.divIndicators={};this.divIndicators.premove={};this.divIndicators.lastmove={};this.handles=[];this.board_handles=[];this.premove_handles=[];this.notation_handles=[];this.clicked_sq1=null;this.clicked_sq2=null;this.premove_sq1=null;this.premove_sq2=null;this.making_move=false;this.isBusy=false;this.in_promotion=false;this.pieceDragging=false;this.switching_timer=false;this.files=new Array("a","b","c","d","e","f","g","h");this.ranks=new Array(1,2,3,4,5,6,7,8);this.ChessSetHash={1:{name:"Alpha",value:"alpha",vip:false},2:{name:"Cases",value:"cases",vip:false},3:{name:"Leipzig",value:"leipzig",vip:false},4:{name:"Merida",value:"merida",vip:false},5:{name:"Smart",value:"smart",vip:false},6:{name:"VIP1",value:"vip1",vip:true}};this.SquareSizeHash={1:{name:"30x30",value:30},2:{name:"45x45",value:45},3:{name:"60x60",value:60},4:{name:"75x75",value:75},5:{name:"90x90",value:90}};this.SkinHash={1:{name:Vegas.f.phrase(101),value:"lwalnut"},2:{name:Vegas.f.phrase(102),value:"mahagon"},3:{name:Vegas.f.phrase(103),value:"walnut"},4:{name:Vegas.f.phrase(104),value:"marble"},5:{name:Vegas.f.phrase(105),value:"wood1"},6:{name:Vegas.f.phrase(106),value:"wood2"},7:{name:Vegas.f.phrase(107),value:"wood3"},8:{name:Vegas.f.phrase(108),value:"wood4"},9:{name:Vegas.f.phrase(112),value:"wood5"},10:{name:Vegas.f.phrase(109),value:"ebonit"}};this.divBoard_zindex=10;this.Captured={};this.Widget={};this.DND=null;this.last_chat_id=0;this.hitch_click_func={board_click:dojo.hitch(this,"__board_click")};this.hitch_pdrag_func={set_piece_dragging:dojo.hitch(this,"__set_piece_dragging")};this.__initProps(a);this.__preload_pieces({set:this.chessSet,size:this.squareSize});if(this.squareSize!=this.captured_size){this.__preload_pieces({set:this.chessSet,size:this.captured_size})}if(this.can_init_board_events){this.DND=ToolMan.drag()}this.__create_containers();this.build_board();this.__create_right_part();Vegas.f.make_unselectable(this.boardContainer);dojo.connect(this.boardContainer,"oncontextmenu",this,function(b){dojo.stopEvent(b);return false});if(this.notationEnabled){this.build_notation({movenum:this.game.movenum})}this.init_timer();if(this.gameMode=="game"){this.__init_dom_objects()}if(this.gameMode=="game"&&this.game.my&&this.game.winner_id==null&&this.game.white_id>0&&this.game.black_id>0){this.start_repeat_move()}};ChessboardInterface.prototype={__initProps:function(a){if(!Vegas.client.settings.chessboard){Vegas.client.settings.chessboard={};Vegas.client.settings.chessboard=dojo.fromJson(dojo.cookie("chessboard"));if(!Vegas.client.settings.chessboard){Vegas.client.settings.chessboard={}}}this.MainNode=dojo.byId(a.MainNode);if(a.GameContentDiv){this.GameContentDiv=dojo.byId(a.GameContentDiv)}this.gameMode=a.gameMode||"unknown";this.game=a.gameHash||{};this.squareSize=a.squareSize||Vegas.client.settings.chessboard.squareSize||60;this.captured_size=30;this.skin=a.skin||Vegas.client.settings.chessboard.boardSkin||"walnut";this.colorLightSquares=a.colorLightSquares||"#FFFFFF";this.colorDarkSquares=a.colorDarkSquares||"#CCCCCC";this.boardLabels=a.boardLabels||false;this.flipBoard=((Vegas.client.id==this.game.black_id)||(this.game.black_id==0&&this.game.white_id>0&&Vegas.client.id!=this.game.white_id))?true:false;this.imageFolder="/img/pieces/all/";this.boardBgImgFolder="/img/chessboard/all/";this.chessSet=this.__getAvailableChessSet(a.chessSet||Vegas.client.settings.chessboard.chessSet||"alpha");if(!this.game.fen||!this.game.fen.length){this.game.fen=this.startFEN}this.game.playertomove=(this.game.playertomove=="black"||this.game.playertomove=="b")?"b":"w";this.game.lastmoved=(this.game.playertomove=="w")?"b":"w";this.notation_lastmoved=this.game.lastmoved;this.notation_movenum=this.game.movenum;this.notation_fen=this.game.fen;this.Captured.captured=this.game.captured||"";this.chess_warn=this.game.chess_warn||"";this.game.my=this.__is_my_game();this.game.movedata=this.get_movedata();if(this.gameMode=="analiz"||(this.gameMode=="game"&&this.game.winner_id==null&&this.game.white_id>0&&this.game.black_id>0&&this.game.tlimit>=3600)||(this.gameMode=="game"&&this.game.winner_id!=null&&this.game.white_id>0&&this.game.black_id>0)){this.notationEnabled=true}else{this.notationEnabled=false}this.show_timer=(this.gameMode=="game"&&this.game.white_id>0&&this.game.black_id>0)?true:false;this.TimerPos=Vegas.client.settings.timerpos||"updown";this.TimerDiv_height=(this.show_timer&&this.TimerPos=="updown")?23:0;this.TimerFontSize="160%";this.TimerFontColor="#666666";this.TimerFontFamily="Arial";this.CountdownTimerFontColor="#000066";this.DeadlineTime=30;this.DeadlineTimeColor="#FF0033";this.can_init_board_events=(this.gameMode=="analiz"||(this.gameMode=="game"&&this.game.my&&this.game.winner_id==null&&this.game.white_id>0&&this.game.black_id>0))?true:false;this.marble_color="#006666";this.soundEnabled=Vegas.client.sound_on;this.gameButtonsInTab=(this.gameMode=="game")?true:false;this.chatEnabled=true;this.premove_sq_color="#CCCCCC";this.timer_interval=100;this.timer_increment=0.1;this.warntime1=Vegas.client.settings.warntime1;this.warntime2=Vegas.client.settings.warntime2;this.tenth_rule=Vegas.client.settings.tenth;if(this.tenth_rule==-1){this.tenth_start_seconds=-1}else{if(this.tenth_rule==-2){this.tenth_start_seconds=Math.floor(this.game.tlimit/2)}else{if(this.tenth_rule==-3){this.tenth_start_seconds=this.game.tlimit}else{this.tenth_start_seconds=this.tenth_rule}}}this.fadeInLastMove=true;this.move_history_nodes={};return false},__init_dom_objects:function(){this.upd_html=Vegas.f.updating_game_html();this.WhosturnDiv=dojo.byId("whosturn");if(this.WhosturnDiv&&this.game.winner_id==null&&this.game.white_id>0&&this.game.black_id>0){this.show_game_state({draw_flag:this.game.draw_flag})}},destroy:function(){this.disconnect_handles();for(var a in this.Widget){this.Widget[a].destroyRecursive()}dojo.destroy(this.GameContentDiv);return false},set_board_sizes:function(){if(this.squareSize==30){this.boardContainer_width=300;this.boardContainer_height=300;this.parentRef_paddingLeft=14;this.parentRef_paddingTop=28}else{if(this.squareSize==45){this.boardContainer_width=420;this.boardContainer_height=420;this.parentRef_paddingLeft=14;this.parentRef_paddingTop=29}else{if(this.squareSize==60){this.boardContainer_width=560;this.boardContainer_height=560;this.parentRef_paddingLeft=20;this.parentRef_paddingTop=37}else{if(this.squareSize==75){this.boardContainer_width=670;this.boardContainer_height=670;this.parentRef_paddingLeft=18;this.parentRef_paddingTop=32}else{if(this.squareSize==90){this.boardContainer_width=800;this.boardContainer_height=800;this.parentRef_paddingLeft=20;this.parentRef_paddingTop=37}else{this.boardContainer_width=560;this.boardContainer_height=560;this.parentRef_paddingLeft=23;this.parentRef_paddingTop=37}}}}}return false},__style_parentRef:function(){dojo.style(this.parentRef,{paddingLeft:this.parentRef_paddingLeft+"px",paddingTop:this.parentRef_paddingTop+"px",width:(this.boardContainer_width-this.parentRef_paddingLeft)+"px",height:(this.boardContainer_height-this.parentRef_paddingTop)+"px",backgroundImage:"url("+this.boardBgImgFolder+"board_bg_"+this.skin+"_"+this.squareSize+".jpg)",backgroundRepeat:"no-repeat"});return false},__style_BoardInfoDiv:function(){dojo.style(this.BoardInfoDiv,{position:"absolute",left:(this.boardContainer_width+10)+"px",top:"0px"});return false},__style_parentTabDiv:function(){var a=dojo.window.getBox();this.TabContainer_w=a.w-this.__getLeftPos(this.BoardInfoDiv)-20;if(this.TabContainer_w<=100||this.TabContainer_w>Math.floor(a.w/2)){this.TabContainer_w=400}dojo.style(this.parentTabDiv,{width:this.TabContainer_w+"px",height:this.TabContainer_h+"px"});return false},__style_childTabDiv:function(){dojo.style(this.childTabDiv,{width:"100%",height:"100%"});return false},__create_containers:function(){this.set_board_sizes();if(!this.GameContentDiv){this.GameContentDiv=dojo.create("div",null,this.MainNode)}if(this.show_timer&&this.TimerPos=="updown"){this.UpTimerDiv=dojo.create("div",null,this.GameContentDiv);dojo.style(this.UpTimerDiv,{position:"absolute",left:"0px",top:"0px",width:this.boardContainer_width+"px",height:this.TimerDiv_height+"px",fontSize:this.TimerFontSize,color:this.TimerFontColor,fontFamily:this.TimerFontFamily,textAlign:"center",lineHeight:this.TimerDiv_height+"px"})}if(this.boardContainer){dojo.destroy(this.boardContainer)}this.boardContainer=dojo.create("div",null,this.GameContentDiv);dojo.style(this.boardContainer,{position:"absolute",top:(this.TimerPos=="updown")?this.TimerDiv_height+"px":"0px",left:"0px"});this.parentRef=dojo.create("div",null,this.boardContainer);this.__style_parentRef();if(this.show_timer&&this.TimerPos=="updown"){this.DownTimerDiv=dojo.create("div",null,this.GameContentDiv);dojo.style(this.DownTimerDiv,{position:"absolute",left:"0px",top:this.TimerDiv_height+this.boardContainer_height+"px",width:this.boardContainer_width+"px",height:this.TimerDiv_height+"px",fontSize:this.TimerFontSize,color:this.TimerFontColor,fontFamily:this.TimerFontFamily,textAlign:"center",lineHeight:this.TimerDiv_height+"px"})}return false},__create_right_part:function(){if(this.BoardInfoDiv){dojo.destroy(this.BoardInfoDiv)}if(this.gameMode=="game"){this.BoardInfoDiv=dojo.byId("BoardInfoDiv")}else{this.BoardInfoDiv=dojo.create("div",null,this.GameContentDiv)}this.__style_BoardInfoDiv();this.RightButtonsDiv=dojo.create("div",null,this.BoardInfoDiv,"last");this.RightButtonsDiv_w=190;this.RightButtons_w=this.RightButtonsDiv_w-20;dojo.style(this.RightButtonsDiv,{width:this.RightButtonsDiv_w+"px",textAlign:"center",border:"1px solid #799D81",marginTop:"5px",paddingTop:"5px",paddingBottom:"5px"});this.__create_game_buttons(this.RightButtonsDiv);var b=Math.floor(this.GameButtonsNumber*35+20);this.TabContainer_h=250;if(this.gameButtonsInTab&&b>this.TabContainer_h){this.TabContainer_h=b}if(this.gameMode=="game"){this.OpponentsDiv=dojo.create("div",null,this.BoardInfoDiv,"first");dojo.style(this.OpponentsDiv,{border:"1px solid #CCCCCC",padding:"5px",marginBottom:"5px"});this.OpponentsDiv.innerHTML=dojo.byId("players_div").innerHTML;dojo.destroy(dojo.byId("players_div"))}this.parentTabDiv=dojo.create("div",null,this.BoardInfoDiv);this.__style_parentTabDiv();this.childTabDiv=dojo.create("div",null,this.parentTabDiv);this.__style_childTabDiv();this.Widget.TabContainer=new dijit.layout.TabContainer({tabPosition:"top",useMenu:true,useSlider:true,style:"height: 100%; width: 100%; overflow: auto;"},this.childTabDiv);if(this.gameMode=="game"&&this.gameButtonsInTab){this.Widget.gameOptionsTab=new dijit.layout.ContentPane({title:Vegas.f.phrase(114),content:""});this.Widget.TabContainer.addChild(this.Widget.gameOptionsTab);dojo.place(this.RightButtonsDiv,this.Widget.gameOptionsTab.containerNode)}if(this.gameMode=="game"&&this.game.my&&this.game.winner_id==null&&this.game.white_id>0&&this.game.black_id>0){this.Widget.chatTab=new dijit.layout.ContentPane({title:Vegas.f.phrase(93),content:""});this.Widget.TabContainer.addChild(this.Widget.chatTab);this.ChatDiv=dojo.create("div",null,this.Widget.chatTab.containerNode);this.ChatDiv_h=this.TabContainer_h-85;dojo.style(this.ChatDiv,{width:"95%",height:this.ChatDiv_h+"px",border:"1px solid #799D81",padding:"4px",overflow:"auto"});this.ChatDivInput=dojo.create("div",null,this.Widget.chatTab.containerNode);dojo.style(this.ChatDivInput,{width:"95%",verticalAlign:"middle"});var j={send_chat_msg:dojo.hitch(this,"__send_chat_msg")};var d=dojo.create("div",null,this.ChatDivInput);this.Widget.ChatTextBox=new dijit.form.TextBox({value:"",onKeyUp:function(f){if(f.keyCode==dojo.keys.ENTER){j.send_chat_msg()}return false}},d);var c=this.TabContainer_w-150;if(c<0){c=Math.floor(this.TabContainer_w/2)}dojo.style(this.Widget.ChatTextBox.domNode,"width",c+"px");var g=dojo.create("div",null,this.ChatDivInput);this.Widget.ChatSend=new dijit.form.Button({label:Vegas.f.phrase(94),iconClass:"dijitIconMail",showLabel:false,onClick:function(){j.send_chat_msg();return false}},g);var a={clear_chat:dojo.hitch(this,"__clear_chat")};var h=dojo.create("div",null,this.ChatDivInput);this.Widget.ClearChat=new dijit.form.Button({label:Vegas.f.phrase(122),iconClass:"dijitEditorIcon dijitEditorIconNewPage",showLabel:false,onClick:function(){a.clear_chat();return false}},h);var k={enable_chat:dojo.hitch(this,"__enable_chat")};var e=dojo.create("div",null,this.ChatDivInput);this.Widget.EnableChat=new dijit.form.Button({label:"---",iconClass:"dijitIconUsers",showLabel:false,onClick:function(){k.enable_chat();return false}},e);this.__enable_chat(this.chatEnabled)}if(this.notationEnabled){this.Widget.notationTab=new dijit.layout.ContentPane({title:Vegas.f.phrase(1),style:"overflow: hidden;",content:""});this.Widget.TabContainer.addChild(this.Widget.notationTab)}if(this.gameMode=="game"){this.Widget.gameparamsTab=new dijit.layout.ContentPane({title:Vegas.f.phrase(95),content:dojo.byId("GameParamsDiv").innerHTML});dojo.destroy(dojo.byId("GameParamsDiv"));this.Widget.TabContainer.addChild(this.Widget.gameparamsTab)}if(this.gameMode=="opening"){this.Widget.openingInfoTab=new dijit.layout.ContentPane({title:Vegas.f.phrase(95),content:dojo.byId("posinfoDiv").innerHTML});dojo.destroy(dojo.byId("posinfoDiv"));this.Widget.TabContainer.addChild(this.Widget.openingInfoTab)}if(this.gameMode=="custom"){this.Widget.BoardSettingsTab=new dijit.layout.ContentPane({title:Vegas.f.phrase(97),content:""});this.__set_board_settings_content();this.Widget.TabContainer.addChild(this.Widget.BoardSettingsTab)}this.Widget.TabContainer.startup();if(!this.gameButtonsInTab){dojo.place(this.RightButtonsDiv,this.BoardInfoDiv,"last")}return false},__create_game_buttons:function(a){if(this.gameMode=="game"){if(this.game.winner_id==null&&this.game.white_id>0&&this.game.black_id>0){var p={setSound:dojo.hitch(this,"setSound")};var e=dojo.create("button",null,a);this.GameButtonsNumber+=1;this.Widget.sound=new dijit.form.ToggleButton({label:Vegas.f.phrase(86),showLabel:true,checked:Vegas.client.sound_on,iconClass:"dijitCheckBoxIcon",onChange:function(q){p.setSound(q);return false}},e);dojo.style(this.Widget.sound.containerNode.parentNode,{width:this.RightButtons_w+"px",textAlign:"left"});if(this.game.my){var b=dojo.create("button",null,a);this.GameButtonsNumber+=1;this.Widget.autoqueen=new dijit.form.ToggleButton({label:Vegas.f.phrase(87),showLabel:true,checked:(Vegas.client.settings.autoqueen=="all"||(Vegas.f.tc_name(this.game.tcontrol,this.game.tlimit,this.game.increment)=="blitz"&&Vegas.client.settings.autoqueen=="blitz"))?true:false,iconClass:"dijitCheckBoxIcon",onChange:function(q){return false}},b);dojo.style(this.Widget.autoqueen.containerNode.parentNode,{width:this.RightButtons_w+"px",textAlign:"left"});var j=dojo.create("button",null,a);this.GameButtonsNumber+=1;this.Widget.draw=new dijit.form.ToggleButton({label:Vegas.f.phrase(89),showLabel:true,checked:false,iconClass:"dijitCheckBoxIcon",onChange:function(q){return false}},j);dojo.style(this.Widget.draw.containerNode.parentNode,{width:this.RightButtons_w+"px",textAlign:"left"});var l=dojo.create("button",null,a);this.GameButtonsNumber+=1;this.Widget.resign=new dijit.form.Button({label:Vegas.f.phrase(88),iconClass:"dijitIconDelete",onClick:function(){Vegas.f.confirm_resign();return false}},l);dojo.style(this.Widget.resign.containerNode.parentNode,{width:this.RightButtons_w+"px",textAlign:"left"});if(this.__is_my_color(this.game.playertomove)){this.Widget.resign.set("disabled",false)}else{this.Widget.resign.set("disabled",true)}if(this.game.movenum<=Vegas.config.max_movenum_to_abort&&this.game.tour_id==0){var o=dojo.create("button",null,a);this.GameButtonsNumber+=1;this.Widget.abort=new dijit.form.Button({label:Vegas.f.phrase(57),iconClass:"dijitEditorIcon dijitEditorIconUnlink",onClick:function(){Vegas.f.abort_game({yes:false});return false}},o);dojo.style(this.Widget.abort.containerNode.parentNode,{width:this.RightButtons_w+"px",textAlign:"left"})}}}var m=dojo.create("button",null,a);this.GameButtonsNumber+=1;this.Widget.checkconn=new dijit.form.Button({label:Vegas.f.phrase(90),iconClass:"dijitIconConnector",onClick:function(){realtime.check_connection(this);return false}},m);dojo.style(this.Widget.checkconn.containerNode.parentNode,{width:this.RightButtons_w+"px",textAlign:"left"});var d=dojo.create("button",null,a);this.GameButtonsNumber+=1;this.Widget.pgn=new dijit.form.Button({label:Vegas.f.phrase(91),iconClass:"dijitEditorIcon dijitEditorIconViewSource",onClick:function(){if(!Vegas.client.VIP){Vegas.f.vip_warn({code:"pgn"});return false}Vegas.f.show_pgn(Vegas.game.id);return false}},d);dojo.style(this.Widget.pgn.containerNode.parentNode,{width:this.RightButtons_w+"px",textAlign:"left"});var n=dojo.create("button",null,a);this.GameButtonsNumber+=1;this.Widget.analiz=new dijit.form.Button({label:Vegas.f.phrase(79),iconClass:"dijitIconDocuments",onClick:function(){if(!Vegas.client.VIP){Vegas.f.vip_warn({code:"analiz"});return false}var q=window.open(Vegas.script+"?cmd=analyze_board&board_id="+Vegas.game.id+"&jstime="+(new Date()).getTime(),"_blank");q.focus();return false}},n);dojo.style(this.Widget.analiz.containerNode.parentNode,{width:this.RightButtons_w+"px",textAlign:"left"})}var h={flip:dojo.hitch(this,"flip")};var c=dojo.create("button",null,a);this.GameButtonsNumber+=1;this.Widget.flip=new dijit.form.Button({label:Vegas.f.phrase(96),iconClass:"dijitIconUndo",onClick:function(){h.flip();return false}},c);dojo.style(this.Widget.flip.containerNode.parentNode,{width:this.RightButtons_w+"px",textAlign:"left"});if(this.gameMode=="game"){var g=dojo.create("button",null,a);this.GameButtonsNumber+=1;this.Widget.customize_board=new dijit.form.Button({label:Vegas.f.phrase(110),iconClass:"dijitIconFunction",onClick:function(){Vegas.f.load_url({url:Vegas.script+"?cmd=custom_board"});return false}},g);dojo.style(this.Widget.customize_board.containerNode.parentNode,{width:this.RightButtons_w+"px",textAlign:"left"})}if(this.gameMode=="custom"){var k={saveBoardSettings:dojo.hitch(this,"saveBoardSettings")};var f=dojo.create("button",null,a);this.GameButtonsNumber+=1;this.Widget.save_board_settings=new dijit.form.Button({label:Vegas.f.phrase(111),iconClass:"dijitIconSave",onClick:function(){k.saveBoardSettings();return false}},f);dojo.style(this.Widget.save_board_settings.containerNode.parentNode,{width:this.RightButtons_w+"px",textAlign:"left"})}if(this.gameMode=="game"&&this.game.winner_id!=null&&this.game.movenum>2){this.share_el=dojo.create("div",{style:"margin-top: 5px;"},a);this.game_share=new Ya.share({element:this.share_el,l10n:(Vegas.client.lang=="ru")?"ru":"en",elementStyle:{type:"button",border:true,quickServices:[],text:Vegas.f.phrase(146)},link:"http://"+Vegas.host+this.game.link,title:(Vegas.client.lang=="ru")?"Партия на ChessVegas":"Game on ChessVegas",description:"",image:"http://"+Vegas.host+"/img/chessvegas_logo.gif",popupStyle:{blocks:[Vegas.f.phrase(147),"facebook","twitter","vkontakte","odnoklassniki","lj","yaru","blogger","digg","friendfeed","gbuzz","moikrug","moimir","myspace","liveinternet","yazakladki"]}})}return false},__getUniqueId:function(){var a="UID"+Math.random()+""+Math.random();return a.replace(/\./g,"")},__isArray:function(a){if(!a){return false}if(a.constructor.toString().indexOf("Array")!=-1){return true}return false},__getLeftPos:function(a){var b=dojo.position(a,true);return b.x},__getTopPos:function(a){var b=dojo.position(a,true);return b.y},__addBoardLabels:function(a){var j="ABCDEFGH";var b=parseInt(dojo.style(this.divBoard,"borderWidth"));var k="";if(this.skin=="marble"){k=this.marble_color}else{k="#EBDFB5"}var m=b;try{var f=this.__getLeftPos(this.divBoard);var c=this.__getLeftPos(this.boardFrame);m+=f-c}catch(h){}for(var l=1;l<=8;l++){var d=dojo.create("div",null,a);d.innerHTML=this.flipBoard?j.substr((8-l),1):j.substr((l-1),1);dojo.style(d,{position:"absolute",right:(((8-l)*this.squareSize)+m)+"px",bottom:"0px",textAlign:"center",width:this.squareSize+"px",fontSize:13+"px",fontWeight:"bold",fontFamily:"Trebuchet MS",color:k});var g=dojo.create("div",null,a);g.innerHTML=this.flipBoard?9-l:l;dojo.style(g,{position:"absolute",left:"0px",top:(((8-l)*this.squareSize)+m)+"px",height:this.squareSize+"px",lineHeight:this.squareSize+"px",fontSize:13+"px",fontWeight:"bold",fontFamily:"Trebuchet MS",color:k})}return false},__createSquares:function(){var b=this.boardBgImgFolder+"piece_bg_"+this.skin+"_"+this.squareSize+"_l.png";var e=this.boardBgImgFolder+"piece_bg_"+this.skin+"_"+this.squareSize+"_d.png";var d=this.colorLightSquares;var a=b;for(var g=1;g<=64;g++){var c=dojo.create("div",null,this.divBoard);dojo.style(c,{styleFloat:"left",width:this.squareSize+"px",height:this.squareSize+"px",backgroundColor:d,backgroundImage:"url('"+a+"')"});var f=(g+Math.floor(g/8))%2;if(f==0){d=this.colorLightSquares;a=b}else{d=this.colorDarkSquares;a=e}}return false},__createIndicators:function(){this.divIndicators.premove.from=dojo.create("div",null,this.divBoard);dojo.style(this.divIndicators.premove.from,{position:"absolute",border:"3px solid #4591CA",zIndex:this.divBoard_zindex});this.divIndicators.premove.to=dojo.create("div",null,this.divBoard);dojo.style(this.divIndicators.premove.to,{position:"absolute",border:"3px solid #4591CA",zIndex:this.divBoard_zindex});this.divIndicators.premove.sq2=dojo.create("div",null,this.divBoard);dojo.style(this.divIndicators.premove.sq2,{display:"none",position:"absolute",border:"3px solid #4591CA",backgroundColor:this.premove_sq_color,zIndex:this.divBoard_zindex});this.divIndicators.lastmove.from=dojo.create("div",null,this.divBoard);dojo.style(this.divIndicators.lastmove.from,{position:"absolute",border:"3px solid #FF3333",zIndex:this.divBoard_zindex});this.divIndicators.lastmove.to=dojo.create("div",null,this.divBoard);dojo.style(this.divIndicators.lastmove.to,{position:"absolute",border:"3px solid #FF3333",zIndex:this.divBoard_zindex});return false},__element_to_board_center:function(b,c){var a=0;var d=0;a=Math.floor((this.squareSize*8-b)/2);if(a<0){a=0}if(d<0){d=0}d=Math.floor((this.squareSize*8-c)/2);return{x:a,y:d}},__show_promo_div:function(b){this.in_promotion=true;if(this.promoDiv){dojo.destroy(this.promoDiv)}var f=new Array("q","r","n","b");var k=4;var h=4*this.squareSize+5*k;var c=this.squareSize+2*k;var a=this.__element_to_board_center(h,c);this.promoDiv=dojo.create("div",null,this.divBoard);dojo.style(this.promoDiv,{position:"absolute",left:a.x+"px",top:a.y+"px",width:h+"px",height:c+"px",border:"3px solid #000000",backgroundColor:"#CCFFCC",zIndex:this.divBoard_zindex+2});var j=k;var g=k;for(var e in f){var l=dojo.create("div",null,this.promoDiv);l.style.position="absolute";l.style.width=this.squareSize+"px";l.style.height=this.squareSize+"px";l.style.left=j+"px";l.style.top=g+"px";j=j+this.squareSize+k;var d=dojo.create("img",null,l);d.src=this.imageFolder+this.chessSet+this.squareSize+b.color+f[e]+".png";l.setAttribute("color",b.color);l.setAttribute("to",f[e]);l.setAttribute("sq1",b.sq1);l.setAttribute("sq2",b.sq2);this.board_handles.push(dojo.connect(l,"onclick",this,"__promotion_click"));this.board_handles.push(dojo.connect(l,"onmouseover",function(m){this.style.backgroundColor="#FFFFFF";this.style.border="1px solid #FF0000";return false}));this.board_handles.push(dojo.connect(l,"onmouseout",function(m){this.style.background="none";this.style.border="0px";return false}))}return false},__promotion_click:function(b){b=b||window.event;var a=b.currentTarget;this.do_promotion({sq1:a.getAttribute("sq1"),sq2:a.getAttribute("sq2"),color:a.getAttribute("color"),to:a.getAttribute("to")});return false},__hide_premove_indicators:function(){this.divIndicators.premove.from.style.display="none";this.divIndicators.premove.to.style.display="none";return false},__hide_lastmove_indicators:function(){this.divIndicators.lastmove.from.style.display="none";this.divIndicators.lastmove.to.style.display="none";return false},__createBoardDiv:function(a){if(this.boardOuter){dojo.destroy(this.boardOuter);this.boardOuter=null}this.boardOuter=dojo.create("div",null,this.parentRef);dojo.style(this.boardOuter,{position:"relative",width:(this.squareSize*8+this.parentRef_paddingLeft+3)+"px",height:Math.floor(this.squareSize*8+this.parentRef_paddingTop-5)+"px",padding:"0px"});this.boardFrame=dojo.create("div",null,this.boardOuter);dojo.style(this.boardFrame,{position:"absolute",top:"0px",right:"0px"});var b="";if(this.skin=="marble"){b=this.marble_color}else{b="#ffeac8"}this.divBoard=dojo.create("div",null,this.boardFrame);dojo.style(this.divBoard,{width:(this.squareSize*8)+"px",height:(this.squareSize*8)+"px",position:"relative",border:"2px solid "+b,left:"0px",top:"0px",zIndex:this.divBoard_zindex});if(this.boardLabels){this.__addBoardLabels(this.boardOuter)}this.__createSquares();this.__createIndicators();this.__hide_premove_indicators();this.__hide_lastmove_indicators()},__getBoardPosByCol:function(b){var c=0;while(b>=8){c++;b-=8}var a=new Object();if(this.flipBoard){b=7-b;c=7-c}a.x=b*this.squareSize;a.y=c*this.squareSize;return a},__getNotationByBoardPos:function(a,e){var c="abcdefgh";var b=Math.floor(a/this.squareSize);var d=8-Math.floor(e/this.squareSize);if(this.flipBoard){b=7-b;d=9-d}b=c.charAt(b);return b+d},__getBoardPosByNotation:function(e){var d="abcdefgh";e=e.replace(/[^0-9a-h]/g,"");var f=e.replace(/[^0-9]/gi,"")/1;var c=e.replace(/[0-9]/gi,"");var a=d.indexOf(c)+1;a--;f=8-f;if(this.flipBoard){a=7-a;f=7-f}var b=new Object();b.x=a*this.squareSize;b.y=f*this.squareSize;return b},__loadFen:function(a){var f=a.fen||"";var j=a.premove_piece||null;var k=f.split(/\s/g);var e=k[0];this.piece_hash=null;this.piece_hash={};var d=0;for(var m=0;m<e.length;m++){var g="";var h=e.substr(m,1);if(h.match(/[A-Z]/i)){if(h.match(/[A-Z]/)){g="w"}if(h.match(/[a-z]/)){g="b"}var c=h.toLowerCase();var b=this.__get_square_by_col(d);var l=this.__getBoardPosByCol(d);if(j&&j.sq==b&&j.color==g&&j.name==c){this.piece_hash[b]=j}else{this.__load_piece({pos:l,sq:b,color:g,name:c})}d++}if(h.match(/[0-8]/)){d+=h/1}}return false},__is_my_color:function(a){a=(a=="w"||a=="white")?"w":"b";if((a=="w"&&this.game.white_id==Vegas.client.id)||(a=="b"&&this.game.black_id==Vegas.client.id)){return true}return false},__is_my_game:function(){if(Vegas.client.id>0&&(this.game.white_id==Vegas.client.id||this.game.black_id==Vegas.client.id)){return true}return false},__load_piece:function(c){var b=dojo.create("div",null,this.divBoard);dojo.style(b,{position:"absolute",width:this.squareSize+"px",height:this.squareSize+"px",left:c.pos.x+"px",top:c.pos.y+"px",zIndex:this.divBoard_zindex+1});b.setAttribute("sq",c.sq);var a=dojo.create("img",null,b);var d=c.color+c.name;a.src=Vegas.img.game.piece[this.chessSet][this.squareSize][d].src;if(this.needcorrectPNG){Vegas.f.correctPng(a,this.squareSize,this.squareSize)}this.piece_hash[c.sq]={color:c.color,name:c.name,el:b};if(this.can_init_board_events){if(this.gameMode=="game"){if(this.game.winner_id==null&&this.__is_my_color(c.color)){this.__add_piece_event(b,this.hitch_click_func,this.hitch_pdrag_func)}}else{if(this.gameMode=="analiz"){this.__add_piece_event(b,this.hitch_click_func,this.hitch_pdrag_func)}else{}}}return false},__add_piece_event:function(d,b,a){var c=this.DND.createSimpleGroup(d);c.setThreshold(1);c.register("draginit",function(e){a.set_piece_dragging(true);return false});c.register("dragend",function(e){a.set_piece_dragging(false);b.board_click(e.group);return false});return false},__set_piece_dragging:function(a){this.pieceDragging=a},__indicateSquare:function(g,e,b){if(!this.divIndicators.premove.from.parentNode){this.__createIndicators()}var f=this.divIndicators[e][b];var a=parseInt(dojo.style(f,"borderWidth"))||3;var c=this.squareSize-(a*2);var d=this.__getBoardPosByNotation(g);dojo.style(f,{left:d.x+"px",top:d.y+"px",width:c+"px",height:c+"px"});if(e=="lastmove"&&b=="to"&&this.fadeInLastMove){dojo.style(f,{display:"block",opacity:"0"});dojo.fadeIn({node:f,duration:500}).play()}else{dojo.style(f,"display","block")}},__indicateLastMove:function(b,a){this.__indicateSquare(b,"lastmove","from");this.__indicateSquare(a,"lastmove","to")},__get_board_coords:function(){return dojo.position(this.divBoard,true)},__get_square_by_col:function(a){var c="abcdefgh";var d=1;while(a>=8){d++;a-=8}d=9-d;var b=c.substr(a,1);sq=b+d;return sq},__remove_piece_from_board:function(a){dojo.destroy(this.piece_hash[a].el);delete this.piece_hash[a]},__move_piece:function(b,a){if(b!=a){this.piece_hash[a]=this.piece_hash[b];delete this.piece_hash[b]}if(this.piece_hash[a]){var c=this.__getBoardPosByNotation(a);this.piece_hash[a].el.style.left=c.x+"px";this.piece_hash[a].el.style.top=c.y+"px";if(this.gameMode=="analiz"){this.piece_hash[a].el.setAttribute("sq",a)}}return false},__do_game_move:function(){if(this.gameMode=="game"){return true}if(this.gameMode=="analiz"){this.__rebuild_captured();return false}return false},do_promotion:function(a){if(this.promoDiv){dojo.destroy(this.promoDiv)}if(this.piece_hash[a.sq2]){this.__remove_piece_from_board(a.sq2)}var b=(a.to||"q").toLowerCase();this.__load_piece({pos:this.__getBoardPosByNotation(a.sq2),sq:a.sq2,color:a.color,name:b});this.in_promotion=false;if(this.__do_game_move()){this.make_move({sq1:a.sq1,sq2:a.sq2,promote_to:b})}return false},__do_move:function(h,g){var f=this.piece_hash[h].name;var j=this.piece_hash[h].color;if(f=="p"){var l=h.substr(0,1);var e=h.substr(1,1)/1;var k=g.substr(0,1);var d=g.substr(1,1)/1;var a=k+e;var c=false;var b=false;if(j=="w"&&e==5&&d==6&&l!=k&&!this.piece_hash[g]&&this.piece_hash[a]&&this.piece_hash[a].name=="p"&&this.piece_hash[a].color!=j){c=true;this.__remove_piece_from_board(a);this.__move_piece(h,g);if(this.__do_game_move()){this.make_move({sq1:h,sq2:g})}return false}if(j=="b"&&e==4&&d==3&&l!=k&&!this.piece_hash[g]&&this.piece_hash[a]&&this.piece_hash[a].name=="p"&&this.piece_hash[a].color!=j){c=true;this.__remove_piece_from_board(a);this.__move_piece(h,g);if(this.__do_game_move()){this.make_move({sq1:h,sq2:g})}return false}if((j=="w"&&e==7&&d==8)||(j=="b"&&e==2&&d==1)){b=true;if(this.piece_hash[g]){this.__remove_piece_from_board(g)}this.__move_piece(h,g);if(this.gameMode=="game"&&this.Widget.autoqueen.checked){this.do_promotion({sq1:h,sq2:g,to:"q",color:j});return false}else{this.__show_promo_div({sq1:h,sq2:g,color:j});return false}return false}if(!c&&!b&&this.piece_hash[g]){this.__remove_piece_from_board(g)}this.__move_piece(h,g);if(this.__do_game_move()){this.make_move({sq1:h,sq2:g})}return false}if(f=="k"){if(h=="e1"&&g=="g1"&&j=="w"&&this.piece_hash.h1&&this.piece_hash.h1.name=="r"&&this.piece_hash.h1.color=="w"){this.__move_piece("e1","g1");this.__move_piece("h1","f1");if(this.__do_game_move()){this.make_move({sq1:h,sq2:g})}return false}if(h=="e1"&&g=="c1"&&j=="w"&&this.piece_hash.a1&&this.piece_hash.a1.name=="r"&&this.piece_hash.a1.color=="w"){this.__move_piece("e1","c1");this.__move_piece("a1","d1");if(this.__do_game_move()){this.make_move({sq1:h,sq2:g})}return false}if(h=="e8"&&g=="g8"&&j=="b"&&this.piece_hash.h8&&this.piece_hash.h8.name=="r"&&this.piece_hash.h8.color=="b"){this.__move_piece("e8","g8");this.__move_piece("h8","f8");if(this.__do_game_move()){this.make_move({sq1:h,sq2:g})}return false}if(h=="e8"&&g=="c8"&&j=="b"&&this.piece_hash.a8&&this.piece_hash.a8.name=="r"&&this.piece_hash.a8.color=="b"){this.__move_piece("e8","c8");this.__move_piece("a8","d8");if(this.__do_game_move()){this.make_move({sq1:h,sq2:g})}return false}}if(this.piece_hash[g]){this.__remove_piece_from_board(g)}this.__move_piece(h,g);if(this.__do_game_move()){this.make_move({sq1:h,sq2:g})}return false},__board_click:function(g){if(this.in_promotion){return false}if(this.gameMode=="game"){if(this.game.white_id==0||this.game.black_id==0||this.game.winner_id!=null||!realtime.connected||!this.game.my){return false}}var b=null;var j=null;var h=this.__get_board_coords();var k={x:-1,y:-1};if(g.target){if(g.button&&g.button==dojo.mouseButtons.RIGHT){return false}j=Vegas.f.get_mouse_coords(g);k={x:j.x-h.x,y:j.y-h.y}}else{b=g.element||g.node;k={x:Math.floor(parseInt(b.style.left)+this.squareSize/2),y:Math.floor(parseInt(b.style.top)+this.squareSize/2)}}if(k.x<0||k.y<0||k.x>8*this.squareSize||k.y>8*this.squareSize){if(this.clicked_sq1){this.__move_piece(this.clicked_sq1,this.clicked_sq1)}return false}var c=this.__getNotationByBoardPos(k.x,k.y);var l=this.piece_hash[c]||null;if(this.premove_sq1||this.premove_sq2){this.__cancel_premove()}var d=(this.gameMode=="game"&&!this.__is_my_color(this.game.playertomove))?true:false;if(this.clicked_sq1){if(this.making_move){this.__move_piece(this.clicked_sq1,this.clicked_sq1);this.clicked_sq1=null;this.clicked_sq2=null;this.__hide_premove_indicators();return false}if(this.clicked_sq1==c){this.__move_piece(c,c);if(d){this.premove_sq1=c}return false}if(this.clicked_sq2){if(this.gameMode=="game"){return false}this.clicked_sq1=null;this.clicked_sq2=null;if(this.pieceDragging){this.__board_click(g)}return false}else{if(l&&l.name=="k"){if(d&&!this.__is_my_color(l.color)){}else{this.__move_piece(this.clicked_sq1,this.clicked_sq1);this.__hide_premove_indicators();if(d){this.__cancel_premove()}this.clicked_sq1=null;this.clicked_sq2=null;return false}}if(l&&l.color==this.piece_hash[this.clicked_sq1].color){if(d){this.__move_piece(this.clicked_sq1,this.clicked_sq1);this.clicked_sq2=c;this.__do_premove({sq1:this.clicked_sq1,sq2:this.clicked_sq2});return false}else{this.__move_piece(this.clicked_sq1,this.clicked_sq1);this.clicked_sq1=c;this.__indicateSquare(c,"premove","from");return false}}this.clicked_sq2=c;this.__indicateSquare(c,"premove","to");if(d){this.__do_premove({sq1:this.clicked_sq1,sq2:this.clicked_sq2});return false}this.__do_move(this.clicked_sq1,this.clicked_sq2);return false}}else{if(this.gameMode=="game"){if(!l||(l&&!this.__is_my_color(l.color))){this.__hide_premove_indicators();if(b&&!j){var f=b.getAttribute("sq");if(!f){return false}this.clicked_sq1=f;if(d){this.__indicateSquare(this.clicked_sq1,"premove","from")}this.__board_click(g);return false}else{return false}}if(d){if(b&&!j&&l&&this.__is_my_color(l.color)){var a=b.getAttribute("sq");if(a!=c){c=a}this.__move_piece(a,a)}this.premove_sq1=c;this.__hide_premove_indicators();this.__hide_lastmove_indicators()}}if(this.gameMode=="analiz"){if(!l){return false}this.__hide_premove_indicators();this.__hide_lastmove_indicators()}this.clicked_sq1=c;this.__indicateSquare(c,"premove","from");return false}return false},flip:function(){if(this.isBusy){return false}if(this.flipBoard){this.flipBoard=false}else{this.flipBoard=true}this.build_board();if(this.show_timer&&this.TimerPos=="updown"){this.flip_timer()}return false},get_board_zindex:function(){return this.divBoard_zindex},disconnect_handles:function(){this.__disconnect_board_handles();this.__disconnect_premove_handles();this.__disconnect_notation_handles();if(this.handles.length>0){for(var a in this.handles){dojo.disconnect(this.handles[a]);delete this.handles[a]}}return false},__disconnect_board_handles:function(){if(this.board_handles.length>0){for(var a in this.board_handles){dojo.disconnect(this.board_handles[a]);delete this.board_handles[a]}}return false},__disconnect_premove_handles:function(){if(this.premove_handles.length>0){for(var a in this.premove_handles){dojo.disconnect(this.premove_handles[a]);delete this.premove_handles[a]}}return false},__disconnect_notation_handles:function(){if(this.notation_handles.length>0){for(var a in this.notation_handles){dojo.disconnect(this.notation_handles[a]);delete this.notation_handles[a]}}return false},__add_captured_img:function(c){var b=this.captured_size;var d=c.color+c.name;var a=dojo.create("img",null,c.el,"last");a.src=Vegas.img.game.piece[this.chessSet][b][d].src;if(this.needcorrectPNG){Vegas.f.correctPng(a,b,b)}return false},build_captured:function(b){var o=b.str||null;if(this.Captured.div&&o&&o.length&&this.Captured.captured==o){return false}if(!this.Captured.div){this.Captured.div=dojo.create("div",null,this.GameContentDiv);dojo.style(this.Captured.div,{position:"absolute",width:this.boardContainer_width+"px",top:2*this.TimerDiv_height+this.boardContainer_height+"px",left:"0px"});var s=dojo.create("table",{cols:5,cellspacing:"0"},this.Captured.div);var l=dojo.create("tbody",null,s);var n=dojo.create("tr",null,l);var j=dojo.create("td",{colspan:"5"},n);j.innerHTML="<b>"+Vegas.f.phrase(85)+"</b>";var m=dojo.create("tr",null,l);var g=dojo.create("td",null,m);var f=dojo.create("td",null,m);var e=dojo.create("td",null,m);var d=dojo.create("td",null,m);var c=dojo.create("td",null,m);g.innerHTML=Vegas.f.phrase(80);f.innerHTML=Vegas.f.phrase(81);e.innerHTML=Vegas.f.phrase(82);d.innerHTML=Vegas.f.phrase(83);c.innerHTML=Vegas.f.phrase(84);var k=dojo.create("tr",null,l);this.Captured.wptd=dojo.create("td",null,k);this.Captured.wbtd=dojo.create("td",null,k);this.Captured.wntd=dojo.create("td",null,k);this.Captured.wrtd=dojo.create("td",null,k);this.Captured.wqtd=dojo.create("td",null,k);var h=dojo.create("tr",null,l);this.Captured.bptd=dojo.create("td",null,h);this.Captured.bbtd=dojo.create("td",null,h);this.Captured.bntd=dojo.create("td",null,h);this.Captured.brtd=dojo.create("td",null,h);this.Captured.bqtd=dojo.create("td",null,h);var q=new dojo.NodeList(g,f,e,d,c);dojo.forEach(q,function(r){dojo.style(r,{padding:"2px",height:"25px",border:"1px solid #799D81",textAlign:"center",verticalAlign:"middle"});return false});this.Captured.NodeList=new dojo.NodeList(this.Captured.wptd,this.Captured.wbtd,this.Captured.wntd,this.Captured.wrtd,this.Captured.wqtd,this.Captured.bptd,this.Captured.bbtd,this.Captured.bntd,this.Captured.brtd,this.Captured.bqtd);dojo.forEach(this.Captured.NodeList,function(r){dojo.style(r,{height:"30px",border:"1px solid #799D81"});return false})}if(!o||!o.length){return false}this.Captured.captured=o;dojo.forEach(this.Captured.NodeList,dojo.empty);for(var p=0;p<o.length;p++){var a=o.substr(p,1);if(a=="P"){this.__add_captured_img({el:this.Captured.wptd,color:"w",name:"p"})}else{if(a=="B"){this.__add_captured_img({el:this.Captured.wbtd,color:"w",name:"b"})}else{if(a=="N"){this.__add_captured_img({el:this.Captured.wntd,color:"w",name:"n"})}else{if(a=="R"){this.__add_captured_img({el:this.Captured.wrtd,color:"w",name:"r"})}else{if(a=="Q"){this.__add_captured_img({el:this.Captured.wqtd,color:"w",name:"q"})}else{if(a=="p"){this.__add_captured_img({el:this.Captured.bptd,color:"b",name:"p"})}else{if(a=="b"){this.__add_captured_img({el:this.Captured.bbtd,color:"b",name:"b"})}else{if(a=="n"){this.__add_captured_img({el:this.Captured.bntd,color:"b",name:"n"})}else{if(a=="r"){this.__add_captured_img({el:this.Captured.brtd,color:"b",name:"r"})}else{if(a=="q"){this.__add_captured_img({el:this.Captured.bqtd,color:"b",name:"q"})}else{continue}}}}}}}}}}}return false},__show_chess_warn:function(c){var d=c.san||"";var b=c.chess_warn||"";var a="#000000";var e="";if(b&&b.length){if(b=="checkmate"){e=Vegas.f.phrase(28);a="#FF0000"}else{if(b=="check"){e=Vegas.f.phrase(29);a="#0000FF"}else{if(b=="stalemate"){e=Vegas.f.phrase(30);a="#000000"}else{e="";a="#000000"}}}}else{if(d.match(/\#/)){e=Vegas.f.phrase(28);a="#FF0000"}else{if(d.match(/\+/)){e=Vegas.f.phrase(29);a="#0000FF"}else{e="";a="#000000"}}}return false},build_notation:function(s){if(!s){s={}}var d=s.movenum;var p=s.lastmoved;var c=s.type||"pgn";if(!d){return false}if(!this.game.hist[1]){return false}if(!this.move_history_topic){this.move_history_topic=dojo.create("div",{style:{overflow:"hidden"}},this.Widget.notationTab.containerNode,"last");var k=dojo.create("button",null,this.move_history_topic,"last");var j=dojo.create("button",null,this.move_history_topic,"last");var g=dojo.create("button",null,this.move_history_topic,"last");var f=dojo.create("button",null,this.move_history_topic,"last");var u={show_start_position:dojo.hitch(this,"show_start_position")};var t={show_last_position:dojo.hitch(this,"show_last_position")};var l={step_position:dojo.hitch(this,"step_position")};var q=new dijit.form.Button({label:"&lt;&lt;",onClick:function(){u.show_start_position();return false}},k);var o=new dijit.form.Button({label:"&lt;",onClick:function(){l.step_position(-1);return false}},j);var n=new dijit.form.Button({label:"&gt;",onClick:function(){l.step_position(1);return false}},g);var m=new dijit.form.Button({label:"&gt;&gt;",onClick:function(){t.show_last_position();return false}},f)}if(!this.move_history_obj){this.move_history_obj=dojo.create("div",null,this.Widget.notationTab.containerNode,"last");var a=this.TabContainer_h-80;dojo.style(this.move_history_obj,{padding:"4px",overflowX:"hidden",overflowY:"auto",whiteSpace:"normal",lineHeight:"150%",fontStyle:"italic",fontSize:"120%",fontFamily:'sans-serif, "Trebuchet MS", Verdana, Arial, Helvetica',color:"#003300",height:a+"px",backgroundColor:"#F8F8F8",border:"1px solid #799D81"});if(dojo.isOpera){Vegas.f.preventSelection(this.move_history_obj)}else{Vegas.f.make_unselectable(this.move_history_obj)}}this.__disconnect_notation_handles();dojo.empty(this.move_history_obj);this.move_history_nodes={};for(var b=1;b<=d;b++){var h="";var e=(c=="pgn")?this.game.hist[b].w.san:this.game.hist[b].w.sq;var v=(c=="pgn")?(this.game.hist[b].b.san||""):(this.game.hist[b].b.sq||"");dojo.create("span",{innerHTML:b+".",style:"font-weight: bold;"},this.move_history_obj,"last");this.move_history_nodes["wmove"+b]=dojo.create("a",null,this.move_history_obj,"last");dojo.attr(this.move_history_nodes["wmove"+b],{innerHTML:e,href:"#",style:"margin-left: 2px;",movenum:b,movecolor:"w"});this.notation_handles.push(dojo.connect(this.move_history_nodes["wmove"+b],"onclick",this,"__notation_move_click"));this.move_history_nodes["bmove"+b]=dojo.create("a",null,this.move_history_obj,"last");dojo.attr(this.move_history_nodes["bmove"+b],{innerHTML:v+" ",href:"#",style:"margin-left: 5px; margin-right: 5px;",movenum:b,movecolor:"b"});this.notation_handles.push(dojo.connect(this.move_history_nodes["bmove"+b],"onclick",this,"__notation_move_click"))}return false},__notation_move_click:function(d){var c=d.target;var b=parseInt(dojo.attr(c,"movenum"));var a=dojo.attr(c,"movecolor");this.show_position({movenum:b,color:a});return false},__highlight_notation_move:function(e){if(!this.notationEnabled){return false}if(!e){e={}}var b=e.color||"w";var a=e.movenum||0;if(a<0){a=0}var f=(b=="w")?"wmove"+a:"bmove"+a;var d=this.move_history_nodes[f]||null;if(this.notation_handles.length>0){for(var c in this.move_history_nodes){dojo.style(this.move_history_nodes[c],{backgroundColor:"transparent"})}}if(!d){return false}dojo.style(d,{backgroundColor:"#CCCCCC"});return false},__init_board_events:function(){this.board_handles.push(dojo.connect(this.divBoard,"onmousedown",this,"__board_click"));this.board_handles.push(dojo.connect(this.divBoard,"onmouseup",function(a){if(a.button==dojo.mouseButtons.RIGHT){return false}return false}));return false},show_start_position:function(){if(this.isBusy){return false}this.show_position({movenum:0,color:"w"});return false},show_last_position:function(){if(this.isBusy){return false}this.show_position({movenum:this.game.movenum,color:this.game.lastmoved});return false},step_position:function(b){if(this.isBusy){return false}if(b==0){b=1}var a=(this.notation_lastmoved=="w")?"b":"w";if(b>0){if(this.notation_lastmoved=="b"){this.notation_movenum=this.notation_movenum+1}}else{if(this.notation_lastmoved=="w"){this.notation_movenum=this.notation_movenum-1}}if(this.notation_movenum>this.game.movenum){this.notation_movenum=this.game.movenum;a=this.game.lastmoved}this.show_position({movenum:this.notation_movenum,color:a});return false},show_position:function(e){if(!e){e={}}var c=e.color||"w";var b=e.movenum||0;if(b<0){b=0}if(b>0){if(!this.game.hist[b]){return false}if(!this.game.hist[b][c]){c=(c=="w")?"b":"w";if(!this.game.hist[b][c]){return false}}if(!this.game.hist[b][c].fen){return false}if(b>this.game.movenum){b=this.game.movenum;c=this.game.lastmoved}}var a="";var d="no";var f="";if(b==0){a=this.startFEN;this.notation_lastmoved="b"}else{a=this.game.hist[b][c].fen;this.notation_lastmoved=c;d=this.game.hist[b][c].sq;f=this.game.hist[b][c].san}this.notation_movenum=b;this.build_board({fen:a,lastmove:d,san:f});this.__show_timer_at_move({movenum:b,color:c});this.__rebuild_captured();this.__highlight_notation_move({movenum:b,color:c});return false},__rebuild_captured:function(){this.Captured.captured="";var a=this.__get_captured();if(this.Captured.NodeList){dojo.forEach(this.Captured.NodeList,dojo.empty)}this.build_captured({str:a});return false},__get_captured:function(){var g="";var b={};b.w={p:0,b:0,n:0,r:0,q:0,k:0};b.b={p:0,b:0,n:0,r:0,q:0,k:0};var f={};f.w={p:0,b:0,n:0,r:0,q:0,k:0};f.b={p:0,b:0,n:0,r:0,q:0,k:0};for(var e in this.piece_hash){b[this.piece_hash[e].color][this.piece_hash[e].name]+=1}for(var a in b){f[a].p=8-b[a].p;f[a].b=2-b[a].b;if(f[a].b<0){f[a].b=0}f[a].n=2-b[a].n;if(f[a].n<0){f[a].n=0}f[a].r=2-b[a].r;if(f[a].r<0){f[a].r=0}f[a].q=1-b[a].q;if(f[a].q<0){f[a].q=0}}for(var a in f){for(var d in f[a]){if(f[a][d]<1){continue}for(var c=1;c<=f[a][d];c++){g+=(a=="w")?d.toUpperCase():d}}}return g},build_board:function(a){if(!a){a={}}this.isBusy=true;this.clicked_sq1=null;this.clicked_sq2=null;var c=a.fen||this.game.fen;var k=a.lastmove||this.game.lastmove||null;var b=a.playertomove||this.game.playertomove;b=(b=="black"||b=="b")?"b":"w";captured=a.captured||this.game.captured||null;var e=a.san||this.game.sanmove||"";var h=a.chess_warn||this.game.chess_warn||"";this.chess_warn="";var j=a.premove_piece||null;if(this.boardOuter){this.__disconnect_board_handles();this.__disconnect_premove_handles();dojo.destroy(this.boardOuter);this.boardOuter=null}this.__createBoardDiv();this.__loadFen({fen:c,premove_piece:j});if(k&&k.length>0&&k!="no"){var d=k.split("-");var g=d[0];var f=d[1];this.__indicateLastMove(g,f)}this.build_captured({str:captured});if(this.can_init_board_events){this.__init_board_events()}this.isBusy=false},get_move:function(){return{sq1:this.clicked_sq1,sq2:this.clicked_sq2}},make_move:function(b){if(this.making_move){return false}this.making_move=true;if(!b){return false}var c=b.promote_to||"q";this.clicked_sq1=null;this.clicked_sq2=null;this.stop_timer();var a="";if(this.Widget.draw&&this.Widget.draw.checked){a=Vegas.client.id}else{a=-Vegas.client.id}this.show_game_state({state:"update"});if(this.game.timeout){return false}realtime.send_move_to_server({cmd:"checkmove",client_id:Vegas.client.id,board_id:this.game.id,sq1:b.sq1,sq2:b.sq2,promote_to:c,draw_flag:a,cidkey:Vegas.client.cidkey,expsec:this.game.expsec,lang:Vegas.client.lang});return false},__do_premove:function(b){this.__cancel_premove();this.premove_sq1=b.sq1;this.premove_sq2=b.sq2;this.__move_piece(b.sq1,b.sq1);this.clicked_sq1=null;this.clicked_sq2=null;dojo.style(this.divIndicators.premove.to,{display:"none"});this.__indicateSquare(b.sq2,"premove","sq2");var a=this.divIndicators.premove.sq2;var d=dojo.fadeIn({node:a,beforeBegin:function(e){dojo.style(e,{opacity:0})}});var c=dojo.fadeOut({node:a,beforeBegin:function(e){dojo.style(e,{opacity:1})}});this.premove_handles.push(dojo.connect(d,"onEnd",function(){c.play()}));this.premove_handles.push(dojo.connect(c,"onEnd",function(){d.play()}));c.play();return false},__cancel_premove:function(){this.premove_sq1=null;this.premove_sq2=null;this.__disconnect_premove_handles();if(this.divIndicators.premove.sq2){dojo.style(this.divIndicators.premove.sq2,{display:"none"})}return false},init_timer:function(){if(this.gameMode=="game"){if(this.game.white_id==0||this.game.black_id==0){return false}}else{return false}if(this.TimerPos=="updown"){if(this.flipBoard){this.white_timer=this.UpTimerDiv;this.black_timer=this.DownTimerDiv}else{this.white_timer=this.DownTimerDiv;this.black_timer=this.UpTimerDiv}}if(this.TimerPos=="right"){this.white_timer=dojo.byId("whitetimernode");this.black_timer=dojo.byId("blacktimernode");dojo.style(this.white_timer,{fontSize:this.TimerFontSize,fontFamily:"Arial"});dojo.style(this.black_timer,{fontSize:this.TimerFontSize,fontFamily:"Arial"})}if(this.gameMode=="game"){if(this.game.winner_id==null){this.switch_timer({wsec:this.game.white_expired_sec,bsec:this.game.black_expired_sec});this.start_timer()}else{this.__show_timer_at_move({movenum:this.game.movenum,color:this.game.lastmoved})}}return false},switch_timer:function(c){this.switching_timer=true;var b=c.wsec;var a=c.bsec;var d=c.flip||false;white_expired_dhms=this.timer_time(b);black_expired_dhms=this.timer_time(a);this.white_timer.innerHTML=white_expired_dhms;this.black_timer.innerHTML=black_expired_dhms;if(this.game.playertomove=="w"){this.game.expsec=b;this.timer=this.white_timer;this.stopped_timer=this.black_timer}else{this.game.expsec=a;this.timer=this.black_timer;this.stopped_timer=this.white_timer}dojo.style(this.stopped_timer,{fontWeight:"normal",color:this.TimerFontColor});dojo.style(this.timer,{fontWeight:"bold",color:(this.game.expsec<=this.DeadlineTime)?this.DeadlineTimeColor:this.CountdownTimerFontColor});this.switching_timer=false;return false},__show_timer_at_move:function(b){if(this.gameMode!="game"||this.game.winner_id==null){return false}var h="---";var c=b.movenum||0;var g=b.color||"w";var k;var m;var a;var n=null;var l=null;var f={cur:{},prev:{}};if(g=="w"){k="b";m=c-1;a=this.white_timer;prev_timer=this.black_timer}else{k="w";m=c;a=this.black_timer;prev_timer=this.white_timer}if(m<0){m=0}if(c<=1){c=1;m=1}if(this.game.hist[c]){if(this.game.hist[c][g]){n=this.game.hist[c][g].t}}if(this.game.hist[m]){if(this.game.hist[m][k]){l=this.game.hist[m][k].t}}f.cur={color:g,timer:a,t:n};f.prev={color:k,timer:prev_timer,t:l};if(this.game.tcontrol=="m"){f.prev.t=this.game.tlimit}for(var d in f){if(c==1&&f[d].t==null){f[d].t=this.game.tlimit}if(f[d].t==null){f[d].timer.innerHTML=h}else{var j=f[d].t;if(j<0&&this.game.tcontrol=="m"){var l=j;var e=this.game.hist[c-1];if(e&&e[f[d].color]&&e[f[d].color].t){l=e[f[d].color].t}j=this.game.tlimit-Math.abs(l-j)}f[d].timer.innerHTML=this.timer_time(dojo.number.round(j,1))}}return false},flip_timer:function(){if(this.flipBoard){this.white_timer=this.UpTimerDiv;this.black_timer=this.DownTimerDiv}else{this.white_timer=this.DownTimerDiv;this.black_timer=this.UpTimerDiv}if(this.game.playertomove=="w"){this.switch_timer({wsec:this.game.expsec,bsec:this.game.black_expired_sec,flip:true})}else{this.switch_timer({wsec:this.game.white_expired_sec,bsec:this.game.expsec,flip:true})}return false},timer_time:function(l){l=l+"";var h=l.split(".");var k=h[0]||0;var e=h[1]||0;var m=Math.floor(k/86400);var j=Math.floor((k-(m*86400))/3600);var b=Math.floor((k-(m*86400)-(j*3600))/60);var c=Math.floor((k-(m*86400)-(j*3600)-(b*60)));var f=(Vegas.client.lang=="en")?"d. ":"д. ";var g="";if(m){g+=m+f}if(b<10){b="0"+b}if(c<10){c="0"+c}if(j||this.game.tlimit>=3600){g+=(j<10)?"0"+j+":":j+":"}g+=b+":"+c;if(k<this.tenth_start_seconds){g+="."+e}return g},show_player_time:function(){if(this.switching_timer){return false}var a=this.__is_my_color(this.game.lastmoved)?false:true;if(this.game.tour_id>0&&this.game.tcontrol=="g"&&Vegas.config.tour_nowait_opponent&&this.game.tlimit>Vegas.config.tour_wait_maxtime&&this.game.tlimit<901&&this.game.expsec<(this.game.tlimit-Vegas.config.tour_wait_maxtime)){if(this.game.movenum<this.game.startmovenum||(this.game.movenum==this.game.startmovenum&&this.game.playertomove=="b")){this.game.expsec=0}}if(this.game.expsec<=0){this.game.expsec=0;this.timer.innerHTML=this.timer_time(0);this.game.timeout=true;this.stop_timer();this.stop_repeat_move();if(this.game.my&&!a&&this.clicked_sq1&&this.clicked_sq1){this.build_board()}if(this.game.my){realtime.send_sig_to_control_channel({cmd:"checkexpired",client_id:Vegas.client.id,board_id:this.game.id,cidkey:Vegas.client.cidkey,lang:Vegas.client.lang})}this.show_game_state({state:"update"});var b=this.game.link;setTimeout(function(){Vegas.f.load_url({url:b});Vegas.f.myconfirm({type:"ok",msg:Vegas.f.phrase(14)})},2000);return false}this.game.expsec=dojo.number.round(this.game.expsec-this.timer_increment,1);var c=this.timer_time(this.game.expsec);this.timer.innerHTML=c;if(this.game.expsec<=this.DeadlineTime){dojo.style(this.timer,{color:this.DeadlineTimeColor})}if(Vegas.client.VIP&&this.game.my&&this.soundEnabled&&a){if(this.warntime1>0&&this.game.expsec==this.warntime1+1){Vegas.f.play_chess_sound("timewarn")}if(this.warntime2>0&&this.warntime1!=this.warntime2&&this.game.expsec==this.warntime2+1){Vegas.f.play_chess_sound("timewarn")}}return false},start_timer:function(){if(!Vegas.timer.player_timer){Vegas.timer.player_timer={}}if(Vegas.timer.player_timer.running){return false}Vegas.timer.player_timer.running=true;Vegas.timer.player_timer.func=null;var a={show_player_time:dojo.hitch(this,"show_player_time")};Vegas.timer.player_timer.func=window.setInterval(function(){a.show_player_time()},this.timer_interval);return false},stop_timer:function(){if(!Vegas.timer.player_timer){Vegas.timer.player_timer={}}if(Vegas.timer.player_timer.running){Vegas.timer.player_timer.running=false;window.clearInterval(Vegas.timer.player_timer.func);Vegas.timer.player_timer.func=null}return false},get_movedata:function(){return{cmd:"move",board_id:this.game.id,client_id:Vegas.client.id,winner_id:"",moveseq:this.game.moveseq,movenum:this.game.movenum,move:this.game.lastmove,fen:this.game.fen,san_move:this.game.sanmove,captured:this.game.captured,chess_warn:this.game.chess_warn,result_draw_flag:this.game.draw_flag,white_expired_sec:this.game.white_expired_sec,black_expired_sec:this.game.black_expired_sec}},process_move:function(v){var g=v.error||null;var s=parseInt(v.errcode);var t=parseInt(v.client_id);var f=false;if(g&&t!=Vegas.client.id){return false}if(g){this.making_move=false;g=Vegas.utf8.decode(g);if(s==8){this.show_game_state({state:"error",txt:g});if(this.soundEnabled){Vegas.f.play_chess_sound("error")}return false}if(s==15){this.show_game_state({state:"error",txt:g});if(this.soundEnabled){Vegas.f.play_chess_sound("error")}return false}if(s==6){this.stop_timer();Vegas.f.myconfirm({type:"ok",msg:g,url:this.game.link});return false}this.start_timer();this.build_board();this.show_game_state({state:"error",txt:g});if(this.soundEnabled){Vegas.f.play_chess_sound("error")}return false}var w=isNaN(parseInt(v.winner_id))?null:parseInt(v.winner_id);if(w!=null&&w>=0){f=true;Vegas.game.winner_id=w}var n=v.aborted||false;if(n){this.stop_timer();var h="";if(this.game.my&&t!=Vegas.client.id){h=Vegas.f.phrase(59)}else{h=Vegas.f.phrase(60)}Vegas.f.myconfirm({msg:h,url:Vegas.mainURL,type:"ok"});return false}var q=v.resigned||false;if(q){var h="";if(w==Vegas.client.id){h=Vegas.f.phrase(22)}else{if(w!=Vegas.client.id&&this.game.my){h=Vegas.f.phrase(23)}else{if(w==this.game.white_id){h=Vegas.f.phrase(25)}else{if(w==this.game.black_id){h=Vegas.f.phrase(24)}else{h=Vegas.f.phrase(26)}}}}Vegas.f.load_url({url:this.game.link});Vegas.f.myconfirm({type:"ok",msg:h});return false;Vegas.f.myconfirm({type:"ok",msg:h,url:this.game.link});this.stop_timer();this.stop_repeat_move();return false}var k=v.draw||false;if(k){f=true;Vegas.game.winner_id=0;Vegas.f.load_url({url:this.game.link});Vegas.f.myconfirm({type:"ok",msg:Vegas.f.phrase(27)});return false;Vegas.f.myconfirm({type:"ok",msg:Vegas.f.phrase(27),url:this.game.link});this.stop_timer();this.stop_repeat_move();return false}var m=parseInt(v.moveseq);if(m==1&&(this.game.white_id==0||this.game.black_id==0)){Vegas.f.load_url({url:this.game.link});return false}if(m==this.game.moveseq){return false}if(m<this.game.moveseq){if(this.game.my&&this.__is_my_color(this.game.lastmoved)){this.repeat_move()}return false}this.making_move=false;this.game.moveseq=m;this.game.playertomove=(m==0||(m>0&&m%2==0))?"w":"b";this.game.lastmoved=(this.game.playertomove=="b")?"w":"b";var o=v.move;var j=parseInt(v.movenum);this.game.movenum=j;var l=v.fen;var u=v.san_move;this.game.lastmove=o;this.game.fen=l;this.game.sanmove=u;var p=v.captured||"";var d=v.chess_warn||"";this.game.chess_warn=d;var e=parseInt(v.result_draw_flag);this.game.draw_flag=e;this.game.white_expired_sec=parseFloat(v.white_expired_sec);this.game.black_expired_sec=parseFloat(v.black_expired_sec);if(!f){this.switch_timer({wsec:this.game.white_expired_sec,bsec:this.game.black_expired_sec});this.start_timer()}if(this.game.tour_id==0&&this.game.my&&j==Vegas.config.max_movenum_to_abort+1){if(this.Widget.abort){this.Widget.abort.destroy();delete this.Widget.abort}}if(this.game.my&&this.Widget.resign){if(this.__is_my_color(this.game.playertomove)){this.Widget.resign.set("disabled",false)}else{this.Widget.resign.set("disabled",true)}}if(p.length>0&&p!=this.game.captured){this.game.captured=p}if(!this.game.hist[j]){this.game.hist[j]={};this.game.hist[j].w={};this.game.hist[j].b={}}this.game.hist[j][this.game.lastmoved]={sq:o,san:u,fen:l};var b=null;if(!f&&this.premove_sq1&&!this.premove_sq2&&this.__is_my_color(this.game.playertomove)&&this.piece_hash[this.premove_sq1]){b=this.piece_hash[this.premove_sq1];b.sq=this.premove_sq1;dojo.place(b.el,this.boardContainer,"last")}this.build_board({premove_piece:b});if(b){if(!this.piece_hash[b.sq]||this.piece_hash[b.sq].color!=b.color||this.piece_hash[b.sq].name!=b.name){dojo.destroy(b.el);b=null}else{dojo.place(b.el,this.divBoard,"last");this.clicked_sq1=b.sq;this.__indicateSquare(b.sq,"premove","from")}}var r=(Vegas.client.VIP&&(d=="check"||d=="checkmate"))?"check":"move";if(f){var h="";if(w==0){h=Vegas.f.phrase(27)}else{if(w&&w==Vegas.client.id){h=Vegas.f.phrase(31)}else{if(w&&w!=Vegas.client.id&&this.game.my){h=Vegas.f.phrase(32)}else{h=Vegas.f.phrase(26)}}}if(d=="checkmate"){if(this.soundEnabled){Vegas.f.play_chess_sound(r)}}Vegas.f.load_url({url:this.game.link});Vegas.f.myconfirm({type:"ok",msg:h});return false;Vegas.f.myconfirm({type:"ok",msg:h,url:this.game.link});this.stop_timer();this.stop_repeat_move();return false}this.game.movedata={};this.game.movedata=this.get_movedata();this.show_game_state({state:"move",draw_flag:e});this.process_draw_info(e);if(this.notationEnabled){this.build_notation({movenum:this.game.movenum})}if(u.indexOf("x")>0&&r=="move"){r="capture"}if(this.soundEnabled){Vegas.f.play_chess_sound(r)}if(!f&&this.premove_sq1&&this.premove_sq2&&this.__is_my_color(this.game.playertomove)){var c=this.premove_sq1;var a=this.premove_sq2;this.__cancel_premove();this.__do_move(c,a)}this.stop_repeat_move();if(this.game.my&&this.__is_my_color(this.game.lastmoved)){this.start_repeat_move()}return false},show_game_state:function(d){if(!this.WhosturnDiv){return false}if(!d){d={}}var e=d.state||"";var b=d.draw_flag||0;var a="";var g="";var c=false;var f="#000000";if(b==this.game.white_id){c=true;g=Vegas.f.phrase(17)}else{if(b==-this.game.white_id){c=true;g=Vegas.f.phrase(18)}else{if(b==this.game.black_id){c=true;g=Vegas.f.phrase(19)}else{if(b==-this.game.black_id){c=true;g=Vegas.f.phrase(20)}else{text=""}}}}if(this.game.my&&b>0&&b!=Vegas.client.id){g+='&nbsp;<a href="#" onclick="Vegas.f.accept_draw(); return false;"><b>'+Vegas.f.phrase(21)+"&gt;&gt;&gt;</b></a>"}if(!this.gameStateImg){dojo.empty(this.WhosturnDiv);this.gameStateImg=dojo.create("img",null,this.WhosturnDiv,"last");dojo.style(this.gameStateImg,{verticalAlign:"middle",paddingRight:"2px"})}if(e=="update"){this.gameStateImg.src=Vegas.img.game.state.update.src;a=Vegas.f.phrase(8)}else{if(e=="error"){this.gameStateImg.src=Vegas.img.game.state.error.src;a=d.txt||"Error!"}else{if(this.game.my){if(this.__is_my_color(this.game.lastmoved)){this.gameStateImg.src=Vegas.img.game.state.clock.src;a=Vegas.f.phrase(2)}else{if(c){this.gameStateImg.src=Vegas.img.game.state.draw.src;a=g;f="#FF0000"}else{this.gameStateImg.src=Vegas.img.game.state.mymove.src;a=Vegas.f.phrase(3)}}}else{if(c){this.gameStateImg.src=Vegas.img.game.state.draw.src;a=g}else{if(this.game.lastmoved=="w"){this.gameStateImg.src=Vegas.img.game.state.clock.src;a=Vegas.f.phrase(16)}else{this.gameStateImg.src=Vegas.img.game.state.clock.src;a=Vegas.f.phrase(15)}}}}}if(!this.gameStateInfo){this.gameStateInfo=dojo.create("span",null,this.WhosturnDiv,"last");dojo.style(this.gameStateInfo,{fontWeight:"bold"})}this.gameStateInfo.innerHTML=a;dojo.style(this.gameStateInfo,"color",f);return false},process_draw_info:function(a){if(this.game.my){this.Widget.draw.set("checked",false)}return false},repeat_move:function(){if(!realtime.connected||this.making_move||this.switching_timer){return false}if(this.game.moveseq>0&&this.game.my&&this.__is_my_color(this.game.lastmoved)){realtime.send_move_to_board_channel(this.game.movedata)}return false},start_repeat_move:function(){if(!Vegas.timer.repeat_move){Vegas.timer.repeat_move={}}if(Vegas.timer.repeat_move.running){return false}Vegas.timer.repeat_move.running=true;Vegas.timer.repeat_move.func=null;var b={repeat_move:dojo.hitch(this,"repeat_move")};var a=(this.game.tlimit<15)?5033:10033;Vegas.timer.repeat_move.func=window.setInterval(function(){b.repeat_move()},a);return false},stop_repeat_move:function(){if(!Vegas.timer.repeat_move){Vegas.timer.repeat_move={}}if(Vegas.timer.repeat_move.running){Vegas.timer.repeat_move.running=false;window.clearInterval(Vegas.timer.repeat_move.func);Vegas.timer.repeat_move.func=null}return false},__clear_chat:function(){this.ChatDiv.innerHTML="";return false},__enable_chat:function(a){if(typeof(a)!="undefined"){this.chatEnabled=a}else{this.chatEnabled=this.chatEnabled?false:true}if(this.chatEnabled){this.Widget.EnableChat.set({label:Vegas.f.phrase(124),iconClass:"dijitEditorIcon dijitEditorIconCancel"});this.Widget.ChatTextBox.set("disabled",false);this.Widget.ChatSend.set("disabled",false);dojo.style(this.ChatDiv,{backgroundColor:"#FFFFFF"})}else{this.Widget.EnableChat.set({label:Vegas.f.phrase(123),iconClass:"dijitIconApplication"});this.Widget.ChatTextBox.set("disabled",true);this.Widget.ChatSend.set("disabled",true);dojo.style(this.ChatDiv,{backgroundColor:"#CCCCCC"})}return false},__send_chat_msg:function(){var a=this.Widget.ChatTextBox.get("value");if(!a.length){return false}realtime.send_chat_msg(a);this.Widget.ChatTextBox.set("value","");return false},process_chat_msg:function(e,a,c){if(!this.Widget.chatTab){return false}if(!this.chatEnabled){return false}c=Vegas.f.to_html(Vegas.utf8.decode(c));var d=Vegas.utf8.decode(a);if(e==this.last_chat_id){d="..."}else{this.last_chat_id=e;d+=":"}var b=[];b[0]=this.ChatDiv.innerHTML||"";b.push('<span style="font-weight: bold;">');b.push(d);b.push("&nbsp;</span>");b.push(c);b.push("<br/>");this.ChatDiv.innerHTML=b.join("");this.ChatDiv.scrollTop=9999;if(e!=Vegas.client.id){this.Widget.TabContainer.selectChild(this.Widget.chatTab);if(this.soundEnabled){Vegas.f.play_chess_sound("message")}}return false},setSquareSize:function(a){if(this.squareSize==a){return false}this.squareSize=a;this.__preload_pieces({set:this.chessSet,size:this.squareSize});this.set_board_sizes();this.__style_parentRef();this.__style_BoardInfoDiv();this.__style_parentTabDiv();this.__style_childTabDiv();this.Widget.TabContainer.resize(null,{w:this.TabContainer_w-1,h:this.TabContainer_h-1});dojo.destroy(this.Captured.div);this.Captured.div=null;this.Captured.captured="";this.build_board();return false},setChessSet:function(a){if(this.chessSet==a){return false}this.chessSet=a;this.__preload_pieces({set:this.chessSet,size:this.squareSize});this.Captured.captured="";this.build_board();return false},__isVIPchessSet:function(b){for(var a in this.ChessSetHash){if(this.ChessSetHash[a].value==b&&this.ChessSetHash[a].vip){return true}else{continue}}return false},__getAvailableChessSet:function(a){var b="alpha";if(!a||!a.length){return b}if(Vegas.client.VIP){return a}if(this.__isVIPchessSet(a)){return b}return a},setBoardSkin:function(a){if(this.skin==a){return false}this.skin=a;dojo.style(this.parentRef,{backgroundImage:"url("+this.boardBgImgFolder+"board_bg_"+this.skin+"_"+this.squareSize+".jpg)",backgroundRepeat:"no-repeat"});this.build_board();return false},saveBoardSettings:function(){if(!Vegas.client.VIP&&this.__isVIPchessSet(this.chessSet)){Vegas.f.vip_warn({code:"chessset"});return false}Vegas.client.settings.chessboard.squareSize=this.squareSize;Vegas.client.settings.chessboard.chessSet=this.chessSet;Vegas.client.settings.chessboard.boardSkin=this.skin;var a=360;dojo.cookie("chessboard",dojo.toJson(Vegas.client.settings.chessboard),{expires:a,domain:document.location.host,path:"/"});return false},__set_board_settings_content:function(){var h=5;var l=dojo.create("div",null,this.Widget.BoardSettingsTab.containerNode);dojo.style(l,{marginBottom:h+"px"});l.innerHTML="";l.innerHTML+="<b>"+Vegas.f.phrase(98)+":</b><br/>";var m=[];var f=[];var g={setChessSet:dojo.hitch(this,"setChessSet")};for(var k in this.ChessSetHash){m[k]=dojo.create("button",null,l,"last");f[k]=new dijit.form.Button({label:this.ChessSetHash[k].name,value:this.ChessSetHash[k].value,onClick:function(){g.setChessSet(this.value);return false}},m[k])}var e=dojo.create("div",null,this.Widget.BoardSettingsTab.containerNode);dojo.style(e,{marginBottom:h+"px"});e.innerHTML="";e.innerHTML+="<b>"+Vegas.f.phrase(99)+":</b><br/>";var j=[];var a=[];var n={setSquareSize:dojo.hitch(this,"setSquareSize")};for(var k in this.SquareSizeHash){j[k]=dojo.create("button",null,e,"last");a[k]=new dijit.form.Button({label:this.SquareSizeHash[k].name,value:this.SquareSizeHash[k].value,onClick:function(){n.setSquareSize(this.value);return false}},j[k])}var b=dojo.create("div",null,this.Widget.BoardSettingsTab.containerNode);dojo.style(b,{marginBottom:h+"px"});b.innerHTML="";b.innerHTML+="<b>"+Vegas.f.phrase(100)+":</b><br/>";var d=[];var c=[];var o={setBoardSkin:dojo.hitch(this,"setBoardSkin")};for(var k in this.SkinHash){d[k]=dojo.create("button",null,b,"last");c[k]=new dijit.form.Button({label:this.SkinHash[k].name,value:this.SkinHash[k].value,onClick:function(){o.setBoardSkin(this.value);return false}},d[k])}return false},setSound:function(a){this.soundEnabled=a;return false},isSoundEnabled:function(){return this.soundEnabled},__preload_pieces:function(a){var h=a.set;var j=a.size;var b=["w","b"];var f=["p","b","n","r","q","k"];if(!Vegas.img.game.piece[h]){Vegas.img.game.piece[h]={}}if(!Vegas.img.game.piece[h][j]){Vegas.img.game.piece[h][j]={}}for(var e in b){var d=b[e];for(var c in f){name=f[c];var g=d+name;if(Vegas.img.game.piece[h][j][g]){continue}Vegas.img.game.piece[h][j][g]=new Image();Vegas.img.game.piece[h][j][g].src=this.imageFolder+h+j+g+".png"}}return false},__dummyFunc:function(){return false}};Vegas.w={1:{ru:"Нотация",en:"Notation"},2:{ru:"Ход соперника",en:"Opponent to move"},3:{ru:"Ваш ход",en:"You are to move"},4:{ru:"Подключиться к игре?",en:"Join game?"},5:{ru:"Дата/время",en:"Date/time"},6:{ru:"Нет отмеченных сообщений!",en:"No marked messages!"},7:{ru:"Удалить выбранные сообщения?",en:"Delete marked messages?"},8:{ru:"Обновление партии",en:"Updating game"},9:{ru:"Признаете поражение в этой партии?",en:"Resign game?"},10:{ru:"В этой партии больше нет ходов!",en:"No more moves in this game!"},11:{ru:"Ошибка передачи хода!",en:"Error occurs while transfering the move!"},12:{ru:"Аннулировать партию?",en:"Cancel game?"},13:{ru:"Ожидание ответа...",en:"Waiting for response..."},14:{ru:"Время хода истекло!",en:"Time is out!"},15:{ru:"Ход белых",en:"White to move"},16:{ru:"Ход черных",en:"Black to move"},17:{ru:"Белые предлагают ничью.",en:"White has offered a draw."},18:{ru:"Белые отклонили ничью.",en:"White has declined the draw."},19:{ru:"Черные предлагают ничью.",en:"Black has offered a draw."},20:{ru:"Черные отклонили ничью.",en:"Black has declined the draw."},21:{ru:"Принять",en:"Accept"},22:{ru:"Соперник сдался. Поздравляем с победой!",en:"The opponent has resigned. Congratulations!"},23:{ru:"Игра завершена. Удачи в следующих партиях!",en:"Game is over. Good luck in your next games!"},24:{ru:"Белые сдались.",en:"White resigned."},25:{ru:"Черные сдались.",en:"Black resigned."},26:{ru:"Игра завершена!",en:"Game is over!"},27:{ru:"Игра завершена. Ничья.",en:"Game is over. Draw."},28:{ru:"Мат!",en:"Checkmate!"},29:{ru:"Шах!",en:"Check!"},30:{ru:"Пат!",en:"Stalemate!"},31:{ru:"Игра завершена. Победа!",en:"Game is over. Victory!"},32:{ru:"Игра завершена. Поражение.",en:"You have lost the game."},33:{ru:"Название партии",en:"Game name"},34:{ru:"Соперник",en:"Opponent"},35:{ru:"Отклик",en:"Response"},36:{ru:"сек.",en:"sec."},37:{ru:"Новые сообщения",en:"New messages"},38:{ru:"Внимание! Нет соединения с сервером! Переподключение...",en:"Connection lost. Trying to reconnect..."},39:{ru:"Внимание! В ближайшее время сайт будет недоступен в течение нескольких минут. Администрация.",en:"Attention! The site will be unavailable within the next few minutes. Administration."},40:{ru:"Белые",en:"White"},41:{ru:"Черные",en:"Black"},42:{ru:"Просмотр",en:"View"},43:{ru:"Подключение",en:"Join game"},44:{ru:"рейтинг",en:"raiting"},45:{ru:"Контроль времени",en:"Time control"},46:{ru:"Лимит времени",en:"Time limit"},47:{ru:"Подключиться к игре",en:"Join game"},48:{ru:"На рейтинг",en:"Rated"},49:{ru:"Без рейтинга",en:"Unrated"},50:{ru:"Ваши фигуры",en:"Your pieces"},51:{ru:"Игрок на сайте",en:"Player is on-line"},52:{ru:"Играет в блиц",en:"Playing blitz"},53:{ru:"Играет в PDA-версии",en:"Playing PDA-version"},54:{ru:"Игрок вне сайта",en:"Player is out of site"},55:{ru:"Время на партию",en:"Time per game"},56:{ru:"Время на ход",en:"Time per move"},57:{ru:"Оборвать партию",en:"Abort game"},58:{ru:"Партию уже оборвать нельзя!",en:"You cannot abort game now!"},59:{ru:"Соперник оборвал партию",en:"Opponent has aborted the game"},60:{ru:"Игра оборвана",en:"Game aborted"},61:{ru:"Вызов отклонен. По этой причине партия аннулирована.",en:"The challenge has been declined. Game canceled."},62:{ru:"Ваш браузер не поддерживает технологию нашего сайта!\n\nРекомендуемые браузеры:\n- Opera 9.63+ ( www.opera.ru );\n- Firefox 3.0.5+ ( www.mozilla.ru ).",en:"Your browser is not supported!\n\nBrowsers recommended:\n- Opera 9.63+ ( www.opera.com );\n- Firefox 3.0.5+ ( www.mozilla.com )."},63:{ru:"Учет рейтинга",en:"Rating control"},64:{ru:"Открыт турнир",en:"Tournament open"},65:{ru:"Действие",en:"Action"},66:{ru:"Отклонить",en:"Reject"},67:{ru:"отклонил вызов",en:"has rejected your challenge"},68:{ru:"Соперник аннулировал свой вызов",en:"Opponent has canceled his challenge"},69:{ru:"Вам вызов",en:"You have been challenged"},70:{ru:"Да",en:"Yes"},71:{ru:"Нет",en:"No"},72:{ru:"Загрузка данных...",en:"Loading data..."},73:{ru:"Скрыть",en:"Hide"},74:{ru:"Сообщения",en:"Messages"},75:{ru:"Прямая ссылка на страницу",en:"Direct link to this page"},76:{ru:"Внимание! Этот игрок использует шахматную программу!",en:"Warning! This player uses chess engine!"},77:{ru:"Макс. лаг",en:"Max. lag"},78:{ru:"Номер партии",en:"Game ID"},79:{ru:"Анализ позиции",en:"Analyze position"},80:{ru:"Пешки",en:"Pawns"},81:{ru:"Слоны",en:"Bishops"},82:{ru:"Кони",en:"Knights"},83:{ru:"Ладьи",en:"Rooks"},84:{ru:"Ферзи",en:"Queens"},85:{ru:"Потери соперников",en:"Captured pieces"},86:{ru:"Игра со звуком",en:"Play sound"},87:{ru:"Авто-Ферзь",en:"Auto-Queen"},88:{ru:"Сдаться",en:"Resign"},89:{ru:"Предложить ничью",en:"Offer draw"},90:{ru:"Проверить связь",en:"Check connection"},91:{ru:"PGN-формат",en:"PGN format"},92:{ru:"Соперники",en:"Opponents"},93:{ru:"Чат",en:"Chat"},94:{ru:"Отправить",en:"Send"},95:{ru:"Параметры",en:"Parameters"},96:{ru:"Повернуть доску",en:"Flip board"},97:{ru:"Настройки",en:"Settings"},98:{ru:"Фигуры",en:"Pieces"},99:{ru:"Размер клетки",en:"Square size"},100:{ru:"Стиль доски",en:"Board skin"},101:{ru:"Бук",en:"Beech"},102:{ru:"Махагон",en:"Mahagoni"},103:{ru:"Орех",en:"Walnut"},104:{ru:"Мрамор",en:"Marble"},105:{ru:"Дерево 1",en:"Wood 1"},106:{ru:"Дерево 2",en:"Wood 2"},107:{ru:"Дерево 3",en:"Wood 3"},108:{ru:"Дерево 4",en:"Wood 4"},109:{ru:"Эбонит",en:"Ebonite"},110:{ru:"Настроить доску",en:"Customize board"},111:{ru:"Сохранить настройки",en:"Save settings"},112:{ru:"Дерево 5",en:"Wood 5"},113:{ru:"Настоятельно рекомендуем отключить Firebug!",en:"It is highly recommended to turn off Firebug!"},114:{ru:"Опции",en:"Options"},115:{ru:"<b>Устанавливается соединение с сервером...</b><br/>Кликните на мигающую картинку, чтобы посмотреть требования.<br/>Как только соединение будет установлено, эта картинка исчезнет.",en:"<b>Connecting to server, please wait...</b><br/>Click on the blinking image to read requirements.<br/> The image disappears as soon as the connection is established."},116:{ru:"<b>Соединение с сервером потеряно. Выполняется переподключение...</b><br/>Попробуйте обновить страницу, если соединение не устанавливается в течение 10 секунд.",en:"<b>Connection to server is lost. Trying to reconnect...</b><br/>Try to refresh this page if the connection is not established during 10 seconds."},117:{ru:"Готовность 1 минута!",en:"Get ready within 1 minute!"},118:{ru:"Турнир аннулирован.",en:"Tournament cancelled."},119:{ru:"Причина не известна.",en:"Reason unknown."},120:{ru:"Мало игроков.",en:"Few players."},121:{ru:"Турнир завершен",en:"Tournament finished"},122:{ru:"Очистить окно чата",en:"Clear chat window"},123:{ru:"Включить чат",en:"Enable chat"},124:{ru:"Отключить чат",en:"Disable chat"},125:{ru:"Звуковой модуль не загружен!<br/>Возможно, какая-то программа блокирует swf-файлы.",en:"Could not load sound module!<br/>Are swf files blocked by another program?"},126:{ru:"Необходимо выбрать способ оплаты.",en:"Type of payment is required.<br/>Please choose."},127:{ru:"Пожалуйста, выберите за что Вы хотите заплатить.",en:"Please choose what do you want to pay for."},128:{ru:"Эта возможность доступна только для VIP-игроков.",en:"Only a VIP member has access to this feature."},129:{ru:"Узнать больше о VIP-статусе?",en:"Do you want to learn more?"},130:{ru:"Честная игра",en:"Fair Play"},131:{ru:"Играть адванс",en:"Play Advanced Chess"},132:{ru:"Этот набор фигур доступен только VIP-игрокам.",en:"This chess set is available for VIP members only."},133:{ru:"Не заполнены необходимые поля!",en:"Please check the fields required!"},134:{ru:"вошел в чат",en:"has joined"},135:{ru:"вышел из чата",en:"has left"},136:{ru:"Система",en:"System"},137:{ru:"Только VIP-игроки могут посылать больше одного сообщения в 20 секунд.",en:"Only a VIP member can send more than 1 message per 20 seconds."},138:{ru:"Подождите",en:"Wait"},139:{ru:"Некоторые Ваши данные не изменились.<br/>Обновите страницу кнопкой браузера.",en:"Some data has not been changed.<br/>Refresh the page with browser button."},140:{ru:"Выигрыш",en:"Win"},141:{ru:"Ничья",en:"Draw"},142:{ru:"Проигрыш",en:"Loss"},143:{ru:"Вегасы",en:"Vegases"},144:{ru:"У Вас недостаточно Вегасов",en:"Sorry, you need more Vegases for this"},145:{ru:"Выберите параметр для обмена",en:"Please choose option for exchange"},146:{ru:"Поделиться партией",en:"Share game"},147:{ru:"Поделитесь с друзьями",en:"Share with friends"},148:{ru:"Вы уже авторизованы на сайте",en:"You are already logged in"},9999:{ru:"",en:""}};Vegas.utf8={_utf8_encode:function(b){b=b.replace(/ /g," ");var a="";for(var e=0;e<b.length;e++){var d=b.charCodeAt(e);if(d<128){a+=String.fromCharCode(d)}else{if((d>127)&&(d<2048)){a+=String.fromCharCode((d>>6)|192);a+=String.fromCharCode((d&63)|128)}else{a+=String.fromCharCode((d>>12)|224);a+=String.fromCharCode(((d>>6)&63)|128);a+=String.fromCharCode((d&63)|128)}}}return a},_utf8_decode:function(a){var b="";var e=0;var g=0;var f=0;var d=0;while(e<a.length){g=a.charCodeAt(e);if(g<128){b+=String.fromCharCode(g);e++}else{if((g>191)&&(g<224)){d=a.charCodeAt(e+1);b+=String.fromCharCode(((g&31)<<6)|(d&63));e+=2}else{d=a.charCodeAt(e+1);c3=a.charCodeAt(e+2);b+=String.fromCharCode(((g&15)<<12)|((d&63)<<6)|(c3&63));e+=3}}}return b},encode:function(a){return escape(this._utf8_encode(a))},decode:function(a){return this._utf8_decode(unescape(a))}};Vegas.sound_hash={move:{file:"move.mp3"},capture:{file:"capture.mp3"},check:{file:"check.mp3"},mate:{file:"mate.mp3"},error:{file:"error.mp3"},newgame:{file:"newgame.mp3"},challenge:{file:"challenge.mp3"},timewarn:{file:"timewarn.mp3"},message:{file:"message.mp3"},gamelistplus:{file:"gamelistplus.mp3"},sysmsg:{file:"sysmsg.mp3"}};Vegas.f.is_sound_enabled=function(){if(Vegas.game&&Vegas.game.id&&Vegas.game.id>0&&Vegas.Chess&&Vegas.Chess[Vegas.game.id]&&Vegas.Chess[Vegas.game.id]["game"]){return Vegas.Chess[Vegas.game.id]["game"].isSoundEnabled()}return Vegas.client.sound_on};Vegas.f.init_chessboard=function(){var b="game";var a=Vegas.game.id;if(!Vegas.Chess){Vegas.Chess={}}if(!Vegas.Chess[a]){Vegas.Chess[a]={}}if(Vegas.Chess[a][b]){Vegas.Chess[a][b].destroy();Vegas.Chess[a][b]=null}Vegas.Chess[a][b]=new ChessboardInterface({gameMode:"game",MainNode:"content",GameContentDiv:"gamecontent",gameHash:Vegas.game,boardLabels:true});return false};Vegas.f.custom_board=function(){var b="custom";var a=0;if(!Vegas.Chess){Vegas.Chess={}}if(!Vegas.Chess[a]){Vegas.Chess[a]={}}if(Vegas.Chess[a][b]){Vegas.Chess[a][b].destroy();Vegas.Chess[a][b]=null}Vegas.Chess[a][b]=new ChessboardInterface({gameMode:b,MainNode:"content",GameContentDiv:"gamecontent",gameHash:Vegas.game,boardLabels:true});return false};Vegas.f.common_func=function(){if(Vegas.f.static_object("vegasbal")){Vegas.f.static_object("vegasbal").innerHTML=Vegas.client.Vegases}return false};Vegas.f.analyze_position=function(){var c="analiz";var b=Vegas.game.id;var a=dojo.create("div",null,dojo.body());dojo.style(a,{position:"absolute",margin:"20px",left:"0px",top:"0px"});if(!Vegas.Chess){Vegas.Chess={}}if(!Vegas.Chess[b]){Vegas.Chess[b]={}}if(Vegas.Chess[b][c]){Vegas.Chess[b][c].destroy();Vegas.Chess[b][c]=null}Vegas.Chess[b][c]=new ChessboardInterface({gameMode:c,MainNode:a,GameContentDiv:null,gameHash:Vegas.game,boardLabels:true});return false};Vegas.f.show_opening=function(d){var e="opening";var a=Vegas.game.id;title=d.title||"";var c=dojo.create("div",null,dojo.body(),"last");dojo.style(c,{display:"block",textAlign:"center",height:"30px",verticalAlign:"middle",color:"#0000FF",fontSize:"16px",fontWeight:"bold"});c.innerHTML=title;var b=dojo.create("div",null,dojo.body(),"last");dojo.style(b,{position:"absolute",margin:"20px",left:"0px",top:"30px"});if(!Vegas.Chess){Vegas.Chess={}}if(!Vegas.Chess[a]){Vegas.Chess[a]={}}if(Vegas.Chess[a][e]){Vegas.Chess[a][e].destroy();Vegas.Chess[a][e]=null}Vegas.Chess[a][e]=new ChessboardInterface({gameMode:e,MainNode:b,GameContentDiv:null,gameHash:Vegas.game,boardLabels:true});return false};Vegas.f.init_sounds=function(){soundManager.onready(function(){for(var a in Vegas.sound_hash){soundManager.createSound({id:a,url:"/sound/chess/"+Vegas.client.sound_style+"/"+Vegas.sound_hash[a].file,multiShot:true,autoLoad:true})}Vegas.sound_ready=true;return false});soundManager.ontimeout(function(){Vegas.f.myconfirm({type:"ok",msg:Vegas.f.phrase(125)});return false});return false};Vegas.f.preload_images=function(){if(!document.images){return false}var b={mymove:"/img/mymove48.gif",opmove:"/img/opponent48.png",update:"/img/refresh48.png",draw:"/img/draw48.png",clock:"/img/hourglass48.png",error:"/img/gameerror48.png"};for(var a in b){Vegas.img.game.state[a]=new Image();Vegas.img.game.state[a].src=b[a]}return false};Vegas.f.correctPng=function(c,a,b){c.style.filter="progid:DXImageTransform.Microsoft.AlphaImageLoader(src='"+c.src+"', sizingMethod='scale')";c.src="/blank.gif";c.width=a;c.height=b};Vegas.f.play_chess_sound=function(a){if(!Vegas.sound_ready||typeof(a)=="undefined"||!a||!a.length||!Vegas.sound_hash[a]){return false}soundManager.play(a);return false};Vegas.f.get_cookie=function(a){if(!a||!a.cname||!a.cname.length||!a.ckey||!a.ckey.length){return""}var b=dojo.fromJson(dojo.cookie(a.cname));if(!b||typeof(b[a.ckey])=="undefined"){return""}return b[a.ckey]};Vegas.f.set_cookie=function(b){if(!b||!b.cname||!b.cname.length||!b.ckey||!b.ckey.length){return false}var a=b.days||360;var c=dojo.fromJson(dojo.cookie(b.cname));if(!c){c={}}c[b.ckey]=b.cval;dojo.cookie(b.cname,dojo.toJson(c),{expires:a,domain:document.location.host,path:"/"});return false};Vegas.f.get_browser=function(){var a="";var c=window.navigator.userAgent;var b="";if(c.indexOf("Opera")>=0){b="opera";a=c.substr(c.indexOf("Opera")+6,4)}else{if(c.indexOf("Firefox")>=0){b="ff";a=c.substr(c.indexOf("Firefox")+8,5)}else{if(c.indexOf("Safari")>=0&&c.indexOf("Chrome")==-1){b="safari";a=c.substr(c.indexOf("Version")+8,5)}else{if(c.indexOf("Chrome")>=0){b="chrome";a=c.substr(c.indexOf("Chrome")+7,10)}else{if(c.indexOf("MSIE")>=0){b="ie";a=c.substr(c.indexOf("MSIE")+5,3)}else{b=window.navigator.appName;a=""}}}}}return{name:b,version:a}};Vegas.f.is_supported_browser=function(){var b=Vegas.f.get_browser();var a=0;if(b.name=="opera"){a=parseFloat(b.version);if(a>=9.62){return true}else{return false}}else{if(b.name=="ff"){a=parseInt(b.version);if(a>=3){return true}else{return false}}else{if(b.name=="ie"){a=parseFloat(b.version);if(a>=6){return true}else{return false}}else{if(b.name=="safari"){return true}else{if(b.name=="chrome"){a=parseInt(b.version);if(a>=1){return true}else{return false}}else{return false}}}}}return false};Vegas.f.new_window=function(b){var a=window.open(b.url,"_blank");a.focus();return false};Vegas.f.phrase=function(a){return Vegas.w[a][Vegas.client.lang]};Vegas.f.static_object=function(a){if(Vegas.static_o[a]){return Vegas.static_o[a]}Vegas.static_o[a]=dojo.byId(a);if(Vegas.static_o[a]){return Vegas.static_o[a]}return null};Vegas.f.get_widget=function(a){return dijit.byId(a)};Vegas.f.get_mouse_coords=function(c){c=c||window.event;if(dojo.isIE){var b=document.documentElement;var a=document.body;c.pageX=c.clientX+(b&&b.scrollLeft||a&&a.scrollLeft||0)-(b.clientLeft||0);c.pageY=c.clientY+(b&&b.scrollTop||a&&a.scrollTop||0)-(b.clientTop||0)}return{x:c.pageX,y:c.pageY}};Vegas.f.myconfirm=function(r){var msg=r.msg||null;var url=r.url||null;var type=r.type||"yn";var func=r.func||null;if(!msg||!msg.length){return false}var text_only=msg.replace(/<.*?>/g,"");var div_id="myconfirm";var div=dojo.byId(div_id);if(!div){div=dojo.create("div",null,dojo.body());div.id=div_id;Vegas.o[div_id]=div}var w=400;var h=100;div.style.display="none";dojo.empty(div);dojo.style(div,{textAlign:"center",background:"#CCFFCC",border:"2px solid #000000",padding:"10px",width:w+"px",height:h+"px",overflow:(text_only.length>120)?"auto":"hidden",position:"absolute"});var msg_div=dojo.create("div",null,div);var btn_div=dojo.create("div",null,div);dojo.style(btn_div,{marginTop:"5px"});msg_div.innerHTML=msg;if(type=="yn"){if(url){var btn1=dojo.create("button",null,btn_div);var dijit_btn1=new dijit.form.Button({label:Vegas.f.phrase(70),onClick:function(){Vegas.f.load_url({url:url});return false}},btn1)}if(func){var btn2=dojo.create("button",null,btn_div);var dijit_btn2=new dijit.form.Button({label:Vegas.f.phrase(70),onClick:function(){dojo.eval(func);return false}},btn2)}var btn3=dojo.create("button",null,btn_div);var dijit_btn3=new dijit.form.Button({label:Vegas.f.phrase(71),onClick:function(){dojo.style(div,{display:"none"});return false}},btn3)}if(type=="ok"&&url){var btn1=dojo.create("button",null,btn_div);var dijit_btn1=new dijit.form.Button({label:"Ok",onClick:function(){Vegas.f.load_url({url:url});return false}},btn1)}if(type=="ok"&&!url){var btn1=dojo.create("button",null,btn_div);var dijit_btn1=new dijit.form.Button({label:"Ok",onClick:function(){dojo.style(div,{display:"none"});return false}},btn1)}Vegas.f.to_center(div);div.style.zIndex=1000000;div.style.display="";return false};Vegas.f.vip_warn=function(c){var b=c.code;var d=128;if(b=="chessset"){d=132}else{d=128}var e=Vegas.f.phrase(d)+"<br/>"+Vegas.f.phrase(129);var a=Vegas.script+"?cmd=about_vip";Vegas.f.myconfirm({msg:e,url:a});return false};Vegas.f.to_center=function(f){var a=dojo.window.getBox();var b=parseInt(f.style.width);var e=parseInt(f.style.height);var d=Math.floor((a.w-b)/2+a.l-10);var c=Math.floor(a.h/2-e+a.t-20);if(d<0){d=10}if(c<0){c=10}f.style.left=d+"px";f.style.top=c+"px";return false},Vegas.f.connect_to_board=function(b){var a=Vegas.script+"?cmd=join_board&board_id="+b;Vegas.f.load_url({url:a});return false};Vegas.f.change_div_display=function(c,a){var b=dojo.byId(c);if(!b){return false}b.style.display=a;return true};Vegas.f.show_hide_div=function(b,a){var c=dojo.byId(b);if(!c){return false}if(c.style.display=="none"){c.style.display=a}else{c.style.display="none"}return true};Vegas.f.delete_msg=function(l,d){var j=l.split(",");var h=new Array();var c=0;var k;for(var g in j){var e="msg_"+j[g];var f=dojo.byId(e);if(!f){continue}if(f.checked){c++;h[c-1]=j[g]}}if(!c){Vegas.f.myconfirm({type:"ok",msg:Vegas.f.phrase(6)});return false}k=h.join(",");Vegas.f.myconfirm({msg:Vegas.f.phrase(7),url:Vegas.script+"?cmd=delete_msg&msg_id="+k+"&folder="+d});return false};Vegas.f.set_msg_checked=function(a){var b=dojo.byId(a);if(!b){return false}b.checked=true;return true};Vegas.f.empty_msg_folder=function(e,d){var b=e.split(",");for(i in b){var c="msg_"+b[i];Vegas.f.set_msg_checked(c)}Vegas.f.delete_msg(e,d);return true};Vegas.f.set_td_background=function(c,a){var b=dojo.byId(c);if(b){b.style.background=a}return false};Vegas.f.show_pgn=function(b){var a=Vegas.script+"?cmd=show_pgn&board_id="+b+"&jstime="+(new Date()).getTime();window.open(a,"PGN","toolbar=no, location=no, directories=no, status=no, resizable=yes, scrollbars=yes, width=600, height=600, screenX=100, screenY=100, left=100, top=100");return true};Vegas.f.updating_game_html=function(){var a=[];a.push('<img border="0" align="absmiddle" src="/img/wait.gif"/>&nbsp;');a.push(Vegas.f.phrase(8));a.push("...");return a.join("")};Vegas.f.waiting_html=function(d){if(!d){d={}}var a=d.txt||"Waiting...";var b=d.src||"/img/wait6.gif";var c=[];c.push('<img border="0" align="absmiddle" src="');c.push(b);c.push('"/>&nbsp;');c.push(a);return c.join("")};Vegas.f.confirm_resign=function(a){if(!a){a={}}var b=a.yes||false;if(!b){Vegas.f.myconfirm({msg:Vegas.f.phrase(9),func:"Vegas.f.confirm_resign({yes:true})"});return false}Vegas.f.change_div_display("myconfirm","none");Vegas.Chess[Vegas.game.id]["game"].show_game_state({state:"update"});realtime.send_move_to_server({cmd:"checkmove",action:"resign",client_id:Vegas.client.id,board_id:Vegas.game.id,cidkey:Vegas.client.cidkey,lang:Vegas.client.lang});return false};Vegas.f.abort_game=function(a){if(!a){a={}}var b=a.yes||false;if(Vegas.game.movenum>Vegas.config.max_movenum_to_abort){Vegas.f.myconfirm({msg:Vegas.f.phrase(58),type:"ok"});return false}if(!b){Vegas.f.myconfirm({msg:Vegas.f.phrase(57),func:"Vegas.f.abort_game({yes:true})"});return false}Vegas.f.change_div_display("myconfirm","none");Vegas.Chess[Vegas.game.id]["game"].show_game_state({state:"update"});realtime.send_move_to_server({cmd:"checkmove",action:"abort",client_id:Vegas.client.id,board_id:Vegas.game.id,cidkey:Vegas.client.cidkey,lang:Vegas.client.lang});return false};Vegas.f.accept_draw=function(){Vegas.Chess[Vegas.game.id]["game"].show_game_state({state:"update"});realtime.send_move_to_server({cmd:"checkmove",action:"draw",draw_flag:Vegas.client.id,client_id:Vegas.client.id,board_id:Vegas.game.id,cidkey:Vegas.client.cidkey,lang:Vegas.client.lang})};Vegas.f.confirm_cancel_board=function(){Vegas.f.myconfirm({msg:Vegas.f.phrase(12),url:Vegas.script+"?cmd=cancel_board&board_id="+Vegas.game.id+"&confirm=1"});return false};Vegas.f.seconds_to_human_readable=function(g){var h=Math.floor(g/86400);var a=Math.floor((g-(h*86400))/3600);var c=Math.floor((g-(h*86400)-(a*3600))/60);var b=Math.floor((g-(h*86400)-(a*3600)-(c*60)));var f=(Vegas.client.lang=="en")?"d. ":"д. ";var e="";if(h){e+=h+f}if(a<10){a="0"+a}if(c<10){c="0"+c}if(b<10){b="0"+b}e+=a+":"+c+":"+b;return e};Vegas.f.tlimit_for_gamelist=function(f,n,o){var g=(Vegas.client.lang=="ru")?"сек":"sec";if(f=="g"&&n<60){return(n+g+"+"+o)}if(f=="m"&&n<60){return(n+g)}if(f=="g"&&n<3600){var c=parseInt(n/60);return(c+"+"+o)}var p=Math.floor(n/86400);var l=Math.floor((n-(p*86400))/3600);var b=Math.floor((n-(p*86400)-(l*3600))/60);var j=(Vegas.client.lang=="en")?"d. ":"д. ";var e=(Vegas.client.lang=="en")?"h. ":"ч. ";var a=(Vegas.client.lang=="en")?"min.":"мин.";var k="";if(p){k+=p+j}if(l){k+=l+e}if(b){k+=b+a}return k};Vegas.f.show_annulate_time=function(){var a=Vegas.game.expsec;if(a<=0){a=0}var b=Vegas.f.seconds_to_human_readable(a);Vegas.o.AnnulateTimerObject.innerHTML=b;if(a<=0){Vegas.timer.annulate_timer.running=false;window.clearInterval(Vegas.timer.annulate_timer.func);Vegas.timer.annulate_timer.func=null;realtime.send_sig_to_control_channel({cmd:"checkstandby",client_id:Vegas.client.id,board_id:Vegas.game.id,cidkey:Vegas.client.cidkey,lang:Vegas.client.lang});setTimeout(function(){Vegas.f.load_url({url:Vegas.mainURL})},2000);return false}if(a>0&&a%20==0&&realtime.connected&&Vegas.game.my){realtime.send_sig_to_control_channel({cmd:"isjoined",client_id:Vegas.client.id,board_id:Vegas.game.id,cidkey:Vegas.client.cidkey,lang:Vegas.client.lang})}Vegas.game.expsec=Vegas.game.expsec-1;return false};Vegas.f.show_tour_timer=function(){var a=Vegas.tour.expsec;if(a<=0){a=0}Vegas.o.TourTimerObject.innerHTML=(a>0)?Vegas.f.seconds_to_human_readable(a):Vegas.f.phrase(117);if(a<=0){Vegas.timer.tour_timer.running=false;window.clearInterval(Vegas.timer.tour_timer.func);Vegas.timer.tour_timer.func=null;return false}Vegas.tour.expsec=Vegas.tour.expsec-1;return false};Vegas.f.stop_timer_by_id=function(a){if(!Vegas.timer||!Vegas.timer[a]||!Vegas.timer[a].running){return false}Vegas.timer[a].running=false;window.clearInterval(Vegas.timer[a].func);Vegas.timer[a].func=null;return false};Vegas.f.stop_all_timers=function(){if(Vegas.timer){for(var a in Vegas.timer){Vegas.f.stop_timer_by_id(a)}}return false};Vegas.f.start_annulate_timer=function(a){Vegas.game.expsec=a;Vegas.o.AnnulateTimerObject=dojo.byId("AnnulateTimerSpan");if(!Vegas.timer.annulate_timer){Vegas.timer.annulate_timer={}}if(Vegas.timer.annulate_timer.running){return false}Vegas.timer.annulate_timer.running=true;Vegas.timer.annulate_timer.func=null;Vegas.timer.annulate_timer.func=window.setInterval(function(){Vegas.f.show_annulate_time()},1000);return false};Vegas.f.start_tour_timer=function(a){Vegas.tour.expsec=a;Vegas.o.TourTimerObject=null;Vegas.o.TourTimerObject=dojo.byId("tourtimernode");if(!Vegas.o.TourTimerObject){return false}if(!Vegas.timer.tour_timer){Vegas.timer.tour_timer={}}if(Vegas.timer.tour_timer.running){return false}Vegas.timer.tour_timer.running=true;Vegas.timer.tour_timer.func=null;Vegas.timer.tour_timer.func=window.setInterval(function(){Vegas.f.show_tour_timer()},1000)};Vegas.f.check_flash_plugin=function(){Vegas.client.browser.flash_installed=false;Vegas.client.browser.mymetype_check_disabled=false;if(navigator.mimeTypes&&navigator.mimeTypes.length){var a=navigator.mimeTypes["application/x-shockwave-flash"];if(a&&a.enabledPlugin){Vegas.client.browser.flash_installed=true;return false}else{Vegas.client.browser.flash_installed=false;return false}}else{Vegas.client.browser.mymetype_check_disabled=true;return false}return false};Vegas.f.is_blitz=function(b,a){if(b=="g"&&a<=900){return true}else{return false}};Vegas.f.tc_name=function(c,b,a){if(c=="g"&&b<=900){return"blitz"}if(c=="g"&&b<=3600){return"classic"}return"long"};Vegas.f.get_board_icon=function(d,c,a){var b=Vegas.f.tc_name(d,c,a);if(b=="blitz"){if(c<60){return"/img/icon-xtreme.gif"}else{if(c==60){return"/img/icon-bullet.gif"}else{return"/img/icon-blitz.gif"}}}else{if(b=="classic"){return"/img/icon-classic.gif"}else{return"/img/icon-chess.gif"}}};Vegas.f.proger_label=function(b){var a=[];a.push('<a href="#" title="');a.push(Vegas.f.phrase(76));a.push('" onclick="return false;"><img src="/img/proger.gif" border="0" align="absmiddle" /></a>');return a.join("")};Vegas.f.build_join_game_list=function(W){var k;var m;if(W=="blitz"){k=dojo.byId("openblitzgames");m=dojo.byId("openblitznum")}else{k=dojo.byId("openothergames");m=dojo.byId("openothernum")}var z=dojo.query("[widgetId]",k);dojo.forEach(z,function(X){var Y=dojo.attr(X,"widgetId");var Z=dijit.byId(Y);if(Z){Z.destroyRecursive()}});dojo.empty(k);var Q=0;var C="1px solid "+Vegas.iface.border_color1;var s=dojo.create("table",{cellpadding:3,cellspacing:0,style:{borderTop:C}},k);var J=dojo.create("tbody",null,s);var R=dojo.create("tr",{align:"center",valign:"middle"},J);var l=dojo.create("td",{height:"25",innerHTML:Vegas.f.phrase(42),style:{borderBottom:C,borderRight:C}},R);var I=dojo.create("td",{height:"25",innerHTML:Vegas.f.phrase(43),style:{borderBottom:C,borderRight:C}},R);var L=dojo.create("td",{height:"25",innerHTML:'<a href="#" onclick="return false;" title="'+Vegas.f.phrase(143)+'"><img src="/img/vegas_coin_16.png" border="0" /></a>',style:{borderBottom:C,borderRight:C}},R);var V=dojo.create("td",{height:"25",innerHTML:'<a href="#" onclick="return false;" title="'+Vegas.f.phrase(63)+'"><img src="/img/ratecontrol.gif" border="0" /></a>',style:{borderBottom:C,borderRight:C}},R);var o=dojo.create("td",{height:"25",innerHTML:Vegas.f.phrase(50),style:{borderBottom:C,borderRight:C}},R);var a=dojo.create("td",{height:"25",innerHTML:Vegas.f.phrase(34)+"<br/>["+Vegas.f.phrase(44)+"]",style:{borderBottom:C,borderRight:C}},R);var b=dojo.create("td",{height:"25",innerHTML:Vegas.f.phrase(45),style:{borderBottom:C,borderRight:C}},R);var K=dojo.create("td",{height:"25",innerHTML:Vegas.f.phrase(46),style:{borderBottom:C,borderRight:C}},R);var f=dojo.create("td",{height:"25",innerHTML:Vegas.f.phrase(77),style:{borderBottom:C}},R);var u=(new Date()).getTime();for(var y in Vegas.gamelist){if(!Vegas.gamelist[y]||!Vegas.gamelist[y].id){continue}var r=Vegas.gamelist[y];var n=parseInt(r.tlimit);var A=r.tcontrol;var H=parseInt(r.increment);var N=Vegas.f.is_blitz(A,n);if(W=="blitz"&&!N){continue}if(W!="blitz"&&N){continue}Q++;var S=parseInt(r.stake)||0;var P=parseInt(r.ow_proger)||0;var c=Vegas.f.get_board_icon(A,n,H);var E="";var x="";var h="";var v="";if(r.for_rate=="1"){E="/img/rated.gif";rated_title=Vegas.f.phrase(48)}else{E="/img/unrated.gif";rated_title=Vegas.f.phrase(49)}var q="";var G="";if(r.owner_color=="w"){q=Vegas.f.phrase(41);G=Vegas.iface.black_piece}else{q=Vegas.f.phrase(40);G=Vegas.iface.white_piece}var j=r.owner_online;if(j=="on"){h="/img/user_online.gif";v=Vegas.f.phrase(51)}else{if(j=="blitz"){h="/img/blitz_online.gif";v=Vegas.f.phrase(52)}else{if(j=="pda"){h="/img/pda_online.gif";v=Vegas.f.phrase(53)}else{h="/img/user_offline.gif";v=Vegas.f.phrase(54)}}}var g=(A=="g")?"/img/chessclock2.gif":"/img/chessclock1.gif";var d=(A=="g")?Vegas.f.phrase(55):Vegas.f.phrase(56);var T=dojo.create("tr",{align:"center",valign:"middle"},J);var U=dojo.create("td",{height:"25",innerHTML:Vegas.f.get_link({url:Vegas.f.get_game_url(y),txt:'<img border="0" src="'+c+'" />'}),style:{borderBottom:C,borderRight:C}},T);var p=(r.comp=="1")?"/img/advance32.png":"/img/fairplay32.png";var M=(r.comp=="1")?Vegas.f.phrase(131):Vegas.f.phrase(130);var t=dojo.create("td",{height:"25",style:{borderBottom:C,borderRight:C}},T);var D=dojo.create("button",{id:"play_btn_"+y,type:"button",innerHTML:'<img border="0" src="'+p+'" />'},t);var F=new dijit.form.Button({board_id:y,onClick:function(){this.set("disabled",true);Vegas.f.connect_to_board(this.board_id);return false}},D);var e=new dijit.Tooltip({connectId:[D.id],label:M});e.placeAt(k);var w=dojo.create("td",{height:"25",innerHTML:(S>0)?"<b>"+S+"</b>":"0",style:{borderBottom:C,borderRight:C}},T);var w=dojo.create("td",{height:"25",innerHTML:'<a href="#" onclick="return false;" title="'+rated_title+'"><img border="0" src="'+E+'" hspace="2" /></a>',style:{borderBottom:C,borderRight:C}},T);var O=dojo.create("td",{height:"25",innerHTML:q,style:{borderBottom:C,borderRight:C}},T);var B=(P==1)?Vegas.f.proger_label():"";var O=dojo.create("td",{align:"left",height:"25",innerHTML:B+'<a onclick="return false;" href="#" title="'+v+'"><img hspace="2" border="0" align="absmiddle" src="'+h+'" /></a>'+Vegas.f.get_link({url:Vegas.f.get_player_url(r.owner_id),txt:r.owner_nickname})+"<br/>["+r.owner_elo+"]",style:{borderBottom:C,borderRight:C}},T);var O=dojo.create("td",{height:"25",innerHTML:'<a href="#" title="'+d+'"><img border="0" src="'+g+'" /></a>',style:{borderBottom:C,borderRight:C}},T);var O=dojo.create("td",{height:"25",innerHTML:Vegas.f.tlimit_for_gamelist(A,n,H),style:{borderBottom:C,borderRight:C}},T);var O=dojo.create("td",{height:"25",innerHTML:r.maxlag+Vegas.f.phrase(36),style:{borderBottom:C}},T)}if(Q<1){m.innerHTML="0";dojo.empty(k);k.innerHTML=dojo.byId("nogames").innerHTML;return false}m.innerHTML=Q;return false};Vegas.f.build_warnboard_div=function(M,P){var c=dojo.byId(P);if(!c){return false}var L=(new Date()).getTime();var x="1px solid #799D81";dojo.empty(c);var p=dojo.create("table",{bgcolor:"#FFFFFF",cellpadding:2,cellspacing:1},c);var C=dojo.create("tbody",null,p);var J=dojo.create("tr",{align:"center",valign:"middle"},C);var y=dojo.create("td",{height:"20",innerHTML:'<a href="#" title="'+Vegas.f.phrase(73)+'" onclick="Vegas.f.change_div_display(\''+P+'\', \'none\');return false;"><img border="0" src="/img/close.gif" /></a>',style:{borderBottom:x}},J);if(P=="challenges"){var m=dojo.create("td",{height:"20",innerHTML:'<a href="#" title="'+Vegas.f.phrase(50)+'" onclick="return false;"><img border="0" src="/img/black-white.gif" /></a>',style:{borderBottom:x}},J)}var a=dojo.create("td",{height:"20",innerHTML:"<b>"+Vegas.f.phrase(78)+"</b>",style:{borderBottom:x}},J);var b=dojo.create("td",{height:"20",innerHTML:"<b>"+Vegas.f.phrase(34)+"</b>",style:{borderBottom:x}},J);var d=dojo.create("td",{height:"20",innerHTML:"<b>"+Vegas.f.phrase(45)+"</b>",style:{borderBottom:x}},J);if(P=="challenges"){var D=dojo.create("td",{height:"20",innerHTML:'<img src="/img/vegas_coin_16.png" border="0" />',style:{borderBottom:x}},J)}if(P=="challenges"){var g=dojo.create("td",{height:"20",innerHTML:"<b>"+Vegas.f.phrase(77)+"</b>",style:{borderBottom:x}},J)}var q=dojo.create("td",{height:"20",innerHTML:"<b>"+Vegas.f.phrase(65)+"</b>",style:{borderBottom:x}},J);var I=0;for(var s in M){if(!M[s]){continue}var o=M[s];I++;var e=parseInt(o.ow_proger)||0;var K=parseInt(o.stake);var f=(o.for_rate=="1")?"/img/rated.gif":"/img/unrated.gif";var O=(o.for_rate=="1")?Vegas.f.phrase(48):Vegas.f.phrase(49);var v=o.tcontrol;var k=parseInt(o.tlimit);var B=parseInt(o.increment);var G=o.owner_color||"";var A=(G=="w")?Vegas.iface.black_piece:Vegas.iface.white_piece;var l=Vegas.f.tlimit_for_gamelist(v,k,B);if(k>=3600||v!="g"){var F=(v=="g")?Vegas.f.phrase(55):Vegas.f.phrase(56);l+="<br/>(";l+=F;l+=")"}var h=[];if(P=="challenges"){h.push('<a href="#" onclick="realtime.accept_challenge(');h.push(s);h.push(')">');h.push(Vegas.f.phrase(21));h.push("</a>");h.push("&nbsp;|&nbsp;");h.push('<a href="#" onclick="realtime.reject_challenge(');h.push(s);h.push(')">');h.push(Vegas.f.phrase(66));h.push("</a>")}else{h.push('<a href="#" onclick="Vegas.f.load_game_url({board_id:\'');h.push(s);h.push("'}); return false;\">");h.push(Vegas.f.phrase(42));h.push("</a>")}var N=dojo.create("tr",{align:"center",valign:"middle"},C);var u=dojo.create("td",{height:"30",innerHTML:'<a onclick="return false;" href="#" title="'+O+'"><img border="0" src="'+f+'" hspace="5" /></a>'},N);if(P=="challenges"){var H=dojo.create("td",{height:"30",innerHTML:'<img border="0" src="'+A+'" />'},N)}var r=(o.comp=="1")?'<img border="0" src="/img/advance16.png" style="vertical-align: middle; padding-right: 5px;"/>':"";var E=dojo.create("td",{height:"30",innerHTML:r+'<a href="#" onclick="Vegas.f.load_game_url({board_id:\''+s+"'}); return false;\">"+s+"</a>"},N);var w=(e==1)?Vegas.f.proger_label():"";var z=dojo.create("td",{align:"left",height:"30",innerHTML:w+Vegas.f.get_link({url:Vegas.f.get_player_url(o.opponent_id),txt:Vegas.utf8.decode(o.opponent_name)})+"&nbsp;["+o.opponent_elo+"]"},N);var n=dojo.create("td",{height:"30",innerHTML:l},N);if(P=="challenges"){var j=dojo.create("td",{height:"30",innerHTML:(K>0)?"<b>"+K+"</b>":"0"},N)}if(P=="challenges"){var j=dojo.create("td",{height:"30",innerHTML:o.maxlag},N)}var t=dojo.create("td",{height:"30",innerHTML:h.join("")},N);h=null}if(I<1){dojo.empty(c);Vegas.f.change_div_display(P,"none");if(P=="challenges"){Vegas.f.change_div_display("warnchallenge","none")}if(P=="warnmoveboards"){Vegas.f.change_div_display("warnmove","none")}return false}c.style.zIndex=1000000;return false};Vegas.f.hash_to_string=function(b){for(var a in b){if(!b[a]||typeof(b[a])=="undefined"){b[a]=""}else{if(typeof(b[a])!="string"){b[a]=b[a].toString()}else{}}}return b};Vegas.f.show_game_form=function(c){var b=["blitz","tpg","tpm"];for(var a in b){var d="div"+b[a];var e=dojo.byId(d);if(!e){continue}if(b[a]==c){e.style.display=(e.style.display=="none")?"block":"none"}else{e.style.display="none"}}return false};Vegas.f.show_tour_form=function(c){var b=["itour","ttour","tourgrafik"];for(var a in b){var d="div"+b[a];var e=dojo.byId(d);if(!e){continue}if(b[a]==c){e.style.display="block"}else{e.style.display="none"}}return false};Vegas.f.show_tour_grafik_list=function(c){var b=["tourgrafik06_12","tourgrafik12_18","tourgrafik18_00","tourgrafik00_06"];for(var a in b){var d=b[a];var e=dojo.byId(d);if(!e){continue}if(b[a]==c||c=="all"){e.style.display="block"}else{e.style.display="none"}}return false};Vegas.f.exchange_divs=function(d,b){var c=dojo.byId(d);if(!c){return false}var a=dojo.byId(b);if(!a){return false}c.innerHTML="";c.innerHTML=a.innerHTML;return false};Vegas.f.exp_col_gamelist=function(c){var b=dojo.byId(c);var a=dojo.byId(c+"img");if(b.style.display=="none"){b.style.display="";a.src="/img/collapse.gif"}else{b.style.display="none";a.src="/img/expand.gif"}};Vegas.f.to_html=function(b){var a=String(b);a=a.replace(/&/g,"&amp;");a=a.replace(/\"/g,"&quot;");a=a.replace(/\'/g,"&apos;");a=a.replace(/</g,"&lt;");a=a.replace(/>/g,"&gt;");return a};Vegas.f.get_game_url=function(a){var b=Vegas.script+"?cmd=show_board&board_id="+a;return b};Vegas.f.get_tour_url=function(a){var b=Vegas.script+"?cmd=show_tour_info&action=view&tour_id="+a;return b};Vegas.f.load_game_url=function(a){var b=a.board_id;if(!b){return false}if(realtime._warnmove_data[b]){delete realtime._warnmove_data[b];Vegas.f.build_warnboard_div(realtime._warnmove_data,"warnmoveboards");Vegas.f.change_div_display("warnmoveboards","none")}if(realtime._challenge_data[b]){delete realtime._challenge_data[b];Vegas.f.build_warnboard_div(realtime._challenge_data,"challenges");Vegas.f.change_div_display("challenges","none")}Vegas.f.load_url({url:Vegas.f.get_game_url(b)})};Vegas.f.accept_challenge_url=function(a){var b=Vegas.script+"?cmd=join_board&board_id="+a;return b};Vegas.f.get_player_url=function(b){var a=Vegas.script+"?cmd=show_player_info&player_id="+b;return a};Vegas.f.switch_lang=function(d){if(!d||!d.length){return false}var c=document.location.host;var a=(d=="ru")?"chessvegas.ru":"chessvegas.com";if(c==a){return false}var b=document.URL.replace(/^http:\/\/.*?\//i,"http://"+a+"/");realtime.quit();location.href=b;return false};Vegas.f.reset_globals=function(){Vegas.Chess=null;Vegas.o={};Vegas.s={};Vegas.game={};Vegas.tour={};Vegas.timer={};Vegas.gamelist={};Vegas.rtmode=null;Vegas.Chat={};return false};Vegas.f.eval_scripts=function(d){if(!d){return false}var a=d.getElementsByTagName("script");if(!a||!a.length){return false}for(var b=0;b<a.length;b++){var c=new Function(a[b].innerHTML);c()}return false};Vegas.f.get_link=function(c){var b=c.url||"#";var a=c.txt||"NoText";var d=c.title;var e='<a href="#" onclick="Vegas.f.load_url({url:\''+b+"'}); return false;\"";if(d){e+=' title="'+d+'"'}e+=">"+a+"</a>";return e};Vegas.f.submit_dijit_form=function(c){var b=c.form||null;if(!b){return false}var e=c.method||"get";var d=dojo.objectToQuery(b.getValues());var a=Vegas.script+"?"+d;Vegas.f.load_url({method:e,url:a,form:b.getValues()});return false};Vegas.f.onGameStakeChange=function(a){var c=dojo.byId(a.node);if(!c){return false}var b=a.stake||0;var f=Vegas.f.phrase(140);var h=Vegas.f.phrase(141);var g=Vegas.f.phrase(142);var d="+"+Vegas.config.game_vegas_stake[b].win;var e="+0";var j="-"+b;c.innerHTML=f+": <b>"+d+"</b>. ";c.innerHTML+=h+": <b>"+e+"</b>. ";c.innerHTML+=g+": <b>"+j+"</b>. ";return false};Vegas.f.load_url=function(c){if(Vegas.xhrLoading){return false}var a=c.url;if(!a||!a.length){return false}var e=c.method||"get";if(Vegas.linkstyle=="ajax"){var b=c.bf||"";if(Vegas.client.browser.url_id<1){Vegas.client.browser.url_id=1}if(b=="back"){Vegas.client.browser.url_id=Vegas.client.browser.url_id-1}else{if(b=="forward"){Vegas.client.browser.url_id++}else{Vegas.client.browser.url_id++;Vegas.client.browser.hist[Vegas.client.browser.url_id]=a}}var d={back:function(){var g=Vegas.client.browser.url_id-1;var f=Vegas.client.browser.hist[g];if(!f){return false}Vegas.f.load_url({url:f,bf:"back"})},forward:function(){var g=Vegas.client.browser.url_id+1;var f=Vegas.client.browser.hist[g];if(!f){return false}Vegas.f.load_url({url:f,bf:"forward"})},changeUrl:true};if(e=="get"){dojo.back.addToHistory(d)}Vegas.f.xhr({method:e,url:a,form:c.form||null})}else{realtime.quit();location.href=a+"&jstime="+(new Date()).getTime();return false}return false};Vegas.f.scroll_up=function(){var a=dojo.window.getBox();if(a.t>0){var b=300;dojox.fx.smoothScroll({win:window,node:"cornerdiv",offset:{x:0,y:0},duration:b}).play()}return false};Vegas.f.logout=function(){realtime.quit();location.href=Vegas.script+"?cmd=logout&jstime="+(new Date()).getTime();return false};Vegas.f.show_direct_link=function(){var a=Vegas.f.phrase(75)+':<br/><span style="color: #0000FF">http://'+Vegas.host+Vegas.client.browser.url+"</span>";Vegas.f.myconfirm({type:"ok",msg:a});return false};Vegas.f.show_msg_link=function(b){var c=dojo.byId("newmsg");if(!c){return false}var e=parseInt(b.n);var d=b.mode||"diff";if(!e){e=0}if(d=="diff"){Vegas.client.newmsg=Vegas.client.newmsg+e}else{Vegas.client.newmsg=e}if(Vegas.client.newmsg<0){Vegas.client.newmsg=0}var a=[];if(Vegas.client.newmsg>0){a.push(Vegas.f.phrase(37));a.push(":&nbsp;<b>");a.push(Vegas.client.newmsg);a.push("</b>")}else{a.push(Vegas.f.phrase(74))}c.innerHTML=a.join("");return true};Vegas.f.update_my_elo=function(c){var e=parseInt(c.elo);if(e==0){return false}var f=c.tcname;var b=c.comp||false;var a="";if(f=="blitz"){if(b){Vegas.client.comp_blitz_elo=e;a="mycompblitzelo"}else{Vegas.client.blitz_elo=e;a="myblitzelo"}}else{if(b){Vegas.client.comp_elo=e;a="mycompelo"}else{Vegas.client.elo=e;a="mygenelo"}}var d=dojo.byId(a);if(d){d.innerHTML=e}return false};Vegas.f.set_daemon_routing_key=function(){var a=Math.round(Math.random()*(Vegas.server_routing_keys.length-1));if(Vegas.server_routing_keys[a]){Vegas.daemon_routing_key=Vegas.server_routing_keys[a]}else{Vegas.daemon_routing_key=Vegas.server_routing_keys[0]}return Vegas.daemon_routing_key};Vegas.f.selectText=function(b){var c=dojo.byId(b);if(!c){return false}Vegas.f.deselectText();if(document.selection){var a=document.body.createTextRange();a.moveToElementText(c);a.select()}else{if(window.getSelection){var a=document.createRange();a.selectNode(c);window.getSelection().addRange(a)}}return false};Vegas.f.deselectText=function(){if(document.selection){document.selection.empty()}else{if(window.getSelection){window.getSelection().removeAllRanges()}}return false};Vegas.f.make_unselectable=function(a){dojo.setSelectable(a,false);return false},Vegas.f.destroy_extra_nodes=function(){dojo.forEach(dojo.query("[id^=ya-share]"),dojo.destroy);return false};Vegas.f.preventSelection=function(c){function d(e,g,f){if(e.attachEvent){e.attachEvent("on"+g,f)}else{if(e.addEventListener){e.addEventListener(g,f,false)}}}function b(){if(window.getSelection){window.getSelection().removeAllRanges()}else{if(document.selection&&document.selection.clear){document.selection.clear()}}}function a(g){var g=g||window.event;var f=g.target||g.srcElement;var e=g.keyCode||g.which;if(g.ctrlKey&&e==65){b();if(g.preventDefault){g.preventDefault()}else{g.returnValue=false}}}d(c,"mousemove",function(){b()});d(c,"mousedown",function(f){var f=f||window.event;var e=f.target||f.srcElement});d(c,"mouseup",function(){b()})};Vegas.f.press_login_button=function(a){if(Vegas.client.id>0){Vegas.f.myconfirm({type:"ok",msg:Vegas.f.phrase(148)});return false}Vegas.f.popup_tooltip_dialog(a);return false};Vegas.f.popup_tooltip_dialog=function(c){var a=dijit.byId(c.dialog);var b=dojo.byId(c.node);dijit.popup.open({popup:a,around:b});return false};Vegas.f.close_tooltip_dialog=function(a){dijit.popup.close(dijit.byId(a));return false};Vegas.f.xhr=function(b){Vegas.xhrLoading=true;Vegas.f.stop_all_timers();realtime.quit_game();realtime.quit_chat();Vegas.f.reset_globals();realtime.reset_vars();Vegas.f.destroy_extra_nodes();var a=b.method||"get";var k=b.div_id||"content";var d=dojo.byId(k);if(!d){d=document.createElement("DIV");d.id=k;document.body.appendChild(d);Vegas.o[k]=d}else{var j=dojo.query("[widgetId]",d);dojo.forEach(j,function(n){var o=dojo.attr(n,"widgetId");var p=dijit.byId(o);if(p){p.destroyRecursive()}})}var f=dojo.byId("StatusDiv");if(f){document.body.removeChild(f)}var l=["serverwarn","myconfirm"];for(var e in l){var h=dojo.byId(l[e]);if(h&&h.style.display!="none"){h.style.display="none"}}d.style.display="none";var g=dojo.byId("loadingdiv");if(g.style.display=="none"){dojo.style(g,{display:"",position:"absolute",top:70+"px",left:210+"px"})}else{dojo.fadeIn({node:g,duration:1}).play()}var m=10000;var c="";if(a=="post"){Vegas.client.browser.url=Vegas.mainURL;c=Vegas.script;dojo.xhrPost({headers:{"Content-Type":"application/x-www-form-urlencoded; charset=utf-8"},url:c,timeout:m,sync:false,handleAs:"text",content:b.form,load:function(n,o){dojo.fadeOut({node:d,onEnd:function(){d.style.display="";d.innerHTML=n;dojo.parser.parse(d);Vegas.f.eval_scripts(d);realtime.xhr_start();Vegas.xhrLoading=false;dojo.style(g,{display:"none"});dojo.fadeIn({node:d}).play()}}).play();return n},error:function(n,o){Vegas.xhrLoading=false;Vegas.f.myconfirm({type:"ok",msg:"!"+n});dojo.fadeOut({node:g,duration:300}).play();dojo.fadeIn({node:d}).play();return n}})}else{if(!b.url){b.url=Vegas.mainURL}Vegas.client.browser.url=b.url;c=b.url+"&xhr=1&jstime="+(new Date()).getTime();dojo.xhrGet({url:c,timeout:m,sync:false,handleAs:"text",load:function(n,o){dojo.fadeOut({node:d,onEnd:function(){d.style.display="";d.innerHTML=n;dojo.parser.parse(d);Vegas.f.eval_scripts(d);realtime.xhr_start();Vegas.xhrLoading=false;dojo.style(g,{display:"none"});dojo.fadeIn({node:d}).play()}}).play();return n},error:function(n,o){Vegas.xhrLoading=false;Vegas.f.myconfirm({type:"ok",msg:"!"+n});dojo.fadeOut({node:g,duration:300}).play();dojo.fadeIn({node:d}).play();return n}})}Vegas.f.scroll_up();return false};Vegas.f.animate_connection=function(a){var e=dojo.byId("warnconnection");if(!e){return false}var h=a.mode||"";var c=(h=="reconnect")?Vegas.f.phrase(116):Vegas.f.phrase(115);dojo.style(e,{display:"",cursor:"pointer"});var j=new dijit.Tooltip({connectId:[e],label:c});j.startup();j.open(e);var f=dojo.fadeIn({node:e});var g=dojo.fadeOut({node:e});var d=dojo.connect(f,"onEnd",function(k){if(realtime.connected){dojo.disconnect(d);g.stop();j.destroyRecursive();dojo.style(k,{display:"none"})}else{g.play()}});var b=dojo.connect(g,"onEnd",function(k){if(realtime.connected){dojo.disconnect(b);f.stop();j.destroyRecursive();dojo.style(k,{display:"none"})}else{f.play()}});g.play();return false};var realtime={connected:false,reconnection:false,_onload_connected:false,_all_players_exchange:Vegas.all_players_exchange,_tournaments_exchange:Vegas.tournaments_exchange,_player_exchange:Vegas.player_exchange,_board_exchange:Vegas.board_exchange,_board_chat_exchange:Vegas.board_chat_exchange,_ingame_exchange:Vegas.ingame_exchange,_pubchat_exchange:"pubchat.fanout",_teamchat_exchange:(Vegas.client.team_id>0)?"team"+Vegas.client.team_id+"chat.fanout":null,_control_routing_key:Vegas.control_routing_keys[0],_game_queue:null,_game_chat_queue:null,_ingame_queue:null,_player_queue:((Vegas.client.id>0)?"user":"guest")+"-"+Vegas.client.id+"-"+(new Date()).getTime(),_all_players_queue:"allplayers-"+Vegas.client.id+"-"+(new Date()).getTime(),_tournaments_queue:"tours-"+Vegas.client.id+"-"+(new Date()).getTime(),_unload:false,_challenge_data:{},_warnmove_data:{},_msg_id:0,_frames:{},_ChatHash:{},online_timer:null,_checkconn_node:null,amqp_proxy_node:null,amqp_proxy_node_ID:"AMQPProxy",_memd_check_period:50133,global_quit:false,reset_vars:function(){realtime.opponent_connected=false;realtime._board_id=null;realtime._ingame_packets=0;realtime._game_queue=null;realtime._game_chat_queue=null;realtime._ingame_queue=null;realtime._ChatHash={};return false},_amqp_declare_server_exchanges:function(){MQ.exchange(Vegas.all_players_exchange,{type:"fanout",autoDelete:false});MQ.exchange(Vegas.tournaments_exchange,{type:"fanout",autoDelete:false});MQ.exchange(realtime._pubchat_exchange,{type:"fanout",autoDelete:false});MQ.exchange(Vegas.server_exchange,{type:"direct",autoDelete:false});MQ.exchange(Vegas.player_exchange,{type:"direct",autoDelete:false});MQ.exchange(Vegas.board_exchange,{type:"direct",autoDelete:false});MQ.exchange(Vegas.board_chat_exchange,{type:"direct",autoDelete:false});MQ.exchange(Vegas.control_exchange,{type:"direct",autoDelete:false});MQ.exchange(Vegas.ingame_exchange,{type:"direct",autoDelete:false});if(realtime._teamchat_exchange){MQ.exchange(realtime._teamchat_exchange,{type:"fanout",autoDelete:false})}return false},_get_unique_queue:function(){var a="q"+Math.random()+""+Math.random();return a.replace(/\./g,"")},_amqp_bind:function(f){if(!f||!f.queue||!f.queue.length||!f.exchange||!f.exchange.length){return false}var a=f.queue;var b=f.exchange;var d=f.routing_key;if(!d||d==""||d=="#"||d=="*"){d="all"}var c=f.exchange_type||"direct";var e=MQ.queue(a,{autoDelete:true,durable:false,exclusive:false});e.callback(function(h){realtime._handler(h)});var g=e.bind(b,d);return false},_amqp_send:function(c,a,b){if(!realtime.connected){return false}if(!a||!a.length){return false}MQ.exchange(a).publish(c,b);return false},quit:function(){realtime.global_quit=true;if(!realtime.connected){return false}if(realtime._ingame_queue&&Vegas.game.my&&Vegas.game.id){realtime._amqp_send({msg:"off",client_id:Vegas.client.id,cmd:"offgame"},realtime._ingame_exchange,Vegas.game.id)}MQ.disconnect();realtime.connected=false;return false},quit_game:function(){if(Vegas.Chess){for(var b in Vegas.Chess){for(var a in Vegas.Chess[b]){Vegas.Chess[b][a].destroy()}}}if(!realtime.connected){return false}if(realtime._game_chat_queue){MQ.deleteQueue(realtime._game_chat_queue,{ifUnused:false,ifEmpty:false,nowait:false})}if(realtime._ingame_queue&&Vegas.game.my&&Vegas.game.id){realtime._amqp_send({msg:"off",client_id:Vegas.client.id,cmd:"offgame"},realtime._ingame_exchange,Vegas.game.id)}if(realtime._game_queue){MQ.deleteQueue(realtime._game_queue,{ifUnused:false,ifEmpty:false,nowait:false})}if(realtime._ingame_queue){MQ.deleteQueue(realtime._ingame_queue,{ifUnused:false,ifEmpty:false,nowait:false})}return false},quit_chat:function(){if(realtime._ChatHash&&realtime._ChatHash.queue){MQ.deleteQueue(realtime._ChatHash.queue,{ifUnused:false,ifEmpty:false,nowait:false});realtime.send_message_to_allchat({sys:1,text:Vegas.client.nickname+" "+Vegas.f.phrase(135)})}return false},_chat:function(c,a,b){Vegas.Chess[Vegas.game.id]["game"].process_chat_msg(c,a,b);return false},send_chat_msg:function(b){if(!realtime._board_id||!realtime._game_chat_queue){return false}if(!b||!b.length){return false}var a={msg:Vegas.utf8.encode(b),client_id:Vegas.client.id,cmd:"chat",nickname:Vegas.utf8.encode(Vegas.client.nickname)};realtime._amqp_send(a,realtime._board_chat_exchange,realtime._board_id);return false},_send_ingame_packet:function(b,a){if(!realtime._board_id||!realtime._ingame_queue){return false}if(Vegas.game.my&&Vegas.game.winner_id==null&&Vegas.game.white_id>0&&Vegas.game.black_id>0){realtime._amqp_send({msg:"in",client_id:b,cmd:"ingame",pnum:a},realtime._ingame_exchange,realtime._board_id)}return false},_show_icq_flower:function(c){var a=dojo.byId("siteonline"+c);var b=dojo.byId("icqonline"+c);if(!a||!b){return false}a.style.display="none";b.style.display="inline";return false},_hide_icq_flower:function(c){var a=dojo.byId("siteonline"+c);var b=dojo.byId("icqonline"+c);if(!a||!b){return false}a.style.display="inline";b.style.display="none";return false},_init_game_list:function(){if(typeof(Vegas.rtmode)=="undefined"||Vegas.rtmode!="join_game_list"){return false}var d="sound";var b=["newblitzsound","newothersound"];for(var a in b){var f=b[a];var e=Vegas.f.get_cookie({cname:"sound",ckey:f});Vegas.f.get_widget(f).set("checked",(typeof(e)=="boolean"&&!e)?false:true)}Vegas.f.build_join_game_list("blitz");Vegas.f.build_join_game_list("other");return false},_init_game_interface:function(){if(!realtime._board_id){return false}Vegas.f.init_chessboard();if(Vegas.game.my&&Vegas.game.winner_id==null&&Vegas.game.white_id>0&&Vegas.game.black_id>0){realtime._show_icq_flower(Vegas.client.id)}if(realtime._warnmove_data[realtime._board_id]){delete realtime._warnmove_data[realtime._board_id];Vegas.f.build_warnboard_div(realtime._warnmove_data,"warnmoveboards")}return false},_in_game:function(b,a){realtime._ingame_packets++;if(Vegas.game.my){if(a>=2&&b==Vegas.client.id){return false}if(a==2&&b!=Vegas.client.id){realtime._show_icq_flower(b);return false}if(b==Vegas.client.id){return false}else{realtime._show_icq_flower(b);if(a==1){realtime._send_ingame_packet(Vegas.client.id,2)}}}else{realtime._show_icq_flower(b)}return false},_bind_to_game_exchanges:function(){if(!realtime._board_id){return false}if(Vegas.game.winner_id!=null){return false}if(Vegas.game.my&&Vegas.game.winner_id==null){realtime._game_chat_queue="gamechat-"+Vegas.client.id+"-"+realtime._board_id+"-"+(new Date()).getTime();realtime._amqp_bind({queue:realtime._game_chat_queue,exchange:realtime._board_chat_exchange,exchange_type:"direct",routing_key:realtime._board_id})}if(Vegas.game.winner_id==null){realtime._game_queue="game-"+Vegas.client.id+"-"+realtime._board_id+"-"+(new Date()).getTime();realtime._amqp_bind({queue:realtime._game_queue,exchange:realtime._board_exchange,exchange_type:"direct",routing_key:realtime._board_id});realtime._ingame_queue="gamein-"+Vegas.client.id+"-"+realtime._board_id+"-"+(new Date()).getTime();realtime._amqp_bind({queue:realtime._ingame_queue,exchange:realtime._ingame_exchange,exchange_type:"direct",routing_key:realtime._board_id})}return false},_bind_to_all_exchanges:function(){realtime._amqp_bind({queue:realtime._all_players_queue,exchange:realtime._all_players_exchange,exchange_type:"fanout",routing_key:null});realtime._amqp_bind({queue:realtime._tournaments_queue,exchange:realtime._tournaments_exchange,exchange_type:"fanout",routing_key:null});realtime._amqp_bind({queue:realtime._player_queue,exchange:realtime._player_exchange,exchange_type:"direct",routing_key:Vegas.client.id});return false},send_move_to_server:function(a){Vegas.f.set_daemon_routing_key();a.msg="checkmove";realtime._amqp_send(a,Vegas.server_exchange,Vegas.daemon_routing_key);return false},send_move_to_board_channel:function(a){a.msg="move";realtime._amqp_send(a,realtime._board_exchange,realtime._board_id);return false},_set_control_routing_key:function(){var a=Math.round(Math.random()*(Vegas.control_routing_keys.length-1));if(Vegas.control_routing_keys[a]){realtime._control_routing_key=Vegas.control_routing_keys[a]}else{realtime._control_routing_key=Vegas.control_routing_keys[0]}return realtime._control_routing_key},send_sig_to_control_channel:function(a){a.msg="control";realtime._set_control_routing_key();realtime._amqp_send(a,Vegas.control_exchange,realtime._control_routing_key);return false},_check_conn:function(e,b){if(e!=Vegas.client.id){return false}if(!realtime._checkconn_node){return false}var a=(new Date()).getTime();var d=(a-b)/1000;var c=[];c.push(Vegas.f.phrase(35));c.push(" ");c.push(d);c.push(" ");c.push(Vegas.f.phrase(36));realtime._checkconn_node.set("label",c.join(""));realtime._checkconn_node.set("disabled",false);return false},check_connection:function(a){realtime._checkconn_node=null;realtime._checkconn_node=a;a.set("disabled",true);a.set("label",Vegas.f.phrase(13));realtime._amqp_send({msg:"c",client_id:Vegas.client.id,cmd:"checkconn",ts1:(new Date()).getTime()},realtime._player_exchange,Vegas.client.id);return false},_make_move:function(a){if(!realtime._board_id||realtime._board_id!=a.board_id){return false}Vegas.Chess[Vegas.game.id]["game"].process_move(a);return false},_init_chat:function(c){if(!Vegas.Chat||!Vegas.Chat.type){return false}realtime._ChatHash={};var b=Vegas.Chat.type||"";var a="";if(b=="team"){a=realtime._teamchat_exchange}else{a=realtime._pubchat_exchange}if(a!=Vegas.Chat.exchange){Vegas.f.myconfirm({type:"ok",msg:Vegas.f.phrase(139)});return false}realtime._ChatHash={type:b,last_chat_id:0,my_last_ts:0,exchange:a||null,queue:Vegas.Chat.type+"chat-"+Vegas.client.id+"-"+(new Date()).getTime(),chatWidget:dijit.byId(Vegas.Chat.win_id)||null,msgWidget:dijit.byId(Vegas.Chat.input_id)||null,clients:{}};if(!realtime._ChatHash.exchange||!realtime._ChatHash.chatWidget||!realtime._ChatHash.msgWidget){realtime._ChatHash={};return false}realtime._amqp_bind({queue:realtime._ChatHash.queue,exchange:realtime._ChatHash.exchange,exchange_type:"fanout",routing_key:null});realtime._ChatHash.msgWidget.focus();dojo.connect(realtime._ChatHash.msgWidget,"onKeyUp",function(d){if(d.keyCode==dojo.keys.ENTER){realtime.send_message_to_allchat()}return false});realtime.send_message_to_allchat({sys:1,text:Vegas.client.nickname+" "+Vegas.f.phrase(134)});return false},send_message_to_allchat:function(d){if(!realtime._ChatHash.exchange||!realtime._ChatHash.queue){return false}if(!d){d={}}var f=d.sys||"0";var c=(new Date()).getTime();last_ts=realtime._ChatHash.my_last_ts;var a=c-last_ts;if(f!="1"&&!Vegas.client.VIP&&realtime._ChatHash.type=="public"&&last_ts!=0&&a<20000){var b=dojo.number.round((20000-a)/1000,0);var e=Vegas.f.phrase(137)+" "+Vegas.f.phrase(138)+" "+b+" "+Vegas.f.phrase(36);realtime._receive_allchat_message({msg:Vegas.utf8.encode(e),client_id:Vegas.client.id,nickname:"System",sys:1});return false}var h=d.text||realtime._ChatHash.msgWidget.get("value")||"";if(!h.length){return false}realtime._ChatHash.msgWidget.set("value","");var g={msg:Vegas.utf8.encode(h),client_id:Vegas.client.id,cmd:"allchat",nickname:Vegas.utf8.encode(Vegas.client.nickname),sys:f};realtime._amqp_send(g,realtime._ChatHash.exchange,"#");g=null;d=null;return false},_receive_allchat_message:function(a){if(!realtime._ChatHash.chatWidget){return false}var j=Vegas.f.to_html(Vegas.utf8.decode(a.msg));var k=a.sys||"0";var f=a.client_id;var b=Vegas.utf8.decode(a.nickname);var e="#0000FF";var h="";if(k=="1"){h+=Vegas.f.phrase(136);e="#FF0000"}else{realtime._ChatHash.last_chat_id=f;if(!realtime._ChatHash.clients[f]){realtime._ChatHash.clients[f]={}}if(!realtime._ChatHash.clients[f].nick){realtime._ChatHash.clients[f].nick=b}if(Vegas.client.id==f){realtime._ChatHash.my_last_ts=(new Date()).getTime();e="#000000";h+=b}else{h+='<a href="#" onclick="realtime.copy_nick_to_input(\''+f+"'); return false;\">"+b+"</a>"}}var c=realtime._ChatHash.chatWidget.domNode;var g=dojo.create("div",{style:{marginBottom:"5px"}},c);var l=dojo.create("span",{style:{color:e,fontWeight:"bold"}},g);l.innerHTML=h+":&nbsp;";var d=dojo.create("span",{style:{color:"#000000"}},g);d.innerHTML=j;c.scrollTop=c.scrollHeight;c=null;return false},clear_chat_window:function(){if(!realtime._ChatHash.chatWidget){return false}dojo.empty(realtime._ChatHash.chatWidget.domNode);return false},copy_nick_to_input:function(e){if(!e){return false}var c=realtime._ChatHash;if(c&&c.msgWidget&&c.clients&&c.clients[e]&&c.clients[e].nick){var b=c.clients[e].nick;var d=c.msgWidget.get("value")||"";var a=d.length?"":",";c.msgWidget.set("value",d+b+a+" ");c.msgWidget.focus()}return false},_serverwarn:function(b,a){if(b!=Vegas.client.id){return false}Vegas.f.myconfirm({type:"ok",msg:Vegas.utf8.decode(a)});return false},accept_challenge:function(a){delete realtime._challenge_data[a];Vegas.f.build_warnboard_div(realtime._challenge_data,"challenges");Vegas.f.change_div_display("challenges","none");Vegas.f.load_url({url:Vegas.f.accept_challenge_url(a)});return false},reject_challenge:function(a){delete realtime._challenge_data[a];Vegas.f.build_warnboard_div(realtime._challenge_data,"challenges");realtime.send_sig_to_control_channel({cmd:"reject",board_id:a,client_id:Vegas.client.id,cidkey:Vegas.client.cidkey,nickname:Vegas.utf8.encode(Vegas.client.nickname)});return false},_challenge:function(a){var d=a.client_id;if(d==Vegas.client.id){return false}var c=parseInt(a.ow_proger)||0;if(c==1&&Vegas.client.ignoreprog==1){return false}var b=a.board_id;realtime._challenge_data[b]={};realtime._challenge_data[b]={opponent_id:d,opponent_elo:a.op_elo,opponent_name:a.nickname,tcontrol:a.tcontrol,tlimit:a.movetime,increment:a.increment,for_rate:a.for_rate,ow_proger:c,maxlag:a.maxlag,comp:a.comp||"0",stake:a.stake||"0",owner_color:a.owner_color};Vegas.f.build_warnboard_div(realtime._challenge_data,"challenges");dojo.byId("warnchallenge").style.display="";realtime._sysmsg({action:"challenge"});if(Vegas.f.is_sound_enabled()){Vegas.f.play_chess_sound("challenge")}return false},_warnmove:function(c){if(c.client_id!=Vegas.client.id){return false}var a=0;var b=[];b=c.boards;for(var d in b){realtime._warnmove_data[d]={};realtime._warnmove_data[d]={opponent_id:b[d].op_id,opponent_elo:b[d].op_elo,opponent_name:b[d].op_name,tcontrol:b[d].tcontrol,tlimit:b[d].movetime,increment:b[d].increment,for_rate:b[d].for_rate,comp:b[d].comp||"0",ow_proger:"0"};a++}if(a>0){Vegas.f.build_warnboard_div(realtime._warnmove_data,"warnmoveboards");Vegas.f.change_div_display("warnmove","")}return false},_joined_board:function(a){if(!Vegas.game.id||a!=Vegas.game.id){return false}if(Vegas.game.white_id>0&&Vegas.game.black_id>0){return false}Vegas.f.load_url({url:Vegas.game.link});return false},_challenge_declined:function(a){if(Vegas.client.id==a.client_id){return false}if(!realtime._board_id||(realtime._board_id!=a.board_id)){a.action="rejectchallenge";realtime._sysmsg(a);return false}if(!Vegas.game.id||Vegas.game.id!=a.board_id){return false}if(Vegas.game.winner_id||(Vegas.game.white_id>0&&Vegas.game.black_id>0)){return false}Vegas.f.stop_timer_by_id("annulate_timer");Vegas.f.myconfirm({type:"ok",msg:Vegas.f.phrase(61),url:Vegas.mainURL});return false},_challenge_aborted:function(a){if(realtime._board_id&&realtime._board_id==a.board_id){Vegas.f.myconfirm({type:"ok",msg:Vegas.f.phrase(68),url:Vegas.mainURL});return false}delete realtime._challenge_data[a.board_id];Vegas.f.build_warnboard_div(realtime._challenge_data,"challenges");return false},_newmsg:function(b,a){if(a!=Vegas.client.id){return false}if(Vegas.f.show_msg_link({n:"1"})){if(Vegas.f.is_sound_enabled()){Vegas.f.play_chess_sound("message")}}return false},_update_game_list:function(e){if(typeof(Vegas.rtmode)=="undefined"||!Vegas.rtmode||Vegas.rtmode!="join_game_list"){return false}if(Vegas.client.ignoreprog==1&&e.game.ow_proger=="1"){return false}if(Vegas.client.proger==1&&e.game.ignoreprog=="1"){return false}var f=e.game.id;if(!Vegas.gamelist[f]||!Vegas.gamelist[f].id){Vegas.gamelist[f]={}}if(e.newgame=="y"){var a=Vegas.f.is_blitz(e.game.tcontrol,parseInt(e.game.tlimit));var c=parseInt(e.game.min_elo);var d=parseInt(e.game.max_elo);var b=a?Vegas.client.blitz_elo:Vegas.client.elo;if(b<c||b>d){return false}Vegas.gamelist[f]=e.game;Vegas.gamelist[f].owner_nickname=Vegas.utf8.decode(e.game.owner_nickname);Vegas.gamelist[f].name=Vegas.utf8.decode(e.game.name);if(a&&Vegas.f.get_widget("newblitzsound").checked){Vegas.f.play_chess_sound("gamelistplus")}if(!a&&Vegas.f.get_widget("newothersound").checked){Vegas.f.play_chess_sound("gamelistplus")}}else{if(!Vegas.gamelist[f].id){return false}delete Vegas.gamelist[f]}realtime._init_game_list();return false},_admin_broadcast:function(b){var a=b.action||"";if(!a||!a.length){return false}if(a=="updating"){Vegas.f.myconfirm({type:"ok",msg:Vegas.f.phrase(39)});return false}return false},_sysmsg:function(f){var e=f.action||"";if(!e||!e.length){return false}var j=dojo.byId("sysmsg");if(!j){return false}var g=[];var b=[];if(e=="touropen"){var l=parseInt(f.movetime);var h=f.tcontrol;var k=parseInt(f.increment);var a=Vegas.script+"?cmd=show_tour_info&tour_id="+f.tour_id;b.push("<a href=\"#\" onclick=\"Vegas.f.change_div_display('sysmsg', 'none'); Vegas.f.load_url({url:'");b.push(a);b.push("'});\">");b.push(Vegas.f.phrase(64));b.push(".&nbsp;");b.push(Vegas.f.phrase(45));b.push(":&nbsp;");b.push(Vegas.f.tlimit_for_gamelist(h,l,k));if(l>=3600||h!="g"){var d=(h=="g")?Vegas.f.phrase(55):Vegas.f.phrase(56);b.push("&nbsp;(");b.push(d);b.push(")")}b.push("&nbsp;&gt;&gt;&gt;");b.push("</a>")}else{if(e=="rejectchallenge"){b.push(Vegas.f.get_link({url:Vegas.f.get_player_url(f.client_id),txt:Vegas.utf8.decode(f.nick)}));b.push("&nbsp;");b.push(Vegas.f.phrase(67))}else{if(e=="challenge"){b.push("<a href=\"#\" onclick=\"Vegas.f.change_div_display('challenges', ''); Vegas.f.change_div_display('sysmsg', 'none');\">");b.push(Vegas.f.phrase(69));b.push("&nbsp;&gt;&gt;&gt;");b.push("</a>")}else{return false}}}b.push("&nbsp;&nbsp;&nbsp;[&nbsp;<a href=\"#\" onclick=\"Vegas.f.change_div_display('sysmsg', 'none');\">");b.push(Vegas.f.phrase(73));b.push("</a>");b.push("&nbsp;]");var c=dojo.byId("StatusDiv");if(c){c.style.display="none"}g.push('<table height="20"><tbody><tr><td valign="middle"><img border="0" src="/img/sysmsg.gif" hspace="2" align="middle"/></td>');g.push('<td valign="middle">');g.push(b.join(""));g.push("</td></tr></tbody></table>");j.innerHTML=g.join("");j.style.display="";if(Vegas.f.is_sound_enabled()){if(e!="challenge"){Vegas.f.play_chess_sound("sysmsg")}}return false},_warn_tour_deleted:function(d){var a=parseInt(d.tour_id)||0;if(!a){return false}if(Vegas.tour&&Vegas.tour.id&&Vegas.tour.id==a){var c=d.reason||"";var b="";if(c=="fewplayers"){b=Vegas.f.phrase(120)}else{b=Vegas.f.phrase(119)}var e=Vegas.f.phrase(118)+"<br/>"+b;if(Vegas.o.TourTimerObject){Vegas.o.TourTimerObject.innerHTML=Vegas.f.phrase(118)}Vegas.f.myconfirm({type:"ok",msg:e});return false}return false},_warn_tour_finished:function(b){var a=parseInt(b.tour_id)||0;if(!a){return false}if(Vegas.tour.id&&Vegas.tour.id==a){Vegas.f.load_url({url:Vegas.f.get_tour_url(a)});Vegas.f.myconfirm({type:"ok",msg:Vegas.f.phrase(121)});return false}return false},_gamestart:function(g){var b=0;var a=parseInt(g.tour_id)||0;var h=0;for(var e in g.games){var d=parseInt(g.games[e].id);var f=parseInt(g.games[e].ow);var c=parseInt(g.games[e].op);if(a>0){if(!Vegas.tourstate[a]){Vegas.tourstate[a]={}}if(!Vegas.tourstate[a].games){Vegas.tourstate[a].games={}}if(!Vegas.tourstate[a].games[d]){Vegas.tourstate[a].games[d]={ow:f,op:c};h=h+1}}if(realtime._board_id&&!Vegas.game.my&&realtime._board_id==d&&(Vegas.game.white_id==0||Vegas.game.black_id==0)){Vegas.f.load_url({url:Vegas.f.get_game_url(d)});if(Vegas.client.sound_on){Vegas.f.play_chess_sound("newgame")}return false}if(Vegas.client.id==f||Vegas.client.id==c){b=d;break}}if(b==0){if(a>0&&h>0&&Vegas.tour.id&&Vegas.tour.id==a){Vegas.f.load_url({url:Vegas.f.get_tour_url(a)});return false}return false}if(realtime._board_id&&realtime._board_id==b&&Vegas.game.white_id>0&&Vegas.game.black_id>0){return false}if(realtime._board_id&&Vegas.game.my&&Vegas.game.white_id>0&&Vegas.game.black_id>0&&Vegas.game.winner_id==null&&Vegas.game.tour_id>0){return false}if(realtime._board_id&&Vegas.game.my&&Vegas.game.white_id>0&&Vegas.game.black_id>0&&Vegas.game.winner_id==null&&a==0&&((Vegas.game.tcontrol=="g"&&Vegas.game.tlimit<=3600)||(Vegas.game.tcontrol=="m"&&Vegas.game.tlimit<=600))){return false}Vegas.f.load_url({url:Vegas.f.get_game_url(b)});if(Vegas.client.sound_on){Vegas.f.play_chess_sound("newgame")}return false},_gameend:function(e){var a=parseInt(e.board_id);var b=parseInt(e.ow_id);var j=parseInt(e.op_id);var h=(b==Vegas.client.id||j==Vegas.client.id)?true:false;if(!h){return false}var f=parseInt(e.ow_elo);var c=parseInt(e.op_elo);var d=(parseInt(e.for_rate)>0)?true:false;var g=(e.comp&&e.comp=="1")?true:false;if(h){if(realtime._warnmove_data[a]){delete realtime._warnmove_data[a];Vegas.f.build_warnboard_div(realtime._warnmove_data,"warnmoveboards")}}if(h&&d){if(Vegas.client.id==b){Vegas.f.update_my_elo({elo:e.ow_elo,tcname:e.tcname,comp:g})}else{Vegas.f.update_my_elo({elo:e.op_elo,tcname:e.tcname,comp:g})}}return false},update_ignorelist:function(b){var d=parseInt(b.my_id)||0;var a=parseInt(b.his_id)||0;if(d!=Vegas.client.id&&a!=Vegas.client.id){return false}var c=parseInt(b.allinv)||0;if(c==0){if(d==Vegas.client.id){if(typeof(Vegas.client.ignorelist[1][a])!="undefined"){delete Vegas.client.ignorelist[1][a]}}else{if(typeof(Vegas.client.ignorelist[-1][d])!="undefined"){delete Vegas.client.ignorelist[-1][d]}}}else{if(d==Vegas.client.id){Vegas.client.ignorelist[1][a]=1}else{Vegas.client.ignorelist[-1][d]=1}}return false},repeat_frames:function(){for(var a in realtime._frames){var b=realtime._frames[a];delete realtime._frames[a];realtime._handler(b)}return false},_handler:function(d){if(typeof(d)!="object"){return false}if(Vegas.xhrLoading){realtime._msg_id+=1;realtime._frames[realtime._msg_id]=d;return false}var b={};b=d.data;var e=parseInt(b.client_id)||0;if(!e){return false}var c=b.msg||"";if(!c||!c.length){realtime._warn(e,"No key msg!");return false}var a=b.cmd||"";if(!a||!a.length){realtime._warn(e,"No command to run!");return false}if(a=="move"){realtime._make_move(b);return false}else{if(a=="chat"){realtime._chat(e,b.nickname,c);return false}else{if(a=="ingame"){if(Vegas.game.white_id==0||Vegas.game.black_id==0){return false}if(e!=Vegas.client.id){realtime.opponent_connected=true}realtime._in_game(e,parseInt(b.pnum));return false}else{if(a=="offgame"){if(e!=Vegas.client.id){realtime.opponent_connected=false}realtime._hide_icq_flower(e);return false}else{if(a=="checkconn"){realtime._check_conn(e,parseInt(b.ts1));return false}else{if(a=="serverwarn"){realtime._serverwarn(e,b.error);return false}else{if(a=="challenge"){realtime._challenge(b);return false}else{if(a=="challdeclined"){realtime._challenge_declined(b);return false}else{if(a=="joined"){realtime._joined_board(b.board_id);return false}else{if(a=="newmsg"){realtime._newmsg(e,b.to);return false}else{if(a=="warnmove"){realtime._warnmove(b);return false}else{if(a=="gamelist"){if(e==Vegas.client.id&&b.newgame=="y"){return false}if(typeof(Vegas.client.ignorelist[1][e])!="undefined"||typeof(Vegas.client.ignorelist[-1][e])!="undefined"){return false}realtime._update_game_list(b);return false}else{if(a=="gamestart"){realtime._gamestart(b);return false}else{if(a=="gameend"){realtime._gameend(b);return false}else{if(a=="adminbroadcast"){realtime._admin_broadcast(b);return false}else{if(a=="sysmsg"){realtime._sysmsg(b);return false}else{if(a=="abortchall"){realtime._challenge_aborted(b);return false}else{if(a=="ignore"){realtime.update_ignorelist(b);return false}else{if(a=="tourdel"){realtime._warn_tour_deleted(b);return false}else{if(a=="tourend"){realtime._warn_tour_finished(b);return false}else{if(a=="allchat"){realtime._receive_allchat_message(b);return false}else{realtime._warn(e,"No command to run!");return false}}}}}}}}}}}}}}}}}}}}}return false},_init_vars:function(){realtime._board_id=Vegas.game.id||null;if(realtime._board_id!=null&&realtime._board_id==0){realtime._board_id=null}return false},_player_online:function(){var b=(Vegas.game.id&&Vegas.game.my&&Vegas.game.winner_id==null&&Vegas.game.blitz&&Vegas.game.white_id>0&&Vegas.game.black_id>0)?1:0;var a=(Vegas.game.id&&Vegas.game.my)?Vegas.game.id:0;var c=(Vegas.game.id&&Vegas.game.winner_id==null&&Vegas.game.blitz&&Vegas.game.white_id>0&&Vegas.game.black_id>0)?0:1;realtime._set_control_routing_key();realtime._amqp_send({msg:"on",cmd:"memdonline",client_id:Vegas.client.id,cidkey:Vegas.client.cidkey,lang:Vegas.client.lang,blitz:b,pda:Vegas.client.browser.pda_version,warnmove:c,no_id:a},Vegas.control_exchange,realtime._control_routing_key);return false},reconnect:function(){if(realtime.reconnection||realtime._unload||!realtime._onload_connected){return false}realtime.reconnection=true;realtime.connected=false;Vegas.f.stop_all_timers();if(realtime.online_timer){realtime.online_timer=null;window.clearInterval(realtime.online_timer)}Vegas.f.animate_connection({mode:"reconnect"});MQ.exchanges={};MQ.queues={};MQ.connect();return false},configure_MQ:function(){var a=(Vegas.client.id==1&&window.console&&window.console.firebug)?console:null;MQ.configure({logger:a,logLevel:1,user:"guest",password:"guest",port:5672,vhost:"/",host:document.location.host,onReceiveHandler:"queue"});MQ.on("load",function(){return false});MQ.on("connect",function(){realtime.connected=true;realtime._onload_connected=true;realtime._amqp_declare_server_exchanges();realtime._bind_to_all_exchanges();if(!realtime.reconnection){realtime._init_game_interface();realtime._bind_to_game_exchanges();realtime._send_ingame_packet(Vegas.client.id,1);realtime._init_chat()}else{realtime.reconnection=false;Vegas.f.load_url({url:Vegas.client.browser.url})}if(Vegas.client.id&&Vegas.client.id>0&&Vegas.client.cidkey&&Vegas.client.cidkey.length){if(Vegas.client.browser.cmd.length&&Vegas.client.browser.cmd!="show_index_page"){realtime._player_online()}realtime.online_timer=window.setInterval(function(){realtime._player_online()},realtime._memd_check_period)}});MQ.on("disconnect",function(){realtime.reconnect();return false})},_init_connection:function(a){var b=a.mode||"connect";realtime._init_vars();realtime.configure_MQ();if(!realtime.amqp_proxy_node){realtime.amqp_proxy_node=dojo.create("div",null,dojo.body());realtime.amqp_proxy_node.id=realtime.amqp_proxy_node_ID;dojo.style(realtime.amqp_proxy_node,{display:"none"})}if(b=="connect"){swfobject.embedSWF("/js/amqp-js-3/amqp3.swf",realtime.amqp_proxy_node_ID,"1","1","9","/js/amqp-js-3/expressInstall.swf",{},{allowScriptAccess:"always",wmode:"opaque",bgcolor:"#FFFFFF"},{},function(){})}return false},xhr_start:function(){realtime._init_game_list();realtime._init_vars();realtime._init_game_interface();if(realtime.connected&&realtime._board_id){realtime._bind_to_game_exchanges();realtime._send_ingame_packet(Vegas.client.id,1)}realtime._init_chat();Vegas.f.common_func();return false},start:function(){realtime.reset_vars();Vegas.f.animate_connection({mode:"connect"});realtime._init_game_list();realtime._init_connection({mode:"connect"});window.setInterval(function(){realtime.repeat_frames()},2033);return false},unload_quit:function(){realtime._unload=true;realtime.quit();return false},tmp:null};dojo.addOnLoad(function(){if(window.console&&window.console.firebug){Vegas.f.myconfirm({type:"ok",msg:Vegas.f.phrase(113)})}if(Vegas.pageMode=="realtime"){if(Vegas.linkstyle=="ajax"){dojo.back.setInitialState({back:function(){return false},forward:function(){return false},changeUrl:true})}Vegas.f.init_sounds();Vegas.f.preload_images();realtime.start();return false}});dojo.addOnUnload(window,function(){realtime.unload_quit()});
