function draw_property_search_form($args = false)
    {
        global $wp_properties;
        WPP_F::force_script_inclusion('wpp-jquery-number-format');
        $args = wp_parse_args($args, array('search_attributes' => false, 'searchable_property_types' => false, 'use_pagination' => 'on', 'per_page' => '10', 'group_attributes' => false, 'strict_search' => false, 'instance_id' => false, 'sort_order' => false, 'cache' => true));
        if (empty($args['search_attributes']) && isset($args['searchable_attributes'])) {
            $args['search_attributes'] = $args['searchable_attributes'];
        }
        extract($args, EXTR_SKIP);
        $search_values = array();
        $property_type_flag = false;
        //** Bail if no search attributes passed */
        if (!is_array($args['search_attributes'])) {
            return;
        }
        $property_stats = $wp_properties['property_stats'];
        if (!isset($property_stats['property_type'])) {
            $property_stats['property_type'] = sprintf(__('%s Type', ud_get_wp_property()->domain), WPP_F::property_label());
        }
        //** Load search values for attributes (from cache, or generate) */
        if (!empty($search_attributes) && !empty($searchable_property_types)) {
            $search_values = WPP_F::get_search_values($search_attributes, $searchable_property_types, $args['cache'], $args['instance_id']);
        }
        //** This looks clumsy - potanin@UD */
        if (array_key_exists('property_type', array_fill_keys($search_attributes, 1)) && is_array($searchable_property_types) && count($searchable_property_types) > 1) {
            $spt = array_fill_keys($searchable_property_types, 1);
            if (!empty($wp_properties['property_types'])) {
                foreach ($wp_properties['property_types'] as $key => $value) {
                    if (array_key_exists($key, $spt)) {
                        $search_values['property_type'][$key] = $value;
                    }
                }
                if (isset($search_values['property_type']) && count($search_values['property_type']) <= 1) {
                    unset($search_values['property_type']);
                }
            }
        }
        ?>

    <form action="<?php 
        echo WPP_F::base_url($wp_properties['configuration']['base_slug']);
        ?>
" method="post" class="wpp_shortcode_search_form">
      <?php 
        do_action("draw_property_search_form", $args);
        ?>
      <?php 
        if ($sort_order) {
            ?>
        <input type="hidden" name="wpp_search[sort_order]" value="<?php 
            echo $sort_order;
            ?>
"/>
      <?php 
        }
        ?>
      <?php 
        if (!empty($sort_by)) {
            ?>
        <input type="hidden" name="wpp_search[sort_by]" value="<?php 
            echo $sort_by;
            ?>
"/>
      <?php 
        }
        ?>
      <?php 
        if (!empty($use_pagination)) {
            ?>
        <input type="hidden" name="wpp_search[pagination]" value="<?php 
            echo $use_pagination;
            ?>
"/>
      <?php 
        }
        ?>
      <?php 
        if (!empty($per_page)) {
            ?>
        <input type="hidden" name="wpp_search[per_page]" value="<?php 
            echo $per_page;
            ?>
"/>
      <?php 
        }
        ?>
      <?php 
        if (!empty($strict_search)) {
            ?>
        <input type="hidden" name="wpp_search[strict_search]" value="<?php 
            echo $strict_search;
            ?>
"/>
      <?php 
        }
        ?>
      <?php 
        //** If no property_type passed in search_attributes, we get defaults */
        if (is_array($searchable_property_types) && !array_key_exists('property_type', array_fill_keys($search_attributes, 1))) {
            echo '<input type="hidden" name="wpp_search[property_type]" value="' . implode(',', $searchable_property_types) . '" />';
        }
        ?>
      <ul class="wpp_search_elements">
    <?php 
        if (isset($group_attributes) && $group_attributes) {
            //** Get group data */
            $groups = $wp_properties['property_groups'];
            $_search_attributes = array();
            foreach ($search_attributes as $attr) {
                $_search_attributes[$attr] = $attr;
            }
            $search_groups = sort_stats_by_groups($_search_attributes);
            unset($_search_attributes);
        } else {
            //** Create an ad-hoc group */
            $search_groups['ungrouped'] = $search_attributes;
        }
        $main_stats_group = isset($wp_properties['configuration']['main_stats_group']) ? $wp_properties['configuration']['main_stats_group'] : false;
        $count = 0;
        foreach ($search_groups as $this_group => $search_attributes) {
            $count++;
            if ($this_group == 'ungrouped' || $this_group === 0 || $this_group == $main_stats_group) {
                $is_a_group = false;
                $this_group = 'not_a_group';
            } else {
                $is_a_group = true;
            }
            ?>
      <li class="wpp_search_group wpp_group_<?php 
            echo $this_group;
            ?>
">
      <?php 
            if ($is_a_group) {
                ?>
        <span class="wpp_search_group_title wpp_group_<?php 
                echo $this_group;
                ?>
_title"><?php 
                echo $groups[$this_group]['name'];
                ?>
</span>
      <?php 
            } elseif ($group_attributes && $count == count($search_groups)) {
                ?>
        <span class="wpp_search_group_title" style="height:1px;line-height:1px;">&nbsp;</span>
      <?php 
            }
            ?>
        <ul class="wpp_search_group wpp_group_<?php 
            echo $this_group;
            ?>
">
      <?php 
            //** Begin Group Attributes */
            foreach ($search_attributes as $attrib) {
                //** Override search values if they are set in the developer tab */
                if (!empty($wp_properties['predefined_search_values'][$attrib])) {
                    $maybe_search_values = explode(',', $wp_properties['predefined_search_values'][$attrib]);
                    if (is_array($maybe_search_values)) {
                        $using_predefined_values = true;
                        $search_values[$attrib] = $maybe_search_values;
                    } else {
                        $using_predefined_values = true;
                    }
                }
                //** Don't display search attributes that have no values */
                if (!apply_filters('wpp::show_search_field_with_no_values', isset($search_values[$attrib]), $attrib)) {
                    continue;
                }
                $label = apply_filters('wpp::search_attribute::label', empty($property_stats[$attrib]) ? WPP_F::de_slug($attrib) : $property_stats[$attrib], $attrib);
                ?>
        <li class="wpp_search_form_element seach_attribute_<?php 
                echo $attrib;
                ?>
  wpp_search_attribute_type_<?php 
                echo isset($wp_properties['searchable_attr_fields'][$attrib]) ? $wp_properties['searchable_attr_fields'][$attrib] : $attrib;
                ?>
 <?php 
                echo !empty($wp_properties['searchable_attr_fields'][$attrib]) && $wp_properties['searchable_attr_fields'][$attrib] == 'checkbox' ? 'wpp-checkbox-el' : '';
                echo !empty($wp_properties['searchable_attr_fields'][$attrib]) && ($wp_properties['searchable_attr_fields'][$attrib] == 'multi_checkbox' && count($search_values[$attrib]) == 1) || isset($wp_properties['searchable_attr_fields'][$attrib]) && $wp_properties['searchable_attr_fields'][$attrib] == 'checkbox' ? ' single_checkbox' : '';
                ?>
">
          <?php 
                $random_element_id = 'wpp_search_element_' . rand(1000, 9999);
                ?>

          <label for="<?php 
                echo $random_element_id;
                ?>
" class="wpp_search_label wpp_search_label_<?php 
                echo $attrib;
                ?>
"><?php 
                echo $label;
                ?>
<span class="wpp_search_post_label_colon">:</span></label>

          <div class="wpp_search_attribute_wrap">
            <?php 
                $value = isset($_REQUEST['wpp_search'][$attrib]) ? $_REQUEST['wpp_search'][$attrib] : '';
                ob_start();
                wpp_render_search_input(array('attrib' => $attrib, 'random_element_id' => $random_element_id, 'search_values' => $search_values, 'value' => $value));
                $this_field = ob_get_contents();
                ob_end_clean();
                echo apply_filters('wpp_search_form_field_' . $attrib, $this_field, $attrib, $label, $value, isset($wp_properties['searchable_attr_fields'][$attrib]) ? $wp_properties['searchable_attr_fields'][$attrib] : false, $random_element_id);
                ?>
          </div>
          <div class="clear"></div>
          </li>
      <?php 
            }
            //** End Group Attributes */
            ?>
      </ul>
      <div class="clear"></div>
      </li>
    <?php 
        }
        ?>
        <li class="wpp_search_form_element submit"><input type="submit" class="wpp_search_button submit btn btn-large" value="<?php 
        _e('Search', ud_get_wp_property()->domain);
        ?>
"/></li>
    </ul>
    </form>
  <?php 
    }
    /**
     *
     * Renders back-end property search widget tools.
     *
     * @complexity 8
     * @author potanin@UD
     *
     */
    function form($instance)
    {
        global $wp_properties;
        //** Get widget-specific data */
        $title = isset($instance['title']) ? $instance['title'] : false;
        $searchable_attributes = isset($instance['searchable_attributes']) ? $instance['searchable_attributes'] : false;
        $grouped_searchable_attributes = isset($instance['grouped_searchable_attributes']) ? $instance['grouped_searchable_attributes'] : false;
        $use_pagi = isset($instance['use_pagi']) ? $instance['use_pagi'] : false;
        $per_page = isset($instance['per_page']) ? $instance['per_page'] : false;
        $strict_search = isset($instance['strict_search']) ? $instance['strict_search'] : false;
        $sort_by = isset($instance['sort_by']) ? $instance['sort_by'] : false;
        $sort_order = isset($instance['sort_order']) ? $instance['sort_order'] : false;
        $group_attributes = isset($instance['group_attributes']) ? $instance['group_attributes'] : false;
        $searchable_property_types = isset($instance['searchable_property_types']) ? $instance['searchable_property_types'] : false;
        $property_stats = isset($wp_properties['property_stats']) ? $wp_properties['property_stats'] : array();
        //** Get WPP data */
        $all_searchable_property_types = array_unique($wp_properties['searchable_property_types']);
        $all_searchable_attributes = array_unique($wp_properties['searchable_attributes']);
        $groups = isset($wp_properties['property_groups']) ? $wp_properties['property_groups'] : false;
        $main_stats_group = isset($wp_properties['configuration']['main_stats_group']) ? $wp_properties['configuration']['main_stats_group'] : false;
        $error = array();
        if (!is_array($all_searchable_property_types)) {
            $error['no_searchable_types'] = true;
        }
        if (!is_array($all_searchable_property_types)) {
            $error['no_searchable_attributes'] = true;
        }
        /** Set label for list below only */
        if (!isset($property_stats['property_type'])) {
            $property_stats['property_type'] = sprintf(__('%s Type', ud_get_wp_property()->domain), WPP_F::property_label());
        }
        if (is_array($all_searchable_property_types) && count($all_searchable_property_types) > 1) {
            //** Add property type to the beginning of the attribute list, even though it's not a typical attribute */
            array_unshift($all_searchable_attributes, 'property_type');
        }
        //** Find the difference between selected attributes and all attributes, i.e. unselected attributes */
        if (is_array($searchable_attributes) && is_array($all_searchable_attributes)) {
            $unselected_attributes = array_diff($all_searchable_attributes, $searchable_attributes);
            //* Clean searchable attributes: remove unavailable ones */
            foreach ($searchable_attributes as $k => $v) {
                if (!in_array($v, $all_searchable_attributes)) {
                    //* Don't remove hardcoded attributes (property_type,city) */
                    if ($v != 'property_type' && $v != 'city') {
                        unset($searchable_attributes[$k]);
                    }
                }
            }
            // Build new array beginning with selected attributes, in order, follow by all other attributes
            $ungrouped_searchable_attributes = array_merge($searchable_attributes, $unselected_attributes);
        } else {
            $ungrouped_searchable_attributes = $all_searchable_attributes;
        }
        $ungrouped_searchable_attributes = array_unique($ungrouped_searchable_attributes);
        //* Perpare $all_searchable_attributes for using by sort function */
        $temp_attrs = array();
        foreach ($all_searchable_attributes as $slug) {
            $temp_attrs[$slug] = $slug;
        }
        //* Sort stats by groups */
        $stats_by_groups = sort_stats_by_groups($temp_attrs);
        //** If the search widget cannot be created without some data, we bail */
        if (!empty($error)) {
            echo '<p>' . printf(__('No searchable %s types were found.', ud_get_wp_property()->domain), WPP_F::property_label()) . '</p>';
            return;
        }
        ?>

    <ul data-widget_number="<?php 
        echo $this->number;
        ?>
" data-widget="search_properties_widget"
        class="wpp_widget wpp_property_search_wrapper">

      <li class="<?php 
        echo $this->get_field_id('title');
        ?>
">
        <label for="<?php 
        echo $this->get_field_id('title');
        ?>
"><?php 
        _e('Title:', ud_get_wp_property()->domain);
        ?>
          <input class="widefat" id="<?php 
        echo $this->get_field_id('title');
        ?>
"
                 name="<?php 
        echo $this->get_field_name('title');
        ?>
" type="text" value="<?php 
        echo $title;
        ?>
"/>
        </label>
      </li>

      <li class="wpp_property_types">
        <p><?php 
        printf(__('%s types to search:', ud_get_wp_property()->domain), WPP_F::property_label());
        ?>
</p>
        <ul>
          <?php 
        foreach ($all_searchable_property_types as $property_type) {
            ?>
            <li>
              <label
                  for="<?php 
            echo $this->get_field_id('searchable_property_types');
            ?>
_<?php 
            echo $property_type;
            ?>
">
                <input class="wpp_property_types"
                       id="<?php 
            echo $this->get_field_id('searchable_property_types');
            ?>
_<?php 
            echo $property_type;
            ?>
"
                       name="<?php 
            echo $this->get_field_name('searchable_property_types');
            ?>
[]"
                       type="checkbox" <?php 
            if (empty($searchable_property_types)) {
                echo 'checked="checked"';
            }
            ?>
                       value="<?php 
            echo $property_type;
            ?>
" <?php 
            if (is_array($searchable_property_types) && in_array($property_type, $searchable_property_types)) {
                echo " checked ";
            }
            ?>
 />
                <?php 
            echo !empty($wp_properties['property_types'][$property_type]) ? $wp_properties['property_types'][$property_type] : ucwords($property_type);
            ?>
              </label>
            </li>
          <?php 
        }
        ?>
        </ul>
      </li>

      <li class="wpp_attribute_selection">
        <p><?php 
        _e('Select the attributes you want to search.', ud_get_wp_property()->domain);
        ?>
</p>

        <div class="wpp_search_widget_tab wpp_subtle_tabs ">

          <ul class="wpp_section_tabs  tabs">
            <li><a href="#all_atributes_<?php 
        echo $this->id;
        ?>
"><?php 
        _e('All Attributes', ud_get_wp_property()->domain);
        ?>
</a></li>

            <?php 
        if ($stats_by_groups) {
            ?>
              <li><a href="#grouped_attributes_<?php 
            echo $this->id;
            ?>
"><?php 
            _e('Grouped Attributes', ud_get_wp_property()->domain);
            ?>
</a>
              </li>
            <?php 
        }
        ?>
          </ul>

          <div id="all_atributes_<?php 
        echo $this->id;
        ?>
" class="wp-tab-panel wpp_all_attributes">
            <ul class="wpp_sortable_attributes">
              <?php 
        foreach ($ungrouped_searchable_attributes as $attribute) {
            ?>

                <li class="wpp_attribute_wrapper <?php 
            echo $attribute;
            ?>
">
                  <input id="<?php 
            echo $this->get_field_id('searchable_attributes');
            ?>
_<?php 
            echo $attribute;
            ?>
"
                         name="<?php 
            echo $this->get_field_name('searchable_attributes');
            ?>
[]"
                         type="checkbox" <?php 
            if (empty($searchable_attributes)) {
                echo 'checked="checked"';
            }
            ?>
                         value="<?php 
            echo $attribute;
            ?>
" <?php 
            echo is_array($searchable_attributes) && in_array($attribute, $searchable_attributes) ? " checked " : "";
            ?>
 />
                  <label
                      for="<?php 
            echo $this->get_field_id('searchable_attributes');
            ?>
_<?php 
            echo $attribute;
            ?>
"><?php 
            echo apply_filters('wpp::search_attribute::label', empty($property_stats[$attribute]) ? WPP_F::de_slug($attribute) : $property_stats[$attribute], $attribute);
            ?>
</label>
                </li>
              <?php 
        }
        ?>
            </ul>
          </div><?php 
        /* end all (ungrouped) attribute selection */
        ?>

          <?php 
        if ($stats_by_groups) {
            ?>
            <div id="grouped_attributes_<?php 
            echo $this->id;
            ?>
" class="wpp_grouped_attributes_container wp-tab-panel">

              <?php 
            foreach ($stats_by_groups as $gslug => $gstats) {
                ?>
                <?php 
                if ($main_stats_group != $gslug || !key_exists($gslug, $groups)) {
                    ?>
                  <?php 
                    $group_name = key_exists($gslug, $groups) ? $groups[$gslug]['name'] : "<span style=\"color:#8C8989\">" . __('Ungrouped', ud_get_wp_property()->domain) . "</span>";
                    ?>
                  <h2 class="wpp_stats_group"><?php 
                    echo $group_name;
                    ?>
</h2>
                <?php 
                }
                ?>
                <ul>
                  <?php 
                foreach ($gstats as $attribute) {
                    ?>
                    <li>
                      <input
                          id="<?php 
                    echo $this->get_field_id('grouped_searchable_attributes');
                    ?>
_<?php 
                    echo $attribute;
                    ?>
"
                          name="<?php 
                    echo $this->get_field_name('grouped_searchable_attributes');
                    ?>
[]"
                          type="checkbox" <?php 
                    if (empty($grouped_searchable_attributes)) {
                        echo 'checked="checked"';
                    }
                    ?>
                          value="<?php 
                    echo $attribute;
                    ?>
" <?php 
                    echo is_array($grouped_searchable_attributes) && in_array($attribute, $grouped_searchable_attributes) ? " checked " : "";
                    ?>
 />
                      <label
                          for="<?php 
                    echo $this->get_field_id('grouped_searchable_attributes');
                    ?>
_<?php 
                    echo $attribute;
                    ?>
"><?php 
                    echo apply_filters('wpp::search_attribute::label', empty($property_stats[$attribute]) ? WPP_F::de_slug($attribute) : $property_stats[$attribute], $attribute);
                    ?>
</label>
                    </li>
                  <?php 
                }
                ?>
                </ul>
              <?php 
            }
            /* End cycle through $stats_by_groups */
            ?>
            </div>
          <?php 
        }
        ?>

        </div>

      </li>

      <li>

        <?php 
        if ($stats_by_groups) {
            ?>
        <div>
          <input id="<?php 
            echo $this->get_field_id('group_attributes');
            ?>
" class="wpp_toggle_attribute_grouping"
                 type="checkbox" value="true"
                 name="<?php 
            echo $this->get_field_name('group_attributes');
            ?>
" <?php 
            checked($group_attributes, 'true');
            ?>
 />
          <label
              for="<?php 
            echo $this->get_field_id('group_attributes');
            ?>
"><?php 
            _e('Group attributes together.');
            ?>
</label>
        </div>
      </li>
      <?php 
        }
        ?>

      <li>

        <div class="wpp_something_advanced_wrapper" style="margin-top: 10px;">
          <ul>

            <?php 
        if (!empty($wp_properties['sortable_attributes']) && is_array($wp_properties['sortable_attributes'])) {
            ?>
              <li class="wpp_development_advanced_option">
                <div><label
                      for="<?php 
            echo $this->get_field_id('sort_by');
            ?>
"><?php 
            _e('Default Sort Order', ud_get_wp_property()->domain);
            ?>
</label>
                </div>
                <select id="<?php 
            echo $this->get_field_id('sort_by');
            ?>
"
                        name="<?php 
            echo $this->get_field_name('sort_by');
            ?>
">
                  <option></option>
                  <?php 
            foreach ($wp_properties['sortable_attributes'] as $attribute) {
                ?>
                    <option
                        value="<?php 
                echo esc_attr($attribute);
                ?>
"  <?php 
                selected($sort_by, $attribute);
                ?>
 ><?php 
                echo $property_stats[$attribute];
                ?>
</option>
                  <?php 
            }
            ?>
                </select>

                <select id="<?php 
            echo $this->get_field_id('sort_order');
            ?>
"
                        name="<?php 
            echo $this->get_field_name('sort_order');
            ?>
">
                  <option></option>
                  <option value="DESC"  <?php 
            selected($sort_order, 'DESC');
            ?>
 ><?php 
            _e('Descending', ud_get_wp_property()->domain);
            ?>
</option>
                  <option value="ASC"  <?php 
            selected($sort_order, 'ASC');
            ?>
 ><?php 
            _e('Ascending', ud_get_wp_property()->domain);
            ?>
</option>
                </select>

              </li>
            <?php 
        }
        ?>

            <li class="wpp_development_advanced_option">
              <label for="<?php 
        echo $this->get_field_id('use_pagi');
        ?>
">
                <input id="<?php 
        echo $this->get_field_id('use_pagi');
        ?>
"
                       name="<?php 
        echo $this->get_field_name('use_pagi');
        ?>
" type="checkbox"
                       value="on" <?php 
        if ($use_pagi == 'on') {
            echo " checked='checked';";
        }
        ?>
 />
                <?php 
        _e('Use pagination', ud_get_wp_property()->domain);
        ?>
              </label>
            </li>

            <li class="wpp_development_advanced_option">
              <label for="<?php 
        echo $this->get_field_id('strict_search');
        ?>
">
                <input id="<?php 
        echo $this->get_field_id('strict_search');
        ?>
"
                       name="<?php 
        echo $this->get_field_name('strict_search');
        ?>
" type="checkbox"
                       value="on" <?php 
        if ($strict_search == 'on') {
            echo " checked='checked';";
        }
        ?>
 />
                <?php 
        _e('Strict Search', ud_get_wp_property()->domain);
        ?>
              </label>
            </li>

            <li class="wpp_development_advanced_option">
              <label for="<?php 
        echo $this->get_field_id('per_page');
        ?>
"><?php 
        _e('Items per page', ud_get_wp_property()->domain);
        ?>
                <input style="width:30px" id="<?php 
        echo $this->get_field_id('per_page');
        ?>
"
                       name="<?php 
        echo $this->get_field_name('per_page');
        ?>
" type="text"
                       value="<?php 
        echo $per_page;
        ?>
"/>
              </label>
            </li>

            <li>
              <span class="wpp_show_advanced"><?php 
        _e('Toggle Advanced Search Options', ud_get_wp_property()->domain);
        ?>
</span>
            </li>
          </ul>
        </div>
      </li>
    </ul>
  <?php 
    }