<?php
include( "client_func.php" );
$hddnClientId = $_SESSION[ 'caller' ][ 'args' ][ 1 ];
if ( $_SESSION[ 'user' ][ 'access_level' ] < SABLE_ACCESS_MANAGER ) {
  SableGeneralFunctions::divertFromPage();
}

?>
<script src="<?= SableGeneralFunctions::printModuleJS('client') ?>"></script>

<!--// Client -->
<form id="frmClient" name="frmClient" autocomplete="on">
  <input type="hidden" value="<?= (SableSystem::sableEncode($hddnAddressId)); ?>" id="hddnAddressId" name="hddnAddressId" />
  <input type="hidden" value="<?= (SableSystem::sableEncode($hddnClientDeleted)); ?>" id="hddnClientDeleted" name="hddnClientDeleted" />
  <input type="hidden" value="<?= (SableSystem::sableEncode($hddnLastUpdate)); ?>" id="hddnLastUpdate" name="hddnLastUpdate" />
  <div class="forms">
    <div class="container forms-grids">
      <div class="row">
        <div class="col-md-12">
          <h3 class="title"><i class="fa fa-plus" aria-hidden="true"></i>&nbsp;Add Client</h3>
          <p></p>
        </div>
      </div>
      
      <!--// selClientTypeId -->
      <div class="row forms-grids">
        <div class="col-xs-12 col-sm-10 col-md-8 col-lg-6 forms-grid">
          <div class="dropdown">
            <select name="selClientTypeId" type="select" id="selClientTypeId" onfocus="showHint('selClientTypeId');" onblur="hideHint('selClientTypeId'); validate_selClientTypeId()" onkeypress="handleEnter(this, event)" onchange="getIdTypeByClientType()" placeholder="Client Type Id">
              <?= (SableDBFunctions::getOptions("client_type", "client_type_id", "client_type_name", -1)); ?>
            </select>
          </div>
          <label class="fieldHint hintUnder" id="hint_selClientTypeId">Client Type Id</label>
        </div>
        <div class="col-xs-12 col-sm-10 col-md-8 col-lg-6 forms-grid">
          <div class="switch">
            <input name="cbClientContract" type="checkbox" id="cbClientContract" class="form-toggle form-toggle-yes-no" onfocus="showHint('cbClientContract');" onblur="hideHint('cbClientContract'); validate_cbClientContract()" checked placeholder="Client Contract" onkeypress="handleEnter(this, event)"/>
            <label for="cbClientContract" data-on="Yes" data-off="No"></label>
          </div>
          <label class="fieldHint hintUnder" id="hint_cbClientContract">Client Contract</label>
        </div>
      </div>
      <p></p>
      
      <!--// Name & Surname -->
      <div class="row forms-grids">
        <div class="col-xs-12 col-sm-10 col-md-8 col-lg-6 forms-grid">
          <input name="edtClientName" type="text" id="edtClientName" onfocus="showHint('edtClientName');" onchange="validate_edtClientName();" onblur="hideHint('edtClientName'); validate_edtClientName();" placeholder="Client Name" onkeypress="handleEnter(this, event);" >
          <label class="fieldHint hintUnder" id="hint_edtClientName">Client Name</label>
        </div>
        <div class="col-xs-12 col-sm-10 col-md-8 col-lg-6 forms-grid">
          <input name="edtClientSurname" type="text" id="edtClientSurname" onfocus="showHint('edtClientSurname');" onchange="validate_edtClientSurname();" onblur="hideHint('edtClientSurname'); validate_edtClientSurname();" placeholder="Client Surname" onkeypress="handleEnter(this, event);" >
          <label class="fieldHint hintUnder" id="hint_edtClientSurname">Client Surname</label>
        </div>
      </div>
      
      <!--// edtClientPhone -->
      <div class="row forms-grids">
        <div class="col-xs-12 col-sm-10 col-md-8 col-lg-6 forms-grid">
          <input name="edtClientPhone" type="tel" id="edtClientPhone" onfocus="showHint('edtClientPhone');" onchange="validate_edtClientPhone();" onblur="hideHint('edtClientPhone'); validate_edtClientPhone();" placeholder="Client Phone" onkeypress="handleEnter(this, event);" >
          <label class="fieldHint hintUnder" id="hint_edtClientPhone">Client Phone</label>
        </div>
        <div class="col-xs-12 col-sm-10 col-md-8 col-lg-6 forms-grid">
          <input name="edtClientPhoneAlt" type="tel" id="edtClientPhoneAlt" onfocus="showHint('edtClientPhoneAlt');" onchange="validate_edtClientPhoneAlt();" onblur="hideHint('edtClientPhoneAlt'); validate_edtClientPhoneAlt();" placeholder="Client Phone Alt" onkeypress="handleEnter(this, event);" >
          <label class="fieldHint hintUnder" id="hint_edtClientPhoneAlt">Client Phone Alt</label>
        </div>
      </div>
      <p></p>
      <!-- edtClientPhone //-->
      
      <div class="row forms-grids">
        <div class="col-xs-12 col-sm-10 col-md-8 col-lg-6 forms-grid">
          <input name="edtClientEmail" type="email" id="edtClientEmail" onfocus="showHint('edtClientEmail');" onchange="validate_edtClientEmail();" onblur="hideHint('edtClientEmail'); validate_edtClientEmail();" placeholder="Client Email" onkeypress="handleEnter(this, event);" >
          <label class="fieldHint hintUnder" id="hint_edtClientEmail">Client Email</label>
        </div>
        <div class="col-xs-12 col-sm-10 col-md-8 col-lg-6 forms-grid">
          <input name="edtClientNote" type="text" id="edtClientNote" onfocus="showHint('edtClientNote');" onchange="validate_edtClientNote();" onblur="hideHint('edtClientNote'); validate_edtClientNote();" placeholder="Client Note" onkeypress="handleEnter(this, event);" >
          <label class="fieldHint hintUnder" id="hint_edtClientNote">Client Note</label>
        </div>
      </div>
      <p></p>
      <div id="divClientIndividual" style="display:none;">
        <div class="row forms-grids">
          <div class="col-xs-12 col-sm-10 col-md-8 col-lg-6 forms-grid">
            <div class="dropdown">
              <select name="selIdTypeId" type="select" id="selIdTypeId" onfocus="showHint('selIdTypeId');" onblur="hideHint('selIdTypeId'); validate_selIdTypeId()" onkeypress="handleEnter(this, event)" placeholder="Client ID Type">
                <?= (SableDBFunctions::getOptions("id_type", "id_type_id", "id_type_name", -1)); ?>
              </select>
            </div>
            <label class="fieldHint hintUnder" id="hint_selIdTypeId">Client ID Type</label>
          </div>
          <div class="col-xs-12 col-sm-10 col-md-8 col-lg-6 forms-grid">
            <input name="edtClientIdNo" type="number" id="edtClientIdNo" class="mod"  onfocus="showHint('edtClientIdNo');" onchange="validate_edtClientIdNo();" onblur="hideHint('edtClientIdNo'); validate_edtClientIdNo();" placeholder="Client Id No" onkeypress="handleEnter(this, event);" >
            <label class="fieldHint hintUnder" id="hint_edtClientIdNo">Client Id No</label>
          </div>
        </div>
        <div class="row forms-grids">
          <div class="col-xs-12 col-sm-10 col-md-8 col-lg-6 forms-grid">
            <div class="dropdown">
              <select name="selGenderId" type="select" id="selGenderId" onfocus="showHint('selGenderId');" onblur="hideHint('selGenderId'); validate_selGenderId()" onkeypress="handleEnter(this, event)" placeholder="Client Gender">
                <?= (SableDBFunctions::getOptions("gender", "gender_id", "gender_name", -1)); ?>
              </select>
            </div>
            <label class="fieldHint hintUnder" id="hint_selGenderId"> Client Gender</label>
          </div>
        </div>
        <p></p>
      </div>
      <p></p>
      <div id="divClientBusiness" style="display:none;"> 
        
        <!--// edtClientBusinessName -->
        
        <div class="row forms-grids">
          <div class="col-xs-12 col-sm-10 col-md-8 col-lg-6 forms-grid">
            <input name="edtClientBusinessName" type="text" id="edtClientBusinessName" onfocus="showHint('edtClientBusinessName');" onchange="validate_edtClientBusinessName();" onblur="hideHint('edtClientBusinessName'); validate_edtClientBusinessName();" placeholder="Client Business Name" onkeypress="handleEnter(this, event);" >
            <label class="fieldHint hintUnder" id="hint_edtClientBusinessName">Client Business Name</label>
          </div>
        </div>
        <p></p>
        <!--// edtClientVatNo -->
        
        <div class="row forms-grids">
          <div class="col-xs-12 col-sm-10 col-md-8 col-lg-6 forms-grid">
            <input name="edtClientVatNo" type="number" id="edtClientVatNo" class="mod"  onfocus="showHint('edtClientVatNo');" onchange="validate_edtClientVatNo();" onblur="hideHint('edtClientVatNo'); validate_edtClientVatNo();" placeholder="Client Vat No" onkeypress="handleEnter(this, event);" >
            <label class="fieldHint hintUnder" id="hint_edtClientVatNo">Client Vat No</label>
          </div>
          <div class="col-xs-12 col-sm-10 col-md-8 col-lg-6 forms-grid">
            <input name="edtClientRegNo" type="number" id="edtClientRegNo" class="mod"  onfocus="showHint('edtClientRegNo');" onchange="validate_edtClientRegNo();" onblur="hideHint('edtClientRegNo'); validate_edtClientRegNo();" placeholder="Client Reg No" onkeypress="handleEnter(this, event);" >
            <label class="fieldHint hintUnder" id="hint_edtClientRegNo">Client Reg No</label>
          </div>
        </div>
        <p></p>
      </div>
      
      <!--// selRewardLevelId -->
      
      <div class="row forms-grids">
        <div class="col-xs-12 col-sm-10 col-md-8 col-lg-6 forms-grid">
          <div class="dropdown">
            <select name="selRewardLevelId" type="select" id="selRewardLevelId" onfocus="showHint('selRewardLevelId');" onblur="hideHint('selRewardLevelId'); validate_selRewardLevelId()" onkeypress="handleEnter(this, event)" placeholder="Client RewardLevel">
              <?= (SableDBFunctions::getOptions("reward_level", "reward_level_id", "reward_level_name", -1)); ?>
            </select>
          </div>
          <label class="fieldHint hintUnder" id="hint_selRewardLevelId">Client Reward Level</label>
        </div>
      </div>
      <p></p>
      <!-- selRewardLevelId //--> 
      
      <!--// Add Addresses -->
      
      <div class="row forms-grid">
        <div class="col-md-12">
          <p></p>
          <h2><i class="fa fa-home" aria-hidden="true"></i>&nbsp;Client Address</h2>
        </div>
      </div>
      
      <!--// Add Addresses -->
      <div class="row forms-grids">
        <div class="col-xs-12 col-sm-10 col-md-8 col-lg-6 forms-grid">
          <label class="title"> <span> [Multiple addresses can be added. Type an address and click "+Address"]</span> </label>
          <select name="selAddressTypeId" id="selAddressTypeId" onkeypress="handleEnter(this, event)" placeholder="Address Type">
            <?php SableDBFunctions::printOptions('address_type', 'address_type_id', 'address_type_name', -1); ?>
          </select>
          <label class="fieldHint hintUnder" id="hint_selAddressType">Select address type</label>
        </div>
      </div>
      <p></p>
      
      <!--// cbClientAddrBill -->
      <div class="row">
        <div class="col-md-4">
          <div class="switch">
            <input name="cbClientAddrBill" type="checkbox" id="cbClientAddrBill" class="form-toggle form-toggle-yes-no" onfocus="showHint('cbClientAddrBill');" onblur="hideHint('cbClientAddrBill'); validate_cbClientAddrBill()" checked placeholder="Billing address provided" onkeypress="handleEnter(this, event)"/>
            <label for="cbClientAddrBill" data-on="Yes" data-off="No"></label>
          </div>
        </div>
        <div class="col-md-8">
          <div class="fieldHint" id="hint_cbClientAddrBill">Billing address same as physical address?</div>
        </div>
      </div>
      <p></p>
      <!-- cbClientAddrBill //-->
      
      <div class="row forms-grid">
        <div class="col-md-4 forms-grid">
          <input name="edtAddressStreet" type="text" id="edtAddressStreet" onfocus="showHint('edtAddressStreet'); validate_edtAddressStreet();" onblur="hideHint('edtAddressStreet');" placeholder="Address Street" onkeypress="handleEnter(this, event);" >
        </div>
        <div class="col-md-8">
          <div class="fieldHint" id="hint_edtAddressStreet">Address Street</div>
        </div>
      </div>
      <p></p>
      <div class="row forms-grid">
        <div class="col-md-4 forms-grid">
          <input name="edtAddressSuburb" type="text" id="edtAddressSuburb" onfocus="showHint('edtAddressSuburb'); validate_edtAddressSuburb();" onblur="hideHint('edtAddressSuburb');" placeholder="Address Suburb" onkeypress="handleEnter(this, event);" >
        </div>
        <div class="col-md-8">
          <div class="fieldHint" id="hint_edtAddressSuburb">Address Suburb</div>
        </div>
      </div>
      <p></p>
      
      <!-- edtBuildingName //--> 
      
      <!--// edtBuildingName -->
      
      <div class="row forms-grid">
        <div class="col-md-4 forms-grid">
          <input name="edtAddressCity" type="text" id="edtAddressCity" onfocus="showHint('edtAddressCity'); validate_edtAddressCity();" onblur="hideHint('edtAddressCity');" placeholder="Address City" onkeypress="handleEnter(this, event);" >
        </div>
        <div class="col-md-8">
          <div class="fieldHint" id="hint_edtAddressCity">Address City</div>
        </div>
      </div>
      <p></p>
      
      <!-- edtBuildingName //--> 
      
      <!--// edtBuildingName -->
      <div class="row forms-grid">
        <div class="col-md-4 forms-grid">
          <input name="edtAddressCounty" type="text" id="edtAddressCounty" onfocus="showHint('edtAddressCounty'); validate_edtAddressCounty();" onblur="hideHint('edtAddressCounty');" placeholder="Address County" onkeypress="handleEnter(this, event);" >
        </div>
        <div class="col-md-8">
          <div class="fieldHint" id="hint_edtAddressCounty">Address County</div>
        </div>
      </div>
      <p></p>
      
      <!-- edtBuildingName //--> 
      
      <!--// edtBuildingName -->
      <div class="row forms-grid">
        <div class="col-md-4 forms-grid">
          <input name="edtAddressPostalCode" type="text" id="edtAddressPostalCode" onfocus="showHint('edtAddressPostalCode'); validate_edtAddressPostalCode();" onblur="hideHint('edtAddressPostalCode');" placeholder="Address Postal Code" onkeypress="handleEnter(this, event);" >
        </div>
        <div class="col-md-8">
          <div class="fieldHint" id="hint_edtAddressPostalCode">Address Postal Code</div>
        </div>
      </div>
      <p></p>
      
      <!-- edtBuildingName //-->
      
      <div class="col-xs-12 col-sm-6 col-md-2 col-lg-2 forms-grid">
        <input id="btnAddAddress" type="button" onclick="addAddressToArray()" value="+ Address" class="sub-button" />
      </div>
      </br>
      </br>
    
                <div class="row forms-grids">
                <div class="col-md-12 forms-grid">
                	<div id="searchResults"></div>
                </div>
            </div>    
    
      <div class="col-md-4 forms-grid">
        <div class="row forms-grids" id="addressElement"> 
          <!--// Address elements will be placed here. --> 
          
        </div>
      </div>
      <p></p>
      </br>      </br>

      </br>
      <div class="row forms-grid">
        <div class="col-md-12">
          <p></p>
          <h2><i class="fa fa-building" aria-hidden="true"></i>&nbsp;Buildings</h2>
        </div>
      </div>
      
      <!--// edtAreaName --> 
      
      <!--    <div class="row forms-grids">
      <div class="col-md-4 forms-grid">
        <input type="text" id="edtAreaName" name="edtAreaName" placeholder="SEARCH..." onKeyUp="doAreaRefinement(this)" style="border-bottom: none;"  autocomplete="off"/>
      </div>
      <div class="col-md-8">
        <div class="fieldHint" id="hint_edtAreaName">Search by area</div>
      </div>
    </div>--> 
      
      <!-- edtAreaName //-->
      
      <p></p>
      
      <!--// edtBuildingName --> 
      
      <!--// Add Addresses -->
      <div class="row forms-grids">
        <div class="col-xs-12 col-sm-10 col-md-8 col-lg-6 forms-grid">
          <label class="title"> <span> [Multiple buildings can be added. Type an address and click "+Building"]</span> </label>
          <select name="selAreaId" id="selAreaId" onkeypress="handleEnter(this, event)" placeholder="Area">
            <?php SableDBFunctions::printOptions('area', 'area_id', 'area_name', -1); ?>
          </select>
          <label class="fieldHint hintUnder" id="hint_selAreaId">Select building type</label>
        </div>
      </div>
      <p></p>
      <div class="row forms-grid">
        <div class="col-md-4 forms-grid">
          <input name="edtBuildingName" type="text" id="edtBuildingName" onfocus="showHint('edtBuildingName'); validate_edtBuildingName();" onblur="hideHint('edtBuildingName');" placeholder="Building Name" onkeypress="handleEnter(this, event);" >
        </div>
        <div class="col-md-8">
          <div class="fieldHint" id="hint_edtBuildingName">Building Name</div>
        </div>
      </div>
      <p></p>
      
      <!-- edtBuildingName //--> 
      
      <!--// Add Addresses -->
      <div class="row forms-grids">
        <div class="col-xs-12 col-sm-10 col-md-8 col-lg-6 forms-grid">
          <label class="fieldHint hintUnder" id="hint_txtBuildingAddress">Building Address</label>
        </div>
      </div>
      <p></p>
      <!--// edtBuildingName -->
      <div class="row forms-grid">
        <div class="col-md-4 forms-grid">
          <input name="edtBuildingAddressStreet" type="text" id="edtBuildingAddressStreet" onfocus="showHint('edtBuildingAddressStreet'); validate_edtBuildingAddressStreet();" onblur="hideHint('edtBuildingAddressStreet');" placeholder="Building Address Street" onkeypress="handleEnter(this, event);" >
        </div>
        <div class="col-md-8">
          <div class="fieldHint" id="hint_edtBuildingAddressStreet">Building Address Street</div>
        </div>
      </div>
      <p></p>
      
      <!-- edtBuildingName //--> 
      
      <!--// edtBuildingName -->
      <div class="row forms-grid">
        <div class="col-md-4 forms-grid">
          <input name="edtBuildingAddressSuburb" type="text" id="edtBuildingAddressSuburb" onfocus="showHint('edtBuildingAddressSuburb'); validate_edtBuildingAddressSuburb();" onblur="hideHint('edtBuildingAddressSuburb');" placeholder="Building Address Suburb" onkeypress="handleEnter(this, event);" >
        </div>
        <div class="col-md-8">
          <div class="fieldHint" id="hint_edtBuildingAddressSuburb">Building Address Suburb</div>
        </div>
      </div>
      <p></p>
      
      <!-- edtBuildingName //--> 
      
      <!--// edtBuildingName -->
      
      <div class="row forms-grid">
        <div class="col-md-4 forms-grid">
          <input name="edtBuildingAddressCity" type="text" id="edtBuildingAddressCity" onfocus="showHint('edtBuildingAddressCity'); validate_edtBuildingAddressCity();" onblur="hideHint('edtBuildingAddressCity');" placeholder="Building Address City" onkeypress="handleEnter(this, event);" >
        </div>
        <div class="col-md-8">
          <div class="fieldHint" id="hint_edtBuildingAddressCity">Building Address City</div>
        </div>
      </div>
      <p></p>
      
      <!-- edtBuildingName //--> 
      
      <!--// edtBuildingName -->
      <div class="row forms-grid">
        <div class="col-md-4 forms-grid">
          <input name="edtBuildingAddressCounty" type="text" id="edtBuildingAddressCounty" onfocus="showHint('edtBuildingAddressCounty'); validate_edtBuildingAddressCounty();" onblur="hideHint('edtBuildingAddressCounty');" placeholder="Building Address County" onkeypress="handleEnter(this, event);" >
        </div>
        <div class="col-md-8">
          <div class="fieldHint" id="hint_edtBuildingAddressCounty">Building Address County</div>
        </div>
      </div>
      <p></p>
      
      <!-- edtBuildingName //--> 
      
      <!--// edtBuildingName -->
      <div class="row forms-grid">
        <div class="col-md-4 forms-grid">
          <input name="edtBuildingAddressPostalCode" type="text" id="edtBuildingAddressPostalCode" onfocus="showHint('edtBuildingAddressPostalCode'); validate_edtBuildingAddressPostalCode();" onblur="hideHint('edtBuildingAddressPostalCode');" placeholder="Building Address Postal Code" onkeypress="handleEnter(this, event);" >
        </div>
        <div class="col-md-8">
          <div class="fieldHint" id="hint_edtBuildingAddressPostalCode">Building Address Postal Code</div>
        </div>
      </div>
      <p></p>
      
      <!-- edtBuildingName //-->
      
      <div class="row forms-grid">
        <div class="col-md-4 forms-grid">
          <textarea name="txtBuildingNeeds" type="date" id="txtBuildingNeeds" onfocus="showHint('txtBuildingNeeds'); validate_txtBuildingNeeds();" onblur="hideHint('txtBuildingNeeds');" placeholder="Requirements" onkeypress="handleEnter(this, event);" ></textarea>
        </div>
        <div class="col-md-8">
          <div class="fieldHint" id="hint_txtBuildingNeeds">Requirements</div>
        </div>
      </div>
      <p></p>
      <p></p>
      
      <!-- edtBuildingName //-->
      
      <div class="col-xs-12 col-sm-6 col-md-2 col-lg-2 forms-grid">
        <input id="btnAddBuilding" type="button" onclick="addBuildingToArray()" value="+ Building" class="sub-button" />
      </div>
      </br>
      </br>


            <div class="row forms-grids">
                <div class="col-md-12 forms-grid">
                	<div id="searchResults"></div>
                </div>
            </div>    


      <div class="row forms-grid">
        <div class="col-md-4 forms-grid">
          <div id="buildingElement"> 
            <!--// Address elements will be placed here. --> 
            
          </div>
        </div>
      </div>
      <p></p>
      <p></p>
      <p></p>
      <p></p>
      <p></p>
      </br>
      </br>
      
      <!-- buttons //--> 
      
      <!--// buttons -->
            <div class="row forms-grids">
                <div class="col-md-2 forms-grid">
          <input type="button" id="btnCancel" value="Cancel" class="submit" onclick="window.location = '<?php SableSystem::printCallPageLink('/client/'); ?>'"/>
        </div>
                <div class="col-md-2 forms-grid">
          <input id="btnOk" type="button" onclick="insertClient();" value="Add Client" class="submit"/>
        </div>
      </div>
      <!-- buttons //--> 






    </div>
  </div>
</form>
<!-- Client //--> 
