<!doctype html>
<html lang="en">
    <head>
        <meta charset="utf-8" />
        <title>Login gestión - Camperspatagonia</title>
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <!-- App favicon -->
        <link rel="shortcut icon" href="assets/images/favicon.ico">
        <!-- Bootstrap Css -->
        <link href="assets/css/bootstrap.css" id="bootstrap-style" rel="stylesheet" type="text/css" />
        <!-- Icons Css -->
        <link href="assets/css/icons.css" rel="stylesheet" type="text/css" />
        <!-- App Css-->
        <link href="assets/css/app.css" id="app-style" rel="stylesheet" type="text/css" />

    </head>
<script>
function nuevoAjax(){ 
	/* Crea el objeto AJAX. Esta funcion es generica para cualquier utilidad de este tipo, por
	lo que se puede copiar tal como esta aqui */
	var xmlhttp=false;
	try
	{
		// Creacion del objeto AJAX para navegadores no IE
		xmlhttp=new ActiveXObject("Msxml2.XMLHTTP");
	}
	catch(e)
	{
		try
		{
			// Creacion del objet AJAX para IE
			xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
		}
		catch(E)
		{
			if (!xmlhttp && typeof XMLHttpRequest!='undefined') xmlhttp=new XMLHttpRequest();
		}
	}
	return xmlhttp; 
}
	
	
function val_log(){
    // variables del formulario
	var cp1      = document.form.cp_usu.value;
	var cp2      = document.form.cp_pass.value;	
	
	if (cp1==""){
		document.getElementById("zona_err").innerHTML='<div class="alert alert-warning alert-dismissable" id="zona_err"><button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button> Ingrese su usuario</div>';
		return false;
	}else{
		if (cp2==""){
			document.getElementById("zona_err").innerHTML='<div class="alert alert-warning alert-dismissable" id="zona_err"><button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button> Ingrese su password</div>';
			return false;
		}else{
			var ajax=nuevoAjax();
			ajax.open("GET", "v_acc.php?cp1="+cp1+"&cp2="+cp2, true);
			ajax.onreadystatechange=function()
				{ 
					if (ajax.readyState==1)
					{
						// Mientras se envía el formulario

					}
					if (ajax.readyState==4){
						if (ajax.responseText=="0"){
							document.getElementById("zona_err").innerHTML='<div class="alert alert-danger alert-dismissable" id="zona_err"><button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button> Inicio de sesión incorrecto.</div>';
							document.form.cp_usu.value="";
							document.form.cp_pass.value="";
							document.form.cp_usu.focus();
							return false;
						}
						if (ajax.responseText=="1"){				
							window.location='modulos/index_M.php';
						}else{
																					
						}

					} 
				}
			ajax.send(null);		
		}
	}
	
}	
</script>
    <body class="authentication-bg d-flex align-items-center min-vh-100 py-5">
        <div class="container">
         
            <div class="row justify-content-center">
                <div class="col-md-8 col-lg-6 col-xl-5">
                <div class="p-4">
                    <div class="card overflow-hidden mt-2">
                        <div class="auth-logo text-center bg-primary position-relative">
                            <div class="img-overlay"></div>
                            <div class="position-relative pt-4 py-5 mb-1">
                                <h5 class="text-white">Bienvenido</h5>
                            <p class="text-white-50 mb-0">Inicie sesión para ingresar</p>
                            </div>
                        </div>
                        <div class="card-body position-relative">
                            <div class="p-4 mt-n5 card rounded">
                                <form name="form" action="#">
                                    <div class="mb-3" style="text-align: center;"><img src="../newweb/img/_src/logo_campers_patagonia.jpg" alt="" width="100px" ></div>
                                    <div id="zona_err"></div>

                                    <div class="mb-3">
                                        <label for="username" class="form-label">Usuario</label>
                                        <input type="text" class="form-control" name="cp_usu" id="cp_usu" placeholder="Ingrese username">
                                    </div>

                                    <div class="mb-3">
                                        <label for="userpassword">Password</label>
                                        <input type="password" class="form-control" name="cp_pass" id="cp_pass" placeholder="Ingrese password">        
                                    </div>

                                    <div class="mt-3">
                                        <button class="btn btn-primary w-100 waves-effect waves-light" type="button" onClick="val_log();">Ingresar</button>
                                    </div>
                                    
                                    <div class="mt-5 text-center">                        
                                        <p>© <script>document.write(new Date().getFullYear())</script> Camperspatagonia <i class="mdi mdi-heart text-danger"></i> by <a href="https://www.solucionesinformatica.cl" target="_blank">Solucionesinformatica.cl</a></p>
                                    </div>
                                </form>
                            </div>
                        </div>
                    </div>

                    
                </div>
                </div>
            </div>

        </div>

        <!-- JAVASCRIPT -->
        <script src="assets/libs/jquery/jquery.min.js"></script>
        <script src="assets/libs/bootstrap/js/bootstrap.bundle.min.js"></script>
        <script src="assets/libs/metismenu/metisMenu.min.js"></script>
        <script src="assets/libs/simplebar/simplebar.min.js"></script>
        <script src="assets/libs/node-waves/waves.min.js"></script>

        <script src="assets/js/app.js"></script>

    </body>
</html>
