function wpv_filter_shortcode_start($atts){
	
	global $WP_Views;
	$view_id = $WP_Views->get_current_view();
	$view_settings = $WP_Views->get_view_settings();
	$view_layout_settings = $WP_Views->get_view_layout_settings();
	$view_attrs = $WP_Views->get_view_shortcodes_attributes();
	$is_required = false;
	$dps_enabled = false;
	$counters_enabled = false;
	$out = '';
    if ( _wpv_filter_is_form_required() ) {
		
		$is_required = true;
		
        extract(
            shortcode_atts( array(), $atts )
        );
        
        $hide = '';
        if (
			( isset( $atts['hide'] ) && $atts['hide'] == 'true' )
			|| ( isset( $view_attrs['view_display'] ) && $view_attrs['view_display'] == 'layout' )
		) {
            $hide = ' style="display:none;"';
        }
        
        $form_class = array( 'js-wpv-form-full' );
        // Dependant stuf
        if ( !isset( $view_settings['dps'] ) || !is_array( $view_settings['dps'] ) ) {
			$view_settings['dps'] = array();
		}
		if ( isset( $view_settings['dps']['enable_dependency'] ) && $view_settings['dps']['enable_dependency'] == 'enable' ) {
			$dps_enabled = true;
			$controls_per_kind = wpv_count_filter_controls( $view_settings );
			$controls_count = 0;
			$no_intersection = array();
			if ( !isset( $controls_per_kind['error'] ) ) {
				$controls_count = $controls_per_kind['cf'] + $controls_per_kind['tax'] + $controls_per_kind['pr'] + $controls_per_kind['search'];
				if ( $controls_per_kind['cf'] > 1 && ( !isset( $view_settings['custom_fields_relationship'] ) || $view_settings['custom_fields_relationship'] != 'AND' ) ) {
					$no_intersection[] = __( 'custom field', 'wpv-views' );
				}
				if ( $controls_per_kind['tax'] > 1 && ( !isset( $view_settings['taxonomy_relationship'] ) || $view_settings['taxonomy_relationship'] != 'AND' ) ) {
					$no_intersection[] = __( 'taxonomy', 'wpv-views' );
				}
			} else {
				$dps_enabled = false;
			}
			if ( $controls_count > 0 ) {
				if ( count( $no_intersection ) > 0 ) {
					$dps_enabled = false;
				}
			} else {
				$dps_enabled = false;
			}
		}
		if ( !isset( $view_settings['filter_meta_html'] ) ) {
			$view_settings['filter_meta_html'] = '';
		}
		if ( strpos( $view_settings['filter_meta_html'], '%%COUNT%%' ) !== false ) {
			$counters_enabled = true;
		}
		if ( $dps_enabled || $counters_enabled ) {
			// TODO review this, makes little sense
			if ( $dps_enabled ) {
				$form_class[] = 'js-wpv-dps-enabled';
			}
		} else {
			// Set the force value
			$WP_Views->set_force_disable_dependant_parametric_search( true );
		}
        if ( !isset( $view_settings['dps']['ajax_results'] ) ) {
			$view_settings['dps']['ajax_results'] = 'disable';
		}
		if ( !isset( $view_settings['dps']['ajax_results_submit'] ) ) {
			$view_settings['dps']['ajax_results_submit'] = 'reload';
		}
		$ajax = $view_settings['dps']['ajax_results'];
		$ajax_submit = $view_settings['dps']['ajax_results_submit'];
		if ( $ajax == 'enable' ) {
			$form_class[] = 'js-wpv-ajax-results-enabled';
		} else if ( $ajax == 'disable' && $ajax_submit == 'ajaxed' ) {
			$form_class[] = 'js-wpv-ajax-results-submit-enabled';
		}
		

        $page = 1;
		
        $effect = 'fade';
		$ajax_pre_before = '';
		if ( isset( $view_settings['dps']['ajax_results_pre_before'] ) ) {
			$ajax_pre_before = esc_attr( $view_settings['dps']['ajax_results_pre_before'] );
		}
        $ajax_before = '';
        if ( isset( $view_settings['dps']['ajax_results_before'] ) ) {
			$ajax_before = esc_attr( $view_settings['dps']['ajax_results_before'] );
        }
        $ajax_after = '';
        if ( isset( $view_settings['dps']['ajax_results_after'] ) ) {
			$ajax_after = esc_attr( $view_settings['dps']['ajax_results_after'] );
        }
        
        $url = get_permalink();
        $out = '<form' . $hide . ' autocomplete="off" name="wpv-filter-' . $WP_Views->get_view_count() . '" action="' . $url . '" method="get" class="wpv-filter-form js-wpv-filter-form js-wpv-filter-form-' . $WP_Views->get_view_count() . ' ' . implode( ' ', $form_class ) . '" data-viewnumber="' . $WP_Views->get_view_count() . '" data-viewid="' . $view_id . '">';
        
        $out .= '<input type="hidden" class="js-wpv-dps-filter-data js-wpv-filter-data-for-this-form" data-action="' . $url . '" data-page="' . $page . '" data-ajax="' . $ajax . '" data-effect="' . $effect . '" data-maxpages="' . $WP_Views->get_max_pages() . '" data-ajaxprebefore="' . $ajax_pre_before . '" data-ajaxbefore="' . $ajax_before . '" data-ajaxafter="' . $ajax_after . '" />';
        
		// Set a hidden input for the View attributes, so we can pass them if needed
		if ( isset( $view_attrs['name'] ) ) {
			unset( $view_attrs['name'] );
		}
		if ( !empty( $view_attrs ) ) {
			$att_data = '';
			foreach ( $view_attrs as $att_key => $att_val ) {
				$att_data .= ' data-' . $att_key . '="' . esc_attr( $att_val ) . '"';
			}
			$out .= '<input type="hidden" class="js-wpv-view-attributes"' . $att_data . ' />';
		}
		
        // add hidden inputs for any url parameters.
        // We need these for when the form is submitted.
        $url_query = parse_url($url, PHP_URL_QUERY);
        if ($url_query != '') {
            $query_parts = explode('&', $url_query);
            foreach($query_parts as $param) {
                $item = explode('=', $param);
                if (strpos($item[0], 'wpv_') !== 0) {
                    $out .= '<input id="wpv_param_' . $item[0] . '" type="hidden" name="' . $item[0] . '" value="' . $item[1] . '" />';
                }
            }
        }
        
        // Add hidden inputs for column sorting id and direction:
        // these start populated with the View settings values and will be changed when a column title is clicked.
        if (isset($view_layout_settings['style']) && ($view_layout_settings['style'] == 'table_of_fields' or $view_layout_settings['style'] == 'table')) {
            if ($view_settings['query_type'][0] == 'posts') {
                $sort_id = $view_settings['orderby'];
                $sort_dir = strtolower($view_settings['order']);
            }
            if ($view_settings['query_type'][0] == 'taxonomy') {
                $sort_id = $view_settings['taxonomy_orderby'];
                $sort_dir = strtolower($view_settings['taxonomy_order']);
            }
            if ($view_settings['query_type'][0] == 'users') {
                $sort_id = $view_settings['users_orderby'];
                $sort_dir = strtolower($view_settings['users_order']);
            }

            if (
				isset( $_GET['wpv_column_sort_id'] ) 
				&& esc_attr( $_GET['wpv_column_sort_id'] ) != '' 
				&& isset( $_GET['wpv_view_count'] ) 
				&& esc_attr( $_GET['wpv_view_count'] ) == $WP_Views->get_view_count() 
			) {
                $sort_id = esc_attr( $_GET['wpv_column_sort_id'] );
            }
            if (
				isset( $_GET['wpv_column_sort_dir'] ) 
				&& esc_attr( $_GET['wpv_column_sort_dir'] ) != '' 
				&& isset( $_GET['wpv_view_count'] ) 
				&& esc_attr( $_GET['wpv_view_count'] ) == $WP_Views->get_view_count()
			) {
                $sort_dir = esc_attr( $_GET['wpv_column_sort_dir'] );
            }
            
            $out .= '<input id="wpv_column_sort_id" type="hidden" name="wpv_column_sort_id" value="' . $sort_id . '" />';
            $out .= '<input id="wpv_column_sort_dir" type="hidden" name="wpv_column_sort_dir" value="' . $sort_dir . '" />';
        }
        
        /**
        * Add other hidden fields for:
        *
        * max number of pages for this View
        * preload reach
        * widget ID when aplicable
        * View count for multiple Views per pages
        * View hash
        * current post ID when needed
        */
        
		/**
		* @todo this might not need a name at all...
		*/
        $out .= '<input id="wpv_paged_max-' . $WP_Views->get_view_count() . '" type="hidden" name="wpv_paged_max" value="' . intval($WP_Views->get_max_pages()) . '" />';
        
        if ( isset( $view_settings['pagination']['pre_reach'] ) ) { $pre_reach = intval($view_settings['pagination']['pre_reach']); } else { $pre_reach = 1; }
		/**
		* @todo this might not need a name at all...
		*/
        $out .= '<input id="wpv_paged_preload_reach-' . $WP_Views->get_view_count() . '" type="hidden" name="wpv_paged_preload_reach" value="' . $pre_reach . '" />';
        
        $out .= '<input id="wpv_widget_view-' . $WP_Views->get_view_count() . '" type="hidden" name="wpv_widget_view_id" value="' . intval($WP_Views->get_widget_view_id()) . '" />';
        $out .= '<input id="wpv_view_count-' . $WP_Views->get_view_count() . '" type="hidden" name="wpv_view_count" value="' . $WP_Views->get_view_count() . '" />';

        $view_data = $WP_Views->get_view_shortcodes_attributes();
        //$view_data['view_id'] = $WP_Views->get_current_view();
        $out .= '<input id="wpv_view_hash-' . $WP_Views->get_view_count() . '" type="hidden" name="wpv_view_hash" value="' . base64_encode(json_encode($view_data)) . '" />';
    
        $requires_current_page = false;
		/**
		* wpv_filter_requires_current_page
		*
		* Whether the current View requires the current page for any filter
		*
		* @param $requires_current_page boolean
		* @param $view_settings
		*
		* @since unknown
		*/
        $requires_current_page = apply_filters('wpv_filter_requires_current_page', $requires_current_page, $view_settings);
        if ( $requires_current_page ) {
            $current_post = $WP_Views->get_top_current_page();
            if (
				$current_post 
				&& isset( $current_post->ID ) 
			) {
                $out .= '<input id="wpv_post_id-' . esc_attr( $WP_Views->get_view_count() ) . '" type="hidden" name="wpv_post_id" value="' . esc_attr( $current_post->ID ) . '" class="js-wpv-keep-on-clear" />';
            }
        }
		
		$requires_parent_term = false;
		/**
		* wpv_filter_requires_parent_term
		*
		* Whether the current View is nested and requires the parent term for any filter
		*
		* @param $requires_parent_term boolean
		* @param $view_settings
		*
		* @since unknown
		*/
		$requires_parent_term = apply_filters( 'wpv_filter_requires_parent_term', $requires_parent_term, $view_settings );
		if ( $requires_parent_term ) {
            $parent_term_id = $WP_Views->get_parent_view_taxonomy();
            if ( $parent_term_id ) {
                $out .= '<input id="wpv_aux_parent_term_id-' . esc_attr( $WP_Views->get_view_count() ) . '" type="hidden" name="wpv_aux_parent_term_id" value="' . esc_attr( $parent_term_id ) . '" class="js-wpv-keep-on-clear" />';
            }
        }
		
		$requires_parent_user = false;
		/**
		* wpv_filter_requires_parent_user
		*
		* Whether the current View is nested and requires the parent user for any filter
		*
		* @param $requires_parent_user boolean
		* @param $view_settings
		*
		* @since unknown
		*/
		$requires_parent_user = apply_filters( 'wpv_filter_requires_parent_user', $requires_parent_user, $view_settings );
		if ( $requires_parent_user ) {
            $parent_user_id = $WP_Views->get_parent_view_user();
            if ( $parent_user_id ) {
                $out .= '<input id="wpv_aux_parent_user_id-' . esc_attr( $WP_Views->get_view_count() ) . '" type="hidden" name="wpv_aux_parent_user_id" value="' . esc_attr( $parent_user_id ) . '" class="js-wpv-keep-on-clear" />';
            }
        }
		
        add_action('wp_footer', 'wpv_pagination_js');
        
        // Rollover
        if (isset($view_settings['pagination']['mode']) && $view_settings['pagination']['mode'] == 'rollover') {
            wpv_pagination_rollover_shortcode();
        }
        
    }
    
	/**
	* Filter wpv_filter_start_filter_form
	*
	* @param $out the default form opening tag followed by the required hidden input tags needed for pagination and table sorting
	* @param $view_settings the current View settings
	* @param $view_id the ID of the View being displayed
	* @param $is_required [true|false] whether this View requires a form to be displayed (has a parametric search OR uses table sorting OR uses pagination)
	*
	* This can be useful to create additional inputs for the current form without needing to add them to the Filter HTML textarea
	* Also, can help users having formatting issues
	*
	* @return $out
	*
	* Since 1.5.1
	*
	*/
	
	$out = apply_filters( 'wpv_filter_start_filter_form', $out, $view_settings, $view_id, $is_required );
    
    return $out;
}
function wpv_filter_shortcode_start($atts)
{
    if (_wpv_filter_is_form_required()) {
        global $WP_Views;
        extract(shortcode_atts(array(), $atts));
        $hide = '';
        if (isset($atts['hide']) && $atts['hide'] == 'true') {
            $hide = ' display:none;';
        }
        $url = get_permalink();
        $out = '<form style="margin:0; padding:0;' . $hide . '" name="wpv-filter-' . $WP_Views->get_view_count() . '" action="' . $url . '" method="get" class="wpv-filter-form"' . ">\n";
        // add hidden inputs for any url parameters.
        // We need these for when the form is submitted.
        $url_query = parse_url($url, PHP_URL_QUERY);
        if ($url_query != '') {
            $query_parts = explode('&', $url_query);
            foreach ($query_parts as $param) {
                $item = explode('=', $param);
                if (strpos($item[0], 'wpv_') !== 0) {
                    $out .= '<input id="wpv_param_' . $item[0] . '" type="hidden" name="' . $item[0] . '" value="' . $item[1] . '" />' . "\n";
                }
            }
        }
        // add hidden inputs for column sorting id and direction.
        // these are empty to start off with but will be populated
        // when a column title is clicked.
        $view_layout_settings = $WP_Views->get_view_layout_settings();
        if (!isset($view_layout_settings['style'])) {
            return '';
        }
        $view_settings = $WP_Views->get_view_settings();
        if ($view_layout_settings['style'] == 'table_of_fields' or $view_layout_settings['style'] == 'table') {
            if ($view_settings['query_type'][0] == 'posts') {
                $sort_id = $view_settings['orderby'];
                $sort_dir = strtolower($view_settings['order']);
            }
            if ($view_settings['query_type'][0] == 'taxonomy') {
                $sort_id = $view_settings['taxonomy_orderby'];
                $sort_dir = strtolower($view_settings['taxonomy_order']);
            }
            if (isset($_GET['wpv_column_sort_id'])) {
                $sort_id = esc_attr($_GET['wpv_column_sort_id']);
            }
            if (isset($_GET['wpv_column_sort_dir'])) {
                $sort_dir = esc_attr($_GET['wpv_column_sort_dir']);
            }
            $out .= '<input id="wpv_column_sort_id" type="hidden" name="wpv_column_sort_id" value="' . $sort_id . '" />' . "\n";
            $out .= '<input id="wpv_column_sort_dir" type="hidden" name="wpv_column_sort_dir" value="' . $sort_dir . '" />' . "\n";
            $out .= "\n            <script type=\"text/javascript\">\n                function wpv_column_head_click_" . $WP_Views->get_view_count() . "(name, direction) {\n                    jQuery('#wpv_column_sort_id').val(name);\n                    jQuery('#wpv_column_sort_dir').val(direction);\n                    wpv_add_url_controls_for_column_sort(jQuery('#wpv-filter-" . $WP_Views->get_view_count() . "'));\n                    jQuery('form[name=\"wpv-filter-" . $WP_Views->get_view_count() . "\"]').submit();\n                    return false;\n                }\n            </script>\n            ";
        }
        $out .= '<input id="wpv_paged_max-' . $WP_Views->get_view_count() . '" type="hidden" name="wpv_paged_max" value="' . intval($WP_Views->get_max_pages()) . '" />' . "\n";
        $out .= '<input id="wpv_widget_view-' . $WP_Views->get_view_count() . '" type="hidden" name="wpv_widget_view_id" value="' . intval($WP_Views->get_widget_view_id()) . '" />' . "\n";
        $out .= '<input id="wpv_view_count-' . $WP_Views->get_view_count() . '" type="hidden" name="wpv_view_count" value="' . $WP_Views->get_view_count() . '" />' . "\n";
        $view_data = $WP_Views->get_view_shortcodes_attributes();
        //$view_data['view_id'] = $WP_Views->get_current_view();
        $out .= '<input id="wpv_view_hash-' . $WP_Views->get_view_count() . '" type="hidden" name="wpv_view_hash" value="' . base64_encode(serialize($view_data)) . '" />' . "\n";
        $requires_current_page = false;
        $requires_current_page = apply_filters('wpv_filter_requires_current_page', $requires_current_page, $view_settings);
        if ($requires_current_page) {
            // Output the current page ID. This is used for ajax call back in pagination.
            $current_post = $WP_Views->get_top_current_page();
            if ($current_post && isset($current_post->ID)) {
                $out .= '<input id="wpv_post_id-' . $WP_Views->get_view_count() . '" type="hidden" name="wpv_post_id" value="' . $current_post->ID . '" />' . "\n";
            }
        }
        add_action('wp_footer', 'wpv_pagination_js');
        // Rollover
        if (isset($view_settings['pagination']['mode']) && $view_settings['pagination']['mode'] == 'rollover') {
            wpv_pagination_rollover_shortcode();
        }
        return $out;
    } else {
        return '';
    }
}
function wpv_filter_shortcode_start($atts)
{
    global $WP_Views;
    $view_id = $WP_Views->get_current_view();
    $view_settings = $WP_Views->get_view_settings();
    $view_layout_settings = $WP_Views->get_view_layout_settings();
    $is_required = false;
    $out = '';
    if (_wpv_filter_is_form_required()) {
        $is_required = true;
        extract(shortcode_atts(array(), $atts));
        $hide = '';
        if (isset($atts['hide']) && $atts['hide'] == 'true') {
            $hide = ' style="display:none;"';
        }
        $url = get_permalink();
        $out = '<form' . $hide . ' name="wpv-filter-' . $WP_Views->get_view_count() . '" action="' . $url . '" method="get" class="wpv-filter-form">';
        // add hidden inputs for any url parameters.
        // We need these for when the form is submitted.
        $url_query = parse_url($url, PHP_URL_QUERY);
        if ($url_query != '') {
            $query_parts = explode('&', $url_query);
            foreach ($query_parts as $param) {
                $item = explode('=', $param);
                if (strpos($item[0], 'wpv_') !== 0) {
                    $out .= '<input id="wpv_param_' . $item[0] . '" type="hidden" name="' . $item[0] . '" value="' . $item[1] . '" />';
                }
            }
        }
        // Add hidden inputs for column sorting id and direction:
        // these start populated with the View settings values and will be changed when a column title is clicked.
        if (isset($view_layout_settings['style']) && ($view_layout_settings['style'] == 'table_of_fields' or $view_layout_settings['style'] == 'table')) {
            if ($view_settings['query_type'][0] == 'posts') {
                $sort_id = $view_settings['orderby'];
                $sort_dir = strtolower($view_settings['order']);
            }
            if ($view_settings['query_type'][0] == 'taxonomy') {
                $sort_id = $view_settings['taxonomy_orderby'];
                $sort_dir = strtolower($view_settings['taxonomy_order']);
            }
            if ($view_settings['query_type'][0] == 'users') {
                $sort_id = $view_settings['users_orderby'];
                $sort_dir = strtolower($view_settings['users_order']);
            }
            if (isset($_GET['wpv_column_sort_id']) && esc_attr($_GET['wpv_column_sort_id']) != '' && isset($_GET['wpv_view_count']) && esc_attr($_GET['wpv_view_count']) == $WP_Views->get_view_count()) {
                $sort_id = esc_attr($_GET['wpv_column_sort_id']);
            }
            if (isset($_GET['wpv_column_sort_dir']) && esc_attr($_GET['wpv_column_sort_dir']) != '' && isset($_GET['wpv_view_count']) && esc_attr($_GET['wpv_view_count']) == $WP_Views->get_view_count()) {
                $sort_dir = esc_attr($_GET['wpv_column_sort_dir']);
            }
            $out .= '<input id="wpv_column_sort_id" type="hidden" name="wpv_column_sort_id" value="' . $sort_id . '" />';
            $out .= '<input id="wpv_column_sort_dir" type="hidden" name="wpv_column_sort_dir" value="' . $sort_dir . '" />';
        }
        /**
         * Add other hidden fields for:
         *
         * max number of pages for this View
         * preload reach
         * widget ID when aplicable
         * View count for multiple Views per pages
         * View hash
         * current post ID when needed
         */
        $out .= '<input id="wpv_paged_max-' . $WP_Views->get_view_count() . '" type="hidden" name="wpv_paged_max" value="' . intval($WP_Views->get_max_pages()) . '" />';
        if (isset($view_settings['pagination']['pre_reach'])) {
            $pre_reach = intval($view_settings['pagination']['pre_reach']);
        } else {
            $pre_reach = 1;
        }
        $out .= '<input id="wpv_paged_preload_reach-' . $WP_Views->get_view_count() . '" type="hidden" name="wpv_paged_preload_reach" value="' . $pre_reach . '" />';
        $out .= '<input id="wpv_widget_view-' . $WP_Views->get_view_count() . '" type="hidden" name="wpv_widget_view_id" value="' . intval($WP_Views->get_widget_view_id()) . '" />';
        $out .= '<input id="wpv_view_count-' . $WP_Views->get_view_count() . '" type="hidden" name="wpv_view_count" value="' . $WP_Views->get_view_count() . '" />';
        $view_data = $WP_Views->get_view_shortcodes_attributes();
        //$view_data['view_id'] = $WP_Views->get_current_view();
        $out .= '<input id="wpv_view_hash-' . $WP_Views->get_view_count() . '" type="hidden" name="wpv_view_hash" value="' . base64_encode(serialize($view_data)) . '" />';
        $requires_current_page = false;
        $requires_current_page = apply_filters('wpv_filter_requires_current_page', $requires_current_page, $view_settings);
        if ($requires_current_page) {
            // Output the current page ID. This is used for ajax call back in pagination.
            $current_post = $WP_Views->get_top_current_page();
            if ($current_post && isset($current_post->ID)) {
                $out .= '<input id="wpv_post_id-' . $WP_Views->get_view_count() . '" type="hidden" name="wpv_post_id" value="' . $current_post->ID . '" />';
            }
        }
        add_action('wp_footer', 'wpv_pagination_js');
        // Rollover
        if (isset($view_settings['pagination']['mode']) && $view_settings['pagination']['mode'] == 'rollover') {
            wpv_pagination_rollover_shortcode();
        }
    }
    /**
     * Filter wpv_filter_start_filter_form
     *
     * @param $out the default form opening tag followed by the required hidden input tags needed for pagination and table sorting
     * @param $view_settings the current View settings
     * @param $view_id the ID of the View being displayed
     * @param $is_required [true|false] whether this View requires a form to be displayed (has a parametric search OR uses table sorting OR uses pagination)
     *
     * This can be useful to create additional inputs for the current form without needing to add them to the Filter HTML textarea
     * Also, can help users having formatting issues
     *
     * @return $out
     *
     * Since 1.5.1
     *
     */
    $out = apply_filters('wpv_filter_start_filter_form', $out, $view_settings, $view_id, $is_required);
    return $out;
}