<ul class="nav nav-tabs">
	<li class="active"><a href="#generalinfo" data-toggle="tab"><i class="icon-link"></i> Caractéristiques</a></li>
	<?php $i = 1; ?>
	<?php foreach($languages as $l): ?>
	<li><a href="#tab<?php echo  $i++; ; ?>" data-toggle="tab"><img src="<?php echo  URL::to_asset('image/flag_'.strtoupper($l->short)); ?>.png" title="<?php echo $l->short; ?>" style="margin-bottom:2px;" alt=""> Contenu (<?php echo  $l->name ; ?>)</a></li>
	<?php endforeach; ?>
	<li><a href="#tabphotos" data-toggle="tab"><i class="icon-camera"></i> Photo(s)</a></li>
	<li><a href="#tabfiles" data-toggle="tab"><i class="icon-file"></i> Fichier(s) </a></li>
</ul>

<div class="tab-content">
	<div class="tab-pane active" id="generalinfo">
		<table class="table table-striped">
			<tr <?php if($errors->first('category_id')) echo 'class="error"'; ?>>
				<td>Catégorie du produit *</td>
				<td>
					<?php echo  Form::select('category_id', $categories, Input::old('category_id', (isset($product) ? $product->category_id : NULL))); ; ?>
					<?php echo  $errors->first('category_id', '<span class="help-inline">:message</span>') ; ?>
				</td>
			</tr>
			<tr <?php if($errors->first('nom')) echo 'class="error"'; ?>>
				<td>Nom du produit *</td>
				<td>
					<?php echo  Form::text('nom', Input::old('nom', (isset($product) ? $product->nom : NULL)), array('class' => 'input-xxlarge')) ; ?>
					<?php echo  $errors->first('nom', '<span class="help-inline">:message</span>') ; ?>
				</td>
			</tr>
			<tr <?php if($errors->first('prix_ht')) echo 'class="error"'; ?>>
				<td>Tarif (hors remise) *</td>
				<td>
					<div class="input-append">
						<?php echo  Form::text('prix_ht', Input::old('prix_ht', (isset($product) ? $product->prix_ht : NULL)), array('style'=>'width:100px; text-align:right;')) ; ?>
						<span class="add-on">€ HT</span>
					</div>
					<?php echo  $errors->first('prix_ht', '<span class="help-inline">:message</span>') ; ?>
				</td>
			</tr>
			<tr <?php if($errors->first('stock')) echo 'class="error"'; ?>>
				<td>Stock</td>
				<td>
					<div class="input-append">
						<?php echo  Form::text('stock', Input::old('stock', (isset($product) ? $product->stock : NULL)), array('style'=>'width:100px; text-align:right;')) ; ?>
						<span class="add-on">Produit(s) en stock</span>
					</div>
					<?php echo  $errors->first('stock', '<span class="help-inline">:message</span>') ; ?>
				</td>
			</tr>
		</table>
	</div>

	<?php $i = 1; ?>
	<?php foreach($languages as $l): ?>
		<script type="text/javascript">
			// Compteur de caractères
			$(document).ready(function(){
			  var limitnum = 130;
			  
			  function limiting(obj, limit) {
			    var cnt = $(".<?php echo $l->short; ?>_counter");
			    var txt = $(obj).val(); 
			    var len = txt.length;
			    
			    // On vérifie qu'on ne dépasse pas la limite
			    if(len > limit){
			       $(obj).val(txt.substr(0,limit));
			       $(cnt).html(len-1);
			     } 
			     else { 
			       $(cnt).html(len);
			     }
			  }
			
			  // Action
			  $('#<?php echo $l->short; ?>_textarea').keyup(function(){
			    limiting($(this), limitnum);
			  });
			  
			  // On inscrit le nb de caract au chargement de la page
			  $(".<?php echo $l->short; ?>_counter").html($('#<?php echo $l->short; ?>_textarea').val().length);
			});
		</script>
		<div class="tab-pane" id="tab<?php echo $i; ?>">
			<table class="table table-striped">
				<tr <?php if($errors->first($l->short.'_delai')) echo 'class="error"'; ?>>
					<td>Délai de livraison *</td>
					<td>
						<?php echo  Form::text($l->short.'_delai', Input::old($l->short.'_delai', (isset($product) ? $product->content[$l->id -1]->delai : NULL)), array('placeholder' => 'Exemple : 3 jours', 'style' => 'width:400px;')) ; ?>
						<?php echo  $errors->first($l->short.'_delai', '<span class="help-inline">:message</span>') ; ?>
					</td>
				</tr>
				<tr <?php if($errors->first($l->short.'_resume')) echo 'class="error"'; ?>>
					<td width="20%">
						Description courte<br/><strong>130 caractères MAX</strong>
						<span class="badge badge-warning <?php echo $l->short; ?>_counter">0</span>
					</td>
					<td>
						<?php echo  Form::textarea($l->short.'_resume', Input::old($l->short.'_resume', (isset($product) ? $product->content[$l->id -1]->resume : NULL)), array('id' => $l->short.'_textarea' , 'style' => 'height:40px;width:60%;')) ; ?>
						<?php echo  $errors->first($l->short.'_resume', '<span class="help-inline">:message</span>') ; ?>
					</td>
				</tr>
				<tr>
					<td>Description longue</td>
					<td>
						<?php echo  Form::textarea($l->short.'_html', Input::old($l->short.'_html', (isset($product) ? $product->content[$l->id -1]->html : NULL)), array('id' => 'editor'.$l->id, 'class' => 'input-xxlarge', 'rows' => 10)) ; ?>
					</td>
				</tr>
				<tr>
					<td colspan="2"><strong><?php echo __('admin.metadonnees'); ?></strong></td>
				</tr>
				<tr <?php if($errors->first($l->short.'_meta_titre')) echo 'class="error"'; ?>>
					<td><?php echo __('admin.balise_meta_titre'); ?></td>
					<td>
						<?php echo  Form::textarea($l->short.'_meta_titre', Input::old($l->short.'_meta_titre', (isset($product) ? $product->content[$l->id -1]->meta_titre : NULL)), array('class' => 'input-xxlarge', 'rows' => 5)) ; ?>
						<?php echo  $errors->first($l->short.'_meta_titre', '<span class="help-inline">:message</span>') ; ?>
					</td>
				</tr>
				<tr <?php if($errors->first($l->short.'_meta_description')) echo 'class="error"'; ?>>
					<td><?php echo __('admin.balise_meta_description'); ?></td>
					<td>
						<?php echo  Form::textarea($l->short.'_meta_description', Input::old($l->short.'_meta_description', (isset($product) ? $product->content[$l->id -1]->meta_description : NULL)), array('class' => 'input-xxlarge', 'rows' => 5)) ; ?>
						<?php echo  $errors->first($l->short.'_meta_description', '<span class="help-inline">:message</span>') ; ?>
					</td>
				</tr>
			</table>
		</div>
		<?php $i++; ?>
	<?php endforeach; ?>
	
	<div class="tab-pane" id="tabphotos">
		<div style="margin-bottom: 10px;">
			Vous pouvez organisez l'ordre des photos en les sélectionnant et les déplaçant.
		</div>
		<div style="margin-bottom: 30px;">
			<div class="alert alert-info">
				<button type="button" class="close" data-dismiss="alert">×</button>
				<i class="icon-warning-sign"></i> Attention : Seules les <b>5 premières photos</b> seront affichées sur le site internet.
			</div>
		</div>
			
		<input class="btn" id="file_upload" name="file_upload" type="file" multiple="true">
		<div style="clear:both; margin-bottom: 15px;"></div>
		
		<div>
			<ul id="sortable" class="unstyled">
			<?php if(isset($product)): ?>
			<?php foreach($product->photos as $p): ?>
			<li>
				<input type="hidden" name="photos[]" value="<?php echo  $p->id ; ?>">
				<img src="<?php echo  URL::to_asset('uploads/photos/products/small/'.$p->name); ; ?>" style="width:250px;" class="img-polaroid">
				<a class="btn btn-danger delete_file"><?php echo __('admin.supprimer'); ?></a>
			</li>
			<?php endforeach; ?>
			<?php endif; ?>
			</ul>
			<div style="clear:both"></div>
		</div>	
		
		<div id="queue"></div>
	</div>
	
	<div class="tab-pane" id="tabfiles">
		<div style="margin-bottom: 10px;">
			<?php echo __('admin.organiser_fichiers'); ?>
		</div>
		<div>
			<ul id="sortable2" class="unstyled">
			<?php if(isset($product)): ?>
			<?php foreach($product->files as $f): ?>
			<li>
				<input type="hidden" name="files[]" value="<?php echo  $f->id ; ?>">
				<br /><a href="<?php echo URL::to_asset('uploads/files/products/'.$f->name);; ?>" target="_blank"><?php echo  substr($f->short_name(),0,24) ; ?></a>
				<br /><br />
				<?php echo  Form::select('visible_'.$f->id, array('public'=>'Public', 'prive'=>'Membres identifiés seulement'), Input::old('visible_'.$f->id, ((isset($f) && $f->visible!='') ? $f->visible : 'public')), array('style'=>'width:180px;')); ; ?>
				<br /><br />
				<a class="btn btn-danger delete_file"><?php echo __('admin.supprimer'); ?></a></li>
			<?php endforeach; ?>
			<?php endif; ?>
			</ul>
			<div style="clear:both"><br /></div>
		</div>	
	
		<input class="btn" id="file_upload2" name="file_upload2" type="file" multiple="true">
		<div style="clear:both; margin-bottom: 15px;"></div>
		<div id="queue2"></div>
	</div>
		
</div>

<script type="text/javascript">
var upload_script = '<?php echo URL::to_action('backend::products@file'); ?>';
</script>
<script type="text/javascript">
	var nb_editor = <?php echo $i; ?>;
	var cfg_editor = {
		fullPage : false,
		height : 300,
		language: '<?php echo Config::get('application.language'); ?>',
		contentsCss : '<?php echo URL::base(); ?>/bundles/backend/js/ckeditor/_samples/assets/output_xhtml.css',
		coreStyles_bold	: { element : 'span', attributes : {'class': 'Bold'} },
		coreStyles_italic : { element : 'span', attributes : {'class': 'Italic'} },
		extraPlugins : 'docprops',

		filebrowserBrowseUrl : '<?php echo URL::base(); ?>/bundles/backend/js/ckfinder/ckfinder.html',
		filebrowserImageBrowseUrl : '<?php echo URL::base(); ?>/bundles/backend/js/ckfinder/ckfinder.html?type=Images',
		filebrowserFlashBrowseUrl : '<?php echo URL::base(); ?>/bundles/backend/js/ckfinder/ckfinder.html?type=Flash',
		filebrowserUploadUrl : '<?php echo URL::base(); ?>/bundles/backend/js/ckfinder/core/connector/php/connector.php?command=QuickUpload&type=Files',
		filebrowserImageUploadUrl : '<?php echo URL::base(); ?>/bundles/backend/js/ckfinder/core/connector/php/connector.php?command=QuickUpload&type=Images',
		filebrowserFlashUploadUrl : '<?php echo URL::base(); ?>/bundles/backend/js/ckfinder/core/connector/php/connector.php?command=QuickUpload&type=Flash'
	}
</script>