var chessRules = {	saveBG : "",		'.chessPiece' : function(el){		if (typeof retroSel == "undefined") retroSel = false;		el.onmouseover = function(){			if (sjakkEngine.yourTurn() && sjakkEngine.gameIsOn() && !retroSel){				saveBG = this.style.backgroundColor;				this.style.backgroundColor = "#c0c0c0";			}		}		el.onmouseout = function(){			if (sjakkEngine.yourTurn() && sjakkEngine.gameIsOn()){				if ((this.style.backgroundColor == "#c0c0c0") || (this.style.backgroundColor == "silver") || (this.style.backgroundColor == "rgb(192, 192, 192)")) {					this.style.backgroundColor = saveBG;				}			}		}	},		'#myGamesBar' : function(el){		el.onclick = function(){			if ($('myGamesContent').style.display != "none") {				new Effect.BlindUp($('myGamesContent'));			} else {				new Effect.BlindDown($('myGamesContent'));			}		}	},		'#otherGamesBar' : function(el){		el.onclick = function(){			if ($('otherGamesContent').style.display != "none") {				new Effect.BlindUp($('otherGamesContent'));			} else {				new Effect.BlindDown($('otherGamesContent'));			}		}	},		'#challengesBar' : function(el){		el.onclick = function(){			if ($('challengesContent').style.display != "none") {				new Effect.BlindUp($('challengesContent'));			} else {				new Effect.BlindDown($('challengesContent'));			}		}	},		'#oldGamesBar' : function(el){		el.onclick = function(){			if ($('oldGamesContent').style.display != "none") {				new Effect.BlindUp($('oldGamesContent'));			} else {				new Effect.BlindDown($('oldGamesContent'));			}		}	} ,		'#backToMainMenu' : function(el){			el.onclick = function(){			top.location.href = "index.php?option=com_sjakk&Itemid=28";		}	},		'#cancelGame' : function(el){		el.onclick = function(){			var gameId = Engine.getURLParam("game");			if (confirm(unescape("Vil du virkelig avlyse dette spillet f%F8r det har startet?"))) {	      		var myAjax = new Ajax.Request("components/com_sjakk/sjakkAction.php",{	      			method: 'post', 	      			parameters: "task=cancelGame&gameId=" + gameId,	      			onComplete: function(){						top.location.href = "index.php?option=com_sjakk&Itemid=28";	      			}	      		});			}			}	},		'#resign' : function(el){		el.onclick = function(){			var gameId = Engine.getURLParam("game");			if (sjakkEngine.yourTurn() && sjakkEngine.gameIsOn()) {				if (confirm(unescape("Vil du virkelig overlate seieren til motspilleren? Dette vil f%F8re til fall i rankingen din."))) {		      		var myAjax = new Ajax.Request("components/com_sjakk/sjakkAction.php",{		      			method: 'post', 		      			parameters: "task=playerResigns&gameId=" + gameId,		      			onFailure: function(){		      			},		      			onSuccess: function(){		      				sjakkEngine.updateGame();		      			}		      		});				}				}		}	},			'#offerRemis' : function(el){		el.onclick = function(){			var gameId = Engine.getURLParam("game");			if (!lock) {				if (confirm(unescape("Vil du virkelig foresl%E5 remis? Du m%E5 likevel gj%F8re et trekk for %E5 f%E5 svar."))) {		      		var myAjax = new Ajax.Request("components/com_sjakk/sjakkAction.php",{		      			method: 'post', 		      			parameters: "task=offerRemis&gameId=" + gameId,		      			onFailure: function(){		      			},						onSuccess: function(){		      				sjakkEngine.updateGame();		      			}		      		});				}				}		}	},		'#acceptRemis' : function(el){		el.onclick = function(){			var gameId = Engine.getURLParam("game");			if (!lock) {					if (confirm(unescape("Vil du virkelig godta remis? Spillet vil da ende i uavgjort."))) {		      		var myAjax = new Ajax.Request("components/com_sjakk/sjakkAction.php",{		      			method: 'post', 		      			parameters: "task=acceptRemis&gameId=" + gameId,		      			onFailure: function(){		      			},						onSuccess: function(){		      				sjakkEngine.updateGame();		      			}		      		});				}				}		}	},		'#offerPause' : function(el){		el.onclick = function(){			if (!lock) {				var gameId = Engine.getURLParam("game");				if (confirm(unescape("Vil du virkelig foresl%E5 %E5 sette spillet p%E5 pause? Mostanderen din m%E5 i s%E5fall akseptere f%F8rst. Et spill som har st%E5tt i feriemodus i 3 m%E5neder vil ende i uavgjort."))) {		      		var myAjax = new Ajax.Request("components/com_sjakk/sjakkAction.php",{		      			method: 'post', 		      			parameters: "task=offerPause&gameId=" + gameId + "&activePlayer=" + gameData.playerColor,					    onSuccess: function(){		      				sjakkEngine.updateGame();		      			}		      		});				}				}		}	},		'#acceptPause' : function(el){		el.onclick = function(){			if (!lock) {				var gameId = Engine.getURLParam("game");		      		var myAjax = new Ajax.Request("components/com_sjakk/sjakkAction.php",{		      			method: 'post', 		      			parameters: "task=acceptPause&gameId=" + gameId + "&activePlayer=" + gameData.playerColor,						onSuccess: function(){		      				sjakkEngine.updateGame();		      			}		      		});			}		}	},		'#offerUnPause' : function(el){		el.onclick = function(){			if (!lock) {				var gameId = Engine.getURLParam("game");		      		var myAjax = new Ajax.Request("components/com_sjakk/sjakkAction.php",{		      			method: 'post', 		      			parameters: "task=offerUnPause&gameId=" + gameId + "&activePlayer=" + gameData.playerColor,					    onSuccess: function(){		      				sjakkEngine.updateGame();		      			}					});					}			}	},		'#acceptUnPause' : function(el){		el.onclick = function(){			if (!lock) {				var gameId = Engine.getURLParam("game");		      		var myAjax = new Ajax.Request("components/com_sjakk/sjakkAction.php",{		      			method: 'post', 		      			parameters: "task=acceptUnPause&gameId=" + gameId,						onSuccess: function(){		      				sjakkEngine.updateGame();		      			}		      		});			}		}	},		'a.newGame' : function(el){		if(el.onclick)			return;		var target = el.href.substring(el.href.indexOf('?') + 1);		el.href = "#"+target;		el.onclick = function(){			challengesUpdater.currentlyExecuting = true;			/* commentId = this.getAttributeNode("commentId").value; */			var myAjax = new Ajax.Request("components/com_sjakk/menuAction.php",{	      			method: 'post', 	      			parameters: "task=newGame",	      			onFailure: function(){	      			},					onSuccess: function(req){						$('challengesContent').innerHTML = req.responseText;						$('challengesContent').style.display = "none";						new Effect.BlindDown($('challengesContent')); 						// Element.scrollTo($('challengesContent'));						Behaviour.apply();	      			}	      	});		}	},	'#newGame' : function(el){		if(el.onclick)			return;		var target = el.href.substring(el.href.indexOf('?') + 1);		el.href = "#"+target;		el.onclick = function(){			challengesUpdater.currentlyExecuting = true;			/* commentId = this.getAttributeNode("commentId").value; */			var myAjax = new Ajax.Request("components/com_sjakk/menuAction.php",{	      			method: 'post', 	      			parameters: "task=newGame",	      			onFailure: function(){	      			},					onSuccess: function(req){						$('challengesContent').innerHTML = req.responseText;						$('challengesContent').style.display = "none";						new Effect.BlindDown($('challengesContent')); 						// Element.scrollTo($('challengesContent'));						Behaviour.apply();	      			}	      	});		}	},	'a.withdrawChallenge' : function(el){		if(el.onclick)			return;		var target = el.href.substring(el.href.indexOf('?') + 1);		el.href = "#"+target;		el.onclick = function(){			gameId = this.getAttributeNode("gameId").value;			var myAjax = new Ajax.Request("components/com_sjakk/menuAction.php",{	      			method: 'post', 	      			parameters: "task=withdrawChallenge&gameId=" + gameId,	      			onFailure: function(){	      			},					onSuccess: function(req){						sjakkMenuEngine.updateChallenges();	      			}	      	});		}	},		'a.acceptChallenge' : function(el){		if(el.onclick)			return;		var target = el.href.substring(el.href.indexOf('?') + 1);		el.href = "#"+target;		el.onclick = function(){			gameId = this.getAttributeNode("gameId").value;			var myAjax = new Ajax.Request("components/com_sjakk/menuAction.php",{	      			method: 'post', 	      			parameters: "task=acceptChallenge&gameId=" + gameId,	      			onFailure: function(){	      			},					onSuccess: function(req){						top.location.href = "index.php?option=com_sjakk&task=enterGame&Itemid=28&game=" + gameId;			      			}	      	});		}	},		'a.declineChallenge' : function(el){		if(el.onclick)			return;		var target = el.href.substring(el.href.indexOf('?') + 1);		el.href = "#"+target;		el.onclick = function(){			gameId = this.getAttributeNode("gameId").value;			var myAjax = new Ajax.Request("components/com_sjakk/menuAction.php",{	      			method: 'post', 	      			parameters: "task=declineChallenge&gameId=" + gameId,	      			onFailure: function(){	      			},					onSuccess: function(req){						sjakkMenuEngine.updateChallenges();	      			}	      	});		}	},		'#opponentSelector, #manualInputOpponent' : function(el){		el.onchange = function() {			if (this.value == "") this.value = "brukernavn";			if((this.value != 'anybody') && (this.value != "brukernavn")) {				$('specificUserRadio').checked = true;			} else {				$('anybodyRadio').checked = true;			}		};		el.onclick = function() {			if (this.value == "brukernavn") this.value = "";				$('specificUserRadio').checked = true;		};	},		'#inputEmail' : function(el){		el.onchange = function() {			if (this.value == "") this.value = "motstander@domene.no";			if (this.value != 'motstander@domene.no') {				$('emailUserRadio').checked = true;			} else {				$('anybodyRadio').checked = true;			}			if (!sjakkMenuEngine.validEmail(this.value)) this.focus();		};		el.onclick = function() {			if (this.value == "motstander@domene.no") this.value = "";			$('emailUserRadio').checked = true;		};	},		'#newGameCancel' : function(el){		el.onclick = function(){			oldChallenges ="";			sjakkMenuEngine.updateChallenges();			challengesUpdater.currentlyExecuting = false;		}	},		'#newGameOK' : function(el){		el.onclick = function(){			oldChallenges ="";			if ($F('gameTitleInput') == "") {				alert(unescape("Spillet m%E5 ha en tittel!"));				return;			}			sjakkMenuEngine.registerChallenge();			sjakkMenuEngine.updateChallenges();			challengesUpdater.currentlyExecuting = false;		}	},		'#chatText' : function(el){		el.onclick = function(){			if (escape($('chatText').value) == "Klikk%20her%20for%20%E5%20chatte...") {				$('chatText').value = "";      			      		}		},		el.onkeypress = function(e){			var characterCode;				 if(e && e.which){					e = e;				 	characterCode = e.which;				 }				 else {					e = event;					characterCode = e.keyCode;				 }				 if(characterCode == 13){					chatEngine.doSubmitChat(escape($F('chatText')));					$('chatText').value = "";				 	 return false;				 }			return true;		}	},		'#sound' : function(el){		el.onclick = function(){			if ($('sound').checked) {				sjakkEngine.turnOnSound();			} else {				sjakkEngine.turnOffSound();			}		}	},		'#menuSound' : function(el){		el.onclick = function(){			if ($('menuSound').checked) {				sjakkMenuEngine.turnOnSound();			} else {				sjakkMenuEngine.turnOffSound();			}		}	},		'#PBM' : function(el){		el.onclick = function(){			sjakkEngine.togglePBM();		}	},			'.chessUser' : function(el){		el.onmouseover = function(el){			var chessUserId = this.getAttributeNode("chessUserId").value;			var rating = this.getAttributeNode("chessUserRating").value;			var username = this.getAttributeNode("chessUsername").value;			if(navigator.appName == "Microsoft Internet Explorer") sjakkMenuEngine.showUserStats(event, chessUserId, rating, username);			else sjakkMenuEngine.showUserStats(el, chessUserId, rating, username)		}		el.onmouseout = function(el){			// sjakkMenuEngine.hideUserStats();		}	},	'a.showRunningGames' : function(el){		if(el.onclick)			return;		var target = el.href.substring(el.href.indexOf('?') + 1);		el.href = "#"+target;		el.onclick = function(){			document.cookie = "showActive=0";			sjakkMenuEngine.updateOtherGames();		}	},		'a.showActiveGames' : function(el){		if(el.onclick)			return;		var target = el.href.substring(el.href.indexOf('?') + 1);		el.href = "#"+target;		el.onclick = function(){			document.cookie = "showActive=1";			sjakkMenuEngine.updateOtherGames();		}	},			'.move': function(el){		if (typeof retroSel == "undefined") retroSel = false;		if (typeof retroToggle == "undefined") retroToggle = false;		el.onmouseover = function(){			rollOffId = this.getAttributeNode("id").value;			if (retroSel != this.getAttributeNode("id").value) {				oldMoveColor = this.style.color;				oldMoveBGColor = this.style.backgroundColor;				this.style.backgroundColor = "#DDDDFF";				var board = this.getAttributeNode("board").value;				var fromSquare = this.getAttributeNode("fromSquare").value;				var toSquare = this.getAttributeNode("toSquare").value;		   		retroToggle = true;				setTimeout("sjakkEngine.retroShow('" + board + "', '" + fromSquare + "', '" + toSquare + "', '" + rollOffId + "')", 500);		   	}   		}   		el.onmouseout =  function(){   			if (retroSel != this.getAttributeNode("id").value) {	 			this.style.backgroundColor = oldMoveBGColor;	 			this.style.color = oldMoveColor;	 		}		    retroToggle = false;		    setTimeout("sjakkEngine.retroOff()", 500);    	}     	el.onclick = function() {    		if (retroSel) {	 			$(retroSel).style.backgroundColor = oldMoveBGColor; 				$(retroSel).style.color = oldMoveColor;			}			if (retroSel != this.getAttributeNode("id").value) {				retroSel = this.getAttributeNode("id").value;				this.style.backgroundColor = "black";				this.style.color = "white";				if (!retroToggle) {		    		retroToggle = true;		    		rollOffId = retroSel;					sjakkEngine.retroShow(this.getAttributeNode("board").value, $(retroSel).getAttributeNode("fromSquare").value, $(retroSel).getAttributeNode("toSquare").value, rollOffId); 				}			} else {			    sjakkEngine.generate_board(gameData.FEN);	    		$('sjakkbrett').innerHTML = sjakkEngine.output_board();	    		sjakkEngine.highlightLastMove();		    	sjakkEngine.renderCapturedPieces();					  			sjakkEngine.uncheckPieces();	    		Behaviour.apply();	    		retroToggle = false; 		    	retroSel = false;   						}	    	}	}};Behaviour.register(chessRules);