function esVacio(s)
{   return ((s == null) || (s.length == 0))
}

function estaEn(chequeo,digitos)
{
  for (i = 0;  i < chequeo.length;  i++)
  {
    ch = chequeo.charAt(i);
    ch2 = chequeo.charCodeAt(i);
    for (j = 0;  j < digitos.length;  j++)
    {
        if (ch == digitos.charAt(j))
        {
            correcto = true;
            break;
        }
        else
        {
            correcto = false;
        }
    }

    if (!correcto)
    {
        if (ch2 == 13)
            alert ('No Se Acepta el <Enter>');
        else
            alert ('El Siguiente Caracter no es Valido:'+ch);
        return (false);
    }
  }
  return (true);
}

function quitarEnter(chequeo)
{
  var retorno = "";
  for (i = 0;  i < chequeo.length;  i++)
  {
    ch = chequeo.charAt(i);
    ch2 = chequeo.charCodeAt(i);
    
    //alert (ch2);
    if (ch2 != 13 && ch2 !=10)
    {
    	retorno = retorno + ch;
    }
    else
    {
    	if (ch2 ==10)
    	{
    		retorno = retorno + " ";
    	}
    }
    //alert (retorno);
  }
  return (retorno);
}

function f_procesa_Form(form_formulario)
{
	var var_Aux,var_Nombre,var_Arr;
	var_Aux='';
	//alert (form_formulario.length);
	for (var i=0;i<(form_formulario.length-1);i++)
	{
		//alert (form_formulario.elements[i].name);
		if (form_formulario.elements[i].name != null)
		{
            var_Nombre=form_formulario.elements[i].name;
            var_Arr = var_Nombre.split("_");
            /*Verifica si el el campo en cuestion pude ser nulo, si no puede ser null,
            se procede a verificar si lo es, si el campo no tiene algun valor entonces no procede,
            la operacion*/
            if (var_Arr[0]=='f')
            {
                /*El campo puede ser vacio o no
                */
                if (var_Arr[3]=='N')
                {
                    if (esVacio(form_formulario.elements[i].value))
                    {
                        form_formulario.elements[i].focus();
                        if (var_Arr[1]=='2')
                            alert ('Debes de Selaccionar una opcion');
                        else
                            alert ('Debes de meter un dato');
                        return(false);
                    }
                }
                /*Si el campo debe ser entero
                */
                if(var_Arr[2]=='1')
                {
                    if (!estaEn(form_formulario.elements[i].value,'0123456789-.'))
                    {
                        form_formulario.elements[i].focus();
                        alert ('El Valor debe ser Entero');
                        return(false);
                    }
                }
                /*Si el campo debe ser alfanumerico
                */
                if(var_Arr[2]=='2')
                {
                    if (!estaEn(form_formulario.elements[i].value," ÁÉÍÓÚáéíóú0123456789ABCDEFGHIJKLMNÑOPQRSTUVXWYZabcdefghijklmnñopqrstuvwxyz&()%:;<>@/*/-+.$!¿¡?{][}_,\n´"))
                    {
                        form_formulario.elements[i].focus();
                        //alert ('El Valor debe ser Alfanumerio Valido');
                        return(false);
                    }
                }
                /*Si el campo debe ser nombre
                */
                if(var_Arr[2]=='3')
                {
                    if (!estaEn(form_formulario.elements[i].value,' 0123456789ÁÉÍÓÚáéíóúABCDEFGHIJKLMNÑOPQRSTUVWXYZabcdefghijklmnñopqrstuvwxyz:\'.,'))
                    {
                        form_formulario.elements[i].focus();
                        //alert ('El Valor debe ser Solo Letras');
                        return(false);
                    }
                }//
                /*Si el campo debe ser flotante
                */
                if(var_Arr[2]=='4')
                {
                    if (!estaEn(form_formulario.elements[i].value,'0123456789.') || form_formulario.elements[i].value == '.')
                    {
                        form_formulario.elements[i].focus();
                        //alert ('El Valor debe ser Flotante');
                        return(false);
                    }
                }
                /*Si el campo debe ser direccion de correo
                */
                if(var_Arr[2]=='5')
                {
                    if (!estaEn(form_formulario.elements[i].value,'0123456789ABCDEFGHIJKLMNÑOPQRSTUVXYZabcdefghijklmnñopqrstuvwxyz#/*/-+.$!¿¡?{][:}_@') || form_formulario.elements[i].value.indexOf ('@', 0) == -1)
                    {
                        form_formulario.elements[i].focus();
                        //alert ('Introduzca una dirección valida');
                        return(false);
                    }
                }
            }
       	}
	}
	return (true);
}
