function nuevoAjax(){
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;
}

//poner todos los cuadros de texto del form de alta del usuario a los valores iniciales.
function borrarDAlEmpresa(){
	
	document.getElementById('ref').value="";
	document.getElementById('descripc').value="";
	document.getElementById('material').value=0;
	document.getElementById('familia').value=0;
	document.getElementById('largo').value="";	
	document.getElementById('ancho').value="";
	document.getElementById('fotop').value="";
	document.getElementById('fotog').value="";
	
}

  

//existeUsuario
function existeUsuario(){
	
	var contenedor = document.getElementById('capaContenedora');
	var usuario= document.getElementById('usuario').value;
	usuario= trim(usuario);
	if (usuario!="")
	{
			ajax=nuevoAjax();
			ajax.open("GET", "existeusuario.php?user="+usuario,true);
			ajax.onreadystatechange=function() {
			if (ajax.readyState==4) {
				contenedor.innerHTML = ajax.responseText
				}
			else
				{
				contenedor.innerHTML = 'Comprobando usuario...';		
				}
				
			
			}
			ajax.send(null)
	}
}

//existeUsuario
function existeEmail(){
	var varemail=/^[^@\s]+@[^@\.\s]+(\.[^@\.\s]+)+$/
	var email= trim(document.getElementById('correo').value);
	 if  (varemail.test(email))
	{
			var contenedor = document.getElementById('capaContenedora1');
			
			ajax=nuevoAjax();
			ajax.open("GET", "existeemail.php?email="+email,true);
			ajax.onreadystatechange=function() {
			if (ajax.readyState==4) {
				contenedor.innerHTML = ajax.responseText
				}
			else
				{
				contenedor.innerHTML = 'Comprobando email...';		
				}
				
			
			}
			ajax.send(null)
		}
	}
	
	function existeEmail1(user){
	var varemail=/^[^@\s]+@[^@\.\s]+(\.[^@\.\s]+)+$/
	var email= trim(document.getElementById('correo').value);
	 if  (varemail.test(email))
	{
			var contenedor = document.getElementById('capaContenedora3');
			
			ajax=nuevoAjax();
			ajax.open("GET", "existeemail1.php?email="+email + "&user=" + user,true);
			ajax.onreadystatechange=function() {
			if (ajax.readyState==4) {
				contenedor.innerHTML = ajax.responseText
				}
			else
				{
				contenedor.innerHTML = 'Comprobando email...';		
				}
				
			
			}
			ajax.send(null)
		}
	}
	
function recuperaMail(){
	var varemail=/^[^@\s]+@[^@\.\s]+(\.[^@\.\s]+)+$/
	var email= trim(document.getElementById('correo').value);
	 if  (varemail.test(email))
	{
			var contenedor = document.getElementById('capaContenedora');
			
			ajax=nuevoAjax();
			ajax.open("GET", "reccon1.php?correo="+email,true);
			ajax.onreadystatechange=function() {
			if (ajax.readyState==4) {
				contenedor.innerHTML = ajax.responseText
				}
			else
				{
				contenedor.innerHTML = 'Comprobando email...';		
				}
				
			
			}
			ajax.send(null)
		}
		else
		alert ("La DIRECCION DE CORREO ELECTRONICO es incorrecta");
	}
	
	
function ltrim(s) {
   return s.replace(/^\s+/, "");
}

function rtrim(s) {
   return s.replace(/\s+$/, "");
}

function trim(s) {
   return rtrim(ltrim(s));
}

