<?php 
require_once('xconn.php');
session_start();
 
  if(!isset($_SESSION['d_usuario'])){
    header('Location: index.php');
    exit;
  }else{
    $iUsuario = $_SESSION['c_usuario'];
  }

  $idSolicitud = $_GET['sol'];

  if ($conn ->connect_error) {
  die("Connection failed: " . $conn ->connect_error);
  }

  if ($idSolicitud == '0') {
    
    $xFetch = mysqli_query($conn,"SELECT * FROM t_solicitud ORDER BY c_solicitud DESC LIMIT 1");
    
    while ($valores = mysqli_fetch_array($xFetch)) {
      $idSolicitud = $valores['c_solicitud'];
    }

    if($idSolicitud == '0'){
      $idSolicitud = '1';
    }else{
      $idSolicitud = intval($idSolicitud) + 1;
    }
  }

  $idSolicitudBanco = 0;
  $xFetch2 = mysqli_query($conn,"SELECT * FROM t_solicitudbanco ORDER BY c_solicitudbanco DESC LIMIT 1");

  while($xRes = mysqli_fetch_array($xFetch2)){
    $idSolicitudBanco = intval($xRes['c_solicitudbanco']) + 1;
  }

  if($idSolicitudBanco == 0){
    $idSolicitudBanco = 1;
  }

  if(isset($_POST['btn_banco'])){

    $idSolicitud = $_POST['txt_idsol'];
    
    $banco = htmlspecialchars($_POST['Cbo_banco'],ENT_QUOTES);
    $banproducto = htmlspecialchars($_POST['txt_banproducto'],ENT_QUOTES);
    $banpagos = htmlspecialchars($_POST['txt_banpagos'],ENT_QUOTES);
    $banvivienda = htmlspecialchars($_POST['txt_banvivienda'],ENT_QUOTES);
    $banmonto = htmlspecialchars($_POST['txt_banmonto'],ENT_QUOTES);
    $banmonto = floatval($banmonto);
    if ($banmonto <= 0){
      echo'<script type="text/javascript">
          alert("Error:  Monto = 0");
          </script>';
      header("Location: solicitud3.php?sol=$idSolicitud");

    } else {
      $banplazo = htmlspecialchars($_POST['txt_banplazo'],ENT_QUOTES);
      $banaforo = htmlspecialchars($_POST['txt_banaforo'],ENT_QUOTES);
      $banusoinmueble = htmlspecialchars($_POST['txt_banusoinmueble'],ENT_QUOTES);
      $bantipoinmueble = htmlspecialchars($_POST['txt_bantipoinmueble'],ENT_QUOTES);
      $bansuperficie = htmlspecialchars($_POST['txt_bansuperficie'],ENT_QUOTES);
      $banconstruccion = htmlspecialchars($_POST['txt_banconstruccion'],ENT_QUOTES);
      $banporcentaje = htmlspecialchars($_POST['txt_banporcentaje'],ENT_QUOTES);
      $banvendedor = htmlspecialchars($_POST['txt_banvendedor'],ENT_QUOTES);
      $banvendtel = htmlspecialchars($_POST['txt_banvendtel'],ENT_QUOTES);
      $banvenddomicilio = htmlspecialchars($_POST['txt_banvenddomicilio'],ENT_QUOTES);
      $banfecha = date('Y-m-d');
       
      $sql = "INSERT INTO `t_solicitudbanco`(`c_cliente`, `c_solicitud`, `d_producto`, `d_pagosfijos`, `m_valorvivienda`, `b_cofinanciamiento`, `m_monto`, `d_plazo`, `d_aforo`, `d_usoinmueble`, `d_tipoinmueble`, `d_superficie`, `d_construccion`, `d_porcentajefinan`, `d_vendedornombre`, `d_vendedortelefono`, `d_vendedordomicilio`, `d_banco`, `c_estatus`, `f_solicitud`, `c_asesor`) VALUES ('','$idSolicitud','$banproducto','$banpagos','$banvivienda','0','$banmonto','$banplazo','$banaforo','$banusoinmueble','$bantipoinmueble','$bansuperficie','$banconstruccion','$banporcentaje','$banvendedor','$banvendtel','$banvenddomicilio', '$banco', '1', '$banfecha', '2')";

      if ($conn->query($sql) === TRUE) {

        foreach ($_FILES["documentos"]["error"] as $clave => $error) {
          if ($error == UPLOAD_ERR_OK) {
              $nombre_tmp = $_FILES["documentos"]["tmp_name"][$clave];
              // basename() puede evitar ataques de denegació del sistema de ficheros;
              // podría ser apropiado más validación/saneamiento del nombre de fichero
              $nombre = basename($_FILES["documentos"]["name"][$clave]);
              move_uploaded_file($nombre_tmp, "files/$nombre");
              
          }
        }

        header("Location: solicitud3.php?sol=$idSolicitud");
      } else {
        echo'<script type="text/javascript">
            alert("Error:  $sql <br> $conn->error");
            </script>';
      }
    }
  }
?>
<html>
<head>
  <title>Diaso | Brokers</title>
  <!-- Required meta tags -->
  <meta charset="utf-8">
  <meta content="width=device-width, initial-scale=1.0" name="viewport" />
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
  <!--     Fonts and icons     -->
  <link rel="stylesheet" type="text/css" href="https://fonts.googleapis.com/css?family=Roboto:300,400,500,700|Roboto+Slab:400,700|Material+Icons" />
  <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/latest/css/font-awesome.min.css">
  <!-- Material Kit CSS -->
  <link href="assets/css/material-dashboard.css?v=2.1.2" rel="stylesheet" />
  <script type="text/javascript">
    function filterFloat(evt,input){
      // Backspace = 8, Enter = 13, ‘0′ = 48, ‘9′ = 57, ‘.’ = 46, ‘-’ = 43
      var key = window.Event ? evt.which : evt.keyCode;    
      var chark = String.fromCharCode(key);
      var tempValue = input.value+chark;
      if(key >= 48 && key <= 57){
          if(filter(tempValue)=== false){
              return false;
          }else{       
              return true;
          }
      }else{
            if(key == 8 || key == 13 || key == 0) {     
                return true;              
            }else if(key == 46){
                  if(filter(tempValue)=== false){
                      return false;
                  }else{       
                      return true;
                  }
            }else{
                return false;
            }
      }
    }
    function filter(__val__){
      var preg = /^([0-9]+\.?[0-9]{0,2})$/; 
      if(preg.test(__val__) === true){
          return true;
      }else{
         return false;
      }
    }
    function validanumero(evt){
      
      // code is the decimal ASCII representation of the pressed key.
      var code = (evt.which) ? evt.which : evt.keyCode;
      
      if(code==8) { // backspace.
        return true;
      } else if(code>=48 && code<=57) { // is a number.
        return true;
      } else{ // other keys.
        return false;
      }
    }
  </script>
</head>

<body>
  <div class="wrapper ">
    <div class="sidebar" data-color="azure" data-background-color="black">
      <!--
      Tip 1: You can change the color of the sidebar using: data-color="purple | azure | green | orange | danger"

      Tip 2: you can also add an image using data-image tag
  -->
      <div class="logo">
        <a href="https://diaso.com.mx/" class="simple-text logo-mini">
          Brokers -
          Diaso
        </a>
        <img src="img/logo.png" width="200" height="100"/>
      </div>
      <div class="sidebar-wrapper">
        <ul class="nav">
          <li class="nav-item">
            <a class="nav-link" href="dashboard.php">
              <i class="material-icons">dashboard</i>
              <p>Dashboard</p>
            </a>
          </li>
          <li class="nav-item">
            <a class="nav-link" href="clientes.php">
              <i class="material-icons">dashboard</i>
              <p>Clientes</p>
            </a>
          </li>
          <li class="nav-item">
            <a class="nav-link" href="solicitudes.php">
              <i class="material-icons">dashboard</i>
              <p>Solicitudes</p>
            </a>
          </li>
          <li class="nav-item">
            <a class="nav-link" href="catalogos.php">
              <i class="material-icons">dashboard</i>
              <p>Catalogos</p>
            </a>
          </li>
          <li class="nav-item">
            <a class="nav-link" href="users.php">
              <i class="material-icons">dashboard</i>
              <p>Usuarios</p>
            </a>
          </li>
          
          <li class="nav-item active-pro ">
              <p>Disponible en: Web & Movil</p>
          </li>
          <!-- your sidebar here -->
        </ul>
      </div>
    </div>
    <div class="main-panel">
      <!-- Navbar -->
      <nav class="navbar navbar-expand-lg navbar-transparent navbar-absolute fixed-top ">
        <div class="container-fluid">
          <div class="navbar-wrapper">
            <a class="navbar-brand" href="javascript:;">Solicitud <?php echo "$idSolicitud"; ?></a>
          </div>
          <button class="navbar-toggler" type="button" data-toggle="collapse" aria-controls="navigation-index" aria-expanded="false" aria-label="Toggle navigation">
            <span class="sr-only">Toggle navigation</span>
            <span class="navbar-toggler-icon icon-bar"></span>
            <span class="navbar-toggler-icon icon-bar"></span>
            <span class="navbar-toggler-icon icon-bar"></span>
          </button>
          <div class="collapse navbar-collapse justify-content-end">
            <ul class="navbar-nav">
              <li class="nav-item">
                <a class="nav-link" href="javascript:;">
                  <i class="material-icons">notifications</i> Notificaciones
                </a>
              </li>
              <li class="nav-item dropdown">
                <a class="nav-link" href="javascript:;" id="navbarDropdownProfile" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
                  <i class="material-icons">person</i>Hola <?php echo', ' . $_SESSION['d_usuario'] . '.'; ?>
                  <p class="d-lg-none d-md-block">
                    Hola, <?php 'Edgar Mejia'; ?>
                  </p>
                </a>
                <div class="dropdown-menu dropdown-menu-right" aria-labelledby="navbarDropdownProfile">
                  <a class="dropdown-item" href="profile.php">Perfil</a>
                  <a class="dropdown-item" href="configuration.php">Configuracion</a>
                  <div class="dropdown-divider"></div>
                  <a class="dropdown-item" href="xlogout.php">Salir</a>
                </div>
              </li>
              <!-- your navbar here -->
            </ul>
          </div>
        </div>
      </nav>
      
      <!-- End Navbar -->
      <div class="content">
        <div class="container-fluid">
          <div class="col-lg-12 col-md-12">
              <div class="card">
                <div class="card-header card-header-tabs card-header-primary">
                  <div class="nav-tabs-navigation">
                    <div class="nav-tabs-wrapper">
                      <span class="nav-tabs-title">Completa los Datos</span>
                      <ul class="nav nav-tabs" data-tabs="tabs">
                        <li class="nav-item">
                          <a class="nav-link active" href="#datospersonales" data-toggle="tab">
                            <i class="material-icons">account_circle</i> Bancos
                            <div class="ripple-container"></div>
                          </a>
                        </li>
                      </ul>
                    </div>
                  </div>
                </div>
                <div class="card-body">
                  <div class="tab-content">
                    <div class="tab-pane active" id="datospersonales">
                      <form method="post" id="finfoadic" action="<?php echo $_SERVER['PHP_SELF']; ?>" enctype="multipart/form-data">
                        <div class="row">
                          <div class="col-md-12">
                            <input name="txt_idsol" type="hidden" value="<?php echo $idSolicitud; ?>">
                            <div class="card-body">
                              <h3>Selecciona un Banco</h3>
                              <div class="row">
                                <div class="col-md-4"></div>
                                <div class="col-md-4">
                                  <div class="form-group">
                                    <select class="form-control" name="Cbo_banco">
                                      <option value="0">Seleccione un Banco</option>
                                      <?php
                                        $result2 = mysqli_query($conn,"SELECT c_banco,d_banco FROM t_catalogobancos");
                                        while ($valores = mysqli_fetch_array($result2)) {
                                          echo '<option value="' .$valores['c_banco']. '">' .$valores['d_banco']. '</option>';
                                        }
                                      ?>
                                    </select>
                                  </div>
                                </div>
                                <div class="col-md-4"></div>
                              </div>
                              <div class="row">
                                  <div class="col-md-3">
                                    <div class="form-group">
                                      <label class="bmd-label-floating">Producto</label>
                                      <input type="text" class="form-control" name="txt_banproducto" >
                                    </div>
                                  </div>
                                  <div class="col-md-3">
                                    <div class="form-group">
                                      <label class="bmd-label-floating">Pagos Fijos o Crecientes</label>
                                      <input type="text" class="form-control" name="txt_banpagos" >
                                    </div>
                                  </div>
                                  <div class="col-md-3">
                                    <div class="form-group">
                                      <label class="bmd-label-floating">Valor de Vivienda</label>
                                      <input type="text" class="form-control" name="txt_banvivienda" onkeypress="return filterFloat(event,this);">
                                    </div>
                                  </div>
                              </div>
                              <div class="row">
                                  <div class="col-md-3">
                                    <div class="form-group">
                                      <label class="bmd-label-floating">Monto del Credito</label>
                                      <input type="text" class="form-control" name="txt_banmonto" onkeypress="return filterFloat(event,this);">
                                    </div>
                                  </div>
                                  <div class="col-md-3">
                                    <div class="form-group">
                                      <label class="bmd-label-floating">Plazo</label>
                                      <input type="text" class="form-control" name="txt_banplazo" >
                                    </div>
                                  </div>
                                  <div class="col-md-3">
                                    <div class="form-group">
                                      <label class="bmd-label-floating">Aforo</label>
                                      <input type="text" class="form-control" name="txt_banaforo" onkeypress="return filterFloat(event,this);">
                                    </div>
                                  </div>
                              </div>
                              <h3>Del inmueble a financiar</h3>
                              <div class="row">
                                  <div class="col-md-4">
                                    <div class="form-group">
                                      <label class="bmd-label-floating">Uso del Inmueble</label>
                                      <input type="text" class="form-control" name="txt_banusoinmueble" >
                                    </div>
                                  </div>
                                  <div class="col-md-4">
                                    <div class="form-group">
                                      <label class="bmd-label-floating">Tipo de Inmueble</label>
                                      <input type="text" class="form-control" name="txt_bantipoinmueble" >
                                    </div>
                                  </div>
                                  <div class="col-md-2">
                                    <div class="form-group">
                                      <label class="bmd-label-floating">M2 de Superficie</label>
                                      <input type="text" class="form-control" name="txt_bansuperficie" onkeypress="return filterFloat(event,this);">
                                    </div>
                                  </div>
                                  <div class="col-md-2">
                                    <div class="form-group">
                                      <label class="bmd-label-floating">M2 de Construccion</label>
                                      <input type="text" class="form-control" name="txt_banconstruccion" onkeypress="return filterFloat(event,this);">
                                    </div>
                                  </div>
                              </div>
                              <div class="row">
                                  <div class="col-md-4">
                                    <div class="form-group">
                                      <label class="bmd-label-floating">% del Financiamiento</label>
                                      <input type="text" class="form-control" name="txt_banporcentaje" >
                                    </div>
                                  </div>
                                  <div class="col-md-4">
                                    <div class="form-group">
                                      <label class="bmd-label-floating">Nombre del Vendedor</label>
                                      <input type="text" class="form-control" name="txt_banvendedor" >
                                    </div>
                                  </div>
                                  <div class="col-md-2">
                                    <div class="form-group">
                                      <label class="bmd-label-floating">No. Telefonico del Vendedor</label>
                                      <input type="text" class="form-control" name="txt_banvendtel" maxlength="10">
                                    </div>
                                  </div>
                                  <div class="col-md-2">
                                    <div class="form-group">
                                      <label class="bmd-label-floating">Domicilio Vendedor</label>
                                      <input type="text" class="form-control" name="txt_banvenddomicilio" >
                                    </div>
                                  </div>
                              </div>
                              <h3>Documentos a Adjuntar</h3>
                              <div class="row">
                                  <div class="col-md-3">
                                    <div class="form-group">
                                      <label class="bmd-label-floating">Documento 1</label>
                                      <div class="form-group form-file-upload form-file-multiple">
                                        <input type="file" class="inputFileHidden" name="documentos[]">
                                        <div class="input-group">
                                            <input type="text" class="form-control inputFileVisible" placeholder="Subir">
                                            <span class="input-group-btn">
                                                <button type="button" class="btn btn-fab btn-round btn-primary">
                                                    <i class="material-icons">attach_file</i>
                                                </button>
                                            </span>
                                        </div>
                                      </div>
                                    </div>
                                  </div>
                                  <div class="col-md-3">
                                    <div class="form-group">
                                      <label class="bmd-label-floating">Documento 2</label>
                                      <div class="form-group form-file-upload form-file-multiple bmd-form-group">
                                        <input type="file" multiple="" class="inputFileHidden" name="documentos[]">
                                        <div class="input-group">
                                            <input type="text" class="form-control inputFileVisible" placeholder="Subir">
                                            <span class="input-group-btn">
                                                <button type="button" class="btn btn-fab btn-round btn-primary">
                                                    <i class="material-icons">attach_file</i>
                                                </button>
                                            </span>
                                        </div>
                                      </div>
                                    </div>
                                  </div>
                                  <div class="col-md-3">
                                    <div class="form-group">
                                      <label class="bmd-label-floating">Documento 3</label>
                                      <div class="form-group form-file-upload form-file-multiple">
                                        <input type="file" multiple="" class="inputFileHidden" name="documentos[]">
                                        <div class="input-group">
                                            <input type="text" class="form-control inputFileVisible" placeholder="Subir">
                                            <span class="input-group-btn">
                                                <button type="button" class="btn btn-fab btn-round btn-primary">
                                                    <i class="material-icons">attach_file</i>
                                                </button>
                                            </span>
                                        </div>
                                      </div>
                                    </div>
                                  </div>
                                  <div class="col-md-3">
                                    <div class="form-group">
                                      <label class="bmd-label-floating">Documento 4</label>
                                      <div class="form-group form-file-upload form-file-multiple">
                                        <input type="file" multiple="" class="inputFileHidden" name="documentos[]">
                                        <div class="input-group">
                                            <input type="text" class="form-control inputFileVisible" placeholder="Subir">
                                            <span class="input-group-btn">
                                                <button type="button" class="btn btn-fab btn-round btn-primary">
                                                    <i class="material-icons">attach_file</i>
                                                </button>
                                            </span>
                                        </div>
                                      </div>
                                    </div>
                                  </div>
                              </div>
                              <div class="row">
                                  <div class="col-md-3">
                                    <div class="form-group">
                                      <label class="bmd-label-floating">Documento 5</label>
                                      <div class="form-group form-file-upload form-file-multiple">
                                        <input type="file" class="inputFileHidden" name="documentos[]">
                                        <div class="input-group">
                                            <input type="text" class="form-control inputFileVisible" placeholder="Subir">
                                            <span class="input-group-btn">
                                                <button type="button" class="btn btn-fab btn-round btn-primary">
                                                    <i class="material-icons">attach_file</i>
                                                </button>
                                            </span>
                                        </div>
                                      </div>
                                    </div>
                                  </div>
                                  <div class="col-md-3">
                                    <div class="form-group">
                                      <label class="bmd-label-floating">Documento 6</label>
                                      <div class="form-group form-file-upload form-file-multiple bmd-form-group">
                                        <input type="file" multiple="" class="inputFileHidden" name="documentos[]">
                                        <div class="input-group">
                                            <input type="text" class="form-control inputFileVisible" placeholder="Subir">
                                            <span class="input-group-btn">
                                                <button type="button" class="btn btn-fab btn-round btn-primary">
                                                    <i class="material-icons">attach_file</i>
                                                </button>
                                            </span>
                                        </div>
                                      </div>
                                    </div>
                                  </div>
                                  <div class="col-md-3">
                                    <div class="form-group">
                                      <label class="bmd-label-floating">Documento 7</label>
                                      <div class="form-group form-file-upload form-file-multiple">
                                        <input type="file" multiple="" class="inputFileHidden" name="documentos[]">
                                        <div class="input-group">
                                            <input type="text" class="form-control inputFileVisible" placeholder="Subir">
                                            <span class="input-group-btn">
                                                <button type="button" class="btn btn-fab btn-round btn-primary">
                                                    <i class="material-icons">attach_file</i>
                                                </button>
                                            </span>
                                        </div>
                                      </div>
                                    </div>
                                  </div>
                                  <div class="col-md-3">
                                    <div class="form-group">
                                      <label class="bmd-label-floating">Documento 8</label>
                                      <div class="form-group form-file-upload form-file-multiple">
                                        <input type="file" multiple="" class="inputFileHidden" name="documentos[]">
                                        <div class="input-group">
                                            <input type="text" class="form-control inputFileVisible" placeholder="Subir">
                                            <span class="input-group-btn">
                                                <button type="button" class="btn btn-fab btn-round btn-primary">
                                                    <i class="material-icons">attach_file</i>
                                                </button>
                                            </span>
                                        </div>
                                      </div>
                                    </div>
                                  </div>
                              </div>
                            </div>
                            <input type="submit" name="btn_banco" value="Guardar" class="btn btn-primary pull-right"><br>
                          </div>
                        </div>
                      </form>
                      <div class="card-body">
                        <div class="table-responsive">
                          <table class="table">
                            <thead class=" text-primary">
                              <th>Banco</th><th>Producto</th><th>Pagos</th><th>V. Vivienda</th><th>Cofinanciamiento</th><th>Monto Credito</th><th>Plazo</th><th>Aforo</th><th>Uso Inmueble</th>
                              <th>Tipo Inm.</th><th>M2 Superficie</th><th>M2 Construccion</th><th>% Finan</th><th>Nombre Vend.</th><th>Telefono Vend.</th><th>Domicilio Vend.</th>
                            </thead>
                            <tbody>
                              <?php
                                $xFetch3 = mysqli_query($conn,"SELECT `d_producto`, `d_pagosfijos`, `m_valorvivienda`, `b_cofinanciamiento`, `m_monto`, `d_plazo`, `d_aforo`, `d_usoinmueble`, `d_tipoinmueble`, `d_superficie`, `d_construccion`, `d_porcentajefinan`, `d_vendedornombre`, `d_vendedortelefono`, `d_vendedordomicilio`, t_catalogobancos.d_banco AS t_banco  FROM t_solicitudbanco INNER JOIN t_catalogobancos ON t_solicitudbanco.d_banco = t_catalogobancos.c_banco  WHERE c_solicitud = '$idSolicitud'");
                                while ($xRes = mysqli_fetch_array($xFetch3)) {
                                  echo '<tr>';
                                  echo '<td>' .$xRes['t_banco']. '</td>';
                                  echo '<td>' .$xRes['d_producto']. '</td>';
                                  echo '<td>' .$xRes['d_pagosfijos']. '</td>';
                                  echo '<td> $' . number_format($xRes['m_valorvivienda'],2). '</td>';
                                  echo '<td>' .$xRes['b_cofinanciamiento']. '</td>';
                                  echo '<td> $' . number_format($xRes['m_monto'],2). '</td>';
                                  echo '<td>' .$xRes['d_plazo']. '</td>';
                                  echo '<td> $' . number_format($xRes['d_aforo'],2). '</td>';
                                  echo '<td>' .$xRes['d_usoinmueble']. '</td>';
                                  echo '<td>' .$xRes['d_tipoinmueble']. '</td>';
                                  echo '<td>' . number_format($xRes['d_superficie'],2). '</td>';
                                  echo '<td>' . number_format($xRes['d_construccion'],2). '</td>';
                                  echo '<td> %' . number_format($xRes['d_porcentajefinan'],2). '</td>';
                                  echo '<td>' .$xRes['d_vendedornombre']. '</td>';
                                  echo '<td>' .$xRes['d_vendedortelefono']. '</td>';
                                  echo '<td>' .$xRes['d_vendedordomicilio']. '</td>';
                                  echo '</tr>';
                                } 
                              ?>
                            </tbody>
                          </table>
                        </div>
                    </div>
                    </div>
                    
                  </div>
                </div>
              </div>
            </div>
        </div>
      </div>
      <footer class="footer">
        <div class="container-fluid">
          <nav class="float-left">
            <ul>
              <li>
                <a href="https://diaso.com.mx/">
                  Brokers
                </a>
              </li>
            </ul>
          </nav>
          <div class="copyright float-right">
            &copy;
            <script>
              document.write(new Date().get())
            </script>, Diaso.
            <a href="xlogout.php" class="btn btn-primary btn-round">Salir</a>
          </div> 
          <!-- your footer here -->
        </div>
      </footer>
    </div>
  </div>

  <script src="assets/js/core/jquery.min.js"></script>
  <script src="assets/js/core/popper.min.js"></script>
  <script src="assets/js/core/bootstrap-material-design.min.js"></script>
  <script src="assets/js/plugins/perfect-scrollbar.jquery.min.js"></script>
  <script src="assets/js/plugins/jquery.validate.min.js"></script>
  <script src="assets/js/plugins/jasny-bootstrap.min.js"></script>
  <script>
    $(document).ready(function() {
      if ($('.card-header.card-chart').length != 0) {
        md.initDashboardPageCharts();
      }

      if ($('#websiteViewsChart').length != 0) {
        md.initDocumentationCharts();
      }
      
      if ($('.datetimepicker').length != 0) {
        md.initFormExtendedDatetimepickers();
      }
      if ($('#fullCalendar').length != 0) {
        md.initFullCalendar();
      }

      if ($('.slider').length != 0) {
        md.initSliders();
      }

      //  Activate the tooltips
      $('[data-toggle="tooltip"]').tooltip();

      // Activate Popovers
      $('[data-toggle="popover"]').popover();

      // Vector map
      if ($('#worldMap').length != 0) {
        md.initVectorMap();
      }

      if ($('#RegisterValidation').length != 0) {

        setFormValidation('#RegisterValidation');

        function setFormValidation(id) {
          $(id).validate({
            highlight: function(element) {
              $(element).closest('.form-group').removeClass('has-success').addClass('has-danger');
              $(element).closest('.form-check').removeClass('has-success').addClass('has-danger');
            },
            success: function(element) {
              $(element).closest('.form-group').removeClass('has-danger').addClass('has-success');
              $(element).closest('.form-check').removeClass('has-danger').addClass('has-success');
            },
            errorPlacement: function(error, element) {
              $(element).closest('.form-group').append(error);
            },
          });
        }
      }

    });

    // FileInput
    $('.form-file-simple .inputFileVisible').click(function() {
      $(this).siblings('.inputFileHidden').trigger('click');
    });

    $('.form-file-simple .inputFileHidden').change(function() {
      var filename = $(this).val().replace(/C:\\fakepath\\/i, '');
      $(this).siblings('.inputFileVisible').val(filename);
    });

    $('.form-file-multiple .inputFileVisible, .form-file-multiple .input-group-btn').click(function() {
      $(this).parent().parent().find('.inputFileHidden').trigger('click');
      $(this).parent().parent().addClass('is-focused');
    });

    $('.form-file-multiple .inputFileHidden').change(function() {
      var names = '';
      for (var i = 0; i < $(this).get(0).files.length; ++i) {
        if (i < $(this).get(0).files.length - 1) {
          names += $(this).get(0).files.item(i).name + ',';
        } else {
          names += $(this).get(0).files.item(i).name;
        }
      }
      $(this).siblings('.input-group').find('.inputFileVisible').val(names);
    });

    $('.form-file-multiple .btn').on('focus', function() {
      $(this).parent().siblings().trigger('focus');
    });

    $('.form-file-multiple .btn').on('focusout', function() {
      $(this).parent().siblings().trigger('focusout');
    });
  </script>
</body>
</html>