<!doctype html>
<html class="no-js" lang="zxx">
<head>
<meta charset="utf-8">
<meta http-equiv="x-ua-compatible" content="ie=edge">
<title>Sudila Printers - Kurunegala Sri Lanka</title>
<meta name="description" content="Sudila Printers.">
<meta name="keywords" content="">
<meta name="viewport" content="width=device-width, initial-scale=1">
<!-- Favicons -->
<link rel="shortcut icon" href="images/favicon.ico">

<!-- Google font (font-family: 'Roboto', sans-serif; Poppins ; Satisfy) -->
<link type="text/css" href="css/font_opensans.css" rel="stylesheet">
<link type="text/css" href="css/font_poppins.css" rel="stylesheet">
<link type="text/css" href="css/font_roboto.css" rel="stylesheet">
<!-- Stylesheets -->
<link type="text/css" rel="stylesheet" href="css/bootstrap.min.css">
<link type="text/css" rel="stylesheet" href="css/plugins.css">
<link type="text/css" rel="stylesheet" href="css/style.css">
<!-- Cusom css -->
<link type="text/css" rel="stylesheet" href="css/custom.css">
<link href="css/jquery.toast.min.css" rel="stylesheet" type="text/css">
<!-- Modernizer js -->
<script type="text/javascript" src="js/vendor/modernizr-3.5.0.min.js"></script>
</head>
<body>
<!-- Main wrapper -->
<div class="wrapper" id="wrapper">
  <div id="pre_loader"></div>
  <!-- Header -->
  <?php include 'common/header.php';
	if (isset($_SESSION['normal_user_bb'])) {
		$redirectUrl = "index";
		echo "<script type=\"text/javascript\">";
		echo "window.location.href = '$redirectUrl'";
		echo "</script>";
	}
  ?>
  <!-- //Header --> 
  <!-- Start Bradcaump area -->
  <div class="ht__bradcaump__area bg-image--4">
    <div class="container">
      <div class="row">
        <div class="col-lg-12">
          <div class="bradcaump__inner text-center">
            <h2 class="bradcaump-title">Create Account</h2>
            <nav class="bradcaump-content"> <a class="breadcrumb_item" href="index">Home</a> <span class="brd-separetor">/</span> <span class="breadcrumb_item active">Create Account</span> </nav>
          </div>
        </div>
      </div>
    </div>
  </div>
  <!-- End Bradcaump area --> 
	<!-- Start My Account Area -->
	<section class="my_account_area pt--30 pb--30 bg--white text-center">
		<div class="container">
			<div class="row">
				<div class="col-lg-2 col-12">
				</div>
				<div class="col-lg-8 col-12">
					<div class="my__account__wrapper">
						<form method="post" id="reg_form" action="javascript:void(0);">
							<div class="account__form">
							<h3 class="account__title">CREATE NEW ACCOUNT</h3><hr>
							<p>Already a Member? <a href="sign-in" class="forget_pass">Sign In</a></p><br>
								<div class="row">
									<div class="input__box col-md-6">
										<label>First Name:<span>*</span></label>
										<input type="text" autocomplete="off" name="fname" required>
										<span class="help-block"></span>
									</div>
									<div class="input__box col-md-6">
										<label>Last Name:<span>*</span></label>
										<input type="text" autocomplete="off" name="lname" required>
										<span class="help-block"></span>
									</div>
								</div>
								<div class="row">
									<div class="input__box col-md-6">
										<label>Address Line 1:<span>*</span></label>
										<input type="text" autocomplete="off" name="address_1" required>
										<span class="help-block"></span>
									</div>
									<div class="input__box col-md-6">
										<label>Address Line 2:</label>
										<input type="text" autocomplete="off" name="address_2">
										<span class="help-block"></span>
									</div>
								</div>
								<div class="input__box">
									<label>City:<span>*</span></label>
									<input type="text" autocomplete="off" name="city" required>
									<span class="help-block"></span>
								</div>
								<div class="input__box">
									<label>Email Address:<span>*</span></label>
									<input type="email" autocomplete="off" name="email" id="email" required>
									<span class="help-block"></span>
								</div>
								<div class="input__box">
									<label>Contact No:<span>*</span></label>
									<input type="text" autocomplete="off" maxlength=10 name="tel_no" required>
									<span class="help-block"></span>
								</div>
								<div class="row">
									<div class="input__box col-md-6">
										<label>Account Password:<span>*</span></label>
										<input type="password" id="password" autocomplete="off" name="password" required>
										<span class="help-block"></span>
									</div>
									<div class="input__box col-md-6">
										<label>Confirm Password:<span>*</span></label>
										<input type="password" id="cpassword" autocomplete="off" name="cpassword" required>
										<span class="help-block"></span>
									</div>
								</div>
								<div id="errorDiv"></div>
								<div class="form__btn">
									<input type="submit" value="Register" name="reg_btn" id="reg_btn" class="button"/>
								</div>
								<?php if(isset($_SESSION['temp_user_bb'])) { ?> <hr class="mt--20">
								<div class="mt--20 product-add-to-cart chkt">
									<a href="connection/guest-login">CONTINUE AS A GUEST</a>
								</div>
								<?php } ?>
							</div>
						</form>
					</div>
				</div>
			</div>
		</div>
	</section>
	<!-- End My Account Area --> 
  <!-- Footer Area -->
  <?php include 'common/footer.php'; ?>
  <!-- //Footer Area --> 
</div>
<!-- //Main wrapper -->
<!-- JS Files --> 
<script type="text/javascript" src="js/vendor/jquery-3.2.1.min.js"></script> 
<script type="text/javascript" src="js/popper.min.js"></script> 
<script type="text/javascript" src="js/bootstrap.min.js"></script> 
<script type="text/javascript" src="js/plugins.js"></script> 
<script type="text/javascript" src="js/active.js"></script>
<script type="text/javascript" src="js/jquery.validate.min.js"></script>
<script type="text/javascript" src="js/add-to-cart.js"></script>
<script type="text/javascript" src="js/jquery.toast.js"></script>
<script type="text/javascript">
$('document').ready(function () {
	// valid email pattern
	var eregex = /^([a-zA-Z0-9_\.\-\+])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
	$.validator.addMethod("validemail", function (value, element) {
		return this.optional(element) || eregex.test(value);
	});
	
	// contact no validation
	var telregex = /^\d{10}$/;
	$.validator.addMethod("validtel", function (value, element) {
		return this.optional(element) || telregex.test(value);
	});
	
	// JavaScript Validation For Reg Form	
	$("#reg_form").validate({
		rules: {
			password: {
				required: true,
				minlength: 5,
				maxlength: 15
			},
			email: {
				required: true,
				validemail: true
			},
			cpassword: {
				required: true,
				equalTo: '#password'
			},
			tel_no: {
				validtel: true,
			}
		},
		messages: {
			password: {
				minlength: "Password at least have 5 characters"
			},
			email: {
				validemail: "Please Enter Valid Email Address"
			},
			cpassword: {
				equalTo: "Passwords do not match!"
			},
			tel_no: {
				validtel: "Invalid Contact Number"
			}
		},
		errorPlacement: function (error, element) {
			$(element).closest('.input__box').find('.help-block').html(error.html());
		},
		highlight: function (element) {
			$(element).closest('.input__box').removeClass('has-success').addClass('has-error');
		},
		unhighlight: function (element, errorClass, validClass) {
			$(element).closest('.input__box').removeClass('has-error');
			$(element).closest('.input__box').find('.help-block').html('');
		},
		submitHandler: regForm
	});

	function regForm() {
		$("#pre_loader").show();
		$.ajax({
		url: 'connection/user_login',
		type: 'POST',
		data: $('#reg_form').serialize(),
		dataType: 'json'
		})
		.done(function (data) {
			$('input[name=reg_btn]').prop('disabled', true);
			$('input[type=text],input[type=password],input[type=email]').prop('disabled', true);
			setTimeout(function () {
				if (data.status === '1') {
					$("#pre_loader").hide();
					showAccSuccessMsg();
					send_sms_fun(data.tel_no, data.email);
					setTimeout(function() {
						window.location.href = 'checkout';
					}, 1000);
				
				} else if (data.status === '2') {
					$("#pre_loader").hide();
					showAccSuccessMsg();
					send_sms_fun(data.tel_no, data.email);
					setTimeout(function() {
						window.location.href = 'index';
					}, 1000);
				
				} else {
					$("#pre_loader").hide();
					$('#errorDiv').slideDown(200, function () {
						$('#errorDiv').html('<div class="alert alert-danger">' + data.message + '</div>');
						$('#errorDiv').delay(5000).slideUp(100);
						$('input[type=text],input[type=password],input[type=email]').prop('disabled', false);
						$('input[name=reg_btn]').prop('disabled', false);				
						$('#email').focus();
						$('#password').val('');
						$('#cpassword').val('');
					});
				}
			}, 1000);
		})
		.fail(function () {
			$('input[name=reg_btn]').prop('disabled', true);
			$('input[type=text],input[type=password],input[type=email]').prop('disabled', true);
			setTimeout(function () {
				$("#pre_loader").hide();
				//alert('An unknown error occoured, Please try again Later...!')
				$('#errorDiv').slideDown(200, function () {
					$('#errorDiv').html('<div class="alert alert-danger">An unknown error occoured, Please try again Later...!</div>');
					$('#errorDiv').delay(5000).slideUp(100);
					$('input[type=text],input[type=password],input[type=email]').prop('disabled', false);
					$('input[name=reg_btn]').prop('disabled', false);
				});
			}, 1000);
		});
	}
});

showAccSuccessMsg = function() {
    'use strict';
    resetPosition();
    $.toast({
      heading: 'Successfully Registered.',
	  closeButton: true,
      text: '',
      showHideTransition: 'slide',
      icon: 'success',
	  bgColor: '#ea1202',
	  progressBar: true,
      loaderBg: '#c41f24',
	  textColor: '#fff',
      position: 'bottom-right',
    })
};

function send_sms_fun(mobile_no, email) {
	var msg = "Thank you for registered on buddhistbooksonline. Use "+email+" as your username."; 
	var res = mobile_no.substring(1);
	var tel = '94'+res;
	
	$.ajax({
		type: "POST",
		async: false,
		dataType: 'jsonp',
		url: "https://sms.textware.lk:5001/sms/send_sms.php",
		data: {'username': 'samudra_group',
		'password': 'smr56grp',
		'src': 'Samudra',
		'dst': tel,
		'msg': msg,
		'dr': '1',           
		},
		success: function (response) {
		//alert(response);
		}		
	});
}
</script>
</body>
</html>