


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 obj;

            if(window.XMLHttpRequest)

            {

                        obj = new XMLHttpRequest();

            }

            else if(window.ActiveXObject)
            {
                        obj = new ActiveXObject("Microsoft.XMLHTTP");
            }

            return obj;

}

function comprobar_existe(UserName,UserEmail){
	var comprobacion_user=nuevoAjax();

	comprobacion_user.open("GET", "comprobacion_user.php?user_name="+UserName+"&user_email="+UserEmail+"&user_password="+UserPass+"&ms="+new Date().getTime(), true);
	comprobacion_user.onreadystatechange=function(){
		if (comprobacion_user.readyState==4){
			if(comprobacion_user.responseText!="NO"){
				document.getElementById('mensajes').innerHTML = comprobacion_user.responseText;
				return false;
			}
		}
	}
	comprobacion_user.send(null);
	return true;
}

function altarun()
{
	UserName = document.formulario.user_name.value;
	UserEmail = document.formulario.user_email.value;
	UserPass = document.formulario.user_password.value;

	comprobar_existe(UserName,UserEmail)

	if(!comprobar(UserName,'txt')){document.getElementById('mensajes').innerHTML = 'Nombre de usuario incorrecto';document.formulario.user_name.focus();}
	if(!comprobar(UserEmail,'mail')){document.getElementById('mensajes').innerHTML = 'E-mail incorrecto';document.formulario.user_email.focus();}
	if(!comprobar(UserPass,'txt')){document.getElementById('mensajes').innerHTML = 'Contrase&ntilde;a incorrecta';document.formulario.user_password.focus();}



	if(comprobar(UserName,'txt') && comprobar(UserPass,'txt') && comprobar(UserEmail,'mail') && comprobar_existe(UserName,UserEmail)){
		document.getElementById('mensajes').innerHTML = '';
	    // Creo el nuevo objeto AJAX y envio al servidor el ID del select a cargar y la opcion seleccionada del select origen
	    var ajax=nuevoAjax();

	    ajax.open("GET", "/sections/perfil/perfilAltarun.php?user_name="+UserName+"&user_email="+UserEmail+"&user_password="+UserPass+"&ms="+new Date().getTime(), true);
	    ajax.onreadystatechange=function()
	    {
	      if (ajax.readyState==1)
	      {
			//AvisosId.innerHTML="<div style='width:100%;height:100%;text-align:center;'><img src='http://www.blaugranas.com/img/general/ajax-loader.gif'> <small>Enviando...</small></div>";
			document.getElementById('loading').style.display='block';
	      }
	      if (ajax.readyState==4)
	      {
		  	//alert('fi');
			document.getElementById('loading').style.display='none';
			document.getElementById('finalizado').style.display='block';
	      //  document.getElementById('mensajes').innerHTML = ajax.responseText;
	      }
	    }
	    ajax.send(null);
	}
}


function comprobar(texto,valor){
  if(valor=='txt')var comp = /^([a-zA-Z0-9\s]{2,13})$/;
  if(valor=='mail')var comp = /[\w-\.]{3,}@([\w-]{2,}\.)*([\w-]{2,}\.)[\w-]{2,4}/;

  if (comp.test(texto)) {return true;}
  else {return false;}
}


/**
 * Includes all JS needed
 *
 * $Id: main.js,v 1.7 2008/09/01 11:07:48 jcreus Exp $


function IncludeJS(jsFile){
	document.write(unescape("%3Cscript type='text/javascript' src='"+jsFile+"'%3E%3C/script%3E")); 
}

path="http://www.redpoesia.loc/js/new/";

IncludeJS(path+'jquery-1.2.6.js');
IncludeJS(path+'jquery.form.js');
IncludeJS(path+'jquery.validate.js');
IncludeJS(path+'thickbox.js');
IncludeJS(path+'jquery.scrollTo.js');
IncludeJS(path+'jquery.serialScroll.js');
IncludeJS(path+'generic.js');
IncludeJS(path+'functions.js');
IncludeJS(path+'event_functions.js');
IncludeJS(path+'validation_rules.js');


 */