// Configuraciones
//var web = "//localhost/lorenzo/";
var web = "http://www.adcsanlorenzo.com/";
var template = "templates/moderm/";

// Funciones JavaScript para visualizar los documentos...
function MM_reloadPage(init) {  //reloads the window if Nav4 resized
  if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
    document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
  else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
}
function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}
function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}
function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}
function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

// Funciones para trabajar con capas...
//--------------------------------------
// Constantes...
var NS4=(navigator.appName=="Netscape" && parseInt(navigator.appVersion)>=4);
//var ConstMostrar=(NS4)?'show':'visible',ConstEsconder=(NS4)?'hide':'hidden';
var ConstMostrar='visible',ConstEsconder='hidden';
// Funciones...
function $(el) { if (typeof el == 'string') return document.getElementById(el); return el; }
function Capa(NomeCapa){return document.getElementById(NomeCapa).style; }
function IsVisibleCapa(NomeCapa) { return Capa(NomeCapa).visibility=='visible'; }
function MostrarCapa(NomeCapa){ Capa(NomeCapa).visibility='visible'; }
function OcultarCapa(NomeCapa){ Capa(NomeCapa).visibility='hidden'; }
function ContidoCapa(NomeCapa,Contido){
	document.getElementById(NomeCapa).innerHTML = Contido;
}
function ObterContidoCapa(NomeCapa){
	return document.getElementById(NomeCapa).innerHTML;
}

// Cambiar estilos
function cambiarestilo(id, estilo){
	document.getElementById(id).className=estilo;
}

// Funciones javascript necesarias para la plantilla normal...
//
//
// Funciones para el menu
//-----------------------
//
var menu_sel = 0;

function show_menu(pos, menu){
	menu_sel = menu;
	var rest = 0;
	
	rest = document.body.scrollWidth - 980;
	if(rest>20){
		rest = (rest/2)-2;
	}else{
		if(NS4)	rest = 7;
		else	rest = 9;
	}

	var obj = "submenu" + menu_sel;
	var contido = ObterContidoCapa(obj);

	Capa("submenu").left = pos + rest;
	if(contido!=""){
		MostrarCapa("submenu");
		ContidoCapa("submenu", contido);
	}
}

function hide_menu(){
	OcultarCapa("submenu");
}

function on_submenu(id){
	if(NS4){
		cambiarestilo(id, 'submenusel');
	}else{
		var arr = document.getElementsByName(id);
		for(i=0;arr && i<arr.length;i++)
			arr[i].className = 'submenusel';
	}
}

function out_submenu(id){
	if(NS4){
		cambiarestilo(id, 'submenu');
	}else{
		var arr = document.getElementsByName(id);
		for(i=0;arr && i<arr.length;i++)
			arr[i].className = 'submenu';
	}
}

function on_menu(){
	var obj="menu"+menu_sel;
	cambiarestilo(obj, 'menusel');
	MostrarCapa('submenu');
}

function out_menu(){
	var obj="menu"+menu_sel;
	cambiarestilo(obj, 'menufnd');
	OcultarCapa('submenu');
}

function click_menu(sec, subsc, art){
	if(sec==undefined){document.getElementById("sc").disabled=true;sec="";}
	if(subsc==undefined){document.getElementById("subsc").disabled=true;subsc="";}
	if(art==undefined){document.getElementById("art").disabled=true;art="";}
	document.getElementById("sc").value=sec;
	document.getElementById("art").value=art;
	document.getElementById("subsc").value=subsc;
	document.frmMenu.submit();
}

// Accions con transparencias, ampliacion de imagenes y galeria
var tm_trans = new Array();
var tm_capa = 0;
var tm_capa2 = 0;

function oscurecer(id, alpha){
	if(tm_trans[id]!=undefined && tm_trans[id]){
		clearTimeout(tm_trans[id]);
		tm_trans[id] = 0;
	}
	object = document.getElementById(id).style;
	if(object!=undefined){
		if(object.filter!=undefined){			// explorer
			pos=object.filter.indexOf("=");
			opy=parseInt(object.filter.substring(pos+1), 10);
			num=parseInt(alpha);
			if(opy<num){
				opy+=10;
				object.filter="alpha(opacity="+opy+")";
				tm_trans[id] = setTimeout("oscurecer('"+id+"', "+alpha+")", 75);
			}
		}else if(object.opacity){				// firefox
			num = parseInt(alpha, 10)/100;
			opy = parseFloat(object.opacity);
			if(opy<num){
				opy+=0.1;
				object.opacity=opy;
				tm_trans[id] = setTimeout("oscurecer('"+id+"', "+alpha+")", 75);
			}
		}
	}
}

function aclarecer(id, alpha){
	if(tm_trans[id]!=undefined && tm_trans[id]){
		clearTimeout(tm_trans[id]);
		tm_trans[id] = 0;
	}
	object = document.getElementById(id).style;
	if(object!=undefined){
		if(object.filter!=undefined){			// explorer
			pos=object.filter.indexOf("=");
			opy=parseInt(object.filter.substring(pos+1), 10);
			num=parseInt(alpha);
			if(opy>num){
				opy-=10;
				object.filter="alpha(opacity="+opy+")";
				tm_trans[id] = setTimeout("aclarecer('"+id+"', "+alpha+")", 75);
			}
		}else if(object.opacity!=undefined){	// firefox
			num = parseInt(alpha, 10)/100;
			opy = parseFloat(object.opacity);
			if(opy>num){
				opy-=0.1;
				object.opacity=opy;
				tm_trans[id] = setTimeout("aclarecer('"+id+"', "+alpha+")", 75);
			}
		}
	}
}

// Funciones para galeria de fotos
function ampliarFoto(id){
	// Si se esta visionando la galería de imaxes y le damos al boton de ampliar, redireccionamos la página a la galería
	if(IsVisibleCapa('galeria1') || IsVisibleCapa('galeria2')){
		top.location.href = web+"index.php?sc=galery&id="+g_id+"&foto="+g_foto;
		return;
	}
	
	Capa('fondo_deg').width = document.body.scrollWidth;
	Capa('fondo_deg').height = document.body.scrollHeight;
	MostrarCapa('fondo_deg');
	
	Capa(id).top = document.body.scrollTop;
	Capa(id).width = document.body.scrollWidth;
	if(NS4)	Capa(id).height = window.innerHeight;
	else	Capa(id).height = document.body.offsetHeight;
	MostrarDegCapa(id);
}
function cerrarFoto(id){
	OcultarDegCapa(id);
	OcultarCapa('fondo_deg');
	//
	Capa('fondo_deg').width = 0;
	Capa('fondo_deg').height = 0;
}
function MostrarDegCapa(id){
	if(!IsVisibleCapa(id)) MostrarCapa(id);
	if(tm_capa){// && seg){
		clearTimeout(tm_capa);
		tm_capa=0;
	}
	object = document.getElementById(id).style;
	if(object!=undefined){
		if(object.filter!=undefined){			// explorer
			pos=object.filter.indexOf("=");
			opy=parseInt(object.filter.substring(pos+1), 10);
			if(opy<100){
				opy+=10;
				object.filter="alpha(opacity="+opy+")";
				tm_capa = setTimeout("MostrarDegCapa('"+id+"')", 100);
			}
		}else if(object.opacity){				// firefox
			opy = parseFloat(object.opacity);
			if(opy<1){
				opy+=0.1;
				object.opacity=opy;
				tm_capa = setTimeout("MostrarDegCapa('"+id+"')", 100);
			}
		}
	}
}
function OcultarDegCapa(id, seg){
	if(tm_capa2){
		clearTimeout(tm_capa2);
		tm_capa2 = 0;
	}
	object = document.getElementById(id).style;
	if(object!=undefined){
		if(object.filter!=undefined){			// explorer
			pos=object.filter.indexOf("=");
			opy=parseInt(object.filter.substring(pos+1), 10);
			if(opy>0){
				opy-=10;
				object.filter="alpha(opacity="+opy+")";
				if(seg==0)	tm_capa = setTimeout("OcultarDegCapa('"+id+"')", 50);
				else		tm_capa2 = setTimeout("OcultarDegCapa('"+id+"')", 50);
			}else if(IsVisibleCapa(id)) OcultarCapa(id);
		}else if(object.opacity){				// firefox
			opy = parseFloat(object.opacity);
			if(opy>0){
				opy-=0.1;
				object.opacity=opy;
				if(seg==0)	tm_capa = setTimeout("OcultarDegCapa('"+id+"')", 50);
				else		tm_capa2 = setTimeout("OcultarDegCapa('"+id+"')", 50);
			}else if(IsVisibleCapa(id)) OcultarCapa(id);
		}
	}
}

// Para galeria
var n_gal=1;
var g_id=0;
var g_ancho=0;
var g_fotoIni=-1;
var g_foto=-1;
var g_fotos=-1;
var tm_galeri=0;
var g_play=1;
var g_temp=5000;
// Aumentar velocidad da galería
var g_resT="";
var g_swT=0;

function aumentarTemp(){
	if(g_temp<15000){
		g_temp=g_temp+1000;
		var seg=g_temp/1000;
		ContidoCapa("lblTemp", seg);		
	}
}
function disminuirTemp(){
	if(g_temp>1000){
		g_temp=g_temp-1000;
		var seg=g_temp/1000;
		ContidoCapa("lblTemp", seg);
	}
}
function countGaleria(responseText, responseXML){
	g_fotos=parseInt(responseText, 10);
}
function galeriaTemporizador(){
	if(n_gal==1){
		ContidoCapa("galeria1", g_resT);
		OcultarDegCapa("galeria2", 1);
		MostrarDegCapa("galeria1");
		n_gal=2;
	}else if(n_gal==2){
		ContidoCapa("galeria2", g_resT);
		OcultarDegCapa("galeria1", 1);
		MostrarDegCapa("galeria2");
		n_gal=1;
	}
	// Introducimos valor en la etiqueta
	foto = g_foto+1;
	ContidoCapa("lblImaxes", foto+" de "+g_fotos+" imaxes");
	
	if(g_play){
		showGaleria();
		g_swT=1;
		g_resT="";
		tm_galeri = setTimeout("galeriaTemporizador()", g_temp);
	}else g_swT=0;
}
function galeriaCompletado(responseText, responseXML){
	g_resT = responseText;
	ContidoCapa("precarga", responseText);
	if(!g_swT) galeriaTemporizador();
}
function showGaleria(id, ancho, foto){
	// Ocultar tabla
	obj = document.getElementById("fndimagen").style;
	if(obj) obj.visibility='hidden';
	
	if(id==undefined)	id=g_id;
	if(ancho==undefined)ancho=g_ancho;
	if(foto==undefined){
		foto=g_foto+1;
		if(foto>=g_fotos && g_fotos!=-1) foto=0;
	}
	g_id=id;
	g_ancho=ancho;
	g_foto=foto;
	
	hora = new Date();
	gal = new CAjax();
	url = web+'templates/moderm/galeria.php?id='+id+'&foto='+foto+'&ancho='+ancho+'&tm='+hora.getTime();
	gal.Load(url);
	gal.completado = galeriaCompletado;
	
	if(g_fotos==-1){
		txt = ObterContidoCapa("lblImaxes");
		pos = txt.indexOf('e')+1;
		txt = txt.substring(pos);
		g_fotos = parseInt(txt, 10);
		if(g_fotos<=0){
			cgal = new CAjax();
			url = web+'templates/moderm/galeria.php?id='+id+'&sw=1&tm='+hora.getTime();
			cgal.Load(url);
			cgal.completado = countGaleria;
		}
	}
}
function obterFotoIni(){
	if(g_fotoIni==-1){
		txt = ObterContidoCapa("lblImaxes");
		g_fotoIni = parseInt(txt, 10);
		g_foto=g_fotoIni-1;
	}
}
function cambiarIcono(){
	// Cambio el icono de play para marcar que esta en reprodución
	ico = document.getElementById("btPlay");
	if(ico!=undefined){
		if(g_play==0) ico.src = web+"templates/moderm/imaxes/play.gif";
		else ico.src = web+"templates/moderm/imaxes/playR.gif";
	}
}
function gal_play(id, ancho, foto){
	obterFotoIni();
	if(tm_galeri){clearTimeout(tm_galeri); tm_galeri=0;}
	if(id!=undefined)	g_id=id;
	if(ancho!=undefined)g_ancho=ancho;
	if(foto!=undefined) g_foto=foto;
	
	g_play=1;
	showGaleria();
	cambiarIcono();
}
function gal_pause(){
	g_play=0;
	g_swT=0;
	if(tm_galeri){clearTimeout(tm_galeri); tm_galeri=0;}
	cambiarIcono();
}
function gal_stop(){
	g_foto=g_fotoIni-1;
	g_play=0;
	g_swT=0;
	if(tm_galeri){clearTimeout(tm_galeri); tm_galeri=0;}

	// Ocultamos y mostramos la foto inicial
	if(tm_capa){
		clearTimeout(tm_capa);
		tm_capa=0;
	}
	if(tm_capa2){
		clearTimeout(tm_capa2);
		tm_capa2=0;
	}
	if(n_gal==1) OcultarDegCapa("galeria2", 1);
	if(n_gal==2) OcultarDegCapa("galeria1", 1);
	obj = document.getElementById("fndimagen").style;
	if(obj) obj.visibility='visible';
	
	// Restablecemos el valor de label
	ContidoCapa("lblImaxes", g_fotoIni+" de "+g_fotos+" imaxes");
	cambiarIcono();
}
function gal_next(id, ancho, foto){
	obterFotoIni();
	gal_pause();
	if(id!=undefined)	g_id=id;
	if(ancho!=undefined)g_ancho=ancho;
	if(foto!=undefined) g_foto=foto;
	
	showGaleria();
}
function gal_prev(id, ancho, foto, fotos){
	obterFotoIni();
	gal_pause();
	if(id!=undefined)	g_id=id;
	if(ancho!=undefined)g_ancho=ancho;
	if(foto!=undefined) g_foto=foto;
	if(fotos!=undefined)g_fotos=fotos;
	
	if(g_foto>0)			g_foto=g_foto-2;
	else if(g_fotos!=-1)	g_foto=g_fotos-2;
	else 					g_foto=0;
	
	showGaleria();
}

// Funciones para cargar las clasificaciones en las capas
var t_sex = 0;
var t_div = 1;

function selClasifSex(valor){ t_sex = valor; loadClasif(); }
function selClasifDiv(valor){ t_div = valor; loadClasif(); }
function clasifCompletado(responseText, responseXML){
	ContidoCapa("r_clasificacion", responseText);
}
function loadClasif(){
	hora = new Date();
	cla = new CAjax();
	url = web+'templates/moderm/plateral.php?pajax=1&t_sex='+t_sex+'&t_div='+t_div+'&tm='+hora.getTime();
	cla.Load(url);
	cla.completado = clasifCompletado;
	ContidoCapa("r_clasificacion", "<br><br>Cargando...<br><br><br>");
	
	// Vamos ha cambiar o aspecto segun la configuración
	if(t_sex==0){
		cambiarestilo('t_fsm', 'tab_sel');
		cambiarestilo('t_fsf', 'tab_fondo');
		Capa('to_fsm').display="block";
		Capa('to_fsf').display="none";
	}else{
		cambiarestilo('t_fsm', 'tab_fondo');
		cambiarestilo('t_fsf', 'tab_sel');
		Capa('to_fsm').display="none";
		Capa('to_fsf').display="block";
	}
	if(t_div==0){
		cambiarestilo('o_divpri', 'cajetin_lnk');
		cambiarestilo('o_divseg', 'cajetinb_lnk');
		cambiarestilo('o_gruA', 'cajetin_lnk');
		cambiarestilo('o_gruB', 'cajetinb_lnk');
	}else{
		cambiarestilo('o_divpri', 'cajetinb_lnk');
		cambiarestilo('o_divseg', 'cajetin_lnk');
		cambiarestilo('o_gruA', 'cajetinb_lnk');
		cambiarestilo('o_gruB', 'cajetin_lnk');
	}
}

function trim(cadena){
for(i=0;i<cadena.length;){if(cadena.charAt(i)==" ") cadena=cadena.substring(i+1, cadena.length); else break;}
for(i=cadena.length-1; i>=0; i=cadena.length-1){if(cadena.charAt(i)==" ") cadena=cadena.substring(0,i); else break;}
return cadena;}

function validarMail(correo){
var mailres=true;
var cadena="abcdefghijklmnñopqrstuvwxyzABCDEFGHIJKLMNÑOPQRSTUVWXYZ1234567890@._-";
var arroba=correo.indexOf("@",0);
if((correo.lastIndexOf("@"))!=arroba)arroba=-1;
var punto=correo.lastIndexOf("."); 
for(var contador=0;contador<correo.length;contador++){if(cadena.indexOf(correo.substr(contador,1),0)==-1){mailres = false;break;}}
if((arroba>1)&&(arroba+1<punto)&&(punto+1<(correo.length))&&(mailres==true)&&(correo.indexOf("..",0)==-1))mailres = true;
else mailres = false;
return mailres;}

function txornadaOnChange(obj){
	if(obj==undefined) return;
	var para="xornada="+obj.value+"&grupo="+$("g_id").value;
	var func = new CTools();
	func.Exec("getEncontrosXornada", para, function(responseText, responseXML){ $("t_encontros").innerHTML=responseText; });
}
function CTools(){
this.name = new String();
this.script = new String("libtools.php?ajax=1&func=");
this.isload = 0;
this.parametros = new String();	// Para pasarlle parametros ao script
this.metodo = new String("get");
this.pCallback = null;
this._ajax =  new CAjax();	// Objeto ajax
this.Exec = function(func, param, callback){
	hora = new Date();
	this.name=func;
	url=template+this.script+func;
	if(param!=undefined) this.parametros=param;
	if(this.parametros!="" && this.metodo!="post") url+="&"+this.parametros;
	url+="&tm="+hora.getTime();
	if(this.metodo=="post"){
		this.metodo="";
		this._ajax.LoadPost(url, this.parametros);
	}
	else this._ajax.Load(url);
	this._ajax.completado = callback;
	this._ajax.parent = this;}
}
// Funcion para mostrar a ficha do xogador
function showFicha(id, torneo){
	Capa('fondo_deg').width = document.body.scrollWidth;
	Capa('fondo_deg').height = document.body.scrollHeight;
	MostrarCapa('fondo_deg');
	
	var para="xogador="+id+"&torneo="+torneo;
	var func = new CTools();
	func.Exec("getXogador", para, function(responseText, responseXML){
		$("foto_amp").innerHTML=responseText;
		Capa("foto_amp").top = document.body.scrollTop;
		Capa("foto_amp").width = document.body.scrollWidth;
		if(NS4)	Capa("foto_amp").height = window.innerHeight;
		else	Capa("foto_amp").height = document.body.offsetHeight;
		MostrarDegCapa("foto_amp");
	});
}