<?php echo $header; ?>
<style>
	.list tbody td {
		background-color: transparent;
	}
	.list tbody .left{
		text-align: center;
	}
	
	.list tbody  input{
		width: 95%;
	}	
	
	#filterName{
		width: 75%;
	}
</style>
<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 } ?>
  <?php if ($success) { ?>
  <div class="success"><?php echo $success; ?></div>
  <?php } ?>
  <div class="box">
    <div class="heading">
      <h1><img src="view/image/product.png" alt="" /> <?php echo $heading_title; ?></h1>
       <form action="<?php echo $action; ?>" method="post" enctype="multipart/form-data" id="form">
       <div class="buttons">
            <a id="import" class="button"><span>Import</span></a><a onclick="location='<?php echo $export; ?>'" class="button"><span>Export</span></a></div>
            <div style="float:right;margin-top:8px;margin-right:10px;">Import from spreadsheet file: <input id="upload" type="file" name="upload" /></div>
      </form>
    </div>
    <div class="content">
      <form action="<?php echo $delete; ?>" method="post" enctype="multipart/form-data" id="form">
        <table class="list">
          <thead>
            <tr>
              <td class="left"><?php echo $column_image; ?></td>
              <td class="left"><?php if ($sort == 'pd.name') { ?>
                <a href="<?php echo $sort_name; ?>" class="<?php echo strtolower($order); ?>"><?php echo $column_name; ?></a>
                <?php } else { ?>
                <a href="<?php echo $sort_name; ?>"><?php echo $column_name; ?></a>
                <?php } ?></td>
            	<td class="left"><?php echo $column_title_tags; ?></td>
				<td class="left"><?php echo $column_description; ?></td>
				<td class="left"><?php echo $column_keywords; ?></td>
				<td class="left"><?php echo $column_img_alt; ?></td>
              <td class="left"><?php echo $column_URL ?></td>
				<td class="left" width="80"><?php echo $column_action ?></td>
            </tr>
          </thead>
          <tbody>
            <tr class="filter">
              <td></td>
              <td style="width:315px"><input id="filterName" type="text" size="35" name="filter_name" value="<?php echo $filter_name; ?>"/>  <a onclick="filter();" class="button"><span><?php echo $button_filter; ?></span></a></td>
              <td></td>
              <td></td>
              <td></td>
              <td></td>              
              <td></td>
              <td></td>        
              
            </tr>
            <?php if ($products) { $i=0;?>
            <?php foreach ($products as $product) {
            if($i%2 == 0){
            		echo '<tr>';
            	}
            	else{
            		echo '<tr style="background-color: #F0F0F0;">';
            	}
            	$i++;
            ?>	
              <td class="center"><img src="<?php echo $product['image']; ?>" alt="<?php echo $product['name']; ?>" style="padding: 1px; border: 1px solid #DDDDDD;" /></td>
              <td><?php echo $product['name']; ?></td>
              <td class="left" id="td-TitleTags-<?php echo $product['product_id']; ?>"><input class="seoEdit" id='titleTags-<?php echo $product['product_id']; ?>' type='input' name='titleTags' value='<?php echo $product['titleTags']; ?>'/></td>
              <td class="left" id="td-Description-<?php echo $product['product_id']; ?>"><input class="seoEdit" id='description-<?php echo $product['product_id']; ?>' type='input' name='description' value='<?php echo $product['description']; ?>'/></td>
              <td class="left" id="td-Keywords-<?php echo $product['product_id']; ?>"><input class="seoEdit" id='keywords-<?php echo $product['product_id']; ?>' type='input' name='keywords' value='<?php echo $product['keywords']; ?>'/></td>
              <td class="left" id="td-ImgAlt-<?php echo $product['product_id']; ?>"><input class="seoEdit" id='imgAlt-<?php echo $product['product_id']; ?>' type='input' name='imgAlt' value='<?php echo $product['imgAlt']; ?>'/></td>
              <td class="left" id="td-Url-<?php echo $product['product_id']; ?>"><input class="seoEdit" id='url-<?php echo $product['product_id']; ?>' type='input' name='url' value='<?php echo $product['URL']; ?>'/></td>
              <td> <div class="buttons"><a class="save button" style="visibility:hidden" id="save-<?php echo $product['product_id']; ?>" class="button"><span>Save</span></a><img style="visibility:visible" id="success-<?php echo $product['product_id']; ?>" src="<?php echo $linkSuccessImg;?>"/></div></td>
              <!--<td class="right"><?php foreach ($product['action'] as $action) { ?>
                [ <a href="<?php echo $action['href']; ?>"><?php echo $action['text']; ?></a> ]
                <?php } ?></td>-->
            </tr>
            <?php } ?>
            <?php } else { ?>
            <tr>
              <td class="center" colspan="8"><?php echo $text_no_results; ?></td>
            </tr>
            <?php } ?>
          </tbody>
        </table>
      </form>
      <div class="pagination"><?php echo $pagination; ?></div>
    </div>
  </div>
</div>
<script type="text/javascript"><!--

$('.seoEdit').click(function() {
	$array = $(this).attr('id').split("-");
	name = $array[0];
	id = $array[1];
	$('#save-'+id).css("visibility", "visible");
	$('#success-'+id).css("visibility", "hidden");
});

$('.save').click(function() {
	$array = $(this).attr('id').split("-");
	id = $array[1];
	$.ajax({	
		type: 'POST',
		url: 'index.php?route=seo/product/update&token=<?php echo $token; ?>',
		data: "product_id="+id+
				"&titleTags="+$('#titleTags-'+id).val()+
				"&description="+$('#description-'+id).val()+
				"&keywords="+$('#keywords-'+id).val()+
				"&imgAlt="+$('#imgAlt-'+id).val()+
				"&url="+$('#url-'+id).val(),
	});
	$('#save-'+id).css("visibility", "hidden");	
	$('#success-'+id).css("visibility", "visible");	
	return false;
});

//--></script> 
<script type="text/javascript"><!--
function filter() {
	url = 'index.php?route=seo/product&token=<?php echo $token; ?>';
	
	var filter_name = $('input[name=\'filter_name\']').attr('value');
	
	if (filter_name) {
		url += '&filter_name=' + encodeURIComponent(filter_name);
	}

	location = url;
}
//--></script> 
<script type="text/javascript"><!--
$('#form input').keydown(function(e) {
	if (e.keyCode == 13) {
		filter();
	}
});
//--></script> 
<script type="text/javascript"><!--
$('input[name=\'filter_name\']').autocomplete({
	delay: 0,
	source: function(request, response) {
		$.ajax({
			url: 'index.php?route=seo/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.name
					}
				}));
			}
		});
	}, 
	select: function(event, ui) {
		$('input[name=\'filter_name\']').val(ui.item.label);
						
		return false;
	}
});

$('input[name=\'filter_model\']').autocomplete({
	delay: 0,
	source: function(request, response) {
		$.ajax({
			url: 'index.php?route=seo/category/autocomplete&token=<?php echo $token; ?>&filter_model=' +  encodeURIComponent(request.term),
			dataType: 'json',
			success: function(json) {		
				response($.map(json, function(item) {
					return {
						label: item.name,
						value: item.category_id
					}
				}));
			}
		});
	}, 
	select: function(event, ui) {
		$('input[name=\'filter_model\']').val(ui.item.label);
						
		return false;
	}
});


$('#import').click(function(){
	if($('#upload').val() != ""){
		$('#form').submit();
	}
	else{
		alert('No file to import… Please click on "Browse" and choose the file to import');
	}
});
//--></script> 
<?php echo $footer; ?>