<script type="text/javascript">
jQuery("#type_operation").change(function(){
	jQuery.ajax({
		url : "<?php echo site_url('maintenance/getnameoperation'); ?>/"+jQuery("#type_operation :selected").val(),
		type: "GET",
		success: function(data, textStatus, jqXHR)
		{
			jQuery("#id_operation").empty().append(data);
		},
		error: function (jqXHR, textStatus, errorThrown)
		{
			jQuery("#alert_dialog").html('Erreur lors de la recupération des opérations');
			jQuery("#alert_dialog").dialog('open');
		}
	}); 
});

jQuery("#submitMaintenance").click(function(){
	jQuery.ajax({
		url : "<?php echo site_url('maintenance/addmainteance'); ?>/",
		type: "POST",
		data :jQuery("#frm_assets_maint").serialize(),
		success: function(data, textStatus, jqXHR)
		{
			jQuery("#alert_dialog").html('<?php echo $this->lang->line('Record_Updated_Successfully'); ?>');
			jQuery("#alert_dialog").dialog('open');
		},
		error: function (jqXHR, textStatus, errorThrown)
		{
			jQuery("#alert_dialog").html('Erreur lors de l\'ajout de cette maintenance');
			jQuery("#alert_dialog").dialog('open');
		}
	}); 
	return false;	
}); 
		
	jQuery(document).ready(function() {

	jQuery(document).keypress(function(e) {
			if (e.keyCode == 27) {
			if(jQuery('#assets_category_form_div').css("display") != "none" &&  jQuery('#assets_category_form_div').css("display") != undefined){			
				conf_dialog_assests_catagory_assets_dopost.dialog("open");
				}
		}
	}); 

	jQuery("#loading_top").css("display","none");
			
	});
</script>
<script type="text/javascript">
loadDropdown()
</script>
<script>
jQuery(document).ready(function() {
	jQuery("input:button, input:submit, input:reset").button();	
	jQuery("#debut_alerte").datepicker({dateFormat: 'yy-mm-dd'});
	jQuery("#fin_alerte").datepicker({dateFormat: 'yy-mm-dd'});
	
	jQuery("#debut_alerte").datepicker('setDate', new Date());
	jQuery("#fin_alerte").datepicker('setDate', new Date());

	jQuery("#loading_top").css("display","none");
	jQuery("#device").html(assets_combo_opt_report);
	jQuery("#ddcl-device").css('vertical-align','middle');
	jQuery("#ddcl-device-ddw").css('overflow-x','hidden');
	jQuery("#ddcl-device-ddw").css('overflow-y','auto');
	jQuery("#ddcl-device-ddw").css('height','200px');
	jQuery(".ui-dropdownchecklist-dropcontainer").css('overflow','visible');
});

</script>
<?php if($this->form_model->assets_cat_name == ""){ ?>
<h3 class="title_black"><?php echo $this->lang->line("Create Maintenance"); ?></h3>
<?php }else{ ?>
<h3 class="title_black"><?php echo $this->lang->line("Update Maintenance"); ?></h3>
<?php } ?>
<?php $this->load->view('dashboard/system_messages'); ?>
<div id="assets_category_error" class="error" style="display:none"><?php echo $this->lang->line("Assets category Already Exist"); ?>.!</div>
<div class="content toggle" align="center">
  <form id="frm_assets_maint" method="post" action="#">
    <p id="error" class="addTips">* <?php echo $this->lang->line("Fields_are_mendatory"); ?></p>
    <table width="70%" align="center" class="formtable">
      <tbody>				
		<tr>
			<td width="20%"><label>
			Vehicule *
			</td>
			<td width="50%"><select name="assets_id" id="device" class="select"></select></td>
		</tr>				
		<tr>
			<td width="20%"><label>
			Type d'opération *
			</td>
			<td width="50%">
				<select class="text ui-widget-content ui-corner-all" id="type_operation" name="type_operation">
					<option value="Administrative">Administrative</option>
					<option value="Materielle">Matérielle</option>
				</select>
			</td>
		</tr>
		<tr>
			<td width="20%"><label>
			Type de maintenance *
			</td>
			<td width="50%">
				<select class="text ui-widget-content ui-corner-all" id="type_maintenance" name="type_maintenance" required="true">
					<option value="">Séléctionner un choix</option>
					<option value="kilometrage">par kilometrage</option>
					<option value="date">par date</option>
				</select>
			</td>
		</tr>
        <tr>
			<td width="20%">
			Nom d'opération *</td> 
			<td width="50%">
				<select class="text ui-widget-content ui-corner-all" id="id_operation" name="id_operation">
				<option value="">Veuillez séléctionner d'abord le type</option>
				</select>
			</td>
        </tr>
		<tr class="duree" style="display:none">
			<td width="20%"><label>
			Date début alerte
			</td>
			<td width="50%">
			<input type="text" name="debut_alerte" id="debut_alerte" class="date text ui-widget-content ui-corner-all" value="<?php echo date('d.m.Y'); ?>" readonly="readonly"/>
			</td>
		</tr>
		<tr class="duree" style="display:none">
			<td width="20%"><label>
			Date fin alerte
			</td>
			<td width="50%">
			<input type="text" name="fin_alerte" id="fin_alerte" class="date text ui-widget-content ui-corner-all" value="<?php echo date('d.m.Y');?>"/></td>
		</tr>
		<tr class="kilometrage" style="display:none">
			<td width="20%"><label>
			Kms début alerte 
			</td>
			<td width="50%"><input type="text" name="kms_debut_alerte" id="kms_debut_alerte" class="text ui-widget-content ui-corner-all"><?php echo $this->form_model->assets_ids; ?></td>
		</tr>
		<tr  class="kilometrage" style="display:none">
			<td width="20%"><label>
			Kms fin alerte 
			</td>
			<td width="50%"><input type="text" name="kms_fin_alerte" id="kms_fin_alerte" class="text ui-widget-content ui-corner-all"></td>
		</tr>
		<tr  class="duree" style="display:none">
			<td width="20%"><label>
			Durée début alerte (# heures) 
			</td>
			<td width="50%"><input type="text" name="duree_debut_alerte" id="duree_debut_alerte" class="text ui-widget-content ui-corner-all"></td>
		</tr>
		<tr  class="duree" style="display:none">
			<td width="20%"><label>
			Durée fin alerte (# heures) 
			</td>
			<td width="50%"><input type="text" name="duree_fin_alerte" id="duree_fin_alerte" class="text ui-widget-content ui-corner-all"></td>
		</tr>
		<tr>
			<td width="20%"><label>
			Coûts * 
			</td>
			<td width="50%"><input type="text" name="cout" id="cout" class="text ui-widget-content ui-corner-all"></td>
		</tr>
		<tr>
			<td width="20%"><label>
			Statut *
			</td>
			<td width="50%"><input type="text" name="statut" id="statut" class="text ui-widget-content ui-corner-all"></td>
		</tr>
		<tr>
			<td width="20%"><label>
			Remarques 	
			</td>
			<td width="50%"><textarea class="text ui-widget-content ui-corner-all" name="comments"></textarea></td>
		</tr>
        <tr>
          <td align="center" colspan="2"><input type="button" id="submitMaintenance" value="<?php echo $this->lang->line('submit'); ?>" name="submitMaintenance"/>
            &nbsp;&nbsp;
            <input type="button" id="btn_cancel" onclick="cancel_assets_category()" name="btn_cancel" value="<?php echo $this->lang->line("Back"); ?>" /></td>
        </tr>
      </tbody> 
    </table>
  </form>  
</div>

<script>
$( "#type_maintenance" ).change(function() {
	 if ($(this).val() == "kilometrage")
	 {
		 $(".kilometrage").show();
		 $(".duree").hide();
	 }

	 if ($(this).val() == "date")
	 {
		 $(".kilometrage").hide();
		 $(".duree").show();
	 }
	});
</script>