/**
     * Output the metabox
     */
    public static function output($post, $args = array())
    {
        global $wpdb, $thepostid;
        $original_post = $post;
        $original_thepostid = $thepostid;
        // Used in the scenario where this meta box isn't used on the property edit page
        if (isset($args['args']['property_post'])) {
            $post = $args['args']['property_post'];
            $thepostid = $post->ID;
            setup_postdata($post);
        }
        $parent_post = false;
        if (isset($_GET['post_parent']) && $_GET['post_parent'] != '') {
            $parent_post = $_GET['post_parent'];
        }
        echo '<div class="propertyhive_meta_box">';
        echo '<div class="options_group">';
        //TODO: Get the departments being used from the plugin settings and only display them options
        $departments = array();
        if (get_option('propertyhive_active_departments_sales') == 'yes') {
            $departments['residential-sales'] = __('Residential Sales', 'propertyhive');
        }
        if (get_option('propertyhive_active_departments_lettings') == 'yes') {
            $departments['residential-lettings'] = __('Residential Lettings', 'propertyhive');
        }
        if (get_option('propertyhive_active_departments_commercial') == 'yes') {
            $departments['commercial'] = __('Commercial', 'propertyhive');
        }
        if ($parent_post !== FALSE || isset($post->post_parent) && $post->post_parent != '' && $post->post_parent != 0) {
            unset($departments['residential-sales']);
            unset($departments['residential-lettings']);
        } else {
            // Make sure property doesn't have any children
            $args = array('post_parent' => $post->ID, 'post_type' => 'property', 'posts_per_page' => 1);
            $unit_query = new WP_Query($args);
            if ($unit_query->have_posts()) {
                unset($departments['residential-sales']);
                unset($departments['residential-lettings']);
            }
            wp_reset_postdata();
        }
        $value = get_post_meta($post->ID, '_department', TRUE);
        if ($parent_post !== FALSE) {
            $value = get_post_meta($parent_post, '_department', TRUE);
        }
        if ($value == '') {
            $value = get_option('propertyhive_primary_department');
        }
        $args = array('id' => '_department', 'label' => 'Department', 'value' => $value, 'options' => $departments);
        if (count($departments) == 1) {
            foreach ($departments as $key => $value) {
                $args['value'] = $key;
            }
        }
        propertyhive_wp_radio($args);
        echo '
        <script>
            
            jQuery(document).ready(function()
            {
                //showHideDepartmentMetaBox();
                
                jQuery(\'input[type=\\\'radio\\\'][name=\\\'_department\\\']\').change(function()
                {
                     showHideDepartmentMetaBox();
                });
            });
            
            function showHideDepartmentMetaBox()
            {
                 jQuery(\'#propertyhive-property-residential-sales-details\').hide();
                 jQuery(\'#propertyhive-property-residential-lettings-details\').hide();
                 jQuery(\'#propertyhive-property-commercial-details\').hide();

                 var selectedDepartment = jQuery(\'input[type=\\\'radio\\\'][name=\\\'_department\\\']:checked\').val();
                 
                 jQuery(\'#propertyhive-property-\' + selectedDepartment + \'-details\').show();

                 if (selectedDepartment == \'commercial\')
                 {
                    jQuery(\'#propertyhive-property-residential-details\').hide();
                 }
                 else
                 {
                    jQuery(\'#propertyhive-property-residential-details\').show();
                 }
            }
            
        </script>';
        do_action('propertyhive_property_department_fields');
        echo '</div>';
        echo '</div>';
        $post = $original_post;
        $thepostid = $original_thepostid;
        setup_postdata($post);
    }
    /**
     * Output the metabox
     */
    public static function output($post)
    {
        global $post, $wpdb, $thepostid;
        $total_profiles = 0;
        $owner_profiles = array();
        // get properties where this is the owner
        $args = array('post_type' => 'property', 'meta_query' => array(array('key' => '_owner_contact_id', 'value' => $post->ID, 'compare' => '=')));
        $property_query = new WP_Query($args);
        if ($property_query->have_posts()) {
            while ($property_query->have_posts()) {
                $property_query->the_post();
                $owner_profiles[] = $post;
                ++$total_profiles;
            }
        }
        wp_reset_postdata();
        $applicant_profiles = array();
        $num_applicant_profiles = get_post_meta($thepostid, '_applicant_profiles', TRUE);
        if ($num_applicant_profiles == '') {
            $num_applicant_profiles = 0;
        }
        if ($num_applicant_profiles > 0) {
            $total_profiles += $num_applicant_profiles;
            for ($i = 0; $i < $num_applicant_profiles; ++$i) {
                $applicant_profiles[] = get_post_meta($thepostid, '_applicant_profile_' . $i, TRUE);
            }
        }
        $third_party_profiles = array();
        $third_party_categories = get_post_meta($thepostid, '_third_party_categories', TRUE);
        if (is_array($third_party_categories) && !empty($third_party_categories)) {
            $ph_third_party_contacts = new PH_Third_Party_Contacts();
            foreach ($third_party_categories as $third_party_category) {
                $third_party_profiles[] = $third_party_category;
                ++$total_profiles;
            }
        }
        echo '<div class="propertyhive_meta_box">';
        echo '<div class="panel-wrap">
            
            <div class="ph-tabs-back"></div>

                <ul class="contact_data_tabs ph-tabs">';
        $tab = 0;
        foreach ($owner_profiles as $property_post) {
            $owner_type = __('Property Owner', 'propertyhive');
            $department = get_post_meta($property_post->ID, '_department', TRUE);
            if ($department == 'lettings') {
                $owner_type = __('Property Landlord', 'propertyhive');
            }
            echo '<li class="property_tab' . ($tab == 0 ? ' active' : '') . '">
                        <a href="#tab_property_data_' . $property_post->ID . '">' . $owner_type . '</a>
                    </li>';
            ++$tab;
        }
        foreach ($applicant_profiles as $key => $applicant_profile) {
            $label = __('New Applicant', 'propertyhive');
            if (isset($applicant_profile['department']) && $applicant_profile['department'] == 'residential-sales') {
                $label = __('Sales Applicant', 'propertyhive');
            } elseif (isset($applicant_profile['department']) && $applicant_profile['department'] == 'residential-lettings') {
                $label = __('Lettings Applicant', 'propertyhive');
            } elseif (isset($applicant_profile['department']) && $applicant_profile['department'] == 'commercial') {
                $label = __('Commercial Applicant', 'propertyhive');
            }
            echo '<li class="property_tab' . ($tab == 0 ? ' active' : '') . '">
                        <a href="#tab_applicant_data_' . $key . '">' . $label . '</a>
                    </li>';
            ++$tab;
        }
        foreach ($third_party_profiles as $key => $third_party_profile) {
            $label = __('New Third Party', 'propertyhive');
            if ($third_party_profile != '' && $third_party_profile != 0) {
                $category_name = $ph_third_party_contacts->get_category($third_party_profile);
                if ($category_name !== false) {
                    $label = $category_name;
                }
            }
            echo '<li class="property_tab' . ($tab == 0 ? ' active' : '') . '">
                        <a href="#tab_third_party_data_' . $key . '">' . $label . '</a>
                    </li>';
            ++$tab;
        }
        echo '<li class="property_tab' . ($tab == 0 ? ' active' : '') . '">
                        <a href="#tab_add_relationship">' . __('Add Relationship', 'propertyhive') . '</a>
                    </li>';
        echo '</ul>';
        $contact_id = $thepostid;
        $tab = 0;
        foreach ($owner_profiles as $property_post) {
            $the_property = new PH_Property($property_post->ID);
            echo '<div id="tab_property_data_' . $property_post->ID . '" class="panel propertyhive_options_panel" style="' . ($tab == 0 ? 'display:block;' : 'display:none;') . '">
                        <div class="options_group" style="float:left; width:100%;">';
            echo '<p class="form-field">';
            echo '<label>' . __('Address', 'propertyhive') . '</label>';
            echo $the_property->get_formatted_summary_address('<br>');
            echo '</p>';
            echo '<p class="form-field">';
            echo '<label>' . __('Price', 'propertyhive') . '</label>';
            echo $the_property->get_formatted_price();
            echo '</p>';
            echo '<p class="form-field">';
            echo '<label>' . __('Bedrooms', 'propertyhive') . '</label>';
            echo $the_property->_bedrooms;
            echo '</p>';
            echo '<p class="form-field">';
            echo '<label>' . __('Status', 'propertyhive') . '</label>';
            echo $the_property->_on_market == 'yes' ? __('On Market', 'propertyhive') : __('Not On Market', 'propertyhive');
            echo '</p>';
            echo '<p class="form-field">';
            echo '<label></label>';
            echo '<a href="' . get_edit_post_link($property_post->ID) . '" class="button">' . __('View Property Record', 'propertyhive') . '</a>';
            echo '</p>';
            echo '
                        </div>
                    </div>';
            ++$tab;
        }
        foreach ($applicant_profiles as $key => $applicant_profile) {
            echo '<div id="tab_applicant_data_' . $key . '" class="panel propertyhive_options_panel" style="' . ($tab == 0 ? 'display:block;' : 'display:none;') . '">
                        
                        <div class="options_group applicant-fields-' . $key . '" style="float:left; width:100%;">';
            $departments = array();
            if (get_option('propertyhive_active_departments_sales') == 'yes') {
                $departments['residential-sales'] = __('Residential Sales', 'propertyhive');
            }
            if (get_option('propertyhive_active_departments_lettings') == 'yes') {
                $departments['residential-lettings'] = __('Residential Lettings', 'propertyhive');
            }
            if (get_option('propertyhive_active_departments_commercial') == 'yes') {
                $departments['commercial'] = __('Commercial', 'propertyhive');
            }
            $value = isset($applicant_profile['department']) && $applicant_profile['department'] != '' ? $applicant_profile['department'] : get_option('propertyhive_primary_department');
            $args = array('id' => '_applicant_department_' . $key, 'label' => 'Looking For', 'value' => $value, 'options' => $departments);
            if (count($departments) == 1) {
                foreach ($departments as $department_key => $value) {
                    $args['value'] = $department_key;
                }
            }
            propertyhive_wp_radio($args);
            echo '<div class="propertyhive-applicant-residential-sales-details-' . $key . '">';
            // Price
            propertyhive_wp_text_input(array('id' => '_applicant_maximum_price_' . $key, 'label' => __('Maximum Price', 'propertyhive') . ' (&pound;)', 'desc_tip' => false, 'type' => 'text', 'class' => '', 'custom_attributes' => array('style' => 'width:100%; max-width:150px;'), 'value' => isset($applicant_profile['max_price']) ? $applicant_profile['max_price'] : ''));
            echo '</div>';
            echo '<div class="propertyhive-applicant-residential-lettings-details-' . $key . '">';
            // Rent / Rent Frequency
            $rent_frequency = isset($applicant_profile['rent_frequency']) ? $applicant_profile['rent_frequency'] : '';
            echo '<p class="form-field rent_field ">
                        
                            <label for="_applicant_maximum_rent_' . $key . '">' . __('Maximum Rent', 'propertyhive') . ' (&pound;)</label>
                            
                            <input type="text" class="" name="_applicant_maximum_rent_' . $key . '" id="_applicant_maximum_rent_' . $key . '" value="' . (isset($applicant_profile['max_rent']) ? $applicant_profile['max_rent'] : '') . '" placeholder="" style="width:20%; max-width:150px;">
                            
                            <select id="_applicant_rent_frequency_' . $key . '" name="_applicant_rent_frequency_' . $key . '" class="select short">
                                <option value="pw"' . ($rent_frequency == 'pw' ? ' selected' : '') . '>' . __('Per Week', 'propertyhive') . '</option>
                                <option value="pcm"' . ($rent_frequency == 'pcm' || $rent_frequency == '' ? ' selected' : '') . '>' . __('Per Calendar Month', 'propertyhive') . '</option>
                                <option value="pq"' . ($rent_frequency == 'pq' ? ' selected' : '') . '>' . __('Per Quarter', 'propertyhive') . '</option>
                                <option value="pa"' . ($rent_frequency == 'pa' ? ' selected' : '') . '>' . __('Per Annum', 'propertyhive') . '</option>
                            </select>
                            
                        </p>';
            echo '</div>';
            echo '<div class="propertyhive-applicant-residential-details-' . $key . '">';
            // Bedrooms
            propertyhive_wp_text_input(array('id' => '_applicant_minimum_bedrooms_' . $key, 'label' => __('Minimum Bedrooms', 'propertyhive'), 'desc_tip' => false, 'type' => 'number', 'class' => '', 'custom_attributes' => array('style' => 'width:100%; max-width:75px;'), 'value' => isset($applicant_profile['min_beds']) ? $applicant_profile['min_beds'] : ''));
            // Residential Types
            ?>
                        <p class="form-field"><label for="_applicant_property_types_<?php 
            echo $key;
            ?>
"><?php 
            _e('Property Types', 'propertyhive');
            ?>
</label>
                        <select id="_applicant_property_types_<?php 
            echo $key;
            ?>
" name="_applicant_property_types_<?php 
            echo $key;
            ?>
[]" multiple="multiple" data-placeholder="Start typing to add property types..." class="multiselect attribute_values">
                            <?php 
            $options = array('' => '');
            $args = array('hide_empty' => false, 'parent' => 0);
            $terms = get_terms('property_type', $args);
            $selected_values = array();
            $term_list = isset($applicant_profile['property_types']) ? $applicant_profile['property_types'] : array();
            if (is_array($term_list) && !empty($term_list)) {
                foreach ($term_list as $term_id) {
                    $selected_values[] = $term_id;
                }
            }
            if (!empty($terms) && !is_wp_error($terms)) {
                foreach ($terms as $term) {
                    echo '<option value="' . esc_attr($term->term_id) . '"';
                    if (in_array($term->term_id, $selected_values)) {
                        echo ' selected';
                    }
                    echo '>' . esc_html($term->name) . '</option>';
                    $args = array('hide_empty' => false, 'parent' => $term->term_id);
                    $subterms = get_terms('property_type', $args);
                    if (!empty($subterms) && !is_wp_error($subterms)) {
                        foreach ($subterms as $term) {
                            echo '<option value="' . esc_attr($term->term_id) . '"';
                            if (in_array($term->term_id, $selected_values)) {
                                echo ' selected';
                            }
                            echo '>- ' . esc_html($term->name) . '</option>';
                        }
                    }
                }
            }
            ?>
                        </select></p>
                    <?php 
            echo '</div>';
            // end 'propertyhive-applicant-residential-details-' . $key
            echo '<div class="propertyhive-applicant-commercial-details-' . $key . '">';
            $args = array('id' => '_applicant_available_as_' . $key, 'label' => 'Available As', 'value' => array('sale', 'rent'), 'options' => array('sale' => 'For Sale', 'rent' => 'To Rent'));
            if (isset($applicant_profile['available_as']) && is_array($applicant_profile['available_as'])) {
                $args['value'] = array();
                foreach ($applicant_profile['available_as'] as $value) {
                    $args['value'][] = $value;
                }
            }
            propertyhive_wp_checkboxes($args);
            // Commercial Types
            ?>
                        <p class="form-field"><label for="_applicant_commercial_property_types_<?php 
            echo $key;
            ?>
"><?php 
            _e('Property Types', 'propertyhive');
            ?>
</label>
                        <select id="_applicant_commercial_property_types_<?php 
            echo $key;
            ?>
" name="_applicant_commercial_property_types_<?php 
            echo $key;
            ?>
[]" multiple="multiple" data-placeholder="Start typing to add property types..." class="multiselect attribute_values">
                            <?php 
            $options = array('' => '');
            $args = array('hide_empty' => false, 'parent' => 0);
            $terms = get_terms('commercial_property_type', $args);
            $selected_values = array();
            $term_list = isset($applicant_profile['commercial_property_types']) ? $applicant_profile['commercial_property_types'] : array();
            if (is_array($term_list) && !empty($term_list)) {
                foreach ($term_list as $term_id) {
                    $selected_values[] = $term_id;
                }
            }
            if (!empty($terms) && !is_wp_error($terms)) {
                foreach ($terms as $term) {
                    echo '<option value="' . esc_attr($term->term_id) . '"';
                    if (in_array($term->term_id, $selected_values)) {
                        echo ' selected';
                    }
                    echo '>' . esc_html($term->name) . '</option>';
                    $args = array('hide_empty' => false, 'parent' => $term->term_id);
                    $subterms = get_terms('property_type', $args);
                    if (!empty($subterms) && !is_wp_error($subterms)) {
                        foreach ($subterms as $term) {
                            echo '<option value="' . esc_attr($term->term_id) . '"';
                            if (in_array($term->term_id, $selected_values)) {
                                echo ' selected';
                            }
                            echo '>- ' . esc_html($term->name) . '</option>';
                        }
                    }
                }
            }
            ?>
                        </select></p>
                    <?php 
            echo '</div>';
            // end 'propertyhive-applicant-commercial-details-' . $key
            // Locations
            ?>
                        <p class="form-field"><label for="_applicant_locations_<?php 
            echo $key;
            ?>
"><?php 
            _e('Locations', 'propertyhive');
            ?>
</label>
                        <select id="_applicant_locations_<?php 
            echo $key;
            ?>
" name="_applicant_locations_<?php 
            echo $key;
            ?>
[]" multiple="multiple" data-placeholder="Start typing to add location..." class="multiselect attribute_values">
                            <?php 
            $options = array('' => '');
            $args = array('hide_empty' => false, 'parent' => 0);
            $terms = get_terms('location', $args);
            $selected_values = array();
            $term_list = isset($applicant_profile['locations']) ? $applicant_profile['locations'] : array();
            if (is_array($term_list) && !empty($term_list)) {
                foreach ($term_list as $term_id) {
                    $selected_values[] = $term_id;
                }
            }
            if (!empty($terms) && !is_wp_error($terms)) {
                foreach ($terms as $term) {
                    echo '<option value="' . esc_attr($term->term_id) . '"';
                    if (in_array($term->term_id, $selected_values)) {
                        echo ' selected';
                    }
                    echo '>' . esc_html($term->name) . '</option>';
                    $args = array('hide_empty' => false, 'parent' => $term->term_id);
                    $subterms = get_terms('location', $args);
                    if (!empty($subterms) && !is_wp_error($subterms)) {
                        foreach ($subterms as $term) {
                            echo '<option value="' . esc_attr($term->term_id) . '"';
                            if (in_array($term->term_id, $selected_values)) {
                                echo ' selected';
                            }
                            echo '>- ' . esc_html($term->name) . '</option>';
                            $args = array('hide_empty' => false, 'parent' => $term->term_id);
                            $subsubterms = get_terms('location', $args);
                            if (!empty($subsubterms) && !is_wp_error($subsubterms)) {
                                foreach ($subsubterms as $term) {
                                    echo '<option value="' . esc_attr($term->term_id) . '"';
                                    if (in_array($term->term_id, $selected_values)) {
                                        echo ' selected';
                                    }
                                    echo '>- - ' . esc_html($term->name) . '</option>';
                                }
                            }
                        }
                    }
                }
            }
            ?>
                        </select></p>
                    <?php 
            // Additional Requirement Notes
            propertyhive_wp_textarea_input(array('id' => '_applicant_requirement_notes_' . $key, 'label' => __('Additional Requirements', 'propertyhive'), 'desc_tip' => false, 'class' => '', 'value' => isset($applicant_profile['notes']) ? $applicant_profile['notes'] : ''));
            propertyhive_wp_checkbox(array('id' => '_send_matching_properties_' . $key, 'label' => __('Send Matching Properties', 'propertyhive'), 'desc_tip' => false, 'value' => isset($applicant_profile['send_matching_properties']) && $applicant_profile['send_matching_properties'] == 'yes' || !isset($applicant_profile['send_matching_properties']) ? 'yes' : ''));
            $auto_property_match = get_option('propertyhive_auto_property_match', '');
            if ($auto_property_match == 'yes') {
                // Auto match emails are enabled. Add ability to disable on per-applicant basis
                propertyhive_wp_checkbox(array('id' => '_auto_match_disabled_' . $key, 'label' => __('Disable Auto-Match', 'propertyhive'), 'desc_tip' => false, 'value' => isset($applicant_profile['auto_match_disabled']) && $applicant_profile['auto_match_disabled'] == 'yes' ? 'yes' : ''));
            }
            echo '

                        </div>

                        <div class="actions">

                            <a 
                                href="' . admin_url('admin.php?page=ph-matching-properties&contact_id=' . $contact_id . '&applicant_profile=' . $key) . '" 
                                class="button view-matching-properties-' . $key . '" 
                                ' . (isset($applicant_profile['send_matching_properties']) && $applicant_profile['send_matching_properties'] == '' ? ' disabled title="Send Matching Properties not selected"' : '') . '
                            >' . __('View Matching Properties', 'propertyhive') . '</a>

                            <a 
                                href="' . wp_nonce_url(admin_url('post.php?post=' . $contact_id . '&action=edit#propertyhive-contact-relationships'), $key, 'delete_applicant_relationship') . '" 
                                class="button"
                                onclick="var confirmBox = confirm(\'' . __('Are you sure you wish to delete this applicant relationship?', 'propertyhive') . '\'); return confirmBox;"
                            >' . __('Delete Relationship', 'propertyhive') . '</a>

                            <div id="view_matching_properties_' . $key . '" style="display:none;">
                                
                                <div class="loading-properties" style="text-align:center;"><br><br>Loading matching properties...</div>

                                <div class="need-to-save-changes" style="text-align:center;"><br><br>Please save your changes before viewing matching properties</div>

                                <div class="matching-properties" id="matching_properties_' . $key . '" style="display:none;">

                                </div>

                            </div>

                        </div>

                    </div>

                    <script>

                        var applicant_details_changed_' . $key . ' = false;
                        jQuery(document).ready(function()
                        {
                            showHideApplicantDepartmentMetaBox_' . $key . '();

                            jQuery(\'input[type=\\\'radio\\\'][name=\\\'_applicant_department_' . $key . '\\\']\').change(function()
                            {
                                 showHideApplicantDepartmentMetaBox_' . $key . '();
                            });

                            jQuery(\'.applicant-fields-' . $key . ' input, .applicant-fields-' . $key . ' select, .applicant-fields-' . $key . ' textarea\').change(function()
                            {
                                applicant_details_changed_' . $key . ' = true;
                            });

                            jQuery(\'a.view-matching-properties-' . $key . '\').click(function(e)
                            {
                                if (applicant_details_changed_' . $key . ')
                                {
                                    alert(\'You\\\'ve made changes to the requirements. Please save the changes before viewing matching properties\');
                                    return false;
                                }

                                return true;
                            });
                        });
                        
                        function showHideApplicantDepartmentMetaBox_' . $key . '()
                        {
                            jQuery(\'.propertyhive-applicant-residential-details-' . $key . '\').hide();
                            jQuery(\'.propertyhive-applicant-residential-sales-details-' . $key . '\').hide();
                            jQuery(\'.propertyhive-applicant-residential-lettings-details-' . $key . '\').hide();
                            jQuery(\'.propertyhive-applicant-commercial-details-' . $key . '\').hide();
                            
                            switch (jQuery(\'input[type=\\\'radio\\\'][name=\\\'_applicant_department_' . $key . '\\\']:checked\').val())
                            {
                                case "residential-sales":
                                {
                                    jQuery(\'.propertyhive-applicant-residential-details-' . $key . '\').show();
                                    jQuery(\'.propertyhive-applicant-residential-sales-details-' . $key . '\').show();
                                    break;
                                }
                                case "residential-lettings":
                                {
                                    jQuery(\'.propertyhive-applicant-residential-details-' . $key . '\').show();
                                    jQuery(\'.propertyhive-applicant-residential-lettings-details-' . $key . '\').show();
                                    break;
                                }
                                case "commercial":
                                {
                                    jQuery(\'.propertyhive-applicant-commercial-details-' . $key . '\').show();
                                    break;
                                }
                            }
                            
                        }
                        
                    </script>';
            ++$tab;
        }
        foreach ($third_party_profiles as $key => $category) {
            echo '<div id="tab_third_party_data_' . $key . '" class="panel propertyhive_options_panel" style="' . ($tab == 0 ? 'display:block;' : 'display:none;') . '">
                        <div class="options_group" style="float:left; width:100%;">';
            echo '<p class="form-field rent_field ">
                        
                            <label for="_third_party_category_' . $key . '">' . __('Contact Category', 'propertyhive') . '</label>
                            
                            <select id="_third_party_category_' . $key . '" name="_third_party_category[]" class="select short">';
            if ($category == '' || $category == 0) {
                echo '<option value="0"></option>';
            }
            $categories = $ph_third_party_contacts->get_categories();
            foreach ($categories as $id => $category_name) {
                echo '<option value="' . $id . '"';
                if ($id == $category) {
                    echo ' selected';
                }
                echo '>' . $category_name . '</option>';
            }
            echo '</select>
                            
                        </p>';
            echo '
                        </div>
                    </div>';
            ++$tab;
        }
        echo '<div id="tab_add_relationship" class="panel propertyhive_options_panel" style="' . ($tab == 0 ? 'display:block;' : 'display:none;') . '">
                    <div class="options_group">';
        echo '<p class="form-field">';
        echo '<label>' . __('New Relationship Type', 'propertyhive') . '</label>';
        echo '<a href="' . wp_nonce_url(admin_url('post.php?post=' . $thepostid . '&action=edit#propertyhive-contact-relationships'), '1', 'add_applicant_relationship') . '" class="button">' . __('New Applicant Profile', 'propertyhive') . '</a><br><br>';
        echo '<a href="' . admin_url('post-new.php?post_type=property&owner_contact_id=' . $thepostid) . '" class="button">' . __('New Property Owner / Landlord', 'propertyhive') . '</a><br><br>';
        echo '<a href="' . wp_nonce_url(admin_url('post.php?post=' . $thepostid . '&action=edit#propertyhive-contact-relationships'), '1', 'add_third_party_relationship') . '" class="button">' . __('New Third Party Contact', 'propertyhive') . '</a>';
        echo '</p>';
        echo '
                        </div>
                    </div>';
        echo '<div class="clear"></div>
            
        </div>';
        echo '</div>';
        //do_action('propertyhive_contact_relationships_fields');
    }