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) {
	window.open("/"+link+".html?"+parametros+"&Idioma="+idioma, "","resizable=1,SCROLLBARS=YES,HEIGHT="+alto+",WIDTH="+ancho);
}

var H1_Replace =(window.onload)? window.onload : function(){};
window.onload = function(){H1_Replace(); H1_Replace_Setup('h4');}

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();
}

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);
    }
}



function tit(swf,texto,pagina) {

	var width=196;
	var height=20;


	if (swf=='titl') {
		width=196;
		height=20;
	}

	if (swf=='titc') {
		width=686;
		height=20;
	}
	
	if (swf=='titp') {
		width=602;
		height=20;
	}

	var so = new SWFObject("media/Flash/"+swf+".swf", "+pagina+", width, height, "8", "#FFFFFF");
	so.addVariable("mitexto", texto.toUpperCase());
	so.addParam("wmode", "transparent");
	so.addParam("menu", "false");
	so.write(pagina);
}

function Carrito(msg) {
	alert(msg);
}

function Email(msg) {
	alert(msg);
}

/* validar NIF */

function CalculaNifCif(nif,ff) {
	nif = replaceSubstring(nif,' ','');
	nif = replaceSubstring(nif,'-','');
	nif = replaceSubstring(nif,'.','');
	if(nif.length!=9){
		return false;
	}
	else{
		if(!(CalculaNif(nif) || CalculaCif(nif) || CalculaNie(nif))) {
			return false;
		}
		else {
			ff.nif.value = nif.toUpperCase();
			return true;
		}
	}
}
function CalculaNie(nif){
	var letras = 'TRWAGMYFPDXBNJZSQVHLCKE';
	var letraNie = nif.substring(0,1);
	var dni = nif.substring(1,8);
	var letraNif = nif.substring(8,9);
	var letraAux;
	var letraInicio='X';
	var numero = dni%23;
	letraAux = letras.substring(numero,numero+1);
	if ((letraAux == letraNif.toUpperCase()) && (letraInicio==letraNie.toUpperCase())){
		return true;
	}
	else{
		return false;
	}
}
function CalculaNif(nif){
	var letras = 'TRWAGMYFPDXBNJZSQVHLCKE';
	var dni    = nif.substring(0,8);
	var letraNif = nif.substring(8,9);
	var letraAux;
	var numero = dni%23;
	letraAux = letras.substring(numero,numero+1);
	if(letraAux == letraNif.toUpperCase()){
		return true;
	}
	else{
		return false;
	}
}
function CalculaCif(elCIF){
	var resul = false;
	var temp = elCIF.toUpperCase();
	if (!/^[A-Za-z0-9]{9}$/.test(temp)) {
		resul = false;
	}
	else {
		if (!/^[ABCDEFGHKLMNPQS]/.test(temp)) {
			resul = false;
		}
		else {
			resul = ValidaCIF(temp);
		}
	}
	return resul;
}
function ValidaCIF(elCIF){
	var resul = false;
	var v1 = new Array(0,2,4,6,8,1,3,5,7,9);
	var letrascif = "ABCDEFGHIJ";
	var temp = 0;
	var temp1;
	for(i=2;i<=6;i+=2){
		temp = temp + v1[parseInt(elCIF.substr(i-1,1))];
		temp = temp + parseInt(elCIF.substr(i,1));
	}
	temp = temp + v1[parseInt(elCIF.substr(7,1))];
	temp = (10 - ( temp % 10));
	if( temp == 10 ) {
		if ((elCIF.substring(8,9)=='J') || (elCIF.substring(8,9)=='0')) {
			resul = true;
		}
		else {
			resul = false;
		}
	}
	else {
		if ((elCIF.substring(8,9)==temp) || (elCIF.substring(8,9)==letrascif.substring(temp-1,temp))) {
			resul = true;
		}
		else {
			resul = false;
		}
	}
	return resul;
}

function ValidaCIFaaaa(elCIF){
	var resul = false;
	var v1 = new Array(0,2,4,6,8,1,3,5,7,9);
	var temp = 0;
	var temp1;
	for(i=2;i<=6;i+=2){
		temp = temp + v1[parseInt(elCIF.substr(i-1,1))];
		temp = temp + parseInt(elCIF.substr(i,1));
	}
	temp = temp + v1[parseInt(elCIF.substr(7,1))];
	temp = (10 - ( temp % 10));
	if( temp == 10 ) {
		if ((elCIF.substring(8,9)=='J') || (elCIF.substring(8,9)=='0')) {
			resul = true;
		}
		else {
			resul = false;
		}
	}
	else {
		if (elCIF.substring(8,9)==temp) {
			resul = true;
		}
		else {
			resul = false;
		}
	}
	return resul;
}
function replaceSubstring(inputString, fromString, toString) {
   var temp = inputString;
   if (fromString == '') {
      return inputString;
   }
   if (toString.indexOf(fromString) == -1){
      while (temp.indexOf(fromString) != -1){
         var toTheLeft = temp.substring(0, temp.indexOf(fromString));
         var toTheRight = temp.substring(temp.indexOf(fromString)+fromString.length, temp.length);
         temp = toTheLeft + toString + toTheRight;
      }
   }
   else{
      var midStrings = new Array('~', '`', '_', '^', '#');
      var midStringLen = 1;
      var midString = '';
      while (midString == '') {
         for (var i=0; i < midStrings.length; i++) {
            var tempMidString = '';
            for (var j=0; j < midStringLen; j++) { tempMidString += midStrings[i]; }
            if (fromString.indexOf(tempMidString) == -1) {
               midString = tempMidString;
               i = midStrings.length + 1;
            }
         }
      }
      while (temp.indexOf(fromString) != -1) {
         var toTheLeft = temp.substring(0, temp.indexOf(fromString));
         var toTheRight = temp.substring(temp.indexOf(fromString)+fromString.length, temp.length);
         temp = toTheLeft + midString + toTheRight;
      }
      while (temp.indexOf(midString) != -1) {
         var toTheLeft = temp.substring(0, temp.indexOf(midString));
         var toTheRight = temp.substring(temp.indexOf(midString)+midString.length, temp.length);
         temp = toTheLeft + toString + toTheRight;
      }
   }
   return temp;
}