<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="#tabthumb" data-toggle="tab"><i class="icon-picture"></i> Miniature</a></li>
	<li><a href="#tabphotos" data-toggle="tab"><i class="icon-camera"></i> Photos</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</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('ref')) echo 'class="error"'; ?>>
				<td>Référence</td>
				<td>
					<?php echo  Form::text('ref', Input::old('url', (isset($product) ? $product->ref : NULL)), array('style' => '100px;')) ; ?>
					<?php echo  $errors->first('ref', '<span class="help-inline">:message</span>') ; ?>
				</td>
			</tr>
			<tr <?php if($errors->first('prix_ttc')) echo 'class="error"'; ?>>
				<td>Prix TTC</td>
				<td>
					<div class="input-append">
						<?php echo  Form::text('prix_ttc', Input::old('prix_ttc', (isset($product) ? $product->prix_ttc : NULL)), array('style'=>'width:100px;')) ; ?>
						<span class="add-on">€</span>
					</div>
					<?php echo  $errors->first('prix_ttc', '<span class="help-inline">:message</span>') ; ?>
				</td>
			</tr>
			<tr>
				<td>Type</td>
				<td>
					<?php echo Form::checkbox('homme', 'y', (($product->homme=='y') ? TRUE : FALSE), array('style'=>'margin:0;','class'=>'homme')); ?> <label for="homme" style="display:inline;">&nbsp;Homme</label><br/>
					<?php echo Form::checkbox('femme', 'y', (($product->femme=='y') ? TRUE : FALSE), array('style'=>'margin:0;','class'=>'femme')); ?> <label for="femme" style="display:inline;">&nbsp;Femme</label>
				</td>
			</tr>
			<tr>
				<td>Taille(s) disponible(s)<br/><a href="<?php echo URL::to_route('tailles'); ?>">Gestion des tailles</a></td>
				<td>
					<?php
					$tailles_products = array();
					if(isset($product))
					{
						foreach($product->tailles as $r)
							$tailles_products[] = $r->taille_id;
					}
					?>
					<?php foreach($tailles as $t): ?>
					<label class="checkbox">
					    <input name="tailles[]" value="<?php echo  $t->id ; ?>" type="checkbox"<?php if(in_array($t->id, Input::old('tailles', $tailles_products))) echo ' checked="checked"' ?>> <?php echo  $t->name ; ?>
					</label>
					<?php endforeach; ?>
				</td>
			</tr>
			<tr>
				<td>Couleur(s) disponible(s)<br/><a href="<?php echo URL::to_route('couleurs'); ?>">Gestion des couleurs</a></td>
				<td>
					<?php 
					$couleurs_products = array();
					if(isset($product))
					{
						foreach($product->couleurs as $c)
							$couleurs_products[] = $c->couleur_id;
					}
					?>
					<?php foreach($couleurs as $c): ?>
					<label class="checkbox">
					    <input name="couleurs[]" value="<?php echo  $c->id ; ?>" type="checkbox"<?php if(in_array($c->id, Input::old('couleurs', $couleurs_products))) echo ' checked="checked"' ?>> <span class="label" style="background-color:#<?php echo  $c->couleur ; ?>;border:1px solid #D8D8D8;">&nbsp;&nbsp;&nbsp;</span> (#<?php echo  $c->couleur ; ?>)
					</label>
					<?php endforeach; ?>
				</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.'_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>
			</table>
		</div>
		<?php $i++; ?>
	<?php endforeach; ?>
	
	<div class="tab-pane" id="tabthumb">
		<div style="margin-bottom: 30px;">
			<div class="alert alert-info">
				<button type="button" class="close" data-dismiss="alert">×</button>
				<i class="icon-info-sign"></i> Note :
				Veuillez uploader ici la <b>miniature</b> correspondante à ce produit.
			</div>
		</div>
		
		<table class="table table-striped">
			<tr <?php if($errors->first('miniature')) echo 'class="error"'; ?>>
				<td style="width:200px">
					<?php if($miniature): ?>
						Modifier la miniature
					<?php else: ?>
						Ajouter une miniature
					<?php endif; ?>
				</td>
				<td>
					<div class="fileupload fileupload-new" data-provides="fileupload">
						<div class="input-append">
							<div class="uneditable-input span3"><i class="icon-file fileupload-exists"></i> <span class="fileupload-preview"></span></div>
							<span class="btn btn-file">
								<span class="fileupload-new"><?php echo __('admin.choisir_fichier'); ?></span><span class="fileupload-exists"><?php echo __('admin.changer'); ?></span>
								<input type="file" name="miniature" />
							</span>
							<a href="#" class="btn fileupload-exists" data-dismiss="fileupload"><?php echo __('admin.retirer'); ?></a>
						</div>
					</div>
					<span class="help-inline">Important : Format JPG/JPEG seulement.</span>
			     	<?php echo  $errors->first('miniature', '<span class="help-inline">:message</span>') ; ?>
			    </td>
			</tr>
			<?php if($product && $product->miniature!=''): ?>
				<tr>
					<td>Miniature actuelle</td>
					<td><img src="<?php echo $miniature; ?>" alt="" title="" /></td>
				</tr>
			<?php else: ?>
				<?php if($product): ?>
				<tr>
					<td>Miniature actuelle</td>
					<td><b>Aucune miniature pour le moment.</b></td>
				</tr>
				<?php endif; ?>
			<?php endif; ?>
		</table>
		
	</div>
	
	<div class="tab-pane" id="tabphotos">
		<div style="margin-bottom: 30px;">
			<div class="alert alert-info">
				<button type="button" class="close" data-dismiss="alert">×</button>
				<i class="icon-info-sign"></i> Note : Les photos de produit ajoutées ici doivent être <b>décentrées</b> pour respecter la structure du site internet.<br/>
				<i class="icon-warning-sign"></i> Attention : Seules les <b>4 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>

<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>