//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function valida_txt(id, Min, Max, modo_n, modo_ce, obligado) {
	contenedor = document.getElementById(id);
	flag = true;

	id_mostrar = id.split('_');
	id_mostrar = id_mostrar.join(' ');
	
	/* Verifica si el minimo/maximo es 1 para el alert */
	text_final1 = (Min == 1) ? ' character' : ' characters';
	text_final2 = (Max == 1) ? ' character' : ' characters';

	if(obligado != 'no' || contenedor.value != '') {
		/* Verifica el minimo de caracteres */
		if(contenedor.value.length < Min) {
			alert("The field '"+id_mostrar+"' must have at least " + Min + text_final1);
			contenedor.focus();
			flag = false;
			return false;
		}
		/* Verifica el maximo (*si es 0 no tiene limite de caracteres) */
		if(flag == true)
			if(Max != 0)
				if(contenedor.value.length > Max) {
					alert("The field '"+id_mostrar+"' cannot exceed " + Max + text_final2);
					contenedor.focus();
					flag = false;
					return false;
				}
		/* Verifica que no contenga números */
		if(flag == true)
		if(modo_n == 'sinN')
			if(!isNaN(contenedor.value) && contenedor.value != '') {
				alert("The field '" + id_mostrar + "' must not contain numbers");
				contenedor.focus();
				flag = false;
				return false;
			}
		/* Verifica que solo contenga los siguientes caracteres */
			/* Verifica que si puede tener números puede llevar . y los 10 digitos */
		if(modo_n == 'sinN')
		caracteres = "abcdefghijklmnñopqrstuvwxyzABCDEFGHIJKLMNÑOPQRSTUVWXYZ áéíóúÁÉÍÓÚ";
		else
		caracteres = "abcdefghijklmnñopqrstuvwxyzABCDEFGHIJKLMNÑOPQRSTUVWXYZ áéíóúÁÉÍÓÚ.0123456789-";
		
		if(flag == true)
		if(modo_ce == 'sinCE')
			for(i=0; i < contenedor.value.length; i++) {
				ubicacion = contenedor.value.substring(i, i + 1);
				if(caracteres.indexOf(ubicacion) == -1) {
					alert("The character '" + ubicacion + "' is not accepted in the field '" + id_mostrar);
					contenedor.focus();
					flag = false;
					return false;
					break;
				}
			}
			
		return true;
	} else return true;
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function valida_num(id, Min, Max, modo_num, obligado) {
	contenedor = document.getElementById(id);
	flag = true;

	id_mostrar = id.split('_');
	id_mostrar = id_mostrar.join(' ');

	/* Verifica si el minimo/maximo es 1 para el alert */
	text_final1 = (Min == 1) ? ' character' : ' characters';
	text_final2 = (Max == 1) ? ' character' : ' characters';
	
	if(obligado != 'no' || contenedor.value != '') {
		/* Verifica el minimo de digitos */
		if(contenedor.value.length < Min) {
			alert("The field '"+id_mostrar+"' must be a number of at least " + Min + text_final1);
			contenedor.focus();
			flag = false;
			return false;
		}
		/* Verifica mayor a 0 */
		if(contenedor.value <= 0) {
			alert("The field '"+id_mostrar+"'must be greater than zero");
			contenedor.focus();
			flag = false;
			return false;
		}		
		/* Verifica el maximo (*si es 0 no tiene limite de caracteres) */
		if(flag == true)
			if(Max != 0)
				if(contenedor.value.length > Max) {
					alert("The field '"+id_mostrar+"' must be a number of no more than " + Max + text_final2); 
					contenedor.focus();
					flag = false;
					return false;
				}
		
		/* Verifica que sea numero entero o decimal */
		if(flag == true)
			if(isNaN(contenedor.value)) {
				alert("The field '"+id_mostrar+"' must be numeric");
				contenedor.focus();
				flag = false;
				return false;
			}
		
		/* Verifica que sea numero entero*/
		caracteres = '.';
		if(flag == true)
			if(modo_num == 'int')
				for(i=0; i < contenedor.value.length; i++) {
					ubicacion = contenedor.value.substring(i, i + 1);
					if(caracteres.indexOf(ubicacion) != -1) {
						alert("The field '" + id_mostrar + "' does not accept decimal numbers");
						contenedor.focus();
						return false;
						break;
					}
				}
		return true;
	} else return true;
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function valida_email(id, obligado) {
	contenedor = document.getElementById(id);
	id_mostrar = id.split('_');
	id_mostrar = id_mostrar.join(' ');
	
	flag = true;
	caracteres = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_-.0123456789@';

if(obligado != 'no' || contenedor.value != '') {
	for(i=0; i < contenedor.value.length; i++) {
			ubicacion = contenedor.value.substring(i, i + 1);
			if(caracteres.indexOf(ubicacion) == -1) {
				alert("The character '" + ubicacion + "' is not accepted by '"+id_mostrar);
				contenedor.focus();
				flag = false;
				return false;
				break;
			}
	}
	
	//Para formato xxx@xxx.xx xxx....
	if(flag == true)
		if(contenedor.value.length < 10) {
			alert("The '"+id_mostrar+"' is too short to be correct");
			contenedor.focus();
			flag = false;
			return false;
		}
		
	// Checa q exista solo 1 @
	if(flag == true) {
		for(i=0, cont=0; i < contenedor.value.length; i++) {
			caracter = contenedor.value.substring(i, i + 1);
			if(caracter == '@')
				cont++;
			}
		if(cont != 1) {
			if(cont > 1)
				alert("There can only be one '@' in the field '"+id_mostrar);
			else
				alert("There must be a '@' in the field '"+id_mostrar);

			
			flag = false;
			contenedor.focus();
			return false
		}
	}
	
	// Checa que la arroba este antes de 3 caracteres: xxx@
	if(flag == true)
		if(contenedor.value.indexOf('@') < 3) {
			alert("It appears that the field '"+id_mostrar+"' is incorrect. There must be 3 characters before the '@'");
			flag = false;
			contenedor.focus();
			return false;
		}
		
	if(flag == true)
		if(contenedor.value.indexOf('@') < 3) {
			alert("It appears that the field '"+id_mostrar+"' is incorrect. There must be 3 characters before the '@'");
			flag = false;
			contenedor.focus();
			return false;
		}

	pos_arroba = contenedor.value.indexOf('@');
	dominio = contenedor.value.substring(pos_arroba+1, contenedor.value.length);
	arreglo_extenciones = new Array('.co','.com','.net','.org','.info','.biz','.tv','.us','.cc','.name','.bz','.uk','.de','.be','.nz','.at','.ws');
	if(flag == true) {
		for(i=0,cont=0; i < arreglo_extenciones.length; i++) {
			if(dominio.indexOf(arreglo_extenciones[i]) != -1) {
				cont++;
				extencion = arreglo_extenciones[i];
			}
		}
		if(cont == 0) {
			alert("It appears that the field '"+id_mostrar+"' is incorrect. It must contain a valid extension (i.e. .com, .net)");
			flag = false;
			contenedor.focus();
			return false;
		}
	}
	if(flag == true) 
		if(dominio.indexOf(extencion) < 3) {
			alert("It appears that the field '"+id_mostrar+"' is incorrect. There must be at least 3 characters between the '@' and the extension");	
			flag = false;
			contenedor.focus();
			return false;
	}
	return true;
  } else return true;
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function valida_confirmacion(id_1, id_2) {
	contenedor0 = document.getElementByNameId(id_1);
	contenedor1 = document.getElementByNameId(id_2);
	
	id_mostrar = id_1.split('_');
	id_mostrar = id_mostrar.join(' ');
	
	if(contenedor0.value != contenedor1.value) {
		alert("The field '"+id_mostrar+"' does not match with the confirmation");
		contenedor1.focus();
		return false;
	} else
		return true;
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////