/*on*/
function foco(elemento,id) { 
	elemento.style.border = "1px solid #ff9900";	
	var noteid = 'note' + id; 
	var alertid = 'alert' + id; 
	document.getElementById(noteid).style.display="block";	
	document.getElementById(alertid).style.display="none";
		if(id=="correo"){
			document.getElementById("noteDcorreo").style.display="none";
		}
} 
	function foco_usuario(elemento,id,string) { 
		elemento.style.border = "1px solid #ff9900";	
		var noteid = 'note' + id; 
		var noteDid = 'noteD' + id; 
		var alertid = 'alert' + id; 
			document.getElementById(alertid).style.display="none";
		if (elemento.value.length ==""){
			document.getElementById(noteid).style.display="block";
			document.getElementById(noteDid).style.display="none";
			document.getElementById(alertid).style.display="none";	
			document.getElementById("showusuario").innerHTML="NOMBRE DE USUARIO";
		}
		
	}

	
/*out*/
function no_foco(elemento,id) { 
	elemento.style.border = "1px solid #CCCCCC"; 
	var noteid = 'note' + id; 
	document.getElementById(noteid).style.display="none";
}

	function no_foco_correo(elemento,id,stringmail) { 
		elemento.style.border = "1px solid #CCCCCC"; 
		var noteid = 'note' + id; 
		document.getElementById(noteid).style.display="none";		
		if (!elemento.value.length ==""){ 
			var tempmail = "";
				stringmail = '' + stringmail;
				splitstringmail = stringmail.split(" ");
				for(i = 0; i < splitstringmail.length; i++)
				tempmail += splitstringmail[i];	
				elemento.value=tempmail;			
			if (!elemento.value.indexOf('@', 0) == -1 || elemento.value.indexOf('.', 0) == -1){ 
				document.getElementById("alertcorreo").innerHTML="Escribe una dirección de correo válida";
				document.getElementById("alertcorreo").style.display="block";
			}
			else{
				var variable_post=tempmail;	
				$.post("home/inc/searchcorreo.php", { variablec: variable_post }, function(data){
					document.getElementById("alertcorreo").style.display="none";
					document.getElementById("noteDcorreo").style.display="block";
					$("#noteDcorreo").html(data);
				});	
			}
			return tempmail;
		}		
	}
	
	function ignoreSpaces(string,elemento,id) {
		var noteid = 'note' + id; 
		document.getElementById(noteid).style.display="none";
		if (!elemento.value.length ==""){
			if (elemento.value.length < 17) { 
				var temp = "";
				string = '' + string;
				splitstring = string.split(" ");
				for(i = 0; i < splitstring.length; i++)
				temp += splitstring[i];	
				
				elemento.value=temp;
				
				var variable_post=temp;			
				$.post("home/inc/typename.php", { variable: variable_post }, function(data){
					$("#showusuario").html(data);
				});	
				$.post("home/inc/searchname.php", { variable: variable_post }, function(data){
					document.getElementById("alertusuario").style.display="none";
					document.getElementById("noteDusuario").style.display="block";					
					$("#noteDusuario").html(data);
				});				
				return temp;
			}
			else{
				document.getElementById("noteDusuario").style.display="none";
				document.getElementById("alertusuario").innerHTML="Límite de 16 Caracteres";
				document.getElementById("alertusuario").style.display="block";
			}
		}
		else{
			document.getElementById("showusuario").innerHTML="NOMBRE DE USUARIO";
			document.getElementById("noteDusuario").style.display="none";
			document.getElementById(noteid).style.display="block";
		}		
	}
	
	function ignoreSpacesblur(string,elemento,id) {
		elemento.style.border = "1px solid #CCCCCC"; 
		var noteid = 'note' + id; 
		document.getElementById(noteid).style.display="none";
		
		if (!elemento.value.length ==""){
			if (elemento.value.length < 17) { 
				var temp = "";
				string = '' + string;
				splitstring = string.split(" ");
				for(i = 0; i < splitstring.length; i++)
				temp += splitstring[i];
				
				elemento.value=temp;
				
				var variable_post=temp;
				$.post("home/inc/typename.php", { variable: variable_post }, function(data){
					$("#showusuario").html(data);
				});	
				$.post("home/inc/searchname.php", { variable: variable_post }, function(data){
					document.getElementById("alertusuario").style.display="none";
					document.getElementById("noteDusuario").style.display="block";
					$("#noteDusuario").html(data);
				});	
				return temp;
			}
			else{
				document.getElementById("noteDusuario").style.display="none";
				document.getElementById("alertusuario").innerHTML="Límite de 16 Caracteres";
				document.getElementById("alertusuario").style.display="block";				
			}	
		}
		else{
			document.getElementById("showusuario").innerHTML="NOMBRE DE USUARIO";
			document.getElementById("noteDusuario").style.display="none";
		}		
	}

	
	
/*chk*/
function checkterm() { 
	if (!registro.terminos.checked) {
		document.getElementById("alertterminos").style.display="block";
	}
	else{
		document.getElementById("alertterminos").style.display="none";
	}
}



/*val*/
function validar(formulario) {
	var contret=0;

	if (formulario.nombre.value.length =="") { 
		document.getElementById("notenombre").style.display="none";		
		document.getElementById("alertnombre").style.display="block";
			contret = contret+1;		
	} 

	if (formulario.correo.value.length =="") {
		document.getElementById("notecorreo").style.display="none";
		document.getElementById("alertcorreo").innerHTML="Escribe tu correo electrónico";
		document.getElementById("alertcorreo").style.display="block";
			contret = contret+1;
	} 
	else{
		if (!formulario.correo.value.indexOf('@', 0) == -1 || formulario.correo.value.indexOf('.', 0) == -1){ 
			document.getElementById("alertcorreo").innerHTML="Escribe una dirección de correo válida";
			document.getElementById("alertcorreo").style.display="block";
				contret = contret+1;
		}
		else{
			document.getElementById("alertcorreo").style.display="none";
		}
	}
	
	if (formulario.usuario.value.length =="") { 
		document.getElementById("noteusuario").style.display="none";
		document.getElementById("alertusuario").style.display="block";
			contret = contret+1;
	} 
	else{
		if (formulario.usuario.value.length < 17) {
			var checkOK = "0123456789" + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
			  var checkStr = formulario.usuario.value;
			  var allValid = true; 
			  for (i = 0; i < checkStr.length; i++) {
				ch = checkStr.charAt(i); 
				for (j = 0; j < checkOK.length; j++)
				  if (ch == checkOK.charAt(j))
					break;
				if (j == checkOK.length) { 
				  allValid = false; 
				  break; 
				}
			  }
			  if (!allValid) { 
				document.getElementById("noteusuario").style.display="none";	
				document.getElementById("noteDusuario").style.display="none";	
				document.getElementById("alertusuario").innerHTML="Letras o números, sin acentos ni símbolos";
				document.getElementById("alertusuario").style.display="block";
					contret = contret+1; 
			  } 
			  else{
				document.getElementById("alertusuario").style.display="none";
			}
		}
		else{
			document.getElementById("noteusuario").style.display="none";	
			document.getElementById("noteDusuario").style.display="none";	
			document.getElementById("alertusuario").innerHTML="Límite de 16 Caracteres";
			document.getElementById("alertusuario").style.display="block";
				contret = contret+1;
		}
	}
	
		 
	
	
	var elementos = 4;

	if (formulario.clave.value.length < elementos) { 
		document.getElementById("noteclave").style.display="none";
		document.getElementById("alertclave").style.display="block";
		contret = contret+1;
	}
	
	
   if (!formulario.terminos.checked) {
		document.getElementById("alertterminos").style.display="block";
	    contret = contret+1; 
   }
   else{
		document.getElementById("alertterminos").style.display="none";
   }
   
   if(contret!=0){
	return (false);
	}
  
}
