<?php

require_once "config.php";

$officeKey = $_GET['office'] ?? 'zadar-ap';

if(!isset($offices[$officeKey])){
    $officeKey='zadar-ap';
}

$office=$offices[$officeKey];

?>
<!DOCTYPE html>
<html lang="en">

<head>

<meta charset="UTF-8">

<meta
name="viewport"
content="width=device-width, initial-scale=1.0">

<title>

AVIA Rent a Car

</title>

<link
rel="stylesheet"
href="assets/css/style.css">

</head>

<body>

<div class="language">

<a href="#"
onclick="changeLanguage('en');return false;">

EN

</a>

|

<a href="#"
onclick="changeLanguage('hr');return false;">

HR

</a>

</div>

<div class="container">

<div class="logo">

<img
src="assets/images/logo.png"
alt="AVIA">

</div>

<h1 id="title">

Customer Information Form

</h1>

<p id="subtitle">

Please complete the form before signing the rental agreement.

</p>

<div class="office">

<?php

echo $office['name'];

?>

</div>

<form

id="customerForm"

action="send.php"

method="POST"

>

<input

type="hidden"

name="office"

value="<?php echo $officeKey; ?>">

<div class="group">

<label id="lReservation">

Reservation / Voucher Number

</label>

<input

type="text"

name="reservation"

id="reservation"

required>

</div>

<div class="group">

<label id="lFullName">

Full Name

</label>

<input
type="text"
name="fullname"
id="fullname"
required>

</div>

<div class="group">

<label id="lAddress">

Address

</label>

<input

type="text"

name="address"

id="address"

required>

</div>

<div class="row">

<div class="group">

<label id="lCity">

City

</label>

<input

type="text"

name="city"

id="city"

required>

</div>

<div class="group">

<label id="lZip">

ZIP Code

</label>

<input

type="text"

name="zip"

id="zip"

required>

</div>

</div>

<div class="group">

<label id="lCountry">

Country

</label>

<input

type="text"

name="country"

id="country"

required>

</div>

<div class="group">

<label id="lPhone">

Mobile Phone

</label>

<input
type="tel"
name="phone"
id="phone"
placeholder="00385 91 123 4567"
autocomplete="tel"
required>

</div>

<div class="group">

<label>

Email

</label>

<input

type="email"

name="email"

id="email"

required>

</div>
<div class="gdpr">

<label class="checkbox">

<input
type="checkbox"
name="gdpr"
id="gdpr"
required>

<span id="gdprText">

I confirm that I have read the Privacy Policy and I agree that AVIA Rent a Car
may process my personal data for the purpose of preparing and concluding the
vehicle rental agreement.

</span>

</label>

</div>

<div id="errorBox" class="errorBox"></div>

<button
type="submit"
class="sendButton"
id="sendButton">

SEND

</button>

</form>

<div
id="successMessage"
class="successMessage"
style="display:none;">

<h2 id="successTitle">

Thank you!

</h2>

<p id="successText">

Your information has been successfully submitted.

</p>

</div>

</div>

<script
src="assets/js/app.js">

</script>

<script>

document
.getElementById("customerForm")
.addEventListener("submit",function(e){

let reservation=document.getElementById("reservation").value.trim();

let firstname=document.getElementById("firstname").value.trim();

let lastname=document.getElementById("lastname").value.trim();

let birth=document.getElementById("birth").value.trim();

let address=document.getElementById("address").value.trim();

let city=document.getElementById("city").value.trim();

let zip=document.getElementById("zip").value.trim();

let country=document.getElementById("country").value.trim();

let phone=document.getElementById("phone").value.trim();

let email=document.getElementById("email").value.trim();

let gdpr=document.getElementById("gdpr").checked;

let error="";

if(reservation=="")
error="Please enter Reservation / Voucher Number.";

else if(firstname=="")
error="Please enter First Name.";

else if(lastname=="")
error="Please enter Last Name.";

else if(birth=="")
error="Please enter Date of Birth.";

else if(address=="")
error="Please enter Address.";

else if(city=="")
error="Please enter City.";

else if(zip=="")
error="Please enter ZIP Code.";

else if(country=="")
error="Please enter Country.";

else if(phone=="")
error="Please enter Mobile Phone.";

else if(email=="")
error="Please enter Email.";

else{

let reg=/^[^\s@]+@[^\s@]+\.[^\s@]+$/;

if(!reg.test(email))
error="Please enter a valid Email.";

}

if(!gdpr)
error="Please accept GDPR consent.";

if(error!=""){

e.preventDefault();

document.getElementById("errorBox").style.display="block";

document.getElementById("errorBox").innerHTML=error;

window.scrollTo({

top:0,

behavior:"smooth"

});

}

});

</script>

</body>

</html>