<script type="text/javascript">
    $(document).ready(function () {
        $('#form').validate(
            {
                rules: {
                    nombre: {
                        required: true
                    },
                    razon_social: {
                        required: true
                    },
                    cuit: {
                        required: true
                    }
                },
                focusCleanup: false,

                highlight: function (label) {
                    $(label).closest('.control-group').removeClass('success').addClass('error');
                },
                success: function (label) {
                    label
                        .text('OK!').addClass('valid')
                        .closest('.control-group').addClass('success');
                },
                errorPlacement: function (error, element) {
                    error.appendTo(element.parents('.controls'));
                }
            });
        <?php $this->load->view('partials/script_edit.php'); ?>
    }); // end document.ready
</script>
<form action="<?php echo $action ?>" id="form" method="POST" enctype="multipart/form-data" class="form-horizontal"
      novalidate="novalidate">
    <input type="hidden" id="id" name="id" value="<?php echo (isset($row->id)) ? $row->id : "0"; ?>"/>
    <div id="page-title" class="clearfix">
        <span
            style="font-size:24px;font-weight:bold;float:left;margin-top:5px;"><?php echo (isset($row->id)) ? $dir2 : $dir1; ?></span>
        <div class="item-content" style="float:right;">
            <button type="submit" class="btn btn-inverse">Guardar</button>
            <button class="btn cancel">Cancelar</button>
        </div>
    </div> <!-- /.page-title -->
    <div class="row">
        <div class="span12">
            <div id="validation" class="widget highlight widget-form">
                <div class="widget-content">
                    <fieldset>

                        <?php //echo (isset($message))?$message:'';?>

                        <div class="control-group">
                            <label class="control-label" for="nombre">Nombre</label>
                            <div class="controls">
                                <?php $nombre = (isset($row->nombre)) ? $row->nombre : ''; ?>
                                <input type="text" class="input-xxlarge" name="nombre" id="nombre"
                                       value="<?php echo set_value('nombre', $nombre); ?>">
                            </div>
                        </div>

                        <div class="control-group">
                            <label class="control-label" for="razon_social">Raz&oacute;n social</label>
                            <div class="controls">
                                <?php $razon_social = (isset($row->razon_social)) ? $row->razon_social : ''; ?>
                                <input type="text" class="input-xxlarge" name="razon_social" id="razon_social"
                                       value="<?php echo set_value('razon_social', $razon_social); ?>">
                            </div>
                        </div>

                        <div class="control-group">
                            <label class="control-label" for="cuit">C.U.I.T.</label>
                            <div class="controls">
                                <?php $cuit = (isset($row->cuit)) ? $row->cuit : ''; ?>
                                <input type="text" class="input-xxlarge" name="cuit" id="cuit"
                                       value="<?php echo set_value('cuit', $cuit); ?>">
                            </div>
                        </div>

                        <div class="control-group">
                            <label class="control-label" for="condicion_iva">Condici&oacute;n I.V.A.</label>
                            <div class="controls">
                                <?php $condicion_iva = (isset($row->condicion_iva)) ? $row->condicion_iva : ''; ?>
                                <input type="text" class="input-xxlarge" name="condicion_iva" id="condicion_iva"
                                       value="<?php echo set_value('condicion_iva', $condicion_iva); ?>">
                            </div>
                        </div>

                        <div class="control-group">
                            <label class="control-label" for="telefono">Tel&eacute;fono</label>
                            <div class="controls">
                                <?php $telefono = (isset($row->telefono)) ? $row->telefono : ''; ?>
                                <input type="text" class="input-xxlarge" name="telefono" id="telefono"
                                       value="<?php echo set_value('telefono', $telefono); ?>">
                            </div>
                        </div>

                        <div class="control-group">
                            <label class="control-label" for="domicilio_legal">Domicilio legal</label>
                            <div class="controls">
                                <?php $domicilio_legal = (isset($row->domicilio_legal)) ? $row->domicilio_legal : ''; ?>
                                <input type="text" class="input-xxlarge" name="domicilio_legal" id="domicilio_legal"
                                       value="<?php echo set_value('domicilio_legal', $domicilio_legal); ?>">
                            </div>
                        </div>

                        <div class="control-group">
                            <label class="control-label" for="domicilio_fiscal">Domicilio fiscal</label>
                            <div class="controls">
                                <?php $domicilio_fiscal = (isset($row->domicilio_fiscal)) ? $row->domicilio_fiscal : ''; ?>
                                <input type="text" class="input-xxlarge" name="domicilio_fiscal" id="domicilio_fiscal"
                                       value="<?php echo set_value('domicilio_fiscal', $domicilio_fiscal); ?>">
                            </div>
                        </div>

                        <div class="control-group">
                            <label class="control-label" for="localidad">Localidad</label>
                            <div class="controls">
                                <?php $localidad = (isset($row->localidad)) ? $row->localidad : ''; ?>
                                <input type="text" class="input-xxlarge" name="localidad" id="localidad"
                                       value="<?php echo set_value('localidad', $localidad); ?>">
                            </div>
                        </div>

                        <div class="control-group">
                            <label class="control-label" for="web">Sitio web</label>
                            <div class="controls">
                                <?php $web = (isset($row->web)) ? $row->web : ''; ?>
                                <input type="text" class="input-xxlarge" name="web" id="web"
                                       value="<?php echo set_value('web', $web); ?>">
                            </div>
                        </div>

                        <div class="control-group">
                            <label class="control-label" for="email">E-Mail</label>
                            <div class="controls">
                                <?php $email = (isset($row->email)) ? $row->email : ''; ?>
                                <input type="text" class="input-xxlarge" name="email" id="email"
                                       value="<?php echo set_value('email', $email); ?>">
                            </div>
                        </div>

                        <div class="control-group">
                            <label class="control-label" for="logo">Logo</label>
                            <div class="controls">
                                <input class="input-file" id="logo" type="file" name="logo" value="" />
                                <p class="help-block">gif|jpg|jpeg|png</p>
                            </div>
                        </div>
                        <?php if (isset($row->logo) && ($row->logo != "")) { ?>
                            <script type="text/javascript">
                                $(document).ready(function () {
                                    $(function () {
                                        var timeout = '';

                                        $('.gallery').find('.frame').append('<img src="<?php echo base_url(AADMINPATH . 'img/gallery/frame.png');?>" alt="Frame" />');

                                        $('.gallery li').live('mouseenter', function (e) {
                                            var $this = $(this);

                                            timeout = setTimeout(function () {
                                                $this.find('.actions').fadeIn();
                                                $this.find('.img img').animate({opacity: '.35'});
                                            }, 550);

                                        }).live('mouseleave', function (e) {
                                            clearTimeout(timeout);

                                            $(this).find('.actions').hide();
                                            $(this).find('.img img').animate({opacity: '1'});
                                        });
                                    });
                                });
                            </script>
                            <div class="control-group">
                                <ul class="gallery">
                                    <li>
                                        <div class="frame">
                                            <div class="img">
                                                <img
                                                    src="<?php echo base_url('assets/archivos/' . $dir . '/logos/' . $row->logo); ?>"
                                                    alt="" style="opacity: 1; ">
                                            </div> <!-- /img -->

                                            <div class="actions" style="display: none; ">
                                                <a href="<?php echo base_url('admin/' . $dir . '/eliminar_img/' . $row->id); ?>"
                                                   id="eliminar" class="edit">
                                                    <i class="icon-remove"></i>
                                                </a>
                                                <a href="<?php echo base_url('assets/archivos/' . $dir . '/logos/' . $row->logo); ?>"
                                                   class="zoom ui-lightbox ui-lightbox">
                                                    <i class="icon-search"></i>
                                                </a>
                                            </div> <!-- /actions -->
                                            <img src="<?php echo base_url(AADMINPATH . 'img/gallery/frame.png'); ?>"
                                                 alt="Frame">
                                        </div> <!-- /frame -->
                                    </li>
                                </ul>
                            </div>
                        <?php } ?>

                        <div class="control-group">
                            <label class="control-label">Habilitado</label>
                            <div class="controls">
                                <?php
                                $habilitado = (isset($row->habilitado)) ? $row->habilitado : '1';
                                $si = ($habilitado == 1) ? TRUE : FALSE;
                                $no = ($habilitado == 0) ? TRUE : FALSE;
                                ?>
                                <label class="radio">
                                    <input type="radio" name="habilitado" id="si"
                                           value="1" <?php echo set_radio('habilitado', '1', $si); ?>>
                                    Si
                                </label>
                                <label class="radio">
                                    <input type="radio" name="habilitado" id="no"
                                           value="0" <?php echo set_radio('habilitado', '0', $no); ?>>
                                    No
                                </label>
                            </div>
                        </div>

                        <div class="form-actions">
                            <button type="submit" class="btn btn-inverse">Guardar</button>
                            <button class="btn cancel">Cancelar</button>
                        </div>
                    </fieldset>
                </div>
            </div>
        </div>
    </div>
</form>
<?php if (isset($row->id)) { ?>
    <div id="sucursales"></div>
    <script type="text/javascript">
        $(document).ready(function () {
            $("#sucursales").load("<?php echo base_url('admin/empresas/sub_index/' . $row->id)?>");
        });
    </script>
<?php } ?>