// JavaScript Document
function disableForms() {
	var forms = document.getElementsByTagName('form');
	for (var k = 0; k < forms.length; k++) {
		try {
			Form.disable(forms[k]);
		} catch(e) {;}
	}
}
function enableForms() {
	var forms = document.getElementsByTagName('form');
	for (var k = 0; k < forms.length; k++) {
		try {
			Form.enable(forms[k]);
		} catch(e) {;}
	}
}

var mostrandoImagen = false;
var enMostrarImagen = false;
var enOcultarImagen= false;
function mostrarImagen(toHide, imgUrl, w, h,top) {
	if (mostrandoImagen || enMostrarImagen) return false;
	enMostrarImagen = true;
	var oBox = $('mostrarImagenBox');
	var oImg = $('mostrarImagenImg');
	var oHide = $(toHide);
	// Set image parameters
	oImg.src = imgUrl;
	oImg.width = w;
	oImg.height = h;
	document.body.appendChild(oBox);
	var bodyDims = Element.getDimensions(document.body);
	var toHideDims = Element.getDimensions(toHide);
	var boxDims = Element.getDimensions(oBox);
//	oBox.style.left = parseInt(bodyDims.width/2-boxDims.width/2+100)+"px";
	oBox.style.left = parseInt(bodyDims.width/2-boxDims.width/2+1)+"px";
	oBox.style.top = parseInt(top)+"px";
//	oBox.style.top = parseInt(400)+"px";
//	oBox.style.top = parseInt(toHideDims.height/2-boxDims.height-100)+"px";
	var fAfterFinish = function () {
		mostrandoImagen = true;
	}
	disableForms();
	new Effect.Fade(oHide, {duration: 0.1, from: 1.0, to: 0.5});
	new Effect.Appear(oBox, {duration: 0.1, afterFinish: fAfterFinish});
	enMostrarImagen = false;
	return false;
}

function ocultarImagen(toShow) {
	if (!mostrandoImagen || enOcultarImagen) return false;
	enOcultarImagen = true;
	var oBox = $('mostrarImagenBox');
	var oImg = $('mostrarImagenImg');
	var oShow = $(toShow);
	var fAfterFinish = function () {
		mostrandoImagen = false;
		enableForms();
		oBox.style.display = 'none';
	}
	new Effect.Fade(oBox, {duration: 0.1});
	new Effect.Appear(oShow, {duration: 0.1, from: 0.6, to: 1.0, afterFinish: fAfterFinish});	
	enOcultarImagen = false;
	return false;
}



/* AJAX */
/*Inicio Funciones Remotas*/
function RMT_inicializa() {
var xx=null;
 try {
  xx = new XMLHttpRequest();
 } catch (e) {
  xx=null;
  var msxmlhttp = new Array('Msxml2.XMLHTTP.5.0',
                      'Msxml2.XMLHTTP.4.0',
                      'Msxml2.XMLHTTP.3.0',
                      'Msxml2.XMLHTTP',
                      'Microsoft.XMLHTTP');
  var success = false;
  for (var i=0; i<msxmlhttp.length && !success;i++) {
   try {
    xx = new ActiveXObject(msxmlhttp[i]);
    success = true;
   } catch (e) { xx=null; }
  }
 }
 return xx;
}

var LNSR_layer='';
var LNSR_funcion='';

function LNSR_ejecutar(lay,reg,metodo,uri,funcion, args) {
 var i, n;
 var post_data;
 var retorno=true;
 LRMT_ResultadoError='';
 LRMT_ResultadoHttp='';
 LNSR_layer=lay;
 LNSR_funcion=reg;
 if (typeof(metodo) == "undefined" || metodo== "") 	metodo = "GET";
 if (metodo == "GET") {
  if (uri.indexOf("?") == -1) uri += "?fn=" + escape(funcion);
  else uri += "&fn=" + escape(funcion);
  uri += "&fnrnd=" + new Date().getTime();
  for (i = 0; i < args.length-1; i+=2) uri += "&" + args[i] + "=" + escape(args[i+1]);
  post_data = null;
 } else if (metodo == "POST") {
  post_data = "fn=" + escape(funcion);
  post_data += "&fnrnd=" + new Date().getTime();
  for (i = 0; i < args.length-1; i+=2) {
		post_data += "&" + args[i] + "=" + escape(args[i+1]);
	}
 } else {
  alert("Tipo de Petición Ilegal: " + LRMT_tipopeticion);
  LNSR_funcion();
  return false;
 }
 if (LRMT_conector == null) {
  alert("Imposible Crear Objeto de conexión Remota al Servidor.");
  return false;
  LNSR_funcion();
 } else {
	bComplete = false;
  LRMT_conector.open(metodo, uri, true);
  if (metodo == "POST") {
   LRMT_conector.setRequestHeader("Method", "POST " + uri + " HTTP/1.1");
   LRMT_conector.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=iso-8859-1");
  }
  LRMT_conector.onreadystatechange = function(){
   if (LRMT_conector.readyState == 4 && !bComplete) {
     bComplete = true
     LNSR_ejecutar2(LRMT_conector)
   }
  };
  LRMT_conector.send(post_data);
  return retorno;
 }
}


function LNSR_ejecutar2(a) {
		var reto = false;
		try {
			switch(a.status) {
				case 200:
					document.getElementById(LNSR_layer).innerHTML=a.responseText;
					reto = true;
					break;
				case 400:
					alert('El servidor envió el código de Error: '+a.status+' (Petición errónea. Se ha introducido una URL mal formada.) a la petición solicitada');
					break;
				case 401:
					alert('El servidor envió el código de Error: '+a.status+' (No autorizado. El visitante no tiene autorización para acceder a esa página.) a la petición solicitada');
					break;
				case 403:
					alert('El servidor envió el código de Error: '+a.status+' (Prohibido. Permisos insuficientes para leer esa página o directorio.) a la petición solicitada');
					break;
				case 404:
					alert('El servidor envió el código de Error: '+a.status+' (No encontrado. La página solicitada no se ha encontrado.) a la petición solicitada');
					break;
				default:
					alert('El servidor envió el código de Error: '+a.status+' (Error interno del servidor Ocurrió un error interno mientras se intentaba mostrar la página solicitada.) a la petición solicitada');
					break;
			}
		} catch (e) {
			alert("Unable connect to server.")
		}
	if (!reto) LNSR_funcion();
	return reto;
}

var LRMT_conector = RMT_inicializa();
var LRMT_ResultadoHttp="";
var LRMT_ResultadoError="";
/*final Funciones Remotas*/

function aviso_legal(ln){
	var nn= new Array('ln',ln);
	xx='includes/ajax.avisolegal.php';
	LNSR_ejecutar('mostrar-bios','','GET',xx,'', nn);
	capa=document.getElementById('mostrar-bios');
	capa2=document.getElementById('cerrar-bios');
	capa.style.visibility='visible';
	capa.style.display='block';

	if (window.innerHeight){
		var h=window.self.innerHeight;
		var v=window.innerWidth;
	espacio_pagina = window.innerHeight
	}else{
		var v=document.body.clientWidth;
		var h=document.body.clientHeight;
	}
	var posi_h=(h-500);
	var posi_v=((v/2)-200);

	capa2.style.top=(posi_h-30)+'px';
	capa2.style.left=posi_v+'px';

	capa.style.top=posi_h+'px';
	capa.style.left=posi_v+'px';
	capa2.style.visibility='visible';
}

function close_aviso(){
	capa=document.getElementById('mostrar-bios');
	capa2=document.getElementById('cerrar-bios');
	capa.style.visibility='hidden';
	capa.style.display='none';
	capa2.style.visibility='hidden';
}


function close_perfil(){
	capa=document.getElementById('mostrar-bios');
	capa2=document.getElementById('cerrar-bios');
	capa.style.visibility='hidden';
	capa.style.display='none';
	capa2.style.visibility='hidden';
}

function mostrar_bios(valor,lng){
	if (valor!=''){
		var nn= new Array('peri',valor,'ln',lng);
		xx='includes/ajax.bios.php';
		LNSR_ejecutar('mostrar-bios','','GET',xx,'', nn);
		capa=document.getElementById('mostrar-bios');
		capa2=document.getElementById('cerrar-bios');
		capa.style.display='block';
 		capa.style.visibility='visible';
 		capa2.style.visibility='visible';
	}
}