var MSG_BOX = "";
var LOGUEADO;
var InitFuncArray = new Array();

// Efecto de visibilidad del video de la home.
var video_home_visible = false;
function video_home_visibilidad()
{
	if (video_home_visible) {
		video_home_visible = false;
		Effect.SlideUp('toggle_swf', { duration: 1.5 });
		setTimeout(function() {
			document.getElementById('toggle_swf').innerHTML = '&nbsp;';
		}, 1500);
	} else {
		video_home_visible = true;
		var enlace_inferior = '<div align="right" style="margin-top:5px"><table border="0" cellpadding="0" cellspacing="0"><tr><td class="botones_izq"></td><td class="botones_centro"><span class="botones_texto_general"><a href="http://www.um.edu.uy/universidad/noticias/508_Adelanta-el-2010-en-el-segundo-semestre/#imagenes">Adelant&aacute; el 2010</a></span></td><td class="botones_der"></td></tr></table>';
		document.getElementById('toggle_swf').innerHTML = '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,28,0" width="560" height="335"><param name="movie" value="../swf/video_home.swf" /><param name="quality" value="high" /><param name="wmode" value="transparent" /><embed src="../swf/video_home.swf" width="560" height="335" loop="true" quality="high" pluginspage="http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash" type="application/x-shockwave-flash" wmode="transparent"></embed></object>'+enlace_inferior;
		setTimeout(function() {
			Effect.SlideDown('toggle_swf', { duration: 1.5 });
		}, 200);
	}
	//video_home_visible = !video_home_visible;
}

function hidestatus()
{
	window.status = 'Universidad de Montevideo';
	return true;
}

if (document.layers) {
	document.captureEvents(Event.MOUSEOVER | Event.MOUSEOUT)
}
document.onmouseover = hidestatus;
document.onmouseout = hidestatus;

function msg(Mensaje) {
	if (MSG_BOX) {
		try {
			MSG_BOX.innerHTML = Mensaje;
		} catch (e) {
			if (Mensaje) alert(Mensaje);
		}
	} else 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 isEmail(elemento)
{
	var valor = elemento.value;
	var filtro = /^[A-Za-z][A-Za-z0-9_.-]*@[A-Za-z0-9_]+\.[A-Za-z0-9_.-]+[A-za-z]$/;
	if (filtro.test(valor))
		return true;
	else
		return false;
}

// Funciones que se llaman al terminar de cargar la pagina
function onLoadInit()
{
	for (var i = 0; i < InitFuncArray.length; i++)
	{
		eval(InitFuncArray[i]).call();
	}
	try {
		botonera_alinear();
	} catch (e) {}
}
function addInitFunc(func)
{
	InitFuncArray.push(func);
}

function botonera_alinear() 
{
	botonera = document.getElementById('div_botonera');
	contenido = document.getElementById('content');
	
	var windowWidth; var minWidth;
	if (document.documentElement && document.documentElement.clientWidth) { // other Explorers
		windowWidth = document.documentElement.clientWidth;
		minWidth = 112;
	} else if (document.body) { // Explorer 6 Strict Mode
		windowWidth = document.body.clientWidth - 35;
		minWidth = 97;
	}	
	
	var windowHeight;
	if (document.documentElement && document.documentElement.scrollTop) {
		windowHeight = document.documentElement.scrollTop;
	} else {
		windowHeight = document.body.scrollTop
	}
	
	if(botonera != null){
		botonera.style.left = Math.max(minWidth,(windowWidth/2) - 387);
	}
	calcularAlto();
	//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) + 100;
	}	
}


function botonera_multimedia_alinear()
{
	botonera = document.getElementById('submenu');
	
	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 = 500;
	} else {
		botonera.style.left = ((windowWidth - 1024)/2) + 500;
	}	
}

function botonera_multimedia_alinear_init(){
	window.onresize = botonera_multimedia_alinear;
	botonera_multimedia_alinear();
}

function show_submenu(){
	$('submenu').style.display = '';
	$('a_multimedia').className = 'menu_on';
}

function hide_submenu(){
	$('submenu').style.display = 'none';
	$('a_multimedia').className = 'menu';
}

function calcularAlto()
{
	var tabla = document.getElementById('content');
	var botonera = document.getElementById('div_botonera');
	
	var a = botonera.style.top;
	a = a.substring(0,a.length-2);
	
	var fin_botonera = Number(a) + botonera.offsetHeight;

	if (tabla.offsetHeight < fin_botonera) {
		tabla.style.height = fin_botonera -100;
	}
}

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");
}

// LANG
function setLang(lang)
{
	var AJAX = new sack(RUTA+MODULO+"/ajax/idioma/"+lang+"/");
	AJAX.setVar("lang", lang);
	AJAX.onCompletion = function() 
	{
		var v_result = AJAX.response.split("|");
		var result = v_result[0];
		if (result > 0) {
			//window.location.reload(false);
			if (MODULO == 'universidad') {
				window.location.href = RUTA+"internacional/";
			} else {
				window.location.href = RUTA+MODULO+"/";
			}
		} else {
			msg("Función no disponible.");
		}
	}
	AJAX.runAJAX();
}


// UM

function show_div(div_str)
{
	document.getElementById(div_str).style.display = '';
	document.getElementById(div_str+"_img_0").style.display = '';
	document.getElementById(div_str+"_img_1").style.display = 'none';
	try {
		calcularAlto();
	} catch (e) {}
}
function hide_div(div_str)
{
	document.getElementById(div_str).style.display = 'none';
	document.getElementById(div_str+"_img_0").style.display = 'none';
	document.getElementById(div_str+"_img_1").style.display = '';
	try {
		calcularAlto();
	} catch (e) {}
}

function get_modulo()
{
	return document.URL.split("http://")[1].split("/")[2];
}

/*
function doSearch(comunicacion)
{
	if ($('q').value == 'Escriba aquí su búsqueda') $('q').value = '';
	if(comunicacion){
		document.getElementById('frm_busqueda').action = RUTA+MODULO+"/busqueda/"+urlencode(document.getElementById('q').value);
	}
	else{
		document.getElementById('frm_busqueda').action = RUTA+MODULO+"/busqueda/"+urlencode(document.getElementById('q').value);
	}
	document.frm_busqueda.submit();
}
*/
function doSearch(comunicacion)
{
	if ($('q').value == 'Escriba aquí su búsqueda') $('q').value = '';
	var buscar = $F('q');
	
	if (comunicacion) {
		document.getElementById('frm_busqueda').action = RUTA+MODULO+"/busqueda/"+urlencode(buscar);
	} else {
		document.getElementById('frm_busqueda').action = RUTA+MODULO+"/busqueda/"+urlencode(buscar);
	}
	document.frm_busqueda.submit();
}

function doSearchCarreras()
{
	document.getElementById('frm_carrera').action = RUTA+MODULO+"/carreras/";
	document.frm_carrera.submit();
}

function cargarUM(div, pagina, func_onComplete){
	new Ajax.Updater(div, RUTA+MODULO+"/"+pagina, {onComplete: func_onComplete});	
}

function investigacionesFiltrar(cmb)
{
	var id_facultad = cmb.options[cmb.selectedIndex].value;
	cargarUM('div_investigaciones_listado', 'investigaciones-listado-facultad/1/'+id_facultad);
}

function publicacionesFiltrar(cmb)
{
	var id_facultad = cmb.options[cmb.selectedIndex].value;
	cargarUM('div_publicaciones_listado', 'publicaciones-listado/1/'+id_facultad);
}

function gotoURL(url)
{
	window.location.href = RUTA+MODULO+"/"+url;
}

function goURL(url, target)
{
	if (target == '_blank') {
		window.open(url); 
	} else
	window.location.href = url; 
}

function popUp(url,w,h)
{
	var my_win = window.open(RUTA+url,null,'width='+w+',height='+h+',status=no,toolbar=no,resizable=no,menubar=no,location=no,scrollbars=no');
	my_win.moveTo(window.screen.availWidth/2 - w/2, window.screen.availHeight/2 - h/2);
}

function btn_seccion(div) 
{
	var div = document.getElementById(div);
	if (div.style.display == '') {
		div.style.display = 'none'
	} else {
		div.style.display = '';
	}
	calcularAlto();
}

function btn_over(td, over)
{
	td.className = (over) ? "listado_fila_over" : "";
}


// Formulario
function form_submit(id)
{
	var form = eval("document.form_"+id);
	form.action = RUTA+MODULO+"/form/";
	form.submit();
}

function fondoNegro(activar)
{
	if (activar) {
		window.scrollTo(0,0);
		var block_div = document.createElement('div');
		block_div.id = block_div.name = 'block_div';
		block_div.className = 'windowPopup_black';
		document.body.appendChild(block_div);
		window.onscroll = function() { window.scrollTo(0,0); }
	} else {
		document.body.removeChild(document.getElementById('block_div'));
		window.onscroll = function() {  }	
	}
}


function close_enviar_div()
{
	fondoNegro(false);
	document.body.removeChild(document.getElementById('new_div'));	
}


// IMAGENES
function imagenes_listado(tabla, id, comunicacion)
{
	if (comunicacion) {
		new Ajax.Updater('div_imagenes_listado', RUTA+MODULO+"/imagenes/"+tabla+"/"+id+"/");
	}
	else{
		new Ajax.Updater('div_imagenes_listado', RUTA+MODULO+"/imagenes/"+tabla+"/"+id+"/");
	}
	window.location.href = "#imagenes";
}
function galeria(id,num)
{
	new Ajax.Updater('div_galeria_imagenes', RUTA+MODULO+"/galeria/"+id+"/"+num+"/");
}


// IMPRIMIR
function imprimirDocumento(url) 
{
	var new_win = window.open(url, null, '');
}
function imprimirContent()
{
	var a = window.open(RUTA+MODULO+'/imprimir/','','');
	a.document.close();
}

// ACESO ALUMNOS Y DOCENTES
var accesso_alumnos = '';
function accesoAlumnos()
{
	accesso_alumnos = window.open("http://www3.um.edu.uy/alumnos", accesso_alumnos, "");	
}
var accesso_docentes = '';
function accesoDocentes()
{
	accesso_docentes = window.open("http://www3.um.edu.uy/profesores", accesso_docentes, "");	
}