﻿function $getId(id)
{
    return document.getElementById(id);
}

function ShowLounge()
{
    window.open('https://online.32deck.com/', 'quickPlay', 'fullscreen=yes, menubar=no, resizable=no, scrollbars=no, status=yes, toolbar=no');
}

function openCasino(game)
{
    var wUrl = "http://www.32deck.com/APis/casino.aspx?game=" + game + "&sId=" + sId;
    var wCasino = window.open(wUrl, '_blank', 'fullscreen=yes, menubar=no, resizable=no, scrollbars=no, status=yes, toolbar=no');
}


//Used for Client-Side Validation
function IsDropDownValueWasChosen(source, args)
{
    if (args.Value == "0")
        args.IsValid = false;
    else
        args.IsValid = true; 
}    

function ResizeLightWindow(_width, _height)
{
    if (self.parent.myLightWindow.resizeTo.height == _height && self.parent.myLightWindow.resizeTo.width == _width)
        return;
        
	self.parent.myLightWindow._getScroll();
	self.parent.myLightWindow._browserDimensions();
	self.parent.myLightWindow._setupDimensions();

	self.parent.myLightWindow._setStatus(true);
    self.parent.myLightWindow.resizeTo.height=_height;
    self.parent.myLightWindow.resizeTo.width=_width;

    self.parent.myLightWindow.dimensions.container = {height: self.parent.document.getElementById('lightwindow_container').getHeight(), width: self.parent.document.getElementById('lightwindow_container').getWidth()};
	self.parent.myLightWindow._resizeWindowToFit(); // Even if the window is preset we still don't want it to go outside of the viewport

	if (!self.parent.myLightWindow.windowActive) {
		// Position the window
	   	self.parent.document.getElementById('lightwindow_container').setStyle({
			left: -(self.parent.myLightWindow.dimensions.container.width/2)+'px',
			top: -(self.parent.myLightWindow.dimensions.container.height/2)+'px'
		});
	}
   	self.parent.document.getElementById('lightwindow_container').setStyle({
		height: self.parent.myLightWindow.dimensions.container.height+'px',
		width: self.parent.myLightWindow.dimensions.container.width+'px'
	});
	
	// We are ready, lets show this puppy off!
	self.parent.myLightWindow._displayLightWindow('block', 'visible');
	self.parent.myLightWindow._defaultAnimationHandler();
}


function getFlashMovieObject(movieName){      if (window.document[movieName])       {          return window.document[movieName];      }      if (navigator.appName.indexOf("Microsoft Internet")==-1)      {        if (document.embeds && document.embeds[movieName])          return document.embeds[movieName];       }      else // if (navigator.appName.indexOf("Microsoft Internet")!=-1)      {        return document.getElementById(movieName);      }}


function openNewWindow(url, iWidth, iHeight)
{
    var newWin = window.open(url,'mywindow','width=' + iWidth + ',height=' + iHeight + ',toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,copyhistory=no, resizable=yes'); 
}

function IsAgreeCheckBoxChecked(source, args)
{
    var selOk = false;
    var leng = document.getElementsByTagName("Input").length
    for (var i = 0; i < leng ;i++)
        if (document.getElementsByTagName("Input").item(i).type == 'checkbox')
            if(document.getElementsByTagName("Input").item(i).checked && document.getElementsByTagName("Input").item(i).id.indexOf('chkAgree') >= 0)
                selOk = true;
                
    if (selOk)
        args.IsValid = true;
    else
        args.IsValid = false;
}

function isNumberKey(evt)
{
    var charCode = (evt.which) ? evt.which : event.keyCode
    if (charCode > 31 && (charCode < 48 || charCode > 57))
        return false;

    return true;
}

function HighlightAll(theField)
{
    //var tempval=eval("document."+theField);
    theField.focus();
    theField.select();
    therange=theField.createTextRange()
}



function _tmp_validateCreditCard(source, args)
{
    // remove non-numerics
    var s = args.Value;
    var v = "0123456789";
    var w = "";
    for (i=0; i < s.length; i++)
    {
        x = s.charAt(i);
        if (v.indexOf(x,0) != -1)
            w += x;
    }
    // validate number
    j = w.length / 2;
    if (j < 6.5 || j > 8 || j == 7)
    {
        args.IsValid = false;
        return;
    }
    k = Math.floor(j);
    m = Math.ceil(j) - k;
    c = 0;
    for (i=0; i<k; i++)
    {
        a = w.charAt(i*2+m) * 2;
        c += a > 9 ? Math.floor(a/10 + a%10) : a;
    }
    for (i=0; i<k+m; i++)
        c += w.charAt(i*2+1-m) * 1;

    if (c%10 == 0)
        args.IsValid = true;
    else
        args.IsValid = false;        
}

function ShowCashOutDiv(id)
{
    document.getElementById('divBankTransfer').style.display = 'none';
    document.getElementById('divCreditCard').style.display = 'none';
    document.getElementById('divPayPal').style.display = 'none';
    document.getElementById('divMoneybookers').style.display = 'none';

    document.getElementById(id).style.display = 'block';
}

////// NEXT DRAW TIME /////////

function ShowNextDraw()
{
    var hours;
    var minutes;
    var seconds;
    
    //dateNow = new Date();                                    //grab current date
    amount = dateFuture.getTime() - serverdate.getTime();        //calc milliseconds between dates
    var mili = amount.toString();
    //alert(amount);
    mili = mili.substr((mili.length - 3),3);
    delete dateNow;

    // time is already past
    if(amount < 0){
        document.getElementById('divNextDrawTime').innerHTML="Now!";
    }
    // date is still good
    else{
        days=0;hours=0;mins=0;secs=0;out="";

        amount = Math.floor(amount/1000);//kill the "milliseconds" so just secs

        days=Math.floor(amount/86400);//days
        days = twoDigit(days)
        amount=amount%86400;

        hours=Math.floor(amount/3600);//hours
        hours = twoDigit(hours)
        amount=amount%3600;

        mins=Math.floor(amount/60);//minutes
        mins = twoDigit(mins)
        amount=amount%60;

        secs=Math.floor(amount);//seconds
        secs = twoDigit(secs)

        out += hours + ":" + mins + ":" + secs + "";
        document.getElementById('divNextDrawTime').innerHTML=out;

        setTimeout("ShowNextDraw()", 1000);
    }
}

function twoDigit(_v)
{
  if(_v<10)_v="0"+_v;
  return _v;
}



////// SERVER TIME /////////
var montharray=new Array("January","February","March","April","May","June","July","August","September","October","November","December")

function padlength(what)
{
    var output=(what.toString().length==1)? "0"+what : what
    return output
}

function ShowServerTime()
{
    serverdate.setSeconds(serverdate.getSeconds()+1)
    var datestring=montharray[serverdate.getMonth()]+" "+padlength(serverdate.getDate())+", "+serverdate.getFullYear()
    var timestring=padlength(serverdate.getHours())+":"+padlength(serverdate.getMinutes()) + " GMT"
    document.getElementById("divServerTime").innerHTML=datestring+" "+timestring
    
    setTimeout("ShowServerTime()", 1000);
}


//Preload for all the images on the games
var preloads=[]; 
function preload()
{ 
    for(var c=0;c<arguments.length;c++)
    { 
        preloads[preloads.length]=new Image(); 
        preloads[preloads.length-1].src=arguments[c]; 
    } 
} 


//Registration Span
function onBlurSpan(what)
{
    document.getElementById(what).style.display = 'none';
}

function onFocusSpan(what)
{
    document.getElementById(what).style.display = 'inline';
}


function CheckValidationForLoginHeader(emailControl, passwordControl)
{
    var isGood = true;
    var sEmail = document.getElementById(emailControl).value;
    var sPassword = document.getElementById(passwordControl).value;

    var emailRegEx = '\\w+([-+.]\\w+)*@\\w+([-.]\\w+)*\\.\\w+([-.]\\w+)*';
    var passwordRegEx = '[^\\s]{6,20}';

    if (sEmail.search(emailRegEx) == -1)
    {
        document.getElementById(emailControl).style.border='solid 1px #cc0000';
        isGood = false;
    }
    if (sPassword.search(passwordRegEx) == -1)
    {
        document.getElementById(passwordControl).style.border='solid 1px #cc0000';
        isGood = false;
    }

    return isGood;
}

function showTicket(id)
{
    if (document.getElementById(id).style.display == 'none')
        document.getElementById(id).style.display = '';	  
    else
        document.getElementById(id).style.display = 'none';
}

function startOnLoad()
{
    jQuery("#choose_language").toggle(function()
        {
            jQuery('#languages').slideDown(200);
        }, function()
        {
            jQuery('#languages').slideUp(200);
        }
    );
}

preload('/images/loadingAnimation.gif', '/images/HeaderArrowDivider.png'); 

