
$("document").ready(function () {
   consultaImagenesLogin();
   $("#btnLogin").click(function(){ validarCredenciales();});	
});


function validarCredenciales(){
	
	var pUsuario = $("#txtUsuario").val();
	var pContrasenia = $("#txtPassword").val();
	
	var json_request = {
		tipoOperacion: "login"            
		,pUsuario:pUsuario
		,pContrasenia:pContrasenia
	};
	
	$.ajax({
		type: "POST",
		data: json_request,
		url: "../sippre/dataAccess/login.php",
		dataType: "json",
		async: true,
		beforeSend: function () {
			ajaxindicatorstart();
		},
		success: function (resp) {     
		    //MessageBox(resp, resp.mensaje);
			if(parseInt(resp.transaccion) === 0){
				MessageBox(resp.transaccion, resp.mensaje);
			}if(parseInt(resp.datos[0].nidEmpresa) === 1){
				window.location.href = "../sippre/account.php";
			}else{
				window.location.href = "../kuba/account.php";
		    }
		},
		complete: function () {
			ajaxindicatorstop();
		},
		error: function (xhr, ajaxOptions, thrownError) {
			console.log(xhr);
			console.log(ajaxOptions);
			console.log(thrownError);
			
		}
	});	
}


function consultaImagenesLogin() {

    var stringImagenes = "";
    var listaImagenes = [];

    $('.foo').backstretch([
      '/sippre/assets/images/fondoLogin/b1.jpg',
	  '/sippre/assets/images/fondoLogin/b2.jpg',
	  '/sippre/assets/images/fondoLogin/b3.jpg',
	  '/sippre/assets/images/fondoLogin/b4.jpg'
    ], {   
        overlay: {
            init: true,
            background: "#000000",
            opacity: 0.9
        },     
        duration: 5000,
        fade: 750,
        transition: 'fade',
        transitionDuration: 250,
        animateFirst: true
    });


}