function addLoadEvent(func) {
	var oldonload = window.onload;
	if (typeof window.onload != 'function') {
		window.onload = func;
	} else {
		window.onload = function() {
			if (oldonload) {
				oldonload();
			}
			func();
		}
	}
}

/* Funcion para el Pop-Up */

function Zoom(idioma,link,parametros,ancho,alto) {
	var a = window.open(idioma+"_"+link+".html?"+parametros, "","resizable=1,SCROLLBARS=YES,HEIGHT="+alto+",WIDTH="+ancho);
} 

function ZoomG(ruta,sPicURL,comentario) { 
	window.open("/zoom.html?img="+sPicURL+"&comentario="+comentario+"&ruta="+ruta,"","resizable=1,HEIGHT=200,WIDTH=200");
} 

var PreSimpleSwapOnload =(window.onload)? window.onload : function(){};
window.onload = function(){PreSimpleSwapOnload(); SimpleSwapSetup();}

function SimpleSwap(el, which) {
    el.src = el.getAttribute(which || "origsrc");
}

function SimpleSwapSetup() {
    var x = document.getElementsByTagName("img");
    for (var i = 0; i < x.length; i++) {
        var oversrc = x[i].getAttribute("oversrc");
        if (!oversrc) {
            continue;
        }
        x[i].oversrc_img = new Image;
        x[i].oversrc_img.src = oversrc;
        x[i].onmouseover = new Function("SimpleSwap(this,'oversrc');");
        x[i].onmouseout = new Function("SimpleSwap(this);");
        x[i].setAttribute("origsrc", x[i].src);
    }
}


var H1_Replace =(window.onload)? window.onload : function(){};
window.onload = function(){H1_Replace(); H1_Replace_Setup('h1'); H1_Replace_Setup('h2'); H1_Replace_Setup('h3');}

function H1_Replace_Setup(etiqueta) {
    var x = document.getElementsByTagName(etiqueta);
    for (var i = 0; i < x.length; i++) {
        var texto = x[i].innerHTML;
        if (!texto) {
            continue;
        }
        mi_id = x[i].id = etiqueta+"_"+i;
        H1_x_Div(x[i]);


	width = str_replace("px","",getStyle(mi_id,'width'));
	height = str_replace("px","",getStyle(mi_id,'height'));


        H1_Flash(x[i].id,x[i].className,texto,width,height);
    }
}


function H1_x_Div(x)
{
	var replace = document.createElement('div');
	for (var i=0;i<x.length;i++)
	{
		if (x[i].id)
		{
			var y = replace.cloneNode(true);
			x[i].replaceChild(y,x[i].firstChild);
		}
	}
}

function H1_Flash(id,estilo,texto,width,height) {

	var so = new SWFObject("media/Flash/"+estilo+".swf", "subtitulo", width, height, "8", "#FFFFFF");
	so.addVariable("mitexto", texto);
	so.addParam("wmode", "transparent");
	so.addParam("menu", "false");
	so.write(id);
}

function getStyle(el,styleProp)
{
	var x = document.getElementById(el);
	if (x.currentStyle)
		var y = x.currentStyle[styleProp];
	else if (window.getComputedStyle)
		var y = document.defaultView.getComputedStyle(x,null).getPropertyValue(styleProp);
	return y;
}

function str_replace(busca, repla, orig)
{
	str 	= new String(orig);

	rExp	= "/"+busca+"/g";
	rExp	= eval(rExp);
	newS	= String(repla);

	str = new String(str.replace(rExp, newS));

	return str;
}

/* Función para el Paginado */

function paginadoListado(mipagina) {
	var ff=window.document.bava;
	ff.pagina.value=mipagina;
	ff.submit();
}

/* Funcion para la busqueda */

function cambiarFiltro(id) {
	var ff=window.document.busqueda;
	ff.Cat.value=id;
	ff.submit();
}


/* Cargar el botón de instalación de Digital Editions  Versión 1.7 */


	// ********************
	// Stub function provided to support operation
	// independent of DigitalEditionsDetection.js
	// ********************
	function ShowADE_DivLayer()
	{
		// This example does not use DigitalEditionsDetection.js
		// Therefore this stub is needed
		return;
	}

	// ********************
	// Stub function provided to support operation for SWF Version
	// This is called when sendSWFVersion = "true"
	// and the script at setG_strSWFVersion() detects a fresh string
	// ********************
	function ShowSWFVersion_DivLayer()
	{
		// We do the version in this example therefore this is needed
		if (G_bUpdateSWFVersion)
		{
			G_bUpdateSWFVersion = false;
			var element = document.getElementById("swfVersionDiv");

			if (G_strSWFVersion.length > 0)
			{
				element.innerHTML = "<hr/>Adobe Digital Editions SWF Version:<br/><br/>" + G_strSWFVersion;
				// kick in the pants to be sure to display
				element.style.display = "block";
			}
			else
			{
				element.style.display = "none";
			}
		}
		return;
	}

	// ********************
	// Stub function provided to support send_ADE_SWF_ButtonPush()
	// That anchor function will call the stub
	// This way, the anchor function is always defined, and various
	// implementations can provide the stub where needed
	// ********************
	function ADE_SWF_ButtonPush_action()
	{
		// Copy and enable this function into your
		// implementations where sendButtonPush = "true"

		//  NOTE: When sendButtonPush = "true", then even if contentURL is set, it will not
		//  be sent to ADE after it is launched.  When sendButtonPush = "true", all that happens
		//  after ADE is launched is that the JS Callback is made, and that is it.

		// We dont do this, but stub is provided anyway
		return;
	}

	function doOnLoad()
	{
		// Please reference ADEBadgeLauncher.js for full documentation

		//  HTML Section params:
		//  =========================
		// HTMLdivID - id of the <div> which will hold the SWF
		// HTMLobjectID - desired ID for the HTML <object> that contains the SWF (may be null - default is ADEBadgeLauncherInstance)


		// *******************************
		// FOR installerDivLayer1
		// *******************************

		//  HTML Section params:
		//  =========================
		var HTMLdivID = "installerDivLayer1"; 
		var HTMLobjectID = "ADEBadgeInstallerInstance1";

		//  Flash SWF parameters:
		//  =========================
		var autoInstall = false; 
		var autoLaunch = false;
		var badFlashRedirectURL	= null; // "http://my.domain.com/flashhelp";  // null; // can be null

		var sendSWFVersion = true;
		var sendButtonPush = false;  // if true, only call the JS function - contentURL would be ignored if used

		ADEBadgeInstallerInstance(HTMLdivID, HTMLobjectID,  autoInstall, autoLaunch, badFlashRedirectURL, sendSWFVersion, sendButtonPush);

		// *******************************
		// THIS SECTION SHOWING THE USE OF THE DEFAULTS
		// *******************************

	 /**** installerDivLayer2 commented for now ****	

		//  HTML Section params:
		//  =========================
		HTMLdivID = "installerDivLayer2"; 
		HTMLobjectID = "ADEBadgeInstallerInstance2";

		SetADEBadgeInstallerDefaults(autoInstall, autoLaunch, badFlashRedirectURL, sendSWFVersion, sendButtonPush);

		// simpler API
		ADEBadgeInstallerInstanceWithDefs(HTMLdivID, HTMLobjectID);

	**** installerDivLayer2 commented for now ****/

	}
	


/* Cargar el botón de instalación de Digital Editions  Versión 1.6 */

function ADE_Instalador() {


	var qs = new Querystring();

	var so = new SWFObject("/media/Flash/ade_web_library.swf", "subtitulo", 315, 220, "7", "#FFFFFF");
	so.addParam("wmode", "opaque");
	so.addParam("menu", "false");

	so.addVariable("min_major_version", "7");
	so.addVariable("min_minor_version", "0");
	so.addVariable("min_rev_version", "0");
	so.addVariable("min_build_version", "0");

	so.addVariable("MMredirectURL", document.location.href);
	so.addVariable("userAgent", navigator.userAgent);
	so.addVariable("ADEVersion", "2");  // "2" means ADE 1.5

	var ap = qs.get("autoPrompt", "false");
	so.addVariable("autoPrompt", ap);

	so.addVariable("badgeJSLauncher", "true");
	so.addVariable("file", "");
	so.addVariable("contentURL", "");

	so.write('div_ADE_Instalador');

}



/* Client-side access to querystring name=value pairs
	Version 1.3
	28 May 2008
	
	License (Simplified BSD):
	http://adamv.com/dev/javascript/qslicense.txt
*/
function Querystring(qs) { // optionally pass a querystring to parse
	this.params = {};
	
	if (qs == null) qs = location.search.substring(1, location.search.length);
	if (qs.length == 0) return;

// Turn <plus> back to <space>
// See: http://www.w3.org/TR/REC-html40/interact/forms.html#h-17.13.4.1
	qs = qs.replace(/\+/g, ' ');
	var args = qs.split('&'); // parse out name/value pairs separated via &
	
// split out each name=value pair
	for (var i = 0; i < args.length; i++) {
		var pair = args[i].split('=');
		var name = decodeURIComponent(pair[0]);
		
		var value = (pair.length==2)
			? decodeURIComponent(pair[1])
			: name;
		
		this.params[name] = value;
	}
}

Querystring.prototype.get = function(key, default_) {
	var value = this.params[key];
	return (value != null) ? value : default_;
}

Querystring.prototype.contains = function(key) {
	var value = this.params[key];
	return (value != null);
}



/* Zoom en Fotos */

/*
Simple Image Trail script- By JavaScriptKit.com
Visit http://www.javascriptkit.com for this script and more
This notice must stay intact
*/

var offsetfrommouse=[15,15]; //image x,y offsets from cursor position in pixels. Enter 0,0 for no offset
var displayduration=0; //duration in seconds image should remain visible. 0 for always.

var defaultimageheight = 40;	// maximum image size.
var defaultimagewidth = 40;	// maximum image size.

var timer;

function gettrailobj(){
if (document.getElementById)
return document.getElementById("preview_div").style
}

function gettrailobjnostyle(){
if (document.getElementById)
return document.getElementById("preview_div")
}


function truebody(){
return (!window.opera && document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body
}


function hidetrail(){	
	gettrailobj().display= "none";
	document.onmousemove=""
	gettrailobj().left="-3500px"
	clearTimeout(timer);
}

function showtrail(imagename,title,width,height){
	i = imagename
	t = title
	w = width
	h = height
	timer = setTimeout("show('"+i+"',t,w,h);",200);
	followmouse;
}
function show(imagename,title,width,height){
 
    	var oWidth = width;
    	var oHeight = height;
    	var docwidth=document.all? truebody().scrollLeft+truebody().clientWidth : pageXOffset+window.innerWidth - offsetfrommouse[0]
	var docheight=document.all? Math.min(truebody().scrollHeight, truebody().clientHeight) : Math.min(window.innerHeight)

	if( (navigator.userAgent.indexOf("Konqueror")==-1  || navigator.userAgent.indexOf("Firefox")!=-1 || (navigator.userAgent.indexOf("Opera")==-1 && navigator.appVersion.indexOf("MSIE")!=-1)) && (docwidth>650 && docheight>500)) {
		( width == 0 ) ? width = defaultimagewidth: '';
		( height == 0 ) ? height = defaultimageheight: '';
			
		width+=30
		height+=30
		defaultimageheight = height
		defaultimagewidth = width
	
		document.onmousemove=followmouse_2; 

		
		newHTML = '<div class="border_preview" style="width:'+  width +'px;height:'+ height +'px"><div id="loader_container"><div id="loader"><div align="center">Cargando imagen '+title+' ...</div><div id="loader_bg"><div id="progress"> </div></div></div></div>';
		//newHTML = newHTML + '<h2 class="title_h2">' + ' '+title + '</h2>'
		
    		newHTML = newHTML + '<div class="preview_temp_load"><img onload="javascript:remove_loading();" src="' + imagename + '" border="0" width="'+oWidth+'" height="'+oHeight+'"></div>';
		newHTML = newHTML + '</div>'; 
		
		if(navigator.userAgent.indexOf("MSIE")!=-1 && navigator.userAgent.indexOf("Opera")==-1 ){
			newHTML = newHTML+'<iframe src="about:blank" scrolling="no" frameborder="0" width="'+width+'" height="'+height+'"></iframe>';
		}		

		gettrailobjnostyle().innerHTML = newHTML;
		gettrailobj().display="block";
	}
}


function followmouse_2(e){

	var xcoord=offsetfrommouse[0]
	var ycoord=offsetfrommouse[1]

	var docwidth=document.all? truebody().scrollLeft+truebody().clientWidth : pageXOffset+window.innerWidth-15
	var docheight=document.all? Math.min(truebody().scrollHeight, truebody().clientHeight) : Math.min(window.innerHeight)

	if (typeof e != "undefined"){
		if (docwidth - e.pageX < defaultimagewidth + 2*offsetfrommouse[0]){
			xcoord = e.pageX - xcoord - defaultimagewidth; // Move to the left side of the cursor
		} else {
			xcoord += e.pageX;
		}
		if (docheight - e.pageY < defaultimageheight + 2*offsetfrommouse[1]){
			ycoord += e.pageY - Math.max(0,(2*offsetfrommouse[1] + defaultimageheight + e.pageY - docheight - truebody().scrollTop));
		} else {
			ycoord += e.pageY;
		}

	} else if (typeof window.event != "undefined"){
		if (docwidth - event.clientX < defaultimagewidth + 2*offsetfrommouse[0]){
			xcoord = event.clientX + truebody().scrollLeft - xcoord - defaultimagewidth; // Move to the left side of the cursor
		} else {
			xcoord += truebody().scrollLeft+event.clientX
		}
		if (docheight - event.clientY < (defaultimageheight + 2*offsetfrommouse[1])){
			ycoord += event.clientY + truebody().scrollTop - Math.max(0,(2*offsetfrommouse[1] + defaultimageheight + event.clientY - docheight));
		} else {
			ycoord += truebody().scrollTop + event.clientY;
		}
	}
	
	//xcoord = docwidth/2; 
	gettrailobj().left=xcoord+"px"
	gettrailobj().top=ycoord+"px"

}

function followmouse(e){

	var xcoord=offsetfrommouse[0]
	var ycoord=offsetfrommouse[1]

	var docwidth=document.all? truebody().scrollLeft+truebody().clientWidth : pageXOffset+window.innerWidth-15
	var docheight=document.all? Math.min(truebody().scrollHeight, truebody().clientHeight) : Math.min(window.innerHeight)

	if (typeof e != "undefined"){
		if (docwidth - e.pageX < defaultimagewidth + 2*offsetfrommouse[0]){
			xcoord = e.pageX - xcoord - defaultimagewidth; // Move to the left side of the cursor
		} else {
			xcoord += e.pageX;
		}
		if (docheight - e.pageY < defaultimageheight + 2*offsetfrommouse[1]){
			ycoord += e.pageY - Math.max(0,(2*offsetfrommouse[1] + defaultimageheight + e.pageY - docheight - truebody().scrollTop));
		} else {
			ycoord += e.pageY;
		}

	} else if (typeof window.event != "undefined"){
		if (docwidth - event.clientX < defaultimagewidth + 2*offsetfrommouse[0]){
			xcoord = event.clientX + truebody().scrollLeft - xcoord - defaultimagewidth; // Move to the left side of the cursor
		} else {
			xcoord += truebody().scrollLeft+event.clientX
		}
		if (docheight - event.clientY < (defaultimageheight + 2*offsetfrommouse[1])){
			ycoord += event.clientY + truebody().scrollTop - Math.max(0,(2*offsetfrommouse[1] + defaultimageheight + event.clientY - docheight));
		} else {
			ycoord += truebody().scrollTop + event.clientY;
		}
	}
	gettrailobj().left=xcoord+"px"
	gettrailobj().top=ycoord+"px"

}


var t_id = setInterval(animate,20);
var pos=0;
var dir=2;
var len=0;

function animate()
{
var elem = document.getElementById('progress');
if(elem != null) {
if (pos==0) len += dir;
if (len>32 || pos>79) pos += dir;
if (pos>79) len -= dir;
if (pos>79 && len==0) pos=0;
elem.style.left = pos;
elem.style.width = len;
}
}

function remove_loading() {
this.clearInterval(t_id);
var targelem = document.getElementById('loader_container');
targelem.style.display='none';
targelem.style.visibility='hidden';
var t_id = setInterval(animate,60);
}

