//a esta función se le pasa una fecha en trozos y se encarga de validarla
//si la fecha es inválida retorna false, si es válida retorna true
function validate_date(day,month,year) {
	//debe tener seleccionado algunos valores
	if (day == -1 || month == -1 || year == "" || year.length < 4) {
		alert("Coloque la fecha completa");
		return false;
	}//if
	//sumar uno al día, pues el indice comienza en cero, pero los dias en uno
	day += 1;
	//crear una fecha con los datos suministrados
	testDate = new Date(year,month,day);
	testYear = testDate.getFullYear().toString();
	testMonth = testDate.getMonth().toString();
	testDay = testDate.getDate().toString();
	//si los datos son incorrectos, la fecha no coincide
	if (year != testYear || month != testMonth || day != testDay) {
		alert("La fecha que colocó es inválida: " + day + "/" + (month + 1) + "/" + year);
		return false;
	}//if
	return true;
}//validate_date

// valida una fecha en un formato DD/MM/YYYY o DD-MM-YYYY que viene en un
// solo string
function validateDateAsString(paramDate) {
	// ver si se ha pasado algún valor como parámetro
	if (paramDate != "") {
		var separationChar = "/";
		// obtener un string a partir de lo que se pasa como fecha
		var stringDate = new String(paramDate);
		//lo primero es tratar de obtener el dia, mes y ano separados unos de otros
		var indexOfDay = stringDate.indexOf(separationChar);
		// si no consigui /, entonces tal vez viene con separador -
		if (indexOfDay == -1) {
			separationChar = "-";
			indexOfDay = stringDate.indexOf(separationChar);
		}//if
		// si aun no lo consigue, entonces no hay una fecha valida
		if (indexOfDay == -1) {
			alert("Debe colocar una fecha con formato válido DD/MM/AAAA");
			return false;
		} else {
			// ahora obtener el dia en una variable, y el resto en otra
			var day = stringDate.substr(0,indexOfDay);
			// obtener el resto de la fecha
			var remainderDate = stringDate.substr(indexOfDay + 1,stringDate.length - 1);
			// ahora separar mes de ano
			var indexOfMonth = remainderDate.indexOf(separationChar);
			if (indexOfMonth == -1) {
				alert("Debe colocar una fecha con formato válido DD/MM/AAAA");
				return false;
			} else {
				// obtener ahora el mes y el ano
				var month = remainderDate.substr(0,indexOfMonth);
				var year = remainderDate.substr(indexOfMonth + 1,remainderDate.length - 1);
				if (day == "" || month == "" || year == "") {
					alert("Coloque la fecha completa. Formato válido DD/MM/AAAA");
					return false
				} else {
					integerDay = day;
					var integerMonth = month;
					integerYear = year;
					if (isNaN(integerDay) || isNaN(integerMonth) || isNaN(integerYear)) {
						alert("El formato de fecha no es correcto (DD/MM/AAAA). Se introdujo: " + paramDate);
						return false;
					} else {
						integerDay -= 1;
						integerMonth -= 1;
						return validate_date(integerDay,integerMonth,integerYear);
					}//if
				}
			}//if
		}//if
	} else {
		alert("Debe colocar una fecha.");
		return false;
	}//if
}