<!DOCTYPE html>
<html>

<head>

	<meta charset="utf-8">
	<meta http-equiv="X-UA-Compatible" content="IE=edge">
	<title>Merchbay | Dashboard</title>
	<!-- Tell the browser to be responsive to screen width -->
	<meta content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" name="viewport">
	<meta name="csrf_token" content="{{ csrf_token() }}" />
	<meta http-equiv="Cache-Control" content="no-cache, no-store, must-revalidate" />
	<meta http-equiv="Pragma" content="no-cache" />
	<meta http-equiv="Expires" content="0" />
	<!-- Bootstrap 3.3.6 -->
	<link rel="stylesheet" href="{{asset('/bower_components/AdminLTE/bootstrap/css/bootstrap.min.css')}}">
	<!-- Font Awesome -->
	<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.css">
	<!-- Ionicons -->
	<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/ionicons/2.0.1/css/ionicons.min.css">
	<!-- Theme style -->
	<link rel="stylesheet" href="{{asset('/bower_components/AdminLTE/dist/css/AdminLTE.min.css')}}">
	<!-- AdminLTE Skins. Choose a skin from the css/skins
		folder instead of downloading all of them to reduce the load. -->
	<link rel="stylesheet" href="{{asset('/bower_components/AdminLTE/dist/css/skins/_all-skins.min.css')}}">
	<!-- iCheck -->
	<link rel="stylesheet" href="{{asset('/bower_components/AdminLTE/plugins/iCheck/flat/blue.css')}}">
	<!-- Date Picker -->
	<link rel="stylesheet" href="{{asset('/bower_components/AdminLTE/plugins/datepicker/datepicker3.css')}}">
	<!-- Daterange picker -->
	<link rel="stylesheet" href="{{asset('/bower_components/AdminLTE/plugins/daterangepicker/daterangepicker.css')}}">
	<!-- bootstrap wysihtml5 - text editor -->
	<link rel="stylesheet" href="{{asset('/bower_components/AdminLTE/plugins/bootstrap-wysihtml5/bootstrap3-wysihtml5.min.css')}}">
	<!-- Select2 -->
	<link href="{{asset('/bower_components/AdminLTE/plugins/select2/select2.min.css')}}" rel="stylesheet" />
	<!-- ekko-lightbox -->
	<link href="https://cdnjs.cloudflare.com/ajax/libs/ekko-lightbox/5.3.0/ekko-lightbox.css" rel="stylesheet">
	<!-- bootstrap-toggle -->
	<link href="https://gitcdn.github.io/bootstrap-toggle/2.2.2/css/bootstrap-toggle.min.css" rel="stylesheet">
	<!-- DataTables -->
	<link rel="stylesheet" href="{{ asset('/bower_components/AdminLTE/plugins/datatables.net-bs/css/dataTables.bootstrap.min.css') }}">
	<!-- datepicker -->
	<link rel="stylesheet" href="{{ asset('/bower_components/AdminLTE/plugins/datepicker/datepicker3.css') }}">
	<!-- jquery-ui -->
	<link href="{{ asset('/assets/css/jquery-ui.css') }}" rel="stylesheet">
	<link href="{{asset('/designer/css/build.css')}}" rel="stylesheet">

	
	<script src="https://cdn.jsdelivr.net/npm/vue@2.7.14"></script>
	<script src="https://cdn.jsdelivr.net/npm/axios/dist/axios.min.js"></script>
	<!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries -->
	<!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
	<!--[if lt IE 9]>
		<script src="https://oss.maxcdn.com/html5shiv/3.7.3/html5shiv.min.js"></script>
		<script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
		<![endif]-->

	<style>
		.skin-black-light .wrapper,
		.skin-black-light .main-sidebar,
		.skin-black-light .left-side {
			background-color: #222d32;
		}

		.skin-black-light .sidebar-menu>li:hover>a,
		.skin-black-light .sidebar-menu>li.active>a {
			color: #fff;
			background: #1e282c;
			border-left-color: #fff;
		}

		.skin-black-light .sidebar-menu>li.header {
			color: #4b646f;
			background: #1a2226;
		}

		.skin-black-light .sidebar a {
			color: rgb(184, 199, 206);
		}

		.skin-black-light .user-panel>.info,
		.skin-black-light .user-panel>.info>a {
			color: #fff;
		}

		.skin-black-light .sidebar-menu>li>.treeview-menu {
			margin: 0 1px;
			background: #2c3b41;
		}

		.skin-black-light .treeview-menu>li.active>a,
		.skin-black-light .treeview-menu>li>a:hover {
			color: #fff;
		}

		.skin-black .treeview-menu>li>a {
			color: #8aa4af;
		}

		.box.box-custom-color {
			border-top-color: #222d32;
		}

		.carousel-inner>.item>a>img,
		.carousel-inner>.item>img,
		.img-responsive,
		.thumbnail a>img,
		.thumbnail>img,
		.product-center {
			margin: auto;
		}

		.sports-border {
			border: 1px solid #e2e2e2;
			padding: 5px;
			margin-bottom: 20px;
		}

		.sport-edit-btn {
			margin-top: 5px;
		}

		#prev-img {
			height: 300px;
			width: 300px;
			overflow: hidden;
			object-fit: contain;
			border: 1px solid #e2e2e2;
			padding: 2px;

		}

		/* #prev-img{
				height: 300px;
				width: 300px;
				overflow:hidden;
				object-fit: contain;
				border: 1px solid #e2e2e2;
				padding: 2px;

			} */

		#prev-print-template {
			height: 300px;
			width: 600px;
			overflow: hidden;
			object-fit: contain;
			border: 1px solid #e2e2e2;
			padding: 2px;
		}

		#label-suggest-upload {
			color: red;
		}

		/* for add template step by step design*/
		.wizard {
			margin: 20px auto;
			background: #fff;
			margin-top: -38px;
		}

		.wizard .nav-tabs {
			position: relative;
			margin: 40px auto;
			margin-bottom: 0;
			border-bottom-color: #e0e0e0;
		}

		.wizard>div.wizard-inner {
			position: relative;
		}

		.connecting-line {
			height: 2px;
			background: #e0e0e0;
			position: absolute;
			width: 65%;
			margin: 0 auto;
			left: 0;
			right: 0;
			top: 50%;
			z-index: 1;
		}

		.wizard .nav-tabs>li.active>a,
		.wizard .nav-tabs>li.active>a:hover,
		.wizard .nav-tabs>li.active>a:focus {
			color: #555555;
			cursor: default;
			border: 0;
			border-bottom-color: transparent;
		}

		span.round-tab {
			width: 70px;
			height: 70px;
			line-height: 70px;
			display: inline-block;
			border-radius: 100px;
			background: #fff;
			border: 2px solid #e0e0e0;
			z-index: 2;
			position: absolute;
			left: 0;
			text-align: center;
			font-size: 25px;
		}

		span.round-tab i {
			color: #555555;
		}

		.wizard li.active span.round-tab {
			background: #fff;
			border: 2px solid #5bc0de;

		}

		.wizard li.active span.round-tab i {
			color: #5bc0de;
		}

		span.round-tab:hover {
			color: #333;
			border: 2px solid #333;
		}

		.wizard .nav-tabs>li {
			width: 33.33333333333333%;
		}

		.wizard li:after {
			content: " ";
			position: absolute;
			left: 46%;
			opacity: 0;
			margin: 0 auto;
			bottom: 0px;
			border: 5px solid transparent;
			border-bottom-color: #5bc0de;
			transition: 0.1s ease-in-out;
		}

		.wizard li.active:after {
			content: " ";
			position: absolute;
			left: 46%;
			opacity: 1;
			margin: 0 auto;
			bottom: 0px;
			border: 10px solid transparent;
			border-bottom-color: #5bc0de;
		}

		.wizard .nav-tabs>li a {
			width: 70px;
			height: 70px;
			margin: 20px auto;
			border-radius: 100%;
			padding: 0;
		}

		.wizard .nav-tabs>li a:hover {
			background: transparent;
		}

		.wizard .tab-pane {
			position: relative;
			padding-top: 20px;
		}

		.wizard h3 {
			margin-top: 0;
		}

		@media(max-width : 585px) {

			.wizard {
				width: 90%;
				height: auto !important;
			}

			span.round-tab {
				font-size: 16px;
				width: 50px;
				height: 50px;
				line-height: 50px;
			}

			.wizard .nav-tabs>li a {
				width: 50px;
				height: 50px;
				line-height: 50px;
			}

			.wizard li.active:after {
				content: " ";
				position: absolute;
				left: 35%;
			}
		}

		/*end*/

		.custom-panel-footer.panel-footer {
			padding: 2px 2px;
		}

		.custom-panel-body.panel-body {
			padding: 10px;
		}

		.obj-container {
			height: 254px;
			width: 100%;
			margin: auto;
		}


		/*add pattern Select custom css*/
		.select2-container--default.select2-container--open.select2-container--below .select2-selection--single,
		.select2-container--default.select2-container--open.select2-container--below .select2-selection--multiple {

			border-radius: 0;
			border-color: #d2d6de;
		}

		.select2-container--default .select2-selection--multiple {
			border-radius: 0;
			border-color: #d2d6de;
		}

		.select2-container--default.select2-container--focus .select2-selection--multiple {
			border-color: #d2d6de;
		}

		.select2-container--default .select2-selection--multiple .select2-selection__choice {
			background-color: #3c8dbc;
			border: 1px solid #3c8dbc;
			border-radius: 2px;
			cursor: default;
			float: left;
			margin-right: 5px;
			margin-top: 5px;
			padding: 0 5;
		}

		.select2-container--default .select2-selection--multiple .select2-selection__choice__remove {

			color: #c5c5c5;
			margin-right: 5px;
		}

		/*end add pattern Select custom css*/

		#template-img-preview {
			height: 300px;
			width: 300px;
			overflow: hidden;
			object-fit: contain;
			border: 1px solid #e2e2e2;
			padding: 2px;

		}

		/*listview*/
		div.list-group-item {
			height: auto;
			min-height: 190px;
		}

		div.list-group-item.active small {
			color: #fff;
		}

		.stars {
			margin: 20px auto 1px;
		}

		/*.img-print-preview{
				min-height: 250px;
				height: 250px;
				width: 350px;
			}*/

		#homepage-logo {
			margin-top: 120px;
		}

		.no-record {
			color: #bbbbbb;
		}

		.btn-custom-save {
			width: 150px;
		}

		.error {
			color: #F44336;
		}

		.custom-box-body {
			min-height: 400px;
		}

		.thumbnail>img {
			height: 187px;
		}

		.funkyradio div {
			clear: both;
			overflow: hidden;
		}

		.funkyradio label {
			width: 100%;
			border-radius: 3px;
			border: 1px solid #D1D3D4;
			font-weight: normal;
		}

		.funkyradio input[type="radio"]:empty,
		.funkyradio input[type="checkbox"]:empty {
			display: none;
		}

		.funkyradio input[type="radio"]:empty~label,
		.funkyradio input[type="checkbox"]:empty~label {
			position: relative;
			line-height: 2.5em;
			text-indent: 3.25em;
			margin-top: 2em;
			cursor: pointer;
			-webkit-user-select: none;
			-moz-user-select: none;
			-ms-user-select: none;
			user-select: none;
		}

		.funkyradio input[type="radio"]:empty~label:before,
		.funkyradio input[type="checkbox"]:empty~label:before {
			position: absolute;
			display: block;
			top: 0;
			bottom: 0;
			left: 0;
			content: '';
			width: 2.5em;
			background: #D1D3D4;
			border-radius: 0 0 0 3px;
		}

		.funkyradio input[type="radio"]:hover:not(:checked)~label,
		.funkyradio input[type="checkbox"]:hover:not(:checked)~label {
			color: #888;
		}

		.funkyradio input[type="radio"]:hover:not(:checked)~label:before,
		.funkyradio input[type="checkbox"]:hover:not(:checked)~label:before {
			content: '\2714';
			text-indent: .9em;
			color: #C2C2C2;
		}

		.funkyradio input[type="radio"]:checked~label,
		.funkyradio input[type="checkbox"]:checked~label {
			color: #777;
		}

		.funkyradio input[type="radio"]:checked~label:before,
		.funkyradio input[type="checkbox"]:checked~label:before {
			content: '\2714';
			text-indent: .9em;
			color: #333;
			background-color: #ccc;
		}

		.funkyradio input[type="radio"]:focus~label:before,
		.funkyradio input[type="checkbox"]:focus~label:before {
			box-shadow: 0 0 0 3px #999;
		}

		.funkyradio-default input[type="radio"]:checked~label:before,
		.funkyradio-default input[type="checkbox"]:checked~label:before {
			color: #333;
			background-color: #ccc;
		}

		.funkyradio-primary input[type="radio"]:checked~label:before,
		.funkyradio-primary input[type="checkbox"]:checked~label:before {
			color: #fff;
			background-color: #337ab7;
		}

		.funkyradio-success input[type="radio"]:checked~label:before,
		.funkyradio-success input[type="checkbox"]:checked~label:before {
			color: #fff;
			background-color: #5cb85c;
		}

		.funkyradio-danger input[type="radio"]:checked~label:before,
		.funkyradio-danger input[type="checkbox"]:checked~label:before {
			color: #fff;
			background-color: #d9534f;
		}

		.funkyradio-warning input[type="radio"]:checked~label:before,
		.funkyradio-warning input[type="checkbox"]:checked~label:before {
			color: #fff;
			background-color: #f0ad4e;
		}

		.funkyradio-info input[type="radio"]:checked~label:before,
		.funkyradio-info input[type="checkbox"]:checked~label:before {
			color: #fff;
			background-color: #5bc0de;
		}

		.store-logo-holder {
			width: 200px;
			height: 200px;
			border: 1px solid #e2e2e2;
			padding: 2px;
			text-align: center;
			position: relative;
		}

		#img_store_logo {
			position: absolute;
			margin: auto;
			top: 0;
			left: 0;
			right: 0;
			bottom: 0;
		}

		.store-banner-holder {
			width: 100%;
			height: 100px;
			border: 1px solid #e2e2e2;
			padding: 2px;
			text-align: center;
			position: relative;
		}

		#img_store_banner {
			position: absolute;
			margin: auto;
			top: 0;
			left: 0;
			right: 0;
			bottom: 0;
		}

		.error {
			color: red;
		}

		.store-logo {
			width: 200px;
			height: 200px;
			margin: auto;
			padding: 2px;
			text-align: center;
			position: relative;
		}

		@media (min-width: 768px) {
			.grid-divider {
				position: relative;
				padding: 0;
			}

			.grid-divider>[class*='col-'] {
				position: static;
			}

			.grid-divider>[class*='col-']:nth-child(n+2):before {
				content: "";
				border-left: 1px solid #DDD;
				position: absolute;
				top: 0;
				bottom: 0;
			}

			.col-padding {
				padding: 0 15px;
			}
		}

		/* table.dataTable td,table.dataTable th {
			padding: 3px 10px;
			width: 1px;
			white-space: nowrap;
			} */
	</style>

	<!-- Global site tag (gtag.js) - Google Analytics -->
	<script async src="https://www.googletagmanager.com/gtag/js?id=UA-136108155-1"></script>
	<script>
		window.dataLayer = window.dataLayer || [];

		function gtag() {
			dataLayer.push(arguments);
		}
		gtag('js', new Date());

		gtag('config', 'UA-136108155-1');
	</script>
</head>

<body id="bodyId_" class="sidebar-mini wysihtml5-supported skin-black">
	<div class="wrapper">

		<!-- Header -->
		@include('user-layouts.header')

		<!-- Sidebar -->
		@include('user-layouts.sidebar')

		<!-- Content Wrapper. Contains page content -->
		@yield('content')

		<!-- Footer -->
		@include('user-layouts.footer')
	</div>
	<!-- ./wrapper -->

	<!-- jQuery 2.2.3 -->
	<script src="{{asset('/bower_components/AdminLTE/plugins/jQuery/jquery-2.2.3.min.js')}}"></script>
	<!-- Bootstrap 3.3.6 -->
	<script src="{{asset('/bower_components/AdminLTE/bootstrap/js/bootstrap.min.js')}}"></script>

	<!-- daterangepicker -->
	<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.11.2/moment.min.js"></script>
	<script src="{{asset('/bower_components/AdminLTE/plugins/daterangepicker/daterangepicker.js')}}"></script>
	<!-- datepicker -->
	<script src="{{asset('/bower_components/AdminLTE/plugins/datepicker/bootstrap-datepicker.js')}}"></script>
	<!-- Bootstrap WYSIHTML5 -->
	<script src="{{asset('/bower_components/AdminLTE/plugins/bootstrap-wysihtml5/bootstrap3-wysihtml5.all.min.js')}}"></script>
	<!-- Slimscroll -->
	<script src="{{asset('/bower_components/AdminLTE/plugins/slimScroll/jquery.slimscroll.min.js')}}"></script>
	<!-- FastClick -->
	<script src="{{asset('/bower_components/AdminLTE/plugins/fastclick/fastclick.js')}}"></script>
	<!-- AdminLTE App -->
	<script src="{{asset('/bower_components/AdminLTE/dist/js/app.min.js')}}"></script>
	<!-- AdminLTE dashboard demo (This is only for demo purposes)
	    <script src="{{asset('/bower_components/AdminLTE/dist/js/pages/dashboard.js')}}"></script>-->
	<!-- AdminLTE for demo purposes -->
	<script src="{{asset('/bower_components/AdminLTE/dist/js/demo.js')}}"></script>

	<!-- Select2 -->
	<script src="https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.3/js/select2.min.js"></script>
	<!-- validate jquery -->
	<script src="https://ajax.aspnetcdn.com/ajax/jquery.validate/1.11.1/jquery.validate.min.js"></script>
	<!-- \priceformat -->
	<script src="{{asset('/designer/js/jquery.priceformat.min.js')}}"></script>
	<!-- ekko-lightbox -->
	<script src="https://cdnjs.cloudflare.com/ajax/libs/ekko-lightbox/5.3.0/ekko-lightbox.js"></script>
	<!-- bootstrap-toggle -->
	<script src="https://gitcdn.github.io/bootstrap-toggle/2.2.2/js/bootstrap-toggle.min.js"></script>
	<!-- DataTables -->
	<script src="{{ asset('/bower_components/AdminLTE/plugins/datatables.net/js/jquery.dataTables.min.js') }}"></script>
	<script src="{{ asset('/bower_components/AdminLTE/plugins/datatables.net-bs/js/dataTables.bootstrap.min.js') }}"></script>
	<script src="https://cdn.datatables.net/buttons/1.5.6/js/dataTables.buttons.min.js"></script>
	<script src="https://cdn.datatables.net/buttons/1.5.6/js/buttons.flash.min.js"></script>
	<script src="https://cdnjs.cloudflare.com/ajax/libs/jszip/3.1.3/jszip.min.js"></script>
	<script src="https://cdnjs.cloudflare.com/ajax/libs/pdfmake/0.1.53/pdfmake.min.js"></script>
	<script src="https://cdnjs.cloudflare.com/ajax/libs/pdfmake/0.1.53/vfs_fonts.js"></script>
	<script src="https://cdn.datatables.net/buttons/1.5.6/js/buttons.html5.min.js"></script>
	<script src="https://cdn.datatables.net/buttons/1.5.6/js/buttons.print.min.js"></script>
	<!-- datepicker -->
	<script src="{{asset('/bower_components/AdminLTE/plugins/datepicker/bootstrap-datepicker.js')}}"></script>
	<!-- jquery-ui -->
	<script src="{{ asset('/assets/js/jquery-ui.js') }}"></script>
	{{-- Chartjs --}}
	<script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.9.4/Chart.min.js"></script>



	<script>
		$(document).ready(function() {

			// var ctx = document.getElementById('myChart');
			// var myChart = new Chart(ctx, {
			// 		type: 'line',
			// 		data: {
			// 				labels: ['Red', 'Blue', 'Yellow', 'Green', 'Purple', 'Orange'],
			// 				datasets: [{
			// 						label: '# of Votes',
			// 						data: [12, 19, 3, 5, 2, 3]
			// 				}]
			// 		},
			// 		options: {
			// 				scales: {
			// 						yAxes: [{
			// 								ticks: {
			// 										beginAtZero: true
			// 								}
			// 						}]
			// 				}
			// 		}
			// });

			$.fn.dataTable.ext.search.push(
				function(settings, data, dataIndex) {

					var min = $('#min').datepicker("getDate");
					var max = $('#max').datepicker("getDate");
					var startDate = new Date(data[12]);
					if (min == null && max == null) {
						return true;
					}
					if (min == null && startDate <= max) {
						return true;
					}
					if (max == null && startDate >= min) {
						return true;
					}
					if (startDate <= max && startDate >= min) {
						return true;
					}
					return false;
				}
			);

			$("#min").datepicker({
				onSelect: function() {
					table.draw();
				},
				changeMonth: true,
				changeYear: true
			});
			$("#max").datepicker({
				onSelect: function() {
					table.draw();
				},
				changeMonth: true,
				changeYear: true
			});

			var table = $('#tbl_store_orders').DataTable({
				scrollX: true,
				dom: 'Bfrtip',
				buttons: [{
						extend: 'csv',
						exportOptions: {
							// columns: [ 0, 1, 2, 3, 4, 5, 6, 7, 8, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19 ]
							columns: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23]
						},
						className: "btn btn-default",
						text: "<i class=\"fa fa-table\"></i> CSV",
						title: function() {
							return "ORDER REPORTS";
						}
					},
					{
						extend: 'excel',
						exportOptions: {
							columns: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23]
						},
						className: "btn btn-default",
						text: "<i class=\"fa fa-file-excel-o\"></i> Excel",
						title: function() {
							return "ORDER REPORTS";
						}
					}

					//,
					// {
					// 	extend: 'pdf',
					// 	exportOptions: {
					// 		columns: [ 0, 1, 2, 3, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14 ]
					// 	},
					// 	className : "btn btn-default",
					// 	text: "<i class=\"fa fa-file-pdf-o\"></i> PDF",
					// 	orientation: 'landscape',
					// 	pageSize: 'LEGAL',
					// 	title : function() {
					// 		return "ORDER REPORTS";
					// 	}

					// },
					// {
					// 	extend: 'print',
					// 	exportOptions: {
					// 		columns: [ 0, 1, 2, 3, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14 ]
					// 	},
					// 	className : "btn btn-default",
					// 	text : "<i class=\"fa fa-print\"></i> Print",
					// 	orientation: 'landscape',
					// 	pageSize: 'LEGAL',
					// 	title : function() {
					// 		return "ORDER REPORTS";
					// 	}
					// }
				],
				columnDefs: [{
						targets: 12,
						type: 'date',
						visible: false
					},
					{
						targets: 12,
						type: 'date'
					}
				],

			});

			// Event listener to the two range filtering inputs to redraw on input
			$('#min, #max').change(function() {
				table.draw();
			});


			$(document).on('a click', '.btn-order-item-details', function(e) {

				e.preventDefault();
				var getCK = $(this).data('ck');
				var getPid = $(this).data('pid');
				var getId = $(this).data('id');
				$.ajax({
					data: {
						ck: getCK,
						pid: getPid,
						id: getId
					},
					type: 'POST',
					url: "{{ url('user/post/show-store-order-details') }}",
					dataType: 'json',
					beforeSend: function(xhr) {

						var token = $('meta[name="csrf_token"]').attr('content');

						if (token) {
							return xhr.setRequestHeader('X-CSRF-TOKEN', token);
						}
						xhr.setRequestHeader('X-Requested-With', 'XMLHttpRequest');
					},
					success: function(result) {
						if (result.success) {
							$('#modal_store_order_details_body_content').html(result.payment_details_response);
						}
					}
				});
				$('#modal_store_order_details').modal('show');
			});

			$(document).on('a click', '.btn-add-thumbnail', function(e) {
				e.preventDefault();
				$('#modal_add_thumbnail').modal('show');


			});
			$('.select2').select2();

			var tr_sortable = $('#sortable');

			var item_list_sort = $('#item_list_sort');
			item_list_sort.sortable();
			item_list_sort.disableSelection();
			// setTimeout(function(){ 
			// 	item_list_sort.sortable("disable");
			// }, 500);


			tr_sortable.sortable({
				revert: 100,
				placeholder: 'placeholder'
			});

			tr_sortable.disableSelection();

			$('#btn_save_thumbnail_sorting').on('click', function(e) {
				e.preventDefault();
				var sortable_data = tr_sortable.sortable('serialize');
				$.ajax({
					data: sortable_data,
					type: 'POST',
					url: "{{ url('user/post/save-thumbnail-ordering') }}",
					beforeSend: function(xhr) {

						var token = $('meta[name="csrf_token"]').attr('content');

						if (token) {
							return xhr.setRequestHeader('X-CSRF-TOKEN', token);
						}
						xhr.setRequestHeader('X-Requested-With', 'XMLHttpRequest');
					},
					success: function(result) {
						// div_response.html(result);
						console.log(result);
						if (result.success) {
							alert('Thumbnail ordering is succcessfully updated!');
						}
					}
				});
			});

			$('#btn_save_item_sorting').on('click', function(e) {
				e.preventDefault();
				var sorted_data = item_list_sort.sortable('serialize');
				$.ajax({
					data: sorted_data,
					type: 'POST',
					url: "{{ url('user/post/save-item-ordering') }}",
					beforeSend: function(xhr) {

						var token = $('meta[name="csrf_token"]').attr('content');

						if (token) {
							return xhr.setRequestHeader('X-CSRF-TOKEN', token);
						}
						xhr.setRequestHeader('X-Requested-With', 'XMLHttpRequest');
					},
					success: function(result) {
						// div_response.html(result);
						console.log(result);
						if (result.success) {
							alert('Item ordering is succcessfully updated!');
						}
					}
				});
			});

			$('#myModal').on('hidden.bs.modal', function() {
				location.reload();
			});

			$('#OpenImgUpload').click(function() {
				$('#imgupload').trigger('click');
				return false;
			});

			$('#OpenImgUpload2').click(function() {
				// $('#imgupload').trigger('click'); 

				var getImages = $('#imgupload').val();

				// console.log(getImages);
				return false;
			});

			var imagesPreview = function(input) {

				if (input.files) {
					var filesAmount = input.files.length;
					$('#main_thumbnail_uploader').css({
						"display": "none"
					});

					$('#upload_thumbnail_preview').css({
						"display": ""
					});

					for (i = 0; i < filesAmount; i++) {
						var reader = new FileReader();

						if (i == 0) {
							reader.onload = function(event) {
								$('#main-thumbnail').attr('src', event.target.result);
								$(".small-preview-thumb").prepend('<li class="col-sm-3 col-xs-3"> ' +
									'<a class="text-center thumbnail a_thumbnail active"> ' +
									'<img class="img img-responsive product-center image-thumbnails" style="height: 90px;" src="' + event.target.result + '"/> ' +
									'</a> ' +
									'</li>');
							}
						} else {
							reader.onload = function(event) {
								$(".small-preview-thumb").prepend('<li class="col-sm-3 col-xs-3"> ' +
									'<a class="text-center thumbnail a_thumbnail"> ' +
									'<img class="img img-responsive product-center image-thumbnails" style="height: 90px;" src="' + event.target.result + '"/> ' +
									'</a> ' +
									'</li>');
							}
						}

						reader.readAsDataURL(input.files[i]);
					}
				}

			};

			// for add Image ( View Item Details)
			var imagesPreview1 = function(input) {
				if (input.files) {
					var filesAmount = input.files.length;
					$(".small-preview-thumb").html('');
					for (i = 0; i < filesAmount; i++) {
						var reader = new FileReader();
						reader.onload = function(event) {
							$(".small-preview-thumb").fadeIn(500, function() {
								$(this).append('<li class="col-sm-3 col-xs-3"> ' +
									'<a class="text-center thumbnail a_thumbnail"> ' +
									'<img class="img img-responsive product-center image-thumbnails" style="height: 90px;" src="' + event.target.result + '"/> ' +
									'</a> ' +
									'</li>');
							});
						}
						reader.readAsDataURL(input.files[i]);
					}
				}
			};

			$('#imgupload').on('change', function() {
				imagesPreview(this);
			});

			$('#upload_images').on('change', function() {
				imagesPreview1(this);
			});

			$('#clear_frm_add_new_images').click(function() {
				$('#frm_add_new_images')[0].reset();
				$(".small-preview-thumb").html('');
			});

			$('.price_format').priceFormat({
				prefix: '$ '
			});

			resend_timer();


			$("#frm-create-address-book").validate({
				rules: {
					fullname: {
						required: true
					},
					mobilenumber: {
						required: true
					},
					address: {
						required: true
					},
					state: {
						required: true
					},
					city: {
						required: true
					},
					zipcode: {
						required: true
					},
					countryCode: {
						required: true
					}
				},

				messages: {},
				errorPlacement: function(error, element) {
					var placement = $(element).data('error');

					if (placement) {

						$(placement).append(error)

					} else {

						error.insertAfter(element);

					}
				},
				submitHandler: submitFormCreateAddressBook
			});

			$("#frm-edit-address-book").validate({
				rules: {
					fullname: {
						required: true
					},
					mobilenumber: {
						required: true
					},
					state: {
						required: true
					},
					city: {
						required: true
					},
					address: {
						required: true
					},
					zipcode: {
						required: true
					},
					countryCode: {
						required: true
					}
				},
				messages: {},
				errorPlacement: function(error, element) {
					var placement = $(element).data('error');

					if (placement) {

						$(placement).append(error)

					} else {

						error.insertAfter(element);

					}
				},
				submitHandler: submitFormEditAddressBook
			});

			$("#frm-edit-profile").validate({
				rules: {
					fullname: {
						required: true
					},
					contactnumber: {
						required: true,
						number: true
					},
					email: {
						required: true,
						email: true
					},
					birthday: {
						required: true
					},
					gender: {
						required: true
					}
				},
				messages: {},
				errorPlacement: function(error, element) {
					var placement = $(element).data('error');

					if (placement) {

						$(placement).append(error)

					} else {

						error.insertAfter(element);

					}
				},
				submitHandler: submitFormEditProfile
			});

			$('#datepicker_bday').datepicker({
				// calendarWeeks: true,
				// todayHighlight: true,
				autoclose: true
			});

			$("#frm-change-password").validate({
				rules: {
					current_password: {
						required: true
					},
					new_password: {
						required: true
					},
					con_new_password: {
						required: true
					}
				},
				messages: {},
				errorPlacement: function(error, element) {
					var placement = $(element).data('error');

					if (placement) {

						$(placement).append(error)

					} else {

						error.insertAfter(element);

					}
				},
				submitHandler: submitFormChangePassword
			});

			$("#frm-design-details").validate({
				rules: {
					design_name: {
						required: true
					},

					design_code: {
						require: true
					}
				},
				messages: {},
				errorPlacement: function(error, element) {
					var placement = $(element).data('error');

					if (placement) {

						$(placement).append(error)

					} else {

						error.insertAfter(element);

					}
				},
				submitHandler: submitFormDesignDetails
			});

			$("#frm-item-details").validate({
				rules: {
					item_url: {
						required: true
					},
					itemName: {
						required: true
					},
					itemDescription: {
						required: true
					},
					item_price: {
						required: true
					},
					item_privacy: {
						required: true
					},
					available_size: {
						required: true
					}

				},
				messages: {},
				errorPlacement: function(error, element) {
					var placement = $(element).data('error');

					if (placement) {

						$(placement).append(error)

					} else {

						error.insertAfter(element);

					}
				},
				submitHandler: submitFormItemDetails
			});

			$("#frm-add-item").validate({
				rules: {
					imgupload: {
						required: true
					},
					itemName: {
						required: true
					},
					itemDescription: {
						required: true
					},
					item_price: {
						required: true
					},
					item_url: {
						required: true
					},
					available_size: {
						required: true
					},
					item_privacy: {
						required: true
					}

				},
				messages: {},
				errorPlacement: function(error, element) {
					var placement = $(element).data('error');

					if (placement) {

						$(placement).append(error)

					} else {

						error.insertAfter(element);

					}
				},
				submitHandler: submitFormAddItem
			});

			$("#frm_add_new_images").validate({
				rules: {
					upload_images: {
						required: true
					}
				},
				messages: {},
				errorPlacement: function(error, element) {
					var placement = $(element).data('error');

					if (placement) {

						$(placement).append(error)

					} else {

						error.insertAfter(element);

					}
				},
				submitHandler: submitFormAddNewImage
			});

			$("#frm_verification_code").validate({
				rules: {
					verification_code: {
						required: true
					}

				},
				messages: {},
				errorPlacement: function(error, element) {
					var placement = $(element).data('error');

					if (placement) {

						$(placement).append(error)

					} else {

						error.insertAfter(element);

					}
				},
				submitHandler: submitFormVerificationCode
			});

			$("#frm_sell_design").validate({
				rules: {
					itemName: {
						required: true
					},
					itemDescription: {
						required: true
					},
					itemPrice: {
						required: true
					},
					itemForm: {
						required: true
					},
					itemUrl: {
						required: true
					},
					available_size: {
						required: true
					},
					itemPrivacy: {
						required: true
					},
				},
				messages: {},
				errorPlacement: function(error, element) {
					var placement = $(element).data('error');

					if (placement) {

						$(placement).append(error)

					} else {

						error.insertAfter(element);

					}
				},
				submitHandler: submitSellDesignForm
			});

			$(document).on('button click', '.btn-delete-item-image', function(e) {
				e.preventDefault();
				var thumb_filename = $(this).data('filename');
				var thumb_id = $(this).data('id');
				// console.log(thumb_id);
				$.ajax({ //create an ajax request to load_page.php
					type: "POST",
					url: "{{  url('user/post/delete-image-thumb') }}",
					data: {
						thumb_filename: thumb_filename,
						thumb_id: thumb_id
					},
					dataType: 'json',
					beforeSend: function(xhr) {
						var token = $('meta[name="csrf_token"]').attr('content');

						if (token) {
							return xhr.setRequestHeader('X-CSRF-TOKEN', token);
						}
						xhr.setRequestHeader('X-Requested-With', 'XMLHttpRequest');
					},
					success: function(response) {
						// console.log(response);
						$('#' + response.delete_row).fadeOut(300, function() {
							$(this).remove();
						});
					}
				});
			});

			$(document).on('button click', '#chk-currentpass', function() {

				if ($(this).is(':checked')) {
					$('#current_password').attr('type', 'text');
				} else {
					$('#current_password').attr('type', 'password');
				}
			});

			$(document).on('button click', '#chk-newpass', function() {

				if ($(this).is(':checked')) {
					$('#new_password').attr('type', 'text');
				} else {
					$('#new_password').attr('type', 'password');
				}
			});

			$(document).on('button click', '#chk-con-newpass', function() {

				if ($(this).is(':checked')) {
					$('#con_new_password').attr('type', 'text');
				} else {
					$('#con_new_password').attr('type', 'password');
				}
			});


			$(document).on('a click', '#btn_resend_code', function() {

				var email = $(this).data("email");

				$.ajax({
					type: 'POST',
					url: "{{ url('user/post/resend-verification') }}",
					data: {
						email: email
					},
					beforeSend: function(xhr) {
						$('#btn_resend_code').attr('disabled', true);
						$('#btn_resend_code').append(' <i class="fa fa-circle-o-notch fa-spin"></i>');

						var token = $('meta[name="csrf_token"]').attr('content');

						if (token) {
							return xhr.setRequestHeader('X-CSRF-TOKEN', token);
						}
						xhr.setRequestHeader('X-Requested-With', 'XMLHttpRequest');
					},
					success: function(response) {

						if (response) {
							alert("Verification code is successfully sent.");

							$('#btn_resend_code').html('<i class="fa fa-angle-double-right"></i> Resend Code <span class="badge" id="resend_countdown"></span>');

							var settime = 120;
							localStorage.setItem('timerRunning', 'true');
							localStorage.setItem('timeleft', settime);
							var getTimeleft = parseInt(localStorage.getItem('timeleft'));


							var getTimeleft = parseInt(localStorage.getItem('timeleft'));
							var downloadTimer = setInterval(function() {
								$('#resend_countdown').html(getTimeleft);

								var timeleft = getTimeleft -= 1;
								localStorage.setItem('timeleft', timeleft);

								if (timeleft <= 0) {
									clearInterval(downloadTimer);
									$('#resend_countdown').html('');
									localStorage.setItem('timerRunning', 'false');
									$('#btn_resend_code').attr('disabled', false);

								}
							}, 1000);

						} else {
							alert("Something went wrong, Please try again.");
							location.reload();
						}
					}
				});

			});

			// $('.image-thumbnails').click(function(){
			$(document).on('button click', '.image-thumbnails', function() {
				// console.log($(this)[0].firstElementChild.geAttribute('class'))
				// console.log($(this).attr('src'))
				$('#main-thumbnail').attr('src', $(this).attr('src'));

				$('.a_thumbnail').removeClass('active');
				$(this).parent().addClass('active');
			});

			$(document).on('button click', '#btn-reload-thumbnails', function() {

				$(this).attr('disabled', 'disabled');
				$('.thumb-content').html('Please wait..');
				var ip = "116.93.97.200";
				var port = $(this).data('port');
				var url = "http://" + ip + ":" + port + "/forceload/" + $(this).data('dd');
				// console.log(url);
				$.ajax({ //create an ajax request to load_page.php
					type: "GET",
					url: "http://" + ip + ":" + port + "/forceload/" + $(this).data('dd'),
					dataType: "json", //expect html to be returned
					beforeSend: function() {
						// console.log('loading images');
					},
					success: function(response) {
						if (response['status'] == "success") {
							location.reload();
						} else {
							alert("Error: failed to reload the thumbnail. Please try again");
							location.reload();
						}
					}
				});


			});

			$("#itemName").on('keyup', function() {
				var getsportName = $(this).val();
				getsportName = getsportName.replace(/\s+/g, '-').toLowerCase(); //new object assigned to var str
				$("#product_url").val(getsportName);
				// /[\/]/g matches forward slashes.
				// /[\\]/g matches backward slashes.
			});

			$('#list').click(function(event) {
				event.preventDefault();
				$('#products .item').addClass('list-group-item');
			});
			$('#grid').click(function(event) {
				event.preventDefault();
				$('#products .item').removeClass('list-group-item');
				$('#products .item').addClass('grid-group-item');
			});

			$('input[name="setActive"]').change(function() {
				if ($(this).prop('checked')) {

					var product_id = $(this).data('product-id');
					var id = $(this).data('id');
					$.ajax({
						type: 'POST',
						url: "{{ url('user/update-active-thumbnail') }}",
						data: {
							product_id: product_id,
							id: id
						},
						beforeSend: function(xhr) {
							var token = $('meta[name="csrf_token"]').attr('content');

							if (token) {
								return xhr.setRequestHeader('X-CSRF-TOKEN', token);
							}
							xhr.setRequestHeader('X-Requested-With', 'XMLHttpRequest');
						},
						success: function(response) {
							console.log(response);
						}
					});
					return false;
				}
			});

			$(document).on('click', '[data-toggle="lightbox"]', function(event) {
				event.preventDefault();
				$(this).ekkoLightbox({
					alwaysShowClose: true,
				});
			});

			$('#with_password_opt').change(function() {
				if ($(this).prop('checked')) {
					$('.store-password-field').css({
						'display': 'block'
					});
				} else {
					$('.store-password-field').css({
						'display': 'none'
					});
				}
			});

			$('#isActiveAnnouncement').change(function() {

				$.ajax({
					type: 'POST',
					url: "{{ url('user/announcement/status/update') }}",
					data: {
						Id: $(this).data('id'),
						IsActive: $(this).prop('checked')
					},
					beforeSend: function(xhr) {
						var token = $('meta[name="csrf_token"]').attr('content');

						if (token) {
							return xhr.setRequestHeader('X-CSRF-TOKEN', token);
						}
						xhr.setRequestHeader('X-Requested-With', 'XMLHttpRequest');
					},
					success: function(response) {
						if (response.success) {
							alert(response.message);
						} else {
							// $('#isActiveAnnouncement').attr('checked', false);

							$('#isActiveAnnouncement').removeClass('btn-primary');
							// $(this).addClass('btn-default');



						}
					}
				});
				return false;
			});

			$("#frm_edit_store").validate({
				rules: {
					store_name: {
						required: true
					},
					store_url: {
						required: true
					},
					store_password: {
						required: '#with_password_opt:checked'
					},
					// store_logo: {
					//     required: true
					// },
					// store_banner: {
					//     required: true
					// },
					store_status: {
						required: true
					},
				},
				messages: {},
				errorPlacement: function(error, element) {
					var placement = $(element).data('error');
					if (placement) {
						$(placement).append(error);
					} else {
						error.insertAfter(element);
					}
				},
				submitHandler: submitFormEditStore
			});

			$("#form_announcement").validate({
				rules: {
					announcementInput: {
						required: true
					}
				},
				messages: {},
				errorPlacement: function(error, element) {
					var placement = $(element).data('error');
					if (placement) {
						$(placement).append(error);
					} else {
						error.insertAfter(element);
					}
				},
				submitHandler: submitFormAnnouncement
			});

			$("#store_name").on('keyup', function() {
				var getsportName = $(this).val();
				getsportName = getsportName.replace(/\s+/g, '-').toLowerCase(); //new object assigned to var str
				$("#store_url").val(getsportName);
			});

			$(".upload_img").change(function() {
				var $id = $(this).data('use-id');
				readURL(this, $id);
			});

			$("#btn_delete_store_id").click(function() {
				var id = $(this).data('id');

				var result = confirm("Are you want to delete?");
				if (result) {
					//Logic to delete the item
					$.ajax({
						type: 'POST',
						url: "{{ url('user/store-items/delete') }}",
						data: {
							id: id
						},
						beforeSend: function(xhr) {
							var token = $('meta[name="csrf_token"]').attr('content');

							if (token) {
								return xhr.setRequestHeader('X-CSRF-TOKEN', token);
							}
							xhr.setRequestHeader('X-Requested-With', 'XMLHttpRequest');
						},
						success: function(response) {
							// console.log(response);
							if (response.success) {
								alert(response.message);
								window.location = "{{ url('user/store-items') }}";
							} else {
								alert("Something went wrong. Please try again!");
								location.reload();
							}
						}
					});
					return false;
				}
				return false;
			});

			$(document).on('button click', '.btn-purchase', function() {
				// console.log()
				var designCode = $(this).data('design-code');
				// var images_thumb = $('#images_thumb').val();
				$.ajax({
					type: 'POST',
					url: "{{ url('/user/store-items/personal-design') }}",
					data: {
						designCode: designCode
					},
					beforeSend: function(xhr) {
						var token = $('meta[name="csrf_token"]').attr('content');

						if (token) {
							return xhr.setRequestHeader('X-CSRF-TOKEN', token);
						}
						xhr.setRequestHeader('X-Requested-With', 'XMLHttpRequest');
					},
					success: function(response) {
						if (response.success) {
							window.location = response.link;
						} else {
							alert("Something went wrong. Please try again.");
							location.reload();
						}
					}
				});
				return false;
			});

			// fetchUSA()
			// fetchCanada()
			getSelectedCountry()
		}); //end document ready

		// function

		function getSelectedCountry() {
			var selectedState = $('#select_country').data('selected');
			if (selectedState) {
				// console.log(selectedState)
				$("#select_country").val(selectedState).change();
				// selectCountry()
			}

		}

		function selectCountry(item) {

			const country = item.options[item.selectedIndex].text;
			const countryCode = item.options[item.selectedIndex].value
			console.log(countryCode)

			if (countryCode === "US") {
				fetchUSA()
			}

			if (countryCode === "CA") {
				fetchCanada()
			}

		}

		function fetchCanada() {
			$.getJSON("{{ asset('/api/canada.json') }}", function(items) {
				var states = [];

				Object.keys(items).forEach(function(state) {
					states.push(state)
				});

				var uniqueStates = Array.from(new Set(states));
				var selectedState = $('#lst-states').data('selected');

				$('.dynamic-state').remove();
				$('.dynamic-city').remove();
				uniqueStates.sort().forEach(function(key) {
					if (selectedState == key) {
						$('#lst-states').append('<option value="' + key + '" selected class="dynamic-state">' + key + '</option>');

						var cities = [];
						cities = items[selectedState];
						var uniqueCities = Array.from(new Set(cities));
						var selectedCity = $('#lst-cities').data('selected');
						$('.dynamic-city').remove();
						uniqueCities.sort().forEach(function(key) {
							if (selectedCity == key) {
								$('#lst-cities').append('<option value="' + key + '" class="dynamic-city" selected>' + key + '</option>');
							} else {
								$('#lst-cities').append('<option value="' + key + '" class="dynamic-city">' + key + '</option>');
							}
						});

					} else {
						$('#lst-states').append('<option value="' + key + '" class="dynamic-state">' + key + '</option>');
					}
				});


				$(document).on('select change', '#lst-states', function() {
					var cities = [];
					var selectedState = $(this).val()
					cities = items[selectedState];
					var uniqueCities = Array.from(new Set(cities));
					$('.dynamic-city').remove();
					uniqueCities.sort().forEach(function(key) {
						$('#lst-cities').append('<option value="' + key + '" class="dynamic-city">' + key + '</option>');
					});
				});
			});
		}

		function fetchUSA() {
			$.getJSON("{{ asset('/api/usaCities.json') }}", function(data) {
				var states = [];

				for (i = 0; i < data.length; i++) {
					states.push(data[i]['state']);
				}
				var uniqueStates = Array.from(new Set(states));
				var selectedState = $('#lst-states').data('selected');
				$('.dynamic-state').remove();
				$('.dynamic-city').remove();
				uniqueStates.sort().forEach(function(key) {
					if (selectedState == key) {
						$('#lst-states').append('<option value="' + key + '" selected class="dynamic-state">' + key + '</option>');
						// 
						var cities = [];
						for (i = 0; i < data.length; i++) {
							console.log(data[i])
							cities.push(data[i]);
						}
						var city = getCities(cities, key);
						var uniqueCities = Array.from(new Set(city));
						var selectedCity = $('#lst-cities').data('selected');
						$('.dynamic-city').remove();
						uniqueCities.sort().forEach(function(key) {
							if (selectedCity == key) {
								$('#lst-cities').append('<option value="' + key + '" class="dynamic-city" selected>' + key + '</option>');
							} else {
								$('#lst-cities').append('<option value="' + key + '" class="dynamic-city">' + key + '</option>');
							}
						});

					} else {
						$('#lst-states').append('<option value="' + key + '" class="dynamic-state">' + key + '</option>');
					}
				});



				$(document).on('select change', '#lst-states', function() {
					var cities = [];
					for (i = 0; i < data.length; i++) {
						cities.push(data[i]);
					}
					var city = getCities(cities, $(this).val());
					var uniqueCities = Array.from(new Set(city));
					$('.dynamic-city').remove();
					uniqueCities.sort().forEach(function(key) {

						$('#lst-cities').append('<option value="' + key + '" class="dynamic-city">' + key + '</option>');
					});
				});

			});
		}


		function submitFormAnnouncement() {
			var data = $("#form_announcement").serialize();
			// console.log(data);
			$.ajax({
				type: 'POST',
				url: "{{ url('user/announcement/updateSave') }}",
				data: data,
				beforeSend: function(xhr) {
					var token = $('meta[name="csrf_token"]').attr('content');

					if (token) {
						return xhr.setRequestHeader('X-CSRF-TOKEN', token);
					}
					xhr.setRequestHeader('X-Requested-With', 'XMLHttpRequest');
				},
				success: function(response) {
					console.log(response);
					if (response) {
						alert(response.message);
					} else {
						alert(response.message);
						location.reload();
					}
				}
			});
			return false;
		}

		function submitFormEditStore() {
			$.ajax({
				type: "POST",
				url: "{{ url('user/store-settings/update') }}",
				data: new FormData($('#frm_edit_store')[0]),
				processData: false,
				contentType: false,
				dataType: 'json',
				beforeSend: function(xhr) {
					$("#btn_update_store").attr('disabled', true);
					$("#btn_update_store").html('<i class="fa fa-spinner fa-spin"></i> Saving...');

					var token = $('meta[name="csrf_token"]').attr('content');
					if (token) {
						return xhr.setRequestHeader('X-CSRF-TOKEN', token);
					}

				},
				success: function(response) {
					// console.log(response);
					if (response.success) {
						$('#edit_store_msg').html('<div class="alert alert-success alert-dismissible"> ' +
							'<button type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button> ' +
							'<h4><i class="icon fa fa-check"></i> Success!</h4> ' +
							'<p>' + response.message + '</p> ' +
							'</div>').fadeIn().delay(5000).fadeOut();

					} else {
						$('#edit_store_msg').html('<div class="alert alert-danger alert-dismissible"> ' +
							'<button type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button> ' +
							'<h4><i class="icon fa fa-ban"></i> Error!</h4> ' +
							'<p>' + response.message + '</p> ' +
							'</div>').fadeIn().delay(5000).fadeOut();
					}

					$("html, body").animate({
						scrollTop: 0
					}, "slow");
					$("#btn_update_store").attr('disabled', false);
					$("#btn_update_store").html('Save Changes');

					if (response.clearform) {
						var form = $('#frm_edit_store')
						form.validate().resetForm();
						form[0].reset();

						// $("#with_password_opt").prop("checked", false);

						$('.img_store_logo_href').attr('href', "{{ config('site_config.images_directory')  . 'teamstore/store-logo-placeholder.jpg' }}");
						$('.img_store_logo_img').attr('src', "{{ config('site_config.images_directory')  . 'teamstore/store-logo-placeholder.jpg' }}");

						$('.img_store_banner_href').attr('href', "{{ config('site_config.images_directory')  . 'teamstore/store-banner-placeholder.jpg' }}");
						$('.img_store_banner_img').attr('src', "{{ config('site_config.images_directory')  . 'teamstore/store-banner-placeholder.jpg' }}");
					}
				}
			});
			return false;
		}

		function getCities(arr, q) {
			var sd = [];
			arr.find(function(element) {
				if (element['state'] == q) {
					sd.push(element['city']);
				}
			});
			return sd;
		}

		function submitFormCreateAddressBook() {
			var data = $("#frm-create-address-book").serializeArray();
			data.push({
				name: "country",
				value: $("#select_country option:selected").text()
			});
			$.ajax({
				type: 'POST',
				url: "{{ url('user/address-book/save') }}",
				data: data,
				beforeSend: function(xhr) {
					var token = $('meta[name="csrf_token"]').attr('content');

					if (token) {
						return xhr.setRequestHeader('X-CSRF-TOKEN', token);
					}
					xhr.setRequestHeader('X-Requested-With', 'XMLHttpRequest');
				},
				success: function(response) {
					// console.log(response);
					if (response) {
						alert("Address is successfully added.");
						window.location = "{{ url('/cart') }}";
					} else {
						alert("Something went wrong. Please try again!");
						location.reload();
					}
				}
			});
			return false;
		}

		function submitFormEditAddressBook() {
			var data = $("#frm-edit-address-book").serializeArray();
			data.push({
				name: "country",
				value: $("#select_country option:selected").text()
			});
			$.ajax({
				type: 'POST',
				url: "{{ url('user/address-book/update') }}",
				data: data,
				beforeSend: function(xhr) {
					var token = $('meta[name="csrf_token"]').attr('content');

					if (token) {
						return xhr.setRequestHeader('X-CSRF-TOKEN', token);
					}
					xhr.setRequestHeader('X-Requested-With', 'XMLHttpRequest');
				},
				success: function(response) {
					// console.log(response);
					if (response) {
						alert("Address is successfully updated.");
						window.location = "{{ url('/cart') }}";
					} else {
						alert("Something went wrong. Please try again!");
						location.reload();
					}
				}
			});
			return false;
		}

		function submitFormEditProfile() {
			var data = $("#frm-edit-profile").serialize();
			// console.log(data);
			$.ajax({
				type: 'POST',
				url: "{{ url('user/profile/update') }}",
				data: data,
				beforeSend: function(xhr) {
					var token = $('meta[name="csrf_token"]').attr('content');

					if (token) {
						return xhr.setRequestHeader('X-CSRF-TOKEN', token);
					}
					xhr.setRequestHeader('X-Requested-With', 'XMLHttpRequest');
				},
				success: function(response) {
					// console.log(response);
					if (response) {
						alert("Your profile is successfully updated.");
						window.location = "{{ url('user/profile') }}";
					} else {
						alert("Something went wrong. Please try again!");
						location.reload();
					}
				}
			});
			return false;
		}

		function submitFormChangePassword() {
			var data = $("#frm-change-password").serialize();
			// console.log(data);
			$.ajax({
				type: 'POST',
				url: "{{ url('user/profile/update-password') }}",
				data: data,
				beforeSend: function(xhr) {
					var token = $('meta[name="csrf_token"]').attr('content');

					if (token) {
						return xhr.setRequestHeader('X-CSRF-TOKEN', token);
					}
					xhr.setRequestHeader('X-Requested-With', 'XMLHttpRequest');
				},
				success: function(response) {
					// console.log(response);
					if (response) {
						if (response != 1) {
							alert(response);
							// window.location = "{{ url('user/profile/change-password') }}";
						} else {

							alert("Your password is successfully updated.");
							window.location = "{{ url('user/profile') }}";
						}

					} else {
						alert("Something went wrong. Please try again!");
						location.reload();
					}
				}
			});
			return false;
		}

		function submitFormDesignDetails() {
			var data = $("#frm-design-details").serialize();
			// console.log(data);
			$.ajax({
				type: 'POST',
				url: "{{ url('user/my-designs/update') }}",
				data: data,
				beforeSend: function(xhr) {
					var token = $('meta[name="csrf_token"]').attr('content');

					if (token) {
						return xhr.setRequestHeader('X-CSRF-TOKEN', token);
					}
					xhr.setRequestHeader('X-Requested-With', 'XMLHttpRequest');
				},
				success: function(response) {
					// console.log(response);
					if (response) {
						alert('Design details is successfully updated.');
						location.reload();
					} else {
						alert("Something went wrong. Please try again!");
						location.reload();
					}
				}
			});
			return false;
		}


		function submitFormItemDetails() {
			var data = $("#frm-item-details").serialize();
			$.ajax({
				type: 'POST',
				url: "{{ url('user/store-items/update') }}",
				data: data,
				beforeSend: function(xhr) {
					var token = $('meta[name="csrf_token"]').attr('content');

					if (token) {
						return xhr.setRequestHeader('X-CSRF-TOKEN', token);
					}
					xhr.setRequestHeader('X-Requested-With', 'XMLHttpRequest');
				},
				success: function(response) {
					// console.log(response);
					if (response) {
						alert('Item details is successfully updated.');
						location.reload();
					} else {
						alert("Something went wrong. Please try again!");
						location.reload();
					}
				}
			});
			return false;
		}

		function submitFormAddItem() {

			$.ajax({
				type: 'POST',
				url: "{{ url('user/store-items/save-new-item') }}",
				data: new FormData($('#frm-add-item')[0]),
				processData: false,
				contentType: false,
				beforeSend: function(xhr) {
					$("#add_item_response_msg").fadeOut();
					$("#btn_submit_new_item").html('Saving... &nbsp; <i class="fa fa-spinner fa-spin"></i>');
					$("#btn_submit_new_item").prop("disabled", true);
					var token = $('meta[name="csrf_token"]').attr('content');

					if (token) {
						return xhr.setRequestHeader('X-CSRF-TOKEN', token);
					}
					xhr.setRequestHeader('X-Requested-With', 'XMLHttpRequest');

				},
				success: function(response) {
					if (response.success) {
						alert('New item is successfully added.');
						location.reload();
					} else {
						// alert("Something went wrong. Please try again!");
						$("#add_item_response_msg").html("");
						$("#add_item_response_msg").fadeIn(1000, function() {
							$("#add_item_response_msg").html(response.message);
							$("#btn_submit_new_item").prop("disabled", false);
							$("#btn_submit_new_item").html('Submit');
						});
					}

				}
			});
			return false;
		}

		function submitFormAddNewImage() {
			$.ajax({
				type: 'POST',
				url: "{{ url('user/store-items/save-new-item-image') }}",
				data: new FormData($('#frm_add_new_images')[0]),
				processData: false,
				contentType: false,
				beforeSend: function(xhr) {
					$("#new_item_image_response_msg").fadeOut();
					$("#btn_submit_new_item_image").html('Please wait &nbsp; <i class="fa fa-spinner fa-spin"></i>');
					$("#btn_submit_new_item_image").prop("disabled", true);

					var token = $('meta[name="csrf_token"]').attr('content');
					if (token) {
						return xhr.setRequestHeader('X-CSRF-TOKEN', token);
					}
					xhr.setRequestHeader('X-Requested-With', 'XMLHttpRequest');

				},
				success: function(response) {
					if (response.success) {
						alert('New item image(s) is successfully added.');
						location.reload();
					} else {
						$("#new_item_image_response_msg").html("");
						$("#new_item_image_response_msg").fadeIn(1000, function() {
							$("#new_item_image_response_msg").html(response.message);
							$("#btn_submit_new_item_image").prop("disabled", false);
							$("#btn_submit_new_item_image").html('Submit');
						});
					}

				}
			});
			return false;
		}

		function submitFormVerificationCode() {
			var data = $("#frm_verification_code").serialize();

			$.ajax({
				type: 'POST',
				url: "{{ url('user/post/verify-code') }}",
				data: data,
				dataType: 'json',
				beforeSend: function(xhr) {
					var token = $('meta[name="csrf_token"]').attr('content');

					if (token) {
						return xhr.setRequestHeader('X-CSRF-TOKEN', token);
					}
					xhr.setRequestHeader('X-Requested-With', 'XMLHttpRequest');
				},
				success: function(response) {
					// console.log(response);
					if (response.success) {
						alert(response.message);
						window.location = "{{ url('user/profile') }} ";
					} else {
						alert(response.message);
						location.reload();
					}
				}
			});
			return false;
		}

		function resend_timer() {
			var settime = 129;
			var getTimeStatus = localStorage.getItem('timerRunning');

			if (getTimeStatus == 'true') {

				var getTimeleft = parseInt(localStorage.getItem('timeleft'));
				var downloadTimer = setInterval(function() {
					$('#resend_countdown').html(getTimeleft);

					var timeleft = getTimeleft -= 1;
					localStorage.setItem('timeleft', timeleft);

					if (timeleft <= 0) {
						clearInterval(downloadTimer);
						$('#resend_countdown').html('');
						localStorage.setItem('timerRunning', 'false');
						$('#btn_resend_code').attr('disabled', false);

					} else {
						$('#btn_resend_code').attr('disabled', true);
					}
				}, 1000);
			}
		}


		function submitSellDesignForm() {

			var data = $("#frm_sell_design").serialize();
			$.ajax({
				type: 'POST',
				url: "{{ url('user/my-designs/addstoreitem') }}",
				data: data,
				dataType: 'json',
				beforeSend: function(xhr) {
					var token = $('meta[name="csrf_token"]').attr('content');

					if (token) {
						return xhr.setRequestHeader('X-CSRF-TOKEN', token);
					}
					xhr.setRequestHeader('X-Requested-With', 'XMLHttpRequest');
				},
				success: function(response) {
					// console.log(response);
					if (response.success) {
						alert("Item is successfully added to your store.");
						location.reload();
					} else {
						$("#sell-design-response-msg").html(response.message);
					}
				}
			});
			return false;
		}

		function readURL(input, id) {

			if (input.files && input.files[0]) {
				var reader = new FileReader();

				reader.onload = function(e) {
					$('#' + id).attr('src', e.target.result);
					// for lightbox 
					$('.' + id + '_href').attr('href', e.target.result);
					$('.' + id + '_img').attr('src', e.target.result);
				}
				reader.readAsDataURL(input.files[0]);
			}

		}
	</script>

</body>

</html>