var MSG_BOX = "";
var LOGUEADO;

function msg(Mensaje) {
	try {
		MSG_BOX.innerHTML = Mensaje;
	} catch (e) {
		if (Mensaje) alert(Mensaje);
	}
}

function urlencode(str) {
    var result = "";
    for (i = 0; i < str.length; i++) {
        if (str.charAt(i) == " ") result += "+";
        else result += str.charAt(i);
    }
    return escape(result);
}


function urldecode(str) {    
    var result = str.replace(/\+/g, " ");
    return unescape(result);
}

function botonera_alinear() 
{
	botonera = document.getElementById('div_botonera');
	contenido = document.getElementById('content');
	
	var windowWidth;
	if (document.documentElement && document.documentElement.clientWidth) { // Explorer 6 Strict Mode
		windowWidth = document.documentElement.clientWidth;
	} else if (document.body) { // other Explorers
		windowWidth = document.body.clientWidth;
	}	
	
	if(botonera != null){
		if(document.body.offsetWidth/2 - 460 < 0) botonera.style.left = 35;
		else botonera.style.left = ((windowWidth - contenido.width)/2) + 15;
	}
	botonera_principal_alinear();
}

function botonera_principal_alinear()
{
	botonera = document.getElementById('div_botonera_principal');
	contenido = document.getElementById('content');
	
	var windowWidth;
	if (document.documentElement && document.documentElement.clientWidth) { // Explorer 6 Strict Mode
		windowWidth = document.documentElement.clientWidth;
	} else if (document.body) { // other Explorers
		windowWidth = document.body.clientWidth;
	}	
	
	if(document.body.offsetWidth/2 - 460 < 0) botonera.style.left = 0;
	else botonera.style.left = ((windowWidth - contenido.width)/2);	
}


function calcularAlto(){
	var tabla = document.getElementById('tablaContenedor');
	if (tabla.offsetHeight < 1800) {
		tabla.style.height = 1800;
	}
	
}

function botonera_alinear_init()
{
	window.onresize = botonera_alinear;
	botonera_alinear();
}


function window_open(pagina) {
	Win = new Window({className: "alphacube", minimizable: false, maximizable: false, resizable: false, destroyOnClose: true, showEffectOptions: {duration:null}})
	Win.setURL(RUTA+"estructura/"+pagina);
	tamano = Win.getSize();
	Win.setSize('676','314');         
	Win.set
    Win.showCenter("modal");
}

function cargarPagina(params, div, pagina){
	new Ajax.Updater(div, RUTA+"estructura/"+pagina+".php"+params);	
}

function buscarDocumento(formulario, pagina){
	var form = $(formulario);
	params = Form.serialize(formulario);
	if(pagina) {
		params = params+"&desde="+pagina;	
	}
	new Ajax.Updater('documentos', RUTA+"estructura/lista_documentos.php?"+params);
}

function buscarEvento(formulario, borrar){
	var form = $(formulario);
	params = Form.serialize(formulario);
	if(borrar) {
		params = 'estado=1';
		form.descripcion.value = '';
		var radios = document.getElementsByName('estado');
		radios[0].checked = true;
		form.tipo.options[0].selected= true;
	}

	new Ajax.Updater('resultadoEventos', RUTA+"estructura/lista_eventos.php?"+params);
	calcularAlto();
}

function mostrarRevistas(year){
	new Ajax.Updater('revistas', RUTA+"estructura/revistas.php?year="+year);
}

function ocultarCurso(curso) {
  fila = document.getElementById('tabla').getElementsByTagName('tr');
  for(i=0;i<fila.length;i++){
  	if(fila[i].id == curso){
		fila[i].style.display = 'none';
	}
  }
}

function mostrarCurso(curso,color) {
  fila = document.getElementById('tabla').getElementsByTagName('tr');
  for(i=0;i<fila.length;i++){
  	if(fila[i].id == curso){
		if(fila[i].style.display == ''){
			fila[i].style.display = 'none';
			img = document.getElementById('img_'+curso);
			img.src=RUTA+'_img/botones/ampliar_informacion_'+color+'.jpg';
		}
		else{
			fila[i].style.display = '';
			img = document.getElementById('img_'+curso);
			img.src=RUTA+'_img/botones/ocultar_informacion_'+color+'.jpg';
		}
	}
	else{
		var id = fila[i].id;
		if(id != '') {
			fila[i].style.display = 'none';
			img = document.getElementById('img_'+id);
			img.src=RUTA+'_img/botones/ampliar_informacion_'+color+'.jpg';
		}
	}
  }
}

function mostrar(tr) {
  fila = document.getElementById('tablaEventos').getElementsByTagName('tr');
  var spanNombre = 'ampliar_'+tr;
  var span = document.getElementById(spanNombre);
  for(i=0;i<fila.length;i++){
  	if(fila[i].id == tr){
		if (fila[i].style.display == 'none'){
			fila[i].style.display = '';
			span.innerHTML = 'minimizar';
		}
		else{
			fila[i].style.display = 'none';
			span.innerHTML = 'ampliar';
		}
		
	}
  }
}

function mostrarTabla(tabla, color) {
  	var filas = document.getElementById('tabla_'+tabla).getElementsByTagName('tr');
	if(color != '') var img = document.getElementById('img_'+tabla);
	for(i=0;i<filas.length;i++){
		if(filas[i].id == tabla){
			if (filas[i].style.display == 'none'){
				filas[i].style.display = '';
				if(color != '') img.src = RUTA+'_img/botones/ocultar_informacion_'+color+'.jpg';
			}
			else{
				filas[i].style.display = 'none';
				if(color != '') img.src = RUTA+'_img/botones/ampliar_informacion_'+color+'.jpg';
			}
		}
  }
}

var type = "";
var file = "";

function descargarArchivo(type, archivo){
	if(type){
		type = type;
		file = archivo;
	}
	
	if(!LOGUEADO){
		window_open_login('descargar');
	}
	else{
		url = '../_php/download.php?type='+type+'&archivo='+file;
		window.location.href = url;
	}
}

var tipo_inscripcion;
var titulo;

function inscribirse(tipo, nombre){
	
	if(tipo){
		tipo_inscripcion = tipo;
		titulo = nombre;
	}
	
	if(!LOGUEADO){
		window_open_login('inscripcion');
	}
	else{
		window_open_inscripcion(tipo_inscripcion, titulo);
	}	
}

function sacarImg(ele){
	ele.style.background = "";
}

function setBg(ele){
	if(ele.value==''){
		ele.style.background = "url('../../img/ingrese-busqueda.gif') no-repeat";
	}
	else{
		ele.style.background = "";	
	}
}


function mostrar_banner(){
//	var left = (getWindowWidth()/2) - 275;
//	var top = (getWindowHeight()/2) - 175;
	var my_win = window.open('../estructura/tpl_folleto.html',null,'scrollbars=0,width=600,height=670');
	my_win.moveTo(window.screen.availWidth/2-300, window.screen.availHeight/2-335);
}
