/* Funcion para añadir eventos al cargar la pagina */


function addLoadEvent(func) {
	var oldonload = window.onload;
	if (typeof window.onload != 'function') {
		window.onload = func;
	} else {
		window.onload = function() {
			if (oldonload) {
				oldonload();
			}
			func();
		}
	}
}


/* Función para el Paginado */

function paginadoListado(mipagina) {
	var ff=window.document.bava;
	ff.pagina.value=mipagina;
	ff.submit();
}

/* Funcion para el Pop-Up */

function Zoom(idioma,link,parametros,ancho,alto) {
	var a = window.open("/"+link+".html?"+parametros+"&Idioma="+idioma, "","resizable=1,SCROLLBARS=YES,HEIGHT="+alto+",WIDTH="+ancho);
}


/* Funcion para el oversrc */

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 H_Replace =(window.onload)? window.onload : function(){};
window.onload = function(){ H_Replace; SimpleSwapSetup(); /* H4_Replace_Setup('h4'); */ H4_Replace_Setup('h3'); H4_Replace_Setup('h2'); }

function H4_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]);

	link = x[i].getAttribute("href");
	//alert(link);
	width = str_replace("px","",getStyle(mi_id,'width'));
	height = str_replace("px","",getStyle(mi_id,'height'));

	if(etiqueta=='h4') {
		document.getElementById(x[i].id).style.width='1';
	}
        H4_Flash(x[i].id,x[i].className,texto,width,height,link);
    }
}

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 H4_Flash(id,estilo,texto,width,height,link) {
	var so = new SWFObject("/media/Flash/"+estilo+".swf", "f"+id, width, height, "8", "#FFFFFF");
	so.addVariable("mitexto", texto);
	so.addVariable("miid", id);
	so.addVariable("miurl", link);
	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;
}

function h4_width(id,valor) {
	document.getElementById(id).style.width=intval(valor)+"px";
	//alert(id+" : "+valor);
}

function Show_Menu() {
	id = 'Top_3_1';
	document.getElementById(id).style.display='block';
}

function intval( mixed_var, base ) {
    // http://kevin.vanzonneveld.net
    // +   original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +   improved by: stensi
    // +   bugfixed by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // *     example 1: intval('Kevin van Zonneveld');
    // *     returns 1: 0
    // *     example 2: intval(4.2);
    // *     returns 2: 4
    // *     example 3: intval(42, 8);
    // *     returns 3: 42
    // *     example 4: intval('09');
    // *     returns 4: 9
 
    var tmp;
 
    var type = typeof( mixed_var );
 
    if(type == 'boolean'){
        if (mixed_var == true) {
            return 1;
        } else {
            return 0;
        }
    } else if(type == 'string'){
        tmp = parseInt(mixed_var * 1);
        if(isNaN(tmp) || !isFinite(tmp)){
            return 0;
        } else{
            return tmp.toString(base || 10);
        }
    } else if(type == 'number' && isFinite(mixed_var) ){
        return Math.floor(mixed_var);
    } else{
        return 0;
    }
}

function Go(url) {
	document.location.href	= url;
}
