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


<!--// Client -->
<form id="frmClient" name="frmClient" autocomplete="on">
	<div class="forms">
		<div class="container forms-grids">
			<div class="row forms-grid">
				<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-grid">
				<div class="col-md-4 forms-grid">
					<div class="dropdown">
						<select name="selClientTypeId" type="select" id="selClientTypeId" onfocus="showHint('selClientTypeId');" 
								onblur="hideHint('selClientTypeId'); validate_selClientTypeId()" onkeypress="handleEnter(this, event)" 
								placeholder="Client Type" onchange="getIdTypeByClientType()">
						<?php echo(SableDBFunctions::getOptions("client_type", "client_type_id", "client_type_name", -1)); ?>
						</select>
					</div>
				</div>
				<div class="col-md-8">
					<div class="fieldHint" id="hint_selClientTypeId">Client Type</div>
				</div>
			</div>
			<p></p>
			<!-- selClientTypeId //-->
			<p></p>			
			<!--// selIdTypeId -->
			<div class="row forms-grid">
				<div class="col-md-4 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="ID Type" onChange="setIdField()">
						<option>Select Client Type First</option>
						</select>
					</div>
				</div>
				<div class="col-md-8">
					<div class="fieldHint" id="hint_selIdTypeId">ID Type</div>
				</div>
			</div>
			<p></p>
			<!-- selIdTypeId //-->			
			<p></p>
			
	<!--//		<div id="divClientProxy" style="display:none;">
				<div class="row forms-grid">
					<div class="col-md-4 forms-grid">
						<div class="dropdown">
							<select name="selClientParentId" type="select" id="selClientParentId" onfocus="showHint('selClientParentId');" 
									onblur="hideHint('selClientParentId'); validate_selClientParentId()" onkeypress="handleEnter(this, event)" 
									placeholder="Company (Employer)">
							<?php 
								echo(SableDBFunctions::getOptions("client", "client_id", "client_business_name", -1, "where client_type_id = 2"));
							?>
							</select>
						</div>
					</div>
					<div class="col-md-8">
						<div class="fieldHint" id="hint_selClientParentId">Company (Employer)</div>
					</div>
				</div>
				<p></p>
				<p></p>
			</div> -->

			<div id="divClientIndividual" style="display:none;">
				<!--// edtClientName -->
				<div class="row forms-grid">
					<div class="col-md-4 forms-grid">
						<input name="edtClientName" type="text" id="edtClientName" onfocus="showHint('edtClientName'); validate_edtClientName();" onblur="hideHint('edtClientName');" placeholder="Client Name" onkeypress="handleEnter(this, event);" >	
					</div>
					<div class="col-md-8">
						<div class="fieldHint" id="hint_edtClientName">Client Name</div>
					</div>
				</div>
				<p></p>
				<!-- edtClientName //-->
				<p></p>
				<!--// edtClientSurname -->
				<div class="row forms-grid">
					<div class="col-md-4 forms-grid">
						<input name="edtClientSurname" type="text" id="edtClientSurname" onfocus="showHint('edtClientSurname'); validate_edtClientSurname();" onblur="hideHint('edtClientSurname');" placeholder="Client Surname" onkeypress="handleEnter(this, event);" >	
					</div>
					<div class="col-md-8">
						<div class="fieldHint" id="hint_edtClientSurname">Client Surname</div>
					</div>
				</div>
				<p></p>
				<!-- edtClientSurname //-->
				<p></p>
				<!--// edtClientIdNo -->
				<div class="row forms-grid">
					<div class="col-md-4 forms-grid">
						<input name="edtClientIdNo" type="text" id="edtClientIdNo" onfocus="showHint('edtClientIdNo'); validate_edtClientIdNo();" onblur="hideHint('edtClientIdNo');" placeholder="Client ID No" onkeypress="handleEnter(this, event);" >	
					</div>
					<div class="col-md-8">
						<div class="fieldHint" id="hint_edtClientIdNo">Client ID No</div>
					</div>
				</div>
				<p></p>
				<!-- edtClientIdNo //-->
				<p></p>
				<!--// selClientGender -->
				<div class="row forms-grid">
					<div class="col-md-4 forms-grid">
						<div class="dropdown">
							<select name="selClientGender" type="select" id="selClientGender" 
									onfocus="showHint('selClientGender');" 
									onblur="hideHint('selClientGender'); validate_selClientGender()" 
									onkeypress="handleEnter(this, event)" 
									placeholder="Gender">
							<?php 
								SableDBFunctions::printOptions("gender", "gender_id", "gender_name", -1, "where client_type_id = 1");
							?>
							</select>
						</div>	
					</div>
					<div class="col-md-8">
						<div class="fieldHint" id="hint_selClientGender">Gender</div>
					</div>
				</div>
				<p></p>
				<!-- selClientGender //-->				
			</div>
			
			<div id="divClientBusiness" style="display:none;">
				<!--// edtClientName -->
				<div class="row forms-grid">
					<div class="col-md-4 forms-grid">
						<input name="edtClientName" type="text" id="edtClientName" onfocus="showHint('edtClientName'); validate_edtClientName();" onblur="hideHint('edtClientName');" placeholder="Client Business Name" onkeypress="handleEnter(this, event);" >	
					</div>
					<div class="col-md-8">
						<div class="fieldHint" id="hint_edtClientName">Client Business Name</div>
					</div>
				</div>
				<p></p>
				<!-- edtClientName //-->
				<p></p>
				<!--// edtClientVatNo -->
				<div class="row forms-grid">
					<div class="col-md-4 forms-grid">
						<input name="edtClientVatNo" type="text" id="edtClientVatNo" onfocus="showHint('edtClientVatNo'); validate_edtClientVatNo();" onblur="hideHint('edtClientVatNo');" placeholder="VAT No" onkeypress="handleEnter(this, event);" >	
					</div>
					<div class="col-md-8">
						<div class="fieldHint" id="hint_edtClientVatNo">VAT No</div>
					</div>
				</div>
				<p></p>
				<!-- edtClientVatNo //-->
				<p></p>
				
				<!--// edtClientRegNo -->
				<div class="row forms-grids" id="divBusinessRegNo" style="display:none">
					<div class="col-md-4 forms-grid">
						<input name="edtClientRegNoYear" type="number" maxlength="4" max="<?php echo(date('Y')); ?>" min="1900" id="edtClientRegNoYear"
							   onfocus="showHint('edtClientRegNo');" onblur="hideHint('edtClientRegNo'); validate_edtClientRegNoYear()" onkeypress="handleEnter(this, event)" style="width:33%;">&nbsp;/&nbsp;
						<input name="edtClientRegNoMid" type="number" maxlength="6" min="1" id="edtClientRegNoMid" onfocus="showHint('edtClientRegNo');" 
							   onblur="hideHint('edtClientRegNo'); validate_edtClientRegNoMid()" onkeypress="handleEnter(this, event)"
							   style="width:40%; margin-left:3px;">&nbsp;/&nbsp;
						<input name="edtClientRegNoType" type="number" maxlength="2" max="30" min="6" id="edtClientRegNoType" 
							   onfocus="showHint('edtClientRegNo');" onblur="hideHint('edtClientRegNo'); validate_edtClientRegNoType()" 
							   onkeypress="handleEnter(this, event)"  style="width:17%; margin-left:3px;">
					</div>
					<div class="col-md-8">
						<div class="fieldHint" id="hint_edtClientRegNo">Company Registration No.</div>
					</div>
				</div>
				 <!-- edtClientRegNo //-->
				
				<!--// edtTrafficRegNo -->
				<div class="row forms-grid" id="divTaxRegNo" style="display:none">
					<div class="col-md-4 forms-grid">
						<input name="edtTrafficRegNo" type="text" id="edtTrafficRegNo" onfocus="showHint('edtTrafficRegNo'); validate_edtTrafficRegNo();" onblur="hideHint('edtTrafficRegNo');" placeholder="Traffic Register No." onkeypress="handleEnter(this, event);" >	
					</div>
					<div class="col-md-8">
						<div class="fieldHint" id="hint_edtTrafficRegNo">Traffic Register No.</div>
					</div>
				</div>
				<p></p>
				<!-- edtTrafficRegNo //-->
				
				<p></p>
				<!--// selBusinessNature -->
				<div class="row forms-grid">
					<div class="col-md-4 forms-grid">
						<div class="dropdown">
							<select name="selBusinessNature" type="select" id="selBusinessNature" 
									onfocus="showHint('selBusinessNature');" 
									onblur="hideHint('selBusinessNature'); validate_selBusinessNature()" 
									onkeypress="handleEnter(this, event)" 
									placeholder="Nature of Business">
							<?php 
								SableDBFunctions::printOptions("gender", "gender_id", "gender_name", -1, "where client_type_id = 2");
							?>
							</select>
						</div>	
					</div>
					<div class="col-md-8">
						<div class="fieldHint" id="hint_selBusinessNature">Nature of Business</div>
					</div>
				</div>
				<p></p>
				<!-- selBusinessNature //-->				
				
			</div>
			
			<p></p>
			<!--// edtClientPhone -->
			<div class="row forms-grid">
				<div class="col-md-4 forms-grid">
					<input name="edtClientPhone" type="tel" id="edtClientPhone" onfocus="showHint('edtClientPhone'); validate_edtClientPhone();" onblur="hideHint('edtClientPhone');" placeholder="Client Phone" onkeypress="handleEnter(this, event);" >	
				</div>
				<div class="col-md-8">
					<div class="fieldHint" id="hint_edtClientPhone">Client Phone</div>
				</div>
			</div>
			<p></p>
			<!-- edtClientPhone //-->
			<p></p>
			<!--// edtClientEmail -->
			<div class="row forms-grid">
				<div class="col-md-4 forms-grid">
					<input name="edtClientEmail" type="email" id="edtClientEmail" onfocus="showHint('edtClientEmail'); validate_edtClientEmail();" onblur="hideHint('edtClientEmail');" placeholder="Client Email" onkeypress="handleEnter(this, event);" >	
				</div>
				<div class="col-md-8">
					<div class="fieldHint" id="hint_edtClientEmail">Client Email</div>
				</div>
			</div>
			<p></p>
			<!-- edtClientEmail //-->
			<p></p>

       		<!--// 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">Addresses <span>
                    	<br />[Multiple addresses can be added. Type an address and click "+Address"]</span>
                    </label>
                    <select name="selAddress" id="selAddress" 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_selAddress">Select address type</label>
                </div>
            </div>

            <div class="row forms-grids"> 
                <div class="col-xs-12 col-sm-10 col-md-8 col-lg-6 forms-grid">
                    <textarea name="txtClientAddress" type="text" id="txtClientAddress" placeholder="Address" sabledata="address"
                    onkeypress="handleEnter(this, event)" rows="6" onKeyUp="updateMapData();"></textarea>
                    <label class="fieldHint hintUnder" id="hint_txtClientAddress">Address</label>
                </div>
                <div class="col-xs-12 col-sm-6 col-md-2 col-lg-2 forms-grid">
                    <input id="btnAddAddress" type="button" onclick="addAddress()" value="+ Address" class="sub-button" />
                </div>                              
            </div>
            <div class="row forms-grids">
                <div class="col-md-12 forms-grid">
                	<div id="searchResults"></div>
                </div>
            </div>
			
			<div class="row forms-grids" id="addressElement">
				<!--// Address elements will be placed here. -->
			</div>
			
			<p></p>
			<!--// selVehicleId -->
			<div class="row forms-grid">
				<div class="col-md-4 forms-grid">
					<div class="dropdown">
						<input type="text" id="edtVehicleId" name="edtVehicleId" placeholder="Vehicles" onKeyUp="refineVehicle()" 
								onBlur="CheckVehicle()"/>						
						<select name="selVehicleId" type="select" id="selVehicleId" onChange="vehicleItem.addItem(this); setVehicle();" onfocus="showHint('edtVehicleId');" onblur="hideHint('edtVehicleId'); CheckVehicle()" onkeypress="handleEnter(this, event)" placeholder="Vehicles" size="12" class="noArrow">
						<?php 
						$params = [];
						$params['table_name']				= 'vehicle';
						$params['tables']					= [];
						$params['tables'][0]['table_name']	= 'vehicle';
						
						$params['tables'][1]['table_name']	= 'vehicle_make';
						$params['tables'][1]['join_type']	= 'inner';							
						$params['tables'][1]['field_name']	= 'vehicle_make_id';
							
						$params['tables'][2]['table_name']	= 'vehicle_series';
						$params['tables'][2]['join_type']	= 'inner';
						$params['tables'][2]['field_name']	= 'vehicle_series_id';
							
						$params['value_field_name'] 		= 'vehicle_id';
						$params['caption_field_name']		= "concat(vehicle_register_no, ' [', vehicle_make_name, ' ', vehicle_series_name, ']')";
						$params['selected_value']			= 1;
						$params['order_field'] 				= 'vehicle_register_no';
						$params['select_title']				= 'Select Vehicle';
						$params['where_clause']				= "";
						SableDBFunctions::printOptionsAdv($params); 
						?>
						</select>
					</div>

				</div>
				<div class="col-md-8">
					<div class="fieldHint" id="hint_edtVehicleId">Vehicles</div>
				</div>
			</div>
			<div class="row forms-grid" id="VehicleElement">
				<!--// Selected elements will be placed here. -->
			</div>
			<p></p>
			<!-- selVehicleId //-->			

		<!--// buttons -->
			<div class="row forms-grid">
				<div class="col-md-2">
					<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 //-->
