<?php echo $header; ?>
<div id="content">
  <div class="breadcrumb">
    <?php foreach ($breadcrumbs as $breadcrumb) { ?>
    <?php echo $breadcrumb['separator']; ?><a href="<?php echo $breadcrumb['href']; ?>"><?php echo $breadcrumb['text']; ?></a>
    <?php } ?>
  </div>
  <?php if ($error_warning) { ?>
  <div class="warning"><?php echo $error_warning; ?></div>
  <?php } ?>
  <div class="box">
    <div class="heading">
      <h1><img src="view/image/module.png" alt="" /> <?php echo $heading_title; ?></h1>
      <div class="buttons"><a onclick="$('#form').submit();" class="button"><?php echo $button_save; ?></a><a onclick="location = '<?php echo $cancel; ?>';" class="button"><?php echo $button_cancel; ?></a></div>
    </div>
    <div class="content">
      <form action="<?php echo $action; ?>" method="post" enctype="multipart/form-data" id="form">
        <table class="form">
          <tr>
            <td><?php echo $entry_product; ?></td>
            <td><input type="text" name="product" value="" /></td>
          </tr>
          <tr>
            <td>&nbsp;</td>
            <td><div id="bp-fpp-product" class="scrollbox">
                <?php $class = 'odd'; ?>
                <?php foreach ($products as $product) { ?>
                <?php $class = ($class == 'even' ? 'odd' : 'even'); ?>
                <div id="bp-fpp-product<?php echo $product['product_id']; ?>" class="<?php echo $class; ?>"><?php echo $product['name']; ?> <img src="view/image/delete.png" />
                  <input type="hidden" value="<?php echo $product['product_id']; ?>" />
                </div>
                <?php } ?>
              </div>
              <input type="hidden" name="bp_fpp_product" value="<?php echo $bp_fpp_product; ?>" /></td>
          </tr>
		  <tr>
			<td><?php echo $entry_image; ?></td>
			<td>
				<input type="text" name="bp_fpp_image_width" value="<?php echo $bp_fpp_image_width; ?>" size="4" />
				<input type="text" name="bp_fpp_image_height" value="<?php echo $bp_fpp_image_height; ?>" size="4" />
			</td>
		  </tr>
		  <tr>
			<td class="left"><?php echo $entry_status; ?></td>
			<td class="left"><select name="bp_fpp_status">
			<?php if ($bp_fpp_status) { ?>
			<option value="1" selected="selected"><?php echo $text_enabled; ?></option>
			<option value="0"><?php echo $text_disabled; ?></option>
			<?php } else { ?>
			<option value="1"><?php echo $text_enabled; ?></option>
			<option value="0" selected="selected"><?php echo $text_disabled; ?></option>
			<?php } ?>	
			</select></td>
		  </tr>
        </table>
      </form>
    </div>
  </div>
</div>
<script type="text/javascript"><!--
$('input[name=\'product\']').autocomplete({
	delay: 0,
	source: function(request, response) {
		$.ajax({
			url: 'index.php?route=catalog/product/autocomplete&token=<?php echo $token; ?>&filter_name=' +  encodeURIComponent(request.term),
			dataType: 'json',
			success: function(json) {		
				response($.map(json, function(item) {
					return {
						label: item.name,
						value: item.product_id
					}
				}));
			}
		});
	}, 
	select: function(event, ui) {
		$('#bp-fpp-product' + ui.item.value).remove();
		
		$('#bp-fpp-product').append('<div id="bp-fpp-product' + ui.item.value + '">' + ui.item.label + '<img src="view/image/delete.png" /><input type="hidden" value="' + ui.item.value + '" /></div>');

		$('#bp-fpp-product div:odd').attr('class', 'odd');
		$('#bp-fpp-product div:even').attr('class', 'even');
		
		data = $.map($('#bp-fpp-product input'), function(element){
			return $(element).attr('value');
		});
						
		$('input[name=\'bp_fpp_product\']').attr('value', data.join());
					
		return false;
	},
	focus: function(event, ui) {
      	return false;
   	}
});

$('#bp-fpp-product div img').live('click', function() {
	$(this).parent().remove();
	
	$('#bp-fpp-product div:odd').attr('class', 'odd');
	$('#bp-fpp-product div:even').attr('class', 'even');

	data = $.map($('#bp-fpp-product input'), function(element){
		return $(element).attr('value');
	});
					
	$('input[name=\'bp_fpp_product\']').attr('value', data.join());	
});
//--></script> 

<?php echo $footer; ?>