$(document).ready(function () { 

$("#bettingForm").on('submit',(function(e) {
e.preventDefault();

var finalamount = $('input#finalamount').val();
var counter = $('input#counter').val();
var userid=$('input#userid').val();
var inputgameid=$('input#inputgameid').val();
var tab=$('input#tab').val();


if((finalamount)== 0) {

$('#payment').modal('hide');
  $('#alert').modal({backdrop: 'static', keyboard: false})  
     $('#alert').modal('show');
	 document.getElementById('alertmessage').innerHTML = "<h4>Fail !</h4><p>Invalid contract count,please try again !</p>";
            return false;
			}
if(finalamount<10) {
  
  $('#payment').modal('hide');
  $('#alert').modal({backdrop: 'static', keyboard: false})  
     $('#alert').modal('show');
	 document.getElementById('alertmessage').innerHTML = "<h4>Fail !</h4><p>Invalid contract count,please try again !</p>";
            return false;
			}
if(finalamount>100000) {
  
  $('#payment').modal('hide');
  $('#alert').modal({backdrop: 'static', keyboard: false})  
     $('#alert').modal('show');
	 document.getElementById('alertmessage').innerHTML = "<h4>Fail !</h4><p>Invalid contract count,please try again !</p>";
            return false;
			}

if(counter<30)
{
$('#payment').modal('hide');
$('#alert').modal({backdrop: 'static', keyboard: false})  
$('#alert').modal('show');
document.getElementById('alertmessage').innerHTML = "<h4>Fail !</h4><p>Invalid period,please try again !</p>";
            return false;

	}

if($('#presalerule').is(':checked')){}
else{
  $('#payment').modal('hide');
  $('#alert').modal({backdrop: 'static', keyboard: false})  
     $('#alert').modal('show');
	 document.getElementById('alertmessage').innerHTML = "<h4>Fail !</h4><p>Please select presale rule !</p>";
        return false;
	
	}			


$.ajax({
			type: "POST", 
			url: "betNow.php",              
			data: new FormData(this), 
			contentType: false,       
			cache: false,             
			processData:false,       

			success: function(html)   
			{ //alert(html);
			var arr = html.split('~');
			if (arr[0]== 1) {
			    waitlist(tab,userid,tab+'wait');
				$('#payment').modal('hide');
				var balance=parseFloat(arr[1]).toFixed(2);
			document.getElementById('balance').innerHTML =balance;
			$('#alert').modal({backdrop: 'static', keyboard: false})  
$('#alert').modal('show');
document.getElementById('alertmessage').innerHTML = "<h4>Completed</h4><p>Your contract is successful completed</p>";
            return false;

			}
			else if(arr[0]==2)
			{ 
			$('#payment').modal('hide');
$('#alert').modal({backdrop: 'static', keyboard: false})  
$('#alert').modal('show');
document.getElementById('alertmessage').innerHTML = "<h4>Fail !</h4><p>Invalid action,please try again !</p>";
            return false;

				}
				else if (arr[0]==3){
					$('#payment').modal('hide');
$('#alert').modal({backdrop: 'static', keyboard: false})  
$('#alert').modal('show');
document.getElementById('alertmessage').innerHTML = "<h4>Fail !</h4><p>Invalid period,please try again !</p>";
            return false;

					}else if(arr[0]==4) {

$('#payment').modal('hide');
  $('#alert').modal({backdrop: 'static', keyboard: false})  
     $('#alert').modal('show');
	 document.getElementById('alertmessage').innerHTML = "<h4>Fail !</h4><p>Invalid contract count,please try again !</p>";
            return false;
			}
else if(arr[0]==5) {
  
  $('#payment').modal('hide');
  $('#alert').modal({backdrop: 'static', keyboard: false})  
     $('#alert').modal('show');
	 document.getElementById('alertmessage').innerHTML = "<h4>Fail !</h4><p>Invalid contract count,please try again !</p>";
            return false;
			}
	else if(arr[0]==6) {
  
  $('#payment').modal('hide');
  $('#alert').modal({backdrop: 'static', keyboard: false})  
     $('#alert').modal('show');
	 document.getElementById('alertmessage').innerHTML = "<h4>Fail !</h4><p>The balance is not enough !</p>";
            return false;
			}		
			}
		});	
}));



$("#bettingForm10").on('submit',(function(e) {
e.preventDefault();

var finalamount = $('input#finalamount').val();
var counter = $('input#counter').val();
var userid=$('input#userid').val();
var inputgameid=$('input#inputgameid').val();
var tab=$('input#tab').val();


if((finalamount)== 0) {

$('#payment').modal('hide');
  $('#alert').modal({backdrop: 'static', keyboard: false})  
     $('#alert').modal('show');
	 document.getElementById('alertmessage').innerHTML = "<h4>Fail !</h4><p>Invalid contract count,please try again !</p>";
            return false;
			}
if(finalamount<10) {
  
  $('#payment').modal('hide');
  $('#alert').modal({backdrop: 'static', keyboard: false})  
     $('#alert').modal('show');
	 document.getElementById('alertmessage').innerHTML = "<h4>Fail !</h4><p>Invalid contract count,please try again !</p>";
            return false;
			}
if(finalamount>100000) {
  
  $('#payment').modal('hide');
  $('#alert').modal({backdrop: 'static', keyboard: false})  
     $('#alert').modal('show');
	 document.getElementById('alertmessage').innerHTML = "<h4>Fail !</h4><p>Invalid contract count,please try again !</p>";
            return false;
			}

if(counter<30)
{
$('#payment').modal('hide');
$('#alert').modal({backdrop: 'static', keyboard: false})  
$('#alert').modal('show');
document.getElementById('alertmessage').innerHTML = "<h4>Fail !</h4><p>Invalid period,please try again !</p>";
            return false;

	}

if($('#presalerule').is(':checked')){}
else{
  $('#payment').modal('hide');
  $('#alert').modal({backdrop: 'static', keyboard: false})  
     $('#alert').modal('show');
	 document.getElementById('alertmessage').innerHTML = "<h4>Fail !</h4><p>Please select presale rule !</p>";
        return false;
	
	}			


$.ajax({
			type: "POST", 
			url: "betNow10.php",              
			data: new FormData(this), 
			contentType: false,       
			cache: false,             
			processData:false,       

			success: function(html)   
			{ //alert(html);
			var arr = html.split('~');
			if (arr[0]== 1) {
			    waitlist10(tab,userid,tab+'wait');
				$('#payment').modal('hide');
				var balance=parseFloat(arr[1]).toFixed(2);
			document.getElementById('balance').innerHTML =balance;
			$('#alert').modal({backdrop: 'static', keyboard: false})  
$('#alert').modal('show');
document.getElementById('alertmessage').innerHTML = "<h4>Completed</h4><p>Your contract is successful completed</p>";
            return false;

			}
			else if(arr[0]==2)
			{ 
			$('#payment').modal('hide');
$('#alert').modal({backdrop: 'static', keyboard: false})  
$('#alert').modal('show');
document.getElementById('alertmessage').innerHTML = "<h4>Fail !</h4><p>Invalid action,please try again !</p>";
            return false;

				}
				else if (arr[0]==3){
					$('#payment').modal('hide');
$('#alert').modal({backdrop: 'static', keyboard: false})  
$('#alert').modal('show');
document.getElementById('alertmessage').innerHTML = "<h4>Fail !</h4><p>Invalid period,please try again !</p>";
            return false;

					}else if(arr[0]==4) {

$('#payment').modal('hide');
  $('#alert').modal({backdrop: 'static', keyboard: false})  
     $('#alert').modal('show');
	 document.getElementById('alertmessage').innerHTML = "<h4>Fail !</h4><p>Invalid contract count,please try again !</p>";
            return false;
			}
else if(arr[0]==5) {
  
  $('#payment').modal('hide');
  $('#alert').modal({backdrop: 'static', keyboard: false})  
     $('#alert').modal('show');
	 document.getElementById('alertmessage').innerHTML = "<h4>Fail !</h4><p>Invalid contract count,please try again !</p>";
            return false;
			}
	else if(arr[0]==6) {
  
  $('#payment').modal('hide');
  $('#alert').modal({backdrop: 'static', keyboard: false})  
     $('#alert').modal('show');
	 document.getElementById('alertmessage').innerHTML = "<h4>Fail !</h4><p>The balance is not enough !</p>";
            return false;
			}		
			}
		});	
}));

$("#bettingForm15").on('submit',(function(e) {
e.preventDefault();

var finalamount = $('input#finalamount').val();
var counter = $('input#counter').val();
var userid=$('input#userid').val();
var inputgameid=$('input#inputgameid').val();
var tab=$('input#tab').val();


if((finalamount)== 0) {

$('#payment').modal('hide');
  $('#alert').modal({backdrop: 'static', keyboard: false})  
     $('#alert').modal('show');
	 document.getElementById('alertmessage').innerHTML = "<h4>Fail !</h4><p>Invalid contract count,please try again !</p>";
            return false;
			}
if(finalamount<10) {
  
  $('#payment').modal('hide');
  $('#alert').modal({backdrop: 'static', keyboard: false})  
     $('#alert').modal('show');
	 document.getElementById('alertmessage').innerHTML = "<h4>Fail !</h4><p>Invalid contract count,please try again !</p>";
            return false;
			}
if(finalamount>100000) {
  
  $('#payment').modal('hide');
  $('#alert').modal({backdrop: 'static', keyboard: false})  
     $('#alert').modal('show');
	 document.getElementById('alertmessage').innerHTML = "<h4>Fail !</h4><p>Invalid contract count,please try again !</p>";
            return false;
			}

if(counter<30)
{
$('#payment').modal('hide');
$('#alert').modal({backdrop: 'static', keyboard: false})  
$('#alert').modal('show');
document.getElementById('alertmessage').innerHTML = "<h4>Fail !</h4><p>Invalid period,please try again !</p>";
            return false;

	}

if($('#presalerule').is(':checked')){}
else{
  $('#payment').modal('hide');
  $('#alert').modal({backdrop: 'static', keyboard: false})  
     $('#alert').modal('show');
	 document.getElementById('alertmessage').innerHTML = "<h4>Fail !</h4><p>Please select presale rule !</p>";
        return false;
	
	}			


$.ajax({
			type: "POST", 
			url: "betNow15.php",              
			data: new FormData(this), 
			contentType: false,       
			cache: false,             
			processData:false,       

			success: function(html)   
			{ //alert(html);
			var arr = html.split('~');
			if (arr[0]== 1) {
			    waitlist15(tab,userid,tab+'wait');
				$('#payment').modal('hide');
				var balance=parseFloat(arr[1]).toFixed(2);
			document.getElementById('balance').innerHTML =balance;
			$('#alert').modal({backdrop: 'static', keyboard: false})  
$('#alert').modal('show');
document.getElementById('alertmessage').innerHTML = "<h4>Completed</h4><p>Your contract is successful completed</p>";
            return false;

			}
			else if(arr[0]==2)
			{ 
			$('#payment').modal('hide');
$('#alert').modal({backdrop: 'static', keyboard: false})  
$('#alert').modal('show');
document.getElementById('alertmessage').innerHTML = "<h4>Fail !</h4><p>Invalid action,please try again !</p>";
            return false;

				}
				else if (arr[0]==3){
					$('#payment').modal('hide');
$('#alert').modal({backdrop: 'static', keyboard: false})  
$('#alert').modal('show');
document.getElementById('alertmessage').innerHTML = "<h4>Fail !</h4><p>Invalid period,please try again !</p>";
            return false;

					}else if(arr[0]==4) {

$('#payment').modal('hide');
  $('#alert').modal({backdrop: 'static', keyboard: false})  
     $('#alert').modal('show');
	 document.getElementById('alertmessage').innerHTML = "<h4>Fail !</h4><p>Invalid contract count,please try again !</p>";
            return false;
			}
else if(arr[0]==5) {
  
  $('#payment').modal('hide');
  $('#alert').modal({backdrop: 'static', keyboard: false})  
     $('#alert').modal('show');
	 document.getElementById('alertmessage').innerHTML = "<h4>Fail !</h4><p>Invalid contract count,please try again !</p>";
            return false;
			}
	else if(arr[0]==6) {
  
  $('#payment').modal('hide');
  $('#alert').modal({backdrop: 'static', keyboard: false})  
     $('#alert').modal('show');
	 document.getElementById('alertmessage').innerHTML = "<h4>Fail !</h4><p>The balance is not enough !</p>";
            return false;
			}		
			}
		});	
}));

$("#bettingForm20").on('submit',(function(e) {
e.preventDefault();

var finalamount = $('input#finalamount').val();
var counter = $('input#counter').val();
var userid=$('input#userid').val();
var inputgameid=$('input#inputgameid').val();
var tab=$('input#tab').val();


if((finalamount)== 0) {

$('#payment').modal('hide');
  $('#alert').modal({backdrop: 'static', keyboard: false})  
     $('#alert').modal('show');
	 document.getElementById('alertmessage').innerHTML = "<h4>Fail !</h4><p>Invalid contract count,please try again !</p>";
            return false;
			}
if(finalamount<10) {
  
  $('#payment').modal('hide');
  $('#alert').modal({backdrop: 'static', keyboard: false})  
     $('#alert').modal('show');
	 document.getElementById('alertmessage').innerHTML = "<h4>Fail !</h4><p>Invalid contract count,please try again !</p>";
            return false;
			}
if(finalamount>100000) {
  
  $('#payment').modal('hide');
  $('#alert').modal({backdrop: 'static', keyboard: false})  
     $('#alert').modal('show');
	 document.getElementById('alertmessage').innerHTML = "<h4>Fail !</h4><p>Invalid contract count,please try again !</p>";
            return false;
			}

if(counter<30)
{
$('#payment').modal('hide');
$('#alert').modal({backdrop: 'static', keyboard: false})  
$('#alert').modal('show');
document.getElementById('alertmessage').innerHTML = "<h4>Fail !</h4><p>Invalid period,please try again !</p>";
            return false;

	}

if($('#presalerule').is(':checked')){}
else{
  $('#payment').modal('hide');
  $('#alert').modal({backdrop: 'static', keyboard: false})  
     $('#alert').modal('show');
	 document.getElementById('alertmessage').innerHTML = "<h4>Fail !</h4><p>Please select presale rule !</p>";
        return false;
	
	}			


$.ajax({
			type: "POST", 
			url: "betNow20.php",              
			data: new FormData(this), 
			contentType: false,       
			cache: false,             
			processData:false,       

			success: function(html)   
			{ //alert(html);
			var arr = html.split('~');
			if (arr[0]== 1) {
			    waitlist20(tab,userid,tab+'wait');
				$('#payment').modal('hide');
				var balance=parseFloat(arr[1]).toFixed(2);
			document.getElementById('balance').innerHTML =balance;
			$('#alert').modal({backdrop: 'static', keyboard: false})  
$('#alert').modal('show');
document.getElementById('alertmessage').innerHTML = "<h4>Completed</h4><p>Your contract is successful completed</p>";
            return false;

			}
			else if(arr[0]==2)
			{ 
			$('#payment').modal('hide');
$('#alert').modal({backdrop: 'static', keyboard: false})  
$('#alert').modal('show');
document.getElementById('alertmessage').innerHTML = "<h4>Fail !</h4><p>Invalid action,please try again !</p>";
            return false;

				}
				else if (arr[0]==3){
					$('#payment').modal('hide');
$('#alert').modal({backdrop: 'static', keyboard: false})  
$('#alert').modal('show');
document.getElementById('alertmessage').innerHTML = "<h4>Fail !</h4><p>Invalid period,please try again !</p>";
            return false;

					}else if(arr[0]==4) {

$('#payment').modal('hide');
  $('#alert').modal({backdrop: 'static', keyboard: false})  
     $('#alert').modal('show');
	 document.getElementById('alertmessage').innerHTML = "<h4>Fail !</h4><p>Invalid contract count,please try again !</p>";
            return false;
			}
else if(arr[0]==5) {
  
  $('#payment').modal('hide');
  $('#alert').modal({backdrop: 'static', keyboard: false})  
     $('#alert').modal('show');
	 document.getElementById('alertmessage').innerHTML = "<h4>Fail !</h4><p>Invalid contract count,please try again !</p>";
            return false;
			}
	else if(arr[0]==6) {
  
  $('#payment').modal('hide');
  $('#alert').modal({backdrop: 'static', keyboard: false})  
     $('#alert').modal('show');
	 document.getElementById('alertmessage').innerHTML = "<h4>Fail !</h4><p>The balance is not enough !</p>";
            return false;
			}		
			}
		});	
}));

//=============================payment detail=========================================================================

});

function waitlist(category,userid,containerid)
{ //alert(containerid);
var inputgameid=$("#futureid").val();

	$.ajax({
    type: "Post",
    data:"category=" + category+ "& userid=" + userid +"& periodid=" + inputgameid,
    url: "getwaitlist.php",
    success: function (html) { //alert(html);
		document.getElementById(containerid).innerHTML=html;
		},
      error: function (e) {}
      });
	}
	
	function waitlist10(category,userid,containerid)
    { 
     var inputgameid=$("#futureid").val();

	$.ajax({
    type: "Post",
    data:"category=" + category+ "& userid=" + userid +"& periodid=" + inputgameid,
    url: "getwaitlist10.php",
    success: function (html) { //alert(html);
		document.getElementById(containerid).innerHTML=html;
		},
      error: function (e) {}
      });
	}
	
	function waitlist15(category,userid,containerid)
{ //alert(containerid);
var inputgameid=$("#futureid").val();

	$.ajax({
    type: "Post",
    data:"category=" + category+ "& userid=" + userid +"& periodid=" + inputgameid,
    url: "getwaitlist15.php",
    success: function (html) { //alert(html);
		document.getElementById(containerid).innerHTML=html;
		},
      error: function (e) {}
      });
	}
	
	function waitlist20(category,userid,containerid)
{ //alert(containerid);
var inputgameid=$("#futureid").val();

	$.ajax({
    type: "Post",
    data:"category=" + category+ "& userid=" + userid +"& periodid=" + inputgameid,
    url: "getwaitlist20.php",
    success: function (html) { //alert(html);
		document.getElementById(containerid).innerHTML=html;
		},
      error: function (e) {}
      });
	}