﻿var newwindow = '';
var RSplayers = 2;
var RSScore = 0;
var RSSum = 0;

if(document.getElementById('imgLoadPixels')!=null)
{
	document.getElementById('imgLoadPixels').src="http://67.227.197.129/LoadPixels.aspx?" + window.location.search.substring(1);
}
    
function popitup(url) {
  	url += "&rand=" + (Math.round((Math.random()*1000)+1));
	if (!newwindow.closed && newwindow.location) {
		newwindow.location.href = url;
	}
	else {
		newwindow=window.open(url,'domino','height=600,width=860,toolbar=no,location=no,status=no,menubar=no,scrollbars=no');
		
		if (!newwindow.opener) newwindow.opener = self;
	}
	if (window.focus) {newwindow.focus()}
	//return false;
}

function popitup2(url) {
  	url += "&rand=" + (Math.round((Math.random()*1000)+1));
	if (!newwindow.closed && newwindow.location) {
		newwindow.location.href = url;
	}
	else {
		newwindow=window.open(url,'domino','height=600,width=860');
		
		if (!newwindow.opener) newwindow.opener = self;
	}
	if (window.focus) {newwindow.focus()}
	//return false;
}

function tour(){
	newwindow=window.open('/tour.html','domino','height=470,width=700');
}

// Calls AJAX function that caclulates Rake.
function calculateRakedSum()
{
    //RSplayers = document.getElementById("RSPlayersField").value;
    RSScore = document.getElementById("RSScoreField").value;
    RSSum = document.getElementById("RSSumField").value;
    DominoService.GetRake(RSplayers, RSScore, RSSum, onCalculateRakedSum);
}

// calculateRakedSum function callback.
function onCalculateRakedSum(ret)
{
    // calculate and place result.
    document.getElementById("rake_result").innerHTML = "The fee will be: " + ((RSSum * ret) / 100) + "$";
}

function onPlayersChanged(value)
{
    // More than 2 Players.
    RSplayers = value;
    var RSsel = document.getElementById("RSScoreField");

    while (RSsel.options.length > 0)
    {
        RSsel.options[0] = null;
    }
    
    RSsel.options[RSsel.length] = new Option('200', '200');
    RSsel.options[RSsel.length] = new Option('400', '400');
}

function onPlayersChanged1(value)
{
    // 2 Players.
    RSplayers = value;
    var RSsel = document.getElementById("RSScoreField");
    while (RSsel.options.length > 0)
    {
        RSsel.options[0] = null;
    }
    
    RSsel.options[RSsel.length] = new Option('100', '100');
    RSsel.options[RSsel.length] = new Option('250', '250');
    RSsel.options[RSsel.length] = new Option('500', '500');
}

// onkeydown=""TypingNumbers(event);"
function TypingNumbers(evnt)
{
  try
  {
    if (evnt==null)
    {
      evnt=event;
    }
    if (((evnt.keyCode < 48) || (evnt.keyCode > 57)) && (evnt.keyCode!=8))  
    {
      evnt.returnValue = false;
      return false;
    }
    else if ((evnt.keyCode > 48) && (evnt.keyCode < 57) && (evnt.shiftKey) || (evnt.shiftLeft))
    {
      evnt.returnValue = false;
      return false;
    }
  }
  catch(ex){}
}

var ns = (navigator.appName.indexOf("Netscape") != -1);
var d = document;
function floatingButtons(id, sx, sy, oy)
{
	var el=d.getElementById?d.getElementById(id):d.all?d.all[id]:d.layers[id];
	var px = document.layers ? "" : "px";
	window[id + "_obj"] = el;
	if(d.layers)el.style=el;
	el.cx = el.sx = sx;el.cy = el.sy = sy;el.oy=oy + 130;
	el.sP=function(x,y){
		this.style.left=x+px;
		//y = (y > this.oy) ? (y-this.oy) : y;
		y -= this.oy;
		y = (y < 0) ? 0 : y;
		this.style.top=y+px;
	};

	el.floatButtons=function()
	{
		var pX, pY;
		pX = (this.sx >= 0) ? 0 : ns ? innerWidth : 
		document.documentElement && document.documentElement.clientWidth ? 
		document.documentElement.clientWidth : document.body.clientWidth;
		pY = ns ? pageYOffset : document.documentElement && document.documentElement.scrollTop ? 
		document.documentElement.scrollTop : document.body.scrollTop;
		if(this.sy<0) 
		pY += ns ? innerHeight : document.documentElement && document.documentElement.clientHeight ? 
		document.documentElement.clientHeight : document.body.clientHeight;
		//alert(pY);
		this.cx += (pX + this.sx - this.cx)/8;
		this.cy += (pY + this.sy - this.cy)/8;
		this.sP(this.cx, this.cy);
		setTimeout(this.id + "_obj.floatButtons()", 40);
	}
	return el;
}
    function detectPopupBlocker()
    {
        var testBlock = window.open('','','width=1,height=1,left=0,top=0,scrollbars=no');
        var popUpsBlocked;
        if(testBlock)
           popUpsBlocked = false
        else
           popUpsBlocked = true
        testBlock.close();
        if(popUpsBlocked)
        {
            alert('We have detected that you are using popup blocking software.\nDominoesStars requires you to disable any popup blocker...');
        }
        return popUpsBlocked;
    }
function tutorialOpen(url)
{
  
   tutorial = window.open(url,'Domino','width=700,height=470,left=100,top=100,screenx=0,screeny=100,resizable=0,location=0,scrollbar=0,toolbar=0',false);
  
   //tutorial.moveTo(0,100);
    //window.location.href+
    //location=0,status=0,scrollbars=0,,left=100,top=100,screenx=0,screeny=100');
}
