function ValidarTlfn(sTelefono){
	var bOk=true;
	if(sTelefono!=''){
		bOk=isNum(sTelefono);
	
		if(bOk){
			//alert(sTelefono.indexOf("9"))
			bOk=((sTelefono.indexOf("9")==0) || (sTelefono.indexOf("6")==0) || (sTelefono.indexOf("8")==0))
		}
	}	
	return(bOk);
}

 function isNum(st) {
    var RefString="1234567890";
    var esNumerico=true;
    for (i=0; i < st.length; i++) {
      if (RefString.indexOf(st.charAt(i), 0) == -1) {
        esNumerico = false;
      }
    }
    return(esNumerico);
  }
  
  
function C_email(valor){
	if(ValidaMail(valor)){
		pos_A= valor.indexOf("@")
		pos_P= valor.indexOf(".")
	
		if(pos_A==-1 || pos_A==0 || pos_A==valor.length-1)
			return false;
	
		return true;
	}
}


function QuitaBlancos(string) {
	var temp = "";
	string = '' + string;
	splitstring = string.split(" ");
	for(i = 0; i < splitstring.length; i++)
	temp += splitstring[i];
	return(temp);
}


function ValidaMail(eMail) {
    var er_email = /^(.+\@.+\..+)$/

    if(!er_email.test(eMail)) {
       alert('Campo E-MAIL no válido.');
       return false;
    } else {
	return true;
	}
}



/* ********************************************************************************************************** */
/* ESTA FUNCIÓN VALIDA UN CAMPO FECHA                                                                         */
/* ********************************************************************************************************** */
function isDate(sFecha) {

	var bError = 0;
	var sDia = "";
	var sMes = "";
	var sAnyo = "";
	var i = 0;
	sMensaje = "Se han encontrado los siguientes errores:\n"
	aMensajeError = new Array();
	aMensajeError[0] = '';
	aMensajeError[1] = 'Error en el formato de fecha. Falta algun dato.';
	aMensajeError[2] = 'El dia "dd" es incorrecto';
	aMensajeError[3] = 'El mes "mm" es incorrecto';
	aMensajeError[4] = 'El año "aa" o "aaaa" es incorrecto';
	aMensajeError[5] = 'El numero de dias en Febrero no corresponde'; 
	aMensajeError[6] = 'El numero de dias en ese mes no corresponde';
	aMensajeError[7] = 'Error en el formato de fecha. Separador incorrecto.';

	var daysInMonth = new Array(31,29,31,30,31,30,31,31,30,31,30,31);
	
	aFecha = sFecha.split("/")
	
	if (aFecha.length == 3) {
		sDia = aFecha[0]
		sMes = aFecha[1]
		sAnyo = aFecha[2]
	}
	else {
		aFecha = sFecha.split("-")
		if (aFecha.length == 3) {
			
			sFecha= sFecha.replace(/-/g, "/")
			sDia = aFecha[0]
			sMes = aFecha[1]
			sAnyo = aFecha[2]

		}
		else
		{
			sMensaje += aMensajeError[7] + "\n";
			bError = 1;
		}
	}
		
	if (aFecha.length == 3) {	
		if (sDia != "" && sMes != "" && sAnyo != "") {
		
			if (isNum(sDia)) {
				if (( parseInt(sDia,10) > 31 ) || ( parseInt(sDia,10) < 1 ) || (sDia < "0") || (sDia > "9")) {
					sMensaje += aMensajeError[2] + "\n";
					bError = 1;
				}
			} else {
				sMensaje += aMensajeError[2] + "\n"
				bError = 1;
			}
			
			if (isNum(sMes)) {
				if (( parseInt(sMes,10) > 12 ) || ( parseInt(sMes,10) < 1 ) || sMes < "0" || sMes > "9") {
					sMensaje += aMensajeError[3] + "\n"
					bError = 1;
				}
			} else {
				sMensaje += aMensajeError[3] + "\n"
				bError = 1;
			}
			
			if (( parseInt(sMes,10) == 2) && ( parseInt(sDia,10) > daysInFebruary(parseInt(sAnyo)) )) {
				sMensaje += aMensajeError[5] + "\n";
				bError = 1;
			}
			else {
				//Control "Dia del Mes" correcto, menos febrero
				if (daysInMonth[parseInt(sMes,10)-1] < parseInt(sDia,10)) {
					sMensaje += aMensajeError[6] + "\n";
					bError = 1;
				}
			}
					
			if (isNum(sAnyo)) {
				if ( (sAnyo.length != 2) && (sAnyo.length != 4) ) {
					sMensaje += aMensajeError[4] + "\n"; 
					bError = 1;
				}
			} else {
				sMensaje += aMensajeError[4] + "\n"
				bError = 1;
			}
		
		}
		else {
			sMensaje += aMensajeError[1] + "\n"; 
			bError = 1;
		}
	}
		if ( bError != 0 ) {
			// Este alert mostraría el mensaje concretando el error en caso de ser necesario
			return false;
		}
		else{
			return true;
		}

}


//Laura Varela: 
function daysInFebruary (year)
{   
// Febrero tiene 29 dias en cualquier año divisible por 400 excepto los siglos
    return (  ((year % 4 == 0) && ( (!(year % 100 == 0)) || (year % 400 == 0) ) ) ? 29 : 28 );
} 


/* ********************************************************************************************************** */
/* ESTA FUNCIÓN DEVUELVE TRUE SI EL DATO ENVIADO COMO PARÁMETRO A LA FUNCIÓN ES NUMÉRICO, Y FALSE SI NO LO ES */
/* Creada 17-08-2006 por Natalia									      */
/* ********************************************************************************************************** */
 function isNum(st) {
    var RefString="1234567890";
    var esNumerico=true;
    for (i=0; i < st.length; i++) {
      if (RefString.indexOf(st.charAt(i), 0) == -1) {
        esNumerico = false;
      }
    }
    return(esNumerico);
  }
  