<script>
$(document).ready(function(){
	jQuery('.datepicker2').datepicker({
			dateFormat : 'dd-mm-yy',
			changeMonth : true,
			changeYear : true
			});
	jQuery("#supplierCode").keyup(function() {
		jQuery(this).val(jQuery(this).val().toUpperCase());
	});
        
          $('select').select2();
//                $.each($(".select2-container"), function (i, n) {
//                    $(n).next().show().fadeTo(0, 0).height("0px").css("left", "auto"); // make the original select visible for validation engine and hidden for us
//                    $(n).prepend($(n).next());
//                    $(n).delay(500).queue(function () {
//                        $(this).removeClass("validate[required]"); //remove the class name from select2 container(div), so that validation engine dose not validate it
//                        $(this).dequeue();
//                    });
//                });	
                
});
    
     function checkDuplicateCode() {
        //	alert("");

        $.ajax({
            type: "POST",
            data: "code=" + $("#accountCode").val(),
            url: "<?php echo base_url() ?>customerSetup/checkCustomerCode",
            success: function(data) {
                //if (data != "false") {
				if (data != false) {
                    $("#accountCode").val("");
                    $("#accountCode").attr("placeholder", "Code been using ...");
                   // $("#employeeCode").attr("class", "span12 validate[required] error");


                } else {
                 //   $("#employeeCode").attr("class", "span12 validate[required] success");
                }
            }
        });

    }
    
	function changeList(obj){
		var id = obj.value;
		$.ajax({
			type: "POST",
			url: "<?php base_url()?>../setting/getState/",
			data: "region="+id,
			dataType:"json",
			success: function(content){
				if(content.status == "success") {
					var items = [];
					items.push('<option>-Please Select-</option>');
					for ( var i = 0; i < content.message.length; i++) {
					items.push('<option value="'+content.message[i].fldid+'">'
						+ content.message[i].fldname + '</option>');
					}
					jQuery("#customerStateID").empty();
					jQuery("#customerStateID").append(items.join('</br>'));
				} else {
					$("#error").html('<p>'+content.message+'</p>');
				}
			}
		});
		return false;
	}
	
	function selectChartOfAcct(){
		try{
			
        $.ajax({
        type: "POST",
        url: "<?php echo base_url()?>customerSetup/refreshChartAcct",
        success: function(data) {
			   var resul = eval ("(" + data + ")"); 
			   var n=resul.records.length;
			   var i=0;
			   var opt='' +
					'<option></option>';
					for (i=0;i<n;i++)
							opt=opt + '<option value="' + resul.records[i].id +'">' + resul.records[i].acctCode + '</option>';
					$('#linkedAPAccountID').empty();
					$('#linkedAPAccountID').append(opt);
			}
   		});
		
		}
		catch(err){
		}
	}
	
</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() ."admin/usermaster" ?>'><?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="row-fluid">
				<div class="span12">
				<?php 
				$hidden = array('order_time' => date('Y-m-d H-i-s'));
					if($customermaster)
					$hidden['ID'] = $customermaster->ID;
					$attrib = array('id'=>'validate'); 
						echo form_open('', $attrib, $hidden);?>
					<div class="block">
						<div class="head">
							<h2><?php echo $this->lang->line('title') ?></h2>
                            <ul class="buttons">                                            
                            	<li><a href="#" class="block_toggle"><span class="i-arrow-down-3"></span></a></li>
                        	</ul>                                         
						</div>
						<div class="content np"> <!-- Content 1 --> 
							<div class="controls-row">
								<div class="span3"><?php echo $this->lang->line('customerCode') ?></div>
								<div class="span4">
								<?php
								$data = array(
									'name'=>'accountCode', 
									'id'=>'accountCode', 
                                    'onblur' => 'checkDuplicateCode()',
									'class'=>'span12 validate[required]',); 
								if($customermaster){		
									echo form_input($data, $customermaster->accountCode); 
								} else {
									echo form_input($data, set_value('accountCode')); 
								} ?>      
								</div> 
							</div>
							<div class="controls-row">
								<div class="span3"><?php echo $this->lang->line('customerCompanyNo') ?></div>
								<div class="span4">
								<?php
								$data = array(
									'name'=>'customerCompanyNo',
                                    'class' => 'span12 validate[required,minSize[5],maxSize[20]]',
									'id'=>'customerCompanyNo',);
								if($customermaster){
									echo form_input($data, $customermaster->customerCompanyNo); 
								} else {
									echo form_input($data, set_value('customerCompanyNo')); 
								} ?>
								</div>
								<div class="span2"><?php echo $this->lang->line('gstRegNo') ?></div>
								<div class="span2">
                                 <?php
                                 $data = array(
									'name' => 'gstRegNo',
                                    'id' => 'gstRegNo',
                                    'placeholder' => $this->lang->line('example') . ':123456789012',
									'class' => 'span12 validate[custom[integer],minSize[12],maxSize[12]]');
                                 if ($customermaster) {
									echo form_input($data, $customermaster->gstRegNo);
                                 } else {
									echo form_input($data, set_value('gstRegNo'));
                                 } ?> 
								</div>         
							</div>    						            
							<div class="controls-row">
								<div class="span3"><?php echo $this->lang->line('customerName') ?></div>
								<div class="span8">
								<?php
								$data = array(
									'name'=>'customerName', 
									'id'=>'customerName', 									
									'class'=>'span12 validate[required]',); 
								if($customermaster){		
									echo form_input($data, $customermaster->customerName); 
								} else {
									echo form_input($data, set_value('customerName')); 
								} ?> 
								</div>
							</div>        						 
						</div><!-- End Content-->
					</div> <!-- Block -->   
				</div><!-- span 12-->                
			</div><!-- row-fluid scRow-->
			
			<div class="row-fluid">
				<div class="span12">					
					<div class="block">
						<div class="head">
							<h2><?php echo $this->lang->line('addressinfo') ?></h2>
                            <ul class="buttons">                                            
                            	<li><a href="#" class="block_toggle"><span class="i-arrow-down-3"></span></a></li>
                        	</ul>                                         
						</div>
						<div class="content np">    
							<div class="controls-row">
								<div class="span3"><?php echo $this->lang->line('addressName') ?></div>
								<div class="span8">
								<?php
								$data = array(
									'name'=>'line1', 
									'id'=>'line1', 									
									'class'=>'span12 validate[maxSize[128]]',); 
								if($customermaster){		
									echo form_input($data, $customermaster->line1); 
								} else {
									echo form_input($data, set_value('line1')); 
								} ?> 
								</div>	
							</div>
							<div class="controls-row">
								<div class="span3">&nbsp;</div>
								<div class="span8">
								<?php
								$data = array(
									'name'=>'line2', 
									'id'=>'line2', 									
									'class'=>'span12 validate[maxSize[128]]',); 
								if($customermaster){		
									echo form_input($data, $customermaster->line2); 
								} else {
									echo form_input($data, set_value('line2')); 
								} ?> 
								</div>
							</div>
							<div class="controls-row">
								<div class="span3">&nbsp;</div>
								<div class="span8">
								<?php
								$data = array(
									'name'=>'line3', 
									'id'=>'line3', 									
									'class'=>'span12 validate[maxSize[128]]',); 
								if($customermaster){		
									echo form_input($data, $customermaster->line3); 
								} else {
									echo form_input($data, set_value('line3')); 
								} ?> 
								</div>
							</div>
							<div class="controls-row">
								<div class="span3"><?php echo $this->lang->line('city') ?></div>
								<div class="span4">
								<?php
								$data = array(
									'name'=>'city', 
									'id'=>'city', 									
									'class'=>'span12',); 
								if($customermaster){		
									echo form_input($data, $customermaster->city); 
								} else {
									echo form_input($data, set_value('city')); 
								} ?> 
								</div>
								<div class="span1 TAR"><?php echo $this->lang->line('postCode') ?></div>
								<div class="span3">
								<?php
								$data = array(
									'name'=>'customerPostCode', 
									'id'=>'customerPostCode', 									
									'class'=>'span12 validate[minSize[5],maxSize[5]]',); 
								if($customermaster){		
									echo form_input($data, $customermaster->customerPostCode); 
								} else {
									echo form_input($data, set_value('customerPostCode')); 
								} ?> 
								</div>
							</div>
							<div class="controls-row"> <!-- row 1 -->
								<div class="span3"><?php echo $this->lang->line('country') ?></div>
								<div class="span4">
								<?php
								if($customermaster){		
									$preselcat = $customermaster->customerCountryID;
								} else {
									$preselcat = '458';
								}        
								$options = array();                
								$options[] = '--Please Select--';
								foreach($country as $row){
									$options[$row->fldid] = $row->fldcountry;
								}
								$js='onChange="changeList(this)" class="span12"';
									echo form_dropdown('customerCountryID', $options, $preselcat, $js);
								?>       
								</div>                
								<div class="span1" TAR><?php echo $this->lang->line('state') ?></div>
								<div class="span3">
								<?php
								if($customermaster){		
									$preselcat = $customermaster->customerStateID;
								} else {
									$preselcat = '0';
								}                        
								$options='';
								$options[] = '--Please Select--';
								if($state != ''){
									foreach($state as $row){
										$options[$row->fldid] = $row->fldname;
									}
								}
								$js='id=customerStateID class="span12"';
									echo form_dropdown('customerStateID', $options, $preselcat, $js);
								?>       
								</div>                
							</div><!-- End Row 1 -->
						</div><!-- End Content-->
					</div> <!-- Block -->  
				</div><!-- span12 -->
			</div><!-- row-fluid -->
			
			<div class="row-fluid">
				<div class="span12">
					<div class="block">
						<div class="head">
							<h2><?php echo $this->lang->line('contactinfo') ?></h2>
								<ul class="buttons">                                            
									<li><a href="#" class="block_toggle"><span class="i-arrow-down-3"></span></a></li>
								</ul>                                         
						</div>
						<div class="content np">    
							<div style="display: none;" class="controls-row">
								<div class="span3"><?php echo $this->lang->line('position') ?></div>
								<div class="span8">
								<?php
								$data = array(
									'name'=>'position',
									'id'=>'position',
									'class'=>'span7',); 
								if($customermaster){		
									echo form_input($data, $customermaster->position); 
								} else {
									echo form_input($data, set_value('position')); 
								} ?> 
								</div>                            
							</div>  
							<div class="controls-row">
								<div class="span3"><?php echo $this->lang->line('email') ?></div>
								<div class="span8">
								<?php
								$data = array(
									'name'=>'email', 
									'class'=>'span7 validate[custom[email]]',); 
								if($customermaster){		
									echo form_input($data, $customermaster->email); 
								} else {
									echo form_input($data, set_value('email')); 
								} ?> 
									<span class="help-inline"><?php echo $this->lang->line('example') ?>: accounts@salihin.com.my</span>
								</div>                        
							</div>
							<div class="controls-row">
								<div class="span3"><?php echo $this->lang->line('phoneNumber1') ?></div>
								<div class="span8">
								<?php
								$data = array(
									'name'=>'phoneNumber1', 
									'id'=>'phoneNumber1', 
									'class'=>'span7 validate[maxSize[16]]',); 
								if($customermaster){		
									echo form_input($data, $customermaster->phoneNumber1); 
								} else {
									echo form_input($data, set_value('phoneNumber1')); 
								} ?> 
									<span class="help-inline"><?php echo $this->lang->line('example') ?>: +603-2261 4180</span>
								</div>                
							</div>
							<div class="controls-row">
								<div class="span3"><?php echo $this->lang->line('fax') ?></div>
								<div class="span8">
								<?php
								$data = array(
									'name'=>'fax', 
									'id'=>'fax', 
									'class'=>'span7 validate[maxSize[16]]',); 
								if($customermaster){		
									echo form_input($data, $customermaster->fax); 
								} else {
									echo form_input($data, set_value('fax')); 
								}  ?> 
								<span class="help-inline"><?php echo $this->lang->line('example') ?>: +603-2261 4182</span>
								</div>                
							</div>
							<div class="controls-row">
								<div class="span3"><?php echo $this->lang->line('phoneNumber2') ?></div>
								<div class="span8">
								<?php
								$data = array(
									'name'=>'phoneNumber2',
									'class'=>'span7',);
									//'class'=>'span5 validate[maxSize[16]]',); 
								if($customermaster){		
									echo form_input($data, $customermaster->phoneNumber2); 
								} else {
									echo form_input($data, set_value('phoneNumber2')); 
								}                       ?> 
									<span class="help-inline"><?php echo $this->lang->line('example') ?>: 012-261 4180</span>
								</div>                        
							</div>    
						</div><!-- End Content-->
					</div> <!-- Block -->  
				</div><!-- span 12-->                
			</div><!-- row-fluid scRow-->
			
			<div class="row-fluid">
				<div class="span12">
					<div class="block">
						<div class="head">
							<h2><?php echo $this->lang->line('othersinfo') ?></h2>
								<ul class="buttons">                                            
									<li><a href="#" class="block_toggle"><span class="i-arrow-down-3"></span></a></li>
								</ul>                                         
						</div>
						<div class="content np">    
							<div class="controls-row">
								<div class="span3"><?php echo $this->lang->line('generalNote') ?></div>
								<div class="span8">
								<?php
								$data = array(
									'name'=>'generalNote', 
									'class'=>'span12',); 
								if($customermaster){		
									echo form_input($data, $customermaster->generalNote); 
								} else {
									echo form_input($data, set_value('generalNote')); 
								} ?> 
								</div>                                                
							</div>
							<div class="controls-row"> 
								<div class="span3"><?php echo $this->lang->line('termstatus') ?></div>
								<div class="span4">
								<?php
								if($customermaster){		
									$preselstatus = $customermaster->termsID; 
								} else {
									$preselstatus = ''; 
								}                       
								$options = '';
								$options[] = '--Please Select--';
								if ($termstatus) 
									foreach($termstatus as $row){
										$options[$row->ID] = $row->termName;
									}
								$js='class="span12"';
									echo form_dropdown('termsID', $options, $preselstatus, $js);
								?>         
								</div> 
							</div>                      
							<div class="controls-row">
								<div class="span3"><?php echo $this->lang->line('creditLimit') ?></div>
								<div class="span4">
								<?php 								
								$data = array(
									'name'=>'creditLimit', 
									'id'=>'creditLimit', 
									'class'=>'span12 tar');
								if($customermaster){		
									echo form_input($data, number_format($customermaster->creditLimit,2)); 
								} else {
									echo form_input($data, set_value('creditLimit')); 
								} ?> 
								</div>
								<div class="span4">
									<label class="checkbox inline">
										<input type="checkbox" class="validate" name="creditLimitAlert" value="1" <?php if(isset($customermaster->creditLimitAlert) && $customermaster->creditLimitAlert==1 ): ?>checked="checked" <?php endif; ?>/>Credit Limit Alert</label>
								</div>
							</div>
							<div class="controls-row"> <!-- row 1 -->
								<div class="span3"><?php echo $this->lang->line('linkedAPAccountID') ?></div>
								<div class="span4">
								<?php
								//if($suppliermaster){	
									$preselacct = ($customermaster)?$customermaster->linkedAPAccountID:$defaultacct;	
									//$presellinkAP = $suppliermaster->linkedAPAccountID; 
								//} else {
									//$presellinkAP = ''; 
								// }                       
								$options = '';
								$options[] = '--Please Select--';
								if ($chartAccounts) 
									foreach($chartAccounts as $row){
										$options[$row->ID] = substr($row->acctCode,0, 4).'-'.substr($row->acctCode,4, 3).'-'.substr($row->acctCode,7, 2) . " [" . $row->acctName . "]";
									}
								$js='class="span12" id="linkedAPAccountID"';
									echo form_dropdown('linkedAPAccountID', $options, $preselacct, $js);
								?>       
								</div>
                                <div class="btn-group span1">
                                	<button class="btn-icon btn-small dropdown-toggle" data-toggle="dropdown">
                                    	<span class="i-arrow-down-2"></span>
                                    </button>
                                        <ul class="dropdown-menu">
                                        	<!-- dropdown menu links -->
                                            	<li><a target="_blank" href="<?php echo base_url() ?>glsetting/chartOfAcctCustomer"  id="btnNewChartOfAcct">
                                                	<i class="icon-plus-sign"></i> <?php echo $this->lang->line('addNewChartOfAcct')?></a></li>
                                                <li><a href="#" onclick="selectChartOfAcct()"><i class="icon-refresh"></i> <?php echo $this->lang->line('refreshlist')?></a></li>
                                        </ul>
                                </div><!-- btn group -->
							</div>  
							<div class="controls-row">
								<div class="span3"><?php echo $this->lang->line('createdDate') ?></div>
								<div class="span4">
									<div class="input-prepend span12">
										<span class="add-on span2"><i class="i-calendar"></i></span>
										<?php
										$data = array(
											'name' => 'createdDate',
											'id' => 'createdDate',
											'type' => 'text',
											'class' => 'datepicker2 span10 financhk',);
										if($customermaster){		
											echo form_input($data, date("d-m-Y", strtotime($customermaster->createdDate))); 
										} else {
											echo form_input($data, date("d-m-Y"));
										}  ?>
									</div>
								</div>    
							</div>    
							<div class="controls-row"> 
								<div class="span3"><?php echo $this->lang->line('currency') ?></div>
								<div class="span4">
								<?php
								if($customermaster){		
									$preselcurr = $customermaster->currencyID; 
								} else {
									$preselcurr = 1;
									}                       
								$options = '';
								$options[] = '--Please Select--';
									foreach($currency as $row){
										$options[$row->fldid] = $row->fldcurr_code . " [" . $row->fldcurr_desc . "]";
									}
								$js='class="span12"';
									echo form_dropdown('currencyID', $options, $preselcurr, $js);
								?>       
								</div> 
							</div>
						</div><!-- End Content-->
						<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'=>'mysubmit', 
									'class'=>'btn-form btn-success-form');
									echo form_submit($data,'Submit');
								?>
								</div>
							</div>
						</div>                                
						</form>
					</div><!-- block -->
				</div><!-- span12 -->
			</div><!-- row-fluid -->	
		
		</div><!-- content class -->
	</div><!-- wrap -->
</div><!-- content id -->
