/**
     * Output the metabox
     */
    public static function output($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">';
        $available_as = array();
        if (get_post_meta($post->ID, '_for_sale', true) == 'yes') {
            $available_as[] = 'sale';
        }
        if (get_post_meta($post->ID, '_to_rent', true) == 'yes') {
            $available_as[] = 'rent';
        }
        if ($parent_post !== FALSE && get_post_meta($parent_post, '_for_sale', TRUE)) {
            $available_as[] = 'sale';
        }
        if ($parent_post !== FALSE && get_post_meta($parent_post, '_to_rent', TRUE)) {
            $available_as[] = 'rent';
        }
        propertyhive_wp_checkboxes(array('id' => '_available_as', 'label' => __('Available As', 'propertyhive'), 'desc_tip' => false, 'value' => $available_as, 'options' => array('sale' => 'For Sale', 'rent' => 'To Rent')));
        // Currency / Price
        $ph_countries = new PH_Countries();
        $default_country = get_option('propertyhive_default_country', 'GB');
        $countries = get_option('propertyhive_countries', array($default_country));
        $currencies = array();
        foreach ($countries as $country) {
            $country = $ph_countries->get_country($country);
            if (!isset($currencies[$country['currency_code']])) {
                $currencies[$country['currency_code']] = $country['currency_symbol'];
            }
        }
        $selected_sale_currency = get_post_meta($post->ID, '_commercial_price_currency', true);
        if ($selected_sale_currency == '') {
            $country = $ph_countries->get_country($default_country);
            $selected_sale_currency = $country['currency_code'];
        }
        $selected_rent_currency = get_post_meta($post->ID, '_commercial_rent_currency', true);
        if ($selected_rent_currency == '') {
            $country = $ph_countries->get_country($default_country);
            $selected_rent_currency = $country['currency_code'];
        }
        // Sale fields
        echo '<div class="commercial-sale-fields"' . (!in_array('sale', $available_as) ? ' style="display:none"' : '') . '>';
        echo '<p class="form-field price_field">
        
            <label for="_price_from">' . __('Price', 'propertyhive') . (empty($currencies) || count($currencies) <= 1 ? ' (<span class="currency-symbol">' . $currencies[$selected_sale_currency] . '</span>)' : '') . '</label>';
        if (count($currencies) > 1) {
            echo '<select id="_commercial_price_currency" name="_commercial_price_currency" class="select" style="width:auto; float:left;">';
            foreach ($currencies as $currency_code => $currency_sybmol) {
                echo '<option value="' . $currency_code . '"' . ($currency_code == $selected_sale_currency ? ' selected' : '') . '>' . $currency_sybmol . '</option>';
            }
            echo '</select>';
        } else {
            echo '<input type="hidden" name="_commercial_price_currency" value="' . $selected_sale_currency . '">';
        }
        $price_options = get_commercial_price_units();
        echo '
        <input type="text" class="" name="_price_from" id="_price_from" value="' . get_post_meta($post->ID, '_price_from', true) . '" placeholder="" style="width:15%; min-width:85px;">
        <span style="float:left"> - </span>
        <input type="text" class="" name="_price_to" id="_price_to" value="' . get_post_meta($post->ID, '_price_to', true) . '" placeholder="" style="width:15%; min-width:85px;">

        <select name="_price_units" id="_price_units">
            <option value=""></option>';
        foreach ($price_options as $key => $value) {
            echo '<option value="' . $key . '"';
            if ($key == get_post_meta($post->ID, '_price_units', true)) {
                echo ' selected';
            }
            echo '>' . $value . '</option>';
        }
        echo '</select>

        </p>';
        // POA
        propertyhive_wp_checkbox(array('id' => '_commercial_price_poa', 'label' => __('Price On Application', 'propertyhive'), 'desc_tip' => false, 'value' => get_post_meta($post->ID, '_price_poa', true)));
        // Price Qualifier
        $options = array('' => '');
        $args = array('hide_empty' => false, 'parent' => 0);
        $terms = get_terms('price_qualifier', $args);
        $selected_value = '';
        if (!empty($terms) && !is_wp_error($terms)) {
            foreach ($terms as $term) {
                $options[$term->term_id] = $term->name;
            }
            $term_list = wp_get_post_terms($post->ID, 'price_qualifier', array("fields" => "ids"));
            if (!is_wp_error($term_list) && is_array($term_list) && !empty($term_list)) {
                $selected_value = $term_list[0];
            }
        }
        $args = array('id' => 'commercial_price_qualifier_id', 'label' => __('Price Qualifier', 'propertyhive'), 'desc_tip' => false, 'options' => $options);
        if ($selected_value != '') {
            $args['value'] = $selected_value;
        }
        propertyhive_wp_select($args);
        // Sale By
        $options = array('' => '');
        $args = array('hide_empty' => false, 'parent' => 0);
        $terms = get_terms('sale_by', $args);
        $selected_value = '';
        if (!empty($terms) && !is_wp_error($terms)) {
            foreach ($terms as $term) {
                $options[$term->term_id] = $term->name;
            }
            $term_list = wp_get_post_terms($post->ID, 'sale_by', array("fields" => "ids"));
            if (!is_wp_error($term_list) && is_array($term_list) && !empty($term_list)) {
                $selected_value = $term_list[0];
            }
        }
        $args = array('id' => 'commercial_sale_by_id', 'label' => __('Sale By', 'propertyhive'), 'desc_tip' => false, 'options' => $options);
        if ($selected_value != '') {
            $args['value'] = $selected_value;
        }
        propertyhive_wp_select($args);
        // Tenure
        $options = array('' => '');
        $args = array('hide_empty' => false, 'parent' => 0);
        $terms = get_terms('commercial_tenure', $args);
        $selected_value = '';
        if (!empty($terms) && !is_wp_error($terms)) {
            foreach ($terms as $term) {
                $options[$term->term_id] = $term->name;
            }
            $term_list = wp_get_post_terms($post->ID, 'commercial_tenure', array("fields" => "ids"));
            if (!is_wp_error($term_list) && is_array($term_list) && !empty($term_list)) {
                $selected_value = $term_list[0];
            }
        }
        $args = array('id' => 'commercial_tenure_id', 'label' => __('Tenure', 'propertyhive'), 'desc_tip' => false, 'options' => $options);
        if ($selected_value != '') {
            $args['value'] = $selected_value;
        }
        propertyhive_wp_select($args);
        do_action('propertyhive_property_commercial_sale_details_fields');
        echo '</div>';
        // Rent Fields
        echo '<div class="commercial-rent-fields"' . (!in_array('rent', $available_as) ? ' style="display:none"' : '') . '>';
        echo '<p class="form-field price_field">
        
            <label for="_rent_from">' . __('Rent', 'propertyhive') . (empty($currencies) || count($currencies) <= 1 ? ' (<span class="currency-symbol">' . $currencies[$selected_rent_currency] . '</span>)' : '') . '</label>';
        if (count($currencies) > 1) {
            echo '<select id="_commercial_rent_currency" name="_commercial_rent_currency" class="select" style="width:auto; float:left;">';
            foreach ($currencies as $currency_code => $currency_sybmol) {
                echo '<option value="' . $currency_code . '"' . ($currency_code == $selected_rent_currency ? ' selected' : '') . '>' . $currency_sybmol . '</option>';
            }
            echo '</select>';
        } else {
            echo '<input type="hidden" name="_commercial_rent_currency" value="' . $selected_rent_currency . '">';
        }
        $rent_units = get_post_meta($post->ID, '_rent_units', true);
        echo '
        <input type="text" class="" name="_rent_from" id="_rent_from" value="' . get_post_meta($post->ID, '_rent_from', true) . '" placeholder="" style="width:15%; min-width:85px;">
        <span style="float:left; padding:0 5px"> - </span>
        <input type="text" class="" name="_rent_to" id="_rent_to" value="' . get_post_meta($post->ID, '_rent_to', true) . '" placeholder="" style="width:15%; min-width:85px;">
        
        <select name="_rent_units" id="_rent_units">
            <option value="pw"' . ($rent_units == 'pw' ? ' selected' : '') . '>' . __('Per Week', 'propertyhive') . '</option>
            <option value="pcm"' . ($rent_units == 'pcm' || $rent_units == '' ? ' selected' : '') . '>' . __('Per Calendar Month', 'propertyhive') . '</option>
            <option value="pq"' . ($rent_units == 'pq' ? ' selected' : '') . '>' . __('Per Quarter', 'propertyhive') . '</option>
            <option value="pa"' . ($rent_units == 'pa' ? ' selected' : '') . '>' . __('Per Annum', 'propertyhive') . '</option>';
        foreach ($price_options as $key => $value) {
            echo '<option value="' . $key . '"';
            if ($key == $rent_units) {
                echo ' selected';
            }
            echo '>' . $value . '</option>';
        }
        echo '</select>

        </p>';
        // POA
        propertyhive_wp_checkbox(array('id' => '_commercial_rent_poa', 'label' => __('Rent On Application', 'propertyhive'), 'desc_tip' => false, 'value' => get_post_meta($post->ID, '_rent_poa', true)));
        do_action('propertyhive_property_commercial_rent_details_fields');
        echo '</div>';
        // end commercial-rent-fields
        ?>

        <p class="form-field"><label for="property_type_ids"><?php 
        _e('Property Types', 'propertyhive');
        ?>
</label>
        <select id="property_type_ids" name="property_type_ids[]" multiple="multiple" data-placeholder="<?php 
        _e('Select property types', 'propertyhive');
        ?>
" class="multiselect attribute_values">
            <?php 
        $options = array('' => '');
        $args = array('hide_empty' => false, 'parent' => 0);
        $terms = get_terms('commercial_property_type', $args);
        if (!empty($terms) && !is_wp_error($terms)) {
            foreach ($terms as $term) {
                $options[$term->term_id] = $term->name;
                $args = array('hide_empty' => false, 'parent' => $term->term_id);
                $subterms = get_terms('commercial_property_type', $args);
                if (!empty($subterms) && !is_wp_error($subterms)) {
                    foreach ($subterms as $subterm) {
                        $options[$subterm->term_id] = '- ' . $subterm->name;
                        $args = array('hide_empty' => false, 'parent' => $subterm->term_id);
                        $subsubterms = get_terms('commercial_property_type', $args);
                        if (!empty($subsubterms) && !is_wp_error($subsubterms)) {
                            foreach ($subsubterms as $subsubterm) {
                                $options[$subsubterm->term_id] = '- - ' . $subsubterm->name;
                            }
                        }
                    }
                }
            }
        }
        $selected_values = array();
        $term_list = wp_get_post_terms($post->ID, 'commercial_property_type', array("fields" => "ids"));
        if (!is_wp_error($term_list) && is_array($term_list) && !empty($term_list)) {
            foreach ($term_list as $term_id) {
                $selected_values[] = $term_id;
            }
        }
        if (!empty($options) && !is_wp_error($options)) {
            foreach ($options as $key => $value) {
                echo '<option value="' . esc_attr($key) . '"';
                if (in_array($key, $selected_values)) {
                    echo ' selected';
                }
                echo '>' . esc_html($value) . '</option>';
            }
        }
        ?>
        </select>

        <?php 
        $size_options = get_area_units();
        $floor_area_units = get_post_meta($post->ID, '_floor_area_units', true);
        echo '<p class="form-field">

        <label for="_floor_area_from">' . __('Floor Area', 'propertyhive') . '</label>
        
        <input type="text" class="" name="_floor_area_from" id="_floor_area_from" value="' . get_post_meta($post->ID, '_floor_area_from', true) . '" placeholder="" style="width:15%; min-width:85px;">
        <span style="float:left; padding:0 5px"> - </span>
        <input type="text" class="" name="_floor_area_to" id="_floor_area_to" value="' . get_post_meta($post->ID, '_floor_area_to', true) . '" placeholder="" style="width:15%; min-width:85px;">

        <select name="_floor_area_units" id="_floor_area_units">';
        foreach ($size_options as $key => $value) {
            echo '<option value="' . $key . '"';
            if ($key == $floor_area_units) {
                echo ' selected';
            }
            echo '>' . $value . '</option>';
        }
        echo '</select>

        </p>';
        $site_area_units = get_post_meta($post->ID, '_site_area_units', true);
        echo '<p class="form-field">

        <label for="_site_area_from">' . __('Site Area', 'propertyhive') . '</label>
        
        <input type="text" class="" name="_site_area_from" id="_site_area_from" value="' . get_post_meta($post->ID, '_site_area_from', true) . '" placeholder="" style="width:15%; min-width:85px;">
        <span style="float:left; padding:0 5px"> - </span>
        <input type="text" class="" name="_site_area_to" id="_site_area_to" value="' . get_post_meta($post->ID, '_site_area_to', true) . '" placeholder="" style="width:15%; min-width:85px;">

        <select name="_site_area_units" id="_site_area_units">';
        foreach ($size_options as $key => $value) {
            echo '<option value="' . $key . '"';
            if ($key == $site_area_units) {
                echo ' selected';
            }
            echo '>' . $value . '</option>';
        }
        echo '</select>

        </p>';
        do_action('propertyhive_property_commercial_details_fields');
        echo '</div>';
        echo '</div>';
        echo '<script>

            jQuery(document).ready(function()
            {
                jQuery(\'#_available_as_sale\').change(function()
                {
                    console.log(jQuery(this).is(\':checked\'));
                    if (jQuery(this).is(\':checked\'))
                    {
                        jQuery(\'.commercial-sale-fields\').slideDown(\'fast\');
                    }
                    else
                    {
                        jQuery(\'.commercial-sale-fields\').slideUp(\'fast\');
                    }
                });

                jQuery(\'#_available_as_rent\').change(function()
                {
                    console.log(jQuery(this).is(\':checked\'));
                    if (jQuery(this).is(\':checked\'))
                    {
                        jQuery(\'.commercial-rent-fields\').slideDown(\'fast\');
                    }
                    else
                    {
                        jQuery(\'.commercial-rent-fields\').slideUp(\'fast\');
                    }
                });
                    
            });

        </script>';
    }
 public function get_formatted_site_area()
 {
     $area = '';
     if ($this->_site_area_from != '') {
         $explode_area = explode(".", $this->_site_area_from);
         if (count($explode_area) == 2) {
             $area .= number_format($explode_area[0], 0) . '.' . $explode_area[1];
         } else {
             $area .= number_format($this->_site_area_from, 0);
         }
     }
     if ($this->_site_area_to != '' && $this->_site_area_to != $this->_site_area_from) {
         if ($area != '') {
             $area .= ' - ';
         }
         $explode_area = explode(".", $this->_site_area_to);
         if (count($explode_area) == 2) {
             $area .= number_format($explode_area[0], 0) . '.' . $explode_area[1];
         } else {
             $area .= number_format($this->_site_area_to, 0);
         }
     }
     if ($area != '') {
         $area_units = get_area_units();
         $area .= isset($area_units[$this->_site_area_units]) ? ' ' . $area_units[$this->_site_area_units] : '';
     }
     return $area;
 }