<?php if(isset($language)): ?> 
<div id="link-field-<?php echo $id; ?>" class="form-field-link form-group form-language-group form-language-<?php echo $language; ?><?php echo $language == $defaultLang ? ' default-lang' : ''; ?><?php echo (isset($hasErrors) && $hasErrors ? ' has-group-error' : ''); ?><?php echo $parentHidden ? ' parent-hidden' : ''; ?>" style="<?php echo !empty($hide) ? 'display:none' : ''; ?>">
<?php else: ?>
<div id="link-field-<?php echo $id; ?>" class="form-group <?php echo $hasErrors ? ' has-group-error' : ''; ?><?php echo $parentHidden ? ' parent-hidden' : ''; ?>" style="<?php echo !empty($hide) ? 'display:none' : ''; ?>">
<?php endif; ?>
    <?php echo Form::label($id, ucfirst($label), array('class' => 'control-label')); ?>

    <div class="well">    
        <div class="row">
            <div class="col-sm-8">    
                <div class="form-group <?php echo (isset($errors) && $errors->has($errorKey . '.label') ? ' has-error' : ''); ?>">
                    <?php echo Form::text($name . '[label]', $linkLabel, array(
                    'id' => $id . '_label', 
                    'class' => 'form-control' . (isset($language) && $language == $defaultLang ? ' default-lang' : ''), 
                    'maxlength' => $maxLength,
                    'data-toggle' => (isset($errors) && $errors->has($errorKey . '.label') ? 'tooltip': null),
                    'title' => (isset($errors) && $errors->has($errorKey . '.label') ? $errors->first($errorKey . '.label'): null),
                    'disabled' => $enabled ? null : 'disabled',
                    'placeholder' => Lang::get('backend.insert_link_label')
                    )); ?>    
                </div>
            </div>      
            <div class="col-sm-4">
                <div class="form-group">
                    <label class="checkbox-inline">
                    <?php echo Form::checkbox($name . '[isExternal]', 'true', $isExternal, array(
                    'id' => $id . '_isExternal',
                    'class' => 'is-external-checkbox',
                    'disabled' => $enabled ? null : 'disabled'
                    )); ?>

                        <b><?php echo Lang::get('backend.external_link'); ?></b>
                    </label>
                </div>
            </div>
        </div>            
        <div class="internal-link-chooser">
            <?php echo Form::hidden($name . '[selectedObjectId]', $selectedObjectId, array(
                    'id' => $id . '_selectedObjectId',
                    'class' => 'selected-object-id'
                    )); ?> 
            <div class="row select-object" <?php echo (isset($errors) && $errors->has($errorKey . '.selectedObjectId') ? 'data-toggle="tooltip" title="' . $errors->first($errorKey . '.selectedObjectId') . '"': null); ?> >
                <div class="col-sm-8 object-placeholder">
                </div>
                <div class="col-sm-4">
                    <button type="button" class="btn btn-default command-choose-object">
                        <span><?php echo Lang::get('backend.select_object'); ?></span>
                    </button>    
                </div>   
            </div>            
            <div class="row object-list-picker" <?php echo $isExternal ? 'style="display: none;"' : ''; ?>>
                <div class="col-sm-8 multiple-picker-wrapper">
                    <div class="panel panel-default">
                        <div class="panel-heading">
                            <?php echo ucfirst(Lang::get("backend.select_link_object")); ?>

                        </div>
                        <div class="panel-body multiple-picker-list multiple-picker-unpicked-list">
                            <div class="panel panel-default picker-panel">
                                <ol class="list-group"></ol>  
                            </div>
                        </div>
                    </div>
                </div>       
                <div class="col-sm-4">
                    <button type="button" class="btn btn-default command-cancel-select">
                        <span><?php echo Lang::get('backend.cancel'); ?></span>
                    </button>    
                </div>
            </div>
        </div>                   
        <div class="row external-link-chooser" <?php echo !$isExternal ? 'style="display: none;"' : ''; ?>>
            <div class="col-sm-8">
                <div class="form-group <?php echo (isset($errors) && $errors->has($errorKey . '.url') ? ' has-error' : ''); ?>">
                    <?php echo Form::text($name . '[url]', $linkUrl, array(
                    'id' => $id . '_label', 
                    'class' => 'form-control' . (isset($language) && $language == $defaultLang ? ' default-lang' : ''), 
                    'data-toggle' => (isset($errors) && $errors->has($errorKey . '.url') ? 'tooltip': null),
                    'title' => (isset($errors) && $errors->has($errorKey . '.url') ? $errors->first($errorKey . '.url'): null),
                    'disabled' => $enabled ? null : 'disabled',
                    'placeholder' => Lang::get('backend.insert_link_url')
                    )); ?>

                </div>    
            </div>
        </div>
    </div>
    <?php if(!empty($info)): ?>
        <span id="helpBlock" class="help-block"><?php echo $info; ?></span>
    <?php endif; ?>
</div>

<script>          
    $(function(){   
        var linkField_<?php echo $id; ?> = new Eae.View.BackendLinkField({
            el: $("#link-field-<?php echo $id; ?>"),
            fullList: <?php echo json_encode($fullList); ?>,
            isExternal: <?php echo $isExternal ? 'true' : 'false'; ?>,
            disabled: <?php echo $enabled ? 'false': 'true'; ?>,
            parent:  <?php echo empty($parent) ? 'false': json_encode($parent); ?>,
            <?php if(isset($language)): ?>
                language: '<?php echo $language; ?>'
            <?php endif; ?>
        });    
    });       
</script>