// JavaScript Document
function display_date() {

   date = new Date();

   var day_of_week_number = date.getDay();
   var day_of_month = date.getDate();
   var month_number = date.getMonth();
   var year = date.getFullYear();
   var day_of_week = '';
   var month = ''

   if(month_number == 0){month = 'Enero';}
   if(month_number == 1){month = 'Febrero';}
   if(month_number == 2){month = 'Marzo';}
   if(month_number == 3){month = 'Abril';}
   if(month_number == 4){month = 'Mayo';} 
   if(month_number == 5){month = 'Junio';}
   if(month_number == 6){month = 'Julio';}
   if(month_number == 7){month = 'Agosto';}
   if(month_number == 8){month = 'Septiembre';}
   if(month_number == 9){month = 'Octubre';}
   if(month_number == 10){month = 'Noviembre';}
   if(month_number == 11){month ='Diciembre';}


   if(day_of_week_number == 0){day_of_week = 'Domingo';}
   if(day_of_week_number == 1){day_of_week = 'Lunes';}
   if(day_of_week_number == 2){day_of_week = 'Martes';}
   if(day_of_week_number == 3){day_of_week = 'Miércoles';}
   if(day_of_week_number == 4){day_of_week = 'Jueves';}
   if(day_of_week_number == 5){day_of_week = 'Viernes';}
   if(day_of_week_number == 6){day_of_week = 'Sábado';}
   var date_to_show = day_of_week + ', ' + day_of_month + ' de ' + month + ' de ' + year; 
   document.write('<span class="style4">' + date_to_show + '</span>');
} 

//VALIDA EL FORMATO DE UNA DIRECCION DE MAIL
function validarEmail(valor) {
	return(/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(valor))
}

//VALIDA LOS DATOS DEL FORMULARIO DE CONTACTO ANTES DE ENVIARLO
function validar_form_contacto(){
	
	if(document.getElementById("nombre").value.length == 0)
		{
			window.alert("Por favor, ingrese su Nombre y Apellido");
			document.getElementById("nombre").focus();
			return;
		}
	
	
	if(!validarEmail(document.getElementById("mail").value))
	{
		window.alert("Por favor, ingrese una dirección de e-mail correcta.");
		document.getElementById("mail").focus();
		return;	
	}
	
	if(document.getElementById("destinatarios").value.length == 0)
		{
			window.alert("Por favor, seleccione un Destinatario");
			document.getElementById("destinatarios").focus();
			return;
		}
	
	if(document.getElementById("mensaje").value.length == 0)
		{
			window.alert("Por favor, ingrese su mensaje.");
			document.getElementById("mensaje").focus();
			return;
		}
	
	document.form_contacto.submit();
	//window.alert("ok");
}

/*******************************************************/
/*  Funcion que crea el Objeto XMLHTTP para implementar AJAX
/*
/*******************************************************/
function creaAjax(){
  var objetoAjax=false;
  try {
   /*Para navegadores distintos a internet explorer*/
   objetoAjax = new ActiveXObject("Msxml2.XMLHTTP");
  } catch (e) {
   try {
     /*Para explorer*/
     objetoAjax = new ActiveXObject("Microsoft.XMLHTTP");
     } 
     catch (E) {
     objetoAjax = false;
   }
  }

  if (!objetoAjax && typeof XMLHttpRequest!='undefined') {
   objetoAjax = new XMLHttpRequest();
  }
  return objetoAjax;
}

//VALIDAR FORMULARIO INSCRIPCION
function validar_form_inscripcion(){
	if(document.getElementById("nombre").value.length == 0)
		{
			window.alert("Por favor, ingrese su Nombre");
			document.getElementById("nombre").focus();
			return;
		}
	
	if(document.getElementById("apellido").value.length == 0)
		{
			window.alert("Por favor, ingrese su Apellido");
			document.getElementById("apellido").focus();
			return;
		}
		
	if(document.getElementById("doc").value.length == 0)
		{
			window.alert("Por favor, ingrese su Número de Documento");
			document.getElementById("doc").focus();
			return;
		}
	
	var doc = parseInt(document.getElementById("doc").value);
	if(isNaN(doc) || doc != document.getElementById("doc").value || doc < 0)
	{
		window.alert("Ingrese un Número de Documento correcto.");
		document.getElementById("doc").focus();
		return;
	}
	
	if(document.getElementById("nacionalidad").value.length == 0)
	{
		window.alert("Por favor, ingrese su Nacionalidad.");
		document.getElementById("nacionalidad").focus();
		return;
	}
	
	var dia_nac = parseInt(document.getElementById("dia_nacimiento").value);
	var mes_nac = parseInt(document.getElementById("mes_nacimiento").value);
	var anio_nac = parseInt(document.getElementById("anio_nacimiento").value);
	
	if(dia_nac < 0 || dia_nac > 31 || mes_nac < 0 || mes_nac > 12 || anio_nac < 1900 || anio_nac > 9999 || isNaN(dia_nac) || isNaN(mes_nac) || isNaN(anio_nac)){
		window.alert("Por favor, reingrese su Fecha de Nacimiento segun el formato día-mes-año.");
		document.getElementById("dia_nacimiento").focus();
		return;
	}
	else
	{
		var fecha = anio_nac + "-" + mes_nac + "-" + dia_nac;
		document.getElementById("fecha_nacimiento").value = fecha;
	}
		
	if(document.getElementById("lugar_nacimiento").value.length == 0)
	{
		window.alert("Por favor, ingrese la Ciudad o Localidad donde nació.");
		document.getElementById("lugar_nacimiento").focus();
		return;
	}
	
	if(document.getElementById("direccion").value.length == 0)
	{
		window.alert("Por favor, ingrese su domicilio (Calle, Nro, Piso, Dto).");
		document.getElementById("direccion").focus();
		return;
	}
	
	if(document.getElementById("localidad").value.length == 0)
	{
		window.alert("Por favor, ingrese su Localidad de residencia.");
		document.getElementById("localidad").focus();
		return;
	}
		
	if(document.getElementById("codigo_postal").value.length == 0)
	{
		window.alert("Por favor, ingrese el Código Postal de su domicilio.");
		document.getElementById("codigo_postal").focus();
		return;
	}
	
	if(document.getElementById("provincia").value.length == 0)
	{
		window.alert("Por favor, ingrese su Provincia de residencia.");
		document.getElementById("provincia").focus();
		return;
	}
	
	if(document.getElementById("pais").value.length == 0)
	{
		window.alert("Por favor, ingrese su País de residencia.");
		document.getElementById("pais").focus();
		return;
	}
	
	if(document.getElementById("email").value.length != 0 )
	if(!validarEmail(document.getElementById("email").value))
	{
		window.alert("Por favor, ingrese una dirección de e-mail correcta.");
		document.getElementById("email").focus();
		return;	
	}
	
	if(hayCurso)
	{
		if(document.getElementById("clave_curso").value.length == 0)
		{
			window.alert("Por favor, ingrese la Clave del Curso que le fue provista por el instituto.");
			document.getElementById("clave_curso").focus();
			return;
		}
		
		
	}
	
	document.form_inscripcion.submit();
}

//VALIDAR FORMULARIO LOGIN
function validar_form_login(){
	if(document.getElementById("usuario").value.length == 0)
	{
		window.alert("Por favor, ingrese su Nombre de Usuario.");
		document.getElementById("usuario").focus();
		return;
	}
	
	if(document.getElementById("clave").value.length == 0)
	{
		window.alert("Por favor, ingrese su Contraseña.");
		document.getElementById("clave").focus();
		return;
	}
	
	document.form_login.submit();
}

//REDIRECCION A LA PAGINA PRINCIPAL
function redir_inicio(){
	document.location.href = 'index.php';
}


//SECCION ALEJANDRO
function changeDisplay(objectId)
{
	if(document.getElementById(objectId).style.display == "none")
		document.getElementById(objectId).style.display = "block";
	else
		document.getElementById(objectId).style.display = "none";
}

function changeDisabledStatus(checkboxObjectId, objectId)
{
	if(document.getElementById(checkboxObjectId).checked == true)
		document.getElementById(objectId).disabled = false;
	else
		document.getElementById(objectId).disabled = true;
}

function setDisabledStatus(disabled, objectId)
{
	if(disabled == true)
		document.getElementById(objectId).disabled = true;
	else
	{
		document.getElementById(objectId).value = "";
		document.getElementById(objectId).disabled = false;
	}
}

//VALIDA FORMULARIOS DE ACTUALIZACION DE PROFESOR EXISTENTE
function validarFormModificarProfesor()
{
	if(document.getElementById("nombre").value.length == 0)
	{
		window.alert("Por favor, ingrese los nombres.");
		document.getElementById("nombre").focus();
		return;
	}
	if(document.getElementById("apellido").value.length == 0)
	{
		window.alert("Por favor, ingrese los apellidos.");
		document.getElementById("apellido").focus();
		return;
	}
	if(document.getElementById("nro_documento").value.length == 0)
	{
		window.alert("Por favor, ingrese el número de documento.");
		document.getElementById("nro_documento").focus();
		return;
	}
	if(!isInteger(document.getElementById("nro_documento").value))
	{
		window.alert("Por favor, ingrese sólo números en el campo número de documento.");
		document.getElementById("nro_documento").focus();
		return;
	}
	if(document.getElementById("nro_documento").value <= 0)
	{
		window.alert("Por favor, ingrese un número de documento válido.");
		document.getElementById("nro_documento").focus();
		return;
	}
	
	//razones para no usar parseInt: devuelve NaN si no es un numero y eso está bien
	//pero si el numero tiene '.' devuelve la parte entera
	var dia = document.getElementById("dia_nacimiento").value;
	var mes = document.getElementById("mes_nacimiento").value;
	var anio = document.getElementById("anio_nacimiento").value;

	if (!isInteger(dia) || !isInteger(mes) || !isInteger(anio) || 
		dia < 1 || dia > 31 || mes < 1 || mes > 12 || anio < 1900 || anio > 9999)
	{
		window.alert("Por favor, reingrese su fecha de nacimiento según el formato día-mes-año.");
		document.getElementById("dia_nacimiento").focus();
		return;
	}
	else
	{
		var fecha = anio + "-" + mes + "-" + dia;
		document.getElementById("fecha_nacimiento").value = fecha;
	}
	
	if(document.getElementById("lugar_nacimiento").value.length == 0)
	{
		window.alert("Por favor, ingrese la ciudad de nacimiento.");
		document.getElementById("lugar_nacimiento").focus();
		return;
	}
	if(document.getElementById("nacionalidad").value.length == 0)
	{
		window.alert("Por favor, ingrese la nacionalidad.");
		document.getElementById("nacionalidad").focus();
		return;
	}
	if(document.getElementById("direccion").value.length == 0)
	{
		window.alert("Por favor, ingrese el domicilio.");
		document.getElementById("direccion").focus();
		return;
	}
	if(document.getElementById("localidad").value.length == 0)
	{
		window.alert("Por favor, ingrese la localidad.");
		document.getElementById("localidad").focus();
		return;
	}
	if(document.getElementById("codigo_postal").value.length == 0)
	{
		window.alert("Por favor, ingrese el código postal.");
		document.getElementById("codigo_postal").focus();
		return;
	}
	if(document.getElementById("provincia").value.length == 0)
	{
		window.alert("Por favor, ingrese la provincia.");
		document.getElementById("provincia").focus();
		return;
	}//0800-ALE vale por lo tanto no voy a validar teléfonos 
	if(document.getElementById("email").value.length != 0)
	{
		if(validarEmail(document.getElementById("email").value) == false)
		{
			window.alert("Por favor, ingrese una dirección de e-mail correcta.");
			document.getElementById("email").focus();
			return;
		}
	}
	
	if(document.getElementById("foto").value != "")
	{
		if(document.getElementById("radio_foto_digital") != null)
		{	
			for (i = 0; i < document.form_nuevo_profesor.radio_foto_digital.length; i++)
			{
				if(document.form_nuevo_profesor.radio_foto_digital[i].checked)
					break;
			}
			if (document.form_nuevo_profesor.radio_foto_digital[i].value == "reemplazar")
			{
				var filenameArray = document.getElementById("foto").value.split(".");
				var extension = filenameArray[filenameArray.length - 1].toLowerCase();
		
				if(!extension.match("jpg|gif|png|bmp|tif"))
				{
					window.alert("El formato de archivo seleccionado no es válido.\nLos formatos válidos son 'JPG', 'GIF', 'PNG', 'BMP' y 'TIF'. Por favor seleccione otro archivo con estas características.");
					document.getElementById("foto").focus();
					return;
				}
			}
		}
		
		if(document.getElementById("chk_foto") != null)
		{
			if (document.getElementById("chk_foto").checked == true)
			{
				var filenameArray = document.getElementById("foto").value.split(".");
				var extension = filenameArray[filenameArray.length - 1].toLowerCase();
		
				if(!extension.match("jpg|gif|png|bmp|tif"))
				{
					window.alert("El formato de archivo seleccionado no es válido.\nLos formatos válidos son 'JPG', 'GIF', 'PNG', 'BMP' y 'TIF'. Por favor seleccione otro archivo con estas características.");
					document.getElementById("foto").focus();
					return;					
				}
			}
		}
	}
	else if(document.getElementById("foto").value == "")
	{
		if(document.getElementById("radio_foto_digital") != null)
		{	
			for (i = 0; i < document.form_nuevo_profesor.radio_foto_digital.length; i++)
			{
				if(document.form_nuevo_profesor.radio_foto_digital[i].checked)
					break;
			}
			if (document.form_nuevo_profesor.radio_foto_digital[i].value == "reemplazar")
			{
				window.alert("Debe seleccionar un archivo para reemplazar al documento existente. Sino elija otra opción.");
				document.getElementById("foto").focus();
				return;
			}
		}
	}

	document.form_nuevo_profesor.submit();
}

//VALIDA FORMULARIOS DE REGISTRACION DE NUEVO PROFESOR
function validarFormNuevoProfesor()
{
	if(document.getElementById("nombre").value.length == 0)
	{
		window.alert("Por favor, ingrese los nombres.");
		document.getElementById("nombre").focus();
		return;
	}
	if(document.getElementById("apellido").value.length == 0)
	{
		window.alert("Por favor, ingrese los apellidos.");
		document.getElementById("apellido").focus();
		return;
	}
	if(document.getElementById("nro_documento").value.length == 0)
	{
		window.alert("Por favor, ingrese el número de documento.");
		document.getElementById("nro_documento").focus();
		return;
	}
	if(!isInteger(document.getElementById("nro_documento").value))
	{
		window.alert("Por favor, ingrese sólo números en el campo número de documento.");
		document.getElementById("nro_documento").focus();
		return;
	}
	if(document.getElementById("nro_documento").value <= 0)
	{
		window.alert("Por favor, ingrese un número de documento válido.");
		document.getElementById("nro_documento").focus();
		return;
	}
	
	//razones para no usar parseInt: devuelve NaN si no es un numero y eso está bien
	//pero si el numero tiene '.' devuelve la parte entera
	var dia = document.getElementById("dia_nacimiento").value;
	var mes = document.getElementById("mes_nacimiento").value;
	var anio = document.getElementById("anio_nacimiento").value;

	if (!isInteger(dia) || !isInteger(mes) || !isInteger(anio) || 
		dia < 1 || dia > 31 || mes < 1 || mes > 12 || anio < 1900 || anio > 9999)
	{
		window.alert("Por favor, reingrese su fecha de nacimiento según el formato día-mes-año.");
		document.getElementById("dia_nacimiento").focus();
		return;
	}
	else
	{
		var fecha = anio + "-" + mes + "-" + dia;
		document.getElementById("fecha_nacimiento").value = fecha;
	}
	
	if(document.getElementById("lugar_nacimiento").value.length == 0)
	{
		window.alert("Por favor, ingrese la ciudad de nacimiento.");
		document.getElementById("lugar_nacimiento").focus();
		return;
	}
	if(document.getElementById("nacionalidad").value.length == 0)
	{
		window.alert("Por favor, ingrese la nacionalidad.");
		document.getElementById("nacionalidad").focus();
		return;
	}
	if(document.getElementById("direccion").value.length == 0)
	{
		window.alert("Por favor, ingrese el domicilio.");
		document.getElementById("direccion").focus();
		return;
	}
	if(document.getElementById("localidad").value.length == 0)
	{
		window.alert("Por favor, ingrese la localidad.");
		document.getElementById("localidad").focus();
		return;
	}
	if(document.getElementById("codigo_postal").value.length == 0)
	{
		window.alert("Por favor, ingrese el código postal.");
		document.getElementById("codigo_postal").focus();
		return;
	}
	if(document.getElementById("provincia").value.length == 0)
	{
		window.alert("Por favor, ingrese la provincia.");
		document.getElementById("provincia").focus();
		return;
	}//0800-ALE vale por lo tanto no voy a validar teléfonos 
	if(document.getElementById("email").value.length != 0)
	{
		if(validarEmail(document.getElementById("email").value) == false)
		{
			window.alert("Por favor, ingrese una dirección de e-mail correcta.");
			document.getElementById("email").focus();
			return;
		}
	}
	if (document.getElementById("chk_foto").checked == true && 
		document.getElementById("foto").value != "")
	{
		var filenameArray = document.getElementById("foto").value.split(".");
		var extension = filenameArray[filenameArray.length - 1].toLowerCase();

		if(!extension.match("jpg|gif|png|bmp|tif"))
		{
			window.alert("El formato de archivo seleccionado no es válido.\nPor favor seleccione otro archivo");
			document.getElementById("foto").focus();
			return;
		}
	}

	document.form_nuevo_profesor.submit();
}

//VALIDA FORMULARIOS DE ACTUALIZACION DE ALUMNO EXISTENTE
function validarFormModificarAlumno()
{
	if(document.getElementById("legajo").value.length == 0)
	{
		window.alert("Por favor, ingrese el número de legajo.");
		document.getElementById("legajo").focus();
		return;
	}
	if(document.getElementById("nombre").value.length == 0)
	{
		window.alert("Por favor, ingrese los nombres.");
		document.getElementById("nombre").focus();
		return;
	}
	if(document.getElementById("apellido").value.length == 0)
	{
		window.alert("Por favor, ingrese los apellidos.");
		document.getElementById("apellido").focus();
		return;
	}
	if(document.getElementById("nro_documento").value.length == 0)
	{
		window.alert("Por favor, ingrese el número de documento.");
		document.getElementById("nro_documento").focus();
		return;
	}
	if(!isInteger(document.getElementById("nro_documento").value))
	{
		window.alert("Por favor, ingrese sólo números en el campo número de documento.");
		document.getElementById("nro_documento").focus();
		return;
	}
	if(document.getElementById("nro_documento").value <= 0)
	{
		window.alert("Por favor, ingrese un número de documento válido.");
		document.getElementById("nro_documento").focus();
		return;
	}
	
	//razones para no usar parseInt: devuelve NaN si no es un numero y eso está bien
	//pero si el numero tiene '.' devuelve la parte entera
	var dia = document.getElementById("dia_nacimiento").value;
	var mes = document.getElementById("mes_nacimiento").value;
	var anio = document.getElementById("anio_nacimiento").value;

	if (!isInteger(dia) || !isInteger(mes) || !isInteger(anio) || 
		dia < 1 || dia > 31 || mes < 1 || mes > 12 || anio < 1900 || anio > 9999)
	{
		window.alert("Por favor, reingrese su fecha de nacimiento según el formato día-mes-año.");
		document.getElementById("dia_nacimiento").focus();
		return;
	}
	else
	{
		var fecha = anio + "-" + mes + "-" + dia;
		document.getElementById("fecha_nacimiento").value = fecha;
	}
	
	if(document.getElementById("lugar_nacimiento").value.length == 0)
	{
		window.alert("Por favor, ingrese la ciudad de nacimiento.");
		document.getElementById("lugar_nacimiento").focus();
		return;
	}
	if(document.getElementById("nacionalidad").value.length == 0)
	{
		window.alert("Por favor, ingrese la nacionalidad.");
		document.getElementById("nacionalidad").focus();
		return;
	}
	if(document.getElementById("direccion").value.length == 0)
	{
		window.alert("Por favor, ingrese el domicilio.");
		document.getElementById("direccion").focus();
		return;
	}
	if(document.getElementById("localidad").value.length == 0)
	{
		window.alert("Por favor, ingrese la localidad.");
		document.getElementById("localidad").focus();
		return;
	}
	if(document.getElementById("codigo_postal").value.length == 0)
	{
		window.alert("Por favor, ingrese el código postal.");
		document.getElementById("codigo_postal").focus();
		return;
	}
	if(document.getElementById("provincia").value.length == 0)
	{
		window.alert("Por favor, ingrese la provincia.");
		document.getElementById("provincia").focus();
		return;
	}//0800-ALE vale por lo tanto no voy a validar teléfonos 
	if(document.getElementById("email").value.length != 0)
	{
		if(validarEmail(document.getElementById("email").value) == false)
		{
			window.alert("Por favor, ingrese una dirección de e-mail correcta.");
			document.getElementById("email").focus();
			return;
		}
	}
	
	if(document.getElementById("foto").value != "")
	{
		if(document.getElementById("radio_foto_digital") != null)
		{	
			for (i = 0; i < document.form_nuevo_alumno.radio_foto_digital.length; i++)
			{
				if(document.form_nuevo_alumno.radio_foto_digital[i].checked)
					break;
			}
			if (document.form_nuevo_alumno.radio_foto_digital[i].value == "reemplazar")
			{
				var filenameArray = document.getElementById("foto").value.split(".");
				var extension = filenameArray[filenameArray.length - 1].toLowerCase();
		
				if(!extension.match("jpg|gif|png|bmp|tif"))
				{
					window.alert("El formato de archivo seleccionado no es válido.\nLos formatos válidos son 'JPG', 'GIF', 'PNG', 'BMP' y 'TIF'. Por favor seleccione otro archivo con estas características.");
					document.getElementById("foto").focus();
					return;
				}
			}
		}
		
		if(document.getElementById("chk_foto") != null)
		{
			if (document.getElementById("chk_foto").checked == true)
			{
				var filenameArray = document.getElementById("foto").value.split(".");
				var extension = filenameArray[filenameArray.length - 1].toLowerCase();
		
				if(!extension.match("jpg|gif|png|bmp|tif"))
				{
					window.alert("El formato de archivo seleccionado no es válido.\nLos formatos válidos son 'JPG', 'GIF', 'PNG', 'BMP' y 'TIF'. Por favor seleccione otro archivo con estas características.");
					document.getElementById("foto").focus();
					return;					
				}
			}
		}
	}
	else if(document.getElementById("foto").value == "")
	{
		if(document.getElementById("radio_foto_digital") != null)
		{	
			for (i = 0; i < document.form_nuevo_alumno.radio_foto_digital.length; i++)
			{
				if(document.form_nuevo_alumno.radio_foto_digital[i].checked)
					break;
			}
			if (document.form_nuevo_alumno.radio_foto_digital[i].value == "reemplazar")
			{
				window.alert("Debe seleccionar un archivo para reemplazar al documento existente. Sino elija otra opción.");
				document.getElementById("foto").focus();
				return;
			}
		}
	}

	document.form_nuevo_alumno.submit();
}

//VALIDA FORMULARIOS DE REGISTRACION DE NUEVO ALUMNO
function validarFormNuevoAlumno()
{
	if(document.getElementById("legajo").value.length == 0)
	{
		window.alert("Por favor, ingrese el número de legajo.");
		document.getElementById("legajo").focus();
		return;
	}
	if(document.getElementById("nombre").value.length == 0)
	{
		window.alert("Por favor, ingrese los nombres.");
		document.getElementById("nombre").focus();
		return;
	}
	if(document.getElementById("apellido").value.length == 0)
	{
		window.alert("Por favor, ingrese los apellidos.");
		document.getElementById("apellido").focus();
		return;
	}
	if(document.getElementById("nro_documento").value.length == 0)
	{
		window.alert("Por favor, ingrese el número de documento.");
		document.getElementById("nro_documento").focus();
		return;
	}
	if(!isInteger(document.getElementById("nro_documento").value))
	{
		window.alert("Por favor, ingrese sólo números en el campo número de documento.");
		document.getElementById("nro_documento").focus();
		return;
	}
	if(document.getElementById("nro_documento").value <= 0)
	{
		window.alert("Por favor, ingrese un número de documento válido.");
		document.getElementById("nro_documento").focus();
		return;
	}
	
	//razones para no usar parseInt: devuelve NaN si no es un numero y eso está bien
	//pero si el numero tiene '.' devuelve la parte entera
	var dia = document.getElementById("dia_nacimiento").value;
	var mes = document.getElementById("mes_nacimiento").value;
	var anio = document.getElementById("anio_nacimiento").value;

	if (!isInteger(dia) || !isInteger(mes) || !isInteger(anio) || 
		dia < 1 || dia > 31 || mes < 1 || mes > 12 || anio < 1900 || anio > 9999)
	{
		window.alert("Por favor, reingrese su fecha de nacimiento según el formato día-mes-año.");
		document.getElementById("dia_nacimiento").focus();
		return;
	}
	else
	{
		var fecha = anio + "-" + mes + "-" + dia;
		document.getElementById("fecha_nacimiento").value = fecha;
	}
	
	if(document.getElementById("lugar_nacimiento").value.length == 0)
	{
		window.alert("Por favor, ingrese la ciudad de nacimiento.");
		document.getElementById("lugar_nacimiento").focus();
		return;
	}
	if(document.getElementById("nacionalidad").value.length == 0)
	{
		window.alert("Por favor, ingrese la nacionalidad.");
		document.getElementById("nacionalidad").focus();
		return;
	}
	if(document.getElementById("direccion").value.length == 0)
	{
		window.alert("Por favor, ingrese el domicilio.");
		document.getElementById("direccion").focus();
		return;
	}
	if(document.getElementById("localidad").value.length == 0)
	{
		window.alert("Por favor, ingrese la localidad.");
		document.getElementById("localidad").focus();
		return;
	}
	if(document.getElementById("codigo_postal").value.length == 0)
	{
		window.alert("Por favor, ingrese el código postal.");
		document.getElementById("codigo_postal").focus();
		return;
	}
	if(document.getElementById("provincia").value.length == 0)
	{
		window.alert("Por favor, ingrese la provincia.");
		document.getElementById("provincia").focus();
		return;
	}//0800-ALE vale por lo tanto no voy a validar teléfonos 
	if(document.getElementById("email").value.length != 0)
	{
		if(validarEmail(document.getElementById("email").value) == false)
		{
			window.alert("Por favor, ingrese una dirección de e-mail correcta.");
			document.getElementById("email").focus();
			return;
		}
	}
	if (document.getElementById("chk_foto").checked == true && 
		document.getElementById("foto").value != "")
	{
		var filenameArray = document.getElementById("foto").value.split(".");
		var extension = filenameArray[filenameArray.length - 1].toLowerCase();

		if(!extension.match("jpg|gif|png|bmp|tif"))
		{
			window.alert("El formato de archivo seleccionado no es válido.\nPor favor seleccione otro archivo");
			document.getElementById("foto").focus();
			return;
		}
	}

	document.form_nuevo_alumno.submit();
}

//VALIDA FORMULARIOS DE ACTUALIZACION DE LIBRO EXISTENTE
function validarFormModificarLibro()
{
	var allowSubmit = true;
	if(document.getElementById("topografia").value.length == 0)
	{
		allowSubmit = false;
		window.alert("Por favor, ingrese la topografía.");
		document.getElementById("topografia").focus();
	}
	else if(document.getElementById("titulo").value.length == 0)
	{
		allowSubmit = false;
		window.alert("Por favor, ingrese un título.");
		document.getElementById("titulo").focus();
	}
	else if(document.getElementById("autores").value.length == 0)
	{
		allowSubmit = false;
		window.alert("Por favor, ingrese el/los autores.");
		document.getElementById("autores").focus();
	}
	else if(document.getElementById("editorial").value.length == 0)
	{
		allowSubmit = false;
		window.alert("Por favor, ingrese una editorial.");
		document.getElementById("editorial").focus();
	}
	else if(!isInteger(document.getElementById("cantidad").value))
	{
		allowSubmit = false;
		window.alert("Por favor, ingrese sólo numeros en el campo cantidad.");
		document.getElementById("cantidad").focus();
	}
	else if(document.getElementById("cantidad").value < 0)
	{
		allowSubmit = false;
		window.alert("Por favor, ingrese una cantidad correcta.");
		document.getElementById("cantidad").focus();
	}
	else if(document.getElementById("tema").value.length == 0)
	{
		allowSubmit = false;
		window.alert("Por favor, ingrese un resumen de los temas del libro.");
		document.getElementById("tema").focus();
	}
	else if(document.getElementById("version_digital").value != "")
	{
		if(document.getElementById("radio_version_digital") != null)
		{	
			for (i = 0; i < document.form_nuevo_libro.radio_version_digital.length; i++)
			{
				if(document.form_nuevo_libro.radio_version_digital[i].checked)
					break;
			}
			if (document.form_nuevo_libro.radio_version_digital[i].value == "reemplazar")
			{
				var filenameArray = document.getElementById("version_digital").value.split(".");
				var extension = filenameArray[filenameArray.length - 1].toLowerCase();
		
				if(extension.match("exe|bat|com"))
				{
					allowSubmit = false;
					window.alert("El formato de archivo seleccionado no es permitido.\nPor favor seleccione otro archivo");
					document.getElementById("version_digital").focus();
				}
			}
		}
		
		if(document.getElementById("chk_version_digital") != null)
		{
			if (document.getElementById("chk_version_digital").checked == true)
			{
				var filenameArray = document.getElementById("version_digital").value.split(".");
				var extension = filenameArray[filenameArray.length - 1].toLowerCase();
		
				if(extension.match("exe|bat|com"))
				{
					allowSubmit = false;
					window.alert("El formato de archivo seleccionado no es permitido.\nPor favor seleccione otro archivo");
					document.getElementById("version_digital").focus();
				}
			}
		}
	}
	else if(document.getElementById("version_digital").value == "")
	{
		if(document.getElementById("radio_version_digital") != null)
		{	
			for (i = 0; i < document.form_nuevo_libro.radio_version_digital.length; i++)
			{
				if(document.form_nuevo_libro.radio_version_digital[i].checked)
					break;
			}
			if (document.form_nuevo_libro.radio_version_digital[i].value == "reemplazar")
			{
				allowSubmit = false;
				window.alert("Debe seleccionar un archivo para reemplazar al documento existente. Sino elija otra opción.");
				document.getElementById("version_digital").focus();
			}
		}
	
		/*if(document.getElementById("chk_version_digital") != null)
		{
			if(document.getElementById("chk_version_digital").checked == true)
				window.alert("Debe seleccionar un archivo sino desactive la opción elegida");
		}*/
	}

	if (allowSubmit == true)
		document.form_nuevo_libro.submit();
}

function validarFormNuevoLibro()
{
	var allowSubmit = true;

	if(document.getElementById("cantidad").value.length > 0)
		document.getElementById("cantidad").value = trim(document.getElementById("cantidad").value);
	
	if(document.getElementById("topografia").value.length == 0)
	{
		allowSubmit = false;
		window.alert("Por favor, ingrese la topografía.");
		document.getElementById("topografia").focus();
	}
	else if(document.getElementById("titulo").value.length == 0)
	{
		allowSubmit = false;
		window.alert("Por favor, ingrese un título.");
		document.getElementById("titulo").focus();
	}
	else if(document.getElementById("autores").value.length == 0)
	{
		allowSubmit = false;
		window.alert("Por favor, ingrese el/los autores.");
		document.getElementById("autores").focus();
	}
	else if(document.getElementById("editorial").value.length == 0)
	{
		allowSubmit = false;
		window.alert("Por favor, ingrese una editorial.");
		document.getElementById("editorial").focus();
	}
	else if(!isInteger(document.getElementById("cantidad").value))
	{
		allowSubmit = false;
		window.alert("Por favor, ingrese sólo números en el campo cantidad.");
		document.getElementById("cantidad").focus();
	}
	else if(document.getElementById("cantidad").value < 0)
	{
		allowSubmit = false;
		window.alert("Por favor, ingrese una cantidad correcta.");
		document.getElementById("cantidad").focus();
	}
	else if(document.getElementById("tema").value.length == 0)
	{
		allowSubmit = false;
		window.alert("Por favor, ingrese un resumen de los temas del libro.");
		document.getElementById("tema").focus();
	}
	else if(document.getElementById("chk_version_digital").checked == true &&
			document.getElementById("version_digital").value != "")
	{
		var filenameArray = document.getElementById("version_digital").value.split(".");
		var extension = filenameArray[filenameArray.length - 1].toLowerCase();

		if(extension.match("exe|bat|com"))
		{
			allowSubmit = false;
			window.alert("El formato de archivo seleccionado no es permitido.\nPor favor seleccione otro archivo");
			document.getElementById("version_digital").focus();
		}
	}
	
	if (allowSubmit == true)
		document.form_nuevo_libro.submit();
}

//summary: Verifica que 'value' sea un entero.
//note: A diferencia de parseInt no devuelve la parte entera si 'value' es un número no entero
//params: 'value' debe ser un String
//return: true si es un entero, sino false
function isInteger(value)
{
	if(isNaN(value))
		return false;
	if(value.indexOf(".") != -1)
		return false;
	return true;
}

function trim(string)
{
	return string.replace(/^\s*|\s*$/g,"");
}

function confirmarForm(pregunta, formName)
{
	if(window.confirm(pregunta))
	{
		document.getElementById(formName).submit();
		//document.location.href=direccion;
	}
}

function hola()
{
	window.alert("hola!");
}

function dibujarFormulario(object)
{
	window.alert("dibujarFormulario INICIO");
	if(object != null)
	{
		for (i = 0; i < object.length; i++)
		{
			document.write("<tr><td><label>" + object[i][0] + ":&nbsp;</label></td>");
			document.write("<td><input type=\"text\" id=\"" + object[i][1] + "\" name=\"" + object[i][1] +
						"\" size=\"" + object[i][2] + "\" maxlength=\"" + object[i][3] + "\"></td></tr><br />");
		}
	}
	window.alert("dibujarFormulario FIN");
}
//FIN SECCION ALEJANDRO
//
function validar_form_cambio_datos(){
	if(document.getElementById("nombre").value.length == 0)
	{
		window.alert("Por favor, ingrese su nombre.");
		document.getElementById("nombre").focus();
		return;
	}
	if(document.getElementById("apellido").value.length == 0)
	{
		window.alert("Por favor, ingrese su apellido.");
		document.getElementById("apellido").focus();
		return;
	}
	if(document.getElementById("fecha_nacimiento").value.length == 0)
	{
		window.alert("Por favor, ingrese su fecha de nacimiento.");
		document.getElementById("fecha_nacimiento").focus();
		return;
	}
	if(document.getElementById("lugar_nacimiento").value.length == 0)
	{
		window.alert("Por favor, ingrese su lugar de nacimiento.");
		document.getElementById("lugar_nacimiento").focus();
		return;
	}
	if(document.getElementById("nacionalidad").value.length == 0)
	{
		window.alert("Por favor, ingrese su nacionalidad.");
		document.getElementById("nacionalidad").focus();
		return;
	}
	if(document.getElementById("direccion").value.length == 0)
	{
		window.alert("Por favor, ingrese su direccion.");
		document.getElementById("direccion").focus();
		return;
	}
	if(document.getElementById("codigo_postal").value.length == 0)
	{
		window.alert("Por favor, ingrese su codigo postal.");
		document.getElementById("codigo_postal").focus();
		return;
	}
	if(document.getElementById("localidad").value.length == 0)
	{
		window.alert("Por favor, ingrese su localidad de residencia.");
		document.getElementById("localidad").focus();
		return;
	}
	if(document.getElementById("provincia").value.length == 0)
	{
		window.alert("Por favor, ingrese su provincia.");
		document.getElementById("provincia").focus();
		return;
	}
	if(document.getElementById("pais").value.length == 0)
	{
		window.alert("Por favor, ingrese su pais de residencia.");
		document.getElementById("pais").focus();
		return;
	}
	
	if(document.getElementById("mensaje").value.length == 0)
	{
		window.alert("Por favor, ingrese los motivos de los cambios solicitados.");
		document.getElementById("mensaje").focus();
		return;
	}
	
	document.form_cambio_datos.submit();
}

//VAlida formulario de cambio de clave
function validar_form_cambio_clave(){
	if(document.getElementById("clave_actual").value.length == 0)
	{
		window.alert("Por favor, ingrese su clave actual.");
		document.getElementById("clave_actual").focus();
		return;
	}
	if(document.getElementById("clave_nueva1").value.length == 0)
	{
		window.alert("Por favor, ingrese la nueva clave.");
		document.getElementById("clave_nueva1").focus();
		return;
	}
	if(document.getElementById("clave_nueva2").value.length == 0)
	{
		window.alert("Por favor, ingrese nuevamente la clave nueva para confirmar.");
		document.getElementById("clave_nueva2").focus();
		return;
	}
	if(document.getElementById("clave_nueva1").value != document.getElementById("clave_nueva2").value)
	{
		window.alert("Las claves nuevas no coinciden, reingrese su Nueva Clave.");
		document.getElementById("clave_nueva2").value="";
		document.getElementById("clave_nueva1").value="";
		document.getElementById("clave_nueva1").focus();
		return;
	}
	document.form_cambio_clave.submit();
}

//VAlida formulario de envio de correo
function validar_form_envio_correo(){
	if(document.getElementById("asunto").value.length == 0)
	{
		window.alert("Por favor, escriba el Asunto del mensaje.");
		document.getElementById("asunto").focus();
		return;
	}
	if(document.getElementById("cuerpo").value.length == 0)
	{
		window.alert("Por favor, ingrese el cuerpo del mensaje.");
		document.getElementById("cuerpo").focus();
		return;
	}
	if(document.getElementById("destino").value == -1)
	{
		window.alert("Seleccione un destinatario para el mensaje.");
		document.getElementById("destino").focus();
		return;
	}
	
	document.form_envio_correo.submit();
}

function setSelect(id_select, value){
	for(i=0; i<document.getElementById(id_select).length; i++){
		if(document.getElementById(id_select).options[i].value == value)
			index = document.getElementById(id_select).options[i].index;
	}
	document.getElementById(id_select).options[index].selected = true;
}

function validar_form_responder_tema(){
	if(document.getElementById("titulo").value.length == 0)
	{
		window.alert("Por favor, ingrese el titulo de su comentario.");
		document.getElementById("titulo").focus();
		return;
	}
	
	if(document.getElementById("cuerpo").value.length == 0)
	{
		window.alert("Por favor, ingrese el mensaje que desea agregar al tema.");
		document.getElementById("cuerpo").focus();
		return;
	}
	
	document.form_responder_tema.submit();
}

function validar_form_enviar_tp(){
	if(document.getElementById("archivo").value.length == 0)
	{
		window.alert("Por favor, presione Examinar y seleccione el archivo del Trabajo Práctico que desea enviar.");
		document.getElementById("archivo").focus();
		return;
	}
	document.form_enviar_tp.submit();
}

function validar_form_new_apunte(){
	if(document.getElementById("descripcion").value.length == 0)
	{
		window.alert("Por favor, ingrese una breve descripción del apunte.");
		document.getElementById("descripcion").focus();
		return;
	}
	
	if(document.getElementById("archivo").value.length == 0)
	{
		window.alert("Por favor, presione Examinar y seleccione el archivo del apunte que desea publicar.");
		document.getElementById("archivo").focus();
		return;
	}
	document.form_new_apunte.submit();
}

function validar_form_new_multimedia(){
	if(document.getElementById("descripcion").value.length == 0)
	{
		window.alert("Por favor, ingrese una breve descripción del apunte.");
		document.getElementById("descripcion").focus();
		return;
	}
	
	if(document.getElementById("archivo").value.length == 0)
	{
		window.alert("Por favor, presione Examinar y seleccione el archivo del apunte que desea publicar.");
		document.getElementById("archivo").focus();
		return;
	}
	document.form_new_multimedia.submit();
}

function validar_form_new_consigna(){
	if(document.getElementById("nombre").value.length == 0)
	{
		window.alert("Por favor, ingrese un Nombre para el nuevo Trabajo Práctico.");
		document.getElementById("nombre").focus();
		return;
	}
	
	var dia = parseInt(document.getElementById("dia").value);
	var mes = parseInt(document.getElementById("mes").value);
	var anio = parseInt(document.getElementById("anio").value);
	
	if(dia < 0 || dia > 31 || mes < 0 || mes > 12 || anio < 1900 || anio > 9999 || isNaN(dia) || isNaN(mes) || isNaN(anio)){
		window.alert("Por favor, reingrese la Fecha de Entrega segun el formato día-mes-año.");
		document.getElementById("dia").focus();
		return;
	}
	else
	{
		var fecha = anio + "-" + mes + "-" + dia;
		document.getElementById("fecha_entrega").value = fecha;
	}
	
	document.form_new_consigna.submit();
}

function validar_form_new_evento(){
	if(document.getElementById("id_comision").value == -1)
	{
		window.alert("Por favor, seleccione la Comisión a la que pertenece el evento.");
		document.getElementById("id_comision").focus();
		return;
	}
	if(document.getElementById("id_asignatura").value == -1)
	{
		window.alert("Por favor, seleccione la Asignatura a la que pertenece el evento.");
		document.getElementById("id_asignatura").focus();
		return;
	}
	if(document.getElementById("titulo").value.length == 0)
	{
		window.alert("Por favor, ingrese un Título para el nuevo evento.");
		document.getElementById("titulo").focus();
		return;
	}
	if(document.getElementById("dia").value == -1)
	{
		window.alert("Por favor, seleccione el Día del evento.");
		document.getElementById("dia").focus();
		return;
	}
	if(document.getElementById("mes").value == -1)
	{
		window.alert("Por favor, seleccione el Mes del evento.");
		document.getElementById("mes").focus();
		return;
	}
	if(document.getElementById("anio").value == -1)
	{
		window.alert("Por favor, seleccione el Año del evento.");
		document.getElementById("anio").focus();
		return;
	}
	document.getElementById("date").value = document.getElementById("anio").value + '-' + document.getElementById("mes").value + '-' + document.getElementById("dia").value;
	document.getElementById("time").value = document.getElementById("hora").value + ':' + document.getElementById("minutos").value + ':' + '00';
		
	//alert(document.getElementById("dia_hora").value);
	document.form_nuevo_evento.submit();
}

function actualizarSelectAsignatura(capa, id_comision, id_profesor){
	
	if(document.getElementById(capa))
	{
		var ajax=creaAjax();
		var claveCurso = "clave";
		var capaContenedora = document.getElementById(capa);
		ajax.open ('GET', 'select_asignaturas.php?id_comision='+id_comision+'&id_profesor='+id_profesor , true);
		ajax.onreadystatechange = function() {
			  if (ajax.readyState==1) {
					 capaContenedora.innerHTML="Cargando....";
			 }
			 else if (ajax.readyState==4){
				if(ajax.status==200)
				{
					 capaContenedora.innerHTML=ajax.responseText; 
				}
				else if(ajax.status==404)
					 {
	
						 capaContenedora.innerHTML = "La direccion no existe";
					 }
				 else
					 {
						 capaContenedora.innerHTML = "Error: ".ajax.status;
					 }
			}
		}
		ajax.send();
	}
}

//actualizarSelectDestino
function actualizarSelectDestino(capa, id_comision){
	
	var ajax=creaAjax();
	var claveCurso = "clave";
	var capaContenedora = document.getElementById(capa);
	ajax.open ('GET', 'select_destino.php?id_comision='+id_comision , true);
	ajax.onreadystatechange = function() {
		  if (ajax.readyState==1) {
                 capaContenedora.innerHTML="Cargando....";
         }
         else if (ajax.readyState==4){
            if(ajax.status==200)
            {
                 capaContenedora.innerHTML=ajax.responseText; 
            }
            else if(ajax.status==404)
                 {

                     capaContenedora.innerHTML = "La direccion no existe";
                 }
             else
                 {
                     capaContenedora.innerHTML = "Error: ".ajax.status;
                 }
        }
	}
	ajax.send();
}

function confirmar(pregunta, direccion){
	if(confirm(pregunta))
	{
		document.location.href=direccion;
	}
}

function validar_form_nueva_noticia(){
	if(document.getElementById("tipo").value == -1)
	{
		window.alert("Por favor, seleccione la sección en que desea publicar su noticia.");
		document.getElementById("tipo").focus();
		return;
	}
	if(document.getElementById("titulo").value.length == 0)
	{
		window.alert("Por favor, ingrese un título para la noticia.");
		document.getElementById("titulo").focus();
		return;
	}
	if(document.getElementById("cuerpo").value.length == 0)
	{
		window.alert("Por favor, ingrese un cuerpo para la noticia.");
		document.getElementById("cuerpo").focus();
		return;
	}
	if(document.getElementById("chk_foto").checked && document.getElementById("foto").value.length == 0)
	{
		window.alert("Por favor, seleccione una imagen para adjuntar a la noticia.");
		document.getElementById("foto").focus();
		return;
	}
	
	document.form_nueva_noticia.submit();
}

function validar_form_nueva_autoridad(){
	if(document.getElementById("nombre").value.length == 0)
	{
		window.alert("Por favor, ingrese el nombre de la nueva autoridad.");
		document.getElementById("nombre").focus();
		return;
	}
	if(document.getElementById("cargo").value.length == 0)
	{
		window.alert("Por favor, ingrese un título para el cargo de la nueva autoridad.");
		document.getElementById("cargo").focus();
		return;
	}
	
	if(document.getElementById("chk_cv").checked && document.getElementById("cv").value.length == 0)
	{
		window.alert("Por favor, seleccione un documento correspondiente al CV de la nueva autoridad (Formatos aceptados: .DOC / .PDF / .RTF) .");
		document.getElementById("cv").focus();
		return;
	}
	
	document.form_nueva_autoridad.submit();
}

function validar_form_nuevo_documento(){
	if(document.getElementById("titulo").value.length == 0)
	{
		window.alert("Por favor, ingrese el titulo del documento.");
		document.getElementById("titulo").focus();
		return;
	}
	if(document.getElementById("descripcion").value.length == 0)
	{
		window.alert("Por favor, ingrese una descripción del documento.");
		document.getElementById("descripcion").focus();
		return;
	}
	
	if(document.getElementById("archivo").value.length == 0)
	{
		window.alert("Por favor, seleccione un documento (Formatos aceptados: .DOC / .PDF / .RTF) .");
		document.getElementById("archivo").focus();
		return;
	}
	
	document.form_nuevo_documento.submit();
}

function validar_form_nueva_asignatura(){
	if(document.getElementById("nombre").value.length == 0)
	{
		window.alert("Por favor, ingrese un nombre para la asignatura.");
		document.getElementById("nombre").focus();
		return;
	}
	if(document.getElementById("codigo").value.length == 0)
	{
		window.alert("Por favor, ingrese un código para la asignatura.");
		document.getElementById("codigo").focus();
		return;
	}
	
	document.form_nueva_asignatura.submit();
}

function validar_form_nueva_especialidad(){
	if(document.getElementById("id_curso").value == -1)
	{
		window.alert("Por favor, seleccione el Tipo de Curso al que pertenece la nueva especialidad.");
		document.getElementById("id_curso").focus();
		return;
	}
	if(document.getElementById("nombre").value.length == 0)
	{
		window.alert("Por favor, ingrese un nombre para la especialidad.");
		document.getElementById("nombre").focus();
		return;
	}
	if(document.getElementById("codigo").value.length == 0)
	{
		window.alert("Por favor, ingrese un código para la especialidad.");
		document.getElementById("codigo").focus();
		return;
	}
	if(document.getElementById("archivo").value.length == 0)
	{
		window.alert("Por favor, seleccione el documento descriptivo de la especialidad.");
		document.getElementById("archivo").focus();
		return;
	}
	document.form_nueva_especialidad.submit();
}

function validar_form_nuevo_evento(){
	if(document.getElementById("tipo").value == -1)
	{
		window.alert("Por favor, seleccione el tipo de evento.");
		document.getElementById("tipo").focus();
		return;
	}
	if(document.getElementById("titulo").value.length == 0)
	{
		window.alert("Por favor, ingrese un Título para el nuevo evento.");
		document.getElementById("titulo").focus();
		return;
	}
	if(document.getElementById("dia").value == -1)
	{
		window.alert("Por favor, seleccione el Día del evento.");
		document.getElementById("dia").focus();
		return;
	}
	if(document.getElementById("mes").value == -1)
	{
		window.alert("Por favor, seleccione el Mes del evento.");
		document.getElementById("mes").focus();
		return;
	}
	if(document.getElementById("anio").value == -1)
	{
		window.alert("Por favor, seleccione el Año del evento.");
		document.getElementById("anio").focus();
		return;
	}
	document.getElementById("date").value = document.getElementById("anio").value + '-' + document.getElementById("mes").value + '-' + document.getElementById("dia").value;
	document.getElementById("time").value = document.getElementById("hora").value + ':' + document.getElementById("minutos").value + ':' + '00';
		
	//alert(document.getElementById("dia_hora").value);
	document.form_nuevo_evento.submit();
}

function actualizarSelectEspecialidad(capa, id_curso){
	if(document.getElementById(capa))
	{
		var ajax=creaAjax();
		var capaContenedora = document.getElementById(capa);
		ajax.open ('GET', 'select_especialidad_curso.php?id_curso='+id_curso, true);
		ajax.onreadystatechange = function() {
			  if (ajax.readyState==1) {
					 capaContenedora.innerHTML="Cargando....";
			 }
			 else if (ajax.readyState==4){
				if(ajax.status==200)
				{
					 capaContenedora.innerHTML=ajax.responseText; 
				}
				else if(ajax.status==404)
					 {
	
						 capaContenedora.innerHTML = "La direccion no existe";
					 }
				 else
					 {
						 capaContenedora.innerHTML = "Error: ".ajax.status;
					 }
			}
		}
		ajax.send();
	}
	
}

function validar_form_nueva_comision(){
	if(document.getElementById("id_curso").value == -1)
	{
		window.alert("Por favor, seleccione el Tipo de Curso de la comisión.");
		document.getElementById("id_curso").focus();
		return;
	}
	if(document.getElementById("id_especialidad").value == -1)
	{
		window.alert("Por favor, seleccione la Especialidad de la comisión.");
		document.getElementById("id_especialidad").focus();
		return;
	}
	if(document.getElementById("id_anio").value == -1)
	{
		window.alert("Por favor, seleccione el Año de la comisión.");
		document.getElementById("id_anio").focus();
		return;
	}
	if(document.getElementById("id_division").value == -1)
	{
		window.alert("Por favor, seleccione la división de la comisión.");
		document.getElementById("id_division").focus();
		return;
	}
	
	document.form_nueva_comision.submit();

}

function validar_form_nueva_planta(){
	if(document.getElementById("id_asignatura").value == -1)
	{
		window.alert("Por favor, seleccione una Asignatura.");
		document.getElementById("id_asignatura").focus();
		return;
	}
	if(document.getElementById("id_comision").value == -1)
	{
		window.alert("Por favor, seleccione una Comisión.");
		document.getElementById("id_comision").focus();
		return;
	}
	if(document.getElementById("id_persona").value == -1)
	{
		window.alert("Por favor, seleccione un profesor.");
		document.getElementById("id_persona").focus();
		return;
	}
	
	
	document.form_nueva_planta.submit();

}

function asignar_comision(id_alumno, id_comision){
	if(id_comision == -1)
	{
		alert("Seleccione la comisión que desea asignar a este alumno");
		return;
	}
	document.location.href="admin.php?pag=asignar_comision&id_alumno="+id_alumno+"&id_comision="+id_comision;	
}


function validar_form_asignacion_alumnos(){
	var form = document.forms[1];
	var cant_max = document.getElementById("cant_max").value;
	var cadena_ids = "";
	for(k=0; k < form.length; k++)
	{
		if(form.elements[k].checked == true)	
		{
			cadena_ids += form.elements[k].value + "-";	
			//alert(form.elements[k].value);
		}
	}
	document.getElementById("str_ids").value = cadena_ids + '0';
	if(document.getElementById("id_comision").value == -1)
	{
		alert("Seleccione la comisión en la que desea asignar los alumnos seleccionados.");	
		document.getElementById("id_comision").focus();
		return;
	}
	if(document.getElementById("str_ids").value == 0)
	{
		alert("Seleccione al menos un alumno para asignar.");	
		return;
	}
	//alert(document.getElementById("str_ids").value);
	form.submit();
}

function validar_form_nueva_inscripcion(){
	if(document.getElementById("id_curso").value == -1)
	{
		window.alert("Por favor, seleccione el Tipo de Curso.");
		document.getElementById("id_curso").focus();
		return;
	}
	if(document.getElementById("id_especialidad").value == -1)
	{
		window.alert("Por favor, seleccione la Especialidad del curso a abrir.");
		document.getElementById("id_especialidad").focus();
		return;
	}
	if(document.getElementById("email").value.length == 0)
	{
		window.alert("Por favor, ingrese un Email donde se notificarán las inscripciones.");
		document.getElementById("email").focus();
		return;
	}
	if(document.getElementById("vacantes").value.length == 0)
	{
		window.alert("Por favor, ingrese el número de vacantes disponibles para la inscripción.");
		document.getElementById("vacantes").focus();
		return;
	}
	var dia1 = document.getElementById("dia1").value;
	var mes1 = document.getElementById("mes1").value;
	var anio1 = document.getElementById("anio1").value;
	if(document.getElementById("dia1").value == -1)
	{
		window.alert("Por favor, seleccione el Día de Inicio.");
		document.getElementById("dia1").focus();
		return;
	}
	if(document.getElementById("mes1").value == -1)
	{
		window.alert("Por favor, seleccione el Mes de Inicio.");
		document.getElementById("mes1").focus();
		return;
	}
	if(document.getElementById("anio1").value == -1)
	{
		window.alert("Por favor, seleccione el Año de Inicio.");
		document.getElementById("anio1").focus();
		return;
	}

	var fecha_inicio = anio1 + "-" + mes1 + "-" + dia1;
	document.getElementById("fecha_inicio").value = fecha_inicio;
	
	
	var dia2 = document.getElementById("dia2").value;
	var mes2 = document.getElementById("mes2").value;
	var anio2 = document.getElementById("anio2").value;
	if(document.getElementById("dia2").value == -1)
	{
		window.alert("Por favor, seleccione el Día de Cierre.");
		document.getElementById("dia2").focus();
		return;
	}
	if(document.getElementById("mes2").value == -1)
	{
		window.alert("Por favor, seleccione el Mes de Cierre.");
		document.getElementById("mes2").focus();
		return;
	}
	if(document.getElementById("anio2").value == -1)
	{
		window.alert("Por favor, seleccione el Año de Cierre.");
		document.getElementById("anio2").focus();
		return;
	}
	var fecha_cierre = anio2 + "-" + mes2 + "-" + dia2;
	document.getElementById("fecha_cierre").value = fecha_cierre;
	
	document.form_nueva_inscripcion.submit();
}
