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;
}
// *********************************** comprueba valida spacio.. ********************************************
function trim (myString)
{
	return myString.replace(/^\s+/g,'').replace(/\s+$/g,'')
}

 

function enviarDatos(){

user=trim(document.iniciar.usuario2.value);
con=trim(document.iniciar.contrasenha.value);

divResultado = document.getElementById('resultado');
ajax=objetoAjax();

 		if(trim(user) == '')
		{
			document.getElementById("identifi").innerHTML = " * Error de cuenta";	
		}
		else if(trim(con) == '')
		{
			document.getElementById("identifi").innerHTML = " * Error de cuenta";	
		}
		else
		{
			document.getElementById("identifi").innerHTML =" *  Espere";	
			ajax.open("POST", "usuario/control/",true);
			ajax.onreadystatechange=function() 
			{
				if (ajax.readyState==4) {
					//mostrar resultados en esta capa
					//divResultado.innerHTML = ajax.responseText
					  
					var respuesta = trim(ajax.responseText);
			 		 
					if(respuesta=='0501')
					{
						//ver_user_sesion();
						//location.href=botoncito;
						document.getElementById("identifi").innerHTML ="* Error de cuenta";	
						document.iniciar.usuario2.value="Usuario";
						document.iniciar.contrasenha.value="Contraseņa";
						
						
					}
					else if(respuesta=='1001')
					{
							
						location.href='anuncios/crear/';
						
					}
					
				}
			}
			 
			ajax.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
			ajax.send("usuario2="+user+"&contrasenha="+con);
		}
	 
}
function enviarAn(p)
{
		if(p==1)
		{
			location='anuncios/crear/';
		}
		else if(p==0)
		{
			alert("Debes iniciar sesion con tu cuenta");	
		}
		
}
 
