<?php
session_start();
?>
<!DOCTYPE html>
<html>
	<head><meta http-equiv="Content-Type" content="text/html; charset=utf-8">
		<title>Iniciar sesion</title>
		<link rel="apple-touch-icon" sizes="57x57" href="/apple-icon-57x57.png">
		<link rel="apple-touch-icon" sizes="60x60" href="/apple-icon-60x60.png">
		<link rel="apple-touch-icon" sizes="72x72" href="/apple-icon-72x72.png">
		<link rel="apple-touch-icon" sizes="76x76" href="/apple-icon-76x76.png">
		<link rel="apple-touch-icon" sizes="114x114" href="/apple-icon-114x114.png">
		<link rel="apple-touch-icon" sizes="120x120" href="/apple-icon-120x120.png">
		<link rel="apple-touch-icon" sizes="144x144" href="/apple-icon-144x144.png">
		<link rel="apple-touch-icon" sizes="152x152" href="/apple-icon-152x152.png">
		<link rel="apple-touch-icon" sizes="180x180" href="/apple-icon-180x180.png">
		<link rel="icon" type="image/png" sizes="192x192"  href="/android-icon-192x192.png">
		<link rel="icon" type="image/png" sizes="32x32" href="/favicon-32x32.png">
		<link rel="icon" type="image/png" sizes="96x96" href="/favicon-96x96.png">
		<link rel="icon" type="image/png" sizes="16x16" href="/favicon-16x16.png">
		<link rel="manifest" href="/manifest.json">
		<meta name="msapplication-TileColor" content="#ffffff">
		<meta name="msapplication-TileImage" content="/ms-icon-144x144.png">
		<meta name="theme-color" content="#ffffff">
		<link rel="stylesheet" type="text/css" href="css/stylesheet.css">
        <script src="js/jquery.min.js"></script>
        <script type="text/javascript" src="js/script.js"></script>
<!--        <link rel="stylesheet" type="text/css" href="http://fonts.googleapis.com/css?family=Open+Sans">-->
        <script type="text/javascript">
        	function Iniciar(f) { 
        		var usuario = $('#usuario').val();
        		var pass = $('#pass').val();

				if (usuario == '') 
				{ 
					alert ('El nombre de usuario esta vacio');  
					$('#usuario').focus();
				}else{
					if (pass   == '') 
					{
						alert ('La contrase\u00f1a esta vacia');  
						$('#pass').focus();
					}
					else{
						    $.ajax({
						        
						        type    : 'POST',
						        url     : 'validar.php',
						        data    : 'usuario='+usuario+'&pass='+pass,
						        success : function(res){
						            if(res == 3 ){///Ventas = 3 / Bodega = 4 / Solo checador = 5
						            	//JEFE DE TALLER
						            	window.location.href = 'orden.php';
						            }else if(res == 4){ //MECANICOS
                                    	window.location.href = 'busqueda.php';
                                    }else if(res == 5){ //MECANICOS
                                    	window.location.href = 'checador.php';
                                    }else{
						            	alert ("Error de inicio de sesion");
						            }
						        },error: function (jqXHR, exception) {
							        var msg = '';
							        if (jqXHR.status === 0) {
							            msg = 'Not connect.\n Verify Network.';
							        } else if (jqXHR.status == 404) {
							            msg = 'Requested page not found. [404]';
							        } else if (jqXHR.status == 500) {
							            msg = 'Internal Server Error [500].';
							        } else if (exception === 'parsererror') {
							            msg = 'Requested JSON parse failed.';
							        } else if (exception === 'timeout') {
							            msg = 'Time out error.';
							        } else if (exception === 'abort') {
							            msg = 'Ajax request aborted.';
							        } else {
							            msg = 'Uncaught Error.\n' + jqXHR.responseText;
							        }
							        alert(msg);
							    },
						    });
					}
				}


			}

        </script>
	</head>
	<body>
        <div id="header">
        <?php
        /* if($nom !=''){
        ?>
        <ul>
            <li><?php echo "Bienvenido, $nom."?></li>
            <li id="cerrarsesion"><a href="logout.php">Cerrar Sesion</a></li>
        </ul>
        <?php
        }else{
            ?>
            <form id="loginusuario" method="post"  onSubmit="Iniciar(this);">
                <input type="text" name="usuario" id="usuario" placeholder="Usuario"></br>
                <input type="text" name="pass" id="pass" placeholder="Contrase&ntilde;a"></br>
                <input type="Submit" name="guardar" id="userlog" class="boton" value="Entrar"> 
            </form>
            <?php
        }*/
        ?>
        <img src="imagenes/cuad.png" id="logo" align="center">
    </div>
		<div id="form" align="center">
			<h2>SISTEMA DE ADMINISTRACION</h2>
			<form method="post" onsubmit="return false;">
				<input type="text" id="usuario" name="user" placeholder="Usuario" class="inputlogin"></br>
				<input type="password" id="pass" name="pass" placeholder="Contrase&ntilde;a" class="inputlogin"></br>
				<input type="Submit" class="boton" name="enviar" value="Entrar" onclick="Iniciar(this);">
				
		    </form>

		</div>
		<div id="validacion">

		</div>


	</body>
</html>