function objetoAjax(){
	var xmlhttp=false;
	try{
		xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
	}catch(e){
		try{
			xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
		}catch(E){
			xmlhttp = false;
  		}
	}
	if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
		xmlhttp = new XMLHttpRequest();
	}
	return xmlhttp;
}

function enviarDatosLogin(){
	//donde se mostrará lo resultados
	divResultado = document.getElementById('resultado');
	divFormulario = document.getElementById('logarse');
	//divResultado.innerHTML= '<img src="anim.gif">';
	
	//valores de los cajas de texto
	formulario = document.getElementById('login');
	nom=formulario.usuario.value;
	pass=formulario.clave.value;
	
	//instanciamos el objetoAjax
	ajax=objetoAjax();
	//usando del medoto POST
	//archivo que realizará la operacion ->actualizacion.php
	ajax.open("POST", "../inc/consultar_datos_usuario.php",true);
	ajax.onreadystatechange=function() {
		if (ajax.readyState==4) {
			divFormulario.innerHTML = ajax.responseText;
		}
	}
	//muy importante este encabezado ya que hacemos uso de un formulario
	ajax.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
	//enviando los valores
	ajax.send("usuario="+nom+"&clave="+pass);
}

function validacionLogin(theForm){

	if(theForm.usuario.value==''){
			alert("Debe indicar un usuario válido.");
			theForm.usuario.focus();
			return false;
	}
	
	if(theForm.clave.value==''){
			alert("Debe indicar una contraseńa válida.");
			theForm.clave.focus();
			return false;
	}
	
	enviarDatosLogin();
	return false;
}
