@extends('layouts.app')
@section('title')
Book - {{$ebook->title}}
@parent
@stop
@section('content')
<!----Banner Section Starts----> 
@include('layouts.ebook_volume_header_section')  
<!----Banner Section Starts----> 

<!----Main Section Starts (where all content bodies exist)----> 
<main>
  
  <section>
    <div class="container">
      <div class="row">
        <div class="col-md-12 listing">
		<a id="printtopscroll"></a>

          <h2 class="h4">Pre-Order </h2>
		  <hr>
          	 <div class="card bigbox-hvr-slow">
				  <div class="card-body">
				  
	
				  
<div class="col-md-12 fieldset-border">
   <div class="col-md-12 ">
   
   
   @if (isset($preview))
	
	{{ Form::open(array('url' => 'submit_pre_order/'.$ebook_volume_details[0]->ebook_volume_id)) }}
   
<table>

<tbody>
	<tr><td width="300" class="oddrowcolor border-none"><b>First Name:</b></td><td class="oddrowcolor border-none">{{$preview['first_name']}}</td></tr>
	<tr><td width="300" class="oddrowcolor border-none"><b>Last Name:</b></td><td class="oddrowcolor border-none">{{$preview['last_name']}}</td></tr>
	<tr><td width="300" class="oddrowcolor border-none"><b>Email:</b></td><td class="oddrowcolor border-none">{{$preview['email']}}</td></tr>
	<tr><td width="300" class="oddrowcolor border-none"><b>Title:</b></td><td class="oddrowcolor border-none">{{$preview['title']}}</td></tr>

	@if(!empty($preview['user_category']))
	<tr><td width="300" class="oddrowcolor border-none"><b>User Category:</b></td><td class="oddrowcolor border-none">{{$preview['user_category']}}</td></tr>
	@endif
	<tr><td width="300" class="oddrowcolor border-none"><b>Order Type:</b></td><td class="oddrowcolor border-none">{{$preview['order_type']}}</td></tr>
	
	
	<tr><td width="300" class="oddrowcolor border-none"><b>Country:</b></td><td class="oddrowcolor border-none">{{$preview['country']}}</td></tr>
	<tr><td width="300" class="oddrowcolor border-none"><b>City:</b></td><td class="oddrowcolor border-none">{{$preview['city']}}</td></tr>
	<tr><td width="300" class="oddrowcolor border-none"><b>State/Province:</b></td><td class="oddrowcolor border-none">{{$preview['state']}}</td></tr>
	
	@if(!empty($preview['phone']))
	<tr><td width="300" class="oddrowcolor border-none"><b>Phone:</b></td><td class="oddrowcolor border-none">{{$preview['phone']}}</td></tr>
	@endif

	@if(!empty($preview['fax']))
	<tr><td width="300" class="oddrowcolor border-none"><b>Fax: </b></td><td class="oddrowcolor border-none">{{$preview['fax']}}</td></tr>
	@endif
	
	<tr><td width="300" class="oddrowcolor border-none"><b>Zip/Postal Code:</b></td><td class="oddrowcolor border-none">{{$preview['zip']}}</td></tr>

	@if(!empty($preview['org_name']))
	<tr><td width="300" class="oddrowcolor border-none"><b>Organization Name:</b></td><td class="oddrowcolor border-none">{{$preview['org_name']}}</td></tr>
	@endif
	
	<tr><td width="300" class="oddrowcolor border-none"><b>Location/Address:</b></td><td class="oddrowcolor border-none">{{$preview['address']}}</td></tr>
	
	@if($preview['order_type'] != "Electronic Version")
		<tr><td width="300" class="oddrowcolor border-none"><b>No. of Print Copies:</b></td><td class="oddrowcolor border-none">@if($preview['no_of_copies'] == 0) More than 5 @else {{$preview['no_of_copies']}} @endif</td></tr>
	@endif	

	@if(!empty($preview['comments']))
	<tr><td width="300" class="oddrowcolor border-none"><b>Comments: </b></td><td class="oddrowcolor border-none">{{$preview['comments']}}</td></tr>
	@endif
	
	
</tbody>

</table>			

<br>


<input type="hidden" name="first_name" value="{{$preview['first_name']}}" />
<input type="hidden" name="last_name" value="{{$preview['last_name']}}" />
<input type="hidden" name="email" value="{{$preview['email']}}" />

<input type="hidden" name="title" value="{{$preview['title']}}" />
<input type="hidden" name="user_category" value="{{$preview['user_category']}}" />
<input type="hidden" name="order_type" value="{{$preview['order_type']}}" />

<input type="hidden" name="country" value="{{$preview['country']}}" />
<input type="hidden" name="city" value="{{$preview['city']}}" />
<input type="hidden" name="state" value="{{$preview['state']}}" />

<input type="hidden" name="phone" value="{{$preview['phone']}}" />
<input type="hidden" name="fax" value="{{$preview['fax']}}" />
<input type="hidden" name="zip" value="{{$preview['zip']}}" />

<input type="hidden" name="org_name" value="{{$preview['org_name']}}" />
<input type="hidden" name="address" value="{{$preview['address']}}" />
<input type="hidden" name="comments" value="{{$preview['comments']}}" />
<input type="hidden" name="no_of_copies" value="{{$preview['no_of_copies']}}" />


{{ Form::submit('Submit', array('class' => 'btn btn-primary')) }}
		{{ Form::close() }}		
   @else
	   
   
   {{ Form::open(array('url' => 'preview_pre_order/'.$ebook_volume_details[0]->ebook_volume_id , 'method' => 'post')) }}
		{{ csrf_field() }}

                 @if ($errors->any())
                    <div class="form-group col-md-12">
                        <div class="alert alert-danger">
                            <strong>Whoops!</strong> There were some problems with your input.<br>
                            <ul>
                                @foreach ($errors->all() as $error)
                                    <li>{{ $error }}</li>
                                @endforeach
                            </ul>
                        </div>
                    </div>
                    @endif                    


	<div class="form-row">
		<div class="form-group col-md-4">
			<label class="control-label">First Name: *</label>
			<input type="text" maxlength="50" name="first_name" size="60" value="{{ old('first_name') }}" class="form-control" required = 'required'>
		</div>
		<div class="form-group col-md-4" >
			<label class="control-label">Last Name: *</label>
			<input type="text" maxlength="50" name="last_name" size="60" value="{{ old('last_name') }}" class="form-control" required = 'required'>
		</div>
		<div class="form-group col-md-4" >
			<label class="control-label">Email: *</label>
			<input type="email" maxlength="50" name="email" size="60" value="{{ old('email') }}" class="form-control" required = 'required'>
		</div>
	</div>
   
   
	<div class="form-row">
		<div class="form-group col-md-4">
			<label class="control-label">Title: *</label>
			<select name="title" class="form-select form-control" required = 'required'>
				<option title="Select Title" value="">Select Category</option>
				<option value="Mr." {{ (Request::old("title") == "Mr." ? "selected":"") }}>Mr.</option>
				<option value="Mrs." {{ (Request::old("title") == "Mrs." ? "selected":"") }}>Mrs.</option>
				<option value="Ms." {{ (Request::old("title") == "Ms." ? "selected":"") }}>Ms.</option>
				<option value="Prof."  {{ (Request::old("title") == "Prof." ? "selected":"") }}>Prof.</option>
				<option value="Dr."  {{ (Request::old("title") == "Dr." ? "selected":"") }}>Dr.</option>
			</select>	
		</div>
		
		<div class="form-group col-md-4">
		
			<label class="control-label">User Category:</label>
			<select name="user_category" class="form-select form-control">
				<option title="Select Category" value="">Select Category</option>
				<option title="Professor" value="Professor" {{ (Request::old("user_category") == "Professor" ? "selected":"") }}>Professor</option>
				<option title="Student" value="Student" {{ (Request::old("user_category") == "Student" ? "selected":"") }}>Student</option>
				<option title="Researcher" value="Researcher" {{ (Request::old("user_category") == "Researcher" ? "selected":"") }}>Researcher</option>
				<option title="Medical Professional/Practitiionar" value="Medical Professional/Practitiionar" {{ (Request::old("user_category") == "Medical Professional/Practitiionar" ? "selected":"") }}>Medical Professional/Practitiionar</option>
			</select>
			
			
		</div>
		
		<div class="form-group col-md-4">
		
			<label class="control-label">Order Type: *</label>
			<select name="order_type" id="order_type" class="form-select required form-control" required = 'required' onchange="reprintNum()">
				<option title="Select Order Type" value="">Select Order Type</option>
				<option title="Print Version" value="Print Version" {{ (Request::old("order_type") == "Print Version" ? "selected":"") }}>Print Version</option>
				<option title="Electronic Version" value="Electronic Version" {{ (Request::old("order_type") == "Electronic Version" ? "selected":"") }}>Electronic Version</option>
			</select>
		</div>
	 
	</div>
		
	<div class="form-row">
		<div class="form-group col-md-4">
			<label class="control-label">Country: *</label>
			<select class="form-control" id="country" name="country"  required = 'required'>
				<option value="">Country</option>
				@foreach ($country as $countries)
				<option value="{{$countries->printable_name}}" {{ old("country") == $countries->printable_name ? "selected" : "" }}> {{$countries->printable_name}}</option>
				@endforeach
			</select>
		</div>
		<div class="form-group col-md-4" >         
			<label for="edit-city">City: *</label>
			<input type="text" maxlength="50" name="city" id="edit-city" size="60" value="{{ old('city') }}" class="form-control" required = 'required'>
		</div>
		
		<div class="form-group col-md-4" >         
			<label for="edit-city">State/Province:</label>
			<input type="text" maxlength="50" name="state" id="edit-state" size="60" value="{{ old('state') }}" class="form-control">
		</div>
		
	</div>

	<div class="form-row">
		<div class="form-group col-md-4">
			<label for="edit-phone">Phone:</label>
			<input type="text" maxlength="50" name="phone" id="edit-phone" size="60" value="{{ old('phone') }}" class="form-control">
		</div>
		<div class="form-group col-md-4">
			<label for="edit-phone">Fax:</label>
			<input type="text" maxlength="50" name="fax" id="edit-fax" size="60" value="{{ old('fax') }}" class="form-control">
		</div>
	<div class="form-group col-md-4" >
			<label for="edit-zip">Zip/Postal Code: </label>
			<input type="text" maxlength="50" name="zip" id="edit-zip" size="60" value="{{ old('zip') }}" class="form-control">
		</div>
	</div>

	<div class="form-row">
		<div class="form-group col-md-4" id="org_name-wrapper">         
			<label for="org_name">Name of Institution/Organization:</label>
			<input type="text" maxlength="200" name="org_name" id="org_name" size="60" value="{{ old('org_name') }}" class="form-control">
		</div>
			<div class="form-group col-md-4" id="org_location-wrapper">
			<label for="org_location">Location/Address:  *</label>
			<input type="text" maxlength="200" name="address" id="org_location" size="60" value="{{ old('address') }}" class="form-control" required="required">
		</div>
		<div class="form-group col-md-4" id="reprintNum"  @if (old('order_type') != "Print Version") style="display:none;" @endif>
			<label for="edit-math_question">No. of Print Copies: *</label>
			 <select name="no_of_copies" class="form-control" id="edit-printcopies"  required = 'required'>
			 <option title="1" value="1" {{ (Request::old("no_of_copies") == 1 ? "selected":"") }}>1</option>
			 <option title="2" value="2" {{ (Request::old("no_of_copies") == 2 ? "selected":"") }}>2</option>
			 <option title="3" value="3" {{ (Request::old("no_of_copies") == 3 ? "selected":"") }}>3</option>
			 <option title="4" value="4" {{ (Request::old("no_of_copies") == 4 ? "selected":"") }}>4</option>
			 <option title="5" value="5" {{ (Request::old("no_of_copies") == 5 ? "selected":"") }}>5</option>
			 <option title="More than 5" value="0" {{ (Request::old("no_of_copies") == 0 ? "selected":"") }}>More than 5</option>
			 </select>
		</div>
		
	</div>

		<!-- 
		{{ Form::open(array('url' => 'validate_promo_code/'.$ebook_volume_details[0]->ebook_volume_id)) }}
		-->
    <div class="form-row">
		<div class="form-group col-md-12" id="edit-comments-wrapper">
			<label for="edit-comments">Comment: </label>
			<div class="resizable-textarea">
			<span>
			<textarea cols="60" rows="3" name="comments" id="edit-comments" onkeypress="javascript:return LimitVerifyOrderForm();" class="form-control">{{ old('comments') }}</textarea>
			<div  style="margin-right: 351px;"></div>
			</span>
			</div>
		</div>
	</div>

	<div class="form-group text-center">                
                
          <div class="form-group row mt-3 w-100"> 
                
                  <div class="col-auto mx-auto w-100 d-flex ">
                      <div class="col-md-6 text-right">
                          <div class="captcha">                                       
                              <span>{!! captcha_img() !!}</span>             
                          </div>
                      </div>
                      <div class="col-md-6">                                        
                          <button type="button" class="btn btn-danger" class="refresh-captcha" id="refresh-captcha">
                              &#x21bb;
                          </button> 
                      </div>
                  </div>
                  <div class="form-group my-2 mx-auto">
                      <input id="captcha" type="text" class="form-control" placeholder="Enter Captcha" name="captcha">
                      @if ($errors->has('captcha'))

                        <span class="invalid-feedback" style="display: block;">

                            <strong>{{ $errors->first('captcha') }}</strong>

                      </span>
                    @endif
                  </div>
          </div>
                
          </div>
	<div class="form-group text-center border-top pt-3">
	    <input class="btn btn-dark col-md-2" type="submit" name="Preview" value="Preview" />
	  </div>    

   <!-- 
		{{ Form::close() }}		
		-->
		
		{{ Form::close() }}
   
   @endif
   
</div>

	  </div>
	  
	</div>
				
        </div>
    
      </div>
    </div>
  </section>
  
<script>
 	
$(document).ready(function()
{
	$("html, body").animate({scrollTop: $("#printtopscroll").offset().top}, 200);
});	

$( "#promo_code" ).keyup(function(e) 
{
	setTimeout( function(){response = validate_promo_code();}, 2000);
});

function validate_promo_code()
{
	var promo_code = $( "#promo_code" ).val();
	var response = 0;
	
	$.ajax({
        type: "POST",
		data: 
		{
			"_token": "{{ csrf_token() }}",
			"promo_code": promo_code,
			ajax: true
		},
        success: function (data)
		{
			console.log(data[0]);
			
			$( "#promo_code_message" ).html(data[1]);
			
			if (data[0])
			{
				$( "#validate_promocode" ).removeClass('alert alert-danger');
				$( "#validate_promocode" ).removeClass('alert alert-warning');
				$( "#validate_promocode" ).addClass('alert alert-success');
				
			}
			else
			{
				$( "#validate_promocode" ).removeClass('alert alert-success');
				$( "#validate_promocode" ).removeClass('alert alert-warning');
				$( "#validate_promocode" ).addClass('alert alert-danger');
			}
			
        },
		error: function () 
		{
			$( "#validate_promocode" ).removeClass('alert alert-success');
			$( "#validate_promocode" ).removeClass('alert alert-warning');
			$( "#validate_promocode" ).addClass('alert alert-danger');
			
		},
		beforeSend: function () 
		{
			$( "#validate_promocode" ).removeClass('alert alert-success');
			$( "#validate_promocode" ).removeClass('alert alert-danger');
			$( "#validate_promocode" ).addClass('alert alert-warning');
		}
    });    
}


	function reprintNum()
	{
		var reprint_copies = $('#order_type').val();
		
		
		if(reprint_copies == 'Print Version')
		{
			$('#reprintNum').show();
			$('#reprint_copies').attr('required', 'required');
			$('#reprint_copies').val('');
		}
		else
		{
			$('#reprintNum').hide();
			$('#reprint_copies').removeAttr('required');
			$('#reprint_copies').val(reprint_copies);
		}
	}

	
</script>

  
</main>
@endsection
<script src="https://www.recaptcha.net/recaptcha/api.js" async defer></script>
