// JavaScript Document
function display_date(clase) {

   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_month + ' de ' + month + ' de ' + year; 
   document.write('<span>' + date_to_show + '</span>');
} 

function changeDisplay(objectId)
{
	if(document.getElementById(objectId).style.display == "none")
		document.getElementById(objectId).style.display = "block";
	else
		document.getElementById(objectId).style.display = "none";
}


function validar_form_new_section(){
	if(document.getElementById("button_text").value == "")
	{
		alert("Por favor complete todos los campos obligatorios");
		document.getElementById("button_text").focus();
		return;
	}
	
	submitForm();
	document.form_new_section.submit();
}

function validar_form_text_section(){
	if(document.getElementById("button_text").value == "")
	{
		alert("Por favor complete todos los campos obligatorios");
		document.getElementById("button_text").focus();
		return;
	}
	
	if(document.getElementById("orden").value == "")
	{
		alert("Por favor complete todos los campos obligatorios");
		document.getElementById("orden").focus();
		return;
	}
	submitForm();
	document.form_text_section.submit();
}

function validar_form_download_section(){
	if(document.getElementById("button_text").value == "")
	{
		alert("Por favor complete todos los campos obligatorios");
		document.getElementById("button_text").focus();
		return;
	}
	
	if(document.getElementById("orden").value == "")
	{
		alert("Por favor complete todos los campos obligatorios");
		document.getElementById("orden").focus();
		return;
	}
	submitForm();
	document.form_download_section.submit();
}

function validar_form_edit_download_section(){
	if(document.getElementById("button_text").value == "")
	{
		alert("Por favor complete todos los campos obligatorios");
		document.getElementById("button_text").focus();
		return;
	}
	
	if(document.getElementById("orden").value == "")
	{
		alert("Por favor complete todos los campos obligatorios");
		document.getElementById("orden").focus();
		return;
	}
	submitForm();
	document.form_edit_download_section.submit();
}

function validar_form_text_images_section(){
	if(document.getElementById("button_text").value == "")
	{
		alert("Por favor complete todos los campos obligatorios");
		document.getElementById("button_text").focus();
		return;
	}
	
	if(document.getElementById("file1").value == "")
	{
		alert("Por favor seleccione un archivo de imagen.");
		document.getElementById("file1").focus();
		return;
	}
		
	submitForm();
	document.form_text_images_section.submit();
}

function validar_form_new_image(){
	if(document.getElementById("file1").value == "")
	{
		alert("Por favor seleccione un archivo.");
		document.getElementById("file1").focus();
		return;
	}
	
	document.form_new_image.submit();
}

function validar_form_new_file(){
	
	if(document.getElementById("file1") && document.getElementById("file1").value == "")
	{
		alert("Por favor seleccione un archivo.");
		document.getElementById("file1").focus();
		return;
	}
	
	if(document.getElementById("name").value == "")
	{
		alert("Por favor ingrese un nombre para el documento.");
		document.getElementById("name").focus();
		return;
	}
	
	document.form_new_file.submit();
}

function validar_form_new_gallery_file(){
	if(document.getElementById("file1") && document.getElementById("file1").value == "")
	{
		alert("Por favor seleccione un archivo de imagen.");
		document.getElementById("file1").focus();
		return;
	}
	
	document.form_new_file.submit();
}


function validar_form_edit_section(){
	if(document.getElementById("button_text").value == "")
	{
		alert("Por favor complete todos los campos obligatorios");
		document.getElementById("button_text").focus();
		return;
	}
	
	submitForm();
	document.form_edit_section.submit();
}

function confirmar(pregunta, direccion){
	if(confirm(pregunta))
	{
		document.location.href=direccion;
	}
}

function redir_admin_index(){
	document.location.href = 'index.php?sec=sections';
}

function none(){}

function redir_admin_section(sec){
	if(sec == "index")
		document.location.href = 'index.php';
	else
	{
		//window.alert("Hola");
		document.location.href = 'index.php?sec='+sec;
	}
}
function submitForm() {
			//make sure hidden and iframe values are in sync for all rtes before submitting form
	updateRTEs();

	return true;
}

function validar_form_new_pedido(){
	if(document.getElementById("number").value == "")
	{
		alert("Por favor complete todos los campos obligatorios");
		document.getElementById("number").focus();
		return;
	}
	
	if(document.getElementById("description").value == "")
	{
		alert("Por favor complete todos los campos obligatorios");
		document.getElementById("description").focus();
		return;
	}
	
	document.getElementById("fecha").value = document.getElementById("anio").value + "-" + document.getElementById("mes").value + "-" + document.getElementById("dia").value;
	
	document.form_new_pedido.submit();
}

function validar_form_nueva_noticia(){
	if(document.getElementById("tipo").value == 0)
	{
		window.alert("Por favor, seleccione el tipo de noticia a publicar.");
		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("copete").value.length == 0)
	{
		window.alert("Por favor, ingrese un copete para la noticia.");
		document.getElementById("copete").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;
	}
	submitForm();
	document.form_nueva_noticia.submit();
}

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;
	}
}
function validar_form_editar_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.");
		document.getElementById("titulo").focus();
		return;
	}
	/*
	if(document.getElementById("foto"))
	if(document.getElementById("foto").value.length == 0)
	{
		window.alert("Por favor, seleccione una imagen para adjuntar.");
		document.getElementById("foto").focus();
		return;
	}*/
	submitForm();
	document.form_nueva_noticia.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);
	submitForm();
	document.form_nuevo_evento.submit();
}