<SCRIPT language=Javascript>
       <!--
       function isNumberKey(evt)
       {
          var charCode = (evt.which) ? evt.which : event.keyCode;
          if (charCode != 46 && charCode > 31 
            && (charCode < 48 || charCode > 57))
             return false;

          return true;
       }
       //-->
    </SCRIPT>
	
	<script>
	$(document).ready(function() {
    /* Build the DataTable with third column using our custom sort functions */
    var oTable = $("#companyFinancialCalendar").dataTable( {
        "iDisplayLength": 25,
		 "aLengthMenu": [5,10,25,50,100],
		 "asSorting": [ "asc"], "aTargets": [ 1 ],
		 "sPaginationType": "full_numbers", "aoColumns": [ { 
		 	"bSortable": false }, 
			null, 
			null, 
			null, 
			null, 
			null, 
			null, { 
			"bSortable": false } ]});
     oTable.fnSort( [ [1,'asc'] ] );
    $("table.editable").on("click",".remove",function(){
        rRow = $(this).parents("tr");
        ID = $('td:first', $(this).parents('tr')).text(); 
        $("#row_delete").dialog("open");
    });
    $("table.editable").on("click",".edit",function(){
        rRow = $(this).parents("tr");
        ID = $('td:first', $(this).parents('tr')).text(); 
        $("#row_edit").dialog("open");
    });
    $("#row_edit").dialog({
        autoOpen: false,
        resizable: false,        
        modal: true,
        buttons: {
            "Continue...": function() {
				window.location.href = "calendar?id=" + ID;		
                $(this).dialog("close");
            },
            Cancel: function() {
                $(this).dialog("close");
            }
        }
    });
	
$(document).ready(function(){
	$('#journalTable').hide();
	$('select').select2();
	jQuery('.datepicker2').datepicker({
			dateFormat : 'dd-mm-yy',
			changeMonth : true,
			changeYear : true
			});
	
    
    $("table.editable").on("click",".edit",function(){
        var eRow   = $(this).parents('tr');
        var eState = $(this).attr('data-state');
        
        if(eState == null){
            $(this).html('Save');
            eState = 1;
        }
        
        
        
        if(eState == 1) 
            $(this).attr('data-state','2');
        else{
            $(this).removeAttr('data-state');
            $(this).html('Edit');
        }
    });
        
});

function yearperiodCheck(){
	if($('#financialYear').val() == ''){ 
		alert('<?php echo $this->lang->line('year') ?>');
		$('#financialYear').focus();
	}
	else if ($('#period').val() == ''){
		alert('<?php echo $this->lang->line('period') ?>');
		$('#period').focus();
	}
	else{
		var financialYear = $('#financialYear').val();
		var period = $('#period').val();
		//$('#hidePrompt').hide();
		//$('#journalTable').show();
		var postData = {
			'financialYear' : financialYear,
			'period' : period,
		};
		//alert("<?php echo base_url()?>financialCalendarCheck_yearperiod");
 		$.ajax({
  			type: "POST",
  			dataType: "json",
			url: "<?php echo base_url()?>glsetting/financialCalendarCheck_yearperiod",
			data: postData ,
  			success: function(content){
				if(content.status == "success") {
					$('#startDate').removeAttr('disabled');
					$('#endDate').removeAttr('disabled');
					$('#startDate').focus();
				}else if(content.status == "false"){
					alert('Data exists...');
					
					$('#startDate').removeAttr('disabled');
					$('#endDate').removeAttr('disabled');
					$('#startDate').val(content.startDate);
					$('#endDate').val(content.endDate);
					$('#fcID').val(content.ID);
					$('#startDate').focus();
					
				}
			}
		});        // Here your ajax action after delete confirmed
//		location.reload();
	}
}

function dateSearch(){
	var period = $("#period").val();
	var startDate = $("#startDate").val();
		var postData = {
			'period' : period,
			'startDate' : startDate,
		};
 		$.ajax({
  			type: "POST",
  			dataType: "json",
			url: "<?php echo base_url()?>glsetting/dateSearch",
			data: postData ,
  			success: function(content){
				if(content.status == "success") {
					$('#startDate').val(content.startDate);
					$('#endDate').val(content.endDate);
				}
			}
		});        // Here your ajax action after delete confirmed
}

function checkYear(obj){
	/*var financialYear = $("#financialYear").val();
	var period = $("#period").val();*/
	var financialYear = obj.value;
	
		var postData = {
			'financialYear' : financialYear,
		};
		
 		$.ajax({
  			type: "POST",
  			dataType: "json",
					//alert("alert biasa");
			url: "<?php echo base_url()?>glsetting/checkYear",
			data: postData ,
  			success: function(content){
				if(content.status == "success") 
				{
//					$('#companyFinancialCalendar').dataTable().fnClearTable();
					$("#submit").attr("disabled", true);
					$("#period").attr("disabled", true);
					$("#startDate").attr("disabled", true);
					
					$('#companyFinancialCalendar thead').empty();
					$('#companyFinancialCalendar tbody').empty();
					
					$("#companyFinancialCalendar thead").append('<tr><th style="display:none"></th><th class="tac">' + 
						"#" + '</th><th class="tac">' +  
						"<?php echo $this->lang->line('year');?>" + '</th><th class="tac">' + 
						"<?php echo $this->lang->line('period');?>" + '</th><th class="tac">' + 
						"<?php echo $this->lang->line('startDate');?>" + '</th><th class="tac">' + 
						"<?php echo $this->lang->line('endDate');?>" + '</th><th class="tac">' +
						"<?php echo $this->lang->line('status');?>" + '</th></tr>');
						
					for (var i=0; i<content.message.length; i++){
						$("#companyFinancialCalendar tbody").append('<tr><td style="display:none">' + 
						content.message[i].ID + '</td><td class="tac">' + 
						(i+1) + '</td><td class="tac"><a title="Edit" class="btn btn-mini btn-link edit">' + 
						content.message[i].financialYear + '</a></td><td class="tac">' + 
						content.message[i].period + '</td><td class="tac">' + 
						(content.message[i].startDate).substr(8, 2) + 
							"-" + (content.message[i].startDate).substr(5, 2) +
							"-" + (content.message[i].startDate).substr(0, 4) + '</td><td class="tac">' + 
						(content.message[i].endDate).substr(8, 2) + 
							"-" + (content.message[i].endDate).substr(5, 2) +
							"-" + (content.message[i].endDate).substr(0, 4) + '</td><td class="tac">' + 
						content.message[i].status + '</td></tr>');
        			}
					$("#ID").val(financialYear);
				} 
				else 
				{
					$("#submit").attr("disabled", false);
					$("#period").attr("disabled", false);
					$("#startDate").attr("disabled", false);
					
					$('#companyFinancialCalendar thead').empty();
					$('#companyFinancialCalendar tbody').empty();
				}
			}
		});        // Here your ajax action after delete confirmed
}

</script>
	
	
<div id="content">                        
<div class="wrap">
<div class="head">
	<div class="info">
							<h1><?php echo element('compName', $this->session->userdata('logged_in')) ?> [ 
								<?php echo element('compNo', $this->session->userdata('logged_in')) ?> ]</h1>
			<ul class="breadcrumb">
            	<li><a href="#"><?php echo $this->lang->line('dashboard') ?></a> <span class="divider">-</span></li>
                <li><a href="#"><?php echo $this->lang->line('module') ?></a> <span class="divider">-</span></li>
                <li class="active"><?php echo $this->lang->line('title') ?></li>
            </ul>
	</div>
	<div class="search">
		<form action="<?php echo base_url() ?>admin/search" method="post">
			<input name="search_text" type="text" placeholder="search..."/>                                
            <button type="submit"><span class="i-magnifier"></span></button>
		</form>
	</div>                        
</div><!-- head --> 
<div class="content">
<div class="wrap">                    
	<div class="row-fluid">
		<div class="span12">
        	<div class="block">
			<?php 
				$hidden = array('order_time' => date('Y-m-d H-i-s'));
				$attrib = array('id'=>'validate'); 
				echo form_open('', $attrib, $hidden);?>
                                <!-- form id="validate" method="POST" action="javascript:alert('Form #validate submited');"-->
                                <div class="block">
                                    <div class="head">
                                        <h2>FINANCIAL CALENDAR</h2>
                                        <div class="side fr">
                                            <button class="btn" onClick="clear_form('#validate');" type="button">Clear form</button>
                                        </div>
                                    </div>
						<?php
							$data = array(
									'name'=>'fcID', 
									'id'=>'fcID', 
									'type'=>'hidden',); 
							echo form_input($data, $fycmaster->ID); ?>                       
                                    <div class="content np">
											<div class="controls-row">
                                                <div class="span2">Year</div>
                                                <div class="span9">
                                                   <?php
														//echo '<select name="financialYear" id="financialYear" value="financialYear">';
 
														//echo '</select>';
														if($fycmaster){
															$preselyear = $fycmaster->financialYear;
														}else{
															$preselyear = date('Y');
														}
														$options = '';
														$options[] = '--Please Select--';
														for($i=-2; $i<6; $i++){
															$options[date('Y', strtotime($i . "  year"))] = date('Y', strtotime($i . "  year"));
														}
														$js='style="width: 150px;"';
														echo form_dropdown('financialYear', $options, $preselyear, $js);
													?>                                                                                                
                                            	</div>
                                            </div>
											<div class="controls-row">
                                                <div class="span2">Period</div>
                                                <div class="span10">
                                                      <?php
													$data = array(
													'name'=>'period',
													'id'=>'period',
													'onkeypress'=>'return isNumberKey(event)',
													'maxlength'=>'2',);
													$js='onChange="dateSearch(this)" class="span1 tar"';
													if($fycmaster){
														echo form_input($data, $fycmaster->period, $js);                      
													}
													else
													{
														echo form_input($data, '1', $js); 
													} 
													 ?>
                                                </div>
                                            </div>
											<div class="controls-row">
                                                <div class="span2">Start date</div>
                                                <div class="span9">
                                                <div class="input-prepend">
                                                    <span class="add-on"><i class="i-calendar"></i></span>
													<?php
													$data = array(
													'name' => 'startDate',
													'id' => 'startDate',
													'type' => 'text',
													'class' => 'input-small datepicker2',);
													$js='onChange="dateSearch(this)"';
													if($fycmaster){
														echo form_input($data, date('d-m-Y', strtotime($fycmaster->startDate)), $js);                      
													}
													else
													{
														echo form_input($data, date('01-m-Y'), $js); 
													}
													
													?>
                                                </div>                                                                                                
                                            	</div>
                                            </div>
											<div class="controls-row">
                                                <div class="span2">End date</div>
                                                <div class="span9">
                                                <div class="input-prepend">
                                                    <span class="add-on"><i class="i-calendar"></i></span>
													<?php
													$data = array(
													'name' => 'endDate',
													'id' => 'endDate',
													'type' => 'text',
													'class' => 'input-small',);
													if($fycmaster){
														echo form_input($data, date('d-m-Y', strtotime($fycmaster->endDate)), 'readonly');                      
													}
													else
													{
														echo form_input($data, date('t-m-Y'), 'readonly'); 
													}
													?>
                                                </div>                                                                                                
                                            	</div>
                                            </div>
											<div class="controls-row">
                                                <div class="span2">Display</div>
                                                <div class="span5">
                   								<div class="span4">&nbsp;&nbsp;
												<?php
													$data = array(
													'name'=>'status', 
													'id'=>'status',);
													if($fycmaster){
														if($fycmaster->status == 1){
															echo form_radio($data, '1', TRUE);
                            								echo"<span class='help-inline'>Yes</span>&nbsp;&nbsp";
															echo form_radio($data, '0', FALSE); 
                            								echo"<span class='help-inline'>No</span>";
														}
														else{
															echo form_radio($data, '1', FALSE);
                            								echo"<span class='help-inline'>Yes</span>&nbsp;&nbsp";
															echo form_radio($data, '0', TRUE); 
                            								echo"<span class='help-inline'>No</span>";
														}
													}
													else{
													echo form_radio($data, '1', FALSE);
                            						echo"<span class='help-inline'>Yes</span>&nbsp;&nbsp";
													echo form_radio($data, '0', TRUE); 
                            						echo"<span class='help-inline'>No</span>";
													}
													?>
                  								</div>                        
                  								</div>
                                            </div>
                                        
                                    </div>
            <div class="footer">
            	<div class="side fr">
                	<div class="btn-group">
                        <?php 
							$data = array(
									'name'=>'validat', 
									'class'=>'btn',
									'onClick'=>"$('#validate').validationEngine('hide');"); 
							echo form_button($data,'Hide prompts');
							$data = array(
									'name'=>'submit',
									'id'=>'submit',
									'class'=>'btn btn-primary');
							echo form_submit($data,'Submit');
							?>
                    </div>
                </div>
            </div>
            <div class="content np table-sorting">
            	<table cellpadding="0" cellspacing="0" width="100%" id="companyFinancialCalendar" class="editable">
                	<thead>
                    <!--<tr>
            			<th style="display:none"></th>
            			<th class="tac"><?php echo $this->lang->line('#');?></th>
            			<th class="tac"><?php echo $this->lang->line('year');?></th>
                		<th class="tac"><?php echo $this->lang->line('period');?></th>
                		<th class="tac"><?php echo $this->lang->line('startDate');?></th>
                		<th class="tac"><?php echo $this->lang->line('endDate');?></th>                
                		<th class="tac"><?php echo $this->lang->line('status');?></th>               
                		<th width="55" class="tac"><?php echo $this->lang->line('action');?></th>
            		</tr>-->
        			</thead>
       				 <tbody>
			<?php $bil = 0; 
/*				if($datatbls){
				foreach($datatbls as $datatbl):
				$bil++?>
            	<tr>
                	<td style="display:none" ><?php echo $datatbl->ID; ?></td>
                	<td class="tac"><?php echo $bil; ?></td>
                	<td class="tac"><a title="<?php echo $this->lang->line('edit');?>" class="btn btn-mini btn-link edit"><?php echo $datatbl->financialYear ?></a></td>
                	<td class="tac"><?php echo $datatbl->period; ?></td>
                	<td class="tac"><?php echo date(element('dtFormat', $this->session->userdata('logged_in')), strtotime($datatbl->startDate)); ?></td>
                	<td class="tac"><?php echo date(element('dtFormat', $this->session->userdata('logged_in')), strtotime($datatbl->endDate)); ?></td>
                	<td class="tac"><?php echo $datatbl->status; ?></td>
						<td class="tac"><?php
						if($datatbl->yearEnd == 1){
							$js = 'class="btn btn-mini btn-danger remove" title="'.$this->lang->line('delete').'"';
							echo form_button('remove','<span class="i-trashcan">',$js);
						}
						?></td>
                </tr>
            <?php endforeach; } */?>
					</tbody>
			</table>                                         
			</div>                                    
                                </div>
                                </form>

                            </div>

                        </div>

