<?php
include 'header.php';
$bdd=new DB();
?>
<style>
.outer-container {
	background: #F0F0F0;
	border: #e0dfdf 1px solid;
	padding: 40px 20px;
	border-radius: 2px;
}
.btn-submit {
	background: #333;
	border: #1d1d1d 1px solid;
    border-radius: 2px;
	color: #f0f0f0;
	cursor: pointer;
    padding: 5px 20px;
    font-size:0.9em;
}
#response {
    padding: 10px;
    margin-top: 10px;
    border-radius: 2px;
    display:none;
}

.success {
    background: #c7efd9;
    border: #bbe2cd 1px solid;
}

.error {
    background: #fbcfcf;
    border: #f3c6c7 1px solid;
}

div#response.display-block {
    display: block;
}

.tutorial-table {
    margin-top: 40px;
    font-size: 0.8em;
	border-collapse: collapse;
	width: 100%;
}

.tutorial-table th {
    background: #f0f0f0;
    border-bottom: 1px solid #dddddd;
	padding: 8px;
	text-align: left;
}

.tutorial-table td {
    background: #FFF;
	border-bottom: 1px solid #dddddd;
	padding: 8px;
	text-align: left;
}
</style>
<div class="row">
	<div class="col-sm-12"><button class="btn btn-blue btn-block">ADD KYC Customer</button></div>
	<div class="col-sm-12">&nbsp</div>
	<div class="col-sm-12">
    <div class="outer-container">
		<!--<div><a href="uploads/item_sample.xlsx"><h4>Click here for sample file</h4></a></div>-->
        <form action="" method="post" enctype="multipart/form-data" class="form-horizontal" onsubmit="return validateForm()">
			<div class="form-group">
				<label class="control-label col-sm-1" for="tactics">Name:</label>
				<div class="col-sm-3">
					<input type="text" class="form-control" name="customer_name" id="customer_name" required>
				</div>
				<label class="control-label col-sm-2" for="tactics">Contact No:</label>
				<div class="col-sm-2">
					<input type="number" class="form-control" name="contact_no" required>
				</div>
				<label class="control-label col-sm-1" for="tactics">Date:</label>
				<div class="col-sm-3">
					<input type="datetime-local" class="form-control" value="<?php echo date('Y-m-d\TH:i:s'); ?>" name="date" id="date" required>
				</div>
			</div>
			<div class="form-group">
				<label class="control-label col-sm-2" for="tactics">Address:</label>
				<div class="col-sm-10">
					<textarea type="text" class="form-control" name="address" required></textarea>
				</div>
			</div>
			<div class="form-group">
				<label class="control-label col-sm-2" for="Proof">ID Proof:</label>
				<div class="col-sm-10">
					<select class="form-control" name="verify_type" onChange="set_id_proof_value(value)" required>
						<option value="">select varification type</option>
						<?php
						$menu_option_id_rows=$bdd->getAll("SELECT * FROM menu_option WHERE menu_id='22'");
						foreach($menu_option_id_rows as $row){
						?>
							<option value="<?php echo $row['name'];?>"><?php echo $row['name'];?></option>
						<?php
						}
						?>
					</select>
				</div>
			</div>
			<div class="form-group">
				<label class="control-label col-sm-2" for="Document">ID Proof Document:</label>
				<div class="col-sm-4">
					<input type="hidden" id="document_id_proof" name="document_id_proof" required>
					<?php
					foreach($menu_option_id_rows as $row){
					?>
						<input class="form-control"  type="text" id="document_<?php echo $row['name'];?>" name="document_<?php echo $row['name'];?>" style="display:none">
					<?php
					}
					?>
				</div>
				<div class="col-sm-2">
					<input class="form-control" type="text" id="document_id_proof_pan_state_name" name="document_id_proof_pan_state_name" placeholder="State Name" style="display:none">
				</div>
				<div class="col-sm-2">
					<input class="form-control" type="text" id="document_id_proof_valid" name="document_id_proof_valid" placeholder="Valid/Invalid" readonly required>
				</div>
				<div class="col-sm-2">
					<Button class="form-control btn btn-primary"  type="button" id="document_verify_button" name="document_verify_button" style="display:none">Verify</button>
				</div>

			</div>
			
            <div class="form-group">
				<label class="control-label col-sm-2"></label>
				<div class="col-sm-4" style="display:none" id="response_id_proof_document_div"></div>
				 <img style="display:none" id="response_id_proof_aadhar_photo" src="" alt="Aadhar photo" />
				<textarea style="display:none" id="response_id_proof_data" name="response_id_proof_data"></textarea>
				<div id="otp_div" style="display:none">
					<input type="hidden" id="ref_id" name="ref_id">
					<div class="col-sm-3">
						<input class="form-control"  type="text" name="aadhaar_otp" id="aadhaar_otp" Placeholder="Enter otp here">
					</div>
					<div class="col-sm-3">
						<Button class="form-control btn btn-warning"  type="button" id="verify_aadhaar_otp" name="verify_aadhaar_otp">Verify OTP</button>
					</div>
				</div>
			</div>
			
			<div class="form-group">
				<label class="control-label col-sm-2" for="Proof">Address Proof:</label>
				<div class="col-sm-10">
					<select class="form-control" name="verify_type" onChange="set_address_proof_value(value)" required>
						<option value="">select varification type</option>
						<?php
						$menu_option_address_rows=$bdd->getAll("SELECT * FROM menu_option WHERE menu_id='23'");
						foreach($menu_option_address_rows as $row){
						?>
							<option value="<?php echo $row['name'];?>"><?php echo $row['name'];?></option>
						<?php
						}
						?>
					</select>
				</div>
			</div>
			<div class="form-group">
				<label class="control-label col-sm-2" for="Document">Address Proof Document:</label>
				<div class="col-sm-4">
					<input type="hidden" id="document_address_proof" name="document_address_proof" required>
					<?php
					foreach($menu_option_address_rows as $row){
					?>
						<input class="form-control"  type="text" id="address_proof_document_<?php echo $row['name'];?>" name="address_proof_document_<?php echo $row['name'];?>" style="display:none">
					<?php
					}
					?>
				</div>
				<div class="col-sm-2">
					<input class="form-control" type="text" id="document_address_proof_pan_state_name" name="document_address_proof_pan_state_name" placeholder="State Name" style="display:none">
				</div>
				<div class="col-sm-2">
					<input class="form-control" type="text" id="document_address_proof_valid" name="document_address_proof_valid" placeholder="Valid/Invalid" readonly required>
				</div>
				<div class="col-sm-2">
					<Button class="form-control btn btn-primary"  type="button" id="address_proof_document_verify_button" name="address_proof_document_verify_button" style="display:none">Verify</button>
				</div>
			</div>
			
			<div class="form-group">
				<label class="control-label col-sm-2"></label>
				<div class="col-sm-4" style="display:none" id="response_address_proof_document_div"></div>
				<textarea style="display:none" id="response_address_proof_data" name="response_address_proof_data"></textarea>
				<div id="aadhaar_otp_div" style="display:none">
					<input type="hidden" id="address_proof_ref_id" name="address_proof_ref_id">
					<div class="col-sm-3">
						<input class="form-control"  type="text" name="address_aadhaar_otp" id="address_aadhaar_otp" Placeholder="Enter otp here">
					</div>
					<div class="col-sm-3">
						<Button class="form-control btn btn-warning"  type="button" id="verify_address_aadhaar_otp" name="verify_address_aadhaar_otp">Verify OTP</button>
					</div>
				</div>
			</div>
			
			<!--
			<div class="form-group">
				<label class="control-label col-sm-2" for="Document">ID Proof Image:</label>
				<div class="col-sm-10">
					<input class="form-control" type="file" id="id_proof_image" name="id_proof_image" accept="image/*,application/pdf">
				</div>
			</div>
			
			<div class="form-group">
				<label class="control-label col-sm-2" for="Document">Address Proof Image:</label>
				<div class="col-sm-10">
					<input class="form-control"  type="file" id="address_proof_image" name="address_proof_image" accept="image/*,application/pdf">
				</div>
			</div>
			-->
			
			<div class="form-group">
				<div class="col-sm-2"></div>
				<div class="col-sm-10">
					<button type="submit" id="submit" name="save_data" class="form-control btn btn-info" style="margin-top:10px;">Upload</button>
				</div>
				</div>
			</div>
            
        </form>
    </div>
    <div id="response" class="<?php if(!empty($type)) { echo $type . " display-block"; } ?>"><?php if(!empty($message)) { echo $message; } ?>
	</div>
    
	</div>
</div>
</div>
</div>
</div>
    
<?php
include "footer.php";

if(isset($_POST['save_data'])){
	$year=date('Y',strtotime($_POST['date']));
	$month=date('m',strtotime($_POST['date']));
	$date=date('Y-m-d',strtotime($_POST['date']));
	$date_time=date("Y-m-d H:i:s");
	$temp_chs_no="TEMP".date('YmdHis');
	$customer_name = preg_replace('/\s+/', '_', $_POST['customer_name']);
	
	$checkYear = 'uploads/'.$year;
	$checkMonth = 'uploads/'.$year.'/'.$month;
	if(!file_exists($checkYear)) {
		mkdir('uploads/'.$year);
	}
	if(!file_exists($checkMonth)) {
		mkdir('uploads/'.$year.'/'.$month);
	}
	$filename = 'uploads/'.$year.'/'.$month.'/'.$customer_name.'-'.$_POST['contact_no'].'-'.$temp_chs_no;
	
	if (file_exists($filename)) {
		echo "<script>alert('Customer Alreay Exist')</script>";
	} else {
		$cust_row=$bdd->getOne("SELECT customer_id FROM customer WHERE name='".$customer_name."' and contact_no='".$_POST['contact_no']."'");
		if(!empty($cust_row)){
			echo "<script>alert('Customer Alreay Exist')</script>";
		}else{
			
			mkdir('uploads/'.$year.'/'.$month.'/'.$customer_name.'-'.$_POST['contact_no'].'-'.$temp_chs_no);
			
			$last_id=$bdd->lastId("INSERT INTO `customer` (`name`, `contact_no`,`date`, `status`, `added_by`,`address`,`chassis_no`) VALUES ('".$customer_name."', '".$_POST['contact_no']."', '$date_time', 'KYC', '".$_SESSION['admin_id']."','".$_POST['address']."','$temp_chs_no')");
			if($last_id>0){
				$id_proof_name=$_POST['document_id_proof'];
				$id_proof_value=$_POST['document_'.$id_proof_name];
				$address_proof_name=$_POST['document_address_proof'];
				$address_proof_value=$_POST['address_proof_document_'.$address_proof_name];
				if($_FILES["id_proof_image"]["tmp_name"]!=null && $_FILES["id_proof_image"]["tmp_name"]!=""){
					$id_proof_image_name="IdProof".$_POST['document_id_proof'].".".strtolower(pathinfo($_FILES['id_proof_image']['name'], PATHINFO_EXTENSION));
				}else{
					$id_proof_image_name="";
				}
				if($_FILES["address_proof_image"]["tmp_name"]!=null && $_FILES["address_proof_image"]["tmp_name"]!=""){
					$address_proof_image_name="AddressProof".$_POST['document_address_proof'].".".strtolower(pathinfo($_FILES['address_proof_image']['name'], PATHINFO_EXTENSION));
				}else{
					$address_proof_image_name="";
				}
				
				$last_id_verify_data=$bdd->lastId("INSERT INTO `customer_verification_data` (`customer_id`, `id_proof_type`, `address_proof_type`, `id_proof_value`, `address_proof_value`, `id_proof_data`, `address_proof_data`,`date_time`) VALUES ('$last_id', '$id_proof_name','$address_proof_name', '".$id_proof_value."','".$address_proof_value."', '".$_POST['response_id_proof_data']."','".$_POST['response_address_proof_data']."','$date_time')");
				
				if($_FILES["id_proof_image"]["tmp_name"]!=null && $_FILES["id_proof_image"]["tmp_name"]!=""){
					$last_id_proof=$bdd->lastId("INSERT INTO `customer_menu` (`customer_id`, `menu_id`, `menu_option_id`, `filename`, `added_by`) VALUES ('$last_id', '22',(SELECT menu_option_id FROM menu_option WHERE name='$id_proof_name' AND menu_id='22'), '$id_proof_image_name', '".$_SESSION['admin_id']."')");
					move_uploaded_file($_FILES["id_proof_image"]["tmp_name"], 'uploads/'.$year.'/'.$month.'/'.$customer_name.'-'.$_POST['contact_no'].'-'.$temp_chs_no.'/'. $id_proof_image_name);
				}
				
				if($_FILES["address_proof_image"]["tmp_name"]!=null && $_FILES["address_proof_image"]["tmp_name"]!=""){
					$last_address_proof=$bdd->lastId("INSERT INTO `customer_menu` (`customer_id`, `menu_id`, `menu_option_id`, `filename`, `added_by`) VALUES ('$last_id', '23',(SELECT menu_option_id FROM menu_option WHERE name='$address_proof_name' AND menu_id='23'), '$address_proof_image_name', '".$_SESSION['admin_id']."')");
					move_uploaded_file($_FILES["address_proof_image"]["tmp_name"], 'uploads/'.$year.'/'.$month.'/'.$customer_name.'-'.$_POST['contact_no'].'-'.$temp_chs_no.'/'. $address_proof_image_name);
				}
				
				echo "<script>alert('Customer added')</script>";
			}else{
				echo "<script>alert('Something went wrong. Try again')</script>";
			}
		}
	}
}
$bdd->disconnect();
?>
<script>
function validateForm(){
	var valid_id_proof_value=$("#document_id_proof_valid").val()
	var valid_address_proof_value=$("#document_address_proof_valid").val()
	if(valid_id_proof_value=="" || valid_address_proof_value==""){
		alert('Id proof or address proof is not valid')
		return false
	}else{
		return true
	}
}
function set_id_proof_value(value){
	const menu_option = []
	$("#document_id_proof").val(value)
	<?php
	foreach($menu_option_id_rows as $row){
	?>
		menu_option.push(<?php echo "'".$row['name']."'";?>);
		
	<?php	
	}
	?>
	for (let i = 0; i < menu_option.length; i++) {
		if(value==menu_option[i]){
			document.getElementById("document_"+value).style.display = 'block';
			document.getElementById ("document_"+value).placeholder=value;
			document.getElementById ("document_"+value).setAttribute('required', '');
		}
	}
	for (let i = 0; i < menu_option.length; i++) {
		if(value!=menu_option[i]){
			document.getElementById("document_"+menu_option[i]).style.display = 'none';
			document.getElementById("document_"+menu_option[i]).removeAttribute('required');
		}
	}
	if(value=="ElectionCard"){
		document.getElementById("document_id_proof_pan_state_name").style.display = 'block';
		document.getElementById ("document_id_proof_pan_state_name").setAttribute('required', '');
	}else{
		document.getElementById("document_id_proof_pan_state_name").removeAttribute('required');
		document.getElementById("document_id_proof_pan_state_name").style.display = 'none';
	}
	if(value=="AadharCard" || value=="ElectionCard" || value=="PanCard"){
		$("#document_id_proof_valid").val("")
		document.getElementById("document_verify_button").style.display = 'block';
	}else{
		$("#document_id_proof_valid").val("Valid")
		document.getElementById("document_verify_button").style.display = 'none';
	}
	$('#document_verify_button').data('doc_type',value);
}
$("#document_verify_button").click(function(){
	var doc_type = $('#document_verify_button').data('doc_type');
	var voter_state="";
	var doc_value = $("#document_"+doc_type).val()
	if(doc_value==""){
		alert("Enter document name or number")
		return;
	}
	
	if(doc_type=="ElectionCard"){
		voter_state=$("#document_id_proof_pan_state_name").val()
		if(voter_state==""){
			alert("Enter state name")
			return;
		}
	}
	
	$("#popup_message_modal").modal("show");
	dataString='action=verificationApi&doc_type='+doc_type+'&doc_value='+doc_value+"&voter_state="+voter_state;
	$.ajax({
		type:'POST',
		async: false,
		url:'ajax_data.php',
		data:dataString,
		success:function(data){
			$("#popup_message_modal").modal("hide");
			value=JSON.parse(data);
			if(doc_type=="AadharCard"){
				//if(value.data.status=="generate_otp_success"){
				//if(value=="data"){
				if(value.hasOwnProperty("error")){
					$('#response_id_proof_document_div').html(value.error.message)
					document.getElementById('response_id_proof_document_div').style.display = 'block'
				}else{
					$('#response_id_proof_document_div').html(value.message)
					document.getElementById('response_id_proof_document_div').style.display = 'block'
					document.getElementById('ref_id').value = value.data.requestId
					document.getElementById('otp_div').style.display = 'block'
				}
			}else if(doc_type=="ElectionCard"){
				document.getElementById('response_id_proof_data').innerHTML = data
				if(value.hasOwnProperty("error")){
					$('#response_id_proof_document_div').html(value.error.message)
					document.getElementById('response_id_proof_document_div').style.display = 'block'
				}else{
					$("#customer_name").val(value.result.name)
					$("#document_id_proof_valid").val("Valid")
					var response_data=""
					response_data+="<br><b>Epic no : </b> <i>"+value.essentials.epicNumber+"</i>"
					response_data+="<br><b>Name : </b> <i>"+value.result.name+"</i>"
					response_data+="<br><b>Birth Date : </b> <i>"+value.result.dob+"</i>"
					response_data+="<br><b>Gender : </b> <i>"+value.result.gender+"</i>"
					response_data+="<br><b>District : </b> <i>"+value.result.district+"</i>"
					document.getElementById('response_id_proof_document_div').innerHTML = response_data
					document.getElementById('response_id_proof_document_div').style.display = 'block'
				}
			}else if(doc_type=="PanCard"){
				document.getElementById('response_id_proof_data').innerHTML = data
				if(value.hasOwnProperty("error")){
					$('#response_id_proof_document_div').html(value.error.message)
					document.getElementById('response_id_proof_document_div').style.display = 'block'
				}else{
					$("#document_id_proof_valid").val("Valid")
					//$('#response_id_proof_document_div').html(value.message)
					var response_data=""
					response_data+="<br><b>PAN No : </b> <i>"+value.essentials.number+"</i>"
					response_data+="<br><b>Name : </b> <i>"+value.result.name+"</i>"
					response_data+="<br><b>Pan Status : </b> <i>"+value.result.panStatus+"</i>"
					document.getElementById('response_id_proof_document_div').innerHTML = response_data
					document.getElementById('response_id_proof_document_div').style.display = 'block'
				}
			}
		}
	});
});
$("#verify_aadhaar_otp").click(function(){
	var ref_id = $("#ref_id").val()
	var aadhaar_otp = $("#aadhaar_otp").val()
	if(aadhaar_otp==""){
		alert("Enter OTP")
		return;
	}
	$("#popup_message_modal").modal("show");
	dataString='action=verifyAadhaarOtp&ref_id='+ref_id+'&aadhaar_otp='+aadhaar_otp;
	$.ajax({
		type:'POST',
		async: false,
		url:'ajax_data.php',
		data:dataString,
		success:function(data){
			document.getElementById('response_id_proof_data').innerHTML = data
			$("#popup_message_modal").modal("hide");
			//alert(data)
			value=JSON.parse(data);
			if(value.data.status=="success_aadhaar"){
				$("#document_id_proof_valid").val("Valid")
				var response_data="";
				response_data+="<br><b>Aadhar No : </b> <i>"+value.data.aadhaar_number+"</i>";
				response_data+="<br><b>Name : </b> <i>"+value.data.full_name+"</i>";
				response_data+="<br><b>Birth Date : </b> <i>"+value.data.dob+"</i>";
				response_data+="<br><b>Gender : </b> <i>"+value.data.gender+"</i>";
				response_data+="<br><b>Address : </b> <i>"+value.data.address.house+","+value.data.address.street+", "+value.data.address.loc+", "+value.data.address.po+","+value.data.address.dist+", "+value.data.address.state+","+value.data.address.country+"</i>";
				document.getElementById('response_id_proof_document_div').innerHTML = response_data
				document.getElementById('response_id_proof_aadhar_photo').src = "data:image/png;base64, "+value.data.profile_image;
				document.getElementById('response_id_proof_document_div').style.display = 'block';
				document.getElementById('response_id_proof_aadhar_photo').style.display = 'block';
				document.getElementById('otp_div').style.display = 'none'
			}else{
				$('#response_id_proof_document_div').html(value.message)
				document.getElementById('response_id_proof_document_div').style.display = 'block'
			}
		}
	});
});
function set_address_proof_value(value){
	const menu_option = []
	$("#document_address_proof").val(value)
	<?php
	foreach($menu_option_address_rows as $row){
	?>
		menu_option.push(<?php echo "'".$row['name']."'";?>);
		
	<?php	
	}
	?>
	for (let i = 0; i < menu_option.length; i++) {
		if(value==menu_option[i]){
			document.getElementById("address_proof_document_"+value).style.display = 'block';
			document.getElementById ("address_proof_document_"+value).placeholder=value;
			document.getElementById ("address_proof_document_"+value).setAttribute('required', '');
		}
	}
	for (let i = 0; i < menu_option.length; i++) {
		if(value!=menu_option[i]){
			document.getElementById("address_proof_document_"+menu_option[i]).style.display = 'none';
			document.getElementById("address_proof_document_"+menu_option[i]).removeAttribute('required');
		}
	}
	
	if(value=="ElectionCard"){
		document.getElementById("document_address_proof_pan_state_name").style.display = 'block';
		document.getElementById ("document_address_proof_pan_state_name").setAttribute('required', '');
	}else{
		document.getElementById("document_address_proof_pan_state_name").removeAttribute('required');
		document.getElementById("document_address_proof_pan_state_name").style.display = 'none';
	}
	
	if(value=="AadharCard" || value=="ElectionCard"){
		$("#document_address_proof_valid").val("")
		document.getElementById("address_proof_document_verify_button").style.display = 'block';
	}else{
		$("#document_address_proof_valid").val("Valid")
		document.getElementById("address_proof_document_verify_button").style.display = 'none';
	}
	$('#address_proof_document_verify_button').data('doc_type',value);
}
$("#address_proof_document_verify_button").click(function(){
	var voter_state="";
	var doc_type = $('#address_proof_document_verify_button').data('doc_type');
	var doc_value = $("#address_proof_document_"+doc_type).val()
	if(doc_value==""){
		alert("Enter document name or number")
		return;
	}
	if(doc_type=="ElectionCard"){
		voter_state=$("#document_address_proof_pan_state_name").val()
		if(voter_state==""){
			alert("Enter state name")
			return;
		}
	}
	$("#popup_message_modal").modal("show");
	dataString='action=verificationApi&doc_type='+doc_type+'&doc_value='+doc_value+"&voter_state="+voter_state;
	$.ajax({
		type:'POST',
		async: false,
		url:'ajax_data.php',
		data:dataString,
		success:function(data){
			$("#popup_message_modal").modal("hide");
			//alert(data)
			value=JSON.parse(data);
			if(doc_type=="AadharCard"){
				if(value.status=="success"){
					$('#response_address_proof_document_div').html(value.response.message)
					document.getElementById('response_address_proof_document_div').style.display = 'block'
					document.getElementById('address_proof_ref_id').value = value.response.ref_id
					document.getElementById('aadhaar_otp_div').style.display = 'block'
				}else{
					$('#response_address_proof_document_div').html(value.response)
					document.getElementById('response_address_proof_document_div').style.display = 'block'
				}
			}else if(doc_type=="ElectionCard"){
				document.getElementById('response_address_proof_data').innerHTML = data
				/*if(value.status=="success"){
					$("#document_address_proof_valid").val("Valid")
					var response_data=""
					response_data+="<br><b>Epic no : </b> <i>"+value.response.epic_no+"</i>"
					response_data+="<br><b>Name : </b> <i>"+value.response.holder_name+"</i>"
					response_data+="<br><b>Birth Date : </b> <i>"+value.response.dob+"</i>"
					response_data+="<br><b>Age : </b> <i>"+value.response.age+"</i>"
					response_data+="<br><b>Gender : </b> <i>"+value.response.gender+"</i>"
					response_data+="<br><b>Area : </b> <i>"+value.response.area+"</i>"
					document.getElementById('response_address_proof_document_div').innerHTML = response_data
					document.getElementById('response_address_proof_document_div').style.display = 'block'
				}else{
					$('#response_address_proof_document_div').html(value.response)
					document.getElementById('response_address_proof_document_div').style.display = 'block'
				}*/
				if(value.hasOwnProperty("error")){
					$('#response_address_proof_document_div').html(value.error.message)
					document.getElementById('response_address_proof_document_div').style.display = 'block'
				}else{
					$("#customer_name").val(value.result.name)
					$("#document_address_proof_valid").val("Valid")
					var response_data=""
					response_data+="<br><b>Epic no : </b> <i>"+value.essentials.epicNumber+"</i>"
					response_data+="<br><b>Name : </b> <i>"+value.result.name+"</i>"
					response_data+="<br><b>Birth Date : </b> <i>"+value.result.dob+"</i>"
					response_data+="<br><b>Gender : </b> <i>"+value.result.gender+"</i>"
					response_data+="<br><b>District : </b> <i>"+value.result.district+"</i>"
					document.getElementById('response_address_proof_document_div').innerHTML = response_data
					document.getElementById('response_address_proof_document_div').style.display = 'block'
				}
			}
		}
	});
});
$("#verify_address_aadhaar_otp").click(function(){
	var ref_id = $("#address_proof_ref_id").val()
	var aadhaar_otp = $("#address_aadhaar_otp").val()
	if(aadhaar_otp==""){
		alert("Enter OTP")
		return;
	}
	$("#popup_message_modal").modal("show");
	dataString='action=verifyAadhaarOtp&ref_id='+ref_id+'&aadhaar_otp='+aadhaar_otp;
	$.ajax({
		type:'POST',
		async: false,
		url:'ajax_data.php',
		data:dataString,
		success:function(data){
			document.getElementById('response_address_proof_data').innerHTML = data
			$("#popup_message_modal").modal("hide");
			//alert(data)
			value=JSON.parse(data);
			if(value.status=="success"){
				$("#document_address_proof_valid").val("Valid")
				var response_data=""
				response_data+="<br><b>Aadhar No : </b> <i>"+value.response.aadhar+"</i>";
				response_data+="<br><b>Name : </b> <i>"+value.response.name+"</i>";
				response_data+="<br><b>Birth Date : </b> <i>"+value.response.dob+"</i>";
				response_data+="<br><b>Gender : </b> <i>"+value.response.gender+"</i>";
				response_data+="<br><b>Address : </b> <i>"+value.response.address.house+","+value.response.address.street+", "+value.response.address.po+", "+value.response.address.dist+", "+value.response.address.state+","+value.response.address.country+"</i>";
				document.getElementById('response_address_proof_document_div').innerHTML = response_data
				document.getElementById('response_address_proof_document_div').style.display = 'block';
				document.getElementById('aadhaar_otp_div').style.display = 'none'
			}else{
				$('#response_address_proof_document_div').html(value.response)
				document.getElementById('response_address_proof_document_div').style.display = 'block'
			}
		}
	});
});
</script>