<!DOCTYPE HTML>
<html lang="en-US">
<head>
	<meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
	<title>boomtag{title}</title>
    <link href='http://fonts.googleapis.com/css?family=Open+Sans:400,300,600,700,800' rel='stylesheet' type='text/css'>
    <link href='http://fonts.googleapis.com/css?family=Open+Sans+Condensed:300,300italic,700' rel='stylesheet' type='text/css'>
    <script src='https://ajax.googleapis.com/ajax/libs/jquery/1.7.0/jquery.min.js'></script>
    <style type="text/css">boomtag{main_css}</style>
   	<script type="text/javascript">

		$(function() {

			$("#email-submit").attr('disabled', false);
			$("#email_add").attr('disabled',false);

			function validateEmail($email) {
			  	var emailReg = /^([\w-\.]+@([\w-]+\.)+[\w-]{2,4})?$/;
			  	if( !emailReg.test( $email ) ) {
			    	return false;
			  	} else {
			    	return true;
			  	}
			}

			$("#email-submit").click(function(){

				$("#err_msg").html('');
				$('#jackpot').fadeOut('fast');
				$('.slot-wrapper').fadeTo( "fast", 1 );

				if(!$("#email_add").val()) {
					$("#err_msg").html("* Please enter your email address.");
					return false;
				} else if( !validateEmail($("#email_add").val())){
					$("#err_msg").html("* Please enter a valid email address. For example <b><i>johnsmith@gmail.com</i></b>");
					return false;
			    } else {

					$("#email-submit").attr('disabled', true);
					$("#email_add").attr('disabled',true);
					var start_time = new Date().getTime();

					// starts ajax to GET the prize won
					$.ajax({
						url: '/slot-machine',
					 	type: "POST",
					  	dataType: "json",
					  	data: { 
					  		id : 'play_slot',
					  		email: $('#email_add').val(),
					  		referred_org: 'boomtag{org_business_client_email}'
					  	},
					  	success: function(data){
					  		var success = true;

					  		if(data[0] == "error")
					  		{
					  			$('#won_msg').text('Sorry!');
					  			$('#offer').text('No prizes available.');
					  			$('#prize_info').text('Prize Info: Sorry no email was sent.');
					  			success = false;
					  		}
					  		else if(data[0] == 'exist')
					  		{
					  			$('#won_msg').text('Sorry, only one spin per email address.');
					  			$('#offer').text('');
					  			$('#prize_info').text('');
					  			success = false;
					  		}

					  		if(!success) {
					  				$('#jackpot').fadeIn('fast');
									$('.slot-wrapper').fadeTo( "slow", 0.33 );
									$("#email-submit").attr('disabled', true);
									$("#email_add").attr('disabled',true);
					  			return false;
					  		} else {
						  			$('#won_msg').text('You’ve Won!');
									$('#offer').text(data[0]);
					  				$('#org_client').val(data[1]);
									$('#page-title').text('Congratulations').after('<p>You will be redirected to your prize in a moment.</p>');	

									var send_data = {};
									send_data.prize = data[0];
						  			send_data.client_id = data[1];

									var frm = document.createElement("form");
										frm.method = "post";
											send_data.main_org = 'boomtag{main_org}';
											frm.action = 'boomtag{main_org_claim_prize}';
									var input = document.createElement("input");
										input.type="hidden";
										input.name="data";
										input.value = JSON.stringify(send_data);
										
									frm.appendChild(input);
									document.body.appendChild(frm);

									setTimeout(function() {
										frm.submit();	
									}, 500);
									
									$('html, body, #wrapper, #container').delay(3600).css('height', 'auto');
					  		}
						}
					});
				}
			});
		});
	  </script>  
</head>
<body>
<div id="main-wrapper-ribbon">
	<div class="container">
    
    <div class="row">

        <div id="tag-wrapper" class="col-xs-9 col-xs-offset-3">
            <div id="tag-container">
                <div class="tag-boarder">
                    <div class="clearfix">
                        <div class="recipient-container">
                            <h2>Enter your email address to open your gift</h2>
                            
                            <div class="prof-form-container">
                            <span style="color:red;font-size:14px" id="err_msg"></span>
<div class="row">  
                       
   
        <div class="col-sm-9">
            <div class="form-group">
            	<div id="jackpot">
					<div class="wrapper">
						<h1 id="won_msg">YOU�VE WON!!</h1>
						<p id="offer"></p>
						<p><small><i id="prize_info">Prize Info: An email with your prize has been sent</i></small></p>
					</div>
				</div>
                <input class="form-control input-sm" id="email_add" placeholder="Email Address">
            </div>
        </div>
        <div class="col-sm-3">
            <div class="form-group">
                <button type="submit" id="email-submit" class="btn btn-primary btn-block btn-sm">Submit</button>
            </div>
        </div>
  

</div>
                            </div>
                        </div>
                    </div>
                    <div class="clearfix">
                        
                        <div id="tag-org-details">
                            <div class="row">
                              <div class="col-md-12 tag-orgname-container"><span class="tag-orgname">boomtag{org_name}</span></div>
                            </div>
                        </div>
                    
                    </div>
                </div>    
            </div>
        </div>
    </div>
    
    </div>
</div>    
</body>
</html>