function downloadImage(index,size){
	L_idUsuario=parseInt(L_idUsuario,10);if(isNaN(L_idUsuario)){L_idUsuario=0;}
	if (L_idUsuario=="0") {
		showLoginPopupBox("<b>descargar de forma directa esta foto</b> ");
		return;	
	}
	if(!document.getElementById("controlIframe")){return;}
	var url = "/images/download/"+fotos[index][0]+"/"+fotos[index][1]+"/"+size+fotos[index][4];
	document.getElementById("controlIframe").src = url;return;
}
function getLoader(style){
	if(style!=null){var html="<div style=\""+style+"\">";}else{var html="<div>";}
	html+="<img align=\"middle\" src=\"/images/layout/anima/ajax-loader.gif\" border=0>&nbsp;cargando...</div>";
	return html;
}
function closeFoto(){
	closeEpp();
	closeLoginPop();
	document.getElementById("coverDiv").style.width="0px";
	document.getElementById("coverDiv").style.height="0px";
	document.getElementById("coverDiv").innerHTML = ""
	if(document.getElementById("fotoGallery")){document.getElementById("fotoGallery").style.display="none";}
	if(document.getElementById("coverDiv")){document.getElementById("coverDiv").style.display="none";}
}
function hideLayer(obj){
	obj.style.display="none";
}
function getPageNumber(index,paginas){
	index++;
	if(index%paginas==0){return parseInt(index/paginas,10);}else{return parseInt(index/paginas,10)+1;}
}
function nextPhoto(offset){
	if(isNaN(cPhoto)){cPhoto=0;}
	if(((parseInt(offset,10)+parseInt(cPhoto,10))>=fotos.length)||((parseInt(offset,10)+parseInt(cPhoto,10))<0)){return;}
	var thisPage = getPageNumber(cPhoto,fotosxpagina); var newPage = getPageNumber(parseInt(offset,10)+parseInt(cPhoto,10),fotosxpagina);
	if(thisPage!=newPage){showFotoPage(newPage);}
	cPhoto=parseInt(cPhoto)+offset;showFoto(cPhoto);
	if(cPhoto==0){document.getElementById("popupPrev").style.display="none";}else{document.getElementById("popupPrev").style.display="block";}
	if((cPhoto+1)==fotos.length){document.getElementById("popupNext").style.display="none";}else{document.getElementById("popupNext").style.display="block";}
}
function hidePreload(){
	if(document.getElementById("preloading")){document.getElementById("preloading").style.display="none";}
}
function sendPhoto(){
	var arrayPageSize = getPageSize();
	var arrayPageScroll = getPageScroll();	
	var posX = "20px"; var posY="20px";
	document.getElementById("controlIframe").src="/control/control_galerias_epp.asp?idFoto="+fotos[cPhoto][1];
	document.getElementById("control").style.height="auto";
	document.getElementById("control").style.width="auto";
	document.getElementById("control").style.position="absolute";
	if(arrayPageSize[0]>450){posX=parseInt(((arrayPageSize[0]-450)/2)+arrayPageScroll[0])+"px";}else{posX=(parseInt(posX)+arrayPageScroll[0])+"px";}
	if(arrayPageSize[3]>210){posY=parseInt(((arrayPageSize[3]-210)/2)+arrayPageScroll[1])+"px";}else{posY=(parseInt(posY)+arrayPageScroll[1])+"px";}	
	document.getElementById("control").style.top=posY;
	document.getElementById("control").style.left=posX;
	document.getElementById("control").style.zIndex=200;
	document.getElementById("controlIframe").style.display="block";
	document.getElementById("control").style.display="block";
}
function closeEpp(){
	if(!document.getElementById("controlIframe")){return;}
	if(!document.getElementById("control")){return;}
								
	document.getElementById("control").style.height="0px";
	document.getElementById("control").style.width="0px";
	document.getElementById("control").style.position="absolute";
	document.getElementById("control").style.top="0px"
	document.getElementById("control").style.left="0px";
	document.getElementById("control").style.display="none";
	document.getElementById("controlIframe").src="/blank.htm";
	document.getElementById("controlIframe").style.display="none";	
}	
function getMonthName(yearmonth){
	if(yearmonth==null){yearmonth = document.getElementById("galMonth").value;}else if(yearmonth.length!=6){return "---";}
	if(yearmonth.substring(4,5)=="0"){var smes=parseInt(yearmonth.substring(5,6));}else{var smes=parseInt(yearmonth.substring(4,6));}
	var meses = new Array("Enero","Febrero","Marzo","Abril","Mayo","Junio","Julio","Agosto","Septiembre","Octubre","Noviembre","Diciembre");
	return meses[smes-1];
}
function getYear(){
	if(document.getElementById("galYear")){return document.getElementById("galYear").value;}else{return "---";}
}
function getCategorias(obj,sCat){
	if(sCat==null){sCat="";}
	if(obj==null){
		if(!document.getElementById("galMonth")){return;};var sFecha = document.getElementById("galMonth").value;
	}else{
		var sFecha = obj.value;
	}
	xmlHttpC=GetXmlHttpObject();
	if(xmlHttpC==null){return;}
	xmlHttpC.onreadystatechange=function(){
		if(xmlHttpC.readyState==4){
			var responseTxt = unescape(xmlHttpC.responseText);
			responseTxt = responseTxt.replace(/\+/gi," ");
			eval("categorias = new Array("+responseTxt+");");
			var index = -1;
			if (sCat!=""){for(var i=0;i<categorias.length;i++){if(categorias[i][0]==sCat){index=i;}};}
			if(index!=-1){showCategorias(index,"detail");}else{showCategorias();}
		}	
	}
	if(showLoader){
		if(document.getElementById("categorias_div")){document.getElementById("categorias_div").innerHTML=getLoader("text-align:center;width:400px;height:40px;border:1px solid #303030;margin:auto;padding:20px;;color:#82C226;font-size:10px;");}
	}
	var url = "/control/control_galerias_dev.asp?pag=catesxmes&sFecha="+sFecha;
	xmlHttpC.open("GET",url,true);
	xmlHttpC.send(null); 
}
function getGalerias(index,accion){
	if(index==null){index=0;};var idcategoria=categorias[index][0];
	if(!document.getElementById("galMonth")){return;};var sFecha = document.getElementById("galMonth").value;
	xmlHttpG=GetXmlHttpObject();
	if(xmlHttpG==null){return;}
	xmlHttpG.onreadystatechange=function(){
		if(xmlHttpG.readyState==4){
			var responseTxt = unescape(xmlHttpG.responseText);
			responseTxt = responseTxt.replace(/\+/gi," ");
			eval("galerias = new Array("+responseTxt+");");
			var indexGal = -1;
			if((accion=="detail")&&(dGal!="")){for(var i=0;i<galerias.length;i++){if(galerias[i][0]==dGal){indexGal=i;}};}
			if(indexGal!=-1){showGalerias(index,indexGal);}else{showGalerias(index);}
		}	
	}
	if(showLoader){
		if(document.getElementById("galerias_div")){document.getElementById("galerias_div").innerHTML=getLoader("text-align:center;width:400px;height:40px;border:1px solid #303030;margin:auto;padding:20px;;color:#82C226;font-size:10px;");}
	}
	var url = "/control/control_galerias_dev.asp?pag=galsxmes&sFecha="+sFecha+"&id="+idcategoria;
	xmlHttpG.open("GET",url,true);
	xmlHttpG.send(null); 
}	
function getFotos(index){
	if(index==null){return;}
	if(index>galerias.length){return;}
	var idGaleria = galerias[index][0];
	if(!document.getElementById("galMonth")){return;};var sFecha = document.getElementById("galMonth").value;
	xmlHttpF=GetXmlHttpObject();
	if(xmlHttpF==null){return;}
	xmlHttpF.onreadystatechange=function(){
		if(xmlHttpF.readyState==4){
			var responseTxt = unescape(xmlHttpF.responseText);
			responseTxt = responseTxt.replace(/\+/gi," ");
			eval("fotos = new Array("+responseTxt+");");
			showFotos(index);
		}	
	}
	if(document.getElementById("fotos_div_header_titulo")){document.getElementById("fotos_div_header_titulo").innerHTML=galerias[index][2]+"<br/>("+galerias[index][4]+" fotos)";}
	if(document.getElementById("fotos_div_header_fecha")){document.getElementById("fotos_div_header_fecha").innerHTML=galerias[index][1];}		
	if(document.getElementById("popupTitulo")){document.getElementById("popupTitulo").innerHTML=galerias[index][2];}
	if(document.getElementById("popupPaginador")){document.getElementById("popupPaginador").innerHTML="1/"+galerias[index][4].toString();}
	if(showLoader){
		if(document.getElementById("fotos_div")){document.getElementById("fotos_div").innerHTML=getLoader("text-align:center;width:400px;height:40px;border:1px solid #303030;margin:auto;margin-top:20px;margin-bottom:20px;padding:20px;;color:#82C226;font-size:10px;");}
		if(document.getElementById("zona_seleccion")){document.getElementById("zona_seleccion").style.display="none";}
		if(document.getElementById("zona_detalle")){document.getElementById("zona_detalle").style.display="block";}
	}
	var url = "/control/control_galerias_dev.asp?pag=fotosxmes&id="+idGaleria;
	xmlHttpF.open("GET",url,true);
	xmlHttpF.send(null);
}
function showFoto(index){
	var posX = "20px"; var posY="20px";
	getPageSize();getPageScroll();
	if(document.getElementById("preloading")){document.getElementById("preloading").style.display="block";}
	var html=	"pageWidth:"+arrayPageSize[0]+"px\n"+
				"pageHeight:"+arrayPageSize[1]+"px\n"+
				"windowWidth:"+arrayPageSize[2]+"px\n"+
				"windowHeight:"+arrayPageSize[3]+"px\n"+
				"-----------------------------------\n"+
				"arrayPageScroll[0]:"+arrayPageScroll[0]+"px\n"+
				"arrayPageScroll[1]:"+arrayPageScroll[1]+"px"
	if(arrayPageSize[0]>520){posX=parseInt(((arrayPageSize[0]-520)/2)+arrayPageScroll[0])+"px";}else{posX=(parseInt(posX)+arrayPageScroll[0])+"px";}
	if(arrayPageSize[3]>600){posY=parseInt(((arrayPageSize[3]-600)/2)+arrayPageScroll[1])+"px";}else{posY=(parseInt(posY)+arrayPageScroll[1])+"px";}	
	document.getElementById("coverDiv").style.width=(arrayPageSize[0]-5)+"px";
	document.getElementById("coverDiv").style.height=arrayPageSize[1]+"px";
	document.getElementById("coverDiv").style.display="block";
	document.getElementById("fotoGallery").style.width="505px";
	document.getElementById("fotoGallery").style.height="auto";
	document.getElementById("fotoGallery").style.marginTop=posY;
	document.getElementById("fotoGallery").style.marginLeft=posX;
	var f = "<img onerror=\"this.src='/images/layout/clearpixel.gif';\" onload=\"hidePreload();\" src=\"/store/galerias/"+fotos[index][0]+"/"+fotos[index][1]+"/480x360_"+fotos[index][4]+"\" border=0 width=480 height=360>";
	document.getElementById("popupFoto").innerHTML=f;
	cPhoto = index;	
	if(document.getElementById("popupPaginador")){document.getElementById("popupPaginador").innerHTML=(parseInt(index,10)+1).toString()+"/"+fotos.length;}
	document.getElementById("popup480x360").href="javascript:downloadImage("+index+",'480x360_');";
	document.getElementById("popup800x600").href="javascript:downloadImage("+index+",'800x600_');";
	document.getElementById("popup1024x768").href="javascript:downloadImage("+index+",'1024x768_');";
	document.getElementById("fotoGallery").style.display="block";
	if(cPhoto==0){document.getElementById("popupPrev").style.display="none";}else{document.getElementById("popupPrev").style.display="block";}
	if((cPhoto+1)==fotos.length){document.getElementById("popupNext").style.display="none";}else{document.getElementById("popupNext").style.display="block";}
}
function showCategorias(index,accion){
	var html="";
	if(categorias.length<1){
		html="No hay ninguna categoría con galerías disponibles para el mes de "+getMonthName()+" del "+getYear();
	}else{
		//html+="<div class=titulo>Categorías disponibles para el mes de "+getMonthName()+" del "+getYear()+"</div>";
		html+="<div class=titulo><br></div>";
		if (index==null){var idcategoria=categorias[0][0];index=0;}else{var idcategoria=categorias[index][0];}
		for(var i=0;i<categorias.length;i++){
			html+="<div ";if(idcategoria==categorias[i][0]){html+="class=\"categoriasH\" ";}else{html+="class=\"categorias\" ";};
			html+="title=\"pulsa aquí para ver las galerías en esta categoría\" onclick=\"setGalerias('"+i+"');\">"+categorias[i][1]+"</div>"; 
		}	
	}
	html+="<div style=\"clear:both;\"></div>";
	if(document.getElementById("categorias_div")){document.getElementById("categorias_div").innerHTML=html;}
	html=null;
	if(accion==null){
		if(!document.getElementById("galerias_div")){return;}
		if(document.getElementById("galerias_div").getAttribute("idcategoria")!=idcategoria){setGalerias(index);}
	}else if (accion="detail"){
		getGalerias(index,'detail');
	}
}
function setGalerias(index){
	showCategorias(index,'render');
	getGalerias(index);
}
function showGalerias(index,idg){
	if(!document.getElementById("galerias_div")){return;}
	var html = "<div style=\"width:100%;\">"
	html+="<div class=titulo>Galerías en \""+categorias[index][1]+"\" para el mes de "+getMonthName()+"</div>";
	html+="<div class=fecha>"+galerias.length+"</div>";
	html+="<div style=\"clear:both;\"></div>";
	html+="</div>"
	var cpage = 1;
	html+="<div class=\"galpagina\" id=\"galpagina1\" style=\"display:block;\">\n";
	for(var i=0;i<galerias.length;i++){
		if((i%galeriasxpagina==0)&&(i>0)){
			cpage++;
			html+="\n</div>\n";
			html+="<div style=\"clear:both;\"></div>";
			html+="<div class=\"galpagina\" id=\"galpagina"+cpage+"\" style=\"display:none;\">\n";
		}			
		html+=getGalItem(i,idg);	
	}
	html+="\n</div>\n";
	html+="<div style=\"clear:both;\"></div>";
	html+="<div id=paginadogalerias>\n"
	for(var i=cpage;i>0;i--){
		html+="<div ";if(i==1){html+="class=\"npaginaH\" ";}else{html+="class=\"npagina\" ";}
		html+="onclick=\"showGalPage('"+i+"');\">"+i.toString()+"</div>";
	}
	html+="<div style=\"float:right;margin-top:2px;\">Página: &nbsp;&nbsp;</div>";
	html+="<div style=\"clear:both;\"></div>";
	html+="</div>\n";
	document.getElementById("galerias_div").innerHTML=html;
	if(idg==null){
		if(document.getElementById("zona_seleccion")){document.getElementById("zona_seleccion").style.display="block";}
		if(document.getElementById("zona_detalle")){document.getElementById("zona_detalle").style.display="none";}		
	}else{
		getFotos(idg);
	}
	html=null;
}
function showGalPage(nropag){
	if(galerias.length==0){return;}
	if(galerias.length/galeriasxpagina!=parseInt(galerias.length/galeriasxpagina,10)){var cpage=parseInt(galerias.length/galeriasxpagina,10)+1;}else{var cpage=parseInt(galerias.length/galeriasxpagina,10);}
	var divs = document.getElementsByTagName("DIV")
	for (var i=0;i<divs.length;i++){
		if(divs[i].className=="galpagina"){
			if(divs[i].id=="galpagina"+nropag){divs[i].style.display="block";}else{divs[i].style.display="none";}
		}
	}
	var html="";
	for(var i=cpage;i>0;i--){
		html+="<div ";if(nropag==i){html+="class=\"npaginaH\" ";}else{html+="class=\"npagina\" ";}
		html+="onclick=\"showGalPage('"+i+"');\">"+i.toString()+"</div>";
	}
	html+="<div style=\"float:right;\">Página: &nbsp;&nbsp;</div><div style=\"clear:both;\"></div>";
	if(document.getElementById("paginadogalerias")){document.getElementById("paginadogalerias").innerHTML=html;}
	html=null;	
}
function getGalItem(index,w,h){
	if(w==null){w=148;}if(h==null){h=120;}
	if(index>=galerias.length){return "";}
	var html= "<div class=\"galeriaN\" style=\"float:left;margin-left:5px;\">";
		html+="	<div class=container title=\"pulsa aquí para ver estas fotos...\" onclick=\"getFotos('"+index+"');\">";
		html+="		<div class=foto style=\"background-image: url('/store/galerias/"+galerias[index][0]+"/"+galerias[index][5].toString().replace("/","/160x120_")+"');\"></div>";
		if(galerias[index][3]!=""){
			html+="	<div class=title>"+galerias[index][3]+"</div>";
		}else{
			html+="	<div class=title>"+galerias[index][2]+"</div>";
		}
		html+="		<div class=date><nobr>"+galerias[index][1]+"</nobr></div>";	
		html+="		<div class=nrofotos>"
						if(galerias[index][4]=="1"){html+="1 Fotografía";}else{html+=galerias[index][4]+" Fotografías";}
		html+="		</div>";
		html+="	</div>";
		html+="</div>";		
	return html;		
}	
function showFotos(index){
	if(fotos.length==0){return;}
	if(!document.getElementById("fotos_div")){return;}
	var cpage = 1;
	var html="";
	html+="<div class=\"fotopagina\" id=\"fotopagina1\" style=\"display:block;\">\n"
	for(var i=0;i<fotos.length;i++){
		if((i%fotosxpagina==0)&&(i>0)){
			cpage++;
			html+="\n</div>\n";
			html+="<div style=\"clear:both;\"></div>";
			html+="<div class=\"fotopagina\" id=\"fotopagina"+cpage+"\" style=\"display:none;\">\n";
		}			
		html+=getImage(i,156,117,index);
	}
	html+="\n</div>\n";
	html+="<div style=\"clear:both;\"></div>";
	html+="<div id=paginadofotos style=\"margin-top:5px;\">\n"
	for(var i=cpage;i>0;i--){
		html+="<div ";if(i==1){html+="class=\"npaginaH\" ";}else{html+="class=\"npagina\" ";}
		html+="onclick=\"showFotoPage('"+i+"');\">"+i.toString()+"</div>";
	}
	html+="<div style=\"float:right;margin-top:2px;\">Página: &nbsp;&nbsp;</div><div style=\"clear:both;\"></div>";
	html+="</div>\n";		
	document.getElementById("fotos_div").innerHTML=html;
	if(document.getElementById("zona_seleccion")){document.getElementById("zona_seleccion").style.display="none";}
	if(document.getElementById("zona_detalle")){document.getElementById("zona_detalle").style.display="block";}
	html=null;
}
function getImage(indexfoto,w,h,index){
	if(w==null){w=160;}if(h==null){h=120;}
	if(indexfoto<fotos.length){
		var html="<div class=container title=\"pulsa aquí para ampliar esta foto...\" onclick=\"showFoto('"+indexfoto+"');\">";	
		html+="<div class=foto id=\"foto"+indexfoto+"\">";
		html+="<div id=loading"+indexfoto+" style=\"height:"+(h+8)+"px;width:"+(w+8)+"px;\"><img src=\"/images/layout/anima/arrows_loading.gif\" height=18 width=15 style=\"margin-top:44px;margin-left:64px;\"></div>"
		html+="<img class=imagen onerror=\"loadFotoError('"+indexfoto+"');\" onload=\"stopLoading('"+indexfoto+"');\"src=\"/store/galerias/"+fotos[indexfoto][0]+"/"+fotos[indexfoto][1]+"/160x120_"+fotos[indexfoto][4]+"\" width="+w+" height="+h+">";
		html+="</div>";
		html+="</div>";
	}else{
		var html="<img src=\"/images/layout/clearpixel.gif\" width="+w+" height=0>";
	}
	return html;		
}
function showFotoPage(nropag){
	if(fotos.length==0){return;}
	if(fotos.length/fotosxpagina!=parseInt(fotos.length/fotosxpagina,10)){var cpage=parseInt(fotos.length/fotosxpagina,10)+1;}else{var cpage=parseInt(fotos.length/fotosxpagina,10);}
	var divs = document.getElementsByTagName("DIV")
	for (var i=0;i<divs.length;i++){
		if(divs[i].className=="fotopagina"){
			if(divs[i].id=="fotopagina"+nropag){divs[i].style.display="block";}else{divs[i].style.display="none";}
		}
	}
	var html="";
	for(var i=cpage;i>0;i--){
		html+="<div ";if(nropag==i){html+="class=\"npaginaH\" ";}else{html+="class=\"npagina\" ";}
		html+="onclick=\"showFotoPage('"+i+"');\">"+i.toString()+"</div>";
	}
	html+="<div style=\"float:right;\">Página: &nbsp;&nbsp;</div><div style=\"clear:both;\"></div>";
	if(document.getElementById("paginadofotos")){document.getElementById("paginadofotos").innerHTML=html;}
	html=null;
}
function loadFotoError(indexfoto){
	if(document.getElementById("foto"+indexfoto)){document.getElementById("foto"+indexfoto).innerHTML="<img src=\"/images/layout/anima/arrows_loading.gif\" height=18 width=15 style=\"margin-top:44px;margin-left:64px;\">";}
}
function stopLoading(indexfoto){
	if(document.getElementById("loading"+indexfoto)){document.getElementById("loading"+indexfoto).style.display="none";}
}
function showYearsN(dYear,dMonth,dCat){
	var html="<select name=galYear id=galYear size=1 onchange=\"showMonthsN(this.value);\">";
	var actualYear = "";
	for(var i=0;i<selectFechas.length;i++){
		if(actualYear!=selectFechas[i].toString().substring(0,4)){
			actualYear=selectFechas[i].toString().substring(0,4);
			html+="<option ";if(dYear==actualYear){html+="selected ";}
			html+="value=\""+selectFechas[i].toString().substring(0,4)+"\">"+selectFechas[i].toString().substring(0,4)+"</option>";
		}
	}
	html+="</select>";
	document.getElementById("div_galyear").innerHTML=html; html=null;		
	//if(!document.getElementById("div_galmes")){showMonthsN();}
	showMonthsN(dYear,dMonth,dCat);
}
function showMonthsN(sYear,sMonth,sCat){
	if(sMonth==null){sMonth="0";};if(sYear==null){sYear=document.getElementById("galYear").value;}
	var html="<select name=galMonth id=galMonth size=1 onchange=\"getCategorias(this);\">";
	for(var i=0;i<selectFechas.length;i++){
		if(sYear==selectFechas[i].toString().substring(0,4)){
			html+="<option ";if((sYear.toString()+completa2(sMonth).toString())==selectFechas[i]){html+="selected ";}
			html+="value=\""+selectFechas[i]+"\">"+getMonthName(selectFechas[i])+"</option>";
		}
	}	
	html+="</select>";
	//if(!document.getElementById("div_galmes")){document.write("<div id=\"div_galmes\"></div><div style=\"clear:both;\"></div>");}
	document.getElementById("div_galmes").innerHTML=html;html=null;
	getCategorias(null,sCat);
}
function showGalMenu(){
	if(document.getElementById("zona_seleccion")){document.getElementById("zona_seleccion").style.display="block";}
	if(document.getElementById("zona_detalle")){document.getElementById("zona_detalle").style.display="none";}
	if(document.getElementById("fotos_div")){document.getElementById("fotos_div").innerHTML="";}
}
function showGaleria(){
	showYearsN(dYear,dMonth,dCat);
}
function backSearch(){
	document.forms["buscarForm"].p.value=p;
	document.forms["buscarForm"].submit();
}
