function validarForm() { //v4.0 if (document.getElementById) { var i, p, q, nm, test, num, min, max, errors = '', args = validarForm.arguments; var queryStr = ''; for (i = 0; i < (args.length - 2); i += 3) { test = args[i + 2]; val = document.getElementById(args[i]); if (val) { nm = val.name; if ((val = val.value) != "") { if (test.indexOf('isEmail') != -1) { var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/; if (reg.test(val) == false) { errors += '- ' + nm + ' debe contener una dirección de email.\n'; } } else if (test.indexOf('isDate') != -1) { var fecha = parseDate(val); if (fecha == null) errors += '- ' + nm + ' debe ser una fecha válida.\n'; } else if (test.indexOf('esPersonas') != -1) { num = parseFloat(val); ind = Number(document.getElementById('individual').value); dob = Number(document.getElementById('doble').value); tri = Number(document.getElementById('triple').value); cua = Number(document.getElementById('cuadruple').value); maxpersonas = ind + dob * 2 + tri * 3 + cua * 4; //alert('ind ' + ind + ', dob ' + dob + ', tri ' + tri + ', cua ' + cua+ '\nmax: ' + maxpersonas + ', num: ' + num); if (num > maxpersonas) errors += '- ' + nm + ' excede el número permitido con la configuración actual de habitaciones.\n'; /*} else if (test.indexOf('isCaptcha') != -1) { alert("Hay Captcha! Es "+codeImg+"!"); if (codeImg != document.getElementById('code').value) { errors += 'El código introducido ('; errors += document.getElementById('code').value; errors += ') es inválido. Por favor vuelva a intentarlo.\n'; }*/ } else if (test != 'R') { num = parseFloat(val); if (isNaN(val)) errors += '- ' + nm + ' debe ser un teléfono.\n'; if (test.indexOf('inRange') != -1) { p = test.indexOf(':'); min = test.substring(8, p); max = test.substring(p + 1); if (num < min || max < num) errors += '- ' + nm + ' debe ser un número entre ' + min + ' y ' + max + '.\n'; } } } else if (test.charAt(0) == 'R') errors += '- ' + nm + ' es obligatorio.\n'; } //queryStr += nm+'='+val+'&'; } if (errors) { alert('Error(es):\n' + errors); } else { window.location = 'reserva.php'; } } }