var serviceURLHR 	=localStorage['serviceURLHR'];
$('#emp_id,#financial_year').change(function(){
	$('#lnd_inf').hide();
	$('#ld_mdfy').hide();	
	$('#ld_dec').show();
    var emp_id			= $('#emp_id').val();
	var financial_year	= $('#financial_year').val();
		$('#emp_dtl').html('');
		$.getJSON(serviceURLHR + 'manageIncomeTax.php?action=loademp_details&emp_id='+emp_id,function(data){
			empnamelist = data.empnamelist;	
			
			$.each(empnamelist, function(index, empnamelist) {								 
				$('#emp_dtl').html('<table width="70%" border="0" cellspacing="0"  cellpadding="0" class="list-leaves">'+
										  '<tr style="height:35px;color:#686868;font-size:12px;font-weight:bold;line-height:20px;background-color: #F4F4F4;">'+
											'<td width=""><translate>Employee No:   '+empnamelist.employee_id+'</translate></td>'+
											'<td width=""><translate>Name:  '+empnamelist.emp_name+'</translate></td>'+
										  '</tr>'+
										  '<tr>'+
											'<td width=""><translate>Date Of Join:   '+empnamelist.date_join+'</translate></td>'+
											'<td width=""><translate>Permanent Account Number:</translate></td>'+
										 '</tr>'+
									'</table>');
			});	
		});	
		
		/* load income tax details*/
		$.getJSON(serviceURLHR + 'manageIncomeTax.php?action=load_incometax_details&emp_id='+emp_id+'&financial_year='+financial_year,function(data){ 
			declaration_list = data.declaration_list;
			$('input[name^="ded_amnt"]').each(function() {
				$(this).val('');
			});
			if(declaration_list!=null){
				$.each(declaration_list, function(index, declaration_list) {						 
					$("input[name^=ded_amnt]").eq(index).val(declaration_list.amount);
				});	
			}
			
			notes_list = data.notes_list;
			if(notes_list!=null){
				$.each(notes_list, function(index, notes_list) {  	  					 
					$('#declaration_note').val(notes_list.declaration_note);
					$('#rental_note').val(notes_list.rental_note);
					$('#section_note').val(notes_list.section_note);
					$('#pre_emp_note').val(notes_list.pre_emp_note);
					$('#other_income_note').val(notes_list.other_income_note);
					$('#other_income1').val(notes_list.other_income1);
					$('#other_income2').val(notes_list.other_income2);
					$('#other_income1_amount').val(notes_list.other_income1_amount);
					$('#other_income2_amount').val(notes_list.other_income2_amount);
				});
			}else {
					$('#declaration_note').val('');
					$('#rental_note').val('');
					$('#section_note').val('');
					$('#pre_emp_note').val('');
					$('#other_income_note').val('');
					$('#other_income1').val('');
					$('#other_income2').val('');
					$('#other_income1_amount').val('');
					$('#other_income2_amount').val('');
			}
			/*landlord list*/
			landlord_list = data.landlord_list;
			if(landlord_list!=null){
				$.each(landlord_list, function(index, landlord_list) { 
					$('#ld_mdfy').show();	
					$('#ld_dec').hide();	
					$('#landlord_has_pan').val(landlord_list.landlord_has_pan);
					$('#landlord_name').val(landlord_list.landlord_name);
					$('#landlord_address').val(landlord_list.landlord_address);
					$('#landlord_pan_number').val(landlord_list.landlord_pan_number);
					
				});
			} else {
					$('#landlord_has_pan').val('');
					$('#landlord_name').val('');
					$('#landlord_address').val('');
					$('#landlord_pan_number').val('');
			}
		});	
	
 });

  $("#tab1Button").click(function() {
		$('.tabbable li:eq(1) a').tab('show');
  })
  $("#tab2Button").click(function() {
		$('.tabbable li:eq(2) a').tab('show');
  })
  $("#tab3Button").click(function() {
		$('.tabbable li:eq(3) a').tab('show');
  })
  $("#tab4Button").click(function() {
		$('.tabbable li:eq(4) a').tab('show');
  })
  $('.lnd_dcl').click(function(){
		$('#lnd_inf').show();						   
  });
  
  $('#cancel-button').click(function(){
		$('#lnd_inf').hide();						   
  });


  $("#tax_submit").click(function() {
								  
		if ($('#emp_id').val()=='')	 {
				alert("Please select an employee");
		} 
		else if ($('#financial_year').val()=='')	 {
				alert("Please select financial year");
		} 
		else {
			 var datastring = $("#frm").serialize();	
			 $.post(serviceURLHR + "manageIncomeTax.php?action=insert",datastring,function(data){   
					alert("IT Declarations Successfully Inserted.");
			 },'json');
		}

  });
  
  $("input[name=landlord_has_pan]").change(function() {
		if($("input[name='landlord_has_pan']:checked").val()=='Yes') {
			$('#pan').toggle();
			$('#not_pan').toggle();
		} else {
			$('#pan').toggle();
			$('#not_pan').toggle();
		}
  });
  
    $("#landlord_save").click(function() {
		/*var file =  $('#fileupload')[0].files[0];
		fileName = file.name;	alert(fileName);	*/				  
		if ($('#emp_id').val()=='')	 {
				alert("Please select an employee");
		} 
		else if ($('#financial_year').val()=='')	 {
				alert("Please select financial year");
		} 
		else {
			var dataString = $('#frm').serialize();
			 var formData = new FormData($('#frm')[0]);	
			 $.ajax({
				url: serviceURLHR + "manageIncomeTax.php?action=landlord_insert",  //Server script to process data
				type: 'POST',
				data: formData,
				processData: false,  // tell jQuery not to process the data
				contentType: false ,  // tell jQuery not to set contentType
				success: function(data){
						alert("Landlord Details Successfully Saved.");
				}
			});	
		}

  });
  function check_max_limit(max_limit,value,cnt){
		if(parseFloat(value)>parseFloat(max_limit)) {
			alert("Not allowed to exceed the maximum limit.");
			$('#ded_amnt'+cnt).val('');
		}
  }
  $("#dec_frm").click(function() { 
  		 window.location.href = serviceURLHR + "download_rentproof.php"	
		 
  });
  $('#e_id,#financial_year,#month').change(function(){
	
    	var emp_id			= $('#e_id').val();
		var financial_year	= $('#financial_year').val();
		var month			= $('#month').val();
		
		/*listing employee details*/
		$('#emp_dtl').html('');
		$.getJSON(serviceURLHR + 'manageIncomeTax.php?action=loademp_details&emp_id='+emp_id,function(data){
			empnamelist = data.empnamelist;	
			$.each(empnamelist, function(index, empnamelist) {								 
				$('#emp_dtl').html('<table width="70%" border="0" cellspacing="0"  cellpadding="0" class="list-leaves">'+
										  '<tr style="height:35px;color:#686868;font-size:12px;font-weight:bold;line-height:20px;background-color: #F4F4F4;">'+
											'<td width=""><translate>Employee No:   '+empnamelist.employee_id+'</translate></td>'+
											'<td width=""><translate>Name:  '+empnamelist.emp_name+'</translate></td>'+
										  '</tr>'+
										   '<tr>'+
											'<td width=""><translate>Bank:   '+empnamelist.e_bank+'</translate></td>'+
											'<td width=""><translate>Bank Account No:   '+empnamelist.e_accountno+'</translate></td>'+
										 '</tr>'+
										  '<tr>'+
											'<td width=""><translate>Date Of Join:   '+empnamelist.date_join+'</translate></td>'+
											'<td width=""><translate>PF No:</translate></td>'+
										 '</tr>'+
									'</table>');
			});	
		});
		/*listing employee details end*/
		
		$.getJSON(serviceURLHR + 'manageIncomeTax.php?action=tax_calculation&emp_id='+emp_id+'&financial_year='+financial_year+'&month='+month,function(data){
				$('#tax_income').html(data.taxable_income);	
				$('#tax_deduction').html(data.tax_deduction);	
				
		 });
		
	});	
    function row_expan(id)
	{
		 var cls= $("#icons"+id).hasClass('glyphicon glyphicon-plus');
		
		if(cls==true)
		{
		$("#icons"+id).addClass('glyphicon-minus').removeClass('glyphicon-plus');
		}
		else
		{
		$("#icons"+id).addClass('glyphicon-plus').removeClass('glyphicon-minus');
		}
	}