<div class="col-lg-10 col-md-10 col-sm-10 col-xs-10 bodyitem">
    <div class="row no-padding">
        <fieldset>
            <ul id="HomePageFormError" class="error_message_box"></ul>
            <?php $action = 'gkpos/online/save_home' ?>
            <?php echo form_open($action, array('id' => 'HomePageForm', 'enctype' => 'multipart/form-data', 'class' => 'form-horizontal')); ?>
            <div class="form-group">
                <?php echo form_label('Homeage Title', 'title', array('class' => 'col-sm-2 control-label required')); ?>
                <div class="col-sm-6">
                    <?php echo form_input(array('name' => 'title', 'id' => 'title', 'class' => 'form-control input-sm required', 'value' => isset($home[0]->title) ? $home[0]->title : '')) ?>
                </div>
            </div>
            <input type='hidden' name='slug' value='home'>
            <div class="form-group">
                <?php echo form_label('Homepage Image', 'image', array('class' => 'col-sm-2 control-label')); ?>
                <div class="col-sm-6">
                    <div class="fileinput-preview fileinput-exists thumbnail" style="max-width: 95px; max-height: 75px;">
                        <img data-src="holder.js/100%x100%" alt='Page Main Image'
                             src="<?php
                             if (!isset($home[0]->image))
                                 echo '';
                             else
                                 echo UPLOAD_PATH . 'page/' . $home[0]->image;
                             ?>"
                             style="max-height: 100%; max-width: 100%;">
                    </div>
                    <div>
                        <span class="btn btn-default btn-sm btn-file">
                            <input type="file" name="image">
                        </span>
                    </div>
                </div>
            </div>
            <div class="form-group">
                <?php echo form_label('Homepage Content', 'content', array('class' => 'col-sm-2 control-label')) ?>
                <div class="col-sm-6">
                    <?php echo form_textarea(array('name' => 'content', 'rows' => 3, 'id' => 'desc', 'class' => 'form-control input-sm required'), isset($home[0]->content) ? $home[0]->content : '') ?>
                </div>
            </div>  
            <hr/>
            <div class="form-group">
                <?php echo form_label('Meta Keywords', 'meta_keys', array('class' => 'col-sm-2 control-label')) ?>
                <div class="col-sm-6">
                    <?php echo form_input(array('name' => 'meta_keys', 'id' => 'meta_desc', 'class' => 'form-control input-sm', 'value' => isset($home[0]->meta_keys) ? $home[0]->meta_keys : '')) ?>
                </div>
            </div>
            <div class="form-group">
                <?php echo form_label('Meta Description', 'meta_keys', array('class' => 'col-sm-2 control-label')) ?>
                <div class="col-sm-6">
                    <?php echo form_textarea(array('name' => 'meta_desc', 'rows' => 3, 'id' => 'meta_desc', 'class' => 'form-control input-sm'), isset($home[0]->meta_desc) ? ($home[0]->meta_desc) : '') ?>
                </div>
            </div>  
            <div class="form-group">
                <div class="col-sm-offset-2 col-sm-6">
                    <input class="btn btn-block btn-danger round btn-sm" type="submit" name="submit_form" value="Save Homepage Information" onclick="saveHomePageInfo('HomePageForm', 'HomePageFormError')">
                </div>
            </div>
            <?php echo form_close(); ?>  
        </fieldset>
    </div>
</div>
<script type='text/javascript'>
    function saveHomePageInfo(formId, error_message_box) {
        
        $('#' + formId).validate({
            submitHandler: function () {
                var myform = document.getElementById(formId);
                var formdata = new FormData(myform);
                $.ajax({
                    url: $('#' + formId).attr('action'),
                    data: formdata,
                    cache: false,
                    processData: false,
                    contentType: false,
                    type: 'POST',
                    dataType: 'json',
                    beforeSend: function () {
                        $("#waitingAjaxLoading").show();
                    },
                    success: function (response) {
                        if (response.success) {
                            ALERT_TITLE = "Sucess!";
                            alert('Homepage Saved Successfully')
                        } else {
                            alert('Homepage Saved failed')
                        }
                    },
                });
            },
            errorClass: "has-error",
            errorLabelContainer: "#" + error_message_box,
            wrapper: "li",
            highlight: function (e) {
                $(e).closest('.form-group').addClass('has-error');
            },
            unhighlight: function (e) {
                $(e).closest('.form-group').removeClass('has-error');
            },
            rules: {
                title: {
                    required: true
                },
                content: {
                    required: true
                }
            },
            messages: {
                title: "Home Page Title is a required Field",
                content: "Please provide Home page content as well"
            }
        });
    }
</script>