<div id="ebook" class="postbox welcome-postbox-ebook">
	<h3 class="hndle">
		<span>Get Free eBook Now! <strong>($9.99 Value)</strong></span>
	</h3>

	<div class="inside">
		<div class="row">
			<div class="col-xs-12 col-sm-5">
				<img class="img-responsive" src="http://peepso.com/peepsotools-integration-json/assets/peepso_ebook.jpg">
			</div>
			<div class="col-xs-12 col-sm-7">

				<p>This eBook will teach you everything you need to know to start, grow and monetize your online community.</p>
				<p>Based on research of hundreds successful and unsuccessful communities.</p>
				<p>Subscribe to our mailing list and get the ebook!</p>

				<form action="http://newsletter.ijoomla.com/subscribe" method="POST" accept-charset="utf-8" target="_blank" onsubmit="return peepso_sendy_subscribe(this);">
					<div class="form-group">
						<label for="name"><strong>Firstname</strong></label>
						<div class="peepso_sendy_name_error" style="color:red;display:none">Firstname cannot be empty.</div>
						<input type="text" name="name" value="FORM_FIRST_NAME" id="name" class="form-control"/>
					</div>
					<div class="form-group">
						<label for="last_name"><strong>Lastname</strong></label>
						<div class="peepso_sendy_last_name_error" style="color:red;display:none">Lastname cannot be empty.</div>
						<input type="text" name="last_name" value="FORM_LAST_NAME" id="last_name" class="form-control"/>
					</div>
					<div class="form-group">
						<label for="email"><strong>Email</strong></label>
						<div class="peepso_sendy_email_error" style="color:red;display:none">Please provide valid email address.</div>
						<input type="text" name="email" value="FORM_EMAIL" id="email" class="form-control"/>
					</div>
					<input type="hidden" name="list" value="ZSdRcX1D5XKqMsqxfH3vIA"/>
					<div class="clear">
						<div class="peepso_sendy_message" style="color:blue;margin-bottom:10px;display:none">Thank you for subscribing. You will receive the eBook shortly.</div>
						<button type="submit" name="submit" class="btn btn-warning btn-block" id="submit">
							<span>SEND ME THIS EBOOK NOW</span> &nbsp;
							<img class="peepso_sendy_loading" style="display:none" src="../wp-content/plugins/peepso/assets/images/ajax-loader.gif"/>
						</button>
					</div>
				</form> 

			</div>
		</div>
	</div>
</div>

<script>
	function peepso_sendy_subscribe(elem) {
		if ( !window.$PeepSo ) {
			return true;
		}

		var $form = jQuery(elem),
			$name_error = $form.find(".peepso_sendy_name_error").hide(),
			$last_name_error = $form.find(".peepso_sendy_last_name_error").hide(),
			$email_error = $form.find(".peepso_sendy_email_error").hide(),
			$message = $form.find(".peepso_sendy_message").hide(),
			$loading = $form.find(".peepso_sendy_loading").hide(),
			valid = true;

		var req = {
			sendy_list_id: $form.find("[name=list]").val(),
			sendy_url: $form.attr("action"),
			sendy_name: jQuery.trim( $form.find("[name=name]").val() ),
			sendy_last_name: jQuery.trim( $form.find("[name=last_name]").val() ),
			sendy_email: jQuery.trim( $form.find("[name=email]").val() ),
		};

		if (!req.sendy_name) {
			$name_error.show();
			valid = false;
		}

		if (!req.sendy_last_name) {
			$last_name_error.show();
			valid = false;
		}

		var re = /^([\w-]+(?:\.[\w-]+)*)(?:\+[\w]+)?@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i;
		if (!re.test( req.sendy_email )) {
			$email_error.show();
			valid = false;
		}

		if (!valid) {
			return false;
		}

		if (!$message.data('default_msg')) {
			$message.data('default_msg', $message.text());
		}

		$loading.show();
		$PeepSo.postJson("adminSendy.add_user", req, function(json) {
			var response = $message.data('default_msg');
			if (json.data && json.data.response && json.data.response != 1) {
				response = json.data.response;
			}
			$loading.hide();
			$message.html( response ).show();
		});

		return false;
	}
</script>