<script>
$(document).ready(function(){
	$('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('<span class="icon-ok-circle">');
			$(this).find('id').show();
            eState = 1;
        }
        
        eRow.find('td').each(function(){            
            if(eState == 1){
                var eContent = $(this).html(); 
//				alert(eContent);
//				alert($(this).attr('id'));
				if($(this).attr('id') == 'rateConv'){     
                	if(eContent.indexOf('<') < 0){
                    	$(this).addClass("editing").html('<input class="tar" type="text" value="' + eContent + '"/>');
                	}
				}else if($(this).attr('id') == 'startDate' || $(this).attr('id') == 'endDate'){
                	if(eContent.indexOf('<') < 0){
                    	$(this).addClass("editing").html('<input class="datepicker2" type="text" value="' + eContent + '"/>');                    
						$(".datepicker2").datepicker({
			dateFormat : 'dd-mm-yy',
			changeMonth : true,
			changeYear : true
							});                    
                	}
				}
            }
            if(eState == 2){
                var eContent = $(this).find('input').val();                                
                if(eContent != null){
                    $(this).removeClass("editing").html(eContent);
                    // Here your ajax action after Save button pressed
			        var fldid = $('td:first', $(this).parents('tr')).text(); 
					var fieldname = $(this).attr('id');
                	var newContent = $(this).val();
					var urls = "<?php echo base_url()?>glsetting/currencyConv_update";
//			 		alert(fieldname);
					postData = {
						'fldid' : fldid,
						'fieldname' : fieldname,
						'eContent' : eContent,
					};
 					$.ajax({
  						type: "POST",
  						dataType: "json",
						url: urls,
						data: postData ,
	  					async: false,
						success: function(content){
						}
					});
					/* $.ajax({
  						type: "POST",
  						url: "menu_save?id=" + fldid,
  						success: function(){
						alert('Data has been saved...');
					}, 
		});   */    // Here your ajax action after delete confirmed
					
                }
            }
        });
        
        if(eState == 1) 
            $(this).attr('data-state','2');
        else{
            $(this).removeAttr('data-state');
            $(this).html('<span class="i-pen">');
        }
    });
});


</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()."gl/home" ?>'> <?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">
            	<div class="row-fluid">

                            <div class="span12">
			<?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>Currency Setup</h2>
                                        <div class="side fr">
                                            <button class="btn" onClick="clear_form('#validate');" type="button"><?php echo $this->lang->line('clearform') ?></button>
                                        </div>
                                    </div>
						<?php
							$data = array(
									'name'=>'fldid', 
									'id'=>'fldid', 
									'type'=>'hidden',); 
													  if($addCurrency){
															echo form_input($data, $addCurrency->fldid);                      
													  }
													  else
													  {
															echo form_input($data); 
													  }?>
                                    <div class="content np">
											<div class="controls-row">
                                                <div class="span2">Currency Code</div>
                                                <div class="span10">
                                                
                                                      <?php
													$data = array(
													'name'=>'fldcurr_code',
													'id'=>'fldcurr_code',
													'maxlength'=>'9',);
													  if($addCurrency){
															echo form_input($data, $addCurrency->fldcurr_code); 
													  }
													  else
													  {
															echo form_input($data, set_value('fldcurr_code')); 
													  }?>
                                                </div>
                                            </div>
											<div class="controls-row">
                                                <div class="span2">Currency Description</div>
                                                <div class="span9">
                                                <div class="input-prepend">
                                                   <?php
													$data = array(
													'name'=>'fldcurr_desc',
													'id'=>'fldcurr_desc',);
													
													if($addCurrency){
														echo form_input($data, $addCurrency->fldcurr_desc); 
													}
													else
													{
														echo form_input($data, set_value('fldcurr_desc')); 
													}?>
                                                </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, $this->lang->line('hideprompt'));
							$data = array(
									'name'=>'submit',
									'id'=>'submit',
									'class'=>'btn btn-primary');
							echo form_submit($data,$this->lang->line('submit'));
							?>
                    </div>
                </div>
            </div>                                    
                                </div>
                                </form>

                            </div>

                        </div>
