<script src="assets/js/king-table.js"></script>
<div class="content">
				<div class="main-content">
					<!-- DATA EXPORT -->
					<div class="widget widget-table" style="margin-bottom: 0px;">
						<div class="widget-header">
							<h3><i class="fa fa-user"></i> <?php echo e(__('matrimonial.marriage_certificate')); ?></h3>
						</div>						
						<div class="widget-content">
<form id="frmmain" name="frmmain" data-parsley-validate novalidate>
<input type="hidden" name="_token" value="<?php echo e(csrf_token()); ?>">						
<input type="hidden" name="mrg_id" id="mrg_id" value="<?php echo e($data['mrg_id']); ?>">
<input type="hidden" name="cst_id" id="cst_id" value="0">

<div class="alert  alert-info " >
    <ul><li class="fa fa-cog  fa-1x fa-fw"></li><?php echo e(__('user.enter_details')); ?>..</ul>
</div>						
<div class="alert alert-success print-success-msg" style="display:none">
    <ul></ul>
</div>	
<div class="alert alert-danger print-error-msg" style="display:none">
    <ul></ul>
</div>

<div class="col-md-6">
							<!-- ADVANCED VALIDATION -->
								<div class="widget-content">  
                        <div class="form-group">
                            <label for="text-input1"><?php echo e(__('matrimonial.mrg_no')); ?>*</label> <small class="text-danger" id="errmrg_no"></small>
                            <input type="text" name="mrg_no" id="mrg_no" class="form-control"  readonly>
                        </div>
                        <div class="form-group">
                            <label for="text-input1"><?php echo e(__('matrimonial.mrg_printdate')); ?>*</label> <small class="text-danger" id="errmrg_certificatedate"></small>
                            <input type="date" name="mrg_certificatedate" id="mrg_certificatedate" class="form-control">
                        </div>
                        <div class="form-group">
                            <label for="text-input1"><?php echo e(__('matrimonial.mrg_name')); ?>*</label> <small class="text-danger" id="errmrg_name"></small>
                            <input type="text" name="mrg_name" id="mrg_name" class="form-control" >
                        </div>
						<div class="form-group">
                            <label for="text-input1"><?php echo e(__('matrimonial.mrg_father')); ?>*</label> <small class="text-danger" id="errmrg_father"></small>
                            <input type="text" name="mrg_father" id="mrg_father" class="form-control" >
                        </div>
                        <div class="form-group">
                         <label for="text-input1"><?php echo e(__('matrimonial.mrg_dob')); ?>*</label><small class="text-danger" id="errmrg_dob"></small>
							<input type="date" name="mrg_dob" id="mrg_dob" class="form-control"  >
                        </div>
                        <div class="form-group">
							<label for="text-input1"><?php echo e(__('matrimonial.mrg_marriagedate')); ?>*</label>
                            <small class="text-danger" id="errmrg_marriagedate"></small>
							<input type="date" name="mrg_marriagedate" id="mrg_marriagedate" class="form-control" >
                        </div>
                        <div class="form-group">
							<label for="text-input1"><?php echo e(__('matrimonial.mrg_marriagetime')); ?>*</label>
                            <small class="text-danger" id="errmrg_marriagetime"></small>
							<input type="time" name="mrg_marriagetime" id="mrg_marriagetime" class="form-control" >
                        </div>
								</div>
							<!-- END ADVANCED VALIDATION -->
</div>
<div class="col-md-6">
							<!-- ADVANCED VALIDATION -->
								<div class="widget-content">
                        <div class="form-group">
                            <label for="text-input1"><?php echo e(__('matrimonial.mrg_membercode')); ?>*</label>
                            <small class="text-danger" id="errmrg_membercode"></small>
                            <input type="text" name="mrg_membercode" id="mrg_membercode" class="form-control" readonly >
                        </div>
                        <div class="form-group">
                            <label for="text-input1"><?php echo e(__('matrimonial.mrg_address')); ?></label>
                            <small class="text-danger" id="errmrg_address"></small>
                            <textarea name="mrg_address" id="mrg_address" class="form-control" rows="5" cols="30"></textarea>
                        </div>
                        <div class="form-group">
                            <label for="text-input1"><?php echo e(__('matrimonial.mrg_location')); ?></label>
                            <small class="text-danger" id="errmrg_location"></small>
							<textarea name="mrg_location" id="mrg_location" class="form-control" rows="5" cols="30"></textarea>
                        </div>
                        <div class="form-group">
							<label for="text-input1"><?php echo e(__('matrimonial.mrg_cost')); ?>*</label>
                            <small class="text-danger" id="errmrg_cost"></small>
							<input type="text" name="mrg_cost" id="mrg_cost" class="form-control" >
                        </div>
								</div>
							<!-- END ADVANCED VALIDATION -->
</div>                   
                    </form>

						</div>
					

					</div>
<div class="widget">
	<div class="widget-header">
		<div class="col-md-4">
		<?php if(isset($data['cst_id'])): ?>
		<button type="submit" id="btndelete" name="btndelete" class="btn btn-danger  delete_submit">Delete Profile</button>
		<?php endif; ?>
		</div>
		<div class="col-md-4">	
			<center>
				<button type="submit" id="submitmatri" name="submitmatri" class="btn btn-primary submitmatri">Update Marriage Certificate</button>
			</center>
		</div>
		<div class="col-md-4 text-right">
		</div>
	</div>
</div>
				</div>

			</div>
			<!-- /main -->
		


<script type="application/javascript">
	i = 0;
	   $("#submitmatri").click(function()
	   {
				$(".alert-info").find("ul").html('<li class="fa fa-cog fa-spin fa-1x fa-fw"></li>Inserting record...');		
				var _token = $("input[name='_token']").val();				
				var mrg_id = $("#mrg_id").val();
				var cst_id = $("#cst_id").val();
				var mrg_no = $("#mrg_no").val();
				var mrg_certificatedate =  $('#mrg_certificatedate').val();
				var mrg_name =  $('#mrg_name').val();
				var mrg_father =  $('#mrg_father').val();
				var mrg_dob =  $('#mrg_dob').val();
				var mrg_marriagedate =  $('#mrg_marriagedate').val();
				var mrg_marriagetime =  $('#mrg_marriagetime').val();
				var mrg_membercode =  $('#mrg_membercode').val();
				var mrg_address =  $('#mrg_address').val();
				var mrg_location =  $('#mrg_location').val();
				var mrg_cost = $('#mrg_cost').val();
				document.getElementById("errmrg_no").innerHTML = "";
				document.getElementById("errmrg_certificatedate").innerHTML = "";
				document.getElementById("errmrg_name").innerHTML = "";
				document.getElementById("errmrg_father").innerHTML = "";
				document.getElementById("errmrg_dob").innerHTML = "";
				document.getElementById("errmrg_marriagedate").innerHTML = "";
				document.getElementById("errmrg_marriagetime").innerHTML = "";
				document.getElementById("errmrg_membercode").innerHTML = "";
				document.getElementById("errmrg_location").innerHTML = "";
				document.getElementById("errmrg_cost").innerHTML = "";
				document.getElementById("errmrg_address").innerHTML = "";
			var errcondition =0;		
		   if(mrg_no == "")
		   {
				document.getElementById("errmrg_no").innerHTML = "Number should not be empty...";
				$(".alert-info").find("ul").html('<li class="fa fa-cog fa-1x fa-fw"></li>Kindly check the error...');
				errcondition = 1;
		   }
		   if(mrg_certificatedate == "")
		   {
				document.getElementById("errmrg_certificatedate").innerHTML = "This field should not be empty...";
				$(".alert-info").find("ul").html('<li class="fa fa-cog fa-1x fa-fw"></li>Kindly check the error...');
				errcondition = 1;
		   }
		   if(mrg_name == "")
		   {
				document.getElementById("errmrg_name").innerHTML = "This field should not be empty...";
				$(".alert-info").find("ul").html('<li class="fa fa-cog fa-1x fa-fw"></li>Kindly check the error...');
				errcondition = 1;
		   }
		   if(mrg_father == "")
		   {
				document.getElementById("errmrg_father").innerHTML = "This field should not be empty...";
				$(".alert-info").find("ul").html('<li class="fa fa-cog fa-1x fa-fw"></li>Kindly check the error...');
				errcondition = 1;
		   }
		   if(mrg_dob == "")
		   {
				document.getElementById("errmrg_dob").innerHTML = "This field should not be empty...";
				$(".alert-info").find("ul").html('<li class="fa fa-cog fa-1x fa-fw"></li>Kindly check the error...');
				errcondition = 1;
		   }
		   if(mrg_marriagedate == "")
		   {
				document.getElementById("errmrg_marriagedate").innerHTML = "This field should not be empty...";
				$(".alert-info").find("ul").html('<li class="fa fa-cog fa-1x fa-fw"></li>Kindly check the error...');
				errcondition = 1;
		   }
		   if(mrg_marriagetime == "")
		   {
				document.getElementById("errmrg_marriagetime").innerHTML = "This field should not be empty...";
				$(".alert-info").find("ul").html('<li class="fa fa-cog fa-1x fa-fw"></li>Kindly check the error...');
				errcondition = 1;
		   }
		   if(mrg_membercode == "")
		   {
				document.getElementById("errmrg_membercode").innerHTML = "This field should not be empty...";
				$(".alert-info").find("ul").html('<li class="fa fa-cog fa-1x fa-fw"></li>Kindly check the error...');
				errcondition = 1;
		   }
		   if(mrg_address == "")
		   {
				document.getElementById("errmrg_address").innerHTML = "This field should not be empty...";
				$(".alert-info").find("ul").html('<li class="fa fa-cog fa-1x fa-fw"></li>Kindly check the error...');
				errcondition = 1;
		   }
		   if(mrg_location == "")
		   {
				document.getElementById("errmrg_location").innerHTML = "This field should not be empty...";
				$(".alert-info").find("ul").html('<li class="fa fa-cog fa-1x fa-fw"></li>Kindly check the error...');
				errcondition = 1;
		   }
		   if(mrg_cost == "")
		   {
				document.getElementById("errmrg_cost").innerHTML = "This field should not be empty...";
				$(".alert-info").find("ul").html('<li class="fa fa-cog fa-1x fa-fw"></li>Kindly check the error...');
				errcondition = 1;
		   }
			if(errcondition == 0)
		   {
		   
				if(i == 0)
				{
					i++;
					$.ajax({
					url: "/MatriCertificate",
					type:'POST',
					data: {_token:_token,mrg_id:mrg_id,mrg_membercode:mrg_membercode,cst_id:cst_id, mrg_no:mrg_no, mrg_certificatedate:mrg_certificatedate, mrg_name:mrg_name, mrg_dob:mrg_dob, mrg_father:mrg_father, mrg_address:mrg_address, mrg_location:mrg_location, mrg_marriagedate:mrg_marriagedate, mrg_marriagetime:mrg_marriagetime, mrg_cost:mrg_cost},					
					success: function(data) {						
							if(data.status == 1)
							{
								alert("Marriage Certificate record updated successfully..");
								printSuccessMsg(data.message);
								window.open('printmarriagecertificate?id=' + data.insertid  ,'_blank');
								$('#sideMenu').load('matrimonialcertificate');
							}
							else
							{
								printErrorMsg(data.message)
							}
						}
					});
				}
		   }
			return false;
	   });

	function printErrorMsg (msg) {				
		$(".alert-info").css('display','none');
		$(".print-success-msg").css('display','none');
		$(".print-error-msg").find("ul").html('');
		$(".print-error-msg").css('display','block');
		$(".print-error-msg").find("ul").append('<li class="fa fa-times-circle fa-1x fa-fw"></li>'+msg);
	}
			
	function printSuccessMsg (msg) {
		$(".alert-info").css('display','none');
		$(".print-error-msg").css('display','none');
		$(".print-success-msg").find("ul").html('');
		$(".print-success-msg").css('display','block');
		$(".print-success-msg").find("ul").append('<li class="fa fa-check  fa-1x fa-fw"></li>'+msg);
	}
</script>
<script>
	var mrg_id = parseInt($('#mrg_id').val());
	if(mrg_id != 0)
	{
		loadeditcstrec();
	}
	
	function loadeditcstrec()
	{
			var mrg_id = $('#mrg_id').val();
			$.ajax({
			type: "GET",
			url:"/loadeditingmrgapp",
			dataType: "json",
			data: {
				'_token': $('input[name=_token]').val(),
				'mrg_id': mrg_id
			},
			success: function (data) {
				$('#cst_id').val(data['reclist'][0].cst_id);
				$('#mrg_no').val(data['reclist'][0].mrg_no);
				$('#mrg_certificatedate').val(data['reclist'][0].mrg_certificatedate);
				$('#mrg_name').val(data['reclist'][0].mrg_name);
				$('#mrg_father').val(data['reclist'][0].mrg_father);
				$('#mrg_dob').val(data['reclist'][0].mrg_dob);
				$('#mrg_marriagedate').val(data['reclist'][0].mrg_marriagedate);
				$('#mrg_marriagetime').val(data['reclist'][0].mrg_marriagetime);
				$('#mrg_membercode').val(data['reclist'][0].mrg_membercode);
				$('#mrg_address').val(data['reclist'][0].mrg_address);
				$('#mrg_location').val(data['reclist'][0].mrg_location);
				$('#mrg_cost').val(data['reclist'][0].mrg_cost);
			}
		});
	}
</script>