function sunshine_gallery_options_box_html($post)
{
    if (empty($post)) {
        $post_id = '';
    } else {
        $post_id = $post->ID;
    }
    $price_levels = get_terms('sunshine-product-price-level', array('hide_empty' => false));
    if (count($price_levels) > 1) {
        echo '<tr><th><label for="sunshine_gallery_price_level">' . __('Price Level', 'sunshine') . '</label></th>';
        echo '<td>';
        if (count($price_levels) > 1) {
            echo '<select id="sunshine_gallery_price_level" name="sunshine_gallery_price_level">';
            $current_price_level = get_post_meta($post_id, 'sunshine_gallery_price_level', true);
            foreach ($price_levels as $price_level) {
                echo '<option value="' . $price_level->term_id . '"' . selected($current_price_level, $price_level->term_id, false) . '>' . $price_level->name . '</option>';
            }
            echo '</select>';
        } else {
            echo '<input type="hidden" value="' . $price_levels[0]->term_id . '" /> ' . $price_levels[0]->name;
            echo '<br /><small><a href="edit-tags.php?taxonomy=sunshine-product-price-level&post_type=sunshine-product">Add new price level</a></small>';
        }
        echo '</td></tr>';
    } else {
        echo '<input type="hidden" name="sunshine_gallery_price_level" value="' . $price_levels[0]->term_id . '" />';
    }
    $gallery_status = get_post_meta($post_id, 'sunshine_gallery_status', true);
    echo '<tr><th><label for="sunshine_gallery_status">' . __('Gallery Type', 'sunshine') . '</label></th>';
    echo '<td><select name="sunshine_gallery_status">';
    echo '<option value="">' . __('Standard', 'sunshine') . '</option>';
    echo '<option value="password" ' . selected($gallery_status, 'password', 0) . '>' . __('Password Protected', 'sunshine') . '</option>';
    echo '<option value="private" ' . selected($gallery_status, 'private', 0) . '>' . __('Private (only specified users)', 'sunshine') . '</option>';
    echo '</select>';
    /* Options basde on access type */
    /* Password protected */
    echo '<div class="sunshine-status-password sunshine-status-options" style="display: ' . ($gallery_status == 'password' ? '' : 'none') . ';"><label for="sunshine_gallery_password">' . __('Password', 'sunshine') . '</label> ';
    echo '<input name="sunshine_gallery_password" value="' . esc_attr($post->post_password) . '" /> ';
    echo '<label for="sunshine_gallery_password_hint">' . __('Password Hint', 'sunshine') . '</label> ';
    echo '<input name="sunshine_gallery_password_hint" value="' . esc_attr(get_post_meta($post_id, 'sunshine_gallery_password_hint', true)) . '" /></div>';
    /* Private */
    $clients = get_users();
    if ($clients) {
        $selected_users = get_post_meta($post->ID, 'sunshine_gallery_private_user');
        $client_list = '<select name="sunshine_gallery_private_user[]" class="sunshine-multiselect" multiple="multiple">';
        foreach ($clients as $client) {
            $checked = in_array($client->ID, $selected_users) ? ' selected="selected"' : '';
            $client_list .= '<option value="' . $client->ID . '"' . $checked . ' />' . esc_attr($client->display_name) . '</option>';
        }
        $client_list .= '</select>';
    }
    echo '<div class="sunshine-status-private sunshine-status-options" style="display: ' . ($post->post_status == 'private' ? '' : 'none') . ';"><label for="sunshine_gallery_private_user">' . __('Private Access Users', 'sunshine') . '</label> ';
    echo $client_list . '</div>';
    echo '</td></tr>';
    $gallery_access = get_post_meta($post_id, 'sunshine_gallery_access', true);
    echo '<tr><th><label for="sunshine_gallery_access">' . __('Access Type', 'sunshine') . '</label></th>';
    echo '<td><select name="sunshine_gallery_access">';
    echo '<option value="">' . __('None', 'sunshine') . '</option>';
    echo '<option value="account" ' . selected($gallery_access, 'account', 0) . '>' . __('Registered and logged in', 'sunshine') . '</option>';
    echo '<option value="email" ' . selected($gallery_access, 'email', 0) . '>' . __('Provide email address', 'sunshine') . '</option>';
    echo '</select></td></tr>';
    $end_date = get_post_meta($post_id, 'sunshine_gallery_end_date', true);
    $end_date_hidden = $end_date_picker = $end_hour = '';
    if ($end_date) {
        $end_date_picker = esc_attr(date(get_option('date_format'), $end_date));
        $end_date_hidden = esc_attr(date('Y-m-d', $end_date));
        $end_hour = date('G', $end_date);
    }
    echo '<tr><th>' . __('End Date', 'sunshine') . '</th><td><input type="text" name="end_date" class="datepicker" value="' . $end_date_picker . '" /> <input type="hidden" id="sunshine-end-date" name="sunshine_end_date" value="' . $end_date_hidden . '" /> @ ';
    echo '<select name="end_hour"><option></option>';
    for ($i = 0; $i < 24; $i++) {
        echo '<option value="' . $i . '" ' . selected($i, $end_hour, 0) . '>' . ($i % 12 ? $i % 12 : 12) . ':00' . ($i >= 12 ? 'pm' : 'am') . '</option>';
    }
    echo '</select>';
    echo '</td></tr>';
    ?>
	<script>
	jQuery(document).ready(function($){
		$('select[name="sunshine_gallery_status"]').change(function(){
			var gallery_status = $(this).val();
			$('.sunshine-status-options').hide();
			$('.sunshine-status-' + gallery_status ).show();
		});
		jQuery('.datepicker').datepicker( {
			dateFormat: '<?php 
    echo sunshine_date_format_php_to_js(get_option('date_format'));
    ?>
',
			gotoCurrent: true,
			altField: '#sunshine-end-date',
			altFormat: 'yy-mm-dd'
		}).keyup(function(e) {
		    if(e.keyCode == 8 || e.keyCode == 46) {
		        $.datepicker._clearDate(this);
		    }
		});
	});
	</script>

	<?php 
    echo '<tr><th><label for="sunshine_gallery_disable_products">' . __('Disable products', 'sunshine') . '</label></th>';
    echo '<td><label><input type="checkbox" name="sunshine_gallery_disable_products" value="1" ' . checked(get_post_meta($post_id, 'sunshine_gallery_disable_products', true), 1, 0) . ' /> Users will not be able to purchase any products for this gallery</label></td></tr>';
    echo '<tr><th><label for="sunshine_gallery_image_comments">' . __('Allow image comments', 'sunshine') . '</label></th>';
    echo '<td><label><input type="checkbox" name="sunshine_gallery_image_comments" value="1" ' . checked(get_post_meta($post_id, 'sunshine_gallery_image_comments', true), 1, 0) . ' /> Allow users to make comments on images</label></td></tr>';
    echo '<tr><th><label for="sunshine_gallery_images_directory">' . __('FTP Images Folder', 'sunshine') . '</label></th>';
    echo '<td><select id="sunshine_gallery_images_directory" name="sunshine_gallery_images_directory"><option value="">Please select folder</option>';
    $upload_dir = wp_upload_dir();
    $selected_dir = get_post_meta($post_id, 'sunshine_gallery_images_directory', true);
    $folders = scandir($upload_dir['basedir'] . '/sunshine');
    $folders = apply_filters('sunshine_gallery_images_directory', $folders);
    foreach ($folders as $item) {
        if (is_numeric($item) || is_numeric(str_replace('-download', '', $item))) {
            continue;
        }
        // Skip number folders, those were created by Sunshine
        if ($item != '.' && $item != '..') {
            $count = sunshine_image_folder_count($upload_dir['basedir'] . '/sunshine/' . $item);
            if ($selected_dir == $item) {
                $selected = ' selected="selected"';
            } else {
                $selected = '';
            }
            if ($count > 0) {
                echo '<option value="' . $item . '"' . $selected . '>' . $item . ' (' . $count . ' images)</option>';
            }
        }
    }
    echo '</select></td></tr>';
}
function sunshine_add_order_data()
{
    ?>
	<form method="post">
	<p>
		<?php 
    _e('Customer', 'sunshine');
    ?>
:<br />
		<select name="customer" class="sunshine-multiselect">
			<option value=""><?php 
    _e('Guest', 'sunshine');
    ?>
</option>
			<?php 
    $users = get_users();
    foreach ($users as $user) {
        echo '<option value="' . $user->ID . '">' . $user->display_name . '</option>';
    }
    ?>
		</select>
	</p>
	<p id="email">
		<?php 
    _e('Email', 'sunshine');
    ?>
<br />
		<input type="email" name="email" />
	</p>
	<p>
		<?php 
    _e('Order Date', 'sunshine');
    ?>
:<br />
		<input type="text" name="date" class="datepicker" />
	</p>
	<p>
		<?php 
    _e('Order Status', 'sunshine');
    ?>
<br />
		<select name="status">
			<?php 
    $statuses = get_terms('sunshine-order-status', 'hide_empty=0&orderby=id&order=ASC');
    foreach ($statuses as $status) {
        echo '<option value="' . $status->term_id . '">' . $status->name . '</option>';
    }
    ?>
		</select>
	</p>
	<div style="width: 45%; float: left;">
		<h4><?php 
    _e('Billing Information', 'sunshine');
    ?>
</h4>
		<p>
			<?php 
    _e('Country', 'sunshine');
    ?>
<br />
			<?php 
    SunshineCountries::country_only_dropdown('country', '');
    ?>
		</p>
		<p>
			<?php 
    _e('First Name', 'sunshine');
    ?>
<br />
			<input type="text" name="first_name" />
		</p>
		<p>
			<?php 
    _e('Last Name', 'sunshine');
    ?>
<br />
			<input type="text" name="last_name" />
		</p>
		<p>
			<?php 
    _e('Address', 'sunshine');
    ?>
<br />
			<input type="text" name="address" />
		</p>
		<p>
			<?php 
    _e('Address 2', 'sunshine');
    ?>
<br />
			<input type="text" name="address2" />
		</p>
		<p>
			<?php 
    _e('City', 'sunshine');
    ?>
<br />
			<input type="text" name="city" />
		</p>
		<p id="sunshine-billing-state">
			<?php 
    _e('State', 'sunshine');
    ?>
<br />
			<?php 
    SunshineCountries::state_dropdown('', 'state', '');
    ?>
		</p>
	</div>
	<div style="width: 45%; float: right;">
		<h4><?php 
    _e('Shipping Information', 'sunshine');
    ?>
</h4>
	<p>
		<?php 
    _e('Country', 'sunshine');
    ?>
<br />
		<?php 
    SunshineCountries::country_only_dropdown('shipping_country', '');
    ?>
	</p>
	<p>
		<?php 
    _e('First Name', 'sunshine');
    ?>
<br />
		<input type="text" name="shipping_first_name" />
	</p>
	<p>
		<?php 
    _e('Last Name', 'sunshine');
    ?>
<br />
		<input type="text" name="shipping_last_name" />
	</p>
	<p>
		<?php 
    _e('Address', 'sunshine');
    ?>
<br />
		<input type="text" name="shipping_address" />
	</p>
	<p>
		<?php 
    _e('Address 2', 'sunshine');
    ?>
<br />
		<input type="text" name="shipping_address2" />
	</p>
	<p>
		<?php 
    _e('City', 'sunshine');
    ?>
<br />
		<input type="text" name="shipping_city" />
	</p>
	<p id="sunshine-shipping-state">
		<?php 
    _e('State', 'sunshine');
    ?>
<br />
		<?php 
    SunshineCountries::state_dropdown('', 'shipping_state', '');
    ?>
	</p>
	</div>
	<br clear="both" />

	<h4><?php 
    _e('Order Items', 'sunshine');
    ?>
</h4>
	<table style="width: 100%;">
	<tr>
		<th><?php 
    _e('Gallery', 'sunshine');
    ?>
</th>
		<th><?php 
    _e('Image', 'sunshine');
    ?>
</th>
		<th><?php 
    _e('Product', 'sunshine');
    ?>
</th>
		<th><?php 
    _e('Qty', 'sunshine');
    ?>
</th>
		<th><?php 
    _e('Item Total', 'sunshine');
    ?>
</th>
	</tr>
	<tr>
		<td>
			<select name="gallery">
				<option value=""><?php 
    _e('Select gallery', 'sunshine');
    ?>
</option>
				<?php 
    $galleries = get_posts('post_type=sunshine-gallery&nopaging=true');
    foreach ($galleries as $gallery) {
        echo '<option value="' . $gallery->ID . '">' . $gallery->post_title . '</option>';
    }
    ?>
			</select>
		</td>
		<td>
			<select name="image[]">
			</select>
		</td>
		<td>
			<select name="product[]">

			</select>
		</td>
		<td>
		</td>
	</tr>
	</table>

	</form>

	<script>
	jQuery( document ).ready( function($) {
		$(".sunshine-multiselect").select2({
		    width: '100%',
			allowClear: true
		});

		$( 'select[name="customer"]' ).change(function(){
			if ( $( this ).val() == '' ) {
				$( '#email' ).show();
			} else {
				$( '#email' ).hide();
			}
		});

		jQuery('.datepicker').datepicker( {
			dateFormat: '<?php 
    echo sunshine_date_format_php_to_js(get_option('date_format'));
    ?>
',
			gotoCurrent: true,
		}).keyup(function(e) {
		    if(e.keyCode == 8 || e.keyCode == 46) {
		        $.datepicker._clearDate(this);
		    }
		});

		// Changing state selection
		jQuery('form').on('change', 'select[name="country"]', function(){
			var country = jQuery(this).val();
			setTimeout(function () {
				jQuery.ajax({
				  	type: 'POST',
				  	url: '<?php 
    echo admin_url('admin-ajax.php');
    ?>
',
				  	data: {
				  		action: 'sunshine_checkout_update_state',
						country: country,
					},
				  	success: function(data, textStatus, XMLHttpRequest) {
						var obj = jQuery.parseJSON(data);
						if (obj.state_options)
							jQuery('#sunshine-billing-state').html('<label><?php 
    _e('State / Province', 'sunshine');
    ?>
 '+obj.state_options+'</label>');
				  	},
				  	error: function(MLHttpRequest, textStatus, errorThrown) {
						alert('Sorry, there was an error with your request');
				  	}
				});
			}, 500);
			return false;
		});

		jQuery('form').on('change', 'select[name="shipping_country"]', function(){
			var shipping_country = jQuery(this).val();
			setTimeout(function () {
				jQuery.ajax({
				  	type: 'POST',
				  	url: '<?php 
    echo admin_url('admin-ajax.php');
    ?>
',
				  	data: {
				  		action: 'sunshine_checkout_update_shipping_state',
						shipping_country: shipping_country
					},
				  	success: function(data, textStatus, XMLHttpRequest) {
						var obj = jQuery.parseJSON(data);
						if (obj.state_options)
							jQuery('#sunshine-shipping-state').html('<label>State / Province '+obj.state_options+'</label>');
				  	},
				  	error: function(MLHttpRequest, textStatus, errorThrown) {
						alert('Sorry, there was an error with your request');
				  	}
				});
			}, 500);
			return false;
		});

	});
	</script>

<?php 
}