<?php
/**
 * @version    $Id$
 * @package    IT_Theme_Framework
 * @author     InnoThemes Team <support@innothemes.com>
 * @copyright  Copyright (C) 2012 InnoThemes.com. All Rights Reserved.
 * @license    GNU/GPL v2 or later http://www.gnu.org/licenses/gpl-2.0.html
 *
 * Websites: http://www.innothemes.com
 */

// Check if this is an Ajax request for specific form section
if ( empty( $section_id ) || ! isset( $_GET['ajax'] ) || ! $_GET['ajax'] ) :
?>
<div class="jsn-master">
	<div class="jsn-bootstrap">
		<div class="<?php if ( ! empty( $alignment ) ) esc_attr_e( "form-{$alignment}" ); ?>" id="<?php esc_attr_e( $this->id ); ?>">
			<div class="it-form-sections <?php if ( ( $numSection = count( $this->fields ) ) > 1 ) echo 'it-form-sections-tabs'; ?>">
<?php if ( $numSection > 1 ) : ?>
				<ul>
					<?php foreach ( $this->fields as $sid => $section ) : ?>
					<li><a href="#it-form-section-<?php esc_attr_e( $sid ); ?>"><?php _e( isset( $section['title'] ) ? $section['title'] : $sid, IT_THEME_TEXTDOMAIN ); ?></a></li>
					<?php endforeach; ?>
				</ul>
<?php
endif;

endif;

foreach ( $this->fields as $sid => $section ) :

// Load section template
if ( ! isset( $_GET['ajax'] ) || ! $_GET['ajax'] || empty($section_id) || $section_id == $sid ) {
	include IT_Loader::get_path( 'form/tmpl/section.php' );
}

endforeach;

// Check if this is an Ajax request for specific form section
if ( empty( $section_id ) || ! isset( $_GET['ajax'] ) || ! $_GET['ajax'] ) :
?>
			</div>
		</div>
	</div>
</div>
<?php
// Print Javascript initialization
$script = '
		// Init form
		new $.IT_Form(' . json_encode( array_merge( array( 'id' => esc_attr( $this->id ) ), array_combine( $js_init, array_map( 'is_string', $js_init ) ) ) ) . ');';

IT_Init_Assets::inline( 'js', $script, true );

endif;

// Exit immediately if this is an Ajax request
if ( isset( $_GET['ajax'] ) && $_GET['ajax'] ) {
	exit;
}
