<?php
$first_var = "DESCRIBE `first_salaryslip`";
$firstfield_name = $db->run ( $first_var )->fetchAll ();
foreach ( $firstfield_name as $row1 ) {
	$secondarr [] = $row1 ['Field'];
}

$third_var = "DESCRIBE `second_salaryslip`";
$secondfield_name = $db->run ( $third_var )->fetchAll ();
foreach ( $secondfield_name as $row3 ) {
	$thirdarr [] = $row3 ['Field'];
}
?>


<style>
#loader-wrapper {
	position: fixed;
	top: 0;
	left: 0;
	width: 100%;
	height: 100%;
	/*z-index: 1000;*/
	opacity: 0.8;
	z-index: 1040;
	background-color: #000;
	display: none;
}

#spinner {
	display: none;
	position: relative;
	left: 50%;
	top: 50%;
	width: 150px;
	height: 150px;
	margin: -75px 0 0 -75px;
	border-radius: 50%;
	border: 3px solid transparent;
	border-top-color: #3498db;
	-webkit-animation: spin 2s linear infinite;
	/* Chrome, Opera 15+, Safari 5+ */
	animation: spin 2s linear infinite;
	/* Chrome, Firefox 16+, IE 10+, Opera */
}

#spinner:before {
	content: "";
	position: absolute;
	top: 5px;
	left: 5px;
	right: 5px;
	bottom: 5px;
	border-radius: 50%;
	border: 3px solid transparent;
	border-top-color: #e74c3c;
	-webkit-animation: spin 3s linear infinite;
	/* Chrome, Opera 15+, Safari 5+ */
	animation: spin 3s linear infinite;
	/* Chrome, Firefox 16+, IE 10+, Opera */
}

#spinner:after {
	content: "";
	position: absolute;
	top: 15px;
	left: 15px;
	right: 15px;
	bottom: 15px;
	border-radius: 50%;
	border: 3px solid transparent;
	border-top-color: #f9c922;
	-webkit-animation: spin 1.5s linear infinite;
	/* Chrome, Opera 15+, Safari 5+ */
	animation: spin 1.5s linear infinite;
	/* Chrome, Firefox 16+, IE 10+, Opera */
}

@
-webkit-keyframes spin { 0% {
	-webkit-transform: rotate(0deg); /* Chrome, Opera 15+, Safari 3.1+ */
	-ms-transform: rotate(0deg); /* IE 9 */
	transform: rotate(0deg); /* Firefox 16+, IE 10+, Opera */
}

100%
{
-webkit-transform
:
 
rotate
(360deg); /* Chrome, Opera 15+, Safari 3.1+ */

        
-ms-transform
:
 
rotate
(360deg); /* IE 9 */

        
transform
:
 
rotate
(360deg); /* Firefox 16+, IE 10+, Opera */

    
}
}
@
keyframes spin { 0% {
	-webkit-transform: rotate(0deg); /* Chrome, Opera 15+, Safari 3.1+ */
	-ms-transform: rotate(0deg); /* IE 9 */
	transform: rotate(0deg); /* Firefox 16+, IE 10+, Opera */
}
100%
{
-webkit-transform
:
 
rotate
(360deg); /* Chrome, Opera 15+, Safari 3.1+ */

        
-ms-transform
:
 
rotate
(360deg); /* IE 9 */

        
transform
:
 
rotate
(360deg); /* Firefox 16+, IE 10+, Opera */

    
}
}
</style>

<div id="loader-wrapper">
	<p style="color: #FFF;">Loading...</p>
	<div id="spinner"></div>
</div>
<script
	src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script>
	$(document).ready(function(){
		//window.setInterval(function(){
			  /// call your function here
			 //  //alert("bhangi");
			<?php
			foreach ( $secondarr as $row6 ) {
				if ($row6 != 'id') {
					$row6 = str_replace ( '.', '_', $row6 );
					$row6 = str_replace ( " ", '_', $row6 );
					
					$string = str_replace ( ' ', '-', $row6 ); // Replaces all spaces
					                                           // with hyphens.
					                                           // $row6 =
					                                           // preg_replace (
					                                           // '/[^A-Za-z0-9\-]/', '',
					                                           // $string );
					?> 
						$("<?php echo '.'.$row6;?>").click(function(){
							$("<?php echo '.'.$row6;?>").hide();
							$("<?php echo '#'.$row6;?>").show();
							});
						<?php
				}
			}
			?>	
			//}, 1000);
		
		//window.setInterval(function(){
			  /// call your function here
		<?php
		foreach ( $thirdarr as $row7 ) {
			if ($row7 != 'id') {
				$row7 = str_replace ( '.', '_', $row7 );
				$row7 = str_replace ( " ", '_', $row7 );
				?>
			$("<?php echo '.'.$row7;?>").click(function(){
				$("<?php echo '.'.$row7;?>").hide();
				$("<?php echo '#'.$row7;?>").show();
				});
			<?php
			
			}
		}
		
		?>	
		//}, 1000);
		});

	//$(document).ready(function(){
	var size_ini =Math.floor(Math.random() * (1000 + 1));
	function increase_n(size) 
	{
		////alert(size_ini);
		$("#spinner").show();
		$("#loader-wrapper").show();
	    var size_increase = size_ini++;
	      $.ajax({
			type:"POST",
			url:"<?php echo $link->link("salary_slip1", Admin);?>",
			data:'earning=AddField_'+size_increase,
			success:function(data){
				////alert(data);
				$("#spinner").hide();
				$("#loader-wrapper").hide();
				$(".firsttable").append(data);
				//window.location='';
				}
			});
			return false;
	}

	var size_ini =Math.floor(Math.random() * (1000 + 1));
	function increase_ded(size) 
	{
		$("#spinner").show();
		$("#loader-wrapper").show();
	    var size_increase = size_ini++;
	      $.ajax({
			type:"POST",
			url:"<?php echo $link->link("salary_slip1", Admin);?>",
			data:'deduction=AddField_'+size_increase,
			success:function(data){
				$("#spinner").hide();
				$("#loader-wrapper").hide();
				$(".secondtable").append(data);
				 }
			});
	      return false;
	}
	$(document).ready(function(){
		$('select').on('change', function(){
			$("#spinner").show();
			$("#loader-wrapper").show();
			var selectvalue= $(this).val();
			var nameclass= selectvalue.split('&&&');
			
			var sendone= nameclass[0];
			var sendsecond= nameclass[1];
			var tablename= nameclass[2];
			////alert(sendone);
			////alert(sendsecond);
			////alert(tablename);
			$.ajax({
				type:'POST',
				url:'<?php echo $link->link("salary_slip1", Admin);?>',
				data:'firstvalue='+sendone+'&secondvalue='+sendsecond+'&tablename='+tablename,
				success:function(data){
					$("#spinner").hide();
					$("#loader-wrapper").hide();
					$(".b___"+sendsecond).html(data);
					}
				});
			return false;
		});
		
	});
	
	$(document).ready(function(){
		$(function () {
			$(".alphabets").keydown(function (event) {
				 if ((event.keyCode >= 65 && event.keyCode <= 90) || (event.keyCode == 32) || (event.keyCode == 8)) {
					$("p").css('display','none');
					} else {
						$("p").css('display','block');
						$("p").insertAfter(this);
						
			        	event.preventDefault();
		         }
		    }); 
		 });
		$(".alphabets").on('paste', function() {
			$("p").css('display','block');
			$("p").insertAfter(this);
			event.preventDefault();
		});
		
		$(".alphabet").focusout(function(){
			$("#spinner").show();
			$("#loader-wrapper").show();
			var name= $(this).children("input").attr('name');
			var value= $(this).children("input").val();
			var value= value.replace(/_/g, ' ');
			
			var tablename= $(this).children("input").attr('alt');
			var boldclassname= $(this).children("b").attr('class');
			var divclass= $(".movea_"+name).removeClass().addClass("movea_"+value);
			
				$.ajax({
					type:'POST',
					url:'<?php echo $link->link("slipformat", Admin);?>',
					data:'dataname='+name+'&datavalue='+value+'&datatablename='+tablename,
					success:function(data){
						if(data== 2)
						{
							$(".alphabets"+name).attr('name',value);
							$(".alphabets"+name).removeClass().addClass("alphabets span11 alphabets"+value);
							$(".alphabets").hide();
							$("."+boldclassname).html(value);
							$("."+boldclassname).show();
							
							var sec= $(".alpha"+name).children("option:nth-child(2)").text();
							var third= $(".alpha"+name).children("option:nth-child(3)").text();
							
							if(sec == 'Fixed Amount')
							{
								$(".alpha"+name).children("option:nth-child(2)").val('value&&&'+value+'&&&first_salaryslip');
							}
							if(third == '% Of Basics')
							{
								$(".alpha"+name).children("option:nth-child(3)").val('percentage&&&'+value+'&&&first_salaryslip');
							}
							//alert(name);
							//alert(tablename+'_'+name);
							$(".alpha"+name).removeClass().addClass("alpha"+value);
							$("#id"+name).children("div").removeClass().addClass("b___"+value);
							$("#firsttable"+'_'+name).attr("id","firsttable"+'_'+value);
							$(".rowfluid"+name).attr("class", "row-fluid rowfluid"+value);
							$("#spinner").hide();
							$("#loader-wrapper").hide();
						}
						else
						{
							
						}
					}
				});
				return false;
			});

		$(".alphabet1").focusout(function(){
			$("#spinner").show();
			$("#loader-wrapper").show();
			var name= $(this).children("input").attr('name');
			
			////alert("name="+name);
			var value= $(this).children("input").val();
			var value= value.replace(/_/g, ' ');
			
			var tablename= $(this).children("input").attr('alt');
			////alert("tablename="+tablename);
			var boldclassname= $(this).children("b").attr('class');
			////alert("boldclassname="+boldclassname);
			var divclass= $(".movea_"+name).removeClass().addClass("movea_"+value);
			
				$.ajax({
					type:'POST',
					url:'<?php echo $link->link("slipformat", Admin);?>',
					data:'dataname='+name+'&datavalue='+value+'&datatablename='+tablename,
					success:function(data){
						////alert(data);
						if(data== 2)
						{
							////alert("name="+name);
							////alert("value="+value);
							$(".alphabets1"+name).attr('name',value);
							$(".alphabets1"+name).removeClass().addClass("alphabets1 span11 alphabets1"+value);
							$(".alphabets1").hide();
							$("."+boldclassname).html(value);
							$("."+boldclassname).show();
							
							var sec= $(".alpha"+name).children("option:nth-child(2)").text();
							var third= $(".alpha"+name).children("option:nth-child(3)").text();
							
							if(sec == 'Fixed Amount')
							{
								$(".alpha"+name).children("option:nth-child(2)").val('value&&&'+value+'&&&first_salaryslip');
							}
							if(third == '% Of Basics')
							{
								$(".alpha"+name).children("option:nth-child(3)").val('percentage&&&'+value+'&&&first_salaryslip');
							}
							////alert(name);
							$(".alpha"+name).removeClass().addClass("alpha"+value);
							$("#id"+name).children("div").removeClass().addClass("b___"+value);
							$("#spinner").hide();
							$("#loader-wrapper").hide();
						}
						else
						{
							
						}
					}
				});
				return false;
			});
	});
	$(document).ready(function(){
		$(".deletefirst").click(function(){
			$("#spinner").show();
			$("#loader-wrapper").show();
			var delete_column= $(this).attr('id');
			//alert(delete_column);
			$.ajax({
				type:'POST',
				url:'<?php echo $link->link("slipformat", Admin);?>',
				data:'columnname='+delete_column,
				success:function(data){
					////alert("data="+data);
					var value= delete_column.split("_");
					
					////alert(value[1]);
						if(data==1)
						{
							if(value[2])
							{
								$(".rowfluid"+value[1]+'_'+value[2]).hide();
							}
							else
							{
								$(".rowfluid"+value[1]).hide();
							}
						}
						$("#spinner").hide();
						$("#loader-wrapper").hide();
					}
			
				});
			return false;
			});
		/*$("#vipin_mainrs").click(function(){
			var value= $(this).html();
			alert(value);
			$.ajax({
				type:'POST',
				url:'<?php //echo $link->link("slipformat", Admin);?>',
				data:'incometax='+value,
				success:function(data){
					alert(data);
						if(data==1)
						{
							$("#vipin_mainrs").val(value);
							//$(".mainrs").html("Where the total income does not exceed. Rs"+value);
						}
					}
				});
			});*/
		$("#vipin_mainrs").click(function(){
			$("#spinner").show();
			$("#loader-wrapper").show();
				$(this).hide();
				$("#main_input").show();
				$("#spinner").hide();
				$("#loader-wrapper").hide();
				$("#main_input").focusout(function(){
						var value= $(this).val();
						$.ajax({
							type:'POST',
							url:'<?php echo $link->link("slipformat", Admin);?>',
							data:'incometax='+value,
							success:function(data){
									if(data==1)
									{
										//alert(value);
										$("#main_input").hide();
										$("#vipin_mainrs").html(value+"/-");
										$("#vipin_mainrs").show();
									}			
								}
							});
						
					}); 
			});
		
		});
	$(document).ready(function(){
		//stop another keys only alphabets are allowed...
		$(function () {
			$("#main_input").keydown(function (event) {
				if ((event.keyCode >= 48 && event.keyCode <= 57) || (event.keyCode >= 96 && event.keyCode <= 105) /*|| (event.keyCode == 32)*/ || (event.keyCode == 8)) {
					$(".alertshow").hide(); 
					} else {
						$(".alertshow").show();	
						event.preventDefault();
		         }
		    });
		 });
	});
</script>
<p style="display: none; font-size: 10px; color: #FF0000;">Only
	Alpahbets Are Allowed..</p>
<!-- ----------------------------------------------------MODAL------------------------------------------------ -->
<div id="example" class="modal hide fade in" style="top: 38%;">
	<div class="modal-header">
		<a class="close"
			href="<?php echo $link->link('salary_slip_format',Admin);?>">x</a>
		<div class="modal-body"></div>
	</div>
</div>
<!-- .example -->
<!-- -------------------------------------------------------modal end========================== -->
<div class="page-content">
	<div class="page-header position-relative">
		<h1>Salary Slip</h1>
	</div>
	<!--/.page-header-->
	<div class="row-fluid">
		<div class="span12" id="8">
			<form method="post" action="">
				<!-- <div class="row-fluid">
					<div class="span10 center">
					</div>
					<div class="span2">
						<button type="submit" name="submit" class="btn btn-minier btn-yellow">Save Column</button>
						<button type="submit" name="submit1" class="btn btn-minier btn-primary">Save Data</button>
					</div>
				</div><!-- ./row-fluid -->

				<div class="row-fluid">
					<div class="span6">
						<div class="row-fluid firsttable">
							<?php
							$firstnum = 1;
							foreach ( $secondarr as $row2 ) {
								
								if ($row2 != 'id') {
									$row9 = str_replace ( '.', '_', $row2 );
									$row9 = str_replace ( " ", '_', $row2 );
									$columnname = str_replace ( "_", " ", $row2 );
									?>
								<div class="row-fluid <?php echo "rowfluid".$row9;?>">
								<?php if($firstnum == 2){?>
									<div class="span10 center">
								<?php }else{?>
									<div class="span4 alphabet">
								<?php }?>
								<?php if($firstnum == 2){?>
										<b
											class="<?php //echo $row9;?> label label-large label-important arrowed-in-right arrowed-in"><?php echo $columnname;?></b>
								<?php }else{?>
										<b class="<?php echo $row9;?>"><?php echo $columnname;?></b>
								<?php }?>		
										<input class="alphabets<?php echo $row9;?> alphabets span11"
											alt="first_salaryslip" id="<?php echo $row9;?>" type="text"
											name="<?php echo $row9;?>" value="<?php echo $row2;?>"
											style="display: none;">
									</div>
								<?php if($firstnum != 2){?>
									
										<div class="span5" id="id<?php echo $row9;?>">
										<span class="movea_<?php echo $row9;?>">
											<?php
										$getvalue = $db->get_col ( "first_salaryslip", '', $row9 );
										if ($getvalue [0] == '') {
											?>
											<select class="alpha<?php echo $row9;?>"
											name="earning_select">
												<option value="" selected="selected" disabled="disabled">Please
													Select</option>
												<option
													value="<?php echo 'value&&&'.$row9.'&&&first_salaryslip';?>">Fixed
													Amount</option>
												<option
													value="<?php echo 'percentage&&&'.$row9.'&&&first_salaryslip';?>">%
													Of Basics</option>
										</select>
											<?php }else{?>
											<?php echo $getvalue[0]; }?>
											</span>
										<div class="<?php echo "b___".$row9;?>"></div>
									</div>
									<div class="span2">
										<a class="badge badge-important deletefirst"
											id="firsttable_<?php echo $row9; ?>">Delete</a>
									</div>
									
							<?php
									}
									echo "</div>";
								}
								$firstnum ++;
							}
							?>
						</div>
								<!-- ./row-fluid -->
								<div class="row-fluid">
									<div class="span12 center">
										<a name="add" onclick="increase_n(1);"
											class="btn btn-small btn-pink">Add Earnings Fields</a>
									</div>
								</div>
							</div>
							<!-- ./span6 -->
							<div class="span6">
								<div class="row-fluid secondtable">
							<?php
							$secondnum = 1;
							foreach ( $thirdarr as $row4 ) {
								if ($row4 != 'id') {
									$row8 = str_replace ( '.', '_', $row4 );
									$row8 = str_replace ( " ", '_', $row8 );
									$secondcolumnname = str_replace ( "_", " ", $row4 );
									?>
								<div class=" row-fluid <?php echo "rowfluid".$row8;?>"">
							<?php if($secondnum == 2){?>
								<div class="span10 center">
							<?php }else{?>	
								<div class="span4 alphabet1">
							<?php }?>
							<?php if($secondnum == 2){?>
									<b
													class="<?php //echo $row8;?> label label-large label-success arrowed-in-right arrowed-in"><?php echo $secondcolumnname;?></b>
							<?php }else{?>		
									<b class="<?php echo $row8;?>"><?php echo $secondcolumnname;?></b>
							<?php }?>		
									<input class="alphabets1 span11" alt="second_salaryslip"
													id="<?php echo $row8;?>" type="text"
													name="<?php echo $row8;?>" value="<?php echo $row4;?>"
													style="display: none;">
											</div> 
							<?php if($secondnum != 2){?>
								<div class="span5" id="id<?php echo $row8;?>">
												<span class="movea_<?php echo $row8;?>">
											<?php
										$getvalue = $db->get_col ( "second_salaryslip", '', $row8 );
										
										if ($getvalue [0] == '') {
											?>
											<select class="alpha<?php echo $row8;?>"
													name="earning_select">
														<option value="" selected="selected" disabled="disabled">Please
															Select</option>
														<option
															value="<?php echo 'value&&&'.$row8.'&&&second_salaryslip';?>">Add
															Value</option>
														<option
															value="<?php echo 'percentage&&&'.$row8.'&&&second_salaryslip';?>">Add
															Percentage</option>
												</select>
											<?php }else{?>
											<?php echo $getvalue[0]; }?>
											</span>
												<div class="<?php echo "b___".$row8;?>"></div>
											</div>
											<div class="span2">
												<a class="badge badge-important deletefirst"
													id="secondtable_<?php echo $row8; ?>">Delete</a>
											</div>
									
							<?php
									}
									echo "</div>";
								}
								$secondnum ++;
							}
							?>	
						</div>
										<!-- ./row-fluid -->
										<div class="row-fluid">
											<div class="span12 center">
												<a name="add" onclick="increase_ded(1);"
													class="btn btn-small btn-pink">Add Deduction Fields</a>
											</div>
										</div>

									</div>
									<!-- ./span6 -->

								</div>
								<!-- ./row-fluid -->
			
			</form>
			<div class="row-fluid">
				<?php
				$getcalc = $db->get_col ( "calculator", array ("id" => 1 ), "incometaxnull" );
				?>
				<table border="2" style="width: 100%;">
					<tr>
						<td style="width: 50%;"><b class="text-error">Income Slabs</b></td>
						<td style="width: 50%;"><b class="text-error">Tax Rates</b></td>
					</tr>
					<tr>
						<td class="mainrs" style="width: 50%;">Where the total income does
							not exceed. Rs <span><b id="vipin_mainrs"><?php  if($getcalc[0]!=''){ echo $getcalc[0];}else{ echo "Not Given";}?>/-</b>
								<input type="text" id="main_input"
								value="<?php echo $getcalc[0];?>" style="display: none;"> </span><br>
							<strong class="alertshow" style="display: none; color: #FF0000;">Only
								Numeric Value Are Allowed..</strong>
						</td>
						<td style="width: 50%;"><b>Nill</b></td>
					</tr>
				</table>
			</div>
		</div>
		<!-- /control-group -->
	</div>
</div>
<!--/.page-content-->


</div>
<!--/.main-content-->