/**
		 * DHTML date validation script. Courtesy of SmartWebby.com (http://www.smartwebby.com/dhtml/)
		 */
		// Declaring valid date character, minimum year and maximum year
		var now = new Date();			
		var hoy_dia = now.getDate(); 
		var hoy_mes = 1 + (now.getMonth());
		var hoy_ano = now.getYear();
		if (hoy_ano < 1900) { hoy_ano = hoy_ano + 1900; }	  
		
		var dtCh= "/";
		var minYear=1900;
		var maxYear=hoy_ano;
		
		function isInteger(s){
			var i;
			for (i = 0; i < s.length; i++){   
				// Check that current character is number.
				var c = s.charAt(i);
				if (((c < "0") || (c > "9"))) return false;
			}
			// All characters are numbers.
			return true;
		}
		
		function stripCharsInBag(s, bag){
			var i;
			var returnString = "";
			// Search through string's characters one by one.
			// If character is not in bag, append to returnString.
			for (i = 0; i < s.length; i++){   
				var c = s.charAt(i);
				if (bag.indexOf(c) == -1) returnString += c;
			}
			return returnString;
		}
		
		function daysInFebruary (year){
			// February has 29 days in any year evenly divisible by four,
			// EXCEPT for centurial years which are not also divisible by 400.
			return (((year % 4 == 0) && ( (!(year % 100 == 0)) || (year % 400 == 0))) ? 29 : 28 );
		}
		function DaysArray(n) {
			for (var i = 1; i <= n; i++) {
				this[i] = 31
				if (i==4 || i==6 || i==9 || i==11) {this[i] = 30}
				if (i==2) {this[i] = 29}
		   } 
		   return this
		}
		
		function isDate(dtStr){
			var daysInMonth = DaysArray(12)
			var pos1=dtStr.indexOf(dtCh)
			var pos2=dtStr.indexOf(dtCh,pos1+1)
			var strMonth=dtStr.substring(0,pos1)
			var strDay=dtStr.substring(pos1+1,pos2)
			var strYear=dtStr.substring(pos2+1)
			strYr=strYear
			if (strDay.charAt(0)=="0" && strDay.length>1) strDay=strDay.substring(1)
			if (strMonth.charAt(0)=="0" && strMonth.length>1) strMonth=strMonth.substring(1)
			for (var i = 1; i <= 3; i++) {
				if (strYr.charAt(0)=="0" && strYr.length>1) strYr=strYr.substring(1)
			}
			month=parseInt(strMonth)
			day=parseInt(strDay)
			year=parseInt(strYr)
			if (pos1==-1 || pos2==-1){
				alert("Por favor introduzca una fecha válida")
				return false
			}
			if (strDay.length<1 || day<1 || day>31 || (month==2 && day>daysInFebruary(year)) || day > daysInMonth[month]){
				alert("Por favor introduzca un dia válido")
				return false
			}
			if (strMonth.length<1 || month<1 || month>12){
				alert("Por favor introduzca un mes válido")
				return false
			}
			if (strYear.length != 4 || year==0 || year<minYear || year>maxYear){
				alert("Por favor introduzca un año válido de 4 dígitos entre "+minYear+" y "+maxYear)
				return false
			}
			if (dtStr.indexOf(dtCh,pos2+1)!=-1 || isInteger(stripCharsInBag(dtStr, dtCh))==false){
				alert("Por favor introduzca una fecha válida")
				return false
			}
		return true
		}
		function validarFormularioControlEdad () {
		// OBTENER CAMPOS DEL FORMULARIO.
		formulario = document.fRegistro;
		var frm_dia = formulario.dia.value;
		var frm_mes = formulario.mes.value;
		var frm_ano = formulario.ano.value;
		var frm_fecha = frm_mes + "/" + frm_dia + "/" + frm_ano;
		
		// OBTENER LA FECHA DE HOY SEPARADA EN CAMPOS.
		var result = true;			  
		
		// COMPROBAR QUE DIA MES Y AÑO ESTÁN EN INTERVALOS DE VALORES CORRECTOS.
		if (!isDate(frm_fecha)) {
			return false;
		}
		
		// COMPROBAR MES Y DIA SI TIENE 18 AÑOS.
		if ((hoy_ano-frm_ano) < 18) { 
			result = false; 
		} else if ((hoy_ano-frm_ano) == 18 ) {			
			if (hoy_mes < frm_mes) { 
				result = false; 
			} else if (hoy_mes == frm_mes) {
				if (hoy_dia < frm_dia) { result = false; }
			}
		}
		
		if (!result){
			alert("Debe ser mayor de 18 años.")
			return false;
		} else {
			formulario.submit();
		}
		}
		
		/*
		* VALIDACION DE E-MAIL
		*/
		
		function isValidEmail(email, required) {
		if (required==undefined) {   // if not specified, assume it's required
			required=true;
		}
		if (email==null) {
			if (required) {
				return false;
			}
			return true;
		}
		if (email.length==0) {  
			if (required) {
				return false;
			}
			return true;
		}
		if (! allValidChars(email)) {  // check to make sure all characters are valid
			return false;
		}
		if (email.indexOf("@") < 1) { //  must contain @, and it must not be the first character
			return false;
		} else if (email.lastIndexOf(".") <= email.indexOf("@")) {  // last dot must be after the @
			return false;
		} else if (email.indexOf("@") == email.length) {  // @ must not be the last character
			return false;
		} else if (email.indexOf("..") >=0) { // two periods in a row is not valid
		return false;
		} else if (email.indexOf(".") == email.length) {  // . must not be the last character
		return false;
		}
		return true;
		}
		
		function allValidChars(email) {
		var parsed = true;
		var validchars = "abcdefghijklmnopqrstuvwxyz0123456789@.-_";
		for (var i=0; i < email.length; i++) {
		var letter = email.charAt(i).toLowerCase();
		if (validchars.indexOf(letter) != -1)
		  continue;
		parsed = false;
		break;
		}
		return parsed;
		}
		//<!-- FUNCIONES PARA MOSTRAR Y OCULTAR LOS NOMBRES DE LOS CAMPOS -->
		function LimpiarCampo404(campo) {
			if (campo.value == "DD" || campo.value == "MM" || campo.value == "AAAA") {
				campo.value = "";
			}
		}
		function RestaurarCampo404(campo, valor) {
			if (campo.value == "") {
				campo.value = valor;
			}
		}
