<form class="form-horizontal" id="user_basic_data">
    <div class="ibox float-e-margins">
        <div class="ibox-content">
            <div class="col-lg-6">
                <div class="form-group">
                    <label class="col-lg-3 control-label" style="text-align: left;">Name</label>
                    <div class="col-lg-8">
                        <input placeholder="Name" class="form-control pull-left name" type="text" name="name" value="<?php echo !empty($user_details->name) ? $user_details->name : '';?>"> 
                        <!-- <span class="help-block m-b-none">Example block-level help text here.</span> -->
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-lg-3 control-label" style="text-align: left;">Company</label>
                    <div class="col-lg-8">
                        <input placeholder="Company Name" class="form-control pull-left company_name" type="text" name="company_name" value="<?php echo !empty($user_details->company_name) ? $user_details->company_name : '';?>">
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-lg-3 control-label" style="text-align: left;">Contact Display</label>
                    <div class="col-lg-8">
                        <input placeholder="Display Name" class="form-control pull-left contact_display_name" type="text" name="contact_display_name" value="<?php echo !empty($user_details->contact_display_name) ? $user_details->contact_display_name : '';?>">
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-lg-3 control-label" style="text-align: left;">Email</label>
                    <div class="col-lg-8">
                        <input placeholder="Email" class="form-control pull-left contact_email" type="email" name="contact_email" value="<?php echo !empty($user_details->contact_email) ? $user_details->contact_email : '';?>">
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-lg-3 control-label" style="text-align: left;">Phone</label>
                    <div class="col-lg-8">
                        <input placeholder="Phone" class="form-control pull-left contact_phone" type="text" name="contact_phone" value="<?php echo !empty($user_details->contact_phone) ? $user_details->contact_phone : '';?>">
                    </div>
                </div>
                
            </div>
            <div class="col-lg-6">
                <!--<div class="form-group">-->
                <!--    <label class="col-lg-3 control-label" style="text-align: left;">Website</label>-->
                <!--    <div class="col-lg-8">-->
                <!--        <input placeholder="Website" class="form-control pull-left contact_website" type="text" name="contact_website" value="<?php echo !empty($user_details->contact_website) ? $user_details->contact_website : '';?>">-->
                <!--    </div>-->
                <!--</div>-->
                <!--<div class="form-group">-->
                <!--    <label class="col-lg-4 control-label pull-left" style="text-align: left;">Has GST Number</label>-->
                <!--    <div class="col-lg-8">-->
                <!--        <input type="checkbox" class="i-checks has_gst" name="has_gst" value="<?php echo !empty($user_details->has_gst) ? $user_details->has_gst : '0';?>" <?php echo !empty($user_details->has_gst) && ($user_details->has_gst==1) ? 'checked=""' : '';?>>-->
                <!--    </div>-->
                <!--</div>-->
                <div class="form-group gstn_block <?php echo !empty($user_details->has_gst) && ($user_details->has_gst==1) ? '' : 'hide';?>">
                    <label class="col-lg-3 control-label" style="text-align: left;">GST Number</label>
                    <div class="col-lg-8">
                        <input placeholder="GST No." class="form-control pull-left gstn" type="text" name="gstn" value="<?php echo !empty($user_details->gstn) ? $user_details->gstn : '';?>">
                    </div>
                </div>
                <div class="form-group hide">
                    <label class="col-lg-3 control-label" style="text-align: left;">Contact Type</label>
                    <div class="col-lg-8">
                        <!-- <input placeholder="Phone" class="form-control pull-left contact_type" type="text" name="contact_type" value=""> -->
                        <select class="form-control pull-left contact_type" name="contact_type">
                            <option value="2" selected="selected">Vendor</option>
                        </select>
                    </div>
                </div>
            </div>
        </div>
    </div>

  
    <div class="ibox float-e-margins">
        <div class="ibox-content">
            <div class="form-group">
                
                <div class="col-lg-3">
                    <button class="btn btn-sm btn-primary pull-right m-t-n-xs save_userData" type="submit"><strong>Save Data</strong></button>
                </div>
            </div>
        </div>
    </div>
</form>
<script type="text/javascript">
    $(document).ready(function () {
        $('.i-checks').iCheck({
            checkboxClass: 'icheckbox_square-green'
        });

        $('.has_gst').on('ifChecked', function(){
            $(this).val('1');
            $('.gstn_block').removeClass('hide');
        });

        $('.has_gst').on('ifUnchecked', function(){
            $(this).val('0');
           $('.gstn_block').addClass('hide'); 
        });

        $('.same_billing_shipping').on('ifChecked', function(){
            $(this).val('1');
            $("#shipping_block :input").attr("disabled", true);
        });

        $('.same_billing_shipping').on('ifUnchecked', function(){
            $(this).val('0');
           $("#shipping_block :input").attr("disabled", false);
        });

        
        $( "#user_basic_data" ).on( "submit", function( event ) {
            event.preventDefault();
            
            if ($('.name').val() == '') {
                $('.name').parent().parent().addClass('has-error');
                return false;
            } else {
                $('.name').parent().parent().removeClass('has-error');
            }

            // if ($('.company_name').val() == '') {
            //     $('.company_name').parent().parent().addClass('has-error');
            //     return false;
            // } else {
            //     $('.company_name').parent().parent().removeClass('has-error');
            // }

            if ($('.contact_display_name').val() == '') {
                $('.contact_display_name').parent().parent().addClass('has-error');
                return false;
            } else {
                $('.contact_display_name').parent().parent().removeClass('has-error');
            }

           /* if ($('.contact_email').val() == '') {
                $('.contact_email').parent().parent().addClass('has-error');
                return false;
            } else {
                $('.contact_email').parent().parent().removeClass('has-error');
            } */

            // if ($('.contact_phone').val() == '') {
            //     $('.contact_phone').parent().parent().addClass('has-error');
            //     return false;
            // } else {
            //     $('.contact_phone').parent().parent().removeClass('has-error');
            // } 

           /* if ($('.contact_website').val() == '') {
                $('.contact_website').parent().parent().addClass('has-error');
                return false;
            } else {
                $('.contact_website').parent().parent().removeClass('has-error');
            }   */
            
            // if ($('.has_gst').val() == '') {
            //     $('.has_gst').parent().parent().addClass('has-error');
            //     return false;
            // } 

            // if (($('.has_gst').val() == 1) && ($('.gstn').val() == '')) {
            //     $('.gstn').parent().parent().addClass('has-error');
            //     return false;
            // } else {
            //     $('.gstn').parent().parent().removeClass('has-error');
            // }  

            if ($('.contact_type').val() == '') {
                $('.contact_type').parent().parent().addClass('has-error');
                return false;
            } else {
                $('.contact_type').parent().parent().removeClass('has-error');
            }   

            var user_id = '<?php echo $user_id;?>';

            var name = $('.name').val();
            var company_name = $('.company_name').val();
            var contact_display_name = $('.contact_display_name').val();
            var contact_email = $('.contact_email').val();
            var contact_phone = $('.contact_phone').val();
         
            var contact_type = $('.contact_type').val();

           
            $.ajax({
                url: '<?php echo site_url('user/save_worker_basic_info');?>',
                type: "POST",
                data:{
                    user_id : user_id,
                    name : name,
                    company_name : company_name,
                    contact_display_name : contact_display_name,
                    contact_email : contact_email,
                    contact_phone : contact_phone,
                    contact_type : contact_type
                },
                success: function(data){ 
                    if (user_id == 0) {
                       // window.location.href = '<?php //echo site_url("user/newworker/'+data+'");?>'; 
                        window.location.href = '<?php echo site_url("user/workerlist");?>';
                    } else {
                        window.location.href = '<?php echo site_url('user');?>';
                    }
                }
            });

        });

    });
</script>