<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(){
	$('#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
}

</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 base_url()."home" ?>'><?php echo $this->lang->line('dashboard') ?></a> <span class="divider">-</span></li>
					<li><a href='<?php echo base_url()."glsetting/calendar" ?>'><?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>
										<ul class="buttons">
											<li><a href="#" class="block_toggle"><span class="i-arrow-down-3"></span></a></li>
										</ul>
                                        <div class="side fr">
                                            <button class="btn-form btn-danger-form" onClick="clear_form('#validate');" type="button">Clear form</button>
                                        </div>
                                    </div>
										<?php
											$fycmasterID = 0;
                                                if($fycmaster){
													$fycmasterID= $fycmaster->ID;
													}
											$data = array(
												'name'=>'fcID', 
												'id'=>'fcID', 
												'type'=>'hidden',); 
											echo form_input($data, $fycmasterID); ?>                       
                                    <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');
													}
														$js='onChange="checkYear(this)"; style="width: 150px;" readonly';
													echo form_input('financialYear', $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" readonly';
													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 financhk',);
															$js='onChange="dateSearch(this)" readonly';
															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">Month End Closing</div>
                                                <div class="span5">
                   								<div class="span4">&nbsp;&nbsp;
												<?php
													$data = array(
													'name'=>'status', 
													'id'=>'status',);
													if($fycmaster){
														if($fycmaster->status == 0){
															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, '0', FALSE);
                            						echo"<span class='help-inline'>Yes</span>&nbsp;&nbsp";
													echo form_radio($data, '1', 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-form btn-warning-form',
													'onClick'=>"$('#validate').validationEngine('hide');"); 
													echo form_button($data,'Hide prompts');
													$data = array(
													'name'=>'submit',
													'id'=>'submit',
													'class'=>'btn-form btn-success-form');
													echo form_submit($data,'Submit');
												?>
												</div>
											</div>
										</div>                                    
									</div>
								</div>
							</form>
						</div>
					</div>
			</div>
		</div>
	</div>
</div>


