<script type="text/javascript">
    $(document).ready(function(){
        <!-- page script -->
        $('.datatables').DataTable();
        $('.datetimepicker').datetimepicker({
            viewMode: 'months',
            format: 'DD/MM/YYYY'
        });
		

		
		
    });  

	function changeList(obj) {
        var id = obj.value;
		
        $.ajax({
            type: "POST",
            url: "<?php echo base_url() ?>setup/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("#stateID").empty();
                    jQuery("#stateID").append(items.join('</br>'));
                } else {
                    $("#error").html('<p>' + content.message + '</p>');
                }
            }
        });
        return false;
    }
	
	
	function editCompany(){
		alert($('#userfile').val());
		
		var postData = {
			'companyName' : $('#companyName').val(),
			'line1' : $('#line1').val(),
			'line2' : $('#line2').val(),
			'line3' : $('#line3').val(),
			'city' : $('#city').val(),
			'companyPostCode' : $('#companyPostCode').val(),
			'countryID' : $('#countryID option:selected').val(),
			'stateID' : $('#stateID option:selected').val(),
			'phoneNo' : $('#phoneNo').val(),
			'faxNo' : $('#faxNo').val(),
			'businessTypeID' : $('#businessTypeID option:selected').val(),
			'email' : $('#email').val(),
			'userfile' : $('#userfile').val(),
		};
		$.ajax({
			type: "POST",
			dataType: "json",
			url: "<?php echo base_url()?>setup/editCompany",
			data: postData ,
			success: function(content){
				if(content.status == "success") {
					alert('Data successfully saved');
				}
			}
		});
		
	}
	
	function back(){
		window.history.go(-1);
	}
	
	
</script>

			<div class="content-wrapper">
        		<!-- Content Header (Page header) -->
        		<section class="content-header">
          			<h1>
            			<?php echo $this->lang->line('title') ?>
            			<!--<small>advanced tables</small>-->
          			</h1>
                    <ol class="breadcrumb">
                        <li><a href="#"><i class="fa fa-home"></i> <?php echo $this->lang->line('home'); ?></a></li>
                        <li><a href="#"><?php echo $this->lang->line('module'); ?></a></li>
                        <li class="active"><?php echo $this->lang->line('title'); ?></li>
                        <li class="active"><?php echo $this->lang->line('addCompany'); ?></li>
                    </ol>
        		</section>

                <!-- Main content -->
                <section class="content">
                  <div class="row">
                    <div class="col-xs-12">
        			
                    <form action="" method="POST" enctype="multipart/form-data">
        
        			  <div class="box box-primary">
                        <div class="box-header with-border">
                          <h3 class="box-title"><?php echo $this->lang->line('addCompany'); ?></h3>
                        </div><!-- /.box-header -->
                        
                          <div class="box-body">
                            <div class="form-group col-sm-12">
                              <label class="col-sm-2 control-label"><?php echo $this->lang->line('companyName');?></label>
                              <div class="col-sm-8">
                                <?php
									$data = array(
										'id' => 'companyName',
										'name' => 'companyName',
										'class' => 'form-control validate[required,maxSize[128]]',);
										echo form_input($data, set_value('companyName'));
									
                                ?>
                              </div>
                            </div>
                          </div>
                          
                          <div class="box-body">
                            <div class="form-group col-sm-12">
                              <label class="col-sm-2 control-label"><?php echo $this->lang->line('companyAddress');?></label>
                              <div class="col-sm-8">
                                <?php
                                	$data = array(
										'id' => 'line1',
										'name' => 'line1',
                                    	'class' => 'form-control validate[required,maxSize[128]]',);
										echo form_input($data, set_value('line1'));
										
                                ?>
                              </div>
                            </div>
                          </div>
                          
                          <div class="box-body">
                            <div class="form-group col-sm-12">
                              <label class="col-sm-2 control-label"></label>
                              <div class="col-sm-8">
                                <?php
                                	$data = array(
										'id' => 'line2',
										'name' => 'line2',
                                    	'class' => 'form-control validate[required,maxSize[128]]',);
										echo form_input($data, set_value('line2'));
										
                                ?>
                              </div>
                            </div>
                          </div>
                          
                          <div class="box-body">
                            <div class="form-group col-sm-12">
                              <label class="col-sm-2 control-label"></label>
                              <div class="col-sm-8">
                                <?php
                                	$data = array(
										'id' => 'line3',
										'name' => 'line3',
                                    	'class' => 'form-control',);
										echo form_input($data, set_value('line3'));
										
                                ?>
                              </div>
                            </div>
                          </div>
                          
                          <div class="box-body">
                            <div class="form-group col-sm-12">
                              <label class="col-sm-2 control-label"><?php echo $this->lang->line('city');?></label>
                              <div class="col-sm-3">
                                <?php
									$data = array(
										'name' => 'city',
										'id' => 'city',
										'class' => 'form-control',);
										echo form_input($data, set_value('city'));
										
                                ?>
                              </div>
                              <label class="col-sm-1 control-label"><?php echo $this->lang->line('companyPostCode');?></label>
                              <div class="col-sm-3">
                                <?php
                                	$data = array(
										'name' => 'companyPostCode',
										'id' => 'companyPostCode',
										'class' => 'form-control',);
										echo form_input($data, set_value('companyPostCode'));
										
                                 ?>
                              </div>
                            </div>
                          </div>
                          
                          <div class="box-body">
                            <div class="form-group col-sm-12">
                              <label class="col-sm-2 control-label"><?php echo $this->lang->line('country');?></label>
                              <div class="col-sm-3">
                                <?php
									$preselcat = '';
									$options[NULL] = "--Please Select--";
										foreach ($country as $row) {
											$options[$row->fldid] = $row->fldcountry;
											}
											$js = 'onChange="changeList(this)" class="form-control select2" id="countryID"';
												echo form_dropdown('countryID', $options, $preselcat, $js);
								?>
                              </div>
                              <label class="col-sm-1 control-label"><?php echo $this->lang->line('state');?></label>
                              <div class="col-sm-3">
                                <?php
									$preselcat2 = '';
									$options2[NULL] = "--Please Select--";
									if ($state != '') {
										foreach ($state as $row) {
											$options2[$row->fldid] = $row->fldname;
											}
										}
										$js = 'id=stateID class="form-control select2"';
											echo form_dropdown('stateID', $options2, $preselcat2, $js);
                                ?>
                              </div>
                            </div>
                          </div>
                          
                          <div class="box-body">
                            <div class="form-group col-sm-12">
                              <label class="col-sm-2 control-label"><?php echo $this->lang->line('phoneNo');?></label>
                              <div class="col-sm-3">
                                <?php
									$data = array(
										'id' => 'phoneNo',
    									'class' => 'form-control',
    									'name' => 'phoneNo',);
										echo form_input($data, set_value('phoneNo'));
										
										
								?>
                              </div>
                              
                              <label class="col-sm-1 control-label"><?php echo $this->lang->line('faxNo');?></label>
                              <div class="col-sm-3">
                                <?php
									$data = array(
										'id' => 'faxNo',
    									'class' => 'form-control',
    									'name' => 'faxNo',);
										echo form_input($data, set_value('faxNo'));
										
								?>
                              </div>
                            </div>
                          </div>
                          
                          <div class="box-body">
                            <div class="form-group col-sm-12">
                              <label class="col-sm-2 control-label"><?php echo $this->lang->line('typeOfBusiness');?></label>
                              <div class="col-sm-3">
                              <?php
                                $preselTypeOfBussiness = '';
								$options3[NULL] = "--Please Select--";
                                if ($businessType != '') {
									foreach ($businessType as $row) {
										$options3[$row->ID] = $row->name;
                                        }
									}
                                    $js = 'id=businessTypeID class="form-control select2"';
									echo form_dropdown('businessTypeID', $options3, $preselTypeOfBussiness, $js);
                                ?>
                              </div><!-- /.form-group -->
                              <label class="col-sm-1 control-label"><?php echo $this->lang->line('email');?></label>
                              <div class="col-sm-3">
                                <?php
									$data = array(
										'id' => 'email',
    									'class' => 'form-control',
    									'name' => 'email',);
										echo form_input($data, set_value('email'));
										
								?>
                              </div>
                            </div>
                          </div>
                          
                          <div class="box-body">
                            <div class="form-group col-sm-12">
                              <label class="col-sm-2 control-label"><?php echo $this->lang->line('uploadLogo');?></label>
                              <div class="col-sm-3">
                              <?php
                                $data = array(
									'name' => 'userfile',
                                    'id' => 'userfile',
                                    'type ' => 'file',
                                    'value' => '');
										echo form_upload($data, set_value('userfile'));
                                ?>
                              </div><!-- /.form-group -->
                              <div class="col-sm-3">
                              <?php if (isset($company)) { ?>
                              		<div class="pic" align="center">
                                    	<a class="fancybox" href="<?php echo base_url().'dist/companyProfile/'.$comID.'.jpg' ?>">
                                        <?php
											if($comID != NULL){ ?>
												<img class="img-polaroid" src="<?php echo base_url().'dist/companyProfile/'.$comID.'.jpg'; ?>" width="50%"/>
                                    		<?php } ?>
										</a>
									</div>
                              <?php } ?>
                              </div><!-- /.form-group -->
                            </div>
                          </div>
                          
                          <div class="box">
                        	<div class="box-header with-border">
                            	<div class="box-title pull-right">
                            		<div class="btn pull-right">
										<button type="button" onclick="back()" class="btn btn-primary" ><?php echo $this->lang->line('back'); ?></button>
										<?php
                                        $data = array(
                                            'name'=>'mysubmit', 
                                            'class'=>'btn btn-primary');
                                        $js='onclick="return confirm(\'Press OK to continue...\')"';
                                            //$js='onclick="submitForm()"';
                                            echo form_submit($data,$this->lang->line('submit'), $js);
                                        ?>
								</div>
                        		</div>
                            </div>
                          </div><!-- /.box-header -->
                          
                        
                      </div>
        
        </form>
                      
                        
                      </div><!-- /.box -->
                    </div><!-- /.col -->
                  </div><!-- /.row -->
                </section><!-- /.content -->
                
              </div><!-- /.content-wrapper -->