function fix_external_links() { 
	
    if (!document.getElementsByTagName) return; 
    var anchors = document.getElementsByTagName("a"); 
    for (var i = 0; i < anchors.length; i++) { 
        var anchor = anchors[i]; 
        if (anchor.getAttribute("rel") && anchor.getAttribute("rel") == "external") { 
            anchor.target = "_blank"; 
        }  
    } 
    
} 

function inicio () {
	fix_external_links(); 
	//laterales();
}

window.onload = inicio;
//window.onresize = laterales;

function nuevoAjax() { 

	var xmlhttp = false; 
	
	try  { 
		// Creacion del objeto AJAX para navegadores no IE
		xmlhttp = new ActiveXObject("Msxml2.XMLHTTP"); 
	}
	
	catch(e) { 
		try { 
			// Creacion del objet AJAX para IE 
			xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); 
		} 
		catch(E) { xmlhttp = false; }
	}
	
	if (!xmlhttp && typeof XMLHttpRequest != 'undefined') { xmlhttp = new XMLHttpRequest(); } 

	return xmlhttp; 
	
}

function laterales() {
	
	//alert(document.body.offsetWidth);
	if (document.body.offsetWidth <= 1024) {
		document.getElementById("logo_izq").style.display = "none";
		document.getElementById("lateral_izq").style.display = "none";
		document.getElementById("pie_izq").style.display = "none";
		document.getElementById("logo_der").style.display = "none";
		document.getElementById("lateral_der").style.display = "none";
		document.getElementById("pie_der").style.display = "none";
	
		document.getElementById("zon_centro").style.marginLeft = 0;
		document.getElementById("zon_centro").style.marginRight = 0;
	} else {
		if (document.getElementById('noticias') != null) {
			if (document.getElementById("noticias").offsetHeight > document.getElementById("cartelera").offsetHeight)
				alt_lateral = document.getElementById("noticias").offsetHeight;
			else
				alt_lateral = document.getElementById("cartelera").offsetHeight;
			document.getElementById("lateral_izq").style.height = (alt_lateral + 400) + "px";
			document.getElementById("lateral_der").style.height = (alt_lateral + 400) + "px";					
		} else {
			alt_lateral = document.getElementById("contgen").offsetHeight;
			document.getElementById("lateral_izq").style.height = (alt_lateral + 20) + "px";
			document.getElementById("lateral_der").style.height = (alt_lateral + 20) + "px";								
		}			
		
		document.getElementById("logo_izq").style.display = "";
		document.getElementById("lateral_izq").style.display = "";
		document.getElementById("pie_izq").style.display = "";
		document.getElementById("logo_der").style.display = "";
		document.getElementById("lateral_der").style.display = "";
		document.getElementById("pie_der").style.display = "";	
			
		document.getElementById("zon_centro").style.marginLeft = "26px";		
		document.getElementById("zon_centro").style.marginRight = "26px";
	}
		
}

function irPagina (pagina) {
	document.forms[0].numpag.value = pagina;
	document.forms[0].submit();	
}

function irSemCartelera (pagina) {
	anio = document.forms[0].ano_cartelera.value;
	if (pagina == 54) {
		pagina = 0;
		anio++;
	}
	if (pagina == -1) {
		pagina = 53;
		anio--;
	}
	document.forms[0].ano_cartelera.value = anio;
	document.forms[0].sem_cartelera.value = pagina;
	document.forms[0].submit();	
}

function cargarPost() {
	
	var capa = document.getElementById("post_foro");	
	var ajax = nuevoAjax();
	
	capa.innerHTML = "<ul><li>Cargando...</li></ul>";

	ajax.open("POST", "includes/ultimos_post.php", true);
	ajax.setRequestHeader ("Content-Type", "application/x-www-form-urlencoded");
	ajax.send("");

	ajax.onreadystatechange = function() {
		
		if (ajax.readyState == 4) {
			if (ajax.responseText.length == 11)
				capa.innerHTML = "<ul>La información no está disponible temporalmente</ul>";
			else
				capa.innerHTML = ajax.responseText;
		}
			
	}	
	
}

function cargarJuegos() {
	
	var capa = document.getElementById("post_juegos");	
	var ajax = nuevoAjax();
	
	capa.innerHTML = "<ul><li>Cargando...</li></ul>";

	ajax.open("POST", "includes/juegos_foro.php", true);
	ajax.setRequestHeader ("Content-Type", "application/x-www-form-urlencoded");
	ajax.send("");

	ajax.onreadystatechange = function() {
		
		if (ajax.readyState == 4) {
			if (ajax.responseText.length == 11)
				capa.innerHTML = "<ul>La información no está disponible temporalmente</ul>";
			else			
				capa.innerHTML = ajax.responseText;
		}			
	}	
	
}

function sendVoto(cod) {
	
	var ajax = nuevoAjax();

	list = document.getElementById("tu_voto");
	voto = list.options[list.selectedIndex].value;
	
	ajax.open("POST", "includes/send_voto.php", true);
	ajax.setRequestHeader ("Content-Type", "application/x-www-form-urlencoded");
	ajax.send("cod="+cod+"&voto="+voto);

	ajax.onreadystatechange = function() {
		
		if (ajax.readyState == 4) {
			alert(ajax.responseText);
			// if (ajax.responseText != "Solo se admite un voto por IP y película")							
			// window.location.reload();
		}			
	}	
			
}

function sendComen(cod) {
	
	var ajax = nuevoAjax();

	var str_comen = document.getElementById("str_comen").value;
	var str_usuario = document.getElementById("str_usuario").value;
	var str_mail = document.getElementById("str_mail").value;
	if (str_comen == "" || str_usuario == "" || str_mail == "")	{
		alert("Es necesario introducir el nombre de usuario, email y comentario para poder enviarlo");
		return;
	}
	
	ajax.open("POST", "includes/send_comen.php", true);
	ajax.setRequestHeader ("Content-Type", "application/x-www-form-urlencoded");
	ajax.send("cod="+cod+"&str_comen="+escape(str_comen)+"&str_usuario="+escape(str_usuario)+"&str_mail="+escape(str_mail));

	ajax.onreadystatechange = function() {
		
		if (ajax.readyState == 4) {
			if (ajax.responseText != "")
				alert(ajax.responseText);
		}
	}	
			
}

function filtrarEnlaces(accion) {
	
	document.forms[0].conenlace.value = accion;
	document.forms[0].submit();	
	
}

function buscaSemCartelera () {
	
	semana = document.forms[0].busSemana.value;
	
	document.forms[0].ano_cartelera.value = semana.substring(3);
	document.forms[0].sem_cartelera.value = semana.substring(0, 2);
	document.forms[0].submit();	
	
}

function filtrarListado(accion) {
	
	document.forms[0].vista.value = accion;
	document.forms[0].submit();	
	
}

function filtrarCargos(accion) {
	
	document.forms[0].per_papel.value = accion;
	document.forms[0].submit();	
	
}

