var Merr = ""; var Df = ""; var Hf = ""; var wDF = ""; var wHF = ""; function DiasEnElMes(a, c) { var b = CrearTablaVacia(12); b[1] = 31; b[2] = DiasEnFebrero(c); b[3] = 31; b[4] = 30; b[5] = 31; b[6] = 30; b[7] = 31; b[8] = 31; b[9] = 30; b[10] = 31; b[11] = 30; b[12] = 31; return b[a] } function CrearTablaVacia(c) { var b = new Array(); for (var a = 1; a <= c; a++) { b[a] = 0 } return b } function DiasEnFebrero(a) { return (a % 4 == 0 && (!(a % 100 == 0) || (a % 400 == 0)) ? 29 : 28) } function ComprobarFecha(c, a) { Merr = ""; if (c == "" && a == false) { return true } if (c == "" && a == true) { Merr = "es obligatioria."; return false } t = c.split("/"); if (t.length != 3) { Merr = "no tiene el formato adecuado."; return false } if (t[0] == "" || t[1] == "" || t[2] == "") { Merr = "no tiene valores adecuados."; return false } if (isNaN(t[0]) || isNaN(t[1]) || isNaN(t[2])) { Merr = "no posee valores numericos."; return false } if (t[0].length == 1) { t[0] = "0" + t[0] } if (t[1].length == 1) { t[1] = "0" + t[1] } if (t[2].length == 1) { t[2] = "200" + t[2] } if (t[2].length == 2) { t[2] = "20" + t[2] } wDF = t[0] + "/" + t[1] + "/" + t[2]; var b = parseVal(t[0], 10); var d = parseVal(t[1], 10); var e = parseVal(t[2], 10); if (d < 1 || d > 12) { Merr = "el dia es erroneo."; return false } if (b > DiasEnElMes(d, e)) { Merr = "el dia/mes es erroneo."; return false } return true } function ComprobarRangoFecha(c, b) { if (c == "" && b == "") { return true } if (c == "" && b != "") { return false } if (c != "" && b == "") { return false } if (ComprobarFecha(c, true) == true && ComprobarFecha(b, true) == true) { t1 = c.split("/"); t2 = b.split("/"); var d = t1[2] + "/" + t1[1] + "/" + t1[0]; var a = t2[2] + "/" + t2[1] + "/" + t2[0]; if (d > a) { return false } else { return true } } else { return false } } function FechaMenorQueHoy(c) { var e = new Date(); var b = e.getDate() + "/" + (e.getMonth() + 1) + "/" + e.getFullYear(); t1 = c.split("/"); t2 = b.split("/"); if (t1[0].length == 1) { t1[0] = "0" + t1[0] } if (t1[1].length == 1) { t1[1] = "0" + t1[1] } if (t2[0].length == 1) { t2[0] = "0" + t2[0] } if (t2[1].length == 1) { t2[1] = "0" + t2[1] } var d = t1[2] + "/" + t1[1] + "/" + t1[0]; var a = t2[2] + "/" + t2[1] + "/" + t2[0]; if (d < a) { return true } else { return false } } function es_mail(a) { if (a.indexOf("@") == -1) { return false } else { mail_tmp = a.substring(a.indexOf("@"), a.length); if (mail_tmp.indexOf(".") == -1) { return false } else { return true } } } function es_numerico(a) { caracteres_validos = "1234567890"; for (k = 0; k < a.length; k++) { tmp = a.substr(k, 1); if (caracteres_validos.search(tmp) == "-1") { return false } } return true } function isInteger(b) { var a; for (a = 0; a < b.length; a++) { var d = b.charAt(a); if (((d < "0") || (d > "9"))) { return false } } return true } function stripCharsInBag(d, e) { var b; var a = ""; for (b = 0; b < d.length; b++) { var f = d.charAt(b); if (e.indexOf(f) == -1) { a += f } } return a } var dtCh = "/"; var minYear = 1900; var maxYear = 2100; function isDate(c) { var d = c.indexOf(dtCh); var b = c.indexOf(dtCh, d + 1); var f = c.substring(0, d); var g = c.substring(d + 1, b); var e = c.substring(b + 1); strYr = e; if (f.charAt(0) == "0" && f.length > 1) { f = f.substring(1) } if (g.charAt(0) == "0" && g.length > 1) { g = g.substring(1) } for (var a = 1; a <= 3; a++) { if (strYr.charAt(0) == "0" && strYr.length > 1) { strYr = strYr.substring(1) } } month = parseVal(g); day = parseVal(f); year = parseVal(strYr); if (d == -1 || b == -1) { alert("El formato de fecha debe de ser: dd/mm/aaaa"); return false } if (g.length < 1 || month < 1 || month > 12) { alert("Please enter a valid month"); return false } if (f.length < 1 || day < 1 || day > 31 || (month == 2 && day > DiasEnFebrero(year)) || day > DiasEnElMes(month, year)) { alert("Por favor, introduce un día válido"); return false } if (e.length != 4 || year == 0 || year < minYear || year > maxYear) { alert("Por favor introduce un año válido de cuatro cifras"); return false } if (c.indexOf(dtCh, b + 1) != -1 || isInteger(stripCharsInBag(c, dtCh)) == false) { alert("Por favor, introduce una fecha válida"); return false } return true } function ultimoDiaMes(a) { var d = a.split("/"); var e = parseVal(d[0]); var b = parseVal(d[1]); var c = parseVal(d[2]); dias = DiasEnElMes(b, c); return formatearFecha(e + "/" + b + "/" + c) } function parseVal(a) { if (a == null) { return "0" } while (a.charAt(0) == "0") { a = a.substring(1, a.length) } return parseInt(a) } function addDiasAFecha(a, f) { var c = parseVal(f); var e = a.split("/"); var g = parseVal(e[0]); var b = parseVal(e[1]); var d = parseVal(e[2]); c += g; while (c < 1 || c > DiasEnElMes(b, d)) { if (c < 1) { b--; if (b < 1) { b = 12; d-- } c += DiasEnElMes(b, d) } if (c > DiasEnElMes(b, d)) { c -= DiasEnElMes(b, d); b++; if (b > 12) { b = 1; d++ } } } return formatearFecha(cerosIzquierda(c, 2) + "/" + cerosIzquierda(b, 2) + "/" + cerosIzquierda(d, 4)) } function addMesAFecha(a, f) { var d = a.split("/"); var e = parseVal(d[0]); var b = parseVal(d[1]); var c = parseVal(d[2]); b += f; while (b < 1) { b += 12; c-- } while (b > 12) { b -= 12; c++ } if (e > DiasEnElMes(b, c)) { e = DiasEnElMes(b, c) } return formatearFecha(e + "/" + b + "/" + c) } function ValidateForm() { var a = document.frmSample.txtDate; if (isDate(a.value) == false) { a.focus(); return false } return true } function lanzarURL(b, a) { lanzarURLConPregunta(b, a, "") } function lanzarURLConPregunta(e, b, d) { var a = true; if (d != "") { a = confirm(d) } if (a) { var c = document.getElementById(e); c.action = b; c.submit() } } function controlarTamano(c, b) { var a = document.getElementById(c); if (a != null) { if (a.value.length > b) { alert("La longitud maxima de este campo es " + b); a.value = a.value.substring(0, b) } } else { alert("El id " + c + " no ha sido encontrado") } } function formatearFecha(a) { aFecha = a.split("/"); if (aFecha[0].length == 1) { aFecha[0] = "0" + aFecha[0] } if (aFecha[1].length == 1) { aFecha[1] = "0" + aFecha[1] } a = aFecha[0] + "/" + aFecha[1] + "/" + aFecha[2]; return a } function test() { alert("Funciones.js se ha incluido correctamente") } function cerosIzquierda(b, a) { while (b.length < a) { b = "0" + b } return b } function formatearFechaDMA(c, a, b) { while (c < 1) { c++ } while (a < 1) { a += 12; b-- } while (a > 12) { a -= 12; b++ } if (c > DiasEnElMes(a, b)) { c = DiasEnElMes(a, b) } return formatearFecha(cerosIzquierda(c, 2) + "/" + cerosIzquierda(a, 2) + "/" + cerosIzquierda(b, 4)) } function setVisible(c, b) { var a = document.getElementById(c); if (b) { a.style.display = "" } else { a.style.display = "none" } };
