<!--akmal 20160809 -->
<script>
	function deleteId(id)
	{
	var idd = id;
	console.log(idd);
	var textDel = document.getElementById("delete"+id+"").getAttribute("data-delete"+ id+"");

	if (confirm("Anda akan membuang butiran "+ textDel  +". Klik OK untuk teruskan.") == true)
	{
	$.ajax({
	method: 'POST',
	url: '<?php echo base_url().'setup/delete';?>',
	data: {
	a : id
	},
	success: function(result) {
	$('#rowTable1').load('<?php echo current_url().' #rowTable'?>');
	}
	}); 
	}
	}

	function addId(reviewID)
	{
	var idAddModal = reviewID;
	console.log(idAddModal);//debug data reviewID
	var butiran = $("#butiran").val();

	if(confirm("Anda akan menambah butiran "+butiran+". Klik ok untuk teruskan") == true)
	{
	$.ajax({
	method: 'POST',
	url: '<?php echo base_url().'setup/insert';?>',
	data: {
	b : reviewID,
	c : butiran
	},
	success: function(result) {
	$('#rowTable1').load('<?php echo current_url().' #rowTable'?>');
	}
	});
	}
	}

	function editId(a)
	{
	var text = a.getAttribute('data-idItem');
	var id = a.getAttribute('data-id');
	document.getElementById("butiran2").value = text;
	document.getElementById("idButiran").value = id;
	console.log(text);
	console.log(id);
	}

	function editSubmit(reviewID)
	{

	var idAddModal = reviewID;
	console.log(idAddModal);
	var butiran = $("#butiran2").val();
	var idTarget = document.getElementById("idButiran").value;
	console.log(idTarget);
	console.log("idAddModal: "+ idAddModal+"butiran: "+butiran+ "idTarget: "+idTarget);

	if(confirm("Klik Ok jika anda bersetuju untuk mengubah butiran ini.")== true){
	$.ajax({
	method: 'POST',
	url: '<?php echo base_url("/setup/updateRow/");?>',
	data: {
	a : idTarget,
	b : reviewID,
	c : butiran
	},
	success: function(result) {
	$('#rowTable1').load('<?php echo current_url().' #rowTable'?>');
	}
	});
	}else{
	console.log('batal');
	}
	}
</script>

<div id="result">
</div>
<div id="resultAddId">
</div>

<div class="modal fade" id="modal-details" role="dialog" data-backdrop="static" data-keyboard="false">
	<div class="modal-dialog modal-lg">
		<div class="modal-content">
			<div class="modal-header bg-white text-center" >
				<button type="button" class="close" data-dismiss="modal">&times;</button>
				<h4 class="modal-title" id="modal-details-label"></h3>
			</div>
			<div class="modal-body">
				<ul class="nav nav-tabs">
					<li class="active" id="personaltab">
						<a href="#tab_1" data-toggle="tab" aria-expanded="true"><?php echo $this->lang->line('personal');?></a>
					</li>
					<li id="companytab">
						<a href="#tab_2" data-toggle="tab" aria-expanded="true"><?php echo $this->lang->line('company');?></a>
					</li>
				</ul>
				<div class="tab-content">
					<div id="tab_1" class="tab-pane active">
					</div>
				</div>
			</div>
			<div class="modal-footer">
				<a type="button" class="btn btn-danger btn-sm" data-dismiss="modal"><?php echo $this->lang->line('close');?></a>
				<a id="modalAddBtn" href="javascript:newCustomer();" type="button" class="btn bg-olive btn-sm"><span class="glyphicon glyphicon-plus"></span>
					<?php echo $this->lang->line('add');?>
				</a>
				<a id="modalEditBtn" href="" type="button" class="btn bg-olive btn-sm"><span class="glyphicon glyphicon-plus"></span>
					<?php echo $this->lang->line('update');?>
				</a>
			</div>
		</div>
	</div>
</div>

<div class="content-wrapper">
	<!-- Content Header (Page header) -->
	<section class="content-header">
		<h1>Semakan Kelayakan</h1>
		<?php echo $semak; ?>
		<ol class="breadcrumb">
			<li><a href="#"><i class="fa fa-dashboard"></i> Semakan Kelayakan</a></li>
			<li class="active"></li>
		</ol>
	</section>

	<!-- Main content -->
	<section class="content">


		<div class="box box-danger">
			<div class="box-header with-border">
				<h3 class="box-title">Senarai Semak</h3>
				<?php
				if(current_url() == base_url('/setup/subreview/'))
					echo "";
				else
					echo '<button type="button" class="btn btn-sm bg-red pull-right glyphicon glyphicon-plus" data-toggle="modal" data-target="#addModal" style="margin-right:30px;"> Tambah</button>';
				?>
				<div class="box-tools pull-right">
					<button class="btn pull-right btn-box-tool" data-widget="collapse"><i class="fa fa-minus"></i></button>
				</div>
			</div>	

			<div class="box-body">
				<div class="row">
					<div class="col-md-12">
						<div class="row">

							<div class="col-sm-12">
								<div class="dropdown col-sm-12" style="width:100%;">
									<button class="btn btn-default dropdown-toggle col-sm-12" type="button" id="dropdownMenu1" data-toggle="dropdown" aria-haspopup="true" aria-expanded="true">
										<?php  echo $semak;?>
										<span class="caret"/>
									</button>
									<ul class="dropdown-menu" aria-labelledby="dropdownMenu1" style="white-space:normal;overflow:hidden;">
										<?php
									if ($rsSemak) foreach ($rsSemak as $rows){
										echo '<li style="overflow:hidden;"><a href="'.base_url('/setup/subreview/').'/'.$rows->ID.'">'.$rows->text.'</a></li>';
									}
										?>
									</ul>
								</div>
							</div>
						</div>
						<br>
						<form class="form-horizontal">
							<input type="hidden" name="ID" id="companyID" value="1" /> <!-- TODO : PUT ACTUAL COMPANY ID HERE -->

							<table id="datatable_list" class="table table-bordered table-striped datatables">
								<thead>
									<tr>
										<th class="text-center col-sm-1">Bil</th>
										<th class="text-center col-sm-6">Butiran</th>
										<th class="text-center col-sm-1">Tindakan</th>
									</tr>
								</thead>

								<?php 
									echo '<tbody id="rowTable1">';
									$bil = 1;
									if($detailSub) foreach ($detailSub as $row) {
											if(base_url('/setup/subreview/').'/'.$row->reviewID == current_url()){
											$id = $row->reviewID;
											$idItem = $row->ID;
									
										echo '<tr id="rowTable"><td class="text-center">'.$bil.'</td>';
										echo '<td class="text-left" >'.$row->text.'</td>';
										echo '<td><center>
										<a data-idItem="'.$row->text.'" data-id="'.$idItem.'" title="edit" class="btn bg-blue btn-sm" data-toggle="modal" data-target="#editModal" onclick="editId(this)" data-toggle="tooltip" value="'.$idItem.'"> <span class="glyphicon glyphicon-pencil"/></a>
										<a id="delete'.$idItem.'" data-delete'.$idItem.'="'.$row->text.' "title="delete" class="btn bg-red btn-sm" onclick="deleteId('.$idItem.')" data-toggle="tooltip"> <span class="fa fa-times"/></a></center></td></tr>';
										$bil ++;
										}}
										echo '</tbody>';
									?>

							</table>
						</form>
					</div><!-- /.col -->
				</div><!-- /.row -->
			</div><!-- /.box-body -->

			<!-- -------------------Start Tambah Semakan Kelayakan Modal ------------------------------->
			<div id="addModal" class="modal fade" role = "dialog" style="width:100%">
				<div class="modal-dialog">
					<!--modal content-->
					<div class="modal-content">
						<div class="modal-header">
							<button type="button" class="close" data-dismiss="modal">&times</button>
						</div>

						<center><h4 class=modal-title>Tambah Semakan Kelayakan</h4></center>
						<form name="formButiran">
							<!--<form name="formButiran" action="<?php //base_url('/setup/subreview/addId')?>" method="post">-->

							<div class="modal-body">
								<!--form-->
								<div class="form-group" value="<?php $id ?>">
										<label for="number">Semakan Untuk:</label><br>
											<input type="text"  class="form-control" value="<?php echo $semak;?>"  readonly />
												</div>
												<div class="form-group">
													<label for="text">Butiran:</label>
													<input type="text" class="form-control" id="butiran"/>
												</div>
											</form>
											<!--form-->

											<div class="modal-footer">
												<button type="button" class="btn btn-danger btn-sm pull-center" data-dismiss="modal">Batal</button>
												<button type="submit" class="btn bg-olive btn-sm pull-center glyphicon glyphicon-check" onclick="addId(<?php echo $this->uri->segment(3);?>)">Simpan</button>

												</div>
											</div></div></div></div>
								<!-- -------------------End Tambah Semakan Kelayakan Modal ------------------------------->
								<div class="box-footer">
								</div>
								<!-- -------------------Start Edit Semakan Kelayakan Modal ------------------------------->
								<div id="editModal" class="modal fade" role = "dialog" style="width:100%">
									<div class="modal-dialog">
										<!--modal content-->
										<div class="modal-content">
											<div class="modal-header">
												<button type="button" class="close" data-dismiss="modal">&times </button>
											</div>

											<center><h4 class=modal-title>Ubahsuai Butiran Kelayakan</h4></center>
											<form name="formButiran">
												<div class="modal-body">
													<!--form-->
													<!--debug--><div id="idButiran" style="display:none;" value=""></div><!--debug-->
													<div class="form-group">
														<label for="number">Semakan Untuk:</label><br>
															<input type="text"  class="form-control" value="<?php echo $semak;?>"  readonly />
																</div>
																<div class="form-group">
																	<label for="text">Butiran:</label>
																	<input type="text" class="form-control" id="butiran2" value=""/>
																</div>
															</form>
															<!--form-->

															<div class="modal-footer">
																<button type="button" class="btn btn-danger btn-sm pull-center" data-dismiss="modal">Batal</button>
																<button type="submit" class="btn bg-olive btn-sm pull-center glyphicon glyphicon-check" onclick="editSubmit(<?php echo $this->uri->segment(3);?>)"> Simpan</button>
																</div>
															</div></div></div></div>
												<!-- -------------------End Edit Semakan Kelayakan Modal ------------------------------->

												<div class="box-footer">
												</div>

											</div><!-- /.box box-danger-->


											<!-- auditors comment -->
											<!-- TODO : PUT THE ACTUAL COMPANY DETAILS HERE -->

											<!-- reports template -->
											<!-- TODO : PUT THE ACTUAL COMPANY DETAILS HERE -->


		

											</section>
										</div>





										<!-- MODAL SECTION -->
										<!-- GENERAL MODAL -->
										<div class="modal fade" id="modal-details" role="dialog">
											<div class="modal-dialog modal-lg">
												<div class="modal-content">
													<form id="selectCompForm" action="<?php echo base_url(); ?>miti/home/selectCompany" method="POST" role="form">
															<div class="modal-header" >
																<button type="button" class="close" data-dismiss="modal">&times;</button>
																<h3 class="modal-title" id="modal-details-label"></h3>
															</div>			
															<div class="modal-body">				
																<div class="form-group">
																	<h1><?php echo $this->lang->line('choosePrompt'); ?></h1>
																	<textarea id="attachmentDescription" name="description" class="form-control" cols="100" rows="3" style="resize:none;"></textarea>
																</div>
															</div>

															<div class="modal-footer">
																<a type="button" class="btn btn-danger btn-sm" data-dismiss="modal"><?php echo $this->lang->line('Close');?></a>
																<a type="button" class="btn bg-olive btn-sm">
																	<span class="glyphicon glyphicon-plus"></span>
																	<?php echo $this->lang->line('Save');?>
																</a>
															</div>
														</form>
													</div>
												</div>
											</div>
											