<?php 
session_start();
include('../cfg/cfg.php');
include('../cfg/res.php');
if(empty($_SESSION['user_vcrx_tipo']) || !isset($_SESSION['user_vcrx_tipo']))
{
	die('<a href="../salir.php">SU SESSION EXPIRO.</a>');
}


$pagina_descri='VEHICULO ';
$pagina_nivel;
$pagina_tipo;
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title><?php echo $empr_nombre .' - ' . $_SESSION['user_vcrx_descri'];?></title>
<script type="text/javascript" src="../js/jquery-1.11.1.js"></script>

<script type="text/javascript">
<?php include('../../_js/busca_maes3.js');?>
<?php include('../../_js/lista_maes3.js');?>
<?php include('../../_js/fecha_format.js');?>

function _marca(e)
{if(e.keyCode==9 || e.keyCode==13){busca_maes2('mrca',document.getElementById('marca').value,'marca','marca_descri','');}}

function _color(e)
{if(e.keyCode==9 || e.keyCode==13){busca_maes2('clor',document.getElementById('color').value,'color','color_descri','');}}

function _color2(e)
{if(e.keyCode==9 || e.keyCode==13){busca_maes2('clor',document.getElementById('color2').value,'color2','color2_descri','');}}

function _pais(e)
{if(e.keyCode==9 || e.keyCode==13){busca_maes2('pais',document.getElementById('pais').value,'pais','pais_descri','');}}


function guarda_vehiculo()
{
	document.getElementById('guardar').disabled=true;

	var codigo;
	var descri=document.getElementById('descri').value;
	var status;
	var placa =document.getElementById('placa').value;
	var marca=document.getElementById('marca').value;
	var motor=document.getElementById('motor').value;
	var modelo=document.getElementById('modelo').value;
	var vinn=document.getElementById('vinn').value;
	var anio=document.getElementById('anio').value;
	var cilindro=document.getElementById('cilindro').value;
	var color=document.getElementById('color').value;
	var color2=document.getElementById('color2').value;
	var pais=document.getElementById('pais').value;
	var clase=document.getElementById('clase').value;
	var conductor=document.getElementById('conductor').value;
	
	if(placa.length==0 || placa=="")
	{
		alert('placa requerida');
		document.getElementById('placa').focus();
		return false;
	}
	
	if(descri.length==0 || descri=="")
	{
		descri=descri+marca+'/'+modelo;
		document.getElementById('descri').value=descri;
	}
	codigo=placa;
	document.getElementById('codigo').value=codigo;
	$.ajax({
		cache:false,
		url:'vrvhcl2.php',
		datatype: "text",
	    async:false,
		type:'POST',
		data:{codigo:codigo.toUpperCase(),
				descri:descri.toUpperCase(),
				placa:placa.toUpperCase(),
				marca:marca.toUpperCase(),
				motor:motor.toUpperCase(),
				modelo:modelo.toUpperCase(),
				vinn:vinn.toUpperCase(),
				anio:anio,
				cilindro:cilindro,
				color:color.toUpperCase(),
				color2:color2.toUpperCase(),
				pais:pais.toUpperCase(),
				clase:clase.toUpperCase(),
				conductor:conductor.toUpperCase()
				}, 
    	beforeSend: function(jqXHR, textStatus)
		{
	
		}, 
		
		success:function(dato, textStatus, jqXHR)
		{
			console.log(dato);
                  //document.body.style.cursor='default';
		},
		error:function(jqXHR,textStatus,errorThrown )
		{
           if (jqXHR.status === 0) {
              console.log('Not connect: Verify Network.');
           } else if (jqXHR.status == 404) {
               console.log('Requested page not found [404]');
           } else if (jqXHR.status == 500) {
               console.log('Internal Server Error [500].');
           } else if (exception === 'parsererror') {
               console.log('Requested JSON parse failed.');
           } else if (exception === 'timeout') {
               //console.log('Time out error.');
			   alert('Servidor no Responde');
           } else if (exception === 'abort') {
               console.log('Ajax request aborted.');
           } else {
               console.log('Uncaught Error: ' + jqXHR.responseText);
           }

		}, 
	    complete:function(jqXHR, textStatus)
    	{
			if(textStatus==='success'){}           
		},
		timeout:30000
	});

	document.getElementById('guardar').disabled=false;


}

function _placa(e)
{
		get_vehiculo(document.getElementById('placa').value);
	if(e.keyCode==13)
	{
	}
}

function get_vehiculo(indx)
{
	$.ajax({
		cache:false,
		url:'vrvhcl3.php',
		datatype: "text",
	    async:false,
		type:'POST',
		data:{indx:indx}, 
    	beforeSend: function(jqXHR, textStatus)
		{
	
		}, 
		
		success:function(dato, textStatus, jqXHR)
		{
			console.log(dato);
			
			if($(dato).find("error").text()=='0')
			{
			document.getElementById('descri').value=$(dato).find("descri").text();
			document.getElementById('status').value=$(dato).find("status").text();
			document.getElementById('placa').value=$(dato).find("placa").text();
			document.getElementById('codigo').value=$(dato).find("placa").text();
			document.getElementById('placa').disabled=true;
			
			document.getElementById('guardar').style.visibility="hidden";
			document.getElementById('actualiza').style.visibility="visible";
			document.getElementById('cancela').style.visibility="visible";
			
			
			document.getElementById('marca').value=$(dato).find("mrca").text();
			document.getElementById('motor').value=$(dato).find("motor").text();
			document.getElementById('modelo').value=$(dato).find("mdlo").text();
			document.getElementById('vinn').value=$(dato).find("vinn").text();
			document.getElementById('anio').value=$(dato).find("anio").text();
			document.getElementById('cilindro').value=$(dato).find("cilindro").text();
			document.getElementById('color').value=$(dato).find("clor").text();
			document.getElementById('color2').value=$(dato).find("clor2").text();
			document.getElementById('pais').value=$(dato).find("pais").text();
			document.getElementById('clase').value=$(dato).find("clase").text();
			document.getElementById('conductor').value=$(dato).find("conductor").text();
			}
                
		},
		error:function(jqXHR,textStatus,errorThrown )
		{
           if (jqXHR.status === 0) {
              console.log('Not connect: Verify Network.');
           } else if (jqXHR.status == 404) {
               console.log('Requested page not found [404]');
           } else if (jqXHR.status == 500) {
               console.log('Internal Server Error [500].');
           } else if (exception === 'parsererror') {
               console.log('Requested JSON parse failed.');
           } else if (exception === 'timeout') {
               //console.log('Time out error.');
			   alert('Servidor no Responde');
           } else if (exception === 'abort') {
               console.log('Ajax request aborted.');
           } else {
               console.log('Uncaught Error: ' + jqXHR.responseText);
           }

		}, 
	    complete:function(jqXHR, textStatus)
    	{
			if(textStatus==='success'){}           
		},
		timeout:30000
	});


}

function cancela_vehiculo()
{
	document.getElementById('guardar').style.visibility="visible";
	document.getElementById('actualiza').style.visibility="hidden";
	document.getElementById('cancela').style.visibility="hidden";
	document.getElementById('placa').disabled=false;
}


function actualiza_vehiculo()
{
	document.getElementById('guardar').style.visibility="visible";
	document.getElementById('actualiza').style.visibility="hidden";
	document.getElementById('cancela').style.visibility="hidden";
	document.getElementById('placa').disabled=false;
	var codigo=document.getElementById('codigo').value;
	var descri=document.getElementById('descri').value;
	var marca=document.getElementById('marca').value;
	var motor=document.getElementById('motor').value;
	var modelo=document.getElementById('modelo').value;
	var vinn=document.getElementById('vinn').value;
	var anio=document.getElementById('anio').value;
	var cilindro=document.getElementById('cilindro').value;
	var color=document.getElementById('color').value;
	var color2=document.getElementById('color2').value;
	var pais=document.getElementById('pais').value;
	var clase=document.getElementById('clase').value;
	var conductor=document.getElementById('conductor').value;

	$.ajax({
		cache:false,
		url:'vrvhcl4.php',
		datatype: "text",
	    async:false,
		type:'POST',
		data:{	codigo:codigo.toUpperCase(),
				descri:descri.toUpperCase(),
				marca:marca.toUpperCase(),
				motor:motor.toUpperCase(),
				modelo:modelo.toUpperCase(),
				vinn:vinn.toUpperCase(),
				anio:anio,
				cilindro:cilindro,
				color:color.toUpperCase(),
				color2:color2.toUpperCase(),
				pais:pais.toUpperCase(),
				clase:clase.toUpperCase(),
				conductor:conductor.toUpperCase()
				}, 
    	beforeSend: function(jqXHR, textStatus)
		{
	
		}, 
		
		success:function(dato, textStatus, jqXHR)
		{
			console.log(dato);
                  //document.body.style.cursor='default';
		},
		error:function(jqXHR,textStatus,errorThrown )
		{
           if (jqXHR.status === 0) {
              console.log('Not connect: Verify Network.');
           } else if (jqXHR.status == 404) {
               console.log('Requested page not found [404]');
           } else if (jqXHR.status == 500) {
               console.log('Internal Server Error [500].');
           } else if (exception === 'parsererror') {
               console.log('Requested JSON parse failed.');
           } else if (exception === 'timeout') {
               //console.log('Time out error.');
			   alert('Servidor no Responde');
           } else if (exception === 'abort') {
               console.log('Ajax request aborted.');
           } else {
               console.log('Uncaught Error: ' + jqXHR.responseText);
           }

		}, 
	    complete:function(jqXHR, textStatus)
    	{
			if(textStatus==='success'){}           
		},
		timeout:30000
	});
	
	
}


</script>

<style type="text/css">
.txt{ text-transform:uppercase;}
</style>
</head>

<body>
<div align="center">
	<div>
	<div align="center"><?php include('../../_lib/cabecera2.php');?></div>
	<div>
    
    


<table>
<tr>
	<td><input type="button" value="CODIGO:"  /></td>
    <td><input type="text" id="codigo" disabled="disabled" class="txt"  /></td>
    <td><div id="codigo_descri"></div></td>
</tr>

<tr>
	<td><input type="button" value="DESCRIPCION:" /></td>
    <td><input type="text" id="descri"  class="txt" /></td>
    <td><div id="descri_descri"></div></td>
</tr>

<tr>
	<td><input type="button" value="STATUS:"  /></td>
    <td><input type="text" id="status"  disabled="disabled"  class="txt" /></td>
    <td><div id="status_descri"></div></td>
</tr>


<tr>
		<?php $pcaption='PLACA';  $pidtxt='placa'; $ponblur='_placa(event);'; $plong='10';   include('vrgettxt.php'); ?>
	
<!-- 	<td><input type="button" value="PLACA:" onClick="list_carga('vhcl','placa','placa_descri');" /></td>
    <td><input type="text" id="placa"  class="txt" onkeypress="_placa(event);" /></td>
    <td><div id="placa_descri" style="visibility:hidden;"></div></td> -->
</tr>


<tr>
		<?php $pcaption='MARCA';  $ptabla='mrca'; $pidtxt='marca';   include('vrgetcod.php'); ?>
<!-- 	<td><input type="button" value="MARCA:" onClick="list_carga('mrca','marca','marca_descri');" /></td>
    <td><input type="text" id="marca" onkeypress="_marca(event);"  class="txt" /></td>
    <td><div id="marca_descri"></div></td> -->
</tr>

<tr>
		<?php $pcaption='MODELO';  $pidtxt='modelo'; $plong='20';   include('vrgettxt.php'); ?>
<!-- 	<td><input type="button" value="MODELO:" /></td>
    <td><input type="text" id="modelo"  class="txt" /></td>
    <td><div id="modelo_descri"></div></td> -->
</tr>


<tr>
		<?php $pcaption='MOTOR';  $pidtxt='motor'; $plong='20';   include('vrgettxt.php'); ?>
<!-- 	<td><input type="button" value="MOTOR:" /></td>
    <td><input type="text" id="motor"  class="txt" /></td>
    <td><div id="motor_descri"></div></td> -->
</tr>



<tr>
		<?php $pcaption='VINN';  $pidtxt='vinn'; $plong='20';   include('vrgettxt.php'); ?>
<!-- 	<td><input type="button" value="VINN:" /></td>
    <td><input type="text" id="vinn"  class="txt" /></td>
    <td><div id="vinn_descri"></div></td> -->
</tr>

<tr>
		<?php $pcaption='AÑO';  $pidtxt='anio'; $plong='4';   include('vrgetnum.php'); ?>
<!-- 	<td><input type="button" value="AÑO:" /></td>
    <td><input type="text" id="anio"  class="txt" /></td>
    <td><div id="anio_descri"></div></td> -->
</tr>

<tr>
		<?php $pcaption='CILINDRO';  $pidtxt='cilindro'; $plong='5';   include('vrgetval.php'); ?>
<!-- 	<td><input type="button" value="CILINDRO:" /></td>
    <td><input type="text" id="cilindro"  class="txt" /></td>
    <td><div id="cilindro_descri"></div></td> -->
</tr>


<tr>
		<?php $pcaption='COLOR';  $ptabla='clor'; $pidtxt='color';    include('vrgetcod.php'); ?>
<!-- 	<td><input type="button" value="COLOR:"  onClick="list_carga('clor','color','color_descri');" /></td>
    <td><input type="text" id="color" onkeypress="_color(event);"  class="txt" /></td>
    <td><div id="color_descri"></div></td> -->
</tr>

<tr>
		<?php $pcaption='COLOR 2';  $ptabla='clor'; $pidtxt='color2';    include('vrgetcod.php'); ?>
<!-- 	<td><input type="button" value="COLOR2:"  onClick="list_carga('clor','color2','color2_descri');"  /></td>
    <td><input type="text" id="color2" onkeypress="_color2(event);"  class="txt" /></td>
    <td><div id="color2_descri"></div></td> -->
</tr>


<tr>
		<?php $pcaption='PAIS';  $ptabla='pais'; $pidtxt='pais';    include('vrgetcod.php'); ?>
<!-- 	<td><input type="button" value="PAIS:" onClick="list_carga('pais','pais','pais_descri');" /></td>
    <td><input type="text" id="pais" onkeypress="_pais(event);"  class="txt" /></td>
    <td><div id="pais_descri"></div></td> -->
</tr>




<tr>
		<?php $pcaption='CLASE';   $pidtxt='clase';   $plong=10; include('vrgettxt.php'); ?>
<!-- 	<td><input type="button" value="CLASE" /></td>
    <td><input type="text" id="clase"  class="txt" /></td>
    <td><div id="clase_descri"></div></td> -->
</tr>

<tr>
		<?php $pcaption='CONDUCTOR';   $pidtxt='conductor';   $plong=20; include('vrgettxt.php'); ?>
<!-- 	<td><input type="button" value="CONDUCTOR:" /></td>
    <td><input type="text" id="conductor"  class="txt" /></td>
    <td><div id="conductor_descri"></div></td> -->
</tr>
</table>
<input type="button" value="Guardar" id="guardar" onclick="guarda_vehiculo();" />
<input type="button" value="Actualizar" id="actualiza" onclick="actualiza_vehiculo();" style=" visibility:hidden; " />
<input type="button" value="Cancelar" id="cancela" onclick="cancela_vehiculo();"  style=" visibility:hidden;" />
    </div>
    </div>
</div>

<?php		
require('lista_car.php');
?>	

<!-- 
<div id="lista_temporal_contenedor" style=" display:none; padding:0px; margin:0px; background: #666; opacity:0.5; width:100%; min-height: 100%; height:auto !important;position: fixed;top:0;left:0; z-index:1;" ></div>
<div id="lista_cargador" style=" display:none; background:#FFF;position: fixed; top:50px;z-index:10;" ><img src="../img/ajax-loader.gif" /></div>    
<div id="lista_temporal" style=" display:none; background:#FFF;position: fixed; top:50px;z-index:10; overflow-y:scroll; min-height:50px; max-height:400px; width:100%;" ><img src="../img/ajax-loader.gif" /></div>    

 -->
</body>
</html>