// Funciones Genericas del tratamiento de Strings	
	
	// String. Vacio?    
	function isEmpty(s){
	return ((s == null) || (s.length == 0))
	}
	
	// Caracter. Vacio?
	function isDigit (c){ 
  	return ((c >= "0") && (c <= "9"))
	}
	
	// Quita todos los caracteres que que estan en "bag" del string "s" s.
	function stripCharsInBag (s, bag)
	{  
	 var i;
     var returnString = "";

    // Buscar por el string, si el caracter no esta en "bag", 
    // agregarlo a returnString
    
    for (i = 0; i < s.length; i++)
    {   var c = s.charAt(i);
        if (bag.indexOf(c) == -1) returnString += c;
    }

    return returnString;
	}
	
	// s es vacio o solo caracteres de espacio
	function isWhitespace (s)
	{   var i;
		var whitespace = " \t\n\r"; 
	    if (isEmpty(s)) return true;
	    for (i = 0; i < s.length; i++)
	    {   
	        var c = s.charAt(i);
	        // si el caracter en que estoy no aparece en whitespace,
	        // entonces retornar falso
	        if (whitespace.indexOf(c) == -1) return false;
	    }
	    return true;
	}
	
	//
	// s es un numero natural
	function isNatural (s){
	var i;
	var b = true;
	for (i = 0; ((i < s.length) && (b)); i++)
	{
		var c = s.charAt(i);
		if (isDigit(c)){
		b=true;
		}
		else{
		b=false;
		}
		
	}
	
	if (i==0) {
		return false;
	}
	else{
		return b;
	}
	}
	
	// s es un numero real (con o sin signo)
	function isNumber (s){ 
	var i;
    var dotAppeared;
    dotAppeared = false;
    if (isEmpty(s)) 
       if (isNumber.arguments.length == 1) {return false}
       else return (isNumber.arguments[1] == true)
    
    for (i = 0; i < s.length; i++)
    {   
        var c = s.charAt(i);
        if( i != 0 ) {
            if ( c == "." ) {
                if( !dotAppeared )
                    dotAppeared = true;
                else
                    return false;
            } else     
                if (!isDigit(c)) return false;
        } else { 
            if ( c == "." ) {
                if( !dotAppeared )
                    dotAppeared = true;
                else
                    return false;
            } else     
                if (!isDigit(c) && (c != "-") || (c == "+")) return false;
        }
    }
    return true;
	}
	

	// s es un numero entero (con o sin signo)
	function isInteger (s)
	{   var i;
	    if (isEmpty(s)) 
	       if (isInteger.arguments.length == 1) return true;
	       else return (isInteger.arguments[1] == true);
	    
	    for (i = 0; i < s.length; i++)
	    {   
	        var c = s.charAt(i);
	        if( i != 0 ) {
	            if (!isDigit(c)) return false;
	        } else { 
	            if (!isDigit(c) && (c != "-") || (c == "+")) return false;
	        }
	    }
	    return true;
	}
	
	// s es numero de telefono valido
	function isPhoneNumber (s)
	{   
		// caracteres admitidos en nos de telefono
		var phoneChars = "()-+./ ";
		var modString;
	    if (isEmpty(s)) 
	       if (isPhoneNumber.arguments.length == 1) return true;
	       else return (isPhoneNumber.arguments[1] == true);
	    modString = stripCharsInBag( s, phoneChars );
	    return (isInteger(modString))
	}
	
	// s es una direccion de correo valida
	function isEmail (s)
	{
	    if (isEmpty(s)) 
	       if (isEmail.arguments.length == 1) return true;
	       else return (isEmail.arguments[1] == true);
	    if (isWhitespace(s)) return false;
	    var i = 1;
	    var sLength = s.length;
	    while ((i < sLength) && (s.charAt(i) != "@"))
	    { i++
	    }
	
	    if ((i >= sLength) || (s.charAt(i) != "@")) return false;
	    else i += 2;
	
	    while ((i < sLength) && (s.charAt(i) != "."))
	    { i++
	    }
	
	    if ((i >= sLength - 1) || (s.charAt(i) != ".")) return false;
	    else return true;
	}

	// c es un caracter considerado valido
	function isCharValid (c)
	{
		return (c!='\\' && c!='\/' && c!=':' && c!='*' && c!='?' && c!='<' && c!='>' && c!='|' && c!="'" && c!="%")
	}
	
	// s es contiene caracteres validos
	function isStringValid (s) 
	{   var i;
		var b = true;
		for (i = 0; i < s.length && b; i++)
		{
			if (isCharValid(s.charAt(i)) )
			{
				b = true;
			}
			else
			{
				b = false;
			}
		}
		return b;
	}
	
	// c es un caracter considerado valido
	function isCharValidURL (c)
	{
		return (c!="'")
	}
	
	// s es contiene caracteres validos para ser considerada una direccion URL
	function isStringValidURL (s) 
	{   var i;
		var b = true;
		for (i = 0; i < s.length && b; i++)
		{
			if (isCharValidURL(s.charAt(i)) )
			{
				b = true;
			}
			else
			{
				b = false;
			}
		}
		return b;
	}
	
	//  m: mes , d: dia, y: aņo
	function isDate(d,m,y)
	{	
		if (m < 1 || m > 12 || d < 1 || d > 31) {return true;}
		if ((m == 2 || m == 4 || m == 6 || m == 9 || m==11) && d == 31) 
			{return true;}
		if (m == 2){
			var isleap = (y % 4 == 0 && (y % 100 != 0 || y % 400 == 0));
			if ( d > 29 || (d == 29 && !isleap)) {return true;}
		} 
		return false;
	}
	
	// isFileName nos da el nombre del fichero subido
	function isFileName(fichero)
	{
		if (fichero!=""){
								pos = fichero.lastIndexOf('\\');
								if (pos > 0) {
								extension = (fichero.substring( pos+1,fichero.length).toUpperCase());
								return(extension);
								}
												
						}								
	}
	
	// isFileText nos dice si el fichero a subir es de tipo "TEXTO"
	function isFileText(fichero)
	{
		if (fichero!=""){
								pos = fichero.lastIndexOf('.');
								if (pos > 0) {
									extension = (fichero.substring( pos+1,fichero.length).toUpperCase());
									switch(extension)
									{
									case 'TXT': {return(true);break;}
									case 'PDF': {return(true);break;}
									case 'PS':  {return(true);break;}
									case 'DOC': {return(true);break;}
									case 'TEX': {return(true);break;}
									case 'PPT': {return(true);break;}
									
						
									}
								}
								
						}								
	}
	
	// isFileText nos dice si el fichero a subir es de tipo "FOTO"
	function isFileFoto(fichero)
	{
		if (fichero!=""){
								pos = fichero.lastIndexOf('.');
								if (pos > 0) {
									extension = (fichero.substring( pos+1,fichero.length).toUpperCase());
									switch(extension)
									{
										case 'GIF': {return(true);break;}
										case 'JPG': {return(true);break;}
										case 'TIF':  {return(true);break;}
							
									}
								}
								
						}								
	}

	// isFileZip nos dice si el fichero a subir es de tipo COMPRIMIDO
	function isFileZip(fichero)
	{
		if (fichero!=""){
								pos = fichero.lastIndexOf('.');
								if (pos > 0) {
									extension = (fichero.substring( pos+1,fichero.length).toUpperCase());
									switch(extension)
									{
										case 'ZIP': {return(true);break;}
										case 'TAR': {return(true);break;}
										case 'GZ': {return(true);break;}
									}
								}
								
						}								
	}
	
	function isFilePDF(fichero)
	{
		if (fichero!=""){
			pos = fichero.lastIndexOf('.');
			if (pos > 0) 
			{
				extension = (fichero.substring( pos+1,fichero.length).toUpperCase());
				if(extension=='PDF')
				{
					return(true)
				}
				
			}
		}
		return(false);
	}
