function validate_ukash(){
		
		//Check all required fields are filled in.
		var req_fields = new Array("vouchernumber", "vouchervalue");
		
		for (x in req_fields){
			if(!notEmpty(document.getElementById(req_fields[x])))
				return false;
		}
		
		if(document.getElementById('vouchervalue').value < 10)
		{
				alert('The minimum deposit amount is 10');
				return false;
		}

    return true;
}



function validate_lps()
{
	//Check all required fields are filled in.
		var req_fields = new Array("amount","cardnumber","securitynumber");
		
		for (x in req_fields){
			if(!notEmpty(document.getElementById(req_fields[x])))
				return false;
		}

 		var num_fields = new Array("amount","cardnumber","securitynumber");
 			
 		for (x in num_fields){
			if(!isNumeric(document.getElementById(num_fields[x]),'Field must contain numbers only.'))
				return false;
		}
		
		if(document.getElementById('amount').value < 10)
		{
				alert('The minimum deposit amount is 10');
				return false;
		}
		    	
    return true;
}

function popUp(aurl, wwidth, hheight, popname){
    
        var nocache = new Date().getTime();
        var ttop = (screen.height-hheight)/2;
        if (ttop < 0) ttop = 10;
        var lleft = (screen.width-wwidth)/2;
        if (lleft < 0) lleft = 10;
    
        window.open(aurl,popname,'width='+wwidth+', scrollbars=1, height='+hheight+',top='+ttop+',left='+lleft+'');
}


function popupform(myform)
{
	if (! window.focus)return true;
	window.open('', 'formpopup', 'width=800,height=600,scrollbars=no');
	myform.target='formpopup';
	myform.submit();
}

function showErrorValidation(msg){
	alert(msg);
}

function MM_findObj(n, d) { //v4.01
  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 && d.getElementById) x=d.getElementById(n); return x;
}

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_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 preloadButtonsResources(){
	MM_preloadImages('images/inner_pages/home_btn_f2.gif','images/inner_pages/getstarted_btn_f2.gif','images/inner_pages/help_btn_f2.gif','images/inner_pages/times_btn_f2.gif','images/inner_pages/games_btn_f2.gif','images/inner_pages/promo_btn_f2.gif','images/inner_pages/team_btn_f2.gif','images/inner_pages/winners_btn_f2.gif','images/inner_pages/rules_btn_f2.gif','images/inner_pages/contact_btn_f2.gif');
}


function launchGame(wwidth, hheight, game){
    
       // if (game == 'PARLAY90BINGO' || game == 'PARLAY75BINGO' ) {
		
	//	var aurl = "./instant-bingo.php?game="+game+"&width="+wwidth+"&height="+hheight;
		
	//	}
	//	else {
		
		var aurl = "./playgame.php?game="+game+"&width="+wwidth+"&height="+hheight;
		
	//	}
        var game_name = 'game';
        
        var nocache = new Date().getTime();
        var ttop = (screen.height-hheight)/2;
        if (ttop < 0) ttop = 10;
        var lleft = (screen.width-wwidth)/2;
        if (lleft < 0) lleft = 10;
        
        if(game == 'XGBINGO')
            game_name = 'bingo'
        else
        {
           // wwidth = '900';
           // hheight = '600';
        }
    
        window.open(aurl,game_name,'width='+wwidth+',height='+hheight+',top='+ttop+',left='+lleft+'');
		
		
}

function launchWalpay(aurl){
    
        var wwidth =  550;
        var hheight = 650;
    
        var nocache = new Date().getTime();
        var ttop = (screen.height-hheight)/2;
        if (ttop < 0) ttop = 10;
        var lleft = (screen.width-wwidth)/2;
        if (lleft < 0) lleft = 10;
    
        window.open(aurl,'walpay','width='+wwidth+', scrollbars=1, height='+hheight+',top='+ttop+',left='+lleft+'');
}


function launchCB(aurl){
    
        var wwidth =  550;
        var hheight = 650;
    
        var nocache = new Date().getTime();
        var ttop = (screen.height-hheight)/2;
        if (ttop < 0) ttop = 10;
        var lleft = (screen.width-wwidth)/2;
        if (lleft < 0) lleft = 10;
    
        window.open(aurl,'walpay','width='+wwidth+', scrollbars=1, height='+hheight+',top='+ttop+',left='+lleft+'');
}


function OurGameLauncher(){
        var wwidth = 800;

        var is = new Is();

        if (is.ie6up) {
                var hheight = 640;
        }
        else{
                var hheight = 600;
        }

        var nocache = new Date().getTime();
        var ttop = (screen.height-hheight)/2;
        if (ttop < 0) ttop = 10;
        var lleft = (screen.width-wwidth)/2;
        if (lleft < 0) lleft = 10;

        window.open('?page=PlayOurGames&nocache='+nocache,'ActiveOurGameWindow','width='+wwidth+',height='+hheight+',top='+ttop+',left='+lleft+',scrollbars=yes,resizable=yes');
}



function openPage(page){
	window.location=page;
}


function openWin(url) { //v2.0
  /*if (url.indexOf("stream_launcher.page") !=-1)
  {
	alert("Service not available");
  	return;
  }
  */
  window.open(url,'','width=800,height=600');

}

function play(){
openWin('stream_launcher.page?base=bingo&game=bingo',"bingo");
}

function launch_slots()
{
	openWin('game_launcher.page?base=slots&game=bingo',"bingo");
}

function launch_videopoker()
{
	openWin('game_launcher.page?base=videoPoker&game=bingo',"bingo");
}

function openWinSpec(url,w,h) { //v2.0
  openWinSpec2(url,'',w,h,'');
}

function openWinSpec2(url,name,w,h,features) { //v2.0
  window.open(url,'','width='+w+',height='+h+','+features);
}

function switchPicture(objectid, pic1, pic2) {
	img = document.getElementById(objectid);
	current = img.src;
	if(current.indexOf(pic1)>0) img.src=pic2; else img.src=pic1;
}

function register()
{
	openPage('Register');
}

function cashier()
  {
  	if(window.opener !=null){
  		window.opener.location='deposit.page';
		this.close();
	}
	else
	{
		window.location='deposit.page';
	}
}

function my_account()
  {
  	if(window.opener !=null){
  		window.opener.location='account.page';
	}
	else
	{
		window.location='account.page';
	}
}


// Browser Type and Version Checking Object
function Is()
{   var agt=navigator.userAgent.toLowerCase();

    this.major = parseInt(navigator.appVersion);
    this.minor = parseFloat(navigator.appVersion);

    this.nav  = ((agt.indexOf('mozilla')!=-1) && ((agt.indexOf('spoofer')==-1)
                && (agt.indexOf('compatible') == -1)));
    this.nav2 = (this.nav && (this.major == 2));
    this.nav3 = (this.nav && (this.major == 3));

    this.nav4 = (this.nav && (this.major == 4));
    this.nav4up = (this.nav && (this.major >= 4));
    this.navonly      = (this.nav && ((agt.indexOf(";nav") != -1) ||
                          (agt.indexOf("; nav") != -1)) );
    this.nav6 = (this.nav && (this.major == 5));
    this.nav6up = (this.nav && (this.major >= 5));
    this.gecko = (agt.indexOf('gecko') != -1);


    this.ie     = ((agt.indexOf("msie") != -1) && (agt.indexOf("opera") == -1));
    this.ie3    = (this.ie && (this.major < 4));
    this.ie4    = (this.ie && (this.major == 4) && (agt.indexOf("msie 4")!=-1) );
    this.ie4up  = (this.ie && (this.major >= 4));
    this.ie5    = (this.ie && (this.major == 4) && (agt.indexOf("msie 5.0")!=-1) );
    this.ie5_5  = (this.ie && (this.major == 4) && (agt.indexOf("msie 5.5") !=-1));
    this.ie5up  = (this.ie && !this.ie3 && !this.ie4);
    this.ie5_5up =(this.ie && !this.ie3 && !this.ie4 && !this.ie5);
    this.ie6    = (this.ie && (this.major == 4) && (agt.indexOf("msie 6.")!=-1) );
    this.ie6up  = (this.ie && !this.ie3 && !this.ie4 && !this.ie5 && !this.ie5_5);

    // KNOWN BUG: On AOL4, returns false if IE3 is embedded browser
    // or if this is the first browser window opened.  Thus the
    // variables this.aol, this.aol3, and this.aol4 aren't 100% reliable.
    this.aol   = (agt.indexOf("aol") != -1);
    this.aol3  = (this.aol && this.ie3);
    this.aol4  = (this.aol && this.ie4);
    this.aol5  = (agt.indexOf("aol 5") != -1);
    this.aol6  = (agt.indexOf("aol 6") != -1);

    this.opera = (agt.indexOf("opera") != -1);
    this.opera2 = (agt.indexOf("opera 2") != -1 || agt.indexOf("opera/2") != -1);
    this.opera3 = (agt.indexOf("opera 3") != -1 || agt.indexOf("opera/3") != -1);
    this.opera4 = (agt.indexOf("opera 4") != -1 || agt.indexOf("opera/4") != -1);
    this.opera5 = (agt.indexOf("opera 5") != -1 || agt.indexOf("opera/5") != -1);
    this.opera5up = (this.opera && !this.opera2 && !this.opera3 && !this.opera4);

    this.webtv = (agt.indexOf("webtv") != -1);

    this.TVNavigator = ((agt.indexOf("navio") != -1) || (agt.indexOf("navio_aoltv") != -1));
    this.AOLTV = this.TVNavigator;

    this.hotjava = (agt.indexOf("hotjava") != -1);
    this.hotjava3 = (this.hotjava && (this.major == 3));
    this.hotjava3up = (this.hotjava && (this.major >= 3));


    this.vms   = (agt.indexOf("vax")!=-1) || (agt.indexOf("openvms")!=-1);
}

function open_bingo_assistant()
{
    window.open("/bingo-assistant.php","BingoAssistant","width=850,height=590,scrollbars=yes");
}


function notloggedin(){
	//alert('You must be logged in to play the games.');
	window.location = "/register.php?sender=notloggedin"
}

function closeAndRefreshPage()
{
	window.opener.location.reload( true );
	window.close();
}

function notEmpty(elem){
	
	if(elem.value.length == 0){
		alert("Please make sure you fill in the "+elem.name+" field");
		elem.focus(); // set the focus to this input
		return false;
	}
	return true;
}

function selectedValue(elem){
	
	if(elem.value == "0"){
		alert("Please select an option from the "+elem.name+" field");
		elem.focus();
		return false;
	}
	return true;
}

function emailValidator(elem){
	var emailExp = /^[\w\-\.\+]+\@[a-zA-Z0-9\.\-]+\.[a-zA-z0-9]{2,4}$/;
	if(elem.value.match(emailExp)){
		return true;
	}else{
		alert('Please enter a valid email address');
		elem.focus();
		return false;
	}
}

function isNumeric(elem, helperMsg){
	var numericExpression = /^[0-9]+$/;
	if(elem.value.match(numericExpression)){
		return true;
	}else{
		alert(helperMsg);
		elem.focus();
		return false;
	}
}


function isAmount(elem , helperMsg) {
  if (elem.value == null || !elem.value.toString().match(/^[-]?\d*\.?\d*$/))
  {
  	 alert(helperMsg);
		 elem.focus();
  	 return false;
  }
  else	 
  	return true;
}


function calcAge(d2)
{
	var bday=d2.getDate();
	var bmo=d2.getMonth();
	var byr=d2.getFullYear();
	
	var now = new Date();
	var byr;
	var age;
	
	tday=now.getDate();
	tmo=(now.getMonth()+1);
	tyr=(now.getFullYear());

	if((tmo > bmo)||(tmo==bmo & tday>=bday))
		age=byr
	else
		age=byr+1
	
	return(tyr-age);
}

function checkBirthday(elem) {
	
	if( !/^(\d{1,2})\/(\d{1,2})\/(\d{4})$/.test(elem.value) ) {
		alert( "Invalid date supplied - must be format DD/MM/YYYY" );
		elem.focus();
		return false;
	}
	
	var d = new Date();
	var d2 = new Date(RegExp.$3, RegExp.$2, RegExp.$1);
	
	age = calcAge(d2);

	if(age < 18 ) {
		alert("You must be 18+ to register.");
		return false;
	}
	
	return true;
}

function isUpperCase(param) {
  var val = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';

  for (i=0; i<param.length; i++) {
    if (val.indexOf(param.charAt(i),0) == -1) return false;
  }
  return true;
}

function validate_registration(){
	
		//Check all required fields are filled in.
		var req_fields = new Array("nickname","pass","pass2","firstname","lastname","email","address1","town","zipcode","telephone","dob");
		
		var field = null;
		
		for (x in req_fields){
			if(!notEmpty(document.getElementById(req_fields[x])))
				return false;
		}
		
		//Check for invalid characters
		var chars = new Array("_","@");
		for (x in chars){
	    if(document.getElementById('nickname').value.indexOf(chars[x]) != -1){
	    	  alert ( "Your Username must not include the character '"+chars[x]+"'.");
	        return false;
	    }
	  }
    
    //check for Username all upercase.
   	if(isUpperCase(document.getElementById('nickname').value)){
				alert('Your Username must not be all UPPERCASE');
				return false;
		}		

		//Check passwords match.
    if(document.getElementById('pass').value !=  document.getElementById('pass2').value){
    	  alert ( "Please make sure your passwords match" );
        return false;
    }
    
    //Check password is 6 chars or more.
    if(document.getElementById('pass').value.length < 6){
    	  alert ( "Please make sure your password is 6 characters or more." );
        return false;
    }
    
    //Check email address has been entered correctly.
 		if(!emailValidator(document.getElementById('email')))
 			return false;
        
    //Check telephone only contains numbers
    if(!isNumeric(document.getElementById('telephone'),'Telephone number must contain numbers only.'))
    	return false;
    	
    //Check dob field and make sure they are 18+
    if(!checkBirthday(document.getElementById('dob')))
    	return false;
    	
    if(document.getElementById('how').selectedIndex == 0)
    {
    	alert('Please tell us where you heard about us.');
    	return false;
    }
    	
    //Check user has accepted t's and c's
    if(!document.getElementById('terms').checked){
    	alert('You must accept the terms and conditions in order to register');
    	return false;
    }

    return true;
}

function validate_details(){
		//Check all required fields are filled in.
		var req_fields = new Array("firstname","lastname","email","address1","town","zipcode","telephone","dob");
		
		for (x in req_fields){
			if(!notEmpty(document.getElementById(req_fields[x])))
				return false;
		}

    //Check email address has been entered correctly.
 		if(!emailValidator(document.getElementById('email')))
 			return false;
        
    //Check telephone only contains numbers
    if(!isNumeric(document.getElementById('telephone'),'Telephone number must contain numbers only.'))
    	return false;
    	
    //Check dob field and make sure they are 18+
    if(!checkBirthday(document.getElementById('dob')))
    	return false;
    
    return true;
}

function validate_password(){
			//Check passwords match.
    if(document.pass.pass.value !=  document.pass.pass2.value){
    	  alert ( "Please make sure your passwords match" );
        return false;
    }
    
    //Check password is 6 chars or more.
    if(document.pass.pass.value.length < 6){
    	  alert ( "Please make sure your password is 6 characters or more." );
        return false;
    }
}

function roundNumber(rnum, rlength) { // Arguments: number to round, number of decimal places
  var newnumber = Math.round(rnum*Math.pow(10,rlength))/Math.pow(10,rlength);
  return newnumber;
}

function calc_point_value(){
	document.redeem.pounds.value = roundNumber(document.redeem.points.value/200,2).toFixed(2);
}

function validate_points_2_pounds(){
	//Check amount only contains numbers
  if(!isAmount(document.getElementById('points'),'Amount entered must be numeric.'))
   	return false;
   	
  if(document.redeem.points.value < 1000)
  {
  	alert('You must enter an amount greater than 1000 points.');
  	return false;
  }
   	
  if(document.redeem.points.value > (document.redeem.balance.value*1))
  {
  	alert('Amount entered is greater than your Loyalty Balance please check and try again.');
  	return false;
  }	
  
  return true;
}

function validate_password(){
			//Check passwords match.
    if(document.pass.pass.value !=  document.pass.pass2.value){
    	  alert ( "Please make sure your passwords match" );
        return false;
    }
    
    //Check password is 6 chars or more.
    if(document.pass.pass.value.length < 6){
    	  alert ( "Please make sure your password is 6 characters or more." );
        return false;
    }
}

function validate_forgetten_password(){
    
    if(!notEmpty(document.getElementById('user'))){
        return false;
    }
    
    return true;
}

function validate_cashoo_reg(){
		//Check all required fields are filled in.
		var req_fields = new Array("firstname","lastname","email","address1","town","zipcode","county","telcode","telno");
		
		for (x in req_fields){
			if(!notEmpty(document.getElementById(req_fields[x])))
				return false;
		}

    //Check email address has been entered correctly.
 		if(!emailValidator(document.getElementById('email')))
 			return false;
        
    //Check telephone only contains numbers
    if(!isNumeric(document.getElementById('telno'),'Telephone number must contain numbers only.'))
    	return false;
    
    return true;
}

function validate_cashoo_pay(minamt,maxamount){
		//Check all required fields are filled in.
		var req_fields = new Array("email", "amount");
		
		for (x in req_fields){
			if(!notEmpty(document.getElementById(req_fields[x])))
				return false;
		}

    //Check email address has been entered correctly.
 		if(!emailValidator(document.getElementById('email')))
 			return false;
        
    //Check amount only contains numbers
    if(!isNumeric(document.getElementById('amount'),'Amount must contain numbers only.'))
    	return false;
		
		if(parseFloat(document.getElementById('amount').value) < parseFloat(minamt)){
				alert('The minimum deposit amount is ' + parseFloat(minamt));
				return false;
		}
		
		if(parseFloat(document.getElementById('amount').value) > parseFloat(maxamount)){
				alert('The maximum deposit amount is ' + parseFloat(maxamount));
				return false;
		}
    
    return true;
}

function validate_cashout(minamt){



	
		var req_fields = new Array("amount", "password", "name");
		var number_fields = new Array("amount");
	
		if(document.funds.method.value == "bank")
		{
			req_fields = new Array("amount", "password", "name", "bank", "number", "code1", "code2", "code3", "code4", "code5", "code6");
			number_fields = new Array("number", "code1", "code2", "code3", "code4", "code5", "code6");
		}	
		
		for (x in req_fields){
			if(!notEmpty(document.getElementById(req_fields[x])))
				return false;
		}

    for (x in number_fields){
			if(!isNumeric(document.getElementById(number_fields[x]), 'Field must contain numbers only.'))
				return false;
		}

 if(document.getElementById('number').value.length != 8){
    	  alert ( "Please make sure your account number is 8 digits." );
        return false;
    }
		
		if(parseFloat(document.getElementById('amount').value) < parseFloat(minamt)){
				alert('The minimum cashout amount is ' + parseFloat(minamt));
				return false;
		}
    
    return true;
}


function validate_kg_payment()
{
	//Check all required fields are filled in.
		var req_fields = new Array("firstname","lastname","Email","Addr1","City","PostalCode","Phone","AmountIntPart","AmountDecimalPart","CardholderName","CardNumber","SecurityCode");
		
		for (x in req_fields){
			if(!notEmpty(document.getElementById(req_fields[x])))
				return false;
		}

    //Check email address has been entered correctly.
 		if(!emailValidator(document.getElementById('Email')))
 			return false;
 		
 		var num_fields = new Array("Phone","amount1","amount2","CardNumber","SecurityCode");
 			
 		for (x in num_fields){
			if(!isNumeric(document.getElementById(num_fields[x]),'Field must contain numbers only.'))
				return false;
		}
		    	
    //Check card number is valid.	
    var valid = document.getElementById('CardNumber').value.is_valid_card_number();
		if(!valid){
			alert('Card Number is invalid');
			return false;
		}
    
    return true;
}

function validate_yourshot(){

		//Check all required fields are filled in.
		var req_fields = new Array("firstname","lastname","dob","email","occupation","best-time","telephone","address1","town","zipcode","game-name","game-outline","competiting-games","game-advantage","game-detail","url");

		for (x in req_fields){
			if(!notEmpty(document.getElementById(req_fields[x])))
				return false;
		}

		//Check required dropdowns have been selected.
		var req_selections = new Array("game-platform","development-level","type-of-game","game-amount");
		
		for (x in req_selections){
			if(!selectedValue(document.getElementById(req_selections[x])))
				return false;
		}

		//Check email address has been entered correctly.
 		if(!emailValidator(document.getElementById('email')))
 			return false;
        
    //Check telephone only contains numbers
    if(!isNumeric(document.getElementById('telephone'),'Telephone number must contain numbers only.'))
    	return false;

    return true;
}

/**
 * Returns true if the string is a valid credit card number.
 *
 * @return bool
 */
String.prototype.is_valid_card_number = function()
{
	// replace any white space in the card number
	var number = this.replace(/\s+/g, '') ;

	//replace if contains non-numbers
	if(number.match(/\D/)){
		return false ;
	}

	// convert to array and reverse the number
	number = number.split('').reverse().join('') ;

	// loop through the number one digit at a time
	// double the value of every second digit starting
	// from the right, and concatenate the new values 
	// with the unaffected digits
	var digits = '';
	for(var i = 0; i < number.length; i++){
		digits += '' + ((i%2) ?
			number.charAt(i) * 2 :
			number.charAt(i)) ;
	}

	// add all of the single digits together
	var sum = 0 ;
	for (var i = 0; i < digits.length; i++){
		sum += (digits.charAt(i) * 1) ;
	}
	//alert(sum) ;

	// valid card numbers will be transformed into
	// a multiple of 10
	return (sum % 10) ? false : true ;
}
