//-Funcion para validar la entrada de telfonos nuevos.  " onSubmit="return validafiesta(this);">
function validaenforo(F) {
	ok = true;
	if( vacio(F.autor.value) == false ) {
		ok = false;
	} 
	if( vacio(F.asunto.value) == false ) {
		ok = false;
	}
	if( vacio(F.mensaje.value) == false ) {
		ok = false;
	}
	if( ok == true ) {
		return true;
	} else {
		alert("¡ ERROR, ó falta rellenar algún campo ! ");
		return false;
	}
}

//------------------------------------------------------------------------

//-Valida 1 palabra pasada, teniendo en cuenta que:
function Coherencia1Palabra(PalabraX) {
	var palabraMasCorta=0; // error si no es mayor..
	var maximoVocales=6; // error si ms de..
	var maximoConsonantes=8; // error si ms de..
	var inconsistenteSiTieneJuntas=3; // error si ms de..
	var vocales="AEIOU02468"; 
	var consonantes="._-/\!*+&%$BCDFGHJKLMNPQRSTVWXYZ13579";
	var ntvocales = 0;	//cuenta el total de vocales
	var npvocales = 0;	//cuenta las vocales que hay juntas
	var ntconso = 0;	//total de consonantes
	var npconso = 0;	//conson. juntas
	var lonPal = 0;
	PalabraX=Trim(PalabraX).toUpperCase();
	lonPal=PalabraX.length;
	if(PalabraX == "") {return true;}
	if(!(lonPal>palabraMasCorta)){
		alert("Palabra muy corta");
		return false;
	}
	//-letra a letra.
	for(a=0;a<lonPal;a++){ 
		letra=PalabraX.charAt(a); 
		if(vocales.indexOf(letra)>-1){
			ntvocales+=1;
			npvocales+=1;
			npconso = 0;
			if(ntvocales>maximoVocales){
				alert("Demasiadas Vocales");
				return false;
			}
			if(npvocales>inconsistenteSiTieneJuntas){
				alert("Inconsistencia Vocales");
				return false;
			}
		}
		if(consonantes.indexOf(letra)>-1){
			ntconso+=1;
			npconso+=1;
			npvocales=0;
			if(ntconso>maximoConsonantes){
				alert("Demasiadas Consonantes");
				return false;
			}
			if(npconso>inconsistenteSiTieneJuntas){
				alert("Inconsistencia Consonantes");
				return false;
			}
		}
		
	} //for
return true;	
} //-EndFunc

//------------------------------------------------------------------------

//-Funcin que comprueba la validez(+-) de las palabras que se entran.
function Coherencia(frase){
	ok = true;
	//-Quita los espacios iniciales y finales
		frase = Trim(frase);
	//-Si est vaca, devuelve false y sale
		if( vacio(frase) == false ){return false;}		
	//-Bucle palabras
		palabra=frase.split(" "); 
		b = 0;
		lonPal=palabra.length;
		for (b=0;b<lonPal;b++){
			if(Coherencia1Palabra(palabra[b]) == false){
				ok = false;
				break;
			}
		} //-for (bucle palabras)
	return ok;
}

//------------------------------------------------------------------------

//-Quita los espacios de la parte Derecha.
function TrimRight( str ) {
	var resultStr = "";
	var i = 0;
	// Return immediately if an invalid value was passed in
	if (str+"" == "undefined" || str == null)	
		return null;
	// Make sure the argument is a string
	str += "";
	if (str.length == 0) 
		resultStr = "";
	else {
  		// Loop through string starting at the end as long as there
  		// are spaces.
  		i = str.length - 1;
  		while ((i >= 0) && (str.charAt(i) == " "))
 			i--;
 			
 		// When the loop is done, we're sitting at the last non-space char,
 		// so return that char plus all previous chars of the string.
  		resultStr = str.substring(0, i + 1);
  	}
 	
  	return resultStr;  	
} //-TrimRight

//------------------------------------------------------------------------

//-Quita los espacios de la parte izquierda.
function TrimLeft( str ) {
	var resultStr = "";
	var i = len = 0;

	// Return immediately if an invalid value was passed in
	if (str+"" == "undefined" || str == null)	
		return null;

	// Make sure the argument is a string
	str += "";

	if (str.length == 0) 
		resultStr = "";
	else {	
  		// Loop through string starting at the beginning as long as there
  		// are spaces.
//	  	len = str.length - 1;
		len = str.length;
		
  		while ((i <= len) && (str.charAt(i) == " "))
			i++;

   	// When the loop is done, we're sitting at the first non-space char,
 		// so return that char plus the remaining chars of the string.
  		resultStr = str.substring(i, len);
  	}

  	return resultStr;
} //-TrimLeft

//------------------------------------------------------------------------

// Este script depende de otros 2: Trim derecha y Trim izquierda
function Trim( str ) {
	var resultStr = "";
	resultStr = TrimLeft(str);
	resultStr = TrimRight(resultStr);
	return resultStr;
}

//------------------------------------------------------------------------

//-Mira si la cadena est vaca y si lo esta devuelve falso y si no devuelve true.
function vacio(q) {
        for ( i = 0; i < q.length; i++ ) {
                if ( q.charAt(i) != " " ) {
                        return true;
                }
        }
        return false;
}

//------------------------------------------------------------------------

//-Valida que la entrada se numrica.
function IsNum( numstr ) {
	// Return immediately if an invalid value was passed in
	if (numstr+"" == "undefined" || numstr+"" == "null" || numstr+"" == "")	
		return false;

	var isValid = true;
	var decCount = 0;		// number of decimal points in the string

	// convert to a string for performing string comparisons.
	numstr += "";	

	// Loop through string and test each character. If any
	// character is not a number, return a false result.
 	// Include special cases for negative numbers (first char == '-')
	// and a single decimal point (any one char in string == '.').   
	for (i = 0; i < numstr.length; i++) {
		// track number of decimal points
		if (numstr.charAt(i) == ".")
			decCount++;

    	if (!((numstr.charAt(i) >= "0") && (numstr.charAt(i) <= "9") || 
				(numstr.charAt(i) == "-") || (numstr.charAt(i) == "."))) {
       	isValid = false;
       	break;
		} else if ((numstr.charAt(i) == "-" && i != 0) ||
				(numstr.charAt(i) == "." && numstr.length == 1) ||
			  (numstr.charAt(i) == "." && decCount > 1)) {
       	isValid = false;
       	break;
      }         	         	       
//if (!((numstr.charAt(i) >= "0") && (numstr.charAt(i) <= "9")) || 
   } // END for   
   
   	return isValid;
}  // end IsNum

//------------------------------------------------------------------------
