﻿function usernameValidation(str){
  var parsed = true;
  var validchars = "abcdefghijklmnopqrstuvwxyz0123456789";
  //var email = prompt("What is your email address?", "nobody@nowhere.com");
  
  for (var i=0; i < str.length; i++) {
    var letter = str.charAt(i).toLowerCase();
    if (validchars.indexOf(letter) != -1)
      continue;
    alert("Invalid character: " + letter);
    parsed = false;
    break;
  }
  
  if (parsed) return true//alert("Your email address contains all valid characters.");
  else return false
}


function isValidemail(email){ 
	validregexp = /^[^@]+@[^@]+.[a-z]{2,}$/i; 
	stremail = email;
	 if(stremail!="")
	{ // search email text for regular exp matches
 		if (stremail.search(validregexp) == -1) {
			alert('Please enter a valid e-mail address');
			//document.form1.email.value=""; 
			//document.form1.email.focus();
 			return false;
 		} else
			return true;
	}else
		return true
} 

function winOpen(url)
{
	if(url=="")
	{
		 win = window.open("terms.htm","terms","width=620,height=700,resizable=1,scrollbars=1")
	}
	else
	{
		win = window.open(url,"terms","width=665,height=620,resizable=1,scrollbars=0")
	}
	
} 

function bookmarksite(title, url)
{
	if (document.all)
    	window.external.AddFavorite(url, title);
	else if (window.sidebar)
	    window.sidebar.addPanel(title, url, "")
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.0
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && document.getElementById) x=document.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function login()
{
	if(!usernameValidation(document.LogInForm.username.value))
	{
		document.LogInForm.username.focus();
		return false
	}
	if(!usernameValidation(document.LogInForm.password.value))
	{
		document.LogInForm.password.focus();
		return false
	}
	if(document.LogInForm.username.value == "")
	{
		alert("Please fill your username.")
		document.LogInForm.username.focus();// = true;
	 return false
	} 
	if(document.LogInForm.password.value == "")
	{
		alert("Please fill your passowrd.")
		document.LogInForm.password.focus();
	 return false
	}
	//document.LogInForm.action = "https://www.treasureonnet.com/newdesign/default.asp"
	document.LogInForm.action = "login.asp";
	document.LogInForm.submit()
}



function CheckRegistrationForm()
{
	if(document.form1.UserID.value.length<4){
		alert("Username must be at least 4  character!")
		return
	}
	if(document.form1.password.value.length<4 ){
		alert("Passowrd must be at least 4  character!")
		return
	}
	if(document.form1.UserID.value == ""){
		alert("You must supply your UserID.")
		return
	}
	if(document.form1.password.value == ""){
		alert("You must supply your password.")
		return
	}
	if(document.form1.password.value != document.form1.password2.value){
		alert("Your passwords do not match.  Please re-enter your password (twice).")
		return
	}
	
	email = document.form1.email.value
	if (email == ""){
		alert("You must supply your Email.");
		return
	}
	
	if(!document.form1.terms.checked){
		alert("To continue you must agree to the Terms & Conditions. ")
		return
	}
	if (isValidemail(email) && usernameValidation(document.form1.UserID.value) && usernameValidation(document.form1.password.value) )
		document.form1.submit();
}

function jumptoGame(game)
{
    var strGame = new String();
   /* switch(game)
    {
        case 'bigChance':
            strGame = 'bigChance';
            break;
        case 'journey':
            strGame = '4x4journey';
            break;
        case 'hugeTreasure':
            strGame = 'hugetreasure';
            break;
        case 'stepByStep':
            strGame = 'stepByStep';
            alert("Coming Soon.")
            return;
            break;
        case 'soEasy':
            strGame = 'game';
            break;
        case 'treasureCircle':
            strGame = 'scratch256';
            break;
        case 'magnificentPrize':
            strGame = 'scratch4x4';
            break;
        case 'stepByStep2':
            strGame = 'scratc9';
            break;
        case 'theMagicCard':
            strGame = 'cardGame';
            break;
    }*/

	document.lobby.game.value = game
	document.lobby.submit();
}

function helpWin(gameId)
{
	if (gameId == "bigChance"){
		url = "HowToPlayBigChance.asp"
	}else if(gameId == "journey"){
		url = "HowToPlay4x4Journey.asp"
	}else if(gameId =="stepByStep"){
		url = "HowToPlayStepByStep.asp"
	}else if(gameId == "hugeTreasure"){
		url = "HowToPlayHugeTreasure.asp"
	}else if(gameId=="theMagicCard"){
		url = "HowToPlayTheMagicCard.asp"
	}else if(gameId=="soEasy"){
		url = "HowToPlaySoEasy.asp"
	}else if(gameId=="treasureCircle"){
		url = "HowToPlayTreasureCircle.asp"
	}else if(gameId=="magnificentPrize"){
		url = "HowToPlayMagnificentPrize.asp"
	}else if(gameId=="stepByStep2"){
		url = "HowToPlayStepByStep1.asp"
	}
	helpwin = window.open(url,"help","width=665,height=625,resizable=1,scrollbars=0")
}

function CheckDepositForm()
{
    if(document.form1.item1_price.value>1000  )
    {
        alert("Maximum deposit 1000$.")
        return;
    }else if(isNaN(document.form1.item1_price.value)||document.form1.item1_price.value<25 ||document.form1.item1_price.value=="" ){
        alert("Minimum deposit amount is $25.")
        return 
    }else	if(document.form1.cust_country.selectedIndex ==0){
        alert("Card holder Country must be selected.")
        return 
    }

    if(document.form1.cust_name.value == ""){
        alert("Customer Name is a required field.")
        return 
    }

    if(document.form1.cust_address1.value == ""){
        alert("Customer Address is a required field.")
        return 
    }

    if(document.form1.cust_zip.value == ""){
        alert("Customer ZipCode is a required field.")
        return 
    }

    if(document.form1.cust_city.value == ""){
        alert("Customer City is a required field.")
        return 
    }

    if(document.form1.cust_email.value == ""){
        alert("Customer Email is a required field.")
        return 
    }

    if(document.form1.cust_city.value == ""){
        alert("Customer City is a required field.")
        return 
    }

    if(document.form1.cust_phone.value == ""){
        alert("Customer Phone is a required field.")
        return 
    }

    if(isValidemail(document.form1.cust_email.value))
        document.form1.submit()
}

function doBack(){
	parent.document.location.href = "LobbyR.asp?st=1"
}

function CheckOutChangeDivForm(Name){
	if(Name == "check"){
	    document.getElementById('Cashout_MailingAddress').style.display='block';
	    document.getElementById('Cashout_BankDetails').style.display='none';
	}else{
	    document.getElementById('Cashout_MailingAddress').style.display='none';
	    document.getElementById('Cashout_BankDetails').style.display='block';

	}
	return true
}

function CheckMailingAddressForm()
{
 	amount = document.form1.amount.value;
 	
	if(amount<=0 || isNaN(amount)){
		alert("Amount can't be 0.")
	}else if(amount<150)	{
		alert("Minimum withdrawal is $150.")
	}else if(document.form1.fn.value==""){
		alert("Please fill in your first name.")
	}else if(document.form1.ln.value==""){
		alert("Please fill in your surname.")
	}else if(document.form1.address.value==""){
		alert("Please fill in your address.")
	}else if(document.form1.zip.value==""){
		alert("Please fill in your zip code.")
	}else if(document.form1.country.value==""){
		alert("Please fill in your country.")
	}else{
		document.form1.submit();
	}
}

function CheckBankAddressForm(){
	amount = document.form2.amount.value;
	
	if(amount<=0 || isNaN(amount)){
		alert("Amount can't be 0.")
		//return false
	}else if(amount<150){	
		alert("Minimum withdrawal is $150.")
		
	}else if(document.form2.country.value==""){
		alert("Please fill in your country.")
		//return false		
	}else if(document.form2.bank_name.value==""){
		alert("Please fill in your bank name.")
		//return false		
	}else if(document.form2.iban.value==""){
		alert("Please fill in your IBAN/Acount#.")
		//return false		
	}else
		document.form2.submit();
}




function OnSupportFormSubmit()
{
    try
    {
        if(document.getElementById('subject').selectedIndex==0)
        {
            alert('Please select a subject.');
            return;
        }
        document.getElementById('frmSupport').submit();
    }
    catch(e)
    {
        //todo: add debug and log mode.
    }
}



function scroller(obj,isVertical,speed){
    try{
        if(speed!=null){
            this.scrollSpeed = speed;
        }
        if(document.getElementById(obj)){
            this.init(document.getElementById(obj),isVertical);
        }
    }catch(e){
        alert(e.description)
    }
}

scroller.prototype = {
    scrollerheight : null,
    scrollerspeed : 1,
    scrollercontent : null,
    pauseit : 1,
    copyspeed : null,
    iedom : null,
    actualheight : null,
    actualWidth : null,
    cross_scroller : null,
    ns_scroller : null,
    pausespeed : null,
    lefttime : null,
    scrollSpeed : (document.all)?100:45,
    isVertical : true,
    isStop : true,
    init : function(obj,isVertical){
        this.scrollerspeed = (document.all)?this.scrollerspeed:Math.max(1, this.scrollerspeed-1) //slow speed down by 1 for NS
        this.copyspeed = this.scrollerspeed;
        this.iedom = document.all||document.getElementById;
        this.pausespeed = (this.pauseit==0)?this.copyspeed:0;
        this.element = obj;
        this.scrollerheight = obj.offsetHeight;
        this.isVertical = isVertical?true:false;
        var scroller = this;
        this.element.onmouseover=function(){
            scroller.stop();
        }
        this.element.onmouseout=function(){
            scroller.start()
        }
        this.populate();
        this.start();
    },
    stop : function(){
        clearInterval(this.lefttime);
        this.isStop = true;
    },
    start : function(){
        this.lefttime = null;
        this.isStop = false;
        var scroll = this;
        this.lefttime = setInterval(function(){
            scroll.scrollscroller();           
        },this.scrollSpeed);
    },
    populate : function(){
        if (this.iedom){
            this.cross_scroller = this.element;
            if(this.isVertical){
                this.cross_scroller.style.top = parseInt(this.element.parentNode.offsetHeight) + 2 + "px";
                this.actualheight = this.cross_scroller.offsetHeight;
            }else{
                this.cross_scroller.style.left = parseInt(this.element.parentNode.offsetWidth) + 2 + "px";
                this.actualWidth = this.cross_scroller.offsetWidth;
            }
        }
        this.element.style.display = 'block';
    },
    scrollscroller : function(){
        if (this.iedom){
            if(this.isVertical){
                if (parseInt(this.cross_scroller.style.top)>(this.actualheight*(-1)+8)){
                    this.cross_scroller.style.top = parseInt(this.cross_scroller.style.top)-this.copyspeed+"px";
                } else { 
                    this.cross_scroller.style.top = parseInt(this.element.parentNode.offsetHeight) + 2 + "px";
                }
            }else{
                
                if((parseInt(this.cross_scroller.style.left)+140)<this.cross_scroller.parentNode.style.left){    
                    this.cross_scroller.style.left = parseInt(this.cross_scroller.style.left)+ 140 + "px";
                    doRotation();
                    //clearInterval(this.lefttime);
                }
                
                //this.cross_scroller.style.left = parseInt(this.cross_scroller.style.left)-this.copyspeed+"px";
                if (parseInt(this.cross_scroller.style.left)>((this.actualWidth*-1)-50)){
                    this.cross_scroller.style.left = parseInt(this.cross_scroller.style.left)-this.copyspeed+"px";
                } else { 
                    this.cross_scroller.style.left = parseInt(this.element.parentNode.offsetWidth) + 2 + "px";
                }
            }
        }   
    }
    
}

function doRotation(){
    if(document.all){
        var table = document.getElementById('gamesIcons');
        var tableRow = table.rows(0);
        var firstChild = tableRow.childNodes.item(0);
        tableRow.appendChild(firstChild)
    }else{
        var tableRow = document.getElementById('gamesIconsRow');
        tableRow.appendChild(tableRow.childNodes.item(0))
    }
}
