<?php
session_start();

if( isset($_SESSION["lic"]) ) {
   $license = checkLicense();
   if( $license == false ) return;
}

function checkLicense() {
   if( $myfile = fopen("lic.txt", "r") ) {

      $url = "";
      if( isset( $_SERVER['HTTP_HOST'] ) ) {
         $url = $_SERVER['HTTP_HOST'];
      }
      for( $i = 0; $i < 3; ++$i ) {

         if( feof( $myfile ) ) break;
         $lic = fgets($myfile);
         $lic = str_replace("\r","",$lic);
         $lic = str_replace("\n","",$lic);
         $url_encoded = sha1("license:" . $url);
         if( $url_encoded == $lic ) {
            fclose($myfile);
            return true;
         }
      }
      echo "Invalid license file.</br>";  
      fclose($myfile);
   }
   else echo "Cannot find license file.</br>";
   return false;
}

$_SESSION["module"] = "Contact Us";
$width="72%";

include 'deckertHeader.php'; 
?>
   <link type="text/css" rel="stylesheet" href="styles/main.css"  media="screen,projection"/> 
   <link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
  <link rel="home" href="https://www.deckerstore.com" /> 
<style>
input[type=text]:disabled {
   color: black;
}
.input-field {
   margin-bottom: 2px !important;
}

@import url('https://fonts.googleapis.com/css2?family=Montserrat&display=swap');
@import url('https://fonts.googleapis.com/css2?family=Montserrat:wght@400;500&display=swap');

body, #content, #nav, .page-content, .dashboard {
  background-color: white !important;

}

#content, #nav, .page-content, .dashboard {
  background-color: white !important;
}

.card, .card-content {
   padding-top: 5px !important;
   padding-bottom: 5px !important;
   font-family: 'Montserrat', sans-serif;
   font-weight: bold;
}
.card-title {
   border-bottom: 1px solid;
   border-bottom-color: rgb(222, 226, 230);
}
.field-text {
 color: rgb(85,85,85);
 font-size: 1rem !important;
}
.field-label {
   color:black !important; 
}
textarea.materialize-textarea{height: 8rem !important;}
</style>
<?php
   echo "<div class='container' style='width:70%;' >";
      echo "<div style='height: 85px;'></div>";
               echo "<div style='height:10px;'></div>";
               echo "<div style='width:75%; margin:auto;'>";
               echo "<div style='width:30%;'>";

                  echo "<div class='row'>";
                     echo "<div class='input-field col s12 m12 l12 center-align' style='color:#141414; font-weight:bold; font-size: 1.2rem; border: none;'>CONTACT US</div>";
                  echo "</div>";
                  echo "<div class='row'>";
                     echo "<div class='input-field col s12 m12 l12 center-align'>Tell us what you need. We'll contact you as soon as we can. Thanks.";
                     echo "</div>";
                  echo "</div>";

                  echo "<div class='row'>";
                     echo "<div class='input-field col s12 m12 l12'>";
                        echo "<input id='first' name='first' type='text' class='field-text' value='' placeholder='First Name' autocomplete='off' >";
                     echo "</div>";
                  echo "</div>";

                  echo "<div class='row'>";
                    echo "<div class='input-field col s12 m12 l12'>";
                        echo "<input id='last' name='last' type='text' style='color:black;' value='' placeholder='Last Name' autocomplete='off' >";
                     echo "</div>";
                  echo "</div>";

                  echo "<div class='row'>";
                     echo "<div class='input-field col s12 m12 l12'>";
                        echo "<input id='email' name='email' type='email' style='color:black;' value='' placeholder='Email' autocomplete='off' >";
                     echo "</div>";
                  echo "</div>";

                  echo "<div class='row'>";
                     echo "<div class='input-field col s12 m12 l12'>";
                        echo "<textarea id='nota' class='materialize-textarea' style='color:black;' value='' rows='8' placeholder='Messsage' ></textarea>";
                     echo "</div>";
                  echo "</div>";

                  echo "<div style='height:10px;'></div>";
                  echo "<div class='input-field col s1'>";
                   echo "<a id='send' onclick='SendMail(this);' class='waves-effect waves-light btn blue darken-4 left' style='margin-top:0 !important; margin-left:10px; height:40px; border-radius:20px; width:80px; line-height:40px; float:right !important;'>Send</a>";
                  echo "</div>";

               echo "</div>";
               echo "</div>";
   echo "</div>"; 
?>
<style>
.dropdown-client {
   background-color: white;
   opacity: 1;
   overflow-y: auto;
   border-bottom: 1px solid #d0d0d0;
   box-shadow: 0 2px 5px 0 rgba(0, 0, 0, 0.16), 0 2px 10px 0 rgba(0, 0, 0, 0.12);
}
ul.dropdown-client li {
   line-height:3em;
   height:3em;
   vertical-align: middle;
   color: #009688;
   min-height: 3em;
   text-align: left;
   padding: 0px 16px;
}
ul.dropdown-client li:hover {
 background-color:#90a4ae;
}
</style>
  <script type="text/javascript" src="js/jquery.min.js"></script>
  <script type="text/javascript" src="materialize/1.0.0/js/materialize.js"></script> 
<script>

   $(document).ready(function() {

      $("#t4").addClass('active');
      $('.tabs').tabs();
      $('.sidenav').sidenav();
      $('.dropdown-trigger').dropdown({
         "hover": true,
         "constrainWidth": false,
         "coverTrigger": false
      });
      $('.modal-trigger').modal({
          dismissible: false,
          preventScrolling: true,
          opacity: .7, // Opacity of modal background
          in_duration: 300, // Transition in duration
          out_duration: 200, // Transition out duration
          starting_top: '40%'
       });         
      $('select').formSelect();
       $('.modal-trigger').modal({
          dismissible: false,
          opacity: .7, // Opacity of modal background
          in_duration: 300, // Transition in duration
          out_duration: 200, // Transition out duration
          starting_top: '40%'
       });     
   });   


   // Post to the provided URL with the specified parameters.
   function post(path, parameters) {
      var form = $('<form></form>');

       form.attr("method", "post");
       form.attr("action", path);

       $.each(parameters, function(key, value) {
           var field = $('<input></input>');
           field.attr("type", "hidden");
           field.attr("name", key);
           field.attr("value", value);
           form.append(field);
       });
       $(document.body).append(form);
      form.submit();
   };
   function SendMail(e) {

      var first = $("#first").val(); 
      var last = $("#last").val(); 
      var email = $("#email").val(); 
      var nota = $("#nota").val(); 

      if( first.length <= 0 && last.length <= 0 ) { 
         M.toast({html: 'Please enter your name',displayLength:4000, classes: 'rounded  red'}) 
//         $( "#first" ).addClass( "invalid" );
         return;
      }

      if( email.length <= 0 || ValidateEmail(email) == false ) { 
         M.toast({html: 'Please verify your email',displayLength:4000, classes: 'rounded  red'}) 
//         $( "#email" ).addClass( "invalid" );
         return;
      }

      if( nota.length <= 0 ) { 
         M.toast({html: 'Please add you message',displayLength:4000, classes: 'rounded  red'}) 
//         $( "#nota" ).addClass( "invalid" );
         return;
      }


      $.ajax({ type: "POST", url: "mailerSendMail.php",
               data: { first: first, last: last, email: email, message: nota },
               success: function(data){
                  if( parseInt(data) == 1 ) {
                     M.toast({html: 'Message sent',displayLength:2000, classes: 'rounded green'}) 
                     $("#first").val(""); 
                     $("#last").val(""); 
                     $("#email").val(""); 
                     $("#nota").val(""); 

                  }
                  else {
                     M.toast({html: 'Error sending message',displayLength:4000, classes: 'rounded  purple darken-1'}) 
                  }
               },
               complete: function(){
               },
               error: function(err) { 
                     M.toast({html: 'Error sending message',displayLength:4000, classes: 'rounded  purple darken-1'}) 
              }
      });
   }

   function ValidateEmail(mail) {

     if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(mail))
     {
       return (true)
     }
    return (false)
   }
</script>
<!-- Google tag (gtag.js) -->
<script async src="https://www.googletagmanager.com/gtag/js?id=G-TRM5WNEN0B"></script>
<script>
  window.dataLayer = window.dataLayer || [];
  function gtag(){dataLayer.push(arguments);}
  gtag('js', new Date());

  gtag('config', 'G-TRM5WNEN0B');
</script></body>
</html>
