function borrar(){
	form = document.forms.eventos
	
	form.nro_comensales.value = ""
	form.dia_evento.value = ""
	form.mes_evento.value = ""
	form.anio_evento.value = ""
	form.hora_evento.value = ""
	form.min_evento.value = ""
}

function check_values() {
	form = document.forms.eventos

	if((form.hlogin.value == 0) || (form.hlogin.value == "")) {
		if((form.apellido.value == "") ||
	   		(form.nombre.value == "") ||
		   (form.telefono.value == "") ||
		   (form.email.value == "")) {
				alert("Los campos marcados con (*) son obligatorios");
				return false; 
		}
		else {
			if(check_datos()) return true;
			else return false;
			return true;
		}
	}
}

function check_datos() {
	form = document.forms.eventos
	bool = true
	cad = "";
	
	if(!validarEmail(form.email.value)){
		cad = "El email tiene un formato incorrecto \n\n";
		bool = false;
	}
	
	if((form.tipo_evento.selectedIndex < 0) || (form.tipo_evento.options[form.tipo_evento.selectedIndex].value == 0)){
		cad += "Debe seleccionar un tipo de evento \n\n";
		bool = false;
	}
	
	if (form.nro_comensales.value == "") {
		cad += "El numero de Comensales no debe estar vacio \n\n";
		bool = false;
	}
	else {
		if(isNaN(parseInt(form.nro_comensales.value))){
			cad += "El numero de Comensales ingresado no es un numero valido \n\n";
			bool = false;
		}
	}
	
	if (parseInt(form.nro_comensales.value) > 50) {
		cad += "El numero de Comensales no debe superar la cifra de 50 \n\n";
		bool = false;
	}
	
	if ((!check_dia(form.dia_evento.value)) || (!check_mes(form.mes_evento.value)) || (!check_anio(form.anio_evento.value))) {
			cad += "El formato de fecha es incorrecto \n\n";
			bool = false; 
	}
	
	today = new Date();
	var day   = today.getDate();
	var month = today.getMonth()+1;
    var year  = today.getYear();
	
	day = "" + day
	month = "" + month

	if(day.length == 1) day = "0" + day
	if(month.length == 1) month = "0" + month
	
	fday = form.dia_evento.value
	fmes = form.mes_evento.value
	
	if(fday.length == 1) fday = "0" + fday
	if(fmes.length == 1) fmes = "0" + fmes
	
	now = year + "/" + month + "/" + day
	date = form.anio_evento.value + "/" + fmes + "/" + fday
	
	if(now >= date){
		cad += "La fecha debe ser mayor a la actual \n\n";
		bool = false; 
	}
	
	if ((!check_min(form.min_evento.value)) || (!check_hora(form.hora_evento.value))) {
			cad += "El formato de hora es incorrecto \n\n";
			bool = false; 
	}
	
	if (bool) return true;
	else {
		alert(cad);
		return false;
	}
}

function check_dia(dia) {
	if(dia != "") {
		if(dia.charAt(0) == "0") dia = dia.substring(1,2)
		if(((parseInt(dia) >= 1) && (parseInt(dia) <= 31))) return true;
		else return false;
	}
	else return false;
}

function check_mes(mes) {
	if(mes != "") {
		if(mes.charAt(0) == "0") mes = mes.substring(1,2)
		if (((parseInt(mes) >= 1) && (parseInt(mes) <= 12))) return true;
		else return false;
	}
	else return false;
}

function check_anio(anio) {
	if(anio != "") {
		if (((parseInt(anio) >= 1900) && (parseInt(anio) <= 2100))) return true;
		else return false;
	}
	else return false;
}

function check_hora(hora) {
	if(hora != "") {
		if (((parseInt(hora) >= 0) && (parseInt(hora) <= 24))) return true;
		else return false;
	}
	else return false;
}

function check_min(minu) {
	if(minu != "") {
		if (((parseInt(minu) >= 0) && (parseInt(minu) <= 60))) return true;
		else return false;
	}
	else return false;
}

function validarEmail(valor) {
  if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(valor)){
    return true
  } 
  else return false;
}


